Java Code Examples for org.apache.maven.artifact.Artifact#setGroupId()

The following examples show how to use org.apache.maven.artifact.Artifact#setGroupId() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: deadcode4j   File: A_ModuleGenerator.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void createsClassPathEntryForKnownProject() throws MojoExecutionException {
    MavenProject firstProject = givenMavenProject("firstProject");
    Artifact artifact = new ArtifactStub();
    artifact.setGroupId("de.is24.junit");
    artifact.setArtifactId("firstProject");
    artifact.setVersion("42");
    artifact.setScope("compile");
    mavenProject.setArtifacts(newHashSet(artifact));

    Iterable<Module> modules = objectUnderTest.getModulesFor(asList(firstProject, mavenProject));

    assertThat(modules, is(Matchers.<Module>iterableWithSize(2)));
    Module module = Iterables.getLast(modules);
    assertThat(module.getClassPath(), is(Matchers.<File>iterableWithSize(1)));
}
 
Example 2
Source Project: deadcode4j   File: A_ModuleGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private Artifact addArtifact(MavenProject mavenProject, final boolean resolved) {
    Artifact artifact = new ArtifactStub() {
        private boolean resolved = false;

        @Override
        public boolean isResolved() {
            return this.resolved;
        }

        @Override
        public void setResolved(boolean b) {
            this.resolved = b;
        }

        @Override
        public File getFile() {
            return isResolved() ? super.getFile() : null;
        }
    };
    artifact.setGroupId("de.is24.junit");
    artifact.setArtifactId("dependency");
    artifact.setVersion("42");
    artifact.setScope("compile");
    artifact.setResolved(resolved);
    artifact.setFile(tempFileRule.getTempFile());

    mavenProject.setArtifactFilter(new ScopeArtifactFilter(SCOPE_COMPILE_PLUS_RUNTIME));
    if (resolved) {
        mavenProject.setResolvedArtifacts(newHashSet(artifact));
    } else {
        mavenProject.setArtifacts(newHashSet(artifact));
    }
    return artifact;
}
 
Example 3
Source Project: dependency-mediator   File: ProjectStub.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Default constructor
 */
public ProjectStub() {
    MavenXpp3Reader pomReader = new MavenXpp3Reader();
    Model model;
    try {
        model = pomReader.read(ReaderFactory.newXmlReader(new File(getBasedir(), "pom.xml")));
        setModel(model);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    Artifact artifact = new ArtifactStub();
    artifact.setArtifactId(model.getArtifactId());
    artifact.setGroupId(model.getGroupId());
    artifact.setVersion(model.getVersion());
    setArtifact(artifact);

    setGroupId(model.getGroupId());
    setArtifactId(model.getArtifactId());
    setVersion(model.getVersion());
    setName(model.getName());
    setUrl(model.getUrl());
    setPackaging(model.getPackaging());

    Build build = new Build();
    build.setFinalName(model.getArtifactId());
    build.setDirectory(getBasedir() + "/target");
    build.setSourceDirectory(getBasedir() + "/src/main/java");
    build.setOutputDirectory(getBasedir() + "/target/classes");
    build.setTestSourceDirectory(getBasedir() + "/src/test/java");
    build.setTestOutputDirectory(getBasedir() + "/target/test-classes");
    setBuild(build);

    List<String> compileSourceRoots = new ArrayList<String>();
    compileSourceRoots.add(getBasedir() + "/src/main/java");
    setCompileSourceRoots(compileSourceRoots);

    List<String> testCompileSourceRoots = new ArrayList<String>();
    testCompileSourceRoots.add(getBasedir() + "/src/test/java");
    setTestCompileSourceRoots(testCompileSourceRoots);
}