List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:org.openspaces.maven.plugin.Utils.java
License:Apache License
/** * Resolves the processing unit's dependencies classpath. * /*w w w . jav a 2 s .c om*/ * @param project the processing unit project * @param includeScopes the scopes of the dependencies to include * @param includeProjects whether to include project's output directories * @param reactorProjects the reactor projects * @param dependencyTreeBuilder the dependency tree builder * @param metadataSource the metadata source * @param artifactCollector the artifact collector * @param artifactResolver the artifact resolver * @param artifactFactory the artifact factory * @param localRepository the local repository * @param remoteRepositories the remote repositories * @return a list containing all dependency URLs. * @throws Exception */ static List resolveExecutionClasspath(MavenProject project, String[] includeScopes, boolean includeProjects, List reactorProjects, DependencyTreeBuilder dependencyTreeBuilder, ArtifactMetadataSource metadataSource, ArtifactCollector artifactCollector, ArtifactResolver artifactResolver, ArtifactFactory artifactFactory, ArtifactRepository localRepository, List remoteRepositories) throws Exception { Set scopes = new HashSet(includeScopes.length); Collections.addAll(scopes, includeScopes); // resolve all dependency of the specifies scope // scope 'test' is the widest scope available. ArtifactFilter artifactFilter = new ScopeArtifactFilter("test"); DependencyNode root = dependencyTreeBuilder.buildDependencyTree(project, localRepository, artifactFactory, metadataSource, artifactFilter, artifactCollector); // resolve all dependency files. if the dependency is a referenced project and not // a file in the repository add its output directory to the classpath. Iterator i = root.preorderIterator(); Set artifacts = new HashSet(); while (i.hasNext()) { DependencyNode node = (DependencyNode) i.next(); // the dependency may not be included due to duplication // dependency cycles and version conflict. // don't include those in the classpath. if (node.getState() != DependencyNode.INCLUDED) { PluginLog.getLog().debug("Not including dependency: " + node); continue; } Artifact artifact = node.getArtifact(); if (artifact.getFile() == null) { try { // if file is not found an exception is thrown artifactResolver.resolve(artifact, remoteRepositories, localRepository); } catch (Exception e) { if (includeProjects) { // try to see if the dependency is a referenced project Iterator projectsIterator = reactorProjects.iterator(); while (projectsIterator.hasNext()) { MavenProject proj = (MavenProject) projectsIterator.next(); if (proj.getArtifactId().equals(artifact.getArtifactId())) { artifact.setFile(new File(proj.getBuild().getOutputDirectory())); break; } } } } } if (!scopes.contains(artifact.getScope())) { if (artifact.getScope() != null) { continue; } // if it's not the same project don't add if (!includeProjects || !project.getArtifactId().equals(artifact.getArtifactId())) { continue; } } artifacts.add(artifact); } return getArtifactURLs(artifacts); }
From source file:org.ops4j.pax.construct.clone.CloneMojo.java
License:Apache License
/** * Analyze major project and build the right pax-create-project call * /*from w w w . ja v a 2s .c o m*/ * @param script build script * @param project major Maven project */ private void handleMajorProject(PaxScript script, MavenProject project) { if (unify && !project.isExecutionRoot()) { // exclude the local poms settings from the unified project m_handledDirs.add(new File(project.getBasedir(), "poms")); return; } PaxCommandBuilder command = script.call(PaxScript.CREATE_PROJECT); command.option('g', project.getGroupId()); command.option('a', project.getArtifactId()); command.option('v', project.getVersion()); setTargetDirectory(command, project.getBasedir().getParentFile()); registerProject(project); m_majorProjectMap.put(project, command); }
From source file:org.ops4j.pax.construct.clone.CloneMojo.java
License:Apache License
/** * Analyze bundle project and determine if any pax-create-bundle or pax-wrap-jar calls are needed * // w w w .j a v a 2 s .c o m * @param script build script * @param project Maven bundle project * @throws MojoExecutionException */ private void handleBundleProject(PaxScript script, MavenProject project) throws MojoExecutionException { PaxCommandBuilder command; String bundleName; String namespace = findBundleNamespace(project); if (null != namespace) { bundleName = project.getArtifactId(); command = script.call(PaxScript.CREATE_BUNDLE); command.option('p', namespace); if (!bundleName.equals(namespace)) { command.option('n', bundleName); } command.option('v', project.getVersion()); command.maven().flag("noDeps"); } else { Dependency wrappee = findWrappee(project); if (wrappee != null) { command = script.call(PaxScript.WRAP_JAR); command.option('g', wrappee.getGroupId()); command.option('a', wrappee.getArtifactId()); command.option('v', wrappee.getVersion()); if (repair) { // this is expected to be the generated bundle name bundleName = PomUtils.getCompoundId(wrappee.getGroupId(), wrappee.getArtifactId()); // detect if we need to add the version back later on... if (project.getArtifactId().endsWith(wrappee.getVersion())) { command.maven().flag("addVersion"); } } else { bundleName = project.getArtifactId(); // need to retain the old name and version settings command.maven().option("bundleName", bundleName); command.maven().option("bundleVersion", project.getVersion()); } } else { getLog().warn("Unable to clone bundle project " + project.getId()); return; } } Pom customizedPom = null; if (repair) { // fix references to local bundles by re-importing customizedPom = repairBundleImports(script, project); } else { // need to keep old groupId intact (name is already retained) command.maven().option("bundleGroupId", project.getGroupId()); } addFragmentToCommand(command, createBundleArchetype(project, namespace, customizedPom)); setTargetDirectory(command, project.getBasedir().getParentFile()); registerProject(project); registerBundleName(project, bundleName); }
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 * // w w w. ja v a 2 s . c om * @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
/** * Create a new archetype for a bundle project, with potentially customized POM and Bnd settings * //from www. ja va 2 s. 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.clone.CloneMojo.java
License:Apache License
/** * Archive all the selected resources under a single Maven archetype * /*www. j av a 2s .c o m*/ * @param project containing Maven project * @return clause identifying the archetype fragment * @throws MojoExecutionException */ private String createProjectArchetype(MavenProject project) throws MojoExecutionException { File baseDir = project.getBasedir(); getLog().info("Cloning primary project " + project.getArtifactId()); ArchetypeFragment fragment = new ArchetypeFragment(getFragmentDir(), null, unify); fragment.addPom(baseDir, null); List excludes = new ArrayList(); excludes.addAll(getExcludedPaths(project)); excludes.add("**/target/"); excludes.add("runner/"); excludes.add("pom.xml"); // consider everything else that's not been handled 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 all the customized non-bundle POMs and projects String fragmentId = groupId + ':' + artifactId + ':' + version; fragment.createArchive(fragmentId.replace(':', '_'), newJarArchiver()); return fragmentId; }
From source file:org.ops4j.pax.construct.clone.CloneMojo.java
License:Apache License
/** * @param project Maven bundle project/*w w w . ja va 2s . c o m*/ * @param bundleName expected symbolic name of the bundle (null if imported) */ private void registerBundleName(MavenProject project, String bundleName) { m_bundleNameMap.put(project.getGroupId() + ':' + project.getArtifactId(), bundleName); }
From source file:org.ops4j.pax.construct.lifecycle.EclipseOSGiMojo.java
License:Apache License
private boolean isReactorDependency(IdeDependency dependency) { // check current reactor... if (reactorProjects != null) { for (Iterator i = reactorProjects.iterator(); i.hasNext();) { MavenProject reactorProject = (MavenProject) i.next(); if (reactorProject.getGroupId().equals(dependency.getGroupId()) && reactorProject.getArtifactId().equals(dependency.getArtifactId())) { return true; }/*w w w. ja v a2s . co m*/ } } return false; }
From source file:org.ops4j.pax.construct.lifecycle.EclipseOSGiMojo.java
License:Apache License
/** * Provide better naming for Pax-Construct generated OSGi bundles * //from ww w. j av a2s . c om * @param project current Maven project * @param addVersion when true, add the project version to the name * @return an Eclipse friendly name for the bundle */ private static String getEclipseProjectName(MavenProject project, boolean addVersion) { String projectName = project.getProperties().getProperty("bundle.symbolicName"); if (null == projectName) { // fall back to standard "groupId.artifactId" but try to eliminate duplicate segments projectName = PomUtils.getCompoundId(project.getGroupId(), project.getArtifactId()); } if (addVersion) { // check for wrapper version, which reflects the version of the wrapped contents String projectVersion = project.getProperties().getProperty("wrapped.version"); if (null == projectVersion) { projectVersion = project.getVersion(); } return projectName + " [" + projectVersion + ']'; } return projectName; }
From source file:org.ops4j.pax.construct.lifecycle.ProvisionMojo.java
License:Apache License
/** * Does this look like a provisioning POM? ie. artifactId of 'provision', packaging type 'pom', with dependencies * /* ww w . j a v a 2 s .co m*/ * @param project a Maven project * @return true if this looks like a provisioning POM, otherwise false */ public static boolean isProvisioningPom(MavenProject project) { // ignore POMs which don't have provision as their artifactId if (!"provision".equals(project.getArtifactId())) { return false; } // ignore POMs that produce actual artifacts if (!"pom".equals(project.getPackaging())) { return false; } // ignore POMs with no dependencies at all List dependencies = project.getDependencies(); if (dependencies == null || dependencies.size() == 0) { return false; } return true; }