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

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

Introduction

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

Prototype

public String getArtifactId() 

Source Link

Usage

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

License:Open Source License

/**
 * //from w  w w  . ja va  2  s. c  o m
 * @param libs a list of libraries 
 * @return a set of ArtifactMetadata for the libraries
 * @throws MavenEclipseApiException 
 */
public static Set<ArtifactMetadata> artifactMetadata(final Collection<String> libs)
        throws MavenEclipseApiException {
    if (SOALogger.DEBUG)
        logger.entering(libs);

    final Set<ArtifactMetadata> metadata = SetUtil.set();
    final Set<String> processedMetadatas = new HashSet<String>();
    for (final String lib : libs) {
        ArtifactMetadata aMeta = getLibraryIdentifier(lib);
        if (aMeta != null && StringUtils.isNotBlank(aMeta.getArtifactId())) {
            final String fullLibName = libraryName(aMeta);
            if (processedMetadatas.contains(fullLibName) == false) {
                if (SOALogger.DEBUG)
                    logger.debug("Non-processed lib->", fullLibName);
                metadata.add(aMeta);
                processedMetadatas.add(fullLibName);
            }
        }
    }
    if (SOALogger.DEBUG)
        logger.exiting(metadata);
    return metadata;
}

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

License:Open Source License

/**
 * @param artifact artifact meta data/*www . j  a v a  2 s.  com*/
 * @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.// ww  w .j av  a2  s.  c  o  m
 *
 * @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.maven.ui.preferences.TurmericSOAConfigPrefPage.java

License:Open Source License

@Override
protected void createFieldEditors() {
    final IPreferenceStore prefStore = TurmericSOAConfigPrefInitializer.getPreferenceStore();
    final Composite composite = getFieldEditorParent();

    try {/*from  w w w . jav  a 2  s .  co m*/
        final Group group = new Group(composite, SWT.SHADOW_ETCHED_IN);
        group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        GridLayout layout = new GridLayout(2, false);
        group.setLayout(layout);
        group.setText("Framework Version Configurations");
        final ISOAOrganizationProvider orgProvider = GlobalRepositorySystem.instanceOf()
                .getActiveRepositorySystem().getActiveOrganizationProvider();
        String soatoolsId = orgProvider.getSOAFrameworkLibraryIdentifier(SOAFrameworkLibrary.SOATOOLS);
        final ArtifactMetadata metadata = MavenEclipseUtil.artifactMetadata(soatoolsId);

        BooleanFieldEditor overwriteEditor = new BooleanFieldEditor(
                TurmericSOAConfigPrefInitializer.PREF_KEY_OVERWRITE_PREFERRED_VERSOIN,
                "Overwrite Preferred Version", group) {

            @Override
            protected void valueChanged(boolean oldValue, boolean newValue) {
                enableVersionEditor(newValue);
                super.valueChanged(oldValue, newValue);
            }

            private void enableVersionEditor(boolean newValue) {
                if (preferredVerEditor != null) {
                    preferredVerEditor.setEnabled(newValue, group);
                    if (newValue == true && StringUtils.isBlank(preferredVerEditor.getStringValue())) {
                        TurmericSOAConfigPrefPage.this.setErrorMessage("preferred version must not be empty");
                        preferredVerEditor.setErrorMessage("preferred version must not be empty");
                    }
                }
            }

            @Override
            protected void doLoadDefault() {

                super.doLoadDefault();
                enableVersionEditor(getBooleanValue());
            }
        };
        addField(overwriteEditor);
        final Collection<String> versions = new TreeSet<String>();
        if (metadata != null) {
            for (Artifact artifact : MavenCoreUtils.mavenEclipseAPI()
                    .findArtifactByNameAndGroup(metadata.getArtifactId(), metadata.getGroupId())) {
                versions.add(artifact.getVersion());
            }
        }

        final String minVersion = orgProvider.getMinimumRequiredTurmericFrameworkVersion();
        this.preferredVerEditor = new StringFieldEditor(
                TurmericSOAConfigPrefInitializer.PREF_KEY_TURMERIC_PREFERRED_VERSOIN,
                "Preferred Turmeric Version:", group) {

            @Override
            protected boolean doCheckState() {
                if (VersionUtil.compare(getStringValue(), minVersion) < 0) {
                    this.setErrorMessage("Preferred version must be equal to or greater than " + minVersion);
                    return false;
                }
                return super.doCheckState();
            }

        };
        this.preferredVerEditor.setEmptyStringAllowed(false);
        this.preferredVerEditor.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE);

        addField(preferredVerEditor);

        if (versions.isEmpty() == false) {
            Text verText = this.preferredVerEditor.getTextControl(group);
            new AutoCompleteField(verText, new TextContentAdapter(), versions.toArray(new String[0]));
        }

        this.preferredVerEditor.setEnabled(
                prefStore.getBoolean(TurmericSOAConfigPrefInitializer.PREF_KEY_OVERWRITE_PREFERRED_VERSOIN),
                group);

        prefStore.setValue(TurmericSOAConfigPrefInitializer.PREF_KEY_MINIMUM_REQUIRED_VERSOIN, minVersion);
        prefStore.setDefault(TurmericSOAConfigPrefInitializer.PREF_KEY_MINIMUM_REQUIRED_VERSOIN, minVersion);
        StringFieldEditor text = new StringFieldEditor(
                TurmericSOAConfigPrefInitializer.PREF_KEY_MINIMUM_REQUIRED_VERSOIN, "Minimum Required Version:",
                group);
        text.getTextControl(group).setEditable(false);
        text.setStringValue(orgProvider.getMinimumRequiredTurmericFrameworkVersion());
        addField(text);
    } catch (Exception e) {
        logger.error(e);
        UIUtil.showErrorDialog(e);
    }
}

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/*w  w  w.  ja  v a2 s  . co 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 .ja 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  av  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./*from   ww  w.  j a  va  2  s .  c  o  m*/
 *
 * @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./*from   w w w  .  j  a  v  a  2s .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/*  w ww  .  j  a  v  a2 s  .c o  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;
}