Java Code Examples for org.apache.maven.artifact.Artifact#getArtifactHandler()

The following examples show how to use org.apache.maven.artifact.Artifact#getArtifactHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlatRepositoryLayout.java    From appassembler with MIT License 6 votes vote down vote up
public String pathOf( Artifact artifact )
{
    ArtifactHandler artifactHandler = artifact.getArtifactHandler();

    StringBuilder path = new StringBuilder();

    path.append( artifact.getArtifactId() ).append( ARTIFACT_SEPARATOR ).append( artifact.getVersion() );

    if ( artifact.hasClassifier() )
    {
        path.append( ARTIFACT_SEPARATOR ).append( artifact.getClassifier() );
    }

    if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 )
    {
        path.append( GROUP_SEPARATOR ).append( artifactHandler.getExtension() );
    }

    return path.toString();
}
 
Example 2
Source File: AbstractMavenEventHandler.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
public Xpp3Dom newElement(@Nonnull String name, @Nullable Artifact artifact) {
    Xpp3Dom element = new Xpp3Dom(name);
    if (artifact == null) {
        return element;
    }

    element.setAttribute("groupId", artifact.getGroupId());
    element.setAttribute("artifactId", artifact.getArtifactId());
    element.setAttribute("baseVersion", artifact.getBaseVersion());
    element.setAttribute("version", artifact.getVersion());
    element.setAttribute("snapshot", String.valueOf(artifact.isSnapshot()));
    if (artifact.getClassifier() != null) {
        element.setAttribute("classifier", artifact.getClassifier());
    }
    element.setAttribute("type", artifact.getType());
    element.setAttribute("id", artifact.getId());

    ArtifactHandler artifactHandler = artifact.getArtifactHandler();
    String extension;
    if (artifactHandler == null) {
        extension = artifact.getType();
    } else {
        extension = artifactHandler.getExtension();
    }
    element.setAttribute("extension", extension);

    return element;
}
 
Example 3
Source File: ArtifactUtils.java    From appassembler with MIT License 5 votes vote down vote up
/**
 * get relative path the copied artifact using base version. This is mainly use to SNAPSHOT instead of timestamp in
 * the file name
 *
 * @param artifactRepositoryLayout {@link ArtifactRepositoryLayout}
 * @param artifact {@link Artifact}
 * @return The base version.
 */
public static String pathBaseVersionOf( ArtifactRepositoryLayout artifactRepositoryLayout, Artifact artifact )
{
    ArtifactHandler artifactHandler = artifact.getArtifactHandler();

    StringBuilder fileName = new StringBuilder();

    fileName.append( artifact.getArtifactId() ).append( "-" ).append( artifact.getBaseVersion() );

    if ( artifact.hasClassifier() )
    {
        fileName.append( "-" ).append( artifact.getClassifier() );
    }

    if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 )
    {
        fileName.append( "." ).append( artifactHandler.getExtension() );
    }

    String relativePath = artifactRepositoryLayout.pathOf( artifact );
    String[] tokens = StringUtils.split( relativePath, "/" );
    tokens[tokens.length - 1] = fileName.toString();

    StringBuilder path = new StringBuilder();

    for ( int i = 0; i < tokens.length; ++i )
    {

        path.append( tokens[i] );
        if ( i != tokens.length - 1 )
        {
            path.append( "/" );
        }
    }

    return path.toString();

}
 
Example 4
Source File: NativeLinkMojo.java    From maven-native with MIT License 4 votes vote down vote up
/**
 *
 */
private void attachPrimaryArtifact()
{
    Artifact artifact = this.project.getArtifact();

    if ( null == this.classifier )
    {
        artifact.setFile( new File( this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "."
                + this.project.getArtifact().getArtifactHandler().getExtension() ) );
    }
    else
    {
        // install primary artifact as a classifier

        DefaultArtifact clone = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
                artifact.getVersionRange().cloneOf(), artifact.getScope(), artifact.getType(), classifier,
                artifact.getArtifactHandler(), artifact.isOptional() );

        clone.setRelease( artifact.isRelease() );
        clone.setResolvedVersion( artifact.getVersion() );
        clone.setResolved( artifact.isResolved() );
        clone.setFile( artifact.getFile() );

        if ( artifact.getAvailableVersions() != null )
        {
            clone.setAvailableVersions( new ArrayList<>( artifact.getAvailableVersions() ) );
        }

        clone.setBaseVersion( artifact.getBaseVersion() );
        clone.setDependencyFilter( artifact.getDependencyFilter() );

        if ( artifact.getDependencyTrail() != null )
        {
            clone.setDependencyTrail( new ArrayList<>( artifact.getDependencyTrail() ) );
        }

        clone.setDownloadUrl( artifact.getDownloadUrl() );
        clone.setRepository( artifact.getRepository() );

        clone.setFile( new File( this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "."
                + this.project.getArtifact().getArtifactHandler().getExtension() ) );

        project.setArtifact( clone );
    }
}
 
Example 5
Source File: ScopeFilter.java    From sundrio with Apache License 2.0 4 votes vote down vote up
public Artifact apply(Artifact artifact) {
    return artifact == null ? null : new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() != null ? artifact.getScope() : Artifact.SCOPE_COMPILE, artifact.getType(), artifact.getClassifier(), artifact.getArtifactHandler());
}
 
Example 6
Source File: NarProvidedDependenciesMojo.java    From nifi-maven with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new ArtifactHandler for the specified Artifact that overrides the includeDependencies flag. When set, this flag prevents transitive
 * dependencies from being printed in dependencies plugin.
 *
 * @param artifact  The artifact
 * @return          The handler for the artifact
 */
private ArtifactHandler excludesDependencies(final Artifact artifact) {
    final ArtifactHandler orig = artifact.getArtifactHandler();

    return new ArtifactHandler() {
        @Override
        public String getExtension() {
            return orig.getExtension();
        }

        @Override
        public String getDirectory() {
            return orig.getDirectory();
        }

        @Override
        public String getClassifier() {
            return orig.getClassifier();
        }

        @Override
        public String getPackaging() {
            return orig.getPackaging();
        }

        // mark dependencies has excluded so they will appear in tree listing
        @Override
        public boolean isIncludesDependencies() {
            return false;
        }

        @Override
        public String getLanguage() {
            return orig.getLanguage();
        }

        @Override
        public boolean isAddedToClasspath() {
            return orig.isAddedToClasspath();
        }
    };
}
 
Example 7
Source File: AscArtifactHandler.java    From pgpverify-maven-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Initializes a new ASC Artifact Handler for the provided artifact.
 *
 * @param targetArtifact
 *   The artifact for which a GPG signature artifact is desired.
 */
AscArtifactHandler(Artifact targetArtifact) {
    this(targetArtifact.getArtifactHandler());
}