Search in sources :

Example 96 with ArtifactRepository

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

the class TestCopyDependenciesMojo2 method testRepositoryLayout.

public void testRepositoryLayout() throws Exception {
    String baseVersion = "2.0-SNAPSHOT";
    String groupId = "testGroupId";
    String artifactId = "expanded-snapshot";
    Artifact expandedSnapshot = createExpandedVersionArtifact(baseVersion, groupId, artifactId, "compile", "jar", null);
    mojo.getProject().getArtifacts().add(expandedSnapshot);
    mojo.getProject().getDependencyArtifacts().add(expandedSnapshot);
    Artifact pomExpandedSnapshot = createExpandedVersionArtifact(baseVersion, groupId, artifactId, "compile", "pom", null);
    mojo.getProject().getArtifacts().add(pomExpandedSnapshot);
    mojo.getProject().getDependencyArtifacts().add(pomExpandedSnapshot);
    mojo.useRepositoryLayout = true;
    mojo.execute();
    ArtifactFactory artifactFactory = lookup(ArtifactFactory.class);
    File outputDirectory = mojo.outputDirectory;
    ArtifactRepository targetRepository = new MavenArtifactRepository("local", outputDirectory.toURL().toExternalForm(), new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
    Set<Artifact> artifacts = mojo.getProject().getArtifacts();
    for (Artifact artifact : artifacts) {
        assertArtifactExists(artifact, targetRepository);
        if (!artifact.getBaseVersion().equals(artifact.getVersion())) {
            Artifact baseArtifact = artifactFactory.createArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getScope(), artifact.getType());
            assertArtifactExists(baseArtifact, targetRepository);
        }
    }
}
Also used : ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 97 with ArtifactRepository

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

the class DeployMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    boolean addedDeployRequest = false;
    if (skip) {
        getLog().info("Skipping artifact deployment");
    } else {
        failIfOffline();
        // CHECKSTYLE_OFF: LineLength
        // @formatter:off
        ProjectDeployerRequest pdr = new ProjectDeployerRequest().setProject(project).setUpdateReleaseInfo(isUpdateReleaseInfo()).setRetryFailedDeploymentCount(getRetryFailedDeploymentCount()).setAltReleaseDeploymentRepository(altReleaseDeploymentRepository).setAltSnapshotDeploymentRepository(altSnapshotDeploymentRepository).setAltDeploymentRepository(altDeploymentRepository);
        // @formatter:on
        // CHECKSTYLE_ON: LineLength
        ArtifactRepository repo = getDeploymentRepository(pdr);
        if (!deployAtEnd) {
            deployProject(getSession().getProjectBuildingRequest(), pdr, repo);
        } else {
            DEPLOYREQUESTS.add(pdr);
            addedDeployRequest = true;
        }
    }
    boolean projectsReady = READYPROJECTSCOUNTER.incrementAndGet() == reactorProjects.size();
    if (projectsReady) {
        synchronized (DEPLOYREQUESTS) {
            while (!DEPLOYREQUESTS.isEmpty()) {
                ArtifactRepository repo = getDeploymentRepository(DEPLOYREQUESTS.get(0));
                deployProject(getSession().getProjectBuildingRequest(), DEPLOYREQUESTS.remove(0), repo);
            }
        }
    } else if (addedDeployRequest) {
        getLog().info("Deploying " + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + " at end");
    }
}
Also used : ProjectDeployerRequest(org.apache.maven.shared.project.deploy.ProjectDeployerRequest) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 98 with ArtifactRepository

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

the class SignAndDeployFileMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    AbstractGpgSigner signer = newSigner(null);
    signer.setOutputDirectory(ascDirectory);
    signer.setBaseDirectory(new File("").getAbsoluteFile());
    if (offline) {
        throw new MojoFailureException("Cannot deploy artifacts when Maven is in offline mode");
    }
    initProperties();
    validateArtifactInformation();
    if (!file.exists()) {
        throw new MojoFailureException(file.getPath() + " not found.");
    }
    ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get(repositoryLayout);
    if (layout == null) {
        throw new MojoFailureException("Invalid repository layout: " + repositoryLayout);
    }
    ArtifactRepository deploymentRepository = repositoryFactory.createDeploymentArtifactRepository(repositoryId, url, layout, uniqueVersion);
    if (StringUtils.isEmpty(deploymentRepository.getProtocol())) {
        throw new MojoFailureException("No transfer protocol found.");
    }
    Artifact artifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier);
    if (file.equals(getLocalRepoFile(artifact))) {
        throw new MojoFailureException("Cannot deploy artifact from the local repository: " + file);
    }
    File fileSig = signer.generateSignatureForArtifact(file);
    ArtifactMetadata metadata = new AscArtifactMetadata(artifact, fileSig, false);
    artifact.addMetadata(metadata);
    if (!"pom".equals(packaging)) {
        if (pomFile == null && generatePom) {
            pomFile = generatePomFile();
        }
        if (pomFile != null) {
            metadata = new ProjectArtifactMetadata(artifact, pomFile);
            artifact.addMetadata(metadata);
            fileSig = signer.generateSignatureForArtifact(pomFile);
            metadata = new AscArtifactMetadata(artifact, fileSig, true);
            artifact.addMetadata(metadata);
        }
    }
    if (updateReleaseInfo) {
        artifact.setRelease(true);
    }
    project.setArtifact(artifact);
    try {
        deploy(file, artifact, deploymentRepository, localRepository);
    } catch (ArtifactDeploymentException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    if (sources != null) {
        projectHelper.attachArtifact(project, "jar", "sources", sources);
    }
    if (javadoc != null) {
        projectHelper.attachArtifact(project, "jar", "javadoc", javadoc);
    }
    if (files != null) {
        if (types == null) {
            throw new MojoExecutionException("You must specify 'types' if you specify 'files'");
        }
        if (classifiers == null) {
            throw new MojoExecutionException("You must specify 'classifiers' if you specify 'files'");
        }
        int filesLength = StringUtils.countMatches(files, ",");
        int typesLength = StringUtils.countMatches(types, ",");
        int classifiersLength = StringUtils.countMatches(classifiers, ",");
        if (typesLength != filesLength) {
            throw new MojoExecutionException("You must specify the same number of entries in 'files' and " + "'types' (respectively " + filesLength + " and " + typesLength + " entries )");
        }
        if (classifiersLength != filesLength) {
            throw new MojoExecutionException("You must specify the same number of entries in 'files' and " + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )");
        }
        int fi = 0;
        int ti = 0;
        int ci = 0;
        for (int i = 0; i <= filesLength; i++) {
            int nfi = files.indexOf(',', fi);
            if (nfi == -1) {
                nfi = files.length();
            }
            int nti = types.indexOf(',', ti);
            if (nti == -1) {
                nti = types.length();
            }
            int nci = classifiers.indexOf(',', ci);
            if (nci == -1) {
                nci = classifiers.length();
            }
            File file = new File(files.substring(fi, nfi));
            if (!file.isFile()) {
                // try relative to the project basedir just in case
                file = new File(project.getBasedir(), files.substring(fi, nfi));
            }
            if (file.isFile()) {
                if (StringUtils.isWhitespace(classifiers.substring(ci, nci))) {
                    projectHelper.attachArtifact(project, types.substring(ti, nti).trim(), file);
                } else {
                    projectHelper.attachArtifact(project, types.substring(ti, nti).trim(), classifiers.substring(ci, nci).trim(), file);
                }
            } else {
                throw new MojoExecutionException("Specified side artifact " + file + " does not exist");
            }
            fi = nfi + 1;
            ti = nti + 1;
            ci = nci + 1;
        }
    } else {
        if (types != null) {
            throw new MojoExecutionException("You must specify 'files' if you specify 'types'");
        }
        if (classifiers != null) {
            throw new MojoExecutionException("You must specify 'files' if you specify 'classifiers'");
        }
    }
    List attachedArtifacts = project.getAttachedArtifacts();
    for (Object attachedArtifact : attachedArtifacts) {
        Artifact attached = (Artifact) attachedArtifact;
        fileSig = signer.generateSignatureForArtifact(attached.getFile());
        attached = new AttachedSignedArtifact(attached, new AscArtifactMetadata(attached, fileSig, false));
        try {
            deploy(attached.getFile(), attached, deploymentRepository, localRepository);
        } catch (ArtifactDeploymentException e) {
            throw new MojoExecutionException("Error deploying attached artifact " + attached.getFile() + ": " + e.getMessage(), e);
        }
    }
}
Also used : ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) ProjectArtifactMetadata(org.apache.maven.project.artifact.ProjectArtifactMetadata) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactDeploymentException(org.apache.maven.artifact.deployer.ArtifactDeploymentException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact) List(java.util.List) File(java.io.File) ArtifactMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) ProjectArtifactMetadata(org.apache.maven.project.artifact.ProjectArtifactMetadata)

Example 99 with ArtifactRepository

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

the class ProcessRemoteResourcesMojo method getProjects.

@SuppressWarnings("unchecked")
protected List<MavenProject> getProjects() throws MojoExecutionException {
    List<MavenProject> projects = new ArrayList<MavenProject>();
    // add filters in well known order, least specific to most specific
    FilterArtifacts filter = new FilterArtifacts();
    Set<Artifact> artifacts = resolveProjectArtifacts();
    if (this.excludeTransitive) {
        Set<Artifact> depArtifacts;
        if (runOnlyAtExecutionRoot) {
            depArtifacts = aggregateProjectDependencyArtifacts();
        } else {
            depArtifacts = project.getDependencyArtifacts();
        }
        filter.addFilter(new ProjectTransitivityFilter(depArtifacts, true));
    }
    filter.addFilter(new ScopeFilter(this.includeScope, this.excludeScope));
    filter.addFilter(new GroupIdFilter(this.includeGroupIds, this.excludeGroupIds));
    filter.addFilter(new ArtifactIdFilter(this.includeArtifactIds, this.excludeArtifactIds));
    // perform filtering
    try {
        artifacts = filter.filter(artifacts);
    } catch (ArtifactFilterException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    for (Artifact artifact : artifacts) {
        try {
            List<ArtifactRepository> remoteRepo = remoteArtifactRepositories;
            if (artifact.isSnapshot()) {
                VersionRange rng = VersionRange.createFromVersion(artifact.getBaseVersion());
                artifact = artifactFactory.createDependencyArtifact(artifact.getGroupId(), artifact.getArtifactId(), rng, artifact.getType(), artifact.getClassifier(), artifact.getScope(), null, artifact.isOptional());
            }
            getLog().debug("Building project for " + artifact);
            MavenProject p;
            try {
                p = mavenProjectBuilder.buildFromRepository(artifact, remoteRepo, localRepository);
            } catch (InvalidProjectModelException e) {
                getLog().warn("Invalid project model for artifact [" + artifact.getArtifactId() + ":" + artifact.getGroupId() + ":" + artifact.getVersion() + "]. " + "It will be ignored by the remote resources Mojo.");
                continue;
            }
            String supplementKey = generateSupplementMapKey(p.getModel().getGroupId(), p.getModel().getArtifactId());
            if (supplementModels.containsKey(supplementKey)) {
                Model mergedModel = mergeModels(p.getModel(), supplementModels.get(supplementKey));
                MavenProject mergedProject = new MavenProject(mergedModel);
                projects.add(mergedProject);
                mergedProject.setArtifact(artifact);
                mergedProject.setVersion(artifact.getVersion());
                getLog().debug("Adding project with groupId [" + mergedProject.getGroupId() + "] (supplemented)");
            } else {
                projects.add(p);
                getLog().debug("Adding project with groupId [" + p.getGroupId() + "]");
            }
        } catch (ProjectBuildingException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    Collections.sort(projects, new ProjectComparator());
    return projects;
}
Also used : InvalidProjectModelException(org.apache.maven.project.InvalidProjectModelException) ArtifactIdFilter(org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) ProjectTransitivityFilter(org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) ScopeFilter(org.apache.maven.shared.artifact.filter.collection.ScopeFilter) MavenProject(org.apache.maven.project.MavenProject) FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) Model(org.apache.maven.model.Model) GroupIdFilter(org.apache.maven.shared.artifact.filter.collection.GroupIdFilter)

Example 100 with ArtifactRepository

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

the class RemoteResourcesMojoTest method testFilteredBundles.

public void testFilteredBundles() throws Exception {
    final MavenProjectResourcesStub project = createTestProject("default-filterbundles");
    final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithSettings(project, new String[] { "test:test:1.1" });
    setupDefaultProject(project);
    ArtifactRepository repo = (ArtifactRepository) getVariableValueFromObject(mojo, "localRepository");
    String path = repo.pathOf(new DefaultArtifact("test", "test", VersionRange.createFromVersion("1.1"), null, "jar", "", new DefaultArtifactHandler()));
    File file = new File(repo.getBasedir() + "/" + path + ".jar");
    file.getParentFile().mkdirs();
    buildResourceBundle("default-filterbundles-create", null, new String[] { "FILTER.txt.vm" }, file);
    mojo.execute();
    // executing a second time (example: forked lifecycle) should still work
    mojo.execute();
    file = (File) getVariableValueFromObject(mojo, "outputDirectory");
    file = new File(file, "FILTER.txt");
    assertTrue(file.exists());
    String data = FileUtils.fileRead(file);
    assertTrue(data.contains("2007"));
    assertTrue(data.contains("default-filterbundles"));
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

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