Search in sources :

Example 1 with Dependency

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());
}
Also used : Dependency(org.apache.maven.model.Dependency) Test(org.junit.Test)

Example 2 with Dependency

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);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Exclusion(org.apache.maven.model.Exclusion) Dependency(org.apache.maven.model.Dependency)

Example 3 with Dependency

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());
    }
}
Also used : TreeSet(java.util.TreeSet) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Dependency(org.apache.maven.model.Dependency)

Example 4 with Dependency

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Dependency(org.apache.maven.model.Dependency)

Example 5 with Dependency

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;
}
Also used : Resource(org.apache.maven.model.Resource) Dependency(org.apache.maven.model.Dependency) ExecutableDependency(org.codehaus.mojo.exec.ExecutableDependency) File(java.io.File)

Aggregations

Dependency (org.apache.maven.model.Dependency)73 ArrayList (java.util.ArrayList)24 Artifact (org.apache.maven.artifact.Artifact)17 File (java.io.File)11 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 Exclusion (org.apache.maven.model.Exclusion)7 WebappStructure (org.apache.maven.plugins.war.util.WebappStructure)7 MavenProject (org.apache.maven.project.MavenProject)7 IOException (java.io.IOException)6 MojoFailureException (org.apache.maven.plugin.MojoFailureException)6 HashMap (java.util.HashMap)5 Model (org.apache.maven.model.Model)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 DependencyManagement (org.apache.maven.model.DependencyManagement)4 Plugin (org.apache.maven.model.Plugin)4 List (java.util.List)3 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)3 Test (org.junit.Test)3 MavenPublishable (com.facebook.buck.jvm.java.MavenPublishable)2