本文整理汇总了Java中org.apache.maven.shared.dependency.graph.DependencyNode类的典型用法代码示例。如果您正苦于以下问题:Java DependencyNode类的具体用法?Java DependencyNode怎么用?Java DependencyNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DependencyNode类属于org.apache.maven.shared.dependency.graph包,在下文中一共展示了DependencyNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printTree
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
/**
* Returns a multi-lined string representation of the path from the project root dependency to the provided node.
* @param node The dependency to draw the path to.
* @return The dependency tree path to the provided node from the root node. E.g.
* <pre>
* some.group.id:some.artifact.id:jar:1.0-SNAPSHOT
* └─ io.github.patrickpilch:some-module:jar:2.1.3
* └─ node.group.id:node.artifact.id:jar:node.version
* </pre>
*/
public static String printTree(final DependencyNode node) {
final List<DependencyNode> dependencyChain = createDependencyChain(node);
final StringBuilder treeBuilder = new StringBuilder();
treeBuilder.append(dependencyChain.get(0).getArtifact().getId());
for (int i = 1; i < dependencyChain.size(); i++) {
treeBuilder.append('\n');
for (int spaceRepetitions = 1; spaceRepetitions < i; spaceRepetitions++) {
treeBuilder.append(EMPTY);
}
treeBuilder.append(BRANCH)
.append(dependencyChain.get(i).getArtifact().getId());
}
return treeBuilder.toString();
}
示例2: checkDependency
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
private void checkDependency(final DependencyNode dependency) throws ProjectResolutionException, DependencyException {
log.debug("Checking dependency: " + dependency.getArtifact().getId());
if (!excludedArtifacts.contains(convertArtifactToExclusion(dependency.getArtifact()))) {
final List<License> licenses = getArtifactLicenses(dependency.getArtifact());
if (licenses.isEmpty()) {
throw new LicenseMissingException(dependency);
} else {
for (final License license : licenses) {
log.debug("Inspecting license - " + license.getName());
if (!whitelistedLicenses.contains(license.getName())) {
throw new LicenseNotAllowedException(dependency, license);
} else if (log.isDebugEnabled()) {
log.debug("\"" + dependency.getArtifact().getId() + "\" with license \"" + license.getName() +
"\" is good!");
}
}
}
} else if (log.isDebugEnabled()) {
log.debug(dependency.getArtifact().getId() + " is in artifact exclusions");
}
}
示例3: getAllDescendants
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
private Set<Artifact> getAllDescendants( DependencyNode node )
{
Set<Artifact> children = null;
if( node.getChildren() != null )
{
children = new HashSet<Artifact>();
for( DependencyNode depNode : node.getChildren() )
{
children.add( depNode.getArtifact() );
Set<Artifact> subNodes = getAllDescendants( depNode );
if( subNodes != null )
{
children.addAll( subNodes );
}
}
}
return children;
}
示例4: addPackageDependencies
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
/**
* Find all of the dependencies for a specified artifact
*/
private List<PackageDescriptor> addPackageDependencies(PackageDescriptor parent, String groupId, String artifactId, String version,
DependencyNode parentDep) {
List<PackageDescriptor> packageDependency = new LinkedList<PackageDescriptor>();
List<DependencyNode> children = parentDep.getChildren();
if (children != null) {
for (DependencyNode node : children) {
DependencyNodeVisitor nlg = new CollectingDependencyNodeVisitor();
node.accept(nlg);
List<DependencyNode> deps = ((CollectingDependencyNodeVisitor) nlg).getNodes();
for (DependencyNode dep : deps) {
Artifact artifact = dep.getArtifact();
PackageDescriptor pkgDep = new PackageDescriptor("maven", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
// Only include each package once. They might be transitive dependencies from multiple places.
if (!parents.containsKey(pkgDep)) {
pkgDep = request.add("maven", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
parents.put(pkgDep, parent);
packageDependency.add(pkgDep);
}
}
}
}
return packageDependency;
}
示例5: resolveTransitiveDependencies
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Set<Artifact> resolveTransitiveDependencies(Artifact artifact) throws EnforcerRuleException {
final DependencyNode root;
try {
root = dependencyGraphBuilder.buildDependencyGraph(project, null);
} catch (DependencyGraphBuilderException e) {
throw new EnforcerRuleException("Unable to build the dependency graph!", e);
}
if (logger.isDebugEnabled()) {
logger.debug("Root node is '" + root + "'.");
}
final Set<Artifact> transitiveDependencies = new HashSet<Artifact>();
traverseDependencyNodes(root, transitiveDependencies);
final Set<Artifact> directDependencies = resolveDirectDependencies(artifact);
transitiveDependencies.removeAll(directDependencies);
if (logger.isDebugEnabled()) {
logger.debug("Transitive dependencies are '" + transitiveDependencies + "'.");
}
return transitiveDependencies;
}
开发者ID:ImmobilienScout24,项目名称:illegal-transitive-dependency-check,代码行数:23,代码来源:IllegalTransitiveDependencyCheck.java
示例6: traverseDependencyNodes
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
private void traverseDependencyNodes(DependencyNode node, Set<Artifact> transitiveDependencies)
throws EnforcerRuleException {
final List<DependencyNode> children = node.getChildren();
if ((children == null) || children.isEmpty()) {
return;
}
for (DependencyNode child : children) {
final Artifact artifact = child.getArtifact();
enforceArtifactResolution(artifact);
if (logger.isDebugEnabled()) {
logger.debug("Add dependency '" + artifact.getId() + "'");
}
transitiveDependencies.add(artifact);
traverseDependencyNodes(child, transitiveDependencies);
}
}
开发者ID:ImmobilienScout24,项目名称:illegal-transitive-dependency-check,代码行数:17,代码来源:IllegalTransitiveDependencyCheck.java
示例7: visit
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
/**
* Visits all nodes from the given node and collects dependencies.
*
* @param node DependencyNode from which to search.
* @param collecting Whether we are currently collecting artifacts.
*/
public void visit( DependencyNode node, boolean collecting )
{
if ( collecting )
{
dependencies.add( node.getArtifact() );
}
if ( matchesTarget( node.getArtifact() ) )
{
collecting = true;
log.debug( "Found target. Collecting dependencies after " + node.getArtifact() );
}
for ( final DependencyNode child : node.getChildren() )
{
visit( child, collecting );
}
}
示例8: execute
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// Find the plugin in the project dependencies
final List<DependencyNode> projectChildren = resolveDependencies(getProject(), new FlumePluginDependencyArtifactFilter(dependency));
if (projectChildren.isEmpty()) {
throw new MojoFailureException(String.format("No dependency found matching %s in dependency list.", dependency.getFormattedIdentifier()));
} else if (projectChildren.size() > 1) {
throw new MojoFailureException(String.format("More than one dependency matching %s found in project dependencies: %s", dependency.getFormattedIdentifier(), projectChildren));
}
// Resolve the dependencies of the project we've located
final Artifact projectChildArtifact = projectChildren.get(0).getArtifact();
final File projectChildFile = getArtifactRepository().find(projectChildArtifact).getFile();
try {
buildFlumePluginArchive(projectChildFile, projectBuilder.buildFromRepository(projectChildArtifact, getRemoteArtifactRepositories(), getArtifactRepository()));
} catch (ProjectBuildingException e) {
throw new MojoExecutionException(String.format("Failed to resolve project for artifact %s", formatIdentifier(projectChildArtifact)), e);
}
}
示例9: CollectLibrariesNodeVisitor
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
/**
* Creates a dependency node visitor that collects visited nodes for further processing.
* @param explicitLibraries list of explicit libraries
* @param runtimeArtifacts list of runtime artifacts
* @param examinerCache cache of netbeans manifest for artifacts
* @param log mojo logger
* @param root dependency to start collect with
* @param useOsgiDependencies whether to allow osgi dependencies or not
*/
public CollectLibrariesNodeVisitor( List<String> explicitLibraries,
List<Artifact> runtimeArtifacts, Map<Artifact, ExamineManifest> examinerCache,
Log log, DependencyNode root, boolean useOsgiDependencies )
{
nodes = new ArrayList<Artifact>();
artifacts = new HashMap<String, Artifact>();
for ( Artifact a : runtimeArtifacts )
{
artifacts.put( a.getDependencyConflictId(), a );
}
this.examinerCache = examinerCache;
this.explicitLibs = explicitLibraries;
this.log = log;
this.root = root;
this.useOsgiDependencies = useOsgiDependencies;
duplicates = new HashSet<String>();
conflicts = new HashSet<String>();
includes = new HashSet<String>();
}
示例10: endVisit
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public boolean endVisit( DependencyNode node )
{
if ( throwable != null )
{
return false;
}
if ( node == root )
{
if ( nodes.size() > 0 )
{
log.info( "Adding on module's Class-Path:" );
for ( Artifact inc : nodes )
{
log.info( " " + inc.getId() );
}
}
}
return true;
}
示例11: CollectModuleLibrariesNodeVisitor
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
/**
* Creates a dependency node visitor that collects visited nodes for further processing.
* @param runtimeArtifacts list of runtime artifacts
* @param examinerCache cache of netbeans manifest for artifacts
* @param log mojo logger
* @param root dependency to start collect with
* @param useOSGiDependencies whether to allow osgi dependencies or not
*/
public CollectModuleLibrariesNodeVisitor(
List<Artifact> runtimeArtifacts, Map<Artifact, ExamineManifest> examinerCache,
Log log, DependencyNode root, boolean useOSGiDependencies )
{
directNodes = new HashMap<String, List<Artifact>>();
transitiveNodes = new HashMap<String, List<Artifact>>();
artifacts = new HashMap<String, Artifact>();
for ( Artifact a : runtimeArtifacts )
{
artifacts.put( a.getDependencyConflictId(), a );
}
this.examinerCache = examinerCache;
this.log = log;
this.root = root;
this.useOSGiDependencies = useOSGiDependencies;
}
示例12: getLibraryArtifacts
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
static List<Artifact> getLibraryArtifacts( DependencyNode treeRoot, NetBeansModule module,
List<Artifact> runtimeArtifacts,
Map<Artifact, ExamineManifest> examinerCache, Log log,
boolean useOsgiDependencies )
throws MojoExecutionException
{
List<Artifact> include = new ArrayList<Artifact>();
if ( module != null )
{
List<String> librList = new ArrayList<String>();
if ( module.getLibraries() != null )
{
librList.addAll( module.getLibraries() );
}
CollectLibrariesNodeVisitor visitor = new CollectLibrariesNodeVisitor( librList,
runtimeArtifacts, examinerCache, log, treeRoot, useOsgiDependencies );
treeRoot.accept( visitor );
include.addAll( visitor.getArtifacts() );
}
return include;
}
示例13: testGetLibraryArtifact5
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
/**
* transitive dependency of a library is a duplicate of a transitive dependency of a module
* ->doesn't get included.
* @throws java.lang.Exception if AbstractNbmMojo.getLibraryArtifacts fail
*/
public void testGetLibraryArtifact5() throws Exception {
System.out.println("getLibraryArtifacts5");
Map<Artifact, ExamineManifest> examinerCache = new HashMap<Artifact, ExamineManifest>();
List<Artifact> runtimes = new ArrayList<Artifact>();
DependencyNode module = createNode(treeRoot, "gr1", "ar1", "1.0", "jar", "compile", true, runtimes, examinerCache);
DependencyNode translibrary = createNode(module, "gr2", "ar2", "1.0", "jar", "runtime", false, runtimes, examinerCache);
((DefaultDependencyNode)module).setChildren( Collections.singletonList( translibrary ) );
DependencyNode library = createNode(treeRoot, "gr3", "ar3", "1.0", "jar", "compile", false, runtimes, examinerCache);
DependencyNode translibrary2 = createNode(library, "gr4", "ar4", "1.0", "jar", "runtime", false, runtimes, examinerCache);
((DefaultDependencyNode)library).setChildren( Collections.singletonList( translibrary2 ) );
treeRoot.setChildren( Arrays.asList( new DependencyNode[] { module, library}));
NetBeansModule mdl = new NetBeansModule();
List<Artifact> result = AbstractNbmMojo.getLibraryArtifacts(treeRoot, mdl, runtimes, examinerCache, log, false);
assertEquals(2, result.size());
assertEquals(result.get(0).getId(), library.getArtifact().getId());
assertEquals(result.get(1).getId(), translibrary2.getArtifact().getId());
}
示例14: dependencies
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
/**
* Retrieve dependencies for from given node and scope.
* @param node Node to traverse.
* @param scps Scopes to use.
* @return Collection of dependency files.
*/
private Collection<String> dependencies(final DependencyNode node,
final Collection<String> scps) {
final Artifact artifact = node.getArtifact();
final Collection<String> files = new LinkedList<String>();
if (artifact.getScope() == null
|| scps.contains(artifact.getScope())) {
if (artifact.getScope() == null) {
files.add(artifact.getFile().toString());
} else {
files.add(
this.session.getLocalRepository().find(artifact).getFile()
.toString()
);
}
for (final DependencyNode child : node.getChildren()) {
if (child.getArtifact().compareTo(node.getArtifact()) != 0) {
files.addAll(this.dependencies(child, scps));
}
}
}
return files;
}
示例15: root
import org.apache.maven.shared.dependency.graph.DependencyNode; //导入依赖的package包/类
/**
* Convert dependency to root artifact.
* @param dep Dependency
* @return Root artifact
*/
private MavenRootArtifact root(final Dependency dep) {
final DefaultArtifact artifact = new DefaultArtifact(
dep.getGroupId(),
dep.getArtifactId(),
dep.getVersion(),
dep.getScope(),
dep.getType(),
dep.getClassifier(),
new DefaultArtifactHandler()
);
try {
final Collection<Artifact> children = new LinkedList<Artifact>();
for (final DependencyNode child : this.graph().getChildren()) {
children.add(child.getArtifact());
}
return new MavenRootArtifact(
artifact,
dep.getExclusions(),
children
);
} catch (final DependencyGraphBuilderException ex) {
throw new IllegalStateException(ex);
}
}