Search in sources :

Example 1 with TreeMojo

use of org.apache.maven.plugins.dependency.tree.TreeMojo in project maven-plugins by apache.

the class TestTreeMojo method runTreeMojo.

/**
 * Help finding content in the given list of string
 *
 * @param outputFile the outputFile.
 * @param format The format.
 * @throws Exception in case of an error.
 * @return list of strings in the output file
 */
private List<String> runTreeMojo(String outputFile, String format) throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/tree-test/plugin-config.xml");
    String outputFileName = testDir.getAbsolutePath() + outputFile;
    TreeMojo mojo = (TreeMojo) lookupMojo("tree", testPom);
    setVariableValueToObject(mojo, "outputType", format);
    setVariableValueToObject(mojo, "outputFile", new File(outputFileName));
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenProject project = mojo.getProject();
    project.setArtifact(this.stubFactory.createArtifact("testGroupId", "project", "1.0"));
    Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
    Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
    artifacts.addAll(directArtifacts);
    project.setArtifacts(artifacts);
    project.setDependencyArtifacts(directArtifacts);
    mojo.execute();
    BufferedReader fp1 = new BufferedReader(new FileReader(outputFileName));
    List<String> contents = new ArrayList<String>();
    String line;
    while ((line = fp1.readLine()) != null) {
        contents.add(line);
    }
    fp1.close();
    return contents;
}
Also used : TreeMojo(org.apache.maven.plugins.dependency.tree.TreeMojo) MavenProject(org.apache.maven.project.MavenProject) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) FileReader(java.io.FileReader) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with TreeMojo

use of org.apache.maven.plugins.dependency.tree.TreeMojo in project maven-plugins by apache.

the class TestTreeMojo method _testTreeTestEnvironment.

/**
 * Tests the proper discovery and configuration of the mojo.
 *
 * @throws Exception in case of an error.
 */
public void _testTreeTestEnvironment() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/tree-test/plugin-config.xml");
    TreeMojo mojo = (TreeMojo) lookupMojo("tree", testPom);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenProject project = mojo.getProject();
    project.setArtifact(this.stubFactory.createArtifact("testGroupId", "project", "1.0"));
    Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
    Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
    artifacts.addAll(directArtifacts);
    project.setArtifacts(artifacts);
    project.setDependencyArtifacts(directArtifacts);
    mojo.execute();
    DependencyNode rootNode = mojo.getDependencyGraph();
    assertNodeEquals("testGroupId:project:jar:1.0:compile", rootNode);
    assertEquals(2, rootNode.getChildren().size());
    assertChildNodeEquals("testGroupId:snapshot:jar:2.0-SNAPSHOT:compile", rootNode, 0);
    assertChildNodeEquals("testGroupId:release:jar:1.0:compile", rootNode, 1);
}
Also used : TreeMojo(org.apache.maven.plugins.dependency.tree.TreeMojo) MavenProject(org.apache.maven.project.MavenProject) DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 3 with TreeMojo

use of org.apache.maven.plugins.dependency.tree.TreeMojo in project maven-dependency-plugin by apache.

the class TestTreeMojo method _testTreeTestEnvironment.

/**
 * Tests the proper discovery and configuration of the mojo.
 *
 * @throws Exception in case of an error.
 */
public void _testTreeTestEnvironment() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/tree-test/plugin-config.xml");
    TreeMojo mojo = (TreeMojo) lookupMojo("tree", testPom);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenProject project = mojo.getProject();
    project.setArtifact(this.stubFactory.createArtifact("testGroupId", "project", "1.0"));
    Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
    Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
    artifacts.addAll(directArtifacts);
    project.setArtifacts(artifacts);
    project.setDependencyArtifacts(directArtifacts);
    mojo.execute();
    DependencyNode rootNode = mojo.getDependencyGraph();
    assertNodeEquals("testGroupId:project:jar:1.0:compile", rootNode);
    assertEquals(2, rootNode.getChildren().size());
    assertChildNodeEquals("testGroupId:snapshot:jar:2.0-SNAPSHOT:compile", rootNode, 0);
    assertChildNodeEquals("testGroupId:release:jar:1.0:compile", rootNode, 1);
}
Also used : TreeMojo(org.apache.maven.plugins.dependency.tree.TreeMojo) MavenProject(org.apache.maven.project.MavenProject) DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 4 with TreeMojo

use of org.apache.maven.plugins.dependency.tree.TreeMojo in project maven-dependency-plugin by apache.

the class TestTreeMojo method runTreeMojo.

/**
 * Help finding content in the given list of string
 *
 * @param outputFile the outputFile.
 * @param format The format.
 * @throws Exception in case of an error.
 * @return list of strings in the output file
 */
private List<String> runTreeMojo(String outputFile, String format) throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/tree-test/plugin-config.xml");
    String outputFileName = testDir.getAbsolutePath() + outputFile;
    TreeMojo mojo = (TreeMojo) lookupMojo("tree", testPom);
    setVariableValueToObject(mojo, "outputType", format);
    setVariableValueToObject(mojo, "outputFile", new File(outputFileName));
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenProject project = mojo.getProject();
    project.setArtifact(this.stubFactory.createArtifact("testGroupId", "project", "1.0"));
    Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
    Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
    artifacts.addAll(directArtifacts);
    project.setArtifacts(artifacts);
    project.setDependencyArtifacts(directArtifacts);
    mojo.execute();
    BufferedReader fp1 = new BufferedReader(new FileReader(outputFileName));
    List<String> contents = new ArrayList<String>();
    String line;
    while ((line = fp1.readLine()) != null) {
        contents.add(line);
    }
    fp1.close();
    return contents;
}
Also used : TreeMojo(org.apache.maven.plugins.dependency.tree.TreeMojo) MavenProject(org.apache.maven.project.MavenProject) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) FileReader(java.io.FileReader) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

File (java.io.File)4 Artifact (org.apache.maven.artifact.Artifact)4 TreeMojo (org.apache.maven.plugins.dependency.tree.TreeMojo)4 MavenProject (org.apache.maven.project.MavenProject)4 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 ArrayList (java.util.ArrayList)2 DependencyNode (org.apache.maven.shared.dependency.graph.DependencyNode)2