List of usage examples for org.apache.maven.project MavenProject getId
public String getId()
From source file:org.ops4j.pax.construct.project.ImportBundleMojo.java
License:Apache License
/** * @param rootId initial import//from www .ja v a2 s .c o m */ private void importBundles(String rootId) { while (!m_candidateIds.isEmpty()) { String id = (String) m_candidateIds.remove(0); String[] fields = id.split(":"); MavenProject p = buildMavenProject(fields[0], fields[1], fields[2]); if (null == p) { continue; } if ("pom".equals(p.getPackaging())) { // support 'dependency' POMs processDependencies(p); } else if (rootId.equals(id) /* user knows best: assume given artifact is a bundle */ || PomUtils.isBundleProject(p, m_resolver, m_remoteRepos, m_localRepo, testMetadata)) { importBundle(p); // stop at first bundle if (!importTransitive) { break; } processDependencies(p); } else { getLog().info("Ignoring non-bundle dependency " + p.getId()); } } }
From source file:org.ops4j.pax.construct.project.ImportBundleMojo.java
License:Apache License
/** * Search direct dependencies for more import candidates * /*from w w w . j av a2 s . com*/ * @param project the Maven project being imported */ private void processDependencies(MavenProject project) { try { /* * exclude common OSGi system bundles, as they don't need to be imported or provisioned */ Set artifacts = project.createArtifacts(m_factory, null, new ExcludeSystemBundlesFilter()); for (Iterator i = artifacts.iterator(); i.hasNext();) { Artifact artifact = (Artifact) i.next(); String candidateId = getCandidateId(artifact); String scope = artifact.getScope(); scope = adjustDependencyScope(scope); if (!importOptional && artifact.isOptional()) { getLog().info("Skipping optional dependency " + artifact); } else if (Artifact.SCOPE_PROVIDED.equals(scope)) { scheduleCandidate(candidateId); } else { getLog().info("Skipping dependency " + artifact); } } } catch (InvalidDependencyVersionException e) { getLog().warn("Problem resolving dependencies for " + project.getId()); } }
From source file:org.sonar.batch.maven.MavenProjectConverter.java
License:Open Source License
private List<File> existingDirsOrFail(List<File> dirs, MavenProject pom, String propertyKey) { for (File dir : dirs) { if (!dir.isDirectory() || !dir.exists()) { throw MessageException.of(String.format( "The directory '%s' does not exist for Maven module %s. Please check the property %s", dir.getAbsolutePath(), pom.getId(), propertyKey)); }/*from www .ja v a 2 s .c o m*/ } return dirs; }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
private static List<File> existingPathsOrFail(List<File> dirs, MavenProject pom, String propertyKey) throws MojoExecutionException { for (File dir : dirs) { if (!dir.exists()) { throw new MojoExecutionException(String.format( "The directory '%s' does not exist for Maven module %s. Please check the property %s", dir.getAbsolutePath(), pom.getId(), propertyKey)); }/*from w w w . ja va 2 s . co m*/ } return dirs; }
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 . ja v a2s .com 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.m2e.webby.internal.launch.ProjectClasspathContributor.java
License:Open Source License
@Override public void contribute(WarClasspath classpath, IProgressMonitor monitor) throws CoreException { SubMonitor pm = SubMonitor.convert(monitor, 100); try {//w ww .ja v a 2 s.c o m if (overlayConfig.getTargetPath().length() > 0) { return; } MavenProject mvnProject = mvnFacade.getMavenProject(pm.newChild(30)); IMaven mvn = MavenPlugin.getMaven(); MavenExecutionRequest mvnRequest = mvn.createExecutionRequest(pm.newChild(10)); MavenSession mvnSession = mvn.createSession(mvnRequest, mvnProject); WarConfiguration warConfig; try { warConfig = new WarConfigurationExtractor().getConfiguration(mvnFacade, mvnProject, mvnSession, pm.newChild(10)); } catch (CoreException e) { throw WebbyPlugin .newError("Could not read configuration of maven-war-plugin for overlay from project " + mvnProject.getId(), e); } PathSelector overlaySelector = new PathSelector(overlayConfig.getIncludes(), overlayConfig.getExcludes()); PathSelector packagingSelector = new PathSelector(warConfig.getPackagingIncludes(), warConfig.getPackagingExcludes()); PathCollector pathCollector = new PathCollector(null, null); String classesDir = warConfig.getClassesDirectory(); for (String classFile : pathCollector.collectFiles(classesDir)) { String targetPath = "WEB-INF/classes/" + classFile; if (packagingSelector.isSelected(targetPath)) { if (overlaySelector.isSelected(targetPath)) { classpath.addRuntimeClasspathEntry(new File(classesDir)); break; } } } OverlayClasspath overlayClasspath = new OverlayClasspath(classpath, packagingSelector, overlaySelector); FilenameMapper filenameMapper = new FilenameMapper(warConfig.getFilenameMapping()); Map<String, Artifact> targetPaths = filenameMapper.getTargetPaths(mvnProject.getArtifacts()); for (Map.Entry<String, Artifact> e : targetPaths.entrySet()) { File file = e.getValue().getFile(); if (file == null) { continue; } String targetPath = e.getKey(); if (overlayClasspath.registerTargetPath(targetPath, 0)) { classpath.addRuntimeClasspathEntry(file); } } new WarClasspathPopulator().populate(overlayClasspath, mvnProject, warConfig, false, pm.newChild(50)); } finally { if (monitor != null) { monitor.done(); } } }
From source file:org.sourcepit.tpmp.change.ChecksumTargetPlatformConfigurationChangeDiscoverer.java
License:Apache License
@Override public void clearTargetPlatformConfigurationStausCache(File statusCacheDir, MavenProject project) { final File checksumFile = new File(statusCacheDir, "project-status.properties"); final PropertiesMap properties = new LinkedPropertiesMap(); if (checksumFile.exists()) { properties.load(checksumFile);/*w ww .j a v a 2 s .c o m*/ properties.remove(project.getId()); properties.store(checksumFile); } }
From source file:org.sourcepit.tpmp.change.ChecksumTargetPlatformConfigurationChangeDiscoverer.java
License:Apache License
private String getProjectChecksum(File statusCacheDir, MavenProject project) { final File checksumFile = new File(statusCacheDir, "project-status.properties"); if (checksumFile.exists()) { final PropertiesMap properties = new LinkedPropertiesMap(); properties.load(checksumFile);/* w w w . j a va2 s . com*/ return properties.get(project.getId()); } return null; }
From source file:org.sourcepit.tpmp.change.ChecksumTargetPlatformConfigurationChangeDiscoverer.java
License:Apache License
private void setProjectChecksum(File statusCacheDir, MavenProject project, String checksum) { final File checksumFile = new File(statusCacheDir, "project-status.properties"); final PropertiesMap properties = new LinkedPropertiesMap(); if (checksumFile.exists()) { properties.load(checksumFile);/* ww w .jav a 2 s. c o m*/ } else { checksumFile.getParentFile().mkdirs(); try { checksumFile.createNewFile(); } catch (IOException e) { throw Exceptions.pipe(e); } } properties.put(project.getId(), checksum); properties.store(checksumFile); }
From source file:org.sourcepit.tpmp.resolver.PerProjectTargetPlatformResolver.java
License:Apache License
private void resolveTargetPlatform(MavenSession session, MavenProject project, boolean includeSource, boolean forceUpdate, File metadataDir, final TargetPlatformResolutionHandler handler) throws Error { if (isResolutionRequired(metadataDir, session, project, forceUpdate)) { getLogger().info("Materializing target platform of project " + project.getId()); try {/* w w w. j a v a 2 s . co m*/ tpResolver.resolveTargetPlatform(session, project, includeSource, handler); } catch (RuntimeException e) { changeDiscoverer.clearTargetPlatformConfigurationStausCache(metadataDir, project); throw e; } catch (Error e) { changeDiscoverer.clearTargetPlatformConfigurationStausCache(metadataDir, project); throw e; } } else { getLogger() .info("Target platform of project " + project.getId() + " already materialized and up to date"); } }