Java 如何扫描maven存储库?
我正在为eclipse开发一个代码共享插件(用于学士学位论文项目) 目前,我正在尝试扫描maven存储库并生成一个包列表 我可以使用maven.model类下载并解析pom.xml,但我无法确定哪些maven类负责解析archetype-catalog.xml 有没有非maven解析器 我可以扫描整个存储库树中的pom.xml文件吗 编辑:Java 如何扫描maven存储库?,java,maven,parsing,maven-indexer,Java,Maven,Parsing,Maven Indexer,我正在为eclipse开发一个代码共享插件(用于学士学位论文项目) 目前,我正在尝试扫描maven存储库并生成一个包列表 我可以使用maven.model类下载并解析pom.xml,但我无法确定哪些maven类负责解析archetype-catalog.xml 有没有非maven解析器 我可以扫描整个存储库树中的pom.xml文件吗 编辑: 我找到了nexus indexer,但我不知道如何使用它:(扫描我的本地存储库中的包会非常容易。在我共享任何东西之前,我会有大量重复的包需要考虑。因为昨天我
我找到了nexus indexer,但我不知道如何使用它:(扫描我的本地存储库中的包会非常容易。在我共享任何东西之前,我会有大量重复的包需要考虑。因为昨天我在我的存储库中构建了1.1.1-SNAPSHOT版本,而今天我在构建1.1.2-SNAPSHOT版本,两个版本的目录将共享同一个包年龄 现在,如果您想显示项目中使用的工件,可以使用依赖插件。在maven项目开始时,我最喜欢的两个命令是:
mvn dependency:tree
及
花了好长时间,但我终于找到了一个有效的例子 PlexusContainer plexus = new DefaultPlexusContainer(); NexusIndexer n = (NexusIndexer) plexus.lookup(NexusIndexer.class); IndexUpdater iu = (IndexUpdater) plexus.lookup(IndexUpdater.class); // DefaultNexusIndexer n = new DefaultNexusIndexer(); List indexCreators=new ArrayList(); // IndexingContext c = n.addIndexingContext("test", "test",new File( "/home/tomas/Desktop/test"),new File( "/home/tomas/Desktop/index"), "http://repository.jboss.org/", null); Directory tempIndexDirectory = new RAMDirectory(); // IndexCreator min = new MinimalArtifactInfoIndexCreator(); // MavenPluginArtifactInfoIndexCreator mavenPlugin = new MavenPluginArtifactInfoIndexCreator(); // MavenArchetypeArtifactInfoIndexCreator mavenArchetype = new MavenArchetypeArtifactInfoIndexCreator(); // JarFileContentsIndexCreator jar = new JarFileContentsIndexCreator(); // IndexCreator min = plexus.lookup( IndexCreator.class, MinimalArtifactInfoIndexCreator.ID ); IndexCreator mavenPlugin = plexus.lookup( IndexCreator.class, MavenPluginArtifactInfoIndexCreator.ID ); IndexCreator mavenArchetype = plexus.lookup( IndexCreator.class, MavenArchetypeArtifactInfoIndexCreator.ID ); IndexCreator jar = plexus.lookup( IndexCreator.class, JarFileContentsIndexCreator.ID ); indexCreators.add(min); indexCreators.add(mavenPlugin); indexCreators.add(mavenArchetype); indexCreators.add(jar); IndexingContext c = n.addIndexingContext( "temp", "test", new File("/home/tomas/Desktop/mavenTest"), tempIndexDirectory, "http://repository.jboss.org/maven2/", null, indexCreators ); IndexUpdateRequest ur=new IndexUpdateRequest(c); ur.setForceFullUpdate(true); iu.fetchAndUpdateIndex(ur); // for (String s : c.getAllGroups()) { // System.out.println(s); // } BooleanQuery q = new BooleanQuery(); q.add(n.constructQuery(ArtifactInfo.GROUP_ID, "*"), Occur.SHOULD); FlatSearchRequest request = new FlatSearchRequest(q); FlatSearchResponse response = n.searchFlat(request); for (ArtifactInfo a : response.getResults()) { String bUrl=url+a `enter code here`.groupId+"/"+a.artifactId+"/"+a.version+"/"; String fileName=a.artifactId+"-"+a.version; System.out.println(bUrl+fileName+"."+a.packaging); )} PlexusContainer-plexus=新的DefaultPlexusContainer(); NexusIndexer n=(NexusIndexer)plexus.lookup(NexusIndexer.class); IndexUpdater iu=(IndexUpdater)plexus.lookup(IndexUpdater.class); //DefaultNexusIndexer n=新的DefaultNexusIndexer(); List indexCreators=new ArrayList(); //IndexingContext c=n.addIndexingContext(“测试”、“测试”、新文件(“/home/tomas/Desktop/test”)、新文件(“/home/tomas/Desktop/index”)、”http://repository.jboss.org/“,空); 目录tempIndexDirectory=new-RAMDirectory(); //IndexCreator min=新的MinimalArtificationFoIndexCreator(); //MavenPluginArtifactInfoIndexCreator mavenPlugin=新的MavenPluginArtifactInfoIndexCreator(); //MavenArchetypeArtifactInfoIndexCreator mavenArchetype=新的MavenArchetypeArtifactInfoIndexCreator(); //JarFileContentsIndexCreator jar=新的JarFileContentsIndexCreator(); // IndexCreator min=plexus.lookup(IndexCreator.class,minimarArtificationFoIndexCreator.ID); IndexCreator mavenPlugin=plexus.lookup(IndexCreator.class,MavenPluginArtifactInfoIndexCreator.ID); IndexCreator mavenArchetype=plexus.lookup(IndexCreator.class,MavenArchetypeArtifactInfoIndexCreator.ID); IndexCreator jar=plexus.lookup(IndexCreator.class,JarFileContentsIndexCreator.ID); 添加(最小值); 添加(mavenPlugin); add(mavenArchetype); 添加(jar); IndexingContext c=n.addIndexingContext( “临时工”, “测试”, 新文件(“/home/tomas/Desktop/mavenTest”), 临时索引目录, "http://repository.jboss.org/maven2/", 无效的 非激励器); IndexUpdateRequest ur=新的IndexUpdateRequest(c); ur.SETLUPDATE(真); iu.fetchAndUpdateIndex(ur); //for(字符串s:c.getAllGroups()){ //系统输出打印项次; // } BooleanQuery q=新的BooleanQuery(); q、 添加(n.constructQuery(ArtifactInfo.GROUP_ID,“*”),出现。应); FlatSearchRequest请求=新的FlatSearchRequest(q); FlatSearchResponse响应=n.searchFlat(请求); for(ArtifactInfo a:response.getResults()){ String bUrl=url+a `在此处输入代码“.groupId+”/“+a.artifactId+”/“+a.version+”/”; 字符串文件名=a.artifactId+“-”+a.version; System.out.println(bUrl+fileName+“+a.packaging);
)}作为将来的参考,nexus indexer一直被称为
maven indexer
。有一个项目,该项目也列在上,感谢您的回复,但我需要扫描远程存储库并将结果保存到数据库中,以便以后可以搜索,最终结果是rem的类层次结构ote存储库?最终结果应该是所有人工制品的列表。
PlexusContainer plexus = new DefaultPlexusContainer();
NexusIndexer n = (NexusIndexer) plexus.lookup(NexusIndexer.class);
IndexUpdater iu = (IndexUpdater) plexus.lookup(IndexUpdater.class);
// DefaultNexusIndexer n = new DefaultNexusIndexer();
List indexCreators=new ArrayList();
// IndexingContext c = n.addIndexingContext("test", "test",new File( "/home/tomas/Desktop/test"),new File( "/home/tomas/Desktop/index"), "http://repository.jboss.org/", null);
Directory tempIndexDirectory = new RAMDirectory();
// IndexCreator min = new MinimalArtifactInfoIndexCreator();
// MavenPluginArtifactInfoIndexCreator mavenPlugin = new MavenPluginArtifactInfoIndexCreator();
// MavenArchetypeArtifactInfoIndexCreator mavenArchetype = new MavenArchetypeArtifactInfoIndexCreator();
// JarFileContentsIndexCreator jar = new JarFileContentsIndexCreator();
//
IndexCreator min = plexus.lookup( IndexCreator.class, MinimalArtifactInfoIndexCreator.ID );
IndexCreator mavenPlugin = plexus.lookup( IndexCreator.class, MavenPluginArtifactInfoIndexCreator.ID );
IndexCreator mavenArchetype = plexus.lookup( IndexCreator.class, MavenArchetypeArtifactInfoIndexCreator.ID );
IndexCreator jar = plexus.lookup( IndexCreator.class, JarFileContentsIndexCreator.ID );
indexCreators.add(min);
indexCreators.add(mavenPlugin);
indexCreators.add(mavenArchetype);
indexCreators.add(jar);
IndexingContext c = n.addIndexingContext(
"temp",
"test",
new File("/home/tomas/Desktop/mavenTest"),
tempIndexDirectory,
"http://repository.jboss.org/maven2/",
null,
indexCreators );
IndexUpdateRequest ur=new IndexUpdateRequest(c);
ur.setForceFullUpdate(true);
iu.fetchAndUpdateIndex(ur);
// for (String s : c.getAllGroups()) {
// System.out.println(s);
// }
BooleanQuery q = new BooleanQuery();
q.add(n.constructQuery(ArtifactInfo.GROUP_ID, "*"), Occur.SHOULD);
FlatSearchRequest request = new FlatSearchRequest(q);
FlatSearchResponse response = n.searchFlat(request);
for (ArtifactInfo a : response.getResults()) {
String bUrl=url+a
`enter code here`.groupId+"/"+a.artifactId+"/"+a.version+"/";
String fileName=a.artifactId+"-"+a.version;
System.out.println(bUrl+fileName+"."+a.packaging);
)}