List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:org.eclipse.scada.build.helper.AbstractSetQualifierMojo.java
License:Open Source License
private void process(final Collection<MavenProject> projects, final MavenProject project) throws Exception { getLog().debug("Processing: " + project + " / " + project.getVersion()); final String qualifier = getQualifier(project); final String version = makeVersion(project, qualifier); recordVersion("pom", String.format("%s:%s", project.getGroupId(), project.getArtifactId()), version); addChange(project.getFile(), new ModelModifier() { @Override// w w w . ja v a 2 s.c om public boolean apply(final Model model) { if (version != null && !version.equals(project.getVersion())) { getLog().info(String.format("Update from %s to %s on project %s", project.getVersion(), version, project)); model.setVersion(version); return true; } return false; } }); addChange(project.getFile(), new ModelModifier() { @Override public boolean apply(final Model model) { boolean change = false; final Properties p = model.getProperties(); getLog().debug("Project Properties: " + p); for (final String prop : AbstractSetQualifierMojo.this.qualifierProperties) { if (p.containsKey(prop)) { getLog().info(String.format("%s: Setting property - %s -> %s", project, prop, qualifier)); p.put(prop, qualifier); change = true; } } for (final Map.Entry<String, String> entry : AbstractSetQualifierMojo.this.additionalProperties .entrySet()) { if (p.containsKey(entry.getKey())) { if (entry.getValue() != null) { getLog().info(String.format("%s: Setting property - %s -> %s", project, entry.getKey(), entry.getValue())); p.put(entry.getKey(), entry.getValue()); change = true; } else { getLog().info(String.format("%s: Removing property - %s", entry.getKey())); p.remove(entry.getKey()); change = true; } } } return change; } @Override public String toString() { return String.format("Change properties: " + project); }; }); addChange(project.getFile(), new ModelModifier() { @Override public boolean apply(final Model model) { boolean changed = false; for (final Dependency dep : model.getDependencies()) { changed |= syncDep(dep); } for (final Profile profile : model.getProfiles()) { for (final Dependency dep : profile.getDependencies()) { changed |= syncDep(dep); } } return changed; } @Override public String toString() { return String.format("Change dependencies: " + project); }; }); // visit all modules that have this project as a parent this.helper.visitModulesWithParent(projects, project, new VisitorChange(this.changeManager) { @Override protected boolean performChange(final Model model) { getLog().debug(String.format("Update parent version in module: %s", model)); model.getParent().setVersion(version); return true; } }); checkNonRelativeParent(project); syncModule(project, version); }
From source file:org.eclipse.scada.build.helper.AbstractSetQualifierMojo.java
License:Open Source License
private void handleFeature(final MavenProject project, final String version) throws Exception { recordVersion("feature", project.getArtifactId(), version); this.changeManager.addChange(new Callable<Void>() { @Override// w w w. j ava 2 s . c o m public Void call() throws Exception { final File file = new File(project.getBasedir(), "feature.xml"); final Document doc = XmlHelper.parse(file); XmlHelper.updateValue(doc, "/feature/@version", version); XmlHelper.write(doc, file); return null; } }); }
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 ww w. ja v a 2s. co m*/ 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.scada.build.helper.target.UpdateMojo.java
License:Open Source License
protected String getVersion(final MavenProject project) { getLog().debug("Properties: " + project.getProperties()); if (!project.getVersion().endsWith("-SNAPSHOT")) { // project version is already qualified return project.getVersion(); }/* w ww.j a v a2 s .co m*/ final String version = project.getProperties().getProperty("qualifiedVersion"); if (version != null) { // we do have a direct qualified version return version; } final String q = project.getProperties().getProperty("buildQualifier"); final String v = project.getProperties().getProperty("unqualifiedVersion"); if (q == null || v == null) { throw new IllegalStateException( String.format("Unable to find qualified version for: %s", project.getArtifactId())); } // just stick it together return v + "." + q; }
From source file:org.eclipse.tycho.core.osgitools.DebugUtils.java
License:Open Source License
public static boolean isDebugEnabled(MavenSession session, MavenProject project) { String config = session.getUserProperties().getProperty("tycho.debug.resolver"); return config != null && config.trim().equals(project.getArtifactId()); }
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 www . j a va 2 s . 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.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);//from w w w . ja v a2 s . 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 va 2s. co 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.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 w w w . j a v a 2 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); }//w ww .j av a 2 s .c om } } iu.addProperty(MAVEN_GROUP_ID, project.getGroupId()); iu.addProperty(MAVEN_ARTIFACT_ID, project.getArtifactId()); iu.addProperty(MAVEN_VERSION, project.getVersion()); }