mirror of https://github.com/apache/archiva.git
PR: MRM-16
Still incomplete. Requires unit tests, waiting for abstract unit test. git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@350205 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
54991f3c7e
commit
649f02cc6d
|
@ -0,0 +1,43 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ package org.apache.maven.repository.reporting;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface is used by the single artifact processor.
|
* This interface is used by the single artifact processor.
|
||||||
|
@ -34,4 +35,10 @@ public interface ArtifactReporter
|
||||||
void addSuccess( Artifact artifact );
|
void addSuccess( Artifact artifact );
|
||||||
|
|
||||||
void addWarning( Artifact artifact, String message );
|
void addWarning( Artifact artifact, String message );
|
||||||
|
|
||||||
|
void addFailure( RepositoryMetadata metadata, String reason );
|
||||||
|
|
||||||
|
void addSuccess( RepositoryMetadata metadata );
|
||||||
|
|
||||||
|
void addWarning( RepositoryMetadata metadata, String message );
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,194 @@
|
||||||
|
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 java.io.File;
|
||||||
|
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.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
|
||||||
|
* information inside the metadata file. Plugin metadata will be checked for validity of the latest plugin artifacts.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BadMetadataReporter implements MetadataReportProcessor
|
||||||
|
{
|
||||||
|
private WagonManager wagon;
|
||||||
|
private ArtifactFactory artifactFactory;
|
||||||
|
|
||||||
|
public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter )
|
||||||
|
{
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
else if ( metadata.storedInArtifactVersionDirectory() )
|
||||||
|
{
|
||||||
|
//snapshot metadata
|
||||||
|
}
|
||||||
|
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 )
|
||||||
|
{
|
||||||
|
boolean hasFailures = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return hasFailures;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the snapshot metadata
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the declared metadata versions if the artifacts are present in the repository
|
||||||
|
*/
|
||||||
|
public boolean checkMetadataVersions( RepositoryMetadata metadata, ArtifactRepository repository,
|
||||||
|
ArtifactReporter reporter )
|
||||||
|
{
|
||||||
|
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 );
|
||||||
|
|
||||||
|
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() )
|
||||||
|
{
|
||||||
|
reporter.addFailure( metadata, "Artifact version " + version + " is present in metadata but " +
|
||||||
|
"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 )
|
||||||
|
{
|
||||||
|
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; idx<versions.length; idx++ )
|
||||||
|
{
|
||||||
|
String version = versions[ idx ].getName();
|
||||||
|
if ( !versioning.getVersions().contains( version ) )
|
||||||
|
{
|
||||||
|
reporter.addFailure( metadata, "Artifact version " + version + " found in the repository but " +
|
||||||
|
"missing in the metadata." );
|
||||||
|
if ( !hasFailures ) hasFailures = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasFailures;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats an artifact groupId to the directory structure format used for storage in repositories
|
||||||
|
*/
|
||||||
|
private String formatAsDirectory( String directory )
|
||||||
|
{
|
||||||
|
return directory.replace( '.', File.pathSeparatorChar );
|
||||||
|
}
|
||||||
|
|
||||||
|
private Artifact createArtifact( RepositoryMetadata metadata )
|
||||||
|
{
|
||||||
|
return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(),
|
||||||
|
metadata.getBaseVersion(), "pom" );
|
||||||
|
}
|
||||||
|
|
||||||
|
private Artifact createArtifact( RepositoryMetadata metadata, String version )
|
||||||
|
{
|
||||||
|
return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(),
|
||||||
|
version, "pom" );
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,5 @@
|
||||||
package org.apache.maven.repository.reporting;
|
package org.apache.maven.repository.reporting;
|
||||||
|
|
||||||
import org.apache.maven.repository.discovery.AbstractArtifactDiscoverer;
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2005 The Apache Software Foundation.
|
* Copyright 2001-2005 The Apache Software Foundation.
|
||||||
*
|
*
|
||||||
|
@ -21,6 +16,7 @@ import java.util.List;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
|
* @author <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
|
||||||
|
@ -40,4 +36,16 @@ public class DefaultArtifactReporter
|
||||||
public void addWarning( Artifact artifact, String message )
|
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)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,5 +12,18 @@
|
||||||
<implementation>org.apache.maven.repository.reporting.DefaultRepositoryQueryLayer</implementation>
|
<implementation>org.apache.maven.repository.reporting.DefaultRepositoryQueryLayer</implementation>
|
||||||
<instantiation-strategy>per-lookup</instantiation-strategy>
|
<instantiation-strategy>per-lookup</instantiation-strategy>
|
||||||
</component>
|
</component>
|
||||||
|
<component>
|
||||||
|
<role>org.apache.maven.repository.reporting.BadMetadataReporter</role>
|
||||||
|
<role-hint>default</role-hint>
|
||||||
|
<implementation>org.apache.maven.repository.reporting.BadMetadataReporter</implementation>
|
||||||
|
<requirements>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.artifact.manager.WagonManager</role>
|
||||||
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||||
|
</requirement>
|
||||||
|
</requirements>
|
||||||
|
</component>
|
||||||
</components>
|
</components>
|
||||||
</component-set>
|
</component-set>
|
||||||
|
|
Loading…
Reference in New Issue