List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:org.piraso.maven.packaging.ClassesPackagingTask.java
License:Apache License
protected void generateJarArchive(WarPackagingContext context) throws MojoExecutionException { MavenProject project = context.getProject(); ArtifactFactory factory = context.getArtifactFactory(); Artifact artifact = factory.createBuildArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "jar"); String archiveName = null;/*from w w w . jav a2 s. c o m*/ try { archiveName = getArtifactFinalName(context, artifact); } catch (InterpolationException e) { throw new MojoExecutionException("Could not get the final name of the artifact [" + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + "]", e); } final String targetFilename = LIB_PATH + archiveName; if (context.getWebappStructure().registerFile(currentProjectOverlay.getId(), targetFilename)) { final File libDirectory = new File(context.getWebappDirectory(), LIB_PATH); final File jarFile = new File(libDirectory, archiveName); final ClassesPackager packager = new ClassesPackager(); packager.packageClasses(context.getClassesDirectory(), jarFile, context.getJarArchiver(), context.getSession(), project, context.getArchive()); } else { context.getLog().warn( "Could not generate archive classes file [" + targetFilename + "] has already been copied."); } }
From source file:org.pitest.maven.MojoToReportOptionsConverter.java
License:Apache License
private void useHistoryFileInTempDir(final ReportOptions data) { String tempDir = System.getProperty("java.io.tmpdir"); MavenProject project = this.mojo.project; String name = project.getGroupId() + "." + project.getArtifactId() + "." + project.getVersion() + "_pitest_history.bin"; File historyFile = new File(tempDir, name); log.info("Will read and write history at " + historyFile); if (this.mojo.getHistoryInputFile() == null) { data.setHistoryInputLocation(historyFile); }// w w w. j ava2 s .c o m if (this.mojo.getHistoryOutputFile() == null) { data.setHistoryOutputLocation(historyFile); } }
From source file:org.renjin.maven.MavenBuildContext.java
License:Open Source License
public MavenBuildContext(MavenProject project, Collection<Artifact> pluginDependencies, Log log) throws MojoExecutionException { this.project = project; this.logger = new MavenBuildLogger(log); this.buildDir = new File(project.getBuild().getDirectory()); this.outputDir = new File(project.getBuild().getOutputDirectory()); this.packageOuputDir = new File(project.getBuild().getOutputDirectory() + File.separator + project.getGroupId().replace('.', File.separatorChar) + File.separator + project.getArtifactId()); this.pluginDependencies = pluginDependencies; this.homeDir = new File(buildDir, "gnur"); this.pluginFile = new File(buildDir, "bridge.so"); this.unpackedIncludeDir = new File(buildDir, "include"); this.classpath = buildClassPath(); ensureDirExists(outputDir);/*from w w w .j a va2s . co m*/ ensureDirExists(packageOuputDir); ensureDirExists(getGnuRHomeDir()); ensureDirExists(unpackedIncludeDir); classloader = new URLClassLoader(classpath, getClass().getClassLoader()); packageLoader = new ClasspathPackageLoader(classloader); }
From source file:org.revapi.maven.Analyzer.java
License:Apache License
public static String getProjectArtifactCoordinates(MavenProject project, RepositorySystemSession session, String versionOverride) { org.apache.maven.artifact.Artifact artifact = project.getArtifact(); String extension = session.getArtifactTypeRegistry().get(artifact.getType()).getExtension(); String version = versionOverride == null ? project.getVersion() : versionOverride; if (artifact.hasClassifier()) { return project.getGroupId() + ":" + project.getArtifactId() + ":" + extension + ":" + artifact.getClassifier() + ":" + version; } else {//w w w. ja va 2 s . c o m return project.getGroupId() + ":" + project.getArtifactId() + ":" + extension + ":" + version; } }
From source file:org.revapi.maven.UpdateReleasePropertiesMojo.java
License:Apache License
@Override void updateProjectVersion(MavenProject project, Version version) throws MojoExecutionException { File rpf = getReleasePropertiesFile(); Properties ps = readProperties(rpf); String relProp;//from ww w.j av a 2s.c o m String devProp; if (isSingleVersionForAllModules()) { relProp = "project.rel." + project.getGroupId() + ":" + project.getArtifactId(); devProp = "project.dev." + project.getGroupId() + ":" + project.getArtifactId(); } else { relProp = "releaseVersion"; devProp = "developmentVersion"; } ps.setProperty(relProp, version.toString()); Version dev = version.clone(); dev.setPatch(dev.getPatch() + 1); dev.setSuffix(releaseVersionSuffix == null ? "SNAPSHOT" : releaseVersionSuffix + "-SNAPSHOT"); ps.setProperty(devProp, dev.toString()); try (FileOutputStream out = new FileOutputStream(rpf)) { ps.store(out, null); } catch (IOException e) { throw new MojoExecutionException("Failed to write to the release.properties file.", e); } }
From source file:org.sakaiproject.maven.plugin.component.AbstractComponentMojo.java
License:Apache License
/** * Builds the webapp for the specified project. <p/> Classes, libraries and * tld files are copied to the <tt>webappDirectory</tt> during this phase. * /*from w w w. j a va 2s . com*/ * @param project * the maven project * @param webappDirectory * @throws java.io.IOException * if an error occured while building the webapp */ public void buildWebapp(MavenProject project, File webappDirectory) throws MojoExecutionException, IOException, MojoFailureException { getLog().info("Assembling webapp " + project.getArtifactId() + " in " + webappDirectory); File webinfDir = new File(webappDirectory, WEB_INF); webinfDir.mkdirs(); File metainfDir = new File(webappDirectory, META_INF); metainfDir.mkdirs(); List webResources = this.webResources != null ? Arrays.asList(this.webResources) : null; if (webResources != null && webResources.size() > 0) { Map filterProperties = getBuildFilterProperties(); for (Iterator it = webResources.iterator(); it.hasNext();) { Resource resource = (Resource) it.next(); copyResources(resource, webappDirectory, filterProperties); } } copyResources(warSourceDirectory, webappDirectory); if (webXml != null && StringUtils.isNotEmpty(webXml.getName())) { if (!webXml.exists()) { throw new MojoFailureException("The specified web.xml file '" + webXml + "' does not exist"); } // rename to web.xml copyFileIfModified(webXml, new File(webinfDir, "/web.xml")); } checkComponentWebXmlExists(new File(webinfDir, "/web.xml")); if (containerConfigXML != null && StringUtils.isNotEmpty(containerConfigXML.getName())) { metainfDir = new File(webappDirectory, META_INF); String xmlFileName = containerConfigXML.getName(); copyFileIfModified(containerConfigXML, new File(metainfDir, xmlFileName)); } File libDirectory = new File(webinfDir, "lib"); File tldDirectory = new File(webinfDir, "tld"); File webappClassesDirectory = new File(webappDirectory, WEB_INF + "/classes"); if (classesDirectory.exists() && !classesDirectory.equals(webappClassesDirectory)) { if (archiveClasses) { createJarArchive(libDirectory); } else { copyDirectoryStructureIfModified(classesDirectory, webappClassesDirectory); } } Set artifacts = project.getArtifacts(); List duplicates = findDuplicates(artifacts); List dependentWarDirectories = new ArrayList(); for (Iterator iter = artifacts.iterator(); iter.hasNext();) { Artifact artifact = (Artifact) iter.next(); String targetFileName = getDefaultFinalName(artifact); getLog().debug("Processing: " + targetFileName); if (duplicates.contains(targetFileName)) { getLog().debug("Duplicate found: " + targetFileName); targetFileName = artifact.getGroupId() + "-" + targetFileName; getLog().debug("Renamed to: " + targetFileName); } // TODO: utilise appropriate methods from project builder ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME); if (!artifact.isOptional() && filter.include(artifact)) { String type = artifact.getType(); if ("tld".equals(type)) { copyFileIfModified(artifact.getFile(), new File(tldDirectory, targetFileName)); } else { if ("jar".equals(type) || "ejb".equals(type) || "ejb-client".equals(type)) { copyFileIfModified(artifact.getFile(), new File(libDirectory, targetFileName)); } else { if ("par".equals(type)) { targetFileName = targetFileName.substring(0, targetFileName.lastIndexOf('.')) + ".jar"; getLog().debug("Copying " + artifact.getFile() + " to " + new File(libDirectory, targetFileName)); copyFileIfModified(artifact.getFile(), new File(libDirectory, targetFileName)); } else { if ("war".equals(type)) { dependentWarDirectories.add(unpackWarToTempDirectory(artifact)); } else { getLog().debug("Skipping artifact of type " + type + " for WEB-INF/lib"); } } } } } } if (dependentWarDirectories.size() > 0) { getLog().info("Overlaying " + dependentWarDirectories.size() + " war(s)."); // overlay dependent wars for (Iterator iter = dependentWarDirectories.iterator(); iter.hasNext();) { copyDependentWarContents((File) iter.next(), webappDirectory); } } }
From source file:org.seasar.kvasir.plust.KvasirPlugin.java
@SuppressWarnings("unchecked") public void resolveClasspathEntries(Set<IClasspathEntry> libraryEntries, Set<String> moduleArtifacts, IFile pomFile, boolean recursive, boolean downloadSources, IProgressMonitor monitor) { monitor.beginTask("Reading " + pomFile.getLocation(), IProgressMonitor.UNKNOWN); try {/*from ww w . j av a2 s. co m*/ if (monitor.isCanceled()) { throw new OperationCanceledException(); } final MavenProject mavenProject = getMavenProject(pomFile, new SubProgressMonitor(monitor, 1)); if (mavenProject == null) { return; } deleteMarkers(pomFile); // TODO use version? moduleArtifacts.add(mavenProject.getGroupId() + ":" + mavenProject.getArtifactId()); Set artifacts = mavenProject.getArtifacts(); for (Iterator it = artifacts.iterator(); it.hasNext();) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } final Artifact a = (Artifact) it.next(); monitor.subTask("Processing " + a.getId()); if (!"jar".equals(a.getType())) { continue; } // TODO use version? if (!moduleArtifacts.contains(a.getGroupId() + ":" + a.getArtifactId()) && // TODO verify if there is an Eclipse API to check that archive is acceptable ("jar".equals(a.getType()) || "zip".equals(a.getType()))) { String artifactLocation = a.getFile().getAbsolutePath(); // TODO add a lookup through workspace projects Path srcPath = null; File srcFile = new File( artifactLocation.substring(0, artifactLocation.length() - 4) + "-sources.jar"); if (srcFile.exists()) { // XXX ugly hack to do not download any sources srcPath = new Path(srcFile.getAbsolutePath()); } else if (downloadSources && !isSourceChecked(a)) { srcPath = (Path) executeInEmbedder(new MavenEmbedderCallback() { public Object run(MavenEmbedder mavenEmbedder, IProgressMonitor monitor) { monitor.beginTask("Resolve sources " + a.getId(), IProgressMonitor.UNKNOWN); try { Artifact src = mavenEmbedder.createArtifactWithClassifier(a.getGroupId(), a.getArtifactId(), a.getVersion(), "java-source", "sources"); if (src != null) { mavenEmbedder.resolve(src, mavenProject.getRemoteArtifactRepositories(), mavenEmbedder.getLocalRepository()); return new Path(src.getFile().getAbsolutePath()); } } catch (AbstractArtifactResolutionException ex) { String name = ex.getGroupId() + ":" + ex.getArtifactId() + "-" + ex.getVersion() + "." + ex.getType(); getConsole().logMessage(ex.getOriginalMessage() + " " + name); } finally { monitor.done(); } return null; } }, new SubProgressMonitor(monitor, 1)); setSourceChecked(a); } libraryEntries.add(JavaCore.newLibraryEntry(new Path(artifactLocation), srcPath, null)); } } if (recursive) { IContainer parent = pomFile.getParent(); List modules = mavenProject.getModules(); for (Iterator it = modules.iterator(); it.hasNext() && !monitor.isCanceled();) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } String module = (String) it.next(); IResource memberPom = parent.findMember(module + "/" + IKvasirProject.POM_FILE_NAME); if (memberPom != null && memberPom.getType() == IResource.FILE) { resolveClasspathEntries(libraryEntries, moduleArtifacts, (IFile) memberPom, true, downloadSources, new SubProgressMonitor(monitor, 1)); } } } } catch (OperationCanceledException ex) { throw ex; } catch (InvalidArtifactRTException ex) { addMarker(pomFile, ex.getBaseMessage(), 1, IMarker.SEVERITY_ERROR); } catch (Throwable ex) { addMarker(pomFile, ex.toString(), 1, IMarker.SEVERITY_ERROR); } finally { monitor.done(); } }
From source file:org.seasar.kvasir.plust.KvasirPlugin.java
void buildTestEnvironment(IProject project, String groupId, String artifactId, String version, IProgressMonitor monitor) throws CoreException { monitor.beginTask("Preparing test environment", 80); try {/*from w w w. j a va2 s. c o m*/ MavenProject mavenProject = plugin.getMavenProject(project.getFile(IKvasirProject.POM_FILE_NAME), monitor); monitor.worked(10); Artifact distArchive = (Artifact) plugin.executeInEmbedder( new PrepareTestEnvironmentTask(mavenProject, groupId, artifactId, version), monitor); monitor.worked(10); if (distArchive == null) { plugin.getConsole().logError("Can't resolve archive: " + distArchive); throw new CoreException(KvasirPlugin.constructStatus("Can't resolve archive: " + distArchive)); } ZipFile zipFile = null; File file = null; try { zipFile = new ZipFile(distArchive.getFile()); ZipEntry entry = zipFile .getEntry(distArchive.getArtifactId() + "-" + distArchive.getVersion() + "/kvasir.war"); if (entry == null) { throw new CoreException(KvasirPlugin.constructStatus( "Can't find kvasir.war in " + distArchive.getFile().getAbsolutePath())); } file = File.createTempFile("kvasir", ".tmp"); file.deleteOnExit(); copyZipEntryAsFile(zipFile, entry, file); IFolder webapp = project.getFolder(IKvasirProject.WEBAPP_PATH); unzip(file, webapp, true, monitor); monitor.worked(50); webapp.setDerived(true); monitor.worked(10); } catch (ZipException ex) { throw new CoreException(KvasirPlugin.constructStatus(ex)); } catch (IOException ex) { throw new CoreException(KvasirPlugin.constructStatus(ex)); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException ex) { plugin.log(ex); } zipFile = null; } if (file != null) { file.delete(); } } // ??distribution???????? // ?????????? String targetPluginDirectoryName = mavenProject.getArtifactId() + "-" + mavenProject.getArtifact().getVersion(); IFolder targetPluginDirectory = project .getFolder(IKvasirProject.TEST_PLUGINS_PATH + "/" + targetPluginDirectoryName); if (targetPluginDirectory.exists()) { targetPluginDirectory.delete(false, new SubProgressMonitor(monitor, 1)); } } finally { monitor.done(); } }
From source file:org.semver.enforcer.AbstractEnforcerRule.java
License:Apache License
@Override public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException { final MavenProject project = getMavenProject(helper); if (shouldSkipRuleExecution(project)) { helper.getLog().debug("Skipping non " + AbstractEnforcerRule.JAR_ARTIFACT_TYPE + " or " + BUNDLE_ARTIFACT_TYPE + " artifact."); return;/*from w w w . j a va 2 s .com*/ } final Artifact previousArtifact; final Artifact currentArtifact = validateArtifact(project.getArtifact()); final Version current = Version.parse(currentArtifact.getVersion()); try { final ArtifactRepository localRepository = (ArtifactRepository) helper.evaluate("${localRepository}"); final String version; if (this.previousVersion != null) { version = this.previousVersion; helper.getLog().info("Version specified as <" + version + ">"); } else { final ArtifactMetadataSource artifactMetadataSource = (ArtifactMetadataSource) helper .getComponent(ArtifactMetadataSource.class); final List<ArtifactVersion> availableVersions = getAvailableReleasedVersions(artifactMetadataSource, project, localRepository); final List<ArtifactVersion> availablePreviousVersions = filterNonPreviousVersions(availableVersions, current); if (availablePreviousVersions.isEmpty()) { helper.getLog() .warn("No previously released version. Backward compatibility check not performed."); return; } version = availablePreviousVersions.iterator().next().toString(); helper.getLog().info("Version deduced as <" + version + "> (among all availables: " + availablePreviousVersions + ")"); } final ArtifactFactory artifactFactory = (ArtifactFactory) helper.getComponent(ArtifactFactory.class); previousArtifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), version, null, project.getArtifact().getType()); final ArtifactResolver resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class); resolver.resolve(previousArtifact, project.getRemoteArtifactRepositories(), localRepository); validateArtifact(previousArtifact); } catch (Exception e) { helper.getLog().warn("Exception while accessing artifacts; skipping check.", e); return; } final Version previous = Version.parse(previousArtifact.getVersion()); final File previousJar = previousArtifact.getFile(); final File currentJar = currentArtifact.getFile(); compareJars(helper, previous, previousJar, current, currentJar); }
From source file:org.smallmind.license.SourceNoticeMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { MavenProject rootProject = project; Stencil[] mergedStencils;//from ww w .jav a 2 s . c o m char[] buffer = new char[8192]; while ((root == null) ? !(rootProject.getParent() == null) : !(root.getGroupId().equals(rootProject.getGroupId()) && root.getArtifactId().equals(rootProject.getArtifactId()))) { rootProject = rootProject.getParent(); } mergedStencils = new Stencil[(stencils != null) ? stencils.length + DEFAULT_STENCILS.length : DEFAULT_STENCILS.length]; System.arraycopy(DEFAULT_STENCILS, 0, mergedStencils, 0, DEFAULT_STENCILS.length); if (stencils != null) { System.arraycopy(stencils, 0, mergedStencils, DEFAULT_STENCILS.length, stencils.length); } for (Rule rule : rules) { FileFilter[] fileFilters; String[] noticeArray; boolean noticed; boolean stenciled; if (verbose) { getLog().info(String.format("Processing rule(%s)...", rule.getId())); } noticed = true; if (rule.getNotice() == null) { if (!allowNoticeRemoval) { throw new MojoExecutionException("No notice was provided for rule(" + rule.getId() + "), but notice removal has not been enabled(allowNoticeRemoval = false)"); } noticeArray = null; } else { File noticeFile; noticeFile = new File(rule.getNotice()); if ((noticeArray = getFileAsLineArray(noticeFile.isAbsolute() ? noticeFile.getAbsolutePath() : rootProject.getBasedir() + System.getProperty("file.separator") + noticeFile.getPath())) == null) { noticed = false; } } if (!noticed) { getLog().warn(String.format("Unable to acquire the notice file(%s), skipping notice updating...", rule.getNotice())); } else { if ((rule.getFileTypes() == null) || (rule.getFileTypes().length == 0)) { throw new MojoExecutionException("No file types were specified for rule(" + rule.getId() + ")"); } fileFilters = new FileFilter[rule.getFileTypes().length]; for (int count = 0; count < fileFilters.length; count++) { fileFilters[count] = new FileTypeFilenameFilter(rule.getFileTypes()[count]); } stenciled = false; for (Stencil stencil : mergedStencils) { if (stencil.getId().equals(rule.getStencilId())) { stenciled = true; updateNotice(stencil, noticeArray, buffer, project.getBuild().getSourceDirectory(), fileFilters); updateNotice(stencil, noticeArray, buffer, project.getBuild().getScriptSourceDirectory(), fileFilters); if (includeResources) { for (Resource resource : project.getBuild().getResources()) { updateNotice(stencil, noticeArray, buffer, resource.getDirectory(), fileFilters); } } if (includeTests) { updateNotice(stencil, noticeArray, buffer, project.getBuild().getTestSourceDirectory(), fileFilters); if (includeResources) { for (Resource testResource : project.getBuild().getTestResources()) { updateNotice(stencil, noticeArray, buffer, testResource.getDirectory(), fileFilters); } } } break; } } if (!stenciled) { throw new MojoExecutionException( "No stencil found with id(" + rule.getStencilId() + ") for rule(" + rule.getId() + ")"); } } } }