org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor Java Examples
The following examples show how to use
org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FingerprintMojo.java From java-specialagent with Apache License 2.0 | 4 votes |
private CustomNodeVisitor(final DependencyNodeVisitor target) { this.target = target; }
Example #2
Source File: FingerprintMojo.java From java-specialagent with Apache License 2.0 | 4 votes |
@Override public DependencyNodeVisitor getSerializingDependencyNodeVisitor(final Writer writer) { final DependencyNodeVisitor visitor = super.getSerializingDependencyNodeVisitor(writer); return visitor instanceof TGFDependencyNodeVisitor ? new CustomNodeVisitor(visitor) : visitor; }
Example #3
Source File: NarProvidedDependenciesMojo.java From nifi-maven with Apache License 2.0 | 4 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { try { // find the nar dependency Artifact narArtifact = null; for (final Artifact artifact : project.getDependencyArtifacts()) { if (NAR.equals(artifact.getType())) { // ensure the project doesn't have two nar dependencies if (narArtifact != null) { throw new MojoExecutionException("Project can only have one NAR dependency."); } // record the nar dependency narArtifact = artifact; } } // ensure there is a nar dependency if (narArtifact == null) { throw new MojoExecutionException("Project does not have any NAR dependencies."); } // build the project for the nar artifact final ProjectBuildingRequest narRequest = new DefaultProjectBuildingRequest(); narRequest.setRepositorySession(repoSession); narRequest.setSystemProperties(System.getProperties()); final ProjectBuildingResult narResult = projectBuilder.build(narArtifact, narRequest); narRequest.setProject(narResult.getProject()); // get the artifact handler for excluding dependencies final ArtifactHandler narHandler = excludesDependencies(narArtifact); narArtifact.setArtifactHandler(narHandler); // nar artifacts by nature includes dependencies, however this prevents the // transitive dependencies from printing using tools like dependency:tree. // here we are overriding the artifact handler for all nars so the // dependencies can be listed. this is important because nar dependencies // will be used as the parent classloader for this nar and seeing what // dependencies are provided is critical. final Map<String, ArtifactHandler> narHandlerMap = new HashMap<>(); narHandlerMap.put(NAR, narHandler); artifactHandlerManager.addHandlers(narHandlerMap); // get the dependency tree final DependencyNode root = dependencyGraphBuilder.buildDependencyGraph(narRequest, null); // write the appropriate output DependencyNodeVisitor visitor = null; if ("tree".equals(mode)) { visitor = new TreeWriter(); } else if ("pom".equals(mode)) { visitor = new PomWriter(); } // ensure the mode was specified correctly if (visitor == null) { throw new MojoExecutionException("The specified mode is invalid. Supported options are 'tree' and 'pom'."); } // visit and print the results root.accept(visitor); getLog().info("--- Provided NAR Dependencies ---\n\n" + visitor.toString()); } catch (ProjectBuildingException | DependencyGraphBuilderException e) { throw new MojoExecutionException("Cannot build project dependency tree", e); } }