List of usage examples for org.apache.maven.project MavenProject setVersion
public void setVersion(String version)
From source file:de.eacg.ecs.plugin.ProjectFix.java
public static void fixProject(MavenProject model) { Artifact a = model.getArtifact();/*from w w w. ja va 2 s. c om*/ String str = String.format("%s:%s:%s:%s:%s", a.getGroupId(), a.getArtifactId(), a.getType(), a.hasClassifier() ? a.getClassifier() : "", a.getVersion()); String fixed = lookup.get(str); if (fixed != null) { String[] parts = fixed.split(":"); if (parts.length == 5) { model.setGroupId(parts[0]); model.setArtifactId(parts[1]); model.setPackaging(parts[2]); model.setVersion(parts[4]); model.setArtifact(new DefaultArtifact(parts[0], parts[1], parts[4], model.getArtifact().getScope(), parts[2], parts[3].isEmpty() ? null : parts[3], model.getArtifact().getArtifactHandler())); } } }
From source file:de.jiac.micro.util.ReducedArchiver.java
License:Open Source License
public void createArchive(MavenProject project, MavenArchiveConfiguration archiveConfiguration) throws ArchiverException, ManifestException, IOException, DependencyResolutionRequiredException { // ---------------------------------------------------------------------- // We want to add the metadata for the project to the JAR in two forms: ///*w ww .j a va 2 s. c om*/ // The first form is that of the POM itself. Applications that wish to // access the POM for an artifact using maven tools they can. // // The second form is that of a properties file containing the basic // top-level POM elements so that applications that wish to access // POM information without the use of maven tools can do so. // ---------------------------------------------------------------------- // we have to clone the project instance so we can write out the pom with the deployment version, // without impacting the main project instance... MavenProject workingProject = new MavenProject(project); if (workingProject.getArtifact().isSnapshot()) { workingProject.setVersion(workingProject.getArtifact().getVersion()); } // ---------------------------------------------------------------------- // Create the manifest // ---------------------------------------------------------------------- File manifestFile = archiveConfiguration.getManifestFile(); if (manifestFile != null) { archiver.setManifest(manifestFile); } Manifest manifest = getManifest(workingProject, archiveConfiguration.getManifest()); // any custom manifest entries in the archive configuration manifest? if (!archiveConfiguration.isManifestEntriesEmpty()) { Map entries = archiveConfiguration.getManifestEntries(); Set entrySet = entries.entrySet(); for (Iterator iter = entrySet.iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String key = (String) entry.getKey(); String value = (String) entry.getValue(); Manifest.Attribute attr = new Manifest.Attribute(key, value); manifest.addConfiguredAttribute(attr); } } // any custom manifest sections in the archive configuration manifest? if (!archiveConfiguration.isManifestSectionsEmpty()) { List sections = archiveConfiguration.getManifestSections(); for (Iterator iter = sections.iterator(); iter.hasNext();) { ManifestSection section = (ManifestSection) iter.next(); Manifest.Section theSection = new Manifest.Section(); theSection.setName(section.getName()); if (!section.isManifestEntriesEmpty()) { Map entries = section.getManifestEntries(); Set keys = entries.keySet(); for (Iterator it = keys.iterator(); it.hasNext();) { String key = (String) it.next(); String value = (String) entries.get(key); Manifest.Attribute attr = new Manifest.Attribute(key, value); theSection.addConfiguredAttribute(attr); } } manifest.addConfiguredSection(theSection); } } // Configure the jar archiver.addConfiguredManifest(manifest); archiver.setCompress(archiveConfiguration.isCompress()); archiver.setIndex(archiveConfiguration.isIndex()); archiver.setDestFile(archiveFile); // create archive archiver.createArchive(); }
From source file:fr.brouillard.oss.jgitver.JGitverExtension.java
License:Apache License
@Override public void afterProjectsRead(MavenSession mavenSession) throws MavenExecutionException { MavenProject rootProject = mavenSession.getTopLevelProject(); List<MavenProject> projects = locateProjects(mavenSession, rootProject.getModules()); Map<GAV, String> newProjectVersions = new LinkedHashMap<>(); if (JGitverModelProcessor.class.isAssignableFrom(modelProcessor.getClass())) { JGitverModelProcessor jGitverModelProcessor = JGitverModelProcessor.class.cast(modelProcessor); JGitverModelProcessorWorkingConfiguration workingConfiguration = jGitverModelProcessor .getWorkingConfiguration(); if (workingConfiguration == null) { logger.warn(""); logger.warn("jgitver has changed!"); logger.warn(""); logger.warn(//from ww w . j a v a 2 s. c o m "it now requires the usage of maven core extensions instead of standard plugin extensions."); logger.warn("The plugin must be now declared in a `.mvn/extensions.xml` file."); logger.warn(""); logger.warn(" read https://github.com/jgitver/jgitver-maven-plugin for further information"); logger.warn(""); throw new MavenExecutionException("detection of jgitver old setting mechanism", new IllegalStateException("jgitver must now use maven core extensions")); } newProjectVersions = workingConfiguration.getNewProjectVersions(); } else { logger.info("jgitver-maven-plugin is about to change project(s) version(s)"); String newVersion = null; try { newVersion = JGitverUtils .calculateVersionForProject(rootProject, mavenSession.getUserProperties(), logger) .getCalculatedVersion(); } catch (IOException ex) { throw new MavenExecutionException("failure calculating version from git information", ex); } // Let's modify in memory resolved projects model for (MavenProject project : projects) { GAV projectGAV = GAV.from(project); // SUPPRESS CHECKSTYLE AbbreviationAsWordInName logger.debug("about to change in memory POM for: " + projectGAV); // First the project itself project.setVersion(newVersion); logger.debug(" version set to " + newVersion); VersionRange newVersionRange = VersionRange.createFromVersion(newVersion); project.getArtifact().setVersionRange(newVersionRange); logger.debug(" artifact version range set to " + newVersionRange); newProjectVersions.put(projectGAV, newVersion); // No need to worry about parent link, because model is in memory } try { JGitverUtils.attachModifiedPomFilesToTheProject(projects, newProjectVersions, mavenSession, logger); } catch (IOException | XmlPullParserException ex) { throw new MavenExecutionException("cannot attach updated POMs during project execution", ex); } } newProjectVersions.entrySet() .forEach(e -> logger.info(" " + e.getKey().toString() + " -> " + e.getValue())); }
From source file:io.konig.maven.KonigSchemagenMojo.java
License:Apache License
private void buildPackagingProject() throws IOException, ParseException, MavenInvocationException { MavenPackagingProjectGenerator generator = new MavenPackagingProjectGenerator(); PackagingProjectRequest request = new PackagingProjectRequest(); request.setBasedir(mavenProject.getBasedir()); io.konig.schemagen.packaging.MavenProject deployProject = new io.konig.schemagen.packaging.MavenProject(); deployProject.setGroupId(mavenProject.getGroupId()); deployProject.setArtifactId(mavenProject.getArtifactId()); deployProject.setVersion(mavenProject.getVersion()); deployProject.setName(mavenProject.getName()); request.setMavenProject(deployProject); File logDir = new File("target/logs"); logDir.mkdirs();//from w w w.ja v a 2 s .c om request.setVelocityLogFile(new File(logDir, "velocity.log")); if (googleCloudPlatform != null) { request.addPackage( new MavenPackage(ResourceKind.gcp).include(GCP_PATTERN, "/gcp", "deployment/config.yaml")); } File pomFile = generator.generate(request); InvocationRequest invokeRequest = new DefaultInvocationRequest(); List<String> goalList = mavenSession.getGoals(); invokeRequest.setPomFile(pomFile); invokeRequest.setGoals(goalList); Invoker invoker = new DefaultInvoker(); invoker.setMavenHome(mavenHome()); invoker.execute(invokeRequest); }
From source file:io.sundr.maven.GenerateBomMojo.java
License:Apache License
/** * Returns the model of the {@link org.apache.maven.project.MavenProject} to generate. * This is a trimmed down version and contains just the stuff that need to go into the bom. * * @param project The source {@link org.apache.maven.project.MavenProject}. * @param config The {@link io.sundr.maven.BomConfig}. * @return The build {@link org.apache.maven.project.MavenProject}. *//*from ww w . j av a2 s . c om*/ private static MavenProject toGenerate(MavenProject project, BomConfig config, Collection<Dependency> dependencies, Set<Artifact> plugins) { MavenProject toGenerate = project.clone(); toGenerate.setGroupId(project.getGroupId()); toGenerate.setArtifactId(config.getArtifactId()); toGenerate.setVersion(project.getVersion()); toGenerate.setPackaging("pom"); toGenerate.setName(config.getName()); toGenerate.setDescription(config.getDescription()); toGenerate.setUrl(project.getUrl()); toGenerate.setLicenses(project.getLicenses()); toGenerate.setScm(project.getScm()); toGenerate.setDevelopers(project.getDevelopers()); toGenerate.getModel().setDependencyManagement(new DependencyManagement()); for (Dependency dependency : dependencies) { toGenerate.getDependencyManagement().addDependency(dependency); } toGenerate.getModel().setBuild(new Build()); if (!plugins.isEmpty()) { toGenerate.getModel().setBuild(new Build()); toGenerate.getModel().getBuild().setPluginManagement(new PluginManagement()); for (Artifact artifact : plugins) { toGenerate.getPluginManagement().addPlugin(toPlugin(artifact)); } } return toGenerate; }
From source file:io.sundr.maven.GenerateBomMojo.java
License:Apache License
/** * Returns the generated {@link org.apache.maven.project.MavenProject} to build. * This version of the project contains all the stuff needed for building (parents, profiles, properties etc). * * @param project The source {@link org.apache.maven.project.MavenProject}. * @param config The {@link io.sundr.maven.BomConfig}. * @return The build {@link org.apache.maven.project.MavenProject}. *///from w w w . j av a 2 s .c o m private static MavenProject toBuild(MavenProject project, BomConfig config) { File outputDir = new File(project.getBuild().getOutputDirectory()); File bomDir = new File(outputDir, config.getArtifactId()); File generatedBom = new File(bomDir, BOM_NAME); MavenProject toBuild = project.clone(); //we want to avoid recursive "generate-bom". toBuild.setExecutionRoot(false); toBuild.setFile(generatedBom); toBuild.getModel().setPomFile(generatedBom); toBuild.setModelVersion(project.getModelVersion()); toBuild.setArtifact(new DefaultArtifact(project.getGroupId(), config.getArtifactId(), project.getVersion(), project.getArtifact().getScope(), project.getArtifact().getType(), project.getArtifact().getClassifier(), project.getArtifact().getArtifactHandler())); toBuild.setParent(project.getParent()); toBuild.getModel().setParent(project.getModel().getParent()); toBuild.setGroupId(project.getGroupId()); toBuild.setArtifactId(config.getArtifactId()); toBuild.setVersion(project.getVersion()); toBuild.setPackaging("pom"); toBuild.setName(config.getName()); toBuild.setDescription(config.getDescription()); toBuild.setUrl(project.getUrl()); toBuild.setLicenses(project.getLicenses()); toBuild.setScm(project.getScm()); toBuild.setDevelopers(project.getDevelopers()); toBuild.setDistributionManagement(project.getDistributionManagement()); toBuild.getModel().setProfiles(project.getModel().getProfiles()); //We want to avoid having the generated stuff wiped. toBuild.getProperties().put("clean.skip", "true"); toBuild.getModel().getBuild().setDirectory(bomDir.getAbsolutePath()); toBuild.getModel().getBuild().setOutputDirectory(new File(bomDir, "target").getAbsolutePath()); for (String key : config.getProperties().stringPropertyNames()) { toBuild.getProperties().put(key, config.getProperties().getProperty(key)); } return toBuild; }
From source file:org.apache.hyracks.maven.license.LicenseMojo.java
License:Apache License
protected MavenProject resolveDependency(Artifact depObj) throws ProjectBuildingException { String key = depObj.getGroupId() + ":" + depObj.getArtifactId() + ":" + depObj.getVersion(); MavenProject depProj = projectCache.get(key); if (depProj == null) { try {//from w ww. j a va 2s . c o m depProj = projectBuilder.buildFromRepository(depObj, remoteRepositories, localRepository, false); } catch (ProjectBuildingException e) { throw new ProjectBuildingException(key, "Error creating dependent artifacts", e); } Model supplement = supplementModels.get( SupplementalModelHelper.generateSupplementMapKey(depObj.getGroupId(), depObj.getArtifactId())); if (supplement != null) { Model merged = SupplementalModelHelper.mergeModels(assembler, depProj.getModel(), supplement); Set<String> origLicenses = depProj.getModel().getLicenses().stream().map(License::getUrl) .collect(Collectors.toSet()); Set<String> newLicenses = merged.getLicenses().stream().map(License::getUrl) .collect(Collectors.toSet()); if (!origLicenses.equals(newLicenses)) { getLog().warn("license list for " + toGav(depProj) + " changed with supplemental model; was: " + origLicenses + ", now: " + newLicenses); } depProj = new MavenProject(merged); depProj.setArtifact(depObj); depProj.setVersion(depObj.getVersion()); } depProj.getArtifact().setScope(depObj.getScope()); projectCache.put(key, depProj); } return depProj; }
From source file:org.codehaus.griffon.maven.plugin.tools.DefaultGriffonServices.java
License:Apache License
public MavenProject createPOM(String groupId, GriffonProject griffonProjectDescriptor, String mtgGroupId, String griffonPluginArtifactId, String mtgVersion, boolean addEclipseSettings) { MavenProject pom = new MavenProject(); if (pom.getBuild().getPluginManagement() == null) { pom.getBuild().setPluginManagement(new PluginManagement()); }//from ww w . java 2 s .c o m PluginManagement pluginMgt = pom.getPluginManagement(); // Those four properties are needed. pom.setModelVersion("4.0.0"); pom.setPackaging("griffon-app"); // Specific for GRAILS pom.getModel().getProperties().setProperty("griffonHome", "${env.GRIFFON_HOME}"); pom.getModel().getProperties().setProperty("griffonVersion", griffonProjectDescriptor.getAppGriffonVersion()); // Add our own plugin Plugin griffonPlugin = new Plugin(); griffonPlugin.setGroupId(mtgGroupId); griffonPlugin.setArtifactId(griffonPluginArtifactId); griffonPlugin.setVersion(mtgVersion); griffonPlugin.setExtensions(true); pom.addPlugin(griffonPlugin); // Add compiler plugin settings Plugin compilerPlugin = new Plugin(); compilerPlugin.setGroupId("org.apache.maven.plugins"); compilerPlugin.setArtifactId("maven-compiler-plugin"); Xpp3Dom compilerConfig = new Xpp3Dom("configuration"); Xpp3Dom source = new Xpp3Dom("source"); source.setValue("1.5"); compilerConfig.addChild(source); Xpp3Dom target = new Xpp3Dom("target"); target.setValue("1.5"); compilerConfig.addChild(target); compilerPlugin.setConfiguration(compilerConfig); pom.addPlugin(compilerPlugin); // Add eclipse plugin settings if (addEclipseSettings) { Plugin eclipsePlugin = new Plugin(); eclipsePlugin.setGroupId("org.apache.maven.plugins"); eclipsePlugin.setArtifactId("maven-eclipse-plugin"); Xpp3Dom configuration = new Xpp3Dom("configuration"); Xpp3Dom projectnatures = new Xpp3Dom("additionalProjectnatures"); Xpp3Dom projectnature = new Xpp3Dom("projectnature"); projectnature.setValue("org.codehaus.groovy.eclipse.groovyNature"); projectnatures.addChild(projectnature); configuration.addChild(projectnatures); Xpp3Dom additionalBuildcommands = new Xpp3Dom("additionalBuildcommands"); Xpp3Dom buildcommand = new Xpp3Dom("buildcommand"); buildcommand.setValue("org.codehaus.groovy.eclipse.groovyBuilder"); additionalBuildcommands.addChild(buildcommand); configuration.addChild(additionalBuildcommands); Xpp3Dom packaging = new Xpp3Dom("packaging"); packaging.setValue("zip"); configuration.addChild(packaging); eclipsePlugin.setConfiguration(configuration); pluginMgt.addPlugin(eclipsePlugin); } // Change the default output directory to generate classes pom.getModel().getBuild().setOutputDirectory("web-app/WEB-INF/classes"); pom.setArtifactId(griffonProjectDescriptor.getAppName()); pom.setName(griffonProjectDescriptor.getAppName()); pom.setGroupId(groupId); pom.setVersion(griffonProjectDescriptor.getAppVersion()); if (!griffonProjectDescriptor.getAppVersion().endsWith("SNAPSHOT")) { getLogger().warn("====================================================================="); getLogger().warn("If your project is currently in development, in accordance with maven "); getLogger().warn("standards, its version must be " + griffonProjectDescriptor.getAppVersion() + "-SNAPSHOT and not " + griffonProjectDescriptor.getAppVersion() + "."); getLogger().warn("Please, change your version in the application.properties descriptor"); getLogger().warn("and regenerate your pom."); getLogger().warn("====================================================================="); } return pom; }
From source file:org.grails.maven.plugin.tools.DefaultGrailsServices.java
License:Apache License
public MavenProject createPOM(final String groupId, final GrailsProject grailsProjectDescriptor, final String mtgGroupId, final String grailsPluginArtifactId, final String mtgVersion, final boolean addEclipseSettings) { final MavenProject pom = new MavenProject(); if (pom.getBuild().getPluginManagement() == null) { pom.getBuild().setPluginManagement(new PluginManagement()); }/*from www.j a va 2 s. co m*/ final PluginManagement pluginMgt = pom.getPluginManagement(); // Those four properties are needed. pom.setModelVersion("4.0.0"); pom.setPackaging("grails-app"); // Specific for GRAILS pom.getModel().getProperties().setProperty("grailsHome", "${env.GRAILS_HOME}"); pom.getModel().getProperties().setProperty("grailsVersion", grailsProjectDescriptor.getAppGrailsVersion()); // Add our own plugin final Plugin grailsPlugin = new Plugin(); grailsPlugin.setGroupId(mtgGroupId); grailsPlugin.setArtifactId(grailsPluginArtifactId); grailsPlugin.setVersion(mtgVersion); grailsPlugin.setExtensions(true); pom.addPlugin(grailsPlugin); // Add compiler plugin settings final Plugin compilerPlugin = new Plugin(); compilerPlugin.setGroupId("org.apache.maven.plugins"); compilerPlugin.setArtifactId("maven-compiler-plugin"); final Xpp3Dom compilerConfig = new Xpp3Dom("configuration"); final Xpp3Dom source = new Xpp3Dom("source"); source.setValue("1.5"); compilerConfig.addChild(source); final Xpp3Dom target = new Xpp3Dom("target"); target.setValue("1.5"); compilerConfig.addChild(target); compilerPlugin.setConfiguration(compilerConfig); pom.addPlugin(compilerPlugin); // Add eclipse plugin settings if (addEclipseSettings) { final Plugin warPlugin = new Plugin(); warPlugin.setGroupId("org.apache.maven.plugins"); warPlugin.setArtifactId("maven-war-plugin"); final Xpp3Dom warConfig = new Xpp3Dom("configuration"); final Xpp3Dom warSourceDirectory = new Xpp3Dom("warSourceDirectory"); warSourceDirectory.setValue("web-app"); warConfig.addChild(warSourceDirectory); warPlugin.setConfiguration(warConfig); pluginMgt.addPlugin(warPlugin); final Plugin eclipsePlugin = new Plugin(); eclipsePlugin.setGroupId("org.apache.maven.plugins"); eclipsePlugin.setArtifactId("maven-eclipse-plugin"); final Xpp3Dom configuration = new Xpp3Dom("configuration"); final Xpp3Dom projectnatures = new Xpp3Dom("additionalProjectnatures"); final Xpp3Dom projectnature = new Xpp3Dom("projectnature"); projectnature.setValue("org.codehaus.groovy.eclipse.groovyNature"); projectnatures.addChild(projectnature); configuration.addChild(projectnatures); final Xpp3Dom additionalBuildcommands = new Xpp3Dom("additionalBuildcommands"); final Xpp3Dom buildcommand = new Xpp3Dom("buildcommand"); buildcommand.setValue("org.codehaus.groovy.eclipse.groovyBuilder"); additionalBuildcommands.addChild(buildcommand); configuration.addChild(additionalBuildcommands); // Xpp3Dom additionalProjectFacets = new Xpp3Dom( // "additionalProjectFacets"); // Xpp3Dom jstWeb = new Xpp3Dom("jst.web"); // jstWeb.setValue("2.5"); // additionalProjectFacets.addChild(jstWeb); // configuration.addChild(additionalProjectFacets); final Xpp3Dom packaging = new Xpp3Dom("packaging"); packaging.setValue("war"); configuration.addChild(packaging); eclipsePlugin.setConfiguration(configuration); pluginMgt.addPlugin(eclipsePlugin); } // Change the default output directory to generate classes pom.getModel().getBuild().setOutputDirectory("web-app/WEB-INF/classes"); pom.setArtifactId(grailsProjectDescriptor.getAppName()); pom.setName(grailsProjectDescriptor.getAppName()); pom.setGroupId(groupId); pom.setVersion(grailsProjectDescriptor.getAppVersion()); if (!grailsProjectDescriptor.getAppVersion().endsWith("SNAPSHOT")) { getLogger().warn("====================================================================="); getLogger().warn("If your project is currently in development, in accordance with maven "); getLogger().warn("standards, its version must be " + grailsProjectDescriptor.getAppVersion() + "-SNAPSHOT and not " + grailsProjectDescriptor.getAppVersion() + "."); getLogger().warn("Please, change your version in the application.properties descriptor"); getLogger().warn("and regenerate your pom."); getLogger().warn("====================================================================="); } return pom; }
From source file:org.ops4j.pax.construct.lifecycle.ProvisionMojo.java
License:Apache License
/** * Create new POM (based on the root POM) which lists the deployed bundles as dependencies * //from w w w .j ava 2s . c o m * @param bundles list of bundles to be deployed * @return deployment project * @throws MojoExecutionException */ private MavenProject createDeploymentProject(List bundles) throws MojoExecutionException { MavenProject deployProject; if (null == m_project.getFile()) { deployProject = new MavenProject(); deployProject.setGroupId("examples"); deployProject.setArtifactId("pax-provision"); deployProject.setVersion("1.0-SNAPSHOT"); } else { deployProject = new MavenProject(m_project); } String internalId = PomUtils.getCompoundId(deployProject.getGroupId(), deployProject.getArtifactId()); deployProject.setGroupId(internalId + ".build"); deployProject.setArtifactId("deployment"); // remove unnecessary cruft deployProject.setPackaging("pom"); deployProject.getModel().setModules(null); deployProject.getModel().setDependencies(bundles); deployProject.getModel().setPluginRepositories(null); deployProject.getModel().setReporting(null); deployProject.setBuild(null); File deployFile = new File(deployProject.getBasedir(), "runner/deploy-pom.xml"); deployFile.getParentFile().mkdirs(); deployProject.setFile(deployFile); try { Writer writer = StreamFactory.newXmlWriter(deployFile); deployProject.writeModel(writer); IOUtil.close(writer); } catch (IOException e) { throw new MojoExecutionException("Unable to write deployment POM " + deployFile); } return deployProject; }