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:com.googlecode.t7mp.steps.deployment.AbstractDeploymentStep.java

License:Apache License

protected List<AbstractArtifact> resolveArtifacts(List<? extends AbstractArtifact> artifacts) {
    List<AbstractArtifact> resolvedArtifacts = Lists.newArrayList();
    for (AbstractArtifact abstractArtifact : artifacts) {
        context.getLog().debug("Resolve artifact for " + abstractArtifact.toString());
        if (!abstractArtifact.getGroupId().equals("local")) {
            Artifact artifact;// ww w  .  j av a  2  s.c  o m
            try {
                artifact = myArtifactResolver.resolve(abstractArtifact.getGroupId(),
                        abstractArtifact.getArtifactId(), abstractArtifact.getVersion(),
                        abstractArtifact.getClassifier(), abstractArtifact.getType(), Artifact.SCOPE_COMPILE);
            } catch (MojoExecutionException e) {
                throw new TomcatSetupException(e.getMessage(), e);
            }
            abstractArtifact.setArtifact(artifact);
            resolvedArtifacts.add(abstractArtifact);
        } else {
            Artifact artifact = new DefaultArtifact(abstractArtifact.getGroupId(),
                    abstractArtifact.getArtifactId(),
                    VersionRange.createFromVersion(abstractArtifact.getVersion()), Artifact.SCOPE_COMPILE,
                    abstractArtifact.getType(), null, new DefaultArtifactHandler("jar"), false);
            String resourceName = "/com/googlecode/t7mp/repo/" + abstractArtifact.getArtifactId() + "/"
                    + abstractArtifact.getVersion() + "/" + abstractArtifact.getArtifactId() + "-"
                    + abstractArtifact.getVersion() + ".jar";
            BufferedInputStream bis = new BufferedInputStream(getClass().getResourceAsStream(resourceName));
            File tempFile;
            try {
                tempFile = File.createTempFile("local_Artifact", ".maven.tmp");
                tempFile.deleteOnExit();
                IOUtils.copy(bis, new FileOutputStream(tempFile));
                artifact.setFile(tempFile);
                abstractArtifact.setArtifact(artifact);
                resolvedArtifacts.add(abstractArtifact);
            } catch (FileNotFoundException e) {
                throw new TomcatSetupException(e.getMessage(), e);
            } catch (IOException e) {
                throw new TomcatSetupException(e.getMessage(), e);
            }
        }
    }
    return resolvedArtifacts;
}

From source file:com.jayway.maven.plugins.android.phase09package.ApkMojo.java

License:Apache License

private Set<Artifact> processTransientDependencies(org.sonatype.aether.artifact.Artifact aetherArtifact,
        ArtifactHandler artifactHandler) throws MojoExecutionException {

    try {/*from  w  w  w .  j a  va  2 s  .c om*/
        final Set<Artifact> artifacts = new TreeSet<Artifact>();

        Dependency dependency = new Dependency(aetherArtifact, "runtime");

        final CollectRequest collectRequest = new CollectRequest();

        collectRequest.setRoot(dependency);
        collectRequest.setRepositories(projectRepos);
        final DependencyNode node = repoSystem.collectDependencies(repoSession, collectRequest).getRoot();

        final DependencyRequest dependencyRequest = new DependencyRequest(node,
                new ScopeDependencyFilter(Arrays.asList("compile", "runtime"), Arrays.asList("test")));

        repoSystem.resolveDependencies(repoSession, dependencyRequest);

        PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
        node.accept(nlg);

        final List<Dependency> dependencies = nlg.getDependencies(false);

        for (Dependency dep : dependencies) {
            final org.sonatype.aether.artifact.Artifact artifact = dep.getArtifact();
            if ("so".equals(artifact.getExtension())) {
                final Artifact mavenArtifact = artifactFactory.createDependencyArtifact(artifact.getGroupId(),
                        artifact.getArtifactId(), VersionRange.createFromVersion(artifact.getVersion()),
                        artifact.getExtension(), artifact.getClassifier(), dep.getScope());
                artifacts.add(mavenArtifact);
            }
        }

        return artifacts;
    } catch (Exception e) {
        throw new MojoExecutionException("Error while processing transient dependencies", e);
    }
}

From source file:com.maestrodev.plugins.collabnet.FrsCopyWorker.java

License:Apache License

private String copyArtifact(FrsSession frsSession, String releaseId)
        throws MalformedURLException, RemoteException {
    Artifact artifact = new DefaultArtifact(artifactGroupId, artifactId,
            VersionRange.createFromVersion(artifactVersion), null, artifactType, artifactClassifier,
            new DefaultArtifactHandler(artifactType));
    String path = new DefaultRepositoryLayout().pathOf(artifact);
    String url = repositoryUrl + "/" + path;

    String filename = this.filename;
    if (StringUtils.isBlank(filename)) {
        filename = path.substring(path.lastIndexOf('/') + 1);
    }/*  w ww .j  a v  a 2s. c  o m*/

    String msg = "Uploading '" + url + "' to release '" + releaseId + "' as '" + filename + "'";
    logger.debug(msg);
    writeOutput(msg + "\n");

    Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(repositoryUsername, repositoryPassword.toCharArray());
        }
    });

    return frsSession.uploadFileFromUrl(releaseId, new URL(url), filename, overwrite);
}

From source file:com.mercatis.maven.plugins.eclipse.GatherDependencies.java

License:Apache License

@SuppressWarnings("unchecked")
private void addDependencyToMavenProject(String bundleName, File bundle) {
    Artifact fact = factory.createDependencyArtifact("ECLIPSE", bundleName,
            VersionRange.createFromVersion("0.0"), "jar", null, Artifact.SCOPE_SYSTEM);
    fact.setFile(bundle);/*from  w w w.  j  a va  2 s.com*/
    fact.setResolved(true);
    project.getDependencyArtifacts().add(fact);
}

From source file:com.photon.maven.plugins.android.common.NativeHelper.java

License:Apache License

private Set<Artifact> processTransientDependencies(Dependency dependency, boolean sharedLibraries)
        throws MojoExecutionException {
    try {/*from w  w  w.  j av  a 2  s. c om*/
        final Set<Artifact> artifacts = new LinkedHashSet<Artifact>();

        final CollectRequest collectRequest = new CollectRequest();

        collectRequest.setRoot(dependency);
        collectRequest.setRepositories(projectRepos);
        final DependencyNode node = repoSystem.collectDependencies(repoSession, collectRequest).getRoot();

        final DependencyRequest dependencyRequest = new DependencyRequest(node,
                new AndDependencyFilter(
                        new ScopeDependencyFilter(Arrays.asList("compile", "runtime"), Arrays.asList("test")),
                        // Also exclude any optional dependencies
                        new DependencyFilter() {
                            @Override
                            public boolean accept(DependencyNode dependencyNode,
                                    List<DependencyNode> dependencyNodes) {
                                return !dependencyNode.getDependency().isOptional();
                            }
                        }));

        repoSystem.resolveDependencies(repoSession, dependencyRequest);

        PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
        node.accept(nlg);

        final List<Dependency> dependencies = nlg.getDependencies(false);

        for (Dependency dep : dependencies) {
            final org.sonatype.aether.artifact.Artifact depAetherArtifact = dep.getArtifact();
            if (isNativeLibrary(sharedLibraries, depAetherArtifact.getExtension())) {
                final Artifact mavenArtifact = artifactFactory.createDependencyArtifact(
                        depAetherArtifact.getGroupId(), depAetherArtifact.getArtifactId(),
                        VersionRange.createFromVersion(depAetherArtifact.getVersion()),
                        depAetherArtifact.getExtension(), depAetherArtifact.getClassifier(), dep.getScope());
                mavenArtifact.setFile(depAetherArtifact.getFile());
                artifacts.add(mavenArtifact);
            }
        }

        return artifacts;
    } catch (Exception e) {
        throw new MojoExecutionException("Error while processing transient dependencies", e);
    }
}

From source file:com.smartitengineering.cms.maven.tools.plugin.StartMojo.java

License:Open Source License

protected Artifact getArtifact(ArtifactItem item) {
    VersionRange vr;//from  w w  w. ja  v  a2 s .co  m
    try {
        vr = VersionRange.createFromVersionSpec(item.getVersion());
    } catch (InvalidVersionSpecificationException e1) {
        vr = VersionRange.createFromVersion(item.getVersion());
    }
    final Artifact artifact;
    if (StringUtils.isBlank(item.getClassifier())) {
        artifact = factory.createDependencyArtifact(item.getGroupId(), item.getArtifactId(), vr, item.getType(),
                item.getClassifier(), Artifact.SCOPE_COMPILE);
    } else {
        artifact = factory.createDependencyArtifact(item.getGroupId(), item.getArtifactId(), vr, item.getType(),
                null, Artifact.SCOPE_COMPILE);
    }
    try {
        resolver.resolve(artifact, remoteRepos, local);
    } catch (ArtifactResolutionException ex) {
        throw new IllegalArgumentException(ex);
    } catch (ArtifactNotFoundException ex) {
        throw new IllegalArgumentException(ex);
    }
    return artifact;
}

From source file:de.berlios.jsunit.maven2.stub.SimpleMavenProjectStub.java

License:Apache License

/**
 * Create an artifact/*ww w .  ja  v  a 2s  . c  om*/
 * 
 * @param groupId the groupId
 * @param artifactId the artifactId
 * @param version the version
 * @param type the type
 * @param classifier the classifier
 * @param file the file itself
 * @return the artifact
 */
protected Artifact createArtifact(final String groupId, final String artifactId, final String version,
        final String type, final String classifier, final File file) {
    final Artifact artifact = new DefaultArtifact(groupId, artifactId, VersionRange.createFromVersion(version),
            "compile", type, classifier, new DefaultArtifactHandler(type));
    if (file != null) {
        artifact.setFile(file);
    }

    return artifact;
}

From source file:de.jiac.micro.mojo.ConfiguratorMojo.java

License:Open Source License

private Set transitivelyResolvePomDependencies(String groupId, String artifactId, String version)
        throws ProjectBuildingException, InvalidDependencyVersionException, ArtifactResolutionException,
        ArtifactNotFoundException {//w w w . j  a v a2 s.  co  m
    //get the pom as an Artifact 
    Artifact pomArtifact = artifactFactory.createPluginArtifact(groupId, artifactId,
            VersionRange.createFromVersion(version));

    //load the pom as a MavenProject
    MavenProject tempProject = mavenProjectBuilder.buildFromRepository(pomArtifact, remoteRepositories,
            localRepository);

    //get all of the dependencies for the project
    List dependencies = tempProject.getDependencies();

    //make Artifacts of all the dependencies
    Set dependencyArtifacts = MavenMetadataSource.createArtifacts(artifactFactory, dependencies, null, null,
            null);

    //not forgetting the Artifact of the project itself
    dependencyArtifacts.add(tempProject.getArtifact());

    //resolve all dependencies transitively to obtain a comprehensive list of jars        
    ArtifactResolutionResult result = artifactResolver.resolveTransitively(dependencyArtifacts, pomArtifact,
            Collections.EMPTY_MAP, localRepository, remoteRepositories, metadataSource, null,
            Collections.EMPTY_LIST);

    return result.getArtifacts();
}

From source file:fr.brouillard.oss.jgitver.JGitverExtension.java

License:Apache License

@Override
public void afterProjectsRead(MavenSession mavenSession) throws MavenExecutionException {
    MavenProject rootProject = mavenSession.getTopLevelProject();
    List<MavenProject> projects = locateProjects(mavenSession, rootProject.getModules());

    Map<GAV, String> newProjectVersions = new LinkedHashMap<>();

    if (JGitverModelProcessor.class.isAssignableFrom(modelProcessor.getClass())) {
        JGitverModelProcessor jGitverModelProcessor = JGitverModelProcessor.class.cast(modelProcessor);
        JGitverModelProcessorWorkingConfiguration workingConfiguration = jGitverModelProcessor
                .getWorkingConfiguration();

        if (workingConfiguration == null) {
            logger.warn("");
            logger.warn("jgitver has changed!");
            logger.warn("");
            logger.warn(/*w ww .  j av a2  s. co m*/
                    "it now requires the usage of maven core extensions instead of standard plugin extensions.");
            logger.warn("The plugin must be now declared in a `.mvn/extensions.xml` file.");
            logger.warn("");
            logger.warn("    read https://github.com/jgitver/jgitver-maven-plugin for further information");
            logger.warn("");
            throw new MavenExecutionException("detection of jgitver old setting mechanism",
                    new IllegalStateException("jgitver must now use maven core extensions"));
        }

        newProjectVersions = workingConfiguration.getNewProjectVersions();
    } else {
        logger.info("jgitver-maven-plugin is about to change project(s) version(s)");

        String newVersion = null;
        try {
            newVersion = JGitverUtils
                    .calculateVersionForProject(rootProject, mavenSession.getUserProperties(), logger)
                    .getCalculatedVersion();
        } catch (IOException ex) {
            throw new MavenExecutionException("failure calculating version from git information", ex);
        }

        // Let's modify in memory resolved projects model
        for (MavenProject project : projects) {
            GAV projectGAV = GAV.from(project); // SUPPRESS CHECKSTYLE AbbreviationAsWordInName

            logger.debug("about to change in memory POM for: " + projectGAV);
            // First the project itself
            project.setVersion(newVersion);
            logger.debug("    version set to " + newVersion);
            VersionRange newVersionRange = VersionRange.createFromVersion(newVersion);
            project.getArtifact().setVersionRange(newVersionRange);
            logger.debug("    artifact version range set to " + newVersionRange);
            newProjectVersions.put(projectGAV, newVersion);

            // No need to worry about parent link, because model is in memory
        }

        try {
            JGitverUtils.attachModifiedPomFilesToTheProject(projects, newProjectVersions, mavenSession, logger);
        } catch (IOException | XmlPullParserException ex) {
            throw new MavenExecutionException("cannot attach updated POMs during project execution", ex);
        }
    }

    newProjectVersions.entrySet()
            .forEach(e -> logger.info("    " + e.getKey().toString() + " -> " + e.getValue()));
}

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

License:Open Source License

private Artifact getArtifact(MavenProject parent) {
    Artifact art = parent.getArtifact();
    if (art == null) {
        // happens for Maven 2.x
        DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler("pom");
        art = new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(),
                VersionRange.createFromVersion(parent.getVersion()), null, "pom", "", artifactHandler);
    }/*w ww .  ja v a  2s. c  om*/
    return art;
}