if ( !force && targetFile.exists() )
{
matching = FileUtils.contentEquals( sourceFile, targetFile );
+ if ( !matching )
+ {
+ reporter.addFailure( artifact, getI18NString( "failure.target.already.exists" ) );
+ result = false;
+ }
}
- if ( force || !matching )
+ if ( result )
{
- if ( testChecksums( artifact, sourceFile, reporter ) )
+ if ( force || !matching )
{
- if ( !dryrun )
+ if ( testChecksums( artifact, sourceFile, reporter ) )
{
- FileUtils.copyFile( sourceFile, targetFile );
+ if ( !dryrun )
+ {
+ FileUtils.copyFile( sourceFile, targetFile );
+ }
+ }
+ else
+ {
+ result = false;
}
- }
- else
- {
- result = false;
}
}
}
}
public void testModifedArtifactFails()
+ throws InterruptedException, RepositoryConversionException, IOException
{
// test that it fails when the source artifact has changed and is different to the existing artifact in the
// target repository
- // TODO
+ 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 );
+
+ repositoryConverter.convert( artifact, targetRepository, reporter );
+ checkFailure();
+ assertEquals( "Check failure message", getI18nString( "failure.target.already.exists" ),
+ getFailure().getReason() );
+
+ 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()
assertFalse( "Check modified", origTime == targetFile.lastModified() );
assertFalse( "Check modified", origPomTime == 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()
--- /dev/null
+<!--
+ ~ Copyright 2005-2006 The Apache Software Foundation.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>modified-artifact</artifactId>
+ <groupId>test</groupId>
+ <currentVersion>1.0.0</currentVersion>
+</project>
--- /dev/null
+<!--
+ ~ Copyright 2005-2006 The Apache Software Foundation.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>modified-artifact</artifactId>
+ <groupId>test</groupId>
+ <currentVersion>1.0.0</currentVersion>
+</project>