summaryrefslogtreecommitdiffstats
path: root/archiva-converter
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-02-23 19:05:21 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-02-23 19:05:21 +0000
commitdee0d5a300ee0ba0240efc1277428b52cdcec9e0 (patch)
tree0f4c8d3b8b8b0468deac3c8851380a68bfa1744e /archiva-converter
parent2b50a18d22ef8972d241f54c20a131e05a584ac4 (diff)
downloadarchiva-dee0d5a300ee0ba0240efc1277428b52cdcec9e0.tar.gz
archiva-dee0d5a300ee0ba0240efc1277428b52cdcec9e0.zip
Merge from archiva-MRM-239 branch to trunk. r506385:HEAD
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@511053 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-converter')
-rw-r--r--archiva-converter/pom.xml15
-rw-r--r--archiva-converter/src/main/java/org/apache/maven/archiva/converter/ConversionEvent.java128
-rw-r--r--archiva-converter/src/main/java/org/apache/maven/archiva/converter/ConversionListener.java31
-rw-r--r--archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java168
-rw-r--r--archiva-converter/src/main/java/org/apache/maven/archiva/converter/RepositoryConverter.java21
-rw-r--r--archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java124
-rw-r--r--archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java105
-rw-r--r--archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyRepositoryConverter.java64
-rw-r--r--archiva-converter/src/test/java/org/apache/maven/archiva/converter/AllTests.java44
-rw-r--r--archiva-converter/src/test/java/org/apache/maven/archiva/converter/MockConversionListener.java163
-rw-r--r--archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java438
-rw-r--r--archiva-converter/src/test/java/org/apache/maven/archiva/converter/transaction/AllTests.java44
-rw-r--r--archiva-converter/src/test/resources/log4j.properties10
-rw-r--r--archiva-converter/src/test/resources/org/apache/maven/archiva/converter/RepositoryConverterTest.xml67
14 files changed, 1166 insertions, 256 deletions
diff --git a/archiva-converter/pom.xml b/archiva-converter/pom.xml
index d123cdcf9..49bde7bd2 100644
--- a/archiva-converter/pom.xml
+++ b/archiva-converter/pom.xml
@@ -30,6 +30,10 @@
<name>Archiva Repository Converter</name>
<dependencies>
<dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-discoverer</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
@@ -46,8 +50,8 @@
<artifactId>maven-model-converter</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.maven.archiva</groupId>
- <artifactId>archiva-reports-standard</artifactId>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-digest</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
@@ -58,6 +62,13 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
+ <!-- TEST DEPS -->
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.7.3.3</version>
+ <scope>test</scope>
+ </dependency>
<!-- Needed for PlexusTestCase -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/ConversionEvent.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/ConversionEvent.java
new file mode 100644
index 000000000..bd5ef5854
--- /dev/null
+++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/ConversionEvent.java
@@ -0,0 +1,128 @@
+package org.apache.maven.archiva.converter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.converter.legacy.LegacyRepositoryConverter;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+
+/**
+ * ConversionEvent
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ConversionEvent
+{
+ public static final int STARTED = 0;
+
+ public static final int PROCESSED = 1;
+
+ public static final int WARNING = 2;
+
+ public static final int ERROR = 3;
+
+ public static final int FINISHED = 4;
+
+ private int type;
+
+ private String message;
+
+ private Artifact artifact;
+
+ private ArtifactRepository repository;
+
+ private Exception exception;
+
+ public ConversionEvent( ArtifactRepository repository, int type )
+ {
+ this.repository = repository;
+ this.type = type;
+ }
+
+ public ConversionEvent( ArtifactRepository repository, int type, Artifact artifact )
+ {
+ this( repository, type );
+ this.artifact = artifact;
+ }
+
+ public ConversionEvent( ArtifactRepository repository, int type, Artifact artifact, String message )
+ {
+ this( repository, type );
+ this.artifact = artifact;
+ this.message = message;
+ }
+
+ public ConversionEvent( ArtifactRepository repository, int type, Artifact artifact, Exception exception )
+ {
+ this( repository, type );
+ this.artifact = artifact;
+ this.exception = exception;
+ }
+
+ public Artifact getArtifact()
+ {
+ return artifact;
+ }
+
+ public Exception getException()
+ {
+ return exception;
+ }
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ public ArtifactRepository getRepository()
+ {
+ return repository;
+ }
+
+ /**
+ * <p>
+ * The type of event.
+ * </p>
+ *
+ * <p>
+ * Can be one of the following ...
+ * </p>
+ *
+ * <ul>
+ * <li>{@link #STARTED} - the whole repository conversion process has started.
+ * only seen when using the whole repository conversion technique with the
+ * {@link LegacyRepositoryConverter#convertLegacyRepository(java.io.File, java.io.File, java.util.List, boolean)}
+ * method.</li>
+ * <li>{@link #PROCESSED} - a specific artifact has been processed.</li>
+ * <li>{@link #WARNING} - a warning has been detected for a specific artifact during the conversion process.</li>
+ * <li>{@link #ERROR} - an error in the processing of an artifact has been detected.</li>
+ * <li>{@link #FINISHED} - the whole repository conversion process has finished.
+ * only seen when using the whole repository conversion technique with the
+ * {@link LegacyRepositoryConverter#convertLegacyRepository(java.io.File, java.io.File, java.util.List, boolean)}
+ * method.</li>
+ * </ul>
+ * @return
+ */
+ public int getType()
+ {
+ return type;
+ }
+}
diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/ConversionListener.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/ConversionListener.java
new file mode 100644
index 000000000..3193bd475
--- /dev/null
+++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/ConversionListener.java
@@ -0,0 +1,31 @@
+package org.apache.maven.archiva.converter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * ConversionListener
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface ConversionListener
+{
+ public void conversionEvent( ConversionEvent event );
+}
diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java
index c723a11ab..5b03d6f48 100644
--- a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java
+++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java
@@ -22,7 +22,6 @@ package org.apache.maven.archiva.converter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.archiva.converter.transaction.FileTransaction;
-import org.apache.maven.archiva.reporting.database.ReportingDatabase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
@@ -38,7 +37,6 @@ import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Relocation;
-import org.apache.maven.model.converter.ArtifactPomRewriter;
import org.apache.maven.model.converter.ModelConverter;
import org.apache.maven.model.converter.PomTranslationException;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
@@ -46,6 +44,7 @@ import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.digest.Digester;
import org.codehaus.plexus.digest.DigesterException;
import org.codehaus.plexus.i18n.I18N;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
@@ -54,6 +53,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -67,6 +67,7 @@ import java.util.regex.Matcher;
* @plexus.component role="org.apache.maven.archiva.converter.RepositoryConverter" role-hint="default"
*/
public class DefaultRepositoryConverter
+ extends AbstractLogEnabled
implements RepositoryConverter
{
/**
@@ -84,11 +85,6 @@ public class DefaultRepositoryConverter
/**
* @plexus.requirement
*/
- private ArtifactPomRewriter rewriter;
-
- /**
- * @plexus.requirement
- */
private ModelConverter translator;
/**
@@ -111,7 +107,9 @@ public class DefaultRepositoryConverter
*/
private I18N i18n;
- public void convert( Artifact artifact, ArtifactRepository targetRepository, ReportingDatabase reporter )
+ private List listeners = new ArrayList();
+
+ public void convert( Artifact artifact, ArtifactRepository targetRepository )
throws RepositoryConversionException
{
if ( artifact.getRepository().getUrl().equals( targetRepository.getUrl() ) )
@@ -119,20 +117,19 @@ public class DefaultRepositoryConverter
throw new RepositoryConversionException( getI18NString( "exception.repositories.match" ) );
}
- if ( validateMetadata( artifact, reporter ) )
+ if ( validateMetadata( artifact ) )
{
FileTransaction transaction = new FileTransaction();
- if ( copyPom( artifact, targetRepository, reporter, transaction ) )
+ if ( copyPom( artifact, targetRepository, transaction ) )
{
- if ( copyArtifact( artifact, targetRepository, reporter, transaction ) )
+ if ( copyArtifact( artifact, targetRepository, transaction ) )
{
Metadata metadata = createBaseMetadata( artifact );
Versioning versioning = new Versioning();
versioning.addVersion( artifact.getBaseVersion() );
metadata.setVersioning( versioning );
- updateMetadata( new ArtifactRepositoryMetadata( artifact ), targetRepository, metadata,
- transaction );
+ updateMetadata( new ArtifactRepositoryMetadata( artifact ), targetRepository, metadata, transaction );
metadata = createBaseMetadata( artifact );
metadata.setVersion( artifact.getBaseVersion() );
@@ -173,8 +170,8 @@ public class DefaultRepositoryConverter
Metadata newMetadata, FileTransaction transaction )
throws RepositoryConversionException
{
- File file = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File file = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
Metadata metadata;
boolean changed;
@@ -244,7 +241,7 @@ public class DefaultRepositoryConverter
return metadata;
}
- private boolean validateMetadata( Artifact artifact, ReportingDatabase reporter )
+ private boolean validateMetadata( Artifact artifact )
throws RepositoryConversionException
{
ArtifactRepository repository = artifact.getRepository();
@@ -252,12 +249,11 @@ public class DefaultRepositoryConverter
boolean result = true;
RepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
- File file =
- new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
+ File file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
if ( file.exists() )
{
Metadata metadata = readMetadata( file );
- result = validateMetadata( metadata, repositoryMetadata, artifact, reporter );
+ result = validateMetadata( metadata, repositoryMetadata, artifact );
}
repositoryMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
@@ -265,14 +261,13 @@ public class DefaultRepositoryConverter
if ( file.exists() )
{
Metadata metadata = readMetadata( file );
- result = result && validateMetadata( metadata, repositoryMetadata, artifact, reporter );
+ result = result && validateMetadata( metadata, repositoryMetadata, artifact );
}
return result;
}
- private boolean validateMetadata( Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact,
- ReportingDatabase reporter )
+ private boolean validateMetadata( Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact )
{
String groupIdKey;
String artifactIdKey = null;
@@ -302,14 +297,14 @@ public class DefaultRepositoryConverter
if ( metadata.getGroupId() == null || !metadata.getGroupId().equals( artifact.getGroupId() ) )
{
- addFailure( reporter, artifact, groupIdKey );
+ addFailure( artifact, groupIdKey );
result = false;
}
if ( !repositoryMetadata.storedInGroupDirectory() )
{
if ( metadata.getGroupId() == null || !metadata.getArtifactId().equals( artifact.getArtifactId() ) )
{
- addFailure( reporter, artifact, artifactIdKey );
+ addFailure( artifact, artifactIdKey );
result = false;
}
if ( !repositoryMetadata.storedInArtifactVersionDirectory() )
@@ -319,8 +314,7 @@ public class DefaultRepositoryConverter
boolean foundVersion = false;
if ( metadata.getVersioning() != null )
{
- for ( Iterator i = metadata.getVersioning().getVersions().iterator();
- i.hasNext() && !foundVersion; )
+ for ( Iterator i = metadata.getVersioning().getVersions().iterator(); i.hasNext() && !foundVersion; )
{
String version = (String) i.next();
if ( version.equals( artifact.getBaseVersion() ) )
@@ -332,7 +326,7 @@ public class DefaultRepositoryConverter
if ( !foundVersion )
{
- addFailure( reporter, artifact, versionsKey );
+ addFailure( artifact, versionsKey );
result = false;
}
}
@@ -341,7 +335,7 @@ public class DefaultRepositoryConverter
// snapshot metadata
if ( !artifact.getBaseVersion().equals( metadata.getVersion() ) )
{
- addFailure( reporter, artifact, versionKey );
+ addFailure( artifact, versionKey );
result = false;
}
@@ -364,7 +358,7 @@ public class DefaultRepositoryConverter
if ( !correct )
{
- addFailure( reporter, artifact, snapshotKey );
+ addFailure( artifact, snapshotKey );
result = false;
}
}
@@ -374,30 +368,30 @@ public class DefaultRepositoryConverter
return result;
}
- private void addFailure( ReportingDatabase reporter, Artifact artifact, String key )
+ private void addFailure( Artifact artifact, String key )
{
- addFailureWithReason( reporter, artifact, getI18NString( key ) );
-
+ addFailureWithReason( artifact, getI18NString( key ) );
}
- private static void addWarning( ReportingDatabase reporter, Artifact artifact, String message )
+ private void addWarning( Artifact artifact, String message )
{
// TODO: should we be able to identify/fix these?
- reporter.addWarning( artifact, null, null, message );
+ // TODO: write archiva-artifact-repair module
+ triggerConversionEvent( new ConversionEvent( artifact.getRepository(), ConversionEvent.WARNING, artifact,
+ message ) );
}
- private static void addFailureWithReason( ReportingDatabase reporter, Artifact artifact, String reason )
+ private void addFailureWithReason( Artifact artifact, String reason )
{
// TODO: should we be able to identify/fix these?
- reporter.addFailure( artifact, null, null, reason );
+ triggerConversionEvent( new ConversionEvent( artifact.getRepository(), ConversionEvent.ERROR, artifact, reason ) );
}
- private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, ReportingDatabase reporter,
- FileTransaction transaction )
+ private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction )
throws RepositoryConversionException
{
- Artifact pom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
- artifact.getVersion() );
+ Artifact pom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact
+ .getVersion() );
pom.setBaseVersion( artifact.getBaseVersion() );
ArtifactRepository repository = artifact.getRepository();
File file = new File( repository.getBasedir(), repository.pathOf( pom ) );
@@ -411,7 +405,7 @@ public class DefaultRepositoryConverter
boolean checksumsValid = false;
try
{
- if ( testChecksums( artifact, file, reporter ) )
+ if ( testChecksums( artifact, file ) )
{
checksumsValid = true;
}
@@ -457,16 +451,15 @@ public class DefaultRepositoryConverter
if ( doRelocation( artifact, v3Model, targetRepository, transaction ) )
{
- Artifact relocatedPom = artifactFactory.createProjectArtifact( artifact.getGroupId(),
- artifact.getArtifactId(),
- artifact.getVersion() );
+ Artifact relocatedPom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact
+ .getArtifactId(), artifact.getVersion() );
targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( relocatedPom ) );
}
Model v4Model = translator.translate( v3Model );
- translator.validateV4Basics( v4Model, v3Model.getGroupId(), v3Model.getArtifactId(),
- v3Model.getVersion(), v3Model.getPackage() );
+ translator.validateV4Basics( v4Model, v3Model.getGroupId(), v3Model.getArtifactId(), v3Model
+ .getVersion(), v3Model.getPackage() );
writer = new StringWriter();
MavenXpp3Writer Xpp3Writer = new MavenXpp3Writer();
@@ -479,13 +472,12 @@ public class DefaultRepositoryConverter
for ( Iterator i = warnings.iterator(); i.hasNext(); )
{
String message = (String) i.next();
- addWarning( reporter, artifact, message );
+ addWarning( artifact, message );
}
}
catch ( XmlPullParserException e )
{
- addFailureWithReason( reporter, artifact,
- getI18NString( "failure.invalid.source.pom", e.getMessage() ) );
+ addFailureWithReason( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) );
result = false;
}
catch ( IOException e )
@@ -494,8 +486,7 @@ public class DefaultRepositoryConverter
}
catch ( PomTranslationException e )
{
- addFailureWithReason( reporter, artifact,
- getI18NString( "failure.invalid.source.pom", e.getMessage() ) );
+ addFailureWithReason( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) );
result = false;
}
finally
@@ -506,7 +497,7 @@ public class DefaultRepositoryConverter
}
else
{
- addWarning( reporter, artifact, getI18NString( "warning.missing.pom" ) );
+ addWarning( artifact, getI18NString( "warning.missing.pom" ) );
}
return result;
}
@@ -516,8 +507,8 @@ public class DefaultRepositoryConverter
throws IOException
{
Properties properties = v3Model.getProperties();
- if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" ) ||
- properties.containsKey( "relocated.version" ) )
+ if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" )
+ || properties.containsKey( "relocated.version" ) )
{
String newGroupId = properties.getProperty( "relocated.groupId", v3Model.getGroupId() );
properties.remove( "relocated.groupId" );
@@ -600,7 +591,7 @@ public class DefaultRepositoryConverter
return i18n.getString( getClass().getName(), Locale.getDefault(), key );
}
- private boolean testChecksums( Artifact artifact, File file, ReportingDatabase reporter )
+ private boolean testChecksums( Artifact artifact, File file )
throws IOException
{
boolean result = true;
@@ -609,7 +600,7 @@ public class DefaultRepositoryConverter
{
Digester digester = (Digester) it.next();
result &= verifyChecksum( file, file.getName() + "." + getDigesterFileExtension( digester ), digester,
- reporter, artifact, "failure.incorrect." + getDigesterFileExtension( digester ) );
+ artifact, "failure.incorrect." + getDigesterFileExtension( digester ) );
}
return result;
}
@@ -623,8 +614,7 @@ public class DefaultRepositoryConverter
return digester.getAlgorithm().toLowerCase().replaceAll( "-", "" );
}
- private boolean verifyChecksum( File file, String fileName, Digester digester, ReportingDatabase reporter,
- Artifact artifact, String key )
+ private boolean verifyChecksum( File file, String fileName, Digester digester, Artifact artifact, String key )
throws IOException
{
boolean result = true;
@@ -639,15 +629,14 @@ public class DefaultRepositoryConverter
}
catch ( DigesterException e )
{
- addFailure( reporter, artifact, key );
+ addFailure( artifact, key );
result = false;
}
}
return result;
}
- private boolean copyArtifact( Artifact artifact, ArtifactRepository targetRepository, ReportingDatabase reporter,
- FileTransaction transaction )
+ private boolean copyArtifact( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction )
throws RepositoryConversionException
{
File sourceFile = artifact.getFile();
@@ -668,7 +657,7 @@ public class DefaultRepositoryConverter
matching = FileUtils.contentEquals( sourceFile, targetFile );
if ( !matching )
{
- addFailure( reporter, artifact, "failure.target.already.exists" );
+ addFailure( artifact, "failure.target.already.exists" );
result = false;
}
}
@@ -676,7 +665,7 @@ public class DefaultRepositoryConverter
{
if ( force || !matching )
{
- if ( testChecksums( artifact, sourceFile, reporter ) )
+ if ( testChecksums( artifact, sourceFile ) )
{
transaction.copyFile( sourceFile, targetFile, digesters );
}
@@ -694,7 +683,7 @@ public class DefaultRepositoryConverter
return result;
}
- public void convert( List artifacts, ArtifactRepository targetRepository, ReportingDatabase reporter )
+ public void convert( List artifacts, ArtifactRepository targetRepository )
throws RepositoryConversionException
{
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
@@ -703,20 +692,49 @@ public class DefaultRepositoryConverter
try
{
- convert( artifact, targetRepository, reporter );
+ convert( artifact, targetRepository );
}
catch ( RepositoryConversionException e )
{
- // Need to add:
- // artifact
- // processor
- // problem
- // reason
- //TODO: this doesn't really provide any real facility for a decent error message, having
- // the stack trace would be useful. I also have no idea what a processor is currently or
- // how to get hold of it here.
-
- reporter.addFailure( artifact, "", e.getLocalizedMessage(), e.getCause().getLocalizedMessage() );
+ triggerConversionEvent( new ConversionEvent( targetRepository, ConversionEvent.ERROR, artifact, e ) );
+ }
+ }
+ }
+
+ /**
+ * Add a listener to the conversion process.
+ *
+ * @param listener the listener to add.
+ */
+ public void addConversionListener( ConversionListener listener )
+ {
+ listeners.add( listener );
+ }
+
+ /**
+ * Remove a listener from the conversion process.
+ *
+ * @param listener the listener to remove.
+ */
+ public void removeConversionListener( ConversionListener listener )
+ {
+ listeners.remove( listener );
+ }
+
+ private void triggerConversionEvent( ConversionEvent event )
+ {
+ Iterator it = listeners.iterator();
+ while ( it.hasNext() )
+ {
+ ConversionListener listener = (ConversionListener) it.next();
+
+ try
+ {
+ listener.conversionEvent( event );
+ }
+ catch ( Throwable t )
+ {
+ getLogger().warn( "ConversionEvent resulted in exception from listener: " + t.getMessage(), t );
}
}
}
diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/RepositoryConverter.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/RepositoryConverter.java
index d47d5b1f9..37c21fcce 100644
--- a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/RepositoryConverter.java
+++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/RepositoryConverter.java
@@ -19,7 +19,6 @@ package org.apache.maven.archiva.converter;
* under the License.
*/
-import org.apache.maven.archiva.reporting.database.ReportingDatabase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -39,9 +38,8 @@ public interface RepositoryConverter
*
* @param artifact the artifact to convert
* @param targetRepository the target repository
- * @param reporter reporter to track the results of the conversion
*/
- void convert( Artifact artifact, ArtifactRepository targetRepository, ReportingDatabase reporter )
+ void convert( Artifact artifact, ArtifactRepository targetRepository )
throws RepositoryConversionException;
/**
@@ -49,8 +47,21 @@ public interface RepositoryConverter
*
* @param artifacts the set of artifacts to convert
* @param targetRepository the target repository
- * @param reporter reporter to track the results of the conversions
*/
- void convert( List artifacts, ArtifactRepository targetRepository, ReportingDatabase reporter )
+ void convert( List artifacts, ArtifactRepository targetRepository )
throws RepositoryConversionException;
+
+ /**
+ * Add a listener to the conversion process.
+ *
+ * @param listener the listener to add.
+ */
+ void addConversionListener( ConversionListener listener );
+
+ /**
+ * Remove a listener from the conversion process.
+ *
+ * @param listener the listener to remove.
+ */
+ void removeConversionListener( ConversionListener listener );
}
diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java
new file mode 100644
index 000000000..469cc33e3
--- /dev/null
+++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java
@@ -0,0 +1,124 @@
+package org.apache.maven.archiva.converter.legacy;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.converter.ConversionListener;
+import org.apache.maven.archiva.converter.RepositoryConversionException;
+import org.apache.maven.archiva.discoverer.Discoverer;
+import org.apache.maven.archiva.discoverer.DiscovererException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Jason van Zyl
+ * @plexus.component
+ * @todo turn this into a general conversion component and hide all this crap here.
+ * @todo it should be possible to move this to the converter module without causing it to gain additional dependencies
+ */
+public class DefaultLegacyRepositoryConverter
+ implements LegacyRepositoryConverter
+{
+ /**
+ * @plexus.requirement role-hint="legacy"
+ */
+ private ArtifactRepositoryLayout legacyLayout;
+
+ /**
+ * @plexus.requirement role-hint="default"
+ */
+ private ArtifactRepositoryLayout defaultLayout;
+
+ /**
+ * @plexus.requirement
+ */
+ private ArtifactRepositoryFactory artifactRepositoryFactory;
+
+ /**
+ * @plexus.requirement role-hint="default"
+ */
+ private Discoverer discoverer;
+
+ /**
+ * @plexus.requirement role="org.apache.maven.archiva.common.consumers.Consumer" role-hint="legacy-converter"
+ */
+ private LegacyConverterArtifactConsumer legacyConverterConsumer;
+
+ public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory,
+ List fileExclusionPatterns, boolean includeSnapshots )
+ throws RepositoryConversionException
+ {
+ ArtifactRepository legacyRepository;
+
+ ArtifactRepository repository;
+
+ try
+ {
+ legacyRepository = artifactRepositoryFactory.createArtifactRepository( "legacy", legacyRepositoryDirectory
+ .toURI().toURL().toString(), legacyLayout, null, null );
+
+ repository = artifactRepositoryFactory.createArtifactRepository( "default", repositoryDirectory.toURI()
+ .toURL().toString(), defaultLayout, null, null );
+ }
+ catch ( MalformedURLException e )
+ {
+ throw new RepositoryConversionException( "Error convering legacy repository.", e );
+ }
+
+ try
+ {
+ List consumers = new ArrayList();
+ legacyConverterConsumer.setDestinationRepository( repository );
+ consumers.add( legacyConverterConsumer );
+
+ discoverer.walkRepository( legacyRepository, consumers, includeSnapshots );
+ }
+ catch ( DiscovererException e )
+ {
+ throw new RepositoryConversionException( "Unable to convert repository due to discoverer error:"
+ + e.getMessage(), e );
+ }
+ }
+
+ /**
+ * Add a listener to the conversion process.
+ *
+ * @param listener the listener to add.
+ */
+ public void addConversionListener( ConversionListener listener )
+ {
+ legacyConverterConsumer.addConversionListener( listener );
+ }
+
+ /**
+ * Remove a listener from the conversion process.
+ *
+ * @param listener the listener to remove.
+ */
+ public void removeConversionListener( ConversionListener listener )
+ {
+ legacyConverterConsumer.removeConversionListener( listener );
+ }
+}
diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java
new file mode 100644
index 000000000..a5b758c4b
--- /dev/null
+++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java
@@ -0,0 +1,105 @@
+package org.apache.maven.archiva.converter.legacy;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.common.consumers.GenericArtifactConsumer;
+import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.maven.archiva.converter.ConversionListener;
+import org.apache.maven.archiva.converter.RepositoryConversionException;
+import org.apache.maven.archiva.converter.RepositoryConverter;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+
+/**
+ * LegacyConverterArtifactConsumer - convert artifacts as they are found
+ * into the destination repository.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.common.consumers.Consumers"
+ * role-hint="legacy-converter"
+ * instantiation-strategy="per-lookup"
+ */
+public class LegacyConverterArtifactConsumer
+ extends GenericArtifactConsumer
+{
+ /**
+ * @plexus.requirement
+ */
+ private RepositoryConverter repositoryConverter;
+
+ private ArtifactRepository destinationRepository;
+
+ public void processArtifact( Artifact artifact, BaseFile file )
+ {
+ try
+ {
+ repositoryConverter.convert( artifact, destinationRepository );
+ }
+ catch ( RepositoryConversionException e )
+ {
+ getLogger().error(
+ "Unable to convert artifact " + artifact + " to destination repository "
+ + destinationRepository, e );
+ }
+ }
+
+ public void processFileProblem( BaseFile path, String message )
+ {
+ getLogger().error( "Artifact Build Failure on " + path + " : " + message );
+ // TODO: report this to the ConversionListener?
+ }
+
+ public ArtifactRepository getDestinationRepository()
+ {
+ return destinationRepository;
+ }
+
+ public void setDestinationRepository( ArtifactRepository destinationRepository )
+ {
+ this.destinationRepository = destinationRepository;
+ }
+
+ public String getName()
+ {
+ return "Legacy Artifact Converter Consumer";
+ }
+
+ /**
+ * Add a listener to the conversion process.
+ *
+ * @param listener the listener to add.
+ */
+ public void addConversionListener( ConversionListener listener )
+ {
+ repositoryConverter.addConversionListener( listener );
+ }
+
+ /**
+ * Remove a listener from the conversion process.
+ *
+ * @param listener the listener to remove.
+ */
+ public void removeConversionListener( ConversionListener listener )
+ {
+ repositoryConverter.removeConversionListener( listener );
+ }
+}
diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyRepositoryConverter.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyRepositoryConverter.java
new file mode 100644
index 000000000..60d3d5599
--- /dev/null
+++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyRepositoryConverter.java
@@ -0,0 +1,64 @@
+package org.apache.maven.archiva.converter.legacy;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.converter.ConversionListener;
+import org.apache.maven.archiva.converter.RepositoryConversionException;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * Convert an entire repository.
+ *
+ * @author Jason van Zyl
+ */
+public interface LegacyRepositoryConverter
+{
+ String ROLE = LegacyRepositoryConverter.class.getName();
+
+ /**
+ * Convert a legacy repository to a modern repository. This means a Maven 1.x repository
+ * using v3 POMs to a Maven 2.x repository using v4.0.0 POMs.
+ *
+ * @param legacyRepositoryDirectory the directory of the legacy repository.
+ * @param destinationRepositoryDirectory the directory of the modern repository.
+ * @param fileExclusionPatterns the list of patterns to exclude from the conversion.
+ * @param includeSnapshots true to include snapshots in conversion or not.
+ * @throws RepositoryConversionException
+ */
+ void convertLegacyRepository( File legacyRepositoryDirectory, File destinationRepositoryDirectory,
+ List fileExclusionPatterns, boolean includeSnapshots )
+ throws RepositoryConversionException;
+
+ /**
+ * Add a listener to the conversion process.
+ *
+ * @param listener the listener to add.
+ */
+ void addConversionListener( ConversionListener listener );
+
+ /**
+ * Remove a listener from the conversion process.
+ *
+ * @param listener the listener to remove.
+ */
+ void removeConversionListener( ConversionListener listener );
+}
diff --git a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/AllTests.java b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/AllTests.java
new file mode 100644
index 000000000..dbd54f604
--- /dev/null
+++ b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/AllTests.java
@@ -0,0 +1,44 @@
+package org.apache.maven.archiva.converter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * AllTests
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class AllTests
+{
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.converter" );
+ //$JUnit-BEGIN$
+ suite.addTest( org.apache.maven.archiva.converter.transaction.AllTests.suite() );
+ suite.addTestSuite( RepositoryConverterTest.class );
+ //$JUnit-END$
+ return suite;
+ }
+
+}
diff --git a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/MockConversionListener.java b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/MockConversionListener.java
new file mode 100644
index 000000000..92b70069b
--- /dev/null
+++ b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/MockConversionListener.java
@@ -0,0 +1,163 @@
+package org.apache.maven.archiva.converter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.artifact.Artifact;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * MockConversionListener
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MockConversionListener
+ implements ConversionListener
+{
+ private Map warnings = new HashMap();
+
+ private Map errors = new HashMap();
+
+ private Map exceptions = new HashMap();
+
+ private List processed = new ArrayList();
+
+ private List repositories = new ArrayList();
+
+ public void conversionEvent( ConversionEvent event )
+ {
+ switch ( event.getType() )
+ {
+ case ConversionEvent.STARTED:
+ addUnique( repositories, event.getRepository() );
+ break;
+ case ConversionEvent.PROCESSED:
+ addUnique( processed, event.getArtifact() );
+ break;
+ case ConversionEvent.WARNING:
+ if ( event.getException() != null )
+ {
+ addObjectList( exceptions, toKey( event.getArtifact() ), event.getException() );
+ }
+
+ if ( event.getMessage() != null )
+ {
+ addObjectList( warnings, toKey( event.getArtifact() ), event.getMessage() );
+ }
+ break;
+ case ConversionEvent.ERROR:
+ if ( event.getException() != null )
+ {
+ addObjectList( exceptions, toKey( event.getArtifact() ), event.getException() );
+ }
+
+ if ( event.getMessage() != null )
+ {
+ addObjectList( errors, toKey( event.getArtifact() ), event.getMessage() );
+ }
+ break;
+ case ConversionEvent.FINISHED:
+ addUnique( repositories, event.getRepository() );
+ break;
+ }
+ }
+
+ public String toKey( Artifact artifact )
+ {
+ return StringUtils.defaultString( artifact.getGroupId() ) + ":"
+ + StringUtils.defaultString( artifact.getArtifactId() ) + ":"
+ + StringUtils.defaultString( artifact.getVersion() ) + ":" + StringUtils.defaultString( artifact.getType() )
+ + ":" + StringUtils.defaultString( artifact.getClassifier() );
+ }
+
+ private void addObjectList( Map map, String key, Object value )
+ {
+ List objlist = (List) map.get( key );
+ if ( objlist == null )
+ {
+ objlist = new ArrayList();
+ }
+
+ objlist.add( value );
+
+ map.put( key, objlist );
+ }
+
+ private void addUnique( Collection collection, Object obj )
+ {
+ if ( !collection.contains( obj ) )
+ {
+ collection.add( obj );
+ }
+ }
+
+ public Map getErrors()
+ {
+ return errors;
+ }
+
+ public Map getExceptions()
+ {
+ return exceptions;
+ }
+
+ public List getProcessed()
+ {
+ return processed;
+ }
+
+ public List getRepositories()
+ {
+ return repositories;
+ }
+
+ public Map getWarnings()
+ {
+ return warnings;
+ }
+
+ private int getObjectListCount( Map map )
+ {
+ int count = 0;
+ for ( Iterator it = map.values().iterator(); it.hasNext(); )
+ {
+ List objList = (List) it.next();
+ count += objList.size();
+ }
+ return count;
+ }
+
+ public int getWarningMessageCount()
+ {
+ return getObjectListCount( warnings );
+ }
+
+ public int getErrorMessageCount()
+ {
+ return getObjectListCount( errors );
+ }
+}
diff --git a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java
index 15d5f187c..8e0c676e3 100644
--- a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java
+++ b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java
@@ -20,10 +20,6 @@ package org.apache.maven.archiva.converter;
*/
import org.apache.commons.io.FileUtils;
-import org.apache.maven.archiva.reporting.database.ReportingDatabase;
-import org.apache.maven.archiva.reporting.group.ReportGroup;
-import org.apache.maven.archiva.reporting.model.ArtifactResults;
-import org.apache.maven.archiva.reporting.model.Result;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
@@ -42,6 +38,8 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.regex.Matcher;
/**
@@ -64,8 +62,6 @@ public class RepositoryConverterTest
private ArtifactFactory artifactFactory;
- private ReportingDatabase reportingDatabase;
-
private static final int SLEEP_MILLIS = 100;
private I18N i18n;
@@ -80,25 +76,28 @@ public class RepositoryConverterTest
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
File sourceBase = getTestFile( "src/test/source-repository" );
- sourceRepository =
- factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null, null );
+ sourceRepository = factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null,
+ null );
layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
File targetBase = getTestFile( "target/test-target-repository" );
copyDirectoryStructure( getTestFile( "src/test/target-repository" ), targetBase );
- targetRepository =
- factory.createArtifactRepository( "target", targetBase.toURL().toString(), layout, null, null );
+ targetRepository = factory.createArtifactRepository( "target", targetBase.toURL().toString(), layout, null,
+ null );
repositoryConverter = (RepositoryConverter) lookup( RepositoryConverter.ROLE, "default" );
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
i18n = (I18N) lookup( I18N.ROLE );
+ }
- ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
- reportingDatabase = new ReportingDatabase( reportGroup );
+ protected void tearDown()
+ throws Exception
+ {
+ super.tearDown();
}
private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory )
@@ -135,8 +134,8 @@ public class RepositoryConverterTest
{
if ( !destination.exists() && !destination.mkdirs() )
{
- throw new IOException(
- "Could not create destination directory '" + destination.getAbsolutePath() + "'." );
+ throw new IOException( "Could not create destination directory '"
+ + destination.getAbsolutePath() + "'." );
}
copyDirectoryStructure( file, destination );
}
@@ -155,20 +154,23 @@ public class RepositoryConverterTest
Artifact artifact = createArtifact( "test", "v4artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File versionMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
+ File versionMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( versionMetadata ) );
versionMetadataFile.delete();
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
artifactFile.delete();
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkSuccess();
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkSuccess(listener);
assertTrue( "Check artifact created", artifactFile.exists() );
assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
@@ -200,17 +202,20 @@ public class RepositoryConverterTest
Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File versionMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
+ File versionMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( versionMetadata ) );
versionMetadataFile.delete();
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkSuccess();
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkSuccess(listener);
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
assertTrue( "Check artifact created", artifactFile.exists() );
@@ -241,22 +246,21 @@ public class RepositoryConverterTest
{
Artifact artifact = createArtifact( "test", "relocated-v3artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File versionMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
+ File versionMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( versionMetadata ) );
versionMetadataFile.delete();
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
+ repositoryConverter.convert( artifact, targetRepository );
//checkSuccess(); --> commented until MNG-2100 is fixed
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
assertTrue( "Check if relocated artifact created", artifactFile.exists() );
- assertTrue( "Check if relocated artifact matches",
- FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
+ assertTrue( "Check if relocated artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
Artifact pomArtifact = createArtifact( "relocated-test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom" );
File pomFile = getTestFile( "src/test/expected-files/" + targetRepository.pathOf( pomArtifact ) );
File testFile = getTestFile( "target/test-target-repository/" + targetRepository.pathOf( pomArtifact ) );
@@ -276,19 +280,20 @@ public class RepositoryConverterTest
Artifact artifact = createArtifact( "test", "v3-warnings-artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File versionMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
+ File versionMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( versionMetadata ) );
versionMetadataFile.delete();
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- assertEquals( "check no errors", 0, reportingDatabase.getNumFailures() );
- assertEquals( "check number of warnings", 2, reportingDatabase.getNumWarnings() );
- assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkCounts( listener, 0, 2 );
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
assertTrue( "Check artifact created", artifactFile.exists() );
@@ -311,17 +316,20 @@ public class RepositoryConverterTest
Artifact artifact = createArtifact( "test", "v4artifact", version );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File snapshotMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
+ File snapshotMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
snapshotMetadataFile.delete();
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkSuccess();
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkCounts( listener, 0, 0 );
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
assertTrue( "Check artifact created", artifactFile.exists() );
@@ -354,17 +362,20 @@ public class RepositoryConverterTest
Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0-SNAPSHOT" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File snapshotMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
+ File snapshotMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
snapshotMetadataFile.delete();
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkSuccess();
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkCounts( listener, 0, 0 );
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
assertTrue( "Check artifact created", artifactFile.exists() );
@@ -410,11 +421,10 @@ public class RepositoryConverterTest
public void testMavenOnePluginConversion()
throws Exception
{
- Artifact artifact =
- createArtifact( "org.apache.maven.plugins", "maven-foo-plugin", "1.0", "1.0", "maven-plugin" );
- artifact.setFile(
- new File( getBasedir(), "src/test/source-repository/test/plugins/maven-foo-plugin-1.0.jar" ) );
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
+ Artifact artifact = createArtifact( "org.apache.maven.plugins", "maven-foo-plugin", "1.0", "1.0",
+ "maven-plugin" );
+ artifact.setFile( new File( getBasedir(), "src/test/source-repository/test/plugins/maven-foo-plugin-1.0.jar" ) );
+ repositoryConverter.convert( artifact, targetRepository );
// There is a warning but I can't figure out how to look at it. Eyeballing the results it appears
// the plugin is being coverted correctly.
//checkSuccess();
@@ -424,14 +434,14 @@ public class RepositoryConverterTest
assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
/*
- The POM isn't needed for Maven 1.x plugins but the raw conversion for
-
- artifact = createPomArtifact( artifact );
- File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File expectedPomFile = getTestFile( "src/test/expected-files/maven-foo-plugin-1.0.pom" );
- assertTrue( "Check POM created", pomFile.exists() );
- compareFiles( expectedPomFile, pomFile );
- */
+ The POM isn't needed for Maven 1.x plugins but the raw conversion for
+
+ artifact = createPomArtifact( artifact );
+ File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File expectedPomFile = getTestFile( "src/test/expected-files/maven-foo-plugin-1.0.pom" );
+ assertTrue( "Check POM created", pomFile.exists() );
+ compareFiles( expectedPomFile, pomFile );
+ */
}
public void testV3TimestampedSnapshotPomConvert()
@@ -441,17 +451,20 @@ public class RepositoryConverterTest
Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0-20060105.130101-3" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File snapshotMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
+ File snapshotMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
snapshotMetadataFile.delete();
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkSuccess();
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkCounts( listener, 0, 0 );
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
assertTrue( "Check artifact created", artifactFile.exists() );
@@ -483,11 +496,13 @@ public class RepositoryConverterTest
// test that a POM is not created when there was none at the source
Artifact artifact = createArtifact( "test", "noPomArtifact", "1.0.0" );
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- assertEquals( "check no errors", 0, reportingDatabase.getNumFailures() );
- assertEquals( "check warnings", 1, reportingDatabase.getNumWarnings() );
- assertEquals( "check warning message", getI18nString( "warning.missing.pom" ), getWarning().getReason() );
- assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkCounts( listener, 0, 1 );
+
+ assertHasWarningReason( listener, getI18nString( "warning.missing.pom" ) );
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
assertTrue( "Check artifact created", artifactFile.exists() );
@@ -510,15 +525,19 @@ public class RepositoryConverterTest
File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
file.delete();
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkFailure();
- assertEquals( "check failure message", getI18nString( "failure.incorrect.md5" ), getFailure().getReason() );
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkCounts( listener, 1, 0 );
+
+ assertHasErrorReason( listener, getI18nString( "failure.incorrect.md5" ) );
assertFalse( "Check artifact not created", file.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile =
- new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@@ -531,15 +550,19 @@ public class RepositoryConverterTest
File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
file.delete();
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkFailure();
- assertEquals( "check failure message", getI18nString( "failure.incorrect.sha1" ), getFailure().getReason() );
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkCounts( listener, 1, 0 );
+
+ assertHasErrorReason( listener, getI18nString( "failure.incorrect.sha1" ) );
assertFalse( "Check artifact not created", file.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile =
- new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@@ -568,8 +591,11 @@ public class RepositoryConverterTest
// Need to guarantee last modified is not equal
Thread.sleep( SLEEP_MILLIS );
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkSuccess();
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkCounts( listener, 0, 0 );
compareFiles( sourceFile, targetFile );
compareFiles( sourcePomFile, targetPomFile );
@@ -604,17 +630,20 @@ public class RepositoryConverterTest
// Need to guarantee last modified is not equal
Thread.sleep( SLEEP_MILLIS );
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkFailure();
- assertEquals( "Check failure message", getI18nString( "failure.target.already.exists" ),
- getFailure().getReason() );
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkCounts( listener, 1, 0 );
+
+ assertHasErrorReason( listener, getI18nString( "failure.target.already.exists" ) );
assertEquals( "Check unmodified", origTime, targetFile.lastModified() );
assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile =
- new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@@ -641,8 +670,11 @@ public class RepositoryConverterTest
sourceFile.setLastModified( dateFormat.parse( "2006-01-01" ).getTime() );
sourcePomFile.setLastModified( dateFormat.parse( "2006-02-02" ).getTime() );
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkSuccess();
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkCounts( listener, 0, 0 );
compareFiles( sourceFile, targetFile );
compareFiles( sourcePomFile, targetPomFile );
@@ -651,8 +683,8 @@ public class RepositoryConverterTest
assertFalse( "Check modified", origTime == targetPomFile.lastModified() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile =
- new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( metadata ) );
assertTrue( "Check metadata created", metadataFile.exists() );
}
@@ -671,8 +703,11 @@ public class RepositoryConverterTest
File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) );
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkSuccess();
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkCounts( listener, 0, 0 );
assertTrue( "Check source file exists", sourceFile.exists() );
assertTrue( "Check source POM exists", sourcePomFile.exists() );
@@ -681,8 +716,8 @@ public class RepositoryConverterTest
assertFalse( "Check target POM doesn't exist", targetPomFile.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile =
- new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@@ -713,17 +748,20 @@ public class RepositoryConverterTest
// Need to guarantee last modified is not equal
Thread.sleep( SLEEP_MILLIS );
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkFailure();
- assertEquals( "Check failure message", getI18nString( "failure.target.already.exists" ),
- getFailure().getReason() );
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkFailure(listener);
+
+ assertHasErrorReason( listener, getI18nString( "failure.target.already.exists" ) );
assertEquals( "Check unmodified", origTime, targetFile.lastModified() );
assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile =
- new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@@ -734,20 +772,38 @@ public class RepositoryConverterTest
Artifact artifact = createArtifact( "test", "rollback-created-artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
FileUtils.deleteDirectory( artifactMetadataFile.getParentFile() );
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File versionMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
+ File versionMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( versionMetadata ) );
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkFailure();
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkCounts( listener, 1, 0 );
+
+ List messages = (List) listener.getErrors().get( listener.toKey( artifact ));
+ assertNotNull("Should have error messages.");
+
+ boolean found = false;
String pattern = "^" + getI18nString( "failure.invalid.source.pom" ).replaceFirst( "\\{0\\}", ".*" ) + "$";
- assertTrue( "Check failure message", getFailure().getReason().matches( pattern ) );
+ for ( Iterator it = messages.iterator(); it.hasNext(); )
+ {
+ String reason = (String) it.next();
+ if( reason.matches( pattern ) )
+ {
+ found = true;
+ break;
+ }
+ }
+
+ assertTrue( "Check failure message.", found );
assertFalse( "check artifact rolled back", artifactFile.exists() );
assertFalse( "check metadata rolled back", artifactMetadataFile.exists() );
@@ -763,10 +819,12 @@ public class RepositoryConverterTest
artifacts.add( createArtifact( "test", "artifact-one", "1.0.0" ) );
artifacts.add( createArtifact( "test", "artifact-two", "1.0.0" ) );
artifacts.add( createArtifact( "test", "artifact-three", "1.0.0" ) );
- repositoryConverter.convert( artifacts, targetRepository, reportingDatabase );
- assertEquals( "check no errors", 0, reportingDatabase.getNumFailures() );
- assertEquals( "check no warnings", 0, reportingDatabase.getNumWarnings() );
- assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
+
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifacts, targetRepository );
+ checkCounts( listener, 0, 0 );
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
{
@@ -778,8 +836,8 @@ public class RepositoryConverterTest
artifact = createPomArtifact( artifact );
File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File expectedPomFile =
- getTestFile( "src/test/expected-files/converted-" + artifact.getArtifactId() + ".pom" );
+ File expectedPomFile = getTestFile( "src/test/expected-files/converted-" + artifact.getArtifactId()
+ + ".pom" );
assertTrue( "Check POM created", pomFile.exists() );
compareFiles( expectedPomFile, pomFile );
@@ -797,16 +855,19 @@ public class RepositoryConverterTest
File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
file.delete();
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkFailure();
- assertEquals( "check failure message", getI18nString( "failure.incorrect.artifactMetadata.versions" ),
- getFailure().getReason() );
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkFailure(listener);
+
+ assertHasErrorReason( listener, getI18nString( "failure.incorrect.artifactMetadata.versions" ) );
assertFalse( "Check artifact not created", file.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile =
- new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@@ -821,16 +882,19 @@ public class RepositoryConverterTest
File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
file.delete();
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkFailure();
- assertEquals( "check failure message", getI18nString( "failure.incorrect.snapshotMetadata.snapshot" ),
- getFailure().getReason() );
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkFailure(listener);
+
+ assertHasErrorReason( listener, getI18nString( "failure.incorrect.snapshotMetadata.snapshot" ) );
assertFalse( "Check artifact not created", file.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile =
- new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
@@ -840,9 +904,11 @@ public class RepositoryConverterTest
// test artifact level metadata is merged when it already exists on successful conversion
Artifact artifact = createArtifact( "test", "newversion-artifact", "1.0.1" );
-
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
- checkSuccess();
+ MockConversionListener listener = new MockConversionListener();
+
+ repositoryConverter.addConversionListener( listener );
+ repositoryConverter.convert( artifact, targetRepository );
+ checkSuccess(listener);
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
assertTrue( "Check artifact created", artifactFile.exists() );
@@ -856,8 +922,8 @@ public class RepositoryConverterTest
compareFiles( sourcePomFile, pomFile );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(),
- targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() );
File expectedMetadataFile = getTestFile( "src/test/expected-files/newversion-artifact-metadata.xml" );
@@ -872,14 +938,14 @@ public class RepositoryConverterTest
ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
- sourceRepository = factory.createArtifactRepository( "source", targetRepository.getUrl(),
- targetRepository.getLayout(), null, null );
+ sourceRepository = factory.createArtifactRepository( "source", targetRepository.getUrl(), targetRepository
+ .getLayout(), null, null );
Artifact artifact = createArtifact( "test", "repository-artifact", "1.0" );
try
{
- repositoryConverter.convert( artifact, targetRepository, reportingDatabase );
+ repositoryConverter.convert( artifact, targetRepository );
fail( "Should have failed trying to convert within the same repository" );
}
catch ( RepositoryConversionException e )
@@ -905,8 +971,7 @@ public class RepositoryConverterTest
return createArtifact( groupId, artifactId, baseVersion, version, "jar" );
}
- private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version,
- String type )
+ private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version, String type )
{
Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type );
artifact.setBaseVersion( baseVersion );
@@ -917,8 +982,8 @@ public class RepositoryConverterTest
private Artifact createPomArtifact( Artifact artifact )
{
- return createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(),
- artifact.getVersion(), "pom" );
+ return createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact
+ .getVersion(), "pom" );
}
private static void compareFiles( File expectedPomFile, File pomFile )
@@ -926,8 +991,7 @@ public class RepositoryConverterTest
{
String expectedContent = normalizeString( FileUtils.readFileToString( expectedPomFile, null ) );
String targetContent = normalizeString( FileUtils.readFileToString( pomFile, null ) );
- assertEquals( "Check file match between " + expectedPomFile + " and " + pomFile, expectedContent,
- targetContent );
+ assertEquals( "Check file match between " + expectedPomFile + " and " + pomFile, expectedContent, targetContent );
}
private static String normalizeString( String path )
@@ -935,35 +999,79 @@ public class RepositoryConverterTest
return path.trim().replaceAll( "\r\n", "\n" ).replace( '\r', '\n' ).replaceAll( "<\\?xml .+\\?>", "" );
}
- private void checkSuccess()
+ private void checkSuccess(MockConversionListener listener)
{
- assertEquals( "check no errors", 0, reportingDatabase.getNumFailures() );
- assertEquals( "check no warnings", 0, reportingDatabase.getNumWarnings() );
- assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
+ checkCounts( listener, 0, 0 );
}
- private void checkFailure()
+ private void checkFailure(MockConversionListener listener)
{
- assertEquals( "check num errors", 1, reportingDatabase.getNumFailures() );
- assertEquals( "check no warnings", 0, reportingDatabase.getNumWarnings() );
- assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
+ checkCounts( listener, 1, 0 );
+ }
+
+ private void checkCounts( MockConversionListener listener, int failures, int warnings )
+ {
+ int actualFailures = listener.getErrorMessageCount();
+ int actualWarnings = listener.getWarningMessageCount();
+
+ if ( ( failures != actualFailures ) || ( warnings != actualWarnings ) )
+ {
+ fail( "Check Results Counts expected:<" + failures + "," + warnings + "> but was:<" + actualFailures + ","
+ + actualWarnings + ">" );
+ }
}
private String getI18nString( String key )
{
return i18n.getString( repositoryConverter.getClass().getName(), Locale.getDefault(), key );
}
-
- private Result getFailure()
+
+ private void assertHasWarningReason( MockConversionListener listener, String reason )
{
- ArtifactResults artifact = (ArtifactResults) reportingDatabase.getArtifactIterator().next();
- return (Result) artifact.getFailures().get( 0 );
+ assertHasMessage( listener.getWarnings(), "warning", reason );
}
- private Result getWarning()
+ private void assertHasErrorReason( MockConversionListener listener, String reason )
{
- ArtifactResults artifact = (ArtifactResults) reportingDatabase.getArtifactIterator().next();
- return (Result) artifact.getWarnings().get( 0 );
+ assertHasMessage( listener.getErrors(), "error", reason );
+ }
+
+ private void assertHasMessage( Map map, String type, String message )
+ {
+ if ( ( map == null ) || ( map.isEmpty() ) )
+ {
+ fail( "No " + type + "s captured, expected " + type + " <" + message + ">" );
+ }
+
+ // Attempt to find the message ...
+ for ( Iterator it = map.values().iterator(); it.hasNext(); )
+ {
+ List msgList = (List) it.next();
+
+ if ( msgList.contains( message ) )
+ {
+ // Found it!
+ return;
+ }
+ }
+
+ // Didn't find it! whoops ...
+ for ( Iterator it = map.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Entry) it.next();
+ String key = (String) entry.getKey();
+ List msgList = (List) entry.getValue();
+
+ System.err.println( " Artifact: " + key );
+
+ for ( Iterator itMsgs = msgList.iterator(); itMsgs.hasNext(); )
+ {
+ String msg = (String) itMsgs.next();
+ System.err.println( " " + msg );
+ }
+ }
+
+ fail( "Unable to find " + type + " reason <" + message + "> in any artifact." );
}
private void createModernSourceRepository()
@@ -974,7 +1082,7 @@ public class RepositoryConverterTest
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
File sourceBase = getTestFile( "src/test/source-modern-repository" );
- sourceRepository =
- factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null, null );
+ sourceRepository = factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null,
+ null );
}
}
diff --git a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/transaction/AllTests.java b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/transaction/AllTests.java
new file mode 100644
index 000000000..9274035d8
--- /dev/null
+++ b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/transaction/AllTests.java
@@ -0,0 +1,44 @@
+package org.apache.maven.archiva.converter.transaction;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * AllTests
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class AllTests
+{
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.converter.transaction" );
+ //$JUnit-BEGIN$
+ suite.addTestSuite( CreateFileEventTest.class );
+ suite.addTestSuite( CopyFileEventTest.class );
+ //$JUnit-END$
+ return suite;
+ }
+
+}
diff --git a/archiva-converter/src/test/resources/log4j.properties b/archiva-converter/src/test/resources/log4j.properties
new file mode 100644
index 000000000..9b2c26ade
--- /dev/null
+++ b/archiva-converter/src/test/resources/log4j.properties
@@ -0,0 +1,10 @@
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=WARN, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
+
diff --git a/archiva-converter/src/test/resources/org/apache/maven/archiva/converter/RepositoryConverterTest.xml b/archiva-converter/src/test/resources/org/apache/maven/archiva/converter/RepositoryConverterTest.xml
index 1007fd835..b1cf9640a 100644
--- a/archiva-converter/src/test/resources/org/apache/maven/archiva/converter/RepositoryConverterTest.xml
+++ b/archiva-converter/src/test/resources/org/apache/maven/archiva/converter/RepositoryConverterTest.xml
@@ -16,10 +16,11 @@
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
- -->
+-->
<component-set>
<components>
+
<component>
<role>org.apache.maven.archiva.converter.RepositoryConverter</role>
<implementation>org.apache.maven.archiva.converter.DefaultRepositoryConverter</implementation>
@@ -37,10 +38,6 @@
<field-name>artifactFactory</field-name>
</requirement>
<requirement>
- <role>org.apache.maven.model.converter.ArtifactPomRewriter</role>
- <field-name>rewriter</field-name>
- </requirement>
- <requirement>
<role>org.codehaus.plexus.i18n.I18N</role>
<field-name>i18n</field-name>
</requirement>
@@ -63,14 +60,66 @@
<field-name>artifactFactory</field-name>
</requirement>
<requirement>
- <role>org.apache.maven.model.converter.ArtifactPomRewriter</role>
- <field-name>rewriter</field-name>
- </requirement>
- <requirement>
<role>org.codehaus.plexus.i18n.I18N</role>
<field-name>i18n</field-name>
</requirement>
</requirements>
</component>
+
+
+ <component>
+ <role>org.codehaus.plexus.jdo.JdoFactory</role>
+ <role-hint>archiva</role-hint>
+ <implementation>org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory</implementation>
+
+ <configuration>
+ <!-- Database Configuration -->
+ <driverName>org.hsqldb.jdbcDriver</driverName>
+ <url>jdbc:hsqldb:mem:TESTDB</url>
+ <userName>sa</userName>
+ <password></password>
+
+ <!-- JPOX and JDO configuration -->
+ <persistenceManagerFactoryClass>org.jpox.PersistenceManagerFactoryImpl</persistenceManagerFactoryClass>
+ <otherProperties>
+ <property>
+ <name>javax.jdo.PersistenceManagerFactoryClass</name>
+ <value>org.jpox.PersistenceManagerFactoryImpl</value>
+ </property>
+ <property>
+ <name>org.jpox.autoCreateSchema</name>
+ <value>true</value>
+ </property>
+ <property>
+ <name>org.jpox.validateTables</name>
+ <value>false</value>
+ </property>
+ <property>
+ <name>org.jpox.validateConstraints</name>
+ <value>false</value>
+ </property>
+ <property>
+ <name>org.jpox.validateColumns</name>
+ <value>false</value>
+ </property>
+ <property>
+ <name>org.jpox.autoStartMechanism</name>
+ <value>None</value>
+ </property>
+ <property>
+ <name>org.jpox.transactionIsolation</name>
+ <value>READ_UNCOMMITTED</value>
+ </property>
+ <property>
+ <name>org.jpox.poid.transactionIsolation</name>
+ <value>READ_UNCOMMITTED</value>
+ </property>
+ <property>
+ <name>org.jpox.rdbms.dateTimezone</name>
+ <value>JDK_DEFAULT_TIMEZONE</value>
+ </property>
+ </otherProperties>
+ </configuration>
+ </component>
</components>
</component-set>