]> source.dussan.org Git - archiva.git/blob
86b8e6eaac99bff3ad336eed8fdd46f5215c0f09
[archiva.git] /
1 package org.apache.maven.repository.manager.cli;
2
3 /*
4  * Copyright 2005-2006 The Apache Software Foundation.
5  *
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
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;
32
33 import java.io.File;
34 import java.net.MalformedURLException;
35
36 /**
37  * Entry point for indexing CLI.
38  *
39  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
40  */
41 public class IndexSearcherCli
42 {
43     public static void main( String[] args )
44         throws PlexusContainerException, ComponentLookupException, RepositoryIndexException, MalformedURLException,
45         RepositoryIndexSearchException
46     {
47         Embedder embedder = new Embedder();
48         embedder.start( new ClassWorld() );
49
50         RepositoryIndexingFactory indexFactory =
51             (RepositoryIndexingFactory) embedder.lookup( RepositoryIndexingFactory.ROLE );
52
53         ArtifactRepositoryFactory factory =
54             (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE );
55
56         ArtifactRepositoryLayout layout =
57             (ArtifactRepositoryLayout) embedder.lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
58
59         ArtifactRepository repository = factory.createArtifactRepository( "repository",
60                                                                           new File( args[0] ).toURL().toString(),
61                                                                           layout, null, null );
62
63         ArtifactRepositoryIndex index =
64             indexFactory.createArtifactRepositoryIndex( new File( args[0], ".index" ).getAbsolutePath(), repository );
65
66         ArtifactRepositoryIndexSearcher searcher = indexFactory.createArtifactRepositoryIndexSearcher( index );
67
68         try
69         {
70             System.out.println( searcher.search( new SinglePhraseQuery( args[1], args[2] ) ) );
71         }
72         finally
73         {
74             index.close();
75         }
76     }
77
78 }