use of org.apache.maven.model.Dependency in project robolectric by robolectric.
the class MavenDependencyResolverTest method getLocalArtifactUrl_shouldAddDependencyToDependenciesTask.
@Test
public void getLocalArtifactUrl_shouldAddDependencyToDependenciesTask() {
DependencyResolver dependencyResolver = createResolver();
DependencyJar dependencyJar = new DependencyJar("group1", "artifact1", "3", null);
dependencyResolver.getLocalArtifactUrl(dependencyJar);
List<Dependency> dependencies = dependenciesTask.getDependencies();
assertEquals(1, dependencies.size());
Dependency dependency = dependencies.get(0);
assertEquals("group1", dependency.getGroupId());
assertEquals("artifact1", dependency.getArtifactId());
assertEquals("3", dependency.getVersion());
assertEquals("jar", dependency.getType());
assertNull(dependency.getClassifier());
}
use of org.apache.maven.model.Dependency in project camel by apache.
the class BomGeneratorMojo method overwriteDependencyManagement.
private void overwriteDependencyManagement(Document pom, List<Dependency> dependencies) throws Exception {
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile("/project/dependencyManagement/dependencies");
NodeList nodes = (NodeList) expr.evaluate(pom, XPathConstants.NODESET);
if (nodes.getLength() == 0) {
throw new IllegalStateException("No dependencies found in the dependencyManagement section of the current pom");
}
Node dependenciesSection = nodes.item(0);
// cleanup the dependency management section
while (dependenciesSection.hasChildNodes()) {
Node child = dependenciesSection.getFirstChild();
dependenciesSection.removeChild(child);
}
for (Dependency dep : dependencies) {
Element dependencyEl = pom.createElement("dependency");
Element groupIdEl = pom.createElement("groupId");
groupIdEl.setTextContent(dep.getGroupId());
dependencyEl.appendChild(groupIdEl);
Element artifactIdEl = pom.createElement("artifactId");
artifactIdEl.setTextContent(dep.getArtifactId());
dependencyEl.appendChild(artifactIdEl);
Element versionEl = pom.createElement("version");
versionEl.setTextContent(dep.getVersion());
dependencyEl.appendChild(versionEl);
if (!"jar".equals(dep.getType())) {
Element typeEl = pom.createElement("type");
typeEl.setTextContent(dep.getType());
dependencyEl.appendChild(typeEl);
}
if (dep.getClassifier() != null) {
Element classifierEl = pom.createElement("classifier");
classifierEl.setTextContent(dep.getClassifier());
dependencyEl.appendChild(classifierEl);
}
if (dep.getScope() != null && !"compile".equals(dep.getScope())) {
Element scopeEl = pom.createElement("scope");
scopeEl.setTextContent(dep.getScope());
dependencyEl.appendChild(scopeEl);
}
if (dep.getExclusions() != null && !dep.getExclusions().isEmpty()) {
Element exclsEl = pom.createElement("exclusions");
for (Exclusion e : dep.getExclusions()) {
Element exclEl = pom.createElement("exclusion");
Element groupIdExEl = pom.createElement("groupId");
groupIdExEl.setTextContent(e.getGroupId());
exclEl.appendChild(groupIdExEl);
Element artifactIdExEl = pom.createElement("artifactId");
artifactIdExEl.setTextContent(e.getArtifactId());
exclEl.appendChild(artifactIdExEl);
exclsEl.appendChild(exclEl);
}
dependencyEl.appendChild(exclsEl);
}
dependenciesSection.appendChild(dependencyEl);
}
}
use of org.apache.maven.model.Dependency in project camel by apache.
the class BomGeneratorMojo method checkConflictsWithExternalBoms.
private void checkConflictsWithExternalBoms(Collection<Dependency> dependencies, Set<String> external) throws MojoFailureException {
Set<String> errors = new TreeSet<>();
for (Dependency d : dependencies) {
String key = comparisonKey(d);
if (external.contains(key)) {
errors.add(key);
}
}
if (errors.size() > 0) {
StringBuilder msg = new StringBuilder();
msg.append("Found ").append(errors.size()).append(" conflicts between the current managed dependencies and the external BOMS:\n");
for (String error : errors) {
msg.append(" - ").append(error).append("\n");
}
throw new MojoFailureException(msg.toString());
}
}
use of org.apache.maven.model.Dependency in project camel by apache.
the class ValidateMojo method findCamelVersion.
// CHECKSTYLE:ON
private static String findCamelVersion(MavenProject project) {
Dependency candidate = null;
List list = project.getDependencies();
for (Object obj : list) {
Dependency dep = (Dependency) obj;
if ("org.apache.camel".equals(dep.getGroupId())) {
if ("camel-core".equals(dep.getArtifactId())) {
// favor camel-core
candidate = dep;
break;
} else {
candidate = dep;
}
}
}
if (candidate != null) {
return candidate.getVersion();
}
return null;
}
use of org.apache.maven.model.Dependency in project camel by apache.
the class RunMojo method detectBlueprintOnClassPathOrBlueprintXMLFiles.
@SuppressWarnings("unchecked")
private boolean detectBlueprintOnClassPathOrBlueprintXMLFiles() {
List<Dependency> deps = project.getCompileDependencies();
for (Dependency dep : deps) {
if ("org.apache.camel".equals(dep.getGroupId()) && "camel-blueprint".equals(dep.getArtifactId())) {
getLog().info("camel-blueprint detected on classpath");
}
}
// maybe there is blueprint XML files
List<Resource> resources = project.getResources();
for (Resource res : resources) {
File dir = new File(res.getDirectory());
File xml = new File(dir, "OSGI-INF/blueprint");
if (xml.exists() && xml.isDirectory()) {
getLog().info("OSGi Blueprint XML files detected in directory " + xml);
return true;
}
}
return false;
}
Aggregations