List of usage examples for org.apache.maven.project MavenProject setArtifact
public void setArtifact(Artifact artifact)
From source file:org.hoydaa.maven.plugins.ParentCheckerMojo.java
License:Apache License
public void execute() throws MojoExecutionException { MavenProject tProject = project; while (tProject != null) { Artifact parentArtifact = tProject.getParentArtifact(); if (null == parentArtifact || checkArtifacts == null || !hasValidParent(tProject)) { getLog().info("This parent '" + parentArtifact + "' is not in the list of artifacts '" + checkArtifacts + "' to be checked, skipping..."); } else {/*from ww w. j a v a 2 s . com*/ try { // get newer versions of the parent, if there is one. ArtifactVersion currentVersion = tProject.getParentArtifact().getSelectedVersion(); List<ArtifactVersion> availableVersions = artifactMetadataSource.retrieveAvailableVersions( artifactFactory.createParentArtifact(parentArtifact.getGroupId(), parentArtifact.getArtifactId(), parentArtifact.getVersion()), localRepository, remoteArtifactRepositories); List<ArtifactVersion> newVersions = getNewerVersions(currentVersion, availableVersions); // if there is newer versions available if (newVersions.size() > 0) { boolean forcedUpdateExists = false; getLog().warn("New versions available for your parent POM " + parentArtifact.toString() + " of project '" + tProject.getArtifact().toString() + "'!"); for (ArtifactVersion version : newVersions) { boolean forced = isForced(version, tProject); forcedUpdateExists = forcedUpdateExists || forced; getLog().warn(version.toString() + " (" + (forced ? "FORCED" : "not forced") + ")"); } if (forceUpgrade) { throw new MojoExecutionException(getWarningText(newVersions, tProject) + " You have to upgrade your parent POM to the latest version!"); } else if (forcedUpdateExists) { throw new MojoExecutionException(getWarningText(newVersions, tProject) + " You have to upgrade your parent POM to the latest forced update at least!"); } else { getLog().warn(getWarningText(newVersions, tProject)); } } else { getLog().info("Your parent POM's are all up-to-date, good to do dude."); } } catch (ArtifactMetadataRetrievalException e) { e.printStackTrace(); } catch (OverConstrainedVersionException e) { e.printStackTrace(); } catch (ProjectBuildingException e) { e.printStackTrace(); } } Artifact temp = tProject.getParentArtifact(); tProject = tProject.getParent(); if (null != tProject) tProject.setArtifact(temp); } }
From source file:org.ops4j.pax.construct.lifecycle.EclipseOSGiMojo.java
License:Apache License
/** * Unpack each imported bundle in turn and generate the relevant Eclipse project files * // ww w .ja v a 2 s . c o m * @throws InvalidDependencyVersionException * @throws MojoExecutionException */ private void setupImportedBundles() throws InvalidDependencyVersionException, MojoExecutionException { // don't process dependencies of imported bundles m_provisionProject = getExecutedProject(); setResolveDependencies(false); Set artifacts = m_provisionProject.createArtifacts(artifactFactory, null, null); for (Iterator i = artifacts.iterator(); i.hasNext();) { Artifact artifact = (Artifact) i.next(); // store project locally underneath the provisioning POM's directory File groupDir = new File(m_provisionProject.getBasedir(), "target/" + artifact.getGroupId()); File baseDir = new File(groupDir, artifact.getArtifactId() + '-' + artifact.getVersion()); // download and unpack the bundle if (!PomUtils.downloadFile(artifact, artifactResolver, remoteArtifactRepositories, localRepository)) { getLog().warn("Skipping missing bundle " + artifact); continue; } DirUtils.unpackBundle(artifact.getFile(), baseDir, null); // download the bundle POM and store locally MavenProject dependencyProject = writeProjectPom(baseDir, artifact); if (null == dependencyProject) { getLog().warn("Skipping missing bundle " + artifact); continue; } dependencyProject.setArtifact(artifact); setExecutedProject(dependencyProject); setProject(dependencyProject); // trick Eclipse plugin to do the right thing setBuildOutputDirectory(new File(baseDir, ".ignore")); setEclipseProjectDir(baseDir); try { // call the Eclipse plugin getLog().info("Generating Eclipse project for bundle " + artifact); execute(); } catch (MojoFailureException e) { getLog().warn("Problem generating Eclipse files for artifact " + artifact); } } }
From source file:org.ops4j.pax.construct.project.ImportBundleMojo.java
License:Apache License
/** * Resolve the Maven project for the given artifact, handling when a POM cannot be found in the repository * //w w w. j av a2s.c o m * @param pomGroupId project group id * @param pomArtifactId project artifact id * @param pomVersion project version * @return resolved Maven project */ private MavenProject buildMavenProject(String pomGroupId, String pomArtifactId, String pomVersion) { Artifact pomArtifact = m_factory.createProjectArtifact(pomGroupId, pomArtifactId, pomVersion); MavenProject project; try { project = m_projectBuilder.buildFromRepository(pomArtifact, m_remoteRepos, m_localRepo); } catch (ProjectBuildingException e) { getLog().warn("Problem resolving project " + pomArtifact.getId()); return null; } /* * look to see if this is a local project (if so then set the POM location) */ Pom localPom = DirUtils.findPom(targetDirectory, pomGroupId + ':' + pomArtifactId); if (localPom != null) { project.setFile(localPom.getFile()); } /* * Repair stubs (ie. when a POM couldn't be found in the various repositories) */ DistributionManagement dm = project.getDistributionManagement(); if (dm != null && "generated".equals(dm.getStatus())) { if (localPom != null) { // local project, use values from the local POM project.setPackaging(localPom.getPackaging()); project.setName(localPom.getId()); } else { // remote project - assume it creates a jarfile (so we can test later for OSGi metadata) Artifact jar = m_factory.createBuildArtifact(pomGroupId, pomArtifactId, pomVersion, "jar"); project.setArtifact(jar); project.setPackaging("jar"); project.setName(jar.getId()); } } return project; }