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