List of usage examples for org.apache.maven.artifact Artifact SCOPE_SYSTEM
String SCOPE_SYSTEM
To view the source code for org.apache.maven.artifact Artifact SCOPE_SYSTEM.
Click Source Link
From source file:com.adviser.maven.GraphArtifactCollector.java
License:Apache License
private void recurse(ResolutionNode node, Map resolvedArtifacts, Map managedVersions, ArtifactRepository localRepository, List remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, List listeners) throws CyclicDependencyException, ArtifactResolutionException, OverConstrainedVersionException { fireEvent(ResolutionListener.TEST_ARTIFACT, listeners, node); // TODO: use as a conflict resolver Object key = node.getKey();/*from ww w .j a v a2 s.co m*/ if (managedVersions.containsKey(key)) { Artifact artifact = (Artifact) managedVersions.get(key); fireEvent(ResolutionListener.MANAGE_ARTIFACT, listeners, node, artifact); if (artifact.getVersion() != null) { node.getArtifact().setVersion(artifact.getVersion()); } if (artifact.getScope() != null) { node.getArtifact().setScope(artifact.getScope()); } } List previousNodes = (List) resolvedArtifacts.get(key); if (previousNodes != null) { node = checkPreviousNodes(node, listeners, previousNodes); } else { previousNodes = new ArrayList(); resolvedArtifacts.put(key, previousNodes); } previousNodes.add(node); if (node.isActive()) { fireEvent(ResolutionListener.INCLUDE_ARTIFACT, listeners, node); } // don't pull in the transitive deps of a system-scoped dependency. if (node.isActive() && !Artifact.SCOPE_SYSTEM.equals(node.getArtifact().getScope())) { fireEvent(ResolutionListener.PROCESS_CHILDREN, listeners, node); for (Iterator i = node.getChildrenIterator(); i.hasNext();) { ResolutionNode child = (ResolutionNode) i.next(); // We leave in optional ones, but don't pick up its dependencies if (!child.isResolved() && (!child.getArtifact().isOptional() || child.isChildOfRootNode())) { Artifact artifact = child.getArtifact(); try { if (artifact.getVersion() == null) { // set the recommended version // TODO: maybe its better to just pass the range // through to retrieval and use a transformation? ArtifactVersion version; version = getArtifactVersion(localRepository, remoteRepositories, source, artifact); artifact.selectVersion(version.toString()); fireEvent(ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child); } ResolutionGroup rGroup = source.retrieve(artifact, localRepository, remoteRepositories); // TODO might be better to have source.retreive() throw // a specific exception for this situation // and catch here rather than have it return null if (rGroup == null) { // relocated dependency artifact is declared // excluded, no need to add and recurse further continue; } child.addDependencies(rGroup.getArtifacts(), rGroup.getResolutionRepositories(), filter); } catch (CyclicDependencyException e) { // would like to throw this, but we have crappy stuff in // the repo fireEvent(ResolutionListener.OMIT_FOR_CYCLE, listeners, new ResolutionNode(e.getArtifact(), remoteRepositories, child)); } catch (ArtifactMetadataRetrievalException e) { artifact.setDependencyTrail(node.getDependencyTrail()); throw new ArtifactResolutionException( "Unable to get dependency information: " + e.getMessage(), artifact, e); } recurse(child, resolvedArtifacts, managedVersions, localRepository, remoteRepositories, source, filter, listeners); } } fireEvent(ResolutionListener.FINISH_PROCESSING_CHILDREN, listeners, node); } }
From source file:com.alibaba.citrus.maven.eclipse.base.ide.AbstractIdeSupportMojo.java
License:Apache License
/** * Resolve project dependencies. Manual resolution is needed in order to avoid resolution of multiproject artifacts * (if projects will be linked each other an installed jar is not needed) and to avoid a failure when a jar is * missing.//from w w w. j av a 2s .c om * * @return resolved IDE dependencies, with attached jars for non-reactor dependencies * @throws MojoExecutionException if dependencies can't be resolved */ protected IdeDependency[] doDependencyResolution() throws MojoExecutionException { if (ideDeps == null) { if (resolveDependencies) { MavenProject project = getProject(); ArtifactRepository localRepo = getLocalRepository(); List deps = getProject().getDependencies(); // Collect the list of resolved IdeDependencies. List dependencies = new ArrayList(); if (deps != null) { Map managedVersions = createManagedVersionMap(getArtifactFactory(), project.getId(), project.getDependencyManagement()); ArtifactResolutionResult artifactResolutionResult = null; try { List listeners = new ArrayList(); if (logger.isDebugEnabled()) { listeners.add(new DebugResolutionListener(logger)); } listeners.add(new WarningResolutionListener(logger)); artifactResolutionResult = artifactCollector.collect(getProjectArtifacts(), project.getArtifact(), managedVersions, localRepo, project.getRemoteArtifactRepositories(), getArtifactMetadataSource(), null, listeners); } catch (ArtifactResolutionException e) { getLog().debug(e.getMessage(), e); getLog().error( Messages.getString("AbstractIdeSupportMojo.artifactresolution", new Object[] { //$NON-NLS-1$ e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() })); // if we are here artifactResolutionResult is null, create a project without dependencies but // don't fail // (this could be a reactor projects, we don't want to fail everything) // Causes MECLIPSE-185. Not sure if it should be handled this way?? return new IdeDependency[0]; } // keep track of added reactor projects in order to avoid duplicates Set emittedReactorProjectId = new HashSet(); for (Iterator i = artifactResolutionResult.getArtifactResolutionNodes().iterator(); i .hasNext();) { ResolutionNode node = (ResolutionNode) i.next(); int dependencyDepth = node.getDepth(); Artifact art = node.getArtifact(); // don't resolve jars for reactor projects if (hasToResolveJar(art)) { try { artifactResolver.resolve(art, node.getRemoteRepositories(), localRepository); } catch (ArtifactNotFoundException e) { getLog().debug(e.getMessage(), e); getLog().warn(Messages.getString("AbstractIdeSupportMojo.artifactdownload", //$NON-NLS-1$ new Object[] { e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() })); } catch (ArtifactResolutionException e) { getLog().debug(e.getMessage(), e); getLog().warn(Messages.getString("AbstractIdeSupportMojo.artifactresolution", new Object[] { //$NON-NLS-1$ e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() })); } } boolean includeArtifact = true; if (getExcludes() != null) { String artifactFullId = art.getGroupId() + ":" + art.getArtifactId(); if (getExcludes().contains(artifactFullId)) { getLog().info("excluded: " + artifactFullId); includeArtifact = false; } } if (includeArtifact && (!(getUseProjectReferences() && isAvailableAsAReactorProject(art)) || emittedReactorProjectId.add(art.getGroupId() + '-' + art.getArtifactId()))) { // the following doesn't work: art.getArtifactHandler().getPackaging() always returns "jar" // also // if the packaging specified in pom.xml is different. // osgi-bundle packaging is provided by the felix osgi plugin // eclipse-plugin packaging is provided by this eclipse plugin // String packaging = art.getArtifactHandler().getPackaging(); // boolean isOsgiBundle = "osgi-bundle".equals( packaging ) || "eclipse-plugin".equals( // packaging ); // we need to check the manifest, if "Bundle-SymbolicName" is there the artifact can be // considered // an osgi bundle boolean isOsgiBundle = false; String osgiSymbolicName = null; if (art.getFile() != null) { JarFile jarFile = null; try { jarFile = new JarFile(art.getFile(), false, ZipFile.OPEN_READ); Manifest manifest = jarFile.getManifest(); if (manifest != null) { osgiSymbolicName = manifest.getMainAttributes() .getValue(new Attributes.Name("Bundle-SymbolicName")); } } catch (IOException e) { getLog().info("Unable to read jar manifest from " + art.getFile()); } finally { if (jarFile != null) { try { jarFile.close(); } catch (IOException e) { // ignore } } } } isOsgiBundle = osgiSymbolicName != null; IdeDependency dep = new IdeDependency(art.getGroupId(), art.getArtifactId(), art.getVersion(), art.getClassifier(), useProjectReference(art), Artifact.SCOPE_TEST.equals(art.getScope()), Artifact.SCOPE_SYSTEM.equals(art.getScope()), Artifact.SCOPE_PROVIDED.equals(art.getScope()), art.getArtifactHandler().isAddedToClasspath(), art.getFile(), art.getType(), isOsgiBundle, osgiSymbolicName, dependencyDepth, getProjectNameForArifact(art)); // no duplicate entries allowed. System paths can cause this problem. if (!dependencies.contains(dep)) { dependencies.add(dep); } } } // @todo a final report with the list of // missingArtifacts? } ideDeps = (IdeDependency[]) dependencies.toArray(new IdeDependency[dependencies.size()]); } else { ideDeps = new IdeDependency[0]; } } return ideDeps; }
From source file:com.alibaba.citrus.maven.eclipse.base.ide.AbstractIdeSupportMojo.java
License:Apache License
/** * Returns the list of project artifacts. Also artifacts generated from referenced projects will be added, but with * the <code>resolved</code> property set to true. * * @return list of projects artifacts//from w ww. j a v a2s. c o m * @throws MojoExecutionException if unable to parse dependency versions */ private Set getProjectArtifacts() throws MojoExecutionException { // [MECLIPSE-388] Don't sort this, the order should be identical to getProject.getDependencies() Set artifacts = new LinkedHashSet(); for (Iterator dependencies = getProject().getDependencies().iterator(); dependencies.hasNext();) { Dependency dependency = (Dependency) dependencies.next(); String groupId = dependency.getGroupId(); String artifactId = dependency.getArtifactId(); VersionRange versionRange; try { versionRange = VersionRange.createFromVersionSpec(dependency.getVersion()); } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException(Messages.getString("AbstractIdeSupportMojo.unabletoparseversion", //$NON-NLS-1$ new Object[] { dependency.getArtifactId(), dependency.getVersion(), dependency.getManagementKey(), e.getMessage() }), e); } String type = dependency.getType(); if (type == null) { type = Constants.PROJECT_PACKAGING_JAR; } String classifier = dependency.getClassifier(); boolean optional = dependency.isOptional(); String scope = dependency.getScope(); if (scope == null) { scope = Artifact.SCOPE_COMPILE; } Artifact art = getArtifactFactory().createDependencyArtifact(groupId, artifactId, versionRange, type, classifier, scope, optional); if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) { art.setFile(new File(dependency.getSystemPath())); } handleExclusions(art, dependency); artifacts.add(art); } return artifacts; }
From source file:com.atlassian.maven.plugin.clover.CloverInstrumentInternalMojo.java
License:Apache License
/** * @param outDir - output directory for temporary artifacts *//* ww w . j ava2 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.dooioo.se.lorik.apidoclet.maven.plugin.JavadocUtil.java
License:Apache License
/** * Copy from {@link org.apache.maven.project.MavenProject#getCompileArtifacts()} * @param artifacts not null//from www .j a va 2 s . co m * @param withTestScope flag to include or not the artifacts with test scope * @return list of compile artifacts with or without test scope. */ protected static List<Artifact> getCompileArtifacts(Set<Artifact> artifacts, boolean withTestScope) { List<Artifact> list = new ArrayList<Artifact>(artifacts.size()); for (Artifact a : artifacts) { // TODO: classpath check doesn't belong here - that's the other method if (a.getArtifactHandler().isAddedToClasspath()) { // TODO: let the scope handler deal with this if (withTestScope) { if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_PROVIDED.equals(a.getScope()) || Artifact.SCOPE_SYSTEM.equals(a.getScope()) || Artifact.SCOPE_TEST.equals(a.getScope())) { list.add(a); } } else { if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_PROVIDED.equals(a.getScope()) || Artifact.SCOPE_SYSTEM.equals(a.getScope())) { list.add(a); } } } } return list; }
From source file:com.github.zhve.ideaplugin.ArtifactDependencyResolver.java
License:Apache License
/** * Convert Dependency to Artifact//w w w . j av a 2 s . c o m * * @param artifactFactory standard Maven's factory to create artifacts * @param dependency dependency * @return artifact * @throws InvalidVersionSpecificationException if VersionRange is invalid */ private Artifact toDependencyArtifact(ArtifactFactory artifactFactory, Dependency dependency) throws InvalidVersionSpecificationException { // instantiate Artifact dependencyArtifact = artifactFactory.createDependencyArtifact(dependency.getGroupId(), dependency.getArtifactId(), VersionRange.createFromVersionSpec(dependency.getVersion()), dependency.getType(), dependency.getClassifier(), dependency.getScope() == null ? Artifact.SCOPE_COMPILE : dependency.getScope(), null, dependency.isOptional()); // apply exclusions is needed if (!dependency.getExclusions().isEmpty()) { List<String> exclusions = new ArrayList<String>(); for (Exclusion exclusion : dependency.getExclusions()) exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId()); dependencyArtifact.setDependencyFilter(new ExcludesArtifactFilter(exclusions)); } // additional if (Artifact.SCOPE_SYSTEM.equalsIgnoreCase(dependency.getScope())) dependencyArtifact.setFile(new File(dependency.getSystemPath())); return dependencyArtifact; }
From source file:com.jayway.maven.plugins.android.phase_prebuild.AarMavenLifecycleParticipant.java
License:Open Source License
private Dependency createSystemScopeDependency(Artifact artifact, File location) { final Dependency dependency = new Dependency(); dependency.setGroupId(artifact.getGroupId()); dependency.setArtifactId(artifact.getArtifactId()); dependency.setVersion(artifact.getVersion()); dependency.setScope(Artifact.SCOPE_SYSTEM); dependency.setSystemPath(location.getAbsolutePath()); return dependency; }
From source file:com.jayway.maven.plugins.android.phase_prebuild.ClasspathModifierLifecycleParticipant.java
License:Open Source License
private Dependency createSystemScopeDependency(Artifact artifact, File location, String suffix) { String artifactId = artifact.getArtifactId(); if (suffix != null) { artifactId = "_" + suffix; }//from w w w . jav a 2 s . c o m final Dependency dependency = new Dependency(); dependency.setGroupId(artifact.getGroupId()); dependency.setArtifactId(artifactId); dependency.setVersion(artifact.getVersion()); dependency.setScope(Artifact.SCOPE_SYSTEM); dependency.setSystemPath(location.getAbsolutePath()); return dependency; }
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);//w ww . j a v a2 s . c o m fact.setResolved(true); project.getDependencyArtifacts().add(fact); }
From source file:com.messapix.ftatr.jfxmobile.maven.plugin.android.AndroidConf.java
License:Apache License
private void configureDependencies(List<Dependency> dependencies) throws MojoExecutionException { // Add Android specific dependencies if (dependencies != null) { for (Dependency dependency : dependencies) { userArtifacts.add(artifactResolver.resolve(dependency)); }//from ww w . java 2 s . c om } Path unpackDir = artifactResolver.unpack(deps.multidex()); Dependency multidexJar = new Dependency(); multidexJar.setGroupId("com.messapix.ftatr.jfxmobile.system"); multidexJar.setArtifactId("multidex"); multidexJar.setVersion(mobileConf.getJavafxportsVersion()); multidexJar.setScope(Artifact.SCOPE_SYSTEM); multidexJar.setType("jar"); multidexJar.setSystemPath(unpackDir.resolve("classes.jar").toAbsolutePath().toString()); // Add Android building dependencies buildingArtifacts.add(artifactResolver.resolve(multidexJar)); buildingArtifacts.add(artifactResolver.resolve(deps.jfxrt())); buildingArtifacts.add(artifactResolver.resolve(deps.compat())); buildingArtifacts.add(artifactResolver.resolve(deps.android())); buildingArtifacts.add(artifactResolver.resolve(deps.jfxDvk())); }