List of usage examples for org.apache.maven.project MavenProject getBuild
public Build getBuild()
From source file:org.openspaces.maven.plugin.Utils.java
License:Apache License
/** * Finds the relative path from current directory to the PU jar file. * * @param project the Maven project//from ww w.ja v a2 s. co m * @return the relative path from current directory to the PU jar file. */ static String getProcessingUnitJar(MavenProject project) { String targetDir = project.getBuild().getDirectory(); String curDir = System.getProperty("user.dir"); String relativePath = targetDir.substring(curDir.length() + 1); relativePath = relativePath.replace('\\', '/'); String finalName = project.getBuild().getFinalName(); if ("war".equalsIgnoreCase(project.getPackaging())) { return relativePath + "/" + finalName + ".war"; } else { return relativePath + "/" + finalName + ".jar"; } }
From source file:org.openspaces.maven.plugin.Utils.java
License:Apache License
/** * Finds the relative path from current directory to the PU dir. * * @param project the Maven project/* w w w . j a v a 2 s . c o m*/ * @return the relative path from current directory to the PU dir. */ static String getPURelativePathDir(MavenProject project) { String targetDir = project.getBuild().getDirectory(); String curDir = System.getProperty("user.dir"); String relativePath = targetDir.substring(curDir.length() + 1); relativePath = relativePath.replace('\\', '/'); String finalName = project.getBuild().getFinalName(); return relativePath + "/" + finalName; }
From source file:org.ops4j.pax.construct.clone.CloneMojo.java
License:Apache License
/** * Analyze project structure to try to deduce if this really is a wrapper * /*from w ww . j ava 2s .c o m*/ * @param project Maven bundle project * @return wrapped artifact, null if it isn't a wrapper project */ private Dependency findCustomizedWrappee(MavenProject project) { List dependencies = project.getDependencies(); String sourcePath = project.getBuild().getSourceDirectory(); // try to find a dependency that relates to the wrapper project if (dependencies.size() > 0 && !new File(sourcePath).exists()) { for (Iterator i = dependencies.iterator(); i.hasNext();) { Dependency dependency = (Dependency) i.next(); if (project.getArtifactId().indexOf(dependency.getArtifactId()) >= 0) { return dependency; // closest match } } return (Dependency) dependencies.get(0); } return null; }
From source file:org.ops4j.pax.construct.clone.CloneMojo.java
License:Apache License
/** * Analyze bundle project to find the primary namespace it provides * //from w w w . j av a 2 s. c o m * @param project Maven project * @return primary Java namespace */ private String findBundleNamespace(MavenProject project) { Properties properties = project.getProperties(); // Pax-Construct v2 String namespace = properties.getProperty("bundle.namespace"); if (null == namespace) { // original Pax-Construct namespace = properties.getProperty("bundle.package"); String sourcePath = project.getBuild().getSourceDirectory(); if (null == namespace && new File(sourcePath).exists()) { namespace = findPrimaryPackage(sourcePath); } } return namespace; }
From source file:org.ops4j.pax.construct.clone.CloneMojo.java
License:Apache License
/** * Create a new archetype for a bundle project, with potentially customized POM and Bnd settings * /*from www .jav a 2s.c o m*/ * @param project Maven project * @param namespace Java namespace, may be null * @param customizedPom customized Maven project model, may be null * @return clause identifying the archetype fragment * @throws MojoExecutionException */ private String createBundleArchetype(MavenProject project, String namespace, Pom customizedPom) throws MojoExecutionException { File baseDir = project.getBasedir(); getLog().info("Cloning bundle project " + project.getArtifactId()); ArchetypeFragment fragment = new ArchetypeFragment(getFragmentDir(), namespace, false); fragment.addPom(baseDir, customizedPom); if (null != namespace) { fragment.addSources(baseDir, project.getBuild().getSourceDirectory(), false); fragment.addSources(baseDir, project.getBuild().getTestSourceDirectory(), true); } for (Iterator i = project.getTestResources().iterator(); i.hasNext();) { Resource r = (Resource) i.next(); fragment.addResources(baseDir, r.getDirectory(), r.getIncludes(), r.getExcludes(), true); } List excludes = new ArrayList(); excludes.addAll(fragment.getIncludedFiles()); excludes.add("target/"); excludes.add("runner/"); excludes.add("pom.xml"); // consider everything else in the bundle directory to be a resource fragment.addResources(baseDir, baseDir.getPath(), null, excludes, false); // archetype must use different id String groupId = project.getGroupId(); String artifactId = project.getArtifactId() + "-archetype"; String version = project.getVersion(); // archive customized bundle sources, POM and Bnd instructions String fragmentId = groupId + ':' + artifactId + ':' + version; fragment.createArchive(fragmentId.replace(':', '_'), newJarArchiver()); return fragmentId; }
From source file:org.ops4j.pax.construct.lifecycle.BundleCompilerMojo.java
License:Apache License
/** * Copy additional compiler settings from maven-compiler-plugin section (only handles simple configuration items) * // w w w . ja v a 2 s . c om * @param mojo compiler mojo * @param project maven project */ protected static void mergeCompilerConfiguration(AbstractCompilerMojo mojo, MavenProject project) { Plugin core = new Plugin(); core.setGroupId("org.apache.maven.plugins"); core.setArtifactId("maven-compiler-plugin"); Plugin pax = new Plugin(); pax.setGroupId("org.ops4j"); pax.setArtifactId("maven-pax-plugin"); // load pluginManagement project.getBuild().addPlugin(core); project.getBuild().addPlugin(pax); Xpp3Dom coreConfig = project.getGoalConfiguration(core.getGroupId(), core.getArtifactId(), null, null); Xpp3Dom paxConfig = project.getGoalConfiguration(pax.getGroupId(), pax.getArtifactId(), null, null); if (null != coreConfig) { ReflectMojo baseMojo = new ReflectMojo(mojo, AbstractCompilerMojo.class); Xpp3Dom[] configuration = coreConfig.getChildren(); for (int i = 0; i < configuration.length; i++) { // don't override pax settings String name = configuration[i].getName(); if ((null == paxConfig || null == paxConfig.getChild(name)) && baseMojo.hasField(name)) { // only use non-empty settings String value = configuration[i].getValue(); if (null != value) { mojo.getLog().debug("Using compiler setting: " + name + "=" + value); baseMojo.setField(name, value); } } } } }
From source file:org.ops4j.pax.construct.lifecycle.EclipseOSGiMojo.java
License:Apache License
/** * @param bundleProject bundle project//from w w w .ja v a2 s. c o m * @return recently built bundle */ private File getBundleFile(MavenProject bundleProject) { Artifact artifact = bundleProject.getArtifact(); File bundleFile = artifact.getFile(); if (null == bundleFile || !bundleFile.exists()) { // no file attached in this cycle, so check local build String name = bundleProject.getBuild().getFinalName() + ".jar"; bundleFile = new File(bundleProject.getBuild().getDirectory(), name); } if (!bundleFile.exists()) { // last chance: see if it is already has been installed locally PomUtils.getFile(artifact, artifactResolver, localRepository); bundleFile = artifact.getFile(); } return bundleFile; }
From source file:org.ops4j.pax.vault.builder.BuilderPlugin.java
License:Apache License
protected String getBundleName(MavenProject currentProject) { String finalName = currentProject.getBuild().getFinalName(); if (null != classifier && classifier.trim().length() > 0) { return finalName + '-' + classifier + ".jar"; }/*from w ww. jav a 2 s.co m*/ return finalName + ".jar"; }
From source file:org.owasp.dependencycheck.maven.BaseDependencyCheckMojo.java
License:Apache License
/** * Returns the correct output directory depending on if a site is being * executed or not./*from w w w . j a v a2s .c om*/ * * @param current the Maven project to get the output directory from * @return the directory to write the report(s) */ protected File getCorrectOutputDirectory(MavenProject current) { final Object obj = current.getContextValue(getOutputDirectoryContextKey()); if (obj != null && obj instanceof File) { return (File) obj; } File target = new File(current.getBuild().getDirectory()); if (target.getParentFile() != null && "target".equals(target.getParentFile().getName())) { target = target.getParentFile(); } return target; }
From source file:org.phpmaven.pear.impl.PearUtility.java
License:Apache License
/** * resolving the pear channels from given project. * // w ww . j a v a2s. co m * @param project * the project * @throws PhpException * thrown on discover errors */ private void resolveChannels(final MavenProject project) throws PhpException { final Build build = project.getBuild(); if (build != null) { for (final Plugin plugin : build.getPlugins()) { if ("org.phpmaven".equals(plugin.getGroupId()) && "maven-php-plugin".equals(plugin.getArtifactId())) { final Xpp3Dom dom = (Xpp3Dom) plugin.getConfiguration(); final Xpp3Dom pearChannelsDom = dom.getChild("pearChannels"); if (pearChannelsDom != null) { for (final Xpp3Dom child : pearChannelsDom.getChildren()) { this.channelAdd(child.getValue(), null, "local-pear-channel"); } } } } } }