List of usage examples for org.apache.maven.project MavenProject getProperties
public Properties getProperties()
From source file:org.sonar.api.batch.maven.MavenUtils.java
License:Open Source License
/** * @return source encoding/*from ww w . j ava 2 s. c o m*/ */ public static String getSourceEncoding(MavenProject pom) { return pom.getProperties().getProperty("project.build.sourceEncoding"); }
From source file:org.sonar.batch.maven.MavenProjectConverter.java
License:Open Source License
private List<File> sourceDirs(MavenProject pom, String propertyKey, List mavenDirs) { List<String> paths; String prop = pom.getProperties().getProperty(propertyKey); if (prop != null) { paths = Arrays.asList(StringUtils.split(prop, ",")); // do not remove dirs that do not exist. They must be kept in order to // notify users that value of sonar.sources has a typo. return existingDirsOrFail(resolvePaths(paths, pom.getBasedir()), pom, propertyKey); }/*from www . j ava2 s .co m*/ List<File> dirs = resolvePaths(mavenDirs, pom.getBasedir()); // Maven provides some directories that do not exist. They // should be removed return keepExistingDirs(dirs); }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
private List<File> sourcePaths(MavenProject pom, String propertyKey, Collection<String> mavenPaths) throws MojoExecutionException { List<File> filesOrDirs; boolean userDefined = false; String prop = StringUtils.defaultIfEmpty(userProperties.getProperty(propertyKey), envProperties.getProperty(propertyKey)); prop = StringUtils.defaultIfEmpty(prop, pom.getProperties().getProperty(propertyKey)); if (prop != null) { List<String> paths = Arrays.asList(StringUtils.split(prop, ",")); filesOrDirs = resolvePaths(paths, pom.getBasedir()); userDefined = true;/*from w w w. ja v a2s. c o m*/ } else { removeTarget(pom, mavenPaths); filesOrDirs = resolvePaths(mavenPaths, pom.getBasedir()); } if (userDefined && !MAVEN_PACKAGING_POM.equals(pom.getModel().getPackaging())) { return existingPathsOrFail(filesOrDirs, pom, propertyKey); } else { // Maven provides some directories that do not exist. They // should be removed. Same for pom module were sonar.sources and sonar.tests // can be defined only to be inherited by children return removeNested(keepExistingPaths(filesOrDirs)); } }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenUtils.java
License:Open Source License
/** * @param pom the project pom/*w ww .j a v a 2 s. c om*/ * @return source encoding */ @CheckForNull public static String getSourceEncoding(MavenProject pom) { return pom.getProperties().getProperty("project.build.sourceEncoding"); }
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 {// w ww . j a va2s . c o 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.sourcepit.b2.internal.maven.B2BootstrapParticipant.java
License:Apache License
public void afterBuild(MavenSession bootSession, MavenProject bootProject, MavenSession actualSession) { final String setScmIgnoresProp = bootProject.getProperties().getProperty("b2.scm.setScmIgnores", System.getProperty("b2.scm.setScmIgnores", "false")); final boolean isSetScmIgnores = Boolean.valueOf(setScmIgnoresProp).booleanValue(); if (isSetScmIgnores) { final AbstractModule module = (AbstractModule) bootProject .getContextValue(AbstractModule.class.getName()); final ModuleDirectory moduleDirectory = (ModuleDirectory) bootProject .getContextValue(ModuleDirectory.class.getName()); if (module != null && moduleDirectory != null) { scm.doSetScmIgnores(moduleDirectory, module); }//from w ww. ja v a2 s .c om } }
From source file:org.sourcepit.b2.internal.maven.MavenModulePropertiesFactory.java
License:Apache License
public PropertiesSource createModuleProperties(MavenSession mavenSession, final MavenProject project) { final PropertiesMap propertiesMap = B2ModelBuildingRequest.newDefaultProperties(); propertiesMap.put("b2.moduleNameSpace", project.getGroupId()); final String mavenVersion = project.getVersion(); final String osgiVersion = VersionUtils.toBundleVersion(mavenVersion); putModuleVersions(propertiesMap, osgiVersion); propertiesMap.putMap(project.getProperties()); propertiesMap.putMap(mavenSession.getSystemProperties()); propertiesMap.putMap(mavenSession.getUserProperties()); final List<ValueSource> valueSources = new ArrayList<ValueSource>(); final List<String> prefixes = new ArrayList<String>(); prefixes.add("pom"); prefixes.add("project"); valueSources.add(ValueSourceUtils.newPrefixedValueSource(prefixes, project)); valueSources.add(ValueSourceUtils.newPrefixedValueSource("session", mavenSession)); final Settings settings = mavenSession.getSettings(); if (settings != null) { valueSources.add(ValueSourceUtils.newPrefixedValueSource("settings", settings)); valueSources//from ww w.j av a 2 s. co m .add(ValueSourceUtils.newSingleValueSource("localRepository", settings.getLocalRepository())); } return new AbstractPropertiesSource() { public String get(String key) { if ("module.id".equals(key) && !isPropertyDefinedOnProject(key)) { return null; } final String value = propertiesMap.get(key); if (value != null) { return value; } for (ValueSource valueSource : valueSources) { final Object oValue = valueSource.getValue(key); if (oValue != null) { return oValue.toString(); } } return null; } private boolean isPropertyDefinedOnProject(String key) { return project.getOriginalModel().getProperties().containsKey(key); } }; }
From source file:org.sourcepit.osgifier.maven.GenerateManifestMojo.java
License:Apache License
private ArtifactManifestBuilderRequest newManifestRequest(final MavenProject project) { final ArtifactManifestBuilderRequest request = new ArtifactManifestBuilderRequest(); request.setArtifact(project.getArtifact()); if (!skipSource) { request.setSourceArtifact(newProjectArtifact(project, sourceClassifier, "jar")); }/*w ww . j a va 2 s.co m*/ request.getDependencies().addAll(project.getArtifacts()); final PropertiesSource options = chainOptions(getMojoConfigurationOptions(), toOptions(project.getProperties()), toOptions(System.getProperties())); request.setOptions(options); request.setSymbolicName(symbolicName); request.setTimestamp(buildContext.getSession().getStartTime()); request.setHeaderModifications(headerModifications); return request; }
From source file:org.sourcepit.tools.shared.resources.internal.mojo.MavenProjectManifestMerger.java
License:Apache License
public void merge(MavenProject project, File manifestFile, ManifestMerger merger, Manifest manifest) throws IOException { Manifest current = loadManifest(manifestFile); merger.merge(current, manifest);/*from w w w .j av a2 s . com*/ current.eResource().save(null); project.getProperties().setProperty("jar.useDefaultManifestFile", String.valueOf(true)); }
From source file:org.sourcepit.tpmp.change.ChecksumTargetPlatformConfigurationChangeDiscoverer.java
License:Apache License
private String getDefaultEncoding(MavenProject project) { return project.getProperties().getProperty("project.build.sourceEncoding", Charset.defaultCharset().name()); }