List of usage examples for org.apache.maven.project MavenProject isExecutionRoot
public boolean isExecutionRoot()
From source file:com.exentes.maven.versions.VersionMojoUtils.java
License:Apache License
public static Map<String, Dependency> allDependenciesMap(MavenSession session) { Map<String, Dependency> allDependencyManagementMap = allDependencyManagementMap(session); Map<String, Dependency> allDependenciesMap = Maps.newHashMap(); for (MavenProject project : session.getProjects()) { for (Dependency dependency : concat(emptyIfNull(project.getOriginalModel().getDependencies()), allActiveProfilesDependencies(project))) { if (dependency.getVersion() != null) { allDependenciesMap.put(projectDependencyKey(project, dependency), dependency); } else { // dependency version is not specified. Perhaps it is specified in a dependencyManagement section // of the project of one of its parents Dependency parentDependency = null; MavenProject projectToCheck = project; while (parentDependency == null && projectToCheck != null) { parentDependency = allDependencyManagementMap .get(projectDependencyKey(projectToCheck, dependency)); if (parentDependency != null) { allDependenciesMap.put(projectDependencyKey(project, dependency), parentDependency); } else { if (!projectToCheck.isExecutionRoot()) { projectToCheck = projectToCheck.getParent(); } else { projectToCheck = null; }/* www. ja v a 2 s . co m*/ } } } } } return allDependenciesMap; }
From source file:com.github.zhve.ideaplugin.IdeaCleanMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("Delete Workspace Files:"); for (MavenProject project : reactorProjects) { Util.deleteFileOrDirectory(getLog(), new File(project.getBasedir(), project.getArtifactId() + ".iml")); if (project.isExecutionRoot()) { Util.deleteFileOrDirectory(getLog(), new File(project.getBasedir(), ".idea")); Util.deleteFileOrDirectory(getLog(), new File(project.getBasedir(), project.getArtifactId() + ".ipr")); Util.deleteFileOrDirectory(getLog(), new File(project.getBasedir(), project.getArtifactId() + ".iws")); }/* ww w .j av a 2s . c o m*/ } }
From source file:com.martenscs.tycho.target.CreateProjectFromArchetypeMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { Properties executionProperties = session.getExecutionProperties(); List<MavenProject> projects = session.getSortedProjects(); MavenProject project = null;/*from ww w . j a v a 2 s . c om*/ for (MavenProject object : projects) { if (object.isExecutionRoot()) project = object; } executionProperties = this.props; ArchetypeGenerationRequest request = new ArchetypeGenerationRequest().setArchetypeGroupId(archetypeGroupId) .setArchetypeArtifactId(archetypeArtifactId).setArchetypeVersion(archetypeVersion) .setOutputDirectory(basedir.getAbsolutePath()).setLocalRepository(localRepository) .setArchetypeRepository(archetypeRepository) .setRemoteArtifactRepositories(remoteArtifactRepositories).setFilter(filter); try { if (interactiveMode.booleanValue()) { getLog().info("Generating project in Interactive mode"); } else { getLog().info("Generating project in Batch mode"); } selector.selectArchetype(request, interactiveMode, archetypeCatalog); if (StringUtils.isBlank(request.getArchetypeArtifactId())) { // no archetype found: stopping return; } configurator.configureArchetype(request, interactiveMode, executionProperties); ArchetypeGenerationResult generationResult = manager.generateProjectFromArchetype(request); if (generationResult.getCause() != null) { throw new MojoFailureException(generationResult.getCause(), generationResult.getCause().getMessage(), generationResult.getCause().getMessage()); } } catch (MojoFailureException ex) { throw ex; } catch (Exception ex) { throw (MojoFailureException) new MojoFailureException(ex.getMessage()).initCause(ex); } String artifactId = request.getArtifactId(); String postArchetypeGenerationGoals = request.getArchetypeGoals(); if (StringUtils.isEmpty(postArchetypeGenerationGoals)) { postArchetypeGenerationGoals = goals; } if (StringUtils.isNotEmpty(postArchetypeGenerationGoals)) { invokePostArchetypeGenerationGoals(postArchetypeGenerationGoals, artifactId); } }
From source file:fr.paris.lutece.maven.AbstractLuteceWebappMojo.java
License:Open Source License
/** * Used for multiproject, return the output directory ( /target/lutece/ ) of root project. * * @return File corresponding to the root project output directory *//* w w w .j av a 2 s. c o m*/ protected File getRootProjectBuildDirectory() { MavenProject mp = null; for (Object o : reactorProjects) { mp = (MavenProject) o; if (mp.isExecutionRoot()) { break; } } return new File(mp.getBuild().getDirectory() + File.separatorChar + LUTECE_DIRECTORY); }
From source file:fr.paris.lutece.maven.AbstractLuteceWebappMojo.java
License:Open Source License
/** * Used for multiproject, return the output directory ( /target ) of root project. * * @return File corresponding to the root project output directory */// w w w . java 2 s. c om protected File getRootProjectBuildDirectoryTarget() { MavenProject mp = null; for (Object o : reactorProjects) { mp = (MavenProject) o; if (mp.isExecutionRoot()) { break; } } return new File(mp.getBuild().getDirectory()); }
From source file:hudson.gridmaven.reporters.AbstractMavenJavadocArchiver.java
License:Open Source License
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException { if (!checkIsJavadocMojo(mojo)) return true; File destDir;/*from ww w.ja v a 2 s . c om*/ try { aggregated = mojo.getConfigurationValue("aggregate", Boolean.class) || mojo.getGoal().equals("aggregate") || mojo.getGoal().equals("test-aggregate"); if (aggregated && !pom.isExecutionRoot()) return true; // in the aggregated mode, the generation will only happen for the root module destDir = mojo.getConfigurationValue("reportOutputDirectory", File.class); if (destDir == null) destDir = mojo.getConfigurationValue("outputDirectory", File.class); } catch (ComponentConfigurationException e) { e.printStackTrace(listener.fatalError(Messages.MavenJavadocArchiver_NoDestDir())); build.setResult(Result.FAILURE); return true; } if (destDir.exists()) { // javadoc:javadoc just skips itself when the current project is not a java project if (aggregated) { // store at MavenModuleSet level. listener.getLogger().println("[JENKINS] Archiving aggregated javadoc"); target = build.getModuleSetRootDir(); } else { listener.getLogger().println("[JENKINS] Archiving javadoc"); target = build.getProjectRootDir(); } target = target.child(getArchiveTargetPath()); try { new FilePath(destDir).copyRecursiveTo("**/*", target); } catch (IOException e) { Util.displayIOException(e, listener); e.printStackTrace(listener.fatalError(Messages.MavenJavadocArchiver_FailedToCopy(destDir, target))); build.setResult(Result.FAILURE); } if (aggregated) build.registerAsAggregatedProjectAction(this); else build.registerAsProjectAction(this); // JENKINS-9202 if project without any module if (pom.getModules() != null && pom.getModules().isEmpty() && pom.isExecutionRoot()) { build.registerAsAggregatedProjectAction(this); } } return true; }
From source file:hudson.maven.reporters.AbstractMavenJavadocArchiver.java
License:Open Source License
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException { if (!checkIsJavadocMojo(mojo)) return true; File destDir;//from w ww . j av a 2s .co m try { aggregated = mojo.getConfigurationValue("aggregate", Boolean.class, Boolean.FALSE) || mojo.getGoal().equals("aggregate") || mojo.getGoal().equals("test-aggregate"); if (aggregated && !pom.isExecutionRoot()) return true; // in the aggregated mode, the generation will only happen for the root module destDir = mojo.getConfigurationValue("reportOutputDirectory", File.class); if (destDir == null) destDir = mojo.getConfigurationValue("outputDirectory", File.class); } catch (ComponentConfigurationException e) { e.printStackTrace(listener.fatalError(Messages.MavenJavadocArchiver_NoDestDir())); build.setResult(Result.FAILURE); return true; } if (destDir != null && destDir.exists()) { // javadoc:javadoc just skips itself when the current project is not a java project if (aggregated) { // store at MavenModuleSet level. listener.getLogger().println("[JENKINS] Archiving aggregated javadoc"); target = build.getModuleSetRootDir(); } else { listener.getLogger().println("[JENKINS] Archiving javadoc"); target = build.getProjectRootDir(); } target = target.child(getArchiveTargetPath()); try { new FilePath(destDir).copyRecursiveTo("**/*", target); } catch (IOException e) { Util.displayIOException(e, listener); e.printStackTrace(listener.fatalError(Messages.MavenJavadocArchiver_FailedToCopy(destDir, target))); build.setResult(Result.FAILURE); } if (aggregated) build.registerAsAggregatedProjectAction(this); else build.registerAsProjectAction(this); // JENKINS-9202 if project without any module if (pom.getModules() != null && pom.getModules().isEmpty() && pom.isExecutionRoot()) { build.registerAsAggregatedProjectAction(this); } } return true; }
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 av a2 s . com*/ 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: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 www. j a v a 2 s .c o m 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();/*w w w . j ava2s .c o m*/ 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); }