View Javadoc
1   package org.apache.maven.it;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.it.util.ResourceExtractor;
23  import org.apache.maven.shared.utils.io.FileUtils;
24  
25  import java.io.File;
26  import java.io.IOException;
27  import java.util.Collections;
28  
29  /**
30   * With the build-consumer the pom.xml will be adjusted during the process.
31   * <ul>
32   *   <li>CLI-friendly versions will be resolved</li>
33   *   <li>parents can omit the version if the relative path points to the correct parent</li>
34   *   <li>dependencies can omit the version if it is part of the reactor</li>
35   * </ul>
36   *
37   * During install the pom will be cleaned up
38   * <ul>
39   *   <li>the modules will be removed</li>
40   *   <li>the relativePath will be removed</li>
41   * </ul>
42   *
43   * <a href="https://issues.apache.org/jira/browse/MNG-6656">MNG-6656</a>.
44   *
45   */
46  public class MavenITmng6656BuildConsumer
47      extends AbstractMavenIntegrationTestCase
48  {
49  
50      public MavenITmng6656BuildConsumer()
51      {
52          super( "[4.0.0-alpha-1,)" );
53      }
54  
55      /**
56       * Verifies:
57       * <ul>
58       *   <li>preserve license</li>
59       *   <li>consistent line separators</li>
60       *   <li>resolved project versions (at least 2 levels deep) in parent and dependencies</li>
61       *   <li>removal of modules in aggregators</li>
62       * </ul>
63       *
64       * @throws Exception in case of failure
65       */
66      public void testPublishedPoms()
67                      throws Exception
68      {
69          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6656-buildconsumer" );
70  
71          Verifier verifier = newVerifier( testDir.getAbsolutePath(), false );
72          verifier.setMavenDebug( false );
73          verifier.setAutoclean( false );
74          verifier.addCliOption( "-Dchangelist=MNG6656" );
75  
76          verifier.executeGoals( Collections.singletonList( "install" ) );
77          verifier.verifyErrorFreeLog();
78  
79          assertTextEquals( new File( testDir, "expected/parent.pom"),
80                  new File( verifier.getArtifactPath( "org.sonatype.mavenbook.multi", "parent", "0.9-MNG6656-SNAPSHOT", "pom" ) ) );
81  
82          assertTextEquals( new File( testDir, "expected/simple-parent.pom"),
83                  new File( verifier.getArtifactPath( "org.sonatype.mavenbook.multi", "simple-parent", "0.9-MNG6656-SNAPSHOT", "pom" ) ) );
84  
85          assertTextEquals( new File( testDir, "expected/simple-weather.pom"),
86                  new File( verifier.getArtifactPath( "org.sonatype.mavenbook.multi", "simple-weather", "0.9-MNG6656-SNAPSHOT", "pom" ) ) );
87  
88          assertTextEquals( new File( testDir, "expected/simple-webapp.pom"),
89                  new File( verifier.getArtifactPath( "org.sonatype.mavenbook.multi", "simple-webapp", "0.9-MNG6656-SNAPSHOT", "pom" ) ) );
90      }
91  
92      static void assertTextEquals( File file1, File file2 )
93          throws IOException
94      {
95          assertEquals( FileUtils.loadFile( file1 ), FileUtils.loadFile( file2 ) );
96      }
97  
98  }