1 package org.apache.maven.repository.manager.cli;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.artifact.repository.ArtifactRepository;
20 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
21 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
22 import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
23 import org.apache.maven.repository.indexing.ArtifactRepositoryIndexSearcher;
24 import org.apache.maven.repository.indexing.RepositoryIndexException;
25 import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
26 import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
27 import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
28 import org.codehaus.classworlds.ClassWorld;
29 import org.codehaus.plexus.PlexusContainerException;
30 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
31 import org.codehaus.plexus.embed.Embedder;
34 import java.net.MalformedURLException;
37 * Entry point for indexing CLI.
39 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
41 public class IndexSearcherCli
43 public static void main( String[] args )
44 throws PlexusContainerException, ComponentLookupException, RepositoryIndexException, MalformedURLException,
45 RepositoryIndexSearchException
47 Embedder embedder = new Embedder();
48 embedder.start( new ClassWorld() );
50 RepositoryIndexingFactory indexFactory =
51 (RepositoryIndexingFactory) embedder.lookup( RepositoryIndexingFactory.ROLE );
53 ArtifactRepositoryFactory factory =
54 (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE );
56 ArtifactRepositoryLayout layout =
57 (ArtifactRepositoryLayout) embedder.lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
59 ArtifactRepository repository = factory.createArtifactRepository( "repository",
60 new File( args[0] ).toURL().toString(),
63 ArtifactRepositoryIndex index =
64 indexFactory.createArtifactRepositoryIndex( new File( args[0], ".index" ).getAbsolutePath(), repository );
66 ArtifactRepositoryIndexSearcher searcher = indexFactory.createArtifactRepositoryIndexSearcher( index );
70 System.out.println( searcher.search( new SinglePhraseQuery( args[1], args[2] ) ) );