4

私はEclipse用のコード共有プラグインを開発しています(学士論文プロジェクト用)。

現在、Maven リポジトリをスキャンしてパッケージ リストを生成しようとしています。

maven.model クラスを使用して pom.xml をダウンロードして解析できますが、どの maven クラスが archetype-catalog.xml の解析を担当しているのかわかりません

Maven 以外のパーサーはありますか?

pom.xml ファイルのリポジトリ ツリー全体をスキャンすることはできますか?

編集:nexus-indexerを見つけましたが、それを使用するのが難しいとは思いません:(

4

3 に答える 3

2

何年もかかりましたが、ようやく実用的な例を見つけました

PlexusContainer plexus =  new DefaultPlexusContainer();

NexusIndexer n = (NexusIndexer) plexus.lookup(NexusIndexer.class);
IndexUpdater iu = (IndexUpdater) plexus.lookup(IndexUpdater.class);

// DefaultNexusIndexer n = new DefaultNexusIndexer();
List<IndexCreator> indexCreators = new ArrayList<IndexCreator>();
// 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);
}
于 2011-05-02T20:17:44.723 に答える
1

今後の参考のために、は Apache Foundationnexus-indexer寄贈され、現在は として知られていmaven-indexerます。github ミラーがあり、プロジェクトはApache Git ページにもリストされています。

于 2011-05-02T20:48:53.383 に答える
0

パッケージのローカル リポジトリをスキャンするのは非常にスムーズです。何かを共有する前に検討する必要がある重複したパッケージが大量にあるでしょう。昨日からバージョン 1.1.1-SNAPSHOT をリポジトリにビルドしており、今日はバージョン 1.1.2-SNAPSHOT をビルドしているため、両方のバージョンのディレクトリが同じパッケージを共有していました。

プロジェクトで使用されているアーティファクトを表示したい場合は、依存関係プラグインを使用できます。Maven プロジェクトの開始時に私が気に入っている 2 つのコマンドは次のとおりです。

mvn dependency:tree

mvn dependency:resolve
于 2011-03-08T15:44:03.027 に答える