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

The following examples show how to use org.apache.maven.model.Model#setModelVersion() . 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: CreateProjectTest.java    From quarkus with 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 File: ExportServiceAction.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
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 3
Source File: DefaultFileUploadService.java    From archiva with Apache License 2.0 6 votes vote down vote up
private StorageAsset createPom(StorageAsset targetPath, String filename, FileMetadata fileMetadata, String groupId,
                       String artifactId, String version, String packaging)
        throws IOException {
    Model projectModel = new Model();
    projectModel.setModelVersion("4.0.0");
    projectModel.setGroupId(groupId);
    projectModel.setArtifactId(artifactId);
    projectModel.setVersion(version);
    projectModel.setPackaging(packaging);

    StorageAsset pomFile = targetPath.resolve(filename);
    MavenXpp3Writer writer = new MavenXpp3Writer();

    try (Writer w = new OutputStreamWriter(pomFile.getWriteStream(true))) {
        writer.write(w, projectModel);
    }

    return pomFile;
}
 
Example 4
Source File: DistributionEnforcingManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@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
Source File: DistributionEnforcingManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@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 6
Source File: Pom.java    From buck with Apache License 2.0 6 votes vote down vote up
private Model constructModel() {
  File file = path.toFile();
  Model model = new Model();
  model.setModelVersion(POM_MODEL_VERSION);

  if (publishable.getPomTemplate().isPresent()) {
    model =
        constructModel(
            pathResolver.getAbsolutePath(publishable.getPomTemplate().get()).toFile(), model);
  }

  if (file.isFile()) {
    model = constructModel(file, model);
  }

  return model;
}
 
Example 7
Source File: MavenUtils.java    From developer-studio with 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 8
Source File: BOMBuilderManipulator.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
private Model createModel( Project project, String s )
{
   final Model newModel = new Model();
    newModel.setModelVersion( project.getModel().getModelVersion() );

    newModel.setGroupId( project.getGroupId() + '.' + project.getArtifactId() );
    newModel.setArtifactId( s );
    newModel.setVersion( project.getVersion() );
    newModel.setPackaging( "pom" );

    return newModel;
}
 
Example 9
Source File: PomIOTest.java    From pom-manipulation-ext with 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 10
Source File: PomIOTest.java    From pom-manipulation-ext with 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 11
Source File: PomIOTest.java    From pom-manipulation-ext with 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 File: MavenCreator.java    From microprofile-starter with Apache License 2.0 4 votes vote down vote up
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 13
Source File: PomProperty.java    From flatten-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void set( Model model, String value )
{
    model.setModelVersion( value );
}