Search in sources :

Example 26 with Repository

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);
        }
    }
}
Also used : Repository(org.apache.maven.wagon.repository.Repository) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) UnsupportedProtocolException(org.apache.maven.wagon.UnsupportedProtocolException) Wagon(org.apache.maven.wagon.Wagon) TransferFailedException(org.apache.maven.wagon.TransferFailedException) Debug(org.apache.maven.wagon.observers.Debug) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) ConnectionException(org.apache.maven.wagon.ConnectionException)

Example 27 with Repository

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");
}
Also used : Repository(org.apache.maven.wagon.repository.Repository) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) IOException(java.io.IOException) Test(org.junit.Test)

Example 28 with Repository

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"));
}
Also used : Repository(org.apache.maven.wagon.repository.Repository) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) AccessToken(com.google.auth.oauth2.AccessToken) Test(org.junit.Test)

Example 29 with Repository

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);
}
Also used : Repository(org.apache.maven.wagon.repository.Repository) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 30 with Repository

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);
}
Also used : Repository(org.apache.maven.wagon.repository.Repository) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Aggregations

Repository (org.apache.maven.wagon.repository.Repository)31 Test (org.junit.Test)13 IOException (java.io.IOException)11 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)9 File (java.io.File)9 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)8 Wagon (org.apache.maven.wagon.Wagon)7 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)7 Path (java.nio.file.Path)6 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)6 ConnectionException (org.apache.maven.wagon.ConnectionException)6 TransferFailedException (org.apache.maven.wagon.TransferFailedException)6 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)5 AuthorizationException (org.apache.maven.wagon.authorization.AuthorizationException)5 AccessToken (com.google.auth.oauth2.AccessToken)4 ZipEntry (java.util.zip.ZipEntry)4 ZipFile (java.util.zip.ZipFile)4 RoleManagementService (org.apache.archiva.redback.rest.api.services.RoleManagementService)4 RemoteRepository (org.apache.archiva.repository.RemoteRepository)4 UnsupportedProtocolException (org.apache.maven.wagon.UnsupportedProtocolException)4