You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ep...@apache.org on 2005/12/02 04:23:49 UTC
svn commit: r351563 - in
/maven/repository-manager/trunk/maven-repository-reports-standard/src/main:
java/org/apache/maven/repository/reporting/BadMetadataReporter.java
resources/META-INF/plexus/components.xml
Author: epunzalan
Date: Thu Dec 1 19:23:43 2005
New Revision: 351563
URL: http://svn.apache.org/viewcvs?rev=351563&view=rev
Log:
PR: MRM-16
Added missing metadata checks...
Modified:
maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReporter.java
maven/repository-manager/trunk/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml
Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReporter.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReporter.java?rev=351563&r1=351562&r2=351563&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReporter.java (original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReporter.java Thu Dec 1 19:23:43 2005
@@ -1,34 +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
- *
+/*
+ * 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.
+
+ *
+ * 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.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.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
+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.apache.maven.wagon.ResourceDoesNotExistException;
-import org.apache.maven.wagon.TransferFailedException;
+
/**
* This class will report on bad metadata files. These include invalid version declarations and incomplete version
@@ -37,13 +37,14 @@
*/
public class BadMetadataReporter implements MetadataReportProcessor
{
- private WagonManager wagon;
+ // plexus components
private ArtifactFactory artifactFactory;
+ private RepositoryQueryLayer repositoryQueryLayer;
public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter )
{
boolean hasFailures = false;
-
+
String lastUpdated = metadata.getMetadata().getVersioning().getLastUpdated();
if ( lastUpdated == null || lastUpdated.length() == 0 )
{
@@ -57,62 +58,101 @@
}
else if ( metadata.storedInArtifactVersionDirectory() )
{
- //snapshot metadata
+ checkSnapshotMetadata( metadata, repository, reporter );
}
else
{
if ( !checkMetadataVersions( metadata, repository, reporter ) ) hasFailures = true;
-
+
if ( checkRepositoryVersions( metadata, repository, reporter ) ) hasFailures = true;
}
-
+
if ( !hasFailures ) reporter.addSuccess( metadata );
}
/**
* Checks the plugin metadata
*/
- public boolean checkPluginMetadata( RepositoryMetadata metadata, ArtifactRepository repository,
- ArtifactReporter reporter )
+ public boolean checkPluginMetadata( RepositoryMetadata metadata, ArtifactRepository repository,
+ ArtifactReporter reporter )
{
- boolean hasFailures = false;
-
-
-
- return hasFailures;
+ boolean hasFailures = false;
+
+ File metadataDir = new File ( repository.getBasedir() + File.pathSeparator + formatAsDirectory( metadata.getGroupId() ) );
+
+ HashMap prefixes = new HashMap();
+ 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 )
+ {
+ reporter.addFailure( metadata, "Missing or empty plugin prefix for artifactId " + artifactId );
+ hasFailures = true;
+ }
+ else
+ {
+ if ( prefixes.containsKey( prefix ) )
+ {
+ reporter.addFailure( metadata, "Duplicate plugin prefix found: " + prefix );
+ hasFailures = true;
+ }
+ else
+ {
+ prefixes.put( prefix, plugin );
+ }
+ }
+
+ File pluginDir = new File( metadataDir, artifactId );
+ if ( !pluginDir.exists() )
+ {
+ reporter.addFailure( metadata, "Metadata plugin " + artifactId + " is not present in the repository" );
+ hasFailures = true;
+ }
+ }
+
+ return hasFailures;
}
/**
* Checks the snapshot metadata
*/
- public boolean checkSnapshotMetadata( RepositoryMetadata metadata, ArtifactRepository repository,
- ArtifactReporter reporter )
+ public 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 ) );
- File snapshotFile = new File( artifactFile.getParentFile(), artifactName );
- if ( !snapshotFile.exists() )
- {
- reporter.addFailure( metadata, "Snapshot artifact " + artifactName + " does not exist." );
- hasFailures = true;
- }
-
- return hasFailures;
+ 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 ) );
+ File snapshotFile = new File( artifactFile.getParentFile(), artifactName );
+ if ( !snapshotFile.exists() )
+ {
+ 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 )
+ public boolean checkMetadataVersions( RepositoryMetadata metadata, ArtifactRepository repository,
+ ArtifactReporter reporter )
{
boolean hasFailures = false;
Versioning versioning = metadata.getMetadata().getVersioning();
@@ -121,25 +161,11 @@
String version = (String) versions.next();
Artifact artifact = createArtifact( metadata, version );
-
- try
- {
- wagon.getArtifact( artifact, repository );
- }
- catch ( TransferFailedException e )
- {
- reporter.addWarning( artifact, "An error occurred during the transfer of the artifact in " +
- "the repository." );
- }
- catch ( ResourceDoesNotExistException e )
- {
- //do nothing, will check later that this artifact has not been resolved
- }
-
- if ( !artifact.isResolved() )
+
+ if ( !repositoryQueryLayer.containsArtifact( artifact ) )
{
reporter.addFailure( metadata, "Artifact version " + version + " is present in metadata but " +
- "missing in the repository." );
+ "missing in the repository." );
if ( !hasFailures ) hasFailures = true;
}
}
@@ -147,17 +173,17 @@
}
/**
- * Searches the artifact repository directory for all versions and verifies that all of them are listed in the
+ * 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 )
+ public boolean checkRepositoryVersions( RepositoryMetadata metadata, ArtifactRepository repository,
+ ArtifactReporter reporter )
{
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 versionsDir = new File( repositoryPath, formatAsDirectory( metadata.getGroupId() ) +
+ File.pathSeparator + metadata.getArtifactId() );
File[] versions = versionsDir.listFiles( new RepositoryFileFilter() );
for( int idx=0; idx<versions.length; idx++ )
{
@@ -165,7 +191,7 @@
if ( !versioning.getVersions().contains( version ) )
{
reporter.addFailure( metadata, "Artifact version " + version + " found in the repository but " +
- "missing in the metadata." );
+ "missing in the metadata." );
if ( !hasFailures ) hasFailures = true;
}
}
@@ -180,15 +206,21 @@
return directory.replace( '.', File.pathSeparatorChar );
}
+ /**
+ * Used to create an artifact object from a metadata base version
+ */
private Artifact createArtifact( RepositoryMetadata metadata )
{
- return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(),
- metadata.getBaseVersion(), "pom" );
+ return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(),
+ metadata.getBaseVersion(), "pom" );
}
-
+
+ /**
+ * Used to create an artifact object with a specified version
+ */
private Artifact createArtifact( RepositoryMetadata metadata, String version )
{
- return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(),
- version, "pom" );
+ return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(),
+ version, "pom" );
}
}
Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml?rev=351563&r1=351562&r2=351563&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml Thu Dec 1 19:23:43 2005
@@ -18,7 +18,7 @@
<implementation>org.apache.maven.repository.reporting.BadMetadataReporter</implementation>
<requirements>
<requirement>
- <role>org.apache.maven.artifact.manager.WagonManager</role>
+ <role>org.apache.maven.repository.reporting.RepositoryQueryLayer</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>