.append("<project path=\"foo\" name=\"").append(defaultUri)
.append("\" revision=\"").append(BRANCH).append("\" >")
.append("<copyfile src=\"hello.txt\" dest=\"Hello\" />")
+ .append("<copyfile src=\"hello.txt\" dest=\"foo/Hello\" />")
.append("</project>").append("</manifest>");
JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
xmlContent.toString());
.getRepository();
// The Hello file should exist
File hello = new File(localDb.getWorkTree(), "Hello");
- localDb.close();
assertTrue("The Hello file should exist", hello.exists());
+ // The foo/Hello file should be skipped.
+ File foohello = new File(localDb.getWorkTree(), "foo/Hello");
+ assertFalse(
+ "The foo/Hello file should be skipped", foohello.exists());
+ localDb.close();
// The content of Hello file should be expected
BufferedReader reader = new BufferedReader(new FileReader(hello));
String content = reader.readLine();
else
last = p;
}
+ removeNestedCopyfiles();
+ }
+
+ /** Remove copyfiles that sit in a subdirectory of any other project. */
+ void removeNestedCopyfiles() {
+ for (RepoProject proj : filteredProjects) {
+ List<CopyFile> copyfiles = new ArrayList<>(proj.getCopyFiles());
+ proj.clearCopyFiles();
+ for (CopyFile copyfile : copyfiles) {
+ if (!isNestedCopyfile(copyfile)) {
+ proj.addCopyFile(copyfile);
+ }
+ }
+ }
}
boolean inGroups(RepoProject proj) {
}
return false;
}
+
+ private boolean isNestedCopyfile(CopyFile copyfile) {
+ if (copyfile.dest.indexOf('/') == -1) {
+ // If the copyfile is at root level then it won't be nested.
+ return false;
+ }
+ for (RepoProject proj : filteredProjects) {
+ if (proj.getPath().compareTo(copyfile.dest) > 0) {
+ // Early return as remaining projects can't be ancestor of this
+ // copyfile config (filteredProjects is sorted).
+ return false;
+ }
+ if (proj.isAncestorOf(copyfile.dest)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
this.copyfiles.addAll(copyfiles);
}
+ /**
+ * Clear all the copyfiles.
+ *
+ * @since 4.2
+ */
+ public void clearCopyFiles() {
+ this.copyfiles.clear();
+ }
+
private String getPathWithSlash() {
if (path.endsWith("/")) //$NON-NLS-1$
return path;
* @return true if this sub repo is the ancestor of given sub repo.
*/
public boolean isAncestorOf(RepoProject that) {
- return that.getPathWithSlash().startsWith(this.getPathWithSlash());
+ return isAncestorOf(that.getPathWithSlash());
+ }
+
+ /**
+ * Check if this sub repo is an ancestor of the given path.
+ *
+ * @param path
+ * path to be checked to see if it is within this repository
+ * @return true if this sub repo is an ancestor of the given path.
+ * @since 4.2
+ */
+ public boolean isAncestorOf(String path) {
+ return path.startsWith(getPathWithSlash());
}
@Override