<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-shared-components</artifactId>
- <version>6</version>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-base</artifactId>
+ <version>1.0-alpha-1-SNAPSHOT</version>
</parent>
- <artifactId>maven-artifact-converter</artifactId>
- <version>2.1-alpha-2-SNAPSHOT</version>
- <name>Maven Artifact Converter</name>
+ <artifactId>archiva-artifact-converter</artifactId>
+ <name>Archiva Artifact Converter</name>
<description>Converts between Legacy and Modern Layout Artifacts.</description>
<dependencies>
<dependency>
<version>2.0.4</version>
</dependency>
<dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-transaction</artifactId>
- <version>1.0-alpha-1</version>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-transaction</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
- <version>1.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
- <version>1.0-alpha-9</version>
</dependency>
</dependencies>
<build>
--- /dev/null
+package org.apache.maven.archiva.converter.artifact;
+
+/*
+ * 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.
+ */
+
+/**
+ * ArtifactConversionException
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArtifactConversionException
+ extends Exception
+{
+
+ public ArtifactConversionException()
+ {
+ }
+
+ public ArtifactConversionException( String message )
+ {
+ super( message );
+ }
+
+ public ArtifactConversionException( Throwable cause )
+ {
+ super( cause );
+ }
+
+ public ArtifactConversionException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.converter.artifact;
+
+/*
+ * 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.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+
+import java.util.Map;
+
+/**
+ * ArtifactConverter
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface ArtifactConverter
+{
+ public static final String ROLE = ArtifactConverter.class.getName();
+
+ /**
+ * Convert an provided artifact, and place it into the destination repository.
+ *
+ * @param artifact the artifact to convert.
+ * @param destinationRepository the respository to send the artifact to.
+ * @throws ArtifactConversionException
+ */
+ void convert( Artifact artifact, ArtifactRepository destinationRepository )
+ throws ArtifactConversionException;
+
+ /**
+ * Get the map of accumulated warnings for the conversion.
+ *
+ * @return the {@link Map}<{@link Artifact}, {@link String}> warning messages.
+ */
+ Map getWarnings();
+
+ /**
+ * Clear the list of warning messages.
+ */
+ void clearWarnings();
+}
--- /dev/null
+package org.apache.maven.archiva.converter.artifact;
+
+/*
+ * 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.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * AsciiFileUtil - conveinence utility for reading / writing ascii files.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ * @todo switch to commons-lang and use their high-performance versions of these utility methods.
+ */
+public class AsciiFileUtil
+{
+ /**
+ * Read a file into a {@link String} and return it.
+ *
+ * @param file the file to read
+ * @return the {@link String} contents of the file.
+ * @throws IOException if there was a problem performing this operation.
+ */
+ public static String readFile( File file )
+ throws IOException
+ {
+ FileInputStream in = null;
+ try
+ {
+ in = new FileInputStream( file );
+ return IOUtil.toString( in );
+ }
+ finally
+ {
+ IOUtil.close( in );
+ }
+ }
+
+ /**
+ * Write the contents of a {@link String} to a file.
+ *
+ * @param file the file to write to
+ * @param content the {@link String} contents to write.
+ * @throws IOException if there was a problem performing this operation.
+ */
+ public static void writeFile( File file, String content )
+ throws IOException
+ {
+ FileOutputStream out = null;
+ try
+ {
+ out = new FileOutputStream( file );
+ IOUtil.copy( content, out );
+ }
+ finally
+ {
+ IOUtil.close( out );
+ }
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.converter.artifact;
+
+/*
+ * 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.transaction.FileTransaction;
+import org.apache.maven.archiva.transaction.TransactionException;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Metadata;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Snapshot;
+import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Versioning;
+import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+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.ModelConverter;
+import org.apache.maven.model.converter.PomTranslationException;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.codehaus.plexus.digest.Digester;
+import org.codehaus.plexus.digest.DigesterException;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+
+/**
+ * LegacyToDefaultConverter
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.converter.artifact.ArtifactConverter"
+ * role-hint="legacy-to-default"
+ */
+public class LegacyToDefaultConverter
+ implements ArtifactConverter
+{
+ /**
+ * {@link List}<{@link Digester}>
+ *
+ * @plexus.requirement role="org.codehaus.plexus.digest.Digester"
+ */
+ private List digesters;
+
+ /**
+ * @plexus.requirement
+ */
+ private ModelConverter translator;
+
+ /**
+ * @plexus.requirement
+ */
+ private ArtifactFactory artifactFactory;
+
+ /**
+ * @plexus.requirement
+ */
+ private ArtifactHandlerManager artifactHandlerManager;
+
+ /**
+ * @plexus.configuration default-value="false"
+ */
+ private boolean force;
+
+ /**
+ * @plexus.configuration default-value="false"
+ */
+ private boolean dryrun;
+
+ private Map warnings = new HashMap();
+
+ public void convert( Artifact artifact, ArtifactRepository targetRepository )
+ throws ArtifactConversionException
+ {
+ if ( artifact.getRepository().getUrl().equals( targetRepository.getUrl() ) )
+ {
+ throw new ArtifactConversionException( Messages.getString( "exception.repositories.match" ) ); //$NON-NLS-1$
+ }
+
+ if ( !validateMetadata( artifact ) )
+ {
+ addWarning( artifact, Messages.getString( "unable.to.validate.metadata" ) ); //$NON-NLS-1$
+ return;
+ }
+
+ FileTransaction transaction = new FileTransaction();
+
+ if ( !copyPom( artifact, targetRepository, transaction ) )
+ {
+ addWarning( artifact, Messages.getString( "unable.to.copy.pom" ) ); //$NON-NLS-1$
+ return;
+ }
+
+ if ( !copyArtifact( artifact, targetRepository, transaction ) )
+ {
+ addWarning( artifact, Messages.getString( "unable.to.copy.artifact" ) ); //$NON-NLS-1$
+ return;
+ }
+
+ Metadata metadata = createBaseMetadata( artifact );
+ Versioning versioning = new Versioning();
+ versioning.addVersion( artifact.getBaseVersion() );
+ metadata.setVersioning( versioning );
+ updateMetadata( new ArtifactRepositoryMetadata( artifact ), targetRepository, metadata, transaction );
+
+ metadata = createBaseMetadata( artifact );
+ metadata.setVersion( artifact.getBaseVersion() );
+ versioning = new Versioning();
+
+ Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( artifact.getVersion() );
+ if ( matcher.matches() )
+ {
+ Snapshot snapshot = new Snapshot();
+ snapshot.setBuildNumber( Integer.valueOf( matcher.group( 3 ) ).intValue() );
+ snapshot.setTimestamp( matcher.group( 2 ) );
+ versioning.setSnapshot( snapshot );
+ }
+
+ // TODO: merge latest/release/snapshot from source instead
+ metadata.setVersioning( versioning );
+ updateMetadata( new SnapshotArtifactRepositoryMetadata( artifact ), targetRepository, metadata, transaction );
+
+ if ( !dryrun )
+ {
+ try
+ {
+ transaction.commit();
+ }
+ catch ( TransactionException e )
+ {
+ throw new ArtifactConversionException( Messages.getString( "transaction.failure", e.getMessage() ), e ); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction )
+ throws ArtifactConversionException
+ {
+ 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 ) );
+
+ boolean result = true;
+ if ( file.exists() )
+ {
+ File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pom ) );
+
+ String contents = null;
+ boolean checksumsValid = false;
+ try
+ {
+ if ( testChecksums( artifact, file ) )
+ {
+ checksumsValid = true;
+ }
+
+ // Even if the checksums for the POM are invalid we should still convert the POM
+ contents = AsciiFileUtil.readFile( file );
+ }
+ catch ( IOException e )
+ {
+ throw new ArtifactConversionException(
+ Messages.getString( "unable.to.read.source.pom", e.getMessage() ), e ); //$NON-NLS-1$
+ }
+
+ if ( checksumsValid && contents.indexOf( "modelVersion" ) >= 0 ) //$NON-NLS-1$
+ {
+ // v4 POM
+ try
+ {
+ boolean matching = false;
+ if ( !force && targetFile.exists() )
+ {
+ String targetContents = AsciiFileUtil.readFile( targetFile );
+ matching = targetContents.equals( contents );
+ }
+ if ( force || !matching )
+ {
+ transaction.createFile( contents, targetFile, digesters );
+ }
+ }
+ catch ( IOException e )
+ {
+ throw new ArtifactConversionException( Messages
+ .getString( "unable.to.write.target.pom", e.getMessage() ), e ); //$NON-NLS-1$
+ }
+ }
+ else
+ {
+ // v3 POM
+ StringReader stringReader = new StringReader( contents );
+ StringWriter writer = null;
+ try
+ {
+ org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader v3Reader = new org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader();
+ org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( stringReader );
+
+ if ( doRelocation( artifact, v3Model, targetRepository, transaction ) )
+ {
+ 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() );
+
+ writer = new StringWriter();
+ MavenXpp3Writer Xpp3Writer = new MavenXpp3Writer();
+ Xpp3Writer.write( writer, v4Model );
+
+ transaction.createFile( writer.toString(), targetFile, digesters );
+
+ List warnings = translator.getWarnings();
+
+ for ( Iterator i = warnings.iterator(); i.hasNext(); )
+ {
+ String message = (String) i.next();
+ addWarning( artifact, message );
+ }
+ }
+ catch ( XmlPullParserException e )
+ {
+ addWarning( artifact, Messages.getString( "invalid.source.pom", e.getMessage() ) ); //$NON-NLS-1$
+ result = false;
+ }
+ catch ( IOException e )
+ {
+ throw new ArtifactConversionException( Messages.getString( "unable.to.write.converted.pom" ), e ); //$NON-NLS-1$
+ }
+ catch ( PomTranslationException e )
+ {
+ addWarning( artifact, Messages.getString( "invalid.source.pom", e.getMessage() ) ); //$NON-NLS-1$
+ result = false;
+ }
+ finally
+ {
+ IOUtil.close( writer );
+ }
+ }
+ }
+ else
+ {
+ addWarning( artifact, Messages.getString( "warning.missing.pom" ) ); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ private boolean testChecksums( Artifact artifact, File file )
+ throws IOException
+ {
+ boolean result = true;
+ Iterator it = digesters.iterator();
+ while ( it.hasNext() )
+ {
+ Digester digester = (Digester) it.next();
+ result &= verifyChecksum( file, file.getName() + "." + getDigesterFileExtension( digester ), digester, //$NON-NLS-1$
+ artifact, "failure.incorrect." + getDigesterFileExtension( digester ) ); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ private boolean verifyChecksum( File file, String fileName, Digester digester, Artifact artifact, String key )
+ throws IOException
+ {
+ boolean result = true;
+
+ File checksumFile = new File( file.getParentFile(), fileName );
+ if ( checksumFile.exists() )
+ {
+ String checksum = AsciiFileUtil.readFile( checksumFile );
+ try
+ {
+ digester.verify( file, checksum );
+ }
+ catch ( DigesterException e )
+ {
+ addWarning( artifact, Messages.getString( key ) );
+ result = false;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * File extension for checksums
+ * TODO should be moved to plexus-digester ?
+ */
+ private String getDigesterFileExtension( Digester digester )
+ {
+ return digester.getAlgorithm().toLowerCase().replaceAll( "-", "" ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ private boolean copyArtifact( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction )
+ throws ArtifactConversionException
+ {
+ File sourceFile = artifact.getFile();
+
+ if ( sourceFile.getAbsolutePath().indexOf( "/plugins/" ) > -1 ) //$NON-NLS-1$
+ {
+ artifact.setArtifactHandler( artifactHandlerManager.getArtifactHandler( "maven-plugin" ) ); //$NON-NLS-1$
+ }
+
+ File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+
+ boolean result = true;
+ try
+ {
+ boolean matching = false;
+ if ( !force && targetFile.exists() )
+ {
+ matching = FileUtils.contentEquals( sourceFile, targetFile );
+ if ( !matching )
+ {
+ addWarning( artifact, Messages.getString( "failure.target.already.exists" ) ); //$NON-NLS-1$
+ result = false;
+ }
+ }
+ if ( result )
+ {
+ if ( force || !matching )
+ {
+ if ( testChecksums( artifact, sourceFile ) )
+ {
+ transaction.copyFile( sourceFile, targetFile, digesters );
+ }
+ else
+ {
+ result = false;
+ }
+ }
+ }
+ }
+ catch ( IOException e )
+ {
+ throw new ArtifactConversionException( Messages.getString( "error.copying.artifact" ), e ); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ private Metadata createBaseMetadata( Artifact artifact )
+ {
+ Metadata metadata = new Metadata();
+ metadata.setArtifactId( artifact.getArtifactId() );
+ metadata.setGroupId( artifact.getGroupId() );
+ return metadata;
+ }
+
+ private Metadata readMetadata( File file )
+ throws ArtifactConversionException
+ {
+ Metadata metadata;
+ MetadataXpp3Reader reader = new MetadataXpp3Reader();
+ FileReader fileReader = null;
+ try
+ {
+ fileReader = new FileReader( file );
+ metadata = reader.read( fileReader );
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), e ); //$NON-NLS-1$
+ }
+ catch ( IOException e )
+ {
+ throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), e ); //$NON-NLS-1$
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), e ); //$NON-NLS-1$
+ }
+ finally
+ {
+ IOUtil.close( fileReader );
+ }
+ return metadata;
+ }
+
+ private boolean validateMetadata( Artifact artifact )
+ throws ArtifactConversionException
+ {
+ ArtifactRepository repository = artifact.getRepository();
+
+ boolean result = true;
+
+ RepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
+ File file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
+ if ( file.exists() )
+ {
+ Metadata metadata = readMetadata( file );
+ result = validateMetadata( metadata, repositoryMetadata, artifact );
+ }
+
+ repositoryMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
+ file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
+ if ( file.exists() )
+ {
+ Metadata metadata = readMetadata( file );
+ result = result && validateMetadata( metadata, repositoryMetadata, artifact );
+ }
+
+ return result;
+ }
+
+ private boolean validateMetadata( Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact )
+ {
+ String groupIdKey;
+ String artifactIdKey = null;
+ String snapshotKey = null;
+ String versionKey = null;
+ String versionsKey = null;
+
+ if ( repositoryMetadata.storedInGroupDirectory() )
+ {
+ groupIdKey = "failure.incorrect.groupMetadata.groupId"; //$NON-NLS-1$
+ }
+ else if ( repositoryMetadata.storedInArtifactVersionDirectory() )
+ {
+ groupIdKey = "failure.incorrect.snapshotMetadata.groupId"; //$NON-NLS-1$
+ artifactIdKey = "failure.incorrect.snapshotMetadata.artifactId"; //$NON-NLS-1$
+ versionKey = "failure.incorrect.snapshotMetadata.version"; //$NON-NLS-1$
+ snapshotKey = "failure.incorrect.snapshotMetadata.snapshot"; //$NON-NLS-1$
+ }
+ else
+ {
+ groupIdKey = "failure.incorrect.artifactMetadata.groupId"; //$NON-NLS-1$
+ artifactIdKey = "failure.incorrect.artifactMetadata.artifactId"; //$NON-NLS-1$
+ versionsKey = "failure.incorrect.artifactMetadata.versions"; //$NON-NLS-1$
+ }
+
+ boolean result = true;
+
+ if ( metadata.getGroupId() == null || !metadata.getGroupId().equals( artifact.getGroupId() ) )
+ {
+ addWarning( artifact, Messages.getString( groupIdKey ) );
+ result = false;
+ }
+ if ( !repositoryMetadata.storedInGroupDirectory() )
+ {
+ if ( metadata.getGroupId() == null || !metadata.getArtifactId().equals( artifact.getArtifactId() ) )
+ {
+ addWarning( artifact, Messages.getString( artifactIdKey ) );
+ result = false;
+ }
+ if ( !repositoryMetadata.storedInArtifactVersionDirectory() )
+ {
+ // artifact metadata
+
+ boolean foundVersion = false;
+ if ( metadata.getVersioning() != null )
+ {
+ for ( Iterator i = metadata.getVersioning().getVersions().iterator(); i.hasNext() && !foundVersion; )
+ {
+ String version = (String) i.next();
+ if ( version.equals( artifact.getBaseVersion() ) )
+ {
+ foundVersion = true;
+ }
+ }
+ }
+
+ if ( !foundVersion )
+ {
+ addWarning( artifact, Messages.getString( versionsKey ) );
+ result = false;
+ }
+ }
+ else
+ {
+ // snapshot metadata
+ if ( !artifact.getBaseVersion().equals( metadata.getVersion() ) )
+ {
+ addWarning( artifact, Messages.getString( versionKey ) );
+ result = false;
+ }
+
+ if ( artifact.isSnapshot() )
+ {
+ Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( artifact.getVersion() );
+ if ( matcher.matches() )
+ {
+ boolean correct = false;
+ if ( metadata.getVersioning() != null && metadata.getVersioning().getSnapshot() != null )
+ {
+ Snapshot snapshot = metadata.getVersioning().getSnapshot();
+ int build = Integer.valueOf( matcher.group( 3 ) ).intValue();
+ String ts = matcher.group( 2 );
+ if ( build == snapshot.getBuildNumber() && ts.equals( snapshot.getTimestamp() ) )
+ {
+ correct = true;
+ }
+ }
+
+ if ( !correct )
+ {
+ addWarning( artifact, Messages.getString( snapshotKey ) );
+ result = false;
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ private void updateMetadata( RepositoryMetadata artifactMetadata, ArtifactRepository targetRepository,
+ Metadata newMetadata, FileTransaction transaction )
+ throws ArtifactConversionException
+ {
+ File file = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+
+ Metadata metadata;
+ boolean changed;
+
+ if ( file.exists() )
+ {
+ metadata = readMetadata( file );
+ changed = metadata.merge( newMetadata );
+ }
+ else
+ {
+ changed = true;
+ metadata = newMetadata;
+ }
+
+ if ( changed )
+ {
+ StringWriter writer = null;
+ try
+ {
+ writer = new StringWriter();
+
+ MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
+
+ mappingWriter.write( writer, metadata );
+
+ transaction.createFile( writer.toString(), file, digesters );
+ }
+ catch ( IOException e )
+ {
+ throw new ArtifactConversionException( Messages.getString( "error.writing.target.metadata" ), e ); //$NON-NLS-1$
+ }
+ finally
+ {
+ IOUtil.close( writer );
+ }
+ }
+ }
+
+ private boolean doRelocation( Artifact artifact, org.apache.maven.model.v3_0_0.Model v3Model,
+ ArtifactRepository repository, FileTransaction transaction )
+ throws IOException
+ {
+ Properties properties = v3Model.getProperties();
+ if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" ) //$NON-NLS-1$ //$NON-NLS-2$
+ || properties.containsKey( "relocated.version" ) ) //$NON-NLS-1$
+ {
+ String newGroupId = properties.getProperty( "relocated.groupId", v3Model.getGroupId() ); //$NON-NLS-1$
+ properties.remove( "relocated.groupId" ); //$NON-NLS-1$
+
+ String newArtifactId = properties.getProperty( "relocated.artifactId", v3Model.getArtifactId() ); //$NON-NLS-1$
+ properties.remove( "relocated.artifactId" ); //$NON-NLS-1$
+
+ String newVersion = properties.getProperty( "relocated.version", v3Model.getVersion() ); //$NON-NLS-1$
+ properties.remove( "relocated.version" ); //$NON-NLS-1$
+
+ String message = properties.getProperty( "relocated.message", "" ); //$NON-NLS-1$ //$NON-NLS-2$
+ properties.remove( "relocated.message" ); //$NON-NLS-1$
+
+ if ( properties.isEmpty() )
+ {
+ v3Model.setProperties( null );
+ }
+
+ writeRelocationPom( v3Model.getGroupId(), v3Model.getArtifactId(), v3Model.getVersion(), newGroupId,
+ newArtifactId, newVersion, message, repository, transaction );
+
+ v3Model.setGroupId( newGroupId );
+ v3Model.setArtifactId( newArtifactId );
+ v3Model.setVersion( newVersion );
+
+ artifact.setGroupId( newGroupId );
+ artifact.setArtifactId( newArtifactId );
+ artifact.setVersion( newVersion );
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ private void writeRelocationPom( String groupId, String artifactId, String version, String newGroupId,
+ String newArtifactId, String newVersion, String message,
+ ArtifactRepository repository, FileTransaction transaction )
+ throws IOException
+ {
+ Model pom = new Model();
+ pom.setGroupId( groupId );
+ pom.setArtifactId( artifactId );
+ pom.setVersion( version );
+
+ DistributionManagement dMngt = new DistributionManagement();
+
+ Relocation relocation = new Relocation();
+ relocation.setGroupId( newGroupId );
+ relocation.setArtifactId( newArtifactId );
+ relocation.setVersion( newVersion );
+ if ( message != null && message.length() > 0 )
+ {
+ relocation.setMessage( message );
+ }
+
+ dMngt.setRelocation( relocation );
+
+ pom.setDistributionManagement( dMngt );
+
+ Artifact artifact = artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" ); //$NON-NLS-1$
+ File pomFile = new File( repository.getBasedir(), repository.pathOf( artifact ) );
+
+ StringWriter strWriter = new StringWriter();
+ MavenXpp3Writer pomWriter = new MavenXpp3Writer();
+ pomWriter.write( strWriter, pom );
+
+ transaction.createFile( strWriter.toString(), pomFile, digesters );
+ }
+
+ private void addWarning( Artifact artifact, String message )
+ {
+ List messages = (List) warnings.get( artifact );
+ if ( messages == null )
+ {
+ messages = new ArrayList();
+ }
+ messages.add( message );
+ warnings.put( artifact, messages );
+ }
+
+ public void clearWarnings()
+ {
+ warnings.clear();
+ }
+
+ public Map getWarnings()
+ {
+ return warnings;
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.converter.artifact;
+
+/*
+ * 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 java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * Messages
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class Messages
+{
+ private static final String BUNDLE_NAME = "org.apache.maven.archiva.converter.artifact.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME );
+
+ private Messages()
+ {
+ }
+
+ public static String getString( String key )
+ {
+ try
+ {
+ return RESOURCE_BUNDLE.getString( key );
+ }
+ catch ( MissingResourceException e )
+ {
+ return '!' + key + '!';
+ }
+ }
+
+ public static String getString( String key, Object argument )
+ {
+ return getString( key, new Object[] { argument } );
+ }
+
+ public static String getString( String key, Object arguments[] )
+ {
+ try
+ {
+ String pattern = RESOURCE_BUNDLE.getString( key );
+ return MessageFormat.format( pattern, arguments );
+ }
+ catch ( MissingResourceException e )
+ {
+ return '!' + key + '!';
+ }
+ }
+}
+++ /dev/null
-package org.apache.maven.artifact.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.
- */
-
-/**
- * ArtifactConversionException
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class ArtifactConversionException
- extends Exception
-{
-
- public ArtifactConversionException()
- {
- }
-
- public ArtifactConversionException( String message )
- {
- super( message );
- }
-
- public ArtifactConversionException( Throwable cause )
- {
- super( cause );
- }
-
- public ArtifactConversionException( String message, Throwable cause )
- {
- super( message, cause );
- }
-}
+++ /dev/null
-package org.apache.maven.artifact.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.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-
-import java.util.Map;
-
-/**
- * ArtifactConverter
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public interface ArtifactConverter
-{
- public static final String ROLE = ArtifactConverter.class.getName();
-
- /**
- * Convert an provided artifact, and place it into the destination repository.
- *
- * @param artifact the artifact to convert.
- * @param destinationRepository the respository to send the artifact to.
- * @throws ArtifactConversionException
- */
- void convert( Artifact artifact, ArtifactRepository destinationRepository )
- throws ArtifactConversionException;
-
- /**
- * Get the map of accumulated warnings for the conversion.
- *
- * @return the {@link Map}<{@link Artifact}, {@link String}> warning messages.
- */
- Map getWarnings();
-
- /**
- * Clear the list of warning messages.
- */
- void clearWarnings();
-}
+++ /dev/null
-package org.apache.maven.artifact.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.codehaus.plexus.util.IOUtil;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-/**
- * AsciiFileUtil - conveinence utility for reading / writing ascii files.
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- * @todo switch to commons-lang and use their high-performance versions of these utility methods.
- */
-public class AsciiFileUtil
-{
- /**
- * Read a file into a {@link String} and return it.
- *
- * @param file the file to read
- * @return the {@link String} contents of the file.
- * @throws IOException if there was a problem performing this operation.
- */
- public static String readFile( File file )
- throws IOException
- {
- FileInputStream in = null;
- try
- {
- in = new FileInputStream( file );
- return IOUtil.toString( in );
- }
- finally
- {
- IOUtil.close( in );
- }
- }
-
- /**
- * Write the contents of a {@link String} to a file.
- *
- * @param file the file to write to
- * @param content the {@link String} contents to write.
- * @throws IOException if there was a problem performing this operation.
- */
- public static void writeFile( File file, String content )
- throws IOException
- {
- FileOutputStream out = null;
- try
- {
- out = new FileOutputStream( file );
- IOUtil.copy( content, out );
- }
- finally
- {
- IOUtil.close( out );
- }
- }
-}
+++ /dev/null
-package org.apache.maven.artifact.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.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
-import org.apache.maven.artifact.repository.metadata.Metadata;
-import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
-import org.apache.maven.artifact.repository.metadata.Snapshot;
-import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
-import org.apache.maven.artifact.repository.metadata.Versioning;
-import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
-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.ModelConverter;
-import org.apache.maven.model.converter.PomTranslationException;
-import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
-import org.apache.maven.transaction.FileTransaction;
-import org.apache.maven.transaction.TransactionException;
-import org.codehaus.plexus.digest.Digester;
-import org.codehaus.plexus.digest.DigesterException;
-import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.regex.Matcher;
-
-/**
- * LegacyToDefaultConverter
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- *
- * @plexus.component role="org.apache.maven.artifact.converter.ArtifactConverter"
- * role-hint="legacy-to-default"
- */
-public class LegacyToDefaultConverter
- implements ArtifactConverter
-{
- /**
- * {@link List}<{@link Digester}>
- *
- * @plexus.requirement role="org.codehaus.plexus.digest.Digester"
- */
- private List digesters;
-
- /**
- * @plexus.requirement
- */
- private ModelConverter translator;
-
- /**
- * @plexus.requirement
- */
- private ArtifactFactory artifactFactory;
-
- /**
- * @plexus.requirement
- */
- private ArtifactHandlerManager artifactHandlerManager;
-
- /**
- * @plexus.configuration default-value="false"
- */
- private boolean force;
-
- /**
- * @plexus.configuration default-value="false"
- */
- private boolean dryrun;
-
- private Map warnings = new HashMap();
-
- public void convert( Artifact artifact, ArtifactRepository targetRepository )
- throws ArtifactConversionException
- {
- if ( artifact.getRepository().getUrl().equals( targetRepository.getUrl() ) )
- {
- throw new ArtifactConversionException( Messages.getString( "exception.repositories.match" ) ); //$NON-NLS-1$
- }
-
- if ( !validateMetadata( artifact ) )
- {
- addWarning( artifact, Messages.getString( "unable.to.validate.metadata" ) ); //$NON-NLS-1$
- return;
- }
-
- FileTransaction transaction = new FileTransaction();
-
- if ( !copyPom( artifact, targetRepository, transaction ) )
- {
- addWarning( artifact, Messages.getString( "unable.to.copy.pom" ) ); //$NON-NLS-1$
- return;
- }
-
- if ( !copyArtifact( artifact, targetRepository, transaction ) )
- {
- addWarning( artifact, Messages.getString( "unable.to.copy.artifact" ) ); //$NON-NLS-1$
- return;
- }
-
- Metadata metadata = createBaseMetadata( artifact );
- Versioning versioning = new Versioning();
- versioning.addVersion( artifact.getBaseVersion() );
- metadata.setVersioning( versioning );
- updateMetadata( new ArtifactRepositoryMetadata( artifact ), targetRepository, metadata, transaction );
-
- metadata = createBaseMetadata( artifact );
- metadata.setVersion( artifact.getBaseVersion() );
- versioning = new Versioning();
-
- Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( artifact.getVersion() );
- if ( matcher.matches() )
- {
- Snapshot snapshot = new Snapshot();
- snapshot.setBuildNumber( Integer.valueOf( matcher.group( 3 ) ).intValue() );
- snapshot.setTimestamp( matcher.group( 2 ) );
- versioning.setSnapshot( snapshot );
- }
-
- // TODO: merge latest/release/snapshot from source instead
- metadata.setVersioning( versioning );
- updateMetadata( new SnapshotArtifactRepositoryMetadata( artifact ), targetRepository, metadata, transaction );
-
- if ( !dryrun )
- {
- try
- {
- transaction.commit();
- }
- catch ( TransactionException e )
- {
- throw new ArtifactConversionException( Messages.getString( "transaction.failure", e.getMessage() ), e ); //$NON-NLS-1$
- }
- }
- }
-
- private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction )
- throws ArtifactConversionException
- {
- 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 ) );
-
- boolean result = true;
- if ( file.exists() )
- {
- File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pom ) );
-
- String contents = null;
- boolean checksumsValid = false;
- try
- {
- if ( testChecksums( artifact, file ) )
- {
- checksumsValid = true;
- }
-
- // Even if the checksums for the POM are invalid we should still convert the POM
- contents = AsciiFileUtil.readFile( file );
- }
- catch ( IOException e )
- {
- throw new ArtifactConversionException(
- Messages.getString( "unable.to.read.source.pom", e.getMessage() ), e ); //$NON-NLS-1$
- }
-
- if ( checksumsValid && contents.indexOf( "modelVersion" ) >= 0 ) //$NON-NLS-1$
- {
- // v4 POM
- try
- {
- boolean matching = false;
- if ( !force && targetFile.exists() )
- {
- String targetContents = AsciiFileUtil.readFile( targetFile );
- matching = targetContents.equals( contents );
- }
- if ( force || !matching )
- {
- transaction.createFile( contents, targetFile, digesters );
- }
- }
- catch ( IOException e )
- {
- throw new ArtifactConversionException( Messages
- .getString( "unable.to.write.target.pom", e.getMessage() ), e ); //$NON-NLS-1$
- }
- }
- else
- {
- // v3 POM
- StringReader stringReader = new StringReader( contents );
- StringWriter writer = null;
- try
- {
- org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader v3Reader = new org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader();
- org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( stringReader );
-
- if ( doRelocation( artifact, v3Model, targetRepository, transaction ) )
- {
- 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() );
-
- writer = new StringWriter();
- MavenXpp3Writer Xpp3Writer = new MavenXpp3Writer();
- Xpp3Writer.write( writer, v4Model );
-
- transaction.createFile( writer.toString(), targetFile, digesters );
-
- List warnings = translator.getWarnings();
-
- for ( Iterator i = warnings.iterator(); i.hasNext(); )
- {
- String message = (String) i.next();
- addWarning( artifact, message );
- }
- }
- catch ( XmlPullParserException e )
- {
- addWarning( artifact, Messages.getString( "invalid.source.pom", e.getMessage() ) ); //$NON-NLS-1$
- result = false;
- }
- catch ( IOException e )
- {
- throw new ArtifactConversionException( Messages.getString( "unable.to.write.converted.pom" ), e ); //$NON-NLS-1$
- }
- catch ( PomTranslationException e )
- {
- addWarning( artifact, Messages.getString( "invalid.source.pom", e.getMessage() ) ); //$NON-NLS-1$
- result = false;
- }
- finally
- {
- IOUtil.close( writer );
- }
- }
- }
- else
- {
- addWarning( artifact, Messages.getString( "warning.missing.pom" ) ); //$NON-NLS-1$
- }
- return result;
- }
-
- private boolean testChecksums( Artifact artifact, File file )
- throws IOException
- {
- boolean result = true;
- Iterator it = digesters.iterator();
- while ( it.hasNext() )
- {
- Digester digester = (Digester) it.next();
- result &= verifyChecksum( file, file.getName() + "." + getDigesterFileExtension( digester ), digester, //$NON-NLS-1$
- artifact, "failure.incorrect." + getDigesterFileExtension( digester ) ); //$NON-NLS-1$
- }
- return result;
- }
-
- private boolean verifyChecksum( File file, String fileName, Digester digester, Artifact artifact, String key )
- throws IOException
- {
- boolean result = true;
-
- File checksumFile = new File( file.getParentFile(), fileName );
- if ( checksumFile.exists() )
- {
- String checksum = AsciiFileUtil.readFile( checksumFile );
- try
- {
- digester.verify( file, checksum );
- }
- catch ( DigesterException e )
- {
- addWarning( artifact, Messages.getString( key ) );
- result = false;
- }
- }
- return result;
- }
-
- /**
- * File extension for checksums
- * TODO should be moved to plexus-digester ?
- */
- private String getDigesterFileExtension( Digester digester )
- {
- return digester.getAlgorithm().toLowerCase().replaceAll( "-", "" ); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- private boolean copyArtifact( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction )
- throws ArtifactConversionException
- {
- File sourceFile = artifact.getFile();
-
- if ( sourceFile.getAbsolutePath().indexOf( "/plugins/" ) > -1 ) //$NON-NLS-1$
- {
- artifact.setArtifactHandler( artifactHandlerManager.getArtifactHandler( "maven-plugin" ) ); //$NON-NLS-1$
- }
-
- File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
-
- boolean result = true;
- try
- {
- boolean matching = false;
- if ( !force && targetFile.exists() )
- {
- matching = FileUtils.contentEquals( sourceFile, targetFile );
- if ( !matching )
- {
- addWarning( artifact, Messages.getString( "failure.target.already.exists" ) ); //$NON-NLS-1$
- result = false;
- }
- }
- if ( result )
- {
- if ( force || !matching )
- {
- if ( testChecksums( artifact, sourceFile ) )
- {
- transaction.copyFile( sourceFile, targetFile, digesters );
- }
- else
- {
- result = false;
- }
- }
- }
- }
- catch ( IOException e )
- {
- throw new ArtifactConversionException( Messages.getString( "error.copying.artifact" ), e ); //$NON-NLS-1$
- }
- return result;
- }
-
- private Metadata createBaseMetadata( Artifact artifact )
- {
- Metadata metadata = new Metadata();
- metadata.setArtifactId( artifact.getArtifactId() );
- metadata.setGroupId( artifact.getGroupId() );
- return metadata;
- }
-
- private Metadata readMetadata( File file )
- throws ArtifactConversionException
- {
- Metadata metadata;
- MetadataXpp3Reader reader = new MetadataXpp3Reader();
- FileReader fileReader = null;
- try
- {
- fileReader = new FileReader( file );
- metadata = reader.read( fileReader );
- }
- catch ( FileNotFoundException e )
- {
- throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), e ); //$NON-NLS-1$
- }
- catch ( IOException e )
- {
- throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), e ); //$NON-NLS-1$
- }
- catch ( XmlPullParserException e )
- {
- throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), e ); //$NON-NLS-1$
- }
- finally
- {
- IOUtil.close( fileReader );
- }
- return metadata;
- }
-
- private boolean validateMetadata( Artifact artifact )
- throws ArtifactConversionException
- {
- ArtifactRepository repository = artifact.getRepository();
-
- boolean result = true;
-
- RepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
- File file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
- if ( file.exists() )
- {
- Metadata metadata = readMetadata( file );
- result = validateMetadata( metadata, repositoryMetadata, artifact );
- }
-
- repositoryMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
- if ( file.exists() )
- {
- Metadata metadata = readMetadata( file );
- result = result && validateMetadata( metadata, repositoryMetadata, artifact );
- }
-
- return result;
- }
-
- private boolean validateMetadata( Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact )
- {
- String groupIdKey;
- String artifactIdKey = null;
- String snapshotKey = null;
- String versionKey = null;
- String versionsKey = null;
-
- if ( repositoryMetadata.storedInGroupDirectory() )
- {
- groupIdKey = "failure.incorrect.groupMetadata.groupId"; //$NON-NLS-1$
- }
- else if ( repositoryMetadata.storedInArtifactVersionDirectory() )
- {
- groupIdKey = "failure.incorrect.snapshotMetadata.groupId"; //$NON-NLS-1$
- artifactIdKey = "failure.incorrect.snapshotMetadata.artifactId"; //$NON-NLS-1$
- versionKey = "failure.incorrect.snapshotMetadata.version"; //$NON-NLS-1$
- snapshotKey = "failure.incorrect.snapshotMetadata.snapshot"; //$NON-NLS-1$
- }
- else
- {
- groupIdKey = "failure.incorrect.artifactMetadata.groupId"; //$NON-NLS-1$
- artifactIdKey = "failure.incorrect.artifactMetadata.artifactId"; //$NON-NLS-1$
- versionsKey = "failure.incorrect.artifactMetadata.versions"; //$NON-NLS-1$
- }
-
- boolean result = true;
-
- if ( metadata.getGroupId() == null || !metadata.getGroupId().equals( artifact.getGroupId() ) )
- {
- addWarning( artifact, Messages.getString( groupIdKey ) );
- result = false;
- }
- if ( !repositoryMetadata.storedInGroupDirectory() )
- {
- if ( metadata.getGroupId() == null || !metadata.getArtifactId().equals( artifact.getArtifactId() ) )
- {
- addWarning( artifact, Messages.getString( artifactIdKey ) );
- result = false;
- }
- if ( !repositoryMetadata.storedInArtifactVersionDirectory() )
- {
- // artifact metadata
-
- boolean foundVersion = false;
- if ( metadata.getVersioning() != null )
- {
- for ( Iterator i = metadata.getVersioning().getVersions().iterator(); i.hasNext() && !foundVersion; )
- {
- String version = (String) i.next();
- if ( version.equals( artifact.getBaseVersion() ) )
- {
- foundVersion = true;
- }
- }
- }
-
- if ( !foundVersion )
- {
- addWarning( artifact, Messages.getString( versionsKey ) );
- result = false;
- }
- }
- else
- {
- // snapshot metadata
- if ( !artifact.getBaseVersion().equals( metadata.getVersion() ) )
- {
- addWarning( artifact, Messages.getString( versionKey ) );
- result = false;
- }
-
- if ( artifact.isSnapshot() )
- {
- Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( artifact.getVersion() );
- if ( matcher.matches() )
- {
- boolean correct = false;
- if ( metadata.getVersioning() != null && metadata.getVersioning().getSnapshot() != null )
- {
- Snapshot snapshot = metadata.getVersioning().getSnapshot();
- int build = Integer.valueOf( matcher.group( 3 ) ).intValue();
- String ts = matcher.group( 2 );
- if ( build == snapshot.getBuildNumber() && ts.equals( snapshot.getTimestamp() ) )
- {
- correct = true;
- }
- }
-
- if ( !correct )
- {
- addWarning( artifact, Messages.getString( snapshotKey ) );
- result = false;
- }
- }
- }
- }
- }
- return result;
- }
-
- private void updateMetadata( RepositoryMetadata artifactMetadata, ArtifactRepository targetRepository,
- Metadata newMetadata, FileTransaction transaction )
- throws ArtifactConversionException
- {
- File file = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
-
- Metadata metadata;
- boolean changed;
-
- if ( file.exists() )
- {
- metadata = readMetadata( file );
- changed = metadata.merge( newMetadata );
- }
- else
- {
- changed = true;
- metadata = newMetadata;
- }
-
- if ( changed )
- {
- StringWriter writer = null;
- try
- {
- writer = new StringWriter();
-
- MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
-
- mappingWriter.write( writer, metadata );
-
- transaction.createFile( writer.toString(), file, digesters );
- }
- catch ( IOException e )
- {
- throw new ArtifactConversionException( Messages.getString( "error.writing.target.metadata" ), e ); //$NON-NLS-1$
- }
- finally
- {
- IOUtil.close( writer );
- }
- }
- }
-
- private boolean doRelocation( Artifact artifact, org.apache.maven.model.v3_0_0.Model v3Model,
- ArtifactRepository repository, FileTransaction transaction )
- throws IOException
- {
- Properties properties = v3Model.getProperties();
- if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" ) //$NON-NLS-1$ //$NON-NLS-2$
- || properties.containsKey( "relocated.version" ) ) //$NON-NLS-1$
- {
- String newGroupId = properties.getProperty( "relocated.groupId", v3Model.getGroupId() ); //$NON-NLS-1$
- properties.remove( "relocated.groupId" ); //$NON-NLS-1$
-
- String newArtifactId = properties.getProperty( "relocated.artifactId", v3Model.getArtifactId() ); //$NON-NLS-1$
- properties.remove( "relocated.artifactId" ); //$NON-NLS-1$
-
- String newVersion = properties.getProperty( "relocated.version", v3Model.getVersion() ); //$NON-NLS-1$
- properties.remove( "relocated.version" ); //$NON-NLS-1$
-
- String message = properties.getProperty( "relocated.message", "" ); //$NON-NLS-1$ //$NON-NLS-2$
- properties.remove( "relocated.message" ); //$NON-NLS-1$
-
- if ( properties.isEmpty() )
- {
- v3Model.setProperties( null );
- }
-
- writeRelocationPom( v3Model.getGroupId(), v3Model.getArtifactId(), v3Model.getVersion(), newGroupId,
- newArtifactId, newVersion, message, repository, transaction );
-
- v3Model.setGroupId( newGroupId );
- v3Model.setArtifactId( newArtifactId );
- v3Model.setVersion( newVersion );
-
- artifact.setGroupId( newGroupId );
- artifact.setArtifactId( newArtifactId );
- artifact.setVersion( newVersion );
-
- return true;
- }
- else
- {
- return false;
- }
- }
-
- private void writeRelocationPom( String groupId, String artifactId, String version, String newGroupId,
- String newArtifactId, String newVersion, String message,
- ArtifactRepository repository, FileTransaction transaction )
- throws IOException
- {
- Model pom = new Model();
- pom.setGroupId( groupId );
- pom.setArtifactId( artifactId );
- pom.setVersion( version );
-
- DistributionManagement dMngt = new DistributionManagement();
-
- Relocation relocation = new Relocation();
- relocation.setGroupId( newGroupId );
- relocation.setArtifactId( newArtifactId );
- relocation.setVersion( newVersion );
- if ( message != null && message.length() > 0 )
- {
- relocation.setMessage( message );
- }
-
- dMngt.setRelocation( relocation );
-
- pom.setDistributionManagement( dMngt );
-
- Artifact artifact = artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" ); //$NON-NLS-1$
- File pomFile = new File( repository.getBasedir(), repository.pathOf( artifact ) );
-
- StringWriter strWriter = new StringWriter();
- MavenXpp3Writer pomWriter = new MavenXpp3Writer();
- pomWriter.write( strWriter, pom );
-
- transaction.createFile( strWriter.toString(), pomFile, digesters );
- }
-
- private void addWarning( Artifact artifact, String message )
- {
- List messages = (List) warnings.get( artifact );
- if ( messages == null )
- {
- messages = new ArrayList();
- }
- messages.add( message );
- warnings.put( artifact, messages );
- }
-
- public void clearWarnings()
- {
- warnings.clear();
- }
-
- public Map getWarnings()
- {
- return warnings;
- }
-}
+++ /dev/null
-package org.apache.maven.artifact.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 java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * Messages
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class Messages
-{
- private static final String BUNDLE_NAME = "org.apache.maven.artifact.converter.messages"; //$NON-NLS-1$
-
- private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME );
-
- private Messages()
- {
- }
-
- public static String getString( String key )
- {
- try
- {
- return RESOURCE_BUNDLE.getString( key );
- }
- catch ( MissingResourceException e )
- {
- return '!' + key + '!';
- }
- }
-
- public static String getString( String key, Object argument )
- {
- return getString( key, new Object[] { argument } );
- }
-
- public static String getString( String key, Object arguments[] )
- {
- try
- {
- String pattern = RESOURCE_BUNDLE.getString( key );
- return MessageFormat.format( pattern, arguments );
- }
- catch ( MissingResourceException e )
- {
- return '!' + key + '!';
- }
- }
-}
--- /dev/null
+#
+# 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.
+#
+
+unable.to.validate.metadata=Unable to validate metadata
+unable.to.copy.pom=Unable to copy pom.
+unable.to.copy.artifact=Unable to copy artifact
+unable.to.read.source.pom=Unable to read source POM: {0}
+unable.to.write.target.pom=Unable to write target POM: {0}
+unable.to.write.converted.pom=Unable to write converted POM
+
+
+exception.repositories.match=Source repository of artifact, and target repository are the same. No conversion needed.
+transaction.failure=Transaction failure: {0}
+invalid.source.pom=Invalid source pom: {0}
+
+warning.missing.pom=The artifact had no POM in the source repository.
+
+error.copying.artifact=Error copying artifact
+error.reading.target.metadata=Error reading target metadata
+error.writing.target.metadata=Error writing target metadata
+
+failure.target.already.exists=The artifact could not be converted because it already exists.
+failure.incorrect.groupMetadata.groupId=The group ID in the source group metadata is incorrect.
+
+failure.incorrect.artifactMetadata.artifactId=The artifact ID in the source artifact metadata is incorrect.
+failure.incorrect.artifactMetadata.groupId=The group ID in the source artifact metadata is incorrect.
+failure.incorrect.artifactMetadata.versions=The version list in the source artifact metadata is incorrect.
+
+failure.incorrect.snapshotMetadata.artifactId=The artifact ID in the source artifact version metadata is incorrect.
+failure.incorrect.snapshotMetadata.groupId=The group ID in the source artifact version metadata is incorrect.
+failure.incorrect.snapshotMetadata.version=The version in the source artifact version metadata is incorrect.
+failure.incorrect.snapshotMetadata.snapshot=The snapshot information in the source artifact version metadata is incorrect.
+
+failure.incorrect.md5=The MD5 checksum value was incorrect.
+failure.incorrect.sha1=The SHA1 checksum value was incorrect.
+++ /dev/null
-#
-# 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.
-#
-
-unable.to.validate.metadata=Unable to validate metadata
-unable.to.copy.pom=Unable to copy pom.
-unable.to.copy.artifact=Unable to copy artifact
-unable.to.read.source.pom=Unable to read source POM: {0}
-unable.to.write.target.pom=Unable to write target POM: {0}
-unable.to.write.converted.pom=Unable to write converted POM
-
-
-exception.repositories.match=Source repository of artifact, and target repository are the same. No conversion needed.
-transaction.failure=Transaction failure: {0}
-invalid.source.pom=Invalid source pom: {0}
-
-warning.missing.pom=The artifact had no POM in the source repository.
-
-error.copying.artifact=Error copying artifact
-error.reading.target.metadata=Error reading target metadata
-error.writing.target.metadata=Error writing target metadata
-
-failure.target.already.exists=The artifact could not be converted because it already exists.
-failure.incorrect.groupMetadata.groupId=The group ID in the source group metadata is incorrect.
-
-failure.incorrect.artifactMetadata.artifactId=The artifact ID in the source artifact metadata is incorrect.
-failure.incorrect.artifactMetadata.groupId=The group ID in the source artifact metadata is incorrect.
-failure.incorrect.artifactMetadata.versions=The version list in the source artifact metadata is incorrect.
-
-failure.incorrect.snapshotMetadata.artifactId=The artifact ID in the source artifact version metadata is incorrect.
-failure.incorrect.snapshotMetadata.groupId=The group ID in the source artifact version metadata is incorrect.
-failure.incorrect.snapshotMetadata.version=The version in the source artifact version metadata is incorrect.
-failure.incorrect.snapshotMetadata.snapshot=The snapshot information in the source artifact version metadata is incorrect.
-
-failure.incorrect.md5=The MD5 checksum value was incorrect.
-failure.incorrect.sha1=The SHA1 checksum value was incorrect.
--- /dev/null
+package org.apache.maven.archiva.converter.artifact;
+
+/*
+ * 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.artifact.ArtifactConversionException;
+import org.apache.maven.archiva.converter.artifact.ArtifactConverter;
+import org.apache.maven.archiva.converter.artifact.AsciiFileUtil;
+import org.apache.maven.archiva.converter.artifact.Messages;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+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;
+
+/**
+ * LegacyToDefaultConverterTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class LegacyToDefaultConverterTest
+ extends PlexusTestCase
+{
+ private ArtifactRepository sourceRepository;
+
+ private ArtifactRepository targetRepository;
+
+ private ArtifactConverter artifactConverter;
+
+ private ArtifactFactory artifactFactory;
+
+ private static final int SLEEP_MILLIS = 100;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+
+ ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
+
+ File sourceBase = getTestFile( "src/test/source-repository" );
+ 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 );
+
+ artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "legacy-to-default" );
+
+ artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+ }
+
+ private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory )
+ throws IOException
+ {
+ if ( !sourceDirectory.exists() )
+ {
+ throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." );
+ }
+
+ File[] files = sourceDirectory.listFiles();
+
+ String sourcePath = sourceDirectory.getAbsolutePath();
+
+ for ( int i = 0; i < files.length; i++ )
+ {
+ File file = files[i];
+
+ String dest = file.getAbsolutePath();
+
+ dest = dest.substring( sourcePath.length() + 1 );
+
+ File destination = new File( destinationDirectory, dest );
+
+ if ( file.isFile() )
+ {
+ destination = destination.getParentFile();
+
+ FileUtils.copyFileToDirectory( file, destination );
+ }
+ else if ( file.isDirectory() )
+ {
+ if ( !".svn".equals( file.getName() ) )
+ {
+ if ( !destination.exists() && !destination.mkdirs() )
+ {
+ throw new IOException( "Could not create destination directory '"
+ + destination.getAbsolutePath() + "'." );
+ }
+ copyDirectoryStructure( file, destination );
+ }
+ }
+ else
+ {
+ throw new IOException( "Unknown file type: " + file.getAbsolutePath() );
+ }
+ }
+ }
+
+ public void testV4PomConvert()
+ throws Exception
+ {
+ // test that it is copied as is
+
+ Artifact artifact = createArtifact( "test", "v4artifact", "1.0.0" );
+ ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
+ 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 ) );
+ versionMetadataFile.delete();
+
+ File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ artifactFile.delete();
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkSuccess( artifactConverter );
+
+ assertTrue( "Check artifact created", artifactFile.exists() );
+ assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
+
+ artifact = createPomArtifact( artifact );
+ File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
+ assertTrue( "Check POM created", pomFile.exists() );
+
+ compareFiles( sourcePomFile, pomFile );
+
+ assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() );
+
+ File expectedMetadataFile = getTestFile( "src/test/expected-files/v4-artifact-metadata.xml" );
+
+ compareFiles( expectedMetadataFile, artifactMetadataFile );
+
+ assertTrue( "Check snapshot metadata created", versionMetadataFile.exists() );
+
+ expectedMetadataFile = getTestFile( "src/test/expected-files/v4-version-metadata.xml" );
+
+ compareFiles( expectedMetadataFile, versionMetadataFile );
+ }
+
+ public void testV3PomConvert()
+ throws Exception
+ {
+ // test that the pom is coverted
+
+ Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0" );
+ ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
+ 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 ) );
+ versionMetadataFile.delete();
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkSuccess( artifactConverter );
+
+ File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ assertTrue( "Check artifact created", artifactFile.exists() );
+ assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
+
+ artifact = createPomArtifact( artifact );
+ File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3.pom" );
+ assertTrue( "Check POM created", pomFile.exists() );
+
+ compareFiles( expectedPomFile, pomFile );
+
+ assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() );
+
+ File expectedMetadataFile = getTestFile( "src/test/expected-files/v3-artifact-metadata.xml" );
+
+ compareFiles( expectedMetadataFile, artifactMetadataFile );
+
+ assertTrue( "Check snapshot metadata created", versionMetadataFile.exists() );
+
+ expectedMetadataFile = getTestFile( "src/test/expected-files/v3-version-metadata.xml" );
+
+ compareFiles( expectedMetadataFile, versionMetadataFile );
+ }
+
+ public void testV3PomConvertWithRelocation()
+ throws Exception
+ {
+ Artifact artifact = createArtifact( "test", "relocated-v3artifact", "1.0.0" );
+ ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
+ 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 ) );
+ versionMetadataFile.delete();
+
+ artifactConverter.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() ) );
+ 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 ) );
+ compareFiles( pomFile, testFile );
+
+ Artifact orig = createArtifact( "test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom" );
+ artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( orig ) );
+ assertTrue( "Check if relocation artifact pom is created", artifactFile.exists() );
+ testFile = getTestFile( "src/test/expected-files/" + targetRepository.pathOf( orig ) );
+ compareFiles( artifactFile, testFile );
+ }
+
+ public void testV3PomWarningsOnConvert()
+ throws Exception
+ {
+ // test that the pom is converted but that warnings are reported
+
+ Artifact artifact = createArtifact( "test", "v3-warnings-artifact", "1.0.0" );
+ ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
+ 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 ) );
+ versionMetadataFile.delete();
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkWarnings( artifactConverter, 2 );
+
+ File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ assertTrue( "Check artifact created", artifactFile.exists() );
+ assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
+
+ artifact = createPomArtifact( artifact );
+ File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-warnings.pom" );
+ assertTrue( "Check POM created", pomFile.exists() );
+
+ compareFiles( expectedPomFile, pomFile );
+
+ // TODO: check 2 warnings (extend and versions) matched on i18n key
+ }
+
+ private void doTestV4SnapshotPomConvert( String version, String expectedMetadataFileName )
+ throws Exception
+ {
+ // test that it is copied as is
+
+ Artifact artifact = createArtifact( "test", "v4artifact", version );
+ ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
+ 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 ) );
+ snapshotMetadataFile.delete();
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkSuccess( artifactConverter );
+
+ File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ assertTrue( "Check artifact created", artifactFile.exists() );
+ assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
+
+ artifact = createPomArtifact( artifact );
+ File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
+ assertTrue( "Check POM created", pomFile.exists() );
+
+ compareFiles( sourcePomFile, pomFile );
+
+ assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() );
+
+ File expectedMetadataFile = getTestFile( "src/test/expected-files/v4-snapshot-artifact-metadata.xml" );
+
+ compareFiles( expectedMetadataFile, artifactMetadataFile );
+
+ assertTrue( "Check snapshot metadata created", snapshotMetadataFile.exists() );
+
+ expectedMetadataFile = getTestFile( expectedMetadataFileName );
+
+ compareFiles( expectedMetadataFile, snapshotMetadataFile );
+ }
+
+ public void testV3SnapshotPomConvert()
+ throws Exception
+ {
+ // test that the pom is coverted
+
+ Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0-SNAPSHOT" );
+ ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
+ 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 ) );
+ snapshotMetadataFile.delete();
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkSuccess( artifactConverter );
+
+ File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ assertTrue( "Check artifact created", artifactFile.exists() );
+ assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
+
+ artifact = createPomArtifact( artifact );
+ File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-snapshot.pom" );
+ assertTrue( "Check POM created", pomFile.exists() );
+
+ compareFiles( expectedPomFile, pomFile );
+
+ assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() );
+
+ File expectedMetadataFile = getTestFile( "src/test/expected-files/v3-snapshot-artifact-metadata.xml" );
+
+ compareFiles( expectedMetadataFile, artifactMetadataFile );
+
+ assertTrue( "Check snapshot metadata created", snapshotMetadataFile.exists() );
+
+ expectedMetadataFile = getTestFile( "src/test/expected-files/v3-snapshot-metadata.xml" );
+
+ compareFiles( expectedMetadataFile, snapshotMetadataFile );
+ }
+
+ public void testV4SnapshotPomConvert()
+ throws Exception
+ {
+ doTestV4SnapshotPomConvert( "1.0.0-SNAPSHOT", "src/test/expected-files/v4-snapshot-metadata.xml" );
+
+ assertTrue( true );
+ }
+
+ public void testV4TimestampedSnapshotPomConvert()
+ throws Exception
+ {
+ doTestV4SnapshotPomConvert( "1.0.0-20060111.120115-1",
+ "src/test/expected-files/v4-timestamped-snapshot-metadata.xml" );
+
+ assertTrue( true );
+ }
+
+ 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" ) );
+ artifactConverter.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();
+
+ File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ assertTrue( "Check artifact created", artifactFile.exists() );
+ 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 );
+ */
+ }
+
+ public void testV3TimestampedSnapshotPomConvert()
+ throws Exception
+ {
+ // test that the pom is coverted
+
+ 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 ) );
+ artifactMetadataFile.delete();
+
+ ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
+ File snapshotMetadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
+ snapshotMetadataFile.delete();
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkSuccess( artifactConverter );
+
+ File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ assertTrue( "Check artifact created", artifactFile.exists() );
+ assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
+
+ artifact = createPomArtifact( artifact );
+ File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-timestamped-snapshot.pom" );
+ assertTrue( "Check POM created", pomFile.exists() );
+
+ compareFiles( expectedPomFile, pomFile );
+
+ assertTrue( "Check artifact snapshotMetadata created", artifactMetadataFile.exists() );
+
+ File expectedMetadataFile = getTestFile( "src/test/expected-files/v3-snapshot-artifact-metadata.xml" );
+
+ compareFiles( expectedMetadataFile, artifactMetadataFile );
+
+ assertTrue( "Check snapshot snapshotMetadata created", snapshotMetadataFile.exists() );
+
+ expectedMetadataFile = getTestFile( "src/test/expected-files/v3-timestamped-snapshot-metadata.xml" );
+
+ compareFiles( expectedMetadataFile, snapshotMetadataFile );
+ }
+
+ public void testNoPomConvert()
+ throws Exception
+ {
+ // test that a POM is not created when there was none at the source
+
+ Artifact artifact = createArtifact( "test", "noPomArtifact", "1.0.0" );
+ artifactConverter.convert( artifact, targetRepository );
+ checkWarnings( artifactConverter, 1 );
+
+ assertHasWarningReason( artifactConverter, Messages.getString( "warning.missing.pom" ) );
+
+ File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ assertTrue( "Check artifact created", artifactFile.exists() );
+ assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
+
+ artifact = createPomArtifact( artifact );
+ File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
+
+ assertFalse( "Check no POM created", pomFile.exists() );
+ assertFalse( "No source POM", sourcePomFile.exists() );
+ }
+
+ public void testIncorrectSourceChecksumMd5()
+ throws Exception
+ {
+ // test that it fails when the source md5 is wrong
+
+ Artifact artifact = createArtifact( "test", "incorrectMd5Artifact", "1.0.0" );
+ File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ file.delete();
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkWarnings( artifactConverter, 2 );
+
+ assertHasWarningReason( artifactConverter, Messages.getString( "failure.incorrect.md5" ) );
+
+ assertFalse( "Check artifact not created", file.exists() );
+
+ ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
+ File metadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( metadata ) );
+ assertFalse( "Check metadata not created", metadataFile.exists() );
+ }
+
+ public void testIncorrectSourceChecksumSha1()
+ throws Exception
+ {
+ // test that it fails when the source sha1 is wrong
+
+ Artifact artifact = createArtifact( "test", "incorrectSha1Artifact", "1.0.0" );
+ File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ file.delete();
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkWarnings( artifactConverter, 2 );
+
+ assertHasWarningReason( artifactConverter, Messages.getString( "failure.incorrect.sha1" ) );
+
+ assertFalse( "Check artifact not created", file.exists() );
+
+ ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
+ File metadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( metadata ) );
+ assertFalse( "Check metadata not created", metadataFile.exists() );
+ }
+
+ public void testUnmodifiedArtifact()
+ throws Exception, InterruptedException
+ {
+ // test the unmodified artifact is untouched
+
+ Artifact artifact = createArtifact( "test", "unmodified-artifact", "1.0.0" );
+ Artifact pomArtifact = createPomArtifact( artifact );
+
+ File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
+ File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) );
+ File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) );
+
+ assertTrue( "Check target file exists", targetFile.exists() );
+ assertTrue( "Check target POM exists", targetPomFile.exists() );
+
+ sourceFile.setLastModified( System.currentTimeMillis() );
+ sourcePomFile.setLastModified( System.currentTimeMillis() );
+
+ long origTime = targetFile.lastModified();
+ long origPomTime = targetPomFile.lastModified();
+
+ // Need to guarantee last modified is not equal
+ Thread.sleep( SLEEP_MILLIS );
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkSuccess( artifactConverter );
+
+ compareFiles( sourceFile, targetFile );
+ compareFiles( sourcePomFile, targetPomFile );
+
+ assertEquals( "Check artifact unmodified", origTime, targetFile.lastModified() );
+ assertEquals( "Check POM unmodified", origPomTime, targetPomFile.lastModified() );
+ }
+
+ public void testModifedArtifactFails()
+ throws Exception
+ {
+ // test that it fails when the source artifact has changed and is different to the existing artifact in the
+ // target repository
+
+ Artifact artifact = createArtifact( "test", "modified-artifact", "1.0.0" );
+ Artifact pomArtifact = createPomArtifact( artifact );
+
+ File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
+ File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) );
+ File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) );
+
+ assertTrue( "Check target file exists", targetFile.exists() );
+ assertTrue( "Check target POM exists", targetPomFile.exists() );
+
+ sourceFile.setLastModified( System.currentTimeMillis() );
+ sourcePomFile.setLastModified( System.currentTimeMillis() );
+
+ long origTime = targetFile.lastModified();
+ long origPomTime = targetPomFile.lastModified();
+
+ // Need to guarantee last modified is not equal
+ Thread.sleep( SLEEP_MILLIS );
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkWarnings( artifactConverter, 2 );
+
+ assertHasWarningReason( artifactConverter, Messages.getString( "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 ) );
+ assertFalse( "Check metadata not created", metadataFile.exists() );
+ }
+
+ public void testForcedUnmodifiedArtifact()
+ throws Exception
+ {
+ // test unmodified artifact is still converted when set to force
+
+ artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "force-repository-converter" );
+
+ Artifact artifact = createArtifact( "test", "unmodified-artifact", "1.0.0" );
+ Artifact pomArtifact = createPomArtifact( artifact );
+
+ File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
+ File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) );
+ File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) );
+
+ SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd", Locale.getDefault() );
+ long origTime = dateFormat.parse( "2006-03-03" ).getTime();
+ targetFile.setLastModified( origTime );
+ targetPomFile.setLastModified( origTime );
+
+ sourceFile.setLastModified( dateFormat.parse( "2006-01-01" ).getTime() );
+ sourcePomFile.setLastModified( dateFormat.parse( "2006-02-02" ).getTime() );
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkSuccess( artifactConverter );
+
+ compareFiles( sourceFile, targetFile );
+ compareFiles( sourcePomFile, targetPomFile );
+
+ assertFalse( "Check modified", origTime == targetFile.lastModified() );
+ assertFalse( "Check modified", origTime == targetPomFile.lastModified() );
+
+ ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
+ File metadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( metadata ) );
+ assertTrue( "Check metadata created", metadataFile.exists() );
+ }
+
+ public void testDryRunSuccess()
+ throws Exception
+ {
+ // test dry run does nothing on a run that will be successful, and returns success
+
+ artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "dryrun-repository-converter" );
+
+ Artifact artifact = createArtifact( "test", "dryrun-artifact", "1.0.0" );
+ Artifact pomArtifact = createPomArtifact( artifact );
+
+ File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
+ File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) );
+ File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) );
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkSuccess( artifactConverter );
+
+ assertTrue( "Check source file exists", sourceFile.exists() );
+ assertTrue( "Check source POM exists", sourcePomFile.exists() );
+
+ assertFalse( "Check target file doesn't exist", targetFile.exists() );
+ assertFalse( "Check target POM doesn't exist", targetPomFile.exists() );
+
+ ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
+ File metadataFile = new File( targetRepository.getBasedir(), targetRepository
+ .pathOfRemoteRepositoryMetadata( metadata ) );
+ assertFalse( "Check metadata not created", metadataFile.exists() );
+ }
+
+ public void testDryRunFailure()
+ throws Exception
+ {
+ // test dry run does nothing on a run that will fail, and returns failure
+
+ artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "dryrun-repository-converter" );
+
+ Artifact artifact = createArtifact( "test", "modified-artifact", "1.0.0" );
+ Artifact pomArtifact = createPomArtifact( artifact );
+
+ File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
+ File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) );
+ File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) );
+
+ assertTrue( "Check target file exists", targetFile.exists() );
+ assertTrue( "Check target POM exists", targetPomFile.exists() );
+
+ sourceFile.setLastModified( System.currentTimeMillis() );
+ sourcePomFile.setLastModified( System.currentTimeMillis() );
+
+ long origTime = targetFile.lastModified();
+ long origPomTime = targetPomFile.lastModified();
+
+ // Need to guarantee last modified is not equal
+ Thread.sleep( SLEEP_MILLIS );
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkWarnings( artifactConverter, 2 );
+
+ assertHasWarningReason( artifactConverter, Messages.getString( "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 ) );
+ assertFalse( "Check metadata not created", metadataFile.exists() );
+ }
+
+ public void testRollbackArtifactCreated()
+ throws Exception
+ {
+ // test rollback can remove a created artifact, including checksums
+
+ Artifact artifact = createArtifact( "test", "rollback-created-artifact", "1.0.0" );
+ ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
+ 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 artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkWarnings( artifactConverter, 2 );
+
+ boolean found = false;
+ String pattern = "^" + Messages.getString( "invalid.source.pom" ).replaceFirst( "\\{0\\}", ".*" ) + "$";
+ for ( Iterator it = artifactConverter.getWarnings().values().iterator(); it.hasNext() && !found; )
+ {
+ List messages = (List) it.next();
+
+ for ( Iterator itmsgs = messages.iterator(); itmsgs.hasNext(); )
+ {
+ String message = (String) itmsgs.next();
+ if ( message.matches( pattern ) )
+ {
+ found = true;
+ break;
+ }
+ }
+ }
+
+ assertTrue( "Check failure message.", found );
+
+ assertFalse( "check artifact rolled back", artifactFile.exists() );
+ assertFalse( "check metadata rolled back", artifactMetadataFile.exists() );
+ assertFalse( "check metadata rolled back", versionMetadataFile.exists() );
+ }
+
+ public void testMultipleArtifacts()
+ throws Exception
+ {
+ // test multiple artifacts are converted
+
+ List artifacts = new ArrayList();
+ 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" ) );
+
+ for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+ {
+ Artifact arti = (Artifact) it.next();
+ artifactConverter.convert( arti, targetRepository );
+ checkSuccess( artifactConverter );
+ }
+
+ for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+ {
+ Artifact artifact = (Artifact) i.next();
+
+ File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ assertTrue( "Check artifact created", artifactFile.exists() );
+ assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
+
+ artifact = createPomArtifact( artifact );
+ File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File expectedPomFile = getTestFile( "src/test/expected-files/converted-" + artifact.getArtifactId()
+ + ".pom" );
+ assertTrue( "Check POM created", pomFile.exists() );
+
+ compareFiles( expectedPomFile, pomFile );
+ }
+ }
+
+ public void testInvalidSourceArtifactMetadata()
+ throws Exception
+ {
+ // test artifact is not converted when source metadata is invalid, and returns failure
+
+ createModernSourceRepository();
+
+ Artifact artifact = createArtifact( "test", "incorrectArtifactMetadata", "1.0.0" );
+ File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ file.delete();
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkWarnings( artifactConverter, 2 );
+
+ assertHasWarningReason( artifactConverter, Messages.getString( "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 ) );
+ assertFalse( "Check metadata not created", metadataFile.exists() );
+ }
+
+ public void testInvalidSourceSnapshotMetadata()
+ throws Exception
+ {
+ // test artifact is not converted when source snapshot metadata is invalid and returns failure
+
+ createModernSourceRepository();
+
+ Artifact artifact = createArtifact( "test", "incorrectSnapshotMetadata", "1.0.0-20060102.030405-6" );
+ File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ file.delete();
+
+ artifactConverter.convert( artifact, targetRepository );
+ checkWarnings( artifactConverter, 2 );
+
+ assertHasWarningReason( artifactConverter, Messages.getString( "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 ) );
+ assertFalse( "Check metadata not created", metadataFile.exists() );
+ }
+
+ public void testMergeArtifactMetadata()
+ throws Exception
+ {
+ // test artifact level metadata is merged when it already exists on successful conversion
+
+ Artifact artifact = createArtifact( "test", "newversion-artifact", "1.0.1" );
+ artifactConverter.convert( artifact, targetRepository );
+ checkSuccess( artifactConverter );
+
+ File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ assertTrue( "Check artifact created", artifactFile.exists() );
+ assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
+
+ artifact = createPomArtifact( artifact );
+ File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+ File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
+ assertTrue( "Check POM created", pomFile.exists() );
+
+ compareFiles( sourcePomFile, pomFile );
+
+ ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
+ 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" );
+
+ compareFiles( expectedMetadataFile, artifactMetadataFile );
+ }
+
+ public void testSourceAndTargetRepositoriesMatch()
+ throws Exception
+ {
+ // test that it fails if the same
+
+ ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+
+ sourceRepository = factory.createArtifactRepository( "source", targetRepository.getUrl(), targetRepository
+ .getLayout(), null, null );
+
+ Artifact artifact = createArtifact( "test", "repository-artifact", "1.0" );
+
+ try
+ {
+ artifactConverter.convert( artifact, targetRepository );
+ fail( "Should have failed trying to convert within the same repository" );
+ }
+ catch ( ArtifactConversionException e )
+ {
+ // expected
+ assertEquals( "check message", Messages.getString( "exception.repositories.match" ), e.getMessage() );
+ assertNull( "Check no additional cause", e.getCause() );
+ }
+ }
+
+ private Artifact createArtifact( String groupId, String artifactId, String version )
+ {
+ Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( version );
+ String baseVersion;
+ if ( matcher.matches() )
+ {
+ baseVersion = matcher.group( 1 ) + "-SNAPSHOT";
+ }
+ else
+ {
+ baseVersion = version;
+ }
+ return createArtifact( groupId, artifactId, baseVersion, version, "jar" );
+ }
+
+ 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 );
+ artifact.setRepository( sourceRepository );
+ artifact.setFile( new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ) );
+ return artifact;
+ }
+
+ private Artifact createPomArtifact( Artifact artifact )
+ {
+ return createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact
+ .getVersion(), "pom" );
+ }
+
+ private static void compareFiles( File expectedPomFile, File pomFile )
+ throws IOException
+ {
+ String expectedContent = normalizeString( AsciiFileUtil.readFile( expectedPomFile ) );
+ String targetContent = normalizeString( AsciiFileUtil.readFile( pomFile ) );
+ assertEquals( "Check file match between " + expectedPomFile + " and " + pomFile, expectedContent, targetContent );
+ }
+
+ private static String normalizeString( String path )
+ {
+ return path.trim().replaceAll( "\r\n", "\n" ).replace( '\r', '\n' ).replaceAll( "<\\?xml .+\\?>", "" );
+ }
+
+ private void checkSuccess( ArtifactConverter converter )
+ {
+ assertNotNull( "Warnings should never be null.", converter.getWarnings() );
+ assertEquals( "Should have no warnings.", 0, countWarningMessages( converter ) );
+ }
+
+ private void checkWarnings( ArtifactConverter converter, int count )
+ {
+ assertNotNull( "Warnings should never be null.", converter.getWarnings() );
+ assertEquals( "Should have some warnings.", count, countWarningMessages( converter ) );
+ }
+
+ private int countWarningMessages( ArtifactConverter converter )
+ {
+ int count = 0;
+ for ( Iterator it = converter.getWarnings().values().iterator(); it.hasNext(); )
+ {
+ List values = (List) it.next();
+ count += values.size();
+ }
+ return count;
+ }
+
+ private void assertHasWarningReason( ArtifactConverter converter, String reason )
+ {
+ assertNotNull( "Warnings should never be null.", converter.getWarnings() );
+ assertTrue( "Expecting 1 or more Warnings", countWarningMessages( converter ) > 0 );
+
+ for ( Iterator it = converter.getWarnings().values().iterator(); it.hasNext(); )
+ {
+ List messages = (List) it.next();
+ if ( messages.contains( reason ) )
+ {
+ /* No need to check any furthor */
+ return;
+ }
+ }
+
+ /* didn't find it. */
+
+ for ( Iterator it = converter.getWarnings().entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Entry) it.next();
+ Artifact artifact = (Artifact) entry.getKey();
+ System.out.println( "-Artifact: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
+ + artifact.getVersion() );
+ List messages = (List) entry.getValue();
+ for ( Iterator itmsgs = messages.iterator(); itmsgs.hasNext(); )
+ {
+ String message = (String) itmsgs.next();
+ System.out.println( " " + message );
+ }
+ }
+ fail( "Unable to find message <" + reason + "> in warnings." );
+ }
+
+ private void createModernSourceRepository()
+ throws Exception
+ {
+ ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+
+ 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 );
+ }
+}
+++ /dev/null
-package org.apache.maven.artifact.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.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
-import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.FileUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-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;
-
-/**
- * LegacyToDefaultConverterTest
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class LegacyToDefaultConverterTest
- extends PlexusTestCase
-{
- private ArtifactRepository sourceRepository;
-
- private ArtifactRepository targetRepository;
-
- private ArtifactConverter artifactConverter;
-
- private ArtifactFactory artifactFactory;
-
- private static final int SLEEP_MILLIS = 100;
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
-
- ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
-
- ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
-
- File sourceBase = getTestFile( "src/test/source-repository" );
- 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 );
-
- artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "legacy-to-default" );
-
- artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
- }
-
- protected void tearDown()
- throws Exception
- {
- super.tearDown();
- }
-
- private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory )
- throws IOException
- {
- if ( !sourceDirectory.exists() )
- {
- throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." );
- }
-
- File[] files = sourceDirectory.listFiles();
-
- String sourcePath = sourceDirectory.getAbsolutePath();
-
- for ( int i = 0; i < files.length; i++ )
- {
- File file = files[i];
-
- String dest = file.getAbsolutePath();
-
- dest = dest.substring( sourcePath.length() + 1 );
-
- File destination = new File( destinationDirectory, dest );
-
- if ( file.isFile() )
- {
- destination = destination.getParentFile();
-
- FileUtils.copyFileToDirectory( file, destination );
- }
- else if ( file.isDirectory() )
- {
- if ( !".svn".equals( file.getName() ) )
- {
- if ( !destination.exists() && !destination.mkdirs() )
- {
- throw new IOException( "Could not create destination directory '"
- + destination.getAbsolutePath() + "'." );
- }
- copyDirectoryStructure( file, destination );
- }
- }
- else
- {
- throw new IOException( "Unknown file type: " + file.getAbsolutePath() );
- }
- }
- }
-
- public void testV4PomConvert()
- throws Exception
- {
- // test that it is copied as is
-
- Artifact artifact = createArtifact( "test", "v4artifact", "1.0.0" );
- ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- 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 ) );
- versionMetadataFile.delete();
-
- File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- artifactFile.delete();
-
- artifactConverter.convert( artifact, targetRepository );
- checkSuccess( artifactConverter );
-
- assertTrue( "Check artifact created", artifactFile.exists() );
- assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
-
- artifact = createPomArtifact( artifact );
- File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
- assertTrue( "Check POM created", pomFile.exists() );
-
- compareFiles( sourcePomFile, pomFile );
-
- assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() );
-
- File expectedMetadataFile = getTestFile( "src/test/expected-files/v4-artifact-metadata.xml" );
-
- compareFiles( expectedMetadataFile, artifactMetadataFile );
-
- assertTrue( "Check snapshot metadata created", versionMetadataFile.exists() );
-
- expectedMetadataFile = getTestFile( "src/test/expected-files/v4-version-metadata.xml" );
-
- compareFiles( expectedMetadataFile, versionMetadataFile );
- }
-
- public void testV3PomConvert()
- throws Exception
- {
- // test that the pom is coverted
-
- Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0" );
- ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- 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 ) );
- versionMetadataFile.delete();
-
- artifactConverter.convert( artifact, targetRepository );
- checkSuccess( artifactConverter );
-
- File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- assertTrue( "Check artifact created", artifactFile.exists() );
- assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
-
- artifact = createPomArtifact( artifact );
- File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3.pom" );
- assertTrue( "Check POM created", pomFile.exists() );
-
- compareFiles( expectedPomFile, pomFile );
-
- assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() );
-
- File expectedMetadataFile = getTestFile( "src/test/expected-files/v3-artifact-metadata.xml" );
-
- compareFiles( expectedMetadataFile, artifactMetadataFile );
-
- assertTrue( "Check snapshot metadata created", versionMetadataFile.exists() );
-
- expectedMetadataFile = getTestFile( "src/test/expected-files/v3-version-metadata.xml" );
-
- compareFiles( expectedMetadataFile, versionMetadataFile );
- }
-
- public void testV3PomConvertWithRelocation()
- throws Exception
- {
- Artifact artifact = createArtifact( "test", "relocated-v3artifact", "1.0.0" );
- ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- 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 ) );
- versionMetadataFile.delete();
-
- artifactConverter.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() ) );
- 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 ) );
- compareFiles( pomFile, testFile );
-
- Artifact orig = createArtifact( "test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom" );
- artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( orig ) );
- assertTrue( "Check if relocation artifact pom is created", artifactFile.exists() );
- testFile = getTestFile( "src/test/expected-files/" + targetRepository.pathOf( orig ) );
- compareFiles( artifactFile, testFile );
- }
-
- public void testV3PomWarningsOnConvert()
- throws Exception
- {
- // test that the pom is converted but that warnings are reported
-
- Artifact artifact = createArtifact( "test", "v3-warnings-artifact", "1.0.0" );
- ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- 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 ) );
- versionMetadataFile.delete();
-
- artifactConverter.convert( artifact, targetRepository );
- checkWarnings( artifactConverter, 2 );
-
- File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- assertTrue( "Check artifact created", artifactFile.exists() );
- assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
-
- artifact = createPomArtifact( artifact );
- File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-warnings.pom" );
- assertTrue( "Check POM created", pomFile.exists() );
-
- compareFiles( expectedPomFile, pomFile );
-
- // TODO: check 2 warnings (extend and versions) matched on i18n key
- }
-
- private void doTestV4SnapshotPomConvert( String version, String expectedMetadataFileName )
- throws Exception
- {
- // test that it is copied as is
-
- Artifact artifact = createArtifact( "test", "v4artifact", version );
- ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- 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 ) );
- snapshotMetadataFile.delete();
-
- artifactConverter.convert( artifact, targetRepository );
- checkSuccess( artifactConverter );
-
- File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- assertTrue( "Check artifact created", artifactFile.exists() );
- assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
-
- artifact = createPomArtifact( artifact );
- File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
- assertTrue( "Check POM created", pomFile.exists() );
-
- compareFiles( sourcePomFile, pomFile );
-
- assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() );
-
- File expectedMetadataFile = getTestFile( "src/test/expected-files/v4-snapshot-artifact-metadata.xml" );
-
- compareFiles( expectedMetadataFile, artifactMetadataFile );
-
- assertTrue( "Check snapshot metadata created", snapshotMetadataFile.exists() );
-
- expectedMetadataFile = getTestFile( expectedMetadataFileName );
-
- compareFiles( expectedMetadataFile, snapshotMetadataFile );
- }
-
- public void testV3SnapshotPomConvert()
- throws Exception
- {
- // test that the pom is coverted
-
- Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0-SNAPSHOT" );
- ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- 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 ) );
- snapshotMetadataFile.delete();
-
- artifactConverter.convert( artifact, targetRepository );
- checkSuccess( artifactConverter );
-
- File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- assertTrue( "Check artifact created", artifactFile.exists() );
- assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
-
- artifact = createPomArtifact( artifact );
- File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-snapshot.pom" );
- assertTrue( "Check POM created", pomFile.exists() );
-
- compareFiles( expectedPomFile, pomFile );
-
- assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() );
-
- File expectedMetadataFile = getTestFile( "src/test/expected-files/v3-snapshot-artifact-metadata.xml" );
-
- compareFiles( expectedMetadataFile, artifactMetadataFile );
-
- assertTrue( "Check snapshot metadata created", snapshotMetadataFile.exists() );
-
- expectedMetadataFile = getTestFile( "src/test/expected-files/v3-snapshot-metadata.xml" );
-
- compareFiles( expectedMetadataFile, snapshotMetadataFile );
- }
-
- public void testV4SnapshotPomConvert()
- throws Exception
- {
- doTestV4SnapshotPomConvert( "1.0.0-SNAPSHOT", "src/test/expected-files/v4-snapshot-metadata.xml" );
-
- assertTrue( true );
- }
-
- public void testV4TimestampedSnapshotPomConvert()
- throws Exception
- {
- doTestV4SnapshotPomConvert( "1.0.0-20060111.120115-1",
- "src/test/expected-files/v4-timestamped-snapshot-metadata.xml" );
-
- assertTrue( true );
- }
-
- 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" ) );
- artifactConverter.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();
-
- File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- assertTrue( "Check artifact created", artifactFile.exists() );
- 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 );
- */
- }
-
- public void testV3TimestampedSnapshotPomConvert()
- throws Exception
- {
- // test that the pom is coverted
-
- 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 ) );
- artifactMetadataFile.delete();
-
- ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File snapshotMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
- snapshotMetadataFile.delete();
-
- artifactConverter.convert( artifact, targetRepository );
- checkSuccess( artifactConverter );
-
- File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- assertTrue( "Check artifact created", artifactFile.exists() );
- assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
-
- artifact = createPomArtifact( artifact );
- File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-timestamped-snapshot.pom" );
- assertTrue( "Check POM created", pomFile.exists() );
-
- compareFiles( expectedPomFile, pomFile );
-
- assertTrue( "Check artifact snapshotMetadata created", artifactMetadataFile.exists() );
-
- File expectedMetadataFile = getTestFile( "src/test/expected-files/v3-snapshot-artifact-metadata.xml" );
-
- compareFiles( expectedMetadataFile, artifactMetadataFile );
-
- assertTrue( "Check snapshot snapshotMetadata created", snapshotMetadataFile.exists() );
-
- expectedMetadataFile = getTestFile( "src/test/expected-files/v3-timestamped-snapshot-metadata.xml" );
-
- compareFiles( expectedMetadataFile, snapshotMetadataFile );
- }
-
- public void testNoPomConvert()
- throws Exception
- {
- // test that a POM is not created when there was none at the source
-
- Artifact artifact = createArtifact( "test", "noPomArtifact", "1.0.0" );
- artifactConverter.convert( artifact, targetRepository );
- checkWarnings( artifactConverter, 1 );
-
- assertHasWarningReason( artifactConverter, Messages.getString( "warning.missing.pom" ) );
-
- File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- assertTrue( "Check artifact created", artifactFile.exists() );
- assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
-
- artifact = createPomArtifact( artifact );
- File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
-
- assertFalse( "Check no POM created", pomFile.exists() );
- assertFalse( "No source POM", sourcePomFile.exists() );
- }
-
- public void testIncorrectSourceChecksumMd5()
- throws Exception
- {
- // test that it fails when the source md5 is wrong
-
- Artifact artifact = createArtifact( "test", "incorrectMd5Artifact", "1.0.0" );
- File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- file.delete();
-
- artifactConverter.convert( artifact, targetRepository );
- checkWarnings( artifactConverter, 2 );
-
- assertHasWarningReason( artifactConverter, Messages.getString( "failure.incorrect.md5" ) );
-
- assertFalse( "Check artifact not created", file.exists() );
-
- ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( metadata ) );
- assertFalse( "Check metadata not created", metadataFile.exists() );
- }
-
- public void testIncorrectSourceChecksumSha1()
- throws Exception
- {
- // test that it fails when the source sha1 is wrong
-
- Artifact artifact = createArtifact( "test", "incorrectSha1Artifact", "1.0.0" );
- File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- file.delete();
-
- artifactConverter.convert( artifact, targetRepository );
- checkWarnings( artifactConverter, 2 );
-
- assertHasWarningReason( artifactConverter, Messages.getString( "failure.incorrect.sha1" ) );
-
- assertFalse( "Check artifact not created", file.exists() );
-
- ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( metadata ) );
- assertFalse( "Check metadata not created", metadataFile.exists() );
- }
-
- public void testUnmodifiedArtifact()
- throws Exception, InterruptedException
- {
- // test the unmodified artifact is untouched
-
- Artifact artifact = createArtifact( "test", "unmodified-artifact", "1.0.0" );
- Artifact pomArtifact = createPomArtifact( artifact );
-
- File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
- File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) );
- File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) );
-
- assertTrue( "Check target file exists", targetFile.exists() );
- assertTrue( "Check target POM exists", targetPomFile.exists() );
-
- sourceFile.setLastModified( System.currentTimeMillis() );
- sourcePomFile.setLastModified( System.currentTimeMillis() );
-
- long origTime = targetFile.lastModified();
- long origPomTime = targetPomFile.lastModified();
-
- // Need to guarantee last modified is not equal
- Thread.sleep( SLEEP_MILLIS );
-
- artifactConverter.convert( artifact, targetRepository );
- checkSuccess( artifactConverter );
-
- compareFiles( sourceFile, targetFile );
- compareFiles( sourcePomFile, targetPomFile );
-
- assertEquals( "Check artifact unmodified", origTime, targetFile.lastModified() );
- assertEquals( "Check POM unmodified", origPomTime, targetPomFile.lastModified() );
- }
-
- public void testModifedArtifactFails()
- throws Exception
- {
- // test that it fails when the source artifact has changed and is different to the existing artifact in the
- // target repository
-
- Artifact artifact = createArtifact( "test", "modified-artifact", "1.0.0" );
- Artifact pomArtifact = createPomArtifact( artifact );
-
- File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
- File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) );
- File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) );
-
- assertTrue( "Check target file exists", targetFile.exists() );
- assertTrue( "Check target POM exists", targetPomFile.exists() );
-
- sourceFile.setLastModified( System.currentTimeMillis() );
- sourcePomFile.setLastModified( System.currentTimeMillis() );
-
- long origTime = targetFile.lastModified();
- long origPomTime = targetPomFile.lastModified();
-
- // Need to guarantee last modified is not equal
- Thread.sleep( SLEEP_MILLIS );
-
- artifactConverter.convert( artifact, targetRepository );
- checkWarnings( artifactConverter, 2 );
-
- assertHasWarningReason( artifactConverter, Messages.getString( "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 ) );
- assertFalse( "Check metadata not created", metadataFile.exists() );
- }
-
- public void testForcedUnmodifiedArtifact()
- throws Exception
- {
- // test unmodified artifact is still converted when set to force
-
- artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "force-repository-converter" );
-
- Artifact artifact = createArtifact( "test", "unmodified-artifact", "1.0.0" );
- Artifact pomArtifact = createPomArtifact( artifact );
-
- File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
- File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) );
- File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) );
-
- SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd", Locale.getDefault() );
- long origTime = dateFormat.parse( "2006-03-03" ).getTime();
- targetFile.setLastModified( origTime );
- targetPomFile.setLastModified( origTime );
-
- sourceFile.setLastModified( dateFormat.parse( "2006-01-01" ).getTime() );
- sourcePomFile.setLastModified( dateFormat.parse( "2006-02-02" ).getTime() );
-
- artifactConverter.convert( artifact, targetRepository );
- checkSuccess( artifactConverter );
-
- compareFiles( sourceFile, targetFile );
- compareFiles( sourcePomFile, targetPomFile );
-
- assertFalse( "Check modified", origTime == targetFile.lastModified() );
- assertFalse( "Check modified", origTime == targetPomFile.lastModified() );
-
- ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( metadata ) );
- assertTrue( "Check metadata created", metadataFile.exists() );
- }
-
- public void testDryRunSuccess()
- throws Exception
- {
- // test dry run does nothing on a run that will be successful, and returns success
-
- artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "dryrun-repository-converter" );
-
- Artifact artifact = createArtifact( "test", "dryrun-artifact", "1.0.0" );
- Artifact pomArtifact = createPomArtifact( artifact );
-
- File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
- File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) );
- File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) );
-
- artifactConverter.convert( artifact, targetRepository );
- checkSuccess( artifactConverter );
-
- assertTrue( "Check source file exists", sourceFile.exists() );
- assertTrue( "Check source POM exists", sourcePomFile.exists() );
-
- assertFalse( "Check target file doesn't exist", targetFile.exists() );
- assertFalse( "Check target POM doesn't exist", targetPomFile.exists() );
-
- ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( metadata ) );
- assertFalse( "Check metadata not created", metadataFile.exists() );
- }
-
- public void testDryRunFailure()
- throws Exception
- {
- // test dry run does nothing on a run that will fail, and returns failure
-
- artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "dryrun-repository-converter" );
-
- Artifact artifact = createArtifact( "test", "modified-artifact", "1.0.0" );
- Artifact pomArtifact = createPomArtifact( artifact );
-
- File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
- File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) );
- File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) );
-
- assertTrue( "Check target file exists", targetFile.exists() );
- assertTrue( "Check target POM exists", targetPomFile.exists() );
-
- sourceFile.setLastModified( System.currentTimeMillis() );
- sourcePomFile.setLastModified( System.currentTimeMillis() );
-
- long origTime = targetFile.lastModified();
- long origPomTime = targetPomFile.lastModified();
-
- // Need to guarantee last modified is not equal
- Thread.sleep( SLEEP_MILLIS );
-
- artifactConverter.convert( artifact, targetRepository );
- checkWarnings( artifactConverter, 2 );
-
- assertHasWarningReason( artifactConverter, Messages.getString( "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 ) );
- assertFalse( "Check metadata not created", metadataFile.exists() );
- }
-
- public void testRollbackArtifactCreated()
- throws Exception
- {
- // test rollback can remove a created artifact, including checksums
-
- Artifact artifact = createArtifact( "test", "rollback-created-artifact", "1.0.0" );
- ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- 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 artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
-
- artifactConverter.convert( artifact, targetRepository );
- checkWarnings( artifactConverter, 2 );
-
- boolean found = false;
- String pattern = "^" + Messages.getString( "invalid.source.pom" ).replaceFirst( "\\{0\\}", ".*" ) + "$";
- for ( Iterator it = artifactConverter.getWarnings().values().iterator(); it.hasNext() && !found; )
- {
- List messages = (List) it.next();
-
- for ( Iterator itmsgs = messages.iterator(); itmsgs.hasNext(); )
- {
- String message = (String) itmsgs.next();
- if ( message.matches( pattern ) )
- {
- found = true;
- break;
- }
- }
- }
-
- assertTrue( "Check failure message.", found );
-
- assertFalse( "check artifact rolled back", artifactFile.exists() );
- assertFalse( "check metadata rolled back", artifactMetadataFile.exists() );
- assertFalse( "check metadata rolled back", versionMetadataFile.exists() );
- }
-
- public void testMultipleArtifacts()
- throws Exception
- {
- // test multiple artifacts are converted
-
- List artifacts = new ArrayList();
- 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" ) );
-
- for ( Iterator it = artifacts.iterator(); it.hasNext(); )
- {
- Artifact arti = (Artifact) it.next();
- artifactConverter.convert( arti, targetRepository );
- checkSuccess( artifactConverter );
- }
-
- for ( Iterator i = artifacts.iterator(); i.hasNext(); )
- {
- Artifact artifact = (Artifact) i.next();
-
- File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- assertTrue( "Check artifact created", artifactFile.exists() );
- assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
-
- artifact = createPomArtifact( artifact );
- File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File expectedPomFile = getTestFile( "src/test/expected-files/converted-" + artifact.getArtifactId()
- + ".pom" );
- assertTrue( "Check POM created", pomFile.exists() );
-
- compareFiles( expectedPomFile, pomFile );
- }
- }
-
- public void testInvalidSourceArtifactMetadata()
- throws Exception
- {
- // test artifact is not converted when source metadata is invalid, and returns failure
-
- createModernSourceRepository();
-
- Artifact artifact = createArtifact( "test", "incorrectArtifactMetadata", "1.0.0" );
- File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- file.delete();
-
- artifactConverter.convert( artifact, targetRepository );
- checkWarnings( artifactConverter, 2 );
-
- assertHasWarningReason( artifactConverter, Messages.getString( "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 ) );
- assertFalse( "Check metadata not created", metadataFile.exists() );
- }
-
- public void testInvalidSourceSnapshotMetadata()
- throws Exception
- {
- // test artifact is not converted when source snapshot metadata is invalid and returns failure
-
- createModernSourceRepository();
-
- Artifact artifact = createArtifact( "test", "incorrectSnapshotMetadata", "1.0.0-20060102.030405-6" );
- File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- file.delete();
-
- artifactConverter.convert( artifact, targetRepository );
- checkWarnings( artifactConverter, 2 );
-
- assertHasWarningReason( artifactConverter, Messages.getString( "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 ) );
- assertFalse( "Check metadata not created", metadataFile.exists() );
- }
-
- public void testMergeArtifactMetadata()
- throws Exception
- {
- // test artifact level metadata is merged when it already exists on successful conversion
-
- Artifact artifact = createArtifact( "test", "newversion-artifact", "1.0.1" );
- artifactConverter.convert( artifact, targetRepository );
- checkSuccess( artifactConverter );
-
- File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- assertTrue( "Check artifact created", artifactFile.exists() );
- assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
-
- artifact = createPomArtifact( artifact );
- File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
- assertTrue( "Check POM created", pomFile.exists() );
-
- compareFiles( sourcePomFile, pomFile );
-
- ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- 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" );
-
- compareFiles( expectedMetadataFile, artifactMetadataFile );
- }
-
- public void testSourceAndTargetRepositoriesMatch()
- throws Exception
- {
- // test that it fails if the same
-
- ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
-
- sourceRepository = factory.createArtifactRepository( "source", targetRepository.getUrl(), targetRepository
- .getLayout(), null, null );
-
- Artifact artifact = createArtifact( "test", "repository-artifact", "1.0" );
-
- try
- {
- artifactConverter.convert( artifact, targetRepository );
- fail( "Should have failed trying to convert within the same repository" );
- }
- catch ( ArtifactConversionException e )
- {
- // expected
- assertEquals( "check message", Messages.getString( "exception.repositories.match" ), e.getMessage() );
- assertNull( "Check no additional cause", e.getCause() );
- }
- }
-
- private Artifact createArtifact( String groupId, String artifactId, String version )
- {
- Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( version );
- String baseVersion;
- if ( matcher.matches() )
- {
- baseVersion = matcher.group( 1 ) + "-SNAPSHOT";
- }
- else
- {
- baseVersion = version;
- }
- return createArtifact( groupId, artifactId, baseVersion, version, "jar" );
- }
-
- 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 );
- artifact.setRepository( sourceRepository );
- artifact.setFile( new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ) );
- return artifact;
- }
-
- private Artifact createPomArtifact( Artifact artifact )
- {
- return createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact
- .getVersion(), "pom" );
- }
-
- private static void compareFiles( File expectedPomFile, File pomFile )
- throws IOException
- {
- String expectedContent = normalizeString( AsciiFileUtil.readFile( expectedPomFile ) );
- String targetContent = normalizeString( AsciiFileUtil.readFile( pomFile ) );
- assertEquals( "Check file match between " + expectedPomFile + " and " + pomFile, expectedContent, targetContent );
- }
-
- private static String normalizeString( String path )
- {
- return path.trim().replaceAll( "\r\n", "\n" ).replace( '\r', '\n' ).replaceAll( "<\\?xml .+\\?>", "" );
- }
-
- private void checkSuccess( ArtifactConverter converter )
- {
- assertNotNull( "Warnings should never be null.", converter.getWarnings() );
- assertEquals( "Should have no warnings.", 0, countWarningMessages( converter ) );
- }
-
- private void checkWarnings( ArtifactConverter converter, int count )
- {
- assertNotNull( "Warnings should never be null.", converter.getWarnings() );
- assertEquals( "Should have some warnings.", count, countWarningMessages( converter ) );
- }
-
- private int countWarningMessages( ArtifactConverter converter )
- {
- int count = 0;
- for ( Iterator it = converter.getWarnings().values().iterator(); it.hasNext(); )
- {
- List values = (List) it.next();
- count += values.size();
- }
- return count;
- }
-
- private void assertHasWarningReason( ArtifactConverter converter, String reason )
- {
- assertNotNull( "Warnings should never be null.", converter.getWarnings() );
- assertTrue( "Expecting 1 or more Warnings", countWarningMessages( converter ) > 0 );
-
- for ( Iterator it = converter.getWarnings().values().iterator(); it.hasNext(); )
- {
- List messages = (List) it.next();
- if ( messages.contains( reason ) )
- {
- /* No need to check any furthor */
- return;
- }
- }
-
- /* didn't find it. */
-
- for ( Iterator it = converter.getWarnings().entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Entry) it.next();
- Artifact artifact = (Artifact) entry.getKey();
- System.out.println( "-Artifact: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
- + artifact.getVersion() );
- List messages = (List) entry.getValue();
- for ( Iterator itmsgs = messages.iterator(); itmsgs.hasNext(); )
- {
- String message = (String) itmsgs.next();
- System.out.println( " " + message );
- }
- }
- fail( "Unable to find message <" + reason + "> in warnings." );
- }
-
- private void createModernSourceRepository()
- throws Exception
- {
- ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
-
- 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 );
- }
-}
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ ~ 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.
+-->
+
+<component-set>
+ <components>
+
+ <component>
+ <role>org.apache.maven.archiva.converter.artifact.ArtifactConverter</role>
+ <role-hint>force-repository-converter</role-hint>
+ <implementation>org.apache.maven.archiva.converter.artifact.LegacyToDefaultConverter</implementation>
+ <description>LegacyToDefaultConverter</description>
+ <requirements>
+ <requirement>
+ <role>org.codehaus.plexus.digest.Digester</role>
+ <field-name>digesters</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.model.converter.ModelConverter</role>
+ <field-name>translator</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.artifact.factory.ArtifactFactory</role>
+ <field-name>artifactFactory</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
+ <field-name>artifactHandlerManager</field-name>
+ </requirement>
+ </requirements>
+ <configuration>
+ <force>true</force>
+ <dryrun>false</dryrun>
+ </configuration>
+ </component>
+
+ <component>
+ <role>org.apache.maven.archiva.converter.artifact.ArtifactConverter</role>
+ <role-hint>dryrun-repository-converter</role-hint>
+ <implementation>org.apache.maven.archiva.converter.artifact.LegacyToDefaultConverter</implementation>
+ <description>LegacyToDefaultConverter</description>
+ <requirements>
+ <requirement>
+ <role>org.codehaus.plexus.digest.Digester</role>
+ <field-name>digesters</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.model.converter.ModelConverter</role>
+ <field-name>translator</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.artifact.factory.ArtifactFactory</role>
+ <field-name>artifactFactory</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
+ <field-name>artifactHandlerManager</field-name>
+ </requirement>
+ </requirements>
+ <configuration>
+ <force>false</force>
+ <dryrun>true</dryrun>
+ </configuration>
+ </component>
+
+
+
+ </components>
+</component-set>
+++ /dev/null
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- ~ 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.
--->
-
-<component-set>
- <components>
-
- <component>
- <role>org.apache.maven.artifact.converter.ArtifactConverter</role>
- <role-hint>force-repository-converter</role-hint>
- <implementation>org.apache.maven.artifact.converter.LegacyToDefaultConverter</implementation>
- <description>LegacyToDefaultConverter</description>
- <requirements>
- <requirement>
- <role>org.codehaus.plexus.digest.Digester</role>
- <field-name>digesters</field-name>
- </requirement>
- <requirement>
- <role>org.apache.maven.model.converter.ModelConverter</role>
- <field-name>translator</field-name>
- </requirement>
- <requirement>
- <role>org.apache.maven.artifact.factory.ArtifactFactory</role>
- <field-name>artifactFactory</field-name>
- </requirement>
- <requirement>
- <role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
- <field-name>artifactHandlerManager</field-name>
- </requirement>
- </requirements>
- <configuration>
- <force>true</force>
- <dryrun>false</dryrun>
- </configuration>
- </component>
-
- <component>
- <role>org.apache.maven.artifact.converter.ArtifactConverter</role>
- <role-hint>dryrun-repository-converter</role-hint>
- <implementation>org.apache.maven.artifact.converter.LegacyToDefaultConverter</implementation>
- <description>LegacyToDefaultConverter</description>
- <requirements>
- <requirement>
- <role>org.codehaus.plexus.digest.Digester</role>
- <field-name>digesters</field-name>
- </requirement>
- <requirement>
- <role>org.apache.maven.model.converter.ModelConverter</role>
- <field-name>translator</field-name>
- </requirement>
- <requirement>
- <role>org.apache.maven.artifact.factory.ArtifactFactory</role>
- <field-name>artifactFactory</field-name>
- </requirement>
- <requirement>
- <role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
- <field-name>artifactHandlerManager</field-name>
- </requirement>
- </requirements>
- <configuration>
- <force>false</force>
- <dryrun>true</dryrun>
- </configuration>
- </component>
-
-
-
- </components>
-</component-set>
<artifactId>archiva-repository-layer</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-artifact-converter</artifactId>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-artifact-converter</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
import org.apache.maven.archiva.consumers.ConsumerException;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
-import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
+import org.apache.maven.archiva.converter.artifact.ArtifactConversionException;
+import org.apache.maven.archiva.converter.artifact.ArtifactConverter;
import org.apache.maven.archiva.model.ArchivaRepository;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
import org.apache.maven.archiva.repository.layout.LayoutException;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.converter.ArtifactConversionException;
-import org.apache.maven.artifact.converter.ArtifactConverter;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-shared-components</artifactId>
- <version>6</version>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-base</artifactId>
+ <version>1.0-alpha-1-SNAPSHOT</version>
</parent>
- <artifactId>maven-transaction</artifactId>
- <version>1.0-alpha-2-SNAPSHOT</version>
- <name>Maven Transactions</name>
+ <artifactId>archiva-transaction</artifactId>
+ <name>Archiva Transactions</name>
<description>API for managing transaction.</description>
<dependencies>
<dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
- <version>1.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
- <version>1.0-alpha-9</version>
</dependency>
</dependencies>
</project>
--- /dev/null
+package org.apache.maven.archiva.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 org.codehaus.plexus.digest.Digester;
+import org.codehaus.plexus.digest.DigesterException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Abstract class for the TransactionEvents
+ *
+ * @author Edwin Punzalan
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public abstract class AbstractTransactionEvent
+ extends AbstractLogEnabled
+ implements TransactionEvent
+{
+ private Map backups = new HashMap();;
+
+ private List createdDirs = new ArrayList();
+
+ private List createdFiles = new ArrayList();
+
+ /** {@link List}<{@link Digester}> */
+ private List digesters;
+
+ protected AbstractTransactionEvent()
+ {
+ this( new ArrayList( 0 ) );
+ }
+
+ protected AbstractTransactionEvent( List digesters )
+ {
+ this.digesters = digesters;
+ }
+
+ protected List getDigesters()
+ {
+ return digesters;
+ }
+
+ /**
+ * Method that creates a directory as well as all the parent directories needed
+ *
+ * @param dir The File directory to be created
+ * @throws IOException when an unrecoverable error occurred
+ */
+ protected void mkDirs( File dir )
+ throws IOException
+ {
+ List createDirs = new ArrayList();
+
+ File parent = dir;
+ while ( !parent.exists() || !parent.isDirectory() )
+ {
+ createDirs.add( parent );
+
+ parent = parent.getParentFile();
+ }
+
+ while ( !createDirs.isEmpty() )
+ {
+ File directory = (File) createDirs.remove( createDirs.size() - 1 );
+
+ if ( directory.mkdir() )
+ {
+ createdDirs.add( directory );
+ }
+ else
+ {
+ throw new IOException( "Failed to create directory: " + directory.getAbsolutePath() );
+ }
+ }
+ }
+
+ protected void revertMkDirs()
+ throws IOException
+ {
+ if ( createdDirs != null )
+ {
+ Collections.reverse( createdDirs );
+
+ while ( !createdDirs.isEmpty() )
+ {
+ File dir = (File) createdDirs.remove( 0 );
+
+ if ( dir.isDirectory() && dir.list().length == 0 )
+ {
+ FileUtils.deleteDirectory( dir );
+ }
+ else
+ {
+ //cannot rollback created directory if it still contains files
+ break;
+ }
+ }
+ }
+ }
+
+ protected void revertFilesCreated()
+ throws IOException
+ {
+ Iterator it = createdFiles.iterator();
+ while ( it.hasNext() )
+ {
+ File file = (File) it.next();
+ file.delete();
+ it.remove();
+ }
+ }
+
+ protected void createBackup( File file )
+ throws IOException
+ {
+ if ( file.exists() && file.isFile() )
+ {
+ File backup = File.createTempFile( "temp-", ".backup" );
+
+ FileUtils.copyFile( file, backup );
+
+ backup.deleteOnExit();
+
+ backups.put( file, backup );
+ }
+ }
+
+ protected void restoreBackups()
+ throws IOException
+ {
+ Iterator it = backups.entrySet().iterator();
+ while ( it.hasNext() )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ FileUtils.copyFile( (File) entry.getValue(), (File) entry.getKey() );
+ }
+ }
+
+ protected void restoreBackup( File file )
+ throws IOException
+ {
+ File backup = (File) backups.get( file );
+ if ( backup != null )
+ {
+ FileUtils.copyFile( backup, file );
+ }
+ }
+
+ /**
+ * Create checksums of file using all digesters defined at construction time.
+ *
+ * @param file
+ * @param force whether existing checksums should be overwritten or not
+ * @throws IOException
+ */
+ protected void createChecksums( File file, boolean force )
+ throws IOException
+ {
+ Iterator it = getDigesters().iterator();
+ while ( it.hasNext() )
+ {
+ Digester digester = (Digester) it.next();
+ File checksumFile = new File( file.getAbsolutePath() + "." + getDigesterFileExtension( digester ) );
+ if ( checksumFile.exists() )
+ {
+ if ( !force )
+ {
+ continue;
+ }
+ createBackup( checksumFile );
+ }
+ else
+ {
+ createdFiles.add( checksumFile );
+ }
+
+ try
+ {
+ writeStringToFile( checksumFile, digester.calc( file ) );
+ }
+ catch ( DigesterException e )
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+ }
+
+ protected void writeStringToFile( File file, String content )
+ throws IOException
+ {
+ FileOutputStream out = null;
+ try
+ {
+ out = new FileOutputStream( file );
+ IOUtil.copy( content, out );
+ }
+ finally
+ {
+ IOUtil.close( out );
+ }
+ }
+
+ /**
+ * File extension for checksums
+ * TODO should be moved to plexus-digester ?
+ */
+ protected String getDigesterFileExtension( Digester digester )
+ {
+ return digester.getAlgorithm().toLowerCase().replaceAll( "-", "" );
+ }
+
+}
--- /dev/null
+package org.apache.maven.archiva.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 org.codehaus.plexus.digest.Digester;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Event to copy a file.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class CopyFileEvent
+ extends AbstractTransactionEvent
+{
+ private final File source;
+
+ private final File destination;
+
+ /**
+ *
+ * @param source
+ * @param destination
+ * @param digesters {@link List}<{@link Digester}> digesters to use for checksumming
+ */
+ public CopyFileEvent( File source, File destination, List digesters )
+ {
+ super( digesters );
+ this.source = source;
+ this.destination = destination;
+ }
+
+ public void commit()
+ throws IOException
+ {
+ createBackup( destination );
+
+ mkDirs( destination.getParentFile() );
+
+ FileUtils.copyFile( source, destination );
+
+ createChecksums( destination, true );
+ copyChecksums();
+
+ copyChecksum( "asc" );
+ }
+
+ /**
+ * Copy checksums of source file with all digesters if exist
+ *
+ * @throws IOException
+ */
+ private void copyChecksums()
+ throws IOException
+ {
+ Iterator it = getDigesters().iterator();
+ while ( it.hasNext() )
+ {
+ Digester digester = (Digester) it.next();
+ copyChecksum( getDigesterFileExtension( digester ) );
+ }
+ }
+
+ /**
+ * Copy checksum of source file with extension provided if exists
+ *
+ * @param extension
+ * @return whether the checksum exists or not
+ * @throws IOException
+ */
+ private boolean copyChecksum( String extension )
+ throws IOException
+ {
+ File checksumSource = new File( source.getAbsolutePath() + "." + extension );
+ if ( checksumSource.exists() )
+ {
+ File checksumDestination = new File( destination.getAbsolutePath() + "." + extension );
+ FileUtils.copyFile( checksumSource, checksumDestination );
+ return true;
+ }
+ return false;
+ }
+
+ public void rollback()
+ throws IOException
+ {
+ destination.delete();
+
+ revertFilesCreated();
+
+ revertMkDirs();
+
+ restoreBackups();
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.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 org.codehaus.plexus.digest.Digester;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Event for creating a file from a string content.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class CreateFileEvent
+ extends AbstractTransactionEvent
+{
+ private final File destination;
+
+ private final String content;
+
+ /**
+ *
+ * @param content
+ * @param destination
+ * @param digesters {@link List}<{@link Digester}> digesters to use for checksumming
+ */
+ public CreateFileEvent( String content, File destination, List digesters )
+ {
+ super( digesters );
+ this.content = content;
+ this.destination = destination;
+ }
+
+ public void commit()
+ throws IOException
+ {
+ createBackup( destination );
+
+ mkDirs( destination.getParentFile() );
+
+ if ( !destination.exists() && !destination.createNewFile() )
+ {
+ throw new IOException( "Unable to create new file" );
+ }
+
+ writeStringToFile( destination, content );
+
+ createChecksums( destination, true );
+ }
+
+ public void rollback()
+ throws IOException
+ {
+ destination.delete();
+
+ revertFilesCreated();
+
+ revertMkDirs();
+
+ restoreBackups();
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.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 java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Implement commit/rollback semantics for a set of files.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class FileTransaction
+{
+ private List events = new ArrayList();
+
+ public void commit()
+ throws TransactionException
+ {
+ List toRollback = new ArrayList( events.size() );
+
+ for ( Iterator i = events.iterator(); i.hasNext(); )
+ {
+ TransactionEvent event = (TransactionEvent) i.next();
+
+ try
+ {
+ event.commit();
+
+ toRollback.add( event );
+ }
+ catch ( IOException e )
+ {
+ try
+ {
+ rollback( toRollback );
+
+ throw new TransactionException( "Unable to commit file transaction", e );
+ }
+ catch ( IOException ioe )
+ {
+ throw new TransactionException(
+ "Unable to commit file transaction, and rollback failed with error: '" + ioe.getMessage() + "'",
+ e );
+ }
+ }
+ }
+ }
+
+ private void rollback( List toRollback )
+ throws IOException
+ {
+ for ( Iterator i = toRollback.iterator(); i.hasNext(); )
+ {
+ TransactionEvent event = (TransactionEvent) i.next();
+
+ event.rollback();
+ }
+ }
+
+ /**
+ *
+ * @param source
+ * @param destination
+ * @param digesters {@link List}<{@link Digester}> digesters to use for checksumming
+ */
+ public void copyFile( File source, File destination, List digesters )
+ {
+ events.add( new CopyFileEvent( source, destination, digesters ) );
+ }
+
+ /**
+ *
+ * @param content
+ * @param destination
+ * @param digesters {@link List}<{@link Digester}> digesters to use for checksumming
+ */
+ public void createFile( String content, File destination, List digesters )
+ {
+ events.add( new CreateFileEvent( content, destination, digesters ) );
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.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 java.io.IOException;
+
+/**
+ * Interface for individual events in a transaction.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public interface TransactionEvent
+{
+ /**
+ * Commit this event.
+ *
+ * @throws IOException if an error occurred committing the change
+ */
+ void commit()
+ throws IOException;
+
+ /**
+ * Rollback the even already committed.
+ *
+ * @throws IOException if an error occurred reverting the change
+ */
+ void rollback()
+ throws IOException;
+}
--- /dev/null
+package org.apache.maven.archiva.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.
+ */
+
+/**
+ * TransactionException
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class TransactionException
+ extends Exception
+{
+
+ public TransactionException()
+ {
+ }
+
+ public TransactionException( String message )
+ {
+ super( message );
+ }
+
+ public TransactionException( Throwable cause )
+ {
+ super( cause );
+ }
+
+ public TransactionException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+}
+++ /dev/null
-package org.apache.maven.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 org.codehaus.plexus.digest.Digester;
-import org.codehaus.plexus.digest.DigesterException;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.IOUtil;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Abstract class for the TransactionEvents
- *
- * @author Edwin Punzalan
- * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
- * @version $Id$
- */
-public abstract class AbstractTransactionEvent
- extends AbstractLogEnabled
- implements TransactionEvent
-{
- private Map backups = new HashMap();;
-
- private List createdDirs = new ArrayList();
-
- private List createdFiles = new ArrayList();
-
- /** {@link List}<{@link Digester}> */
- private List digesters;
-
- protected AbstractTransactionEvent()
- {
- this( new ArrayList( 0 ) );
- }
-
- protected AbstractTransactionEvent( List digesters )
- {
- this.digesters = digesters;
- }
-
- protected List getDigesters()
- {
- return digesters;
- }
-
- /**
- * Method that creates a directory as well as all the parent directories needed
- *
- * @param dir The File directory to be created
- * @throws IOException when an unrecoverable error occurred
- */
- protected void mkDirs( File dir )
- throws IOException
- {
- List createDirs = new ArrayList();
-
- File parent = dir;
- while ( !parent.exists() || !parent.isDirectory() )
- {
- createDirs.add( parent );
-
- parent = parent.getParentFile();
- }
-
- while ( !createDirs.isEmpty() )
- {
- File directory = (File) createDirs.remove( createDirs.size() - 1 );
-
- if ( directory.mkdir() )
- {
- createdDirs.add( directory );
- }
- else
- {
- throw new IOException( "Failed to create directory: " + directory.getAbsolutePath() );
- }
- }
- }
-
- protected void revertMkDirs()
- throws IOException
- {
- if ( createdDirs != null )
- {
- Collections.reverse( createdDirs );
-
- while ( !createdDirs.isEmpty() )
- {
- File dir = (File) createdDirs.remove( 0 );
-
- if ( dir.isDirectory() && dir.list().length == 0 )
- {
- FileUtils.deleteDirectory( dir );
- }
- else
- {
- //cannot rollback created directory if it still contains files
- break;
- }
- }
- }
- }
-
- protected void revertFilesCreated()
- throws IOException
- {
- Iterator it = createdFiles.iterator();
- while ( it.hasNext() )
- {
- File file = (File) it.next();
- file.delete();
- it.remove();
- }
- }
-
- protected void createBackup( File file )
- throws IOException
- {
- if ( file.exists() && file.isFile() )
- {
- File backup = File.createTempFile( "temp-", ".backup" );
-
- FileUtils.copyFile( file, backup );
-
- backup.deleteOnExit();
-
- backups.put( file, backup );
- }
- }
-
- protected void restoreBackups()
- throws IOException
- {
- Iterator it = backups.entrySet().iterator();
- while ( it.hasNext() )
- {
- Map.Entry entry = (Map.Entry) it.next();
- FileUtils.copyFile( (File) entry.getValue(), (File) entry.getKey() );
- }
- }
-
- protected void restoreBackup( File file )
- throws IOException
- {
- File backup = (File) backups.get( file );
- if ( backup != null )
- {
- FileUtils.copyFile( backup, file );
- }
- }
-
- /**
- * Create checksums of file using all digesters defined at construction time.
- *
- * @param file
- * @param force whether existing checksums should be overwritten or not
- * @throws IOException
- */
- protected void createChecksums( File file, boolean force )
- throws IOException
- {
- Iterator it = getDigesters().iterator();
- while ( it.hasNext() )
- {
- Digester digester = (Digester) it.next();
- File checksumFile = new File( file.getAbsolutePath() + "." + getDigesterFileExtension( digester ) );
- if ( checksumFile.exists() )
- {
- if ( !force )
- {
- continue;
- }
- createBackup( checksumFile );
- }
- else
- {
- createdFiles.add( checksumFile );
- }
-
- try
- {
- writeStringToFile( checksumFile, digester.calc( file ) );
- }
- catch ( DigesterException e )
- {
- throw (IOException) e.getCause();
- }
- }
- }
-
- protected void writeStringToFile( File file, String content )
- throws IOException
- {
- FileOutputStream out = null;
- try
- {
- out = new FileOutputStream( file );
- IOUtil.copy( content, out );
- }
- finally
- {
- IOUtil.close( out );
- }
- }
-
- /**
- * File extension for checksums
- * TODO should be moved to plexus-digester ?
- */
- protected String getDigesterFileExtension( Digester digester )
- {
- return digester.getAlgorithm().toLowerCase().replaceAll( "-", "" );
- }
-
-}
+++ /dev/null
-package org.apache.maven.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 org.codehaus.plexus.digest.Digester;
-import org.codehaus.plexus.util.FileUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Event to copy a file.
- *
- * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
- * @version $Id$
- */
-public class CopyFileEvent
- extends AbstractTransactionEvent
-{
- private final File source;
-
- private final File destination;
-
- /**
- *
- * @param source
- * @param destination
- * @param digesters {@link List}<{@link Digester}> digesters to use for checksumming
- */
- public CopyFileEvent( File source, File destination, List digesters )
- {
- super( digesters );
- this.source = source;
- this.destination = destination;
- }
-
- public void commit()
- throws IOException
- {
- createBackup( destination );
-
- mkDirs( destination.getParentFile() );
-
- FileUtils.copyFile( source, destination );
-
- createChecksums( destination, true );
- copyChecksums();
-
- copyChecksum( "asc" );
- }
-
- /**
- * Copy checksums of source file with all digesters if exist
- *
- * @throws IOException
- */
- private void copyChecksums()
- throws IOException
- {
- Iterator it = getDigesters().iterator();
- while ( it.hasNext() )
- {
- Digester digester = (Digester) it.next();
- copyChecksum( getDigesterFileExtension( digester ) );
- }
- }
-
- /**
- * Copy checksum of source file with extension provided if exists
- *
- * @param extension
- * @return whether the checksum exists or not
- * @throws IOException
- */
- private boolean copyChecksum( String extension )
- throws IOException
- {
- File checksumSource = new File( source.getAbsolutePath() + "." + extension );
- if ( checksumSource.exists() )
- {
- File checksumDestination = new File( destination.getAbsolutePath() + "." + extension );
- FileUtils.copyFile( checksumSource, checksumDestination );
- return true;
- }
- return false;
- }
-
- public void rollback()
- throws IOException
- {
- destination.delete();
-
- revertFilesCreated();
-
- revertMkDirs();
-
- restoreBackups();
- }
-}
+++ /dev/null
-package org.apache.maven.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 org.codehaus.plexus.digest.Digester;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-/**
- * Event for creating a file from a string content.
- *
- * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
- * @version $Id$
- */
-public class CreateFileEvent
- extends AbstractTransactionEvent
-{
- private final File destination;
-
- private final String content;
-
- /**
- *
- * @param content
- * @param destination
- * @param digesters {@link List}<{@link Digester}> digesters to use for checksumming
- */
- public CreateFileEvent( String content, File destination, List digesters )
- {
- super( digesters );
- this.content = content;
- this.destination = destination;
- }
-
- public void commit()
- throws IOException
- {
- createBackup( destination );
-
- mkDirs( destination.getParentFile() );
-
- if ( !destination.exists() && !destination.createNewFile() )
- {
- throw new IOException( "Unable to create new file" );
- }
-
- writeStringToFile( destination, content );
-
- createChecksums( destination, true );
- }
-
- public void rollback()
- throws IOException
- {
- destination.delete();
-
- revertFilesCreated();
-
- revertMkDirs();
-
- restoreBackups();
- }
-}
+++ /dev/null
-package org.apache.maven.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 java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Implement commit/rollback semantics for a set of files.
- *
- * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- */
-public class FileTransaction
-{
- private List events = new ArrayList();
-
- public void commit()
- throws TransactionException
- {
- List toRollback = new ArrayList( events.size() );
-
- for ( Iterator i = events.iterator(); i.hasNext(); )
- {
- TransactionEvent event = (TransactionEvent) i.next();
-
- try
- {
- event.commit();
-
- toRollback.add( event );
- }
- catch ( IOException e )
- {
- try
- {
- rollback( toRollback );
-
- throw new TransactionException( "Unable to commit file transaction", e );
- }
- catch ( IOException ioe )
- {
- throw new TransactionException(
- "Unable to commit file transaction, and rollback failed with error: '" + ioe.getMessage() + "'",
- e );
- }
- }
- }
- }
-
- private void rollback( List toRollback )
- throws IOException
- {
- for ( Iterator i = toRollback.iterator(); i.hasNext(); )
- {
- TransactionEvent event = (TransactionEvent) i.next();
-
- event.rollback();
- }
- }
-
- /**
- *
- * @param source
- * @param destination
- * @param digesters {@link List}<{@link Digester}> digesters to use for checksumming
- */
- public void copyFile( File source, File destination, List digesters )
- {
- events.add( new CopyFileEvent( source, destination, digesters ) );
- }
-
- /**
- *
- * @param content
- * @param destination
- * @param digesters {@link List}<{@link Digester}> digesters to use for checksumming
- */
- public void createFile( String content, File destination, List digesters )
- {
- events.add( new CreateFileEvent( content, destination, digesters ) );
- }
-}
+++ /dev/null
-package org.apache.maven.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 java.io.IOException;
-
-/**
- * Interface for individual events in a transaction.
- *
- * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- */
-public interface TransactionEvent
-{
- /**
- * Commit this event.
- *
- * @throws IOException if an error occurred committing the change
- */
- void commit()
- throws IOException;
-
- /**
- * Rollback the even already committed.
- *
- * @throws IOException if an error occurred reverting the change
- */
- void rollback()
- throws IOException;
-}
+++ /dev/null
-package org.apache.maven.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.
- */
-
-/**
- * TransactionException
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class TransactionException
- extends Exception
-{
-
- public TransactionException()
- {
- }
-
- public TransactionException( String message )
- {
- super( message );
- }
-
- public TransactionException( Throwable cause )
- {
- super( cause );
- }
-
- public TransactionException( String message, Throwable cause )
- {
- super( message, cause );
- }
-
-}
--- /dev/null
+package org.apache.maven.archiva.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 org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.digest.Digester;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ *
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public abstract class AbstractFileEventTest
+ extends PlexusTestCase
+{
+ protected List digesters;
+
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ digesters = getContainer().lookupList( Digester.class.getName() );
+ }
+
+ protected void assertChecksumExists( File file, String algorithm )
+ {
+ assertChecksum( file, algorithm, true );
+ }
+
+ protected void assertChecksumDoesNotExist( File file, String algorithm )
+ {
+ assertChecksum( file, algorithm, false );
+ }
+
+ private void assertChecksum( File file, String algorithm, boolean exist )
+ {
+ String msg = exist ? "exists" : "does not exist";
+ File checksumFile = new File( file.getPath() + "." + algorithm );
+ assertEquals( "Test file " + algorithm + " checksum " + msg, exist, checksumFile.exists() );
+ }
+
+ protected void assertChecksumCommit( File file )
+ throws IOException
+ {
+ assertChecksumExists( file, "md5" );
+ assertChecksumExists( file, "sha1" );
+ }
+
+ protected void assertChecksumRollback( File file )
+ throws IOException
+ {
+ assertChecksumDoesNotExist( file, "md5" );
+ assertChecksumDoesNotExist( file, "sha1" );
+ }
+
+ protected String readFile( File file )
+ throws IOException
+ {
+ FileInputStream in = null;
+ try
+ {
+ in = new FileInputStream( file );
+ return IOUtil.toString( in );
+ }
+ finally
+ {
+ IOUtil.close( in );
+ }
+ }
+
+ protected void writeFile( File file, String content )
+ throws IOException
+ {
+ FileOutputStream out = null;
+ try
+ {
+ out = new FileOutputStream( file );
+ IOUtil.copy( content, out );
+ }
+ finally
+ {
+ IOUtil.close( out );
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.apache.maven.archiva.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 org.apache.maven.archiva.transaction.CopyFileEvent;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class CopyFileEventTest
+ extends AbstractFileEventTest
+{
+ private File testDir = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/copy-file" );
+
+ private File testDest = new File( testDir, "test-file.txt" );
+
+ private File testSource = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/test-file.txt" );
+
+ private File testDestChecksum;
+
+ private String source, oldChecksum;
+
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ testSource.getParentFile().mkdirs();
+
+ testSource.createNewFile();
+
+ writeFile( testSource, "source contents" );
+
+ testDestChecksum = new File( testDest.getPath() + ".sha1" );
+
+ testDestChecksum.getParentFile().mkdirs();
+
+ testDestChecksum.createNewFile();
+
+ writeFile( testDestChecksum, "this is the checksum" );
+
+ assertTrue( "Test if the source exists", testSource.exists() );
+
+ assertTrue( "Test if the destination checksum exists", testDestChecksum.exists() );
+
+ source = readFile( testSource );
+
+ oldChecksum = readFile( testDestChecksum );
+ }
+
+ public void testCopyCommitRollback()
+ throws Exception
+ {
+ CopyFileEvent event = new CopyFileEvent( testSource, testDest, digesters );
+
+ assertFalse( "Test that the destination is not yet created", testDest.exists() );
+
+ event.commit();
+
+ assertTrue( "Test that the destination is created", testDest.exists() );
+
+ assertChecksumCommit( testDest );
+
+ String target = readFile( testDest );
+
+ assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) );
+
+ event.rollback();
+
+ assertFalse( "Test that the destination file has been deleted", testDest.exists() );
+
+ assertChecksumRollback( testDest );
+ }
+
+ public void testCopyCommitRollbackWithBackup()
+ throws Exception
+ {
+ testDest.getParentFile().mkdirs();
+
+ testDest.createNewFile();
+
+ writeFile( testDest, "overwritten contents" );
+
+ assertTrue( "Test that the destination exists", testDest.exists() );
+
+ CopyFileEvent event = new CopyFileEvent( testSource, testDest, digesters );
+
+ String target = readFile( testDest );
+
+ assertTrue( "Test that the destination contents have not changed", target.equals( "overwritten contents" ) );
+
+ event.commit();
+
+ target = readFile( testDest );
+
+ assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) );
+
+ assertChecksumCommit( testDest );
+
+ event.rollback();
+
+ target = readFile( testDest );
+
+ assertTrue( "Test the destination file contents have been restored", target.equals( "overwritten contents" ) );
+
+ assertChecksumRollback( testDest );
+ }
+
+ public void testCreateRollbackCommit()
+ throws Exception
+ {
+ CopyFileEvent event = new CopyFileEvent( testSource, testDest, digesters );
+
+ assertFalse( "Test that the destination is not yet created", testDest.exists() );
+
+ event.rollback();
+
+ assertFalse( "Test that the destination file is not yet created", testDest.exists() );
+
+ event.commit();
+
+ assertTrue( "Test that the destination is created", testDest.exists() );
+
+ assertChecksumCommit( testDest );
+
+ String target = readFile( testDest );
+
+ assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) );
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+
+ FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), "target/transaction-tests" ) );
+ }
+
+ protected void assertChecksumCommit( File file )
+ throws IOException
+ {
+ super.assertChecksumCommit( file );
+
+ String target = readFile( testDestChecksum );
+
+ assertFalse( "Test that the destination checksum contents are created correctly", oldChecksum.equals( target ) );
+ }
+
+ protected void assertChecksumRollback( File file )
+ throws IOException
+ {
+ assertChecksumDoesNotExist( file, "md5" );
+ assertChecksumExists( file, "sha1" );
+
+ String target = readFile( testDestChecksum );
+
+ assertEquals( "Test that the destination checksum contents are reverted correctly", oldChecksum, target );
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.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 java.io.File;
+
+import org.apache.maven.archiva.transaction.CreateFileEvent;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class CreateFileEventTest
+ extends AbstractFileEventTest
+{
+ private File testDir = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/create-file" );
+
+ public void testCreateCommitRollback()
+ throws Exception
+ {
+ File testFile = new File( testDir, "test-file.txt" );
+
+ CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
+
+ assertFalse( "Test file is not yet created", testFile.exists() );
+
+ event.commit();
+
+ assertTrue( "Test file has been created", testFile.exists() );
+
+ assertChecksumCommit( testFile );
+
+ event.rollback();
+
+ assertFalse( "Test file is has been deleted after rollback", testFile.exists() );
+
+ assertChecksumRollback( testFile );
+
+ assertFalse( "Test file parent directories has been rolledback too", testDir.exists() );
+ assertTrue( "target directory still exists", new File( PlexusTestCase.getBasedir(), "target" ).exists() );
+ }
+
+ public void testCreateCommitRollbackWithBackup()
+ throws Exception
+ {
+ File testFile = new File( testDir, "test-file.txt" );
+
+ testFile.getParentFile().mkdirs();
+
+ testFile.createNewFile();
+
+ writeFile( testFile, "original contents" );
+
+ CreateFileEvent event = new CreateFileEvent( "modified contents", testFile, digesters );
+
+ String contents = readFile( testFile );
+
+ assertEquals( "Test contents have not changed", "original contents", contents );
+
+ event.commit();
+
+ contents = readFile( testFile );
+
+ assertEquals( "Test contents have not changed", "modified contents", contents );
+
+ assertChecksumCommit( testFile );
+
+ event.rollback();
+
+ contents = readFile( testFile );
+
+ assertEquals( "Test contents have not changed", "original contents", contents );
+
+ assertChecksumRollback( testFile );
+ }
+
+ public void testCreateRollbackCommit()
+ throws Exception
+ {
+ File testFile = new File( testDir, "test-file.txt" );
+
+ CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
+
+ assertFalse( "Test file is not yet created", testFile.exists() );
+
+ event.rollback();
+
+ assertFalse( "Test file is not yet created", testFile.exists() );
+
+ event.commit();
+
+ assertTrue( "Test file is not yet created", testFile.exists() );
+
+ assertChecksumCommit( testFile );
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+
+ FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), "target/transaction-tests" ) );
+ }
+}
+++ /dev/null
-package org.apache.maven.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 org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.digest.Digester;
-import org.codehaus.plexus.util.IOUtil;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.List;
-
-/**
- *
- * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
- * @version $Id$
- */
-public abstract class AbstractFileEventTest
- extends PlexusTestCase
-{
- protected List digesters;
-
- public void setUp()
- throws Exception
- {
- super.setUp();
-
- digesters = getContainer().lookupList( Digester.class.getName() );
- }
-
- protected void assertChecksumExists( File file, String algorithm )
- {
- assertChecksum( file, algorithm, true );
- }
-
- protected void assertChecksumDoesNotExist( File file, String algorithm )
- {
- assertChecksum( file, algorithm, false );
- }
-
- private void assertChecksum( File file, String algorithm, boolean exist )
- {
- String msg = exist ? "exists" : "does not exist";
- File checksumFile = new File( file.getPath() + "." + algorithm );
- assertEquals( "Test file " + algorithm + " checksum " + msg, exist, checksumFile.exists() );
- }
-
- protected void assertChecksumCommit( File file )
- throws IOException
- {
- assertChecksumExists( file, "md5" );
- assertChecksumExists( file, "sha1" );
- }
-
- protected void assertChecksumRollback( File file )
- throws IOException
- {
- assertChecksumDoesNotExist( file, "md5" );
- assertChecksumDoesNotExist( file, "sha1" );
- }
-
- protected String readFile( File file )
- throws IOException
- {
- FileInputStream in = null;
- try
- {
- in = new FileInputStream( file );
- return IOUtil.toString( in );
- }
- finally
- {
- IOUtil.close( in );
- }
- }
-
- protected void writeFile( File file, String content )
- throws IOException
- {
- FileOutputStream out = null;
- try
- {
- out = new FileOutputStream( file );
- IOUtil.copy( content, out );
- }
- finally
- {
- IOUtil.close( out );
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.apache.maven.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 org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.FileUtils;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * @author Edwin Punzalan
- */
-public class CopyFileEventTest
- extends AbstractFileEventTest
-{
- private File testDir = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/copy-file" );
-
- private File testDest = new File( testDir, "test-file.txt" );
-
- private File testSource = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/test-file.txt" );
-
- private File testDestChecksum;
-
- private String source, oldChecksum;
-
- public void setUp()
- throws Exception
- {
- super.setUp();
-
- testSource.getParentFile().mkdirs();
-
- testSource.createNewFile();
-
- writeFile( testSource, "source contents" );
-
- testDestChecksum = new File( testDest.getPath() + ".sha1" );
-
- testDestChecksum.getParentFile().mkdirs();
-
- testDestChecksum.createNewFile();
-
- writeFile( testDestChecksum, "this is the checksum" );
-
- assertTrue( "Test if the source exists", testSource.exists() );
-
- assertTrue( "Test if the destination checksum exists", testDestChecksum.exists() );
-
- source = readFile( testSource );
-
- oldChecksum = readFile( testDestChecksum );
- }
-
- public void testCopyCommitRollback()
- throws Exception
- {
- CopyFileEvent event = new CopyFileEvent( testSource, testDest, digesters );
-
- assertFalse( "Test that the destination is not yet created", testDest.exists() );
-
- event.commit();
-
- assertTrue( "Test that the destination is created", testDest.exists() );
-
- assertChecksumCommit( testDest );
-
- String target = readFile( testDest );
-
- assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) );
-
- event.rollback();
-
- assertFalse( "Test that the destination file has been deleted", testDest.exists() );
-
- assertChecksumRollback( testDest );
- }
-
- public void testCopyCommitRollbackWithBackup()
- throws Exception
- {
- testDest.getParentFile().mkdirs();
-
- testDest.createNewFile();
-
- writeFile( testDest, "overwritten contents" );
-
- assertTrue( "Test that the destination exists", testDest.exists() );
-
- CopyFileEvent event = new CopyFileEvent( testSource, testDest, digesters );
-
- String target = readFile( testDest );
-
- assertTrue( "Test that the destination contents have not changed", target.equals( "overwritten contents" ) );
-
- event.commit();
-
- target = readFile( testDest );
-
- assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) );
-
- assertChecksumCommit( testDest );
-
- event.rollback();
-
- target = readFile( testDest );
-
- assertTrue( "Test the destination file contents have been restored", target.equals( "overwritten contents" ) );
-
- assertChecksumRollback( testDest );
- }
-
- public void testCreateRollbackCommit()
- throws Exception
- {
- CopyFileEvent event = new CopyFileEvent( testSource, testDest, digesters );
-
- assertFalse( "Test that the destination is not yet created", testDest.exists() );
-
- event.rollback();
-
- assertFalse( "Test that the destination file is not yet created", testDest.exists() );
-
- event.commit();
-
- assertTrue( "Test that the destination is created", testDest.exists() );
-
- assertChecksumCommit( testDest );
-
- String target = readFile( testDest );
-
- assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) );
- }
-
- protected void tearDown()
- throws Exception
- {
- super.tearDown();
-
- FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), "target/transaction-tests" ) );
- }
-
- protected void assertChecksumCommit( File file )
- throws IOException
- {
- super.assertChecksumCommit( file );
-
- String target = readFile( testDestChecksum );
-
- assertFalse( "Test that the destination checksum contents are created correctly", oldChecksum.equals( target ) );
- }
-
- protected void assertChecksumRollback( File file )
- throws IOException
- {
- assertChecksumDoesNotExist( file, "md5" );
- assertChecksumExists( file, "sha1" );
-
- String target = readFile( testDestChecksum );
-
- assertEquals( "Test that the destination checksum contents are reverted correctly", oldChecksum, target );
- }
-}
+++ /dev/null
-package org.apache.maven.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 java.io.File;
-
-import org.apache.maven.transaction.CreateFileEvent;
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.FileUtils;
-
-/**
- * @author Edwin Punzalan
- */
-public class CreateFileEventTest
- extends AbstractFileEventTest
-{
- private File testDir = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/create-file" );
-
- public void testCreateCommitRollback()
- throws Exception
- {
- File testFile = new File( testDir, "test-file.txt" );
-
- CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
-
- assertFalse( "Test file is not yet created", testFile.exists() );
-
- event.commit();
-
- assertTrue( "Test file has been created", testFile.exists() );
-
- assertChecksumCommit( testFile );
-
- event.rollback();
-
- assertFalse( "Test file is has been deleted after rollback", testFile.exists() );
-
- assertChecksumRollback( testFile );
-
- assertFalse( "Test file parent directories has been rolledback too", testDir.exists() );
- assertTrue( "target directory still exists", new File( PlexusTestCase.getBasedir(), "target" ).exists() );
- }
-
- public void testCreateCommitRollbackWithBackup()
- throws Exception
- {
- File testFile = new File( testDir, "test-file.txt" );
-
- testFile.getParentFile().mkdirs();
-
- testFile.createNewFile();
-
- writeFile( testFile, "original contents" );
-
- CreateFileEvent event = new CreateFileEvent( "modified contents", testFile, digesters );
-
- String contents = readFile( testFile );
-
- assertEquals( "Test contents have not changed", "original contents", contents );
-
- event.commit();
-
- contents = readFile( testFile );
-
- assertEquals( "Test contents have not changed", "modified contents", contents );
-
- assertChecksumCommit( testFile );
-
- event.rollback();
-
- contents = readFile( testFile );
-
- assertEquals( "Test contents have not changed", "original contents", contents );
-
- assertChecksumRollback( testFile );
- }
-
- public void testCreateRollbackCommit()
- throws Exception
- {
- File testFile = new File( testDir, "test-file.txt" );
-
- CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
-
- assertFalse( "Test file is not yet created", testFile.exists() );
-
- event.rollback();
-
- assertFalse( "Test file is not yet created", testFile.exists() );
-
- event.commit();
-
- assertTrue( "Test file is not yet created", testFile.exists() );
-
- assertChecksumCommit( testFile );
- }
-
- protected void tearDown()
- throws Exception
- {
- super.tearDown();
-
- FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), "target/transaction-tests" ) );
- }
-}
<module>archiva-repository-layer</module>
<module>archiva-xml-tools</module>
<module>archiva-proxy</module>
+ <module>archiva-transaction</module>
+ <module>archiva-artifact-converter</module>
<module>archiva-converter</module>
</modules>
</project>
<subscribe>archiva-users-subscribe@maven.apache.org</subscribe>
<unsubscribe>
archiva-users-unsubscribe@maven.apache.org
- </unsubscribe>
+ </unsubscribe>
<post>archiva-users@maven.apache.org</post>
<archive>
http://mail-archives.apache.org/mod_mbox/maven-archiva-users
- </archive>
+ </archive>
</mailingList>
<mailingList>
<name>Maven Archiva Developer List</name>
<subscribe>archiva-dev-subscribe@maven.apache.org</subscribe>
<unsubscribe>
archiva-dev-unsubscribe@maven.apache.org
- </unsubscribe>
+ </unsubscribe>
<post>archiva-dev@maven.apache.org</post>
<archive>
http://mail-archives.apache.org/mod_mbox/maven-archiva-dev
- </archive>
+ </archive>
</mailingList>
<mailingList>
<name>Maven Archiva Commits List</name>
<subscribe>
archiva-commits-subscribe@maven.apache.org
- </subscribe>
+ </subscribe>
<unsubscribe>
archiva-commits-unsubscribe@maven.apache.org
- </unsubscribe>
+ </unsubscribe>
<post>archiva-commits@maven.apache.org</post>
<archive>
http://mail-archives.apache.org/mod_mbox/maven-archiva-commits
- </archive>
+ </archive>
</mailingList>
</mailingLists>
<scm>
<connection>
scm:svn:http://svn.apache.org/repos/asf/maven/archiva/trunk
- </connection>
+ </connection>
<developerConnection>
scm:svn:https://svn.apache.org/repos/asf/maven/archiva/trunk
- </developerConnection>
+ </developerConnection>
<url>http://svn.apache.org/viewcvs.cgi/maven/archiva/trunk</url>
</scm>
<distributionManagement>
<artifactId>archiva-applet</artifactId>
<version>${archiva.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-artifact-converter</artifactId>
+ <version>${archiva.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-artifact-reports</artifactId>
<artifactId>archiva-signature-consumers</artifactId>
<version>${archiva.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-transaction</artifactId>
+ <version>${archiva.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-webapp</artifactId>