Search in sources :

Example 36 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class ListRepositoriesMojo method doExecute.

/**
 * Displays a list of the repositories used by this build.
 *
 * @throws MojoExecutionException with a message if an error occurs.
 */
@Override
protected void doExecute() throws MojoExecutionException {
    try {
        CollectorResult collectResult = dependencyCollector.collectDependencies(session.getProjectBuildingRequest(), getProject().getModel());
        this.getLog().info("Repositories used by this build:");
        for (ArtifactRepository repo : collectResult.getRemoteRepositories()) {
            this.getLog().info(repo.toString());
        }
    } catch (DependencyCollectorException e) {
        throw new MojoExecutionException("Unable to resolve artifacts", e);
    }
}
Also used : CollectorResult(org.apache.maven.shared.dependencies.collect.CollectorResult) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyCollectorException(org.apache.maven.shared.dependencies.collect.DependencyCollectorException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 37 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class TestGetMojo method testParseRepository.

/**
 * Test parsing of the remote repositories parameter
 *
 * @throws Exception in case of errors
 */
public void testParseRepository() throws Exception {
    ArtifactRepository repo;
    ArtifactRepositoryPolicy policy = null;
    repo = mojo.parseRepository("central::default::http://repo1.maven.apache.org/maven2", policy);
    assertEquals("central", repo.getId());
    assertEquals(DefaultRepositoryLayout.class, repo.getLayout().getClass());
    assertEquals("http://repo1.maven.apache.org/maven2", repo.getUrl());
    try {
        repo = mojo.parseRepository("central::legacy::http://repo1.maven.apache.org/maven2", policy);
        fail("Exception expected: legacy repository not supported anymore");
    } catch (MojoFailureException e) {
    }
    repo = mojo.parseRepository("central::::http://repo1.maven.apache.org/maven2", policy);
    assertEquals("central", repo.getId());
    assertEquals(DefaultRepositoryLayout.class, repo.getLayout().getClass());
    assertEquals("http://repo1.maven.apache.org/maven2", repo.getUrl());
    repo = mojo.parseRepository("http://repo1.maven.apache.org/maven2", policy);
    assertEquals("temp", repo.getId());
    assertEquals(DefaultRepositoryLayout.class, repo.getLayout().getClass());
    assertEquals("http://repo1.maven.apache.org/maven2", repo.getUrl());
    try {
        mojo.parseRepository("::::http://repo1.maven.apache.org/maven2", policy);
        fail("Exception expected");
    } catch (MojoFailureException e) {
    // expected
    }
    try {
        mojo.parseRepository("central::http://repo1.maven.apache.org/maven2", policy);
        fail("Exception expected");
    } catch (MojoFailureException e) {
    // expected
    }
}
Also used : ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 38 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class DependencyFilesetsTask method execute.

/**
 * {@inheritDoc}
 */
public void execute() {
    if (this.getProject().getReference(mavenProjectId) == null) {
        throw new BuildException("Maven project reference not found: " + mavenProjectId);
    }
    MavenProject mavenProject = (MavenProject) this.getProject().getReference("maven.project");
    // Add filesets for depenedency artifacts
    Set<Artifact> depArtifacts = filterArtifacts(mavenProject.getArtifacts());
    FileSet dependenciesFileSet = new FileSet();
    dependenciesFileSet.setProject(getProject());
    ArtifactRepository localRepository = (ArtifactRepository) getProject().getReference("maven.local.repository");
    dependenciesFileSet.setDir(new File(localRepository.getBasedir()));
    if (depArtifacts.isEmpty()) {
        // For performance reasons in case of huge local repo, tell Ant to include a single thing, otherwise the
        // whole directory is scanned (even though ** is excluded).
        dependenciesFileSet.createInclude().setName(".");
        dependenciesFileSet.createExclude().setName("**");
    }
    for (Artifact artifact : depArtifacts) {
        String relativeArtifactPath = localRepository.pathOf(artifact);
        dependenciesFileSet.createInclude().setName(relativeArtifactPath);
        String fileSetName = getPrefix() + artifact.getDependencyConflictId();
        FileSet singleArtifactFileSet = new FileSet();
        singleArtifactFileSet.setProject(getProject());
        singleArtifactFileSet.setFile(artifact.getFile());
        getProject().addReference(fileSetName, singleArtifactFileSet);
    }
    getProject().addReference((getPrefix() + projectDependenciesId), dependenciesFileSet);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) FileSet(org.apache.tools.ant.types.FileSet) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 39 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class DefaultRepositoryCopier method scanForArtifactPaths.

protected List<String> scanForArtifactPaths(ArtifactRepository repository) {
    List<String> collected;
    try {
        Wagon wagon = wagonManager.getWagon(repository.getProtocol());
        Repository artifactRepository = new Repository(repository.getId(), repository.getUrl());
        wagon.connect(artifactRepository);
        collected = new ArrayList<String>();
        scan(wagon, "/", collected);
        wagon.disconnect();
        return collected;
    } catch (UnsupportedProtocolException e) {
        throw new RuntimeException(e);
    } catch (ConnectionException e) {
        throw new RuntimeException(e);
    } catch (AuthenticationException e) {
        throw new RuntimeException(e);
    }
}
Also used : Repository(org.apache.maven.wagon.repository.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) UnsupportedProtocolException(org.apache.maven.wagon.UnsupportedProtocolException) Wagon(org.apache.maven.wagon.Wagon) ConnectionException(org.apache.maven.wagon.ConnectionException)

Example 40 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class DeployMojoTest method testAltSnapshotDeploymentRepository.

public void testAltSnapshotDeploymentRepository() throws Exception {
    DeployMojo mojo = spy(new DeployMojo());
    ArtifactRepository repository = mock(ArtifactRepository.class);
    when(mojo.createDeploymentArtifactRepository("altSnapshotDeploymentRepository", "http://localhost")).thenReturn(repository);
    project.setVersion("1.0-SNAPSHOT");
    ProjectDeployerRequest pdr = new ProjectDeployerRequest().setProject(project).setAltDeploymentRepository("altSnapshotDeploymentRepository::http://localhost");
    assertEquals(repository, mojo.getDeploymentRepository(pdr));
}
Also used : ProjectDeployerRequest(org.apache.maven.shared.project.deploy.ProjectDeployerRequest) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Aggregations

ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)108 File (java.io.File)46 Artifact (org.apache.maven.artifact.Artifact)26 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)26 ArrayList (java.util.ArrayList)23 MavenProject (org.apache.maven.project.MavenProject)20 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)17 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 IOException (java.io.IOException)13 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)13 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)11 Properties (java.util.Properties)10 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)9 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)9 Model (org.apache.maven.model.Model)9 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)8 MojoFailureException (org.apache.maven.plugin.MojoFailureException)8 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)8 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)8 MavenProjectResourcesStub (org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub)7