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:org.codehaus.mojo.pluginsupport.dependency.Dependencies.java

License:Apache License

public Dependencies(final MavenProject project, final DependencyResolutionListener listener) {
    assert project != null;
    assert listener != null;

    this.projectDependencies = listener.getDependencyTree().getRootNode().getChildren();
    this.resolvedDependencies = listener;

    ////from   w  w w.  j  ava  2  s .  c o  m
    // Workaround to ensure proper File objects in the Artifacts from the DependencyResolutionListener
    //
    Map projectMap = new HashMap();
    Iterator iter = project.getArtifacts().iterator();

    while (iter.hasNext()) {
        Artifact artifact = (Artifact) iter.next();
        projectMap.put(ArtifactUtils.versionlessKey(artifact), artifact);
    }

    mapArtifactFiles(listener.getDependencyTree().getRootNode(), projectMap);
}

From source file:org.codehaus.mojo.unix.maven.plugin.MavenProjectWrapper.java

License:Open Source License

public static MavenProjectWrapper mavenProjectWrapper(final MavenProject project, MavenSession session) {
    SortedMap<String, String> properties = new TreeMap<String, String>();

    // This is perhaps not ideal. Maven uses reflection to dynamically extract properties from the project
    // when interpolating each file. This uses a static list that doesn't contain the project.* properties, except
    // the new we hard-code support for.
    //// w w  w. j av a  2 s .  co  m
    // The user can work around this like this:
    // <properties>
    //   <project.build.directory>${project.build.directory}</project.build.directory>
    // </properties>
    //
    // If this has to change, the properties has to be a F<String, String> and interpolation tokens ("${" and "}")
    // has to be defined. Doable but too painful for now.
    properties.putAll(toMap(session.getSystemProperties()));
    properties.putAll(toMap(session.getUserProperties()));
    properties.putAll(toMap(project.getProperties()));
    properties.put("project.groupId", project.getGroupId());
    properties.put("project.artifactId", project.getArtifactId());
    properties.put("project.version", project.getVersion());

    return new MavenProjectWrapper(project.getGroupId(), project.getArtifactId(), project.getVersion(),
            project.getArtifact(), project.getName(), project.getDescription(), project.getBasedir(),
            new File(project.getBuild().getDirectory()), new LocalDateTime(), project.getArtifacts(),
            project.getLicenses(), new ArtifactMap(project.getArtifacts()), unmodifiableSortedMap(properties));
}

From source file:org.codehaus.mojo.wasanttasks.ListToPathTask.java

License:Open Source License

public void execute() throws BuildException {

    try {//  w  w  w  . j  a  va 2 s.c  o  m
        log("Building classpath from dependencies", Project.MSG_DEBUG);

        if (targetRef == null || targetRef.length() == 0) {
            throw new BuildException("targetRef not set");
        }

        if (mavenproject == null || mavenproject.length() == 0) {
            throw new BuildException("mavenproject reference not set");
        }

        MavenProject pom = (MavenProject) getProject().getReferences().get(mavenproject);
        if (pom == null) {
            throw new BuildException("Unable to get Maven project file (pom)");
        }
        log("Found " + pom.getArtifacts().size() + " artifacts", Project.MSG_DEBUG);

        Iterator it2 = pom.getArtifacts().iterator();
        Path path = new Path(getProject());
        while (it2.hasNext()) {
            path.setLocation(((Artifact) it2.next()).getFile());
        }
        getProject().addReference(targetRef, path);
    } catch (Exception e) {
        log("Failure: " + e.getMessage());
        if (e.getCause() != null) {
            log("Caused by: " + e.getCause().getMessage());
        }
        throw new BuildException(e);
    }
}

From source file:org.codehaus.mojo.webstart.util.DefaultArtifactUtil.java

License:Apache License

/**
 * {@inheritDoc}//from  w  ww  .  j  a  v a2  s .  c  om
 */
public Set<Artifact> resolveTransitively(Set<Artifact> jarResourceArtifacts, Set<MavenProject> siblingProjects,
        Artifact originateArtifact, ArtifactRepository localRepository,
        List<ArtifactRepository> remoteRepositories, ArtifactFilter artifactFilter, Map managedVersions)
        throws MojoExecutionException {

    Set<Artifact> resultArtifacts = new LinkedHashSet<Artifact>();

    if (CollectionUtils.isNotEmpty(siblingProjects)) {

        // getting transitive dependencies from project
        for (MavenProject siblingProject : siblingProjects) {
            Set<Artifact> artifacts = siblingProject.getArtifacts();
            for (Artifact artifact : artifacts) {
                if (artifactFilter.include(artifact)) {

                    resultArtifacts.add(artifact);
                }
            }
        }
    }
    try {
        ArtifactResolutionResult result = artifactResolver.resolveTransitively(jarResourceArtifacts,
                originateArtifact, managedVersions, localRepository, remoteRepositories,
                this.artifactMetadataSource, artifactFilter);

        resultArtifacts.addAll(result.getArtifacts());

        return resultArtifacts;
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Could not resolv transitive dependencies", e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException("Could not find transitive dependencies ", e);
    }
}

From source file:org.eclipse.che.maven.server.MavenModelUtil.java

License:Open Source License

public static MavenModel convertProjectToModel(MavenProject project, List<DependencyNode> dependencyNodes,
        File localRepository) {//w  w w .j a v a2  s .  c  o  m
    Model model = project.getModel();
    return convertModel(model, project.getCompileSourceRoots(), project.getTestCompileSourceRoots(),
            project.getArtifacts(), project.getExtensionArtifacts(), localRepository);
}

From source file:org.eclipse.m2e.core.internal.embedder.AbstractWorkspaceRuntime.java

License:Open Source License

public void createLauncherConfiguration(IMavenLauncherConfiguration collector, IProgressMonitor monitor)
        throws CoreException {
    IMavenProjectFacade maven = getMavenDistribution();
    if (maven != null) {
        MavenProject mavenProject = maven.getMavenProject(monitor);
        ///*ww w.  j  a  v a  2 s . c  om*/
        // main is org.apache.maven.cli.MavenCli from plexus.core
        //
        // set maven.home default ${user.home}/m2
        //
        // [plexus.core]
        // optionally ${maven.home}/lib/ext/*.jar
        // load       ${maven.home}/lib/*.jar
        // load       ${maven.home}/conf/logging
        //
        collector.setMainType(getMainClass(), PLEXUS_CLASSWORLD_NAME);
        collector.addRealm(PLEXUS_CLASSWORLD_NAME);
        //
        // plexus.core is the current realm, and now we want the add the SLF4J loggging configuration if 
        // we have a verion>3.1.x Maven-like runtime
        //
        for (IMavenProjectFacade facade : projectManager.getProjects()) {
            ArtifactKey artifactKey = facade.getArtifactKey();
            if (getDistributionArtifactKey().getGroupId().equals(artifactKey.getGroupId()) //
                    && getDistributionArtifactKey().getArtifactId().equals(artifactKey.getArtifactId())) {
                File loggingConfigurationDirectory = new File(facade.getPomFile().getParentFile(),
                        "src/conf/logging");
                if (loggingConfigurationDirectory.exists()) {
                    collector.addArchiveEntry(loggingConfigurationDirectory.getAbsolutePath());
                }
            }
        }
        Set<Artifact> artifacts = mavenProject.getArtifacts();
        Artifact launcherArtifact = null;

        for (Artifact artifact : artifacts) {
            if (Artifact.SCOPE_TEST.equals(artifact.getScope())) {
                continue;
            }

            if (PLEXUS_CLASSWORLDS.getGroupId().equals(artifact.getGroupId())
                    && PLEXUS_CLASSWORLDS.getArtifactId().equals(artifact.getArtifactId())) {
                launcherArtifact = artifact;
                continue;
            }

            addArtifact(collector, artifact);
        }

        if (launcherArtifact != null) {
            collector.addRealm(IMavenLauncherConfiguration.LAUNCHER_REALM);
            addArtifact(collector, launcherArtifact);
        }
    }
}

From source file:org.eclipse.m2e.core.internal.embedder.MavenImpl.java

License:Open Source License

@SuppressWarnings("deprecation")
public void execute(MavenSession session, MojoExecution execution, IProgressMonitor monitor) {
    Map<MavenProject, Set<Artifact>> artifacts = new HashMap<MavenProject, Set<Artifact>>();
    Map<MavenProject, MavenProjectMutableState> snapshots = new HashMap<MavenProject, MavenProjectMutableState>();
    for (MavenProject project : session.getProjects()) {
        artifacts.put(project, new LinkedHashSet<Artifact>(project.getArtifacts()));
        snapshots.put(project, MavenProjectMutableState.takeSnapshot(project));
    }//from w  w w .j a  v  a2 s  .co  m
    try {
        MojoExecutor mojoExecutor = lookup(MojoExecutor.class);
        DependencyContext dependencyContext = mojoExecutor.newDependencyContext(session,
                Collections.singletonList(execution));
        mojoExecutor.ensureDependenciesAreResolved(execution.getMojoDescriptor(), session, dependencyContext);
        lookup(BuildPluginManager.class).executeMojo(session, execution);
    } catch (Exception ex) {
        session.getResult().addException(ex);
    } finally {
        for (MavenProject project : session.getProjects()) {
            project.setArtifactFilter(null);
            project.setResolvedArtifacts(null);
            project.setArtifacts(artifacts.get(project));
            MavenProjectMutableState snapshot = snapshots.get(project);
            if (snapshot != null) {
                snapshot.restore(project);
            }
        }
    }
}

From source file:org.eclipse.m2e.core.internal.embedder.MavenWorkspaceRuntime.java

License:Open Source License

public void createLauncherConfiguration(IMavenLauncherConfiguration collector, IProgressMonitor monitor)
        throws CoreException {
    IMavenProjectFacade maven = getMavenDistribution();
    if (maven != null) {
        MavenProject mavenProject = maven.getMavenProject(monitor);

        collector.setMainType(MAVEN_EXECUTOR_CLASS, PLEXUS_CLASSWORLD_NAME);

        collector.addRealm(PLEXUS_CLASSWORLD_NAME);

        Set<Artifact> artifacts = mavenProject.getArtifacts();

        Artifact launcherArtifact = null;

        for (Artifact artifact : artifacts) {
            if (Artifact.SCOPE_TEST.equals(artifact.getScope())) {
                continue;
            }//  ww  w .jav  a  2 s.c  o  m

            if (PLEXUS_CLASSWORLDS.getGroupId().equals(artifact.getGroupId())
                    && PLEXUS_CLASSWORLDS.getArtifactId().equals(artifact.getArtifactId())) {
                launcherArtifact = artifact;
                continue;
            }

            addArtifact(collector, artifact);
        }

        if (launcherArtifact != null) {
            collector.addRealm(IMavenLauncherConfiguration.LAUNCHER_REALM);
            addArtifact(collector, launcherArtifact);
        }
    }

    // XXX throw something at the caller! 
}

From source file:org.eclipse.m2e.core.internal.launch.AbstractMavenRuntime.java

License:Open Source License

private void collectProject(IMavenLauncherConfiguration collector, ProjectClasspathEntry entry,
        IProgressMonitor monitor) throws CoreException {
    IProject project = workspace.getProject(entry.getProject());
    IMavenProjectFacade facade = registry.create(project, monitor);
    if (facade == null) {
        throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID,
                NLS.bind(Messages.AbstractMavenRuntime_unknownProject, entry.getProject())));
    }/* www.  j  a  va2 s. c om*/
    collector.addProjectEntry(facade);
    MavenProject mavenProject = facade.getMavenProject(monitor);
    for (Artifact dependency : mavenProject.getArtifacts()) {
        if (Artifact.SCOPE_COMPILE.equals(dependency.getScope())
                || Artifact.SCOPE_RUNTIME.equals(dependency.getScope())) {
            collector.addArchiveEntry(dependency.getFile().getAbsolutePath());
        }
    }
}

From source file:org.eclipse.m2e.core.internal.launch.MavenWorkspaceRuntime.java

License:Open Source License

public void createLauncherConfiguration(IMavenLauncherConfiguration collector, IProgressMonitor monitor)
        throws CoreException {
    IMavenProjectFacade maven = getMavenDistribution();
    if (maven != null) {
        MavenProject mavenProject = maven.getMavenProject(monitor);
        ///* w  ww  .j a  va2s.  co  m*/
        // main is org.apache.maven.cli.MavenCli from plexus.core
        //
        // set maven.home default ${user.home}/m2
        //
        // [plexus.core]
        // optionally ${maven.home}/lib/ext/*.jar
        // load       ${maven.home}/lib/*.jar
        // load       ${maven.home}/conf/logging
        //
        collector.setMainType(getMainClass(), PLEXUS_CLASSWORLD_NAME);
        collector.addRealm(PLEXUS_CLASSWORLD_NAME);

        collectExtensions(collector, monitor);

        //
        // plexus.core is the current realm, and now we want the add the SLF4J loggging configuration if 
        // we have a verion>3.1.x Maven-like runtime
        //
        for (IMavenProjectFacade facade : projectManager.getProjects()) {
            ArtifactKey artifactKey = facade.getArtifactKey();
            if (getDistributionArtifactKey().getGroupId().equals(artifactKey.getGroupId()) //
                    && getDistributionArtifactKey().getArtifactId().equals(artifactKey.getArtifactId())) {
                File loggingConfigurationDirectory = new File(facade.getPomFile().getParentFile(),
                        "src/conf/logging");
                if (loggingConfigurationDirectory.exists()) {
                    collector.addArchiveEntry(loggingConfigurationDirectory.getAbsolutePath());
                }
            }
        }
        Set<Artifact> artifacts = mavenProject.getArtifacts();
        Artifact launcherArtifact = null;

        for (Artifact artifact : artifacts) {
            if (Artifact.SCOPE_TEST.equals(artifact.getScope())) {
                continue;
            }

            if (PLEXUS_CLASSWORLDS.getGroupId().equals(artifact.getGroupId())
                    && PLEXUS_CLASSWORLDS.getArtifactId().equals(artifact.getArtifactId())) {
                launcherArtifact = artifact;
                continue;
            }

            addArtifact(collector, artifact);
        }

        if (launcherArtifact != null) {
            collector.addRealm(IMavenLauncherConfiguration.LAUNCHER_REALM);
            addArtifact(collector, launcherArtifact);
        }
    }
}