List of usage examples for org.apache.maven.project MavenProject getFile
public File getFile()
From source file:com.stratio.mojo.scala.crossbuild.RewritePom.java
License:Apache License
public void restorePom(final MavenProject pom) throws IOException { FileRewriter.restoreFile(pom.getFile()); }
From source file:com.sun.enterprise.module.maven.MavenProjectRepository.java
License:Open Source License
public MavenProjectRepository(MavenProject project, ArtifactResolver artifactResolver, ArtifactRepository localRepository, ArtifactFactory artifactFactory) { super(project.getName(), project.getFile().toURI()); this.project = project; this.artifactResolver = artifactResolver; this.localRepository = localRepository; this.artifactFactory = artifactFactory; // adds the ones that we already know of. Artifact ma = project.getArtifact(); if (ma.getFile() != null) { // if the 'ma' is the distribution module, it won't have its own output. artifacts.put(ma.getId(), ma);/*from w w w .j a v a 2s.c om*/ } for (Artifact a : (Set<Artifact>) project.getArtifacts()) artifacts.put(a.getId(), a); }
From source file:com.synedge.enforcer.EnforceImportRelease.java
License:Apache License
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { Log log = helper.getLog();/*ww w. j av a 2 s . c o m*/ log.info("Entering enforcer"); try { // get the various expressions out of the helper. MavenProject project = (MavenProject) helper.evaluate("${project}"); if (project == null) { throw new EnforcerRuleException("There is no project"); } if (onlyWhenRelease && project.getArtifact().isSnapshot()) { log.warn("Project is SNAPSHOT, not validating"); return; } if (project.getDependencyManagement() == null) { log.info("No dependency management found. All ok"); return; } if (project.getDependencyManagement().getDependencies() == null) { log.info("No dependency management dependencies found. All ok"); return; } helper.getLog().debug("Getting POM, parse and check it"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file Document doc = db.parse(project.getFile().getAbsolutePath()); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr = xpath.compile( "/*[local-name()='project']/*[local-name()='dependencyManagement']/*[local-name()='dependencies']/*[local-name()='dependency']/*[local-name()='scope' and text()='import']/../*[local-name()='version']"); NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); for (int i = 0; i < nl.getLength(); i++) { Node version = nl.item(i); if (version.getTextContent().contains("-SNAPSHOT")) { throw new EnforcerRuleException("Found an artifact in the import scope containing SNAPSHOT!"); } } helper.getLog().debug("Checked them all"); } catch (ExpressionEvaluationException e) { throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e); } catch (ParserConfigurationException e) { throw new EnforcerRuleException("Unable to parse POM", e); } catch (SAXException e) { throw new EnforcerRuleException("Unable to parse POM", e); } catch (IOException e) { throw new EnforcerRuleException("Unable to parse POM", e); } catch (XPathExpressionException e) { throw new EnforcerRuleException("Internal error in XPath parser", e); } }
From source file:com.thalesgroup.dtkit.maven.AbstractSourceJarMojo.java
License:Apache License
protected void archiveProjectContent(MavenProject p, Archiver archiver) throws MojoExecutionException { if (includePom) { try {/* w ww . j av a 2 s . c o m*/ archiver.addFile(p.getFile(), p.getFile().getName()); } catch (ArchiverException e) { throw new MojoExecutionException("Error adding POM file to target jar file.", e); } } for (Iterator i = getSources(p).iterator(); i.hasNext();) { String s = (String) i.next(); File sourceDirectory = new File(s); if (sourceDirectory.exists()) { addDirectory(archiver, sourceDirectory, getCombinedIncludes(null), getCombinedExcludes(null)); } } //MAPI: this should be taken from the resources plugin for (Iterator i = getResources(p).iterator(); i.hasNext();) { Resource resource = (Resource) i.next(); File sourceDirectory = new File(resource.getDirectory()); if (!sourceDirectory.exists()) { continue; } List resourceIncludes = resource.getIncludes(); String[] combinedIncludes = getCombinedIncludes(resourceIncludes); List resourceExcludes = resource.getExcludes(); String[] combinedExcludes = getCombinedExcludes(resourceExcludes); String targetPath = resource.getTargetPath(); if (targetPath != null) { if (!targetPath.trim().endsWith("/")) { targetPath += "/"; } addDirectory(archiver, sourceDirectory, targetPath, combinedIncludes, combinedExcludes); } else { addDirectory(archiver, sourceDirectory, combinedIncludes, combinedExcludes); } } }
From source file:de.saumya.mojo.gem.GemspecWriter.java
@SuppressWarnings("unchecked") GemspecWriter(final File gemspec, final MavenProject project, final GemArtifact artifact) throws IOException { this.latestModified = project.getFile() == null ? 0 : project.getFile().lastModified(); this.gemspec = gemspec; this.gemspec.getParentFile().mkdirs(); this.writer = new FileWriter(gemspec); this.project = project; append("Gem::Specification.new do |s|"); append("name", artifact.getGemName()); append("version", gemVersion(project.getVersion())); append();/*from w w w. j ava 2 s. c o m*/ append("summary", project.getName()); append("description", project.getDescription()); append("homepage", project.getUrl()); append(); for (final Developer developer : (List<Developer>) project.getDevelopers()) { appendAuthor(developer.getName(), developer.getEmail()); } for (final Contributor contributor : (List<Contributor>) project.getContributors()) { appendAuthor(contributor.getName(), contributor.getEmail()); } append(); for (final License license : (List<License>) project.getLicenses()) { appendLicense(license.getUrl(), license.getName()); } }
From source file:fr.brouillard.oss.jgitver.JGitverUtils.java
License:Apache License
/** * Attach modified POM files to the projects so install/deployed files contains new version. * * @param projects projects.//from w ww .ja v a2 s. c o m * @param newProjectVersions newProjectVersions. * @param mavenSession the current maven build session * @param logger the logger to report to * @throws IOException if project model cannot be read correctly * @throws XmlPullParserException if project model cannot be interpreted correctly */ public static void attachModifiedPomFilesToTheProject(List<MavenProject> projects, Map<GAV, String> newProjectVersions, MavenSession mavenSession, Logger logger) throws IOException, XmlPullParserException { for (MavenProject project : projects) { Model model = loadInitialModel(project.getFile()); GAV initalProjectGAV = GAV.from(model); // SUPPRESS CHECKSTYLE AbbreviationAsWordInName logger.debug("about to change file pom for: " + initalProjectGAV); if (newProjectVersions.containsKey(initalProjectGAV)) { model.setVersion(newProjectVersions.get(initalProjectGAV)); } if (model.getParent() != null) { GAV parentGAV = GAV.from(model.getParent()); // SUPPRESS CHECKSTYLE AbbreviationAsWordInName if (newProjectVersions.keySet().contains(parentGAV)) { // parent has been modified model.getParent().setVersion(newProjectVersions.get(parentGAV)); } } File newPom = createPomDumpFile(); writeModelPom(model, newPom); logger.debug(" new pom file created for " + initalProjectGAV + " under " + newPom); setProjectPomFile(project, newPom, logger); logger.debug(" pom file set"); } }
From source file:fr.fastconnect.factory.tibco.bw.maven.BWLifecycleParticipant.java
License:Apache License
private List<MavenProject> prepareProjects(List<MavenProject> projects, MavenSession session) throws MavenExecutionException { List<MavenProject> result = new ArrayList<MavenProject>(); ProjectBuildingRequest projectBuildingRequest = session.getProjectBuildingRequest(); for (MavenProject mavenProject : projects) { logger.debug("project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId()); List<String> oldActiveProfileIds = projectBuildingRequest.getActiveProfileIds(); try {//from ww w . ja v a 2 s . c om List<String> activeProfileIds = activateProfilesWithProperties(mavenProject, oldActiveProfileIds); if (activeProfileIds.size() != oldActiveProfileIds.size()) { projectBuildingRequest.setActiveProfileIds(activeProfileIds); if (mavenProject.getFile() != null) { List<File> files = new ArrayList<File>(); files.add(mavenProject.getFile()); List<ProjectBuildingResult> results = null; try { results = projectBuilder.build(files, true, projectBuildingRequest); } catch (ProjectBuildingException e) { } for (ProjectBuildingResult projectBuildingResult : results) { mavenProject = projectBuildingResult.getProject(); } } } } finally { projectBuildingRequest.setActiveProfileIds(oldActiveProfileIds); } if (mavenProject.getPackaging().startsWith(AbstractBWMojo.BWEAR_TYPE) || "true".equals(propertiesManager.getPropertyValue("enableBWLifecycle"))) { addTIBCODependenciesToPlugin(mavenProject, logger); } result.add(mavenProject); } return result; }
From source file:fr.fastconnect.factory.tibco.bw.maven.InitializeMojo.java
License:Apache License
protected static File getParent(MavenProject project, Log logger) throws IOException, XmlPullParserException { File result = null;/*ww w .ja v a2s .c om*/ MavenProject parent = project.getParent(); if (parent == null) { return result; // no parent: return null } File parentPOM = parent.getFile(); File parentBasedir = null; if (parentPOM != null && parentPOM.getParentFile() != null && parentPOM.getParentFile().exists() && parentPOM.getParentFile().isDirectory()) { parentBasedir = parentPOM.getParentFile(); } if (parentPOM != null) { logger.debug("parentPOM: " + parentPOM.getAbsolutePath()); } while (parentBasedir != null && parentBasedir.exists()) { logger.debug("parentBasedir: " + parentBasedir.getAbsolutePath()); if (findParentPath(parentBasedir, logger)) { logger.debug("parentFound"); result = parentBasedir; break; } logger.debug("parentNotFound"); if (parent != null) { logger.debug(parent.getArtifactId()); parentBasedir = parent.getParentFile(); // use <relativePath> to retrieve real parent file if (parentBasedir == null && parent.getParent() != null) { parentBasedir = parent.getParent().getFile(); } if (parentBasedir != null) { logger.debug(parentBasedir.getAbsolutePath()); } if (parentBasedir != null && parentBasedir.exists() && parentBasedir.isFile()) { parentBasedir = parentBasedir.getParentFile(); } parent = parent.getParent(); } } return result; }
From source file:hudson.gridmaven.MavenUtil.java
License:Open Source License
/** * @deprecated MavenEmbedder has now a method to read all projects * Recursively resolves module POMs that are referenced from * the given {@link MavenProject} and parses them into * {@link MavenProject}s.// w ww . j a va2 s . c om * * @param rel * Used to compute the relative path. Pass in "" to begin. * @param relativePathInfo * Upon the completion of this method, this variable stores the relative path * from the root directory of the given {@link MavenProject} to the root directory * of each of the newly parsed {@link MavenProject}. * * @throws AbortException * errors will be reported to the listener and the exception thrown. * @throws MavenEmbedderException */ public static void resolveModules(MavenEmbedder embedder, MavenProject project, String rel, Map<MavenProject, String> relativePathInfo, BuildListener listener, boolean nonRecursive) throws ProjectBuildingException, AbortException, MavenEmbedderException { File basedir = project.getFile().getParentFile(); relativePathInfo.put(project, rel); List<MavenProject> modules = new ArrayList<MavenProject>(); if (!nonRecursive) { for (String modulePath : project.getModules()) { if (Util.fixEmptyAndTrim(modulePath) != null) { File moduleFile = new File(basedir, modulePath); if (moduleFile.exists() && moduleFile.isDirectory()) { moduleFile = new File(basedir, modulePath + "/pom.xml"); } if (!moduleFile.exists()) throw new AbortException( moduleFile + " is referenced from " + project.getFile() + " but it doesn't exist"); String relativePath = rel; if (relativePath.length() > 0) relativePath += '/'; relativePath += modulePath; MavenProject child = embedder.readProject(moduleFile); resolveModules(embedder, child, relativePath, relativePathInfo, listener, nonRecursive); modules.add(child); } } } project.setCollectedProjects(modules); }
From source file:hudson.gridmaven.reporters.MavenArtifactArchiver.java
License:Open Source License
public boolean postBuild(MavenBuildProxy build, MavenProject pom, final BuildListener listener) throws InterruptedException, IOException { // artifacts that are known to Maven. Set<File> mavenArtifacts = new HashSet<File>(); if (pom.getFile() != null) {// goals like 'clean' runs without loading POM, apparently. // record POM final MavenArtifact pomArtifact = new MavenArtifact(pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), null, "pom", pom.getFile().getName(), Util.getDigestOf(new FileInputStream(pom.getFile()))); final String repositoryUrl = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getUrl()); final String repositoryId = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getId()); mavenArtifacts.add(pom.getFile()); pomArtifact.archive(build, pom.getFile(), listener); // record main artifact (if packaging is POM, this doesn't exist) final MavenArtifact mainArtifact = MavenArtifact.create(pom.getArtifact()); if (mainArtifact != null) { File f = pom.getArtifact().getFile(); mavenArtifacts.add(f);//from w ww . j a va 2s . co m mainArtifact.archive(build, f, listener); } // record attached artifacts final List<MavenArtifact> attachedArtifacts = new ArrayList<MavenArtifact>(); for (Artifact a : pom.getAttachedArtifacts()) { MavenArtifact ma = MavenArtifact.create(a); if (ma != null) { mavenArtifacts.add(a.getFile()); ma.archive(build, a.getFile(), listener); attachedArtifacts.add(ma); } } // record the action build.executeAsync(new MavenBuildProxy.BuildCallable<Void, IOException>() { private static final long serialVersionUID = -7955474564875700905L; public Void call(MavenBuild build) throws IOException, InterruptedException { // if a build forks lifecycles, this method can be called multiple times List<MavenArtifactRecord> old = build.getActions(MavenArtifactRecord.class); if (!old.isEmpty()) build.getActions().removeAll(old); MavenArtifactRecord mar = new MavenArtifactRecord(build, pomArtifact, mainArtifact, attachedArtifacts, repositoryUrl, repositoryId); build.addAction(mar); // TODO kutzi: why are the fingerprints recorded here? // I thought that is the job of MavenFingerprinter mar.recordFingerprints(); return null; } }); } // do we have any assembly artifacts? // System.out.println("Considering "+assemblies+" at "+MavenArtifactArchiver.this); // new Exception().fillInStackTrace().printStackTrace(); if (assemblies != null) { for (File assembly : assemblies) { if (mavenArtifacts.contains(assembly)) continue; // looks like this is already archived if (build.isArchivingDisabled()) { listener.getLogger().println("[JENKINS] Archiving disabled - not archiving " + assembly); } else { FilePath target = build.getArtifactsDir().child(assembly.getName()); listener.getLogger().println("[JENKINS] Archiving " + assembly + " to " + target); new FilePath(assembly).copyTo(target); // TODO: fingerprint } } } return true; }