mirror of https://github.com/apache/archiva.git
[MRM-46] Add a very basic CLI interface for some quick tests. These will likely be removed at some point for something that just executes the webwork actions
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@367199 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d56ac4730c
commit
ea01c5f5a4
|
@ -0,0 +1,41 @@
|
|||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.apache.maven.repository</groupId>
|
||||
<artifactId>maven-repository-manager</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>maven-repository-application</artifactId>
|
||||
<name>Maven Repository Application</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.repository</groupId>
|
||||
<artifactId>maven-repository-indexer</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.repository</groupId>
|
||||
<artifactId>maven-repository-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-container-default</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
*/
|
||||
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" );
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
6
pom.xml
6
pom.xml
|
@ -129,6 +129,7 @@
|
|||
</pluginManagement>
|
||||
</build>
|
||||
<modules>
|
||||
<module>maven-repository-application</module>
|
||||
<module>maven-repository-discovery</module>
|
||||
<module>maven-repository-reports-standard</module>
|
||||
<module>maven-repository-indexer</module>
|
||||
|
@ -221,6 +222,11 @@
|
|||
<artifactId>maven-repository-discovery</artifactId>
|
||||
<version>${pom.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.repository</groupId>
|
||||
<artifactId>maven-repository-indexer</artifactId>
|
||||
<version>${pom.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.repository</groupId>
|
||||
<artifactId>maven-repository-utils</artifactId>
|
||||
|
|
Loading…
Reference in New Issue