diff --git a/maven-repository-application/pom.xml b/maven-repository-application/pom.xml new file mode 100644 index 000000000..d2f042856 --- /dev/null +++ b/maven-repository-application/pom.xml @@ -0,0 +1,41 @@ + + + + + org.apache.maven.repository + maven-repository-manager + 1.0-SNAPSHOT + + 4.0.0 + maven-repository-application + Maven Repository Application + + + org.apache.maven.repository + maven-repository-indexer + + + org.apache.maven.repository + maven-repository-discovery + + + org.codehaus.plexus + plexus-container-default + + + diff --git a/maven-repository-application/src/main/java/org/apache/maven/repository/manager/cli/IndexCli.java b/maven-repository-application/src/main/java/org/apache/maven/repository/manager/cli/IndexCli.java new file mode 100644 index 000000000..534b0827d --- /dev/null +++ b/maven-repository-application/src/main/java/org/apache/maven/repository/manager/cli/IndexCli.java @@ -0,0 +1,90 @@ +package org.apache.maven.repository.manager.cli; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.repository.discovery.ArtifactDiscoverer; +import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.apache.maven.repository.indexing.RepositoryIndexingFactory; +import org.codehaus.classworlds.ClassWorld; +import org.codehaus.plexus.PlexusContainerException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.embed.Embedder; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.Iterator; +import java.util.List; + +/** + * Entry point for indexing CLI. + * + * @author Brett Porter + */ +public class IndexCli +{ + public static void main( String[] args ) + throws PlexusContainerException, ComponentLookupException, RepositoryIndexException, MalformedURLException + { + Embedder embedder = new Embedder(); + embedder.start( new ClassWorld() ); + + RepositoryIndexingFactory indexFactory = + (RepositoryIndexingFactory) embedder.lookup( RepositoryIndexingFactory.ROLE ); + + ArtifactRepositoryFactory factory = + (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = + (ArtifactRepositoryLayout) embedder.lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); + + ArtifactRepository repository = factory.createArtifactRepository( "repository", + new File( args[0] ).toURL().toString(), + layout, null, null ); + + ArtifactDiscoverer discoverer = (ArtifactDiscoverer) embedder.lookup( ArtifactDiscoverer.ROLE, "legacy" ); + + List artifacts = discoverer.discoverArtifacts( new File( repository.getBasedir() ), null, false ); + + ArtifactRepositoryIndex index = + indexFactory.createArtifactRepositoryIndex( new File( args[0], ".index" ).getAbsolutePath(), repository ); + + long time = System.currentTimeMillis(); + try + { + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + + index.indexArtifact( artifact ); + } + index.optimize(); + } + finally + { + index.close(); + } + time = System.currentTimeMillis() - time; + + System.out.println( "Indexed " + artifacts.size() + " artifacts in " + time + "ms" ); + } + +} diff --git a/maven-repository-application/src/main/java/org/apache/maven/repository/manager/cli/IndexSearcherCli.java b/maven-repository-application/src/main/java/org/apache/maven/repository/manager/cli/IndexSearcherCli.java new file mode 100644 index 000000000..86b8e6eaa --- /dev/null +++ b/maven-repository-application/src/main/java/org/apache/maven/repository/manager/cli/IndexSearcherCli.java @@ -0,0 +1,78 @@ +package org.apache.maven.repository.manager.cli; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; +import org.apache.maven.repository.indexing.ArtifactRepositoryIndexSearcher; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.apache.maven.repository.indexing.RepositoryIndexSearchException; +import org.apache.maven.repository.indexing.RepositoryIndexingFactory; +import org.apache.maven.repository.indexing.query.SinglePhraseQuery; +import org.codehaus.classworlds.ClassWorld; +import org.codehaus.plexus.PlexusContainerException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.embed.Embedder; + +import java.io.File; +import java.net.MalformedURLException; + +/** + * Entry point for indexing CLI. + * + * @author Brett Porter + */ +public class IndexSearcherCli +{ + public static void main( String[] args ) + throws PlexusContainerException, ComponentLookupException, RepositoryIndexException, MalformedURLException, + RepositoryIndexSearchException + { + Embedder embedder = new Embedder(); + embedder.start( new ClassWorld() ); + + RepositoryIndexingFactory indexFactory = + (RepositoryIndexingFactory) embedder.lookup( RepositoryIndexingFactory.ROLE ); + + ArtifactRepositoryFactory factory = + (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = + (ArtifactRepositoryLayout) embedder.lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); + + ArtifactRepository repository = factory.createArtifactRepository( "repository", + new File( args[0] ).toURL().toString(), + layout, null, null ); + + ArtifactRepositoryIndex index = + indexFactory.createArtifactRepositoryIndex( new File( args[0], ".index" ).getAbsolutePath(), repository ); + + ArtifactRepositoryIndexSearcher searcher = indexFactory.createArtifactRepositoryIndexSearcher( index ); + + try + { + System.out.println( searcher.search( new SinglePhraseQuery( args[1], args[2] ) ) ); + } + finally + { + index.close(); + } + } + +} diff --git a/pom.xml b/pom.xml index f6da4712a..d0013d694 100644 --- a/pom.xml +++ b/pom.xml @@ -129,6 +129,7 @@ + maven-repository-application maven-repository-discovery maven-repository-reports-standard maven-repository-indexer @@ -221,6 +222,11 @@ maven-repository-discovery ${pom.version} + + org.apache.maven.repository + maven-repository-indexer + ${pom.version} + org.apache.maven.repository maven-repository-utils