Java Code Examples for org.apache.maven.model.Build#setOutputDirectory()

The following examples show how to use org.apache.maven.model.Build#setOutputDirectory() . 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 File: A_ModuleGenerator.java    From deadcode4j with Apache License 2.0 6 votes vote down vote up
private MavenProject givenMavenProject(String projectId) {
    MavenProject mavenProject = new MavenProject();
    mavenProject.setGroupId("de.is24.junit");
    mavenProject.setArtifactId(projectId);
    mavenProject.setVersion("42");
    mavenProject.getProperties().setProperty("project.build.sourceEncoding", "UTF-8");
    ArtifactStub projectArtifact = new ArtifactStub();
    projectArtifact.setGroupId("de.is24.junit");
    projectArtifact.setArtifactId(projectId);
    projectArtifact.setVersion("42");
    mavenProject.setArtifact(projectArtifact);
    Build build = new Build();
    build.setOutputDirectory(tempFileRule.getTempFile().getParent());
    mavenProject.setBuild(build);
    return mavenProject;
}
 
Example 2
Source File: InitializeMojoTest.java    From vertx-maven-plugin with Apache License 2.0 6 votes vote down vote up
private InitializeMojo createMojoInstance() throws PlexusContainerException {
    InitializeMojo mojo = new InitializeMojo();
    mojo.project = new MavenProject();
    mojo.repositorySystem = new DefaultRepositorySystem();
    mojo.repositorySystemSession = new DefaultRepositorySystemSession();
    mojo.buildPluginManager = new DefaultBuildPluginManager();
    mojo.container = new DefaultPlexusContainer(new DefaultContainerConfiguration());
    mojo.mavenSession = new MavenSession(mojo.container, mojo.repositorySystemSession, new DefaultMavenExecutionRequest(),
        new DefaultMavenExecutionResult());

    mojo.lifecycleExecutor = new DefaultLifecycleExecutor();
    mojo.scmManager = new DefaultScmManager();
    mojo.remoteRepositories = Collections.emptyList();
    mojo.projectBuildDir = OUT.getAbsolutePath();

    Build build = new Build();
    build.setOutputDirectory(OUT.getAbsolutePath());
    mojo.project.setBuild(build);

    return mojo;
}
 
Example 3
Source File: BasePitMojoTest.java    From pitest with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();
  MockitoAnnotations.initMocks(this);
  this.classPath = new ArrayList<>(FCollection.map(
      ClassPath.getClassPathElementsAsFiles(), fileToString()));
  when(this.project.getTestClasspathElements()).thenReturn(this.classPath);
  when(this.project.getPackaging()).thenReturn("jar");
  
  final Build build = new Build();
  build.setOutputDirectory("");
  
  when(this.project.getBuild()).thenReturn(build);
  
  when(this.plugins.findToolClasspathPlugins()).thenReturn(
      Collections.emptyList());
  when(this.plugins.findClientClasspathPlugins()).thenReturn(
      Collections.emptyList());
}
 
Example 4
Source File: MavenUtilTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private MavenProject getMavenProject() {
    MavenProject mavenProject = new MavenProject();
    mavenProject.setName("testProject");
    mavenProject.setGroupId("org.eclipse.jkube");
    mavenProject.setArtifactId("test-project");
    mavenProject.setVersion("0.1.0");
    mavenProject.setDescription("test description");
    Build build = new Build();
    build.setOutputDirectory("./target");
    build.setDirectory(".");
    mavenProject.setBuild(build);
    DistributionManagement distributionManagement = new DistributionManagement();
    Site site = new Site();
    site.setUrl("https://www.eclipse.org/jkube/");
    distributionManagement.setSite(site);
    mavenProject.setDistributionManagement(distributionManagement);
    return mavenProject;
}
 
Example 5
Source File: MojoToReportOptionsConverterTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  Plugin surefire = new Plugin();
  surefire.setGroupId("org.apache.maven.plugins");
  surefire.setArtifactId("maven-surefire-plugin");
  this.surefireConverter = Mockito.mock(SurefireConfigConverter.class);
  List<Plugin> mavenPlugins = Collections.singletonList(surefire);
  when(this.project.getBuildPlugins()).thenReturn(mavenPlugins);
  Build build = new Build();
  build.setOutputDirectory("");
  when(this.project.getBuild()).thenReturn(build);
}
 
Example 6
Source File: PitMojoTest.java    From pitest with Apache License 2.0 5 votes vote down vote up
public void testRunsAMutationReportWhenMutationCoverageGoalTrigered()
    throws Exception {
  this.testee = createPITMojo(createPomWithConfiguration(""));
  final Build build = new Build();
  build.setOutputDirectory("foo");
  this.testee.getProject().setBuild(build);
  this.testee.execute();
  verify(this.executionStrategy).execute(any(File.class),
      any(ReportOptions.class), any(PluginServices.class), anyMap());
}
 
Example 7
Source File: TypeScriptDTOGeneratorMojoProjectStub.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** Default constructor */
public TypeScriptDTOGeneratorMojoProjectStub() {
  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);
  }

  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 compileSourceRoots = new ArrayList();
  compileSourceRoots.add(getBasedir() + "/src/main/java");
  setCompileSourceRoots(compileSourceRoots);

  List testCompileSourceRoots = new ArrayList();
  testCompileSourceRoots.add(getBasedir() + "/src/test/java");
  setTestCompileSourceRoots(testCompileSourceRoots);
}
 
Example 8
Source File: SPICombineTest.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void testCombineWithSpringDescriptors() throws Exception {
    File jar1 = new File("target/testCombine1Spring.jar");
    File jar2 = new File("target/testCombine2Spring.jar");
    File jar3 = new File("target/testCombine3Spring.jar");

    JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class);
    jarArchive1.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl"),
        "/META-INF/spring.foo");

    jarArchive1.as(ZipExporter.class).exportTo(jar1, true);


    JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class);
    jarArchive2.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl2"),
        "/META-INF/spring.foo");
    jarArchive2.add(new StringAsset("com.test.demo.DemoSPI2.impl.DemoSPI2Impl2"),
        "/META-INF/spring.bar");
    jarArchive2.as(ZipExporter.class).exportTo(jar2, true);

    JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class);
    jarArchive3.addClass(SPICombineTest.class);
    jarArchive3.as(ZipExporter.class).exportTo(jar3, true);

    Set<Artifact> artifacts = new LinkedHashSet<>();
    Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0",
        "compile", "jar", "", null);
    a1.setFile(jar1);
    Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0",
        "compile", "jar", "", null);
    a2.setFile(jar2);
    Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0",
        "compile", "jar", "", null);
    a3.setFile(jar3);

    artifacts.add(a1);
    artifacts.add(a2);
    artifacts.add(a3);

    MavenProject project = new MavenProject();
    project.setVersion("1.0");
    project.setArtifactId("foo");

    AbstractVertxMojo mojo = new AbstractVertxMojo() {
        @Override
        public void execute() throws MojoExecutionException, MojoFailureException {

        }
    };

    mojo.setLog(new SystemStreamLog());
    Build build = new Build();
    build.setOutputDirectory("target/junk");
    project.setBuild(build);

    ServiceFileCombinationConfig config = new ServiceFileCombinationConfig()
        .setProject(project)
        .setArtifacts(artifacts)
        .setArchive(ServiceUtils.getDefaultFatJar())
        .setMojo(mojo);

    combiner.doCombine(config);

    File merged = new File("target/junk/META-INF/spring.foo");
    assertThat(merged).isFile();

    List<String> lines = FileUtils.readLines(merged, "UTF-8");
    assertThat(lines).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl2");
    Stream.of(jar1, jar2, jar3, new File("target/junk")).forEach(FileUtils::deleteQuietly);
}
 
Example 9
Source File: ProjectStub.java    From deadcode4j with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("UnusedDeclaration") // configured via POM
public void setOutputDirectory(String directory) {
    Build build = new Build();
    build.setOutputDirectory(directory);
    setBuild(build);
}
 
Example 10
Source File: ProjectStub.java    From dependency-mediator with 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);
}
 
Example 11
Source File: CukedoctorMojoStub.java    From cukedoctor with Apache License 2.0 4 votes vote down vote up
@Override
public Build getBuild() {
	Build b = new Build();
	b.setOutputDirectory("target/");
	return b;
}
 
Example 12
Source File: SPICombineTest.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void testCombineDiffSPI() throws Exception {

    File jar1 = new File("target/testCombineDiffSPI.jar");
    File jar2 = new File("target/testCombineDiffSPI2.jar");
    File jar3 = new File("target/testCombineDiffSPI3.jar");
    File jar4 = new File("target/testCombineDiffSPI4.jar");

    JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class);
    jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl");
    jarArchive1.as(ZipExporter.class).exportTo(jar1, true);


    JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class);
    jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl2");
    jarArchive2.as(ZipExporter.class).exportTo(jar2, true);

    JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class);
    jarArchive3.addClass(SPICombineTest.class);
    jarArchive3.as(ZipExporter.class).exportTo(jar3, true);

    JavaArchive jarArchive4 = ShrinkWrap.create(JavaArchive.class);
    jarArchive4.addAsServiceProvider("com.test.demo.DemoSPI",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl4");
    jarArchive4.as(ZipExporter.class).exportTo(jar4, true);

    Set<Artifact> artifacts = new LinkedHashSet<>();
    Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0",
        "compile", "jar", "", null);
    a1.setFile(jar1);
    Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0",
        "compile", "jar", "", null);
    a2.setFile(jar2);
    Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0",
        "compile", "jar", "", null);
    a3.setFile(jar3);
    Artifact a4 = new DefaultArtifact("org.acme", "a4", "1.0",
        "compile", "jar", "", null);
    a4.setFile(jar4);

    artifacts.add(a1);
    artifacts.add(a2);
    artifacts.add(a3);
    artifacts.add(a4);

    MavenProject project = new MavenProject();
    project.setVersion("1.0");
    project.setArtifactId("foo");

    AbstractVertxMojo mojo = new AbstractVertxMojo() {
        @Override
        public void execute() throws MojoExecutionException, MojoFailureException {

        }
    };

    mojo.setLog(new SystemStreamLog());
    Build build = new Build();
    build.setOutputDirectory("target/junk");
    project.setBuild(build);

    ServiceFileCombinationConfig config = new ServiceFileCombinationConfig()
        .setProject(project)
        .setArtifacts(artifacts)
        .setArchive(ServiceUtils.getDefaultFatJar())
        .setMojo(mojo);

    combiner.doCombine(config);
    File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI");
    assertThat(merged).isFile();

    List<String> lines = FileUtils.readLines(merged, "UTF-8");
    assertThat(lines).hasSize(3).containsExactly(
        "com.test.demo.DemoSPI.impl.DemoSPIImpl",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl2",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl4");
    Stream.of(jar1, jar2, jar3, jar4, new File("target/junk")).forEach(FileUtils::deleteQuietly);

}
 
Example 13
Source File: SPICombineTest.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void testCombine() throws Exception {
    File jar1 = new File("target/testCombine1.jar");
    File jar2 = new File("target/testCombine2.jar");
    File jar3 = new File("target/testCombine3.jar");

    JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class);
    jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl");

    jarArchive1.as(ZipExporter.class).exportTo(jar1, true);


    JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class);
    jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl2");
    jarArchive2.addAsServiceProvider("com.test.demo.DemoSP2",
        "com.test.demo.DemoSPI2.impl.DemoSPI2Impl2");
    jarArchive2.as(ZipExporter.class).exportTo(jar2, true);

    JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class);
    jarArchive3.addClass(SPICombineTest.class);
    jarArchive3.as(ZipExporter.class).exportTo(jar3, true);

    Set<Artifact> artifacts = new LinkedHashSet<>();
    Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0",
        "compile", "jar", "", null);
    a1.setFile(jar1);
    Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0",
        "compile", "jar", "", null);
    a2.setFile(jar2);
    Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0",
        "compile", "jar", "", null);
    a3.setFile(jar3);

    artifacts.add(a1);
    artifacts.add(a2);
    artifacts.add(a3);

    MavenProject project = new MavenProject();
    project.setVersion("1.0");
    project.setArtifactId("foo");

    AbstractVertxMojo mojo = new AbstractVertxMojo() {
        @Override
        public void execute() throws MojoExecutionException, MojoFailureException {

        }
    };

    mojo.setLog(new SystemStreamLog());
    Build build = new Build();
    build.setOutputDirectory("target/junk");
    project.setBuild(build);

    ServiceFileCombinationConfig config = new ServiceFileCombinationConfig()
        .setProject(project)
        .setArtifacts(artifacts)
        .setArchive(ServiceUtils.getDefaultFatJar())
        .setMojo(mojo);

    combiner.doCombine(config);

    File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI");
    assertThat(merged).isFile();

    List<String> lines = FileUtils.readLines(merged, "UTF-8");
    assertThat(lines).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl2");
    Stream.of(jar1, jar2, jar3, new File("target/junk")).forEach(FileUtils::deleteQuietly);
}
 
Example 14
Source File: MavenProjectStub.java    From swagger-maven-plugin with MIT License 4 votes vote down vote up
public MavenProjectStub() {
    Build b = new Build();
    b.setOutputDirectory("target/test-classes");
    setBuild(b);
}
 
Example 15
Source File: TestProjectStub.java    From steady with Apache License 2.0 4 votes vote down vote up
/**
 * Default constructor
 */
public TestProjectStub(String projectPath, String pomFile) {
    this.projectPath = projectPath;

    MavenXpp3Reader pomReader = new MavenXpp3Reader();
    Model model;
    try {
        model = pomReader.read(ReaderFactory.newXmlReader(new File(getBasedir(), pomFile)));
        setModel(model);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    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");
    build.setPlugins(model.getBuild().getPlugins());
    build.setExtensions(model.getBuild().getExtensions());
    setBuild(build);


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

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



}
 
Example 16
Source File: SPICombineTest.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void testCombineWithSpringDescriptors() throws Exception {
    File jar1 = new File("target/testCombine1Spring.jar");
    File jar2 = new File("target/testCombine2Spring.jar");
    File jar3 = new File("target/testCombine3Spring.jar");

    JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class);
    jarArchive1.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl"),
        "/META-INF/spring.foo");

    jarArchive1.as(ZipExporter.class).exportTo(jar1, true);


    JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class);
    jarArchive2.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl2"),
        "/META-INF/spring.foo");
    jarArchive2.add(new StringAsset("com.test.demo.DemoSPI2.impl.DemoSPI2Impl2"),
        "/META-INF/spring.bar");
    jarArchive2.as(ZipExporter.class).exportTo(jar2, true);

    JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class);
    jarArchive3.addClass(SPICombineTest.class);
    jarArchive3.as(ZipExporter.class).exportTo(jar3, true);

    Set<Artifact> artifacts = new LinkedHashSet<>();
    Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0",
        "compile", "jar", "", null);
    a1.setFile(jar1);
    Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0",
        "compile", "jar", "", null);
    a2.setFile(jar2);
    Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0",
        "compile", "jar", "", null);
    a3.setFile(jar3);

    artifacts.add(a1);
    artifacts.add(a2);
    artifacts.add(a3);

    MavenProject project = new MavenProject();
    project.setVersion("1.0");
    project.setArtifactId("foo");

    AbstractVertxMojo mojo = new AbstractVertxMojo() {
        @Override
        public void execute() throws MojoExecutionException, MojoFailureException {

        }
    };

    mojo.setLog(new SystemStreamLog());
    Build build = new Build();
    build.setOutputDirectory("target/junk");
    project.setBuild(build);

    ServiceFileCombinationConfig config = new ServiceFileCombinationConfig()
        .setProject(project)
        .setArtifacts(artifacts)
        .setArchive(ServiceUtils.getDefaultFatJar())
        .setMojo(mojo);

    combiner.doCombine(config);

    File merged = new File("target/junk/META-INF/spring.foo");
    assertThat(merged).isFile();

    List<String> lines = FileUtils.readLines(merged, "UTF-8");
    assertThat(lines).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl2");
    Stream.of(jar1, jar2, jar3, new File("target/junk")).forEach(FileUtils::deleteQuietly);
}
 
Example 17
Source File: SPICombineTest.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void testCombineDiffSPI() throws Exception {

    File jar1 = new File("target/testCombineDiffSPI.jar");
    File jar2 = new File("target/testCombineDiffSPI2.jar");
    File jar3 = new File("target/testCombineDiffSPI3.jar");
    File jar4 = new File("target/testCombineDiffSPI4.jar");

    JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class);
    jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl");
    jarArchive1.as(ZipExporter.class).exportTo(jar1, true);


    JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class);
    jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl2");
    jarArchive2.as(ZipExporter.class).exportTo(jar2, true);

    JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class);
    jarArchive3.addClass(SPICombineTest.class);
    jarArchive3.as(ZipExporter.class).exportTo(jar3, true);

    JavaArchive jarArchive4 = ShrinkWrap.create(JavaArchive.class);
    jarArchive4.addAsServiceProvider("com.test.demo.DemoSPI",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl4");
    jarArchive4.as(ZipExporter.class).exportTo(jar4, true);

    Set<Artifact> artifacts = new LinkedHashSet<>();
    Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0",
        "compile", "jar", "", null);
    a1.setFile(jar1);
    Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0",
        "compile", "jar", "", null);
    a2.setFile(jar2);
    Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0",
        "compile", "jar", "", null);
    a3.setFile(jar3);
    Artifact a4 = new DefaultArtifact("org.acme", "a4", "1.0",
        "compile", "jar", "", null);
    a4.setFile(jar4);

    artifacts.add(a1);
    artifacts.add(a2);
    artifacts.add(a3);
    artifacts.add(a4);

    MavenProject project = new MavenProject();
    project.setVersion("1.0");
    project.setArtifactId("foo");

    AbstractVertxMojo mojo = new AbstractVertxMojo() {
        @Override
        public void execute() throws MojoExecutionException, MojoFailureException {

        }
    };

    mojo.setLog(new SystemStreamLog());
    Build build = new Build();
    build.setOutputDirectory("target/junk");
    project.setBuild(build);

    ServiceFileCombinationConfig config = new ServiceFileCombinationConfig()
        .setProject(project)
        .setArtifacts(artifacts)
        .setArchive(ServiceUtils.getDefaultFatJar())
        .setMojo(mojo);

    combiner.doCombine(config);
    File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI");
    assertThat(merged).isFile();

    List<String> lines = FileUtils.readLines(merged, "UTF-8");
    assertThat(lines).hasSize(3).containsExactly(
        "com.test.demo.DemoSPI.impl.DemoSPIImpl",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl2",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl4");
    Stream.of(jar1, jar2, jar3, jar4, new File("target/junk")).forEach(FileUtils::deleteQuietly);

}
 
Example 18
Source File: SPICombineTest.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void testCombine() throws Exception {
    File jar1 = new File("target/testCombine1.jar");
    File jar2 = new File("target/testCombine2.jar");
    File jar3 = new File("target/testCombine3.jar");

    JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class);
    jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl");

    jarArchive1.as(ZipExporter.class).exportTo(jar1, true);


    JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class);
    jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl2");
    jarArchive2.addAsServiceProvider("com.test.demo.DemoSP2",
        "com.test.demo.DemoSPI2.impl.DemoSPI2Impl2");
    jarArchive2.as(ZipExporter.class).exportTo(jar2, true);

    JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class);
    jarArchive3.addClass(SPICombineTest.class);
    jarArchive3.as(ZipExporter.class).exportTo(jar3, true);

    Set<Artifact> artifacts = new LinkedHashSet<>();
    Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0",
        "compile", "jar", "", null);
    a1.setFile(jar1);
    Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0",
        "compile", "jar", "", null);
    a2.setFile(jar2);
    Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0",
        "compile", "jar", "", null);
    a3.setFile(jar3);

    artifacts.add(a1);
    artifacts.add(a2);
    artifacts.add(a3);

    MavenProject project = new MavenProject();
    project.setVersion("1.0");
    project.setArtifactId("foo");

    AbstractVertxMojo mojo = new AbstractVertxMojo() {
        @Override
        public void execute() throws MojoExecutionException, MojoFailureException {

        }
    };

    mojo.setLog(new SystemStreamLog());
    Build build = new Build();
    build.setOutputDirectory("target/junk");
    project.setBuild(build);

    ServiceFileCombinationConfig config = new ServiceFileCombinationConfig()
        .setProject(project)
        .setArtifacts(artifacts)
        .setArchive(ServiceUtils.getDefaultFatJar())
        .setMojo(mojo);

    combiner.doCombine(config);

    File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI");
    assertThat(merged).isFile();

    List<String> lines = FileUtils.readLines(merged, "UTF-8");
    assertThat(lines).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl",
        "com.test.demo.DemoSPI.impl.DemoSPIImpl2");
    Stream.of(jar1, jar2, jar3, new File("target/junk")).forEach(FileUtils::deleteQuietly);
}