@Override public boolean accept(Dependency dependency) { return dependency != null && !dependency.getCoordinate().isSnapshot(); } }
public static DependencyBuilder create(final Dependency dep) { DependencyBuilder builder = new DependencyBuilder(); builder.setCoordinate(dep.getCoordinate()); builder.setScopeType(dep.getScopeType()); return builder; }
public static CoordinateBuilder create(Coordinate c) { CoordinateBuilder builder = create(); builder.setGroupId(c.getGroupId()).setArtifactId(c.getArtifactId()); builder.setClassifier(c.getClassifier()).setPackaging(c.getPackaging()).setVersion(c.getVersion()); return builder; }
public MavenDependencyAdapter(final Dependency dep) { if (dep == null) { throw new IllegalArgumentException("Dependency must not be null."); } this.setArtifactId(dep.getCoordinate().getArtifactId()); this.setGroupId(dep.getCoordinate().getGroupId()); this.setVersion(dep.getCoordinate().getVersion()); this.setScope(dep.getScopeType()); this.setType(dep.getCoordinate().getPackaging()); this.setClassifier(dep.getCoordinate().getClassifier()); this.setSystemPath(dep.getCoordinate().getSystemPath()); if (dep.getExcludedCoordinates() != null) { for (Coordinate exclusion : dep.getExcludedCoordinates()) { Exclusion temp = new Exclusion(); temp.setArtifactId(exclusion.getArtifactId()); temp.setGroupId(exclusion.getGroupId()); this.getExclusions().add(temp); } } }
/** * Creates a {@link DependencyQueryBuilder} based on a {@link DependencyQuery} */ public static DependencyQueryBuilder create(DependencyQuery query) { DependencyQueryBuilder builder = new DependencyQueryBuilder(); builder.setCoordinate(query.getCoordinate()); builder.setFilter(query.getDependencyFilter()); builder.setRepositories(query.getDependencyRepositories()); builder.setScopeType(query.getScopeType()); return builder; }
static Artifact coordinateToMavenArtifact(final Coordinate dep) { Artifact artifact = new DefaultArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getClassifier(), dep.getPackaging() == null ? "jar" : dep.getPackaging(), dep.getVersion()); return artifact; }
Coordinate dep = query.getCoordinate(); try String version = dep.getVersion(); if (version == null || version.isEmpty()) dep = CoordinateBuilder.create(dep).setVersion("[,)"); dep = CoordinateBuilder.create(dep).setVersion("[" + version + "]"); List<RemoteRepository> remoteRepos = convertToMavenRepos(query.getDependencyRepositories(), settings); if (remoteRepos.isEmpty()) remoteRepos = convertToMavenRepos( Arrays.asList(new DependencyRepository("central", "http://repo1.maven.org/maven2")), settings); remoteRepos.addAll(container.getEnabledRepositoriesFromProfile(settings));
@Override public List<Coordinate> resolveVersions(DependencyQuery query) { VersionRangeResult r = getVersions(query); List<Coordinate> result = new ArrayList<Coordinate>(); Predicate<Dependency> filter = query.getDependencyFilter(); for (Version v : r.getVersions()) { CoordinateBuilder coord = CoordinateBuilder.create(query.getCoordinate()).setVersion(v.toString()); DependencyBuilder versionedDep = DependencyBuilder.create().setCoordinate(coord); if (filter == null || filter.accept(versionedDep)) { result.add(coord); } } return result; }
/** * Compare the {@link Coordinate} of each given {@link Dependency} for equivalence. */ public static boolean areEquivalent(Dependency l, Dependency r) { if (l == r) { return true; } if ((l == null) && (r == null)) { return true; } else if ((l == null) || (r == null)) { return false; } return !(l.getCoordinate().getArtifactId() != null ? !l.getCoordinate().getArtifactId() .equals(r.getCoordinate().getArtifactId()) : r.getCoordinate().getArtifactId() != null) && !(l.getCoordinate().getGroupId() != null ? !l.getCoordinate().getGroupId() .equals(r.getCoordinate().getGroupId()) : r.getCoordinate().getGroupId() != null) && !(l.getCoordinate().getClassifier() != null ? !l.getCoordinate().getClassifier() .equals(r.getCoordinate().getClassifier()) : r.getCoordinate().getClassifier() != null); } /**
/** * Compare the {@link Coordinate} of each given {@link Dependency} for equivalence. */ public static boolean areEquivalent(Coordinate l, Coordinate r) { if (l == r) { return true; } if ((l == null) && (r == null)) { return true; } else if ((l == null) || (r == null)) { return false; } return !(l.getArtifactId() != null ? !l.getArtifactId() .equals(r.getArtifactId()) : r.getArtifactId() != null) && !(l.getGroupId() != null ? !l.getGroupId() .equals(r.getGroupId()) : r.getGroupId() != null) && !(l.getClassifier() != null ? !l.getClassifier() .equals(r.getClassifier()) : r.getClassifier() != null); }
@Override public Dependency installManaged(Project project, Dependency dependency) { DependencyFacet deps = project.getFacet(DependencyFacet.class); if (Strings.isNullOrEmpty(dependency.getCoordinate().getVersion())) { // we didn't request a specific version updateManagedDependency(deps, dependency); } else { // we requested a specific version updateManagedDependency(deps, dependency); } return dependency; }
private static void prettyPrint(DependencyNode node, Predicate<DependencyNode> filter, StringBuilder builder, int depth) { if (filter.accept(node)) { for (int i = 0; i < depth; i++) { builder.append(" "); } if (depth > 0) { builder.append("|-"); } builder.append(node.getDependency()) .append(" (") .append(node.getDependency().getScopeType()) .append(")\n"); for (DependencyNode child : node.getChildren()) { prettyPrint(child, filter, builder, depth + 1); } } }
@Override public boolean traverseDependency(org.sonatype.aether.graph.Dependency dependency) { if (query.getScopeType() != null) return query.getScopeType().equals(dependency.getScope()); else return !"test".equals(dependency.getScope()); }
/** * Check if the {@link Dependency} object is pointing to a Forge Addon artifact * * @param coordinate * @return */ public static boolean isForgeAddon(Coordinate coordinate) { return FORGE_ADDON_CLASSIFIER.equals(coordinate.getClassifier()); }
private static void selectInternal(DependencyNode root, Predicate<DependencyNode> filter, List<DependencyNode> collector) { if (filter.accept(root)) { collector.add(root); for (DependencyNode child : root.getChildren()) { selectInternal(child, filter, collector); } } }
static RemoteRepository convertToMavenRepo(final DependencyRepository repo, final Settings settings) { RemoteRepository remoteRepository = new RemoteRepository(repo.getId(), "default", repo.getUrl()); Proxy activeProxy = settings.getActiveProxy(); if (activeProxy != null) { Authentication auth = new Authentication(activeProxy.getUsername(), activeProxy.getPassword()); remoteRepository.setProxy(new org.sonatype.aether.repository.Proxy(activeProxy.getProtocol(), activeProxy .getHost(), activeProxy.getPort(), auth)); } return remoteRepository; }
public PostorderIterator(DependencyNode node) { this.root = node; this.children = node.getChildren().iterator(); subtree = Collections.<DependencyNode> emptyList().iterator(); }
@Override public boolean traverseDependency(org.sonatype.aether.graph.Dependency dependency) { boolean isForgeAddon = DependencyNodeUtil.FORGE_ADDON_CLASSIFIER.equals(dependency.getArtifact() .getClassifier()); // We don't want to traverse non-addons optional dependencies if (!isForgeAddon && dependency.isOptional()) { return false; } boolean result; if (query.getScopeType() != null) { result = query.getScopeType().equals(dependency.getScope()); } else { result = !"test".equals(dependency.getScope()); } return result; }
@Override public DependencyNode next() { Iterator<DependencyNode> it = stack.peek(); DependencyNode node = it.next(); Iterator<DependencyNode> itChildren = node.getChildren().iterator(); if (!it.hasNext()) { stack.pop(); } if (itChildren.hasNext()) { stack.push(itChildren); } return node; }
@Override public DependencyNode next() { Iterator<DependencyNode> it = queue.element(); DependencyNode node = it.next(); Iterator<DependencyNode> itChildren = node.getChildren().iterator(); if (!it.hasNext()) { queue.poll(); } if (itChildren.hasNext()) { queue.add(itChildren); } return node; }