import org.apache.maven.archiva.converter.RepositoryConverter;
import org.apache.maven.archiva.discoverer.ArtifactDiscoverer;
import org.apache.maven.archiva.discoverer.DiscovererException;
+import org.apache.maven.archiva.discoverer.filter.AcceptAllArtifactFilter;
+import org.apache.maven.archiva.discoverer.filter.SnapshotArtifactFilter;
import org.apache.maven.archiva.reporting.ArtifactReporter;
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.resolver.filter.ArtifactFilter;
import java.io.File;
import java.net.MalformedURLException;
throw new RepositoryConversionException( "Error convering legacy repository.", e );
}
- List legacyArtifacts =
- artifactDiscoverer.discoverArtifacts( legacyRepository, "converter", null, includeSnapshots );
+ ArtifactFilter filter =
+ includeSnapshots ? new AcceptAllArtifactFilter() : (ArtifactFilter) new SnapshotArtifactFilter();
+ List legacyArtifacts = artifactDiscoverer.discoverArtifacts( legacyRepository, null, filter );
repositoryConverter.convert( legacyArtifacts, repository, reporter );
}
import org.apache.maven.archiva.configuration.ConfigurationStore;
import org.apache.maven.archiva.configuration.ConfigurationStoreException;
import org.apache.maven.archiva.configuration.InvalidConfigurationException;
+import org.apache.maven.archiva.scheduler.task.RepositoryTask;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException;
+++ /dev/null
-package org.apache.maven.archiva.scheduler;
-
-/*
- * 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.archiva.configuration.Configuration;
-import org.apache.maven.archiva.configuration.ConfigurationStore;
-import org.apache.maven.archiva.configuration.ConfigurationStoreException;
-import org.apache.maven.archiva.configuration.ConfiguredRepositoryFactory;
-import org.apache.maven.archiva.configuration.RepositoryConfiguration;
-import org.apache.maven.archiva.discoverer.ArtifactDiscoverer;
-import org.apache.maven.archiva.discoverer.DiscovererException;
-import org.apache.maven.archiva.indexer.RepositoryArtifactIndex;
-import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory;
-import org.apache.maven.archiva.indexer.RepositoryIndexException;
-import org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Task for discovering changes in the repository.
- *
- * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- * @plexus.component role="org.apache.maven.archiva.scheduler.RepositoryTask" role-hint="indexer"
- */
-public class IndexerTask
- extends AbstractLogEnabled
- implements RepositoryTask
-{
- /**
- * Configuration store.
- *
- * @plexus.requirement
- */
- private ConfigurationStore configurationStore;
-
- /**
- * @plexus.requirement
- */
- private RepositoryArtifactIndexFactory indexFactory;
-
- /**
- * @plexus.requirement
- */
- private ConfiguredRepositoryFactory repoFactory;
-
- /**
- * @plexus.requirement role="org.apache.maven.archiva.discoverer.ArtifactDiscoverer"
- */
- private Map artifactDiscoverers;
-
- /**
- * @plexus.requirement role-hint="standard"
- */
- private RepositoryIndexRecordFactory recordFactory;
-
- public void execute()
- throws TaskExecutionException
- {
- Configuration configuration;
- try
- {
- configuration = configurationStore.getConfigurationFromStore();
- }
- catch ( ConfigurationStoreException e )
- {
- throw new TaskExecutionException( e.getMessage(), e );
- }
-
- File indexPath = new File( configuration.getIndexPath() );
-
- execute( configuration, indexPath );
- }
-
- private void execute( Configuration configuration, File indexPath )
- throws TaskExecutionException
- {
- long time = System.currentTimeMillis();
- getLogger().info( "Starting repository discovery process" );
-
- try
- {
- for ( Iterator i = configuration.getRepositories().iterator(); i.hasNext(); )
- {
- RepositoryConfiguration repositoryConfiguration = (RepositoryConfiguration) i.next();
-
- if ( repositoryConfiguration.isIndexed() )
- {
- List blacklistedPatterns = new ArrayList();
- if ( repositoryConfiguration.getBlackListPatterns() != null )
- {
- blacklistedPatterns.addAll( repositoryConfiguration.getBlackListPatterns() );
- }
- if ( configuration.getGlobalBlackListPatterns() != null )
- {
- blacklistedPatterns.addAll( configuration.getGlobalBlackListPatterns() );
- }
- boolean includeSnapshots = repositoryConfiguration.isIncludeSnapshots();
-
- ArtifactRepository repository = repoFactory.createRepository( repositoryConfiguration );
-
- String layoutProperty = repositoryConfiguration.getLayout();
- ArtifactDiscoverer discoverer = (ArtifactDiscoverer) artifactDiscoverers.get( layoutProperty );
- List artifacts =
- discoverer.discoverArtifacts( repository, "indexer", blacklistedPatterns, includeSnapshots );
- if ( !artifacts.isEmpty() )
- {
- getLogger().info( "Indexing " + artifacts.size() + " new artifacts" );
- indexArtifacts( artifacts, indexPath );
- }
- }
- }
- }
- catch ( RepositoryIndexException e )
- {
- throw new TaskExecutionException( e.getMessage(), e );
- }
- catch ( DiscovererException e )
- {
- throw new TaskExecutionException( e.getMessage(), e );
- }
-
- time = System.currentTimeMillis() - time;
- getLogger().info( "Finished repository indexing process in " + time + "ms" );
- }
-
- public void executeNowIfNeeded()
- throws TaskExecutionException
- {
- Configuration configuration;
- try
- {
- configuration = configurationStore.getConfigurationFromStore();
- }
- catch ( ConfigurationStoreException e )
- {
- throw new TaskExecutionException( e.getMessage(), e );
- }
-
- File indexPath = new File( configuration.getIndexPath() );
-
- try
- {
- RepositoryArtifactIndex artifactIndex = indexFactory.createStandardIndex( indexPath );
- if ( !artifactIndex.exists() )
- {
- execute( configuration, indexPath );
- }
- }
- catch ( RepositoryIndexException e )
- {
- throw new TaskExecutionException( e.getMessage(), e );
- }
- }
-
- private void indexArtifacts( List artifacts, File indexPath )
- throws RepositoryIndexException
- {
- List records = new ArrayList();
- for ( Iterator i = artifacts.iterator(); i.hasNext(); )
- {
- Artifact a = (Artifact) i.next();
- records.add( recordFactory.createRecord( a ) );
- }
-
- RepositoryArtifactIndex artifactIndex = indexFactory.createStandardIndex( indexPath );
- artifactIndex.indexRecords( records );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.scheduler;
-
-/*
- * 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.
- */
-
-/**
- * A repository task.
- *
- * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- */
-public interface RepositoryTask
-{
- /**
- * Execute the task.
- */
- void execute()
- throws TaskExecutionException;
-
- /**
- * Execute the task now if needed because the target doesn't exist.
- */
- void executeNowIfNeeded()
- throws TaskExecutionException;
-}
* limitations under the License.\r
*/\r
\r
+import org.apache.maven.archiva.scheduler.task.RepositoryTask;\r
import org.codehaus.plexus.scheduler.AbstractJob;\r
import org.quartz.JobDataMap;\r
import org.quartz.JobExecutionContext;\r
--- /dev/null
+package org.apache.maven.archiva.scheduler.task;
+
+/*
+ * 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.resolver.filter.ArtifactFilter;
+
+import java.util.Collection;
+
+/**
+ * Filter that removes artifacts already in the index.
+ * TODO: we could do timestamp comparisons here
+ */
+public class IndexRecordExistsArtifactFilter
+ implements ArtifactFilter
+{
+ private final Collection keys;
+
+ public IndexRecordExistsArtifactFilter( Collection keys )
+ {
+ this.keys = keys;
+ }
+
+ public boolean include( Artifact artifact )
+ {
+ String artifactKey = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() +
+ ( artifact.getClassifier() != null ? ":" + artifact.getClassifier() : "" );
+ return !keys.contains( artifactKey );
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.scheduler.task;
+
+/*
+ * 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.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.ConfigurationStore;
+import org.apache.maven.archiva.configuration.ConfigurationStoreException;
+import org.apache.maven.archiva.configuration.ConfiguredRepositoryFactory;
+import org.apache.maven.archiva.configuration.RepositoryConfiguration;
+import org.apache.maven.archiva.discoverer.ArtifactDiscoverer;
+import org.apache.maven.archiva.discoverer.DiscovererException;
+import org.apache.maven.archiva.discoverer.filter.SnapshotArtifactFilter;
+import org.apache.maven.archiva.indexer.RepositoryArtifactIndex;
+import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory;
+import org.apache.maven.archiva.indexer.RepositoryIndexException;
+import org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory;
+import org.apache.maven.archiva.scheduler.TaskExecutionException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Task for discovering changes in the repository.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @plexus.component role=org.apache.maven.archiva.scheduler.task.RepositoryTaskk" role-hint="indexer"
+ */
+public class IndexerTask
+ extends AbstractLogEnabled
+ implements RepositoryTask
+{
+ /**
+ * Configuration store.
+ *
+ * @plexus.requirement
+ */
+ private ConfigurationStore configurationStore;
+
+ /**
+ * @plexus.requirement
+ */
+ private RepositoryArtifactIndexFactory indexFactory;
+
+ /**
+ * @plexus.requirement
+ */
+ private ConfiguredRepositoryFactory repoFactory;
+
+ /**
+ * @plexus.requirement role="org.apache.maven.archiva.discoverer.ArtifactDiscoverer"
+ */
+ private Map artifactDiscoverers;
+
+ /**
+ * @plexus.requirement role-hint="standard"
+ */
+ private RepositoryIndexRecordFactory recordFactory;
+
+ public void execute()
+ throws TaskExecutionException
+ {
+ Configuration configuration;
+ try
+ {
+ configuration = configurationStore.getConfigurationFromStore();
+ }
+ catch ( ConfigurationStoreException e )
+ {
+ throw new TaskExecutionException( e.getMessage(), e );
+ }
+
+ File indexPath = new File( configuration.getIndexPath() );
+
+ execute( configuration, indexPath );
+ }
+
+ private void execute( Configuration configuration, File indexPath )
+ throws TaskExecutionException
+ {
+ long time = System.currentTimeMillis();
+ getLogger().info( "Starting repository discovery process" );
+
+ RepositoryArtifactIndex index = indexFactory.createStandardIndex( indexPath );
+
+ try
+ {
+ Collection keys;
+ if ( index.exists() )
+ {
+ keys = index.getAllRecordKeys();
+ }
+ else
+ {
+ keys = Collections.EMPTY_LIST;
+ }
+
+ for ( Iterator i = configuration.getRepositories().iterator(); i.hasNext(); )
+ {
+ RepositoryConfiguration repositoryConfiguration = (RepositoryConfiguration) i.next();
+
+ if ( repositoryConfiguration.isIndexed() )
+ {
+ List blacklistedPatterns = new ArrayList();
+ if ( repositoryConfiguration.getBlackListPatterns() != null )
+ {
+ blacklistedPatterns.addAll( repositoryConfiguration.getBlackListPatterns() );
+ }
+ if ( configuration.getGlobalBlackListPatterns() != null )
+ {
+ blacklistedPatterns.addAll( configuration.getGlobalBlackListPatterns() );
+ }
+ boolean includeSnapshots = repositoryConfiguration.isIncludeSnapshots();
+
+ ArtifactRepository repository = repoFactory.createRepository( repositoryConfiguration );
+
+ String layoutProperty = repositoryConfiguration.getLayout();
+ ArtifactDiscoverer discoverer = (ArtifactDiscoverer) artifactDiscoverers.get( layoutProperty );
+ AndArtifactFilter filter = new AndArtifactFilter();
+ filter.add( new IndexRecordExistsArtifactFilter( keys ) );
+ if ( !includeSnapshots )
+ {
+ filter.add( new SnapshotArtifactFilter() );
+ }
+
+ // Save some memory by not tracking paths we won't use
+ // TODO: Plexus CDC should be able to inject this configuration
+ discoverer.setTrackOmittedPaths( false );
+
+ getLogger().info( "Searching repository " + repositoryConfiguration.getName() );
+ List artifacts = discoverer.discoverArtifacts( repository, blacklistedPatterns, filter );
+ if ( !artifacts.isEmpty() )
+ {
+ getLogger().info( "Indexing " + artifacts.size() + " new artifacts" );
+ index.indexArtifacts( artifacts, recordFactory );
+ }
+ }
+ }
+ }
+ catch ( RepositoryIndexException e )
+ {
+ throw new TaskExecutionException( e.getMessage(), e );
+ }
+ catch ( DiscovererException e )
+ {
+ throw new TaskExecutionException( e.getMessage(), e );
+ }
+
+ time = System.currentTimeMillis() - time;
+ getLogger().info( "Finished repository indexing process in " + time + "ms" );
+ }
+
+ public void executeNowIfNeeded()
+ throws TaskExecutionException
+ {
+ Configuration configuration;
+ try
+ {
+ configuration = configurationStore.getConfigurationFromStore();
+ }
+ catch ( ConfigurationStoreException e )
+ {
+ throw new TaskExecutionException( e.getMessage(), e );
+ }
+
+ File indexPath = new File( configuration.getIndexPath() );
+
+ try
+ {
+ RepositoryArtifactIndex artifactIndex = indexFactory.createStandardIndex( indexPath );
+ if ( !artifactIndex.exists() )
+ {
+ execute( configuration, indexPath );
+ }
+ }
+ catch ( RepositoryIndexException e )
+ {
+ throw new TaskExecutionException( e.getMessage(), e );
+ }
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.scheduler.task;
+
+import org.apache.maven.archiva.scheduler.TaskExecutionException;
+
+/*
+ * 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.
+ */
+
+/**
+ * A repository task.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public interface RepositoryTask
+{
+ /**
+ * Execute the task.
+ */
+ void execute()
+ throws TaskExecutionException;
+
+ /**
+ * Execute the task now if needed because the target doesn't exist.
+ */
+ void executeNowIfNeeded()
+ throws TaskExecutionException;
+}
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Date;
import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
/**
* Base class for artifact discoverers.
"**/*.MD5", "**/*.sha1", "**/*.SHA1", "**/*snapshot-version", "*/website/**", "*/licenses/**", "*/licences/**",
"**/.htaccess", "**/*.html", "**/*.asc", "**/*.txt", "**/*.xml", "**/README*", "**/CHANGELOG*", "**/KEYS*"};
- private List scanForArtifactPaths( File repositoryBase, List blacklistedPatterns, long comparisonTimestamp )
+ private List scanForArtifactPaths( File repositoryBase, List blacklistedPatterns )
{
- return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES,
- comparisonTimestamp );
+ return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES );
}
- public List discoverArtifacts( ArtifactRepository repository, String operation, List blacklistedPatterns,
- boolean includeSnapshots )
+ public List discoverArtifacts( ArtifactRepository repository, List blacklistedPatterns, ArtifactFilter filter )
throws DiscovererException
{
if ( !"file".equals( repository.getProtocol() ) )
throw new UnsupportedOperationException( "Only filesystem repositories are supported" );
}
- Xpp3Dom dom = getLastArtifactDiscoveryDom( readRepositoryMetadataDom( repository ) );
- long comparisonTimestamp = readComparisonTimestamp( repository, operation, dom );
-
- // Note that last checked time is deliberately set to the start of the process so that anything added
- // mid-discoverer and missed by the scanner will get checked next time.
- // Due to this, there must be no negative side-effects of discovering something twice.
- Date newLastCheckedTime = new Date();
-
File repositoryBase = new File( repository.getBasedir() );
List artifacts = new ArrayList();
- List artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns, comparisonTimestamp );
-
- // Also note that the last check time, while set at the start, is saved at the end, so that if any exceptions
- // occur, then the timestamp is not updated so that the discoverer is attempted again
- // TODO: under the list-return behaviour we have now, exceptions might occur later and the timestamp will not be reset - see MRM-83
- try
- {
- setLastCheckedTime( repository, operation, newLastCheckedTime );
- }
- catch ( IOException e )
- {
- throw new DiscovererException( "Error writing metadata: " + e.getMessage(), e );
- }
+ List artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
for ( Iterator i = artifactPaths.iterator(); i.hasNext(); )
{
{
Artifact artifact = buildArtifactFromPath( path, repository );
- if ( includeSnapshots || !artifact.isSnapshot() )
+ if ( filter.include( artifact ) )
{
artifacts.add( artifact );
}
+ // TODO: else add to excluded? [!]
+ // TODO! excluded/kickout tracking should be optional
}
catch ( DiscovererException e )
{
return artifact;
}
-
- public void setLastCheckedTime( ArtifactRepository repository, String operation, Date date )
- throws IOException
- {
- // see notes in resetLastCheckedTime
-
- File file = new File( repository.getBasedir(), "maven-metadata.xml" );
-
- Xpp3Dom dom = readDom( file );
-
- String dateString = new SimpleDateFormat( DATE_FMT, Locale.US ).format( date );
-
- setEntry( getLastArtifactDiscoveryDom( dom ), operation, dateString );
-
- saveDom( file, dom );
- }
}
*/
import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
-import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
-import org.codehaus.plexus.util.xml.Xpp3DomWriter;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
/**
* Base class for the artifact and metadata discoverers.
private List excludedPaths = new ArrayList();
/**
- * @plexus.configuration default-value="60000"
+ * @plexus.configuration default-value="true"
*/
- private int blackoutPeriod;
+ private boolean trackOmittedPaths;
+
+ /** TODO!
+ * @plexus.configuration default-value="60000"
+ protected int blackoutPeriod;
protected static final String DATE_FMT = "yyyyMMddHHmmss";
+ */
/**
* Add a path to the list of files that were kicked out due to being invalid.
*/
protected void addKickedOutPath( String path, String reason )
{
- kickedOutPaths.add( new DiscovererPath( path, reason ) );
+ if ( trackOmittedPaths )
+ {
+ kickedOutPaths.add( new DiscovererPath( path, reason ) );
+ }
}
/**
*/
public Iterator getKickedOutPathsIterator()
{
+ assert trackOmittedPaths;
return kickedOutPaths.iterator();
}
protected List scanForArtifactPaths( File repositoryBase, List blacklistedPatterns, String[] includes,
- String[] excludes, long comparisonTimestamp )
+ String[] excludes )
{
List allExcludes = new ArrayList();
allExcludes.addAll( FileUtils.getDefaultExcludesAsList() );
// TODO: Correct for extremely large repositories (artifact counts over 200,000 entries)
scanner.scan();
- for ( Iterator files = Arrays.asList( scanner.getExcludedFiles() ).iterator(); files.hasNext(); )
+ if ( trackOmittedPaths )
{
- String path = files.next().toString();
+ for ( Iterator files = Arrays.asList( scanner.getExcludedFiles() ).iterator(); files.hasNext(); )
+ {
+ String path = files.next().toString();
- excludedPaths.add( new DiscovererPath( path, "Artifact was in the specified list of exclusions" ) );
+ excludedPaths.add( new DiscovererPath( path, "Artifact was in the specified list of exclusions" ) );
+ }
}
// TODO: this could be a part of the scanner
{
String path = files.next().toString();
- long modTime = new File( repositoryBase, path ).lastModified();
- if ( modTime < System.currentTimeMillis() - blackoutPeriod )
- {
- if ( modTime > comparisonTimestamp )
- {
- includedPaths.add( path );
- }
- }
+ includedPaths.add( path );
}
return includedPaths;
*/
public Iterator getExcludedPathsIterator()
{
+ assert trackOmittedPaths;
return excludedPaths.iterator();
}
- protected long readComparisonTimestamp( ArtifactRepository repository, String operation, Xpp3Dom dom )
- {
- Xpp3Dom entry = dom.getChild( operation );
- long comparisonTimestamp = 0;
- if ( entry != null )
- {
- try
- {
- comparisonTimestamp = new SimpleDateFormat( DATE_FMT, Locale.US ).parse( entry.getValue() ).getTime();
- }
- catch ( ParseException e )
- {
- getLogger().error( "Timestamp was invalid: " + entry.getValue() + "; ignoring" );
- }
- }
- return comparisonTimestamp;
- }
-
- protected Xpp3Dom readDom( File file )
- {
- Xpp3Dom dom;
- FileReader fileReader = null;
- try
- {
- fileReader = new FileReader( file );
- dom = Xpp3DomBuilder.build( fileReader );
- }
- catch ( FileNotFoundException e )
- {
- // Safe to ignore
- dom = new Xpp3Dom( "metadata" );
- }
- catch ( XmlPullParserException e )
- {
- getLogger().error( "Error reading metadata (ignoring and recreating): " + e.getMessage() );
- dom = new Xpp3Dom( "metadata" );
- }
- catch ( IOException e )
- {
- getLogger().error( "Error reading metadata (ignoring and recreating): " + e.getMessage() );
- dom = new Xpp3Dom( "metadata" );
- }
- finally
- {
- IOUtil.close( fileReader );
- }
- return dom;
- }
-
- protected Xpp3Dom getLastArtifactDiscoveryDom( Xpp3Dom dom )
- {
- Xpp3Dom lastDiscoveryDom = dom.getChild( "lastArtifactDiscovery" );
- if ( lastDiscoveryDom == null )
- {
- dom.addChild( new Xpp3Dom( "lastArtifactDiscovery" ) );
- lastDiscoveryDom = dom.getChild( "lastArtifactDiscovery" );
- }
- return lastDiscoveryDom;
- }
-
- protected Xpp3Dom getLastMetadataDiscoveryDom( Xpp3Dom dom )
- {
- Xpp3Dom lastDiscoveryDom = dom.getChild( "lastMetadataDiscovery" );
- if ( lastDiscoveryDom == null )
- {
- dom.addChild( new Xpp3Dom( "lastMetadataDiscovery" ) );
- lastDiscoveryDom = dom.getChild( "lastMetadataDiscovery" );
- }
- return lastDiscoveryDom;
- }
-
- public void resetLastCheckedTime( ArtifactRepository repository, String operation )
- throws IOException
- {
- // TODO: get these changes into maven-metadata.xml and migrate towards that. The model is further diverging to a different layout at each level so submodels might be a good idea.
- // TODO: maven-artifact probably needs an improved pathOfMetadata to cope with top level metadata
- // TODO: might we need to write this as maven-metadata-local in some circumstances? merge others? Probably best to keep it simple and just use this format at the root. No need to merge anything that I can see
- // TODO: since this metadata isn't meant to be shared, perhaps another file is called for after all.
- // Format is: <repository><lastDiscovery><KEY>yyyyMMddHHmmss</KEY></lastDiscovery></repository> (ie, flat properties)
-
- File file = new File( repository.getBasedir(), "maven-metadata.xml" );
-
- Xpp3Dom dom = readDom( file );
-
- boolean changed = false;
-
- if ( removeEntry( getLastArtifactDiscoveryDom( dom ), operation ) )
- {
- changed = true;
- }
-
- if ( removeEntry( getLastMetadataDiscoveryDom( dom ), operation ) )
- {
- changed = true;
- }
-
- if ( changed )
- {
- saveDom( file, dom );
- }
- }
-
- private boolean removeEntry( Xpp3Dom lastDiscoveryDom, String operation )
- {
- boolean changed = false;
-
- // do this in reverse so that removing doesn't affect counter
- Xpp3Dom[] children = lastDiscoveryDom.getChildren();
- for ( int i = lastDiscoveryDom.getChildCount() - 1; i >= 0; i-- )
- {
- if ( children[i].getName().equals( operation ) )
- {
- changed = true;
- lastDiscoveryDom.removeChild( i );
- }
- }
- return changed;
- }
-
- protected void saveDom( File file, Xpp3Dom dom )
- throws IOException
- {
- FileWriter writer = new FileWriter( file );
-
- // save metadata
- try
- {
- Xpp3DomWriter.write( writer, dom );
- }
- finally
- {
- IOUtil.close( writer );
- }
- }
-
- protected void setEntry( Xpp3Dom lastDiscoveryDom, String operation, String dateString )
- {
- Xpp3Dom entry = lastDiscoveryDom.getChild( operation );
- if ( entry == null )
- {
- entry = new Xpp3Dom( operation );
- lastDiscoveryDom.addChild( entry );
- }
- entry.setValue( dateString );
- }
-
- protected Xpp3Dom readRepositoryMetadataDom( ArtifactRepository repository )
+ public void setTrackOmittedPaths( boolean trackOmittedPaths )
{
- return readDom( new File( repository.getBasedir(), "maven-metadata.xml" ) );
+ this.trackOmittedPaths = trackOmittedPaths;
}
}
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import java.util.List;
* consecutively even if unchanged, so any users of this list must handle such a situation gracefully.
*
* @param repository the location of the repository
- * @param operation the operation being used to discover for timestamp checking
* @param blacklistedPatterns pattern that lists any files to prevent from being included when scanning
- * @param includeSnapshots whether to discover snapshots
+ * @param filter filter for artifacts to include in the discovered list
* @return the list of artifacts discovered
* @throws DiscovererException if there was an unrecoverable problem discovering artifacts or recording progress
*/
- List discoverArtifacts( ArtifactRepository repository, String operation, List blacklistedPatterns,
- boolean includeSnapshots )
+ List discoverArtifacts( ArtifactRepository repository, List blacklistedPatterns, ArtifactFilter filter )
throws DiscovererException;
/**
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Date;
import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
import java.util.StringTokenizer;
/**
throw new UnsupportedOperationException( "Only filesystem repositories are supported" );
}
- Xpp3Dom dom = getLastMetadataDiscoveryDom( readRepositoryMetadataDom( repository ) );
- long comparisonTimestamp = readComparisonTimestamp( repository, operation, dom );
-
- // Note that last checked time is deliberately set to the start of the process so that anything added
- // mid-discoverer and missed by the scanner will get checked next time.
- // Due to this, there must be no negative side-effects of discovering something twice.
- Date newLastCheckedTime = new Date();
-
List metadataFiles = new ArrayList();
List metadataPaths = scanForArtifactPaths( new File( repository.getBasedir() ), blacklistedPatterns,
- STANDARD_DISCOVERY_INCLUDES, null, comparisonTimestamp );
-
- // Also note that the last check time, while set at the start, is saved at the end, so that if any exceptions
- // occur, then the timestamp is not updated so that the discoverer is attempted again
- // TODO: under the list-return behaviour we have now, exceptions might occur later and the timestamp will not be reset - see MRM-83
- try
- {
- setLastCheckedTime( repository, operation, newLastCheckedTime );
- }
- catch ( IOException e )
- {
- throw new DiscovererException( "Error writing metadata: " + e.getMessage(), e );
- }
+ STANDARD_DISCOVERY_INCLUDES, null );
for ( Iterator i = metadataPaths.iterator(); i.hasNext(); )
{
return metadata;
}
-
- public void setLastCheckedTime( ArtifactRepository repository, String operation, Date date )
- throws IOException
- {
- // see notes in resetLastCheckedTime
-
- File file = new File( repository.getBasedir(), "maven-metadata.xml" );
-
- Xpp3Dom dom = readDom( file );
-
- String dateString = new SimpleDateFormat( DATE_FMT, Locale.US ).format( date );
-
- setEntry( getLastMetadataDiscoveryDom( dom ), operation, dateString );
-
- saveDom( file, dom );
- }
}
package org.apache.maven.archiva.discoverer;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-
-import java.io.IOException;
-import java.util.Date;
import java.util.Iterator;
/*
*/
Iterator getExcludedPathsIterator();
- /**
- * Reset the time in the repository that indicates the last time a check was performed.
- *
- * @param repository the location of the repository
- * @param operation the operation to record the timestamp for
- * @throws java.io.IOException if there is a non-recoverable problem reading or writing the metadata
- */
- void resetLastCheckedTime( ArtifactRepository repository, String operation )
- throws IOException;
-
- /**
- * Set the time in the repository that indicates the last time a check was performed.
- *
- * @param repository the location of the repository
- * @param operation the operation to record the timestamp for
- * @param date the date to set the last check to
- * @throws java.io.IOException if there is a non-recoverable problem reading or writing the metadata
- */
- void setLastCheckedTime( ArtifactRepository repository, String operation, Date date )
- throws IOException;
+ void setTrackOmittedPaths( boolean trackOmittedPaths );
}
--- /dev/null
+package org.apache.maven.archiva.discoverer.filter;
+
+/*
+ * 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.resolver.filter.ArtifactFilter;
+
+/**
+ * Filter that accepts all.
+ */
+public class AcceptAllArtifactFilter
+ implements ArtifactFilter
+{
+ public boolean include( Artifact artifact )
+ {
+ return true;
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.discoverer.filter;
+
+/*
+ * 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.resolver.filter.ArtifactFilter;
+
+/**
+ * A filter to remove snapshot artifacts during discovery.
+ */
+public class SnapshotArtifactFilter
+ implements ArtifactFilter
+{
+ public boolean include( Artifact artifact )
+ {
+ return !artifact.isSnapshot();
+ }
+}
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.io.File;
-import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
/**
* @author Edwin Punzalan
protected ArtifactRepository repository;
- protected static final String TEST_OPERATION = "test";
-
protected abstract String getLayout();
protected abstract File getRepositoryFile();
repository = getRepository();
- removeTimestampMetadata();
+ // TODO!
+// removeTimestampMetadata();
}
protected ArtifactRepository getRepository()
return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
}
+/* TODO!
public void testUpdatedInRepository()
throws ComponentLookupException, DiscovererException, ParseException, IOException
{
// Set repository time to 1-1-2000, a time in the distant past so definitely updated
- discoverer.setLastCheckedTime( repository, "update",
+ discoverer.setLastCheckedTime( repository, UPDATE_OPERATION,
new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2000-01-01" ) );
- List artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ List artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check included",
artifacts.contains( createArtifact( "org.apache.maven.update", "test-updated", "1.0" ) ) );
// try again with the updated timestamp
- artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertFalse( "Check not included",
throws ComponentLookupException, DiscovererException, IOException
{
// Set repository time to now, which is after any artifacts, so definitely not updated
- discoverer.setLastCheckedTime( repository, "update", new Date() );
+ discoverer.setLastCheckedTime( repository, UPDATE_OPERATION, new Date() );
- List artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ List artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertFalse( "Check not included",
public void testNotUpdatedInRepositoryForcedDiscovery()
throws ComponentLookupException, DiscovererException, IOException
{
- discoverer.resetLastCheckedTime( repository, "update" );
+ discoverer.resetLastCheckedTime( repository, UPDATE_OPERATION );
- List artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ List artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check included",
artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) );
// try again with the updated timestamp
- artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertFalse( "Check not included",
public void testUpdatedInRepositoryBlackout()
throws ComponentLookupException, DiscovererException, IOException
{
- discoverer.resetLastCheckedTime( repository, "update" );
+ discoverer.resetLastCheckedTime( repository, UPDATE_OPERATION );
Artifact artifact = createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" );
artifact.getFile().setLastModified( System.currentTimeMillis() );
- List artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ List artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertFalse( "Check not included", artifacts.contains( artifact ) );
// try again with the updated timestamp
- artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertFalse( "Check not included", artifacts.contains( artifact ) );
public void testUpdatedInRepositoryNotBlackout()
throws ComponentLookupException, DiscovererException, IOException
{
- discoverer.resetLastCheckedTime( repository, "update" );
+ discoverer.resetLastCheckedTime( repository, UPDATE_OPERATION );
Artifact artifact = createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" );
artifact.getFile().setLastModified( System.currentTimeMillis() - 61000 );
- List artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ List artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check included", artifacts.contains( artifact ) );
// try again with the updated timestamp
- artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertFalse( "Check not included", artifacts.contains( artifact ) );
public void testNotUpdatedInRepositoryForcedDiscoveryMetadataAlreadyExists()
throws ComponentLookupException, DiscovererException, IOException
{
- discoverer.setLastCheckedTime( repository, "update", new Date() );
+ discoverer.setLastCheckedTime( repository, UPDATE_OPERATION, new Date() );
- discoverer.resetLastCheckedTime( repository, "update" );
+ discoverer.resetLastCheckedTime( repository, UPDATE_OPERATION );
- List artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ List artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check included",
artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) );
// try again with the updated timestamp
- artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertFalse( "Check not included",
{
discoverer.setLastCheckedTime( repository, "test", new Date() );
- discoverer.resetLastCheckedTime( repository, "update" );
+ discoverer.resetLastCheckedTime( repository, UPDATE_OPERATION );
- List artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ List artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check included",
artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) );
// try again with the updated timestamp
- artifacts = discoverer.discoverArtifacts( repository, "update", null, true );
+ artifacts = discoverUpdateArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertFalse( "Check not included",
removeTimestampMetadata();
// should find all
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check included",
artifacts.contains( createArtifact( "org.apache.maven.update", "test-updated", "1.0" ) ) );
}
+ private List discoverUpdateArtifactsWithSnapshots()
+ throws DiscovererException
+ {
+ return discoverer.discoverArtifacts( repository, UPDATE_OPERATION, null, new AcceptAllArtifactFilter() );
+ }
+
+ private List discoverArtifactsWithSnapshots()
+ throws DiscovererException
+ {
+ return discoverer.discoverArtifacts( repository, TEST_OPERATION, null, new AcceptAllArtifactFilter() );
+ }
+
private void removeTimestampMetadata()
{
// remove the metadata that tracks time
file.delete();
assertFalse( file.exists() );
}
+*/
}
* limitations under the License.
*/
+import org.apache.maven.archiva.discoverer.filter.AcceptAllArtifactFilter;
+import org.apache.maven.archiva.discoverer.filter.SnapshotArtifactFilter;
import org.apache.maven.artifact.Artifact;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
public void testDefaultExcludes()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
public void testStandardExcludes()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
public void testBlacklistedExclude()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, JAVAX_BLACKLIST, false );
+ List artifacts = discoverArtifactsWithBlacklist( JAVAX_BLACKLIST );
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithShortPath()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithWrongArtifactId()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithNoType()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithWrongVersion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithLongerVersion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithWrongSnapshotVersion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithSnapshotBaseVersion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testInclusion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included",
public void testArtifactWithClassifier()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included",
public void testJavaSourcesInclusion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included", artifacts.contains(
public void testDistributionInclusion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check zip included",
public void testSnapshotInclusion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
public void testSnapshotInclusionWithClassifier()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check snapshot included", artifacts.contains(
public void testSnapshotExclusion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
public void testFileSet()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
public void testRepositorySet()
throws MalformedURLException, DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
String url = repository.getUrl();
public void testStandalonePoms()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
// cull down to actual artifacts (only standalone poms will have type = pom)
Map keyedArtifacts = new HashMap();
assertEquals( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", "javadoc" ),
artifact );
}
+
+ private List discoverArtifactsWithSnapshots()
+ throws DiscovererException
+ {
+ return discoverer.discoverArtifacts( repository, null, new AcceptAllArtifactFilter() );
+ }
+
+ private List discoverArtifactsWithBlacklist( List list )
+ throws DiscovererException
+ {
+ return discoverer.discoverArtifacts( repository, list, new SnapshotArtifactFilter() );
+ }
+
+ private List discoverArtifacts()
+ throws DiscovererException
+ {
+ return discoverer.discoverArtifacts( repository, null, new SnapshotArtifactFilter() );
+ }
}
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.io.File;
import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
/**
* This class tests the DefaultMetadataDiscoverer class.
assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) );
}
+/* TODO!
public void testUpdatedInRepository()
throws ComponentLookupException, DiscovererException, ParseException, IOException
{
assertFalse( "Check not included", containsMetadata( metadataPaths, metadata ) );
}
- private boolean containsMetadata( List metadataPaths, RepositoryMetadata metadata )
- {
- for ( Iterator i = metadataPaths.iterator(); i.hasNext(); )
- {
- RepositoryMetadata m = (RepositoryMetadata) i.next();
-
- if ( m.getGroupId().equals( metadata.getGroupId() ) )
- {
- if ( m.getArtifactId() == null && metadata.getArtifactId() == null )
- {
- return true;
- }
- else if ( m.getArtifactId() != null && m.getArtifactId().equals( metadata.getArtifactId() ) )
- {
- return true;
- }
- }
- }
- return false;
- }
-
public void testNotUpdatedInRepository()
throws ComponentLookupException, DiscovererException, IOException
{
new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-updated" ) );
assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) );
}
+*/
protected Artifact createArtifact( String groupId, String artifactId )
{
{
return factory.createArtifact( groupId, artifactId, version, null, "jar" );
}
+
+ private boolean containsMetadata( List metadataPaths, RepositoryMetadata metadata )
+ {
+ for ( Iterator i = metadataPaths.iterator(); i.hasNext(); )
+ {
+ RepositoryMetadata m = (RepositoryMetadata) i.next();
+
+ if ( m.getGroupId().equals( metadata.getGroupId() ) )
+ {
+ if ( m.getArtifactId() == null && metadata.getArtifactId() == null )
+ {
+ return true;
+ }
+ else if ( m.getArtifactId() != null && m.getArtifactId().equals( metadata.getArtifactId() ) )
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
* limitations under the License.
*/
+import org.apache.maven.archiva.discoverer.filter.AcceptAllArtifactFilter;
+import org.apache.maven.archiva.discoverer.filter.SnapshotArtifactFilter;
import org.apache.maven.artifact.Artifact;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
public void testDefaultExcludes()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
public void testStandardExcludes()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
public void testBlacklistedExclude()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, JAVAX_SQL_BLACKLIST, false );
+ List artifacts = discoverArtifactsWithBlacklist();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithShortPath()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithLongPath()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithInvalidType()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithNoExtension()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithWrongExtension()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testKickoutWithNoVersion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
public void testInclusion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included",
public void testTextualVersion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included",
public void testArtifactWithClassifier()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included",
public void testJavaSourcesInclusion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included", artifacts.contains(
public void testDistributionInclusion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check zip included",
public void testSnapshotInclusion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
public void testSnapshotExclusion()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
+ List artifacts = discoverArtifacts();
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
public void testFileSet()
throws DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
public void testRepositorySet()
throws MalformedURLException, DiscovererException
{
- List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
+ List artifacts = discoverArtifactsWithSnapshots();
assertNotNull( "Check artifacts not null", artifacts );
String url = repository.getUrl();
assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact );
}
+
+ private List discoverArtifacts()
+ throws DiscovererException
+ {
+ return discoverer.discoverArtifacts( repository, null, new SnapshotArtifactFilter() );
+ }
+
+ private List discoverArtifactsWithBlacklist()
+ throws DiscovererException
+ {
+ return discoverer.discoverArtifacts( repository, JAVAX_SQL_BLACKLIST, new SnapshotArtifactFilter() );
+ }
+
+ private List discoverArtifactsWithSnapshots()
+ throws DiscovererException
+ {
+ return discoverer.discoverArtifacts( repository, null, new AcceptAllArtifactFilter() );
+ }
}
*/
import org.apache.maven.archiva.indexer.query.Query;
+import org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory;
import java.util.Collection;
import java.util.List;
* Indexes the artifacts found within the specified list of index records. If the artifacts are already in the
* repository they are updated.
*
- * @param records the artifacts to index
+ * @param records the records to index
* @throws RepositoryIndexException if there is a problem indexing the records
*/
void indexRecords( Collection records )
*/
void deleteRecords( Collection records )
throws RepositoryIndexException;
+
+ /**
+ * Retrieve all records in the index.
+ *
+ * @return the records
+ * @throws RepositoryIndexSearchException if there was an error searching the index
+ */
+ Collection getAllRecords()
+ throws RepositoryIndexSearchException;
+
+ /**
+ * Retrieve all primary keys of records in the index.
+ *
+ * @return the keys
+ * @throws RepositoryIndexSearchException if there was an error searching the index
+ */
+ Collection getAllRecordKeys()
+ throws RepositoryIndexException;
+
+ /**
+ * Indexes the artifacts found within the specified list. If the artifacts are already in the
+ * repository they are updated. This method should use less memory than indexRecords as the records can be
+ * created and disposed of on the fly.
+ *
+ * @param artifacts the artifacts to index
+ * @param factory the artifact to record factory
+ * @throws RepositoryIndexException if there is a problem indexing the artifacts
+ */
+ void indexArtifacts( List artifacts, RepositoryIndexRecordFactory factory )
+ throws RepositoryIndexException;
}
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexModifier;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermEnum;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.maven.archiva.indexer.RepositoryArtifactIndex;
import org.apache.maven.archiva.indexer.RepositoryIndexException;
import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
import org.apache.maven.archiva.indexer.query.Query;
import org.apache.maven.archiva.indexer.record.MinimalIndexRecordFields;
import org.apache.maven.archiva.indexer.record.RepositoryIndexRecord;
+import org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory;
import org.apache.maven.archiva.indexer.record.StandardIndexRecordFields;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.project.MavenProjectBuilder;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* Lucene implementation of a repository index.
private static Analyzer luceneAnalyzer = new LuceneAnalyzer();
+ private MavenProjectBuilder projectBuilder;
+
public LuceneRepositoryArtifactIndex( File indexPath, LuceneIndexRecordConverter converter )
{
this.indexLocation = indexPath;
this.converter = converter;
}
+ public LuceneRepositoryArtifactIndex( File indexLocation, LuceneIndexRecordConverter converter,
+ MavenProjectBuilder projectBuilder )
+ {
+ this.indexLocation = indexLocation;
+ this.converter = converter;
+ this.projectBuilder = projectBuilder;
+ }
+
public void indexRecords( Collection records )
throws RepositoryIndexException
{
}
finally
{
- close( indexWriter );
- }
- }
-
- private void close( IndexWriter indexWriter )
- throws RepositoryIndexException
- {
- try
- {
- if ( indexWriter != null )
- {
- indexWriter.close();
- }
- }
- catch ( IOException e )
- {
- throw new RepositoryIndexException( e.getMessage(), e );
+ closeQuietly( indexWriter );
}
}
{
indexReader = IndexReader.open( indexLocation );
- for ( Iterator artifacts = records.iterator(); artifacts.hasNext(); )
+ for ( Iterator i = records.iterator(); i.hasNext(); )
{
- RepositoryIndexRecord record = (RepositoryIndexRecord) artifacts.next();
+ RepositoryIndexRecord record = (RepositoryIndexRecord) i.next();
if ( record != null )
{
}
finally
{
- if ( indexReader != null )
+ closeQuietly( indexReader );
+ }
+ }
+ }
+
+ public Collection getAllRecords()
+ throws RepositoryIndexSearchException
+ {
+ return search( new LuceneQuery( new MatchAllDocsQuery() ) );
+ }
+
+ public Collection getAllRecordKeys()
+ throws RepositoryIndexException
+ {
+ Set keys = new HashSet();
+
+ if ( exists() )
+ {
+ IndexReader indexReader = null;
+ TermEnum terms = null;
+ try
+ {
+ indexReader = IndexReader.open( indexLocation );
+
+ terms = indexReader.terms( new Term( FLD_PK, "" ) );
+ while ( FLD_PK.equals( terms.term().field() ) )
{
- closeQuietly( indexReader );
+ keys.add( terms.term().text() );
+
+ if ( !terms.next() )
+ {
+ break;
+ }
}
}
+ catch ( IOException e )
+ {
+ throw new RepositoryIndexException( "Error deleting document: " + e.getMessage(), e );
+ }
+ finally
+ {
+ closeQuietly( indexReader );
+ closeQuietly( terms );
+ }
+ }
+ return keys;
+ }
+
+ public void indexArtifacts( List artifacts, RepositoryIndexRecordFactory factory )
+ throws RepositoryIndexException
+ {
+ IndexModifier indexModifier = null;
+ try
+ {
+ indexModifier = new IndexModifier( indexLocation, getAnalyzer(), !exists() );
+
+ int count = 0;
+ for ( Iterator i = artifacts.iterator(); i.hasNext(); count++ )
+ {
+ Artifact artifact = (Artifact) i.next();
+ RepositoryIndexRecord record = factory.createRecord( artifact );
+
+ if ( record != null )
+ {
+ Term term = new Term( FLD_PK, record.getPrimaryKey() );
+
+ indexModifier.deleteDocuments( term );
+
+ Document document = converter.convert( record );
+ document.add(
+ new Field( FLD_PK, record.getPrimaryKey(), Field.Store.NO, Field.Index.UN_TOKENIZED ) );
+
+ indexModifier.addDocument( document );
+ }
+
+ if ( count % 100 == 0 )
+ {
+ // MNG-142 - the project builder retains a lot of objects in its inflexible cache. This is a hack
+ // around that. TODO: remove when it is configurable
+ flushProjectBuilderCacheHack();
+ }
+ }
+ indexModifier.optimize();
+ }
+ catch ( IOException e )
+ {
+ throw new RepositoryIndexException( "Error updating index: " + e.getMessage(), e );
+ }
+ finally
+ {
+ closeQuietly( indexModifier );
+ }
+ }
+
+ private void flushProjectBuilderCacheHack()
+ {
+ try
+ {
+ if ( projectBuilder != null )
+ {
+ java.lang.reflect.Field f = projectBuilder.getClass().getDeclaredField( "rawProjectCache" );
+ f.setAccessible( true );
+ Map cache = (Map) f.get( projectBuilder );
+ cache.clear();
+
+ f = projectBuilder.getClass().getDeclaredField( "processedProjectCache" );
+ f.setAccessible( true );
+ cache = (Map) f.get( projectBuilder );
+ cache.clear();
+ }
+ }
+ catch ( NoSuchFieldException e )
+ {
+ throw new RuntimeException( e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new RuntimeException( e );
}
}
}
}
+ private static void closeQuietly( TermEnum terms )
+ throws RepositoryIndexException
+ {
+ if ( terms != null )
+ {
+ try
+ {
+ terms.close();
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ }
+ }
+
+ private static void closeQuietly( IndexWriter indexWriter )
+ throws RepositoryIndexException
+ {
+ try
+ {
+ if ( indexWriter != null )
+ {
+ indexWriter.close();
+ }
+ }
+ catch ( IOException e )
+ {
+ // write should compain if it can't be closed, data probably not persisted
+ throw new RepositoryIndexException( e.getMessage(), e );
+ }
+ }
+
+ private static void closeQuietly( IndexModifier indexModifier )
+ {
+ if ( indexModifier != null )
+ {
+ try
+ {
+ indexModifier.close();
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ }
+ }
+
private static void closeQuietly( IndexReader reader )
{
try
import org.apache.maven.archiva.indexer.RepositoryArtifactIndex;
import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory;
+import org.apache.maven.project.MavenProjectBuilder;
import java.io.File;
public class LuceneRepositoryArtifactIndexFactory
implements RepositoryArtifactIndexFactory
{
+ /**
+ * @plexus.requirement
+ * @todo remove when MNG-142 is fixed
+ */
+ private MavenProjectBuilder projectBuilder;
+
public RepositoryArtifactIndex createStandardIndex( File indexPath )
{
- return new LuceneRepositoryArtifactIndex( indexPath, new LuceneStandardIndexRecordConverter() );
+ return new LuceneRepositoryArtifactIndex( indexPath, new LuceneStandardIndexRecordConverter(), projectBuilder );
}
public RepositoryArtifactIndex createMinimalIndex( File indexPath )
{
- return new LuceneRepositoryArtifactIndex( indexPath, new LuceneMinimalIndexRecordConverter() );
+ return new LuceneRepositoryArtifactIndex( indexPath, new LuceneMinimalIndexRecordConverter(), projectBuilder );
}
}
{
return dependencies;
}
+
+ public String getPrimaryKey()
+ {
+ return groupId + ":" + artifactId + ":" + version + ( classifier != null ? ":" + classifier : "" );
+ }
}