diff options
author | Joakim Erdfelt <joakime@apache.org> | 2007-02-23 19:05:21 +0000 |
---|---|---|
committer | Joakim Erdfelt <joakime@apache.org> | 2007-02-23 19:05:21 +0000 |
commit | dee0d5a300ee0ba0240efc1277428b52cdcec9e0 (patch) | |
tree | 0f4c8d3b8b8b0468deac3c8851380a68bfa1744e /archiva-core | |
parent | 2b50a18d22ef8972d241f54c20a131e05a584ac4 (diff) | |
download | archiva-dee0d5a300ee0ba0240efc1277428b52cdcec9e0.tar.gz archiva-dee0d5a300ee0ba0240efc1277428b52cdcec9e0.zip |
Merge from archiva-MRM-239 branch to trunk. r506385:HEAD
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@511053 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-core')
27 files changed, 915 insertions, 961 deletions
diff --git a/archiva-core/pom.xml b/archiva-core/pom.xml index da35be2b9..ed730ec37 100644 --- a/archiva-core/pom.xml +++ b/archiva-core/pom.xml @@ -35,10 +35,6 @@ </dependency> <dependency> <groupId>org.apache.maven.archiva</groupId> - <artifactId>archiva-converter</artifactId> - </dependency> - <dependency> - <groupId>org.apache.maven.archiva</groupId> <artifactId>archiva-discoverer</artifactId> </dependency> <dependency> @@ -78,6 +74,13 @@ <version>1.0-alpha-1</version> <scope>test</scope> </dependency> + <!-- TEST DEPS --> + <dependency> + <groupId>hsqldb</groupId> + <artifactId>hsqldb</artifactId> + <version>1.7.3.3</version> + <scope>test</scope> + </dependency> <!-- needed for PlexusTestCase --> <dependency> <groupId>org.codehaus.plexus</groupId> @@ -88,16 +91,22 @@ <build> <plugins> <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>cobertura-maven-plugin</artifactId> - <!-- TODO! add unit tests --> - <configuration> - <instrumentation> - <excludes> - <exclude>**/**</exclude> - </excludes> - </instrumentation> - </configuration> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-maven-plugin</artifactId> + <executions> + <execution> + <id>merge</id> + <goals> + <goal>merge-descriptors</goal> + </goals> + <configuration> + <descriptors> + <descriptor>${basedir}/src/main/resources/META-INF/plexus/components.xml</descriptor> + <descriptor>${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml</descriptor> + </descriptors> + </configuration> + </execution> + </executions> </plugin> </plugins> </build> diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/artifact/ManagedArtifact.java b/archiva-core/src/main/java/org/apache/maven/archiva/artifact/ManagedArtifact.java deleted file mode 100644 index 940b6bde2..000000000 --- a/archiva-core/src/main/java/org/apache/maven/archiva/artifact/ManagedArtifact.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.apache.maven.archiva.artifact; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 java.util.HashMap; -import java.util.Map; - -/** - * ManagedArtifact - * - * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> - * @version $Id$ - */ -public class ManagedArtifact -{ - private String repositoryId; - - private Artifact artifact; - - private String path; - - protected Map attached; - - public ManagedArtifact( String repoId, Artifact artifact, String path ) - { - super(); - this.repositoryId = repoId; - this.artifact = artifact; - this.path = path; - this.attached = new HashMap(); - } - - public Artifact getArtifact() - { - return artifact; - } - - public String getPath() - { - return path; - } - - public String getRepositoryId() - { - return repositoryId; - } - - public Map getAttached() - { - return attached; - } - - public void setAttached( Map attached ) - { - this.attached = attached; - } -} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/artifact/ManagedArtifactTypes.java b/archiva-core/src/main/java/org/apache/maven/archiva/artifact/ManagedArtifactTypes.java deleted file mode 100644 index 6cccfcd6a..000000000 --- a/archiva-core/src/main/java/org/apache/maven/archiva/artifact/ManagedArtifactTypes.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.apache.maven.archiva.artifact; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.commons.lang.StringUtils; - -import java.util.ArrayList; -import java.util.List; - -/** - * ManagedArtifactTypes - provides place to test an unknown artifact type. - * - * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> - * @version $Id$ - */ -public class ManagedArtifactTypes -{ - public static final int GENERIC = 0; - - public static final int JAVA = 1; - - public static final int EJB = 2; - - private static List javaArtifacts; - - private static List ejbArtifacts; - - static - { - javaArtifacts = new ArrayList(); - javaArtifacts.add( "jar" ); - javaArtifacts.add( "war" ); - javaArtifacts.add( "sar" ); - javaArtifacts.add( "rar" ); - javaArtifacts.add( "ear" ); - - ejbArtifacts = new ArrayList(); - ejbArtifacts.add( "ejb" ); - ejbArtifacts.add( "ejb-client" ); - } - - public static int whichType( String type ) - { - if ( StringUtils.isBlank( type ) ) - { - // TODO: is an empty type even possible? - return GENERIC; - } - - type = type.toLowerCase(); - - if ( ejbArtifacts.contains( type ) ) - { - return EJB; - } - - if ( javaArtifacts.contains( type ) ) - { - return JAVA; - } - - return GENERIC; - } -} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/artifact/ManagedJavaArtifact.java b/archiva-core/src/main/java/org/apache/maven/archiva/artifact/ManagedJavaArtifact.java deleted file mode 100644 index babb88420..000000000 --- a/archiva-core/src/main/java/org/apache/maven/archiva/artifact/ManagedJavaArtifact.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.apache.maven.archiva.artifact; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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; - -/** - * ManagedJavaArtifact - a ManagedArtifact with optional javadoc and source - * reference jars. - * - * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> - * @version $Id$ - */ -public class ManagedJavaArtifact - extends ManagedArtifact -{ - public static final String JAVADOC = "javadoc"; - - public static final String SOURCES = "sources"; - - public ManagedJavaArtifact( String repoId, Artifact artifact, String path ) - { - super( repoId, artifact, path ); - } - - public String getJavadocPath() - { - return (String) super.attached.get( JAVADOC ); - } - - public void setJavadocPath( String javadocPath ) - { - super.attached.put( JAVADOC, javadocPath ); - } - - public String getSourcesPath() - { - return (String) super.attached.get( SOURCES ); - } - - public void setSourcesPath( String sourcesPath ) - { - super.attached.put( SOURCES, sourcesPath ); - } -} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/consumers/ArtifactHealthConsumer.java b/archiva-core/src/main/java/org/apache/maven/archiva/consumers/ArtifactHealthConsumer.java new file mode 100644 index 000000000..7b6d15ffb --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/archiva/consumers/ArtifactHealthConsumer.java @@ -0,0 +1,97 @@ +package org.apache.maven.archiva.consumers; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.common.consumers.GenericArtifactConsumer; +import org.apache.maven.archiva.common.utils.BaseFile; +import org.apache.maven.archiva.reporting.database.ArtifactResultsDatabase; +import org.apache.maven.archiva.reporting.group.ReportGroup; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.InvalidArtifactRTException; +import org.apache.maven.model.Model; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.ProjectBuildingException; + +import java.util.Collections; + +/** + * ArtifactHealthConsumer + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component role="org.apache.maven.archiva.common.consumers.Consumer" + * role-hint="artifact-health" + * instantiation-strategy="per-lookup" + */ +public class ArtifactHealthConsumer + extends GenericArtifactConsumer +{ + /** + * @plexus.requirement + */ + private ArtifactResultsDatabase database; + + /** + * @plexus.requirement role-hint="health" + */ + private ReportGroup health; + + /** + * @plexus.requirement + */ + private MavenProjectBuilder projectBuilder; + + public void processArtifact( Artifact artifact, BaseFile file ) + { + Model model = null; + try + { + Artifact pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact + .getArtifactId(), artifact.getVersion() ); + MavenProject project = projectBuilder.buildFromRepository( pomArtifact, Collections.EMPTY_LIST, repository ); + + model = project.getModel(); + } + catch ( InvalidArtifactRTException e ) + { + database.addWarning( artifact, null, null, "Invalid artifact [" + artifact + "] : " + e ); + } + catch ( ProjectBuildingException e ) + { + database.addWarning( artifact, null, null, "Error reading project model: " + e ); + } + + database.remove( artifact ); + health.processArtifact( artifact, model ); + } + + public void processFileProblem( BaseFile path, String message ) + { + /* do nothing here (yet) */ + // TODO: store build failure into database? + } + + public String getName() + { + return "Artifact Health Consumer"; + } +} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/consumers/IndexArtifactConsumer.java b/archiva-core/src/main/java/org/apache/maven/archiva/consumers/IndexArtifactConsumer.java new file mode 100644 index 000000000..2d7026bb1 --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/archiva/consumers/IndexArtifactConsumer.java @@ -0,0 +1,99 @@ +package org.apache.maven.archiva.consumers; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.common.consumers.GenericArtifactConsumer; +import org.apache.maven.archiva.common.utils.BaseFile; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +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 java.io.File; + +/** + * IndexArtifactConsumer + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component role="org.apache.maven.archiva.common.consumers.Consumer" + * role-hint="index-artifact" + * instantiation-strategy="per-lookup" + */ +public class IndexArtifactConsumer + extends GenericArtifactConsumer +{ + /** + * @plexus.requirement + */ + private RepositoryArtifactIndexFactory indexFactory; + + /** + * @plexus.requirement role-hint="standard" + */ + private RepositoryIndexRecordFactory recordFactory; + + /** + * Configuration store. + * + * @plexus.requirement + */ + private ArchivaConfiguration archivaConfiguration; + + private RepositoryArtifactIndex index; + + public boolean init( ArtifactRepository repository ) + { + Configuration configuration = archivaConfiguration.getConfiguration(); + + File indexPath = new File( configuration.getIndexPath() ); + + index = indexFactory.createStandardIndex( indexPath ); + + return super.init( repository ); + } + + public void processArtifact( Artifact artifact, BaseFile file ) + { + try + { + index.indexArtifact( artifact, recordFactory ); + } + catch ( RepositoryIndexException e ) + { + getLogger().warn( "Unable to index artifact " + artifact, e ); + } + } + + public void processFileProblem( BaseFile path, String message ) + { + + } + + public String getName() + { + return "Index Artifact Consumer"; + } +} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/consumers/RepositoryMetadataHealthConsumer.java b/archiva-core/src/main/java/org/apache/maven/archiva/consumers/RepositoryMetadataHealthConsumer.java new file mode 100644 index 000000000..d858d32cd --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/archiva/consumers/RepositoryMetadataHealthConsumer.java @@ -0,0 +1,69 @@ +package org.apache.maven.archiva.consumers; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.common.consumers.GenericRepositoryMetadataConsumer; +import org.apache.maven.archiva.common.utils.BaseFile; +import org.apache.maven.archiva.reporting.database.MetadataResultsDatabase; +import org.apache.maven.archiva.reporting.group.ReportGroup; +import org.apache.maven.archiva.reporting.model.MetadataResults; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; + +/** + * RepositoryMetadataHealthConsumer + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component role="org.apache.maven.archiva.common.consumers.Consumer" + * role-hint="metadata-health" + * instantiation-strategy="per-lookup" + */ +public class RepositoryMetadataHealthConsumer + extends GenericRepositoryMetadataConsumer +{ + /** + * @plexus.requirement + */ + private MetadataResultsDatabase database; + + /** + * @plexus.requirement role-hint="health" + */ + private ReportGroup health; + + public void processRepositoryMetadata( RepositoryMetadata metadata, BaseFile file ) + { + MetadataResults results = database.getMetadataResults( metadata ); + database.clearResults( results ); + + health.processMetadata( metadata, repository ); + } + + public void processFileProblem( BaseFile path, String message ) + { + + } + + public String getName() + { + return "RepositoryMetadata Health Consumer"; + } +} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/conversion/DefaultLegacyRepositoryConverter.java b/archiva-core/src/main/java/org/apache/maven/archiva/conversion/DefaultLegacyRepositoryConverter.java deleted file mode 100644 index 7beb18a99..000000000 --- a/archiva-core/src/main/java/org/apache/maven/archiva/conversion/DefaultLegacyRepositoryConverter.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.apache.maven.archiva.conversion; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.converter.RepositoryConversionException; -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.database.ReportingDatabase; -import org.apache.maven.archiva.reporting.group.ReportGroup; -import org.apache.maven.archiva.reporting.store.ReportingStore; -import org.apache.maven.archiva.reporting.store.ReportingStoreException; -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; -import java.util.List; - -/** - * @author Jason van Zyl - * @plexus.component - * @todo turn this into a general conversion component and hide all this crap here. - * @todo it should be possible to move this to the converter module without causing it to gain additional dependencies - */ -public class DefaultLegacyRepositoryConverter - implements LegacyRepositoryConverter -{ - /** - * @plexus.requirement role-hint="legacy" - */ - private ArtifactDiscoverer artifactDiscoverer; - - /** - * @plexus.requirement role-hint="legacy" - */ - private ArtifactRepositoryLayout legacyLayout; - - /** - * @plexus.requirement role-hint="default" - */ - private ArtifactRepositoryLayout defaultLayout; - - /** - * @plexus.requirement - */ - private ArtifactRepositoryFactory artifactRepositoryFactory; - - /** - * @plexus.requirement - */ - private RepositoryConverter repositoryConverter; - - /** - * @plexus.requirement - */ - private ReportingStore reportingStore; - - /** - * @plexus.requirement role-hint="health" - */ - private ReportGroup reportGroup; - - public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory, - List blacklistedPatterns, boolean includeSnapshots ) - throws RepositoryConversionException, DiscovererException - { - ArtifactRepository legacyRepository; - - ArtifactRepository repository; - - try - { - legacyRepository = artifactRepositoryFactory.createArtifactRepository( "legacy", - legacyRepositoryDirectory.toURI().toURL().toString(), - legacyLayout, null, null ); - - repository = artifactRepositoryFactory.createArtifactRepository( "default", - repositoryDirectory.toURI().toURL().toString(), - defaultLayout, null, null ); - } - catch ( MalformedURLException e ) - { - throw new RepositoryConversionException( "Error convering legacy repository.", e ); - } - - ArtifactFilter filter = - includeSnapshots ? new AcceptAllArtifactFilter() : (ArtifactFilter) new SnapshotArtifactFilter(); - List legacyArtifacts = artifactDiscoverer.discoverArtifacts( legacyRepository, blacklistedPatterns, filter ); - - ReportingDatabase reporter; - try - { - reporter = reportingStore.getReportsFromStore( repository, reportGroup ); - - repositoryConverter.convert( legacyArtifacts, repository, reporter ); - - reportingStore.storeReports( reporter, repository ); - } - catch ( ReportingStoreException e ) - { - throw new RepositoryConversionException( "Error convering legacy repository.", e ); - } - } -} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/conversion/LegacyRepositoryConverter.java b/archiva-core/src/main/java/org/apache/maven/archiva/conversion/LegacyRepositoryConverter.java deleted file mode 100644 index 876421475..000000000 --- a/archiva-core/src/main/java/org/apache/maven/archiva/conversion/LegacyRepositoryConverter.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.apache.maven.archiva.conversion; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.converter.RepositoryConversionException; -import org.apache.maven.archiva.discoverer.DiscovererException; - -import java.io.File; -import java.util.List; - -/** - * @author Jason van Zyl - */ -public interface LegacyRepositoryConverter -{ - String ROLE = LegacyRepositoryConverter.class.getName(); - - /** - * Convert a legacy repository to a modern repository. This means a Maven 1.x repository - * using v3 POMs to a Maven 2.x repository using v4.0.0 POMs. - * - * @param legacyRepositoryDirectory - * @param repositoryDirectory - * @throws org.apache.maven.archiva.converter.RepositoryConversionException - * - */ - void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory, List blacklistedPatterns, - boolean includeSnapshots ) - throws RepositoryConversionException, DiscovererException; -} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/repositories/ActiveManagedRepositories.java b/archiva-core/src/main/java/org/apache/maven/archiva/repositories/ActiveManagedRepositories.java index 554fb3491..0bac31018 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/repositories/ActiveManagedRepositories.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/repositories/ActiveManagedRepositories.java @@ -19,7 +19,7 @@ package org.apache.maven.archiva.repositories; * under the License. */ -import org.apache.maven.archiva.artifact.ManagedArtifact; +import org.apache.maven.archiva.common.artifact.managed.ManagedArtifact; import org.apache.maven.archiva.configuration.RepositoryConfiguration; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -31,7 +31,7 @@ import java.util.List; /** * ActiveManagedRepositories * - * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ */ public interface ActiveManagedRepositories @@ -44,12 +44,27 @@ public interface ActiveManagedRepositories * @param id the ID of the repository. * @return the ArtifactRepository associated with the provided ID, or null if none found. */ - ArtifactRepository getArtifactRepository( String id ); + public ArtifactRepository getArtifactRepository( String id ); - List getAllArtifactRepositories(); + /** + * Get the List of active managed repositories as a List of {@link ArtifactRepository} objects. + * + * @return the list of ArtifactRepository objects. + */ + public List /*<ArtifactRepository>*/getAllArtifactRepositories(); RepositoryConfiguration getRepositoryConfiguration( String id ); + /** + * Providing only a groupId, artifactId, and version, return the MavenProject that + * is found, in any managed repository. + * + * @param groupId the groupId to search for + * @param artifactId the artifactId to search for + * @param version the version to search for + * @return the MavenProject from the provided parameters. + * @throws ProjectBuildingException if there was a problem building the maven project object. + */ MavenProject findProject( String groupId, String artifactId, String version ) throws ProjectBuildingException; @@ -59,4 +74,20 @@ public interface ActiveManagedRepositories ManagedArtifact findArtifact( String groupId, String artifactId, String version, String type ); ManagedArtifact findArtifact( Artifact artifact ); + + /** + * Obtain the last data refresh timestamp for all Managed Repositories. + * + * @return the last data refresh timestamp. + */ + long getLastDataRefreshTime(); + + /** + * Tests to see if there needs to be a data refresh performed. + * + * The only valid scenario is if 1 or more repositories have not had their data refreshed ever. + * + * @return true if there needs to be a data refresh. + */ + boolean needsDataRefresh(); } diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/repositories/DefaultActiveManagedRepositories.java b/archiva-core/src/main/java/org/apache/maven/archiva/repositories/DefaultActiveManagedRepositories.java index 128a91d66..6b2504783 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/repositories/DefaultActiveManagedRepositories.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/repositories/DefaultActiveManagedRepositories.java @@ -20,14 +20,15 @@ package org.apache.maven.archiva.repositories; */ import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.artifact.ManagedArtifact; -import org.apache.maven.archiva.artifact.ManagedArtifactTypes; -import org.apache.maven.archiva.artifact.ManagedEjbArtifact; -import org.apache.maven.archiva.artifact.ManagedJavaArtifact; +import org.apache.maven.archiva.common.artifact.managed.ManagedArtifact; +import org.apache.maven.archiva.common.artifact.managed.ManagedArtifactTypes; +import org.apache.maven.archiva.common.artifact.managed.ManagedEjbArtifact; +import org.apache.maven.archiva.common.artifact.managed.ManagedJavaArtifact; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ConfiguredRepositoryFactory; import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.discoverer.DiscovererStatistics; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -49,7 +50,7 @@ import java.util.List; /** * DefaultActiveManagedRepositories * - * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ * @plexus.component role="org.apache.maven.archiva.repositories.ActiveManagedRepositories" */ @@ -224,6 +225,7 @@ public class DefaultActiveManagedRepositories repositories = repositoryFactory.createRepositories( this.configuration ); localRepository = repositoryFactory.createLocalRepository( this.configuration ); + } private ManagedArtifact createManagedArtifact( ArtifactRepository repository, Artifact artifact, File f ) @@ -283,8 +285,9 @@ public class DefaultActiveManagedRepositories { if ( propertyName.startsWith( "repositories" ) || propertyName.startsWith( "localRepository" ) ) { - getLogger().debug( "Triggering managed repository configuration change with " + propertyName + " set to " + - propertyValue ); + getLogger().debug( + "Triggering managed repository configuration change with " + propertyName + " set to " + + propertyValue ); configureSelf( archivaConfiguration.getConfiguration() ); } else @@ -292,4 +295,39 @@ public class DefaultActiveManagedRepositories getLogger().debug( "Not triggering managed repository configuration change with " + propertyName ); } } + + public long getLastDataRefreshTime() + { + long lastDataRefreshTime = 0; + + for ( Iterator i = getAllArtifactRepositories().iterator(); i.hasNext(); ) + { + ArtifactRepository repository = (ArtifactRepository) i.next(); + + DiscovererStatistics stats = new DiscovererStatistics( repository ); + if ( stats.getTimestampFinished() > lastDataRefreshTime ) + { + lastDataRefreshTime = stats.getTimestampFinished(); + } + } + + return lastDataRefreshTime; + } + + public boolean needsDataRefresh() + { + for ( Iterator i = getAllArtifactRepositories().iterator(); i.hasNext(); ) + { + ArtifactRepository repository = (ArtifactRepository) i.next(); + + DiscovererStatistics stats = new DiscovererStatistics( repository ); + if ( stats.getTimestampFinished() <= 0 ) + { + // Found a repository that has NEVER had it's data walked. + return true; + } + } + + return false; + } } diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/DefaultRepositoryTaskScheduler.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/DefaultRepositoryTaskScheduler.java index 04ab088d4..bae351750 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/DefaultRepositoryTaskScheduler.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/DefaultRepositoryTaskScheduler.java @@ -21,11 +21,8 @@ package org.apache.maven.archiva.scheduler; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; -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.scheduler.executors.IndexerTaskExecutor; -import org.apache.maven.archiva.scheduler.task.IndexerTask; +import org.apache.maven.archiva.repositories.ActiveManagedRepositories; +import org.apache.maven.archiva.scheduler.task.DataRefreshTask; import org.apache.maven.archiva.scheduler.task.RepositoryTask; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; @@ -42,7 +39,6 @@ import org.quartz.JobDataMap; import org.quartz.JobDetail; import org.quartz.SchedulerException; -import java.io.File; import java.text.ParseException; /** @@ -61,28 +57,23 @@ public class DefaultRepositoryTaskScheduler private Scheduler scheduler; /** - * @plexus.requirement role-hint="indexer" + * @plexus.requirement role-hint="data-refresh" */ - private TaskQueue indexerQueue; - - /** - * @plexus.requirement role="org.codehaus.plexus.taskqueue.execution.TaskExecutor" role-hint="indexer" - */ - private IndexerTaskExecutor indexerTaskExecutor; + private TaskQueue datarefreshQueue; /** * @plexus.requirement */ private ArchivaConfiguration archivaConfiguration; - + /** * @plexus.requirement */ - private RepositoryArtifactIndexFactory indexFactory; + private ActiveManagedRepositories activeRepositories; private static final String DISCOVERER_GROUP = "DISCOVERER"; - private static final String INDEXER_JOB = "indexerTask"; + private static final String DATA_REFRESH_JOB = "dataRefreshTask"; public void start() throws StartingException @@ -92,11 +83,11 @@ public class DefaultRepositoryTaskScheduler try { - scheduleJobs( configuration.getIndexPath(), configuration.getIndexerCronExpression() ); + scheduleJobs( configuration.getDataRefreshCronExpression() ); } catch ( ParseException e ) { - throw new StartingException( "Invalid configuration: " + configuration.getIndexerCronExpression(), e ); + throw new StartingException( "Invalid configuration: " + configuration.getDataRefreshCronExpression(), e ); } catch ( SchedulerException e ) { @@ -104,29 +95,22 @@ public class DefaultRepositoryTaskScheduler } } - private void scheduleJobs( String indexPath, String indexerCronExpression ) + private void scheduleJobs( String indexerCronExpression ) throws ParseException, SchedulerException { - if ( indexPath != null ) - { - JobDetail jobDetail = createJobDetail( INDEXER_JOB ); + JobDetail jobDetail = createJobDetail( DATA_REFRESH_JOB ); - getLogger().info( "Scheduling indexer: " + indexerCronExpression ); - CronTrigger trigger = new CronTrigger( INDEXER_JOB + "Trigger", DISCOVERER_GROUP, indexerCronExpression ); - scheduler.scheduleJob( jobDetail, trigger ); + getLogger().info( "Scheduling data-refresh: " + indexerCronExpression ); + CronTrigger trigger = new CronTrigger( DATA_REFRESH_JOB + "Trigger", DISCOVERER_GROUP, indexerCronExpression ); + scheduler.scheduleJob( jobDetail, trigger ); - try - { - queueNowIfNeeded(); - } - catch ( org.codehaus.plexus.taskqueue.execution.TaskExecutionException e ) - { - getLogger().error( "Error executing task first time, continuing anyway: " + e.getMessage(), e ); - } + try + { + queueNowIfNeeded(); } - else + catch ( org.codehaus.plexus.taskqueue.execution.TaskExecutionException e ) { - getLogger().info( "Not scheduling indexer - index path is not configured" ); + getLogger().error( "Error executing task first time, continuing anyway: " + e.getMessage(), e ); } } @@ -135,7 +119,7 @@ public class DefaultRepositoryTaskScheduler JobDetail jobDetail = new JobDetail( jobName, DISCOVERER_GROUP, RepositoryTaskJob.class ); JobDataMap dataMap = new JobDataMap(); - dataMap.put( RepositoryTaskJob.TASK_QUEUE, indexerQueue ); + dataMap.put( RepositoryTaskJob.TASK_QUEUE, datarefreshQueue ); dataMap.put( RepositoryTaskJob.TASK_QUEUE_POLICY, RepositoryTask.QUEUE_POLICY_SKIP ); jobDetail.setJobDataMap( dataMap ); @@ -147,7 +131,7 @@ public class DefaultRepositoryTaskScheduler { try { - scheduler.unscheduleJob( INDEXER_JOB, DISCOVERER_GROUP ); + scheduler.unscheduleJob( DATA_REFRESH_JOB, DISCOVERER_GROUP ); } catch ( SchedulerException e ) { @@ -163,7 +147,7 @@ public class DefaultRepositoryTaskScheduler public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) { - if ( "indexPath".equals( propertyName ) || "indexerCronExpression".equals( propertyName ) ) + if ( "dataRefreshCronExpression".equals( propertyName ) ) { getLogger().debug( "Restarting task scheduler with new configuration after property change: " + propertyName + " to " + propertyValue ); @@ -179,7 +163,7 @@ public class DefaultRepositoryTaskScheduler try { Configuration configuration = archivaConfiguration.getConfiguration(); - scheduleJobs( configuration.getIndexPath(), configuration.getIndexerCronExpression() ); + scheduleJobs( configuration.getDataRefreshCronExpression() ); } catch ( ParseException e ) { @@ -199,43 +183,27 @@ public class DefaultRepositoryTaskScheduler } } - public void runIndexer() - throws org.apache.maven.archiva.scheduler.TaskExecutionException + public void runDataRefresh() + throws TaskExecutionException { - IndexerTask task = new IndexerTask(); - task.setJobName( "INDEX_INIT" ); + DataRefreshTask task = new DataRefreshTask(); + task.setJobName( "DATA_REFRESH_INIT" ); try { - indexerQueue.put( task ); + datarefreshQueue.put( task ); } catch ( TaskQueueException e ) { - throw new org.apache.maven.archiva.scheduler.TaskExecutionException( e.getMessage(), e ); + throw new TaskExecutionException( e.getMessage(), e ); } } public void queueNowIfNeeded() - throws org.codehaus.plexus.taskqueue.execution.TaskExecutionException + throws TaskExecutionException { - Configuration configuration = archivaConfiguration.getConfiguration(); - - File indexPath = new File( configuration.getIndexPath() ); - - try + if ( activeRepositories.needsDataRefresh() ) { - RepositoryArtifactIndex artifactIndex = indexFactory.createStandardIndex( indexPath ); - if ( !artifactIndex.exists() ) - { - runIndexer(); - } - } - catch ( RepositoryIndexException e ) - { - throw new TaskExecutionException( e.getMessage(), e ); - } - catch ( org.apache.maven.archiva.scheduler.TaskExecutionException e ) - { - throw new TaskExecutionException( e.getMessage(), e ); + runDataRefresh(); } } diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskJob.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskJob.java index dc3c26ace..06152f244 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskJob.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskJob.java @@ -19,7 +19,7 @@ package org.apache.maven.archiva.scheduler; * under the License. */ -import org.apache.maven.archiva.scheduler.task.IndexerTask; +import org.apache.maven.archiva.scheduler.task.DataRefreshTask; import org.apache.maven.archiva.scheduler.task.RepositoryTask; import org.codehaus.plexus.scheduler.AbstractJob; import org.codehaus.plexus.taskqueue.TaskQueue; @@ -53,27 +53,27 @@ public class RepositoryTaskJob JobDataMap dataMap = context.getJobDetail().getJobDataMap(); setJobDataMap( dataMap ); - TaskQueue indexerQueue = (TaskQueue) dataMap.get( TASK_QUEUE ); + TaskQueue taskQueue = (TaskQueue) dataMap.get( TASK_QUEUE ); String queuePolicy = dataMap.get( TASK_QUEUE_POLICY ).toString(); - RepositoryTask task = new IndexerTask(); + RepositoryTask task = new DataRefreshTask(); task.setJobName( context.getJobDetail().getName() ); try { - if ( indexerQueue.getQueueSnapshot().size() == 0 ) + if ( taskQueue.getQueueSnapshot().size() == 0 ) { - indexerQueue.put( task ); + taskQueue.put( task ); } else { if ( RepositoryTask.QUEUE_POLICY_WAIT.equals( queuePolicy ) ) { - indexerQueue.put( task ); + taskQueue.put( task ); } else if ( RepositoryTask.QUEUE_POLICY_SKIP.equals( queuePolicy ) ) { - //do not queue anymore, policy is to skip + // do not queue anymore, policy is to skip } } } diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskScheduler.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskScheduler.java index c63556ff5..08e511f3e 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskScheduler.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskScheduler.java @@ -19,6 +19,8 @@ package org.apache.maven.archiva.scheduler; * under the License. */ +import org.codehaus.plexus.taskqueue.execution.TaskExecutionException; + /** * The component that takes care of scheduling in the application. * @@ -31,7 +33,7 @@ public interface RepositoryTaskScheduler */ String ROLE = RepositoryTaskScheduler.class.getName(); - void runIndexer() + void runDataRefresh() throws TaskExecutionException; -} +} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/DataRefreshConsumers.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/DataRefreshConsumers.java new file mode 100644 index 000000000..783a44c27 --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/DataRefreshConsumers.java @@ -0,0 +1,61 @@ +package org.apache.maven.archiva.scheduler.executors; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * Mutable list of consumer for the Data Refresh. + * + * NOTE: This class only exists to minimize the requirements of manual component management. + * This approach allows for a small and simple component definition in the application.xml + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component role="org.apache.maven.archiva.scheduler.executors.DataRefreshConsumers" + */ +public class DataRefreshConsumers +{ + /** + * @plexus.configuration + */ + private List consumerNames; + + public List getConsumerNames() + { + if ( consumerNames == null ) + { + consumerNames = new ArrayList(); + consumerNames.add( "index-artifact" ); + consumerNames.add( "artifact-health" ); + consumerNames.add( "metadata-health" ); + } + + return consumerNames; + } + + public Iterator iterator() + { + return getConsumerNames().iterator(); + } +} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/DataRefreshExecutor.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/DataRefreshExecutor.java new file mode 100644 index 000000000..939277235 --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/DataRefreshExecutor.java @@ -0,0 +1,192 @@ +package org.apache.maven.archiva.scheduler.executors; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.common.consumers.Consumer; +import org.apache.maven.archiva.common.consumers.ConsumerException; +import org.apache.maven.archiva.common.consumers.ConsumerFactory; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.ConfiguredRepositoryFactory; +import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.discoverer.Discoverer; +import org.apache.maven.archiva.discoverer.DiscovererException; +import org.apache.maven.archiva.discoverer.DiscovererStatistics; +import org.apache.maven.archiva.scheduler.task.DataRefreshTask; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.taskqueue.Task; +import org.codehaus.plexus.taskqueue.execution.TaskExecutionException; +import org.codehaus.plexus.taskqueue.execution.TaskExecutor; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * DataRefreshExecutor + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component role="org.codehaus.plexus.taskqueue.execution.TaskExecutor" + * role-hint="data-refresh" + */ +public class DataRefreshExecutor + extends AbstractLogEnabled + implements TaskExecutor +{ + /** + * Configuration store. + * + * @plexus.requirement + */ + private ArchivaConfiguration archivaConfiguration; + + /** + * @plexus.requirement + */ + private ConfiguredRepositoryFactory repoFactory; + + /** + * @plexus.requirement + */ + private DataRefreshConsumers consumerNames; + + /** + * @plexus.requirement + */ + private Discoverer discoverer; + + /** + * @plexus.requirement + */ + private ConsumerFactory consumerFactory; + + public void executeTask( Task task ) + throws TaskExecutionException + { + DataRefreshTask indexerTask = (DataRefreshTask) task; + + getLogger().info( "Executing task from queue with job name: " + indexerTask.getJobName() ); + + execute(); + } + + public void execute() + throws TaskExecutionException + { + Configuration configuration = archivaConfiguration.getConfiguration(); + + List consumers = new ArrayList(); + + for ( Iterator it = consumerNames.iterator(); it.hasNext(); ) + { + String name = (String) it.next(); + try + { + Consumer consumer = consumerFactory.createConsumer( name ); + consumers.add( consumer ); + } + catch ( ConsumerException e ) + { + getLogger().warn( e.getMessage(), e ); + throw new TaskExecutionException( e.getMessage(), e ); + } + } + + long time = System.currentTimeMillis(); + + for ( Iterator i = configuration.getRepositories().iterator(); i.hasNext(); ) + { + RepositoryConfiguration repositoryConfiguration = (RepositoryConfiguration) i.next(); + + if ( !repositoryConfiguration.isIndexed() ) + { + continue; + } + + ArtifactRepository repository = repoFactory.createRepository( repositoryConfiguration ); + + List filteredConsumers = filterConsumers( consumers, repository ); + + DiscovererStatistics lastRunStats = new DiscovererStatistics( repository ); + try + { + lastRunStats.load( ".datarefresh" ); + } + catch ( IOException e ) + { + getLogger().info( + "Unable to load last run statistics for repository [" + repository.getId() + "]: " + + e.getMessage() ); + } + + try + { + DiscovererStatistics stats = discoverer + .walkRepository( repository, filteredConsumers, repositoryConfiguration.isIncludeSnapshots(), + lastRunStats.getTimestampFinished(), null, null ); + + stats.dump( getLogger() ); + } + catch ( DiscovererException e ) + { + getLogger().error( + "Unable to run data refresh against repository [" + repository.getId() + "]: " + + e.getMessage(), e ); + } + } + + time = System.currentTimeMillis() - time; + + getLogger().info( "Finished data refresh process in " + time + "ms." ); + } + + /** + * Not all consumers work with all repositories. + * This will filter out those incompatible consumers based on the provided repository. + * + * @param consumers the initial list of consumers. + * @param repository the repository to test consumer against. + * @return the filtered list of consumers. + */ + private List filterConsumers( List consumers, ArtifactRepository repository ) + { + List filtered = new ArrayList(); + + for ( Iterator it = consumers.iterator(); it.hasNext(); ) + { + Consumer consumer = (Consumer) it.next(); + if ( consumer.init( repository ) ) + { + // Approved! + filtered.add( consumer ); + } + else + { + getLogger().info( "Disabling consumer [" + consumer.getName() + "] for repository " + repository ); + } + } + + return filtered; + } +} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/IndexerTaskExecutor.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/IndexerTaskExecutor.java deleted file mode 100644 index 25d390592..000000000 --- a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/executors/IndexerTaskExecutor.java +++ /dev/null @@ -1,317 +0,0 @@ -package org.apache.maven.archiva.scheduler.executors; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.Configuration; -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.MetadataDiscoverer; -import org.apache.maven.archiva.discoverer.filter.MetadataFilter; -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.IndexRecordExistsArtifactFilter; -import org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory; -import org.apache.maven.archiva.reporting.database.ReportingDatabase; -import org.apache.maven.archiva.reporting.executor.ReportExecutor; -import org.apache.maven.archiva.reporting.filter.ReportingMetadataFilter; -import org.apache.maven.archiva.reporting.group.ReportGroup; -import org.apache.maven.archiva.reporting.store.ReportingStoreException; -import org.apache.maven.archiva.scheduler.task.IndexerTask; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; -import org.apache.maven.project.MavenProjectBuilder; -import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.taskqueue.Task; -import org.codehaus.plexus.taskqueue.execution.TaskExecutionException; -import org.codehaus.plexus.taskqueue.execution.TaskExecutor; - -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; - -/** - * @author Edwin Punzalan - * @plexus.component role="org.codehaus.plexus.taskqueue.execution.TaskExecutor" role-hint="indexer" - */ -public class IndexerTaskExecutor - extends AbstractLogEnabled - implements TaskExecutor -{ - /** - * Configuration store. - * - * @plexus.requirement - */ - private ArchivaConfiguration archivaConfiguration; - - /** - * @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="org.apache.maven.archiva.discoverer.MetadataDiscoverer" - */ - private Map metadataDiscoverers; - - /** - * @plexus.requirement role-hint="standard" - */ - private RepositoryIndexRecordFactory recordFactory; - - /** - * @plexus.requirement - */ - private ReportExecutor reportExecutor; - - /** - * @plexus.requirement role-hint="health" - */ - private ReportGroup reportGroup; - - private long lastIndexingTime = 0; - - private static final int ARTIFACT_BUFFER_SIZE = 1000; - - public long getLastIndexingTime() - { - return lastIndexingTime; - } - - public void executeTask( Task task ) - throws TaskExecutionException - { - IndexerTask indexerTask = (IndexerTask) task; - - getLogger().info( "Executing task from queue with job name: " + indexerTask.getJobName() ); - - execute(); - } - - public void execute() - throws TaskExecutionException - { - Configuration configuration = archivaConfiguration.getConfiguration(); - - File indexPath = new File( configuration.getIndexPath() ); - - execute( configuration, indexPath ); - } - - public void executeNowIfNeeded() - throws TaskExecutionException - { - Configuration configuration = archivaConfiguration.getConfiguration(); - - 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 execute( Configuration configuration, File indexPath ) - throws TaskExecutionException - { - long time = System.currentTimeMillis(); - getLogger().info( "Starting repository indexing 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 ); - ReportingDatabase reporter = reportExecutor.getReportDatabase( repository, reportGroup ); - - // keep original value in case there is another process under way - long origStartTime = reporter.getStartTime(); - reporter.setStartTime( System.currentTimeMillis() ); - - // Discovery process - 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( "Discovered " + artifacts.size() + " unindexed artifacts" ); - - // Work through these in batches, then flush the project cache. - for ( int j = 0; j < artifacts.size(); j += ARTIFACT_BUFFER_SIZE ) - { - int end = j + ARTIFACT_BUFFER_SIZE; - List currentArtifacts = - artifacts.subList( j, end > artifacts.size() ? artifacts.size() : end ); - - // TODO: proper queueing of this in case it was triggered externally (not harmful to do so at present, but not optimal) - - // run the reports. Done intermittently to avoid losing track of what is indexed since - // that is what the filter is based on. - reportExecutor.runArtifactReports( reportGroup, currentArtifacts, repository ); - - index.indexArtifacts( currentArtifacts, recordFactory ); - - // MRM-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(); - } - } - - MetadataFilter metadataFilter = new ReportingMetadataFilter( reporter ); - - MetadataDiscoverer metadataDiscoverer = (MetadataDiscoverer) metadataDiscoverers - .get( layoutProperty ); - List metadata = - metadataDiscoverer.discoverMetadata( repository, blacklistedPatterns, metadataFilter ); - - if ( !metadata.isEmpty() ) - { - getLogger().info( "Discovered " + metadata.size() + " unprocessed metadata files" ); - - // run the reports - reportExecutor.runMetadataReports( reportGroup, metadata, repository ); - } - - reporter.setStartTime( origStartTime ); - } - } - } - catch ( RepositoryIndexException e ) - { - throw new TaskExecutionException( e.getMessage(), e ); - } - catch ( DiscovererException e ) - { - throw new TaskExecutionException( e.getMessage(), e ); - } - catch ( ReportingStoreException e ) - { - throw new TaskExecutionException( e.getMessage(), e ); - } - - time = System.currentTimeMillis() - time; - lastIndexingTime = System.currentTimeMillis(); - getLogger().info( "Finished repository indexing process in " + time + "ms" ); - } - - /** - * @todo remove when no longer needed (MRM-142) - * @plexus.requirement - */ - private MavenProjectBuilder projectBuilder; - - private void flushProjectBuilderCacheHack() - { - try - { - if ( projectBuilder != null ) - { - getLogger().info( "projectBuilder is type " + projectBuilder.getClass().getName() ); - - java.lang.reflect.Field f = projectBuilder.getClass().getDeclaredField( "rawProjectCache" ); - f.setAccessible( true ); - Map cache = (Map) f.get( projectBuilder ); - getLogger().info( "projectBuilder.raw is type " + cache.getClass().getName() ); - cache.clear(); - - f = projectBuilder.getClass().getDeclaredField( "processedProjectCache" ); - f.setAccessible( true ); - cache = (Map) f.get( projectBuilder ); - getLogger().info( "projectBuilder.processed is type " + cache.getClass().getName() ); - cache.clear(); - } - } - catch ( NoSuchFieldException e ) - { - throw new RuntimeException( e ); - } - catch ( IllegalAccessException e ) - { - throw new RuntimeException( e ); - } - } -} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/DataRefreshTask.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/DataRefreshTask.java new file mode 100644 index 000000000..57d4b683e --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/DataRefreshTask.java @@ -0,0 +1,41 @@ +package org.apache.maven.archiva.scheduler.task; + +/** + * DataRefreshTask - task for discovering changes in the repository + * and updating all associated data. + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public class DataRefreshTask + implements RepositoryTask +{ + private String jobName; + + private String policy; + + public String getJobName() + { + return jobName; + } + + public String getQueuePolicy() + { + return policy; + } + + public void setJobName( String jobName ) + { + this.jobName = jobName; + } + + public void setQueuePolicy( String policy ) + { + this.policy = policy; + } + + public long getMaxExecutionTime() + { + return 0; + } +} diff --git a/archiva-core/src/main/resources/META-INF/plexus/components.xml b/archiva-core/src/main/resources/META-INF/plexus/components.xml index 1fe09e4ff..cbf418cb4 100644 --- a/archiva-core/src/main/resources/META-INF/plexus/components.xml +++ b/archiva-core/src/main/resources/META-INF/plexus/components.xml @@ -21,9 +21,67 @@ <component-set> <components> + <!-- TODO: Remove once CDC can handle correct cross-module descriptor creation. --> + + <!-- SNIP:START --> + + <component> + <role>org.apache.maven.archiva.common.consumers.Consumer</role> + <role-hint>index-artifact</role-hint> + <implementation>org.apache.maven.archiva.consumers.IndexArtifactConsumer</implementation> + <instantiation-strategy>per-lookup</instantiation-strategy> + <requirements> + <requirement> + <role>org.apache.maven.artifact.factory.ArtifactFactory</role> + <field-name>artifactFactory</field-name> + </requirement> + </requirements> + </component> + + <component> + <role>org.apache.maven.archiva.common.consumers.Consumer</role> + <role-hint>artifact-health</role-hint> + <implementation>org.apache.maven.archiva.consumers.ArtifactHealthConsumer</implementation> + <instantiation-strategy>per-lookup</instantiation-strategy> + <requirements> + <requirement> + <role>org.apache.maven.artifact.factory.ArtifactFactory</role> + <field-name>artifactFactory</field-name> + </requirement> + </requirements> + </component> + + <component> + <role>org.apache.maven.archiva.common.consumers.Consumer</role> + <role-hint>metadata-health</role-hint> + <implementation>org.apache.maven.archiva.consumers.RepositoryMetadataHealthConsumer</implementation> + <instantiation-strategy>per-lookup</instantiation-strategy> + <requirements> + <requirement> + <role>org.apache.maven.artifact.factory.ArtifactFactory</role> + <field-name>artifactFactory</field-name> + </requirement> + </requirements> + </component> + + <!-- SNIP:END --> + + <component> + <role>org.apache.maven.archiva.scheduler.executors.DataRefreshConsumers</role> + <implementation>org.apache.maven.archiva.scheduler.executors.DataRefreshConsumers</implementation> + <description>Mutable list of consumer for the Data Refresh.</description> + <configuration> + <consumer-names> + <consumer-name>index-artifact</consumer-name> + <consumer-name>artifact-health</consumer-name> + <consumer-name>metadata-health</consumer-name> + </consumer-names> + </configuration> + </component> + <component> <role>org.codehaus.plexus.taskqueue.TaskQueue</role> - <role-hint>indexer</role-hint> + <role-hint>data-refresh</role-hint> <implementation>org.codehaus.plexus.taskqueue.DefaultTaskQueue</implementation> <lifecycle-handler>plexus-configurable</lifecycle-handler> <configuration> @@ -38,20 +96,20 @@ <component> <role>org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor</role> - <role-hint>indexer</role-hint> + <role-hint>data-refresh</role-hint> <implementation>org.codehaus.plexus.taskqueue.execution.ThreadedTaskQueueExecutor</implementation> <requirements> <requirement> <role>org.codehaus.plexus.taskqueue.execution.TaskExecutor</role> - <role-hint>indexer</role-hint> + <role-hint>data-refresh</role-hint> </requirement> <requirement> <role>org.codehaus.plexus.taskqueue.TaskQueue</role> - <role-hint>indexer</role-hint> + <role-hint>data-refresh</role-hint> </requirement> </requirements> <configuration> - <name>indexer</name> + <name>data-refresh</name> </configuration> </component> diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/artifact/ManagedEjbArtifact.java b/archiva-core/src/test/java/org/apache/maven/archiva/AllTests.java index eacf1cbdf..e037e09c3 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/artifact/ManagedEjbArtifact.java +++ b/archiva-core/src/test/java/org/apache/maven/archiva/AllTests.java @@ -1,4 +1,4 @@ -package org.apache.maven.archiva.artifact; +package org.apache.maven.archiva; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -19,31 +19,26 @@ package org.apache.maven.archiva.artifact; * under the License. */ -import org.apache.maven.artifact.Artifact; +import junit.framework.Test; +import junit.framework.TestSuite; /** - * ManagedEjbArtifact - adds the ability to reference the ejb-client jar too. + * AllTests - added to allow IDE users to pull all tests into their tool. * * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @version $Id$ */ -public class ManagedEjbArtifact - extends ManagedJavaArtifact +public class AllTests { - public static final String CLIENT = "client"; - public ManagedEjbArtifact( String repoId, Artifact artifact, String path ) + public static Test suite() { - super( repoId, artifact, path ); + TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva" ); + //$JUnit-BEGIN$ + suite.addTest( org.apache.maven.archiva.repositories.AllTests.suite() ); + suite.addTest( org.apache.maven.archiva.scheduler.executors.AllTests.suite() ); + //$JUnit-END$ + return suite; } - public String getClientPath() - { - return (String) super.attached.get( CLIENT ); - } - - public void setClientPath( String clientPath ) - { - super.attached.put( CLIENT, clientPath ); - } } diff --git a/archiva-core/src/test/java/org/apache/maven/archiva/LegacyRepositoryConverterTest.java b/archiva-core/src/test/java/org/apache/maven/archiva/LegacyRepositoryConverterTest.java deleted file mode 100644 index bd13a7deb..000000000 --- a/archiva-core/src/test/java/org/apache/maven/archiva/LegacyRepositoryConverterTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.apache.maven.archiva; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.conversion.LegacyRepositoryConverter; -import org.codehaus.plexus.PlexusTestCase; - -import java.io.File; - -/** - * @author Jason van Zyl - */ -public class LegacyRepositoryConverterTest - extends PlexusTestCase -{ - public void testLegacyRepositoryConversion() - throws Exception - { - File legacyRepositoryDirectory = getTestFile( "src/test/maven-1.x-repository" ); - - File repositoryDirectory = getTestFile( "target/maven-2.x-repository" ); - - LegacyRepositoryConverter rm = (LegacyRepositoryConverter) lookup( LegacyRepositoryConverter.ROLE ); - - rm.convertLegacyRepository( legacyRepositoryDirectory, repositoryDirectory, null, true ); - } -} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/TaskExecutionException.java b/archiva-core/src/test/java/org/apache/maven/archiva/repositories/AllTests.java index 51643445a..0b82640b9 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/TaskExecutionException.java +++ b/archiva-core/src/test/java/org/apache/maven/archiva/repositories/AllTests.java @@ -1,4 +1,4 @@ -package org.apache.maven.archiva.scheduler; +package org.apache.maven.archiva.repositories; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -9,7 +9,7 @@ package org.apache.maven.archiva.scheduler; * "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 + * 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 @@ -19,16 +19,25 @@ package org.apache.maven.archiva.scheduler; * under the License. */ +import junit.framework.Test; +import junit.framework.TestSuite; + /** - * Exception occurring during task execution. + * AllTests * - * @author <a href="mailto:brett@apache.org">Brett Porter</a> + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ */ -public class TaskExecutionException - extends Exception +public class AllTests { - public TaskExecutionException( String message, Throwable t ) + + public static Test suite() { - super( message, t ); + TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.repositories" ); + //$JUnit-BEGIN$ + suite.addTestSuite( DefaultActiveManagedRepositoriesTest.class ); + //$JUnit-END$ + return suite; } + } diff --git a/archiva-core/src/test/java/org/apache/maven/archiva/repositories/DefaultActiveManagedRepositoriesTest.java b/archiva-core/src/test/java/org/apache/maven/archiva/repositories/DefaultActiveManagedRepositoriesTest.java index a535307e2..f4e89eadf 100644 --- a/archiva-core/src/test/java/org/apache/maven/archiva/repositories/DefaultActiveManagedRepositoriesTest.java +++ b/archiva-core/src/test/java/org/apache/maven/archiva/repositories/DefaultActiveManagedRepositoriesTest.java @@ -19,15 +19,15 @@ package org.apache.maven.archiva.repositories; * under the License. */ -import org.apache.maven.archiva.artifact.ManagedArtifact; -import org.apache.maven.archiva.artifact.ManagedEjbArtifact; -import org.apache.maven.archiva.artifact.ManagedJavaArtifact; +import org.apache.maven.archiva.common.artifact.managed.ManagedArtifact; +import org.apache.maven.archiva.common.artifact.managed.ManagedEjbArtifact; +import org.apache.maven.archiva.common.artifact.managed.ManagedJavaArtifact; import org.codehaus.plexus.PlexusTestCase; /** * DefaultActiveManagedRepositoriesTest * - * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ */ public class DefaultActiveManagedRepositoriesTest diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java b/archiva-core/src/test/java/org/apache/maven/archiva/scheduler/executors/AllTests.java index a4cd2f612..9fdfcc15b 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java +++ b/archiva-core/src/test/java/org/apache/maven/archiva/scheduler/executors/AllTests.java @@ -1,4 +1,4 @@ -package org.apache.maven.archiva.scheduler.task; +package org.apache.maven.archiva.scheduler.executors; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -9,7 +9,7 @@ package org.apache.maven.archiva.scheduler.task; * "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 + * 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 @@ -19,42 +19,25 @@ package org.apache.maven.archiva.scheduler.task; * under the License. */ +import junit.framework.Test; +import junit.framework.TestSuite; + /** - * Task for discovering changes in the repository and updating the index accordingly. + * AllTests * - * @author <a href="mailto:brett@apache.org">Brett Porter</a> + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ */ -public class IndexerTask - implements RepositoryTask +public class AllTests { - private String jobName; - - private String policy; - - public long getMaxExecutionTime() - { - return 0; - } - - public String getJobName() - { - return jobName; - } - public String getQueuePolicy() + public static Test suite() { - return policy; + TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.scheduler.executors" ); + //$JUnit-BEGIN$ + suite.addTestSuite( DataRefreshExecutorTest.class ); + //$JUnit-END$ + return suite; } - public void setQueuePolicy( String policy ) - { - this.policy = policy; - } - - public void setJobName( String jobName ) - { - this.jobName = jobName; - } - - } diff --git a/archiva-core/src/test/java/org/apache/maven/archiva/scheduler/executors/IndexerTaskExecutorTest.java b/archiva-core/src/test/java/org/apache/maven/archiva/scheduler/executors/DataRefreshExecutorTest.java index 8729e0ccb..ad9900795 100644 --- a/archiva-core/src/test/java/org/apache/maven/archiva/scheduler/executors/IndexerTaskExecutorTest.java +++ b/archiva-core/src/test/java/org/apache/maven/archiva/scheduler/executors/DataRefreshExecutorTest.java @@ -22,7 +22,7 @@ package org.apache.maven.archiva.scheduler.executors; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; -import org.apache.maven.archiva.scheduler.task.IndexerTask; +import org.apache.maven.archiva.scheduler.task.DataRefreshTask; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.taskqueue.execution.TaskExecutionException; import org.codehaus.plexus.taskqueue.execution.TaskExecutor; @@ -32,10 +32,10 @@ import java.io.File; /** * IndexerTaskExecutorTest * - * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ */ -public class IndexerTaskExecutorTest +public class DataRefreshExecutorTest extends PlexusTestCase { private TaskExecutor taskExecutor; @@ -45,7 +45,7 @@ public class IndexerTaskExecutorTest { super.setUp(); - taskExecutor = (TaskExecutor) lookup( "org.codehaus.plexus.taskqueue.execution.TaskExecutor", "indexer" ); + taskExecutor = (TaskExecutor) lookup( "org.codehaus.plexus.taskqueue.execution.TaskExecutor", "data-refresh" ); ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName() ); @@ -58,18 +58,18 @@ public class IndexerTaskExecutorTest } } - public void testIndexer() + public void testExecutor() throws TaskExecutionException { - taskExecutor.executeTask( new TestIndexerTask() ); + taskExecutor.executeTask( new TestDataRefreshTask() ); } - class TestIndexerTask - extends IndexerTask + class TestDataRefreshTask + extends DataRefreshTask { public String getJobName() { - return "TestIndexer"; + return "TestDataRefresh"; } } } diff --git a/archiva-core/src/test/resources/org/apache/maven/archiva/scheduler/executors/DataRefreshExecutorTest.xml b/archiva-core/src/test/resources/org/apache/maven/archiva/scheduler/executors/DataRefreshExecutorTest.xml new file mode 100644 index 000000000..5a7d8101b --- /dev/null +++ b/archiva-core/src/test/resources/org/apache/maven/archiva/scheduler/executors/DataRefreshExecutorTest.xml @@ -0,0 +1,90 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you 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. + --> + +<component-set> + <components> + <component> + <role>org.codehaus.plexus.registry.Registry</role> + <implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation> + <role-hint>commons-configuration</role-hint> + <configuration> + <properties> + <xml fileName="${basedir}/src/test/conf/archiva.xml" + config-name="org.apache.maven.archiva" config-at="org.apache.maven.archiva"/> + </properties> + </configuration> + </component> + + <component> + <role>org.codehaus.plexus.jdo.JdoFactory</role> + <role-hint>archiva</role-hint> + <implementation>org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory</implementation> + + <configuration> + <!-- Database Configuration --> + <driverName>org.hsqldb.jdbcDriver</driverName> + <url>jdbc:hsqldb:mem:TESTDB</url> + <userName>sa</userName> + <password></password> + + <!-- JPOX and JDO configuration --> + <persistenceManagerFactoryClass>org.jpox.PersistenceManagerFactoryImpl</persistenceManagerFactoryClass> + <otherProperties> + <property> + <name>javax.jdo.PersistenceManagerFactoryClass</name> + <value>org.jpox.PersistenceManagerFactoryImpl</value> + </property> + <property> + <name>org.jpox.autoCreateSchema</name> + <value>true</value> + </property> + <property> + <name>org.jpox.validateTables</name> + <value>false</value> + </property> + <property> + <name>org.jpox.validateConstraints</name> + <value>false</value> + </property> + <property> + <name>org.jpox.validateColumns</name> + <value>false</value> + </property> + <property> + <name>org.jpox.autoStartMechanism</name> + <value>None</value> + </property> + <property> + <name>org.jpox.transactionIsolation</name> + <value>READ_UNCOMMITTED</value> + </property> + <property> + <name>org.jpox.poid.transactionIsolation</name> + <value>READ_UNCOMMITTED</value> + </property> + <property> + <name>org.jpox.rdbms.dateTimezone</name> + <value>JDK_DEFAULT_TIMEZONE</value> + </property> + </otherProperties> + </configuration> + </component> + </components> +</component-set> diff --git a/archiva-core/src/test/resources/org/apache/maven/archiva/scheduler/executors/IndexerTaskExecutorTest.xml b/archiva-core/src/test/resources/org/apache/maven/archiva/scheduler/executors/IndexerTaskExecutorTest.xml deleted file mode 100644 index 34d15023a..000000000 --- a/archiva-core/src/test/resources/org/apache/maven/archiva/scheduler/executors/IndexerTaskExecutorTest.xml +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you 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. - --> - -<component-set> - <components> - <component> - <role>org.codehaus.plexus.registry.Registry</role> - <implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation> - <role-hint>commons-configuration</role-hint> - <configuration> - <properties> - <xml fileName="${basedir}/src/test/conf/archiva.xml" - config-name="org.apache.maven.archiva" config-at="org.apache.maven.archiva"/> - </properties> - </configuration> - </component> - </components> -</component-set> |