List of usage examples for org.apache.maven.artifact.versioning VersionRange createFromVersion
public static VersionRange createFromVersion(String version)
From source file:org.metaeffekt.dita.maven.mojo.DitaInfrastructureMojo.java
License:Apache License
/** * Resolve the DITA Open Toolkit and throw an exception when the dependency * is not found./*from w ww. j a va 2 s . co m*/ * * @return Pointer to the DITA Open Toolkit. * @throws MojoExecutionException */ public Artifact getDitaToolkitDependency() throws MojoExecutionException { Artifact toolkitArtifact; toolkitArtifact = new DefaultArtifact(ditaToolkitGroupId, ditaToolkitArtifactId, VersionRange.createFromVersion(ditaToolkitVersion), Artifact.SCOPE_COMPILE, DitaInstallationHelper.DITA_TOOLKIT_TYPE, ditaToolkitClassifier, new DefaultArtifactHandler(DitaInstallationHelper.DITA_TOOLKIT_TYPE)); try { artifactResolver.resolve(toolkitArtifact, remoteRepositories, localRepository); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Dita Toolkit artifact cannot be resolved.", e); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Exception while resolving the Dita Toolkit.", e); } return toolkitArtifact; }
From source file:org.nuxeo.build.maven.ArtifactDescriptor.java
License:Open Source License
/** * @return ArtifactFactory().createDependencyArtifact() * @since 1.10.2/*from w ww . ja v a2 s .c o m*/ */ public Artifact getArtifact() { MavenClient maven = MavenClientFactory.getInstance(); // Resolve version if not provided if (version == null) { VersionManagement versionManagement = maven.getGraph().getVersionManagement(); version = versionManagement.getVersion(this); if (version == null) { throw new BuildException("Version is required since not found in dependency management: " + this); } } Artifact artifact = maven.getArtifactFactory().createDependencyArtifact(groupId, artifactId, VersionRange.createFromVersion(version), type, classifier, scope); return artifact; }
From source file:org.ops4j.pax.exam.mavenplugin.GenerateConfigMojo.java
License:Apache License
protected void writeProvisioning(PrintStream out, List<Dependency> dependencies) throws ArtifactResolutionException, ArtifactNotFoundException { out.println("# provisioning"); out.println();/*from ww w. j a v a 2 s . com*/ for (Dependency dependency : dependencies) { Artifact artifact = factory.createDependencyArtifact(dependency.getGroupId(), dependency.getArtifactId(), VersionRange.createFromVersion(dependency.getVersion()), dependency.getType(), dependency.getClassifier(), dependency.getScope()); // try to find boolean found = false; for (MavenProject project : (List<MavenProject>) session.getSortedProjects()) { Artifact projectArtifact = project.getArtifact(); if (projectArtifact.getArtifactId().equals(artifact.getArtifactId()) && (projectArtifact.getGroupId().equals(artifact.getGroupId()) && projectArtifact.getVersion().equals(artifact.getVersion()))) { artifact = projectArtifact; found = true; break; } } if (!found) { resolver.resolve(artifact, remoteRepositories, session.getLocalRepository()); } out.println( createPaxRunnerScan(artifact, getSettingsForArtifact(settings.get(SETTINGS_DEPENDENCY_OPTIONS), artifact.getGroupId(), artifact.getArtifactId()))); getLog().debug("Dependency: " + dependency + " classifier: " + dependency.getClassifier() + " type: " + dependency.getType()); } out.println(); }
From source file:org.ops4j.pax.vault.builder.BuilderPlugin.java
License:Apache License
public File getKernel() { File f = null;/* w w w.j a va 2 s .c om*/ // latest local kernel for now ArtifactHandler handler = m_artifactHandlerManager.getArtifactHandler("jar"); Artifact artifact = new DefaultArtifact("com.okidokiteam.gouken", "gouken-kernel", VersionRange.createFromVersion("0.1.0-SNAPSHOT"), "compile", "jar", null, handler); ArtifactRepository repo = localRepo; try { resolver.resolve(artifact, remoteRepos, repo); f = artifact.getFile(); } catch (ArtifactResolutionException e) { e.printStackTrace(); } catch (ArtifactNotFoundException e) { e.printStackTrace(); } if (f == null) { getLog().info("Fallblack :(("); f = new File( "/Users/tonit/devel/com.okidokiteam/gouken/gouken-kernel/target/gouken-kernel-0.1.0-SNAPSHOT.jar"); } else { getLog().info("Found by resolver! ;)"); } return f; }
From source file:org.sakaiproject.maven.plugin.component.stub.SimpleConfigurationArtifact4CCStub.java
License:Apache License
public VersionRange getVersionRange() { return VersionRange.createFromVersion(getVersion()); }
From source file:org.sakaiproject.nakamura.maven.DroolsCompilerMojo.java
License:Apache License
/** * Get a resolved Artifact from the coordinates provided * /*from w w w . j a v a 2s. co m*/ * @return the artifact, which has been resolved. * @throws MojoExecutionException */ 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); } 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.simplericity.jettyconsole.CreateDescriptorMojo.java
License:Apache License
private void setDeps() throws MojoExecutionException, MojoFailureException { List<File> deps = getDependencies(); List<URL> additionalDeps = new ArrayList<URL>(); for (File file : deps) { if (file.getName().contains("jetty-console-core")) { try { creator.setCoreDependency(file.toURL()); } catch (MalformedURLException e) { throw new MojoExecutionException(e.getMessage(), e); }//from ww w . ja va 2 s.c o m } else { try { additionalDeps.add(file.toURL()); } catch (MalformedURLException e) { throw new MojoExecutionException(e.getMessage(), e); } } } Set<Artifact> artifacts = new HashSet<Artifact>(); if (additionalDependencies != null) { for (AdditionalDependency dep : additionalDependencies) { String groupId = dep.getGroupId(); String version = dep.getVersion(); if (groupId == null && version == null) { groupId = "org.simplericity.jettyconsole"; version = props.getProperty("version"); } artifacts.add(artifactFactory.createDependencyArtifact(groupId, dep.getArtifactId(), VersionRange.createFromVersion(version), dep.getType(), dep.getClassifier(), dep.getScope())); } } try { Set<Artifact> slf4jBindingArtifacts = new HashSet<Artifact>(); if (artifacts.size() > 0) { ArtifactResolutionResult result = resolver.resolveTransitively(artifacts, project.getArtifact(), localRepository, remoteRepositories, artifactMetadataSource, new ScopeArtifactFilter("runtime")); for (Artifact artifact : (Set<Artifact>) result.getArtifacts()) { if (!"slf4j-api".equals(artifact.getArtifactId())) { additionalDeps.add(artifact.getFile().toURL()); if (hasSlf4jBinding(artifact.getFile())) { slf4jBindingArtifacts.add(artifact); } } } } if (project.getPackaging().equals("jar")) { additionalDeps.add(project.getArtifact().getFile().toURL()); } if (slf4jBindingArtifacts.isEmpty()) { String slf4jVersion = props.getProperty("slf4jVersion"); final Artifact slf4jArtifact = artifactFactory.createDependencyArtifact("org.slf4j", "slf4j-simple", VersionRange.createFromVersion(slf4jVersion), "jar", null, "runtime"); resolver.resolve(slf4jArtifact, remoteRepositories, localRepository); additionalDeps.add(slf4jArtifact.getFile().toURL()); } else if (slf4jBindingArtifacts.size() > 1) { throw new MojoFailureException( "You have dependencies on multiple SJF4J artifacts, please select a single one: " + slf4jBindingArtifacts); } } catch (ArtifactResolutionException | MalformedURLException | ArtifactNotFoundException e) { throw new MojoExecutionException(e.getMessage(), e); } creator.setAdditionalDependecies(additionalDeps); }
From source file:org.simplericity.jettyconsole.CreateDescriptorMojo.java
License:Apache License
private List<File> getDependencies() throws MojoExecutionException { Set<Artifact> artifacts = new HashSet<>(); String version = props.getProperty("version"); String jettyVersion = props.getProperty("jettyVersion"); getLog().info("Resolving dependencies for version " + version + " of jetty-console-core"); artifacts.add(artifactFactory.createDependencyArtifact("org.simplericity.jettyconsole", "jetty-console-core", VersionRange.createFromVersion(version), "jar", null, "runtime")); List<File> artifactFiles = new ArrayList<File>(); try {/* ww w. j a va2 s.c o m*/ ArtifactResolutionResult result = resolver.resolveTransitively(artifacts, project.getArtifact(), remoteRepositories, localRepository, artifactMetadataSource); for (Artifact artifact : (Set<Artifact>) result.getArtifacts()) { artifactFiles.add(artifact.getFile()); } return artifactFiles; } catch (ArtifactResolutionException | ArtifactNotFoundException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:org.simplericity.jettyconsole.CreateDescriptorMojo.java
License:Apache License
public Artifact getWarArtifact() throws MojoExecutionException { if (warArtifact != null) { try {//w w w .ja va 2 s. c om Artifact artifact = artifactFactory.createDependencyArtifact(warArtifact.getGroupId(), warArtifact.getArtifactId(), VersionRange.createFromVersion(warArtifact.getVersion()), warArtifact.getType(), warArtifact.getClassifier(), "runtime"); resolver.resolve(artifact, remoteRepositories, localRepository); return artifact; } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Unable to resolve war artifact (" + e.getMessage() + ")", e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Unable to find war artifact (" + e.getMessage() + ")", e); } } if (project.getArtifact().getFile().getName().endsWith(".war")) { return project.getArtifact(); } List<Artifact> wars = new ArrayList<Artifact>(); for (Iterator i = project.getArtifacts().iterator(); i.hasNext();) { Artifact artifact = (Artifact) i.next(); if ("war".equals(artifact.getType())) { wars.add(artifact); } } if (wars.size() == 0) { throw new MojoExecutionException("Can't find any war dependency"); } else if (wars.size() > 1) { throw new MojoExecutionException("Found more than one war dependency, can't continue"); } else { return wars.get(0); } }
From source file:org.sonatype.nexus.maven.staging.deploy.strategy.AbstractDeployStrategy.java
License:Open Source License
protected void deployUp(final MavenSession mavenSession, final File sourceDirectory, ArtifactRepository remoteRepository) throws ArtifactDeploymentException, IOException { // I'd need Aether RepoSystem and create one huge DeployRequest will _all_ artifacts (would be FAST as it would // go parallel), but we need to work in Maven2 too, so old compat and slow method remains: deploy one by one... final FileInputStream fis = new FileInputStream(new File(sourceDirectory, ".index")); final Properties index = new Properties(); try {//from w w w . ja v a 2 s. com index.load(fis); } finally { Closeables.closeQuietly(fis); } ArtifactRepository repoToUse = remoteRepository; for (String includedFilePath : index.stringPropertyNames()) { final File includedFile = new File(sourceDirectory, includedFilePath); final String includedFileProps = index.getProperty(includedFilePath); final Matcher matcher = indexProps.matcher(includedFileProps); if (!matcher.matches()) { throw new ArtifactDeploymentException("Internal error! Line \"" + includedFileProps + "\" does not match pattern \"" + indexProps.toString() + "\"?"); } final String groupId = matcher.group(1); final String artifactId = matcher.group(2); final String version = matcher.group(3); final String classifier = "n/a".equals(matcher.group(4)) ? null : matcher.group(4); final String packaging = matcher.group(5); final String extension = matcher.group(6); final String pomFileName = "n/a".equals(matcher.group(7)) ? null : matcher.group(7); final String pluginPrefix = "n/a".equals(matcher.group(8)) ? null : matcher.group(8); final String repoId = "n/a".equals(matcher.group(9)) ? null : matcher.group(9); final String repoUrl = "n/a".equals(matcher.group(10)) ? null : matcher.group(10); if (remoteRepository == null) { if (repoUrl != null && repoId != null) { repoToUse = createDeploymentArtifactRepository(repoId, repoUrl); } else { throw new ArtifactDeploymentException( "Internal error! Remote repository for deployment not defined."); } } // just a synthetic one, to properly set extension final FakeArtifactHandler artifactHandler = new FakeArtifactHandler(packaging, extension); final DefaultArtifact artifact = new DefaultArtifact(groupId, artifactId, VersionRange.createFromVersion(version), null, packaging, classifier, artifactHandler); if (pomFileName != null) { final File pomFile = new File(includedFile.getParentFile(), pomFileName); final ProjectArtifactMetadata pom = new ProjectArtifactMetadata(artifact, pomFile); artifact.addMetadata(pom); if ("maven-plugin".equals(artifact.getType())) { // So, we have a "main" artifact with type of "maven-plugin" // Hence, this is a Maven Plugin, Group level MD needs to be added too final GroupRepositoryMetadata groupMetadata = new GroupRepositoryMetadata(groupId); // TODO: we "simulate" the name with artifactId, same what maven-plugin-plugin // would do. Impact is minimal, as we don't know any tool that _uses_ the name // from Plugin entries. Once the "index file" is properly solved, // or, we are able to properly persist Artifact instances above // (to preserve attached metadatas like this G level, and reuse // deployer without reimplementing it), all this will become unneeded. groupMetadata.addPluginMapping(pluginPrefix, artifactId, artifactId); artifact.addMetadata(groupMetadata); } } artifactDeployer.deploy(includedFile, artifact, repoToUse, mavenSession.getLocalRepository()); } }