Java Code Examples for org.apache.maven.model.Model#setGroupId()

The following examples show how to use org.apache.maven.model.Model#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: quarkus   File: CreateProjectTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void createOnTopOfExisting() throws Exception {
    final File testDir = new File("target/existing");
    delete(testDir);
    testDir.mkdirs();

    Model model = new Model();
    model.setModelVersion("4.0.0");
    model.setGroupId("org.acme");
    model.setArtifactId("foobar");
    model.setVersion("10.1.2");
    final File pom = new File(testDir, "pom.xml");
    MojoUtils.write(model, pom);
    assertThatExceptionOfType(QuarkusCommandException.class).isThrownBy(() -> {
        new CreateProject(testDir.toPath(), getPlatformDescriptor())
                .groupId("something.is")
                .artifactId("wrong")
                .version("1.0.0-SNAPSHOT")
                .className("org.foo.MyResource")
                .execute();
    }).withRootCauseInstanceOf(IOException.class);
}
 
Example 2
Source Project: maven-git-versioning-extension   File: GAVTest.java    License: MIT License 6 votes vote down vote up
@Test
void of_model_withParent_noInheritance() {
    // Given
    Model model = new Model();
    model.setGroupId("group");
    model.setArtifactId("artifact");
    model.setVersion("version");

    Parent parent = new Parent();
    parent.setGroupId("parentGroup");
    parent.setArtifactId("parentArtifact");
    parent.setVersion("parentVersion");
    model.setParent(parent);

    // When
    GAV gav = GAV.of(model);

    // Then
    assertThat(gav).isNotNull();
    assertThat(gav.getGroupId()).isEqualTo("group");
    assertThat(gav.getArtifactId()).isEqualTo("artifact");
    assertThat(gav.getVersion()).isEqualTo("version");
}
 
Example 3
@Test
public void projectDeploySkipTurnedOffWhenModeIsOff()
    throws Exception
{
    final Plugin plugin = new Plugin();
    plugin.setGroupId( MAVEN_PLUGIN_GROUPID );
    plugin.setArtifactId( MAVEN_DEPLOY_ARTIFACTID );
    plugin.setConfiguration( simpleSkipConfig( true ) );

    final Build build = new Build();
    build.addPlugin( plugin );

    final Model model = new Model();
    model.setModelVersion( "4.0.0" );
    model.setGroupId( "org.foo" );
    model.setArtifactId( "bar" );
    model.setVersion( "1" );

    model.setBuild( build );

    applyTest( off, model, model );
    assertSkip( model, null );
}
 
Example 4
@Test
public void projectUnchangedWhenModeIsNone()
    throws Exception
{
    final Plugin plugin = new Plugin();
    plugin.setGroupId( MAVEN_PLUGIN_GROUPID );
    plugin.setArtifactId( MAVEN_DEPLOY_ARTIFACTID );
    plugin.setConfiguration( simpleSkipConfig( true ) );

    final Build build = new Build();
    build.addPlugin( plugin );

    final Model model = new Model();
    model.setModelVersion( "4.0.0" );
    model.setGroupId( "org.foo" );
    model.setArtifactId( "bar" );
    model.setVersion( "1" );

    model.setBuild( build );

    applyTest( none, model, null );
}
 
Example 5
public MavenPomFileGenerator(MavenProjectIdentity identity) {
    mavenProject.setModelVersion(POM_VERSION);
    Model model = getModel();
    model.setGroupId(identity.getGroupId());
    model.setArtifactId(identity.getArtifactId());
    model.setVersion(identity.getVersion());
}
 
Example 6
public MavenPomFileGenerator(MavenProjectIdentity identity) {
    mavenProject.setModelVersion(POM_VERSION);
    Model model = getModel();
    model.setGroupId(identity.getGroupId());
    model.setArtifactId(identity.getArtifactId());
    model.setVersion(identity.getVersion());
}
 
Example 7
Source Project: raptor   File: PomGenerator.java    License: Apache License 2.0 5 votes vote down vote up
public Model buildModel() {
    Model model = readExamplePom();
    model.setArtifactId(pomModel.getArtifactId());
    model.setGroupId(pomModel.getGroupId());
    model.setVersion(pomModel.getVersion());
    return model;
}
 
Example 8
@Test (expected = ManipulationException.class )
public void verifyProjectValidation() throws ManipulationException
{
    final Model m = new Model();
    m.setGroupId( "org.foo" );
    m.setArtifactId( "bar" );
    new Project( m );
}
 
Example 9
Source Project: pom-manipulation-ext   File: PomIOTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGAVReturnPOMs()
                throws Exception
{
    URL resource = PomIOTest.class.getResource( filename );
    assertNotNull( resource );
    File pom = new File( resource.getFile() );
    assertTrue( pom.exists() );

    File targetFile = folder.newFile( "target.xml" );
    FileUtils.copyFile( pom, targetFile );

    Model model = new Model();
    model.setGroupId( "org.commonjava.maven.ext.versioning.test" );
    model.setArtifactId( "dospom" );
    model.setVersion( "1.0" );
    model.setPackaging( "pom" );
    model.setModelVersion( "4.0.0" );

    Project p = new Project( targetFile, model );
    p.setExecutionRoot();
    HashSet<Project> changed = new HashSet<>();
    changed.add( p );

    ProjectVersionRef gav = pomIO.rewritePOMs( changed );

    assertEquals( "1.0", gav.getVersionString() );
    assertEquals( "org.commonjava.maven.ext.versioning.test", gav.getGroupId() );
    assertEquals( "dospom", gav.getArtifactId() );
}
 
Example 10
Source Project: pom-manipulation-ext   File: PomIOTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRewritePOMs()
                throws Exception
{
    URL resource = PomIOTest.class.getResource( filename );
    assertNotNull( resource );
    File pom = new File( resource.getFile() );
    assertTrue( pom.exists() );

    File targetFile = folder.newFile( "target.xml" );
    FileUtils.writeStringToFile( targetFile, FileUtils.readFileToString( pom, StandardCharsets.UTF_8 )
                                                      .replaceAll( "dospom", "newdospom" ), StandardCharsets.UTF_8 );
    FileUtils.copyFile( pom, targetFile );

    List<Project> projects = pomIO.parseProject( targetFile );
    Model model = projects.get( 0 ).getModel();
    model.setGroupId( "org.commonjava.maven.ext.versioning.test" );
    model.setArtifactId( "dospom" );
    model.setVersion( "1.0" );
    model.setPackaging( "pom" );
    model.setModelVersion( "4.0.0" );

    Project p = new Project( targetFile, model );
    HashSet<Project> changed = new HashSet<>();
    changed.add( p );
    pomIO.rewritePOMs( changed );

    assertTrue( FileUtils.contentEqualsIgnoreEOL( pom, targetFile, StandardCharsets.UTF_8.toString() ) );
    assertTrue( FileUtils.contentEquals( targetFile, pom ) );
}
 
Example 11
Source Project: developer-studio   File: MavenUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static MavenProject createMavenProject(String groupId, String artifactId, String version, String packagingType) {
	Model model = new Model();
	model.setGroupId(groupId);
	model.setArtifactId(artifactId);
	model.setVersion(version);
	model.setModelVersion("4.0.0");
	model.setName(artifactId);
	model.setDescription(artifactId);
	if (packagingType!=null){
		model.setPackaging(packagingType);
	}
	return new MavenProject(model);
}
 
Example 12
@Test
public void testValidatPom() {
  Model model = new Model();
  model.setGroupId("testGroup");
  model.setArtifactId("testArtifact");
  model.setVersion("1.0");

  underTest.validatePom(model);
}
 
Example 13
@Test
public void testValidatPom_parentVersion() {
  Model model = new Model();
  model.setParent(new Parent());
  model.getParent().setVersion("2.0");
  model.setGroupId("testGroup");
  model.setArtifactId("testArtifact");

  underTest.validatePom(model);
}
 
Example 14
Source Project: pom-manipulation-ext   File: TestUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Model getDummyModel ()
{
    Model result = new Model();
    result.setGroupId( "org.commonjava.maven.ext" );
    result.setArtifactId( "dummy-model" );
    result.setVersion( "1.0.0-SNAPSHOT" );
    return result;
}
 
Example 15
@Test
public void incrementExistingSerialSuffix_TwoProjects_UsingRepositoryMetadata_AvailableOnlyForOne_Padding()
                throws Exception
{
    final String v = "1.2.0.GA";
    final String os = "-foo-001";
    final String ns = "foo-010";

    final Model m1 = new Model();
    m1.setGroupId( GROUP_ID );
    m1.setArtifactId( ARTIFACT_ID );
    m1.setVersion( v + os );
    final Project p1 = new Project( m1 );

    final String a2 = ARTIFACT_ID + "-dep";
    final Model m2 = new Model();
    m2.setGroupId( GROUP_ID );
    m2.setArtifactId( a2 );
    m2.setVersion( v + os );
    final Project p2 = new Project( m2 );

    final Properties props = new Properties();

    props.setProperty( VersioningState.INCREMENT_SERIAL_SUFFIX_SYSPROP, "foo" );
    setupSession( props, "1.2.0.GA-foo-003", "1.2.0.GA-foo-002", "1.2.0.GA-foo-009" );

    System.out.println ("### Calculating versioning changes for projects " + p1 + " and " + p2);
    final Map<ProjectVersionRef, String>
                    result = modder.calculateVersioningChanges( Arrays.asList( p1, p2 ), session );

    assertThat( result.get( new SimpleProjectVersionRef( GROUP_ID, ARTIFACT_ID, v + os ) ), equalTo( v + "-" + ns ) );
    assertThat( result.get( new SimpleProjectVersionRef( GROUP_ID, a2, v + os ) ), equalTo( v + "-" + ns ) );
}
 
Example 16
@Test(expected = ValidationErrorsException.class)
public void testValidatePom_versionWithProperty() {
  Model model = new Model();
  model.setArtifactId("testArtifact");
  model.setGroupId("testGroup");
  model.setVersion("${aProperty}");
  underTest.validatePom(model);
}
 
Example 17
Source Project: packagedrone   File: Pom.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void writePom ( final Writer writer ) throws IOException
{
    final Model model = new Model ();
    model.setGroupId ( this.groupId );
    model.setArtifactId ( this.artifactId );
    model.setVersion ( this.version );

    new MavenXpp3Writer ().write ( writer, model );
}
 
Example 18
@Test
public void incrementExistingSerialSuffix_TwoProjects_UsingRepositoryMetadata_DifferentAvailableIncrements()
    throws Exception
{
    final String v = "1.2.0.GA";
    final String os = "-foo-1";
    final String ns = "foo-10";

    final Model m1 = new Model();
    m1.setGroupId( GROUP_ID );
    m1.setArtifactId( ARTIFACT_ID );
    m1.setVersion( v + os );
    final Project p1 = new Project( m1 );

    final String a2 = ARTIFACT_ID + "-dep";
    final Model m2 = new Model();
    m2.setGroupId( GROUP_ID );
    m2.setArtifactId( a2 );
    m2.setVersion( v + os );
    final Project p2 = new Project( m2 );

    final Properties props = new Properties();

    props.setProperty( VersioningState.INCREMENT_SERIAL_SUFFIX_SYSPROP, "foo-0" );
    final Map<ProjectRef, String[]> versionMap = new HashMap<>();

    versionMap.put( new SimpleProjectRef( p1.getGroupId(), p1.getArtifactId() ), new String[] { "1.2.0.GA-foo-3",
        "1.2.0.GA-foo-2", "1.2.0.GA-foo-9" } );
    versionMap.put( new SimpleProjectRef( p2.getGroupId(), p2.getArtifactId() ), new String[] { "1.2.0.GA-foo-3",
        "1.2.0.GA-foo-2" } );

    setupSession( props, versionMap );

    final Map<ProjectVersionRef, String>
                    result = modder.calculateVersioningChanges( Arrays.asList( p1, p2 ), session );

    assertThat( result.get( new SimpleProjectVersionRef( GROUP_ID, ARTIFACT_ID, v + os ) ), equalTo( v + "-" + ns ) );
    assertThat( result.get( new SimpleProjectVersionRef( GROUP_ID, a2, v + os ) ), equalTo( v + "-" + ns ) );
}
 
Example 19
@Test
public void updateEffectiveAndOriginalModelMainVersions()
    throws Exception
{
    final Model orig = new Model();
    orig.setGroupId( "org.foo" );
    orig.setArtifactId( "bar" );
    orig.setVersion( "1.0" );

    final Model eff = orig.clone();

    final String suff = AddSuffixJettyHandler.DEFAULT_SUFFIX;
    final String mv = orig.getVersion() + "." + suff;

    final Map<ProjectVersionRef, String> versionsByGAV = new HashMap<>();
    versionsByGAV.put( new SimpleProjectVersionRef( orig.getGroupId(), orig.getArtifactId(), orig.getVersion() ), mv );

    final MavenProject project = new MavenProject( eff );
    project.setOriginalModel( orig );

    final Set<MavenProject> changes =
        newVersioningModifier().applyVersioningChanges( Collections.singletonList( project ), versionsByGAV );

    assertThat( changes.size(), equalTo( 1 ) );
    assertThat( orig.getVersion(), equalTo( mv ) );
    assertThat( eff.getVersion(), equalTo( mv ) );
}
 
Example 20
private ModelWrapper model(String projectName, String groupId) {
	Model parent = new Model();
	parent.setArtifactId(projectName);
	parent.setGroupId(groupId);
	return new ModelWrapper(parent);
}