Fix manifest include exception
According to 'repo help manifest':
Attribute `name`: the manifest to include, specified relative to the
manifest repository's root.
Correcting code and test accordingly.
Change-Id: I054f8fd7275e04515f9ed1558f9ad1277783391e
diff --git a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/CanonicalManifest.java b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/CanonicalManifest.java
index 06df789..5508cfc 100644
--- a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/CanonicalManifest.java
+++ b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/CanonicalManifest.java
@@ -40,18 +40,14 @@
Manifest getCanonicalManifest(String path) throws ManifestReadException {
if (manifests.containsKey(path)) {
Manifest manifest = (Manifest) manifests.get(path).clone();
- Path manifestPath = Paths.get(path);
-
Manifest includedManifest;
Path includedPath;
Iterator<Include> i = manifest.getInclude().listIterator();
String include;
- String parent;
while (i.hasNext()) {
- parent = manifestPath.getParent() != null ? manifestPath.getParent().toString() + "/" : "";
include = i.next().getName();
- includedPath = Paths.get(parent+include);
+ includedPath = Paths.get(include);
i.remove();
includedManifest = getCanonicalManifest(includedPath.normalize().toString());
diff --git a/src/test/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifestsTest.java b/src/test/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifestsTest.java
index 2799435..b8211cd 100644
--- a/src/test/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifestsTest.java
+++ b/src/test/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifestsTest.java
@@ -111,8 +111,8 @@
manifest = versionedManifests.readManifest("subdir/aospincludereplace.xml");
assertThat(manifest.getInclude()).isNotEmpty();
- assertThat(manifest.getInclude().get(0).getName()).isEqualTo("../aospinclude.xml");
- assertThat(manifest.getInclude().get(1).getName()).isEqualTo("testonly1.xml");
+ assertThat(manifest.getInclude().get(0).getName()).isEqualTo("aospinclude.xml");
+ assertThat(manifest.getInclude().get(1).getName()).isEqualTo("subdir/testonly1.xml");
thrown.expect(ManifestReadException.class);
manifest = versionedManifests.readManifest("nonxml.txt");
diff --git a/src/test/resources/subdir/aospincludereplace.xml b/src/test/resources/subdir/aospincludereplace.xml
index 29caea4..1065b26 100644
--- a/src/test/resources/subdir/aospincludereplace.xml
+++ b/src/test/resources/subdir/aospincludereplace.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
- <include name="../aospinclude.xml" />
- <include name="testonly1.xml" />
+ <include name="aospinclude.xml" />
+ <include name="subdir/testonly1.xml" />
<remove-project name="demo/git/test/project4"/>
<project path="git/test/project4" name="demo/git/test/project4" revision="replaced" />