Example usage for org.apache.maven.artifact.versioning VersionRange createFromVersion

List of usage examples for org.apache.maven.artifact.versioning VersionRange createFromVersion

Introduction

In this page you can find the example usage for org.apache.maven.artifact.versioning VersionRange createFromVersion.

Prototype

public static VersionRange createFromVersion(String version) 

Source Link

Usage

From source file:hudson.maven.reporters.MavenFingerprinter.java

License:Open Source License

private void recordParents(MavenBuildProxy build, MavenProject pom, BuildListener listener)
        throws IOException, InterruptedException {
    Map<String, String> modelParents = build.getMavenBuildInformation().modelParents;
    ArtifactRepository localRepository = getLocalRepository(build.getMavenBuildInformation(), pom);
    if (localRepository == null) {
        listener.error(//from   w  w  w  .  j  a v a 2  s  .  c  o  m
                "Could not find local repository for " + build.getMavenBuildInformation().getMavenVersion());
        return;
    }
    String parent = modelParents.get(pom.getId());
    while (parent != null) {
        String[] parts = parent.split(":");
        assert parts.length == 4 : parent;
        // Maven 2.x lacks DefaultArtifact constructor with String version and ArtifactRepository.find:
        Artifact parentArtifact = new DefaultArtifact(parts[0], parts[1],
                VersionRange.createFromVersion(parts[3]), null, parts[2], null,
                new DefaultArtifactHandler(parts[2]));
        File parentFile = new File(localRepository.getBasedir(), localRepository.pathOf(parentArtifact));
        // we need to include the artifact Id for poms as well, otherwise a project with the same groupId would override its parent's fingerprint
        record(parts[0] + ":" + parts[1], parentFile, used);
        parent = modelParents.get(parent);
    }
}

From source file:io.fabric8.maven.stubs.CreateProfileArtifactStub.java

License:Apache License

public CreateProfileArtifactStub(String groupId, String artifactId, String version, String type) {
    setGroupId(groupId);//from   ww  w  .j av a 2 s  .  c  o  m
    setArtifactId(artifactId);
    setVersion(version);
    setType(type);
    versionRange = VersionRange.createFromVersion(version);
}

From source file:io.wcm.devops.conga.tooling.maven.plugin.GenerateMojo.java

License:Apache License

/**
 * Get a resolved Artifact from the coordinates provided
 * @return the artifact, which has been resolved.
 *//*from www.  j  a va 2s . com*/
@SuppressWarnings("deprecation")
private Artifact getArtifact(Dependency dependency) throws IOException {
    Artifact artifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(),
            VersionRange.createFromVersion(dependency.getVersion()), dependency.getScope(),
            dependency.getType(), dependency.getClassifier(),
            artifactHandlerManager.getArtifactHandler(dependency.getType()));
    try {
        this.resolver.resolve(artifact, this.project.getRemoteArtifactRepositories(),
                this.mavenSession.getLocalRepository());
    } catch (final ArtifactResolutionException ex) {
        throw new IOException("Unable to get artifact for " + dependency, ex);
    } catch (ArtifactNotFoundException ex) {
        throw new IOException("Unable to get artifact for " + dependency, ex);
    }
    return artifact;
}

From source file:nl.pieni.maven.dependency_analyzer.mojo.create.AbstractParserMojo.java

License:Apache License

/**
 * Convert a {|@link ArtifactInfo} object to a Maven project.
 *
 * @param artifactInfo The artifact/*from  www  .ja  va2s. c  o  m*/
 * @return A {@link org.apache.maven.project.MavenProject}
 * @throws org.apache.maven.project.ProjectBuildingException
 *          Error parsing the POM file.
 */
MavenProject artifactInfo2MavenProject(ArtifactInfo artifactInfo) throws ProjectBuildingException {
    VersionRange versionRange = VersionRange.createFromVersion(artifactInfo.version);
    Artifact parentArtifact = new DefaultArtifact(artifactInfo.groupId, artifactInfo.artifactId, versionRange,
            "compile", "pom", null, new DefaultArtifactHandler());
    ProjectBuildingResult buildingResult = projectBuilder.build(parentArtifact, this.buildRequest);
    return buildingResult.getProject();
}

From source file:npanday.executable.impl.NetPluginExecutableFactoryImpl.java

License:Apache License

public NetExecutable getPluginExecutable(MavenProject project, Artifact pluginArtifact,
        VendorRequirement vendorRequirement, ArtifactRepository localRepository, File parameterFile,
        String mojoName, File targetDir, String npandayVersion)
        throws PlatformUnsupportedException, ArtifactResolutionException, ArtifactNotFoundException {
    Set<Artifact> dependencies = Sets.newHashSet(pluginArtifact);

    Artifact loaderArtifact = artifactFactory.createDependencyArtifact("org.apache.npanday.plugins",
            "NPanday.Plugin.Loader", VersionRange.createFromVersion(npandayVersion),
            ArtifactType.DOTNET_EXECUTABLE.getPackagingType(), null, "runtime");
    dependencies.add(pluginArtifact);/*from w w  w.ja  va  2s  . c  o  m*/

    // preresolve this one
    artifactResolver.resolve(pluginArtifact, project.getRemoteArtifactRepositories(), localRepository);
    File pluginArtifactPath = getPrivateApplicationBaseFileFor(pluginArtifact, targetDir);

    List<String> commands = new ArrayList<String>();
    commands.add("parameterFile=" + parameterFile.getAbsolutePath());
    commands.add("assemblyFile=" + pluginArtifactPath.getAbsolutePath());
    commands.add("mojoName=" + mojoName);//ArtifactId = namespace

    return getPluginRunner(project, loaderArtifact, dependencies, vendorRequirement, localRepository, commands,
            targetDir, npandayVersion);
}

From source file:npanday.executable.impl.NetPluginExecutableFactoryImpl.java

License:Apache License

private Artifact createPluginRunnerArtifact(String npandayVersion) {
    return artifactFactory.createDependencyArtifact("org.apache.npanday.plugins", "NPanday.Plugin.Runner",
            VersionRange.createFromVersion(npandayVersion), ArtifactType.DOTNET_EXECUTABLE.getPackagingType(),
            null, "runtime");
}

From source file:npanday.plugin.AbstractMojo.java

License:Apache License

/**
 * Executes the mojo./*from w ww  . j a v  a 2s  . c  o m*/
 *
 * @throws MojoExecutionException
 * @throws MojoFailureException
 */
public final void execute() throws MojoExecutionException, MojoFailureException {
    if (!preExecute()) {
        return;
    }

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new MojoExecutionException("NPANDAY-115-000: Unable to create document builder", e);
    }
    Document document = builder.newDocument();

    FileOutputStream fos;
    File paramFile;
    try {
        paramFile = File.createTempFile("Plugin", ".xml");
        fos = new FileOutputStream(paramFile);
    } catch (IOException e) {
        throw new MojoExecutionException(
                "NPANDAY-115-001: IO error on creating or accessing Plugin.xml temp file", e);
    }

    StreamResult result = new StreamResult();
    result.setOutputStream(fos);
    try {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.transform(this.getDOMSourceFor(document), result);
    } catch (TransformerConfigurationException e) {
        throw new MojoExecutionException("NPANDAY-115-002", e);

    } catch (TransformerException e) {
        throw new MojoExecutionException("NPANDAY-115-003", e);
    } finally {
        try {
            fos.close();
        } catch (IOException e) {
            throw new MojoExecutionException(
                    "NPANDAY-115-004: Unable to write file " + paramFile.getAbsolutePath(), e);
        }
    }

    MavenProject project = getMavenProject();

    // TODO: should be configurable, but relies on it being passed into everywhere
    File targetDir = PathUtil.getPrivateApplicationBaseDirectory(project);

    VendorRequirement vendorRequirement = new VendorRequirement(getVendor(), getVendorVersion(),
            getFrameworkVersion());

    try {
        ArtifactRepository localRepository = LocalRepositoryUtil.create(getLocalRepository());

        Artifact artifact = getArtifactFactory().createDependencyArtifact(getMojoGroupId(), getMojoArtifactId(),
                VersionRange.createFromVersion(getPluginVersion()),
                ArtifactType.DOTNET_MAVEN_PLUGIN.getPackagingType(), null, "runtime");

        getNetPluginExecutableFactory().getPluginExecutable(project, artifact, vendorRequirement,
                localRepository, paramFile, getClassName(), targetDir, getNPandayVersion()).execute();
    } catch (PlatformUnsupportedException e) {
        throw new MojoExecutionException(
                "NPANDAY-115-005: Vendor configuration seems to be unsupported: " + vendorRequirement, e);
    } catch (ExecutionException e) {
        throw new MojoExecutionException("NPANDAY-115-006: Error occurred while running the .NET plugin", e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoFailureException("NPANDAY-115-010: Error on resolving plugin artifact(s)", e);
    } catch (ArtifactResolutionException e) {
        throw new MojoFailureException("NPANDAY-115-011: Error on resolving plugin artifact(s)", e);
    }

    postExecute();
}

From source file:npanday.plugin.generator.MojoGeneratorMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    if (skip) {/*from   w  ww. ja  v  a2  s. c  o  m*/
        return;
    }

    SettingsUtil.applyCustomSettings(getLog(), repositoryRegistry, settingsPath);

    try {
        List<String> commands = new ArrayList<String>();
        VendorRequirement vendorRequirement = new VendorRequirement(vendor, vendorVersion, frameworkVersion);

        File targetDir = PathUtil.getPrivateApplicationBaseDirectory(project);
        File targetAssemblyFile = new File(targetDir, project.getArtifactId() + ".dll");
        commands.add("targetAssemblyFile=" + targetAssemblyFile.getAbsolutePath());
        commands.add("outputDirectory=" + basedir);
        commands.add("groupId=" + project.getGroupId());
        commands.add("artifactId=" + project.getArtifactId());
        commands.add("artifactVersion=" + project.getVersion());

        Artifact artifact = artifactFactory.createDependencyArtifact("org.apache.npanday.plugins",
                "NPanday.Plugin.MojoGenerator", VersionRange.createFromVersion(pluginVersion),
                ArtifactType.DOTNET_EXECUTABLE.getPackagingType(), null, "runtime");

        netPluginExecutableFactory
                .getPluginRunner(project, artifact, null, vendorRequirement,
                        LocalRepositoryUtil.create(localRepository), commands, targetDir, pluginVersion)
                .execute();
    } catch (PlatformUnsupportedException e) {
        throw new MojoExecutionException("", e);
    } catch (ExecutionException e) {
        throw new MojoExecutionException("", e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException("", e);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("", e);
    }
}

From source file:npanday.plugin.msdeploy.sync.SyncPackagesMojo.java

License:Apache License

@Override
protected List<Package> prepareIterationItems() throws MojoFailureException, MojoExecutionException {
    Set<Artifact> artifacts = Sets.newHashSet();

    setCredentials(destination);// ww  w .  ja v  a  2s .co  m

    for (Package pkg : packages) {
        Artifact artifact = artifactFactory.createDependencyArtifact(pkg.getGroupId(), pkg.getArtifactId(),
                VersionRange.createFromVersion(pkg.getVersion()),
                ArtifactType.MSDEPLOY_PACKAGE.getPackagingType(), pkg.getClassifier(), "compile");
        artifacts.add(artifact);

        try {
            resolve(artifact);
        } catch (ArtifactResolutionException e) {
            throw new MojoExecutionException(
                    "NPANDAY-153-001: unable to resolve msdeploy package " + artifact.getId(), e);
        } catch (ArtifactNotFoundException e) {
            throw new MojoExecutionException(
                    "NPANDAY-153-002: unable to resolve msdeploy package " + artifact.getId(), e);
        }

        setCredentials(pkg.getDestination());

        pkg.contextualize(artifact, destination);
    }

    return packages;
}

From source file:org.ajax4jsf.builder.mojo.CreateSkinMojo.java

License:Open Source License

private File getPluginArtifactJar() throws ArtifactResolutionException, ArtifactNotFoundException {
    Artifact pluginArtifact = artifactFactory.createPluginArtifact(pluginGroupId, pluginArtifactId,
            VersionRange.createFromVersion(pluginVersion));

    resolver.resolve(pluginArtifact, Collections.emptyList(), localRepository);

    return pluginArtifact.getFile();
}