KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > artifact > test > ArtifactTestCase


1 package org.apache.maven.artifact.test;
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.Artifact;
20 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
21 import org.apache.maven.artifact.repository.ArtifactRepository;
22 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
23 import org.apache.maven.settings.Settings;
24 import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
25 import org.codehaus.plexus.PlexusTestCase;
26
27 import java.io.File JavaDoc;
28 import java.io.FileReader JavaDoc;
29
30 /**
31  * Test case that builds standard artifact stuff like repositories.
32  *
33  * @author <a HREF="mailto:brett@apache.org">Brett Porter</a>
34  * @version $Id: ArtifactTestCase.java 379537 2006-02-21 17:16:39Z jvanzyl $
35  */

36 public abstract class ArtifactTestCase
37     extends PlexusTestCase
38 {
39     private ArtifactRepository localRepository;
40
41     protected File JavaDoc getLocalArtifactPath( Artifact artifact )
42     {
43         return new File JavaDoc( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
44     }
45
46     protected void setUp()
47         throws Exception JavaDoc
48     {
49         super.setUp();
50
51         File JavaDoc settingsFile = new File JavaDoc( System.getProperty( "user.home" ), ".m2/settings.xml" );
52         String JavaDoc localRepo = null;
53         if ( settingsFile.exists() )
54         {
55             Settings settings = new SettingsXpp3Reader().read( new FileReader JavaDoc( settingsFile ) );
56             localRepo = settings.getLocalRepository();
57         }
58         if ( localRepo == null )
59         {
60             localRepo = System.getProperty( "user.home" ) + "/.m2/repository";
61         }
62
63         ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) container.lookup(
64             ArtifactRepositoryLayout.ROLE, "default" );
65
66         localRepository = new DefaultArtifactRepository( "local", "file://" + localRepo, repositoryLayout );
67     }
68
69 }
70
Popular Tags