예제 #1
0
  private static boolean equals(
      org.eclipse.aether.artifact.Artifact a1, org.eclipse.aether.artifact.Artifact a2) {
    if (a1 == a2) {
      return true;
    }

    return a1.getArtifactId().equals(a2.getArtifactId())
        && a1.getGroupId().equals(a2.getGroupId())
        && a1.getVersion().equals(a2.getVersion())
        && a1.getExtension().equals(a2.getExtension())
        && a1.getClassifier().equals(a2.getClassifier());
  }
  private Artifact unify(Artifact dependent, Artifact dependency) {
    for (Entry<String, String> unification : unified.entrySet()) {
      String groupFilter = unification.getKey();
      String version = unification.getValue();
      String artifactId = dependency.toString();

      if ("".equals(version)) {
        version = dependent.getVersion();
      }
      if (artifactId.startsWith(groupFilter) && (!"".equals(version))) {
        Artifact retVal =
            new DefaultArtifact(
                dependency.getGroupId(),
                dependency.getArtifactId(),
                dependency.getClassifier(),
                dependency.getExtension(),
                // The important one
                version);
        retVal.setProperties(dependency.getProperties());
        return retVal;
      }
    }

    return dependency;
  }
예제 #3
0
  public List<ArtifactResult> resolveArtifacts(
      RepositorySystemSession session, Collection<? extends ArtifactRequest> requests)
      throws ArtifactResolutionException {
    List<ArtifactResult> results = new ArrayList<ArtifactResult>();

    for (ArtifactRequest request : requests) {
      ArtifactResult result = new ArtifactResult(request);
      results.add(result);

      Artifact artifact = request.getArtifact();
      if ("maven-test".equals(artifact.getGroupId())) {
        String scope = artifact.getArtifactId().substring("scope-".length());

        try {
          artifact =
              artifact.setFile(
                  ProjectClasspathTest.getFileForClasspathResource(
                      ProjectClasspathTest.dir + "transitive-" + scope + "-dep.xml"));
          result.setArtifact(artifact);
        } catch (FileNotFoundException e) {
          throw new IllegalStateException("Missing test POM for " + artifact);
        }
      } else {
        result.addException(new ArtifactNotFoundException(artifact, null));
        throw new ArtifactResolutionException(results);
      }
    }

    return results;
  }
예제 #4
0
 @Override
 public void packageResolveFailed(DependencyResolutionException exception) {
   clearProgressBar();
   Artifact artifact = exception.getResult().getRoot().getArtifact();
   try {
     reader.println(
         String.format(
             "Could not resolve dependencies for %s.%s version %s",
             artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()));
     reader.println("The following artifacts could not be located:");
     for (ArtifactResult result : exception.getResult().getArtifactResults()) {
       if (result.isMissing()) {
         reader.println("* " + result.getRequest().getArtifact());
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 private String artifactAsString(Artifact artifact) {
   return Settings.GAV_JOINER.join(
       artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
 }
예제 #6
0
 public String getGroupId() {
   return delegate.getGroupId();
 }
  public DependentLoaderImplementation enshureJarLoaded(Artifact _artifactId) {
    Artifact artifactId = unify(_artifactId);

    if ("dependent".equals(artifactId.getArtifactId())
        && "no.dbwatch".equals(artifactId.getGroupId())) {
      return null;
    }
    DependentLoaderImplementation theLoader = findOverride(artifactId);
    if (theLoader != null) {
      visitLoader(theLoader);
      return theLoader;
    }
    if (loaderMap.containsKey(toString(artifactId))) return loaderMap.get(toString(artifactId));
    // Fetch jar and dependencies.
    OutputBouble bouble = OutputBouble.push();

    try {
      Result<File> localFileName = dependencyManager.getLocalFile(artifactId);

      if (localFileName.success())
        theLoader =
            new DependentLoaderImplementation(
                artifactId,
                localFileName.val.getAbsoluteFile().toURI().toURL(),
                exposed,
                parentLoader);
      else theLoader = new DependentLoaderImplementation(artifactId, exposed, parentLoader);
      setLoader(theLoader);

      List<Artifact> dependencies = dependencyManager.getDirectDependencies(artifactId);

      DependentLoaderImplementation[] actualDependencies =
          new DependentLoaderImplementation[dependencies.size() + theLoader.dependencies.length];
      int i = 0;
      for (DependentLoaderImplementation dependencyFromConf : theLoader.dependencies) {
        actualDependencies[i++] = dependencyFromConf;
      }
      for (Artifact dependencyId : dependencies) {

        DependentLoaderImplementation loader = enshureDependencyJarLoaded(artifactId, dependencyId);
        if (loader == null) {
          OutputBouble.logFile.println(artifactId.toString() + ":");
          OutputBouble.logFile.println("\t Missing dependency " + dependencyId.toString());
          OutputBouble.logFile.println("\t Ignoring");
        } else {
          actualDependencies[i++] = loader;
        }
      }
      if (actualDependencies.length > i) {
        actualDependencies = Arrays.copyOf(actualDependencies, i);
      }

      theLoader.setDependencies(actualDependencies);

      extraDependencies.loaderAdded(theLoader);

      visitLoader(theLoader);
      return theLoader;
    } catch (Exception e) {
      OutputBouble.reportError(e);
      return theLoader;
    } finally {
      bouble.pop();
      if (bouble.isError) bouble.writeToParent();
    }
    // return null;
  }
  @Override
  public void resolveProjectDependencies(
      final IMavenProjectFacade facade,
      Set<Capability> capabilities,
      Set<RequiredCapability> requirements,
      final IProgressMonitor monitor)
      throws CoreException {
    long start = System.currentTimeMillis();
    log.debug("Resolving dependencies for {}", facade.toString()); // $NON-NLS-1$

    markerManager.deleteMarkers(facade.getPom(), IMavenConstants.MARKER_DEPENDENCY_ID);

    ProjectBuildingRequest configuration =
        getMaven().getExecutionContext().newProjectBuildingRequest();
    configuration.setProject(facade.getMavenProject()); // TODO do we need this?
    configuration.setResolveDependencies(true);
    MavenExecutionResult mavenResult =
        getMaven().readMavenProject(facade.getPomFile(), configuration);

    markerManager.addMarkers(facade.getPom(), IMavenConstants.MARKER_DEPENDENCY_ID, mavenResult);

    if (!facade.getResolverConfiguration().shouldResolveWorkspaceProjects()) {
      return;
    }

    MavenProject mavenProject = facade.getMavenProject();

    // dependencies

    // resolved dependencies
    for (Artifact artifact : mavenProject.getArtifacts()) {
      requirements.add(
          MavenRequiredCapability.createMavenArtifact(
              new ArtifactKey(artifact), artifact.getScope(), artifact.isOptional()));
    }

    // extension plugins (affect packaging type calculation)
    for (Plugin plugin : mavenProject.getBuildPlugins()) {
      if (plugin.isExtensions()) {
        ArtifactKey artifactKey =
            new ArtifactKey(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), null);
        requirements.add(
            MavenRequiredCapability.createMavenArtifact(
                artifactKey, "plugin", false)); // $NON-NLS-1$
      }
    }

    // missing dependencies
    DependencyResolutionResult resolutionResult = mavenResult.getDependencyResolutionResult();
    if (resolutionResult != null && resolutionResult.getUnresolvedDependencies() != null) {
      for (Dependency dependency : resolutionResult.getUnresolvedDependencies()) {
        org.eclipse.aether.artifact.Artifact artifact = dependency.getArtifact();
        ArtifactKey dependencyKey =
            new ArtifactKey(
                artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), null);
        requirements.add(
            MavenRequiredCapability.createMavenArtifact(
                dependencyKey, dependency.getScope(), dependency.isOptional()));
      }
    }

    log.debug(
        "Resolved dependencies for {} in {} ms",
        facade.toString(),
        System.currentTimeMillis() - start); // $NON-NLS-1$
  }
  private Set<Artifact> processTransientDependencies(Dependency dependency, boolean sharedLibraries)
      throws MojoExecutionException {
    try {
      final Set<Artifact> artifacts = new LinkedHashSet<Artifact>();

      final CollectRequest collectRequest = new CollectRequest();

      collectRequest.setRoot(dependency);
      collectRequest.setRepositories(projectRepos);
      final DependencyNode node =
          repoSystem.collectDependencies(repoSession, collectRequest).getRoot();

      Collection<String> exclusionPatterns = new ArrayList<String>();
      if (dependency.getExclusions() != null && !dependency.getExclusions().isEmpty()) {
        for (Exclusion exclusion : dependency.getExclusions()) {
          exclusionPatterns.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
        }
      }

      final DependencyRequest dependencyRequest =
          new DependencyRequest(
              node,
              new AndDependencyFilter(
                  new ExclusionsDependencyFilter(exclusionPatterns),
                  new AndDependencyFilter(
                      new ScopeDependencyFilter(
                          Arrays.asList("compile", "runtime"), Arrays.asList("test")),
                      // Also exclude any optional dependencies
                      new DependencyFilter() {
                        @Override
                        public boolean accept(
                            DependencyNode dependencyNode, List<DependencyNode> dependencyNodes) {
                          return !dependencyNode.getDependency().isOptional();
                        }
                      })));

      repoSystem.resolveDependencies(repoSession, dependencyRequest);

      PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
      node.accept(nlg);

      final List<Dependency> dependencies = nlg.getDependencies(false);

      for (Dependency dep : dependencies) {
        final org.eclipse.aether.artifact.Artifact depAetherArtifact = dep.getArtifact();
        if (isNativeLibrary(sharedLibraries, depAetherArtifact.getExtension())) {
          final Artifact mavenArtifact =
              artifactFactory.createDependencyArtifact(
                  depAetherArtifact.getGroupId(),
                  depAetherArtifact.getArtifactId(),
                  VersionRange.createFromVersion(depAetherArtifact.getVersion()),
                  depAetherArtifact.getExtension(),
                  depAetherArtifact.getClassifier(),
                  dep.getScope());
          mavenArtifact.setFile(depAetherArtifact.getFile());
          artifacts.add(mavenArtifact);
        }
      }

      return artifacts;
    } catch (Exception e) {
      throw new MojoExecutionException("Error while processing transient dependencies", e);
    }
  }