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 javax.inject.Inject;
22  
23  import org.apache.maven.repository.RepositorySystem;
24  import org.codehaus.plexus.PlexusContainer;
25  import org.codehaus.plexus.testing.PlexusTest;
26  import org.junit.jupiter.api.Disabled;
27  import org.junit.jupiter.api.Test;
28  
29  @PlexusTest
30  @Deprecated
31  class MavenMetadataSourceTest {
32      @Inject
33      private RepositorySystem repositorySystem;
34  
35      @Inject
36      PlexusContainer container;
37  
38      @Test
39      @Disabled
40      void testShouldNotCarryExclusionsOverFromDependencyToDependency() throws Exception {
41          /*
42          Dependency dep1 = new Dependency();
43          dep1.setGroupId( "test" );
44          dep1.setArtifactId( "test-artifact" );
45          dep1.setVersion( "1" );
46          dep1.setType( "jar" );
47  
48          Exclusion exc = new Exclusion();
49          exc.setGroupId( "test" );
50          exc.setArtifactId( "test-artifact3" );
51  
52          dep1.addExclusion( exc );
53  
54          Dependency dep2 = new Dependency();
55          dep2.setGroupId( "test" );
56          dep2.setArtifactId( "test-artifact2" );
57          dep2.setVersion( "1" );
58          dep2.setType( "jar" );
59  
60          List<Dependency> deps = new ArrayList<>();
61          deps.add( dep1 );
62          deps.add( dep2 );
63  
64          ArtifactFactory factory = container.lookup( ArtifactFactory.class );
65  
66          ArtifactFilter dependencyFilter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE );
67  
68          MavenProject project = new MavenProject( new Model() );
69  
70          Set<Artifact> result = project.createArtifacts( dependencyFilter );
71  
72          for (Iterator<Artifact> it = result.iterator(); it.hasNext(); )
73          {
74              Artifact artifact = it.next();
75  
76              if ( "test-artifact2".equals( artifact.getArtifactId() ) )
77              {
78                  ArtifactFilter filter = artifact.getDependencyFilter();
79  
80                  assertSame( dependencyFilter, filter );
81              }
82          }
83          */
84      }
85  
86      @Test
87      @Disabled("TODO restore these if it makes sense")
88      void testShouldUseCompileScopeIfDependencyScopeEmpty() throws Exception {
89          /*
90          String groupId = "org.apache.maven";
91          String artifactId = "maven-model";
92  
93          Dependency dep = new Dependency();
94  
95          dep.setGroupId( groupId );
96          dep.setArtifactId( artifactId );
97          dep.setVersion( "2.0-alpha-3" );
98  
99          Model model = new Model();
100 
101         model.addDependency( dep );
102 
103         MavenProject project = new MavenProject( model, repositorySystem );
104 
105         project.setArtifacts( project.createArtifacts( null ) );
106 
107         String key = ArtifactUtils.versionlessKey( groupId, artifactId );
108 
109         Map artifactMap = project.getArtifactMap();
110 
111         assertNotNull( artifactMap, "artifact-map should not be null." );
112         assertEquals( 1, artifactMap.size(), "artifact-map should contain 1 element." );
113 
114         Artifact artifact = (Artifact) artifactMap.get( key );
115 
116         assertNotNull( artifact, "dependency artifact not found in map." );
117         assertEquals( Artifact.SCOPE_COMPILE, artifact.getScope(), "dependency artifact has wrong scope." );
118 
119         //check for back-propagation of default scope.
120         assertEquals( Artifact.SCOPE_COMPILE, dep.getScope(), "default scope NOT back-propagated to dependency." );
121         */
122     }
123 
124     @Test
125     @Disabled
126     void testShouldUseInjectedTestScopeFromDependencyManagement() throws Exception {
127         /*
128         String groupId = "org.apache.maven";
129         String artifactId = "maven-model";
130 
131         Dependency dep = new Dependency();
132 
133         dep.setGroupId( groupId );
134         dep.setArtifactId( artifactId );
135         dep.setVersion( "2.0-alpha-3" );
136 
137         Model model = new Model();
138 
139         model.addDependency( dep );
140 
141         Dependency mgd = new Dependency();
142         mgd.setGroupId( groupId );
143         mgd.setArtifactId( artifactId );
144         mgd.setScope( Artifact.SCOPE_TEST );
145 
146         DependencyManagement depMgmt = new DependencyManagement();
147 
148         depMgmt.addDependency( mgd );
149 
150         model.setDependencyManagement( depMgmt );
151 
152         MavenProject project = new MavenProject( model, repositorySystem );
153 
154         TestModelDefaultsInjector injector = new TestModelDefaultsInjector();
155 
156         injector.injectDefaults( model );
157 
158         project.setArtifacts( project.createArtifacts( null ) );
159 
160         String key = ArtifactUtils.versionlessKey( groupId, artifactId );
161 
162         Map artifactMap = project.getArtifactMap();
163 
164         assertNotNull( artifactMap, "artifact-map should not be null." );
165         assertEquals( 1, artifactMap.size(), "artifact-map should contain 1 element." );
166 
167         Artifact artifact = (Artifact) artifactMap.get( key );
168 
169         assertNotNull( artifact, "dependency artifact not found in map." );
170         assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_TEST, artifact.getScope() );
171 
172         //check for back-propagation of default scope.
173         assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() );
174         */
175     }
176 }