Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ under the License.
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
12 changes: 4 additions & 8 deletions wagon-provider-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ under the License.

<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Files;
import java.util.List;

import org.apache.maven.wagon.authentication.AuthenticationException;
Expand Down Expand Up @@ -107,6 +108,7 @@ public abstract class AbstractWagon implements Wagon {
// Accessors
// ----------------------------------------------------------------------

@Override
public Repository getRepository() {
return repository;
}
Expand All @@ -123,53 +125,55 @@ public AuthenticationInfo getAuthenticationInfo() {
// Connection
// ----------------------------------------------------------------------

@Deprecated
@Override
public void openConnection() throws ConnectionException, AuthenticationException {
try {
openConnectionInternal();
} catch (ConnectionException e) {
fireSessionConnectionRefused();

throw e;
} catch (AuthenticationException e) {
} catch (ConnectionException | AuthenticationException e) {
fireSessionConnectionRefused();

throw e;
}
}

@Override
public void connect(Repository repository) throws ConnectionException, AuthenticationException {
connect(repository, null, (ProxyInfoProvider) null);
}

@Override
public void connect(Repository repository, ProxyInfo proxyInfo)
throws ConnectionException, AuthenticationException {
connect(repository, null, proxyInfo);
}

@Override
public void connect(Repository repository, ProxyInfoProvider proxyInfoProvider)
throws ConnectionException, AuthenticationException {
connect(repository, null, proxyInfoProvider);
}

@Override
public void connect(Repository repository, AuthenticationInfo authenticationInfo)
throws ConnectionException, AuthenticationException {
connect(repository, authenticationInfo, (ProxyInfoProvider) null);
}

@Override
public void connect(Repository repository, AuthenticationInfo authenticationInfo, ProxyInfo proxyInfo)
throws ConnectionException, AuthenticationException {
final ProxyInfo proxy = proxyInfo;
connect(repository, authenticationInfo, new ProxyInfoProvider() {
public ProxyInfo getProxyInfo(String protocol) {
if (protocol == null || proxy == null || protocol.equalsIgnoreCase(proxy.getType())) {
return proxy;
} else {
return null;
}
connect(repository, authenticationInfo, (ProxyInfoProvider) protocol -> {
if (protocol == null || proxy == null || protocol.equalsIgnoreCase(proxy.getType())) {
return proxy;
} else {
return null;
}
});
}

@Override
public void connect(
Repository repository, AuthenticationInfo authenticationInfo, ProxyInfoProvider proxyInfoProvider)
throws ConnectionException, AuthenticationException {
Expand Down Expand Up @@ -210,6 +214,7 @@ public void connect(

protected abstract void openConnectionInternal() throws ConnectionException, AuthenticationException;

@Override
public void disconnect() throws ConnectionException {
fireSessionDisconnecting();

Expand Down Expand Up @@ -242,10 +247,12 @@ protected void createParentDirectories(File destination) throws TransferFailedEx
}
}

@Override
public void setTimeout(int timeoutValue) {
connectionTimeout = timeoutValue;
}

@Override
public int getTimeout() {
return connectionTimeout;
}
Expand Down Expand Up @@ -277,12 +284,8 @@ protected void getTransfer(Resource resource, File destination, InputStream inpu

fireGetStarted(resource, destination);

OutputStream output = null;
try {
output = new LazyFileOutputStream(destination);
try (OutputStream output = new LazyFileOutputStream(destination)) {
getTransfer(resource, output, input, closeInput, maxSize);
output.close();
output = null;
} catch (final IOException e) {
if (destination.exists()) {
boolean deleted = destination.delete();
Expand All @@ -306,13 +309,6 @@ protected void getTransfer(Resource resource, File destination, InputStream inpu
}
}
throw e;
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
}
}
}

fireGetCompleted(resource, destination);
Expand Down Expand Up @@ -340,9 +336,11 @@ protected void getTransfer(
throw new TransferFailedException(msg, e);
} finally {
if (closeInput) {
try {
input.close();
} catch (IOException ignored) {
if (input != null) {
try {
input.close();
} catch (IOException ignore) {
}
}
}

Expand Down Expand Up @@ -378,30 +376,14 @@ protected void putTransfer(Resource resource, File source, OutputStream output,
*/
protected void transfer(Resource resource, File source, OutputStream output, boolean closeOutput)
throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException {
InputStream input = null;

try {
input = new FileInputStream(source);

try (InputStream input = new FileInputStream(source)) {
putTransfer(resource, input, output, closeOutput);

input.close();
input = null;
} catch (FileNotFoundException e) {
fireTransferError(resource, e, TransferEvent.REQUEST_PUT);

throw new TransferFailedException("Specified source file does not exist: " + source, e);
} catch (final IOException e) {
fireTransferError(resource, e, TransferEvent.REQUEST_PUT);

throw new TransferFailedException("Failure transferring " + source, e);
} finally {
if (input != null) {
try {
input.close();
} catch (IOException ignored) {
}
}
}
}

Expand Down Expand Up @@ -430,13 +412,14 @@ protected void putTransfer(Resource resource, InputStream input, OutputStream ou

throw new TransferFailedException(msg, e);
} finally {
if (closeOutput && output != null) {
try {
output.close();
} catch (IOException ignored) {
if (closeOutput) {
if (output != null) {
try {
output.close();
} catch (IOException ignore) {
}
}
}

cleanupPutTransfer(resource);
}
}
Expand Down Expand Up @@ -493,6 +476,7 @@ protected void transfer(Resource resource, InputStream input, OutputStream outpu
* @param maxSize size of the buffer
* @throws IOException
*/
@SuppressWarnings("RedundantCast")
protected void transfer(Resource resource, InputStream input, OutputStream output, int requestType, long maxSize)
throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(getBufferCapacityForTransfer(resource.getContentLength()));
Expand Down Expand Up @@ -732,26 +716,32 @@ protected void fireSessionDebug(String message) {
sessionEventSupport.fireDebug(message);
}

@Override
public boolean hasTransferListener(TransferListener listener) {
return transferEventSupport.hasTransferListener(listener);
}

@Override
public void addTransferListener(TransferListener listener) {
transferEventSupport.addTransferListener(listener);
}

@Override
public void removeTransferListener(TransferListener listener) {
transferEventSupport.removeTransferListener(listener);
}

@Override
public void addSessionListener(SessionListener listener) {
sessionEventSupport.addSessionListener(listener);
}

@Override
public boolean hasSessionListener(SessionListener listener) {
return sessionEventSupport.hasSessionListener(listener);
}

@Override
public void removeSessionListener(SessionListener listener) {
sessionEventSupport.removeSessionListener(listener);
}
Expand Down Expand Up @@ -789,10 +779,7 @@ protected void postProcessListeners(Resource resource, File source, int requestT
transferEvent.setTimestamp(System.currentTimeMillis());
transferEvent.setLocalFile(source);

InputStream input = null;
try {
input = new FileInputStream(source);

try (InputStream input = Files.newInputStream(source.toPath())) {
while (true) {
int n = input.read(buffer);

Expand All @@ -802,28 +789,19 @@ protected void postProcessListeners(Resource resource, File source, int requestT

fireTransferProgress(transferEvent, buffer, n);
}

input.close();
input = null;
} catch (IOException e) {
fireTransferError(resource, e, requestType);

throw new TransferFailedException("Failed to post-process the source file", e);
} finally {
if (input != null) {
try {
input.close();
} catch (IOException ignored) {
}
}
}
}

@Override
public void putDirectory(File sourceDirectory, String destinationDirectory)
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
throw new UnsupportedOperationException("The wagon you are using has not implemented putDirectory()");
}

@Override
public boolean supportsDirectoryCopy() {
return false;
}
Expand All @@ -838,19 +816,23 @@ protected static String getPath(String basedir, String dir) {
return path;
}

@Override
public boolean isInteractive() {
return interactive;
}

@Override
public void setInteractive(boolean interactive) {
this.interactive = interactive;
}

@Override
public List<String> getFileList(String destinationDirectory)
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
throw new UnsupportedOperationException("The wagon you are using has not implemented getFileList()");
}

@Override
public boolean resourceExists(String resourceName) throws TransferFailedException, AuthorizationException {
throw new UnsupportedOperationException("The wagon you are using has not implemented resourceExists()");
}
Expand All @@ -873,10 +855,12 @@ public void setPermissionsOverride(RepositoryPermissions permissionsOverride) {
this.permissionsOverride = permissionsOverride;
}

@Override
public void setReadTimeout(int readTimeout) {
this.readTimeout = readTimeout;
}

@Override
public int getReadTimeout() {
return this.readTimeout;
}
Expand Down
Loading