List of usage examples for org.apache.maven.project MavenProject getBuild
public Build getBuild()
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
private static void populateSurefireReportsPath(MavenProject pom, Properties props) { String surefireReportsPath = MavenUtils.getPluginSetting(pom, MavenUtils.GROUP_ID_APACHE_MAVEN, ARTIFACTID_MAVEN_SUREFIRE_PLUGIN, "reportsDirectory", pom.getBuild().getDirectory() + File.separator + "surefire-reports"); File path = resolvePath(surefireReportsPath, pom.getBasedir()); if (path != null && path.exists()) { props.put(SUREFIRE_REPORTS_PATH_PROPERTY, path.getAbsolutePath()); }//from w ww .jav a 2 s . co m }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
private static void populateLibraries(MavenProject pom, Properties props, boolean test) throws MojoExecutionException { List<File> libraries = new ArrayList<>(); try {/*from www . j av a2 s . c o m*/ List<String> classpathElements = test ? pom.getTestClasspathElements() : pom.getCompileClasspathElements(); if (classpathElements != null) { for (String classPathString : classpathElements) { if (!classPathString.equals( test ? pom.getBuild().getTestOutputDirectory() : pom.getBuild().getOutputDirectory())) { File libPath = resolvePath(classPathString, pom.getBasedir()); if (libPath != null && libPath.exists()) { libraries.add(libPath); } } } } } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("Unable to populate" + (test ? " test" : "") + " libraries", e); } if (!libraries.isEmpty()) { String librariesValue = StringUtils.join(toPaths(libraries), SEPARATOR); if (test) { props.setProperty(JAVA_PROJECT_TEST_LIBRARIES, librariesValue); } else { // Populate both deprecated and new property for backward compatibility props.setProperty(PROJECT_LIBRARIES, librariesValue); props.setProperty(JAVA_PROJECT_MAIN_LIBRARIES, librariesValue); } } }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
private static void populateBinaries(MavenProject pom, Properties props) { File mainBinaryDir = resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir()); if (mainBinaryDir != null && mainBinaryDir.exists()) { String binPath = mainBinaryDir.getAbsolutePath(); // Populate both deprecated and new property for backward compatibility props.setProperty(PROJECT_BINARY_DIRS, binPath); props.setProperty(JAVA_PROJECT_MAIN_BINARY_DIRS, binPath); props.setProperty(GROOVY_PROJECT_MAIN_BINARY_DIRS, binPath); }/*from ww w . j av a2s.c om*/ File testBinaryDir = resolvePath(pom.getBuild().getTestOutputDirectory(), pom.getBasedir()); if (testBinaryDir != null && testBinaryDir.exists()) { String binPath = testBinaryDir.getAbsolutePath(); props.setProperty(JAVA_PROJECT_TEST_BINARY_DIRS, binPath); } }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
private static void removeTarget(MavenProject pom, Collection<String> relativeOrAbsolutePaths) { final Path baseDir = pom.getBasedir().toPath().toAbsolutePath().normalize(); final Path target = Paths.get(pom.getBuild().getDirectory()).toAbsolutePath().normalize(); final Path targetRelativePath = baseDir.relativize(target); relativeOrAbsolutePaths.removeIf(pathStr -> { Path path = Paths.get(pathStr).toAbsolutePath().normalize(); Path relativePath = baseDir.relativize(path); return relativePath.startsWith(targetRelativePath); });/*from w w w .j av a2 s . c o m*/ }
From source file:org.sonatype.flexmojos.htmlwrapper.HtmlWrapperMojo.java
License:Apache License
private void init() { /*// w w w. java2 s . c om * If sourceProject is defined, then parameters are from an external project and that project (sourceProject) * should be used as reference for default values rather than this project. */ MavenProject project = this.project; if (sourceProject != null) { project = sourceProject; } if (parameters == null) { parameters = new HashMap<String, String>(); } if (!parameters.containsKey("title")) { parameters.put("title", project.getName()); } String[] nodes = targetPlayer != null ? targetPlayer.split("\\.") : new String[] { "9", "0", "0" }; if (!parameters.containsKey("version_major")) { parameters.put("version_major", nodes[0]); } if (!parameters.containsKey("version_minor")) { parameters.put("version_minor", nodes[1]); } if (!parameters.containsKey("version_revision")) { parameters.put("version_revision", nodes[2]); } if (!parameters.containsKey("swf")) { parameters.put("swf", project.getBuild().getFinalName()); } if (!parameters.containsKey("width")) { parameters.put("width", "100%"); } if (!parameters.containsKey("height")) { parameters.put("height", "100%"); } if (!parameters.containsKey("application")) { parameters.put("application", project.getArtifactId()); } if (!parameters.containsKey("bgcolor")) { parameters.put("bgcolor", "#869ca7"); } }
From source file:org.sonatype.flexmojos.plugin.utilities.MavenUtils.java
License:Open Source License
/** * Resolve a resource file in a maven project resources folders * //from w w w. j a v a 2s .c om * @param project maven project * @param fileName sugested name on pom * @return source file or null if source not found * @throws MojoFailureException */ public static File resolveResourceFile(MavenProject project, String fileName) throws MojoFailureException { File file = new File(fileName); if (file.exists()) { return file; } if (file.isAbsolute()) { throw new MojoFailureException("File " + fileName + " not found"); } List<Resource> resources = project.getBuild().getResources(); for (Resource resourceFolder : resources) { File resource = new File(resourceFolder.getDirectory(), fileName); if (resource.exists()) { return resource; } } throw new MojoFailureException("File " + fileName + " not found"); }
From source file:org.sonatype.flexmojos.utilities.MavenUtils.java
License:Apache License
/** * Resolve a resource file in a maven project resources folders * /*from w w w . j a va 2 s . c om*/ * @param project maven project * @param fileName sugested name on pom * @return source file or null if source not found * @throws MojoFailureException */ @SuppressWarnings("unchecked") public static File resolveResourceFile(MavenProject project, String fileName) throws MojoExecutionException { File file = new File(fileName); if (file.exists()) { return file; } if (file.isAbsolute()) { throw new MojoExecutionException("File " + fileName + " not found"); } List<Resource> resources = project.getBuild().getResources(); for (Resource resourceFolder : resources) { File resource = new File(resourceFolder.getDirectory(), fileName); if (resource.exists()) { return resource; } } throw new MojoExecutionException("File " + fileName + " not found"); }
From source file:org.sonatype.m2e.webby.internal.config.WarConfigurationExtractor.java
License:Open Source License
public String getWorkDirectory(MavenProject mvnProject) { String basedir = mvnProject.getBasedir().getAbsolutePath(); return resolve(basedir, mvnProject.getBuild().getDirectory() + "/m2e-webby"); }
From source file:org.sonatype.m2e.webby.internal.config.WarConfigurationExtractor.java
License:Open Source License
public WarConfiguration getConfiguration(IMavenProjectFacade mvnFacade, MavenProject mvnProject, MavenSession mvnSession, IProgressMonitor monitor) throws CoreException { SubMonitor pm = SubMonitor.convert(monitor, "Reading WAR configuration...", 100); try {/*from w w w . j av a 2s . co m*/ WarConfiguration warConfig = new WarConfiguration(); List<MojoExecution> mojoExecs = mvnFacade.getMojoExecutions(WAR_PLUGIN_GID, WAR_PLUGIN_AID, pm.newChild(90), "war"); IMaven maven = MavenPlugin.getMaven(); String basedir = mvnProject.getBasedir().getAbsolutePath(); String encoding = mvnProject.getProperties().getProperty("project.build.sourceEncoding"); warConfig.setWorkDirectory(getWorkDirectory(mvnProject)); warConfig.setClassesDirectory(resolve(basedir, mvnProject.getBuild().getOutputDirectory())); if (!mojoExecs.isEmpty()) { MojoExecution mojoExec = mojoExecs.get(0); Set<String> overlayKeys = new HashSet<String>(); Object[] overlays = maven.getMojoParameterValue(mvnSession, mojoExec, "overlays", Object[].class); if (overlays != null) { boolean mainConfigured = false; for (Object overlay : overlays) { OverlayConfiguration overlayConfig = new OverlayConfiguration(overlay); if (overlayConfig.isMain()) { if (mainConfigured) { continue; } mainConfigured = true; } warConfig.getOverlays().add(overlayConfig); overlayKeys.add(overlayConfig.getArtifactKey()); } if (!mainConfigured) { warConfig.getOverlays().add(0, new OverlayConfiguration(null, null, null, null)); } } Map<String, Artifact> overlayArtifacts = new LinkedHashMap<String, Artifact>(); for (Artifact artifact : mvnProject.getArtifacts()) { if ("war".equals(artifact.getType())) { overlayArtifacts.put(artifact.getDependencyConflictId(), artifact); } } for (Map.Entry<String, Artifact> e : overlayArtifacts.entrySet()) { if (!overlayKeys.contains(e.getKey())) { Artifact a = e.getValue(); OverlayConfiguration warOverlay = new OverlayConfiguration(a.getGroupId(), a.getArtifactId(), a.getClassifier(), a.getType()); warConfig.getOverlays().add(warOverlay); } } for (OverlayConfiguration overlay : warConfig.getOverlays()) { overlay.setEncoding(encoding); } String warSrcDir = maven.getMojoParameterValue(mvnSession, mojoExec, "warSourceDirectory", String.class); String warSrcInc = maven.getMojoParameterValue(mvnSession, mojoExec, "warSourceIncludes", String.class); String warSrcExc = maven.getMojoParameterValue(mvnSession, mojoExec, "warSourceExcludes", String.class); warConfig.getResources() .add(new ResourceConfiguration(warSrcDir, split(warSrcInc), split(warSrcExc))); ResourceConfiguration[] resources = maven.getMojoParameterValue(mvnSession, mojoExec, "webResources", ResourceConfiguration[].class); if (resources != null) { warConfig.getResources().addAll(Arrays.asList(resources)); } for (ResourceConfiguration resource : warConfig.getResources()) { resource.setDirectory(resolve(basedir, resource.getDirectory())); resource.setEncoding(encoding); } String filenameMapping = maven.getMojoParameterValue(mvnSession, mojoExec, "outputFileNameMapping", String.class); warConfig.setFilenameMapping(filenameMapping); String escapeString = maven.getMojoParameterValue(mvnSession, mojoExec, "escapeString", String.class); warConfig.setEscapeString(escapeString); String webXml = maven.getMojoParameterValue(mvnSession, mojoExec, "webXml", String.class); warConfig.setWebXml(resolve(basedir, webXml)); Boolean webXmlFiltered = maven.getMojoParameterValue(mvnSession, mojoExec, "filteringDeploymentDescriptors", Boolean.class); warConfig.setWebXmlFiltered(webXmlFiltered.booleanValue()); Boolean backslashesEscaped = maven.getMojoParameterValue(mvnSession, mojoExec, "escapedBackslashesInFilePath", Boolean.class); warConfig.setBackslashesInFilePathEscaped(backslashesEscaped.booleanValue()); String[] nonFilteredFileExtensions = maven.getMojoParameterValue(mvnSession, mojoExec, "nonFilteredFileExtensions", String[].class); warConfig.getNonFilteredFileExtensions().addAll(Arrays.asList(nonFilteredFileExtensions)); String[] filters = maven.getMojoParameterValue(mvnSession, mojoExec, "filters", String[].class); for (String filter : filters) { warConfig.getFilters().add(resolve(basedir, filter)); } String packagingIncludes = maven.getMojoParameterValue(mvnSession, mojoExec, "packagingIncludes", String.class); warConfig.setPackagingIncludes(split(packagingIncludes)); String packagingExcludes = maven.getMojoParameterValue(mvnSession, mojoExec, "packagingExcludes", String.class); warConfig.setPackagingExcludes(split(packagingExcludes)); } else { throw WebbyPlugin.newError( "Could not locate configuration for maven-war-plugin in POM for " + mvnProject.getId(), null); } return warConfig; } finally { if (monitor != null) { monitor.done(); } } }
From source file:org.sonatype.maven.mojo.execution.MojoExecution.java
License:Open Source License
/** * Returns first MavenProject from projects being built that has this Mojo defined. * * @param mavenSession the MavenSession. * @param pluginGroupId the plugin's groupId. * @param pluginArtifactId the plugin's artifactId. * @param goal the goal to search for and have execution or {@code null} if just interested in plugin * presence./*from w ww . j a v a 2s . c om*/ * @return MavenProject of first project with given plugin is being built or null. */ public static MavenProject getFirstProjectWithMojoInExecution(final MavenSession mavenSession, final String pluginGroupId, final String pluginArtifactId, final String goal) { final ArrayList<MavenProject> projects = new ArrayList<MavenProject>(mavenSession.getSortedProjects()); MavenProject firstWithThisMojo = null; for (MavenProject project : projects) { if (null != findPlugin(project.getBuild(), pluginGroupId, pluginArtifactId, goal)) { firstWithThisMojo = project; break; } } return firstWithThisMojo; }