]> source.dussan.org Git - jgit.git/commitdiff
Support remove-project node in the manifest parser 77/126577/4
authorMasaya Suzuki <masayasuzuki@google.com>
Tue, 24 Jul 2018 19:22:11 +0000 (12:22 -0700)
committerMasaya Suzuki <masayasuzuki@google.com>
Tue, 21 Aug 2018 01:27:32 +0000 (18:27 -0700)
This directive removes the projects added by other directives.

https://gerrit.googlesource.com/git-repo/+/65b0ba5aa0447f7ee25103828115662b1eb80ff9/manifest_xml.py#614
https://gerrit.googlesource.com/git-repo/+/e469a0c741832f6584513f4a382d6b93f417b8d2/docs/manifest-format.txt#339

Change-Id: I90d7b9fc711b586dec05f475422d34d67d909986
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java

index 69a48cc4b5fd0058e4ad75c8e5207924754c264a..024f05480743598acb05bfe3d4e307c923cd77e4 100644 (file)
@@ -43,6 +43,7 @@
 package org.eclipse.jgit.gitrepo;
 
 import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -51,6 +52,8 @@ import java.io.IOException;
 import java.net.URI;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.junit.Test;
 import org.xml.sax.SAXException;
@@ -145,6 +148,29 @@ public class ManifestParserTest {
                }
        }
 
+       @Test
+       public void testRemoveProject() throws Exception {
+               StringBuilder xmlContent = new StringBuilder();
+               xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+                               .append("<manifest>")
+                               .append("<remote name=\"remote1\" fetch=\".\" />")
+                               .append("<default revision=\"master\" remote=\"remote1\" />")
+                               .append("<project path=\"foo\" name=\"foo\" />")
+                               .append("<project path=\"bar\" name=\"bar\" />")
+                               .append("<remove-project name=\"foo\" />")
+                               .append("<project path=\"foo\" name=\"baz\" />")
+                               .append("</manifest>");
+
+               ManifestParser parser = new ManifestParser(null, null, "master",
+                               "https://git.google.com/", null, null);
+               parser.read(new ByteArrayInputStream(
+                               xmlContent.toString().getBytes(CHARSET)));
+
+               assertEquals(Stream.of("bar", "baz").collect(Collectors.toSet()),
+                               parser.getProjects().stream().map(RepoProject::getName)
+                                               .collect(Collectors.toSet()));
+       }
+
        void testNormalize(String in, String want) {
                URI got = ManifestParser.normalizeEmptyPath(URI.create(in));
                if (!got.toString().equals(want)) {
index 929ffac114483f38f796e3fef4ff7df074505da8..26e783ddd7f1d8026338c77472a65d82092cb409 100644 (file)
@@ -252,6 +252,9 @@ public class ManifestParser extends DefaultHandler {
                                                        RepoText.get().errorIncludeFile, path), e);
                                }
                        }
+               } else if ("remove-project".equals(qName)) { //$NON-NLS-1$
+                       String name = attributes.getValue("name"); //$NON-NLS-1$
+                       projects.removeIf((p) -> p.getName().equals(name));
                }
        }