java – 如何扫描maven存储库?

我正在为
eclipse开发一个代码共享插件(用于学士论文项目).

目前我正在尝试扫描maven存储库并生成包列表.

我可以使用maven.model类下载和解析pom.xml,但我无法确定哪些maven类负责解析archetype-catalog.xml

有非maven解析器吗?

我可以只扫描整个存储库树中的pom.xml文件吗?

编辑:
我找到nexus索引器,但我不知道热使用它:(

最佳答案 花了很长时间,但我终于找到了一个有效的例子

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);


)}
点赞