Example usage for org.apache.maven.repository.metadata ArtifactMetadata getClassifier

List of usage examples for org.apache.maven.repository.metadata ArtifactMetadata getClassifier

Introduction

In this page you can find the example usage for org.apache.maven.repository.metadata ArtifactMetadata getClassifier.

Prototype

public String getClassifier() 

Source Link

Usage

From source file:org.ebayopensource.turmeric.eclipse.mavenapi.impl.AbstractMavenApi.java

License:Open Source License

/**
 * Resolve an artifact using a particular maven implementation and repository.
 *
 * @param embedder the embedded version of maven to use
 * @param repoSystem the repository to resolve against
 * @param md the artifact metadata to search
 * @return the resolved artifact/*from   www . ja v  a  2s  .  c o  m*/
 * @throws MavenEclipseApiException the maven eclipse api exception
 */
public Artifact resolveArtifact(MavenImpl embedder, RepositorySystem repoSystem, ArtifactMetadata md)
        throws MavenEclipseApiException {
    if (embedder == null)
        throw new MavenEclipseApiException();

    try {
        List<ArtifactRepository> repos = _getKnownRepositories(embedder, md.getType());
        if (repos == null || repos.size() < 1) {
            throw new MavenEclipseApiException(Messages.ERROR_NO_REPOSITORIES);
        }

        Artifact artifact = null;

        if (md.getClassifier() == null)
            artifact = repoSystem.createArtifact(md.getGroupId(), md.getArtifactId(), md.getVersion(),
                    md.getScope(), md.getType());
        else
            artifact = repoSystem.createArtifactWithClassifier(md.getGroupId(), md.getArtifactId(),
                    md.getVersion(), md.getType(), md.getClassifier());

        if (artifact == null) {
            throw new MavenEclipseApiException(Messages.ERROR_NULL_ARTIFACT);
        }

        // embedder.resolve(artifact, repos, embedder.getLocalRepository());
        MavenApiUtil.resolveArtifact(repoSystem, artifact, embedder.getLocalRepository(), repos);

        return artifact;
    } catch (Exception e) {
        e.printStackTrace();
        throw new MavenEclipseApiException(e);
    }
}

From source file:org.ebayopensource.turmeric.eclipse.mavenapi.impl.AbstractMavenEclipseApi.java

License:Open Source License

/**
 * Create an artifact given the metadata.  This populates it into the repository.
 *
 * @param metadata the artifact metadata to use.
 * @return the created artifact./*from ww w .j a  v  a2  s . c o  m*/
 * @throws MavenEclipseApiException the maven eclipse api exception
 */
public Artifact createArtifact(final ArtifactMetadata metadata) throws MavenEclipseApiException {
    RepositorySystem res = MavenApiHelper.getRepositorySystem();
    if (metadata.getClassifier() == null)
        return res.createArtifact(metadata.getGroupId(), metadata.getArtifactId(), metadata.getVersion(),
                metadata.getScope(), metadata.getType());
    return res.createArtifactWithClassifier(metadata.getGroupId(), metadata.getArtifactId(),
            metadata.getVersion(), metadata.getType(), metadata.getClassifier());
}

From source file:org.ebayopensource.turmeric.eclipse.mavenapi.impl.MavenEclipseUtil.java

License:Open Source License

/**
 * Artifact.//w  w w.  j a  v  a 2 s  . c om
 *
 * @param metadata the metadata
 * @return the artifact
 * @throws MavenEclipseApiException the maven eclipse api exception
 */
public static Artifact artifact(final ArtifactMetadata metadata) throws MavenEclipseApiException {
    if (metadata == null)
        return null;
    if (isNotBlank(metadata.getScope()))
        return MavenApiHelper.getRepositorySystem().createArtifact(metadata.getGroupId(),
                metadata.getArtifactId(), metadata.getVersion(), metadata.getScope(), metadata.getType());
    return MavenApiHelper.getRepositorySystem().createArtifactWithClassifier(metadata.getGroupId(),
            metadata.getArtifactId(), metadata.getVersion(), metadata.getType(), metadata.getClassifier());
}

From source file:org.ebayopensource.turmeric.eclipse.mavenapi.impl.MavenEclipseUtil.java

License:Open Source License

/**
 * Dependency.//w w  w . ja va 2  s. co  m
 *
 * @param metadata the metadata
 * @return the dependency
 */
public static Dependency dependency(final ArtifactMetadata metadata) {
    final Dependency dependency = new Dependency();
    dependency.setGroupId(metadata.getGroupId());
    dependency.setArtifactId(metadata.getArtifactId());
    dependency.setVersion(metadata.getVersion());
    dependency.setClassifier(metadata.getClassifier());
    dependency.setType(metadata.getType());
    if (metadata.getScope() != null
            && ArtifactScopeEnum.DEFAULT_SCOPE.getScope().equals(metadata.getScope()) == false)
        dependency.setScope(metadata.getScope());
    return dependency;
}

From source file:org.maven.ide.eclipse.annotations.AptConfigurator.java

License:Open Source License

/**
 * Configures maven project with associated annotation processors.
 *
 * Limitations://from   w w  w  . j a  va  2s .  c om
 * <ul>
 *  <li>There can be only one outputDirectory.</li>
 *  <li>There can be only one configuration per project.</li>
 *  <li>Might not work for processors that must be run in batch mode.</li>
 * </ul>
 *
 * @author Ivica Loncar
 */
@Override
public void configure(final ProjectConfigurationRequest p_request, final IProgressMonitor p_monitor)
        throws CoreException {
    super.configure(p_request, p_monitor);

    IProject project = p_request.getProject();
    if (project.hasNature(JavaCore.NATURE_ID)) {
        // enable annotation processing
        IJavaProject javaProject = JavaCore.create(project);
        AptConfig.setEnabled(javaProject, true);

        // Associate jars containing annotation processors.
        ProcessorConfiguration processorConfiguration = getProcessorConfiguration(p_request, p_monitor);

        List<ArtifactRepository> remoteArtifactRepositories = p_request.getMavenProject()
                .getRemoteArtifactRepositories();
        IMaven maven = MavenPlugin.getMaven();

        IFactoryPath factoryPath = AptConfig.getFactoryPath(javaProject);

        ArtifactMetadata[] artifactsMetadata = processorConfiguration.getProcessorArtifacts();
        for (ArtifactMetadata artifactMetadata : artifactsMetadata) {
            // Q: what about transitive dependencies?
            Artifact artifact = maven.resolve(artifactMetadata.getGroupId(), artifactMetadata.getArtifactId(),
                    artifactMetadata.getVersion(), artifactMetadata.getType(), artifactMetadata.getClassifier(),
                    remoteArtifactRepositories, p_monitor);

            File file = artifact.getFile();
            if ((file == null) || !file.exists() || !file.canRead()) {
                throw new IllegalStateException("Cannot find file for artifact " + artifact + " file:" + file);
            }

            factoryPath.addExternalJar(file);
        }

        AptConfig.setFactoryPath(javaProject, factoryPath);

        Map<String, String> optionMap = processorConfiguration.getOptionMap();
        // we would like to override existing files
        optionMap.put("defaultOverride", "true");
        AptConfig.setProcessorOptions(optionMap, javaProject);

        // output directory for generated sources
        AptConfig.setGenSrcDir(javaProject, processorConfiguration.getOutputDirectory());
        // From http://www.eclipse.org/forums/index.php?t=rview&goto=533747:
        //
        // Batch mode is mainly intended to support processors that can't handle incremental processing:
        // for example, that rely on static variables being properly initialized at the beginning of the run,
        // or that rely on being able to process all the files in a single round rather than one at a time,
        // or that make assumptions about how many rounds of processing will occur before  they exit.
        // Sun's JPA processors do, I think, need to be run in batch mode;
    }
}