Example usage for org.apache.maven.project MavenProject getArtifacts

List of usage examples for org.apache.maven.project MavenProject getArtifacts

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getArtifacts.

Prototype

public Set<Artifact> getArtifacts() 

Source Link

Document

All dependencies that this project has, including transitive ones.

Usage

From source file:net.flexmojos.oss.plugin.war.CopyMojo.java

License:Open Source License

private List<Artifact> getArtifacts(String type, MavenProject project) {
    List<Artifact> swfArtifacts = new ArrayList<Artifact>();
    Set<Artifact> artifacts = project.getArtifacts();
    for (Artifact artifact : artifacts) {
        if (type.equals(artifact.getType())) {
            swfArtifacts.add(artifact);/*from  w  ww. j ava 2  s . co  m*/
        }
    }
    return swfArtifacts;
}

From source file:org.apache.cactus.maven2.mojos.Dependency.java

License:Apache License

/**
 * We override this mothod. /*ww w .j  a v  a 2s  .  co m*/
 * @param theProject The Maven project parameter
 * @param theLog The Maven Log parameter
 * @return the path to the dependency as <code>java.lang.String</code>
 * @throws MojoExecutionException in case an error occurs
 */
public String getDependencyPath(MavenProject theProject, Log theLog) throws MojoExecutionException {
    String path = getLocation();

    if (path == null) {
        if ((getGroupId() == null) || (getArtifactId() == null)) {
            throw new MojoExecutionException("You must specify a "
                    + "groupId/artifactId or a location that points to a " + "directory or JAR");
        }

        // Default to jar if not type is specified
        if (getType() == null) {
            setType("jar");
        }

        path = findArtifactLocation(theProject.getArtifacts(), theLog);
    }

    theLog.debug("Classpath location = [" + new File(path).getPath() + "]");

    return new File(path).getPath();
}

From source file:org.apache.cxf.maven_plugin.wadlto.AbstractCodeGeneratorMojo.java

License:Apache License

private Artifact resolveRemoteWadlArtifact(Artifact artifact) throws MojoExecutionException {

    /**/*from w  w w. j av a 2  s  .c o m*/
     * First try to find the artifact in the reactor projects of the maven session.
     * So an artifact that is not yet built can be resolved
     */
    List<MavenProject> rProjects = mavenSession.getProjects();
    for (MavenProject rProject : rProjects) {
        if (artifact.getGroupId().equals(rProject.getGroupId())
                && artifact.getArtifactId().equals(rProject.getArtifactId())
                && artifact.getVersion().equals(rProject.getVersion())) {
            Set<Artifact> artifacts = rProject.getArtifacts();
            for (Artifact pArtifact : artifacts) {
                if ("wadl".equals(pArtifact.getType())) {
                    return pArtifact;
                }
            }
        }
    }

    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    request.setResolveRoot(true).setResolveTransitively(false);
    request.setServers(mavenSession.getRequest().getServers());
    request.setMirrors(mavenSession.getRequest().getMirrors());
    request.setProxies(mavenSession.getRequest().getProxies());
    request.setLocalRepository(mavenSession.getLocalRepository());
    request.setRemoteRepositories(mavenSession.getRequest().getRemoteRepositories());
    ArtifactResolutionResult result = repositorySystem.resolve(request);

    return result.getOriginatingArtifact();
}

From source file:org.apache.cxf.maven_plugin.WSDL2JavaMojo.java

License:Apache License

@SuppressWarnings("unchecked")
public Artifact resolveRemoteWsdlArtifact(List remoteRepos, Artifact artifact) throws MojoExecutionException {

    /**/*from   ww  w  . j a  v  a 2  s .c o m*/
     * First try to find the artifact in the reactor projects of the maven session.
     * So an artifact that is not yet built can be resolved
     */
    List<MavenProject> rProjects = mavenSession.getSortedProjects();
    for (MavenProject rProject : rProjects) {
        if (artifact.getGroupId().equals(rProject.getGroupId())
                && artifact.getArtifactId().equals(rProject.getArtifactId())
                && artifact.getVersion().equals(rProject.getVersion())) {
            Set<Artifact> artifacts = rProject.getArtifacts();
            for (Artifact pArtifact : artifacts) {
                if ("wsdl".equals(artifact.getType())) {
                    return pArtifact;
                }
            }
        }
    }

    /**
     * If this did not work resolve the artifact using the artifactResolver
     */
    try {
        artifactResolver.resolve(artifact, remoteRepos, localRepository);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Error downloading wsdl artifact.", e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException("Resource can not be found.", e);
    }

    return artifact;
}

From source file:org.apache.felix.bundleplugin.BundlePlugin.java

License:Apache License

protected Jar[] getClasspath(MavenProject currentProject) throws IOException, MojoExecutionException {
    List list = new ArrayList();

    if (getOutputDirectory() != null && getOutputDirectory().exists()) {
        list.add(new Jar(".", getOutputDirectory()));
    }/*w w w  . j av  a2  s  . c o  m*/

    final Collection artifacts = getSelectedDependencies(currentProject.getArtifacts());
    for (Iterator it = artifacts.iterator(); it.hasNext();) {
        Artifact artifact = (Artifact) it.next();
        if (artifact.getArtifactHandler().isAddedToClasspath()) {
            if (!Artifact.SCOPE_TEST.equals(artifact.getScope())) {
                File file = getFile(artifact);
                if (file == null) {
                    getLog().warn("File is not available for artifact " + artifact + " in project "
                            + currentProject.getArtifact());
                    continue;
                }
                Jar jar = new Jar(artifact.getArtifactId(), file);
                list.add(jar);
            }
        }
    }
    Jar[] cp = new Jar[list.size()];
    list.toArray(cp);
    return cp;
}

From source file:org.apache.felix.bundleplugin.BundlePlugin.java

License:Apache License

protected Collection getEmbeddableArtifacts(MavenProject project, Analyzer analyzer)
        throws MojoExecutionException {
    final Collection artifacts;

    String embedTransitive = analyzer.getProperty(DependencyEmbedder.EMBED_TRANSITIVE);
    if (Boolean.valueOf(embedTransitive).booleanValue()) {
        // includes transitive dependencies
        artifacts = project.getArtifacts();
    } else {/*w w  w .jav  a  2 s  .c  om*/
        // only includes direct dependencies
        artifacts = project.getDependencyArtifacts();
    }

    return getSelectedDependencies(artifacts);
}

From source file:org.apache.hyracks.maven.license.LicenseMojo.java

License:Apache License

private void gatherProjectDependencies(MavenProject project,
        Map<MavenProject, List<Pair<String, String>>> dependencyLicenseMap,
        Map<String, MavenProject> dependencyGavMap) throws ProjectBuildingException {
    final Set dependencyArtifacts = project.getArtifacts();
    if (dependencyArtifacts != null) {
        for (Object depArtifactObj : dependencyArtifacts) {
            final Artifact depArtifact = (Artifact) depArtifactObj;
            if (!excludedScopes.contains(depArtifact.getScope())) {
                MavenProject dep = resolveDependency(depArtifact);
                dep.setArtifact(depArtifact);
                dependencyGavMap.put(toGav(dep), dep);
                List<Pair<String, String>> licenseUrls = new ArrayList<>();
                for (Object license : dep.getLicenses()) {
                    final License license1 = (License) license;
                    String url = license1.getUrl() != null ? license1.getUrl()
                            : (license1.getName() != null ? license1.getName() : "LICENSE_EMPTY_NAME_URL");
                    licenseUrls.add(new ImmutablePair<>(url, license1.getName()));
                }/*from ww w.  j  a  v  a  2 s . co m*/
                dependencyLicenseMap.put(dep, licenseUrls);
            }
        }
    }
}

From source file:org.apache.sis.internal.maven.Assembler.java

License:Apache License

/**
 * Returns all files to include for the given Maven project.
 *//*w  w  w.j  ava 2  s .  c  om*/
private static Set<File> files(final MavenProject project) throws MojoExecutionException {
    final Set<File> files = new LinkedHashSet<>();
    files.add(project.getArtifact().getFile());
    for (final Artifact dep : project.getArtifacts()) {
        final String scope = dep.getScope();
        if (Artifact.SCOPE_COMPILE.equalsIgnoreCase(scope) || Artifact.SCOPE_RUNTIME.equalsIgnoreCase(scope)) {
            files.add(dep.getFile());
        }
    }
    if (files.remove(null)) {
        throw new MojoExecutionException(
                "Invocation of this MOJO shall be done together with a \"package\" Maven phase.");
    }
    return files;
}

From source file:org.apache.tuscany.maven.zip.AbstractZipMojo.java

License:Apache License

/**
 * Builds the webapp for the specified project.
 * <p/>/*from  w w  w.j a  v  a 2 s . c  om*/
 * Classes, libraries and tld files are copied to
 * the <tt>webappDirectory</tt> during this phase.
 *
 * @param project         the maven project
 * @param webappDirectory
 * @throws java.io.IOException if an error occured while building the webapp
 */
public void buildWebapp(MavenProject project, File webappDirectory)
        throws MojoExecutionException, IOException, MojoFailureException {
    getLog().info("Assembling webapp " + project.getArtifactId() + " in " + webappDirectory);

    File metainfDir = new File(webappDirectory, META_INF);
    metainfDir.mkdirs();

    File libDirectory = new File(webappDirectory, "/lib");

    File webappClassesDirectory = new File(webappDirectory, "/");

    if (classesDirectory.exists() && !classesDirectory.equals(webappClassesDirectory)) {
        if (archiveClasses) {
            createJarArchive(libDirectory);
        } else {
            copyDirectoryStructureIfModified(classesDirectory, webappClassesDirectory);
        }
    }

    Set artifacts = project.getArtifacts();

    List duplicates = findDuplicates(artifacts);

    List dependentWarDirectories = new ArrayList();

    for (Iterator iter = artifacts.iterator(); iter.hasNext();) {
        Artifact artifact = (Artifact) iter.next();
        String targetFileName = getDefaultFinalName(artifact);

        getLog().debug("Processing: " + targetFileName);

        if (duplicates.contains(targetFileName)) {
            getLog().debug("Duplicate found: " + targetFileName);
            targetFileName = artifact.getGroupId() + "-" + targetFileName;
            getLog().debug("Renamed to: " + targetFileName);
        }

        // TODO: utilise appropriate methods from project builder
        ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
        if (!artifact.isOptional() && filter.include(artifact)) {
            String type = artifact.getType();
            if ("jar".equals(type) || "ejb".equals(type) || "ejb-client".equals(type)) {
                copyFileIfModified(artifact.getFile(), new File(libDirectory, targetFileName));
            } else {
                if ("par".equals(type)) {
                    targetFileName = targetFileName.substring(0, targetFileName.lastIndexOf('.')) + ".jar";

                    getLog().debug(
                            "Copying " + artifact.getFile() + " to " + new File(libDirectory, targetFileName));

                    copyFileIfModified(artifact.getFile(), new File(libDirectory, targetFileName));
                } else {
                    if ("war".equals(type)) {
                        dependentWarDirectories.add(unpackWarToTempDirectory(artifact));
                    } else {
                        getLog().debug("Skipping artifact of type " + type + " for WEB-INF/lib");
                    }
                }
            }
        }
    }

    if (dependentWarDirectories.size() > 0) {
        getLog().info("Overlaying " + dependentWarDirectories.size() + " war(s).");

        // overlay dependent wars
        for (Iterator iter = dependentWarDirectories.iterator(); iter.hasNext();) {
            copyDependentWarContents((File) iter.next(), webappDirectory);
        }
    }
}

From source file:org.apache.usergrid.chop.plugin.Utils.java

License:Apache License

/**
 * Gets all dependency jars of the project specified by 'project' parameter from the local mirror and copies them
 * under targetFolder//from  w w  w  .  j  a v  a2  s  . c  o m
 *
 * @param targetFolder The folder which the dependency jars will be copied to
 */
public static void copyArtifactsTo(MavenProject project, String targetFolder) throws MojoExecutionException {
    File targetFolderFile = new File(targetFolder);
    for (Iterator it = project.getArtifacts().iterator(); it.hasNext();) {
        Artifact artifact = (Artifact) it.next();

        File f = artifact.getFile();

        LOG.info("Artifact {} found.", f.getAbsolutePath());

        if (f == null) {
            throw new MojoExecutionException("Cannot locate artifact file of " + artifact.getArtifactId());
        }

        // Check already existing artifacts and replace them if they are of a lower version
        try {

            List<String> existing = FileUtils.getFileNames(targetFolderFile,
                    artifact.getArtifactId() + "-*.jar", null, false);

            if (existing.size() != 0) {
                String version = existing.get(0).split("(" + artifact.getArtifactId() + "-)")[1]
                        .split("(.jar)")[0];
                DefaultArtifactVersion existingVersion = new DefaultArtifactVersion(version);
                DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(artifact.getVersion());

                if (existingVersion.compareTo(artifactVersion) < 0) { // Remove existing version
                    FileUtils.forceDelete(targetFolder + existing.get(0));
                } else {
                    LOG.info("Artifact " + artifact.getArtifactId() + " with the same or higher "
                            + "version already exists in lib folder, skipping copy");
                    continue;
                }
            }

            LOG.info("Copying {} to {}", f.getName(), targetFolder);
            FileUtils.copyFileToDirectory(f.getAbsolutePath(), targetFolder);
        } catch (IOException e) {
            throw new MojoExecutionException("Error while copying artifact file of " + artifact.getArtifactId(),
                    e);
        }
    }
}