+++ /dev/null
-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;
- }
-}
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.
+ * <p/>
+ * 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
{
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();
+
}
--- /dev/null
+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 <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @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;
+ }
+}
* 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,
* 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;
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 );
}
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 )
{
prefixes.put( prefix, plugin );
}
}
-
+
File pluginDir = new File( metadataDir, artifactId );
if ( !pluginDir.exists() )
{
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 ) );
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; idx<versions.length; idx++ )
+ // TODO: change this to look for repository artifacts. It needs to centre around that I think, currently this is hardwired to the default layout
+ File versionsDir =
+ new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( metadata ) ).getParentFile();
+ List versions = FileUtils.getFileNames( versionsDir, "*/*.pom", null, false );
+ for ( Iterator i = versions.iterator(); i.hasNext(); )
{
- String version = versions[ idx ].getName();
+ File path = new File( (String) i.next() );
+ String version = path.getParentFile().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;
+ "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 );
- }
-
+
/**
* 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" );
+ 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" );
}
}
+++ /dev/null
-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 java.util.List;
-import java.util.ArrayList;
-
-/**
- * @author <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
- */
-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)
- {
- }
-}
package org.apache.maven.repository.reporting;
-import org.apache.maven.artifact.Artifact;
-
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* 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,
* limitations under the License.
*/
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+
+import java.io.File;
+
/**
* @author <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
*/
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();
}
}
--- /dev/null
+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 <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @version $Id$
+ */
+public class DefaultRepositoryQueryLayerFactory
+ implements RepositoryQueryLayerFactory
+{
+ public RepositoryQueryLayer createRepositoryQueryLayer( ArtifactRepository repository )
+ {
+ return new DefaultRepositoryQueryLayer( repository );
+ }
+}
{
String ROLE = MetadataReportProcessor.class.getName();
- void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter );
+ void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter )
+ throws ReportProcessorException;
}
--- /dev/null
+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 <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @version $Id$
+ */
+public class ReportProcessorException
+ extends Exception
+{
+ public ReportProcessorException( String msg, Throwable cause )
+ {
+ super( msg, cause );
+ }
+}
--- /dev/null
+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 <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @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;
+ }
+}
--- /dev/null
+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 <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @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 );
+}
+++ /dev/null
-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 <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
- */
-public class Failure
- extends ReportError
-{
- public Failure( Artifact artifact, String reason )
- {
- super( artifact, reason );
- }
-}
+++ /dev/null
-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 <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
- */
-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;
- }
-}
+++ /dev/null
-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 <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
- */
-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;
- }
-}
+++ /dev/null
-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 <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
- */
-public class Success
- extends ReportResult
-{
- public Success( Artifact artifact )
- {
- super( artifact );
- }
-}
+++ /dev/null
-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 <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
- */
-public class Warning
- extends ReportError
-{
- public Warning( Artifact artifact, String reason )
- {
- super( artifact, reason );
- }
-}
<component-set>
<components>
<component>
- <role>org.apache.maven.repository.reporting.ArtifactReporter</role>
- <role-hint>default</role-hint>
- <implementation>org.apache.maven.repository.reporting.DefaultArtifactReporter</implementation>
- <instantiation-strategy>per-lookup</instantiation-strategy>
+ <role>org.apache.maven.repository.reporting.RepositoryQueryLayerFactory</role>
+ <implementation>org.apache.maven.repository.reporting.DefaultRepositoryQueryLayerFactory</implementation>
</component>
<component>
- <role>org.apache.maven.repository.reporting.RepositoryQueryLayer</role>
- <role-hint>default</role-hint>
- <implementation>org.apache.maven.repository.reporting.DefaultRepositoryQueryLayer</implementation>
- <instantiation-strategy>per-lookup</instantiation-strategy>
- </component>
- <component>
- <role>org.apache.maven.repository.reporting.BadMetadataReporter</role>
- <role-hint>default</role-hint>
- <implementation>org.apache.maven.repository.reporting.BadMetadataReporter</implementation>
+ <role>org.apache.maven.repository.reporting.MetadataReportProcessor</role>
+ <role-hint>bad-metadata</role-hint>
+ <implementation>org.apache.maven.repository.reporting.BadMetadataReportProcessor</implementation>
<requirements>
<requirement>
- <role>org.apache.maven.repository.reporting.RepositoryQueryLayer</role>
+ <role>org.apache.maven.repository.reporting.RepositoryQueryLayerFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
* 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 <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
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();
- }
}
* 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,
* 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()
public void testCheckRepositoryVersions()
{
}
-
+
}
+++ /dev/null
-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 <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
- */
-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();
- }
-}
+++ /dev/null
-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 <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
- */
-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();
- }
-}
--- /dev/null
+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 <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @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();
+ }
+}
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 <a href="mailto:jtolentino@mergere.com">John Tolentino</a>
implements RepositoryQueryLayer
{
private List queryConditions;
+
private Iterator iterator;
public MockRepositoryQueryLayer()
public void addReturnValue( boolean queryCondition )
{
- queryConditions.add( new Boolean( queryCondition ) );
+ queryConditions.add( Boolean.valueOf( queryCondition ) );
}
public void clearList()
+++ /dev/null
-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 ;
- }
-}