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

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

Introduction

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

Prototype

public String getVersion() 

Source Link

Usage

From source file:org.ebayopensource.turmeric.eclipse.maven.core.utils.MavenCoreUtils.java

License:Open Source License

/**
 * @param artifact artifact meta data//from  w  ww  . j a va  2 s.  c o m
 * @return The full library name in Maven format
 */
public static String libraryName(final ArtifactMetadata artifact) {
    return MavenCoreUtils.translateLibraryName(artifact.getGroupId(), artifact.getArtifactId(),
            artifact.getType(), artifact.getVersion());
}

From source file:org.ebayopensource.turmeric.eclipse.maven.core.utils.MavenCoreUtils.java

License:Open Source License

/**
 * Gets the library identifier./*  w  w  w.j a  v  a  2s.  com*/
 *
 * @param libName the lib name
 * @return the library identifier
 * @throws MavenEclipseApiException the maven eclipse api exception
 */
public static ArtifactMetadata getLibraryIdentifier(final String libName) throws MavenEclipseApiException {
    ArtifactMetadata result = null;
    if (SOALogger.DEBUG)
        logger.entering(libName);
    try {
        result = MavenEclipseUtil.artifactMetadata(libName);
        if (result == null || result.getGroupId() == null || result.getArtifactId() == null)
            return null;
        if (StringUtils.isBlank(result.getVersion())) {
            Artifact artifact = getLatestArtifact(result.getGroupId(), result.getArtifactId());
            if (artifact != null) {
                result.setVersion(artifact.getVersion());
            }
        }
        return result;
    } finally {
        if (SOALogger.DEBUG)
            logger.exiting(result);
    }
}

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 ww w .j a  v a 2  s.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   w w w . j  a v  a  2  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.MavenEclipseApi.java

License:Open Source License

private Model generateModel(final ProjectMavenizationRequest req, IProgressMonitor monitor) {
    final Model model = new Model();
    model.setModelVersion("4.0.0");

    final ArtifactMetadata artifact = req.getArtifact();
    if ((monitor instanceof NullProgressMonitor) == false) {
        monitor = new SubProgressMonitor(monitor, 50);
        monitor.setTaskName("Mavenizing project->" + req.getEclipseProject());
    }//from   w w w  .j a  v  a  2 s  .  c  o  m
    if (req.getParent() != null) {
        final ArtifactMetadata md = req.getParent();
        final Parent parent = new Parent();
        parent.setGroupId(md.getGroupId());
        parent.setArtifactId(md.getArtifactId());
        parent.setVersion(md.getVersion());
        model.setParent(parent);
    }
    monitor.worked(5);

    model.setGroupId(artifact.getGroupId());
    model.setArtifactId(artifact.getArtifactId());
    model.setVersion(artifact.getVersion());
    model.setName(req.getEclipseProject().getName());

    if (isNotBlank(artifact.getType()) && !StringUtils.equalsIgnoreCase(artifact.getType().trim(), "jar"))
        model.setPackaging(artifact.getType());

    final Properties props = req.getProperties();
    if (props != null && props.size() > 0)
        model.setProperties(props);
    monitor.worked(5);

    // build is first set into model here
    if (req.getSourcePath() != null) {
        final String sp = req.getSourcePath();
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        build.setSourceDirectory(sp);
        model.setBuild(build);
    }

    if (req.getTestSourcePath() != null) {
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        build.setTestSourceDirectory(req.getTestSourcePath());
        model.setBuild(build);
    }

    if (req.getTestOutputPath() != null) {
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        build.setTestOutputDirectory(req.getTestOutputPath());
        model.setBuild(build);
    }

    if (req.getResourceDirectories() != null && req.getResourceDirectories().isEmpty() == false) {
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        build.setResources(req.getResourceDirectories());
        model.setBuild(build);
    }
    monitor.worked(5);

    if (req.getTestResourceDirectories() != null && req.getTestResourceDirectories().isEmpty() == false) {
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        build.setTestResources(req.getTestResourceDirectories());
        model.setBuild(build);
    }
    monitor.worked(5);

    if (req.getBuildPlugins() != null && req.getBuildPlugins().isEmpty() == false) {
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        for (Plugin buildPlugin : req.getBuildPlugins()) {
            build.addPlugin(buildPlugin);
        }
    }

    if (req.getOutputPath() != null) {
        final Build build = model.getBuild() != null ? model.getBuild() : new Build();
        build.setOutputDirectory(req.getOutputPath());
    }

    if (req.getDependencies() != null && req.getDependencies().isEmpty() == false) {
        for (final ArtifactMetadata am : req.getDependencies()) {
            model.addDependency(MavenEclipseUtil.dependency(am));
        }
    }
    monitor.worked(5);
    return model;
}

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

License:Open Source License

/**
 * Artifact.//  w  w w . j a v a 2s.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  v  a 2 s.  c o 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.ebayopensource.turmeric.eclipse.mavenapi.internal.util.MavenApiUtil.java

License:Open Source License

/**
 * Tries to resolve the given {@code ArtifactMetadata}s in the given
 * local/remote repositories and returns the resolved {@code Artifact}s.
 *
 * @param embedder the embedder/* ww  w .  jav a 2 s . co  m*/
 * @param mdCollection the md collection
 * @param localRepository the local repository
 * @param remoteRepositories the remote repositories
 * @return the list
 * @throws MavenEclipseApiException the maven eclipse api exception
 */
public static List<Artifact> resolveArtifacts(RepositorySystem embedder, List<ArtifactMetadata> mdCollection,
        ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories)
        throws MavenEclipseApiException {
    if (mdCollection == null || mdCollection.isEmpty()) {
        return null;
    }

    List<Artifact> res = new ArrayList<Artifact>(mdCollection.size());
    Artifact artifact = null;
    for (Iterator<ArtifactMetadata> i$ = mdCollection.iterator(); i$.hasNext(); res.add(artifact)) {
        ArtifactMetadata md = i$.next();
        artifact = embedder.createArtifact(md.getGroupId(), md.getArtifactId(), md.getVersion(), md.getScope(),
                md.getType() != null ? md.getType() : "jar");

        resolveArtifact(embedder, artifact, localRepository, remoteRepositories);
    }

    return res;
}

From source file:org.ebayopensource.turmeric.eclipse.mavenapi.internal.util.MavenApiUtil.java

License:Open Source License

private static MetadataTreeNode resolveMetadataTree(RepositorySystem embedder, ArtifactMetadata query,
        MetadataTreeNode parent, ArtifactRepository localRepository, List remoteRepositories)
        throws MavenEclipseApiException {
    try {/*from  w ww .  j ava 2  s.c om*/
        Artifact pomArtifact = embedder.createArtifact(query.getGroupId(), query.getArtifactId(),
                query.getVersion(), query.getScope(), query.getType() != null ? query.getType() : "jar");
        //Artifact art = MavenApiHelper.getMavenEmbedder().resolve(groupId, artifactId, version, type, classifier, remoteRepositories, monitor);

        ArtifactResolutionResult result = resolveArtifact(embedder, pomArtifact, localRepository,
                remoteRepositories, false);

        if (pomArtifact.isResolved()) {
            MetadataTreeNode node = new MetadataTreeNode(query, parent, true, query.getScopeAsEnum());
            Set<Artifact> artifacts = result.getArtifacts();
            if (artifacts.size() > 1) {
                List<Artifact> dependencies = new ArrayList<Artifact>(artifacts);
                // remove the first one, which is the source artifact itself
                dependencies.remove(0);

                int nKids = dependencies.size();
                node.setNChildren(nKids);
                int kidNo = 0;
                MetadataTreeNode kidNode;
                for (Artifact artifact : dependencies) {
                    ArtifactMetadata amd = new ArtifactMetadata(artifact.getGroupId(), artifact.getArtifactId(),
                            artifact.getVersion(), artifact.getType(),
                            ArtifactScopeEnum.valueOf(artifact.getScope()));
                    // 20100514#emac: no need to resolve dependencies
                    // recursively
                    // kidNode = resolveMetadataTree(embedder, amd, node,
                    // localRepository, remoteRepositories);
                    kidNode = new MetadataTreeNode(amd, node, artifact.isResolved(), amd.getScopeAsEnum());
                    node.addChild(kidNo++, kidNode);
                }
            }

            return node;
        }

        return new MetadataTreeNode(pomArtifact, parent, false, query.getArtifactScope());
    } catch (Exception anyEx) {
        throw new MavenEclipseApiException(anyEx);
    }
}

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

License:Open Source License

/**
 * Configures maven project with associated annotation processors.
 *
 * Limitations:/*from w  ww .j  av a2  s.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;
    }
}