コード例 #1
0
  private void assertDependencies(List<Dependency> deps) {
    assertEquals(4, deps.size());

    Dependency dep = deps.get(0);
    assertEquals("scope", dep.getScope());
    assertEquals(false, dep.isOptional());
    assertEquals(2, dep.getExclusions().size());
    Iterator<Exclusion> it = dep.getExclusions().iterator();
    Exclusion excl = it.next();
    assertEquals("gid3", excl.getGroupId());
    assertEquals("aid", excl.getArtifactId());
    excl = it.next();
    assertEquals("gid2", excl.getGroupId());
    assertEquals("aid2", excl.getArtifactId());

    Artifact art = dep.getArtifact();
    assertEquals("gid", art.getGroupId());
    assertEquals("aid", art.getArtifactId());
    assertEquals("ver", art.getVersion());
    assertEquals("ext", art.getExtension());

    dep = deps.get(1);
    assertEquals("scope", dep.getScope());
    assertEquals(true, dep.isOptional());
    assertEquals(0, dep.getExclusions().size());

    art = dep.getArtifact();
    assertEquals("gid", art.getGroupId());
    assertEquals("aid2", art.getArtifactId());
    assertEquals("ver", art.getVersion());
    assertEquals("ext", art.getExtension());

    dep = deps.get(2);
    assertEquals("scope", dep.getScope());
    assertEquals(true, dep.isOptional());
    assertEquals(0, dep.getExclusions().size());

    art = dep.getArtifact();
    assertEquals("gid", art.getGroupId());
    assertEquals("aid", art.getArtifactId());
    assertEquals("ver3", art.getVersion());
    assertEquals("ext", art.getExtension());

    dep = deps.get(3);
    assertEquals("scope5", dep.getScope());
    assertEquals(true, dep.isOptional());
    assertEquals(0, dep.getExclusions().size());

    art = dep.getArtifact();
    assertEquals("gid1", art.getGroupId());
    assertEquals("aid", art.getArtifactId());
    assertEquals("ver", art.getVersion());
    assertEquals("ext", art.getExtension());
  }
コード例 #2
0
ファイル: Classpath.java プロジェクト: jsenko/jcabi
 /**
  * Artifact exists in collection?
  *
  * @param artifact The artifact
  * @param artifacts Collection of them
  * @return TRUE if it is already there
  */
 private static boolean contains(final Artifact artifact, final Collection<Artifact> artifacts) {
   boolean contains = false;
   for (Artifact exists : artifacts) {
     if (artifact.getArtifactId().equals(exists.getArtifactId())
         && artifact.getGroupId().equals(exists.getGroupId())
         && artifact.getClassifier().equals(exists.getClassifier())) {
       contains = true;
       break;
     }
   }
   return contains;
 }
コード例 #3
0
  public File findArtifact(Artifact artifact) {
    MavenJPackageDepmap.debug(
        "=============JAVADIRREADER-FIND_ARTIFACT: " + artifact.getArtifactId());
    StringBuffer path = new StringBuffer();

    String artifactId = artifact.getArtifactId();
    String groupId = artifact.getGroupId();
    String version = artifact.getVersion();

    MavenJPackageDepmap.debug("Wanted GROUPID=" + groupId);
    MavenJPackageDepmap.debug("Wanted ARTIFACTID=" + artifactId);

    if (!groupId.startsWith("JPP")) {
      MavenJPackageDepmap map = MavenJPackageDepmap.getInstance();
      Hashtable<String, String> newInfo = map.getMappedInfo(groupId, artifactId, version);

      groupId = (String) newInfo.get("group");
      artifactId = (String) newInfo.get("artifact");
    }
    MavenJPackageDepmap.debug("Resolved GROUPID=" + groupId);
    MavenJPackageDepmap.debug("Resolved ARTIFACTID=" + artifactId);

    if (artifact.getExtension().equals("pom")) {
      path = getPOMPath(groupId, artifactId);
    } else if (artifact.getExtension().equals("signature")) {
      path.append("/usr/share/maven/repository/");
      path.append(groupId).append('/');
      path.append(artifactId).append(".signature");
    } else if (artifact.getExtension().equals("zip")) {
      path.append("/usr/share/maven/repository/");
      path.append(groupId).append('/');
      path.append(artifactId).append(".zip");
    } else {
      path.append("/usr/share/maven/repository/");
      path.append(groupId).append('/');
      path.append(artifactId).append(".jar");
    }

    MavenJPackageDepmap.debug("Returning " + path.toString());
    File ret = new File(path.toString());
    // if file doesn't exist return null to delegate to other
    // resolvers (reactor/local repo)
    if (ret.isFile()) {
      MavenJPackageDepmap.debug("Returning " + path.toString());
      return ret;
    } else {
      MavenJPackageDepmap.debug("Returning null for gid:aid =>" + groupId + ":" + artifactId);
      return null;
    }
  }
コード例 #4
0
ファイル: DependencyId.java プロジェクト: WillemJiang/fabric8
 public static DependencyId newInstance(Artifact artifact) {
   return new DependencyId(
       artifact.getGroupId(),
       artifact.getArtifactId(),
       artifact.getClassifier(),
       artifact.getExtension());
 }
コード例 #5
0
  @Test
  public void testLookup() throws ArtifactDescriptorException {
    StubArtifact art = new StubArtifact("gid:aid:ext:ver");
    ArtifactDescriptorRequest request = new ArtifactDescriptorRequest(art, null, "");
    ArtifactDescriptorResult description = reader.readArtifactDescriptor(session, request);

    assertEquals(request, description.getRequest());
    assertEquals(art, description.getArtifact());

    assertEquals(1, description.getRelocations().size());
    Artifact artifact = description.getRelocations().get(0);
    assertEquals("gid", artifact.getGroupId());
    assertEquals("aid", artifact.getArtifactId());
    assertEquals("ver", artifact.getVersion());
    assertEquals("ext", artifact.getExtension());

    assertEquals(1, description.getRepositories().size());
    RemoteRepository repo = description.getRepositories().get(0);
    assertEquals("id", repo.getId());
    assertEquals("type", repo.getContentType());
    assertEquals("protocol://some/url?for=testing", repo.getUrl());

    assertDependencies(description.getDependencies());
    assertDependencies(description.getManagedDependencies());
  }
コード例 #6
0
  @Override
  public DependencyMetadata resolveDependencyMetadata(
      Dependency query, final List<DependencyRepository> repositories) {
    try {
      if (Strings.isNullOrEmpty(query.getVersion())) {
        query = DependencyBuilder.create(query).setVersion("[,)");
      }

      RepositorySystem system = container.lookup(RepositorySystem.class);
      MavenRepositorySystemSession session = setupRepoSession(system);

      DefaultArtifact artifact = new DefaultArtifact(query.toCoordinates());

      ArtifactDescriptorRequest ar =
          new ArtifactDescriptorRequest(artifact, convertToMavenRepos(repositories), null);
      ArtifactDescriptorResult results = system.readArtifactDescriptor(session, ar);

      Artifact a = results.getArtifact();
      Dependency d =
          DependencyBuilder.create()
              .setArtifactId(a.getArtifactId())
              .setGroupId(a.getGroupId())
              .setVersion(a.getVersion());

      return new DependencyMetadataImpl(d, results);
    } catch (Exception e) {
      throw new ProjectModelException(
          "Unable to resolve any artifacts for query [" + query + "]", e);
    }
  }
コード例 #7
0
 /**
  * Converts an Aether artifact to a Maven model dependency.
  *
  * @param artifact the Aether artifact to be converted
  * @return a Maven dependency with the same coordinates
  */
 private Dependency artifactToDependency(Artifact artifact) {
   final Dependency dependency = new Dependency();
   dependency.setGroupId(artifact.getGroupId());
   dependency.setArtifactId(artifact.getArtifactId());
   dependency.setVersion(artifact.getVersion());
   dependency.setType(artifact.getExtension());
   return dependency;
 }
コード例 #8
0
 private static String getId(Artifact artifact) {
   return getId(
       artifact.getGroupId(),
       artifact.getArtifactId(),
       artifact.getExtension(),
       artifact.getClassifier(),
       artifact.getBaseVersion());
 }
コード例 #9
0
  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();

      final DependencyRequest dependencyRequest =
          new DependencyRequest(
              node,
              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.sonatype.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);
    }
  }
コード例 #10
0
  @Test
  public void testDefaultArtifactString() {
    Artifact a;

    a = new DefaultArtifact("gid:aid:ver");
    assertEquals("gid", a.getGroupId());
    assertEquals("aid", a.getArtifactId());
    assertEquals("ver", a.getVersion());
    assertEquals("jar", a.getExtension());
    assertEquals("", a.getClassifier());

    a = new DefaultArtifact("gid:aid:ext:ver");
    assertEquals("gid", a.getGroupId());
    assertEquals("aid", a.getArtifactId());
    assertEquals("ver", a.getVersion());
    assertEquals("ext", a.getExtension());
    assertEquals("", a.getClassifier());

    a = new DefaultArtifact("gid:aid:ext:cls:ver");
    assertEquals("gid", a.getGroupId());
    assertEquals("aid", a.getArtifactId());
    assertEquals("ver", a.getVersion());
    assertEquals("ext", a.getExtension());
    assertEquals("cls", a.getClassifier());

    a = new DefaultArtifact("gid:aid::cls:ver");
    assertEquals("gid", a.getGroupId());
    assertEquals("aid", a.getArtifactId());
    assertEquals("ver", a.getVersion());
    assertEquals("jar", a.getExtension());
    assertEquals("cls", a.getClassifier());

    a = new DefaultArtifact(new DefaultArtifact("gid:aid:ext:cls:ver").toString());
    assertEquals("gid", a.getGroupId());
    assertEquals("aid", a.getArtifactId());
    assertEquals("ver", a.getVersion());
    assertEquals("ext", a.getExtension());
    assertEquals("cls", a.getClassifier());
  }
コード例 #11
0
 public String getArtifactId() {
   return artifact.getArtifactId();
 }