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

The following examples show how to use org.apache.maven.project.MavenProject#setVersion() . 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: 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 3
Source File: ApiGatewayTest.java    From lambadaframework with MIT License 6 votes vote down vote up
protected LambadaDeployer getExampleProject() {
    MavenProject project = new MavenProject();
    project.getProperties().setProperty("deployment.bucket", "maven.cagataygurturk.com");
    project.setGroupId("org.lambadaframework");
    project.setArtifactId("runtime-deploy-maven-plugin");
    project.setVersion("0.0.2");

    Properties props = new Properties();
    props.put("ProjectName", "LambadaTestProject");

    LambadaDeployer deployer = new LambadaDeployer();
    deployer.mavenProject = project;
    deployer.stageToDeploy = "dev";
    deployer.regionToDeploy = "eu-west-1";
    //deployer.cloudFormationParameters = props;
    return deployer;
}
 
Example 4
Source File: MainTest.java    From lambadaframework with MIT License 6 votes vote down vote up
protected LambadaDeployer getExampleProject() {
    MavenProject project = new MavenProject();
    project.getProperties().setProperty("deployment.bucket", "maven.cagataygurturk.com");
    project.setGroupId("com.home24.lambdadeploy");
    project.setArtifactId("runtime-deploy-maven-plugin");
    project.setVersion("0.0.2");

    Properties props = new Properties();
    props.put("ProjectName", "MobileApi");

    LambadaDeployer deployer = new LambadaDeployer();
    deployer.mavenProject = project;
    deployer.stageToDeploy = "dev";
    deployer.regionToDeploy = "eu-west-1";
    return deployer;
}
 
Example 5
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 6
Source File: MavenVersionResolver.java    From multi-module-maven-release-plugin with MIT License 5 votes vote down vote up
static void resolveVersionsDefinedThroughProperties(List<MavenProject> projects) {
    for (MavenProject project : projects) {
        if (isVersionDefinedWithProperty(project.getVersion())) {
            project.setVersion(resolveVersion(project.getVersion(), project.getProperties()));
        }
    }

}
 
Example 7
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 8
Source File: JenkinsMavenEventSpyMTTest.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
private JenkinsMavenEventSpy createSpy() throws Exception {
    FileMavenEventReporter reporter = new FileMavenEventReporter();

    JenkinsMavenEventSpy spy = new JenkinsMavenEventSpy(reporter) {
        @Override
        protected boolean isEventSpyDisabled() {
            return false;
        }
    };

    spy.init(new EventSpy.Context() {
        @Override
        public Map<String, Object> getData() {
            return new HashMap();
        }
    });

    MavenXpp3Reader mavenXpp3Reader = new MavenXpp3Reader();
    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/eventspy/pom.xml");

    Assert.assertThat(in, CoreMatchers.notNullValue());
    Model model = mavenXpp3Reader.read(in);
    project = new MavenProject(model);
    project.setGroupId(model.getGroupId());
    project.setArtifactId(model.getArtifactId());
    project.setVersion(model.getVersion());
    project.setName(model.getName());
    return spy;
}
 
Example 9
Source File: MavenSessionMock.java    From gitflow-incremental-builder with MIT License 5 votes vote down vote up
private static MavenProject createProject(Path path) {
    MavenProject project = new MavenProject();
    Model model = new Model();
    model.setProperties(new Properties());
    project.setModel(model);
    project.setArtifactId(path.getFileName().toString());
    project.setGroupId(path.getFileName().toString());
    project.setVersion("1");
    project.setFile(path.resolve("pom.xml").toFile());
    return project;
}
 
Example 10
Source File: MavenProjectCache.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({
    "LBL_Incomplete_Project_Name=<partially loaded Maven project>",
    "LBL_Incomplete_Project_Desc=Partially loaded Maven project; try building it."
})
public static MavenProject getFallbackProject(File projectFile) throws AssertionError {
    MavenProject newproject = new MavenProject();
    newproject.setGroupId("error");
    newproject.setArtifactId("error");
    newproject.setVersion("0");
    newproject.setPackaging("pom");
    newproject.setName(Bundle.LBL_Incomplete_Project_Name());
    newproject.setDescription(Bundle.LBL_Incomplete_Project_Desc());
    newproject.setFile(projectFile);
    return newproject;
}
 
Example 11
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 12
Source File: AbstractSmartBuilderTest.java    From takari-smart-builder with Apache License 2.0 5 votes vote down vote up
protected MavenProject newProject(String artifactId) {
  MavenProject project = new MavenProject();
  project.setGroupId("test");
  project.setArtifactId(artifactId);
  project.setVersion("1");
  return project;
}
 
Example 13
Source File: ProjectVersionManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
Set<MavenProject> applyVersioningChanges( final Collection<MavenProject> projects,
                                          final Map<ProjectVersionRef, String> _versionsByGAV )
    throws ManipulationException
{
    final VersioningState state = new VersioningState( session.getUserProperties() );
    state.setVersionsByGAVMap( _versionsByGAV );

    final Set<MavenProject> changed = new HashSet<>();
    for ( final MavenProject project : projects )
    {
        if ( applyVersioningChanges( new Project ( project.getOriginalModel()), state ) )
        {
            final String v = _versionsByGAV.get( SimpleProjectVersionRef.parse( gav( project ) ) );

            // this is a bigger model, so only do this if the originalModel was modded.
            applyVersioningChanges( new Project ( project.getModel()), state );
            changed.add( project );

            if ( v != null )
            {
                // belt and suspenders...be double sure this gets set everywhere.
                project.setVersion( v );
            }
        }
    }

    return changed;
}
 
Example 14
Source File: ProjectToCoordinatesTest.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static MavenProject createProject(String gid, String aid, String version, String packaging) {
  MavenProject p = new MavenProject();
  p.setGroupId(gid);
  p.setArtifactId(aid);
  p.setVersion(version);
  p.setPackaging(packaging);
  return p;
}
 
Example 15
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 16
Source File: PackageApplicationMojoTest.java    From roboconf-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testValidAppProject() throws Exception {

	final String finalName = "output";
	final String version = "1";

	// Copy the project
	File targetDirectory = this.resources.getBasedir( "project--valid" );
	File targetArchive = new File( targetDirectory, "target/" + finalName + ".zip" );
	File modelDirectory = new File( targetDirectory, MavenPluginConstants.TARGET_MODEL_DIRECTORY );
	Assert.assertFalse( targetArchive.exists());
	Assert.assertFalse( modelDirectory.exists());

	// Create the Maven project by hand
	File pom = new File( targetDirectory, "pom.xml" );
	final MavenProject mvnProject = new MavenProject() ;
	mvnProject.setFile( pom ) ;
	mvnProject.setVersion( version );
	mvnProject.getBuild().setDirectory( modelDirectory.getParentFile().getAbsolutePath());
	mvnProject.getBuild().setOutputDirectory( modelDirectory.getAbsolutePath());
	mvnProject.getBuild().setFinalName( finalName );
	mvnProject.setArtifact( new ProjectArtifact( mvnProject ));

	// Copy the resources - mimic what Maven would really do
	Utils.copyDirectory(
			new File( mvnProject.getBasedir(), MavenPluginConstants.SOURCE_MODEL_DIRECTORY ),
			new File( mvnProject.getBuild().getOutputDirectory()));

	// Package
	PackageApplicationMojo packageApplicationMojo = (PackageApplicationMojo) this.rule.lookupMojo( "package-application", pom );
	this.rule.setVariableValueToObject( packageApplicationMojo, "project", mvnProject );
	packageApplicationMojo.execute();

	// Check assertions.
	// Unfortunately, no filtering here.
	Assert.assertTrue( targetArchive.exists());
	targetDirectory = this.folder.newFolder();
	Utils.extractZipArchive( targetArchive, targetDirectory );

	ApplicationLoadResult alr = RuntimeModelIo.loadApplication( targetDirectory );
	Assert.assertEquals( 0, alr.getLoadErrors().size());
	Assert.assertEquals( "1.0.0", alr.getApplicationTemplate().getVersion());

	File notFilteredFile = new File( targetDirectory, "graph/Tomcat/readme.md" );
	Assert.assertTrue( notFilteredFile.exists());

	String content = Utils.readFileContent( notFilteredFile );
	Assert.assertTrue( content.contains( "${project.version}" ));
	Assert.assertFalse( content.contains( "1.0-SNAPSHOT" ));
}
 
Example 17
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());
}
 
Example 18
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 19
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 20
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");
}