List of usage examples for org.apache.maven.artifact.versioning VersionRange createFromVersion
public static VersionRange createFromVersion(String version)
From source file:org.apache.cactus.integration.maven2.test.ArtifactStub.java
License:Apache License
/** * Another constructor for the stub./*from w w w. j a v a2 s . com*/ * * @param theGroupId to use * @param theArtifactId to use * @param theVersion to use * @param thePackaging to use * @param theClassifier to use * @param theScope to use */ public ArtifactStub(String theGroupId, String theArtifactId, String theVersion, String thePackaging, String theClassifier, String theScope) { super(theGroupId, theArtifactId, VersionRange.createFromVersion(theVersion), theScope, thePackaging, theClassifier, new DefaultArtifactHandler(thePackaging), false); }
From source file:org.apache.cactus.integration.maven2.test.CactifyMavenProjectStub.java
License:Apache License
/** * @return a set of dependency artifacts. *//*w ww . j a v a 2 s .co m*/ public Set getDependencyArtifacts() { return Collections.singleton( new DefaultArtifact("cactify", "dependency-artifact", VersionRange.createFromVersion("1.0"), Artifact.SCOPE_COMPILE, "jar", null, new DefaultArtifactHandler("jar"), false)); }
From source file:org.apache.cayenne.stubs.ArtifactStub.java
License:Apache License
public ArtifactStub(String groupId, String artifactId, String version, String packaging, String classifier, String scope) {//w w w .j av a 2 s . c o m super(groupId, artifactId, VersionRange.createFromVersion(version), scope, packaging, classifier, new DefaultArtifactHandler(packaging), false); }
From source file:org.apache.felix.bundleplugin.BundleAllPlugin.java
License:Apache License
private Artifact resolveArtifact(Artifact artifact) throws MojoExecutionException, ArtifactNotFoundException { VersionRange versionRange;/*w w w . jav a 2 s . co m*/ if (artifact.getVersion() != null) { versionRange = VersionRange.createFromVersion(artifact.getVersion()); } else { versionRange = artifact.getVersionRange(); } /* * there's a bug with ArtifactFactory#createDependencyArtifact(String, String, VersionRange, * String, String, String) that ignores the scope parameter, that's why we use the one with * the extra null parameter */ Artifact resolvedArtifact = m_factory.createDependencyArtifact(artifact.getGroupId(), artifact.getArtifactId(), versionRange, artifact.getType(), artifact.getClassifier(), artifact.getScope(), null); try { m_artifactResolver.resolve(resolvedArtifact, remoteRepositories, localRepository); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Error resolving artifact " + resolvedArtifact, e); } return resolvedArtifact; }
From source file:org.apache.openejb.maven.jarstxt.JarsTxtMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (!outputFile.getParentFile().exists()) { FileUtils.mkdir(outputFile.getParentFile().getAbsolutePath()); }/*from w w w . j a va 2 s .co m*/ FileWriter writer = null; try { writer = new FileWriter(outputFile); final TreeSet<String> set = new TreeSet<>(); for (final Artifact a : (Set<Artifact>) project.getArtifacts()) { if (!acceptScope(a.getScope()) || !acceptType(a.getType())) { continue; } a.setScope(Artifact.SCOPE_PROVIDED); final StringBuilder line = new StringBuilder("mvn:").append(a.getGroupId()).append("/") .append(a.getArtifactId()).append("/").append(version(a)); final boolean isJar = JAR.equals(a.getType()); if (!isJar) { line.append("/").append(a.getType()); } if (a.getClassifier() != null) { if (isJar) { line.append("/").append(JAR); } line.append("/").append(a.getClassifier()); } if (hashAlgo != null) { final Artifact artifact = factory.createDependencyArtifact(a.getGroupId(), a.getArtifactId(), VersionRange.createFromVersion(a.getVersion()), a.getType(), a.getClassifier(), a.getScope()); try { resolver.resolve(artifact, remoteRepos, local); } catch (final ArtifactResolutionException | ArtifactNotFoundException e) { throw new MojoExecutionException(e.getMessage(), e); } final File file = artifact.getFile(); line.append("|") .append(Files.hash((Set<URL>) Collections.singleton(file.toURI().toURL()), hashAlgo)) .append("|").append(hashAlgo); } set.add(line.toString()); } if (additionals != null) { if (placeHolders == null) { placeHolders = new HashMap<>(); } final StrSubstitutor lookup = new StrSubstitutor(StrLookup.mapLookup(placeHolders)); for (final String line : additionals) { final StringBuilder builder = new StringBuilder(line); if (hashAlgo != null) { builder.append("|").append(Files.hash(urls(line, lookup), hashAlgo)).append("|") .append(hashAlgo); } set.add(builder.toString()); } } // written after to be sorted, more readable for (final String line : set) { writer.write(line); writer.write("\n"); } writer.flush(); } catch (final IOException e) { getLog().error(e.getMessage(), e); } finally { if (writer != null) { try { writer.close(); } catch (final IOException e) { // no-op } } } }
From source file:org.apache.openejb.maven.plugins.TomEEEmbeddedMojo.java
License:Apache License
private File mvnToFile(final String lib) throws Exception { final String[] infos = lib.split(":"); final String classifier; final String type; if (infos.length < 3) { throw new MojoExecutionException( "format for librairies should be <groupId>:<artifactId>:<version>[:<type>[:<classifier>]]"); }//from w w w . java2s. c o m if (infos.length >= 4) { type = infos[3]; } else { type = "war"; } if (infos.length == 5) { classifier = infos[4]; } else { classifier = null; } final Artifact artifact = factory.createDependencyArtifact(infos[0], infos[1], VersionRange.createFromVersion(infos[2]), type, classifier, "compile"); resolver.resolve(artifact, remoteRepos, local); return artifact.getFile(); }
From source file:org.apache.sling.maven.projectsupport.AbstractBundleListMojo.java
License:Apache License
/** * Get a resolved Artifact from the coordinates provided * * @return the artifact, which has been resolved. * @throws MojoExecutionException/*from w ww.ja v a2 s .c o m*/ */ protected Artifact getArtifact(String groupId, String artifactId, String version, String type, String classifier) throws MojoExecutionException { Artifact artifact; VersionRange vr; try { vr = VersionRange.createFromVersionSpec(version); } catch (InvalidVersionSpecificationException e) { vr = VersionRange.createFromVersion(version); } if (StringUtils.isEmpty(classifier)) { artifact = factory.createDependencyArtifact(groupId, artifactId, vr, type, null, Artifact.SCOPE_COMPILE); } else { artifact = factory.createDependencyArtifact(groupId, artifactId, vr, type, classifier, Artifact.SCOPE_COMPILE); } // This code kicks in when the version specifier is a range. if (vr.getRecommendedVersion() == null) { try { List<ArtifactVersion> availVersions = metadataSource.retrieveAvailableVersions(artifact, local, remoteRepos); ArtifactVersion resolvedVersion = vr.matchVersion(availVersions); artifact.setVersion(resolvedVersion.toString()); } catch (ArtifactMetadataRetrievalException e) { throw new MojoExecutionException("Unable to find version for artifact", e); } } try { resolver.resolve(artifact, remoteRepos, local); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Unable to resolve artifact.", e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Unable to find artifact.", e); } return artifact; }
From source file:org.apache.sling.maven.slingstart.ModelPreprocessor.java
License:Apache License
private File resolveSlingstartArtifact(final Environment env, final MavenProject project, final Dependency d) throws MavenExecutionException { final Artifact prjArtifact = new DefaultArtifact(d.getGroupId(), d.getArtifactId(), VersionRange.createFromVersion(d.getVersion()), Artifact.SCOPE_PROVIDED, d.getType(), d.getClassifier(), env.artifactHandlerManager.getArtifactHandler(d.getType())); try {/* ww w . j a v a 2s . c o m*/ env.resolver.resolve(prjArtifact, project.getRemoteArtifactRepositories(), env.session.getLocalRepository()); } catch (final ArtifactResolutionException e) { throw new MavenExecutionException("Unable to get artifact for " + d, e); } catch (final ArtifactNotFoundException e) { throw new MavenExecutionException("Unable to get artifact for " + d, e); } return prjArtifact.getFile(); }
From source file:org.apache.sling.maven.slingstart.ModelUtils.java
License:Apache License
/** * Get a resolved Artifact from the coordinates provided * * @return the artifact, which has been resolved. * @throws MojoExecutionException/* www . ja va 2 s . co m*/ */ public static Artifact getArtifact(final MavenProject project, final MavenSession session, final ArtifactHandlerManager artifactHandlerManager, final ArtifactResolver resolver, final String groupId, final String artifactId, final String version, final String type, final String classifier) throws MojoExecutionException { final Set<Artifact> artifacts = project.getDependencyArtifacts(); for (final Artifact artifact : artifacts) { if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId) && artifact.getVersion().equals(version) && artifact.getType().equals(type) && ((classifier == null && artifact.getClassifier() == null) || (classifier != null && classifier.equals(artifact.getClassifier())))) { return artifact; } } final Artifact prjArtifact = new DefaultArtifact(groupId, artifactId, VersionRange.createFromVersion(version), Artifact.SCOPE_PROVIDED, type, classifier, artifactHandlerManager.getArtifactHandler(type)); try { resolver.resolve(prjArtifact, project.getRemoteArtifactRepositories(), session.getLocalRepository()); } catch (final ArtifactResolutionException e) { throw new MojoExecutionException( "Unable to get artifact for " + groupId + ":" + artifactId + ":" + version, e); } catch (final ArtifactNotFoundException e) { throw new MojoExecutionException( "Unable to get artifact for " + groupId + ":" + artifactId + ":" + version, e); } return prjArtifact; }
From source file:org.apache.sling.maven.slingstart.run.StartMojo.java
License:Apache License
/** * Get a resolved Artifact from the coordinates provided * * @return the artifact, which has been resolved. * @throws MojoExecutionException//from ww w. ja va2 s .co m */ private Artifact getArtifact(final Dependency d) throws MojoExecutionException { final Artifact prjArtifact = new DefaultArtifact(d.getGroupId(), d.getArtifactId(), VersionRange.createFromVersion(d.getVersion()), d.getScope(), d.getType(), d.getClassifier(), this.artifactHandlerManager.getArtifactHandler(d.getType())); try { this.resolver.resolve(prjArtifact, this.project.getRemoteArtifactRepositories(), this.mavenSession.getLocalRepository()); } catch (final ArtifactResolutionException e) { throw new MojoExecutionException("Unable to get artifact for " + d, e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Unable to get artifact for " + d, e); } return prjArtifact; }