Refactor EiffelEventParser and implementations
Use branchRef and repoName consistently.
Re-add param documentation that was removed in:
d237cb4 Rename EiffelEventParser and EiffelEventParserIf
Solves: Jira GER-1734
Change-Id: Ied3366ae0c21c69dbef847a82679492218ed7cc2
diff --git a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParser.java b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParser.java
index 6c0ad07..2524fd5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParser.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParser.java
@@ -25,36 +25,36 @@
* Creates SCC events for all commits reachable from branchRef. I.e. create SCCs for already
* merged commit that are missing SCCs.
*
- * @param repoName
- * @param branchRef
+ * @param repoName - Name of the repository where the branch exists.
+ * @param branchRef - Creates missing events for all commits reachable from branch.
*/
void createAndScheduleSccFromBranch(String repoName, String branchRef);
/**
* Creates SCC events for all commits reachable from commit.
*
- * @param repoName
- * @param targetBranch
- * @param commit
+ * @param repoName - Name of the repository were the commits exists.
+ * @param branchRef - Ref of the branch to create events for.
+ * @param commit - Creates missing events for all commits reachable from commit.
*/
- void createAndScheduleSccFromCommit(String repoName, String targetBranch, String commit);
+ void createAndScheduleSccFromCommit(String repoName, String branchRef, String commit);
/**
* Creates missing SCS events for repoName, branch.
*
- * @param repoName
- * @param branch
+ * @param repoName - Name of the repository where the branch exists.
+ * @param branchRef - Creates missing events for all commits reachable from branchRef.
*/
- void createAndScheduleMissingScssFromBranch(String repoName, String branch);
+ void createAndScheduleMissingScssFromBranch(String repoName, String branchRef);
/**
* Creates missing SCS events for a submit transaction. submitter and submittedAt is set for all
* events created within the submit transaction, i.e. not reachable from commitSha1TransactionEnd.
*
- * @param scs
- * @param commitSha1TransactionEnd
- * @param submitter
- * @param submittedAt
+ * @param scs - Key for the event that should be created, together with parents.
+ * @param commitSha1TransactionEnd - Tip before submit transaction.
+ * @param submitter - The submitter
+ * @param submittedAt - When the commit was submitted.
*/
void createAndScheduleMissingScss(
SourceChangeEventKey scs,
@@ -63,12 +63,12 @@
Long submittedAt);
/**
- * Creates missing ARTC for a tag, together with CD and (if missing) SCS for referenced commit.7
+ * Creates missing ARTC for a tag, together with CD and (if missing) SCS for referenced commit.
*
- * @param projectName
- * @param tagName
- * @param creationTime
- * @param force
+ * @param repoName - Name of the repository were the tag exists.
+ * @param tagName - The name of the tag.
+ * @param creationTime - The time at which the tag was created.
+ * @param force - Whether existing events should be replaced or not.
*/
- void createAndScheduleArtc(String projectName, String tagName, Long creationTime, boolean force);
+ void createAndScheduleArtc(String repoName, String tagName, Long creationTime, boolean force);
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParserImpl.java b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParserImpl.java
index 5d54053..263c9a7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParserImpl.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/EiffelEventParserImpl.java
@@ -126,21 +126,21 @@
* @see com.googlesource.gerrit.plugins.eventseiffel.parsing.EiffelEventParser#createAndScheduleSccFromBranch(java.lang.String, java.lang.String)
*/
@Override
- public void createAndScheduleSccFromBranch(String repoName, String targetBranch) {
- ObjectId tip = getTipOf(repoName, targetBranch);
+ public void createAndScheduleSccFromBranch(String repoName, String branchRef) {
+ ObjectId tip = getTipOf(repoName, branchRef);
if (tip == null) {
return;
}
- createAndScheduleSccFromCommit(repoName, targetBranch, tip.getName());
+ createAndScheduleSccFromCommit(repoName, branchRef, tip.getName());
}
/* (non-Javadoc)
* @see com.googlesource.gerrit.plugins.eventseiffel.parsing.EiffelEventParser#createAndScheduleSccFromCommit(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
- public void createAndScheduleSccFromCommit(String repoName, String targetBranch, String commit) {
+ public void createAndScheduleSccFromCommit(String repoName, String branchRef, String commit) {
- SourceChangeEventKey scc = SourceChangeEventKey.sccKey(repoName, targetBranch, commit);
+ SourceChangeEventKey scc = SourceChangeEventKey.sccKey(repoName, branchRef, commit);
try {
createAndScheduleMissingSccs(scc);
} catch (IOException
@@ -156,12 +156,12 @@
* @see com.googlesource.gerrit.plugins.eventseiffel.parsing.EiffelEventParser#createAndScheduleMissingScssFromBranch(java.lang.String, java.lang.String)
*/
@Override
- public void createAndScheduleMissingScssFromBranch(String repoName, String branch) {
- ObjectId tip = getTipOf(repoName, branch);
+ public void createAndScheduleMissingScssFromBranch(String repoName, String branchRef) {
+ ObjectId tip = getTipOf(repoName, branchRef);
if (tip == null) {
return;
}
- SourceChangeEventKey scs = SourceChangeEventKey.scsKey(repoName, branch, tip.getName());
+ SourceChangeEventKey scs = SourceChangeEventKey.scsKey(repoName, branchRef, tip.getName());
createAndScheduleMissingScss(scs, null, null, null);
}
@@ -235,45 +235,45 @@
*/
@Override
public void createAndScheduleArtc(
- String projectName, String tagName, Long creationTime, boolean force) {
+ String repoName, String tagName, Long creationTime, boolean force) {
try {
CompositionDefinedEventKey cd =
- CompositionDefinedEventKey.create(mapper.tagCompositionName(projectName), tagName);
+ CompositionDefinedEventKey.create(mapper.tagCompositionName(repoName), tagName);
Optional<UUID> oldCdId = eventHub.getExistingId(cd);
if (oldCdId.isEmpty() || force) {
- createAndScheduleCd(projectName, tagName, creationTime, force);
+ createAndScheduleCd(repoName, tagName, creationTime, force);
Optional<UUID> cdId = eventHub.getExistingId(cd);
if (cdId.isPresent() && !cdId.equals(oldCdId)) {
- pushToHub(mapper.toArtc(projectName, tagName, creationTime, cdId.get()), force);
+ pushToHub(mapper.toArtc(repoName, tagName, creationTime, cdId.get()), force);
if (oldCdId.isPresent()) {
logger.atInfo().log(
- "Event Artc has been forcibly created for: %s, %s", projectName, tagName);
+ "Event Artc has been forcibly created for: %s, %s", repoName, tagName);
} else {
- logger.atFine().log("Event Artc has been created for: %s, %s", projectName, tagName);
+ logger.atFine().log("Event Artc has been created for: %s, %s", repoName, tagName);
}
}
} else {
/* Artc event has already been created */
logger.atWarning().log(
- "Event Artc has already been created for: %s, %s", projectName, tagName);
+ "Event Artc has already been created for: %s, %s", repoName, tagName);
}
} catch (EiffelEventIdLookupException | InterruptedException e) {
logger.atSevere().withCause(e).log(
- "Event creation failed for: %s, %s to Artc", projectName, tagName);
+ "Event creation failed for: %s, %s to Artc", repoName, tagName);
}
}
private void createAndScheduleCd(
- String projectName, String tagName, Long creationTime, boolean force) {
+ String repoName, String tagName, Long creationTime, boolean force) {
SourceChangeEventKey scs = null;
Optional<UUID> scsId = Optional.empty();
try {
- String commitId = peelTag(projectName, tagName);
+ String commitId = peelTag(repoName, tagName);
if (commitId == null) {
return;
}
- scs = SourceChangeEventKey.scsKey(projectName, RefNames.REFS_HEADS + "master", commitId);
+ scs = SourceChangeEventKey.scsKey(repoName, RefNames.REFS_HEADS + "master", commitId);
scsId = eventHub.getExistingId(scs);
if (scsId.isEmpty()) {
@@ -284,52 +284,51 @@
.withStopStrategy(StopStrategies.stopAfterAttempt(2))
.build();
try {
- scsId = retryer.call(() -> findSourceChangeEventKey(projectName, commitId));
+ scsId = retryer.call(() -> findSourceChangeEventKey(repoName, commitId));
} catch (RetryException | ExecutionException e) {
- logger.atSevere().withCause(e).log(
- "Failed to find SCS for %s in %s", commitId, projectName);
+ logger.atSevere().withCause(e).log("Failed to find SCS for %s in %s", commitId, repoName);
return;
}
}
if (scsId.isEmpty()) {
- logger.atSevere().log("Could not find SCS for: %s in %s", commitId, projectName);
+ logger.atSevere().log("Could not find SCS for: %s in %s", commitId, repoName);
return;
}
- pushToHub(mapper.toCd(projectName, tagName, creationTime, scsId.get()), force);
+ pushToHub(mapper.toCd(repoName, tagName, creationTime, scsId.get()), force);
} catch (EiffelEventIdLookupException | InterruptedException e) {
logger.atSevere().withCause(e).log(
"Event creation failed for: %s",
- CompositionDefinedEventKey.create(mapper.tagCompositionName(projectName), tagName));
+ CompositionDefinedEventKey.create(mapper.tagCompositionName(repoName), tagName));
}
}
- private String peelTag(String projectName, String tagName) {
- try (Repository repo = repoManager.openRepository(Project.nameKey(projectName))) {
+ private String peelTag(String repoName, String tagName) {
+ try (Repository repo = repoManager.openRepository(Project.nameKey(repoName))) {
Ref tagRef = repo.getRefDatabase().exactRef(Constants.R_TAGS + tagName);
if (tagRef != null) {
ObjectId peeled = repo.getRefDatabase().peel(tagRef).getPeeledObjectId();
return peeled != null ? peeled.getName() : tagRef.getObjectId().getName();
}
- logger.atSevere().log("Cannot find tag: %s:%s", projectName, tagName);
+ logger.atSevere().log("Cannot find tag: %s:%s", repoName, tagName);
} catch (IOException e) {
- logger.atSevere().withCause(e).log("Unable to peel tag: %s:%s", projectName, tagName);
+ logger.atSevere().withCause(e).log("Unable to peel tag: %s:%s", repoName, tagName);
}
return null;
}
- private Optional<UUID> findSourceChangeEventKey(String projectName, String commitId)
+ private Optional<UUID> findSourceChangeEventKey(String repoName, String commitId)
throws EiffelEventIdLookupException {
List<String> branches;
- try (Repository repo = repoManager.openRepository(Project.nameKey(projectName))) {
+ try (Repository repo = repoManager.openRepository(Project.nameKey(repoName))) {
branches =
repo.getRefDatabase().getRefsByPrefix(RefNames.REFS_HEADS).stream()
.map(Ref::getName)
.collect(Collectors.toList());
} catch (IOException ioe) {
- logger.atSevere().withCause(ioe).log("Unable to find branches of %s.", projectName);
+ logger.atSevere().withCause(ioe).log("Unable to find branches of %s.", repoName);
return Optional.empty();
}
- return eventHub.getScsForCommit(projectName, commitId, branches);
+ return eventHub.getScsForCommit(repoName, commitId, branches);
}
private void pushToHub(EiffelEvent toPush) throws InterruptedException {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/ParsingQueuePersistanceIT.java b/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/ParsingQueuePersistanceIT.java
index 9e00301..977e457 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/ParsingQueuePersistanceIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/ParsingQueuePersistanceIT.java
@@ -172,14 +172,13 @@
public void createAndScheduleSccFromEvent(Event event) {}
@Override
- public void createAndScheduleSccFromBranch(String repoName, String ref) {}
+ public void createAndScheduleSccFromBranch(String repoName, String branchRef) {}
@Override
- public void createAndScheduleSccFromCommit(
- String repoName, String targetBranch, String commit) {}
+ public void createAndScheduleSccFromCommit(String repoName, String branchRef, String commit) {}
@Override
- public void createAndScheduleMissingScssFromBranch(String repoName, String branch) {}
+ public void createAndScheduleMissingScssFromBranch(String repoName, String branchRef) {}
@Override
public void createAndScheduleMissingScss(
@@ -190,7 +189,7 @@
@Override
public void createAndScheduleArtc(
- String projectName, String tagName, Long creationTime, boolean force) {}
+ String repoName, String tagName, Long creationTime, boolean force) {}
}
public static class TestModule extends AbstractModule {