Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(uniquet): fixing uniquet bug #3864

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, Map<Integer, VersionValue>> result = new HashMap<>();
private static final String CAMUNDA_VERSION = "8";
private final Map<String, Map<VersionMatrix, String>> result = new HashMap<>();
private final Repository repository;

public GitCrawler(Repository repository) {
Expand All @@ -55,7 +55,7 @@ public static GitCrawler create(String gitDirectory) {
}
}

public Map<String, Map<Integer, VersionValue>> getResult() {
public Map<String, Map<VersionMatrix, String>> getResult() {
return result;
}

Expand All @@ -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<Integer, VersionValue> version = new HashMap<>();
Map<VersionMatrix, String> 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);
}
});
Expand All @@ -117,24 +108,39 @@ public GitCrawler persist(String location) {
return this;
}

private Map<String, List<OutputElementTemplate>> fromMap(
Map<String, Map<Integer, VersionValue>> result) {
private Map<String, Map<String, List<OutputElementTemplate>>> fromMap(
Map<String, Map<VersionMatrix, String>> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
*/
package io.camunda.connector.uniquet.dto;

public record VersionValue(String link, String connectorRuntime) {}
public record VersionMatrix(String elementTemplateVersion, String ConnectorRuntimeVersion) {}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Map<Integer, VersionValue>> 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<String, Map<VersionMatrix, String>> 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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>test</groupId>
<artifactId>test-parent</artifactId>
<version>9.9</version>
<version>8.1</version>
</parent>

<artifactId>test-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>test</groupId>
<artifactId>test-parent</artifactId>
<version>8.2</version>
</parent>

<artifactId>test-test</artifactId>
<packaging>pom</packaging>

<name>test project</name>
<description>Root POM</description>
</project>
Loading