List of usage examples for org.apache.maven.project MavenProject getGroupId
public String getGroupId()
From source file:org.eclipse.scada.build.helper.target.UpdateMojo.java
License:Open Source License
protected String findVersion(final String id) { getLog().debug(String.format("Looking for '%s'", id)); for (final MavenProject p : getReactorProjects()) { final String artifactId = p.getArtifactId(); final String packaging = p.getPackaging(); getLog().debug(String.format("Found %s:%s:%s:%s", p.getGroupId(), p.getArtifactId(), p.getVersion(), p.getPackaging()));/*from w ww.ja va2 s .c om*/ if ("eclipse-plugin".equals(packaging) && artifactId.equals(id)) { return getVersion(p); } if ("eclipse-feature".equals(packaging) && (artifactId + ".feature.group").equals(id)) { return getVersion(p); } } throw new IllegalStateException(String.format("Unable to find installable unit: %s", id)); }
From source file:org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver.java
License:Open Source License
private void addDependencies(MavenSession session, MavenProject project, DefaultDependencyArtifacts 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);//from w w w . j a va2s .c o m } // 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.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);/* w w w .jav a 2s . co m*/ } // 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 w w. ja v a2 s.c om*/ 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.extras.docbundle.JavadocMojo.java
License:Open Source License
private MavenProject findProject(final String groupId, final String artifactId) { getLog().debug(String.format("findProject - groupId: %s, artifactId: %s", groupId, artifactId)); for (final MavenProject p : this.reactorProjects) { if (!p.getGroupId().equals(groupId)) { continue; }/*from ww w .jav a2 s.c om*/ if (!p.getArtifactId().equals(artifactId)) { continue; } return p; } return null; }
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 w w w . j a va 2s . com } } 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 {/* w w w . j a va 2s .c o m*/ 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 {/*from w ww .j a v a2 s.c om*/ 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.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 . j ava 2s .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); } } }
From source file:org.gephi.maven.BuildMetadata.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { String gephiVersion = (String) project.getProperties().get("gephi.version"); if (gephiVersion == null) { throw new MojoExecutionException("The 'gephi.version' property should be defined"); }/*from w w w .j a v a 2 s.c o m*/ getLog().debug("Building metadata for 'gephi.version=" + gephiVersion + "'"); if (reactorProjects != null && reactorProjects.size() > 0) { getLog().debug("Found " + reactorProjects.size() + " projects in reactor"); List<MavenProject> modules = new ArrayList<MavenProject>(); for (MavenProject proj : reactorProjects) { if (proj.getPackaging().equals("nbm")) { String gephiVersionModule = proj.getProperties().getProperty("gephi.version"); if (gephiVersionModule.equals(gephiVersion)) { getLog().debug("Found 'nbm' project '" + proj.getName() + "' with artifactId=" + proj.getArtifactId() + " and groupId=" + proj.getGroupId()); modules.add(proj); } else { getLog().debug("Ignored project '" + proj.getName() + "' based on 'gephi.version' value '" + gephiVersionModule + "'"); } } } ManifestUtils manifestUtils = new ManifestUtils(sourceManifestFile, getLog()); // Get all modules with dependencies Map<MavenProject, List<MavenProject>> tree = ModuleUtils.getModulesTree(modules, getLog()); //Download previous file File pluginsJsonFile = new File(outputDirectory, "plugins.json"); try { URL url = new URL(metadataUrl + "plugins.json"); URLConnection connection = url.openConnection(); connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); connection.connect(); InputStream stream = connection.getInputStream(); ReadableByteChannel rbc = Channels.newChannel(stream); FileOutputStream fos = new FileOutputStream(pluginsJsonFile); long read = fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); rbc.close(); stream.close(); getLog().debug("Read " + read + "bytes from url '" + url + "' and write to '" + pluginsJsonFile.getAbsolutePath() + "'"); } catch (Exception e) { throw new MojoExecutionException("Error while downloading previous 'plugins.json'", e); } // Init json PluginsMetadata pluginsMetadata; Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create(); if (pluginsJsonFile.exists()) { try { FileReader reader = new FileReader(pluginsJsonFile); pluginsMetadata = gson.fromJson(reader, PluginsMetadata.class); reader.close(); getLog().debug("Read previous plugins.json file"); } catch (JsonSyntaxException e) { throw new MojoExecutionException("Error while reading previous 'plugins.json'", e); } catch (JsonIOException e) { throw new MojoExecutionException("Error while reading previous 'plugins.json'", e); } catch (IOException e) { throw new MojoExecutionException("Error while reading previous 'plugins.json'", e); } } else { pluginsMetadata = new PluginsMetadata(); pluginsMetadata.plugins = new ArrayList<PluginMetadata>(); getLog().debug("Create plugins.json"); } // Build metadata for (Map.Entry<MavenProject, List<MavenProject>> entry : tree.entrySet()) { MavenProject topPlugin = entry.getKey(); PluginMetadata pm = new PluginMetadata(); pm.id = topPlugin.getArtifactId(); // Find previous boolean foundPrevious = false; for (PluginMetadata oldPm : pluginsMetadata.plugins) { if (oldPm.id.equals(pm.id)) { pm = oldPm; foundPrevious = true; getLog().debug("Found matching plugin id=" + pm.id + " in previous plugins.json"); break; } } manifestUtils.readManifestMetadata(topPlugin, pm); pm.license = MetadataUtils.getLicenseName(topPlugin); pm.authors = MetadataUtils.getAuthors(topPlugin); pm.last_update = dateFormat.format(new Date()); pm.readme = MetadataUtils.getReadme(topPlugin, getLog()); pm.images = ScreenshotUtils.copyScreenshots(topPlugin, new File(outputDirectory, "imgs" + File.separator + pm.id), "imgs" + "/" + pm.id + "/", getLog()); pm.homepage = MetadataUtils.getHomepage(topPlugin); pm.sourcecode = MetadataUtils.getSourceCode(topPlugin, getLog()); if (pm.versions == null) { pm.versions = new HashMap<String, Version>(); } Version v = new Version(); v.last_update = dateFormat.format(new Date()); v.url = gephiVersion + "/" + ModuleUtils.getModuleDownloadPath(entry.getKey(), entry.getValue(), new File(outputDirectory, gephiVersion), getLog()); pm.versions.put(gephiVersion, v); if (!foundPrevious) { pluginsMetadata.plugins.add(pm); } } String json = gson.toJson(pluginsMetadata); // Write json file try { FileWriter writer = new FileWriter(pluginsJsonFile); writer.append(json); writer.close(); } catch (IOException ex) { throw new MojoExecutionException("Error while writing plugins.json file", ex); } } else { throw new MojoExecutionException("The project should be a reactor project"); } }