Java Code Examples for org.apache.maven.project.MavenProject#getDependencyArtifacts()

The following examples show how to use org.apache.maven.project.MavenProject#getDependencyArtifacts() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MutableMojo.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
static void resolveDependencies(final MavenSession session, final MojoExecution execution, final MojoExecutor executor, final ProjectDependenciesResolver projectDependenciesResolver) throws DependencyResolutionException, LifecycleExecutionException {
//    flushProjectArtifactsCache(executor);

    final MavenProject project = session.getCurrentProject();
    final Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
    final Map<String,List<MojoExecution>> executions = new LinkedHashMap<>(execution.getForkedExecutions());
    final ExecutionListener executionListener = session.getRequest().getExecutionListener();
    try {
      project.setDependencyArtifacts(null);
      execution.getForkedExecutions().clear();
      session.getRequest().setExecutionListener(null);
      executor.execute(session, Collections.singletonList(execution), new ProjectIndex(session.getProjects()));
    }
    finally {
      execution.getForkedExecutions().putAll(executions);
      session.getRequest().setExecutionListener(executionListener);
      project.setDependencyArtifacts(dependencyArtifacts);
    }

    projectDependenciesResolver.resolve(newDefaultDependencyResolutionRequest(session));
  }
 
Example 2
Source File: Util.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Read current project dependencies and check if it don't grab incorrect
 * artifacts versions which could be in conflict with plugin dependencies.
 *
 * @param project
 *            current project
 * @param repoSystem
 *            repository system
 * @param localRepo
 *            local repository
 * @param remoteRepos
 *            remote repositories
 */
static void checkClasspath(final MavenProject project, final RepositorySystem repoSystem,
        final ArtifactRepository localRepo, final List<ArtifactRepository> remoteRepos) {
    Plugin plugin = project.getPlugin(YangToSourcesMojo.PLUGIN_NAME);
    if (plugin == null) {
        LOG.warn("{} {} not found, dependencies version check skipped", LOG_PREFIX, YangToSourcesMojo.PLUGIN_NAME);
    } else {
        Map<Artifact, Collection<Artifact>> pluginDependencies = new HashMap<>();
        getPluginTransitiveDependencies(plugin, pluginDependencies, repoSystem, localRepo, remoteRepos);

        Set<Artifact> projectDependencies = project.getDependencyArtifacts();
        for (Map.Entry<Artifact, Collection<Artifact>> entry : pluginDependencies.entrySet()) {
            checkArtifact(entry.getKey(), projectDependencies);
            for (Artifact dependency : entry.getValue()) {
                checkArtifact(dependency, projectDependencies);
            }
        }
    }
}
 
Example 3
Source File: AjcHelper.java    From aspectj-maven-plugin with MIT License 5 votes vote down vote up
/**
 * Constructs AspectJ compiler classpath string
 *
 * @param project the Maven Project
 * @param pluginArtifacts the plugin Artifacts
 * @param outDirs the outputDirectories
 * @return a os spesific classpath string
 */
@SuppressWarnings( "unchecked" )
public static String createClassPath( MavenProject project, List<Artifact> pluginArtifacts, List<String> outDirs )
{
    String cp = new String();
    Set<Artifact> classPathElements = Collections.synchronizedSet( new LinkedHashSet<Artifact>() );
    Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
    classPathElements.addAll( dependencyArtifacts == null ? Collections.<Artifact>emptySet() : dependencyArtifacts );
    classPathElements.addAll( project.getArtifacts() );
    classPathElements.addAll( pluginArtifacts == null ? Collections.<Artifact>emptySet() : pluginArtifacts );
    for ( Artifact classPathElement  : classPathElements )
    {
        File artifact = classPathElement.getFile();
        if ( null != artifact )
        {
          String type = classPathElement.getType();
          if (!type.equals("pom")){
            cp += classPathElement.getFile().getAbsolutePath();
            cp += File.pathSeparatorChar;                
          }
        }
    }
    Iterator<String> outIter = outDirs.iterator();
    while ( outIter.hasNext() )
    {
        cp += outIter.next();
        cp += File.pathSeparatorChar;
    }

    if ( cp.endsWith( "" + File.pathSeparatorChar ) )
    {
        cp = cp.substring( 0, cp.length() - 1 );
    }

    cp = StringUtils.replace( cp, "//", "/" );
    return cp;
}
 
Example 4
Source File: DefaultDescriptorsExtractor.java    From james-project with Apache License 2.0 5 votes vote down vote up
private void logProjectDependencies(MavenProject project, Log log) {
    log.debug("Logging project dependencies");
    if (log.isDebugEnabled()) {
        @SuppressWarnings("unchecked")
        final Set<Artifact> dependencies = project.getDependencyArtifacts();
        if (dependencies == null) {
            log.debug("No project dependencies");
        } else {
            for (Artifact artifact: dependencies) {
                log.debug("DEP: " + artifact);
            }
        }
    }
}
 
Example 5
Source File: OptionLoader.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static List<WadlOption> loadWsdlOptionsFromDependencies(MavenProject project,
                                                               Option defaultOptions, File outputDir) {
    List<WadlOption> options = new ArrayList<>();
    Set<Artifact> dependencies = project.getDependencyArtifacts();
    for (Artifact artifact : dependencies) {
        WadlOption option = generateWsdlOptionFromArtifact(artifact, outputDir);
        if (option != null) {
            if (defaultOptions != null) {
                option.merge(defaultOptions);
            }
            options.add(option);
        }
    }
    return options;
}
 
Example 6
Source File: MavenUtils.java    From mvn-golang with Apache License 2.0 4 votes vote down vote up
/**
   * Scan project dependencies to find artifacts generated by mvn golang
   * project.
   *
   * @param mavenProject maven project, must not be null
   * @param includeTestDependencies flag to process dependencies marked for test
   * phases
   * @param mojo calling mojo, must not be null
   * @param session maven session, must not be null
   * @param execution maven execution, must not be null
   * @param resolver artifact resolver, must not be null
   * @param remoteRepositories list of remote repositories, must not be null
   * @return list of files found in artifacts generated by mvn golang plugin
   * @throws ArtifactResolverException exception thrown if some artifact can't
   * be resolved
   */
  @Nonnull
  @MustNotContainNull
  public static List<Tuple<Artifact, File>> scanForMvnGoArtifacts(
          @Nonnull final MavenProject mavenProject,
          final boolean includeTestDependencies,
          @Nonnull final AbstractMojo mojo,
          @Nonnull final MavenSession session,
          @Nonnull final MojoExecution execution,
          @Nonnull final ArtifactResolver resolver,
          @Nonnull @MustNotContainNull final List<ArtifactRepository> remoteRepositories
  ) throws ArtifactResolverException {
    final List<Tuple<Artifact, File>> result = new ArrayList<>();
//    final String phase = execution.getLifecyclePhase();

    final Set<String> alreadyFoundArtifactRecords = new HashSet<>();

    MavenProject currentProject = mavenProject;
    while (currentProject != null && !Thread.currentThread().isInterrupted()) {
      final Set<Artifact> projectDependencies = currentProject.getDependencyArtifacts();
      final List<Artifact> artifacts = new ArrayList<>(projectDependencies == null ? Collections.emptySet() : projectDependencies);
      mojo.getLog().debug("Detected dependency artifacts: " + artifacts);

      while (!artifacts.isEmpty() && !Thread.currentThread().isInterrupted()) {
        final Artifact artifact = artifacts.remove(0);

        if (Artifact.SCOPE_TEST.equals(artifact.getScope()) && !includeTestDependencies) {
          continue;
        }

        if (artifact.getType().equals(AbstractGolangMojo.GOARTIFACT_PACKAGING)) {
          final ArtifactResult artifactResult = resolver.resolveArtifact(makeResolveArtifactProjectBuildingRequest(session, remoteRepositories), artifact);
          final File zipFillePath = artifactResult.getArtifact().getFile();

          mojo.getLog().debug("Detected MVN-GOLANG marker inside ZIP dependency: " + artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getVersion() + ':' + artifact.getType());

          if (ZipUtil.containsEntry(zipFillePath, GolangMvnInstallMojo.MVNGOLANG_DEPENDENCIES_FILE)) {
            final byte[] artifactFlagFile = ZipUtil.unpackEntry(zipFillePath, GolangMvnInstallMojo.MVNGOLANG_DEPENDENCIES_FILE, StandardCharsets.UTF_8);

            for (final String str : new String(artifactFlagFile, StandardCharsets.UTF_8).split("\\R")) {
              if (str.trim().isEmpty() || alreadyFoundArtifactRecords.contains(str)) {
                continue;
              }
              mojo.getLog().debug("Adding mvn-golang dependency: " + str);
              alreadyFoundArtifactRecords.add(str);
              try {
                artifacts.add(parseArtifactRecord(str, new MvnGolangArtifactHandler()));
              } catch (InvalidVersionSpecificationException ex) {
                throw new ArtifactResolverException("Can't make artifact: " + str, ex);
              }
            }
          }

          final File artifactFile = artifactResult.getArtifact().getFile();
          mojo.getLog().debug("Artifact file: " + artifactFile);
          if (doesContainFile(result, artifactFile)) {
            mojo.getLog().debug("Artifact file ignored as duplication: " + artifactFile);
          } else {
            result.add(Tuple.of(artifact, artifactFile));
          }
        }
      }
      currentProject = currentProject.hasParent() ? currentProject.getParent() : null;
    }

    return result;
  }
 
Example 7
Source File: ProjectDependencies.java    From wisdom with Apache License 2.0 2 votes vote down vote up
/**
 * Creates the project dependencies instance from a Maven Project.
 *
 * @param project the maven project
 */
public ProjectDependencies(MavenProject project) {
    this(project.getDependencyArtifacts(), project.getArtifacts());
}