View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.project.artifact;
20  
21  import org.junit.jupiter.api.Test;
22  
23  public class MavenMetadataSourceTest {
24  
25      @Test
26      public void testShouldNotCarryExclusionsOverFromDependencyToDependency() {
27          /*
28          Dependency dep1 = new Dependency();
29          dep1.setGroupId( "test" );
30          dep1.setArtifactId( "test-artifact" );
31          dep1.setVersion( "1" );
32          dep1.setType( "jar" );
33  
34          Exclusion exc = new Exclusion();
35          exc.setGroupId( "test" );
36          exc.setArtifactId( "test-artifact3" );
37  
38          dep1.addExclusion( exc );
39  
40          Dependency dep2 = new Dependency();
41          dep2.setGroupId( "test" );
42          dep2.setArtifactId( "test-artifact2" );
43          dep2.setVersion( "1" );
44          dep2.setType( "jar" );
45  
46          List deps = new ArrayList();
47          deps.add( dep1 );
48          deps.add( dep2 );
49  
50          ArtifactFactory factory = lookup( ArtifactFactory.class );
51  
52          ArtifactFilter dependencyFilter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE );
53  
54          MavenProject project = new MavenProject( new Model() );
55  
56          Set result = project.createArtifacts( dependencyFilter );
57  
58          for ( Iterator it = result.iterator(); it.hasNext(); )
59          {
60              Artifact artifact = ( Artifact ) it.next();
61  
62              if ( "test-artifact2".equals( artifact.getArtifactId() ) )
63              {
64                  ArtifactFilter filter = artifact.getDependencyFilter();
65  
66                  assertSame( dependencyFilter, filter );
67              }
68          }
69          */
70      }
71  
72      // TODO restore these if it makes sense
73      /*
74      public void testShouldUseCompileScopeIfDependencyScopeEmpty()
75          throws Exception
76      {
77          String groupId = "org.apache.maven";
78          String artifactId = "maven-model";
79  
80          Dependency dep = new Dependency();
81  
82          dep.setGroupId( groupId );
83          dep.setArtifactId( artifactId );
84          dep.setVersion( "2.0-alpha-3" );
85  
86          Model model = new Model();
87  
88          model.addDependency( dep );
89  
90          MavenProject project = new MavenProject( model, repositorySystem );
91  
92          project.setArtifacts( project.createArtifacts( null ) );
93  
94          String key = ArtifactUtils.versionlessKey( groupId, artifactId );
95  
96          Map artifactMap = project.getArtifactMap();
97  
98          assertNotNull( "artifact-map should not be null.", artifactMap );
99          assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() );
100 
101         Artifact artifact = (Artifact) artifactMap.get( key );
102 
103         assertNotNull( "dependency artifact not found in map.", artifact );
104         assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_COMPILE, artifact.getScope() );
105 
106         //check for back-propagation of default scope.
107         assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_COMPILE, dep.getScope() );
108     }
109 
110     public void testShouldUseInjectedTestScopeFromDependencyManagement()
111         throws Exception
112     {
113         String groupId = "org.apache.maven";
114         String artifactId = "maven-model";
115 
116         Dependency dep = new Dependency();
117 
118         dep.setGroupId( groupId );
119         dep.setArtifactId( artifactId );
120         dep.setVersion( "2.0-alpha-3" );
121 
122         Model model = new Model();
123 
124         model.addDependency( dep );
125 
126         Dependency mgd = new Dependency();
127         mgd.setGroupId( groupId );
128         mgd.setArtifactId( artifactId );
129         mgd.setScope( Artifact.SCOPE_TEST );
130 
131         DependencyManagement depMgmt = new DependencyManagement();
132 
133         depMgmt.addDependency( mgd );
134 
135         model.setDependencyManagement( depMgmt );
136 
137         MavenProject project = new MavenProject( model, repositorySystem );
138 
139         TestModelDefaultsInjector injector = new TestModelDefaultsInjector();
140 
141         injector.injectDefaults( model );
142 
143         project.setArtifacts( project.createArtifacts( null ) );
144 
145         String key = ArtifactUtils.versionlessKey( groupId, artifactId );
146 
147         Map artifactMap = project.getArtifactMap();
148 
149         assertNotNull( "artifact-map should not be null.", artifactMap );
150         assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() );
151 
152         Artifact artifact = (Artifact) artifactMap.get( key );
153 
154         assertNotNull( "dependency artifact not found in map.", artifact );
155         assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_TEST, artifact.getScope() );
156 
157         //check for back-propagation of default scope.
158         assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() );
159     }
160     */
161 
162 }