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  
24  import org.apache.maven.it.util.ResourceExtractor;
25  
26  /**
27   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-6256">MNG-6256</a>: check that directories
28   * passed via <code>-f/--file</code> containing special characters do not break the script. E.g
29   * <code>-f "directoryWithClosing)Bracket/pom.xml"</code>.
30   */
31  public class MavenITmng6256SpecialCharsAlternatePOMLocation
32      extends AbstractMavenIntegrationTestCase
33  {
34      public MavenITmng6256SpecialCharsAlternatePOMLocation()
35      {
36          super( "(3.6.0,)" );
37      }
38  
39      protected MavenITmng6256SpecialCharsAlternatePOMLocation( String constraint )
40      {
41          super( constraint );
42      }
43  
44      /**
45       * check script is working when path to POM is set to <code>directory-with- -space</code>
46       *
47       * @throws Exception in case of failure
48       */
49      public void testDirectoryWithSpace()
50          throws Exception
51      {
52          runWithMvnFileLongOption( "directory-with- -space" );
53          runWithMvnFileShortOption( "directory-with- -space" );
54      }
55  
56      /**
57       * check script is working when path to POM is set to <code>directory-with-)-closing-bracket</code>
58       *
59       * @throws Exception in case of failure
60       */
61      public void testDirectoryWithClosingBracket()
62          throws Exception
63      {
64          runWithMvnFileLongOption( "directory-with-)-closing-bracket" );
65          runWithMvnFileShortOption( "directory-with-)-closing-bracket" );
66      }
67  
68      private void runWithMvnFileLongOption( String subDir )
69          throws Exception
70      {
71          runCoreExtensionWithOption( "--file", subDir );
72      }
73  
74      private void runWithMvnFileShortOption( String subDir )
75          throws Exception
76      {
77          runCoreExtensionWithOption( "-f", subDir );
78      }
79  
80      private void runCoreExtensionWithOption( String option, String subDir )
81          throws Exception
82      {
83          File resourceDir =
84              ResourceExtractor.simpleExtractResources( getClass(), "/mng-6256-special-chars-alternate-pom-location" );
85  
86          File testDir = new File( resourceDir, "../mng-6256-" + subDir );
87          testDir.mkdir();
88  
89          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
90          verifier.getCliOptions().add( option ); // -f/--file
91          verifier.getCliOptions().add( "\"" + new File( resourceDir, subDir ).getAbsolutePath() + "\"" ); // "<path>"
92          verifier.executeGoal( "validate" );
93          verifier.verifyErrorFreeLog();
94          verifier.resetStreams();
95      }
96  }