use of org.apache.maven.wagon.repository.Repository in project myfaces-build-tools by apache.
the class WagonMojo method execute.
public void execute() throws MojoExecutionException {
if (!inputDirectory.exists()) {
throw new MojoExecutionException("The inputDirectory does not exist");
}
Repository repository = new Repository(id, url);
Wagon wagon = null;
try {
wagon = wagonManager.getWagon(repository.getProtocol());
} catch (UnsupportedProtocolException e) {
throw new MojoExecutionException("Unsupported protocol: '" + repository.getProtocol() + "'", e);
}
if (!wagon.supportsDirectoryCopy()) {
throw new MojoExecutionException("Wagon protocol '" + repository.getProtocol() + "' doesn't support directory copying");
}
try {
Debug debug = new Debug();
wagon.addSessionListener(debug);
wagon.addTransferListener(debug);
wagon.connect(repository, wagonManager.getAuthenticationInfo(id));
wagon.putDirectory(inputDirectory, ".");
} catch (ResourceDoesNotExistException e) {
throw new MojoExecutionException("Error uploading", e);
} catch (TransferFailedException e) {
throw new MojoExecutionException("Error uploading", e);
} catch (AuthorizationException e) {
throw new MojoExecutionException("Error uploading", e);
} catch (ConnectionException e) {
throw new MojoExecutionException("Error uploading", e);
} catch (AuthenticationException e) {
throw new MojoExecutionException("Error uploading", e);
} finally {
try {
wagon.disconnect();
} catch (ConnectionException e) {
getLog().error("Error disconnecting wagon - ignored", e);
}
}
}
use of org.apache.maven.wagon.repository.Repository in project artifact-registry-maven-tools by GoogleCloudPlatform.
the class ArtifactRegistryWagonTest method testHeadPermissionDenied.
@Test
public void testHeadPermissionDenied() throws Exception {
MockHttpTransport transport = failingTransportWithStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
ArtifactRegistryWagon wagon = new ArtifactRegistryWagon();
wagon.setCredentialProvider(new FailingCredentialProvider(new IOException("failed to get access token")));
wagon.setHttpTransportFactory(() -> transport);
wagon.connect(new Repository("my-repo", REPO_URL));
expectedException.expect(AuthorizationException.class);
expectedException.expectMessage(CoreMatchers.containsString("Permission denied on remote repository (or it may not exist)"));
wagon.resourceExists("my/resource");
}
use of org.apache.maven.wagon.repository.Repository in project artifact-registry-maven-tools by GoogleCloudPlatform.
the class ArtifactRegistryWagonTest method testHeadExists.
@Test
public void testHeadExists() throws Exception {
MockHttpTransport transport = new MockHttpTransport.Builder().setLowLevelHttpResponse(new MockLowLevelHttpResponse().setStatusCode(HttpStatusCodes.STATUS_CODE_OK)).build();
ArtifactRegistryWagon wagon = new ArtifactRegistryWagon();
wagon.setCredentialProvider(() -> GoogleCredentials.create(new AccessToken("test-access-token", Date.from(Instant.now().plusSeconds(1000)))));
wagon.setHttpTransportFactory(() -> transport);
wagon.connect(new Repository("my-repo", REPO_URL));
Assert.assertTrue(wagon.resourceExists("my/resource"));
}
use of org.apache.maven.wagon.repository.Repository in project artifact-registry-maven-tools by GoogleCloudPlatform.
the class ArtifactRegistryWagonTest method testGetPermissionDenied.
@Test
public void testGetPermissionDenied() throws Exception {
MockHttpTransport transport = failingTransportWithStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
ArtifactRegistryWagon wagon = new ArtifactRegistryWagon();
wagon.setCredentialProvider(new FailingCredentialProvider(new IOException("failed to get access token")));
wagon.setHttpTransportFactory(() -> transport);
wagon.connect(new Repository("my-repo", REPO_URL));
File f = FileTestUtils.createUniqueFile("my/artifact/dir", "test");
expectedException.expect(AuthorizationException.class);
expectedException.expectMessage(CoreMatchers.containsString("Permission denied on remote repository (or it may not exist)"));
expectedException.expectMessage(CoreMatchers.containsString("The request had no credentials"));
wagon.get("my/resource", f);
}
use of org.apache.maven.wagon.repository.Repository in project artifact-registry-maven-tools by GoogleCloudPlatform.
the class ArtifactRegistryWagonTest method testNotFoundReturnsMessage.
@Test
public void testNotFoundReturnsMessage() throws Exception {
MockHttpTransport transport = failingTransportWithStatus(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
ArtifactRegistryWagon wagon = new ArtifactRegistryWagon();
wagon.setCredentialProvider(new FailingCredentialProvider(new IOException("failed to get access token")));
wagon.setHttpTransportFactory(() -> transport);
wagon.connect(new Repository("my-repo", REPO_URL));
File f = FileTestUtils.createUniqueFile("my/artifact/dir", "test");
expectedException.expect(ResourceDoesNotExistException.class);
expectedException.expectMessage(CoreMatchers.containsString("remote resource does not exist"));
wagon.get("my/resource", f);
}
Aggregations