从树数据结构打印纯文本树(java) [英] Print plain text tree from tree data structure (java)

查看:747
本文介绍了从树数据结构打印纯文本树(java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很喜欢

mvn dependency:tree

并希望打印一个外观相似的树作为普通的ascii文本作为我的java程序的输出。

and want to print a similar-looking tree as plain ascii text as output from my java program.

 com.totsp.gwt:maven-gwt-sample:war:1.0-SNAPSHOT
 +- com.google.gwt:gwt-servlet:jar:2.4.0:compile
 +- com.google.gwt:gwt-user:jar:2.4.0:provided
 |  +- javax.validation:validation-api:jar:1.0.0.GA:provided
 |  \- javax.validation:validation-api:jar:sources:1.0.0.GA:provided
 +- log4j:log4j:jar:1.2.14:compile
 \- junit:junit:jar:4.1:test

我希望能实现这一目标的库很容易使用,但我可以找不到。

I was hoping that the library that achieves this would be easily usable but I can't find it.

我看到的最接近的替代品是: http://code.google.com/p/j-text-utils/ 但它不如Maven那么好。

The closest substitute I see is this: http://code.google.com/p/j-text-utils/ but it's not as nice as Maven's.

我在哪里可以找到一个打印树结构的库作为与mvn依赖几乎完全相同的文本:树?

Where can I find a library that prints a tree structure as text almost identically to mvn dependency:tree?

推荐答案

我我不是创建/使用MOJO的专家,但如何下载并查看 maven-dependency-plugin

I'm not an expert of creating/using MOJOs, but how about downloading and taking a look on the maven-dependency-plugin?

将它作为依赖项添加到项目中是微不足道的(我想你是在管理它通过Maven),乍一看,你应该简单地打电话给 TreeMojo.execute()直接或类似的东西。

It's trivial to add it to your project as a dependency (I guess you're managing it by Maven), and on first sight, you should simply call TreeMojo.execute() directly or something like that.

大致上它是这样的:

ArtifactFilter artifactFilter = createResolvingArtifactFilter();
rootNode = dependencyTreeBuilder.buildDependencyTree( project,
        localRepository, artifactFactory, artifactMetadataSource,
        artifactFilter, artifactCollector );
String dependencyTreeString = serializeDependencyTree( rootNode );
DependencyUtil.log( dependencyTreeString, getLog() );

这就是您要搜索的内容吗?

Is that what you were searching for?

这篇关于从树数据结构打印纯文本树(java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆