Search in sources :

Example 1 with DependencyProjectStub

use of org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub in project maven-plugins by apache.

the class TestAnalyzeDepMgt method setUp.

protected void setUp() throws Exception {
    mojo = new AnalyzeDepMgt();
    MavenProject project = new DependencyProjectStub();
    stubFactory = new DependencyArtifactStubFactory(new File(""), false);
    Set<Artifact> allArtifacts = stubFactory.getMixedArtifacts();
    Set<Artifact> directArtifacts = stubFactory.getClassifiedArtifacts();
    exclusionArtifact = stubFactory.getReleaseArtifact();
    directArtifacts.add(exclusionArtifact);
    ex = new Exclusion();
    ex.setArtifactId(exclusionArtifact.getArtifactId());
    ex.setGroupId(exclusionArtifact.getGroupId());
    exclusion = new Dependency();
    exclusion.setArtifactId(exclusionArtifact.getArtifactId());
    exclusion.setGroupId(exclusionArtifact.getGroupId());
    exclusion.setType(exclusionArtifact.getType());
    exclusion.setClassifier("");
    exclusion.setVersion("3.0");
    exclusion.addExclusion(ex);
    List<Dependency> list = new ArrayList<Dependency>();
    list.add(exclusion);
    depMgt = new DependencyManagement();
    depMgt.setDependencies(list);
    project.setArtifacts(allArtifacts);
    project.setDependencyArtifacts(directArtifacts);
    mojo.setProject(project);
}
Also used : AnalyzeDepMgt(org.apache.maven.plugins.dependency.analyze.AnalyzeDepMgt) MavenProject(org.apache.maven.project.MavenProject) Exclusion(org.apache.maven.model.Exclusion) ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) DependencyProjectStub(org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) DependencyManagement(org.apache.maven.model.DependencyManagement) DependencyArtifactStubFactory(org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory)

Example 2 with DependencyProjectStub

use of org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub in project maven-plugins by apache.

the class TestAnalyzeDepMgt method testMojo.

public void testMojo() throws IOException {
    mojo.setIgnoreDirect(false);
    try {
        // test with nothing in depMgt
        mojo.execute();
    } catch (Exception e) {
        e.printStackTrace();
        fail("Caught Unexpected Exception:" + e.getLocalizedMessage());
    }
    try {
        DependencyProjectStub project = (DependencyProjectStub) mojo.getProject();
        project.setDependencyManagement(depMgt);
        // test with exclusion
        mojo.execute();
    } catch (Exception e) {
        e.printStackTrace();
        fail("Caught Unexpected Exception:" + e.getLocalizedMessage());
    }
    try {
        DependencyProjectStub project = (DependencyProjectStub) mojo.getProject();
        project.setDependencyManagement(depMgt);
        // test with exclusion
        mojo.setFailBuild(true);
        mojo.execute();
        fail("Expected exception to fail the build.");
    } catch (Exception e) {
        System.out.println("Caught Expected Exception:" + e.getLocalizedMessage());
    }
    try {
        DependencyProjectStub project = (DependencyProjectStub) mojo.getProject();
        project.setDependencyManagement(depMgt);
        // test with exclusion
        mojo.setFailBuild(true);
        mojo.setIgnoreDirect(true);
        mojo.execute();
    } catch (Exception e) {
        e.printStackTrace();
        fail("Caught Unexpected Exception:" + e.getLocalizedMessage());
    }
}
Also used : DependencyProjectStub(org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub) IOException(java.io.IOException)

Aggregations

DependencyProjectStub (org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Artifact (org.apache.maven.artifact.Artifact)1 Dependency (org.apache.maven.model.Dependency)1 DependencyManagement (org.apache.maven.model.DependencyManagement)1 Exclusion (org.apache.maven.model.Exclusion)1 AnalyzeDepMgt (org.apache.maven.plugins.dependency.analyze.AnalyzeDepMgt)1 DependencyArtifactStubFactory (org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory)1 MavenProject (org.apache.maven.project.MavenProject)1