mirror of https://github.com/apache/maven.git
[MNG-6754] Set the same timestamp in multi module builds (1/2)
Install and deploy a multi module project, compare local and remote last updated timestamps with each other and Maven build timestamp. This closes #77
This commit is contained in:
parent
622eece3a6
commit
ae6f0133b7
|
@ -107,6 +107,7 @@ public class IntegrationTestSuite
|
|||
// -------------------------------------------------------------------------------------------------------------
|
||||
// suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
|
||||
|
||||
suite.addTestSuite( MavenITmng6754TimestampInMultimoduleProject.class );
|
||||
suite.addTestSuite( MavenITmng6981ProjectListShouldIncludeChildrenTest.class );
|
||||
suite.addTestSuite( MavenITmng6972AllowAccessToGraphPackageTest.class );
|
||||
suite.addTestSuite( MavenITmng6772NestedImportScopeRepositoryOverride.class );
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
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.util.ResourceExtractor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class MavenITmng6754TimestampInMultimoduleProject
|
||||
extends AbstractMavenIntegrationTestCase
|
||||
{
|
||||
private static final Pattern LAST_UPDATED_LINE = Pattern.compile( "<lastUpdated>(\\d*)</lastUpdated>" );
|
||||
private static final String RESOURCE_PATH = "/mng-6754-version-timestamp-in-multimodule-build";
|
||||
|
||||
|
||||
public MavenITmng6754TimestampInMultimoduleProject()
|
||||
{
|
||||
super( "[3.7.0,)" );
|
||||
}
|
||||
|
||||
public void testArtifactsHaveSameTimestamp()
|
||||
throws Exception
|
||||
{
|
||||
final File testDir = ResourceExtractor.simpleExtractResources( getClass(), RESOURCE_PATH );
|
||||
final Verifier verifier = newVerifier( testDir.getAbsolutePath() );
|
||||
final Path localRepoDir = Paths.get( verifier.getLocalRepository() );
|
||||
final Path remoteRepoDir = Paths.get( verifier.getBasedir(), "repo" );
|
||||
|
||||
verifier.deleteDirectory( "repo" );
|
||||
verifier.deleteArtifacts ( "org.apache.maven.its.mng6754" );
|
||||
verifier.addCliOption( "-Drepodir=" + remoteRepoDir );
|
||||
verifier.executeGoals( asList( "install", "deploy" ) );
|
||||
verifier.verifyErrorFreeLog();
|
||||
|
||||
final Properties props = verifier.loadProperties( "target/timestamp.properties" );
|
||||
final String mavenBuildTimestamp = props.getProperty( "project.properties.timestamp" );
|
||||
|
||||
final String parentLastUpdatedLocal = getLastUpdatedFromMetadata( getLocalMetadataPath( localRepoDir, "parent" ) );
|
||||
final String aLastUpdatedLocal = getLastUpdatedFromMetadata( getLocalMetadataPath( localRepoDir, "child-a" ) );
|
||||
final String bLastUpdatedLocal = getLastUpdatedFromMetadata( getLocalMetadataPath( localRepoDir, "child-b" ) );
|
||||
|
||||
final String parentLastUpdatedRemote = getLastUpdatedFromMetadata( getRemoteMetadataPath( remoteRepoDir, "parent" ) );
|
||||
final String aLastUpdatedRemote = getLastUpdatedFromMetadata( getRemoteMetadataPath( remoteRepoDir, "child-a" ) );
|
||||
final String bLastUpdatedRemote = getLastUpdatedFromMetadata( getRemoteMetadataPath( remoteRepoDir, "child-b" ) );
|
||||
|
||||
assertEquals( "Installed child modules should have equal lastUpdated in maven-metadata-local.xml",
|
||||
aLastUpdatedLocal, bLastUpdatedLocal );
|
||||
assertEquals( "Installed parent module should have equal lastUpdated in maven-metadata-local.xml as their children",
|
||||
aLastUpdatedLocal, parentLastUpdatedLocal );
|
||||
assertEquals( "Deployed child modules should have equal lastUpdated in maven-metadata.xml",
|
||||
aLastUpdatedRemote, bLastUpdatedRemote );
|
||||
assertEquals( "Deployed parent module should have equal lastUpdated in maven-metadata.xml as their children",
|
||||
aLastUpdatedRemote, parentLastUpdatedRemote );
|
||||
assertEquals( "Installed parent module should have equal lastUpdated as deployed counterparts",
|
||||
parentLastUpdatedLocal, parentLastUpdatedRemote );
|
||||
assertEquals( "Installed child-a module should have equal lastUpdated as deployed counterparts",
|
||||
aLastUpdatedLocal, aLastUpdatedRemote );
|
||||
assertEquals( "Installed child-b module should have equal lastUpdated as deployed counterparts",
|
||||
bLastUpdatedLocal, bLastUpdatedRemote );
|
||||
assertEquals( "Installed parent module should have equal lastUpdated as the Maven build timestamp",
|
||||
parentLastUpdatedLocal, mavenBuildTimestamp );
|
||||
assertEquals( "Deployed parent module should have equal lastUpdated as the Maven build timestamp",
|
||||
parentLastUpdatedRemote, mavenBuildTimestamp );
|
||||
}
|
||||
|
||||
private Path getLocalMetadataPath( final Path repoDir, final String moduleName )
|
||||
{
|
||||
final Path mng6754Path = Paths.get( "org", "apache", "maven", "its", "mng6754" );
|
||||
final Path modulePath = repoDir.resolve( mng6754Path.resolve( moduleName ) );
|
||||
return modulePath.resolve( "maven-metadata-local.xml" );
|
||||
}
|
||||
|
||||
private Path getRemoteMetadataPath( final Path repoDir, final String moduleName )
|
||||
{
|
||||
final Path mng6754Path = Paths.get( "org", "apache", "maven", "its", "mng6754" );
|
||||
final Path modulePath = repoDir.resolve( mng6754Path.resolve( moduleName ) );
|
||||
return modulePath.resolve( "maven-metadata.xml" );
|
||||
}
|
||||
|
||||
private String getLastUpdatedFromMetadata( final Path metadataFile ) throws IOException
|
||||
{
|
||||
final List<String> lines = Files.readAllLines( metadataFile, Charset.defaultCharset() );
|
||||
for (final String line : lines )
|
||||
{
|
||||
final Matcher matcher = LAST_UPDATED_LINE.matcher( line );
|
||||
if ( matcher.find() )
|
||||
{
|
||||
return matcher.group(1);
|
||||
}
|
||||
}
|
||||
|
||||
// just in case, make sure the test will fail if there's no <lastUpdated>
|
||||
// inside "maven-metadata.xml"
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?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 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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.apache.maven.its.mng6754</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>child-a</artifactId>
|
||||
<name>Maven Integration Test :: Child A</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,33 @@
|
|||
package org.apache.maven.its.mng6754;
|
||||
|
||||
/*
|
||||
* 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.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DelayingTest
|
||||
{
|
||||
@Test
|
||||
public void generateSomeDelay() throws InterruptedException
|
||||
{
|
||||
TimeUnit.SECONDS.sleep( 1 );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?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 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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.apache.maven.its.mng6754</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>child-b</artifactId>
|
||||
<name>Maven Integration Test :: Child B</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,33 @@
|
|||
package org.apache.maven.its.mng6754;
|
||||
|
||||
/*
|
||||
* 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.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DelayingTest
|
||||
{
|
||||
@Test
|
||||
public void generateSomeDelay() throws InterruptedException
|
||||
{
|
||||
TimeUnit.SECONDS.sleep( 1 );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
<?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 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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.apache.maven.its.mng6754</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Maven Integration Test :: MNG-6754</name>
|
||||
<description>
|
||||
Test that version timestamp is equal for each module in the build.
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
|
||||
<timestamp>${maven.build.timestamp}</timestamp>
|
||||
</properties>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>maven-core-it</id>
|
||||
<url>file:///${repodir}</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<modules>
|
||||
<module>child-a</module>
|
||||
<module>child-b</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<artifactId>maven-it-plugin-expression</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<configuration>
|
||||
<outputFile>target/timestamp.properties</outputFile>
|
||||
<expressions>
|
||||
<expression>project/properties/timestamp</expression>
|
||||
</expressions>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>test</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>eval</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
Loading…
Reference in New Issue