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 /*
25 * Licensed to the Apache Software Foundation (ASF) under one
26 * or more contributor license agreements. See the NOTICE file
27 * distributed with this work for additional information
28 * regarding copyright ownership. The ASF licenses this file
29 * to you under the Apache License, Version 2.0 (the
30 * "License"); you may not use this file except in compliance
31 * with the License. You may obtain a copy of the License at
32 *
33 * http://www.apache.org/licenses/LICENSE-2.0
34 *
35 * Unless required by applicable law or agreed to in writing,
36 * software distributed under the License is distributed on an
37 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
38 * KIND, either express or implied. See the License for the
39 * specific language governing permissions and limitations
40 * under the License.
41 */
42
43 import org.apache.maven.it.util.ResourceExtractor;
44
45 /**
46 * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-6772">MNG-6772</a>:
47 *
48 * The test POM references an import scope POM, which also has a dependency on an import scope POM.
49 *
50 * Both import POMs can only be found in the repository defined in the test POM.
51 * It has a parent POM that defines the same repository with a different location.
52 * The test confirms that the dominant repository definition (child) wins while resolving the import POMs.
53 *
54 */
55 public class MavenITmng6772NestedImportScopeRepositoryOverride
56 extends AbstractMavenIntegrationTestCase
57 {
58
59 public MavenITmng6772NestedImportScopeRepositoryOverride()
60 {
61 super( "(,4.0.0-alpha-1),[4.0.0-alpha-1,)" );
62 }
63
64 // This will test the behavior using ProjectModelResolver
65 public void testitInProject()
66 throws Exception
67 {
68 final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6772-override-in-project" );
69
70 final Verifier verifier = newVerifier( testDir.getAbsolutePath(), null );
71 overrideGlobalSettings( testDir, verifier );
72 verifier.deleteArtifacts( "org.apache.maven.its.mng6772" );
73
74 verifier.filterFile( "pom-template.xml", "pom.xml", "UTF-8", verifier.newDefaultFilterProperties() );
75
76 verifier.executeGoal( "validate" );
77 verifier.verifyErrorFreeLog();
78 verifier.resetStreams();
79 }
80
81 // This will test the behavior using DefaultModelResolver
82 public void testitInDependency()
83 throws Exception
84 {
85 final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6772-override-in-dependency" );
86
87 final Verifier verifier = newVerifier( testDir.getAbsolutePath(), null );
88 overrideGlobalSettings( testDir, verifier );
89 verifier.deleteArtifacts( "org.apache.maven.its.mng6772" );
90
91 verifier.filterFile( "pom-template.xml", "pom.xml", "UTF-8", verifier.newDefaultFilterProperties() );
92
93 verifier.executeGoal( "compile" );
94 verifier.verifyErrorFreeLog();
95 verifier.resetStreams();
96 }
97
98 // central must not be defined in any settings.xml or super POM will never be in play.
99 private void overrideGlobalSettings( final File testDir, final Verifier verifier )
100 {
101 final File settingsFile = new File( testDir, "settings-override.xml" );
102 final String path = settingsFile.getAbsolutePath();
103 verifier.getCliOptions().add( "--global-settings" );
104 if ( path.indexOf( ' ' ) < 0 )
105 {
106 verifier.getCliOptions().add( path );
107 }
108 else
109 {
110 verifier.getCliOptions().add( '"' + path + '"' );
111 }
112 }
113
114 }