12

Maven Central 用に生成されたインデックスをhttp://mirrors.ibiblio.org/pub/mirrors/maven2/dot-index/nexus-maven-repository-index.gzからダウンロードしました

これらのインデックス ファイル (groupId、artifactId、version など) から成果物情報を一覧表示したいと思います。そのための高レベルの API があることを読みました。次のmaven依存関係を使用する必要があるようです。ただし、使用するエントリ ポイント (どのクラスですか?) と、それを使用してそれらのファイルにアクセスする方法がわかりません。

<dependency>
    <groupId>org.sonatype.nexus</groupId>
    <artifactId>nexus-indexer</artifactId>
    <version>3.0.4</version>
</dependency>
4

4 に答える 4

9

https://github.com/cstamas/maven-indexer-examplesプロジェクトをのぞいてみてください。

要するに、GZ/ZIP (新しい/レガシー形式) を手動でダウンロードする必要はありません。インデクサーがそれを処理します (さらに、可能であれば増分更新も処理します)。

GZ は「新しい」形式であり、データのみを含む Lucene インデックス形式から独立している (したがって、Lucene バージョンから独立している) のに対し、ZIP は「古い」形式であり、実際には単純な Lucene 2.4.x インデックスを圧縮したものです。現在、データ コンテンツの変更は行われていませんが、将来的には計画されています。

前述したように、2 つのデータ コンテンツに違いはありませんが、一部のフィールド (お気づきのように) はインデックス化されていますが、インデックスに保存されていません。したがって、ZIP 形式を使用すると、検索可能になりますが、取得できなくなります。

于 2011-04-26T07:29:02.893 に答える
7

https://github.com/cstamas/maven-indexer-examplesは廃止されました。そして、ビルドは失敗します (テストはパスしません)。

Nexus インデクサーは移動し、例も含まれています: https://github.com/apache/maven-indexer/tree/master/indexer-examples

それがビルドされ、コードが機能します。

独自のロールを作成する場合の簡略版は次のとおりです。

メイヴン:

<dependencies>
    <dependency>
        <groupId>org.apache.maven.indexer</groupId>
        <artifactId>indexer-core</artifactId>
        <version>6.0-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>

    <!-- For ResourceFetcher implementation, if used -->
    <dependency>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-http-lightweight</artifactId>
        <version>2.3</version>
        <scope>compile</scope>
    </dependency>

    <!-- Runtime: DI, but using Plexus Shim as we use Wagon -->
    <dependency>
        <groupId>org.eclipse.sisu</groupId>
        <artifactId>org.eclipse.sisu.plexus</artifactId>
        <version>0.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.sonatype.sisu</groupId>
        <artifactId>sisu-guice</artifactId>
        <version>3.2.4</version>
    </dependency>

ジャワ:

public IndexToGavMappingConverter(File dataDir, String id, String url)
    throws PlexusContainerException, ComponentLookupException, IOException
{
    this.dataDir = dataDir;

    // Create Plexus container, the Maven default IoC container.
    final DefaultContainerConfiguration config = new DefaultContainerConfiguration();
    config.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
    this.plexusContainer = new DefaultPlexusContainer(config);

    // Lookup the indexer components from plexus.
    this.indexer = plexusContainer.lookup( Indexer.class );
    this.indexUpdater = plexusContainer.lookup( IndexUpdater.class );
    // Lookup wagon used to remotely fetch index.
    this.httpWagon = plexusContainer.lookup( Wagon.class, "http" );

    // Files where local cache is (if any) and Lucene Index should be located
    this.centralLocalCache = new File( this.dataDir, id + "-cache" );
    this.centralIndexDir = new File( this.dataDir,   id + "-index" );

    // Creators we want to use (search for fields it defines).
    // See https://maven.apache.org/maven-indexer/indexer-core/apidocs/index.html?constant-values.html
    List<IndexCreator> indexers = new ArrayList();
    // https://maven.apache.org/maven-indexer/apidocs/org/apache/maven/index/creator/MinimalArtifactInfoIndexCreator.html
    indexers.add( plexusContainer.lookup( IndexCreator.class, "min" ) );
    // https://maven.apache.org/maven-indexer/apidocs/org/apache/maven/index/creator/JarFileContentsIndexCreator.html
    //indexers.add( plexusContainer.lookup( IndexCreator.class, "jarContent" ) );
    // https://maven.apache.org/maven-indexer/apidocs/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreator.html
    //indexers.add( plexusContainer.lookup( IndexCreator.class, "maven-plugin" ) );

    // Create context for central repository index.
    this.centralContext = this.indexer.createIndexingContext(
            id + "Context", id, this.centralLocalCache, this.centralIndexDir,
            url, null, true, true, indexers );
}


    final IndexSearcher searcher = this.centralContext.acquireIndexSearcher();
    try
    {
        final IndexReader ir = searcher.getIndexReader();
        Bits liveDocs = MultiFields.getLiveDocs(ir);
        for ( int i = 0; i < ir.maxDoc(); i++ )
        {
            if ( liveDocs == null || liveDocs.get( i ) )
            {
                final Document doc = ir.document( i );
                final ArtifactInfo ai = IndexUtils.constructArtifactInfo( doc, this.centralContext );

                if (ai == null)
                    continue;
                if (ai.getSha1() == null)
                    continue;
                if (ai.getSha1().length() != 40)
                    continue;
                if ("javadoc".equals(ai.getClassifier()))
                    continue;
                if ("sources".equals(ai.getClassifier()))
                    continue;

                out.append(StringUtils.lowerCase(ai.getSha1())).append(' ');
                out.append(ai.getGroupId()).append(":");
                out.append(ai.getArtifactId()).append(":");
                out.append(ai.getVersion()).append(":");
                out.append(StringUtils.defaultString(ai.getClassifier()));
                out.append('\n');
            }
        }
    }
    finally
    {
        this.centralContext.releaseIndexSearcher( searcher );
    }

これは、Windup プロジェクトの JBoss 移行ツールで使用します。

于 2015-01-22T11:01:54.907 に答える
2

従来のzip インデックスは単純な lucene インデックスです。Lukeでそれを開き、 いくつかの単純な lucene コードを記述して、目的のヘッダー (この場合は「u」) をダンプすることができました。

import org.apache.lucene.document.Document;
import org.apache.lucene.search.IndexSearcher;

public class Dumper {
    public static void main(String[] args) throws Exception {
        IndexSearcher searcher = new IndexSearcher("c:/PROJECTS/Test/index");
        for (int i = 0; i < searcher.maxDoc(); i++) {
            Document doc = searcher.doc(i);
            String metadata = doc.get("u");
            if (metadata != null) {
                System.out.println(metadata);
            }
        }
    }
}

サンプル出力 ...

org.ioke|ioke-lang-lib|P-0.4.0-p11|NA
org.jboss.weld.archetypes|jboss-javaee6-webapp|1.0.1.CR2|sources|jar
org.jboss.weld.archetypes|jboss-javaee6-webapp|1.0.1.CR2|NA
org.nutz|nutz|1.b.37|javadoc|jar
org.nutz|nutz|1.b.37|sources|jar
org.nutz|nutz|1.b.37|NA
org.openengsb.wrapped|com.google.gdata|1.41.5.w1|NA
org.openengsb.wrapped|openengsb-wrapped-parent|6|NA

これを達成するためのより良い方法があるかもしれません...

于 2011-04-25T10:46:05.860 に答える
0

レコードについては、Maven インデックスを抽出してテキスト ファイルとしてエクスポートするツール、Maven インデックス エクスポーターが追加されました。Docker イメージとして利用でき、コードは必要ありません。

基本的に、すべての .gz インデックス ファイルをダウンロードし、maven-indexer cli を使用してインデックスを抽出し、それらテキスト ファイルにエクスポートします。Maven Central でテストされており、他の多くのMaven リポジトリで動作します。

于 2021-12-09T07:59:34.370 に答える