Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何解析/解压/解压Nexus生成的Maven存储库索引_Java_Maven_Lucene_Nexus_Maven Indexer - Fatal编程技术网

Java 如何解析/解压/解压Nexus生成的Maven存储库索引

Java 如何解析/解压/解压Nexus生成的Maven存储库索引,java,maven,lucene,nexus,maven-indexer,Java,Maven,Lucene,Nexus,Maven Indexer,我已经从下载了为Maven Central生成的索引 我想列出这些索引文件中的工件信息(例如groupId、artifactId、version)。我已经读到有一个高层次的API。似乎我必须使用以下maven依赖项。但是,我不知道使用什么入口点(哪个类?)以及如何使用它访问这些文件: <dependency> <groupId>org.sonatype.nexus</groupId> <artifactId>nexus-indexe

我已经从下载了为Maven Central生成的索引

我想列出这些索引文件中的工件信息(例如groupId、artifactId、version)。我已经读到有一个高层次的API。似乎我必须使用以下maven依赖项。但是,我不知道使用什么入口点(哪个类?)以及如何使用它访问这些文件:

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

org.sonatype.nexus
nexus索引器
3.0.4
是一个简单的lucene索引。我能用手打开它 并编写一些简单的lucene代码来转储感兴趣的标题(本例中为“u”)

也许有更好的方法来实现这一点…

看看这个项目

简而言之:您不需要手动下载GZ/ZIP(新的/旧的格式),它将为您提供索引(此外,如果可能的话,它还将为您处理增量更新)

GZ是“新”格式,独立于只包含数据的Lucene索引格式(因此,独立于Lucene版本),而ZIP是“旧”格式,实际上是压缩的普通Lucene 2.4.x索引。目前未发生数据内容更改,但计划在将来进行

正如我所说,两者之间没有数据内容的差异,但有些字段(如您所注意到的)被编入索引但未存储在索引中,因此,如果您使用ZIP格式,则可以对其进行搜索,但无法检索。

已过时。构建失败(测试未通过)

Nexus Indexer已开始使用,并包括以下示例:

这样就可以构建,代码也可以运行

如果您想自己动手,这里有一个简化版本:

马文:

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

org.apache.maven.indexer

.

谢谢你的帮助。你知道拉链和gz拉链有什么区别吗?我知道gz使用专有的二进制格式,但它是否包含更多信息?你知道如何迭代吗?不知道内部的差异。谷歌说gz是针对速度而优化的。如果您想使用它作为输入,似乎有一个可用的示例@I发现gz包含更多的信息,比如JAR文件大小、描述、JAR包含的类等等。我已经尝试过像您的示例中那样解析gz版本,但这是不可能的,因为gz归档文件不包含lucene段。另外,在这里发布我的问题之前,我已经看到了您指出的github链接。但是,从这个github示例中,我无法理解作为入口点使用的主要类是什么。假设我有解压缩的gz文件。嗯,我相信这个替代方法可以解决您的问题。您可以使用luceneapi从索引中检索jar,并获取其大小及其包含的类。幸运的是找到一个nexus indexer实现.zip文件的链接已经死了,我想我们现在可以宣布“遗留zip索引”基本上也死了?indexer核心的6.0版快照到底部署在哪里?我遇到编译错误,因为maven找不到那个jar文件。哦,对了。那是我们自己的。在释放之前我们需要6个。请参阅。即使是指向示例的新链接也需要6.0-SNAPSHOT依赖项,请参阅(但一旦有了它就会运行),我知道,我们只需推出自己的版本。你可以得到它并建造它。很抱歉给您带来不便,但我们没有时间让它成为central的正常版本。顺便说一句,我在我们的网站上做了一些重构。检查/nexus indexer子模块,很少有类使用nexus索引。我还没有找到使用“Jar”数据的方法,只有“Min”数据。Jar应该包含关于所包含类的元数据
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
<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 );
    }