Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Rosenberg2012-12-15 14:11:55 +0000
committerGerrit Code Review @ Eclipse.org2012-12-15 14:11:55 +0000
commit0ecbf0ba7795cb8bdb004e8d04f9a75e8658a0a3 (patch)
tree4f1f2734a669082502a28252f4e63aa458805cac
parent0c7958c4263743ff929abc07ddfe57919f329775 (diff)
parent4a506d22b3715984acb0b1dccf4f1fdf4ac8e46e (diff)
downloadegit-0ecbf0ba7795cb8bdb004e8d04f9a75e8658a0a3.tar.gz
egit-0ecbf0ba7795cb8bdb004e8d04f9a75e8658a0a3.tar.xz
egit-0ecbf0ba7795cb8bdb004e8d04f9a75e8658a0a3.zip
Merge "Find nested projects when searching for project files" into stable-2.2
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/util/ProjectUtilTest.java22
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ProjectUtil.java10
2 files changed, 25 insertions, 7 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/util/ProjectUtilTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/util/ProjectUtilTest.java
index f7e816da8f..bd103f17a8 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/util/ProjectUtilTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/util/ProjectUtilTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2012, Matthias Sohn <matthias.sohn@sap.com>
+ * Copyright (C) 2012, Matthias Sohn <matthias.sohn@sap.com> and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,8 @@
*******************************************************************************/
package org.eclipse.egit.core.internal.util;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -27,6 +29,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.egit.core.op.ConnectProviderOperation;
import org.eclipse.egit.core.test.GitTestCase;
+import org.eclipse.egit.core.test.TestProject;
import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.jgit.util.FileUtils;
import org.junit.After;
@@ -37,6 +40,8 @@ public class ProjectUtilTest extends GitTestCase {
private TestRepository repository;
+ private TestProject project2;
+
@Before
public void setUp() throws Exception {
super.setUp();
@@ -46,6 +51,8 @@ public class ProjectUtilTest extends GitTestCase {
@After
public void tearDown() throws Exception {
super.tearDown();
+ if (project2 != null)
+ project2.dispose();
}
@Test
@@ -140,4 +147,17 @@ public class ProjectUtilTest extends GitTestCase {
new NullProgressMonitor()));
}
+ @Test
+ public void testFindProjectFilesNested() throws Exception {
+ project2 = new TestProject(true, "Project-1/Project-Nested");
+ File workingDir = gitDir.getParentFile();
+
+ Collection<File> foundFiles = new ArrayList<File>();
+ boolean found = ProjectUtil.findProjectFiles(foundFiles, workingDir,
+ null, new NullProgressMonitor());
+
+ assertTrue("Expected to find projects", found);
+ assertThat(foundFiles, hasItem(new File(workingDir, "Project-1/.project")));
+ assertThat(foundFiles, hasItem(new File(workingDir, "Project-1/Project-Nested/.project")));
+ }
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ProjectUtil.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ProjectUtil.java
index 980799ff3c..1d9cc84acd 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ProjectUtil.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ProjectUtil.java
@@ -3,6 +3,7 @@
* Copyright (C) 2007, Martin Oberhuber (martin.oberhuber@windriver.com)
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com>
+ * Copyright (C) 2012, Robin Stocker <robin@nibor.org>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -253,8 +254,8 @@ public class ProjectUtil {
* Find directories containing .project files recursively starting at given
* directory
*
- * @param files
- * @param directory
+ * @param files the collection to add the found projects to
+ * @param directory where to search for project files
* @param visistedDirs
* @param monitor
* @return true if projects files found, false otherwise
@@ -300,12 +301,9 @@ public class ProjectUtil {
File file = contents[i];
if (file.isFile() && file.getName().equals(dotProject)) {
files.add(file);
- // don't search sub-directories since we can't have nested
- // projects
- return true;
}
}
- // no project description found, so recurse into sub-directories
+ // recurse into sub-directories (even when project was found above, for nested projects)
for (int i = 0; i < contents.length; i++) {
// Skip non-directories
if (!contents[i].isDirectory())

Back to the top