List of usage examples for org.apache.maven.artifact Artifact getArtifactHandler
ArtifactHandler getArtifactHandler();
From source file:at.yawk.mdep.GenerateMojo.java
private static String getArtifactPath(Artifact artifact, String version) { StringBuilder builder = new StringBuilder().append(artifact.getGroupId().replace('.', '/')).append('/') .append(artifact.getArtifactId()).append('/').append(artifact.getBaseVersion()).append('/') .append(artifact.getArtifactId()).append('-').append(version); if (artifact.getArtifactHandler().getClassifier() != null) { builder.append('-').append(artifact.getArtifactHandler().getClassifier()); }//from w w w.j a va2 s. com String extension = artifact.getArtifactHandler().getExtension(); if (extension == null) { extension = "jar"; } return builder.append('.').append(extension).toString(); }
From source file:biz.vidal.maven.plugins.uberjar.UberjarMojo.java
License:Apache License
private File uberjarArtifactFileWithClassifier() { Artifact artifact = project.getArtifact(); String classifier2 = classifier != null ? classifier : "uberjar"; final String uberjarName = artifact.getArtifactId() + "-" + artifact.getVersion() + "-" + classifier2 + "." + artifact.getArtifactHandler().getExtension(); return new File(outputDirectory, uberjarName); }
From source file:ch.sourcepond.maven.plugin.repobuilder.TargetPathFactory.java
License:Apache License
/** * @param pArtifact/*from www. ja va 2 s . co m*/ * @return */ private String toArtifactFileName(final Artifact pArtifact) { final StringBuilder b = new StringBuilder(pArtifact.getArtifactId()).append("-") .append(pArtifact.getBaseVersion()); if (!isBlank(pArtifact.getClassifier())) { b.append("-").append(pArtifact.getClassifier()); } return b.append(".").append(pArtifact.getArtifactHandler().getExtension()).toString(); }
From source file:com.actility.maven.plugin.cocoon.DependencyUtil.java
License:Apache License
/** * Builds the file name. If removeVersion is set, then the file name must be reconstructed from the groupId (if * <b>prependGroupId</b> is true) artifactId, Classifier (if used) and Type. Otherwise, this method returns the artifact * file name.//from w w w . j a v a 2 s. c o m * * @param artifact File to be formatted. * @param removeVersion Specifies if the version should be removed from the file name. * @param prependGroupId Specifies if the groupId should be prepended to the file name. * @return Formatted file name in the format [groupId].artifactId-[version]-[classifier].[type] */ public static String getFormattedFileName(Artifact artifact, boolean removeVersion, boolean prependGroupId) { StringBuffer destFileName = new StringBuffer(); if (prependGroupId) { destFileName.append(artifact.getGroupId()).append("."); } String versionString = null; if (!removeVersion) { versionString = "-" + artifact.getVersion(); } else { versionString = ""; } String classifierString = ""; if (StringUtils.isNotEmpty(artifact.getClassifier())) { classifierString = "-" + artifact.getClassifier(); } destFileName.append(artifact.getArtifactId()).append(versionString); destFileName.append(classifierString).append("."); destFileName.append(artifact.getArtifactHandler().getExtension()); return destFileName.toString(); }
From source file:com.alibaba.citrus.maven.eclipse.base.ide.AbstractIdeSupportMojo.java
License:Apache License
/** * Resolve project dependencies. Manual resolution is needed in order to avoid resolution of multiproject artifacts * (if projects will be linked each other an installed jar is not needed) and to avoid a failure when a jar is * missing./*from w ww .jav a 2 s .c o m*/ * * @return resolved IDE dependencies, with attached jars for non-reactor dependencies * @throws MojoExecutionException if dependencies can't be resolved */ protected IdeDependency[] doDependencyResolution() throws MojoExecutionException { if (ideDeps == null) { if (resolveDependencies) { MavenProject project = getProject(); ArtifactRepository localRepo = getLocalRepository(); List deps = getProject().getDependencies(); // Collect the list of resolved IdeDependencies. List dependencies = new ArrayList(); if (deps != null) { Map managedVersions = createManagedVersionMap(getArtifactFactory(), project.getId(), project.getDependencyManagement()); ArtifactResolutionResult artifactResolutionResult = null; try { List listeners = new ArrayList(); if (logger.isDebugEnabled()) { listeners.add(new DebugResolutionListener(logger)); } listeners.add(new WarningResolutionListener(logger)); artifactResolutionResult = artifactCollector.collect(getProjectArtifacts(), project.getArtifact(), managedVersions, localRepo, project.getRemoteArtifactRepositories(), getArtifactMetadataSource(), null, listeners); } catch (ArtifactResolutionException e) { getLog().debug(e.getMessage(), e); getLog().error( Messages.getString("AbstractIdeSupportMojo.artifactresolution", new Object[] { //$NON-NLS-1$ e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() })); // if we are here artifactResolutionResult is null, create a project without dependencies but // don't fail // (this could be a reactor projects, we don't want to fail everything) // Causes MECLIPSE-185. Not sure if it should be handled this way?? return new IdeDependency[0]; } // keep track of added reactor projects in order to avoid duplicates Set emittedReactorProjectId = new HashSet(); for (Iterator i = artifactResolutionResult.getArtifactResolutionNodes().iterator(); i .hasNext();) { ResolutionNode node = (ResolutionNode) i.next(); int dependencyDepth = node.getDepth(); Artifact art = node.getArtifact(); // don't resolve jars for reactor projects if (hasToResolveJar(art)) { try { artifactResolver.resolve(art, node.getRemoteRepositories(), localRepository); } catch (ArtifactNotFoundException e) { getLog().debug(e.getMessage(), e); getLog().warn(Messages.getString("AbstractIdeSupportMojo.artifactdownload", //$NON-NLS-1$ new Object[] { e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() })); } catch (ArtifactResolutionException e) { getLog().debug(e.getMessage(), e); getLog().warn(Messages.getString("AbstractIdeSupportMojo.artifactresolution", new Object[] { //$NON-NLS-1$ e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() })); } } boolean includeArtifact = true; if (getExcludes() != null) { String artifactFullId = art.getGroupId() + ":" + art.getArtifactId(); if (getExcludes().contains(artifactFullId)) { getLog().info("excluded: " + artifactFullId); includeArtifact = false; } } if (includeArtifact && (!(getUseProjectReferences() && isAvailableAsAReactorProject(art)) || emittedReactorProjectId.add(art.getGroupId() + '-' + art.getArtifactId()))) { // the following doesn't work: art.getArtifactHandler().getPackaging() always returns "jar" // also // if the packaging specified in pom.xml is different. // osgi-bundle packaging is provided by the felix osgi plugin // eclipse-plugin packaging is provided by this eclipse plugin // String packaging = art.getArtifactHandler().getPackaging(); // boolean isOsgiBundle = "osgi-bundle".equals( packaging ) || "eclipse-plugin".equals( // packaging ); // we need to check the manifest, if "Bundle-SymbolicName" is there the artifact can be // considered // an osgi bundle boolean isOsgiBundle = false; String osgiSymbolicName = null; if (art.getFile() != null) { JarFile jarFile = null; try { jarFile = new JarFile(art.getFile(), false, ZipFile.OPEN_READ); Manifest manifest = jarFile.getManifest(); if (manifest != null) { osgiSymbolicName = manifest.getMainAttributes() .getValue(new Attributes.Name("Bundle-SymbolicName")); } } catch (IOException e) { getLog().info("Unable to read jar manifest from " + art.getFile()); } finally { if (jarFile != null) { try { jarFile.close(); } catch (IOException e) { // ignore } } } } isOsgiBundle = osgiSymbolicName != null; IdeDependency dep = new IdeDependency(art.getGroupId(), art.getArtifactId(), art.getVersion(), art.getClassifier(), useProjectReference(art), Artifact.SCOPE_TEST.equals(art.getScope()), Artifact.SCOPE_SYSTEM.equals(art.getScope()), Artifact.SCOPE_PROVIDED.equals(art.getScope()), art.getArtifactHandler().isAddedToClasspath(), art.getFile(), art.getType(), isOsgiBundle, osgiSymbolicName, dependencyDepth, getProjectNameForArifact(art)); // no duplicate entries allowed. System paths can cause this problem. if (!dependencies.contains(dep)) { dependencies.add(dep); } } } // @todo a final report with the list of // missingArtifacts? } ideDeps = (IdeDependency[]) dependencies.toArray(new IdeDependency[dependencies.size()]); } else { ideDeps = new IdeDependency[0]; } } return ideDeps; }
From source file:com.coderplus.utils.apache.DependencyUtil.java
License:Apache License
/** * Builds the file name. If removeVersion is set, then the file name must be * reconstructed from the groupId (if <b>prependGroupId</b> is true) artifactId, * Classifier (if used) and Type./*from w w w.jav a 2 s . c om*/ * Otherwise, this method returns the artifact file name. * * @param artifact * File to be formatted. * @param removeVersion * Specifies if the version should be removed from the file name. * @param prependGroupId * Specifies if the groupId should be prepended to the file name. * @param useBaseVersion * Specifies if the baseVersion of the artifact should be used instead of the version. * @param removeClassifier * Specifies if the classifier of the artifact should be remved from the file name. * @return Formatted file name in the format * [groupId].artifactId-[version]-[classifier].[type] */ public static String getFormattedFileName(Artifact artifact, boolean removeVersion, boolean prependGroupId, boolean useBaseVersion, boolean removeClassifier) { StringBuilder destFileName = new StringBuilder(); if (prependGroupId) { destFileName.append(artifact.getGroupId()).append("."); } String versionString; if (!removeVersion) { if (useBaseVersion) { versionString = "-" + artifact.getBaseVersion(); } else { versionString = "-" + artifact.getVersion(); } } else { versionString = ""; } String classifierString = ""; if (!removeClassifier && StringUtils.isNotEmpty(artifact.getClassifier())) { classifierString = "-" + artifact.getClassifier(); } destFileName.append(artifact.getArtifactId()).append(versionString); destFileName.append(classifierString).append("."); destFileName.append(artifact.getArtifactHandler().getExtension()); return destFileName.toString(); }
From source file:com.dooioo.se.lorik.apidoclet.maven.plugin.JavadocUtil.java
License:Apache License
/** * Copy from {@link org.apache.maven.project.MavenProject#getCompileArtifacts()} * @param artifacts not null//from w w w . j a va 2 s. c o m * @param withTestScope flag to include or not the artifacts with test scope * @return list of compile artifacts with or without test scope. */ protected static List<Artifact> getCompileArtifacts(Set<Artifact> artifacts, boolean withTestScope) { List<Artifact> list = new ArrayList<Artifact>(artifacts.size()); for (Artifact a : artifacts) { // TODO: classpath check doesn't belong here - that's the other method if (a.getArtifactHandler().isAddedToClasspath()) { // TODO: let the scope handler deal with this if (withTestScope) { if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_PROVIDED.equals(a.getScope()) || Artifact.SCOPE_SYSTEM.equals(a.getScope()) || Artifact.SCOPE_TEST.equals(a.getScope())) { list.add(a); } } else { if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_PROVIDED.equals(a.getScope()) || Artifact.SCOPE_SYSTEM.equals(a.getScope())) { list.add(a); } } } } return list; }
From source file:com.enonic.cms.maven.plugin.PackagePluginMojo.java
License:Apache License
private String getDefaultFinalName(final Artifact artifact) { return artifact.getArtifactId() + "-" + artifact.getVersion() + "." + artifact.getArtifactHandler().getExtension(); }
From source file:com.fizzed.stork.maven.AssemblyMojo.java
public List<Artifact> artifactsToStage() { List<Artifact> artifacts = new ArrayList<Artifact>(); // include project artifact? if (!shouldArtifactBeStaged(project.getArtifact())) { getLog().info("Project artifact may have a classifier or is not of type jar (will not be staged)"); } else {/*w ww. jav a 2 s . co m*/ artifacts.add(project.getArtifact()); } // any additional artifacts attached to this project? for (Artifact a : project.getAttachedArtifacts()) { if (shouldArtifactBeStaged(a)) { artifacts.add(a); } } // get resolved artifacts as well for (Artifact a : project.getArtifacts()) { if (a.getArtifactHandler().isAddedToClasspath() && (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_RUNTIME.equals(a.getScope()))) { artifacts.add(a); } } return artifacts; }
From source file:com.github.manouti.mojo.NormalizeMojo.java
License:Apache License
private File getOutputFile() { Artifact artifact = project.getArtifact(); final String normalizedName = normalizedArtifactId + "-" + artifact.getVersion() + "-" + normalizedClassifierName + "." + artifact.getArtifactHandler().getExtension(); return new File(outputDirectory, normalizedName); }