List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:org.codehaus.mojo.nbm.CreateUpdateSiteMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { Project antProject = registerNbmAntTasks(); File nbmBuildDirFile = new File(outputDirectory, "netbeans_site"); if (!nbmBuildDirFile.exists()) { nbmBuildDirFile.mkdirs();//w w w. j a v a 2s . co m } boolean isRepository = false; if ("auto".equals(distBase)) { distBase = null; } ArtifactRepository distRepository = getDeploymentRepository(distBase, container, getLog()); String oldDistBase = null; if (distRepository != null) { isRepository = true; } else { if (distBase != null && !distBase.contains("::")) { oldDistBase = distBase; } } if ("nbm-application".equals(project.getPackaging())) { @SuppressWarnings("unchecked") Set<Artifact> artifacts = project.getArtifacts(); for (Artifact art : artifacts) { if (!matchesIncludes(art)) { continue; } ArtifactResult res = turnJarToNbmFile(art, artifactFactory, artifactResolver, project, localRepository); if (res.hasConvertedArtifact()) { art = res.getConvertedArtifact(); } if (art.getType().equals("nbm-file")) { Copy copyTask = (Copy) antProject.createTask("copy"); copyTask.setOverwrite(true); copyTask.setFile(art.getFile()); if (!isRepository) { copyTask.setFlatten(true); copyTask.setTodir(nbmBuildDirFile); } else { String path = distRepository.pathOf(art); File f = new File(nbmBuildDirFile, path.replace('/', File.separatorChar)); copyTask.setTofile(f); } try { copyTask.execute(); } catch (BuildException ex) { throw new MojoExecutionException("Cannot merge nbm files into autoupdate site", ex); } } if (res.isOSGiBundle()) { // TODO check for bundles } } getLog().info("Created NetBeans module cluster(s) at " + nbmBuildDirFile.getAbsoluteFile()); } else if (reactorProjects != null && reactorProjects.size() > 0) { Iterator it = reactorProjects.iterator(); while (it.hasNext()) { MavenProject proj = (MavenProject) it.next(); //TODO how to figure where the the buildDir/nbm directory is File moduleDir = proj.getFile().getParentFile(); if (moduleDir != null && moduleDir.exists()) { Copy copyTask = (Copy) antProject.createTask("copy"); if (!isRepository) { FileSet fs = new FileSet(); File projOutputDirectory = new File(proj.getBuild().getDirectory()); fs.setDir(projOutputDirectory); fs.createInclude().setName("*.nbm"); copyTask.addFileset(fs); copyTask.setOverwrite(true); copyTask.setFlatten(true); copyTask.setTodir(nbmBuildDirFile); } else { File target = new File(proj.getBuild().getDirectory()); boolean has = false; File[] fls = target.listFiles(); if (fls != null) { for (File fl : fls) { if (fl.getName().endsWith(".nbm")) { copyTask.setFile(fl); has = true; break; } } } if (!has) { continue; } Artifact art = artifactFactory.createArtifact(proj.getGroupId(), proj.getArtifactId(), proj.getVersion(), null, "nbm-file"); String path = distRepository.pathOf(art); File f = new File(nbmBuildDirFile, path.replace('/', File.separatorChar)); copyTask.setTofile(f); } try { copyTask.execute(); } catch (BuildException ex) { throw new MojoExecutionException("Cannot merge nbm files into autoupdate site", ex); } } } } else { throw new MojoExecutionException( "This goal only makes sense on reactor projects or project with 'nbm-application' packaging."); } MakeUpdateDesc descTask = (MakeUpdateDesc) antProject.createTask("updatedist"); File xmlFile = new File(nbmBuildDirFile, fileName); descTask.setDesc(xmlFile); if (oldDistBase != null) { descTask.setDistBase(oldDistBase); } if (distRepository != null) { descTask.setDistBase(distRepository.getUrl()); } FileSet fs = new FileSet(); fs.setDir(nbmBuildDirFile); fs.createInclude().setName("**/*.nbm"); descTask.addFileset(fs); try { descTask.execute(); } catch (BuildException ex) { throw new MojoExecutionException("Cannot create autoupdate site xml file", ex); } getLog().info("Generated autoupdate site content at " + nbmBuildDirFile.getAbsolutePath()); try { GZipArchiver gz = new GZipArchiver(); gz.addFile(xmlFile, fileName); File gzipped = new File(nbmBuildDirFile, fileName + ".gz"); gz.setDestFile(gzipped); gz.createArchive(); if ("nbm-application".equals(project.getPackaging())) { projectHelper.attachArtifact(project, "xml.gz", "updatesite", gzipped); } } catch (Exception ex) { throw new MojoExecutionException("Cannot create gzipped version of the update site xml file.", ex); } }
From source file:org.codehaus.mojo.pom.DependencyInfo.java
License:Apache License
/** * The constructor from a {@link MavenProject}. *//*ww w . j av a2 s . c o m*/ public DependencyInfo(MavenProject project) { this(project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging(), null, null); }
From source file:org.codehaus.mojo.pom.DependencyInfo.java
License:Apache License
public DependencyInfo getDiff(MavenProject project) { return getDiff(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, null, null); }
From source file:org.codehaus.mojo.pom.DependencyPatternMatcher.java
License:Apache License
/** * @param project/*from w w w. j ava 2s . co m*/ */ public DependencyPatternMatcher(MavenProject project) { this(project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging(), null, null); }
From source file:org.codehaus.mojo.pom.ProjectId.java
License:Apache License
/** * @param project */ public ProjectId(MavenProject project) { this(project.getGroupId(), project.getArtifactId()); }
From source file:org.codehaus.mojo.pom.ProjectId.java
License:Apache License
/** * @see #equals(Object)/*from w w w. j a v a 2s .c o m*/ */ public final boolean isMatching(MavenProject dependency) { return isMatching(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getPackaging(), null, null); }
From source file:org.codehaus.mojo.runtime.builder.MavenJarRuntimeBuilder.java
License:Open Source License
public void build(Runtime runtime, MavenProject project, File runtimeFile, File outputDirectory) throws MavenRuntimeBuilderException { try {/* ww w .j av a 2 s. com*/ // prepare output directories initializeOutputDirectories(runtime, outputDirectory); // add needed dependencies to the runtime object prepareRuntimeDependencies(runtime, project); prepareRuntimeClasses(); prepareRuntimeExecutionDependencies(project); // we need all the compiled classes into a jar of their own JarMaker projectJar = new JarMaker(runtimeLibraryDirectory, project.getArtifactId() + "-" + project.getVersion() + "-runtime.jar"); projectJar.addDirectory("**/**", "**/package.html,**/.svn/**", "", new File(project.getBuild().getDirectory() + File.separator + "classes")); projectJar.create(); // make a dependency reference for this newly created jar runtime.getJar().addDependency( project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + "-runtime"); // place the finalized runtime descriptor RuntimeXpp3Writer runtimeWriter = new RuntimeXpp3Writer(); FileWriter fw = new FileWriter(new File(runtimeMetaDirectory, "jar.runtime")); runtimeWriter.write(fw, runtime); fw.close(); // finally generate the end game jar JarMaker runtimeJar = new JarMaker(outputDirectory, project.getArtifactId() + "-runtime-" + project.getVersion() + ".jar"); runtimeJar.addDirectory("**/**", "**/package.html,**/.svn/**", "", runtimeOutputDirectory); runtimeJar.addManifestEntry("Main-Class", "org.codehaus.mojo.runtime.execute.RuntimeExecutor"); runtimeJar.create(); } catch (IOException ex) { throw new MavenRuntimeBuilderException("Exception while building the runtime", ex); } }
From source file:org.codehaus.mojo.sysdeo.ide.AbstractIdeSupportMojo.java
License:Apache License
/** * Utility method that locates a project producing the given artifact. * * @param artifact the artifact a project should produce. * @return <code>true</code> if the artifact is produced by a reactor projectart. */// w ww . j av a2 s . co m private boolean isAvailableAsAReactorProject(Artifact artifact) { if (reactorProjects != null) { for (Iterator iter = reactorProjects.iterator(); iter.hasNext();) { MavenProject reactorProject = (MavenProject) iter.next(); if (reactorProject.getGroupId().equals(artifact.getGroupId()) && reactorProject.getArtifactId().equals(artifact.getArtifactId())) { if (reactorProject.getVersion().equals(artifact.getVersion())) { return true; } else { getLog().info("Artifact " + artifact.getId() + " already available as a reactor project, but with different version. Expected: " + artifact.getVersion() + ", found: " + reactorProject.getVersion()); } } } } return false; }
From source file:org.codehaus.mojo.unix.maven.plugin.MavenProjectWrapper.java
License:Open Source License
public static MavenProjectWrapper mavenProjectWrapper(final MavenProject project, MavenSession session) { SortedMap<String, String> properties = new TreeMap<String, String>(); // This is perhaps not ideal. Maven uses reflection to dynamically extract properties from the project // when interpolating each file. This uses a static list that doesn't contain the project.* properties, except // the new we hard-code support for. ///*ww w . ja v a 2 s . c o m*/ // The user can work around this like this: // <properties> // <project.build.directory>${project.build.directory}</project.build.directory> // </properties> // // If this has to change, the properties has to be a F<String, String> and interpolation tokens ("${" and "}") // has to be defined. Doable but too painful for now. properties.putAll(toMap(session.getSystemProperties())); properties.putAll(toMap(session.getUserProperties())); properties.putAll(toMap(project.getProperties())); properties.put("project.groupId", project.getGroupId()); properties.put("project.artifactId", project.getArtifactId()); properties.put("project.version", project.getVersion()); return new MavenProjectWrapper(project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getArtifact(), project.getName(), project.getDescription(), project.getBasedir(), new File(project.getBuild().getDirectory()), new LocalDateTime(), project.getArtifacts(), project.getLicenses(), new ArtifactMap(project.getArtifacts()), unmodifiableSortedMap(properties)); }
From source file:org.codehaus.mojo.versions.AbstractVersionsDependencyUpdaterMojo.java
License:Apache License
/** * Compare a project to a dependency. Returns true only if the groupId and artifactId are all * equal.//from w w w . j a v a 2 s . c om * * @param project the project * @param dep the dependency * @return true if project and dep refer to the same artifact */ private boolean compare(MavenProject project, Dependency dep) { if (!StringUtils.equals(project.getGroupId(), dep.getGroupId())) { return false; } if (!StringUtils.equals(project.getArtifactId(), dep.getArtifactId())) { return false; } return true; }