001    package org.apache.maven;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
005     * agreements. See the NOTICE file distributed with this work for additional information regarding
006     * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance with the License. You may obtain a
008     * copy of the License at
009     *
010     * http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software distributed under the License
013     * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
014     * or implied. See the License for the specific language governing permissions and limitations under
015     * the License.
016     */
017    
018    import java.io.File;
019    import java.util.Collections;
020    import java.util.List;
021    import java.util.Properties;
022    import java.util.Set;
023    
024    import org.apache.maven.artifact.Artifact;
025    import org.apache.maven.execution.MavenSession;
026    import org.apache.maven.project.MavenProject;
027    import org.codehaus.plexus.component.annotations.Requirement;
028    
029    public class ProjectDependenciesResolverTest
030        extends AbstractCoreMavenComponentTestCase
031    {
032        @Requirement
033        private ProjectDependenciesResolver resolver;
034    
035        protected void setUp()
036            throws Exception
037        {
038            super.setUp();
039            resolver = lookup( ProjectDependenciesResolver.class );
040        }
041    
042        @Override
043        protected void tearDown()
044            throws Exception
045        {
046            resolver = null;
047            super.tearDown();
048        }
049    
050        protected String getProjectsDirectory()
051        {
052            return "src/test/projects/project-dependencies-resolver";
053        }
054    
055        /*
056        public void testExclusionsInDependencies()
057            throws Exception
058        {
059            MavenSession session = createMavenSession( null );
060            MavenProject project = session.getCurrentProject();
061    
062            Exclusion exclusion = new Exclusion();
063            exclusion.setGroupId( "org.apache.maven.its" );
064            exclusion.setArtifactId( "a" );
065    
066            new ProjectBuilder( project ).addDependency( "org.apache.maven.its", "b", "0.1", Artifact.SCOPE_RUNTIME,
067                                                         exclusion );
068            
069            Set<Artifact> artifactDependencies =
070                resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), session );
071            assertEquals( 0, artifactDependencies.size() );
072    
073            artifactDependencies = resolver.resolve( project, Collections.singleton( Artifact.SCOPE_RUNTIME ), session );
074            assertEquals( 1, artifactDependencies.size() );
075            assertEquals( "b", artifactDependencies.iterator().next().getArtifactId() );
076        }
077        */
078        
079        public void testSystemScopeDependencies()
080            throws Exception
081        {
082            MavenSession session = createMavenSession( null );
083            MavenProject project = session.getCurrentProject();
084    
085            new ProjectBuilder( project )
086                .addDependency( "com.mycompany", "system-dependency", "1.0", Artifact.SCOPE_SYSTEM, new File( getBasedir(), "pom.xml" ).getAbsolutePath() );
087    
088            Set<Artifact> artifactDependencies =
089                resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), session );
090            assertEquals( 1, artifactDependencies.size() );
091        }  
092        
093        public void testSystemScopeDependencyIsPresentInTheCompileClasspathElements()
094            throws Exception
095        {
096            File pom = getProject( "it0063" );
097    
098            Properties eps = new Properties();
099            eps.setProperty( "jre.home", new File( pom.getParentFile(), "jdk/jre" ).getPath() );
100    
101            MavenSession session = createMavenSession( pom, eps );
102            MavenProject project = session.getCurrentProject();
103    
104            project.setArtifacts( resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), session ) );
105                    
106            List<String> elements = project.getCompileClasspathElements();
107            assertEquals( 2, elements.size() );
108            
109            @SuppressWarnings( "deprecation" )
110            List<Artifact> artifacts = project.getCompileArtifacts();
111            assertEquals( 1, artifacts.size() );
112            assertTrue( artifacts.get( 0 ).getFile().getName().endsWith( "tools.jar" ) );
113        }
114    }