[MNG-4368] DefaultArtifactInstaller should only overwrite files if timestamp has changed

o Added IT

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@894116 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-12-27 23:31:39 +00:00
parent 5f939ed285
commit 4486e10798
6 changed files with 393 additions and 0 deletions

View File

@ -127,6 +127,7 @@ public class IntegrationTestSuite
suite.addTestSuite( MavenITmng4385LifecycleMappingFromExtensionInReactorTest.class );
suite.addTestSuite( MavenITmng4383ValidDependencyVersionTest.class );
suite.addTestSuite( MavenITmng4381ExtensionSingletonComponentTest.class );
suite.addTestSuite( MavenITmng4368TimestampAwareArtifactInstallerTest.class );
suite.addTestSuite( MavenITmng4367LayoutAwareMirrorSelectionTest.class );
suite.addTestSuite( MavenITmng4365XmlMarkupInAttributeValueTest.class );
suite.addTestSuite( MavenITmng4363DynamicAdditionOfDependencyArtifactTest.class );

View File

@ -0,0 +1,156 @@
package org.apache.maven.it;
/*
* 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.it.Verifier;
import org.apache.maven.it.util.FileUtils;
import org.apache.maven.it.util.ResourceExtractor;
import java.io.File;
/**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4368">MNG-4368</a>.
*
* @author Benjamin Bentmann
*/
public class MavenITmng4368TimestampAwareArtifactInstallerTest
extends AbstractMavenIntegrationTestCase
{
public MavenITmng4368TimestampAwareArtifactInstallerTest()
{
super( "[2.0.3,3.0-alpha-1),[3.0-alpha-6,)" );
}
/**
* Verify that the artifact installer copies POMs to the local repo even if they have an older timestamp as the
* copy in the local repo.
*/
public void testitPomPackaging()
throws Exception
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4368/pom" );
File aDir = new File( testDir, "branch-a" );
File aPom = new File( aDir, "pom.xml" );
File bDir = new File( testDir, "branch-b" );
File bPom = new File( bDir, "pom.xml" );
aPom.setLastModified( System.currentTimeMillis() );
bPom.setLastModified( aPom.lastModified() - 1000 * 60 );
Verifier verifier = new Verifier( aDir.getAbsolutePath() );
verifier.setAutoclean( false );
verifier.deleteDirectory( "target" );
verifier.deleteArtifacts( "org.apache.maven.its.mng4368" );
verifier.executeGoal( "initialize" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
File installedPom = new File( verifier.getArtifactPath( "org.apache.maven.its.mng4368", "test", "0.1-SNAPSHOT", "pom" ) );
String pom = FileUtils.fileRead( installedPom, "UTF-8" );
assertTrue( pom.indexOf( "Branch-A" ) > 0 );
assertTrue( pom.indexOf( "Branch-B" ) < 0 );
assertEquals( aPom.length(), bPom.length() );
assertTrue( aPom.lastModified() > bPom.lastModified() );
assertTrue( installedPom.lastModified() > bPom.lastModified() );
verifier = new Verifier( bDir.getAbsolutePath() );
verifier.setAutoclean( false );
verifier.deleteDirectory( "target" );
verifier.executeGoal( "initialize" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
pom = FileUtils.fileRead( installedPom, "UTF-8" );
assertTrue( pom.indexOf( "Branch-A" ) < 0 );
assertTrue( pom.indexOf( "Branch-B" ) > 0 );
}
/**
* Verify that the artifact installer copies files to the local repo only if their timestamp differs from the copy
* already in the local repo.
*/
public void testitJarPackaging()
throws Exception
{
requiresMavenVersion( "[3.0-alpha-6,)" );
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4368/jar" );
File aDir = new File( testDir, "branch-a" );
File aArtifact = new File( aDir, "artifact.jar" );
File bDir = new File( testDir, "branch-b" );
File bArtifact = new File( bDir, "artifact.jar" );
FileUtils.fileWrite( aArtifact.getPath(), "UTF-8", "from Branch-A" );
aArtifact.setLastModified( System.currentTimeMillis() );
FileUtils.fileWrite( bArtifact.getPath(), "UTF-8", "from Branch-B" );
bArtifact.setLastModified( aArtifact.lastModified() - 1000 * 60 );
Verifier verifier = new Verifier( aDir.getAbsolutePath() );
verifier.setAutoclean( false );
verifier.deleteDirectory( "target" );
verifier.deleteArtifacts( "org.apache.maven.its.mng4368" );
verifier.executeGoal( "initialize" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
File installedArtifact = new File( verifier.getArtifactPath( "org.apache.maven.its.mng4368", "test", "0.1-SNAPSHOT", "jar" ) );
String data = FileUtils.fileRead( installedArtifact, "UTF-8" );
assertTrue( data.indexOf( "Branch-A" ) > 0 );
assertTrue( data.indexOf( "Branch-B" ) < 0 );
assertEquals( aArtifact.length(), bArtifact.length() );
assertTrue( aArtifact.lastModified() > bArtifact.lastModified() );
assertTrue( installedArtifact.lastModified() > bArtifact.lastModified() );
verifier = new Verifier( bDir.getAbsolutePath() );
verifier.setAutoclean( false );
verifier.deleteDirectory( "target" );
verifier.executeGoal( "initialize" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
data = FileUtils.fileRead( installedArtifact, "UTF-8" );
assertTrue( data.indexOf( "Branch-A" ) < 0 );
assertTrue( data.indexOf( "Branch-B" ) > 0 );
long lastModified = installedArtifact.lastModified();
FileUtils.fileWrite( installedArtifact.getPath(), "UTF-8", "from Branch-C" );
installedArtifact.setLastModified( lastModified );
verifier = new Verifier( bDir.getAbsolutePath() );
verifier.setAutoclean( false );
verifier.deleteDirectory( "target" );
verifier.setLogFileName( "log-b.txt" );
verifier.executeGoal( "initialize" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
data = FileUtils.fileRead( installedArtifact, "UTF-8" );
assertTrue( data.indexOf( "Branch-B" ) < 0 );
assertTrue( data.indexOf( "Branch-C" ) > 0 );
}
}

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng4368</groupId>
<artifactId>test</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Integration Test :: MNG-4368 :: Branch-A</name>
<description>
Verify that the artifact installer copies files to the local repo only if their timestamp differs from the copy
already in the local repo.
</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-artifact</artifactId>
<version>2.1-SNAPSHOT</version>
<configuration>
<mainFile>artifact.jar</mainFile>
</configuration>
<executions>
<execution>
<id>package</id>
<phase>validate</phase>
<goals>
<goal>set</goal>
</goals>
</execution>
<execution>
<id>install</id>
<phase>initialize</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng4368</groupId>
<artifactId>test</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Integration Test :: MNG-4368 :: Branch-B</name>
<description>
Verify that the artifact installer copies files to the local repo only if their timestamp differs from the copy
already in the local repo.
</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-artifact</artifactId>
<version>2.1-SNAPSHOT</version>
<configuration>
<mainFile>artifact.jar</mainFile>
</configuration>
<executions>
<execution>
<id>package</id>
<phase>validate</phase>
<goals>
<goal>set</goal>
</goals>
</execution>
<execution>
<id>install</id>
<phase>initialize</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng4368</groupId>
<artifactId>test</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-4368 :: Branch-A</name>
<description>
Verify that the artifact installer copies POMs to the local repo even if they have an older timestamp as the
copy in the local repo.
</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-artifact</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<id>install</id>
<phase>initialize</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng4368</groupId>
<artifactId>test</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-4368 :: Branch-B</name>
<description>
Verify that the artifact installer copies POMs to the local repo even if they have an older timestamp as the
copy in the local repo.
</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-artifact</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<id>install</id>
<phase>initialize</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>