KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > project > AbstractMavenProjectTestCase


1 package org.apache.maven.project;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * 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, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.maven.artifact.repository.ArtifactRepository;
20 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
21 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
22 import org.apache.maven.profiles.DefaultProfileManager;
23 import org.codehaus.plexus.PlexusTestCase;
24
25 import java.io.File JavaDoc;
26 import java.io.FileNotFoundException JavaDoc;
27 import java.net.URL JavaDoc;
28
29 /**
30  * @author <a HREF="mailto:jason@maven.org">Jason van Zyl </a>
31  * @version $Id: AbstractMavenProjectTestCase.java 240178 2005-08-26 07:31:18Z brett $
32  */

33 public abstract class AbstractMavenProjectTestCase
34     extends PlexusTestCase
35 {
36     protected MavenProjectBuilder projectBuilder;
37
38     protected void setUp()
39         throws Exception JavaDoc
40     {
41         super.setUp();
42
43         if ( getContainer().hasComponent( MavenProjectBuilder.ROLE, "test" ) )
44         {
45             projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE, "test" );
46         }
47         else
48         {
49             // default over to the main project builder...
50
projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
51         }
52     }
53
54     // ----------------------------------------------------------------------
55
// Local repository
56
// ----------------------------------------------------------------------
57

58     protected File JavaDoc getLocalRepositoryPath()
59         throws FileNotFoundException JavaDoc
60     {
61         File JavaDoc markerFile = getFileForClasspathResource( "local-repo/marker.txt" );
62
63         return markerFile.getAbsoluteFile().getParentFile();
64     }
65
66     protected File JavaDoc getFileForClasspathResource( String JavaDoc resource )
67         throws FileNotFoundException JavaDoc
68     {
69         ClassLoader JavaDoc cloader = Thread.currentThread().getContextClassLoader();
70
71         URL JavaDoc resourceUrl = cloader.getResource( resource );
72
73         File JavaDoc resourceFile = null;
74         if ( resourceUrl != null )
75         {
76             resourceFile = new File JavaDoc( resourceUrl.getPath() );
77         }
78         else
79         {
80             throw new FileNotFoundException JavaDoc( "Unable to find: " + resource );
81         }
82
83         return resourceFile;
84     }
85
86     protected ArtifactRepository getLocalRepository()
87         throws Exception JavaDoc
88     {
89         ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
90                                                                                  "legacy" );
91
92         ArtifactRepository r = new DefaultArtifactRepository( "local",
93                                                               "file://" + getLocalRepositoryPath().getAbsolutePath(),
94                                                               repoLayout );
95
96         return r;
97     }
98
99     // ----------------------------------------------------------------------
100
// Project building
101
// ----------------------------------------------------------------------
102

103     protected MavenProject getProjectWithDependencies( File JavaDoc pom )
104         throws Exception JavaDoc
105     {
106         return projectBuilder.buildWithDependencies( pom, getLocalRepository(), null );
107     }
108
109     protected MavenProject getProject( File JavaDoc pom )
110         throws Exception JavaDoc
111     {
112         return projectBuilder.build( pom, getLocalRepository(), new DefaultProfileManager( getContainer() ) );
113     }
114
115 }
116
Popular Tags