List of usage examples for org.apache.maven.project MavenProject getBasedir
public File getBasedir()
From source file:org.apache.felix.bundleplugin.BundlePlugin.java
License:Apache License
private static String getMavenResourcePaths(MavenProject project) { final String basePath = project.getBasedir().getAbsolutePath(); Set pathSet = new LinkedHashSet(); for (Iterator i = project.getResources().iterator(); i.hasNext();) { org.apache.maven.model.Resource resource = (org.apache.maven.model.Resource) i.next(); final String sourcePath = resource.getDirectory(); final String targetPath = resource.getTargetPath(); // ignore empty or non-local resources if (new File(sourcePath).exists() && ((targetPath == null) || (targetPath.indexOf("..") < 0))) { DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(resource.getDirectory()); if (resource.getIncludes() != null && !resource.getIncludes().isEmpty()) { scanner.setIncludes((String[]) resource.getIncludes().toArray(EMPTY_STRING_ARRAY)); } else { scanner.setIncludes(DEFAULT_INCLUDES); }/*from w w w . j a v a2s .c o m*/ if (resource.getExcludes() != null && !resource.getExcludes().isEmpty()) { scanner.setExcludes((String[]) resource.getExcludes().toArray(EMPTY_STRING_ARRAY)); } scanner.addDefaultExcludes(); scanner.scan(); List includedFiles = Arrays.asList(scanner.getIncludedFiles()); for (Iterator j = includedFiles.iterator(); j.hasNext();) { String name = (String) j.next(); String path = sourcePath + '/' + name; // make relative to project if (path.startsWith(basePath)) { if (path.length() == basePath.length()) { path = "."; } else { path = path.substring(basePath.length() + 1); } } // replace windows backslash with a slash // this is a workaround for a problem with bnd 0.0.189 if (File.separatorChar != '/') { name = name.replace(File.separatorChar, '/'); path = path.replace(File.separatorChar, '/'); } // copy to correct place path = name + '=' + path; if (targetPath != null) { path = targetPath + '/' + path; } // use Bnd filtering? if (resource.isFiltering()) { path = '{' + path + '}'; } pathSet.add(path); } } } StringBuffer resourcePaths = new StringBuffer(); for (Iterator i = pathSet.iterator(); i.hasNext();) { resourcePaths.append(i.next()); if (i.hasNext()) { resourcePaths.append(','); } } return resourcePaths.toString(); }
From source file:org.apache.felix.bundleplugin.ManifestPlugin.java
License:Apache License
protected Analyzer getAnalyzer(MavenProject project, Map instructions, Properties properties, Jar[] classpath) throws IOException, MojoExecutionException { File file = project.getArtifact().getFile(); if (file == null) { file = getOutputDirectory();//www. j av a 2 s.com } if (!file.exists()) { throw new FileNotFoundException(file.getPath()); } properties.putAll(getDefaultProperties(project)); properties.putAll(transformDirectives(instructions)); PackageVersionAnalyzer analyzer = new PackageVersionAnalyzer(); if (project.getBasedir() != null) analyzer.setBase(project.getBasedir()); analyzer.setProperties(properties); if (classpath != null) analyzer.setClasspath(classpath); analyzer.setJar(file); if (analyzer.getProperty(Analyzer.EXPORT_PACKAGE) == null && analyzer.getProperty(Analyzer.EXPORT_CONTENTS) == null && analyzer.getProperty(Analyzer.PRIVATE_PACKAGE) == null) { String export = analyzer.calculateExportsFromContents(analyzer.getJar()); analyzer.setProperty(Analyzer.EXPORT_PACKAGE, export); } // Apply Embed-Dependency headers, even though the contents won't be changed Collection embeddableArtifacts = getEmbeddableArtifacts(project, analyzer); new DependencyEmbedder(getLog(), embeddableArtifacts).processHeaders(analyzer); dumpInstructions("BND Instructions:", analyzer.getProperties(), getLog()); dumpClasspath("BND Classpath:", analyzer.getClasspath(), getLog()); analyzer.mergeManifest(analyzer.getJar().getManifest()); analyzer.calcManifest(); dumpManifest("BND Manifest:", analyzer.getJar().getManifest(), getLog()); return analyzer; }
From source file:org.apache.marmotta.maven.plugins.buildinfo.AbstractInfoProvider.java
License:Apache License
private File lookupDirectory(MavenProject project, String child) throws FileNotFoundException { File dir, vcs;//from w w w . j av a 2 s .c o m // walk up the directory structure looking for the .git or .hg directory dir = project.getBasedir(); while (dir != null) { vcs = new File(dir, child); if (vcs.exists() && vcs.isDirectory()) { return dir; } dir = dir.getParentFile(); } //Walk up the project parent hierarchy seeking the .hg directory /* MavenProject mavenProject = project; while (mavenProject != null) { dir = new File(mavenProject.getBasedir(), child); if (dir.exists() && dir.isDirectory()) { return dir; } // If we've reached the top-level parent and not found the .git directory, look one level further up if (mavenProject.getParent() == null && mavenProject.getBasedir() != null) { dir = new File(mavenProject.getBasedir().getParentFile(), child); if (dir.exists() && dir.isDirectory()) { return dir; } } mavenProject = mavenProject.getParent(); } */ throw new FileNotFoundException("Could not find " + child + " directory"); }
From source file:org.apache.marmotta.maven.plugins.buildinfo.GitInfoProvider.java
License:Apache License
public Map<String, String> getInfo(MavenProject project) { File basedir = project.getBasedir(); InfoScmResult result = null;/*from w w w . j a v a 2 s . c o m*/ ScmLogger logger = new DefaultLog(); GitCommand command = new GitExeScmProvider().getInfoCommand(); command.setLogger(logger); try { ScmProviderRepository repository = new GitScmProviderRepository(basedir.getAbsolutePath()); ScmFileSet fileSet = new ScmFileSet(basedir); CommandParameters parameters = new CommandParameters(); result = (InfoScmResult) command.execute(repository, fileSet, parameters); } catch (ScmException e) { if (logger.isErrorEnabled()) { logger.error(e.getMessage()); } } Map<String, String> info = new LinkedHashMap<String, String>(); if (result != null) { if (result.isSuccess()) { List<InfoItem> items = result.getInfoItems(); if ((items != null) && (items.size() == 1)) { info.put("git.revision", items.get(0).getRevision()); info.put("git.author", items.get(0).getLastChangedAuthor()); info.put("git.repository", items.get(0).getRepositoryUUID()); info.put("git.date", items.get(0).getLastChangedDate()); } else { info.put("git.error", "The command returned incorrect number of arguments"); } } else { info.put("git.error", result.getProviderMessage()); } } return info; }
From source file:org.apache.marmotta.maven.plugins.buildinfo.MercurialInfoProvider.java
License:Apache License
public Map<String, String> getInfo(MavenProject project) { ScmLogger logger = new DefaultLog(); HgLogConsumer consumer = new HgLogConsumer(logger); ScmResult result = null;//from www. j a v a 2 s.c o m try { result = HgUtils.execute(consumer, logger, project.getBasedir(), new String[] { HgCommandConstants.REVNO_CMD, "-n", "-i", "-b" }); } catch (ScmException e) { if (logger.isErrorEnabled()) { logger.error(e.getMessage()); } } Map<String, String> info = new LinkedHashMap<String, String>(); if (result != null) { if (result.isSuccess()) { String output = result.getCommandOutput(); if (output != null) { Matcher matcher = HG_OUTPUT_PATTERN.matcher(output); if (matcher.find() && matcher.groupCount() == 3) { StringBuilder changeset = new StringBuilder(); changeset.append("r").append(matcher.group(2)).append(":").append(matcher.group(1)); info.put("build.changeset", changeset.toString()); info.put("build.branch", matcher.group(3)); info.put("build.revision", matcher.group(2)); info.put("build.revhash", matcher.group(1)); } else { info.put("hg.error", "The command returned incorrect number of arguments"); } } } else { info.put("hg.error", result.getProviderMessage()); } } return info; }
From source file:org.apache.myfaces.trinidadbuild.plugin.jdeveloper.JDeveloperMojo.java
License:Apache License
/** * Returns the JDeveloper project file for a Maven POM. * //from w w w . j a va 2 s. c om * @param project * the Maven POM * * @return the JDeveloper project file */ private File getJProjectFile(MavenProject project) { String jprName = project.getArtifactId() + ".jpr"; return new File(project.getBasedir(), jprName); }
From source file:org.apache.myfaces.trinidadbuild.plugin.jdeveloper.JDeveloperMojo.java
License:Apache License
/** * Returns the JDeveloper test project file for a Maven POM. * /*w w w . j a va 2 s .c o m*/ * @param project * the Maven POM * * @return the JDeveloper test project file */ private File getJProjectTestFile(MavenProject project) { String jprName = project.getArtifactId() + "-test.jpr"; return new File(project.getBasedir(), jprName); }
From source file:org.apache.myfaces.trinidadbuild.plugin.jdeveloper.JDeveloperMojo.java
License:Apache License
/** * Returns the JDeveloper workspace file for a Maven POM. * //from ww w . j av a2s . co m * @param project * the Maven POM * * @return the JDeveloper workspace file */ private File getJWorkspaceFile(MavenProject project) { String jwsName = project.getArtifactId() + ".jws"; return new File(project.getBasedir(), jwsName); }
From source file:org.apache.sling.ide.eclipse.m2e.internal.ContentPackageProjectConfigurator.java
License:Apache License
@Override public void configure(ProjectConfigurationRequest configRequest, IProgressMonitor progressMonitor) throws CoreException { IProject project = configRequest.getProject(); MavenProject mavenProject = configRequest.getMavenProject(); boolean active = !"false".equalsIgnoreCase(mavenProject.getProperties().getProperty(M2E_ACTIVE)); if (!active) { trace("M2E project configurer for packing type content-package was disabled with property {0}", M2E_ACTIVE);//from w w w . j av a 2s. c om return; } String mavenGav = mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":" + mavenProject.getVersion(); trace("Configuring Maven project {0} with packaging content-package...", mavenGav); // core configuration for sling ide plugin Resource folder = MavenProjectUtils.guessJcrRootFolder(mavenProject); java.nio.file.Path contentSyncPath = mavenProject.getBasedir().toPath() .relativize(Paths.get(folder.getDirectory())); String jcrRootPath = contentSyncPath.toString(); ConfigurationHelper.convertToContentPackageProject(project, progressMonitor, Path.fromOSString(jcrRootPath)); new WtpProjectConfigurer(mavenProject, project, jcrRootPath).configure(progressMonitor); trace("Done converting ."); }
From source file:org.apache.tuscany.maven.plugin.eclipse.AbstractIdeSupportMojo.java
License:Apache License
/** * Resolve project dependencies. Manual resolution is needed in order to avoid resolution of multiproject artifacts * (if projects will be linked each other an installed jar is not needed) and to avoid a failure when a jar is * missing./*from ww w .j a v a 2s. co m*/ * * @throws MojoExecutionException if dependencies can't be resolved * @return resolved IDE dependencies, with attached jars for non-reactor dependencies */ protected IdeDependency[] doDependencyResolution() throws MojoExecutionException { if (ideDeps == null) { if (resolveDependencies) { MavenProject project = getProject(); Set<String> imported = Collections.emptySet(); try { imported = BundleUtil.getImportedPackages(project.getBasedir()); } catch (IOException e1) { throw new MojoExecutionException(e1.getMessage(), e1); } ArtifactRepository localRepo = getLocalRepository(); List deps = getProject().getDependencies(); // Collect the list of resolved IdeDependencies. List dependencies = new ArrayList(); if (deps != null) { Map managedVersions = createManagedVersionMap(getArtifactFactory(), project.getId(), project.getDependencyManagement()); ArtifactResolutionResult artifactResolutionResult = null; try { List listeners = new ArrayList(); if (logger.isDebugEnabled()) { listeners.add(new DebugResolutionListener(logger)); } listeners.add(new WarningResolutionListener(logger)); artifactResolutionResult = artifactCollector.collect(getProjectArtifacts(), project.getArtifact(), managedVersions, localRepo, project.getRemoteArtifactRepositories(), getArtifactMetadataSource(), null, listeners); } catch (ArtifactResolutionException e) { getLog().debug(e.getMessage(), e); getLog().error( Messages.getString("AbstractIdeSupportMojo.artifactresolution", new Object[] { //$NON-NLS-1$ e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() })); // if we are here artifactResolutionResult is null, create a project without dependencies but // don't fail // (this could be a reactor projects, we don't want to fail everything) // Causes MECLIPSE-185. Not sure if it should be handled this way?? return new IdeDependency[0]; } // keep track of added reactor projects in order to avoid duplicates Set emittedReactorProjectId = new HashSet(); for (Iterator i = artifactResolutionResult.getArtifactResolutionNodes().iterator(); i .hasNext();) { ResolutionNode node = (ResolutionNode) i.next(); int dependencyDepth = node.getDepth(); Artifact art = node.getArtifact(); // don't resolve jars for reactor projects if (hasToResolveJar(art)) { try { artifactResolver.resolve(art, node.getRemoteRepositories(), localRepository); } catch (ArtifactNotFoundException e) { getLog().debug(e.getMessage(), e); getLog().warn(Messages.getString("AbstractIdeSupportMojo.artifactdownload", //$NON-NLS-1$ new Object[] { e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() })); } catch (ArtifactResolutionException e) { getLog().debug(e.getMessage(), e); getLog().warn(Messages.getString("AbstractIdeSupportMojo.artifactresolution", //$NON-NLS-1$ new Object[] { e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() })); } } boolean includeArtifact = true; if (getExcludes() != null) { String artifactFullId = art.getGroupId() + ":" + art.getArtifactId(); if (getExcludes().contains(artifactFullId)) { getLog().info("excluded: " + artifactFullId); includeArtifact = false; } } if (includeArtifact && (!(getUseProjectReferences() && isAvailableAsAReactorProject(art)) || emittedReactorProjectId.add(art.getGroupId() + '-' + art.getArtifactId()))) { // the following doesn't work: art.getArtifactHandler().getPackaging() always returns "jar" // also // if the packaging specified in pom.xml is different. // osgi-bundle packaging is provided by the felix osgi plugin // eclipse-plugin packaging is provided by this eclipse plugin // String packaging = art.getArtifactHandler().getPackaging(); // boolean isOsgiBundle = "osgi-bundle".equals( packaging ) || "eclipse-plugin".equals( // packaging ); // we need to check the manifest, if "Bundle-SymbolicName" is there the artifact can be // considered // an osgi bundle if ("pom".equals(art.getType())) { continue; } File artifactFile = art.getFile(); MavenProject reactorProject = getReactorProject(art); if (reactorProject != null) { artifactFile = reactorProject.getBasedir(); } boolean isOsgiBundle = false; String osgiSymbolicName = null; try { osgiSymbolicName = BundleUtil.getBundleSymbolicName(artifactFile); } catch (IOException e) { getLog().error("Unable to read jar manifest from " + artifactFile, e); } isOsgiBundle = osgiSymbolicName != null; IdeDependency dep = new IdeDependency(art.getGroupId(), art.getArtifactId(), art.getVersion(), art.getClassifier(), useProjectReference(art), Artifact.SCOPE_TEST.equals(art.getScope()), Artifact.SCOPE_SYSTEM.equals(art.getScope()), Artifact.SCOPE_PROVIDED.equals(art.getScope()), art.getArtifactHandler().isAddedToClasspath(), art.getFile(), art.getType(), isOsgiBundle, osgiSymbolicName, dependencyDepth, getProjectNameForArifact(art)); // no duplicate entries allowed. System paths can cause this problem. if (!dependencies.contains(dep)) { // [rfeng] Do not add compile/provided dependencies if (!(pde && (Artifact.SCOPE_COMPILE.equals(art.getScope()) || Artifact.SCOPE_PROVIDED.equals(art.getScope())))) { dependencies.add(dep); } else { // Check this compile dependency is an OSGi package supplier if (!imported.isEmpty()) { Set<String> exported = Collections.emptySet(); try { exported = BundleUtil.getExportedPackages(artifactFile); } catch (IOException e) { getLog().error("Unable to read jar manifest from " + art.getFile(), e); } boolean matched = false; for (String p : imported) { if (exported.contains(p)) { matched = true; break; } } if (!matched) { dependencies.add(dep); } else { getLog().debug( "Compile dependency is skipped as it is added through OSGi dependency: " + art); } } else { dependencies.add(dep); } } } } } // @todo a final report with the list of // missingArtifacts? } ideDeps = (IdeDependency[]) dependencies.toArray(new IdeDependency[dependencies.size()]); } else { ideDeps = new IdeDependency[0]; } } return ideDeps; }