001: package 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:
022: import org.apache.maven.artifact.repository.ArtifactRepository;
023: import org.apache.maven.artifact.repository.DefaultArtifactRepository;
024: import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
025: import org.apache.maven.profiles.DefaultProfileManager;
026: import org.codehaus.plexus.PlexusTestCase;
027:
028: import java.io.File;
029: import java.io.FileNotFoundException;
030: import java.net.URI;
031: import java.net.URISyntaxException;
032: import java.net.URL;
033:
034: /**
035: * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
036: * @version $Id: AbstractMavenProjectTestCase.java 573718 2007-09-07 21:29:08Z jvanzyl $
037: */
038: public abstract class AbstractMavenProjectTestCase extends
039: PlexusTestCase {
040: protected MavenProjectBuilder projectBuilder;
041:
042: protected void setUp() throws Exception {
043: super .setUp();
044:
045: if (getContainer().hasComponent(MavenProjectBuilder.ROLE,
046: "test")) {
047: projectBuilder = (MavenProjectBuilder) lookup(
048: MavenProjectBuilder.ROLE, "test");
049: } else {
050: // default over to the main project builder...
051: projectBuilder = (MavenProjectBuilder) lookup(MavenProjectBuilder.ROLE);
052: }
053: }
054:
055: // ----------------------------------------------------------------------
056: // Local repository
057: // ----------------------------------------------------------------------
058:
059: protected File getLocalRepositoryPath()
060: throws FileNotFoundException, URISyntaxException {
061: File markerFile = getFileForClasspathResource("local-repo/marker.txt");
062:
063: return markerFile.getAbsoluteFile().getParentFile();
064: }
065:
066: protected File getFileForClasspathResource(String resource)
067: throws FileNotFoundException, URISyntaxException {
068: ClassLoader cloader = Thread.currentThread()
069: .getContextClassLoader();
070:
071: URL resourceUrl = cloader.getResource(resource);
072:
073: if (resourceUrl == null) {
074: throw new FileNotFoundException("Unable to find: "
075: + resource);
076: }
077:
078: return new File(new URI(resourceUrl.toString()));
079: }
080:
081: protected ArtifactRepository getLocalRepository() throws Exception {
082: ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup(
083: ArtifactRepositoryLayout.ROLE, "legacy");
084:
085: ArtifactRepository r = new DefaultArtifactRepository("local",
086: "file://" + getLocalRepositoryPath().getAbsolutePath(),
087: repoLayout);
088:
089: return r;
090: }
091:
092: // ----------------------------------------------------------------------
093: // Project building
094: // ----------------------------------------------------------------------
095:
096: protected MavenProject getProjectWithDependencies(File pom)
097: throws Exception {
098: return projectBuilder.buildWithDependencies(pom,
099: getLocalRepository(), null).getProject();
100: }
101:
102: protected MavenProject getProject(File pom) throws Exception {
103: return projectBuilder.build(pom, getLocalRepository(),
104: new DefaultProfileManager(getContainer()));
105: }
106:
107: }
|