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

Feat/rework lastcommitinfo extension #319

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
@Getter
@Setter
public class LastCommitInfo {

private String envLastCommitInfo;
private String envLastBuildDate;
private String envLatestBuildDate;
private String jarLastCommitInfo;
private String jarLastBuildDate;


private String jarLatestBuildDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import java.io.IOException;

@Produces({MediaType.APPLICATION_JSON})
@Path("/last-commit-info")
Expand All @@ -32,7 +31,7 @@ public LastCommitInfoController(LastCommitInfoService lastCommitInfoService) {

@GET
@Produces(MediaType.APPLICATION_JSON)
public LastCommitInfo getLastCommitInfo() throws IOException {
public LastCommitInfo getLastCommitInfo() {
return lastCommitInfoService.getLastCommitInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,48 @@

import org.eclipse.edc.spi.system.ServiceExtensionContext;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Scanner;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

public class LastCommitInfoService {

private final ServiceExtensionContext context;

private String readFileInCurrentClassClasspath(String path) {
var classLoader = LastCommitInfoService.class.getClassLoader();
var is = classLoader.getResourceAsStream(path);
var scanner = new Scanner(Objects.requireNonNull(is), StandardCharsets.UTF_8).useDelimiter("\\A");
return scanner.hasNext() ? scanner.next() : "";
}

public LastCommitInfoService(ServiceExtensionContext context) {
this.context = context;
}

public LastCommitInfo getLastCommitInfo() throws IOException {
var result = new LastCommitInfo();
result.setEnvLastCommitInfo(getEnvLastCommitInfo());
result.setEnvLastBuildDate(getEnvLastCommitDate());

result.setJarLastCommitInfo(getJarInfo().get(0));
result.setJarLastBuildDate(getJarInfo().get(1));
return result;
}

public List<String> getJarInfo() throws IOException {

var jarInfo = new ArrayList<String>();
var classLoader = Thread.currentThread().getContextClassLoader();
var is = classLoader.getResourceAsStream("jar-last-commit-info.txt");
var scanner = new Scanner(Objects.requireNonNull(is), StandardCharsets.UTF_8).useDelimiter("\\A");
jarInfo.add(scanner.hasNext() ? scanner.next() : "");

Manifest manifest = new Manifest(is);
Attributes attributes = manifest.getMainAttributes();
jarInfo.add(attributes.getValue("Build-Date"));

return jarInfo;
public String getJarLastCommitInfo() {
return this.readFileInCurrentClassClasspath("jar-last-commit-info.txt");
}

public String getEnvLastCommitInfo() {
return context.getSetting("edc.last.commit.info", "");
}

public String getEnvLastCommitDate() {
return context.getSetting("edc.env.last.commit.date", "");
public String getLatestJarBuildDate() {
return readFileInCurrentClassClasspath("jar-latest-build-date-info.txt");
}

public String getLatestEnvBuildDate() {
return context.getSetting("edc.env.latest.build.date", "");
}

public LastCommitInfo getLastCommitInfo() {
var lastCommitInfo = new LastCommitInfo();
lastCommitInfo.setEnvLastCommitInfo(getEnvLastCommitInfo());
lastCommitInfo.setJarLastCommitInfo(getJarLastCommitInfo());

lastCommitInfo.setJarLatestBuildDate(getLatestJarBuildDate());
lastCommitInfo.setEnvLatestBuildDate(getLatestEnvBuildDate());
return lastCommitInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void setUp(EdcExtension extension) {
"web.http.management.path", "/api/v1/data",
"edc.api.auth.key", TestUtils.AUTH_KEY,
"edc.last.commit.info", "test env commit message",
"edc.env.last.commit.date", "2023-05-08T15:30:00Z"));
"edc.env.latest.build.date", "2023-05-08T15:30:00Z"));
}

@Test
Expand All @@ -57,8 +57,9 @@ void testEnvAndJar() {
.contentType(ContentType.JSON);

request.assertThat().body("envLastCommitInfo", equalTo("test env commit message"))
.body("envLastBuildDate", equalTo("2023-05-08T15:30:00Z"))
.body("jarLastCommitInfo", equalTo("test jar commit message\n"));
.body("envLatestBuildDate", equalTo("2023-05-08T15:30:00Z"))
.body("jarLastCommitInfo", equalTo("test jar commit message\n"))
.body("jarLatestBuildDate", equalTo("2023-05-08T15:30:00Z\n"));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-05-08T15:30:00Z