List of usage examples for org.apache.maven.project MavenProject getBuild
public Build getBuild()
From source file:org.sonatype.maven.mojo.execution.MojoExecution.java
License:Open Source License
/** * Returns last 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.// w w w .j a va 2s . c om * @return MavenProject of last project with given plugin is being built or null. */ public static MavenProject getLastProjectWithMojoInExecution(final MavenSession mavenSession, final String pluginGroupId, final String pluginArtifactId, final String goal) { final ArrayList<MavenProject> projects = new ArrayList<MavenProject>(mavenSession.getSortedProjects()); Collections.reverse(projects); MavenProject lastWithThisMojo = null; for (MavenProject project : projects) { if (null != findPlugin(project.getBuild(), pluginGroupId, pluginArtifactId, goal)) { lastWithThisMojo = project; break; } } return lastWithThisMojo; }
From source file:org.sonatype.maven.plugin.app.ClasspathUtils.java
License:Open Source License
public static void write(final Set<Artifact> classpathArtifacts, final MavenProject project) throws IOException { Properties p = new Properties(); for (Artifact artifact : classpathArtifacts) { File artifactFile = artifact.getFile(); String fname = formatArtifactKey(artifact); p.setProperty(fname, artifactFile.getAbsolutePath()); }/*from w ww . ja va 2 s . com*/ File cpFile = new File(project.getBuild().getDirectory(), CP_PROPSFILE); FileOutputStream stream = null; try { cpFile.getParentFile().mkdirs(); stream = new FileOutputStream(cpFile); p.store(stream, "Written on: " + new Date() + " (key format is <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>)"); } finally { IOUtil.close(stream); } }
From source file:org.sonatype.maven.plugin.emma.EmmaUtils.java
License:Open Source License
/** * Fix EMMA data file locations. EMMA generates data files in wrong locations: this method moves these files to * valid locations.// w w w .j a v a 2 s . c om * * @param project * current Maven project * @param dataFiles * to fix * @return new data file locations */ public static File[] fixDataFileLocations(MavenProject project, File[] dataFiles) { final List newDataFiles = new ArrayList(); for (int i = 0; i < dataFiles.length; ++i) { final File src = dataFiles[i]; if (!src.exists()) { // if the file does not exist, we cannot use it continue; } if (src.getParentFile().equals(project.getBasedir())) { // EMMA generates coverage data files in project root // (as it is actually the current directory): // move these files to the "target" directory final File dst = new File(project.getBuild().getDirectory(), "coverage-" + i + ".ec"); try { FileUtils.rename(src, dst); } catch (IOException e) { throw new IllegalStateException("Failed to move coverage data file: " + src.getAbsolutePath(), e); } newDataFiles.add(dst); } else { newDataFiles.add(src); } } return (File[]) newDataFiles.toArray(new File[newDataFiles.size()]); }
From source file:org.sonatype.nexus.maven.staging.AbstractStagingMojo.java
License:Open Source License
/** * Returns the working directory root (the one containing all the staged and deferred deploys), that is either set * explicitly by user in plugin configuration (see {@link #altStagingDirectory} parameter), or it's location is * calculated taking as base the first project in this reactor that will/was executing this plugin. *///w w w . j a v a 2 s. c om protected File getWorkDirectoryRoot() { if (altStagingDirectory != null) { return altStagingDirectory; } else { final MavenProject firstWithThisMojo = getFirstProjectWithThisPluginDefined(); if (firstWithThisMojo != null) { final File firstWithThisMojoBuildDir; if (firstWithThisMojo.getBuild() != null && firstWithThisMojo.getBuild().getDirectory() != null) { firstWithThisMojoBuildDir = new File(firstWithThisMojo.getBuild().getDirectory()) .getAbsoluteFile(); } else { firstWithThisMojoBuildDir = new File(firstWithThisMojo.getBasedir().getAbsoluteFile(), "target"); } return new File(firstWithThisMojoBuildDir, "nexus-staging"); } else { // top level (invocation place with some sensible defaults) // TODO: what can we do here? Do we have MavenProject at all? return new File(getMavenSession().getExecutionRootDirectory() + "/target/nexus-staging"); } } }
From source file:org.sonatype.nexus.pluginbundle.maven.ClasspathUtils.java
License:Open Source License
public static Properties read(final MavenProject project) throws IOException { File file = new File(project.getBuild().getDirectory(), FILE_NAME); if (!file.exists()) { throw new IOException("Missing classpath file: " + file.getAbsolutePath()); }/*w w w . ja va2s. c o m*/ Properties props = new Properties(); InputStream input = null; try { input = new BufferedInputStream(new FileInputStream(file)); props.load(input); } finally { IOUtil.close(input); } return props; }
From source file:org.sonatype.nexus.pluginbundle.maven.ClasspathUtils.java
License:Open Source License
public static void write(final BuildContext buildContext, final Set<Artifact> classpathArtifacts, final MavenProject project) throws IOException { Properties props = new Properties(); for (Artifact artifact : classpathArtifacts) { File file = artifact.getFile(); String name = formatArtifactKey(artifact); props.setProperty(name, file.getAbsolutePath()); }// w w w . j a v a 2 s . c o m File file = new File(project.getBuild().getDirectory(), FILE_NAME); file.getParentFile().mkdirs(); OutputStream output = null; try { output = new BufferedOutputStream(buildContext.newFileOutputStream(file)); props.store(output, null); } finally { IOUtil.close(output); } }
From source file:org.sonatype.nexus.pluginbundle.maven.OSGiUtils.java
License:Open Source License
/** * Updates the OSGi metadata wrt the assembled content. * //from w w w . j a va 2s . c o m * @return Path to OSGi manifest */ public static String updateMetadata(final MavenProject project, final List<FileItem> content) throws IOException { File file = new File(project.getBuild().getDirectory(), FILE_NAME); if (!file.exists()) { throw new IOException("Missing metadata file: " + file.getAbsolutePath()); } Manifest mf = new Manifest(); InputStream input = null; try { input = new BufferedInputStream(new FileInputStream(file)); mf.read(input); } finally { IOUtil.close(input); } Attributes attributes = mf.getMainAttributes(); String exportedPackages = getExportedPackages(content); if (exportedPackages.length() > 0) { attributes.putValue(Constants.EXPORT_PACKAGE, exportedPackages); } OutputStream output = null; try { output = new BufferedOutputStream(new FileOutputStream(file)); mf.write(output); } finally { IOUtil.close(output); } return file.getPath(); }
From source file:org.sonatype.nexus.pluginbundle.maven.OSGiUtils.java
License:Open Source License
/** * Generates basic OSGi metadata for the Nexus plugin. *//*from ww w. j a v a 2 s . c o m*/ public static void write(final BuildContext buildContext, final PluginMetadata metadata, final MavenProject project) throws IOException { Manifest mf = new Manifest(); Attributes attributes = mf.getMainAttributes(); attributes.put(Name.MANIFEST_VERSION, "1.0"); attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2"); attributes.putValue(Constants.BUNDLE_SYMBOLICNAME, metadata.getGroupId() + '.' + metadata.getArtifactId()); attributes.putValue(Constants.BUNDLE_VERSION, Analyzer.cleanupVersion(metadata.getVersion())); attributes.putValue(Constants.BUNDLE_CLASSPATH, getBundleClassPath(project, metadata)); String requiredBundles = getRequiredBundles(metadata); if (requiredBundles.length() > 0) { attributes.putValue(Constants.REQUIRE_BUNDLE, requiredBundles); } File file = new File(project.getBuild().getDirectory(), FILE_NAME); file.getParentFile().mkdirs(); OutputStream output = null; try { output = new BufferedOutputStream(buildContext.newFileOutputStream(file)); mf.write(output); } finally { IOUtil.close(output); } }
From source file:org.sonatype.nexus.pluginbundle.maven.OSGiUtils.java
License:Open Source License
/** * Generates a Bundle-ClassPath header for the Nexus plugin. *///from w w w . j av a 2s . c o m private static String getBundleClassPath(final MavenProject project, final PluginMetadata metadata) { StringBuilder buf = new StringBuilder(project.getBuild().getFinalName()).append(".jar"); for (ClasspathDependency d : metadata.getClasspathDependencies()) { buf.append(",dependencies/").append(d.getArtifactId()).append('-').append(d.getVersion()); if (!StringUtils.isBlank(d.getClassifier())) { buf.append('-').append(d.getClassifier()); } buf.append('.').append(d.getType()); } return buf.toString(); }
From source file:org.sonatype.tycho.m2e.internal.PDEProjectHelper.java
License:Open Source License
private IPath getOutputLocation(IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException { File outputDirectory = new File(mavenProject.getBuild().getOutputDirectory()); outputDirectory.mkdirs();//from w w w .jav a 2s. co m IPath relPath = MavenProjectUtils.getProjectRelativePath(project, mavenProject.getBuild().getOutputDirectory()); IFolder folder = project.getFolder(relPath); folder.refreshLocal(IResource.DEPTH_INFINITE, monitor); return folder.getFullPath(); }