Update plugin to target gerrit 2.12.3
Change-Id: Ie7bb6098b9dfe9518fb884fb07d3b04dcb648240
diff --git a/pom.xml b/pom.xml
index 1f5f891..97b349d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,14 +26,14 @@
<properties>
<Gerrit-ApiType>plugin</Gerrit-ApiType>
- <Gerrit-ApiVersion>2.9.1</Gerrit-ApiVersion>
+ <Gerrit-ApiVersion>2.12.3</Gerrit-ApiVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jaxb2-basics-runtime.version>0.6.4</jaxb2-basics-runtime.version>
<jacoco.version>0.7.5.201505241946</jacoco.version>
<gitdescribe-maven-plugin.version>3.0</gitdescribe-maven-plugin.version>
<maven-jaxb2-plugin.version>0.7.0</maven-jaxb2-plugin.version>
<truth.version>0.27</truth.version>
- <jgit.junit.version>3.7.1.201504261725-r</jgit.junit.version>
+ <jgit.junit.version>4.1.1.201511131810-r</jgit.junit.version>
</properties>
<build>
diff --git a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ManifestSubscription.java b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ManifestSubscription.java
index 9899c9c..0ecc2d2 100644
--- a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ManifestSubscription.java
+++ b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/ManifestSubscription.java
@@ -158,10 +158,10 @@
String manifestSrc = manifestSource.get(store, storeBranch);
StringBuilder extraCommitMsg = new StringBuilder();
- try {
- Project.NameKey p = new Project.NameKey(projectName);
- Repository r = gitRepoManager.openRepository(p);
- RevWalk walk = new RevWalk(r);
+ Project.NameKey p = new Project.NameKey(projectName);
+ try (Repository r = gitRepoManager.openRepository(p);
+ RevWalk walk = new RevWalk(r)) {
+
RevCommit c = walk.parseCommit(
ObjectId.fromString(event.getNewObjectId()));
@@ -341,7 +341,6 @@
Maps.<String, Set<com.amd.gerrit.plugins.manifestsubscription.manifest.Project>>newHashMap());
}
-
Map<String,
Set<com.amd.gerrit.plugins.manifestsubscription.manifest.Project>> ps;
ps = subscribedRepos.get(pbKey, store);
@@ -443,9 +442,11 @@
private VersionedManifests parseManifests(Project.NameKey p, String refName)
throws IOException, JAXBException, ConfigInvalidException {
+ Repository repo = gitRepoManager.openRepository(p);
+ ObjectId commitId = repo.resolve(refName);
MetaDataUpdate update = metaDataUpdateFactory.create(p);
VersionedManifests vManifests = new VersionedManifests(refName);
- vManifests.load(update);
+ vManifests.load(update, commitId);
return vManifests;
}
@@ -461,13 +462,15 @@
String extraCommitMsg)
throws JAXBException, IOException {
Project.NameKey p = new Project.NameKey(projectName);
+ Repository repo = gitRepoManager.openRepository(p);
MetaDataUpdate update = metaDataUpdateFactory.create(p);
+ ObjectId commitId = repo.resolve(refName);
VersionedManifests vManifests = new VersionedManifests(refName);
//TODO find a better way to detect no branch
boolean refExists = true;
try {
- vManifests.load(update);
+ vManifests.load(update, commitId);
} catch (Exception e) {
refExists = false;
}
diff --git a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifests.java b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifests.java
index cc3dbb1..0309363 100644
--- a/src/main/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifests.java
+++ b/src/main/java/com/amd/gerrit/plugins/manifestsubscription/VersionedManifests.java
@@ -114,36 +114,34 @@
String path;
Manifest manifest;
- RevWalk rw = new RevWalk(reader);
-
- // This happens when someone configured a invalid branch name
- if (getRevision() == null) {
- throw new ConfigInvalidException(refName);
- }
- RevCommit r = rw.parseCommit(getRevision());
- TreeWalk treewalk = new TreeWalk(reader);
- treewalk.addTree(r.getTree());
- treewalk.setRecursive(false);
- treewalk.setFilter(PathSuffixFilter.create(".xml"));
- while (treewalk.next()) {
- if (treewalk.isSubtree()) {
- treewalk.enterSubtree();
- } else {
- path = treewalk.getPathString();
- try {
+ try (RevWalk rw = new RevWalk(reader);
+ TreeWalk treewalk = new TreeWalk(reader)) {
+ // This happens when someone configured a invalid branch name
+ if (getRevision() == null) {
+ throw new ConfigInvalidException(refName);
+ }
+ RevCommit r = rw.parseCommit(getRevision());
+ treewalk.addTree(r.getTree());
+ treewalk.setRecursive(false);
+ treewalk.setFilter(PathSuffixFilter.create(".xml"));
+ while (treewalk.next()) {
+ if (treewalk.isSubtree()) {
+ treewalk.enterSubtree();
+ } else {
+ path = treewalk.getPathString();
//TODO: Should this be done more lazily?
//TODO: difficult to do when reader is not available outside of onLoad?
- ByteArrayInputStream input = new ByteArrayInputStream(readFile(path));
- manifest = (Manifest) manifestUnmarshaller.unmarshal(input);
- manifests.put(path, manifest);
- } catch (JAXBException e) {
- e.printStackTrace();
+ try (ByteArrayInputStream input
+ = new ByteArrayInputStream(readFile(path))) {
+ manifest = (Manifest) manifestUnmarshaller.unmarshal(input);
+ manifests.put(path, manifest);
+ } catch (JAXBException e) {
+ e.printStackTrace();
+ }
}
}
}
- treewalk.release();
-
//TODO load changed manifest
// DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
}
@@ -226,14 +224,12 @@
GitRepositoryManager gitRepoManager) throws
GitAPIException, IOException {
Project.NameKey p = new Project.NameKey(project.getName());
- Repository db = gitRepoManager.openRepository(p);
- Git git = new Git(db);
-
- RevWalk walk = new RevWalk(db);
- RevCommit commit = walk.parseCommit(db.resolve(hash));
- git.tag().setName(tag).setObjectId(commit).setAnnotated(true).call();
-
- git.close();
+ try (Repository db = gitRepoManager.openRepository(p);
+ Git git = new Git(db);
+ RevWalk walk = new RevWalk(db)) {
+ RevCommit commit = walk.parseCommit(db.resolve(hash));
+ git.tag().setName(tag).setObjectId(commit).setAnnotated(true).call();
+ }
return true;
}
};
@@ -259,13 +255,10 @@
GitRepositoryManager gitRepoManager) throws
GitAPIException, IOException {
Project.NameKey p = new Project.NameKey(project.getName());
- Repository db = gitRepoManager.openRepository(p);
- Git git = new Git(db);
-
- git.branchCreate().setName(branch).setStartPoint(hash).call();
-
- git.close();
- //db.close(); //closed by git.close()
+ try (Repository db = gitRepoManager.openRepository(p);
+ Git git = new Git(db)) {
+ git.branchCreate().setName(branch).setStartPoint(hash).call();
+ }
return true;
}
};
@@ -336,11 +329,8 @@
if (hash == null) {
p = new Project.NameKey(projectName);
- try {
- Repository db = gitRepoManager.openRepository(p);
-
+ try (Repository db = gitRepoManager.openRepository(p)) {
hash = db.resolve(ref).getName();
- db.close();
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md
index 238a523..79a76fd 100644
--- a/src/main/resources/Documentation/about.md
+++ b/src/main/resources/Documentation/about.md
@@ -2,7 +2,7 @@
and generate rev-specific manifests (similar to "repo manifest -o") and store
them to a separate git repository (configurable.)
-> **Warning: this plugin is currently under development and is targeting 2.9.1**
+> **Warning: this plugin is currently under development and is targeting 2.12.3**
The rev-specific manifest of each source manifest is stored in its own branch
with the following naming convention: