List of usage examples for org.apache.maven.project MavenProject getVersion
public String getVersion()
From source file:org.apache.sling.maven.projectsupport.LaunchpadPluginLifecycleParticipant.java
License:Apache License
@Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { try {// w w w . j ava 2 s . c o m Map<String, MavenProject> projectMap = new HashMap<String, MavenProject>(); for (MavenProject project : session.getProjects()) { projectMap.put(project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion(), project); } for (MavenProject project : session.getProjects()) { for (Plugin plugin : project.getBuild().getPlugins()) { if (plugin.getArtifactId().equals(PLUGIN_ID)) { BundleListDependencyAdder performer = new BundleListDependencyAdder(session, project, plugin); performer.addDependencies(); } } } } catch (Exception e) { throw new MavenExecutionException("Unable to determine launchpad plugin-based dependencies", e); } super.afterProjectsRead(session); }
From source file:org.apache.tuscany.maven.bundle.plugin.BundlesMetaDataBuildMojo.java
License:Apache License
private void generateManifestJar(ProjectSet jarNames, File root, Log log) throws FileNotFoundException, IOException { for (Map.Entry<String, Set<String>> e : jarNames.nameMap.entrySet()) { MavenProject pom = jarNames.getProject(e.getKey()); Set<String> jars = e.getValue(); String name = trim(e.getKey()); File feature = new File(root, "../" + featuresName + "/" + (useDistributionName ? trim(e.getKey()) : "")); feature.mkdirs();/* w w w .ja v a 2 s .com*/ String manifestName = name + "-manifest.jar"; File mfJar = new File(feature, manifestName); log.info("Generating manifest jar: " + mfJar.getCanonicalPath()); FileOutputStream fos = new FileOutputStream(mfJar); Manifest mf = new Manifest(); StringBuffer cp = new StringBuffer(); String path = (useDistributionName ? "../../" : "../") + root.getName(); for (String jar : jars) { cp.append(path).append('/').append(jar).append(' '); } if (cp.length() > 0) { cp.deleteCharAt(cp.length() - 1); } Attributes attrs = mf.getMainAttributes(); attrs.putValue("Manifest-Version", "1.0"); attrs.putValue("Implementation-Title", pom.getName()); attrs.putValue("Implementation-Vendor", "The Apache Software Foundation"); attrs.putValue("Implementation-Vendor-Id", "org.apache"); attrs.putValue("Implementation-Version", pom.getVersion()); attrs.putValue("Class-Path", cp.toString()); attrs.putValue("Main-Class", "org.apache.tuscany.sca.node.launcher.NodeMain"); JarOutputStream jos = new JarOutputStream(fos, mf); addFileToJar(jos, "META-INF/LICENSE", getClass().getResource("LICENSE.txt")); addFileToJar(jos, "META-INF/NOTICE", getClass().getResource("NOTICE.txt")); jos.close(); } }
From source file:org.apache.tuscany.maven.bundle.plugin.ModuleBundlesBuildMojo.java
License:Apache License
private void generateManifestJar(ProjectSet jarNames, File root, Log log) throws FileNotFoundException, IOException { for (Map.Entry<String, Set<String>> e : jarNames.nameMap.entrySet()) { MavenProject pom = jarNames.getProject(e.getKey()); Set<String> jars = e.getValue(); File feature = new File(root, "../" + featuresName + "/" + (useDistributionName ? trim(e.getKey()) : "")); feature.mkdirs();/*from w w w .j a v a 2 s . c o m*/ File mfJar = new File(feature, manifestJarName); log.info("Generating manifest jar: " + mfJar.getCanonicalPath()); FileOutputStream fos = new FileOutputStream(mfJar); Manifest mf = new Manifest(); StringBuffer cp = new StringBuffer(); String path = (useDistributionName ? "../../" : "../") + root.getName(); for (String jar : jars) { cp.append(path).append('/').append(jar).append(' '); } if (cp.length() > 0) { cp.deleteCharAt(cp.length() - 1); } Attributes attrs = mf.getMainAttributes(); attrs.putValue("Manifest-Version", "1.0"); attrs.putValue("Implementation-Title", pom.getName()); attrs.putValue("Implementation-Vendor", "The Apache Software Foundation"); attrs.putValue("Implementation-Vendor-Id", "org.apache"); attrs.putValue("Implementation-Version", pom.getVersion()); attrs.putValue("Class-Path", cp.toString()); attrs.putValue("Main-Class", "org.apache.tuscany.sca.node.launcher.NodeMain"); JarOutputStream jos = new JarOutputStream(fos, mf); addFileToJar(jos, "META-INF/LICENSE", getClass().getResource("LICENSE.txt")); addFileToJar(jos, "META-INF/NOTICE", getClass().getResource("NOTICE.txt")); jos.close(); } }
From source file:org.appformer.maven.integration.MavenRepository.java
License:Apache License
protected RemoteRepository getRemoteRepositoryFromDistributionManagement(File pomfile) { MavenProject mavenProject = parseMavenPom(pomfile); DistributionManagement distMan = mavenProject.getDistributionManagement(); if (distMan == null) { return null; }/*from w w w .j ava 2 s. c om*/ DeploymentRepository deployRepo = distMan.getSnapshotRepository() != null && mavenProject.getVersion().endsWith("SNAPSHOT") ? distMan.getSnapshotRepository() : distMan.getRepository(); if (deployRepo == null) { return null; } RemoteRepository.Builder remoteRepoBuilder = new RemoteRepository.Builder(deployRepo.getId(), deployRepo.getLayout(), deployRepo.getUrl()) .setSnapshotPolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN)) .setReleasePolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_WARN)); Server server = MavenSettings.getSettings().getServer(deployRepo.getId()); if (server != null) { MavenEmbedder embedder = MavenProjectLoader.newMavenEmbedder(false); try { Authentication authentication = embedder.getMavenSession().getRepositorySession() .getAuthenticationSelector().getAuthentication(remoteRepoBuilder.build()); remoteRepoBuilder.setAuthentication(authentication); } finally { embedder.dispose(); } } return remoteRepoBuilder.build(); }
From source file:org.artificer.integration.java.artifactbuilder.MavenPomArtifactBuilder.java
License:Apache License
@Override public ArtifactBuilder buildArtifacts(BaseArtifactType primaryArtifact, ArtifactContent artifactContent) throws Exception { super.buildArtifacts(primaryArtifact, artifactContent); try {// w ww.j a v a2 s .c o m Model model = new MavenXpp3Reader().read(getContentStream()); MavenProject project = new MavenProject(model); ((ExtendedDocument) primaryArtifact).setExtendedType(JavaModel.TYPE_MAVEN_POM_XML); for (String key : project.getProperties().stringPropertyNames()) { String value = project.getProperties().getProperty(key); ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PROPERTY + key, value); } //set core properties when not specified on the request if (primaryArtifact.getDescription() == null) primaryArtifact.setDescription(project.getDescription()); if (primaryArtifact.getName() == null) primaryArtifact.setName(project.getName()); if (primaryArtifact.getVersion() == null) primaryArtifact.setVersion(project.getVersion()); //set the GAV and packaging info ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_ARTIFACT_ID, model.getArtifactId()); ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_GROUP_ID, model.getGroupId()); ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_VERSION, model.getVersion()); ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PACKAGING, model.getPackaging()); //set the parent GAV info if (model.getParent() != null) { ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_ARTIFACT_ID, model.getParent().getArtifactId()); ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_GROUP_ID, model.getParent().getGroupId()); ArtificerModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_VERSION, model.getParent().getVersion()); } return this; } catch (XmlPullParserException e) { throw new IOException(e.getMessage(), e); } }
From source file:org.axway.grapes.maven.resolver.LicenseResolver.java
License:Open Source License
public List<License> resolve(final MavenProject project) throws MojoExecutionException { final List<License> licenses = new ArrayList<License>(); licenses.addAll(project.getLicenses()); if (licenses.isEmpty() && project.getParent() != null) { final MavenProject parent = project.getParent(); licenses.addAll(resolve(project, parent.getGroupId(), parent.getArtifactId(), parent.getVersion())); }/* ww w .j a v a2 s.c o m*/ return licenses; }
From source file:org.codehaus.continuum.builder.maven.m2.DefaultMavenBuilderHelper.java
License:Apache License
public String getVersion(MavenProject project) { return project.getVersion(); }
From source file:org.codehaus.continuum.builder.maven.m2.DefaultMavenBuilderHelper.java
License:Apache License
protected MavenProject getProject(File file) throws ContinuumException { MavenProject project = null; try {/* ww w . j a v a 2s.co m*/ project = projectBuilder.build(file, getRepository()); } catch (ProjectBuildingException e) { throw new ContinuumException("Cannot build maven project from " + file, e); } // ---------------------------------------------------------------------- // Validate the MavenProject using some Continuum rules // ---------------------------------------------------------------------- // Nag email address CiManagement ciManagement = project.getCiManagement(); if (ciManagement == null) { throw new ContinuumException("Missing CiManagement from the project descriptor."); } if (StringUtils.isEmpty(getNagEmailAddress(project))) { throw new ContinuumException("Missing nag email address from the continuous integration info."); } // SCM connection Scm scm = project.getScm(); if (scm == null) { throw new ContinuumException("Missing Scm from the project descriptor."); } String url = scm.getConnection(); if (StringUtils.isEmpty(url)) { throw new ContinuumException("Missing anonymous scm connection url."); } // Version if (StringUtils.isEmpty(project.getVersion())) { throw new ContinuumException("Missing version from the project descriptor."); } return project; }
From source file:org.codehaus.continuum.builder.maven2.Maven2ContinuumBuilder.java
License:Open Source License
public ContinuumProject createProject(File workingDirectory) throws ContinuumException { Maven2ProjectDescriptor descriptor = new Maven2ProjectDescriptor(); // try // {//from w w w . java 2 s. co m // scm.checkOutProject( project ); // } // catch( ContinuumScmException ex ) // { // throw new ContinuumException( "Error while checking out the project.", ex ); // } MavenProject mavenProject; File pomFile = getPomFile(workingDirectory); mavenProject = mavenTool.getProject(pomFile); List goals = new LinkedList(); goals.add("pom:install"); mavenTool.execute(mavenProject, goals); // ---------------------------------------------------------------------- // Populating the descriptor // ---------------------------------------------------------------------- if (mavenProject.getScm() == null) { throw new ContinuumException("The project descriptor is missing the SCM section."); } if (mavenProject.getCiManagement() == null) { throw new ContinuumException("The project descriptor is missing the CI section."); } Build build = mavenProject.getBuild(); boolean isPom = true; if (build != null) { String sourceDirectory = build.getSourceDirectory(); if (sourceDirectory != null && sourceDirectory.trim().length() > 0) { if (new File(sourceDirectory).isDirectory()) { isPom = false; } } } if (isPom) { descriptor.getGoals().add("pom:install"); } else { descriptor.getGoals().add("clean:clean"); descriptor.getGoals().add("jar:install"); } // descriptor.setName( mavenProject.getName() ); // The public Url takes priority over the developer connection Scm scm = mavenProject.getScm(); String scmUrl = scm.getConnection(); if (StringUtils.isEmpty(scmUrl)) { scmUrl = scm.getDeveloperConnection(); } if (StringUtils.isEmpty(scmUrl)) { throw new ContinuumException("Missing both anonymous and developer scm connection urls."); } // descriptor.setScmUrl( scmUrl ); CiManagement ciManagement = mavenProject.getCiManagement(); String nagEmailAddress = ciManagement.getNagEmailAddress(); if (StringUtils.isEmpty(nagEmailAddress)) { throw new ContinuumException( "Missing nag email address from the ci section of the project descriptor."); } // descriptor.setNagEmailAddress( nagEmailAddress ); String version = mavenProject.getVersion(); if (StringUtils.isEmpty(version)) { throw new ContinuumException("Missing version from the project descriptor."); } // descriptor.setVersion( version ); // ---------------------------------------------------------------------- // Make the project // ---------------------------------------------------------------------- ContinuumProject project = new GenericContinuumProject(); if (StringUtils.isEmpty(mavenProject.getName())) { throw new ContinuumException("The project name cannot be empty."); } project.setName(mavenProject.getName()); project.setScmUrl(scmUrl); project.setNagEmailAddress(nagEmailAddress); project.setVersion(version); project.setDescriptor(descriptor); return project; }
From source file:org.codehaus.continuum.maven.DefaultMavenTool.java
License:Open Source License
public MavenProject getProject(File file) throws ContinuumException { MavenProject project; try {/*from w ww . j a v a 2s . c o m*/ project = maven.getProject(file); } catch (ProjectBuildingException ex) { throw new ContinuumException("Error while building project.", ex); } // ---------------------------------------------------------------------- // Validate the MavenProject after some Continuum rules // ---------------------------------------------------------------------- // Nag email address CiManagement ciManagement = project.getCiManagement(); if (ciManagement == null) { throw new ContinuumException("Missing CiManagement from the project descriptor."); } if (StringUtils.isEmpty(ciManagement.getNagEmailAddress())) { throw new ContinuumException("Missing nag email address from the continuous integration info."); } // SCM connection Scm scm = project.getScm(); if (scm == null) { throw new ContinuumException("Missing Scm from the project descriptor."); } String url = scm.getConnection(); if (StringUtils.isEmpty(url)) { throw new ContinuumException("Missing anonymous scm connection url."); } // Version if (StringUtils.isEmpty(project.getVersion())) { throw new ContinuumException("Missing version from the project descriptor."); } return project; }