List of usage examples for org.apache.maven.project MavenProject getVersion
public String getVersion()
From source file:org.eclipse.tycho.core.osgitools.targetplatform.LocalTargetPlatformResolver.java
License:Open Source License
private void addDependencies(MavenSession session, MavenProject project, DefaultTargetPlatform platform) { TargetPlatformConfiguration configuration = (TargetPlatformConfiguration) project .getContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION); if (configuration != null && TargetPlatformConfiguration.POM_DEPENDENCIES_CONSIDER .equals(configuration.getPomDependencies())) { Map<String, MavenProject> projectIds = new HashMap<String, MavenProject>( session.getProjects().size() * 2); // make a list of reactor projects for (MavenProject p : session.getProjects()) { String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion()); projectIds.put(key, p);// ww w .j a va2 s.c om } // handle dependencies that are in reactor for (Dependency dependency : project.getDependencies()) { if (Artifact.SCOPE_COMPILE.equals(dependency.getScope())) { String key = ArtifactUtils.key(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); if (projectIds.containsKey(key)) { MavenProject dependent = projectIds.get(key); ArtifactKey artifactKey = getArtifactKey(session, dependent); if (artifactKey != null) { platform.removeAll(artifactKey.getType(), artifactKey.getId()); ReactorProject projectProxy = DefaultReactorProject.adapt(dependent); platform.addReactorArtifact(artifactKey, projectProxy, null, null); if (getLogger().isDebugEnabled()) { getLogger().debug("Add Maven project " + artifactKey); } } } } } // handle rest of dependencies ArrayList<String> scopes = new ArrayList<String>(); scopes.add(Artifact.SCOPE_COMPILE); Collection<Artifact> artifacts; try { artifacts = projectDependenciesResolver.resolve(project, scopes, session); } catch (MultipleArtifactsNotFoundException e) { Collection<Artifact> missing = new HashSet<Artifact>(e.getMissingArtifacts()); for (Iterator<Artifact> it = missing.iterator(); it.hasNext();) { Artifact a = it.next(); String key = ArtifactUtils.key(a.getGroupId(), a.getArtifactId(), a.getBaseVersion()); if (projectIds.containsKey(key)) { it.remove(); } } if (!missing.isEmpty()) { throw new RuntimeException("Could not resolve project dependencies", e); } artifacts = e.getResolvedArtifacts(); artifacts.removeAll(e.getMissingArtifacts()); } catch (AbstractArtifactResolutionException e) { throw new RuntimeException("Could not resolve project dependencies", e); } for (Artifact artifact : artifacts) { String key = ArtifactUtils.key(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); if (!projectIds.containsKey(key)) { File plugin = artifact.getFile(); ArtifactKey artifactKey = getArtifactKey(session, plugin); if (artifactKey != null) { platform.addArtifactFile(artifactKey, plugin, null); if (getLogger().isDebugEnabled()) { getLogger().debug("Add Maven artifact " + artifactKey); } } } } } }
From source file:org.eclipse.tycho.core.resolver.DefaultTargetPlatformConfigurationReader.java
License:Open Source License
private void setTarget(TargetPlatformConfiguration result, MavenSession session, MavenProject project, Xpp3Dom configuration) {/*from w ww. j a va 2s . c o m*/ Xpp3Dom targetDom = configuration.getChild("target"); if (targetDom == null) { return; } Xpp3Dom artifactDom = targetDom.getChild("artifact"); if (artifactDom == null) { return; } Xpp3Dom groupIdDom = artifactDom.getChild("groupId"); Xpp3Dom artifactIdDom = artifactDom.getChild("artifactId"); Xpp3Dom versionDom = artifactDom.getChild("version"); if (groupIdDom == null || artifactIdDom == null || versionDom == null) { return; } Xpp3Dom classifierDom = artifactDom.getChild("classifier"); String groupId = groupIdDom.getValue(); String artifactId = artifactIdDom.getValue(); String version = versionDom.getValue(); String classifier = classifierDom != null ? classifierDom.getValue() : null; File targetFile = null; for (MavenProject otherProject : session.getProjects()) { if (groupId.equals(otherProject.getGroupId()) && artifactId.equals(otherProject.getArtifactId()) && version.equals(otherProject.getVersion())) { targetFile = new File(otherProject.getBasedir(), classifier + ".target"); break; } } if (targetFile == null) { Artifact artifact = repositorySystem.createArtifactWithClassifier(groupId, artifactId, version, "target", classifier); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setLocalRepository(session.getLocalRepository()); request.setRemoteRepositories(project.getRemoteArtifactRepositories()); repositorySystem.resolve(request); if (!artifact.isResolved()) { throw new RuntimeException("Could not resolve target platform specification artifact " + artifact); } targetFile = artifact.getFile(); } result.setTarget(targetFile); }
From source file:org.eclipse.tycho.packaging.IUXmlTransformer.java
License:Open Source License
public void injectMavenProperties(IU iu, MavenProject project) { List<Element> properties = iu.getProperties(); if (properties != null) { for (Element property : properties) { String key = property.getAttributeValue("name"); if (MAVEN_GROUP_ID.equals(key) || MAVEN_ARTIFACT_ID.equals(key) || MAVEN_VERSION.equals(key)) { property.getParent().removeNode(property); }//from ww w . j a v a 2s .co m } } iu.addProperty(MAVEN_GROUP_ID, project.getGroupId()); iu.addProperty(MAVEN_ARTIFACT_ID, project.getArtifactId()); iu.addProperty(MAVEN_VERSION, project.getVersion()); }
From source file:org.eclipse.tycho.target.TargetPlatformMojo.java
License:Open Source License
private boolean enterProject(MavenProject project, HashSet<GAV> consideredProjects) { GAV projectGav = new GAV(project.getGroupId(), project.getArtifactId(), project.getVersion()); if (consideredProjects.contains(projectGav)) { return false; } else {/*from w w w. j a v a2 s . com*/ consideredProjects.add(projectGav); return true; } }
From source file:org.eclipse.virgo.ide.bundlor.internal.core.maven.MavenPropertiesSource.java
License:Open Source License
public Properties getProperties() { try {//w w w . j ava2 s . co m IMavenProjectRegistry registry = MavenPlugin.getMavenProjectRegistry(); IMavenProjectFacade facade = registry.create(this.project, new NullProgressMonitor()); if (facade != null) { MavenProject mavenProj = facade.getMavenProject(new NullProgressMonitor()); Properties props = mavenProj.getProperties(); // add in some special maven properties addPropertyIfNotNull(props, "project.artifactId", mavenProj.getArtifactId()); //$NON-NLS-1$ addPropertyIfNotNull(props, "project.groupId", mavenProj.getGroupId()); //$NON-NLS-1$ addPropertyIfNotNull(props, "project.description", mavenProj.getDescription()); //$NON-NLS-1$ addPropertyIfNotNull(props, "project.name", mavenProj.getName()); //$NON-NLS-1$ addPropertyIfNotNull(props, "project.version", mavenProj.getVersion()); //$NON-NLS-1$ addPropertyIfNotNull(props, "pom.artifactId", mavenProj.getArtifactId()); //$NON-NLS-1$ addPropertyIfNotNull(props, "pom.groupId", mavenProj.getGroupId()); //$NON-NLS-1$ addPropertyIfNotNull(props, "pom.description", mavenProj.getDescription()); //$NON-NLS-1$ addPropertyIfNotNull(props, "pom.name", mavenProj.getName()); //$NON-NLS-1$ addPropertyIfNotNull(props, "pom.version", mavenProj.getVersion()); //$NON-NLS-1$ return props; } } catch (CoreException e) { // this exception will be reported later on as the properties can't be reported. } return EMPTY_STANDARD; }
From source file:org.eiichiro.gig.shell.Main.java
License:Open Source License
/** * @param args/* www .j a v a 2 s .co m*/ * @throws Exception */ public static void main(String[] args) throws Exception { Shell shell = new Shell(); shell.register(new Quit(shell)); shell.register(new Exit(shell)); shell.register(new Help(shell)); shell.register(new Hint(shell)); Console console = shell.console(); console.println(Colors.blue(" ____ _")); console.println(Colors.blue(" / ___(_) __ _")); console.println(Colors.blue("| | _| |/ _` |")); console.println(Colors.blue("| |_| | | (_| |")); console.println(Colors.blue(" \\____|_|\\__, |")); console.println(Colors.blue(" |___/")); console.println(""); console.println(Colors.blue("Gig Shell " + Version.MAJOR + "." + Version.MINER + "." + Version.BUILD + " (Experimental Beta) http://gig.eiichiro.org/")); console.println(""); console.println(Colors.blue("Welcome to Gig. Hit the TAB or press 'hint' to display available commands.")); console.println(Colors.blue("Press 'help command' to display the detailed information for the command.")); console.println(Colors.blue("Press 'quit' or 'exit' to exit this session. Enjoy!")); console.println(""); String dir = Environment.getProperty("user.dir"); File pom = new File(dir + File.separator + "pom.xml"); String prompt = "gig"; if (pom.exists()) { MavenXpp3Reader reader = new MavenXpp3Reader(); Model model = reader.read(new FileReader(pom)); MavenProject project = new MavenProject(model); String artifactId = project.getArtifactId(); String version = project.getVersion(); prompt = prompt + Colors.yellow(":[" + artifactId + "-" + version + "]"); File gig = new File(dir + File.pathSeparator + ".gig"); if (!gig.exists()) { gig.mkdir(); } shell.register(new Scan(shell)); } console.prompt(prompt + "> "); shell.start(); }
From source file:org.exoplatform.maven2.plugin.Utils.java
License:Open Source License
public static void deployProject(File dirJar, File dirWar, MavenProject project, boolean deployDep, HashSet<String> ignoreProjects) throws Exception { if (!dirJar.exists()) { System.out.println("The directory " + dirJar.getParent() + " does not exists !"); return;/* w ww .j a v a 2s . co m*/ } if (!dirWar.exists()) { System.out.println("The directory " + dirWar.getParent() + " does not exists !"); return; } int counter = 0; if (deployDep) { counter += deployedDependency(dirJar, dirWar, project, ignoreProjects).size(); } deleteFileOnExist(dirWar, project.getBuild().getFinalName()); if (project.getPackaging().equals("jar")) { counter++; File moduleFile = new File(project.getBasedir().toString() + "/target/" + project.getArtifactId() + "-" + project.getVersion() + "." + project.getPackaging()); copyFileToDirectory(moduleFile, dirJar); printMessage("deploy", " Deployed file '" + project.getArtifactId() + "' to " + dirJar.getPath()); } else { if (project.getPackaging().equals("war") || project.getPackaging().equals("exo-jcr") || project.getPackaging().equals("exo-portal") || project.getPackaging().equals("exo-portlet")) { File deployWar = new File( project.getBasedir().toString() + "/target/" + project.getBuild().getFinalName() + ".war"); copyFileToDirectory(deployWar, dirWar); printMessage("deploy", " Deployed file '" + project.getArtifactId() + "' to " + dirWar.getPath()); counter++; } } printMessage("deploy", " TOTAL DEPLOY : " + counter + " project"); }
From source file:org.exoplatform.maven2.plugin.Utils.java
License:Open Source License
public static void createManifest(File mf, MavenProject project, HashSet ignoredProjects) throws IOException { StringBuilder b = new StringBuilder(); b.append("Manifest-Version: 1.0\n"); b.append("Ant-Version: Apache Ant 1.5.3\n"); b.append("Created-By: 1.5.0_04-b05 (Sun Microsystems Inc.)\n"); b.append("Class-Path: "); if (checkTypes(project)) { for (Artifact da : allDependencies(project, ignoredProjects)) { if (da.getType().equals("jar")) { b.append(da.getArtifactId() + "-" + da.getVersion() + ".jar "); }/*from w w w . j av a 2 s. co m*/ } } b.append("\n"); b.append("Built-By: exo\n"); b.append("Specification-Title: " + project.getArtifactId() + "\n"); b.append("Specification-Version: " + project.getVersion() + "\n"); b.append("Specification-Vendor: eXo Platform SARL\n"); b.append("Implementation-Title: " + project.getBuild().getFinalName() + "\n"); b.append("Implementation-Version: " + project.getVersion() + "\n"); b.append("Implementation-Vendor: eXo Platform SARL\n"); FileOutputStream out = new FileOutputStream(mf); out.write(b.toString().getBytes()); out.close(); }
From source file:org.exoplatform.maven2.plugin.Utils.java
License:Open Source License
public static void createManifest2(File mf, MavenProject project, HashSet includes) throws IOException { StringBuilder b = new StringBuilder(); b.append("Manifest-Version: 1.0\n"); b.append("Ant-Version: Apache Ant 1.5.3\n"); b.append("Created-By: 1.5.0_04-b05 (Sun Microsystems Inc.)\n"); if (includes != null) { b.append("Class-Path: "); for (Artifact da : allDependencies(project, null)) { if (da.getType().equals("jar") && includes.contains(da.getArtifactId())) { b.append(da.getArtifactId() + "-" + da.getVersion() + ".jar "); }//from ww w. jav a 2 s .c o m } b.append("\n"); } b.append("Built-By: exo\n"); b.append("Specification-Title: " + project.getArtifactId() + "\n"); b.append("Specification-Version: " + project.getVersion() + "\n"); b.append("Specification-Vendor: eXo Platform SARL\n"); b.append("Implementation-Title: " + project.getBuild().getFinalName() + "\n"); b.append("Implementation-Version: " + project.getVersion() + "\n"); b.append("Implementation-Vendor: eXo Platform SARL\n"); FileOutputStream out = new FileOutputStream(mf); out.write(b.toString().getBytes()); out.close(); }
From source file:org.fluidity.deployment.maven.DependenciesSupportImpl.java
License:Apache License
@Override public void saveArtifact(final MavenProject project, final File file, final String finalName, final String classifier, final String packaging, final Logger log) throws MojoExecutionException { final boolean unclassified = classifier == null || classifier.isEmpty(); final String outputName = unclassified ? String.format("%s.%s", finalName, packaging) : String.format("%s-%s.%s", finalName, classifier, packaging); final File outputFile = new File(outputName); final String outputPath = outputFile.getAbsolutePath(); final Artifact artifact = project.getArtifact(); assert artifact != null; final File artifactFile = artifact.getFile(); if (artifactFile != null && artifactFile.getAbsolutePath().equals(outputPath)) { log.info(String.format("Replacing %s: %s", packaging, artifactFile.getAbsolutePath())); if (!artifactFile.delete()) { throw new MojoExecutionException(String.format("Could not delete %s", artifactFile)); }/* ww w . jav a 2 s. co m*/ if (!file.renameTo(artifactFile)) { throw new MojoExecutionException(String.format("Could not create %s", artifactFile)); } } else { boolean replacing = false; for (final Artifact attached : project.getAttachedArtifacts()) { if (attached.getFile().getAbsolutePath().equals(outputPath)) { replacing = true; break; } } log.info(String.format("%s %s: %s", replacing ? "Replacing" : "Saving", packaging, outputPath)); if (outputFile.exists() && !outputFile.delete()) { throw new MojoExecutionException(String.format("Could not delete %s", outputFile)); } if (!file.renameTo(outputFile)) { throw new MojoExecutionException(String.format("Could not create %s", outputFile)); } if (!replacing) { final DefaultArtifact attachment = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), artifact.getScope(), packaging, classifier, artifact.getArtifactHandler()); attachment.setFile(outputFile); project.addAttachedArtifact(attachment); } } }