List of usage examples for org.apache.maven.artifact Artifact setScope
void setScope(String scope);
From source file:com.actility.maven.plugin.cocoon.ClassifierTypeTranslator.java
License:Apache License
public Set<Artifact> translate(Set<Artifact> artifacts, Log log) { Set<Artifact> results = artifacts; log.debug("Translating Artifacts using Classifier: " + this.classifier + " and Type: " + this.type); results = new HashSet<Artifact>(); for (Artifact artifact : artifacts) { // this translator must pass both type and classifier here so we // will use the // base artifact value if null comes in String useType = null;/*from ww w .j a v a 2 s . c o m*/ if (StringUtils.isNotEmpty(this.type)) { useType = this.type; } else { useType = artifact.getType(); } String useClassifier = null; if (StringUtils.isNotEmpty(this.classifier)) { useClassifier = this.classifier; } else { useClassifier = artifact.getClassifier(); } // Create a new artifact Artifact newArtifact = factory.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), useType, useClassifier); // note the new artifacts will always have the scope set to null. We // should // reset it here so that it will pass other filters if needed newArtifact.setScope(artifact.getScope()); results.add(newArtifact); } return results; }
From source file:com.adviser.maven.GraphArtifactCollector.java
License:Apache License
private void checkScopeUpdate(ResolutionNode farthest, ResolutionNode nearest, List listeners) { boolean updateScope = false; Artifact farthestArtifact = farthest.getArtifact(); Artifact nearestArtifact = nearest.getArtifact(); if (Artifact.SCOPE_RUNTIME.equals(farthestArtifact.getScope()) && (Artifact.SCOPE_TEST.equals(nearestArtifact.getScope()) || Artifact.SCOPE_PROVIDED.equals(nearestArtifact.getScope()))) { updateScope = true;/*from ww w . ja v a 2 s . c om*/ } if (Artifact.SCOPE_COMPILE.equals(farthestArtifact.getScope()) && !Artifact.SCOPE_COMPILE.equals(nearestArtifact.getScope())) { updateScope = true; } // current POM rules all if (nearest.getDepth() < 2 && updateScope) { updateScope = false; fireEvent(ResolutionListener.UPDATE_SCOPE_CURRENT_POM, listeners, nearest, farthestArtifact); } if (updateScope) { fireEvent(ResolutionListener.UPDATE_SCOPE, listeners, nearest, farthestArtifact); // previously we cloned the artifact, but it is more effecient to // just update the scope // if problems are later discovered that the original object needs // its original scope value, cloning may // again be appropriate nearestArtifact.setScope(farthestArtifact.getScope()); } }
From source file:com.atlassian.maven.plugin.clover.CloverInstrumentInternalMojo.java
License:Apache License
/** * @param outDir - output directory for temporary artifacts *///from w w w . j a v a 2 s . co m private void injectGrover(final File outDir) { if (skipGroverJar) { getLog().info( "Generation of Clover Groovy configuration is disabled. No Groovy instrumentation will occur."); return; } // create the groovy config for Clover's ASTTransformer InstrumentationConfig config = new InstrumentationConfig(); config.setProjectName(this.getProject().getName()); config.setInitstring(this.resolveCloverDatabase()); config.setTmpDir(outDir); final List<File> includeFiles = calcIncludedFilesForGroovy(); getLog().debug("Clover including the following files for Groovy instrumentation: " + includeFiles); config.setIncludedFiles(includeFiles); config.setEnabled(true); config.setEncoding(getEncoding()); //Don't pass in an instance of DistributedCoverage because it can't be deserialised //by Grover (ClassNotFoundException within the groovyc compiler) config.setDistributedConfig(getDistributedCoverage() == null ? null : new DistributedConfig(getDistributedCoverage().getConfigString())); try { File groverJar = GroovycSupport.extractGroverJar(this.groverJar, false); File groverConfigDir = GroovycSupport.newConfigDir(config, new File(getProject().getBuild().getOutputDirectory())); final Resource groverConfigResource = new Resource(); groverConfigResource.setDirectory(groverConfigDir.getPath()); getProject().addResource(groverConfigResource); // get the clover artifact, and use the same version number for grover... Artifact cloverArtifact = findCloverArtifact(this.pluginArtifacts); // add grover to the compilation classpath final Artifact groverArtifact = artifactFactory.createBuildArtifact(cloverArtifact.getGroupId(), "grover", cloverArtifact.getVersion(), "jar"); groverArtifact.setFile(groverJar); groverArtifact.setScope(Artifact.SCOPE_SYSTEM); addArtifactDependency(groverArtifact); } catch (IOException e) { getLog().error( "Could not create Clover Groovy configuration file. No Groovy instrumentation will occur. " + e.getMessage(), e); } }
From source file:com.atlassian.maven.plugin.clover.CloverInstrumentInternalMojo.java
License:Apache License
protected Set<Artifact> swizzleCloverDependencies(final Set<Artifact> artifacts) { Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>(); for (Artifact artifact : artifacts) { // Do not try to find Clovered versions for artifacts with classifiers. This is because Maven only // supports a single classifier per artifact and thus if we replace the original classifier with // a Clover classifier the artifact will fail to perform properly as intended originally. This is a // limitation. if (artifact.getClassifier() == null) { Artifact cloveredArtifact = this.artifactFactory.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), "clover"); // Try to resolve the artifact with a clover classifier. If it doesn't exist, simply add the original // artifact. If found, use the clovered artifact. try { this.artifactResolver.resolve(cloveredArtifact, new ArrayList(), localRepository); // Set the same scope as the main artifact as this is not set by createArtifactWithClassifier. cloveredArtifact.setScope(artifact.getScope()); // Check the timestamp of the artifact. If the found clovered version is older than the // non-clovered one we need to use the non-clovered version. This is to handle use case such as: // - Say you have a module B that depends on a module A // - You run Clover on A // - You make modifications on A such that B would fail if not built with the latest version of A // - You try to run the Clover plugin on B. The build would fail if we didn't pick the latest // version between the original A version and the clovered version. // // We provide a 'fudge-factor' of 2 seconds, as the clover artifact is created first. if (cloveredArtifact.getFile().lastModified() + cloveredArtifactExpiryInMillis < artifact .getFile().lastModified()) { getLog().warn("Using [" + artifact.getId() + "], built on " + new Date(artifact.getFile().lastModified()) + " even though a Clovered version exists " + "but it's older (lastModified: " + new Date(cloveredArtifact.getFile().lastModified()) + " ) and could fail the build. Please consider running Clover again on that " + "dependency's project."); resolvedArtifacts.add(artifact); } else { resolvedArtifacts.add(cloveredArtifact); }/* ww w .j av a2 s .c o m*/ } catch (ArtifactResolutionException e) { getLog().warn("Skipped dependency [" + artifact.getId() + "] due to resolution error: " + e.getMessage()); resolvedArtifacts.add(artifact); } catch (ArtifactNotFoundException e) { getLog().debug("Skipped dependency [" + artifact.getId() + "] as the clovered artifact could not be found"); resolvedArtifacts.add(artifact); } } else { getLog().debug("Skipped dependency [" + artifact.getId() + "] as it has a classifier"); resolvedArtifacts.add(artifact); } } return resolvedArtifacts; }
From source file:com.coderplus.apacheutils.translators.ClassifierTypeTranslator.java
License:Apache License
public Set<Artifact> translate(Set<Artifact> artifacts) { Set<Artifact> results;/*from w w w. j av a2 s. c om*/ results = new HashSet<Artifact>(); for (Artifact artifact : artifacts) { // this translator must pass both type and classifier here so we // will use the // base artifact value if null comes in String useType; if (StringUtils.isNotEmpty(this.type)) { useType = this.type; } else { useType = artifact.getType(); } String useClassifier; if (StringUtils.isNotEmpty(this.classifier)) { useClassifier = this.classifier; } else { useClassifier = artifact.getClassifier(); } // Create a new artifact Artifact newArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), Artifact.SCOPE_COMPILE, useType, useClassifier, new DefaultArtifactHandler(useType)); // note the new artifacts will always have the scope set to null. We // should // reset it here so that it will pass other filters if needed newArtifact.setScope(artifact.getScope()); results.add(newArtifact); } return results; }
From source file:com.github.ferstl.depgraph.dependency.DependencyNode.java
License:Apache License
private DependencyNode(Artifact artifact, NodeResolution resolution) { if (artifact == null) { throw new NullPointerException("Artifact must not be null"); }//from w w w.j a v a 2s .c om // FIXME: better create a copy of the artifact and set the missing attributes there. if (artifact.getScope() == null) { artifact.setScope("compile"); } this.scopes = new TreeSet<>(); this.artifact = artifact; this.resolution = resolution; this.scopes.add(artifact.getScope()); }
From source file:com.github.ferstl.depgraph.DependencyNodeAdapter.java
License:Apache License
private DependencyNodeAdapter(Artifact artifact, NodeResolution resolution) { if (artifact == null) { throw new NullPointerException("Artifact must not be null"); }//from w w w.j a v a 2 s. c o m // FIXME: better create a copy of the artifact and set the scope there. if (artifact.getScope() == null) { artifact.setScope("compile"); } this.artifact = artifact; this.resolution = resolution; }
From source file:com.github.ferstl.depgraph.graph.GraphNode.java
License:Apache License
private GraphNode(Artifact artifact, NodeResolution resolution) { if (artifact == null) { throw new NullPointerException("Artifact must not be null"); }//from w w w . java 2 s . c o m // FIXME: better create a copy of the artifact and set the missing attributes there. if (artifact.getScope() == null) { artifact.setScope("compile"); } this.scopes = new TreeSet<>(); this.artifact = artifact; this.resolution = resolution; this.scopes.add(artifact.getScope()); }
From source file:com.linkedin.oneclick.hadoop.LauncherPlugin.java
License:Apache License
static void convert(LauncherConfig.Artifact src, Artifact dest) { dest.setGroupId(src.getGroupId());/*ww w . java 2s .com*/ dest.setArtifactId(src.getArtifactId()); dest.setVersion(src.getVersion()); dest.setFile(src.getFile()); dest.setScope(src.getScope()); }
From source file:guru.nidi.maven.tools.dependency.DotCreator.java
License:Apache License
private Collection<Artifact> calcDependencies(Artifact artifact) { artifact.setScope(null); final ArtifactResolutionResult res = mavenContext.resolveArtifact(artifact, parameters); for (Iterator<Artifact> it = res.getArtifacts().iterator(); it.hasNext();) { final Artifact a = it.next(); if (a.equals(artifact) || !parameters.include(a) || a.getDependencyTrail().size() != 2) { it.remove();// www . j a v a 2s . c om } } if (res.getArtifacts().isEmpty() && !res.getMissingArtifacts().isEmpty()) { return null; } return res.getArtifacts(); }