Java Code Examples for org.apache.maven.project.MavenProject#setBuild()

The following examples show how to use org.apache.maven.project.MavenProject#setBuild() . 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: 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 2
Source File: MavenUtilsTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDefaultPropertiesOnProjectWithProperties() throws Exception {
    Model model = new Model();
    model.setPomFile(new File("target/test-classes/maven/test/minimal.xml"));
    MavenProject project = new MavenProject(model);
    project.setFile(new File("target/test-classes/maven/test/minimal.xml"));
    project.setArtifactId("acme");
    project.setGroupId("corp.acme");
    project.setVersion("1.0.0-SNAPSHOT");
    final ProjectArtifact artifact = new ProjectArtifact(project);
    project.setArtifact(artifact);
    Build build = new Build();
    build.setDirectory(new File(project.getBasedir(), "target").getAbsolutePath());
    build.setOutputDirectory(new File(project.getBasedir(), "target/classes").getAbsolutePath());
    project.setBuild(build);

    Properties props = new Properties();
    props.put("p", "v");
    model.setProperties(props);

    Properties properties = MavenUtils.getDefaultProperties(project);

    assertThat(properties.getProperty("p")).isEqualTo("v");
}
 
Example 3
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 4
Source File: PackageMojoTest.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testOutputFileNameComputation() {
    MavenProject project =  new MavenProject();
    Build build = new Build();
    project.setBuild(build);
    project.setArtifactId("some-artifact-id");
    project.setVersion("1.0-SNAPSHOT");
    build.setFinalName("some-artifact-id-1.0-SNAPSHOT-GA");

    // finale name set
    String fn = PackageMojo.computeOutputName(project, null);
    assertThat(fn).isEqualTo("some-artifact-id-1.0-SNAPSHOT-GA.jar");

    // final name set with .jar
    build.setFinalName("some-artifact-id-1.0-SNAPSHOT-GA2.jar");
    fn = PackageMojo.computeOutputName(project, null);
    assertThat(fn).isEqualTo("some-artifact-id-1.0-SNAPSHOT-GA2.jar");

    // same as 1 with classifier
    build.setFinalName("some-artifact-id-1.0-SNAPSHOT-GA");
    fn = PackageMojo.computeOutputName(project, "fat");
    assertThat(fn).isEqualTo("some-artifact-id-1.0-SNAPSHOT-GA-fat.jar");

    // same as 2 with classifier
    build.setFinalName("some-artifact-id-1.0-SNAPSHOT-GA2.jar");
    fn = PackageMojo.computeOutputName(project, "fat");
    assertThat(fn).isEqualTo("some-artifact-id-1.0-SNAPSHOT-GA2-fat.jar");

    // no final name
    build.setFinalName(null);
    fn = PackageMojo.computeOutputName(project, "");
    assertThat(fn).isEqualTo("some-artifact-id-1.0-SNAPSHOT.jar");

    // no final name with classifier
    build.setFinalName(null);
    fn = PackageMojo.computeOutputName(project, "fat");
    assertThat(fn).isEqualTo("some-artifact-id-1.0-SNAPSHOT-fat.jar");
}
 
Example 5
Source File: MavenUtilsTest.java    From wisdom with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDefaultPropertiesOnMinimalPom() throws Exception {
    Model model = new Model();
    model.setPomFile(new File("target/test-classes/maven/test/minimal.xml"));
    MavenProject project = new MavenProject(model);
    project.setFile(new File("target/test-classes/maven/test/minimal.xml"));
    project.setArtifactId("acme");
    project.setGroupId("corp.acme");
    project.setVersion("1.0.0-SNAPSHOT");
    final ProjectArtifact artifact = new ProjectArtifact(project);
    project.setArtifact(artifact);
    Build build = new Build();
    build.setDirectory(new File(project.getBasedir(), "target").getAbsolutePath());
    build.setOutputDirectory(new File(project.getBasedir(), "target/classes").getAbsolutePath());
    project.setBuild(build);

    Properties properties = MavenUtils.getDefaultProperties(project);
    assertThat(properties.getProperty("maven-symbolicname")).isEqualTo(DefaultMaven2OsgiConverter
            .getBundleSymbolicName(artifact));
    assertThat(properties.getProperty(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME)).isEqualTo(DefaultMaven2OsgiConverter
            .getBundleSymbolicName(artifact));

    assertThat(properties.getProperty(org.osgi.framework.Constants.BUNDLE_VERSION)).isEqualTo(DefaultMaven2OsgiConverter
            .getVersion(project.getVersion()));

    assertThat(properties.getProperty(org.osgi.framework.Constants.BUNDLE_DESCRIPTION)).isNull();
    assertThat(properties.getProperty(Analyzer.BUNDLE_LICENSE)).isNull();
    assertThat(properties.getProperty(Analyzer.BUNDLE_VENDOR)).isNull();
    assertThat(properties.getProperty(Analyzer.BUNDLE_DOCURL)).isNull();

    assertThat(properties.getProperty(Analyzer.BUNDLE_LICENSE)).isNull();

    assertThat(properties.getProperty(Analyzer.BUNDLE_NAME)).isEqualTo(project.getArtifactId());
}
 
Example 6
Source File: PackageMojoTest.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void testOutputFileNameComputation() {
    MavenProject project =  new MavenProject();
    Build build = new Build();
    project.setBuild(build);
    project.setArtifactId("some-artifact-id");
    project.setVersion("1.0-SNAPSHOT");
    build.setFinalName("some-artifact-id-1.0-SNAPSHOT-GA");

    // output name set
    String fn = PackageMojo.computeOutputName(new Archive().setOutputFileName("hello"), project, null);
    assertThat(fn).isEqualTo("hello.jar");

    // output name set with extension
    fn = PackageMojo.computeOutputName(new Archive().setOutputFileName("hello.jar"), project, null);
    assertThat(fn).isEqualTo("hello.jar");

    // final name set
    fn = PackageMojo.computeOutputName(new Archive(), project, null);
    assertThat(fn).isEqualTo("some-artifact-id-1.0-SNAPSHOT-GA.jar");


    // final name set with .jar
    build.setFinalName("some-artifact-id-1.0-SNAPSHOT-GA2.jar");
    fn = PackageMojo.computeOutputName(new Archive(), project, null);
    assertThat(fn).isEqualTo("some-artifact-id-1.0-SNAPSHOT-GA2.jar");

    // same as 1 with classifier
    build.setFinalName("some-artifact-id-1.0-SNAPSHOT-GA");
    fn = PackageMojo.computeOutputName(new Archive(), project, "fat");
    assertThat(fn).isEqualTo("some-artifact-id-1.0-SNAPSHOT-GA-fat.jar");

    // same as 2 with classifier
    build.setFinalName("some-artifact-id-1.0-SNAPSHOT-GA2.jar");
    fn = PackageMojo.computeOutputName(new Archive(), project, "fat");
    assertThat(fn).isEqualTo("some-artifact-id-1.0-SNAPSHOT-GA2-fat.jar");

    // no final name
    build.setFinalName(null);
    fn = PackageMojo.computeOutputName(new Archive(), project, "");
    assertThat(fn).isEqualTo("some-artifact-id-1.0-SNAPSHOT.jar");

    // no final name with classifier
    build.setFinalName(null);
    fn = PackageMojo.computeOutputName(new Archive(), project, "fat");
    assertThat(fn).isEqualTo("some-artifact-id-1.0-SNAPSHOT-fat.jar");
}
 
Example 7
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 8
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 9
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 10
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 11
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 12
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 13
Source File: MavenUtilsTest.java    From wisdom with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetDefaultPropertiesOnProjectWithLicenses() throws Exception {
    Model model = new Model();
    model.setPomFile(new File("target/test-classes/maven/test/minimal.xml"));
    MavenProject project = new MavenProject(model);
    project.setFile(new File("target/test-classes/maven/test/minimal.xml"));
    project.setArtifactId("acme");
    project.setGroupId("corp.acme");
    project.setVersion("1.0.0-SNAPSHOT");
    final ProjectArtifact artifact = new ProjectArtifact(project);
    project.setArtifact(artifact);
    Build build = new Build();
    build.setDirectory(new File(project.getBasedir(), "target").getAbsolutePath());
    build.setOutputDirectory(new File(project.getBasedir(), "target/classes").getAbsolutePath());
    project.setBuild(build);

    License license = new License();
    license.setDistribution("repo");
    license.setName("Apache Software License 2.0");
    license.setUrl("http://www.apache.org/licenses/");
    project.setLicenses(ImmutableList.of(license));

    Organization organization = new Organization();
    organization.setName("Acme Corp.");
    organization.setUrl("http://acme.org");
    project.setOrganization(organization);

    project.setDescription("description");

    Properties properties = MavenUtils.getDefaultProperties(project);
    assertThat(properties.getProperty(Analyzer.BUNDLE_LICENSE)).contains(license.getUrl());
    assertThat(properties.getProperty(Analyzer.BUNDLE_VENDOR)).isEqualTo("Acme Corp.");
    assertThat(properties.getProperty(Analyzer.BUNDLE_DOCURL)).isEqualTo(organization.getUrl());
    assertThat(properties.getProperty(Analyzer.BUNDLE_DESCRIPTION)).isEqualTo("description");

    License license2 = new License();
    license2.setDistribution("repo");
    license2.setName("Apache Software License 2.0");
    license2.setUrl("http://www.apache.org/LICENSE.txt");

    project.setLicenses(ImmutableList.of(license, license2));

    properties = MavenUtils.getDefaultProperties(project);
    assertThat(properties.getProperty(Analyzer.BUNDLE_LICENSE)).contains(license.getUrl()).contains(license2.getUrl());
}