Search in sources :

Example 6 with ArtifactCoordinate

use of org.apache.maven.shared.artifact.ArtifactCoordinate in project maven-plugins by apache.

the class TestClassifierTypeTranslator method doTestNullEmptyClassifier.

public void doTestNullEmptyClassifier(String classifier) {
    String type = "zip";
    ArtifactTranslator at = new ClassifierTypeTranslator(artifactHandlerManager, classifier, type);
    Set<ArtifactCoordinate> results = at.translate(artifacts, log);
    for (Artifact artifact : artifacts) {
        Iterator<ArtifactCoordinate> resultIter = results.iterator();
        boolean found = false;
        while (resultIter.hasNext()) {
            ArtifactCoordinate translatedArtifact = resultIter.next();
            if (artifact.getArtifactId().equals(translatedArtifact.getArtifactId()) && artifact.getGroupId().equals(translatedArtifact.getGroupId())) /*&& artifact.getScope().equals(translatedArtifact.getScope())*/
            {
                // classifier is null, should be the same as the artifact
                assertEquals(artifact.getClassifier(), translatedArtifact.getClassifier());
                assertEquals(type, translatedArtifact.getExtension());
                found = true;
                break;
            }
        }
        assertTrue(found);
    }
}
Also used : ArtifactCoordinate(org.apache.maven.shared.artifact.ArtifactCoordinate) Artifact(org.apache.maven.artifact.Artifact)

Example 7 with ArtifactCoordinate

use of org.apache.maven.shared.artifact.ArtifactCoordinate in project maven-plugins by apache.

the class AbstractHelpMojo method getMavenProject.

/**
     * Retrieves the Maven Project associated with the given artifact String, in the form of
     * <code>groupId:artifactId[:version]</code>. This resolves the POM artifact at those coordinates and then builds
     * the Maven project from it.
     * 
     * @param artifactString Coordinates of the Maven project to get.
     * @return New Maven project.
     * @throws MojoExecutionException If there was an error while getting the Maven project.
     */
protected MavenProject getMavenProject(String artifactString) throws MojoExecutionException {
    ArtifactCoordinate coordinate = getArtifactCoordinate(artifactString, "pom");
    try {
        ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        pbr.setRemoteRepositories(remoteRepositories);
        pbr.setProject(null);
        pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
        pbr.setResolveDependencies(true);
        Artifact artifact = artifactResolver.resolveArtifact(pbr, coordinate).getArtifact();
        return projectBuilder.build(artifact.getFile(), pbr).getProject();
    } catch (Exception e) {
        throw new MojoExecutionException("Unable to get the POM for the artifact '" + artifactString + "'. Verify the artifact parameter.", e);
    }
}
Also used : ArtifactCoordinate(org.apache.maven.shared.artifact.ArtifactCoordinate) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) Artifact(org.apache.maven.artifact.Artifact) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 8 with ArtifactCoordinate

use of org.apache.maven.shared.artifact.ArtifactCoordinate in project maven-plugins by apache.

the class AbstractDependencyFilterMojo method getClassifierTranslatedDependencies.

/**
     * Transform artifacts
     *
     * @param artifacts
     * @param stopOnFailure
     * @return DependencyStatusSets - Bean of TreeSets that contains information
     *         on the projects dependencies
     * @throws MojoExecutionException
     */
protected DependencyStatusSets getClassifierTranslatedDependencies(Set<Artifact> artifacts, boolean stopOnFailure) throws MojoExecutionException {
    Set<Artifact> unResolvedArtifacts = new LinkedHashSet<Artifact>();
    Set<Artifact> resolvedArtifacts = artifacts;
    DependencyStatusSets status = new DependencyStatusSets();
    // if this did something, we need to resolve the new artifacts
    if (StringUtils.isNotEmpty(classifier)) {
        ArtifactTranslator translator = new ClassifierTypeTranslator(artifactHandlerManager, this.classifier, this.type);
        Collection<ArtifactCoordinate> coordinates = translator.translate(artifacts, getLog());
        status = filterMarkedDependencies(artifacts);
        // the unskipped artifacts are in the resolved set.
        artifacts = status.getResolvedDependencies();
        // resolve the rest of the artifacts
        resolvedArtifacts = resolve(new LinkedHashSet<ArtifactCoordinate>(coordinates), stopOnFailure);
        // calculate the artifacts not resolved.
        unResolvedArtifacts.addAll(artifacts);
        unResolvedArtifacts.removeAll(resolvedArtifacts);
    }
    // return a bean of all 3 sets.
    status.setResolvedDependencies(resolvedArtifacts);
    status.setUnResolvedDependencies(unResolvedArtifacts);
    return status;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactTranslator(org.apache.maven.plugins.dependency.utils.translators.ArtifactTranslator) ArtifactCoordinate(org.apache.maven.shared.artifact.ArtifactCoordinate) ClassifierTypeTranslator(org.apache.maven.plugins.dependency.utils.translators.ClassifierTypeTranslator) DependencyStatusSets(org.apache.maven.plugins.dependency.utils.DependencyStatusSets) Artifact(org.apache.maven.artifact.Artifact)

Example 9 with ArtifactCoordinate

use of org.apache.maven.shared.artifact.ArtifactCoordinate in project maven-plugins by apache.

the class ClassifierTypeTranslator method translate.

/*
     * (non-Javadoc)
     *
     * @see org.apache.mojo.dependency.utils.translators.ArtifactTranslator#translate(java.util.Set,
     *      org.apache.maven.plugin.logging.Log)
     */
@Override
public Set<ArtifactCoordinate> translate(Set<Artifact> artifacts, Log log) {
    Set<ArtifactCoordinate> results;
    log.debug("Translating Artifacts using Classifier: " + this.classifier + " and Type: " + this.type);
    results = new LinkedHashSet<ArtifactCoordinate>();
    for (Artifact artifact : artifacts) {
        // this translator must pass both type and classifier here so we
        // will use the
        // base artifact value if null comes in
        final String useType;
        if (StringUtils.isNotEmpty(this.type)) {
            useType = this.type;
        } else {
            useType = artifact.getType();
        }
        ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(useType);
        final String extension;
        if (artifactHandler != null) {
            extension = artifactHandler.getExtension();
        } else {
            extension = this.type;
        }
        String useClassifier;
        if (StringUtils.isNotEmpty(this.classifier)) {
            useClassifier = this.classifier;
        } else {
            useClassifier = artifact.getClassifier();
        }
        DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
        coordinate.setGroupId(artifact.getGroupId());
        coordinate.setArtifactId(artifact.getArtifactId());
        coordinate.setVersion(artifact.getVersion());
        coordinate.setClassifier(useClassifier);
        coordinate.setExtension(extension);
        //            // Create a new artifact
        //            Artifact newArtifact = factory.createArtifactWithClassifier( artifact.getGroupId(), artifact
        //                .getArtifactId(), artifact.getVersion(), useType, useClassifier );
        //
        //            // note the new artifacts will always have the scope set to null. We
        //            // should
        //            // reset it here so that it will pass other filters if needed
        //            newArtifact.setScope( artifact.getScope() );
        //
        //            if ( Artifact.SCOPE_SYSTEM.equals( newArtifact.getScope() ) )
        //            {
        //                File baseDir = repositoryManager.getLocalRepositoryBasedir( buildingRequest );
        //                String path = repositoryManager.getPathForLocalArtifact( buildingRequest, newArtifact );
        //                newArtifact.setFile( new File( baseDir, path ) );
        //            }
        results.add(coordinate);
    }
    return results;
}
Also used : ArtifactCoordinate(org.apache.maven.shared.artifact.ArtifactCoordinate) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) Artifact(org.apache.maven.artifact.Artifact)

Example 10 with ArtifactCoordinate

use of org.apache.maven.shared.artifact.ArtifactCoordinate in project maven-plugins by apache.

the class TestClassifierTypeTranslator method doTestNullEmptyType.

public void doTestNullEmptyType(String type) {
    String classifier = "jdk5";
    ArtifactTranslator at = new ClassifierTypeTranslator(artifactHandlerManager, classifier, type);
    Set<ArtifactCoordinate> results = at.translate(artifacts, log);
    for (Artifact artifact : artifacts) {
        Iterator<ArtifactCoordinate> resultIter = results.iterator();
        boolean found = false;
        while (!found && resultIter.hasNext()) {
            ArtifactCoordinate translatedArtifact = resultIter.next();
            if (artifact.getArtifactId() == translatedArtifact.getArtifactId() && artifact.getGroupId() == translatedArtifact.getGroupId()) /*&& artifact.getScope() == translatedArtifact.getScope()*/
            {
                // classifier is null, should be the same as the artifact
                assertEquals(classifier, translatedArtifact.getClassifier());
                assertEquals(artifact.getType(), translatedArtifact.getExtension());
                found = true;
                break;
            }
        }
        assertTrue(found);
    }
}
Also used : ArtifactCoordinate(org.apache.maven.shared.artifact.ArtifactCoordinate) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactCoordinate (org.apache.maven.shared.artifact.ArtifactCoordinate)10 Artifact (org.apache.maven.artifact.Artifact)9 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)3 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)2 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)2 DefaultArtifactCoordinate (org.apache.maven.shared.artifact.DefaultArtifactCoordinate)2 File (java.io.File)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 MavenSession (org.apache.maven.execution.MavenSession)1 Dependency (org.apache.maven.model.Dependency)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)1