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

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

Introduction

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

Prototype

@Deprecated
public Set<Artifact> getDependencyArtifacts() 

Source Link

Document

Direct dependencies that this project has.

Usage

From source file:org.gosu_lang.tools.maven.GosuArtifactMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    MavenProject project = (MavenProject) getPluginContext().get("project");

    @SuppressWarnings("unchecked")
    List<Dependency> dependencies = (List<Dependency>) project.getModel().getDependencies();

    for (Dependency dep : dependencies) {
        String artifactId = dep.getArtifactId();
        String groupId = dep.getGroupId();
        if (GOSU_GROUPID.equals(groupId)
                && (CORE_API_ARTIFACTID.equals(artifactId) || CORE_ARTIFACTID.equals(artifactId))) {
            throw new MojoExecutionException(
                    "Your project cannot explicitly depend on Gosu artifacts with this plugin in use (" + dep
                            + ")");
        }// w  w w  . j a  va  2  s. com
    }

    @SuppressWarnings("unchecked")
    Set<Artifact> artifacts = (Set<Artifact>) project.getDependencyArtifacts();

    Artifact artifact = _factory.createArtifact(GOSU_GROUPID, CORE_API_ARTIFACTID, gosuVersion, "compile",
            "jar");
    getLog().info("Inserting " + artifact + " into the compile classpath.");
    if (!artifacts.contains(artifact)) {
        artifacts.add(artifact);
    }

    if (includeImpl) {
        artifact = _factory.createArtifact(GOSU_GROUPID, CORE_ARTIFACTID, gosuVersion, "compile", "jar");
        getLog().info("Inserting " + artifact + " into the compile classpath. Naughty!");
        if (!artifacts.contains(artifact)) {
            artifacts.add(artifact);
        }
    }
}

From source file:org.grails.maven.plugin.AbstractGrailsMojo.java

License:Apache License

private Artifact findGrailsDependency(MavenProject project) {
    Set dependencyArtifacts = project.getDependencyArtifacts();
    for (Object o : dependencyArtifacts) {
        Artifact artifact = (Artifact) o;
        if (artifact.getArtifactId().equals("grails-dependencies")) {
            return artifact;
        }/*from www  .  j av a2  s .c  om*/
    }
    return null;
}

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

License:Open Source License

/**
 * Copy all {@link Dependency} {@link Artifact}s to the specified destination directory.
 * @param dest The destination directory.
 * @throws Exception/*w w w  .  j  a  v a  2  s  .  co m*/
 */
@SuppressWarnings("unchecked")
public static final void copyDependencies(File dest) throws Exception {

    MavenProject mavenProject = ProjectService.getProject();

    Set<Artifact> artifacts = mavenProject.getDependencyArtifacts();
    Iterator<Artifact> iterator = artifacts.iterator();

    while (iterator.hasNext()) {
        Artifact artifact = iterator.next();
        FileUtils.copyFileToDirectory(artifact.getFile(), dest);
    }
}

From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java

License:Apache License

protected Collection<Artifact> getEmbeddableArtifacts(MavenProject currentProject, Analyzer analyzer)
        throws MojoExecutionException {
    final Collection<Artifact> artifacts;

    String embedTransitive = analyzer.getProperty(DependencyEmbedder.EMBED_TRANSITIVE);
    if (Boolean.valueOf(embedTransitive).booleanValue()) {
        // includes transitive dependencies
        artifacts = currentProject.getArtifacts();
    } else {/*from w w  w .ja v  a2 s  . c o  m*/
        // only includes direct dependencies
        artifacts = currentProject.getDependencyArtifacts();
    }

    return getSelectedDependencies(artifacts);
}

From source file:org.hudsonci.maven.eventspy_30.handler.ExecutionEventHandler.java

License:Open Source License

@SuppressWarnings("unused")
private void recordDirectArtifacts(MavenProject project, MavenProjectDTO projectDTO) {
    Set<Artifact> artifacts = project.getDependencyArtifacts();
    // TODO: may want to record these separately as plugin use.
    // Note:/*from  w  w  w . j av a  2  s  .co  m*/
    //    project.getPluginArtifacts() makes the 'type/extension' maven-plugin which doesn't match anything Aether has resolved.
    //    see underlying org.apache.maven.artifact.factory.DefaultArtifactFactory.createPluginArtifact()
    //    With m3 use Aether Artifact.getProperty( "type" ); see it's JavaDoc
    //artifacts.addAll( project.getPluginArtifacts() );

    for (Artifact artifact : artifacts) {
        ArtifactDTO artifactDTO = new ArtifactDTO().withCoordinates(new MavenCoordinatesDTO()
                .withGroupId(artifact.getGroupId()).withArtifactId(artifact.getArtifactId())
                .withType(artifact.getType()).withVersion(artifact.getVersion())
                .withClassifier(artifact.getClassifier()).normalize());

        artifactDTO.getDependentProjects().add(projectDTO.getId());
        // TODO: Maybe do in batch since it's traffic back to the master.
        //getCallback().updateArtifact( artifactDTO );
    }
}

From source file:org.hudsonci.maven.eventspy_30.handler.ProjectLogger.java

License:Open Source License

public static void log(MavenProject project, String where) {
    if (disabled)
        return;/*from  w  w  w  . ja  v  a 2 s .c  o m*/

    log.debug("MavenProject ({}) artifacts @ {}:", project.getId(), where);
    logArtifactContents("artifacts", project.getArtifacts());
    logArtifactContents("attachedArtifacts", project.getAttachedArtifacts());
    logArtifactContents("dependencyArtifacts", project.getDependencyArtifacts());
    logArtifactContents("extensionArtifacts", project.getExtensionArtifacts());
    logArtifactContents("pluginArtifacts", project.getPluginArtifacts());

    for (Artifact artifact : project.getPluginArtifacts()) {
        if (artifact instanceof PluginArtifact) {
            List<Dependency> dependencies = ((PluginArtifact) artifact).getDependencies();

            Integer maybeSize = (dependencies == null ? null : dependencies.size());
            log.debug("  {} " + "pluginDependencies" + ": {}", maybeSize, dependencies);
        }
    }
}

From source file:org.jetbrains.idea.maven.server.Maven30ServerEmbedderImpl.java

License:Apache License

@Nonnull
public MavenExecutionResult doResolveProject(@Nonnull final File file,
        @Nonnull final List<String> activeProfiles, @Nonnull final List<String> inactiveProfiles,
        final List<ResolutionListener> listeners) throws RemoteException {
    final MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles,
            Collections.<String>emptyList());

    request.setUpdateSnapshots(myAlwaysUpdateSnapshots);

    final AtomicReference<MavenExecutionResult> ref = new AtomicReference<MavenExecutionResult>();

    executeWithMavenSession(request, new Runnable() {
        @Override//from   w w  w.j  a  v a2 s  . c  o  m
        public void run() {
            try {
                // copied from DefaultMavenProjectBuilder.buildWithDependencies
                ProjectBuilder builder = getComponent(ProjectBuilder.class);

                CustomMaven3ModelInterpolator2 modelInterpolator = (CustomMaven3ModelInterpolator2) getComponent(
                        ModelInterpolator.class);

                String savedLocalRepository = modelInterpolator.getLocalRepository();
                modelInterpolator.setLocalRepository(request.getLocalRepositoryPath().getAbsolutePath());
                List<ProjectBuildingResult> results;

                try {
                    // Don't use build(File projectFile, ProjectBuildingRequest request) , because it don't use cache !!!!!!!! (see http://devnet.jetbrains.com/message/5500218)
                    results = builder.build(Collections.singletonList(new File(file.getPath())), false,
                            request.getProjectBuildingRequest());
                } finally {
                    modelInterpolator.setLocalRepository(savedLocalRepository);
                }

                ProjectBuildingResult buildingResult = results.get(0);

                MavenProject project = buildingResult.getProject();

                RepositorySystemSession repositorySession = getComponent(LegacySupport.class)
                        .getRepositorySession();
                if (repositorySession instanceof DefaultRepositorySystemSession) {
                    ((DefaultRepositorySystemSession) repositorySession)
                            .setTransferListener(new Maven30TransferListenerAdapter(myCurrentIndicator));

                    if (myWorkspaceMap != null) {
                        ((DefaultRepositorySystemSession) repositorySession)
                                .setWorkspaceReader(new Maven30WorkspaceReader(myWorkspaceMap));
                    }
                }

                List<Exception> exceptions = new ArrayList<Exception>();
                loadExtensions(project, exceptions);

                //Artifact projectArtifact = project.getArtifact();
                //Map managedVersions = project.getManagedVersionMap();
                //ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
                project.setDependencyArtifacts(
                        project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
                //

                if (USE_MVN2_COMPATIBLE_DEPENDENCY_RESOLVING) {
                    ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
                    resolutionRequest.setArtifactDependencies(project.getDependencyArtifacts());
                    resolutionRequest.setArtifact(project.getArtifact());
                    resolutionRequest.setManagedVersionMap(project.getManagedVersionMap());
                    resolutionRequest.setLocalRepository(myLocalRepository);
                    resolutionRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
                    resolutionRequest.setListeners(listeners);

                    resolutionRequest.setResolveRoot(false);
                    resolutionRequest.setResolveTransitively(true);

                    ArtifactResolver resolver = getComponent(ArtifactResolver.class);
                    ArtifactResolutionResult result = resolver.resolve(resolutionRequest);

                    project.setArtifacts(result.getArtifacts());
                    // end copied from DefaultMavenProjectBuilder.buildWithDependencies
                    ref.set(new MavenExecutionResult(project, exceptions));
                } else {
                    final DependencyResolutionResult dependencyResolutionResult = resolveDependencies(project,
                            repositorySession);
                    final List<Dependency> dependencies = dependencyResolutionResult.getDependencies();

                    Set<Artifact> artifacts = new LinkedHashSet<Artifact>(dependencies.size());
                    for (Dependency dependency : dependencies) {
                        final Artifact artifact = RepositoryUtils.toArtifact(dependency.getArtifact());
                        artifact.setScope(dependency.getScope());
                        artifact.setOptional(dependency.isOptional());
                        artifacts.add(artifact);
                        resolveAsModule(artifact);
                    }

                    project.setArtifacts(artifacts);
                    ref.set(new MavenExecutionResult(project, dependencyResolutionResult, exceptions));
                }
            } catch (Exception e) {
                ref.set(handleException(e));
            }
        }
    });

    return ref.get();
}

From source file:org.jetbrains.idea.maven.server.Maven32ServerEmbedderImpl.java

License:Apache License

@Nonnull
public MavenExecutionResult doResolveProject(@Nonnull final File file,
        @Nonnull final List<String> activeProfiles, @Nonnull final List<String> inactiveProfiles,
        final List<ResolutionListener> listeners) throws RemoteException {
    final MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles,
            Collections.<String>emptyList());

    request.setUpdateSnapshots(myAlwaysUpdateSnapshots);

    final AtomicReference<MavenExecutionResult> ref = new AtomicReference<MavenExecutionResult>();

    executeWithMavenSession(request, new Runnable() {
        @Override/*  w  ww .  j  a va 2 s  . c  o  m*/
        public void run() {
            try {
                // copied from DefaultMavenProjectBuilder.buildWithDependencies
                ProjectBuilder builder = getComponent(ProjectBuilder.class);

                CustomMaven3ModelInterpolator2 modelInterpolator = (CustomMaven3ModelInterpolator2) getComponent(
                        ModelInterpolator.class);

                String savedLocalRepository = modelInterpolator.getLocalRepository();
                modelInterpolator.setLocalRepository(request.getLocalRepositoryPath().getAbsolutePath());
                List<ProjectBuildingResult> results;

                try {
                    // Don't use build(File projectFile, ProjectBuildingRequest request) , because it don't use cache !!!!!!!! (see http://devnet.jetbrains.com/message/5500218)
                    results = builder.build(Collections.singletonList(new File(file.getPath())), false,
                            request.getProjectBuildingRequest());
                } finally {
                    modelInterpolator.setLocalRepository(savedLocalRepository);
                }

                ProjectBuildingResult buildingResult = results.get(0);

                MavenProject project = buildingResult.getProject();

                RepositorySystemSession repositorySession = getComponent(LegacySupport.class)
                        .getRepositorySession();
                if (repositorySession instanceof DefaultRepositorySystemSession) {
                    ((DefaultRepositorySystemSession) repositorySession)
                            .setTransferListener(new TransferListenerAdapter(myCurrentIndicator));

                    if (myWorkspaceMap != null) {
                        ((DefaultRepositorySystemSession) repositorySession)
                                .setWorkspaceReader(new Maven32WorkspaceReader(myWorkspaceMap));
                    }
                }

                List<Exception> exceptions = new ArrayList<Exception>();
                loadExtensions(project, exceptions);

                //Artifact projectArtifact = project.getArtifact();
                //Map managedVersions = project.getManagedVersionMap();
                //ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
                project.setDependencyArtifacts(
                        project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
                //

                if (USE_MVN2_COMPATIBLE_DEPENDENCY_RESOLVING) {
                    ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
                    resolutionRequest.setArtifactDependencies(project.getDependencyArtifacts());
                    resolutionRequest.setArtifact(project.getArtifact());
                    resolutionRequest.setManagedVersionMap(project.getManagedVersionMap());
                    resolutionRequest.setLocalRepository(myLocalRepository);
                    resolutionRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
                    resolutionRequest.setListeners(listeners);

                    resolutionRequest.setResolveRoot(false);
                    resolutionRequest.setResolveTransitively(true);

                    ArtifactResolver resolver = getComponent(ArtifactResolver.class);
                    ArtifactResolutionResult result = resolver.resolve(resolutionRequest);

                    project.setArtifacts(result.getArtifacts());
                    // end copied from DefaultMavenProjectBuilder.buildWithDependencies
                    ref.set(new MavenExecutionResult(project, exceptions));
                } else {
                    final DependencyResolutionResult dependencyResolutionResult = resolveDependencies(project,
                            repositorySession);
                    final List<Dependency> dependencies = dependencyResolutionResult.getDependencies();

                    Set<Artifact> artifacts = new LinkedHashSet<Artifact>(dependencies.size());
                    for (Dependency dependency : dependencies) {
                        final Artifact artifact = RepositoryUtils.toArtifact(dependency.getArtifact());
                        artifact.setScope(dependency.getScope());
                        artifact.setOptional(dependency.isOptional());
                        artifacts.add(artifact);
                        resolveAsModule(artifact);
                    }

                    project.setArtifacts(artifacts);
                    ref.set(new MavenExecutionResult(project, dependencyResolutionResult, exceptions));
                }
            } catch (Exception e) {
                ref.set(handleException(e));
            }
        }
    });

    return ref.get();
}

From source file:org.jetbrains.maven.embedder.MavenEmbedder.java

License:Apache License

@Nonnull
public MavenExecutionResult resolveProject(@Nonnull final File file, @Nonnull final List<String> activeProfiles,
        @Nonnull final List<String> inactiveProfiles, List<ResolutionListener> listeners) {
    MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles,
            Collections.<String>emptyList());
    ProjectBuilderConfiguration config = request.getProjectBuilderConfiguration();

    request.getGlobalProfileManager().loadSettingsProfiles(mySettings);

    ProfileManager globalProfileManager = request.getGlobalProfileManager();
    globalProfileManager.loadSettingsProfiles(request.getSettings());

    List<Exception> exceptions = new ArrayList<Exception>();
    MavenProject project = null;
    try {/*from   w w  w  . j  ava2s .  c o m*/
        // copied from DefaultMavenProjectBuilder.buildWithDependencies
        MavenProjectBuilder builder = getComponent(MavenProjectBuilder.class);
        project = builder.build(new File(file.getPath()), config);
        builder.calculateConcreteState(project, config, false);

        // copied from DefaultLifecycleExecutor.execute
        findExtensions(project);
        // end copied from DefaultLifecycleExecutor.execute

        Artifact projectArtifact = project.getArtifact();
        Map managedVersions = project.getManagedVersionMap();
        ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
        project.setDependencyArtifacts(
                project.createArtifacts(getComponent(ArtifactFactory.class), null, null));

        ArtifactResolver resolver = getComponent(ArtifactResolver.class);
        ArtifactResolutionResult result = resolver.resolveTransitively(project.getDependencyArtifacts(),
                projectArtifact, managedVersions, myLocalRepository, project.getRemoteArtifactRepositories(),
                metadataSource, null, listeners);
        project.setArtifacts(result.getArtifacts());
        // end copied from DefaultMavenProjectBuilder.buildWithDependencies
    } catch (Exception e) {
        return handleException(e);
    }

    return new MavenExecutionResult(project, exceptions);
}

From source file:org.jfrog.maven.annomojo.extractor.AnnoMojoDescriptorExtractor.java

License:Apache License

@SuppressWarnings({ "unchecked" })
public List<MojoDescriptor> execute(MavenProject project, PluginDescriptor pluginDescriptor)
        throws InvalidPluginDescriptorException {
    List<String> sourceRoots = project.getCompileSourceRoots();
    Set<String> sourcePathElements = new HashSet<String>();
    String srcRoot = null;//w  w w .  j  av  a2  s. c o m
    try {
        for (String sourceRoot : sourceRoots) {
            srcRoot = sourceRoot;
            List<File> files = FileUtils.getFiles(new File(srcRoot), "**/*.java", null, true);
            for (File file : files) {
                String path = file.getPath();
                sourcePathElements.add(path);
            }
        }
    } catch (Exception e) {
        throw new InvalidPluginDescriptorException("Failed to get source files from " + srcRoot, e);
    }
    List<String> argsList = new ArrayList<String>();
    argsList.add("-nocompile");
    argsList.add("-cp");
    StringBuilder cp = new StringBuilder();
    //Add the compile classpath
    List<String> compileClasspathElements;
    try {
        compileClasspathElements = project.getCompileClasspathElements();
    } catch (DependencyResolutionRequiredException e) {
        throw new InvalidPluginDescriptorException("Failed to get compileClasspathElements.", e);
    }
    for (String ccpe : compileClasspathElements) {
        appendToPath(cp, ccpe);
    }

    //Add the current CL classptah
    URL[] urls = ((URLClassLoader) getClass().getClassLoader()).getURLs();
    for (URL url : urls) {
        String path;
        try {
            path = url.getPath();
        } catch (Exception e) {
            throw new InvalidPluginDescriptorException("Failed to get classpath files from " + url, e);
        }
        appendToPath(cp, path);
    }

    // Attempts to add dependencies to the classpath so that parameters inherited from abstract mojos in other
    // projects will be processed.
    Set s = project.getDependencyArtifacts();
    if (s != null) {
        for (Object untypedArtifact : project.getDependencyArtifacts()) {
            if (untypedArtifact instanceof Artifact) {
                Artifact artifact = (Artifact) untypedArtifact;
                File artifactFile = artifact.getFile();
                if (artifactFile != null) {
                    appendToPath(cp, artifactFile.getAbsolutePath());
                }
            }
        }
    }

    String classpath = cp.toString();
    debug("cl=" + classpath);
    argsList.add(classpath);
    argsList.addAll(sourcePathElements);
    String[] args = argsList.toArray(new String[argsList.size()]);
    List<MojoDescriptor> descriptors = new ArrayList<MojoDescriptor>();
    MojoDescriptorTls.setDescriptors(descriptors);
    try {
        Main.process(new MojoApf(pluginDescriptor), new PrintWriter(System.out), args);
    } catch (Throwable t) {
        //TODO: [by yl] This is never caught - apt swallows the exception.
        //Use the TLS to hold thrown exception
        throw new InvalidPluginDescriptorException("Failed to extract plugin descriptor.", t);
    }
    return MojoDescriptorTls.getDescriptors();
}