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

The following examples show how to use org.apache.maven.model.Model#setArtifactId() . 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: maven-git-versioning-extension   File: GAVTest.java    License: MIT License 6 votes vote down vote up
@Test
void of_model_withParent_withInheritance() {
    // Given
    Model model = new Model();
    model.setArtifactId("artifact");

    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("parentGroup");
    assertThat(gav.getArtifactId()).isEqualTo("artifact");
    assertThat(gav.getVersion()).isEqualTo("parentVersion");
}
 
Example 2
@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 3
protected ITalendProcessJavaProject createServiceJavaProject() {
    IProgressMonitor monitor = new NullProgressMonitor();

    // temp model.
    Model model = new Model();
    model.setModelVersion("4.0.0"); //$NON-NLS-1$
    model.setGroupId(PomIdsHelper.getJobGroupId(serviceItem.getProperty()));
    model.setArtifactId(PomIdsHelper.getJobArtifactId(serviceItem.getProperty())); // $NON-NLS-1$
    model.setVersion(PomIdsHelper.getProjectVersion());
    model.setPackaging(TalendMavenConstants.PACKAGING_JAR);

    // always use temp model to avoid classpath problem
    final ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration();
    IProject root = ResourcesPlugin.getWorkspace().getRoot()
            .getProject(ProjectManager.getInstance().getCurrentProject().getTechnicalLabel());
    try {
        return createSimpleProject(monitor, root, model, importConfiguration);
    } catch (CoreException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 4
@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 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
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 7
@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 8
public MavenPomFileGenerator(MavenProjectIdentity identity) {
    mavenProject.setModelVersion(POM_VERSION);
    Model model = getModel();
    model.setGroupId(identity.getGroupId());
    model.setArtifactId(identity.getArtifactId());
    model.setVersion(identity.getVersion());
}
 
Example 9
public MavenPomFileGenerator(MavenProjectIdentity identity) {
    mavenProject.setModelVersion(POM_VERSION);
    Model model = getModel();
    model.setGroupId(identity.getGroupId());
    model.setArtifactId(identity.getArtifactId());
    model.setVersion(identity.getVersion());
}
 
Example 10
Source Project: butterfly   File: PomFileTest.java    License: MIT License 5 votes vote down vote up
@BeforeClass
private static void setUpModel() {
    model = new Model();
    model.setGroupId("com.test");
    model.setArtifactId("foo");
    model.setVersion("1.0");
}
 
Example 11
Source Project: pom-manipulation-ext   File: PomIOTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteModel()
                throws Exception
{
    // Thanks to http://www.buildmystring.com
    String sb = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                    + "<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n"
                    + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
                    + "  <modelVersion>4.0.0</modelVersion>\n"
                    + "  <groupId>org.commonjava.maven.ext.versioning.test</groupId>\n"
                    + "  <artifactId>dospom</artifactId>\n" + "  <version>1.0</version>\n"
                    + "  <packaging>pom</packaging>\n" + "</project>\n";

    URL resource = PomIOTest.class.getResource( filename );
    assertNotNull( resource );
    File pom = new File( resource.getFile() );
    assertTrue( pom.exists() );

    File targetFile = folder.newFile( "target.xml" );

    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" );

    pomIO.writeModel( model, targetFile );
    assertTrue( targetFile.exists() );
    assertEquals( sb, FileUtils.readFileToString( targetFile, StandardCharsets.UTF_8 ) );
}
 
Example 12
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 13
@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 14
@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 15
@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 16
@Test(expected = ValidationErrorsException.class)
public void testValidatePom_missingVersion() {
  Model model = new Model();
  model.setArtifactId("testArtifact");
  model.setGroupId("testGroup");
  underTest.validatePom(model);
}
 
Example 17
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 18
@Override
public void set( Model model, String value )
{
    model.setArtifactId( value );
}
 
Example 19
private Model createSingleModule(JessieModel model) {

        Model pomFile = new Model();
        pomFile.setModelVersion("4.0.0");

        pomFile.setGroupId(model.getMaven().getGroupId());
        pomFile.setArtifactId(model.getMaven().getArtifactId());
        pomFile.setVersion("1.0-SNAPSHOT");

        pomFile.setPackaging("war");

        addDependencies(pomFile, model);

        addJavaSEVersionProperties(pomFile, model);

        pomFile.addProperty("failOnMissingWebXml", "false");

        pomFile.addProperty("final.name", model.getMaven().getArtifactId());

        Build build = new Build();
        build.setFinalName(model.getMaven().getArtifactId());
        pomFile.setBuild(build);

        return pomFile;
    }
 
Example 20
private ModelWrapper model(String projectName, String groupId) {
	Model parent = new Model();
	parent.setArtifactId(projectName);
	parent.setGroupId(groupId);
	return new ModelWrapper(parent);
}