Example usage for org.apache.maven.artifact Artifact getClassifier

List of usage examples for org.apache.maven.artifact Artifact getClassifier

Introduction

In this page you can find the example usage for org.apache.maven.artifact Artifact getClassifier.

Prototype

String getClassifier();

Source Link

Usage

From source file:at.yawk.mdep.AntArtifactMatcher.java

@Override
public boolean matches(Artifact artifact) {
    List<String> parts = Arrays.asList(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
            artifact.getClassifier());
    for (int i = 0; i < this.patterns.size(); i++) {
        if (i > parts.size()) {
            // too specific
            return false;
        }// w w w. j  a  va2s  .  c  o m
        if (!patternMatches(patterns.get(i), parts.get(i))) {
            return false;
        }
    }
    return true;
}

From source file:br.com.anteros.restdoc.maven.plugin.util.ResourceResolver.java

License:Apache License

@SuppressWarnings("unchecked")
private static List<String> resolveAndUnpack(final List<Artifact> artifacts, final SourceResolverConfig config,
        final List<String> validClassifiers, final boolean propagateErrors)
        throws ArtifactResolutionException, ArtifactNotFoundException {
    // NOTE: Since these are '-sources' and '-test-sources' artifacts, they won't actually 
    // resolve transitively...this is just used to aggregate resolution failures into a single 
    // exception.
    final Set<Artifact> artifactSet = new LinkedHashSet<Artifact>(artifacts);
    final Artifact pomArtifact = config.project().getArtifact();
    final ArtifactRepository localRepo = config.localRepository();
    final List<ArtifactRepository> remoteRepos = config.project().getRemoteArtifactRepositories();
    final ArtifactMetadataSource metadataSource = config.artifactMetadataSource();

    final ArtifactFilter filter = config.filter();
    ArtifactFilter resolutionFilter = null;
    if (filter != null) {
        // Wrap the filter in a ProjectArtifactFilter in order to always include the pomArtifact for resolution.
        // NOTE that this is necessary, b/c the -sources artifacts are added dynamically to the pomArtifact
        // and the resolver also checks the dependency trail with the given filter, thus the pomArtifact has
        // to be explicitly included by the filter, otherwise the -sources artifacts won't be resolved.
        resolutionFilter = new ProjectArtifactFilter(pomArtifact, filter);
    }/* w w w  .java 2  s. c om*/

    final ArtifactResolver resolver = config.artifactResolver();

    @SuppressWarnings("rawtypes")
    Map managed = config.project().getManagedVersionMap();

    final ArtifactResolutionResult resolutionResult = resolver.resolveTransitively(artifactSet, pomArtifact,
            managed, localRepo, remoteRepos, metadataSource, resolutionFilter);

    final List<String> result = new ArrayList<String>(artifacts.size());
    for (final Artifact a : (Collection<Artifact>) resolutionResult.getArtifacts()) {
        if (!validClassifiers.contains(a.getClassifier()) || (filter != null && !filter.include(a))) {
            continue;
        }

        final File d = new File(config.outputBasedir(),
                a.getArtifactId() + "-" + a.getVersion() + "-" + a.getClassifier());

        if (!d.exists()) {
            d.mkdirs();
        }

        try {
            final UnArchiver unArchiver = config.archiverManager().getUnArchiver(a.getType());

            unArchiver.setDestDirectory(d);
            unArchiver.setSourceFile(a.getFile());

            unArchiver.extract();

            result.add(d.getAbsolutePath());
        } catch (final NoSuchArchiverException e) {
            if (propagateErrors) {
                throw new ArtifactResolutionException(
                        "Failed to retrieve valid un-archiver component: " + a.getType(), a, e);
            }
        } catch (final ArchiverException e) {
            if (propagateErrors) {
                throw new ArtifactResolutionException("Failed to unpack: " + a.getId(), a, e);
            }
        }
    }

    return result;
}

From source file:br.com.uggeri.maven.builder.mojo.ArtifactUtil.java

public final static String artifactName(Artifact artifact) {
    StringBuilder sb = new StringBuilder();
    sb.append(artifact.getArtifactId()).append('-');
    if (artifact.getVersion().isEmpty()) {
        sb.append(artifact.getBaseVersion());
    } else {//from  ww w.  ja  va2s  .com
        sb.append(artifact.getVersion());
    }
    if (artifact.hasClassifier()) {
        sb.append('-').append(artifact.getClassifier());
    }
    sb.append('.').append(artifact.getType());
    return sb.toString();
}

From source file:br.com.uggeri.maven.builder.mojo.ArtifactUtil.java

public final static String artifactPomName(Artifact artifact) {
    StringBuilder sb = new StringBuilder();
    sb.append(artifact.getArtifactId()).append('-');
    if (artifact.getVersion().isEmpty()) {
        sb.append(artifact.getBaseVersion());
    } else {//  w w  w  .  ja  va2s . c  om
        sb.append(artifact.getVersion());
    }
    if (artifact.hasClassifier()) {
        sb.append('-').append(artifact.getClassifier());
    }
    sb.append(".pom");
    return sb.toString();
}

From source file:br.com.uggeri.maven.builder.mojo.ArtifactUtil.java

static boolean areEqual(Artifact a, Dependency d) {
    return a.getGroupId().equals(d.getGroupId()) && a.getArtifactId().equals(d.getArtifactId())
            && a.getVersion().equals(d.getVersion()) && a.getType().equals(d.getType())
            && ((a.getClassifier() == null && d.getClassifier() == null)
                    || a.getClassifier().equals(d.getClassifier()));
}

From source file:ch.sourcepond.maven.plugin.repobuilder.TargetPathFactory.java

License:Apache License

/**
 * @param pArtifact/*from   w  w w  .  ja v  a2  s  .  c o  m*/
 * @return
 */
private String toArtifactFileName(final Artifact pArtifact) {
    final StringBuilder b = new StringBuilder(pArtifact.getArtifactId()).append("-")
            .append(pArtifact.getBaseVersion());
    if (!isBlank(pArtifact.getClassifier())) {
        b.append("-").append(pArtifact.getClassifier());
    }

    return b.append(".").append(pArtifact.getArtifactHandler().getExtension()).toString();
}

From source file:cn.wanghaomiao.maven.plugin.seimi.overlay.DefaultOverlay.java

License:Apache License

/**
 * Creates an overlay for the specified artifact.
 *
 * @param a the artifact//from w ww  . j  a v a 2 s.  co m
 */
public DefaultOverlay(Artifact a) {
    super();
    setGroupId(a.getGroupId());
    setArtifactId(a.getArtifactId());
    setClassifier(a.getClassifier());
    setArtifact(a);
    setType(a.getType());
}

From source file:cn.wanghaomiao.maven.plugin.seimi.overlay.OverlayManager.java

License:Apache License

/**
 * Compare groupId && artifactId && type && classifier.
 *
 * @param overlay the overlay/*  www  . j ava  2s  . c  om*/
 * @param artifact the artifact
 * @return boolean true if equals
 */
private boolean compareOverlayWithArtifact(Overlay overlay, Artifact artifact) {
    return (StringUtils.equals(overlay.getGroupId(), artifact.getGroupId())
            && StringUtils.equals(overlay.getArtifactId(), artifact.getArtifactId())
            && StringUtils.equals(overlay.getType(), artifact.getType())
            // MWAR-241 Make sure to treat null and "" as equal when comparing the classifier
            && StringUtils.equals(StringUtils.defaultString(overlay.getClassifier()),
                    StringUtils.defaultString(artifact.getClassifier())));
}

From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.AbstractWarPackagingTask.java

License:Apache License

/**
 * Returns the final name of the specified artifact.
 * <p/>//from  w  w  w .j  a  v  a 2 s  .c o  m
 * If the <tt>outputFileNameMapping</tt> is set, it is used, otherwise the standard naming scheme is used.
 *
 * @param context the packaging context
 * @param artifact the artifact
 * @return the converted filename of the artifact
 * @throws InterpolationException in case of interpolation problem.
 */
protected String getArtifactFinalName(WarPackagingContext context, Artifact artifact)
        throws InterpolationException {
    if (context.getOutputFileNameMapping() != null) {
        return MappingUtils.evaluateFileNameMapping(context.getOutputFileNameMapping(), artifact);
    }

    String classifier = artifact.getClassifier();
    if ((classifier != null) && !("".equals(classifier.trim()))) {
        return MappingUtils.evaluateFileNameMapping(MappingUtils.DEFAULT_FILE_NAME_MAPPING_CLASSIFIER,
                artifact);
    } else {
        return MappingUtils.evaluateFileNameMapping(MappingUtils.DEFAULT_FILE_NAME_MAPPING, artifact);
    }

}

From source file:cn.wanghaomiao.maven.plugin.seimi.util.WarUtils.java

License:Apache License

/**
 * @param project {@link MavenProject}/*from   ww  w .  j  a  va 2s .  com*/
 * @param dependency {@link Dependency}
 * @return {@link Artifact}
 */
public static Artifact getArtifact(MavenProject project, Dependency dependency) {
    for (Object o : project.getArtifacts()) {
        Artifact artifact = (Artifact) o;
        if (artifact.getGroupId().equals(dependency.getGroupId())
                && artifact.getArtifactId().equals(dependency.getArtifactId())
                && artifact.getType().equals(dependency.getType())) {
            if (artifact.getClassifier() == null && dependency.getClassifier() == null) {
                return artifact;
            } else if (dependency.getClassifier() != null
                    && dependency.getClassifier().equals(artifact.getClassifier())) {
                return artifact;
            }
        }
    }
    return null;
}