git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@412295 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-0.9-alpha-1
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | ||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | ||||
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; | import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; | ||||
import org.apache.maven.repository.indexing.DefaultRepositoryIndexSearcher; | |||||
import org.apache.maven.repository.indexing.RepositoryIndexException; | import org.apache.maven.repository.indexing.RepositoryIndexException; | ||||
import org.apache.maven.repository.indexing.RepositoryIndexSearchException; | import org.apache.maven.repository.indexing.RepositoryIndexSearchException; | ||||
import org.apache.maven.repository.indexing.RepositoryIndexingFactory; | import org.apache.maven.repository.indexing.RepositoryIndexingFactory; | ||||
import org.apache.maven.repository.indexing.DefaultRepositoryIndexSearcher; | |||||
import org.apache.maven.repository.indexing.query.SinglePhraseQuery; | import org.apache.maven.repository.indexing.query.SinglePhraseQuery; | ||||
import org.codehaus.classworlds.ClassWorld; | import org.codehaus.classworlds.ClassWorld; | ||||
import org.codehaus.plexus.PlexusContainerException; | import org.codehaus.plexus.PlexusContainerException; | ||||
*/ | */ | ||||
public class IndexSearcherCli | public class IndexSearcherCli | ||||
{ | { | ||||
private IndexSearcherCli() | |||||
{ | |||||
} | |||||
public static void main( String[] args ) | public static void main( String[] args ) | ||||
throws PlexusContainerException, ComponentLookupException, RepositoryIndexException, MalformedURLException, | throws PlexusContainerException, ComponentLookupException, RepositoryIndexException, MalformedURLException, | ||||
RepositoryIndexSearchException | RepositoryIndexSearchException | ||||
ArtifactRepositoryIndex index = | ArtifactRepositoryIndex index = | ||||
indexFactory.createArtifactRepositoryIndex( new File( args[0], ".index" ).getAbsolutePath(), repository ); | indexFactory.createArtifactRepositoryIndex( new File( args[0], ".index" ).getAbsolutePath(), repository ); | ||||
DefaultRepositoryIndexSearcher searcher = indexFactory.createDefaultRepositoryIndexSearcher( index ); | DefaultRepositoryIndexSearcher searcher = indexFactory.createDefaultRepositoryIndexSearcher( index ); | ||||
try | try |
<!-- | |||||
~ 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" | <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"> | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||||
<modelVersion>4.0.0</modelVersion> | <modelVersion>4.0.0</modelVersion> |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
* limitations under the License. | * limitations under the License. | ||||
* | |||||
*/ | */ | ||||
import javax.swing.*; | import javax.swing.*; | ||||
public String generateMd5( final String file ) | public String generateMd5( final String file ) | ||||
throws IOException, NoSuchAlgorithmException | throws IOException, NoSuchAlgorithmException | ||||
{ | { | ||||
return (String) AccessController.doPrivileged( new PrivilegedAction() | |||||
Object o = AccessController.doPrivileged( new PrivilegedAction() | |||||
{ | { | ||||
public Object run() | public Object run() | ||||
{ | { | ||||
try | try | ||||
{ | { | ||||
MessageDigest digest = MessageDigest.getInstance( "MD5" ); | |||||
long total = new File( file ).length(); | |||||
InputStream fis = new FileInputStream( file ); | |||||
try | |||||
{ | |||||
long totalRead = 0; | |||||
byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE]; | |||||
int numRead; | |||||
do | |||||
{ | |||||
numRead = fis.read( buffer ); | |||||
if ( numRead > 0 ) | |||||
{ | |||||
digest.update( buffer, 0, numRead ); | |||||
totalRead += numRead; | |||||
progressBar.setValue( (int) ( totalRead * progressBar.getMaximum() / total ) ); | |||||
} | |||||
} | |||||
while ( numRead != -1 ); | |||||
} | |||||
finally | |||||
{ | |||||
fis.close(); | |||||
} | |||||
return byteArrayToHexStr( digest.digest() ); | |||||
return checksumFile( file ); | |||||
} | } | ||||
catch ( NoSuchAlgorithmException e ) | catch ( NoSuchAlgorithmException e ) | ||||
{ | { | ||||
throw new RuntimeException( e ); | |||||
return e; | |||||
} | } | ||||
catch ( IOException e ) | catch ( IOException e ) | ||||
{ | { | ||||
throw new RuntimeException( e ); | |||||
return e; | |||||
} | } | ||||
} | } | ||||
} ); | } ); | ||||
//noinspection ChainOfInstanceofChecks | |||||
if ( o instanceof IOException ) | |||||
{ | |||||
throw (IOException) o; | |||||
} | |||||
else if ( o instanceof NoSuchAlgorithmException ) | |||||
{ | |||||
throw (NoSuchAlgorithmException) o; | |||||
} | |||||
else | |||||
{ | |||||
return (String) o; | |||||
} | |||||
} | |||||
protected String checksumFile( String file ) | |||||
throws NoSuchAlgorithmException, IOException | |||||
{ | |||||
MessageDigest digest = MessageDigest.getInstance( "MD5" ); | |||||
long total = new File( file ).length(); | |||||
InputStream fis = new FileInputStream( file ); | |||||
try | |||||
{ | |||||
long totalRead = 0; | |||||
byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE]; | |||||
int numRead; | |||||
do | |||||
{ | |||||
numRead = fis.read( buffer ); | |||||
if ( numRead > 0 ) | |||||
{ | |||||
digest.update( buffer, 0, numRead ); | |||||
totalRead += numRead; | |||||
progressBar.setValue( (int) ( totalRead * progressBar.getMaximum() / total ) ); | |||||
} | |||||
} | |||||
while ( numRead != -1 ); | |||||
} | |||||
finally | |||||
{ | |||||
fis.close(); | |||||
} | |||||
return byteArrayToHexStr( digest.digest() ); | |||||
} | } | ||||
private static String byteArrayToHexStr( byte[] data ) | |||||
protected static String byteArrayToHexStr( byte[] data ) | |||||
{ | { | ||||
String output = ""; | String output = ""; | ||||
import org.apache.maven.model.Relocation; | import org.apache.maven.model.Relocation; | ||||
import org.apache.maven.model.converter.ArtifactPomRewriter; | import org.apache.maven.model.converter.ArtifactPomRewriter; | ||||
import org.apache.maven.model.converter.ModelConverter; | import org.apache.maven.model.converter.ModelConverter; | ||||
import org.apache.maven.model.converter.PomTranslationException; | |||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; | import org.apache.maven.model.io.xpp3.MavenXpp3Writer; | ||||
import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader; | import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader; | ||||
import org.apache.maven.repository.converter.transaction.FileTransaction; | import org.apache.maven.repository.converter.transaction.FileTransaction; | ||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileNotFoundException; | |||||
import java.io.FileReader; | import java.io.FileReader; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.StringReader; | import java.io.StringReader; | ||||
fileReader = new FileReader( file ); | fileReader = new FileReader( file ); | ||||
metadata = reader.read( fileReader ); | metadata = reader.read( fileReader ); | ||||
} | } | ||||
catch ( FileNotFoundException e ) | |||||
{ | |||||
throw new RepositoryConversionException( "Error reading target metadata", e ); | |||||
} | |||||
catch ( IOException e ) | catch ( IOException e ) | ||||
{ | { | ||||
throw new RepositoryConversionException( "Error reading target metadata", e ); | throw new RepositoryConversionException( "Error reading target metadata", e ); | ||||
reporter.addFailure( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) ); | reporter.addFailure( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) ); | ||||
result = false; | result = false; | ||||
} | } | ||||
catch ( Exception e ) | |||||
catch ( IOException e ) | |||||
{ | { | ||||
throw new RepositoryConversionException( "Unable to write converted POM", e ); | throw new RepositoryConversionException( "Unable to write converted POM", e ); | ||||
} | } | ||||
catch ( PomTranslationException e ) | |||||
{ | |||||
// TODO! check handling, fix error message | |||||
reporter.addFailure( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) ); | |||||
result = false; | |||||
} | |||||
finally | finally | ||||
{ | { | ||||
IOUtil.close( writer ); | IOUtil.close( writer ); |
package org.apache.maven.repository.converter.transaction; | package org.apache.maven.repository.converter.transaction; | ||||
import java.io.IOException; | |||||
/* | /* | ||||
* Copyright 2005-2006 The Apache Software Foundation. | * Copyright 2005-2006 The Apache Software Foundation. | ||||
* | * | ||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
import java.io.IOException; | |||||
/** | /** | ||||
* Interface for individual events in a transaction. | * Interface for individual events in a transaction. | ||||
* | * |
exception.repositories.match=Source and target repositories are identical. | exception.repositories.match=Source and target repositories are identical. | ||||
# TODO! update definitions | |||||
failure.incorrect.groupMetadata.groupId=The group ID in the source group metadata is incorrect. | failure.incorrect.groupMetadata.groupId=The group ID in the source group metadata is incorrect. | ||||
failure.incorrect.artifactMetadata.artifactId=The artifact ID in the source artifact metadata is incorrect. | failure.incorrect.artifactMetadata.artifactId=The artifact ID in the source artifact metadata is incorrect. |
File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); | File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); | ||||
File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); | File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); | ||||
SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" ); | |||||
SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd", Locale.getDefault() ); | |||||
long origTime = dateFormat.parse( "2006-03-03" ).getTime(); | long origTime = dateFormat.parse( "2006-03-03" ).getTime(); | ||||
targetFile.setLastModified( origTime ); | |||||
targetPomFile.setLastModified( origTime ); | |||||
targetFile.setLastModified( origTime ); | |||||
targetPomFile.setLastModified( origTime ); | |||||
sourceFile.setLastModified( dateFormat.parse( "2006-01-01" ).getTime() ); | sourceFile.setLastModified( dateFormat.parse( "2006-01-01" ).getTime() ); | ||||
sourcePomFile.setLastModified( dateFormat.parse( "2006-02-02" ).getTime() ); | sourcePomFile.setLastModified( dateFormat.parse( "2006-02-02" ).getTime() ); | ||||
} | } | ||||
else if ( file.isDirectory() ) | else if ( file.isDirectory() ) | ||||
{ | { | ||||
if ( !file.getName().equals( ".svn" ) ) | |||||
if ( !".svn".equals( file.getName() ) ) | |||||
{ | { | ||||
if ( !destination.exists() && !destination.mkdirs() ) | if ( !destination.exists() && !destination.mkdirs() ) | ||||
{ | { |
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
~ See the License for the specific language governing permissions and | ~ See the License for the specific language governing permissions and | ||||
~ limitations under the License. | ~ limitations under the License. | ||||
~ | |||||
--> | --> | ||||
<project> | <project> |
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
~ See the License for the specific language governing permissions and | ~ See the License for the specific language governing permissions and | ||||
~ limitations under the License. | ~ limitations under the License. | ||||
~ | |||||
--> | --> | ||||
<project> | <project> |
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
~ See the License for the specific language governing permissions and | ~ See the License for the specific language governing permissions and | ||||
~ limitations under the License. | ~ limitations under the License. | ||||
~ | |||||
--> | --> | ||||
<project> | <project> |
import org.apache.maven.artifact.repository.ArtifactRepository; | import org.apache.maven.artifact.repository.ArtifactRepository; | ||||
import org.apache.maven.model.Model; | import org.apache.maven.model.Model; | ||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; | import org.apache.maven.model.io.xpp3.MavenXpp3Reader; | ||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileNotFoundException; | |||||
import java.io.FileReader; | import java.io.FileReader; | ||||
import java.io.IOException; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
"**/*.MD5", "**/*.sha1", "**/*.SHA1", "**/*snapshot-version", "*/website/**", "*/licenses/**", "*/licences/**", | "**/*.MD5", "**/*.sha1", "**/*.SHA1", "**/*snapshot-version", "*/website/**", "*/licenses/**", "*/licences/**", | ||||
"**/.htaccess", "**/*.html", "**/*.asc", "**/*.txt", "**/*.xml", "**/README*", "**/CHANGELOG*", "**/KEYS*"}; | "**/.htaccess", "**/*.html", "**/*.asc", "**/*.txt", "**/*.xml", "**/README*", "**/CHANGELOG*", "**/KEYS*"}; | ||||
protected static final String POM = ".pom"; | |||||
private static final String POM = ".pom"; | |||||
/** | /** | ||||
* Scan the repository for artifact paths. | * Scan the repository for artifact paths. | ||||
*/ | */ | ||||
protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns ) | |||||
private String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns ) | |||||
{ | { | ||||
return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES ); | return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES ); | ||||
} | } | ||||
try | try | ||||
{ | { | ||||
Model model = mavenReader.read( new FileReader( filename ) ); | Model model = mavenReader.read( new FileReader( filename ) ); | ||||
if ( ( pomArtifact != null ) && ( "pom".equals( model.getPackaging() ) ) ) | |||||
if ( pomArtifact != null && "pom".equals( model.getPackaging() ) ) | |||||
{ | { | ||||
if ( includeSnapshots || !pomArtifact.isSnapshot() ) | if ( includeSnapshots || !pomArtifact.isSnapshot() ) | ||||
{ | { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
catch ( Exception e ) | |||||
catch ( FileNotFoundException e ) | |||||
{ | { | ||||
getLogger().info( "error reading file: " + filename ); | |||||
e.printStackTrace(); | |||||
// this should never happen | |||||
getLogger().error( "Error finding file during POM discovery: " + filename, e ); | |||||
} | |||||
catch ( IOException e ) | |||||
{ | |||||
getLogger().error( "Error reading file during POM discovery: " + filename + ": " + e ); | |||||
} | |||||
catch ( XmlPullParserException e ) | |||||
{ | |||||
getLogger().error( | |||||
"Parse error reading file during POM discovery: " + filename + ": " + e.getMessage() ); | |||||
} | } | ||||
} | } | ||||
} | } |
package org.apache.maven.repository.discovery; | package org.apache.maven.repository.discovery; | ||||
/* | |||||
* 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.factory.ArtifactFactory; | import org.apache.maven.artifact.factory.ArtifactFactory; | ||||
import org.codehaus.plexus.logging.AbstractLogEnabled; | import org.codehaus.plexus.logging.AbstractLogEnabled; | ||||
import org.codehaus.plexus.util.DirectoryScanner; | import org.codehaus.plexus.util.DirectoryScanner; | ||||
* | * | ||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a> | * @author <a href="mailto:brett@apache.org">Brett Porter</a> | ||||
*/ | */ | ||||
public class AbstractDiscoverer | |||||
public abstract class AbstractDiscoverer | |||||
extends AbstractLogEnabled | extends AbstractLogEnabled | ||||
{ | { | ||||
private List kickedOutPaths = new ArrayList(); | private List kickedOutPaths = new ArrayList(); |
//} | //} | ||||
Artifact artifact = null; | Artifact artifact = null; | ||||
if ( metaVersion != null && !metaVersion.equals( "" ) ) | |||||
if ( metaVersion != null && !"".equals( metaVersion ) ) | |||||
{ | { | ||||
artifact = artifactFactory.createBuildArtifact( metaGroupId, metaArtifactId, metaVersion, "jar" ); | artifact = artifactFactory.createBuildArtifact( metaGroupId, metaArtifactId, metaVersion, "jar" ); | ||||
} | } |
* | * | ||||
* @param indexPath | * @param indexPath | ||||
* @param repository | * @param repository | ||||
* @throws RepositoryIndexException | |||||
*/ | */ | ||||
protected AbstractRepositoryIndex( String indexPath, ArtifactRepository repository ) | protected AbstractRepositoryIndex( String indexPath, ArtifactRepository repository ) | ||||
throws RepositoryIndexException | |||||
{ | { | ||||
this.repository = repository; | this.repository = repository; | ||||
this.indexPath = indexPath; | this.indexPath = indexPath; | ||||
* Check if the index already exists. | * Check if the index already exists. | ||||
* | * | ||||
* @return true if the index already exists | * @return true if the index already exists | ||||
* @throws IOException | |||||
* @throws RepositoryIndexException | * @throws RepositoryIndexException | ||||
*/ | */ | ||||
protected boolean indexExists() | protected boolean indexExists() | ||||
throws IOException, RepositoryIndexException | |||||
throws RepositoryIndexException | |||||
{ | { | ||||
File indexDir = new File( indexPath ); | File indexDir = new File( indexPath ); | ||||
return isAdded; | return isAdded; | ||||
} | } | ||||
private class ArtifactRepositoryIndexAnalyzer | |||||
private static class ArtifactRepositoryIndexAnalyzer | |||||
extends Analyzer | extends Analyzer | ||||
{ | { | ||||
private Analyzer defaultAnalyzer; | private Analyzer defaultAnalyzer; | ||||
* | * | ||||
* @param defaultAnalyzer the analyzer to use as default for the general fields of the artifact indeces | * @param defaultAnalyzer the analyzer to use as default for the general fields of the artifact indeces | ||||
*/ | */ | ||||
public ArtifactRepositoryIndexAnalyzer( Analyzer defaultAnalyzer ) | |||||
ArtifactRepositoryIndexAnalyzer( Analyzer defaultAnalyzer ) | |||||
{ | { | ||||
this.defaultAnalyzer = defaultAnalyzer; | this.defaultAnalyzer = defaultAnalyzer; | ||||
} | } | ||||
return tokenStream; | return tokenStream; | ||||
} | } | ||||
} | |||||
/** | |||||
* Class used to tokenize an artifact's version. | |||||
*/ | |||||
private static class VersionTokenizer | |||||
extends CharTokenizer | |||||
{ | |||||
/** | /** | ||||
* Class used to tokenize an artifact's version. | |||||
* Constructor with the required reader to the index stream | |||||
* | |||||
* @param reader the Reader object of the index stream | |||||
*/ | */ | ||||
private class VersionTokenizer | |||||
extends CharTokenizer | |||||
VersionTokenizer( Reader reader ) | |||||
{ | { | ||||
/** | |||||
* Constructor with the required reader to the index stream | |||||
* | |||||
* @param reader the Reader object of the index stream | |||||
*/ | |||||
VersionTokenizer( Reader reader ) | |||||
{ | |||||
super( reader ); | |||||
} | |||||
super( reader ); | |||||
} | |||||
/** | |||||
* method that lucene calls to check tokenization of a stream character | |||||
* | |||||
* @param character char currently being processed | |||||
* @return true if the char is a token, false if the char is a stop char | |||||
*/ | |||||
protected boolean isTokenChar( char character ) | |||||
{ | |||||
return character != '.' && character != '-'; | |||||
} | |||||
/** | |||||
* method that lucene calls to check tokenization of a stream character | |||||
* | |||||
* @param character char currently being processed | |||||
* @return true if the char is a token, false if the char is a stop char | |||||
*/ | |||||
protected boolean isTokenChar( char character ) | |||||
{ | |||||
return character != '.' && character != '-'; | |||||
} | } | ||||
} | } | ||||
} | } |
* @param indexPath the path where the lucene index will be created/updated. | * @param indexPath the path where the lucene index will be created/updated. | ||||
* @param repository the repository where the indexed artifacts are located | * @param repository the repository where the indexed artifacts are located | ||||
* @param digester the digester object to generate the checksum strings | * @param digester the digester object to generate the checksum strings | ||||
* @throws RepositoryIndexException | |||||
*/ | */ | ||||
public ArtifactRepositoryIndex( String indexPath, ArtifactRepository repository, Digester digester ) | public ArtifactRepositoryIndex( String indexPath, ArtifactRepository repository, Digester digester ) | ||||
throws RepositoryIndexException | |||||
{ | { | ||||
super( indexPath, repository ); | super( indexPath, repository ); | ||||
this.digester = digester; | this.digester = digester; | ||||
* | * | ||||
* @param name the complete path name of the class | * @param name the complete path name of the class | ||||
* @param packages the packages buffer | * @param packages the packages buffer | ||||
* @return true if the package is successfully added | |||||
*/ | */ | ||||
private boolean addClassPackage( String name, StringBuffer packages ) | |||||
private void addClassPackage( String name, StringBuffer packages ) | |||||
{ | { | ||||
boolean isAdded = false; | |||||
int idx = name.lastIndexOf( '/' ); | int idx = name.lastIndexOf( '/' ); | ||||
if ( idx > 0 ) | if ( idx > 0 ) | ||||
{ | { | ||||
{ | { | ||||
packages.append( packageName ).append( "\n" ); | packages.append( packageName ).append( "\n" ); | ||||
} | } | ||||
isAdded = true; | |||||
} | } | ||||
return isAdded; | |||||
} | } | ||||
/** | /** | ||||
* | * | ||||
* @param entry the zip entry to be added | * @param entry the zip entry to be added | ||||
* @param files the buffer of files to update | * @param files the buffer of files to update | ||||
* @return true if the file was successfully added | |||||
*/ | */ | ||||
private boolean addFile( ZipEntry entry, StringBuffer files ) | |||||
private void addFile( ZipEntry entry, StringBuffer files ) | |||||
{ | { | ||||
String name = entry.getName(); | String name = entry.getName(); | ||||
int idx = name.lastIndexOf( '/' ); | int idx = name.lastIndexOf( '/' ); | ||||
name = name.substring( idx + 1 ); | name = name.substring( idx + 1 ); | ||||
} | } | ||||
boolean isAdded = false; | |||||
if ( files.indexOf( name + "\n" ) < 0 ) | if ( files.indexOf( name + "\n" ) < 0 ) | ||||
{ | { | ||||
files.append( name ).append( "\n" ); | files.append( name ).append( "\n" ); | ||||
isAdded = true; | |||||
} | } | ||||
return isAdded; | |||||
} | } | ||||
} | } |
Hits hits = searcher.search( luceneQuery ); | Hits hits = searcher.search( luceneQuery ); | ||||
docs = buildList( hits ); | docs = buildList( hits ); | ||||
} | } | ||||
catch ( MalformedURLException e ) | |||||
{ | |||||
throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e ); | |||||
} | |||||
catch ( IOException e ) | catch ( IOException e ) | ||||
{ | { | ||||
throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e ); | throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e ); | ||||
protected RepositoryIndexSearchHit createSearchedObjectFromIndexDocument( Document doc ) | protected RepositoryIndexSearchHit createSearchedObjectFromIndexDocument( Document doc ) | ||||
throws MalformedURLException, IOException, XmlPullParserException | throws MalformedURLException, IOException, XmlPullParserException | ||||
{ | { | ||||
String groupId, artifactId, version, name, packaging; | |||||
RepositoryIndexSearchHit searchHit = null; | RepositoryIndexSearchHit searchHit = null; | ||||
// the document is of type artifact | // the document is of type artifact | ||||
if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.ARTIFACT ) ) | if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.ARTIFACT ) ) | ||||
{ | { | ||||
groupId = doc.get( RepositoryIndex.FLD_GROUPID ); | |||||
artifactId = doc.get( RepositoryIndex.FLD_ARTIFACTID ); | |||||
version = doc.get( RepositoryIndex.FLD_VERSION ); | |||||
name = doc.get( RepositoryIndex.FLD_NAME ); | |||||
packaging = doc.get( RepositoryIndex.FLD_PACKAGING ); | |||||
String groupId = doc.get( RepositoryIndex.FLD_GROUPID ); | |||||
String artifactId = doc.get( RepositoryIndex.FLD_ARTIFACTID ); | |||||
String version = doc.get( RepositoryIndex.FLD_VERSION ); | |||||
String packaging = doc.get( RepositoryIndex.FLD_PACKAGING ); | |||||
Artifact artifact = factory.createBuildArtifact( groupId, artifactId, version, packaging ); | Artifact artifact = factory.createBuildArtifact( groupId, artifactId, version, packaging ); | ||||
artifact.setFile( | artifact.setFile( | ||||
String metadataFile = (String) it.next(); | String metadataFile = (String) it.next(); | ||||
String tmpDir = (String) it.next(); | String tmpDir = (String) it.next(); | ||||
String metadataType = ""; | |||||
String metadataType; | |||||
if ( tmpDir.equals( doc.get( RepositoryIndex.FLD_VERSION ) ) ) | if ( tmpDir.equals( doc.get( RepositoryIndex.FLD_VERSION ) ) ) | ||||
{ | { | ||||
metadataType = MetadataRepositoryIndex.SNAPSHOT_METADATA; | metadataType = MetadataRepositoryIndex.SNAPSHOT_METADATA; | ||||
* @param filename the name of the metadata file | * @param filename the name of the metadata file | ||||
* @param metadataType the type of RepositoryMetadata object to be created (GROUP, ARTIFACT or SNAPSHOT) | * @param metadataType the type of RepositoryMetadata object to be created (GROUP, ARTIFACT or SNAPSHOT) | ||||
* @return RepositoryMetadata | * @return RepositoryMetadata | ||||
* @throws MalformedURLException | |||||
* @throws IOException | * @throws IOException | ||||
* @throws XmlPullParserException | * @throws XmlPullParserException | ||||
*/ | */ | ||||
private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename, | private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename, | ||||
String metadataType ) | String metadataType ) | ||||
throws MalformedURLException, IOException, XmlPullParserException | |||||
throws IOException, XmlPullParserException | |||||
{ | { | ||||
RepositoryMetadata repoMetadata = null; | RepositoryMetadata repoMetadata = null; | ||||
InputStream is = null; | |||||
// TODO! file handles left open | |||||
InputStream is; | |||||
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); | MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); | ||||
//group metadata | //group metadata |
package org.apache.maven.repository.indexing; | package org.apache.maven.repository.indexing; | ||||
/* | /* | ||||
* Copyright 2001-2005 The Apache Software Foundation. | |||||
* Copyright 2005-2006 The Apache Software Foundation. | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | * | ||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, |
* @param indexPath the path where the lucene index will be created/updated. | * @param indexPath the path where the lucene index will be created/updated. | ||||
* @param repository the repository where the indexed artifacts are located | * @param repository the repository where the indexed artifacts are located | ||||
* @param digester the digester object to generate the checksum strings | * @param digester the digester object to generate the checksum strings | ||||
* @throws RepositoryIndexException | |||||
*/ | */ | ||||
public EclipseRepositoryIndex( String indexPath, ArtifactRepository repository, Digester digester ) | public EclipseRepositoryIndex( String indexPath, ArtifactRepository repository, Digester digester ) | ||||
throws RepositoryIndexException | |||||
{ | { | ||||
super( indexPath, repository ); | super( indexPath, repository ); | ||||
* | * | ||||
* @param indexPath the path to the index | * @param indexPath the path to the index | ||||
* @param repository the repository where the metadata to be indexed is located | * @param repository the repository where the metadata to be indexed is located | ||||
* @throws RepositoryIndexException | |||||
*/ | */ | ||||
public MetadataRepositoryIndex( String indexPath, ArtifactRepository repository ) | public MetadataRepositoryIndex( String indexPath, ArtifactRepository repository ) | ||||
throws RepositoryIndexException | |||||
{ | { | ||||
super( indexPath, repository ); | super( indexPath, repository ); | ||||
} | } | ||||
repoMetadata.getBaseVersion() + "/"; | repoMetadata.getBaseVersion() + "/"; | ||||
} | } | ||||
if ( !repoMetadata.getRemoteFilename().equals( "" ) && repoMetadata.getRemoteFilename() != null ) | |||||
if ( !"".equals( repoMetadata.getRemoteFilename() ) && repoMetadata.getRemoteFilename() != null ) | |||||
{ | { | ||||
path = path + repoMetadata.getRemoteFilename(); | path = path + repoMetadata.getRemoteFilename(); | ||||
} | } | ||||
for ( Iterator iter = plugins.iterator(); iter.hasNext(); ) | for ( Iterator iter = plugins.iterator(); iter.hasNext(); ) | ||||
{ | { | ||||
Plugin plugin = (Plugin) iter.next(); | Plugin plugin = (Plugin) iter.next(); | ||||
if ( plugin.getPrefix() != null && !plugin.getPrefix().equals( "" ) ) | |||||
if ( plugin.getPrefix() != null && !"".equals( plugin.getPrefix() ) ) | |||||
{ | { | ||||
pluginAppended = plugin.getPrefix() + "\n"; | pluginAppended = plugin.getPrefix() + "\n"; | ||||
} | } | ||||
doc.add( Field.Text( FLD_PLUGINPREFIX, pluginAppended ) ); | doc.add( Field.Text( FLD_PLUGINPREFIX, pluginAppended ) ); | ||||
doc.add( Field.Text( FLD_GROUPID, metadata.getGroupId() ) ); | doc.add( Field.Text( FLD_GROUPID, metadata.getGroupId() ) ); | ||||
if ( metadata.getArtifactId() != null && !metadata.getArtifactId().equals( "" ) ) | |||||
if ( metadata.getArtifactId() != null && !"".equals( metadata.getArtifactId() ) ) | |||||
{ | { | ||||
doc.add( Field.Text( FLD_ARTIFACTID, metadata.getArtifactId() ) ); | doc.add( Field.Text( FLD_ARTIFACTID, metadata.getArtifactId() ) ); | ||||
} | } | ||||
doc.add( Field.Text( FLD_ARTIFACTID, "" ) ); | doc.add( Field.Text( FLD_ARTIFACTID, "" ) ); | ||||
} | } | ||||
if ( metadata.getVersion() != null && !metadata.getVersion().equals( "" ) ) | |||||
if ( metadata.getVersion() != null && !"".equals( metadata.getVersion() ) ) | |||||
{ | { | ||||
doc.add( Field.Text( FLD_VERSION, metadata.getVersion() ) ); | doc.add( Field.Text( FLD_VERSION, metadata.getVersion() ) ); | ||||
} | } |
package org.apache.maven.repository.indexing; | package org.apache.maven.repository.indexing; | ||||
/* | /* | ||||
* Copyright 2001-2005 The Apache Software Foundation. | |||||
* Copyright 2005-2006 The Apache Software Foundation. | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | * | ||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
import org.codehaus.plexus.util.StringUtils; | import org.codehaus.plexus.util.StringUtils; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileNotFoundException; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.security.NoSuchAlgorithmException; | import java.security.NoSuchAlgorithmException; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
* @param repository the repository where objects indexed by this class resides | * @param repository the repository where objects indexed by this class resides | ||||
* @param digester the digester to be used for generating checksums | * @param digester the digester to be used for generating checksums | ||||
* @param artifactFactory the factory for building artifact objects | * @param artifactFactory the factory for building artifact objects | ||||
* @throws RepositoryIndexException | |||||
*/ | */ | ||||
public PomRepositoryIndex( String indexPath, ArtifactRepository repository, Digester digester, | public PomRepositoryIndex( String indexPath, ArtifactRepository repository, Digester digester, | ||||
ArtifactFactory artifactFactory ) | ArtifactFactory artifactFactory ) | ||||
throws RepositoryIndexException | |||||
{ | { | ||||
super( indexPath, repository ); | super( indexPath, repository ); | ||||
this.digester = digester; | this.digester = digester; | ||||
{ | { | ||||
return digester.createChecksum( new File( file ), algorithm ); | return digester.createChecksum( new File( file ), algorithm ); | ||||
} | } | ||||
catch ( FileNotFoundException e ) | |||||
{ | |||||
throw new RepositoryIndexException( e.getMessage(), e ); | |||||
} | |||||
catch ( IOException e ) | catch ( IOException e ) | ||||
{ | { | ||||
throw new RepositoryIndexException( e.getMessage(), e ); | throw new RepositoryIndexException( e.getMessage(), e ); |
*/ | */ | ||||
public interface RepositoryIndex | public interface RepositoryIndex | ||||
{ | { | ||||
static final String POM = "POM"; | |||||
String POM = "POM"; | |||||
static final String METADATA = "METADATA"; | |||||
String METADATA = "METADATA"; | |||||
static final String ARTIFACT = "ARTIFACT"; | |||||
String ARTIFACT = "ARTIFACT"; | |||||
static final String FLD_ID = "id"; | |||||
String FLD_ID = "id"; | |||||
static final String FLD_NAME = "name"; | |||||
String FLD_NAME = "name"; | |||||
static final String FLD_DOCTYPE = "doctype"; | |||||
String FLD_DOCTYPE = "doctype"; | |||||
static final String FLD_GROUPID = "groupId"; | |||||
String FLD_GROUPID = "groupId"; | |||||
static final String FLD_ARTIFACTID = "artifactId"; | |||||
String FLD_ARTIFACTID = "artifactId"; | |||||
static final String FLD_VERSION = "version"; | |||||
String FLD_VERSION = "version"; | |||||
static final String FLD_PACKAGING = "packaging"; | |||||
String FLD_PACKAGING = "packaging"; | |||||
static final String FLD_SHA1 = "sha1"; | |||||
String FLD_SHA1 = "sha1"; | |||||
static final String FLD_MD5 = "md5"; | |||||
String FLD_MD5 = "md5"; | |||||
static final String FLD_LASTUPDATE = "last update"; | |||||
String FLD_LASTUPDATE = "last update"; | |||||
static final String FLD_PLUGINPREFIX = "plugin prefix"; | |||||
String FLD_PLUGINPREFIX = "plugin prefix"; | |||||
static final String FLD_CLASSES = "class"; | |||||
String FLD_CLASSES = "class"; | |||||
static final String FLD_PACKAGES = "package"; | |||||
String FLD_PACKAGES = "package"; | |||||
static final String FLD_FILES = "file"; | |||||
String FLD_FILES = "file"; | |||||
static final String FLD_LICENSE_URLS = "license url"; | |||||
String FLD_LICENSE_URLS = "license url"; | |||||
static final String FLD_DEPENDENCIES = "dependency"; | |||||
String FLD_DEPENDENCIES = "dependency"; | |||||
static final String FLD_PLUGINS_BUILD = "build plugin"; | |||||
String FLD_PLUGINS_BUILD = "build plugin"; | |||||
static final String FLD_PLUGINS_REPORT = "report plugin"; | |||||
String FLD_PLUGINS_REPORT = "report plugin"; | |||||
static final String FLD_PLUGINS_ALL = "plugins_all"; | |||||
String FLD_PLUGINS_ALL = "plugins_all"; | |||||
static final String[] FIELDS = {FLD_ID, FLD_NAME, FLD_DOCTYPE, FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION, | |||||
FLD_PACKAGING, FLD_SHA1, FLD_MD5, FLD_LASTUPDATE, FLD_PLUGINPREFIX, FLD_CLASSES, FLD_PACKAGES, FLD_FILES, | |||||
FLD_LICENSE_URLS, FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL}; | |||||
String[] FIELDS = {FLD_ID, FLD_NAME, FLD_DOCTYPE, FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION, FLD_PACKAGING, FLD_SHA1, | |||||
FLD_MD5, FLD_LASTUPDATE, FLD_PLUGINPREFIX, FLD_CLASSES, FLD_PACKAGES, FLD_FILES, FLD_LICENSE_URLS, | |||||
FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL}; | |||||
static final List KEYWORD_FIELDS = Arrays.asList( new String[]{FLD_ID, FLD_PACKAGING, FLD_LICENSE_URLS, | |||||
FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL} ); | |||||
List KEYWORD_FIELDS = Arrays.asList( new String[]{FLD_ID, FLD_PACKAGING, FLD_LICENSE_URLS, FLD_DEPENDENCIES, | |||||
FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL} ); | |||||
static final String[] MODEL_FIELDS = | |||||
{FLD_PACKAGING, FLD_LICENSE_URLS, FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT}; | |||||
String[] MODEL_FIELDS = {FLD_PACKAGING, FLD_LICENSE_URLS, FLD_DEPENDENCIES, FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT}; | |||||
/** | /** | ||||
* Method used to query the index status | * Method used to query the index status |
{ | { | ||||
private Object obj; | private Object obj; | ||||
private boolean isHashMap = false; | |||||
private boolean isHashMap; | |||||
private boolean isMetadata = false; | |||||
private boolean isMetadata; | |||||
private boolean isModel = false; | |||||
private boolean isModel; | |||||
/** | /** | ||||
* Class constructor | * Class constructor |
import org.apache.maven.artifact.Artifact; | import org.apache.maven.artifact.Artifact; | ||||
import org.apache.maven.artifact.factory.ArtifactFactory; | import org.apache.maven.artifact.factory.ArtifactFactory; | ||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; | |||||
import org.apache.maven.model.Dependency; | import org.apache.maven.model.Dependency; | ||||
import org.apache.maven.model.License; | import org.apache.maven.model.License; | ||||
import org.apache.maven.model.Model; | import org.apache.maven.model.Model; | ||||
else if ( hit.isMetadata() ) | else if ( hit.isMetadata() ) | ||||
{ | { | ||||
//@todo what about metadata objects? | //@todo what about metadata objects? | ||||
RepositoryMetadata metadata = (RepositoryMetadata) hit.getObject(); | |||||
// RepositoryMetadata metadata = (RepositoryMetadata) hit.getObject(); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if ( values != null && values.size() > 0 ) | |||||
if ( !values.isEmpty() ) | |||||
{ | { | ||||
resultMap.put( key, values ); | resultMap.put( key, values ); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if ( values.size() > 0 && values != null ) | |||||
if ( !values.isEmpty() ) | |||||
{ | { | ||||
map.put( field, values ); | map.put( field, values ); | ||||
} | } |
package org.apache.maven.repository.indexing; | package org.apache.maven.repository.indexing; | ||||
/* | /* | ||||
* Copyright 2001-2005 The Apache Software Foundation. | |||||
* Copyright 2005-2006 The Apache Software Foundation. | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | * | ||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, |
package org.apache.maven.repository.indexing.query; | package org.apache.maven.repository.indexing.query; | ||||
import org.apache.lucene.queryParser.ParseException; | |||||
import org.apache.maven.repository.indexing.RepositoryIndex; | |||||
/* | /* | ||||
* Copyright 2001-2005 The Apache Software Foundation. | |||||
* Copyright 2005-2006 The Apache Software Foundation. | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | * | ||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
import org.apache.lucene.queryParser.ParseException; | |||||
import org.apache.maven.repository.indexing.RepositoryIndex; | |||||
/** | /** | ||||
* Interface to label the query classes | * Interface to label the query classes | ||||
* | * |
package org.apache.maven.repository.indexing.query; | package org.apache.maven.repository.indexing.query; | ||||
import org.apache.lucene.index.Term; | |||||
import org.apache.lucene.queryParser.ParseException; | |||||
import org.apache.lucene.queryParser.QueryParser; | |||||
import org.apache.lucene.search.TermQuery; | |||||
import org.apache.maven.repository.indexing.RepositoryIndex; | |||||
/* | /* | ||||
* Copyright 2001-2005 The Apache Software Foundation. | |||||
* Copyright 2005-2006 The Apache Software Foundation. | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | * | ||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
import org.apache.lucene.index.Term; | |||||
import org.apache.lucene.queryParser.ParseException; | |||||
import org.apache.lucene.queryParser.QueryParser; | |||||
import org.apache.lucene.search.TermQuery; | |||||
import org.apache.maven.repository.indexing.RepositoryIndex; | |||||
/** | /** | ||||
* Class to hold a single field search condition | * Class to hold a single field search condition | ||||
* | * |
try | try | ||||
{ | { | ||||
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "~~~~~" ); | Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "~~~~~" ); | ||||
List artifacts = repoSearchLayer.searchAdvanced( qry ); | |||||
repoSearchLayer.searchAdvanced( qry ); | |||||
fail( "Must throw an exception on unparseable query." ); | fail( "Must throw an exception on unparseable query." ); | ||||
} | } | ||||
catch ( RepositoryIndexSearchException re ) | catch ( RepositoryIndexSearchException re ) | ||||
try | try | ||||
{ | { | ||||
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" ); | Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" ); | ||||
List artifacts = repoSearchLayer.searchAdvanced( qry ); | |||||
repoSearchLayer.searchAdvanced( qry ); | |||||
fail( "Must throw an exception on invalid index location." ); | fail( "Must throw an exception on invalid index location." ); | ||||
} | } | ||||
catch ( RepositoryIndexSearchException re ) | catch ( RepositoryIndexSearchException re ) | ||||
RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer ); | RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer ); | ||||
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + artifact.getId() ); | Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + artifact.getId() ); | ||||
List artifacts = repoSearcher.search( qry ); | List artifacts = repoSearcher.search( qry ); | ||||
assertEquals( artifacts.size(), 0 ); | |||||
assertEquals( 0, artifacts.size() ); | |||||
} | } | ||||
/** | /** |
package org.apache.maven.repository.indexing; | package org.apache.maven.repository.indexing; | ||||
/* | |||||
* 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.lucene.document.DateField; | import org.apache.lucene.document.DateField; | ||||
import org.apache.lucene.document.Document; | import org.apache.lucene.document.Document; | ||||
import org.apache.lucene.queryParser.QueryParser; | import org.apache.lucene.queryParser.QueryParser; | ||||
import java.io.File; | import java.io.File; | ||||
/* | |||||
* 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. | |||||
*/ | |||||
/** | /** | ||||
* @author Edwin Punzalan | * @author Edwin Punzalan | ||||
*/ | */ | ||||
private long artifactFileTime; | private long artifactFileTime; | ||||
private static final long TIME_DIFFERENCE = 10000L; | |||||
protected void setUp() | protected void setUp() | ||||
throws Exception | throws Exception | ||||
{ | { | ||||
indexer.optimize(); | indexer.optimize(); | ||||
indexer.close(); | indexer.close(); | ||||
long historicTime = artifactFileTime - 10000L; | |||||
long historicTime = artifactFileTime - TIME_DIFFERENCE; | |||||
artifact = getArtifact( "org.apache.maven", "maven-model", "2.0" ); | artifact = getArtifact( "org.apache.maven", "maven-model", "2.0" ); | ||||
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); | artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); |
private String indexPath; | private String indexPath; | ||||
private MetadataRepositoryIndex indexer; | |||||
private ArtifactFactory artifactFactory; | private ArtifactFactory artifactFactory; | ||||
/** | /** | ||||
throws Exception | throws Exception | ||||
{ | { | ||||
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); | RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); | ||||
indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); | |||||
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); | |||||
RepositoryMetadata repoMetadata = | RepositoryMetadata repoMetadata = | ||||
getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA ); | getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA ); | ||||
RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer ); | RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer ); | ||||
// search last update | // search last update | ||||
org.apache.maven.repository.indexing.query.Query qry = | |||||
new SinglePhraseQuery( RepositoryIndex.FLD_LASTUPDATE, "20051212044643" ); | |||||
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_LASTUPDATE, "20051212044643" ); | |||||
List metadataList = repoSearchLayer.searchAdvanced( qry ); | List metadataList = repoSearchLayer.searchAdvanced( qry ); | ||||
//assertEquals( 1, metadataList.size() ); | //assertEquals( 1, metadataList.size() ); | ||||
for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) | for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) | ||||
rQry.addQuery( qry2 ); | rQry.addQuery( qry2 ); | ||||
metadataList = repoSearchLayer.searchAdvanced( rQry ); | metadataList = repoSearchLayer.searchAdvanced( rQry ); | ||||
assertEquals( metadataList.size(), 0 ); | |||||
assertEquals( 0, metadataList.size() ); | |||||
indexer.close(); | indexer.close(); | ||||
} | } | ||||
{ | { | ||||
//test when the object passed in the index(..) method is not a RepositoryMetadata instance | //test when the object passed in the index(..) method is not a RepositoryMetadata instance | ||||
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); | RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); | ||||
indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); | |||||
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); | |||||
try | try | ||||
{ | { | ||||
Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ); | Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ); | ||||
createTestIndex(); | createTestIndex(); | ||||
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); | RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); | ||||
indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); | |||||
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); | |||||
RepositoryMetadata repoMetadata = | RepositoryMetadata repoMetadata = | ||||
getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA ); | getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA ); | ||||
indexer.deleteDocument( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() ); | indexer.deleteDocument( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() ); | ||||
RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer ); | RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer ); | ||||
org.apache.maven.repository.indexing.query.Query qry = | |||||
new SinglePhraseQuery( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() ); | |||||
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() ); | |||||
List metadataList = repoSearcher.search( qry ); | List metadataList = repoSearcher.search( qry ); | ||||
assertEquals( metadataList.size(), 0 ); | |||||
assertEquals( 0, metadataList.size() ); | |||||
} | } | ||||
/** | /** | ||||
{ | { | ||||
RepositoryMetadata repoMetadata = null; | RepositoryMetadata repoMetadata = null; | ||||
URL url; | URL url; | ||||
InputStream is = null; | |||||
InputStream is; | |||||
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); | MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); | ||||
//group metadata | //group metadata |
package org.apache.maven.repository.indexing; | package org.apache.maven.repository.indexing; | ||||
/** | |||||
/* | |||||
* Copyright 2005-2006 The Apache Software Foundation. | * Copyright 2005-2006 The Apache Software Foundation. | ||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
SearchResult result = (SearchResult) artifacts.next(); | SearchResult result = (SearchResult) artifacts.next(); | ||||
Map map = result.getFieldMatches(); | Map map = result.getFieldMatches(); | ||||
Set mapEntry = map.entrySet(); | Set mapEntry = map.entrySet(); | ||||
for ( Iterator it = mapEntry.iterator(); it.hasNext(); ) | |||||
{ | |||||
Map.Entry entry = (Map.Entry) it.next(); | |||||
} | |||||
assertEquals( "jar", (String) map.get( RepositoryIndex.FLD_PACKAGING ) ); | assertEquals( "jar", (String) map.get( RepositoryIndex.FLD_PACKAGING ) ); | ||||
} | } | ||||
SearchResult result = (SearchResult) artifacts.next(); | SearchResult result = (SearchResult) artifacts.next(); | ||||
Map map = result.getFieldMatches(); | Map map = result.getFieldMatches(); | ||||
boolean depFound = false; | boolean depFound = false; | ||||
Iterator dependencies = ( (List) map.get( RepositoryIndex.FLD_DEPENDENCIES ) ).iterator(); | |||||
List list = (List) map.get( RepositoryIndex.FLD_DEPENDENCIES ); | |||||
Iterator dependencies = list.iterator(); | |||||
while ( dependencies.hasNext() ) | while ( dependencies.hasNext() ) | ||||
{ | { | ||||
String dep = (String) dependencies.next(); | String dep = (String) dependencies.next(); | ||||
{ | { | ||||
SearchResult result = (SearchResult) artifacts.next(); | SearchResult result = (SearchResult) artifacts.next(); | ||||
Map map = result.getFieldMatches(); | Map map = result.getFieldMatches(); | ||||
Iterator plugins = ( (List) map.get( RepositoryIndex.FLD_PLUGINS_BUILD ) ).iterator(); | |||||
List list = (List) map.get( RepositoryIndex.FLD_PLUGINS_BUILD ); | |||||
Iterator plugins = list.iterator(); | |||||
boolean found = false; | boolean found = false; | ||||
while ( plugins.hasNext() ) | while ( plugins.hasNext() ) | ||||
{ | { | ||||
{ | { | ||||
SearchResult result = (SearchResult) artifacts.next(); | SearchResult result = (SearchResult) artifacts.next(); | ||||
Map map = result.getFieldMatches(); | Map map = result.getFieldMatches(); | ||||
Iterator plugins = ( (List) map.get( RepositoryIndex.FLD_PLUGINS_REPORT ) ).iterator(); | |||||
List list = (List) map.get( RepositoryIndex.FLD_PLUGINS_REPORT ); | |||||
Iterator plugins = list.iterator(); | |||||
boolean found = false; | boolean found = false; | ||||
while ( plugins.hasNext() ) | while ( plugins.hasNext() ) | ||||
{ | { | ||||
RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer ); | RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer ); | ||||
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.POM + pom.getId() ); | Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.POM + pom.getId() ); | ||||
List artifactList = repoSearcher.search( qry ); | List artifactList = repoSearcher.search( qry ); | ||||
assertEquals( artifactList.size(), 0 ); | |||||
assertEquals( 0, artifactList.size() ); | |||||
} | } | ||||
private Model getPom( String groupId, String artifactId, String version ) | private Model getPom( String groupId, String artifactId, String version ) |
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; | import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; | ||||
import org.apache.maven.model.Model; | import org.apache.maven.model.Model; | ||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; | import org.apache.maven.model.io.xpp3.MavenXpp3Reader; | ||||
import org.apache.maven.repository.digest.DefaultDigester; | |||||
import org.apache.maven.repository.digest.Digester; | |||||
import org.codehaus.plexus.PlexusTestCase; | import org.codehaus.plexus.PlexusTestCase; | ||||
import org.codehaus.plexus.util.FileUtils; | import org.codehaus.plexus.util.FileUtils; | ||||
private ArtifactFactory artifactFactory; | private ArtifactFactory artifactFactory; | ||||
private Digester digester; | |||||
private String indexPath; | private String indexPath; | ||||
/** | /** | ||||
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); | ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); | ||||
ArtifactRepositoryFactory repoFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); | ArtifactRepositoryFactory repoFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); | ||||
repository = repoFactory.createArtifactRepository( "test", repoDir, layout, null, null ); | repository = repoFactory.createArtifactRepository( "test", repoDir, layout, null, null ); | ||||
digester = new DefaultDigester(); | |||||
indexPath = "target/index"; | indexPath = "target/index"; | ||||
FileUtils.deleteDirectory( indexPath ); | FileUtils.deleteDirectory( indexPath ); | ||||
} | } | ||||
/** | |||||
* Tear down method | |||||
* | |||||
* @throws Exception | |||||
*/ | |||||
protected void tearDown() | |||||
throws Exception | |||||
{ | |||||
super.tearDown(); | |||||
} | |||||
/** | /** | ||||
* Method for creating the index used for testing | * Method for creating the index used for testing | ||||
* | * | ||||
MetadataRepositoryIndex metaIndexer = factory.createMetadataRepositoryIndex( indexPath, repository ); | MetadataRepositoryIndex metaIndexer = factory.createMetadataRepositoryIndex( indexPath, repository ); | ||||
RepositoryMetadata repoMetadata = | RepositoryMetadata repoMetadata = | ||||
getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", metaIndexer.GROUP_METADATA ); | |||||
getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA ); | |||||
metaIndexer.index( repoMetadata ); | metaIndexer.index( repoMetadata ); | ||||
metaIndexer.optimize(); | metaIndexer.optimize(); | ||||
metaIndexer.close(); | metaIndexer.close(); | ||||
repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml", | repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml", | ||||
metaIndexer.ARTIFACT_METADATA ); | |||||
MetadataRepositoryIndex.ARTIFACT_METADATA ); | |||||
metaIndexer.index( repoMetadata ); | metaIndexer.index( repoMetadata ); | ||||
metaIndexer.optimize(); | metaIndexer.optimize(); | ||||
metaIndexer.close(); | metaIndexer.close(); | ||||
repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml", | repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml", | ||||
metaIndexer.SNAPSHOT_METADATA ); | |||||
MetadataRepositoryIndex.SNAPSHOT_METADATA ); | |||||
metaIndexer.index( repoMetadata ); | metaIndexer.index( repoMetadata ); | ||||
metaIndexer.optimize(); | metaIndexer.optimize(); | ||||
metaIndexer.close(); | metaIndexer.close(); | ||||
repoMetadata = getMetadata( "test", null, null, "maven-metadata.xml", metaIndexer.GROUP_METADATA ); | |||||
repoMetadata = getMetadata( "test", null, null, "maven-metadata.xml", MetadataRepositoryIndex.GROUP_METADATA ); | |||||
metaIndexer.index( repoMetadata ); | metaIndexer.index( repoMetadata ); | ||||
metaIndexer.optimize(); | metaIndexer.optimize(); | ||||
metaIndexer.close(); | metaIndexer.close(); | ||||
for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) | for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) | ||||
{ | { | ||||
SearchResult result = (SearchResult) iter.next(); | SearchResult result = (SearchResult) iter.next(); | ||||
assertEquals( result.getArtifact().getGroupId(), "test" ); | |||||
assertEquals( "test", result.getArtifact().getGroupId() ); | |||||
} | } | ||||
returnList = searchLayer.searchGeneral( "test-artifactId" ); | returnList = searchLayer.searchGeneral( "test-artifactId" ); | ||||
for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) | for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) | ||||
{ | { | ||||
SearchResult result = (SearchResult) iter.next(); | SearchResult result = (SearchResult) iter.next(); | ||||
assertEquals( result.getArtifact().getArtifactId(), "test-artifactId" ); | |||||
assertEquals( "test-artifactId", result.getArtifact().getArtifactId() ); | |||||
} | } | ||||
} | } | ||||
{ | { | ||||
RepositoryMetadata repoMetadata = null; | RepositoryMetadata repoMetadata = null; | ||||
URL url; | URL url; | ||||
InputStream is = null; | |||||
InputStream is; | |||||
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); | MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); | ||||
//group metadata | //group metadata |
package org.apache.maven.repository.indexing.query; | package org.apache.maven.repository.indexing.query; | ||||
import junit.framework.TestCase; | |||||
/* | /* | ||||
* Copyright 2001-2005 The Apache Software Foundation. | |||||
* Copyright 2005-2006 The Apache Software Foundation. | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | * | ||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
import junit.framework.TestCase; | |||||
/** | /** | ||||
* @author Edwin Punzalan | * @author Edwin Punzalan | ||||
*/ | */ |
<?xml version="1.0"?><project> | |||||
<?xml version="1.0"?> | |||||
<!-- | |||||
~ 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> | |||||
<parent> | <parent> | ||||
<artifactId>maven-repository-manager</artifactId> | <artifactId>maven-repository-manager</artifactId> | ||||
<groupId>org.apache.maven.repository</groupId> | <groupId>org.apache.maven.repository</groupId> |
<?xml version="1.0" encoding="ISO-8859-1"?> | <?xml version="1.0" encoding="ISO-8859-1"?> | ||||
<!-- | |||||
~ 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> | <project> | ||||
<body> | <body> | ||||
<links> | <links> | ||||
<item name="Maven" href="http://maven.apache.org/"/> | <item name="Maven" href="http://maven.apache.org/"/> | ||||
</links> | </links> | ||||
<menu ref="reports" /> | |||||
<menu ref="reports"/> | |||||
</body> | </body> | ||||
<skin> | <skin> | ||||
<groupId>org.apache.maven.skins</groupId> | <groupId>org.apache.maven.skins</groupId> | ||||
<artifactId>maven-stylus-skin</artifactId> | <artifactId>maven-stylus-skin</artifactId> | ||||
</skin> | </skin> | ||||
<publishDate format="dd MMM yyyy" /> | |||||
<publishDate format="dd MMM yyyy"/> | |||||
<bannerLeft> | <bannerLeft> | ||||
<name>Maven</name> | <name>Maven</name> | ||||
<src>http://maven.apache.org/images/apache-maven-project-2.png</src> | <src>http://maven.apache.org/images/apache-maven-project-2.png</src> |
*/ | */ | ||||
private Map failuresCache = new HashMap(); | private Map failuresCache = new HashMap(); | ||||
private static final int MS_PER_SEC = 1000; | |||||
public void setConfiguration( ProxyConfiguration config ) | public void setConfiguration( ProxyConfiguration config ) | ||||
{ | { | ||||
this.config = config; | this.config = config; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
long repoTimestamp = target.lastModified() + repository.getCachePeriod() * 1000; | |||||
long repoTimestamp = target.lastModified() + repository.getCachePeriod() * MS_PER_SEC; | |||||
wagon.getIfNewer( path, temp, repoTimestamp ); | wagon.getIfNewer( path, temp, repoTimestamp ); | ||||
} | } | ||||
*/ | */ | ||||
public interface ProxyManager | public interface ProxyManager | ||||
{ | { | ||||
static String ROLE = ProxyManager.class.getName(); | |||||
String ROLE = ProxyManager.class.getName(); | |||||
/** | /** | ||||
* Used to retrieve a cached path or retrieve one if the cache does not contain it yet. | * Used to retrieve a cached path or retrieve one if the cache does not contain it yet. |
package org.apache.maven.repository.proxy.configuration; | package org.apache.maven.repository.proxy.configuration; | ||||
/* | /* | ||||
* Copyright 2003-2004 The Apache Software Foundation. | |||||
* Copyright 2005-2006 The Apache Software Foundation. | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | * | ||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
config.setRepositoryCachePath( getMandatoryProperty( props, REPO_LOCAL_STORE ) ); | config.setRepositoryCachePath( getMandatoryProperty( props, REPO_LOCAL_STORE ) ); | ||||
{//just get the first proxy and break | |||||
String propertyList = props.getProperty( PROXY_LIST ); | |||||
if ( propertyList != null ) | |||||
//just get the first proxy and break | |||||
String propertyList = props.getProperty( PROXY_LIST ); | |||||
if ( propertyList != null ) | |||||
{ | |||||
StringTokenizer tok = new StringTokenizer( propertyList, "," ); | |||||
while ( tok.hasMoreTokens() ) | |||||
{ | { | ||||
StringTokenizer tok = new StringTokenizer( propertyList, "," ); | |||||
while ( tok.hasMoreTokens() ) | |||||
String key = tok.nextToken(); | |||||
if ( StringUtils.isNotEmpty( key ) ) | |||||
{ | { | ||||
String key = tok.nextToken(); | |||||
if ( StringUtils.isNotEmpty( key ) ) | |||||
String host = getMandatoryProperty( props, "proxy." + key + ".host" ); | |||||
int port = Integer.parseInt( getMandatoryProperty( props, "proxy." + key + ".port" ) ); | |||||
// the username and password isn't required | |||||
String username = props.getProperty( "proxy." + key + ".username" ); | |||||
String password = props.getProperty( "proxy." + key + ".password" ); | |||||
if ( StringUtils.isNotEmpty( username ) ) | |||||
{ | { | ||||
String host = getMandatoryProperty( props, "proxy." + key + ".host" ); | |||||
int port = Integer.parseInt( getMandatoryProperty( props, "proxy." + key + ".port" ) ); | |||||
// the username and password isn't required | |||||
String username = props.getProperty( "proxy." + key + ".username" ); | |||||
String password = props.getProperty( "proxy." + key + ".password" ); | |||||
if ( StringUtils.isNotEmpty( username ) ) | |||||
{ | |||||
config.setHttpProxy( host, port, username, password ); | |||||
} | |||||
else | |||||
{ | |||||
config.setHttpProxy( host, port ); | |||||
} | |||||
//accept only one proxy configuration | |||||
break; | |||||
config.setHttpProxy( host, port, username, password ); | |||||
} | } | ||||
else | |||||
{ | |||||
config.setHttpProxy( host, port ); | |||||
} | |||||
//accept only one proxy configuration | |||||
break; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
List repositories = new ArrayList(); | List repositories = new ArrayList(); | ||||
{ //get the remote repository list | |||||
String repoList = getMandatoryProperty( props, REPO_LIST ); | |||||
StringTokenizer tok = new StringTokenizer( repoList, "," ); | |||||
while ( tok.hasMoreTokens() ) | |||||
{ | |||||
String key = tok.nextToken(); | |||||
//get the remote repository list | |||||
String repoList = getMandatoryProperty( props, REPO_LIST ); | |||||
Properties repoProps = getSubset( props, "repo." + key + "." ); | |||||
String url = getMandatoryProperty( props, "repo." + key + ".url" ); | |||||
String proxyKey = repoProps.getProperty( "proxy" ); | |||||
StringTokenizer tok = new StringTokenizer( repoList, "," ); | |||||
while ( tok.hasMoreTokens() ) | |||||
{ | |||||
String key = tok.nextToken(); | |||||
boolean cacheFailures = | |||||
Boolean.valueOf( repoProps.getProperty( "cache.failures", "false" ) ).booleanValue(); | |||||
boolean hardFail = Boolean.valueOf( repoProps.getProperty( "hardfail", "true" ) ).booleanValue(); | |||||
long cachePeriod = Long.parseLong( repoProps.getProperty( "cache.period", "0" ) ); | |||||
Properties repoProps = getSubset( props, "repo." + key + "." ); | |||||
String url = getMandatoryProperty( props, "repo." + key + ".url" ); | |||||
String proxyKey = repoProps.getProperty( "proxy" ); | |||||
ProxyRepository repository = | |||||
new ProxyRepository( key, url, new DefaultRepositoryLayout(), cacheFailures, cachePeriod ); | |||||
boolean cacheFailures = | |||||
Boolean.valueOf( repoProps.getProperty( "cache.failures", "false" ) ).booleanValue(); | |||||
boolean hardFail = Boolean.valueOf( repoProps.getProperty( "hardfail", "true" ) ).booleanValue(); | |||||
long cachePeriod = Long.parseLong( repoProps.getProperty( "cache.period", "0" ) ); | |||||
repository.setHardfail( hardFail ); | |||||
ProxyRepository repository = | |||||
new ProxyRepository( key, url, new DefaultRepositoryLayout(), cacheFailures, cachePeriod ); | |||||
if ( StringUtils.isNotEmpty( proxyKey ) ) | |||||
{ | |||||
repository.setProxied( true ); | |||||
} | |||||
repository.setHardfail( hardFail ); | |||||
repositories.add( repository ); | |||||
if ( StringUtils.isNotEmpty( proxyKey ) ) | |||||
{ | |||||
repository.setProxied( true ); | |||||
} | } | ||||
repositories.add( repository ); | |||||
} | } | ||||
config.setRepositories( repositories ); | config.setRepositories( repositories ); | ||||
validateDirectories( config ); | validateDirectories( config ); | ||||
private String getMandatoryProperty( Properties props, String key ) | private String getMandatoryProperty( Properties props, String key ) | ||||
throws ValidationException | throws ValidationException | ||||
{ | { | ||||
final String value = props.getProperty( key ); | |||||
String value = props.getProperty( key ); | |||||
if ( value == null ) | if ( value == null ) | ||||
{ | { |
proxyInfo.setHost( host ); | proxyInfo.setHost( host ); | ||||
proxyInfo.setPort( port ); | proxyInfo.setPort( port ); | ||||
setHttpProxy( proxyInfo ); | |||||
httpProxy = proxyInfo; | |||||
} | } | ||||
public void setHttpProxy( String host, int port, String username, String password ) | public void setHttpProxy( String host, int port, String username, String password ) |
package org.apache.maven.repository.proxy.configuration; | package org.apache.maven.repository.proxy.configuration; | ||||
/* | /* | ||||
* Copyright 2003-2004 The Apache Software Foundation. | |||||
* Copyright 2005-2006 The Apache Software Foundation. | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | * | ||||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, |
extends DefaultArtifactRepository | extends DefaultArtifactRepository | ||||
{ | { | ||||
// zero caches forever | // zero caches forever | ||||
private long cachePeriod = 0; | |||||
private long cachePeriod; | |||||
private boolean cacheFailures = false; | |||||
private boolean cacheFailures; | |||||
private boolean hardfail = true; | private boolean hardfail = true; | ||||
private boolean proxied = false; | |||||
private boolean proxied; | |||||
public ProxyRepository( String id, String url, ArtifactRepositoryLayout layout, boolean cacheFailures, | public ProxyRepository( String id, String url, ArtifactRepositoryLayout layout, boolean cacheFailures, | ||||
long cachePeriod ) | long cachePeriod ) | ||||
{ | { | ||||
this( id, url, layout ); | this( id, url, layout ); | ||||
setCacheFailures( cacheFailures ); | |||||
this.cacheFailures = cacheFailures; | |||||
setCachePeriod( cachePeriod ); | |||||
this.cachePeriod = cachePeriod; | |||||
} | } | ||||
public ProxyRepository( String id, String url, ArtifactRepositoryLayout layout ) | public ProxyRepository( String id, String url, ArtifactRepositoryLayout layout ) |
package org.apache.maven.repository.proxy; | package org.apache.maven.repository.proxy; | ||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | |||||
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; | |||||
import org.apache.maven.repository.proxy.configuration.ProxyConfiguration; | |||||
import org.apache.maven.repository.proxy.repository.ProxyRepository; | |||||
import org.apache.maven.wagon.ResourceDoesNotExistException; | |||||
import org.codehaus.plexus.PlexusTestCase; | |||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; | |||||
import java.io.File; | |||||
/* | /* | ||||
* Copyright 2005-2006 The Apache Software Foundation. | * Copyright 2005-2006 The Apache Software Foundation. | ||||
* | * | ||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | |||||
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; | |||||
import org.apache.maven.repository.proxy.configuration.ProxyConfiguration; | |||||
import org.apache.maven.repository.proxy.repository.ProxyRepository; | |||||
import org.apache.maven.wagon.ResourceDoesNotExistException; | |||||
import org.codehaus.plexus.PlexusTestCase; | |||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; | |||||
import java.io.File; | |||||
/** | /** | ||||
* @author Edwin Punzalan | * @author Edwin Punzalan | ||||
*/ | */ | ||||
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) ); | file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) ); | ||||
//test cache | //test cache | ||||
file = proxy.get( "/commons-logging/commons-logging/1.0/commons-logging-1.0.jar" ); | |||||
proxy.get( "/commons-logging/commons-logging/1.0/commons-logging-1.0.jar" ); | |||||
try | try | ||||
{ | { | ||||
file = proxy.get( "/commons-logging/commons-logging/2.0/commons-logging-2.0.jar" ); | |||||
proxy.get( "/commons-logging/commons-logging/2.0/commons-logging-2.0.jar" ); | |||||
fail( "Expected ResourceDoesNotExistException exception not thrown" ); | fail( "Expected ResourceDoesNotExistException exception not thrown" ); | ||||
} | } | ||||
catch ( ResourceDoesNotExistException e ) | catch ( ResourceDoesNotExistException e ) |
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) ); | file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) ); | ||||
//test cache | //test cache | ||||
file = proxy.get( "/commons-logging/jars/commons-logging-1.0.jar" ); | |||||
proxy.get( "/commons-logging/jars/commons-logging-1.0.jar" ); | |||||
try | try | ||||
{ | { | ||||
file = proxy.get( "/commons-logging/jars/commons-logging-2.0.jar" ); | |||||
proxy.get( "/commons-logging/jars/commons-logging-2.0.jar" ); | |||||
fail( "Expected ResourceDoesNotExistException exception not thrown" ); | fail( "Expected ResourceDoesNotExistException exception not thrown" ); | ||||
} | } | ||||
catch ( ResourceDoesNotExistException e ) | catch ( ResourceDoesNotExistException e ) |
import java.io.File; | import java.io.File; | ||||
import java.io.FileInputStream; | import java.io.FileInputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Iterator; | |||||
/** | /** | ||||
public class MavenProxyPropertyLoaderTest | public class MavenProxyPropertyLoaderTest | ||||
extends PlexusTestCase | extends PlexusTestCase | ||||
{ | { | ||||
private static final int DEFAULT_CACHE_PERIOD = 3600; | |||||
public void testLoadValidMavenProxyConfiguration() | public void testLoadValidMavenProxyConfiguration() | ||||
throws ValidationException, IOException | throws ValidationException, IOException | ||||
{ | { | ||||
assertEquals( "Count repositories", 4, config.getRepositories().size() ); | assertEquals( "Count repositories", 4, config.getRepositories().size() ); | ||||
int idx = 0; | |||||
for ( Iterator repos = config.getRepositories().iterator(); repos.hasNext(); ) | |||||
{ | |||||
idx++; | |||||
ProxyRepository repo = (ProxyRepository) repos.next(); | |||||
//switch is made to check for ordering | |||||
switch ( idx ) | |||||
{ | |||||
case 1: | |||||
assertEquals( "Repository name not as expected", "local-repo", repo.getKey() ); | |||||
assertEquals( "Repository url does not match its name", "file://target", repo.getUrl() ); | |||||
assertEquals( "Repository cache period check failed", 0, repo.getCachePeriod() ); | |||||
assertFalse( "Repository failure caching check failed", repo.isCacheFailures() ); | |||||
break; | |||||
case 2: | |||||
assertEquals( "Repository name not as expected", "www-ibiblio-org", repo.getKey() ); | |||||
assertEquals( "Repository url does not match its name", "http://www.ibiblio.org/maven2", | |||||
repo.getUrl() ); | |||||
assertEquals( "Repository cache period check failed", 3600, repo.getCachePeriod() ); | |||||
assertTrue( "Repository failure caching check failed", repo.isCacheFailures() ); | |||||
break; | |||||
case 3: | |||||
assertEquals( "Repository name not as expected", "dist-codehaus-org", repo.getKey() ); | |||||
assertEquals( "Repository url does not match its name", "http://dist.codehaus.org", | |||||
repo.getUrl() ); | |||||
assertEquals( "Repository cache period check failed", 3600, repo.getCachePeriod() ); | |||||
assertTrue( "Repository failure caching check failed", repo.isCacheFailures() ); | |||||
break; | |||||
case 4: | |||||
assertEquals( "Repository name not as expected", "private-example-com", repo.getKey() ); | |||||
assertEquals( "Repository url does not match its name", "http://private.example.com/internal", | |||||
repo.getUrl() ); | |||||
assertEquals( "Repository cache period check failed", 3600, repo.getCachePeriod() ); | |||||
assertFalse( "Repository failure caching check failed", repo.isCacheFailures() ); | |||||
break; | |||||
default: | |||||
fail( "Unexpected order count" ); | |||||
} | |||||
} | |||||
ProxyRepository repo = (ProxyRepository) config.getRepositories().get( 0 ); | |||||
assertEquals( "Repository name not as expected", "local-repo", repo.getKey() ); | |||||
assertEquals( "Repository url does not match its name", "file://target", repo.getUrl() ); | |||||
assertEquals( "Repository cache period check failed", 0, repo.getCachePeriod() ); | |||||
assertFalse( "Repository failure caching check failed", repo.isCacheFailures() ); | |||||
repo = (ProxyRepository) config.getRepositories().get( 1 ); | |||||
assertEquals( "Repository name not as expected", "www-ibiblio-org", repo.getKey() ); | |||||
assertEquals( "Repository url does not match its name", "http://www.ibiblio.org/maven2", repo.getUrl() ); | |||||
assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getCachePeriod() ); | |||||
assertTrue( "Repository failure caching check failed", repo.isCacheFailures() ); | |||||
repo = (ProxyRepository) config.getRepositories().get( 2 ); | |||||
assertEquals( "Repository name not as expected", "dist-codehaus-org", repo.getKey() ); | |||||
assertEquals( "Repository url does not match its name", "http://dist.codehaus.org", repo.getUrl() ); | |||||
assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getCachePeriod() ); | |||||
assertTrue( "Repository failure caching check failed", repo.isCacheFailures() ); | |||||
repo = (ProxyRepository) config.getRepositories().get( 3 ); | |||||
assertEquals( "Repository name not as expected", "private-example-com", repo.getKey() ); | |||||
assertEquals( "Repository url does not match its name", "http://private.example.com/internal", | |||||
repo.getUrl() ); | |||||
assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getCachePeriod() ); | |||||
assertFalse( "Repository failure caching check failed", repo.isCacheFailures() ); | |||||
} | } | ||||
//make sure to delete the test directory after tests | |||||
finally | finally | ||||
{ | { | ||||
//make sure to delete the test directory after tests | |||||
FileUtils.deleteDirectory( "target/remote-repo1" ); | FileUtils.deleteDirectory( "target/remote-repo1" ); | ||||
} | } | ||||
} | } |
{ | { | ||||
private ProxyConfiguration config; | private ProxyConfiguration config; | ||||
private static final int DEFAULT_CACHE_PERIOD = 3600; | |||||
private static final int DEFAULT_PORT = 80; | |||||
protected void setUp() | protected void setUp() | ||||
throws Exception | throws Exception | ||||
{ | { | ||||
ArtifactRepositoryLayout legacyLayout = new LegacyRepositoryLayout(); | ArtifactRepositoryLayout legacyLayout = new LegacyRepositoryLayout(); | ||||
ProxyRepository repo2 = new ProxyRepository( "repo2", "http://www.ibiblio.org/maven", legacyLayout ); | ProxyRepository repo2 = new ProxyRepository( "repo2", "http://www.ibiblio.org/maven", legacyLayout ); | ||||
repo2.setCacheFailures( false ); | repo2.setCacheFailures( false ); | ||||
repo2.setCachePeriod( 3600 ); | |||||
repo2.setCachePeriod( DEFAULT_CACHE_PERIOD ); | |||||
repo2.setProxied( true ); | repo2.setProxied( true ); | ||||
config.setHttpProxy( "some.local.proxy", 80, "username", "password" ); | |||||
config.setHttpProxy( "some.local.proxy", DEFAULT_PORT, "username", "password" ); | |||||
config.addRepository( repo2 ); | config.addRepository( repo2 ); | ||||
assertEquals( 2, config.getRepositories().size() ); | assertEquals( 2, config.getRepositories().size() ); | ||||
assertEquals( "http://www.ibiblio.org/maven", repo.getUrl() ); | assertEquals( "http://www.ibiblio.org/maven", repo.getUrl() ); | ||||
assertFalse( repo.isCacheFailures() ); | assertFalse( repo.isCacheFailures() ); | ||||
assertTrue( repo.isHardfail() ); | assertTrue( repo.isHardfail() ); | ||||
assertEquals( 3600, repo.getCachePeriod() ); | |||||
assertEquals( DEFAULT_CACHE_PERIOD, repo.getCachePeriod() ); | |||||
assertEquals( repo2, repo ); | assertEquals( repo2, repo ); | ||||
assertTrue( repo.isProxied() ); | assertTrue( repo.isProxied() ); | ||||
ProxyInfo proxyInfo = config.getHttpProxy(); | ProxyInfo proxyInfo = config.getHttpProxy(); | ||||
assertNotNull( proxyInfo ); | assertNotNull( proxyInfo ); | ||||
assertEquals( "some.local.proxy", proxyInfo.getHost() ); | assertEquals( "some.local.proxy", proxyInfo.getHost() ); | ||||
assertEquals( 80, proxyInfo.getPort() ); | |||||
assertEquals( DEFAULT_PORT, proxyInfo.getPort() ); | |||||
assertEquals( "username", proxyInfo.getUserName() ); | assertEquals( "username", proxyInfo.getUserName() ); | ||||
assertEquals( "password", proxyInfo.getPassword() ); | assertEquals( "password", proxyInfo.getPassword() ); | ||||
repositories.add( new ProxyRepository( "repo", "url", defLayout ) ); | repositories.add( new ProxyRepository( "repo", "url", defLayout ) ); | ||||
fail( "Expected UnsupportedOperationException not thrown." ); | fail( "Expected UnsupportedOperationException not thrown." ); | ||||
} | } | ||||
catch ( java.lang.UnsupportedOperationException e ) | |||||
catch ( UnsupportedOperationException e ) | |||||
{ | { | ||||
assertTrue( true ); | assertTrue( true ); | ||||
} | } |
* @param key the object to map the valued object | * @param key the object to map the valued object | ||||
* @param value the object to cache | * @param value the object to cache | ||||
*/ | */ | ||||
public Object put( Object key, Object value ) | |||||
public void put( Object key, Object value ) | |||||
{ | { | ||||
Object old = null; | Object old = null; | ||||
} | } | ||||
manageCache(); | manageCache(); | ||||
return old; | |||||
} | } | ||||
/** | /** |
*/ | */ | ||||
public class ArtifactUtils | public class ArtifactUtils | ||||
{ | { | ||||
private ArtifactUtils() | |||||
{ | |||||
} | |||||
/** | /** | ||||
* Method used to build an artifact and then set its repository and file fields with the proper values | * Method used to build an artifact and then set its repository and file fields with the proper values | ||||
* | * | ||||
// contains artifactId, version, classifier, and extension. | // contains artifactId, version, classifier, and extension. | ||||
String avceGlob = tokens.nextToken(); | String avceGlob = tokens.nextToken(); | ||||
//noinspection CollectionDeclaredAsConcreteClass | |||||
LinkedList avceTokenList = new LinkedList(); | LinkedList avceTokenList = new LinkedList(); | ||||
StringTokenizer avceTokenizer = new StringTokenizer( avceGlob, "-" ); | StringTokenizer avceTokenizer = new StringTokenizer( avceGlob, "-" ); |
package org.apache.maven.repository.digest; | package org.apache.maven.repository.digest; | ||||
import org.codehaus.plexus.util.IOUtil; | |||||
import java.io.File; | |||||
import java.io.FileInputStream; | |||||
import java.io.IOException; | |||||
import java.io.InputStream; | |||||
import java.security.MessageDigest; | |||||
import java.security.NoSuchAlgorithmException; | |||||
import java.util.regex.Matcher; | |||||
import java.util.regex.Pattern; | |||||
/* | /* | ||||
* Copyright 2005-2006 The Apache Software Foundation. | * Copyright 2005-2006 The Apache Software Foundation. | ||||
* | * | ||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
import org.codehaus.plexus.util.IOUtil; | |||||
import java.io.File; | |||||
import java.io.FileInputStream; | |||||
import java.io.IOException; | |||||
import java.io.InputStream; | |||||
import java.security.MessageDigest; | |||||
import java.security.NoSuchAlgorithmException; | |||||
import java.util.regex.Matcher; | |||||
import java.util.regex.Pattern; | |||||
/** | /** | ||||
* Create a digest for a file. | * Create a digest for a file. | ||||
* | * |
package org.apache.maven.repository; | package org.apache.maven.repository; | ||||
/* | |||||
* 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.Artifact; | ||||
import org.apache.maven.artifact.factory.ArtifactFactory; | import org.apache.maven.artifact.factory.ArtifactFactory; | ||||
import org.codehaus.plexus.PlexusTestCase; | import org.codehaus.plexus.PlexusTestCase; |
<!-- | |||||
~ 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" | <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"> | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||||
<modelVersion>4.0.0</modelVersion> | <modelVersion>4.0.0</modelVersion> |
*/ | */ | ||||
import com.opensymphony.xwork.Action; | import com.opensymphony.xwork.Action; | ||||
import org.apache.maven.repository.manager.web.job.DiscovererScheduler; | |||||
import org.apache.maven.repository.manager.web.execution.DiscovererExecution; | import org.apache.maven.repository.manager.web.execution.DiscovererExecution; | ||||
import org.apache.maven.repository.manager.web.job.DiscovererScheduler; | |||||
/** | /** | ||||
* This is the Action class of index.jsp, which is the initial page of the web application. | * This is the Action class of index.jsp, which is the initial page of the web application. | ||||
} | } | ||||
catch ( Exception e ) | catch ( Exception e ) | ||||
{ | { | ||||
// TODO: better exception handling! | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
return ERROR; | return ERROR; | ||||
} | } |
package org.apache.maven.repository.manager.web.action; | package org.apache.maven.repository.manager.web.action; | ||||
/* | |||||
* 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 com.opensymphony.xwork.Action; | import com.opensymphony.xwork.Action; | ||||
import org.apache.maven.artifact.repository.ArtifactRepository; | import org.apache.maven.artifact.repository.ArtifactRepository; | ||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; |
import org.apache.maven.artifact.repository.ArtifactRepository; | import org.apache.maven.artifact.repository.ArtifactRepository; | ||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | ||||
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; | import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; | ||||
import org.apache.maven.repository.indexing.DefaultRepositoryIndexSearcher; | |||||
import org.apache.maven.repository.indexing.RepositoryIndex; | |||||
import org.apache.maven.repository.indexing.RepositoryIndexException; | import org.apache.maven.repository.indexing.RepositoryIndexException; | ||||
import org.apache.maven.repository.indexing.RepositoryIndexSearchException; | import org.apache.maven.repository.indexing.RepositoryIndexSearchException; | ||||
import org.apache.maven.repository.indexing.RepositoryIndexingFactory; | |||||
import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer; | import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer; | ||||
import org.apache.maven.repository.indexing.RepositoryIndexingFactory; | |||||
import org.apache.maven.repository.indexing.query.SinglePhraseQuery; | import org.apache.maven.repository.indexing.query.SinglePhraseQuery; | ||||
import org.apache.maven.repository.manager.web.job.Configuration; | import org.apache.maven.repository.manager.web.job.Configuration; | ||||
import org.apache.maven.repository.indexing.RepositoryIndex; | |||||
import java.io.File; | import java.io.File; | ||||
import java.net.MalformedURLException; | import java.net.MalformedURLException; |
package org.apache.maven.repository.manager.web.action; | package org.apache.maven.repository.manager.web.action; | ||||
/* | |||||
* 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 com.opensymphony.xwork.Action; | import com.opensymphony.xwork.Action; | ||||
import org.apache.maven.artifact.Artifact; | import org.apache.maven.artifact.Artifact; | ||||
import org.apache.maven.artifact.repository.ArtifactRepository; | import org.apache.maven.artifact.repository.ArtifactRepository; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | |||||
import java.util.TreeMap; | import java.util.TreeMap; | ||||
/** | /** | ||||
private String group; | private String group; | ||||
private TreeMap artifactMap; | |||||
private Map artifactMap; | |||||
private String folder; | private String folder; | ||||
private int idx; | private int idx; | ||||
public String execute() | public String execute() | ||||
throws Exception | |||||
{ | { | ||||
// TODO! fix hardcoded path | |||||
String path = "E:/jeprox/maven-repository-manager/trunk/maven-repository-discovery/src/test/repository"; | String path = "E:/jeprox/maven-repository-manager/trunk/maven-repository-discovery/src/test/repository"; | ||||
ArtifactRepository repository = | ArtifactRepository repository = | ||||
artifactMap = new TreeMap(); | artifactMap = new TreeMap(); | ||||
String groupId; | |||||
while ( iterator.hasNext() ) | while ( iterator.hasNext() ) | ||||
{ | { | ||||
Artifact artifact = (Artifact) iterator.next(); | Artifact artifact = (Artifact) iterator.next(); | ||||
groupId = artifact.getGroupId(); | |||||
String groupId = artifact.getGroupId(); | |||||
String key = groupId.replace( '.', '/' ) + "/" + artifact.getArtifactId() + "/" + artifact.getVersion(); | String key = groupId.replace( '.', '/' ) + "/" + artifact.getArtifactId() + "/" + artifact.getVersion(); | ||||
ArrayList artifactList; | |||||
List artifactList; | |||||
if ( artifactMap.containsKey( key ) ) | if ( artifactMap.containsKey( key ) ) | ||||
{ | { | ||||
artifactList = (ArrayList) artifactMap.get( key ); | |||||
artifactList = (List) artifactMap.get( key ); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
} | } | ||||
//set the index for folder level to be displayed | //set the index for folder level to be displayed | ||||
setIdx( 1 ); | |||||
idx = 1; | |||||
setFolder( "" ); | |||||
folder = ""; | |||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
// TODO! is this method needed? | |||||
public String doEdit() | public String doEdit() | ||||
throws Exception | |||||
{ | { | ||||
setIdx( getIdx() + 1 ); | |||||
idx = idx + 1; | |||||
//set folder to "" if we are at the root directory | //set folder to "" if we are at the root directory | ||||
if ( getIdx() == 1 ) | |||||
if ( idx == 1 ) | |||||
{ | { | ||||
setFolder( "" ); | |||||
folder = ""; | |||||
} | } | ||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
public TreeMap getArtifactMap() | |||||
public Map getArtifactMap() | |||||
{ | { | ||||
return artifactMap; | return artifactMap; | ||||
} | } |
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
import org.apache.lucene.index.IndexReader; | |||||
import org.apache.maven.artifact.Artifact; | |||||
import org.apache.maven.artifact.repository.ArtifactRepository; | import org.apache.maven.artifact.repository.ArtifactRepository; | ||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | ||||
import org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory; | import org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory; | ||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | ||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; | import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; | ||||
import org.apache.maven.artifact.Artifact; | |||||
import org.apache.maven.repository.indexing.RepositoryIndexException; | |||||
import org.apache.maven.model.Model; | |||||
import org.apache.maven.repository.discovery.ArtifactDiscoverer; | |||||
import org.apache.maven.repository.discovery.MetadataDiscoverer; | |||||
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; | import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; | ||||
import org.apache.maven.repository.indexing.MetadataRepositoryIndex; | import org.apache.maven.repository.indexing.MetadataRepositoryIndex; | ||||
import org.apache.maven.repository.indexing.PomRepositoryIndex; | import org.apache.maven.repository.indexing.PomRepositoryIndex; | ||||
import org.apache.maven.repository.indexing.RepositoryIndexException; | |||||
import org.apache.maven.repository.indexing.RepositoryIndexingFactory; | import org.apache.maven.repository.indexing.RepositoryIndexingFactory; | ||||
import org.apache.maven.repository.manager.web.job.Configuration; | import org.apache.maven.repository.manager.web.job.Configuration; | ||||
import org.apache.maven.repository.discovery.ArtifactDiscoverer; | |||||
import org.apache.maven.repository.discovery.MetadataDiscoverer; | |||||
import org.apache.maven.model.Model; | |||||
import org.apache.lucene.index.IndexReader; | |||||
import org.codehaus.plexus.logging.AbstractLogEnabled; | import org.codehaus.plexus.logging.AbstractLogEnabled; | ||||
import java.util.List; | |||||
import java.util.Iterator; | |||||
import java.util.Properties; | |||||
import java.io.File; | import java.io.File; | ||||
import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||
import java.util.Iterator; | |||||
import java.util.List; | |||||
import java.util.Properties; | |||||
/** | /** | ||||
* This is the class that executes the discoverer and indexer. | * This is the class that executes the discoverer and indexer. | ||||
private ArtifactRepositoryLayout layout; | private ArtifactRepositoryLayout layout; | ||||
private Properties props; | |||||
private String indexPath; | private String indexPath; | ||||
private String blacklistedPatterns; | private String blacklistedPatterns; | ||||
public void executeDiscovererIfIndexDoesNotExist() | public void executeDiscovererIfIndexDoesNotExist() | ||||
throws MalformedURLException, RepositoryIndexException | throws MalformedURLException, RepositoryIndexException | ||||
{ | { | ||||
props = config.getProperties(); | |||||
Properties props = config.getProperties(); | |||||
indexPath = props.getProperty( "index.path" ); | indexPath = props.getProperty( "index.path" ); | ||||
File indexDir = new File( indexPath ); | File indexDir = new File( indexPath ); | ||||
boolean isExisting; | |||||
boolean isExisting = false; | |||||
if ( IndexReader.indexExists( indexDir ) ) | if ( IndexReader.indexExists( indexDir ) ) | ||||
{ | { | ||||
isExisting = true; | isExisting = true; | ||||
} | } | ||||
else if ( !indexDir.exists() ) | |||||
{ | |||||
isExisting = false; | |||||
} | |||||
else | |||||
{ | |||||
isExisting = false; | |||||
} | |||||
if ( !isExisting ) | if ( !isExisting ) | ||||
{ | { | ||||
public void executeDiscoverer() | public void executeDiscoverer() | ||||
throws MalformedURLException, RepositoryIndexException | throws MalformedURLException, RepositoryIndexException | ||||
{ | { | ||||
props = config.getProperties(); | |||||
Properties props = config.getProperties(); | |||||
indexPath = props.getProperty( "index.path" ); | indexPath = props.getProperty( "index.path" ); | ||||
layout = config.getLayout(); | layout = config.getLayout(); | ||||
blacklistedPatterns = props.getProperty( "blacklist.patterns" ); | blacklistedPatterns = props.getProperty( "blacklist.patterns" ); | ||||
includeSnapshots = new Boolean( props.getProperty( "include.snapshots" ) ).booleanValue(); | |||||
convertSnapshots = new Boolean( props.getProperty( "convert.snapshots" ) ).booleanValue(); | |||||
includeSnapshots = Boolean.valueOf( props.getProperty( "include.snapshots" ) ).booleanValue(); | |||||
convertSnapshots = Boolean.valueOf( props.getProperty( "convert.snapshots" ) ).booleanValue(); | |||||
try | try | ||||
{ | { | ||||
} | } | ||||
getLogger().info( "[DiscovererExecution] Started discovery and indexing.." ); | getLogger().info( "[DiscovererExecution] Started discovery and indexing.." ); | ||||
if ( props.getProperty( "layout" ).equals( "default" ) ) | |||||
if ( "default".equals( props.getProperty( "layout" ) ) ) | |||||
{ | { | ||||
executeDiscovererInDefaultRepo(); | executeDiscovererInDefaultRepo(); | ||||
} | } | ||||
else if ( props.getProperty( "layout" ).equals( "legacy" ) ) | |||||
else if ( "legacy".equals( props.getProperty( "layout" ) ) ) | |||||
{ | { | ||||
executeDiscovererInLegacyRepo(); | executeDiscovererInLegacyRepo(); | ||||
} | } | ||||
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) | for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) | ||||
{ | { | ||||
Artifact artifact = (Artifact) iter.next(); | Artifact artifact = (Artifact) iter.next(); | ||||
try | |||||
{ | |||||
artifactIndex.indexArtifact( artifact ); | |||||
} | |||||
catch ( Exception e ) | |||||
{ | |||||
if ( e instanceof RepositoryIndexException ) | |||||
{ | |||||
throw (RepositoryIndexException) e; | |||||
} | |||||
} | |||||
artifactIndex.indexArtifact( artifact ); | |||||
if ( artifactIndex.isOpen() ) | if ( artifactIndex.isOpen() ) | ||||
{ | { | ||||
for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) | for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) | ||||
{ | { | ||||
RepositoryMetadata repoMetadata = (RepositoryMetadata) iter.next(); | RepositoryMetadata repoMetadata = (RepositoryMetadata) iter.next(); | ||||
try | |||||
{ | |||||
metadataIndex.index( repoMetadata ); | |||||
} | |||||
catch ( Exception e ) | |||||
{ | |||||
if ( e instanceof RepositoryIndexException ) | |||||
{ | |||||
throw (RepositoryIndexException) e; | |||||
} | |||||
} | |||||
metadataIndex.index( repoMetadata ); | |||||
if ( metadataIndex.isOpen() ) | if ( metadataIndex.isOpen() ) | ||||
{ | { | ||||
metadataIndex.optimize(); | metadataIndex.optimize(); | ||||
for ( Iterator iter = models.iterator(); iter.hasNext(); ) | for ( Iterator iter = models.iterator(); iter.hasNext(); ) | ||||
{ | { | ||||
Model model = (Model) iter.next(); | Model model = (Model) iter.next(); | ||||
try | |||||
{ | |||||
pomIndex.indexPom( model ); | |||||
} | |||||
catch ( Exception e ) | |||||
{ | |||||
if ( e instanceof RepositoryIndexException ) | |||||
{ | |||||
throw (RepositoryIndexException) e; | |||||
} | |||||
} | |||||
pomIndex.indexPom( model ); | |||||
if ( pomIndex.isOpen() ) | if ( pomIndex.isOpen() ) | ||||
{ | { |
package org.apache.maven.repository.manager.web.job; | package org.apache.maven.repository.manager.web.job; | ||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | |||||
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; | |||||
import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout; | |||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; | |||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; | |||||
import java.util.Properties; | |||||
/* | /* | ||||
* Copyright 2005-2006 The Apache Software Foundation. | * Copyright 2005-2006 The Apache Software Foundation. | ||||
* | * | ||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | |||||
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; | |||||
import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout; | |||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; | |||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; | |||||
import java.util.Properties; | |||||
/** | /** | ||||
* This class contains the configuration values to be used by the scheduler | * This class contains the configuration values to be used by the scheduler | ||||
*/ | */ |
* limitations under the License. | * 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.artifact.repository.metadata.RepositoryMetadata; | |||||
import org.apache.maven.model.Model; | |||||
import org.apache.maven.repository.discovery.ArtifactDiscoverer; | |||||
import org.apache.maven.repository.discovery.DefaultArtifactDiscoverer; | |||||
import org.apache.maven.repository.discovery.DefaultMetadataDiscoverer; | |||||
import org.apache.maven.repository.discovery.LegacyArtifactDiscoverer; | |||||
import org.apache.maven.repository.discovery.MetadataDiscoverer; | |||||
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; | |||||
import org.apache.maven.repository.indexing.MetadataRepositoryIndex; | |||||
import org.apache.maven.repository.indexing.PomRepositoryIndex; | |||||
import org.apache.maven.repository.indexing.RepositoryIndexException; | import org.apache.maven.repository.indexing.RepositoryIndexException; | ||||
import org.apache.maven.repository.indexing.RepositoryIndexingFactory; | |||||
import org.apache.maven.repository.manager.web.execution.DiscovererExecution; | import org.apache.maven.repository.manager.web.execution.DiscovererExecution; | ||||
import org.codehaus.plexus.scheduler.AbstractJob; | import org.codehaus.plexus.scheduler.AbstractJob; | ||||
import org.quartz.JobDataMap; | import org.quartz.JobDataMap; | ||||
import org.quartz.JobExecutionContext; | import org.quartz.JobExecutionContext; | ||||
import org.quartz.JobExecutionException; | import org.quartz.JobExecutionException; | ||||
import java.io.File; | |||||
import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||
import java.util.Iterator; | |||||
import java.util.List; | |||||
/** | /** | ||||
* This class is the discoverer job that is executed by the scheduler. | * This class is the discoverer job that is executed by the scheduler. | ||||
{ | { | ||||
public static final String ROLE = DiscovererJob.class.getName(); | public static final String ROLE = DiscovererJob.class.getName(); | ||||
public static String MAP_DISCOVERER_EXECUTION = "EXECUTION"; | |||||
public static final String MAP_DISCOVERER_EXECUTION = "EXECUTION"; | |||||
/** | /** | ||||
* Execute the discoverer and the indexer. | * Execute the discoverer and the indexer. | ||||
} | } | ||||
catch ( RepositoryIndexException e ) | catch ( RepositoryIndexException e ) | ||||
{ | { | ||||
// TODO! | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
catch ( MalformedURLException me ) | catch ( MalformedURLException me ) | ||||
{ | { | ||||
// TODO! | |||||
me.printStackTrace(); | me.printStackTrace(); | ||||
} | } | ||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
import java.io.File; | |||||
import java.io.IOException; | |||||
import java.net.MalformedURLException; | |||||
import java.text.ParseException; | |||||
import java.util.Properties; | |||||
import org.apache.maven.artifact.repository.ArtifactRepository; | |||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | |||||
import org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory; | |||||
import org.apache.maven.repository.discovery.ArtifactDiscoverer; | |||||
import org.apache.maven.repository.discovery.MetadataDiscoverer; | |||||
import org.apache.maven.repository.indexing.RepositoryIndexingFactory; | |||||
import org.apache.maven.repository.manager.web.execution.DiscovererExecution; | import org.apache.maven.repository.manager.web.execution.DiscovererExecution; | ||||
import org.codehaus.plexus.logging.AbstractLogEnabled; | import org.codehaus.plexus.logging.AbstractLogEnabled; | ||||
import org.codehaus.plexus.scheduler.AbstractJob; | |||||
import org.codehaus.plexus.scheduler.Scheduler; | import org.codehaus.plexus.scheduler.Scheduler; | ||||
import org.quartz.CronTrigger; | import org.quartz.CronTrigger; | ||||
import org.quartz.JobDataMap; | import org.quartz.JobDataMap; | ||||
import org.quartz.JobDetail; | import org.quartz.JobDetail; | ||||
import org.quartz.SchedulerException; | import org.quartz.SchedulerException; | ||||
import java.text.ParseException; | |||||
import java.util.Properties; | |||||
/** | /** | ||||
* This class sets the job to be executed in the plexus-quartz scheduler | * This class sets the job to be executed in the plexus-quartz scheduler | ||||
* | * | ||||
*/ | */ | ||||
private Scheduler scheduler; | private Scheduler scheduler; | ||||
private Properties props; | |||||
/** | /** | ||||
* @plexus.requirement | * @plexus.requirement | ||||
*/ | */ | ||||
/** | /** | ||||
* Method that sets the schedule in the plexus-quartz scheduler | * Method that sets the schedule in the plexus-quartz scheduler | ||||
* | * | ||||
* @throws IOException | |||||
* @throws ParseException | * @throws ParseException | ||||
* @throws SchedulerException | * @throws SchedulerException | ||||
*/ | */ | ||||
public void setSchedule() | public void setSchedule() | ||||
throws IOException, ParseException, SchedulerException | |||||
throws ParseException, SchedulerException | |||||
{ | { | ||||
props = config.getProperties(); | |||||
Properties props = config.getProperties(); | |||||
JobDetail jobDetail = new JobDetail( "discovererJob", "DISCOVERER", DiscovererJob.class ); | JobDetail jobDetail = new JobDetail( "discovererJob", "DISCOVERER", DiscovererJob.class ); | ||||
JobDataMap dataMap = new JobDataMap(); | JobDataMap dataMap = new JobDataMap(); | ||||
dataMap.put( DiscovererJob.LOGGER, getLogger() ); | |||||
dataMap.put( AbstractJob.LOGGER, getLogger() ); | |||||
dataMap.put( DiscovererJob.MAP_DISCOVERER_EXECUTION, execution ); | dataMap.put( DiscovererJob.MAP_DISCOVERER_EXECUTION, execution ); | ||||
jobDetail.setJobDataMap( dataMap ); | jobDetail.setJobDataMap( dataMap ); | ||||
<!-- | |||||
~ 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. | |||||
--> | |||||
<decorators defaultdir="/WEB-INF/jsp/decorators"> | <decorators defaultdir="/WEB-INF/jsp/decorators"> | ||||
<decorator name="default" page="default.jsp"> | <decorator name="default" page="default.jsp"> | ||||
<pattern>/*</pattern> | <pattern>/*</pattern> |
<%-- | |||||
~ 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. | |||||
--%> | |||||
<%@ taglib uri="webwork" prefix="ww" %> | <%@ taglib uri="webwork" prefix="ww" %> | ||||
<html> | <html> | ||||
<body> | <body> | ||||
<h3><a href="<ww:url value="browse!edit.action"><ww:param name="idx" value="0"/></ww:url>">basedir</a> / | <h3><a href="<ww:url value="browse!edit.action"><ww:param name="idx" value="0"/></ww:url>">basedir</a> / | ||||
<ww:set name="previousFolder" value="''"/> | |||||
<ww:set name="counter" value="0"/> | |||||
<ww:set name="previousFolder" value="''" /> | |||||
<ww:set name="counter" value="0" /> | |||||
<ww:if test="folder != ''"> | <ww:if test="folder != ''"> | ||||
<ww:set name="folderHeader" value="folder.split('/')"/> | |||||
<ww:set name="folderHeader" value="folder.split('/')" /> | |||||
<ww:iterator value="#folderHeader"> | <ww:iterator value="#folderHeader"> | ||||
<ww:set name="counter" value="#counter + 1"/> | |||||
<ww:set name="counter" value="#counter + 1" /> | |||||
<ww:if test="#previousFolder == ''"> | <ww:if test="#previousFolder == ''"> | ||||
<ww:set name="previousFolder" value="top"/> | |||||
<ww:set name="previousFolder" value="top" /> | |||||
</ww:if> | </ww:if> | ||||
<ww:else> | <ww:else> | ||||
<ww:set name="previousFolder" value="#previousFolder + '/' + top"/> | |||||
<ww:set name="previousFolder" value="#previousFolder + '/' + top" /> | |||||
</ww:else> | </ww:else> | ||||
<ww:if test="idx > (#counter + 1)"><a href="<ww:url value="browse!edit.action"><ww:param name="idx"><ww:property | <ww:if test="idx > (#counter + 1)"><a href="<ww:url value="browse!edit.action"><ww:param name="idx"><ww:property | ||||
value="#counter"/></ww:param><ww:param name="folder"></ww:param></ww:url>"></ww:if><ww:property/></a> / | |||||
value="#counter" /></ww:param><ww:param name="folder"></ww:param></ww:url>"></ww:if><ww:property /></a> / | |||||
</ww:iterator> | </ww:iterator> | ||||
</ww:if> | </ww:if> | ||||
</h3> | </h3> | ||||
<br/> | |||||
<br /> | |||||
<ww:set name="previousFolder" value="'the previous folder'"/> | <ww:set name="previousFolder" value="'the previous folder'"/> | ||||
<ww:set name="in" value="idx" scope="page"/> | <ww:set name="in" value="idx" scope="page"/> | ||||
<ww:if test="idx == 1 || (folder != '' and #groupName.startsWith(folder))"> | <ww:if test="idx == 1 || (folder != '' and #groupName.startsWith(folder))"> | ||||
<% | <% | ||||
int ctr = 1; | int ctr = 1; | ||||
%> | %> | ||||
<ww:set name="groupFolder" value="#groupName.split('/')"/> | <ww:set name="groupFolder" value="#groupName.split('/')"/> | ||||
<ww:iterator value="#groupFolder"> | <ww:iterator value="#groupFolder"> | ||||
<% | <% | ||||
if (ctr == ((Integer)pageContext.getAttribute("in")).intValue()) { | if (ctr == ((Integer)pageContext.getAttribute("in")).intValue()) { | ||||
%> | %> | ||||
<ww:if test="top != #previousFolder"> | <ww:if test="top != #previousFolder"> | ||||
<ww:set name="previousFolder" value="top"/> | <ww:set name="previousFolder" value="top"/> | ||||
</ww:iterator> | </ww:iterator> | ||||
<ww:if test="folder != ''"> | <ww:if test="folder != ''"> | ||||
<ww:set name="previousFolder" value="''"/> | |||||
<ww:set name="artifactList" value="artifactMap.get(folder)"/> | |||||
<ww:set name="previousFolder" value="''" /> | |||||
<ww:set name="artifactList" value="artifactMap.get(folder)" /> | |||||
<ww:iterator value="#artifactList"> | <ww:iterator value="#artifactList"> | ||||
<table border="1"> | <table border="1"> | ||||
<tr align="left"> | <tr align="left"> | ||||
<th>Group ID</th> | <th>Group ID</th> | ||||
<td><ww:property value="groupId"/></td> | |||||
<td><ww:property value="groupId" /></td> | |||||
</tr> | </tr> | ||||
<tr align="left"> | <tr align="left"> | ||||
<th>Artifact ID</th> | <th>Artifact ID</th> | ||||
<td><ww:property value="artifactId"/></td> | |||||
<td><ww:property value="artifactId" /></td> | |||||
</tr> | </tr> | ||||
<tr align="left"> | <tr align="left"> | ||||
<th>Version</th> | <th>Version</th> | ||||
<td><ww:property value="version"/></td> | |||||
<td><ww:property value="version" /></td> | |||||
</tr> | </tr> | ||||
<tr align="left"> | <tr align="left"> | ||||
<th>Derivatives</th> | <th>Derivatives</th> | ||||
<td><ww:property value="groupId"/></td> | |||||
<td><ww:property value="groupId" /></td> | |||||
</tr> | </tr> | ||||
<tr align="left"> | <tr align="left"> | ||||
<th>Parent</th> | <th>Parent</th> | ||||
<td><ww:property value="folder"/></td> | |||||
<td><ww:property value="folder" /></td> | |||||
</tr> | </tr> | ||||
</table> | </table> | ||||
<br/> | |||||
<br /> | |||||
</ww:iterator> | </ww:iterator> | ||||
</ww:if> | </ww:if> | ||||
</body> | </body> |
<%-- | |||||
~ 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. | |||||
--%> | |||||
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> | <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> | ||||
<html> | <html> | ||||
<head> | <head> |
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
~ See the License for the specific language governing permissions and | ~ See the License for the specific language governing permissions and | ||||
~ limitations under the License. | ~ limitations under the License. | ||||
~ | |||||
--%> | --%> | ||||
<script type="text/javascript"> | <script type="text/javascript"> |
<%-- | |||||
~ 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. | |||||
--%> | |||||
<%@ taglib uri="webwork" prefix="ww" %> | <%@ taglib uri="webwork" prefix="ww" %> | ||||
<html> | <html> | ||||
<head> | <head> |
<!-- | |||||
~ 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. | |||||
--> | |||||
<!DOCTYPE web-app PUBLIC | <!DOCTYPE web-app PUBLIC | ||||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" | "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" | ||||
"http://java.sun.com/dtd/web-app_2_3.dtd" > | "http://java.sun.com/dtd/web-app_2_3.dtd" > |
/* | |||||
* 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. | |||||
*/ | |||||
body { | body { | ||||
margin: 0px; | margin: 0px; | ||||
padding: 0px; | padding: 0px; |
/* | |||||
* 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. | |||||
*/ | |||||
body { | body { | ||||
padding: 0px 0px 10px 0px; | padding: 0px 0px 10px 0px; | ||||
} | } |
/* | |||||
* 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. | |||||
*/ | |||||
#banner, #footer, #leftcol, #breadcrumbs, .docs #toc, .docs .courtesylinks, #leftColumn, #navColumn { | #banner, #footer, #leftcol, #breadcrumbs, .docs #toc, .docs .courtesylinks, #leftColumn, #navColumn { | ||||
display: none !important; | display: none !important; | ||||
} | } |
/* | |||||
* 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. | |||||
*/ | |||||
#sidebar { | #sidebar { | ||||
float: right; | float: right; | ||||
font-size: small; | font-size: small; |
<%-- | |||||
~ 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. | |||||
--%> | |||||
<%response.sendRedirect( request.getContextPath() + "/index.action" );%> | <%response.sendRedirect( request.getContextPath() + "/index.action" );%> |