From: Brett Porter Date: Mon, 5 Dec 2005 01:41:43 +0000 (+0000) Subject: some updates to the reports base and tests X-Git-Tag: archiva-0.9-alpha-1~1087 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5c3468fad9708d8a3098867852fc56f061649b72;p=archiva.git some updates to the reports base and tests - simplify the result classes - we need a factory component for the query layer, because the query layer needs a repository - added a mock implementation of the reporter (removed the "default" one which is the same) - added a default repository query interface that uses the file system - add a test for the metadata versions not matching the repo - add some comments git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@353954 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/RepositoryFileFilter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/RepositoryFileFilter.java deleted file mode 100644 index 5116b1cd2..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/RepositoryFileFilter.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.maven.repository; - -/* - * Copyright 2001-2005 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. - */ - -/** - * This class is used to ignore several files that may be present inside the repository so that the other classes - * may not worry about them and then can concentrate on doing their tasks. - * - */ -public class RepositoryFileFilter implements java.io.FileFilter -{ - public boolean accept(java.io.File pathname) - { - if ( pathname.isDirectory() ) - { - if ( ".svn".equals( pathname.getName() ) ) return false; - if ( "CVS".equals( pathname.getName() ) ) return false; - } - else - { - String name = pathname.getName(); - if ( name.endsWith( ".md5" ) ) return false; - if ( name.endsWith( ".sha1" ) ) return false; - } - - return true; - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java index c6f59eb7f..a65131ef5 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java @@ -19,12 +19,14 @@ package org.apache.maven.repository.reporting; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import java.util.Iterator; + /** * This interface is used by the single artifact processor. - * - * The initial implementation of this will just need to be a mock implementation in src/test/java, used to track the - * failures and successes for checking assertions. Later, implementations will be made to present reports on the - * web interface, send them via mail, and so on. + *

+ * The initial implementation of this will just need to be a mock implementation in src/test/java, used to track the + * failures and successes for checking assertions. Later, implementations will be made to present reports on the + * web interface, send them via mail, and so on. */ public interface ArtifactReporter { @@ -35,10 +37,23 @@ public interface ArtifactReporter void addSuccess( Artifact artifact ); void addWarning( Artifact artifact, String message ); - + void addFailure( RepositoryMetadata metadata, String reason ); void addSuccess( RepositoryMetadata metadata ); void addWarning( RepositoryMetadata metadata, String message ); + + Iterator getArtifactFailureIterator(); + + Iterator getArtifactSuccessIterator(); + + Iterator getArtifactWarningIterator(); + + Iterator getRepositoryMetadataFailureIterator(); + + Iterator getRepositoryMetadataSuccessIterator(); + + Iterator getRepositoryMetadataWarningIterator(); + } diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java new file mode 100644 index 000000000..fd91b9f6a --- /dev/null +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java @@ -0,0 +1,54 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2001-2005 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; + +/** + * A result of the report for a given artifact being processed. + * + * @author Brett Porter + * @version $Id$ + */ +public class ArtifactResult +{ + private final Artifact artifact; + + private final String reason; + + public ArtifactResult( Artifact artifact ) + { + this.artifact = artifact; + this.reason = null; + } + + public ArtifactResult( Artifact artifact, String reason ) + { + this.artifact = artifact; + this.reason = reason; + } + + public Artifact getArtifact() + { + return artifact; + } + + public String getReason() + { + return reason; + } +} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java index ab0d8f62c..85bf9b91a 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java @@ -8,7 +8,6 @@ package org.apache.maven.repository.reporting; * 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, @@ -17,9 +16,6 @@ package org.apache.maven.repository.reporting; * limitations under the License. */ -import java.io.File; -import java.util.HashMap; -import java.util.Iterator; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -27,31 +23,39 @@ import org.apache.maven.artifact.repository.metadata.Plugin; import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; import org.apache.maven.artifact.repository.metadata.Snapshot; import org.apache.maven.artifact.repository.metadata.Versioning; -import org.apache.maven.repository.RepositoryFileFilter; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; /** * This class will report on bad metadata files. These include invalid version declarations and incomplete version * information inside the metadata file. Plugin metadata will be checked for validity of the latest plugin artifacts. - * */ -public class BadMetadataReportProcessor implements MetadataReportProcessor +public class BadMetadataReportProcessor + implements MetadataReportProcessor { // plexus components private ArtifactFactory artifactFactory; - private RepositoryQueryLayer repositoryQueryLayer; - + + private RepositoryQueryLayerFactory repositoryQueryLayerFactory; + public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter ) + throws ReportProcessorException { boolean hasFailures = false; - + String lastUpdated = metadata.getMetadata().getVersioning().getLastUpdated(); if ( lastUpdated == null || lastUpdated.length() == 0 ) { reporter.addFailure( metadata, "Missing lastUpdated element inside the metadata." ); hasFailures = true; } - + if ( metadata.storedInGroupDirectory() ) { checkPluginMetadata( metadata, repository, reporter ); @@ -62,36 +66,53 @@ public class BadMetadataReportProcessor implements MetadataReportProcessor } else { - if ( !checkMetadataVersions( metadata, repository, reporter ) ) hasFailures = true; - - if ( checkRepositoryVersions( metadata, repository, reporter ) ) hasFailures = true; + if ( !checkMetadataVersions( metadata, repository, reporter ) ) + { + hasFailures = true; + } + + try + { + if ( checkRepositoryVersions( metadata, repository, reporter ) ) + { + hasFailures = true; + } + } + catch ( IOException e ) + { + throw new ReportProcessorException( "Error getting versions", e ); + } + } + + if ( !hasFailures ) + { + reporter.addSuccess( metadata ); } - - if ( !hasFailures ) reporter.addSuccess( metadata ); } - + /** * Checks the plugin metadata */ public boolean checkPluginMetadata( RepositoryMetadata metadata, ArtifactRepository repository, - ArtifactReporter reporter ) + ArtifactReporter reporter ) { boolean hasFailures = false; - - File metadataDir = new File ( repository.getBasedir() + File.pathSeparator + formatAsDirectory( metadata.getGroupId() ) ); - + + File metadataDir = + new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( metadata ) ).getParentFile(); + HashMap prefixes = new HashMap(); - for( Iterator plugins = metadata.getMetadata().getPlugins().iterator(); plugins.hasNext(); ) + for ( Iterator plugins = metadata.getMetadata().getPlugins().iterator(); plugins.hasNext(); ) { Plugin plugin = (Plugin) plugins.next(); - + String artifactId = plugin.getArtifactId(); if ( artifactId == null || artifactId.length() == 0 ) { reporter.addFailure( metadata, "Missing or empty artifactId in group metadata." ); hasFailures = true; } - + String prefix = plugin.getPrefix(); if ( prefix == null || prefix.length() == 0 ) { @@ -110,7 +131,7 @@ public class BadMetadataReportProcessor implements MetadataReportProcessor prefixes.put( prefix, plugin ); } } - + File pluginDir = new File( metadataDir, artifactId ); if ( !pluginDir.exists() ) { @@ -118,23 +139,23 @@ public class BadMetadataReportProcessor implements MetadataReportProcessor hasFailures = true; } } - + return hasFailures; } - + /** * Checks the snapshot metadata */ - public boolean checkSnapshotMetadata( RepositoryMetadata metadata, ArtifactRepository repository, - ArtifactReporter reporter ) + private boolean checkSnapshotMetadata( RepositoryMetadata metadata, ArtifactRepository repository, + ArtifactReporter reporter ) { boolean hasFailures = false; - + Snapshot snapshot = metadata.getMetadata().getVersioning().getSnapshot(); String timestamp = snapshot.getTimestamp(); String buildNumber = String.valueOf( snapshot.getBuildNumber() ); String artifactName = metadata.getArtifactId() + "-" + timestamp + "-" + buildNumber + ".pom"; - + //@todo use wagon instead Artifact artifact = createArtifact( metadata ); File artifactFile = new File( repository.pathOf( artifact ) ); @@ -144,83 +165,85 @@ public class BadMetadataReportProcessor implements MetadataReportProcessor reporter.addFailure( metadata, "Snapshot artifact " + artifactName + " does not exist." ); hasFailures = true; } - + return hasFailures; } - + /** * Checks the declared metadata versions if the artifacts are present in the repository */ - public boolean checkMetadataVersions( RepositoryMetadata metadata, ArtifactRepository repository, - ArtifactReporter reporter ) + private boolean checkMetadataVersions( RepositoryMetadata metadata, ArtifactRepository repository, + ArtifactReporter reporter ) { + RepositoryQueryLayer repositoryQueryLayer = + repositoryQueryLayerFactory.createRepositoryQueryLayer( repository ); + boolean hasFailures = false; Versioning versioning = metadata.getMetadata().getVersioning(); for ( Iterator versions = versioning.getVersions().iterator(); versions.hasNext(); ) { String version = (String) versions.next(); - + Artifact artifact = createArtifact( metadata, version ); - + if ( !repositoryQueryLayer.containsArtifact( artifact ) ) { reporter.addFailure( metadata, "Artifact version " + version + " is present in metadata but " + - "missing in the repository." ); - if ( !hasFailures ) hasFailures = true; + "missing in the repository." ); + if ( !hasFailures ) + { + hasFailures = true; + } } } return hasFailures; } - + /** * Searches the artifact repository directory for all versions and verifies that all of them are listed in the * metadata file. */ - public boolean checkRepositoryVersions( RepositoryMetadata metadata, ArtifactRepository repository, - ArtifactReporter reporter ) + private boolean checkRepositoryVersions( RepositoryMetadata metadata, ArtifactRepository repository, + ArtifactReporter reporter ) + throws IOException { boolean hasFailures = false; Versioning versioning = metadata.getMetadata().getVersioning(); - String repositoryPath = repository.getBasedir(); - File versionsDir = new File( repositoryPath, formatAsDirectory( metadata.getGroupId() ) + - File.pathSeparator + metadata.getArtifactId() ); - File[] versions = versionsDir.listFiles( new RepositoryFileFilter() ); - for( int idx=0; idxJohn Tolentino - */ -public class DefaultArtifactReporter - implements ArtifactReporter -{ - private List success; - private List warnings; - private List failures; - - - public DefaultArtifactReporter() - { - success = new ArrayList(); - warnings = new ArrayList(); - failures = new ArrayList(); - } - - public void addFailure( Artifact artifact, String reason ) - { - } - - public void addSuccess( Artifact artifact ) - { - } - - public void addWarning( Artifact artifact, String message ) - { - } - - public void addWarning(org.apache.maven.artifact.repository.metadata.RepositoryMetadata metadata, String message) - { - } - - public void addFailure(org.apache.maven.artifact.repository.metadata.RepositoryMetadata metadata, String reason) - { - } - - public void addSuccess(org.apache.maven.artifact.repository.metadata.RepositoryMetadata metadata) - { - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java index b650ad62b..769845e8a 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java @@ -1,7 +1,5 @@ package org.apache.maven.repository.reporting; -import org.apache.maven.artifact.Artifact; - /* * Copyright 2001-2005 The Apache Software Foundation. * @@ -10,7 +8,6 @@ import org.apache.maven.artifact.Artifact; * 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, @@ -19,14 +16,27 @@ import org.apache.maven.artifact.Artifact; * limitations under the License. */ +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; + +import java.io.File; + /** * @author John Tolentino */ public class DefaultRepositoryQueryLayer implements RepositoryQueryLayer { + private final ArtifactRepository repository; + + public DefaultRepositoryQueryLayer( ArtifactRepository repository ) + { + this.repository = repository; + } + public boolean containsArtifact( Artifact artifact ) { - return true; + File f = new File( repository.getBasedir(), repository.pathOf( artifact ) ); + return f.exists(); } } diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java new file mode 100644 index 000000000..32e3b79e9 --- /dev/null +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java @@ -0,0 +1,34 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.repository.ArtifactRepository; + +/** + * Gets the default implementation of a repository query layer for the given repository. + * + * @author Brett Porter + * @version $Id$ + */ +public class DefaultRepositoryQueryLayerFactory + implements RepositoryQueryLayerFactory +{ + public RepositoryQueryLayer createRepositoryQueryLayer( ArtifactRepository repository ) + { + return new DefaultRepositoryQueryLayer( repository ); + } +} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java index 001128020..aecfdfd35 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java @@ -27,5 +27,6 @@ public interface MetadataReportProcessor { String ROLE = MetadataReportProcessor.class.getName(); - void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter ); + void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter ) + throws ReportProcessorException; } diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java new file mode 100644 index 000000000..5c1fa2a81 --- /dev/null +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java @@ -0,0 +1,32 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2001-2005 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. + */ + +/** + * Exception occurring during reporting. + * + * @author Brett Porter + * @version $Id$ + */ +public class ReportProcessorException + extends Exception +{ + public ReportProcessorException( String msg, Throwable cause ) + { + super( msg, cause ); + } +} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java new file mode 100644 index 000000000..0d10ea4f5 --- /dev/null +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java @@ -0,0 +1,54 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; + +/** + * A result of the report for a given artifact being processed. + * + * @author Brett Porter + * @version $Id$ + */ +public class RepositoryMetadataResult +{ + private final RepositoryMetadata metadata; + + private final String reason; + + public RepositoryMetadataResult( RepositoryMetadata metadata ) + { + this.metadata = metadata; + this.reason = null; + } + + public RepositoryMetadataResult( RepositoryMetadata metadata, String reason ) + { + this.metadata = metadata; + this.reason = reason; + } + + public RepositoryMetadata getMetadata() + { + return metadata; + } + + public String getReason() + { + return reason; + } +} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java new file mode 100644 index 000000000..e001c32fa --- /dev/null +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java @@ -0,0 +1,38 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.repository.ArtifactRepository; + +/** + * Gets the preferred implementation of a repository query layer for the given repository. + * + * @author Brett Porter + * @version $Id$ + */ +public interface RepositoryQueryLayerFactory +{ + String ROLE = RepositoryQueryLayerFactory.class.getName(); + + /** + * Create or obtain a query interface. + * + * @param repository the repository to query + * @return the obtained query layer + */ + RepositoryQueryLayer createRepositoryQueryLayer( ArtifactRepository repository ); +} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/Failure.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/Failure.java deleted file mode 100644 index 8f3505de7..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/Failure.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apache.maven.repository.reporting.reports; - -import org.apache.maven.artifact.Artifact; - -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @author John Tolentino - */ -public class Failure - extends ReportError -{ - public Failure( Artifact artifact, String reason ) - { - super( artifact, reason ); - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/ReportError.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/ReportError.java deleted file mode 100644 index 7d7a99320..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/ReportError.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.apache.maven.repository.reporting.reports; - -import org.apache.maven.artifact.Artifact; - -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @author John Tolentino - */ -public class ReportError - extends ReportResult -{ - String reason = ""; - - public ReportError( Artifact artifact, String reason ) - { - super( artifact ); - this.reason = reason; - } - - public String getReason() - { - return reason; - } - - public void setReason( String reason ) - { - this.reason = reason; - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/ReportResult.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/ReportResult.java deleted file mode 100644 index 773ac4165..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/ReportResult.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.apache.maven.repository.reporting.reports; - -import org.apache.maven.artifact.Artifact; - -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @author John Tolentino - */ -public class ReportResult -{ - private Artifact artifact; - - public ReportResult( Artifact artifact ) - { - this.artifact = artifact; - } - - public Artifact getArtifact() - { - return artifact; - } - - public void setArtifact( Artifact artifact ) - { - this.artifact = artifact; - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/Success.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/Success.java deleted file mode 100644 index 22927d914..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/Success.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.apache.maven.repository.reporting.reports; - -import org.apache.maven.repository.reporting.reports.ReportResult; -import org.apache.maven.artifact.Artifact; - -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @author John Tolentino - */ -public class Success - extends ReportResult -{ - public Success( Artifact artifact ) - { - super( artifact ); - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/Warning.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/Warning.java deleted file mode 100644 index 15a6391e6..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/reports/Warning.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.apache.maven.repository.reporting.reports; - -import org.apache.maven.repository.reporting.reports.ReportError; -import org.apache.maven.artifact.Artifact; - -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @author John Tolentino - */ -public class Warning - extends ReportError -{ - public Warning( Artifact artifact, String reason ) - { - super( artifact, reason ); - } -} diff --git a/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml b/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml index 823f1420b..408483760 100644 --- a/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml +++ b/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml @@ -1,24 +1,16 @@ - org.apache.maven.repository.reporting.ArtifactReporter - default - org.apache.maven.repository.reporting.DefaultArtifactReporter - per-lookup + org.apache.maven.repository.reporting.RepositoryQueryLayerFactory + org.apache.maven.repository.reporting.DefaultRepositoryQueryLayerFactory - org.apache.maven.repository.reporting.RepositoryQueryLayer - default - org.apache.maven.repository.reporting.DefaultRepositoryQueryLayer - per-lookup - - - org.apache.maven.repository.reporting.BadMetadataReporter - default - org.apache.maven.repository.reporting.BadMetadataReporter + org.apache.maven.repository.reporting.MetadataReportProcessor + bad-metadata + org.apache.maven.repository.reporting.BadMetadataReportProcessor - org.apache.maven.repository.reporting.RepositoryQueryLayer + org.apache.maven.repository.reporting.RepositoryQueryLayerFactory org.apache.maven.artifact.factory.ArtifactFactory diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java index 22560cc21..e9fad5b83 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java @@ -17,9 +17,12 @@ package org.apache.maven.repository.reporting; * limitations under the License. */ -import java.io.File; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.util.FileUtils; + +import java.io.File; /** * @author John Tolentino @@ -27,54 +30,22 @@ import org.codehaus.plexus.util.FileUtils; public abstract class AbstractRepositoryReportsTestCase extends PlexusTestCase { - private static String JAR = ".jar"; - - private static String basedir; - - private static String[] directoryStructure; - - public AbstractRepositoryReportsTestCase( String basedir, String[] directoryStructure ) - { - this.basedir = basedir; - this.directoryStructure = directoryStructure; - } + /** + * This should only be used for the few that can't use the query layer. + */ + protected ArtifactRepository repository; protected void setUp() throws Exception { super.setUp(); - buildTestRepoPath(); - } + File repositoryDirectory = getTestFile( "src/test/repository" ); - private void buildTestRepoPath() - { - for ( int i = 0; i < directoryStructure.length; i++ ) - { - File dir = new File( basedir + directoryStructure[i] ); - if ( !dir.exists() ) - { - dir.mkdirs(); - } - } - } + ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - private void deleteTestRepoPath() throws Exception - { - FileUtils.deleteDirectory( basedir ); + repository = + factory.createArtifactRepository( "test", repositoryDirectory.toURL().toString(), layout, null, null ); } - protected boolean writeTestArtifact( String relativePath, String artifactId ) - throws Exception - { - File artifact = new File( basedir + relativePath + artifactId + JAR ); - System.out.println( "" + basedir + relativePath + artifactId ); - return artifact.createNewFile(); - } - - protected void tearDown() - throws Exception - { - deleteTestRepoPath(); - super.tearDown(); - } } diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java index 0022e35b7..927c4aa19 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java @@ -8,7 +8,6 @@ package org.apache.maven.repository.reporting; * 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, @@ -17,44 +16,55 @@ package org.apache.maven.repository.reporting; * limitations under the License. */ -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.List; +import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; -import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Versioning; + +import java.util.Iterator; -public class BadMetadataReportProcessorTest extends PlexusTestCase +public class BadMetadataReportProcessorTest + extends AbstractRepositoryReportsTestCase { protected ArtifactFactory artifactFactory; - private BadMetadataReportProcessor badMetadataReportProcessor; - public BadMetadataReportProcessorTest(String testName) - { - super(testName); - } + private MetadataReportProcessor badMetadataReportProcessor; - protected void setUp() throws Exception + protected void setUp() + throws Exception { - artifactFactory = (ArtifactFactory) getContainer().lookup( ArtifactFactory.ROLE ); - - badMetadataReportProcessor = new TestBadMetadataReportProcessor( artifactFactory, - new DefaultRepositoryQueryLayer() ); - } - - protected RepositoryQueryLayer getRepositoryQueryLayer( List returnValues ) throws NoSuchMethodException - { - GenericMockObject mockObject = new GenericMockObject(); - Method method = RepositoryQueryLayer.class.getMethod( "containsArtifact", null ); - mockObject.setExpectedReturns( method, returnValues ); - RepositoryQueryLayer queryLayer = (RepositoryQueryLayer) Proxy.newProxyInstance( this.getClassLoader(), - new Class[] { RepositoryQueryLayer.class }, - new GenericMockObject() ); - return queryLayer; + super.setUp(); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + badMetadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE ); } - protected void tearDown() throws Exception + public void testMetadataMissingADirectory() + throws ReportProcessorException { - release( artifactFactory ); + ArtifactReporter reporter = new MockArtifactReporter(); + + Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); + + Versioning versioning = new Versioning(); + versioning.addVersion( "1.0-alpha-1" ); + versioning.setLastUpdated( "20050611.202020" ); + + RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check there is a failure", failures.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); + assertEquals( "check metadata", metadata, result.getMetadata() ); + // TODO: should be more robust + assertEquals( "check reason", + "Artifact version 1.0-alpha-2 found in the repository but missing in the metadata.", + result.getReason() ); + assertFalse( "check no more failures", failures.hasNext() ); } public void testProcessMetadata() @@ -76,5 +86,5 @@ public class BadMetadataReportProcessorTest extends PlexusTestCase public void testCheckRepositoryVersions() { } - + } diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java deleted file mode 100644 index 8efee560f..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2001-2005 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.codehaus.plexus.PlexusTestCase; - -import java.io.File; -import java.lang.System; - -/** - * Test the artifact reporter. - * - * @author John Tolentino - */ -public class DefaultArtifactReporterTest - extends AbstractRepositoryReportsTestCase -{ - private static final String[] testRepoStructure = { "valid-poms/", "invalid-poms/" }; - - private ArtifactReporter reporter; - - public DefaultArtifactReporterTest() - { - super( System.getProperty( "basedir" ) + "/src/test/repository/", testRepoStructure ); - } - - protected void setUp() - throws Exception - { - super.setUp(); - reporter = (ArtifactReporter) lookup( ArtifactReporter.ROLE, "default" ); - } - - public void testAddSuccess() throws Exception - { - assertTrue( writeTestArtifact( "valid-poms/", "test" ) ); - } - - protected void tearDown() - throws Exception - { - reporter = null; - super.tearDown(); - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerTest.java deleted file mode 100644 index bbba7ba19..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2001-2005 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.codehaus.plexus.PlexusTestCase; - -/** - * Test the artifact reporter. - * - * @author John Tolentino - */ -public class DefaultRepositoryQueryLayerTest - extends AbstractRepositoryReportsTestCase -{ - private static final String[] testRepoStructure = { "valid-poms/", "invalid-poms/" }; - - private RepositoryQueryLayer queryLayer; - - public DefaultRepositoryQueryLayerTest() - { - super( System.getProperty( "basedir" ) + "/src/test/repository/", testRepoStructure ); - } - - protected void setUp() - throws Exception - { - super.setUp(); - queryLayer = (RepositoryQueryLayer) lookup( RepositoryQueryLayer.ROLE, "default" ); - } - - public void testNonExistingArtifact() - { - assertTrue( queryLayer.containsArtifact( null ) ); - } - - protected void tearDown() - throws Exception - { - queryLayer = null; - super.tearDown(); - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java new file mode 100755 index 000000000..835f97c37 --- /dev/null +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java @@ -0,0 +1,106 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * Mock implementation of the artifact reporter. + * + * @author Brett Porter + * @version $Id$ + */ +public class MockArtifactReporter + implements ArtifactReporter +{ + private List artifactFailures = new ArrayList(); + + private List artifactSuccesses = new ArrayList(); + + private List artifactWarnings = new ArrayList(); + + private List metadataFailures = new ArrayList(); + + private List metadataSuccesses = new ArrayList(); + + private List metadataWarnings = new ArrayList(); + + public void addFailure( Artifact artifact, String reason ) + { + artifactFailures.add( new ArtifactResult( artifact, reason ) ); + } + + public void addSuccess( Artifact artifact ) + { + artifactSuccesses.add( new ArtifactResult( artifact ) ); + } + + public void addWarning( Artifact artifact, String reason ) + { + artifactWarnings.add( new ArtifactResult( artifact, reason ) ); + } + + public void addFailure( RepositoryMetadata metadata, String reason ) + { + metadataFailures.add( new RepositoryMetadataResult( metadata, reason ) ); + } + + public void addSuccess( RepositoryMetadata metadata ) + { + metadataSuccesses.add( new RepositoryMetadataResult( metadata ) ); + } + + public void addWarning( RepositoryMetadata metadata, String reason ) + { + metadataWarnings.add( new RepositoryMetadataResult( metadata, reason ) ); + } + + public Iterator getArtifactFailureIterator() + { + return artifactFailures.iterator(); + } + + public Iterator getArtifactSuccessIterator() + { + return artifactSuccesses.iterator(); + } + + public Iterator getArtifactWarningIterator() + { + return artifactWarnings.iterator(); + } + + public Iterator getRepositoryMetadataFailureIterator() + { + return metadataFailures.iterator(); + } + + public Iterator getRepositoryMetadataSuccessIterator() + { + return metadataSuccesses.iterator(); + } + + public Iterator getRepositoryMetadataWarningIterator() + { + return metadataWarnings.iterator(); + } +} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java index df3232182..fe712046f 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java @@ -18,9 +18,9 @@ package org.apache.maven.repository.reporting; import org.apache.maven.artifact.Artifact; -import java.util.List; -import java.util.Iterator; import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; /** * @author John Tolentino @@ -29,6 +29,7 @@ public class MockRepositoryQueryLayer implements RepositoryQueryLayer { private List queryConditions; + private Iterator iterator; public MockRepositoryQueryLayer() @@ -54,7 +55,7 @@ public class MockRepositoryQueryLayer public void addReturnValue( boolean queryCondition ) { - queryConditions.add( new Boolean( queryCondition ) ); + queryConditions.add( Boolean.valueOf( queryCondition ) ); } public void clearList() diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/TestBadMetadataReportProcessor.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/TestBadMetadataReportProcessor.java deleted file mode 100644 index 40898528d..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/TestBadMetadataReportProcessor.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.maven.artifact.factory.ArtifactFactory; - -public class TestBadMetadataReportProcessor extends BadMetadataReportProcessor -{ - public TestBadMetadataReportProcessor( ArtifactFactory factory, RepositoryQueryLayer layer ) - { - artifactFactory = factory ; - repositoryQueryLayer = layer ; - } -} diff --git a/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom b/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom new file mode 100644 index 000000000..e69de29bb diff --git a/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom b/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom new file mode 100644 index 000000000..e69de29bb