public static Set<Dependency> findCustomCamelArtifacts(Project project) { Set<Dependency> answer = new LinkedHashSet<Dependency>(); List<Dependency> dependencies = project.getFacet(DependencyFacet.class).getEffectiveDependencies(); for (Dependency d : dependencies) { if (isCamelComponentArtifact(d)) { answer.add(d); } } return answer; }
public static Set<Dependency> findCamelArtifacts(Project project) { Set<Dependency> answer = new LinkedHashSet<Dependency>(); List<Dependency> dependencies = project.getFacet(DependencyFacet.class).getEffectiveDependencies(); for (Dependency d : dependencies) { if ("org.apache.camel".equals(d.getCoordinate().getGroupId())) { answer.add(d); } } return answer; }
public static Dependency findCamelArtifactDependency(Project project, String artifactId) { List<Dependency> dependencies = project.getFacet(DependencyFacet.class).getEffectiveDependencies(); for (Dependency d : dependencies) { if ("org.apache.camel".equals(d.getCoordinate().getGroupId()) && artifactId.equals(d.getCoordinate().getArtifactId())) { return d; } } return null; }
DependencyFacet facet = project.getFacet(DependencyFacet.class); List<Dependency> effectiveDependencies = facet .getEffectiveDependencies(); List<URL> urls = new ArrayList<>();
public static boolean hasDependency(Project project, String groupId, String artifactId, String version) { List<Dependency> dependencies = project.getFacet(DependencyFacet.class).getEffectiveDependencies(); for (Dependency d : dependencies) { boolean match = d.getCoordinate().getGroupId().equals(groupId); if (match && artifactId != null) { match = d.getCoordinate().getArtifactId().equals(artifactId); } if (match && version != null) { match = d.getCoordinate().getVersion().equals(version); } if (match) { return match; } } return false; }
public static Dependency getOrAddDependency(Project project, String groupId, String artifactId, String version, String classifier, String scope) { DependencyFacet dependencies = project.getFacet(DependencyFacet.class); Optional<Dependency> found = dependencies.getEffectiveDependencies().stream().filter(dep -> dep.getCoordinate().getGroupId().equalsIgnoreCase(groupId) && dep.getCoordinate().getArtifactId().equalsIgnoreCase(artifactId)
/** * Returns true if the dependency was added or false if its already there */ public static boolean ensureMavenDependencyAdded(Project project, DependencyInstaller dependencyInstaller, String groupId, String artifactId, String scope) { List<Dependency> dependencies = project.getFacet(DependencyFacet.class).getEffectiveDependencies(); for (Dependency d : dependencies) { if (groupId.equals(d.getCoordinate().getGroupId()) && artifactId.equals(d.getCoordinate().getArtifactId())) { getLOG().debug("Project already includes: " + groupId + ":" + artifactId + " for version: " + d.getCoordinate().getVersion()); return false; } } DependencyBuilder component = DependencyBuilder.create(). setGroupId(groupId). setArtifactId(artifactId); if (scope != null) { component.setScopeType(scope); } String version = MavenHelpers.getVersion(groupId, artifactId); if (Strings.isNotBlank(version)) { component = component.setVersion(version); getLOG().debug("Adding pom.xml dependency: " + groupId + ":" + artifactId + " version: " + version + " scope: " + scope); } else { getLOG().debug("No version could be found for: " + groupId + ":" + artifactId); } dependencyInstaller.install(project, component); return true; }