2011-03-07 79 views
4

我正在開發一個eclipse的代碼共享插件(用於學士論文項目)。如何掃描Maven存儲庫?

當前我正在嘗試掃描一個maven倉庫並生成一個軟件包列表。

我可以下載並使用maven.model類解析一個pom.xml,但我不能找出哪些Maven的類負責原型 - catalog.xml中

的分析是否有非行家解析器?

我可以只掃描pom.xml文件的整個存儲庫樹嗎?

編輯: 香港專業教育學院發現的Nexus索引器,但我不知道熱水使用它:(

回答

1

花了年齡,但我終於找到了一個工作示例

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


)}
0

掃描我的本地倉庫中的包會非常漂亮的我會一噸,將需要複製的包。在我分享任何東西之前要考慮自從昨天我建立版本1.1.1-SNAPSHOT到我的倉庫,今天我正在構建版本1.1.2-SNAPSHOT,兩個版本的目錄將共享相同的包

現在,如果你想顯示項目中使用了哪些工件,你可以使用依賴插件。在Maven項目開始時,我最喜歡的兩個命令是:

mvn dependency:tree 

mvn dependency:resolve 
+0

感謝您的答覆,但我需要掃描遠程存儲庫,並將結果保存到數據庫,所以我可以稍後搜索 – sherif 2011-03-08 16:48:05

+0

隨着最終結果是類層次結構遠程倉庫的? – DaShaun 2011-03-09 21:51:07

+0

最終結果應該是所有人工製品的清單。 – sherif 2011-03-10 09:13:26