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 java.io.File;
23  import java.util.Properties;
24  
25  import org.apache.maven.it.util.ResourceExtractor;
26  
27  import com.google.common.base.Charsets;
28  import com.google.common.base.Joiner;
29  import com.google.common.io.Files;
30  
31  /**
32   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-6255">MNG-6255</a>:
33   * Check that the <code>.mvn/jvm.config</code> file contents are concatenated properly, no matter
34   * what line endings are used.
35   */
36  public class MavenITmng6255FixConcatLines
37      extends AbstractMavenIntegrationTestCase
38  {
39      public MavenITmng6255FixConcatLines()
40      {
41          super( "[3.5.3,)" );
42      }
43  
44      protected MavenITmng6255FixConcatLines( String constraint )
45      {
46          super( constraint );
47      }
48  
49      /**
50       * Check that <code>CR</code> line endings work.
51       * <p>
52       * Currently disabled.
53       *
54       * @throws Exception in case of failure
55       */
56      public void disabledJvmConfigFileCR()
57          throws Exception
58      {
59          runWithLineEndings( "\r" );
60      }
61  
62      /**
63       * Check that <code>LF</code> line endings work.
64       *
65       * @throws Exception in case of failure
66       */
67      public void testJvmConfigFileLF()
68          throws Exception
69      {
70          runWithLineEndings( "\n" );
71      }
72  
73      /**
74       * Check that <code>CRLF</code> line endings work.
75       *
76       * @throws Exception in case of failure
77       */
78      public void testJvmConfigFileCRLF()
79          throws Exception
80      {
81          runWithLineEndings( "\r\n" );
82      }
83  
84      protected void runWithLineEndings( String lineEndings )
85          throws Exception
86      {
87          File baseDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6255" );
88          File mvnDir = new File( baseDir, ".mvn" );
89  
90          File jvmConfig = new File( mvnDir, "jvm.config" );
91          createJvmConfigFile( jvmConfig, lineEndings, "-Djvm.config=ok", "-Xms256m", "-Xmx512m" );
92  
93          Verifier verifier = newVerifier( baseDir.getAbsolutePath() );
94          verifier.getCliOptions().add( "-Dexpression.outputFile=" + new File( baseDir, "expression.properties" ).getAbsolutePath() );
95          verifier.setForkJvm( true );
96          verifier.executeGoal( "validate" );
97          verifier.verifyErrorFreeLog();
98          verifier.resetStreams();
99  
100         Properties props = verifier.loadProperties( "expression.properties" );
101         assertEquals( "ok", props.getProperty( "project.properties.jvm-config" ) );
102     }
103 
104     protected void createJvmConfigFile( File jvmConfig, String lineEndings, String...lines )
105         throws Exception
106     {
107         String content = Joiner.on(lineEndings).join(lines);
108         Files.write( content, jvmConfig, Charsets.UTF_8 );
109     }
110 }