Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Oct 8, 2023
2 parents f519c95 + 4533752 commit 361e92b
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 46 deletions.
52 changes: 27 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
name: Build

on:
push:
pull_request:
branches:
- master
push:
pull_request:
branches:
- master
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-latest, ubuntu-latest, windows-latest ]
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build with Maven
run: mvn --no-transfer-progress --batch-mode verify
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest ]
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up Docker
uses: docker/setup-buildx-action@v2
- name: Build with Maven
run: mvn --no-transfer-progress --batch-mode verify
41 changes: 30 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.github.lookfirst</groupId>
<artifactId>sardine</artifactId>
<packaging>jar</packaging>
<version>5.12-SNAPSHOT</version>
<version>5.13-SNAPSHOT</version>
<description>An easy to use WebDAV client for Java</description>
<name>Sardine WebDAV client</name>
<url>https://github.com/lookfirst/sardine</url>
Expand Down Expand Up @@ -82,6 +82,11 @@
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
Expand Down Expand Up @@ -148,6 +153,7 @@
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
Expand All @@ -172,6 +178,7 @@
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
Expand Down Expand Up @@ -205,17 +212,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<releaseProfiles>release-sign-artifacts</releaseProfiles>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -249,8 +257,17 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<!-- Skip integration tests by default with failsafe plugin -->
<skipITs>true</skipITs>
<skipITs>false</skipITs>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand All @@ -262,23 +279,25 @@
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.2</version>
<version>4.0.3</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
Expand All @@ -296,7 +315,7 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.18.3</version>
<version>1.19.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
60 changes: 57 additions & 3 deletions src/main/java/com/github/sardine/DavResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.github.sardine;

import com.github.sardine.model.Activelock;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
Expand All @@ -31,6 +32,8 @@
import com.github.sardine.model.Getcontenttype;
import com.github.sardine.model.Getetag;
import com.github.sardine.model.Getlastmodified;
import com.github.sardine.model.Lockdiscovery;
import com.github.sardine.model.Locktoken;
import com.github.sardine.model.Propstat;
import com.github.sardine.model.Report;
import com.github.sardine.model.Resourcetype;
Expand Down Expand Up @@ -87,14 +90,15 @@ private class DavProperties
final String contentType;
final String etag;
final String displayName;
final String lockToken;
final List<QName> resourceTypes;
final String contentLanguage;
final Long contentLength;
final List<QName> supportedReports;
final Map<QName, String> customProps;

DavProperties(Date creation, Date modified, String contentType,
Long contentLength, String etag, String displayName, List<QName> resourceTypes,
Long contentLength, String etag, String displayName, String lockToken, List<QName> resourceTypes,
String contentLanguage, List<QName> supportedReports, Map<QName, String> customProps)
{
this.creation = creation;
Expand All @@ -103,6 +107,7 @@ private class DavProperties
this.contentLength = contentLength;
this.etag = etag;
this.displayName = displayName;
this.lockToken = lockToken;
this.resourceTypes = resourceTypes;
this.contentLanguage = contentLanguage;
this.supportedReports = supportedReports;
Expand All @@ -116,6 +121,7 @@ private class DavProperties
this.contentLength = getContentLength(response);
this.etag = getEtag(response);
this.displayName = getDisplayName(response);
this.lockToken = getLockToken(response);
this.resourceTypes = getResourceTypes(response);
this.contentLanguage = getContentLanguage(response);
this.supportedReports = getSupportedReports(response);
Expand All @@ -130,13 +136,13 @@ private class DavProperties
* @throws java.net.URISyntaxException If parsing the href from the response element fails
*/
protected DavResource(String href, Date creation, Date modified, String contentType,
Long contentLength, String etag, String displayName, List<QName> resourceTypes,
Long contentLength, String etag, String displayName, String lockToken, List<QName> resourceTypes,
String contentLanguage, List<QName> supportedReports, Map<QName, String> customProps)
throws URISyntaxException
{
this.href = new URI(href);
this.status = DEFAULT_STATUS_CODE;
this.props = new DavProperties(creation, modified, contentType, contentLength, etag, displayName,
this.props = new DavProperties(creation, modified, contentType, contentLength, etag, displayName, lockToken,
resourceTypes, contentLanguage, supportedReports, customProps);
}

Expand Down Expand Up @@ -204,6 +210,46 @@ private String getModifiedDate(Response response)
return null;
}

/**
* Retrieves locktocken from props. If it is not available return null.
*
* @param response The response complex type of the multistatus
* @return Null if not found in props
*/
private String getLockToken(Response response)
{
List<Propstat> list = response.getPropstat();
if (list.isEmpty())
{
return null;
}
for (Propstat propstat : list)
{
if (propstat.getProp() != null) {
Lockdiscovery ld = propstat.getProp().getLockdiscovery();
if (ld != null)
{
if (ld.getActivelock().size() == 1)
{
final Activelock al = ld.getActivelock().get(0);
if (al != null)
{
final Locktoken lt = al.getLocktoken();
if (lt != null)
{
if (lt.getHref().size() == 1)
{
return lt.getHref().get(0);
}
}
}
}
}
}
}
return null;
}

/**
* Retrieves creationdate from props. If it is not available return null.
*
Expand Down Expand Up @@ -552,6 +598,14 @@ public String getDisplayName()
return this.props.displayName;
}

/**
* @return Lock Token
*/
public String getLockToken()
{
return this.props.lockToken;
}

/**
* @return Resource types
*/
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/com/github/sardine/Sardine.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ public interface Sardine
*/
List<DavResource> patch(String url, List<Element> addProps, List<QName> removeProps) throws IOException;

/**
* Add or remove custom properties for a url using WebDAV <code>PROPPATCH</code>.
*
* @param url Path to the resource including protocol and hostname
* @param addProps Properties to add to resource. If a property already exists then its value is replaced.
* @param removeProps Properties to remove from resource. Specifying the removal of a property that does not exist is not an error.
* @param headers Additional HTTP headers to add to the request
* @return The patched resources from the response
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> patch(String url, List<Element> addProps, List<QName> removeProps, Map<String, String> headers) throws IOException;

/**
* Uses HTTP <code>GET</code> to download data from a server. The stream must be closed after reading.
*
Expand Down Expand Up @@ -287,6 +299,15 @@ public interface Sardine
*/
void delete(String url) throws IOException;

/**
* Delete a resource using HTTP <code>DELETE</code> at the specified url
*
* @param url Path to the resource including protocol and hostname
* @param headers Additional HTTP headers to add to the request
* @throws IOException I/O error or HTTP response validation failure
*/
void delete(String url, Map<String, String> headers) throws IOException;

/**
* Uses WebDAV <code>MKCOL</code> to create a directory at the specified url
*
Expand Down Expand Up @@ -314,6 +335,17 @@ public interface Sardine
*/
void move(String sourceUrl, String destinationUrl, boolean overwrite) throws IOException;

/**
* Move a url to from source to destination using WebDAV <code>MOVE</code>.
*
* @param sourceUrl Path to the resource including protocol and hostname
* @param destinationUrl Path to the resource including protocol and hostname
* @param overwrite {@code true} to overwrite if the destination exists, {@code false} otherwise.
* @param headers Additional HTTP headers to add to the request
* @throws IOException I/O error or HTTP response validation failure
*/
void move(String sourceUrl, String destinationUrl, boolean overwrite, Map<String, String> headers) throws IOException;

/**
* Copy a url from source to destination using WebDAV <code>COPY</code>. Assumes overwrite.
*
Expand All @@ -333,6 +365,17 @@ public interface Sardine
*/
void copy(String sourceUrl, String destinationUrl, boolean overwrite) throws IOException;

/**
* Copy a url from source to destination using WebDAV <code>COPY</code>.
*
* @param sourceUrl Path to the resource including protocol and hostname
* @param destinationUrl Path to the resource including protocol and hostname
* @param overwrite {@code true} to overwrite if the destination exists, {@code false} otherwise.
* @param headers Additional HTTP headers to add to the request
* @throws IOException I/O error or HTTP response validation failure
*/
void copy(String sourceUrl, String destinationUrl, boolean overwrite, Map<String, String> headers) throws IOException;

/**
* Performs a HTTP <code>HEAD</code> request to see if a resource exists or not.
*
Expand Down
Loading

0 comments on commit 361e92b

Please sign in to comment.