org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException Java Examples

The following examples show how to use org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException. 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: FakeTimeMojo.java    From faketime with MIT License 6 votes vote down vote up
private void unpackAgent() {
  try {
    Artifact artifact = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), getAgentArtifactCoordinate()).getArtifact();

    getTargetDirectory().mkdirs();

    UnArchiver unArchiver = archiverManager.getUnArchiver(artifact.getType());
    unArchiver.setSourceFile(artifact.getFile());
    unArchiver.setDestDirectory(getTargetDirectory());
    unArchiver.setFileSelectors(getAgentBinaryFileSelector());
    unArchiver.extract();
  }
  catch (ArtifactResolverException | NoSuchArchiverException e) {
    throw new RuntimeException(e);
  }
}
 
Example #2
Source File: ArtifactTransformer.java    From component-runtime with Apache License 2.0 5 votes vote down vote up
private ArtifactResult doResolve(final ArtifactResolver resolver, final Artifact art, final MavenSession session)
        throws ArtifactResolverException {
    final ProjectBuildingRequest request = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
    session
            .getTopLevelProject()
            .getPluginRepositories()
            .stream()
            .map(this::toArtifactRepo)
            .filter(it -> request
                    .getPluginArtifactRepositories()
                    .stream()
                    .noneMatch(a -> String.valueOf(a.getId()).equalsIgnoreCase(it.getId())))
            .forEach(it -> request.getRemoteRepositories().add(it));
    return resolver.resolveArtifact(request, art);
}
 
Example #3
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;
  }