Example usage for org.apache.maven.artifact Artifact setResolved

List of usage examples for org.apache.maven.artifact Artifact setResolved

Introduction

In this page you can find the example usage for org.apache.maven.artifact Artifact setResolved.

Prototype

void setResolved(boolean resolved);

Source Link

Usage

From source file:com.alibaba.citrus.maven.eclipse.base.ide.IdeUtils.java

License:Apache License

/**
 * Wrapper around {@link ArtifactResolver#resolve(Artifact, List, ArtifactRepository)}
 *
 * @param artifactResolver see {@link ArtifactResolver#resolve(Artifact, List, ArtifactRepository)}
 * @param artifact         see {@link ArtifactResolver#resolve(Artifact, List, ArtifactRepository)}
 * @param remoteRepos      see {@link ArtifactResolver#resolve(Artifact, List, ArtifactRepository)}
 * @param localRepository  see {@link ArtifactResolver#resolve(Artifact, List, ArtifactRepository)}
 * @param log              Logger//from   w  ww  .  ja  va  2  s  . c  o  m
 * @return the artifact, resolved if possible.
 */
public static Artifact resolveArtifact(ArtifactResolver artifactResolver, Artifact artifact, List remoteRepos,
        ArtifactRepository localRepository, Log log)

{
    try {
        artifactResolver.resolve(artifact, remoteRepos, localRepository);
    } catch (ArtifactNotFoundException e) {
        // ignore, the jar has not been found

        /*
         * This method gets called with no remote repositories to avoid remote trips (which would ideally be
         * realized by means of a per-request offline flag), the set of available remote repos can however affect
         * the resolution from the local repo as well, in particular in Maven 3. So double check whether the local
         * file is really not present.
         */
        if (artifact.getFile() != null && artifact.getFile().isFile()) {
            artifact.setResolved(true);
        }
    } catch (ArtifactResolutionException e) {
        String message = Messages.getString("IdeUtils.errorresolving",
                new Object[] { artifact.getClassifier(), artifact.getId(), e.getMessage() });

        log.warn(message);
    }

    return artifact;
}

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);//  ww  w  .  java 2  s  .c o  m
    fact.setResolved(true);
    project.getDependencyArtifacts().add(fact);
}

From source file:com.moss.launch.mojo.LaunchSpecMojo.java

License:Open Source License

protected void handleApplet(File next, File outputLocation) throws Exception {
    if (!outputLocation.getParentFile().exists() && !outputLocation.getParentFile().mkdirs()) {
        throw new IOException(
                "Could not create directory: " + outputLocation.getParentFile().getAbsolutePath());
    }//from  w w w .  j  a  v a2  s .com
    getLog().info("Processing launch file: " + next.getAbsolutePath());

    // ATTACH THE ARTIFACT
    JavaAppletSpec spec = helper().readFromFile(next);
    {
        String name = spec.name();
        if (name == null || name.trim().length() == 0) {
            if (next.getName().equals(JavaAppletSpec.FILE_EXTENSION)) {
                name = "";
            } else {
                name = next.getName().substring(0,
                        next.getName().lastIndexOf(JavaAppletSpec.DOT_FILE_EXTENSION));
            }
        }

        getLog().info("Using name: " + name);
        Artifact artifact = artifactFactory.createArtifactWithClassifier(project.getGroupId(),
                project.getArtifactId(), project.getVersion(), JavaAppletSpec.FILE_EXTENSION, name);
        artifact.setFile(outputLocation);
        artifact.setResolved(true);
        project.addAttachedArtifact(artifact);
    }

    spec.components().addAll(getDependencies(true));

    getLog().info("Writing to " + outputLocation.getAbsolutePath());
    helper().writeToFile(helper().writeToXmlString(spec), outputLocation);
}

From source file:com.moss.launch.mojo.LaunchSpecMojo.java

License:Open Source License

protected void handleApp(File next, File outputLocation) throws Exception {
    if (!outputLocation.getParentFile().exists() && !outputLocation.getParentFile().mkdirs()) {
        throw new IOException(
                "Could not create directory: " + outputLocation.getParentFile().getAbsolutePath());
    }/* w  ww  . j ava2 s .com*/
    getLog().info("Processing launch file: " + next.getAbsolutePath());

    // ATTACH THE ARTIFACT
    JavaAppSpec spec = helper().readFromFile(next);
    {
        String name = spec.name();
        if (name == null || name.trim().length() == 0) {
            if (next.getName().equals(JavaAppSpec.FILE_EXTENSION)) {
                name = "";
            } else {
                name = next.getName().substring(0, next.getName().lastIndexOf(JavaAppSpec.DOT_FILE_EXTENSION));
            }
        }
        getLog().info("Using name: " + name);

        Artifact artifact = artifactFactory.createArtifactWithClassifier(project.getGroupId(),
                project.getArtifactId(), project.getVersion(), JavaAppSpec.FILE_EXTENSION, name);
        artifact.setFile(outputLocation);
        artifact.setResolved(true);
        project.addAttachedArtifact(artifact);
    }

    spec.components().addAll(getDependencies(true));

    getLog().info("Writing to " + outputLocation.getAbsolutePath());
    helper().writeToFile(helper().writeToXmlString(spec), outputLocation);
}

From source file:com.puppetlabs.geppetto.forge.maven.plugin.Package.java

License:Open Source License

@Override
protected void invoke(Diagnostic result) throws Exception {
    Collection<File> moduleRoots = findModuleRoots();
    if (moduleRoots.isEmpty()) {
        result.addChild(new Diagnostic(ERROR, PACKAGE, "No modules found in repository"));
        return;//from w ww  .  java 2s. c o  m
    }

    File buildDir = getBuildDir();
    buildDir.mkdirs();
    if (moduleRoots.size() == 1) {
        MavenProject project = getProject();
        File moduleRoot = moduleRoots.iterator().next();
        Metadata[] resultingMetadata = new Metadata[1];
        byte[][] resultingMD5 = new byte[1][];
        project.getArtifact()
                .setFile(buildForge(moduleRoot, buildDir, resultingMetadata, resultingMD5, result));

        Artifact pmriArtifact = repositorySystem.createArtifact(project.getGroupId(), project.getArtifactId(),
                project.getVersion(), "compile", "pmri");

        PuppetModuleReleaseInfo pmri = new PuppetModuleReleaseInfo();
        pmri.setMetadata(resultingMetadata[0]);
        pmri.populate(moduleRoot);

        File pmriFile = new File(buildDir, "release.pmri");
        OutputStream out = new FileOutputStream(pmriFile);
        try {
            Writer writer = new BufferedWriter(new OutputStreamWriter(out, Charsets.UTF_8));
            getGson().toJson(pmri, writer);
            writer.flush();
        } finally {
            out.close();
        }
        pmriArtifact.setFile(pmriFile);
        pmriArtifact.setResolved(true);
        project.addAttachedArtifact(pmriArtifact);
    } else {
        File builtModules = new File(buildDir, "builtModules");
        if (!(builtModules.mkdir() || builtModules.isDirectory())) {
            result.addChild(
                    new Diagnostic(ERROR, PACKAGE, "Unable to create directory" + builtModules.getPath()));
            return;
        }
        for (File moduleRoot : moduleRoots)
            buildForge(moduleRoot, builtModules, null, null, result);
    }
}

From source file:npanday.resolver.NPandayResolutionCache.java

License:Apache License

public Boolean applyTo(Artifact artifact) {
    String key = artifact.getId();
    if (cache.containsKey(key)) {
        File resolvedFile = cache.get(key);
        if (resolvedFile != null) {
            artifact.setFile(resolvedFile);
            artifact.setResolved(true);
        }/* www.jav  a2  s  .  c o  m*/
        return true;
    }
    return false;
}

From source file:npanday.resolver.resolvers.ComReferenceResolver.java

License:Apache License

public void tryResolve(Artifact artifact, Set<Artifact> additionalDependenciesCollector,
        ArtifactFilter filter) {//from  w w  w .j av a  2 s  .  c  o m
    // resolve com reference
    // flow:
    // 1. generate the interop dll in temp folder and resolve to that path during dependency resolution
    // 2. cut and paste the dll to buildDirectory and update the paths once we grab the reference of
    // MavenProject (CompilerContext.java)
    if (ArtifactTypeHelper.isComReference(artifact.getType())) {
        if (cache.applyTo(artifact)) {
            return;
        }

        String tokenId = artifact.getClassifier();
        String interopPath;
        try {
            interopPath = generateInteropDll(artifact.getArtifactId(), tokenId);
        } catch (IOException e) {
            getLogger().error("NPANDAY-150-002: Error creating interop dll for " + artifact.getId());
            return;
        }

        File f = new File(interopPath);

        if (!f.exists()) {
            getLogger().error("NPANDAY-150-001: Dependency com_reference File not found:" + interopPath
                    + " for " + artifact.getId());
            return;
        }

        artifact.setFile(f);
        artifact.setResolved(true);
        cache.put(artifact);
    }
}

From source file:npanday.resolver.resolvers.GacResolver.java

License:Apache License

public void tryResolve(Artifact artifact, Set<Artifact> additionalDependenciesCollector, ArtifactFilter filter)
        throws ArtifactNotFoundException {

    File artifactFile = null;//from   www .jav  a 2  s.c  o  m
    String artifactType = artifact.getType();

    if (ArtifactTypeHelper.isDotnetAnyGac(artifactType)) {
        if (cache.applyTo(artifact)) {
            return;
        }

        if (!ArtifactTypeHelper.isDotnet4Gac(artifactType)) {
            artifactFile = PathUtil.getGlobalAssemblyCacheFileFor(artifact,
                    new File("C:\\WINDOWS\\assembly\\"));
        } else {
            artifactFile = PathUtil.getGACFile4Artifact(artifact);
        }

        if (artifactFile.exists()) {
            artifact.setFile(artifactFile);
            artifact.setResolved(true);
            cache.put(artifact);
        } else {
            throw new ArtifactNotFoundException(
                    "NPANDAY-158-001: Could not resolve gac-dependency " + artifact + ", tried " + artifactFile,
                    artifact);
        }
    }

}

From source file:org.codehaus.mojo.nbm.AbstractNbmMojo.java

License:Apache License

private void checkReactor(Artifact art, Artifact nbmArt) {
    if (art.getFile().getName().endsWith(".jar")) {
        String name = art.getFile().getName();
        name = name.substring(0, name.length() - ".jar".length()) + ".nbm";
        File fl = new File(art.getFile().getParentFile(), name);
        if (fl.exists()) {
            nbmArt.setFile(fl);// w ww  . j  a v  a 2s . c  o m
            nbmArt.setResolved(true);
        }
    }
}

From source file:org.codehaus.mojo.nbm.PopulateRepositoryMojo.java

License:Apache License

Artifact createAttachedArtifact(Artifact primary, File file, String type, String classifier) {
    assert type != null;

    ArtifactHandler handler = null;/* ww w. j a va2 s.co  m*/

    handler = artifactHandlerManager.getArtifactHandler(type);

    if (handler == null) {
        getLog().warn("No artifact handler for " + type);
        handler = artifactHandlerManager.getArtifactHandler("jar");
    }

    Artifact artifact = new AttachedArtifact(primary, type, classifier, handler);

    artifact.setFile(file);
    artifact.setResolved(true);
    return artifact;
}