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.apache.maven.repository.RepositorySystem; 22 import org.codehaus.plexus.PlexusTestCase; 23 import org.junit.Ignore; 24 25 @Ignore 26 public class MavenMetadataSourceTest extends PlexusTestCase { 27 private RepositorySystem repositorySystem; 28 29 protected void setUp() throws Exception { 30 super.setUp(); 31 repositorySystem = lookup(RepositorySystem.class); 32 } 33 34 @Override 35 protected void tearDown() throws Exception { 36 repositorySystem = null; 37 super.tearDown(); 38 } 39 40 public 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 deps = new ArrayList(); 61 deps.add( dep1 ); 62 deps.add( dep2 ); 63 64 ArtifactFactory factory = lookup( ArtifactFactory.class ); 65 66 ArtifactFilter dependencyFilter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE ); 67 68 MavenProject project = new MavenProject( new Model() ); 69 70 Set result = project.createArtifacts( dependencyFilter ); 71 72 for ( Iterator it = result.iterator(); it.hasNext(); ) 73 { 74 Artifact 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 // TODO restore these if it makes sense 87 /* 88 public void testShouldUseCompileScopeIfDependencyScopeEmpty() 89 throws Exception 90 { 91 String groupId = "org.apache.maven"; 92 String artifactId = "maven-model"; 93 94 Dependency dep = new Dependency(); 95 96 dep.setGroupId( groupId ); 97 dep.setArtifactId( artifactId ); 98 dep.setVersion( "2.0-alpha-3" ); 99 100 Model model = new Model(); 101 102 model.addDependency( dep ); 103 104 MavenProject project = new MavenProject( model, repositorySystem ); 105 106 project.setArtifacts( project.createArtifacts( null ) ); 107 108 String key = ArtifactUtils.versionlessKey( groupId, artifactId ); 109 110 Map artifactMap = project.getArtifactMap(); 111 112 assertNotNull( "artifact-map should not be null.", artifactMap ); 113 assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() ); 114 115 Artifact artifact = (Artifact) artifactMap.get( key ); 116 117 assertNotNull( "dependency artifact not found in map.", artifact ); 118 assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_COMPILE, artifact.getScope() ); 119 120 //check for back-propagation of default scope. 121 assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_COMPILE, dep.getScope() ); 122 } 123 124 public void testShouldUseInjectedTestScopeFromDependencyManagement() 125 throws Exception 126 { 127 String groupId = "org.apache.maven"; 128 String artifactId = "maven-model"; 129 130 Dependency dep = new Dependency(); 131 132 dep.setGroupId( groupId ); 133 dep.setArtifactId( artifactId ); 134 dep.setVersion( "2.0-alpha-3" ); 135 136 Model model = new Model(); 137 138 model.addDependency( dep ); 139 140 Dependency mgd = new Dependency(); 141 mgd.setGroupId( groupId ); 142 mgd.setArtifactId( artifactId ); 143 mgd.setScope( Artifact.SCOPE_TEST ); 144 145 DependencyManagement depMgmt = new DependencyManagement(); 146 147 depMgmt.addDependency( mgd ); 148 149 model.setDependencyManagement( depMgmt ); 150 151 MavenProject project = new MavenProject( model, repositorySystem ); 152 153 TestModelDefaultsInjector injector = new TestModelDefaultsInjector(); 154 155 injector.injectDefaults( model ); 156 157 project.setArtifacts( project.createArtifacts( null ) ); 158 159 String key = ArtifactUtils.versionlessKey( groupId, artifactId ); 160 161 Map artifactMap = project.getArtifactMap(); 162 163 assertNotNull( "artifact-map should not be null.", artifactMap ); 164 assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() ); 165 166 Artifact artifact = (Artifact) artifactMap.get( key ); 167 168 assertNotNull( "dependency artifact not found in map.", artifact ); 169 assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_TEST, artifact.getScope() ); 170 171 //check for back-propagation of default scope. 172 assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() ); 173 } 174 */ 175 176 }