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:com.idega.maven.webapp.IdegaWebWarMojo2.java

License:Apache License

private void compileDependencyList() {

    //File libDirectory = new File( webappDirectory, WEB_INF + "/lib" );
    //File tldDirectory = new File( webappDirectory, WEB_INF + "/tld" );
    //File webappClassesDirectory = new File( webappDirectory, WEB_INF + "/classes" );

    MavenProject project = getProject();
    if (project != null) {

        Set artifacts = project.getArtifacts();

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

            // TODO: utilise appropriate methods from project builder
            // TODO: scope handler
            // Include runtime and compile time libraries
            if (!Artifact.SCOPE_PROVIDED.equals(artifact.getScope())
                    && !Artifact.SCOPE_TEST.equals(artifact.getScope())) {
                String type = artifact.getType();
                if ("tld".equals(type)) {
                    //FileUtils.copyFileToDirectory( artifact.getFile(), tldDirectory );
                    getLog().debug("Getting artifact " + artifact.getArtifactId() + " of type " + type
                            + " for WEB-INF/lib");
                } else if ("jar".equals(type) || "ejb".equals(type) || "ejb-client".equals(type)) {
                    //FileUtils.copyFileToDirectory( artifact.getFile(), libDirectory );
                    getLog().debug("Getting artifact " + artifact.getArtifactId() + " of type " + type
                            + " for WEB-INF/lib");
                } else {
                    getLog().debug("Skipping artifact of type " + type + " for WEB-INF/lib");
                }//from   w  w w. j ava 2s.co m
            }

        }
    } else {
        getLog().debug("compileDependencyList() project is null");
    }
}

From source file:com.kamomileware.maven.plugin.opencms.util.ModuleUtils.java

License:Apache License

public static Artifact getArtifact(MavenProject project, Dependency dependency) {
    final Iterator<Artifact> it = project.getArtifacts().iterator();
    while (it.hasNext()) {
        Artifact artifact = (Artifact) it.next();
        if (artifact.getGroupId().equals(dependency.getGroupId())
                && artifact.getArtifactId().equals(dependency.getArtifactId())
                && artifact.getType().equals(dependency.getType())) {
            if (artifact.getClassifier() == null && dependency.getClassifier() == null) {
                return artifact;
            } else if (dependency.getClassifier() != null
                    && dependency.getClassifier().equals(artifact.getClassifier())) {
                return artifact;
            }// www. j a  va2 s .  com
        }
    }
    return null;
}

From source file:com.kw.opencms.module.mojo.util.ModuleUtils.java

License:Apache License

public static Artifact getArtifact(MavenProject project, Dependency dependency) {
    final Iterator it = project.getArtifacts().iterator();
    while (it.hasNext()) {
        Artifact artifact = (Artifact) it.next();
        if (artifact.getGroupId().equals(dependency.getGroupId())
                && artifact.getArtifactId().equals(dependency.getArtifactId())
                && artifact.getType().equals(dependency.getType())) {
            if (artifact.getClassifier() == null && dependency.getClassifier() == null) {
                return artifact;
            } else if (dependency.getClassifier() != null
                    && dependency.getClassifier().equals(artifact.getClassifier())) {
                return artifact;
            }//ww  w.ja v  a2  s  . c o  m
        }
    }
    return null;
}

From source file:com.mcleodmoores.mvn.natives.UnpackDependenciesMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
        getLog().debug("Skipping step");
        return;/*from   w  w  w  . j a  v  a2s .co  m*/
    }
    final MavenProject project = (MavenProject) getPluginContext().get("project");
    final File targetDir = new File(new File(project.getBuild().getDirectory()), "dependency");
    targetDir.mkdirs();
    final Map<String, Set<Artifact>> names = new HashMap<String, Set<Artifact>>();
    for (final Artifact artifact : project.getArtifacts()) {
        if (isNative(artifact)) {
            gatherNames(artifact, names);
        }
    }
    for (final Artifact artifact : project.getArtifacts()) {
        if (isNative(artifact)) {
            unpack(artifact, names, targetDir);
        }
    }
}

From source file:com.monday_consulting.maven.plugins.fsm.DependencyToXMLMojo.java

License:Apache License

/**
 * Log Projects and their resolved dependencies via MavenProject.getArtifacts().
 *
 * @param reactorProjects MavenProjects in the current reactor
 *///from w ww .j  ava2s .c om
private void checkReactor(final List<MavenProject> reactorProjects) {
    for (final MavenProject reactorProject : reactorProjects) {
        final String msg = "Check resolved Artifacts for: " + "\ngroudId:    " + reactorProject.getGroupId()
                + "\nartifactId: " + reactorProject.getArtifactId() + "\nversion:    "
                + reactorProject.getVersion();
        if (getLog().isDebugEnabled())
            getLog().debug(msg);

        if (reactorProject.getArtifacts() == null || reactorProject.getArtifacts().isEmpty()) {
            if (getLog().isDebugEnabled())
                getLog().debug("+  Dependencies not resolved or Reactor-Project has no dependencies!");
        } else {
            for (final Artifact artifact : reactorProject.getArtifacts()) {
                if (getLog().isDebugEnabled())
                    getLog().debug("  + " + artifact.getGroupId() + " : " + artifact.getArtifactId() + " : "
                            + artifact.getVersion() + " : " + artifact.getType() + " : " + artifact.getFile());
            }
        }
    }
}

From source file:com.monday_consulting.maven.plugins.fsm.util.resolver.MavenGetArtifactsResolver.java

License:Apache License

/**
 * {@inheritDoc}//from www  .  jav  a  2s.  c  o  m
 */
public Module resolve(final ModuleType moduleType, final List<String> scopes)
        throws MojoFailureException, MojoExecutionException {
    final Module module = new Module(log, moduleType, scopes);
    MavenProject mavenProject = getMavenProjectViaReactor(module);

    if (mavenProject == null) {
        log.info("Trying to find module " + module.getGroupId() + ":" + module.getArtifactId()
                + " in repository");
        mavenProject = getMavenProjectViaRepository(module, projectBuilder);
    }

    if (mavenProject != null) {
        List<Artifact> artifacts = new ArrayList<Artifact>(mavenProject.getArtifacts());
        module.setProject(mavenProject);
        module.setResolvedModuleArtifacts(artifacts);
    }
    return module;
}

From source file:com.phoenixnap.oss.ramlapisync.plugin.ClassLoaderUtils.java

License:Apache License

public static void addLocationsToClassLoader(MavenProject mavenProject) throws MojoExecutionException {

    List<URL> urls = Lists.newArrayList();
    try {//from w ww .j  a va2  s  .  c o m
        urls.add(new File(mavenProject.getBuild().getOutputDirectory()).toURI().toURL());

        // Getting all artifacts locations
        Set<Artifact> artifacts = mavenProject.getArtifacts();

        for (Artifact artifact : artifacts) {
            urls.add(artifact.getFile().toURI().toURL());
        }

    } catch (MalformedURLException e) {
        // DO NOTHING
    }

    /*
     * this was failing when executing goal on a maven project if (originalClassLoader != null) { throw new
     * MojoExecutionException( "Context setting of the current thread ClassLoader is allowed only once."); }
     */

    // Store ClassLoader before applying modifications.
    originalClassLoader = Thread.currentThread().getContextClassLoader();

    Thread.currentThread()
            .setContextClassLoader(new URLClassLoader(urls.toArray(new URL[urls.size()]), originalClassLoader));

}

From source file:com.pongasoft.maven.ant.tasks.ResolveTask.java

License:Apache License

@SuppressWarnings("unchecked")
private void resolveTransitively(Artifact mainArtifact) {
    try {/* w w w  . j  a  v  a  2  s.  c  o m*/
        Artifact pomArtifact = resolveArtifact("pom", null);
        MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup(MavenProjectBuilder.ROLE);
        MavenProject mavenProject = projectBuilder.buildWithDependencies(pomArtifact.getFile(), _localRepo,
                getProfileManager());

        Set<String> dependencies = new HashSet<String>();

        for (Dependency d : (List<Dependency>) mavenProject.getDependencies()) {
            dependencies.add(d.getGroupId() + ":" + d.getArtifactId() + ":" + d.getVersion() + ":"
                    + d.getClassifier() + ":" + d.getType() + ":" + d.getScope());
        }

        Collection<Artifact> directDependencies = new ArrayList<Artifact>();
        Collection<Artifact> transitiveDependencies = new ArrayList<Artifact>();
        Collection<Artifact> optionalDependencies = new ArrayList<Artifact>();
        Collection<Artifact> classpath = new ArrayList<Artifact>();
        classpath.add(mainArtifact);

        for (org.apache.maven.artifact.Artifact a : (Set<org.apache.maven.artifact.Artifact>) mavenProject
                .getArtifacts()) {
            String scope = a.getScope();
            if ("compile".equals(scope) || "runtime".equals(scope)) {
                Artifact artifact = createArtifact(a);

                if (a.isOptional() && _optional) {
                    classpath.add(artifact);
                    optionalDependencies.add(artifact);
                } else {
                    classpath.add(artifact);

                }
                if (dependencies.contains(a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion() + ":"
                        + a.getClassifier() + ":" + a.getType() + ":" + a.getScope())) {
                    directDependencies.add(artifact);
                } else {
                    transitiveDependencies.add(artifact);
                }
            }
        }

        _result.put("classpath", classpath);
        _result.put("transitiveDependencies", transitiveDependencies);
        _result.put("directDependencies", directDependencies);
        _result.put("optionalDependencies", optionalDependencies);
    } catch (ProjectBuildingException e) {
        throw new BuildException(e);
    } catch (ArtifactNotFoundException e) {
        throw new BuildException(e);
    } catch (ArtifactResolutionException e) {
        throw new BuildException(e);
    }
}

From source file:com.redhat.victims.ArtifactCollector.java

License:Open Source License

@Override
protected void gatherArtifacts() {
    try {// ww w  . j av a2  s  .c  om
        List<MavenProject> reactorProjects = (List<MavenProject>) helper.evaluate("${reactorProjects}");
        for (MavenProject rp : reactorProjects) {
            for (Object item : rp.getArtifacts()) {
                if (item != null && item instanceof Artifact) {
                    Artifact artifact = (Artifact) item;
                    artifacts.add(artifact);
                    helper.getLog()
                            .debug("[victims-enforcer] adding reactor dependency " + artifact.toString());
                }
            }
        }
    } catch (ExpressionEvaluationException ex) {
        helper.getLog().error(ex);
    }
}

From source file:com.sap.prd.mobile.ios.mios.XCodePrepareBuildManager.java

License:Apache License

void prepareBuild(final MavenProject project, Set<String> configurations, final Set<String> sdks)
        throws MojoExecutionException, XCodeException, IOException {

    prepareRootFolders(project, configurations, sdks);

    final Iterator<Artifact> dependentArtifacts = project.getArtifacts().iterator();

    if (!dependentArtifacts.hasNext()) {
        LOGGER.info("No dependencies found.");
    }//  w w  w . ja  va 2 s .  c o m

    while (dependentArtifacts.hasNext()) {

        final Artifact mainArtifact = (Artifact) dependentArtifacts.next();

        LOGGER.info("Preparing dependency: " + mainArtifact.getId());

        if (PackagingType.LIB.getMavenPackaging().equals(mainArtifact.getType())) {
            prepareLibrary(project, configurations, sdks, mainArtifact);
        } else if (PackagingType.FRAMEWORK.getMavenPackaging().equals(mainArtifact.getType())) {
            prepareFramework(project, mainArtifact, configurations);
        } else if (additionalPackagingTypes.keySet().contains(mainArtifact.getType())) {

            final PackagingTypeAction packagingTypeAction = PackagingTypeAction
                    .valueOf(additionalPackagingTypes.get(mainArtifact.getType()));
            LOGGER.info("Packaging type '" + mainArtifact.getType() + "' found in pom. Action: "
                    + packagingTypeAction);
            packagingTypeAction.perform(archiverManager, project, mainArtifact);
        } else {

            LOGGER.warning("Unknown dependency type detected: '" + mainArtifact.getType()
                    + "'. The corresponding dependency '" + mainArtifact.getGroupId() + ":"
                    + mainArtifact.getArtifactId() + ":" + mainArtifact.getVersion() + "' will be ignored.");
        }
    }
}