List of usage examples for org.apache.maven.project MavenProject getFile
public File getFile()
From source file:hudson.gridmaven.reporters.MavenFingerprinter.java
License:Open Source License
/** * Mojos perform different dependency resolution, so we need to check this for each mojo. *//*w ww . ja v a 2 s.com*/ public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException { // TODO (kutzi, 2011/09/06): it should be perfectly safe to move all these records to the // postBuild method as artifacts should only be added by mojos, but never removed/modified. record(pom.getArtifacts(), used); record(pom.getArtifact(), produced); record(pom.getAttachedArtifacts(), produced); record(pom.getGroupId() + ":" + pom.getArtifactId(), pom.getFile(), produced); return true; }
From source file:hudson.gridmaven.reporters.MavenFingerprinter.java
License:Open Source License
private void recordParents(MavenBuildProxy build, MavenProject pom) throws IOException, InterruptedException { MavenProject parent = pom.getParent(); while (parent != null) { File parentFile = parent.getFile(); if (parentFile == null) { // Parent artifact contains no actual file, so we resolve against // the local repository ArtifactRepository localRepository = getLocalRepository(build.getMavenBuildInformation(), parent, pom);//from w w w . j a va 2 s.c om if (localRepository != null) { Artifact parentArtifact = getArtifact(parent); // Don't use ArtifactRepository.find(), for compatibility with Maven 2.x if (parentArtifact != null) { parentFile = new File(localRepository.getBasedir(), localRepository.pathOf(parentArtifact)); } } } if (parentFile != null) { // we need to include the artifact Id for poms as well, otherwise a // project with the same groupId would override its parent's // fingerprint record(parent.getGroupId() + ":" + parent.getArtifactId(), parentFile, used); } parent = parent.getParent(); } }
From source file:hudson.maven.ReactorReader.java
License:Apache License
private File find(MavenProject project, Artifact artifact) { if ("pom".equals(artifact.getExtension())) { return project.getFile(); }//from w w w . j a va 2 s.c om org.apache.maven.artifact.Artifact matchingArtifact = findMatchingArtifact(project, artifact); if (matchingArtifact != null) { return matchingArtifact.getFile(); } return null; }
From source file:hudson.maven.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(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);/* www . j a va 2 s . c o 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 (build.isArchivingDisabled()) { listener.getLogger().println("[JENKINS] Archiving disabled"); } else if (assemblies != null) { for (File assembly : assemblies) { if (mavenArtifacts.contains(assembly)) continue; // looks like this is already archived FilePath target = build.getArtifactsDir().child(assembly.getName()); listener.getLogger().println("[JENKINS] Archiving " + assembly + " to " + target); new FilePath(assembly).copyTo(target); // TODO: fingerprint } } return true; }
From source file:info.mikaelsvensson.devtools.sitesearch.SiteSearchPlugin.java
License:Apache License
private void scanForProjectsInProjectHierarchyWithSiteIndexing(final MavenProject proj, boolean forceEmbed, Set<String> modulePaths) throws IOException { forceEmbed |= isSiteIndexerPluginReferences(proj); if (forceEmbed) { String pathFromProjectRootToOtherProject = getRelativePath(project.getBasedir(), proj.getModel().getPomFile().getParentFile()); modulePaths.add(pathFromProjectRootToOtherProject); }// w w w.j a v a 2 s .c om for (Object moduleName : proj.getModules()) { try { File pomFile = new File(proj.getFile().getParentFile(), moduleName.toString() + File.separatorChar + "pom.xml"); MavenProject subModuleProj = loadPomFile(pomFile); scanForProjectsInProjectHierarchyWithSiteIndexing(subModuleProj, forceEmbed, modulePaths); } catch (XmlPullParserException e) { getLog().warn("Could not read POM file for module '" + moduleName + "'.", e); } } }
From source file:info.ronjenkins.maven.rtr.steps.release.RebuildReleaseReactor.java
License:Apache License
@Override protected void releaseExecute(final MavenSession session, final RTRComponents components) throws MavenExecutionException { final List<MavenProject> reactor = session.getProjects(); final List<MavenProject> newReactor = new ArrayList<>(reactor.size()); final ProjectBuilder projectBuilder = components.getProjectBuilder(); File pomFile;/*from w w w.j a v a 2 s . c om*/ ProjectBuildingResult result; MavenProject newProject; for (final MavenProject project : reactor) { pomFile = project.getFile(); try { result = projectBuilder.build(pomFile, session.getProjectBuildingRequest()); } catch (final ProjectBuildingException e) { this.logger.error(""); throw new SmartReactorReleaseException(e); } newProject = result.getProject(); if (project.isExecutionRoot()) { newProject.setExecutionRoot(true); } newReactor.add(newProject); } // Set the new list of projects, but don't replace the actual list // object. session.getProjects().clear(); session.getProjects().addAll(newReactor); }
From source file:info.ronjenkins.maven.rtr.steps.ValidateSmartReactorEligibility.java
License:Apache License
@Override public void execute(final MavenSession session, final RTRComponents components) throws MavenExecutionException { // Ensure that the Maven Release Plugin is not in the list of goals. for (final String goal : session.getGoals()) { if (goal.startsWith("release:") || goal.startsWith("org.apache.maven.plugins:maven-release-plugin:")) { this.logger.error(""); throw new SmartReactorSanityCheckException( "A goal from the Maven Release Plugin was specified for execution."); }// w w w .j a v a 2 s.c o m } // Ensure that the Maven Release Plugin is not declared in the POM. final List<MavenProject> projectsWithMavenReleasePlugin = new ArrayList<>(); for (final MavenProject project : session.getProjects()) { for (final Artifact artifact : project.getPluginArtifacts()) { if (artifact.getGroupId().equals("org.apache.maven.plugins") && artifact.getArtifactId().equals("maven-release-plugin")) { projectsWithMavenReleasePlugin.add(project); } } } if (!projectsWithMavenReleasePlugin.isEmpty()) { this.logger.error(""); for (final MavenProject project : projectsWithMavenReleasePlugin) { this.logger.error("Project " + project + " contains a reference to the Maven Release Plugin."); } this.logger.error(""); throw new SmartReactorSanityCheckException("Reactor is ineligible to become a Smart Reactor."); } // Ensure that the root is a SNAPSHOT. final MavenProject root = session.getTopLevelProject(); if (!root.getArtifact().isSnapshot()) { this.logger.error(""); this.logger.error("Top-level project " + root + " is not a SNAPSHOT."); this.logger.error(""); throw new SmartReactorSanityCheckException("Reactor is ineligible to become a Smart Reactor."); } // Ensure that the ancestors of every SNAPSHOT are also SNAPSHOTs. final ProjectDependencyGraph pdg = session.getProjectDependencyGraph(); final List<MavenProject> badProjects = new ArrayList<>(); for (final MavenProject project : session.getProjects()) { if (project.getArtifact().isSnapshot()) { for (final MavenProject ancestor : pdg.getUpstreamProjects(project, true)) { if (!ancestor.getArtifact().isSnapshot()) { badProjects.add(ancestor); } } } } // Fail if necessary. if (!badProjects.isEmpty()) { this.logger.error(""); this.logger.error( "The following release projects in the reactor have SNAPSHOT dependencies in the reactor, which is not allowed:"); for (final MavenProject badProject : badProjects) { this.logger.error(" " + badProject.getArtifact().toString() + " @ " + badProject.getFile().getAbsolutePath()); } this.logger.error(""); throw new SmartReactorSanityCheckException("Reactor is ineligible to become a Smart Reactor."); } }
From source file:io.fabric8.maven.AbstractFabric8Mojo.java
License:Apache License
protected void copyReadMe(File appBuildDir) throws IOException { MavenProject project = getProject(); copyReadMe(project.getFile().getParentFile(), appBuildDir); }
From source file:io.fabric8.maven.AbstractProfileMojo.java
License:Apache License
protected void createAggregatedZip(List<MavenProject> reactorProjectList, File projectBaseDir, File projectBuildDir, String reactorProjectOutputPath, File projectOutputFile, boolean includeReadMe, List<MavenProject> pomZipProjects) throws IOException { projectBuildDir.mkdirs();/*from w w w . ja va 2 s. com*/ for (MavenProject reactorProject : reactorProjectList) { // ignoreProject the execution root which just aggregates stuff if (!reactorProject.isExecutionRoot()) { Log log = getLog(); combineProfileFilesToFolder(reactorProject, projectBuildDir, log, reactorProjectOutputPath); } } // we may want to include readme files for pom projects if (includeReadMe) { Map<String, File> pomNames = new HashMap<String, File>(); for (MavenProject pomProjects : pomZipProjects) { File src = pomProjects.getFile().getParentFile(); // must include first dir as prefix String root = projectBaseDir.getName(); String relativePath = Files.getRelativePath(projectBaseDir, pomProjects.getBasedir()); relativePath = root + File.separator + relativePath; // we must use dot instead of dashes in profile paths relativePath = pathToProfilePath(relativePath); File outDir = new File(projectBuildDir, relativePath); File copiedFile = copyReadMe(src, outDir); if (copiedFile != null) { String key = getReadMeFileKey(relativePath); pomNames.put(key, copiedFile); } } if (replaceReadmeLinksPrefix != null) { // now parse each readme file and replace github links for (Map.Entry<String, File> entry : pomNames.entrySet()) { File file = entry.getValue(); String key = entry.getKey(); boolean changed = false; List<String> lines = Files.readLines(file); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); String newLine = replaceGithubLinks(pomNames.keySet(), key, line); if (newLine != null) { lines.set(i, newLine); changed = true; } } if (changed) { Files.writeLines(file, lines); getLog().info("Replaced github links to fabric profiles in reaadme file: " + file); } } } } Zips.createZipFile(getLog(), projectBuildDir, projectOutputFile); String relativePath = Files.getRelativePath(projectBaseDir, projectOutputFile); while (relativePath.startsWith("/")) { relativePath = relativePath.substring(1); } getLog().info("Created profile zip file: " + relativePath); }
From source file:io.fabric8.maven.ZipMojo.java
License:Apache License
protected void createAggregatedZip(File projectBaseDir, File projectBuildDir, String reactorProjectOutputPath, File projectOutputFile, boolean includeReadMe, Set<MavenProject> pomZipProjects) throws IOException { projectBuildDir.mkdirs();//from w ww . j a v a 2 s. com for (MavenProject reactorProject : pomZipProjects) { // ignoreProject the execution root which just aggregates stuff if (!reactorProject.isExecutionRoot()) { Log log = getLog(); // TODO allow the project nesting to be defined via a property? String relativePath = getChildProjectRelativePath(projectBaseDir, reactorProject); File outDir = new File(projectBuildDir, relativePath); combineAppFilesToFolder(reactorProject, outDir, log, reactorProjectOutputPath); } } // we may want to include readme files for pom projects if (includeReadMe) { Map<String, File> pomNames = new HashMap<String, File>(); for (MavenProject pomProject : pomZipProjects) { File src = pomProject.getFile().getParentFile(); String relativePath = getChildProjectRelativePath(projectBaseDir, pomProject); File outDir = new File(projectBuildDir, relativePath); File copiedFile = copyReadMe(src, outDir); if (copiedFile != null) { String key = getReadMeFileKey(relativePath); pomNames.put(key, copiedFile); } } if (replaceReadmeLinksPrefix != null) { // now parse each readme file and replace github links for (Map.Entry<String, File> entry : pomNames.entrySet()) { File file = entry.getValue(); String key = entry.getKey(); boolean changed = false; List<String> lines = Files.readLines(file); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); String newLine = replaceGithubLinks(pomNames.keySet(), key, line); if (newLine != null) { lines.set(i, newLine); changed = true; } } if (changed) { Files.writeLines(file, lines); getLog().info("Replaced github links to fabric apps in reaadme file: " + file); } } } } Zips.createZipFile(getLog(), projectBuildDir, projectOutputFile, null); String relativePath = Files.getRelativePath(projectBaseDir, projectOutputFile); while (relativePath.startsWith("/")) { relativePath = relativePath.substring(1); } getLog().info("Created app zip file: " + relativePath); }