Example usage for org.apache.maven.artifact.factory ArtifactFactory createArtifactWithClassifier

List of usage examples for org.apache.maven.artifact.factory ArtifactFactory createArtifactWithClassifier

Introduction

In this page you can find the example usage for org.apache.maven.artifact.factory ArtifactFactory createArtifactWithClassifier.

Prototype

Artifact createArtifactWithClassifier(String groupId, String artifactId, String version, String type,
            String classifier);

Source Link

Usage

From source file:com.alibaba.citrus.maven.eclipse.base.ide.IdeUtils.java

License:Apache License

/**
 * Wrap {@link ArtifactFactory#createArtifactWithClassifier} so that the type and classifier are set correctly for
 * "sources" and "javadoc"./*  w ww . j  a  v a  2 s .c  o  m*/
 *
 * @param groupId         see {@link ArtifactFactory#createArtifactWithClassifier}
 * @param artifactId      see {@link ArtifactFactory#createArtifactWithClassifier}
 * @param version         see {@link ArtifactFactory#createArtifactWithClassifier}
 * @param depClassifier   see {@link ArtifactFactory#createArtifactWithClassifier}
 * @param inClassifier    either "sources" of "javadoc"
 * @param artifactFactory see {@link ArtifactFactory#createArtifactWithClassifier}
 * @return see {@link ArtifactFactory#createArtifactWithClassifier}
 * @see ArtifactFactory#createArtifactWithClassifier
 */
public static Artifact createArtifactWithClassifier(String groupId, String artifactId, String version,
        String depClassifier, String inClassifier, ArtifactFactory artifactFactory) {
    String type = null;

    // the "sources" classifier maps to the "java-source" type
    if ("sources".equals(inClassifier)) {
        type = "java-source";
    } else {
        type = inClassifier;
    }

    String finalClassifier = null;
    if (depClassifier == null) {
        finalClassifier = inClassifier;
    } else if ("sources".equals(inClassifier) && "tests".equals(depClassifier)) {
        // MECLIPSE-151 - if the dependency is a test, get the correct classifier for it. (ignore for javadocs)
        finalClassifier = "test-sources";
    } else {
        finalClassifier = depClassifier + "-" + inClassifier;
    }

    return artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, type, finalClassifier);
}

From source file:de.thetaphi.forbiddenapis.maven.SignaturesArtifact.java

License:Apache License

/** Used by the mojo to fetch the artifact */
Artifact createArtifact(ArtifactFactory artifactFactory) {
    if (groupId == null || artifactId == null || version == null || type == null) {
        throw new NullPointerException(
                "signaturesArtifact is missing some properties. Required are: groupId, artifactId, version, type");
    }//from www. ja  v  a 2 s .com
    return artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
}

From source file:fr.imag.adele.cadse.platform.DependenciesTask.java

License:Apache License

private void resolveSource(ArtifactFactory artifactFactory, ArtifactResolver resolver,
        List remoteArtifactRepositories, ArtifactRepository localRepo, Artifact artifact, String classifier,
        FileSet sourcesFileSet) {//from www.  jav  a2 s. c o m
    Artifact sourceArtifact = artifactFactory.createArtifactWithClassifier(artifact.getGroupId(),
            artifact.getArtifactId(), artifact.getVersion(), "java-source", classifier);
    try {
        resolver.resolve(sourceArtifact, remoteArtifactRepositories, localRepo);

        addArtifactToResult(localRepo, sourceArtifact, sourcesFileSet);
    } catch (ArtifactResolutionException e) {
        throw new BuildException("Unable to resolve artifact: " + e.getMessage(), e);
    } catch (ArtifactNotFoundException e) {
        // no source available: no problem, it's optional
    }
}

From source file:hudson.gridmaven.reporters.MavenArtifact.java

License:Open Source License

/**
 * Creates a Maven {@link Artifact} back from the persisted data.
 *//* w  w w  . j  av  a 2  s. c o  m*/
public Artifact toArtifact(ArtifactHandlerManager handlerManager, ArtifactFactory factory, MavenBuild build)
        throws IOException {
    // Hack: presence of custom ArtifactHandler during builds could influence the file extension
    // in the repository during deployment. So simulate that behavior if that's necessary.
    final String canonicalExtension = canonicalName.substring(canonicalName.lastIndexOf('.') + 1);
    ArtifactHandler ah = handlerManager.getArtifactHandler(type);
    Map<String, ArtifactHandler> handlers = Maps.newHashMap();

    handlers.put(type, new DefaultArtifactHandler(type) {
        public String getExtension() {
            return canonicalExtension;
        }
    });
    // Fix for HUDSON-3814 - changed from comparing against canonical extension to canonicalName.endsWith.
    if (!canonicalName.endsWith(ah.getExtension())) {
        handlerManager.addHandlers(handlers);
    }

    Artifact a = factory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
    a.setFile(getFile(build));

    return a;
}

From source file:org.codehaus.cargo.maven2.configuration.ArtifactInstaller.java

License:Apache License

/**
 * Resolves the dependency and return the artifact file.
 * @param artifactFactory The artifact factory is used to create valid Maven {@link Artifact}
 * objects./*from  w  w w.  ja  v a2  s  .c o  m*/
 * @param artifactResolver The artifact resolver is used to dynamically resolve
 * {@link Artifact} objects. It will automatically download whatever needed.
 * @param localRepository The local Maven repository. This is used by the artifact resolver to
 * download resolved artifacts and put them in the local repository so that they won't have to
 * be fetched again next time the plugin is executed.
 * @param repositories The remote Maven repositories used by the artifact resolver to look for
 * artifacts.
 * @return Resolved dependency.
 * @throws ArtifactResolutionException If artifact resolution fails.
 * @throws ArtifactNotFoundException If artifact not found.
 */
public File resolve(ArtifactFactory artifactFactory, ArtifactResolver artifactResolver,
        ArtifactRepository localRepository, List<ArtifactRepository> repositories)
        throws ArtifactResolutionException, ArtifactNotFoundException {
    Artifact artifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, type,
            classifier);
    artifactResolver.resolve(artifact, repositories, localRepository);
    return artifact.getFile();
}

From source file:org.codehaus.mojo.sysdeo.ide.IdeUtils.java

License:Apache License

public static Artifact resolveArtifactWithClassifier(String groupId, String artifactId, String version,
        String classifier, ArtifactRepository localRepository, ArtifactResolver artifactResolver,
        ArtifactFactory artifactFactory, List remoteRepos, Log log)

{
    String type = classifier;//from  w w w  .  j a  v a2  s .  c  o  m

    // the "sources" classifier maps to the "java-source" type
    if ("sources".equals(type)) //$NON-NLS-1$
    {
        type = "java-source"; //$NON-NLS-1$
    }

    Artifact resolvedArtifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, type,
            classifier);

    try {
        artifactResolver.resolve(resolvedArtifact, remoteRepos, localRepository);
    } catch (ArtifactNotFoundException e) {
        // ignore, the jar has not been found
    } catch (ArtifactResolutionException e) {
        String message = Messages.getString("errorresolving", new Object[] { //$NON-NLS-1$
                classifier, resolvedArtifact.getId(), e.getMessage() });

        log.warn(message);
    }

    return resolvedArtifact;
}

From source file:org.hardisonbrewing.maven.core.DependencyService.java

License:Open Source License

public static final Artifact createArtifactWithClassifier(Artifact artifact, String classifier) {

    ArtifactFactory artifactFactory = getArtifactFactory();
    return artifactFactory.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(),
            artifact.getVersion(), artifact.getType(), classifier);
}

From source file:org.jfrog.jade.plugins.common.deploy.DeploymentHelper.java

License:Apache License

public static ProjectDeployments getDeployments(MvnInjectable injectable, Artifact dependency)
        throws IOException {
    // TODO: Find a way to know that there is no deployment
    ArtifactFactory artifactFactory = injectable.getArtifactFactory();
    if (artifactFactory == null) {
        throw new IOException("The MvnInjectable " + injectable + " has no artifact Factory");
    }/*  ww  w.  j a v a2  s.c  o m*/
    Artifact deploymentsArtifact = artifactFactory.createArtifactWithClassifier(dependency.getGroupId(),
            dependency.getArtifactId(), dependency.getVersion(), TYPE, CLASSIFIER);
    try {
        injectable.getArtifactResolver().resolve(deploymentsArtifact,
                injectable.getProject().getRemoteArtifactRepositories(), injectable.getLocalRepository());
    } catch (ArtifactResolutionException e) {
        injectable.getLog().error(e);
        return null;
    } catch (ArtifactNotFoundException e) {
        injectable.getLog().error(e);
        return null;
    }
    File deploymentsFile = deploymentsArtifact.getFile();
    return (ProjectDeployments) getXStream().fromXML(new FileReader(deploymentsFile));
}

From source file:org.nbheaven.sqe.core.maven.utils.MavenUtilities.java

License:Open Source License

/**
 * try to collect the plugin's dependency artifacts
 * as defined in <dependencies> section within <plugin>. Will only
 * return files currently in local repository
 *
 * @return list of files in local repository
 *//*from   w  w w . j  av  a 2s  .c o m*/
public static List<File> findDependencyArtifacts(Project project, String pluginGroupId, String pluginArtifactId,
        boolean includePluginArtifact) {
    List<File> cpFiles = new ArrayList<File>();
    final NbMavenProject p = project.getLookup().lookup(NbMavenProject.class);
    final MavenEmbedder online = EmbedderFactory.getOnlineEmbedder();
    MavenProject mp = p.getMavenProject();
    if (includePluginArtifact) {
        Set<Artifact> arts = new HashSet<Artifact>();
        arts.addAll(mp.getReportArtifacts());
        arts.addAll(mp.getPluginArtifacts());
        for (Artifact a : arts) {
            if (pluginArtifactId.equals(a.getArtifactId()) && pluginGroupId.equals(a.getGroupId())) {
                File f = a.getFile();
                if (f == null) {
                    //somehow the report plugins are not resolved, we need to workaround that..
                    f = FileUtil.normalizeFile(new File(new File(online.getLocalRepository().getBasedir()),
                            online.getLocalRepository().pathOf(a)));
                }
                if (!f.exists()) {
                    try {
                        online.resolve(a, mp.getRemoteArtifactRepositories(), online.getLocalRepository());
                    } catch (ArtifactResolutionException ex) {
                        Exceptions.printStackTrace(ex);
                    } catch (ArtifactNotFoundException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
                if (f.exists()) {
                    cpFiles.add(f);
                    try {
                        ProjectBuildingRequest req = new DefaultProjectBuildingRequest();
                        req.setRemoteRepositories(mp.getRemoteArtifactRepositories());
                        req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
                        req.setSystemProperties(online.getSystemProperties());
                        ProjectBuildingResult res = online.buildProject(a, req);
                        MavenProject mp2 = res.getProject();
                        if (mp2 != null) {
                            // XXX this is not really right, but mp.dependencyArtifacts = null for some reason
                            for (Dependency dep : mp2.getDependencies()) {
                                Artifact a2 = online.createArtifact(dep.getGroupId(), dep.getArtifactId(),
                                        dep.getVersion(), "jar");
                                online.resolve(a2, mp.getRemoteArtifactRepositories(),
                                        online.getLocalRepository());
                                File df = a2.getFile();
                                if (df.exists()) {
                                    cpFiles.add(df);
                                }
                            }
                        }
                    } catch (Exception x) {
                        Exceptions.printStackTrace(x);
                    }
                }
            }
        }

    }
    List<Plugin> plugins = mp.getBuildPlugins();
    for (Plugin plug : plugins) {
        if (pluginArtifactId.equals(plug.getArtifactId()) && pluginGroupId.equals(plug.getGroupId())) {
            try {
                List<Dependency> deps = plug.getDependencies();
                ArtifactFactory artifactFactory = online.getPlexus().lookup(ArtifactFactory.class);
                for (Dependency d : deps) {
                    final Artifact projectArtifact = artifactFactory.createArtifactWithClassifier(
                            d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getType(), d.getClassifier());
                    String localPath = online.getLocalRepository().pathOf(projectArtifact);
                    File f = FileUtil
                            .normalizeFile(new File(online.getLocalRepository().getBasedir(), localPath));
                    if (!f.exists()) {
                        try {
                            online.resolve(projectArtifact, mp.getRemoteArtifactRepositories(),
                                    online.getLocalRepository());
                        } catch (ArtifactResolutionException ex) {
                            ex.printStackTrace();
                            //                                        Exceptions.printStackTrace(ex);
                        } catch (ArtifactNotFoundException ex) {
                            ex.printStackTrace();
                            //                            Exceptions.printStackTrace(ex);
                        }
                    }
                    if (f.exists()) {
                        cpFiles.add(f);
                    }
                }
            } catch (ComponentLookupException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
    return cpFiles;
}