From 295de7d14b0d6acd519b0eb26487ef90e1f68c98 Mon Sep 17 00:00:00 2001 From: Mathias Vandaele Date: Mon, 20 Jan 2025 18:42:03 +0100 Subject: [PATCH] chore(uniquet): fixing uniquet bug --- .../uniquet/core/ElementTemplateIterator.java | 2 +- .../connector/uniquet/core/GitCrawler.java | 82 ++++++++++--------- .../uniquet/dto/OutputElementTemplate.java | 2 +- .../{VersionValue.java => VersionMatrix.java} | 2 +- .../connector/core/GitCrawlerTest.java | 28 ++++--- .../uniquet/src/test/resources/fakepom.xml | 2 +- .../uniquet/src/test/resources/fakepom2.xml | 15 ++++ 7 files changed, 81 insertions(+), 52 deletions(-) rename element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/dto/{VersionValue.java => VersionMatrix.java} (90%) create mode 100644 element-template-generator/uniquet/src/test/resources/fakepom2.xml diff --git a/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/core/ElementTemplateIterator.java b/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/core/ElementTemplateIterator.java index 583f889c29..841aafc267 100644 --- a/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/core/ElementTemplateIterator.java +++ b/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/core/ElementTemplateIterator.java @@ -82,7 +82,7 @@ private static String findCurrentConnectorRuntime(Repository repository, RevComm MavenXpp3Reader mavenReader = new MavenXpp3Reader(); Model model = mavenReader.read(reader); String[] version = model.getParent().getVersion().split("\\."); - return "^" + version[0] + "." + version[1]; + return version[0] + "." + version[1]; } } catch (IOException | XmlPullParserException diff --git a/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/core/GitCrawler.java b/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/core/GitCrawler.java index 6d5bcc5760..6bbf196ebd 100644 --- a/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/core/GitCrawler.java +++ b/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/core/GitCrawler.java @@ -18,9 +18,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import io.camunda.connector.uniquet.dto.Engine; import io.camunda.connector.uniquet.dto.OutputElementTemplate; -import io.camunda.connector.uniquet.dto.VersionValue; +import io.camunda.connector.uniquet.dto.VersionMatrix; import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -36,7 +35,8 @@ public class GitCrawler { private static final String RAW_GITHUB_LINK = "https://raw.githubusercontent.com/camunda/connectors/%s/%s"; - private final Map> result = new HashMap<>(); + private static final String CAMUNDA_VERSION = "8"; + private final Map> result = new HashMap<>(); private final Repository repository; public GitCrawler(Repository repository) { @@ -55,7 +55,7 @@ public static GitCrawler create(String gitDirectory) { } } - public Map> getResult() { + public Map> getResult() { return result; } @@ -77,29 +77,20 @@ private void analyzeCommit(RevCommit commit) { new ElementTemplateIterator(repository, commit) .forEachRemaining( elementTemplateFile -> { + VersionMatrix key = + new VersionMatrix( + elementTemplateFile.elementTemplate().version().toString(), + elementTemplateFile.connectorRuntime()); if (result.containsKey(elementTemplateFile.elementTemplate().id())) { result .get(elementTemplateFile.elementTemplate().id()) - .compute( - elementTemplateFile.elementTemplate().version(), - (integer, versionValue) -> - Optional.ofNullable(versionValue) - .map( - vv -> - new VersionValue( - vv.link(), elementTemplateFile.connectorRuntime())) - .orElse( - new VersionValue( - RAW_GITHUB_LINK.formatted( - commit.getName(), elementTemplateFile.path()), - elementTemplateFile.connectorRuntime()))); + .putIfAbsent( + key, + RAW_GITHUB_LINK.formatted(commit.getName(), elementTemplateFile.path())); } else { - Map version = new HashMap<>(); + Map version = new HashMap<>(); version.put( - elementTemplateFile.elementTemplate().version(), - new VersionValue( - RAW_GITHUB_LINK.formatted(commit.getName(), elementTemplateFile.path()), - elementTemplateFile.connectorRuntime())); + key, RAW_GITHUB_LINK.formatted(commit.getName(), elementTemplateFile.path())); result.put(elementTemplateFile.elementTemplate().id(), version); } }); @@ -117,24 +108,39 @@ public GitCrawler persist(String location) { return this; } - private Map> fromMap( - Map> result) { + private Map>> fromMap( + Map> result) { return result.entrySet().stream() - .map( - stringMapEntry -> - Map.entry( - stringMapEntry.getKey(), + .collect( + Collectors.toMap( + Map.Entry::getKey, + stringMapEntry -> stringMapEntry.getValue().entrySet().stream() - .map( - integerVersionValueEntry -> - new OutputElementTemplate( - integerVersionValueEntry.getKey(), - integerVersionValueEntry.getValue().link(), - new Engine( - integerVersionValueEntry.getValue().connectorRuntime()))) - .sorted((o1, o2) -> o2.version() - o1.version()) - .toList())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + .filter( + versionMatrixStringEntry -> + versionMatrixStringEntry + .getKey() + .ConnectorRuntimeVersion() + .startsWith(CAMUNDA_VERSION)) + .collect( + Collectors.groupingBy( + versionMatrixStringEntry -> + versionMatrixStringEntry.getKey().ConnectorRuntimeVersion())) + .entrySet() + .stream() + .collect( + Collectors.toMap( + Map.Entry::getKey, + e -> + e.getValue().stream() + .map( + versionMatrixStringEntry -> + new OutputElementTemplate( + versionMatrixStringEntry + .getKey() + .elementTemplateVersion(), + versionMatrixStringEntry.getValue())) + .toList())))); } public void close() { diff --git a/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/dto/OutputElementTemplate.java b/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/dto/OutputElementTemplate.java index 362958bee0..4f098f75b4 100644 --- a/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/dto/OutputElementTemplate.java +++ b/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/dto/OutputElementTemplate.java @@ -16,4 +16,4 @@ */ package io.camunda.connector.uniquet.dto; -public record OutputElementTemplate(Integer version, String ref, Engine engine) {} +public record OutputElementTemplate(String version, String ref) {} diff --git a/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/dto/VersionValue.java b/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/dto/VersionMatrix.java similarity index 90% rename from element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/dto/VersionValue.java rename to element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/dto/VersionMatrix.java index c35ec6b4f1..07998be234 100644 --- a/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/dto/VersionValue.java +++ b/element-template-generator/uniquet/src/main/java/io/camunda/connector/uniquet/dto/VersionMatrix.java @@ -16,4 +16,4 @@ */ package io.camunda.connector.uniquet.dto; -public record VersionValue(String link, String connectorRuntime) {} +public record VersionMatrix(String elementTemplateVersion, String ConnectorRuntimeVersion) {} diff --git a/element-template-generator/uniquet/src/test/java/io/camunda/connector/core/GitCrawlerTest.java b/element-template-generator/uniquet/src/test/java/io/camunda/connector/core/GitCrawlerTest.java index 7012c5cfb6..57561ae77e 100644 --- a/element-template-generator/uniquet/src/test/java/io/camunda/connector/core/GitCrawlerTest.java +++ b/element-template-generator/uniquet/src/test/java/io/camunda/connector/core/GitCrawlerTest.java @@ -17,7 +17,7 @@ package io.camunda.connector.core; import io.camunda.connector.uniquet.core.GitCrawler; -import io.camunda.connector.uniquet.dto.VersionValue; +import io.camunda.connector.uniquet.dto.VersionMatrix; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -70,21 +70,29 @@ void crawl() throws IOException, GitAPIException { RevCommit revCommit2 = git.commit().setSign(false).setMessage("commit 2").call(); // commit 3 - String content3 = Files.readString(Path.of("src/test/resources/commit3_version_changed.json")); - Files.write(newFilePath, content3.getBytes(), StandardOpenOption.CREATE); + String content3 = Files.readString(Path.of("src/test/resources/fakepom2.xml")); + Files.write(pomPath, content3.getBytes(), StandardOpenOption.CREATE); git.add().addFilepattern(".").call(); RevCommit revCommit3 = git.commit().setSign(false).setMessage("commit 3").call(); - Map> map = + // commit 4 + String content4 = Files.readString(Path.of("src/test/resources/commit3_version_changed.json")); + Files.write(newFilePath, content4.getBytes(), StandardOpenOption.CREATE); + git.add().addFilepattern(".").call(); + RevCommit revCommit4 = git.commit().setSign(false).setMessage("commit 4").call(); + + Map> map = GitCrawler.create(git.getRepository().getDirectory().getParentFile().getPath()) .crawl("master") .getResult(); - // Verification that the version 2 is the last commit - Assertions.assertTrue(map.get("test").get(2).link().contains(revCommit3.getName())); - Assertions.assertTrue(map.get("test").get(2).connectorRuntime().equals("^9.9")); - // Verification that the version 1 is the last commit containing version 1 - Assertions.assertTrue(map.get("test").get(1).link().contains(revCommit2.getName())); - Assertions.assertFalse(map.get("test").get(1).link().contains(revCommit1.getName())); + System.out.println(map); + + Assertions.assertTrue( + map.get("test").get(new VersionMatrix("1", "8.2")).contains(revCommit3.getName())); + Assertions.assertTrue( + map.get("test").get(new VersionMatrix("2", "8.2")).contains(revCommit4.getName())); + Assertions.assertTrue( + map.get("test").get(new VersionMatrix("1", "8.1")).contains(revCommit2.getName())); } } diff --git a/element-template-generator/uniquet/src/test/resources/fakepom.xml b/element-template-generator/uniquet/src/test/resources/fakepom.xml index 37469ad347..1552332327 100644 --- a/element-template-generator/uniquet/src/test/resources/fakepom.xml +++ b/element-template-generator/uniquet/src/test/resources/fakepom.xml @@ -4,7 +4,7 @@ test test-parent - 9.9 + 8.1 test-test diff --git a/element-template-generator/uniquet/src/test/resources/fakepom2.xml b/element-template-generator/uniquet/src/test/resources/fakepom2.xml new file mode 100644 index 0000000000..00a140db31 --- /dev/null +++ b/element-template-generator/uniquet/src/test/resources/fakepom2.xml @@ -0,0 +1,15 @@ + + 4.0.0 + + + test + test-parent + 8.2 + + + test-test + pom + + test project + Root POM + \ No newline at end of file