01: package org.apache.maven.project;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21:
22: import org.apache.maven.artifact.repository.ArtifactRepository;
23: import org.apache.maven.artifact.repository.DefaultArtifactRepository;
24: import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
25: import org.codehaus.plexus.util.FileUtils;
26:
27: import java.io.File;
28: import java.util.ArrayList;
29: import java.util.Iterator;
30: import java.util.List;
31:
32: public class DefaultMavenProjectBuilderTest extends
33: AbstractMavenProjectTestCase {
34:
35: private List filesToDelete = new ArrayList();
36:
37: private File localRepoDir;
38:
39: private DefaultMavenProjectBuilder projectBuilder;
40:
41: public void setUp() throws Exception {
42: super .setUp();
43:
44: projectBuilder = (DefaultMavenProjectBuilder) lookup(MavenProjectBuilder.ROLE);
45:
46: localRepoDir = new File(System.getProperty("java.io.tmpdir"),
47: "local-repo." + System.currentTimeMillis());
48: localRepoDir.mkdirs();
49:
50: filesToDelete.add(localRepoDir);
51: }
52:
53: public void tearDown() throws Exception {
54: super .tearDown();
55:
56: if (!filesToDelete.isEmpty()) {
57: for (Iterator it = filesToDelete.iterator(); it.hasNext();) {
58: File file = (File) it.next();
59:
60: if (file.exists()) {
61: if (file.isDirectory()) {
62: FileUtils.deleteDirectory(file);
63: } else {
64: file.delete();
65: }
66: }
67: }
68: }
69: }
70:
71: /**
72: * Check that we can build ok from the middle pom of a (parent,child,grandchild) heirarchy
73: * @throws Exception
74: */
75: public void testBuildFromMiddlePom() throws Exception {
76: File f1 = getTestFile("src/test/resources/projects/grandchild-check/child/pom.xml");
77: File f2 = getTestFile("src/test/resources/projects/grandchild-check/child/grandchild/pom.xml");
78:
79: getProject(f1);
80:
81: // it's the building of the grandchild project, having already cached the child project
82: // (but not the parent project), which causes the problem.
83: getProject(f2);
84: }
85:
86: protected ArtifactRepository getLocalRepository() throws Exception {
87: ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup(
88: ArtifactRepositoryLayout.ROLE, "legacy");
89:
90: ArtifactRepository r = new DefaultArtifactRepository("local",
91: "file://" + localRepoDir.getAbsolutePath(), repoLayout);
92:
93: return r;
94: }
95: }
|