001package org.apache.maven.project; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.File; 023import java.util.Properties; 024 025import org.apache.maven.AbstractCoreMavenComponentTestCase; 026import org.apache.maven.execution.MavenSession; 027import org.apache.maven.model.building.FileModelSource; 028import org.apache.maven.model.building.ModelSource; 029 030public class ProjectBuilderTest 031 extends AbstractCoreMavenComponentTestCase 032{ 033 protected String getProjectsDirectory() 034 { 035 return "src/test/projects/project-builder"; 036 } 037 038 public void testSystemScopeDependencyIsPresentInTheCompileClasspathElements() 039 throws Exception 040 { 041 File pom = getProject( "it0063" ); 042 043 Properties eps = new Properties(); 044 eps.setProperty( "jre.home", new File( pom.getParentFile(), "jdk/jre" ).getPath() ); 045 046 MavenSession session = createMavenSession( pom, eps ); 047 MavenProject project = session.getCurrentProject(); 048 049 // Here we will actually not have any artifacts because the ProjectDependenciesResolver is not involved here. So 050 // right now it's not valid to ask for artifacts unless plugins require the artifacts. 051 052 project.getCompileClasspathElements(); 053 } 054 055 public void testBuildFromModelSource() 056 throws Exception 057 { 058 File pomFile = new File( "src/test/resources/projects/modelsource/module01/pom.xml" ); 059 MavenSession mavenSession = createMavenSession( pomFile ); 060 ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest(); 061 configuration.setRepositorySession( mavenSession.getRepositorySession() ); 062 ModelSource modelSource = new FileModelSource( pomFile ); 063 ProjectBuildingResult result = 064 lookup( org.apache.maven.project.ProjectBuilder.class ).build( modelSource, configuration ); 065 066 assertNotNull( result.getProject().getParentFile() ); 067 } 068 069 public void testVersionlessManagedDependency() 070 throws Exception 071 { 072 File pomFile = new File( "src/test/resources/projects/versionless-managed-dependency.xml" ); 073 MavenSession mavenSession = createMavenSession( null ); 074 ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest(); 075 configuration.setRepositorySession( mavenSession.getRepositorySession() ); 076 077 try 078 { 079 lookup( org.apache.maven.project.ProjectBuilder.class ).build( pomFile, configuration ); 080 fail(); 081 } 082 catch ( ProjectBuildingException e ) 083 { 084 // this is expected 085 } 086 } 087}