Skip to content

Commit

Permalink
Fixes #63
Browse files Browse the repository at this point in the history
A json schema is generated alongside artifacts file.
When augmenting history, this file is also copied (when present, which will be the case starting this evening). This way we can guarantee
  • Loading branch information
Riduidel authored Sep 30, 2024
1 parent 4c75e91 commit 0eec9ec
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/get_mvnrepository_infos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:
--maven-path $MAVEN
ls -la
mkdir target
mv schema.json target/schema.json
mv artifacts.json target/artifacts.json
env:
VERSION: "${{steps.version.outputs.release}}"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/get_npmjs_infos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
java -jar npmjs-$VERSION-jar-with-dependencies.jar
ls -la
mkdir target
mv schema.json target/schema.json
mv artifacts.json target/artifacts.json
env:
VERSION: "${{steps.version.outputs.release}}"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/get_pypi_infos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ jobs:
--techempower-frameworks-local-clone FrameworkBenchmarks/frameworks
ls -la
mkdir target
mv schema.json target/schema.json
mv artifacts.json target/artifacts.json
env:
VERSION: "${{steps.version.outputs.release}}"
Expand Down
7 changes: 7 additions & 0 deletions model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-jsonSchema-jakarta -->
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jsonSchema-jakarta</artifactId>
<version>2.17.2</version>
</dependency>

<dependency>
<groupId>com.github.fge</groupId>
<artifactId>throwing-lambdas</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import java.net.http.HttpClient;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.logging.Logger;

import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.ndx.aadarchi.technology.detector.history.BaseHistoryBuilder;
import org.ndx.aadarchi.technology.detector.loader.ArtifactLoader;
Expand All @@ -16,6 +18,13 @@
import org.ndx.aadarchi.technology.detector.mappers.MappingGenerator;
import org.ndx.aadarchi.technology.detector.model.ArtifactDetails;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.SimpleType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.module.jsonSchema.jakarta.JsonSchema;
import com.fasterxml.jackson.module.jsonSchema.jakarta.JsonSchemaGenerator;

import picocli.CommandLine.Option;

/**
Expand Down Expand Up @@ -44,6 +53,9 @@ public abstract class InterestingArtifactsDetailsDownloader<Context extends Extr
@Option(names = { "-o",
"--output" }, description = "The output file for generated artifacts.json file", defaultValue = "artifacts.json")
protected Path output;
@Option(names = { "-s",
"--schema" }, description = "The output file for generated JSON schema file", defaultValue = "schema.json")
protected Path schema;
@Option(names = {
"--techempower-frameworks-local-clone" }, description = "The techempower frameworks local clone"
, defaultValue = "../../FrameworkBenchmarks/frameworks")
Expand Down Expand Up @@ -94,6 +106,11 @@ private void generateMappingFiles(Collection<ArtifactDetails> artifactDetails) {

private void writeDetails(Collection<ArtifactDetails> artifactDetails) {
try {
JsonSchemaGenerator generator = new JsonSchemaGenerator(FileHelper.getObjectMapper());
JsonSchema jsonSchema = generator.generateSchema(CollectionType.construct(artifactDetails.getClass(), SimpleType.construct(ArtifactDetails.class)));
FileUtils.write(schema.toFile(),
FileHelper.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema),
"UTF-8");
FileHelper.writeToFile(artifactDetails, output.toFile());
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public abstract class BaseHistoryBuilder<Context extends ExtractionContext> {
public final File artifactsFile;
public final String artifactsQualifier;
public final String gitBranch;
public final File schemaFile;

static {
String path = BaseHistoryBuilder.class.getClassLoader()
Expand All @@ -68,6 +69,7 @@ public BaseHistoryBuilder(Path cache, String gitUsername, String gitEmail, Strin
this.email = gitEmail;
this.artifactsQualifier = artifactQualifierName;
this.artifactsFile = new File(gitHistory.toFile(), artifactQualifierName + "/artifacts.json");
this.schemaFile = new File(gitHistory.toFile(), artifactQualifierName + "/schema.json");
gitBranch = "reports_" + artifactsQualifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.eclipse.jgit.api.AddCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.errors.CheckoutConflictException;
Expand Down Expand Up @@ -37,12 +42,14 @@ public class HistoryAugmenter<Context extends ExtractionContext> {
public final String gitBranchName;
public final String replacerBranchName;
public final File artifactsFile;
public final File schemaFile;
public final Path gitHistory;

public HistoryAugmenter(BaseHistoryBuilder<Context> baseHistoryBuilder) {
this.gitHistory = baseHistoryBuilder.gitHistory;
this.gitBranchName = baseHistoryBuilder.gitBranch;
this.artifactsFile = baseHistoryBuilder.artifactsFile;
this.schemaFile = baseHistoryBuilder.schemaFile;
replacerBranchName = gitBranchName + "_REPLACER";
}

Expand Down Expand Up @@ -100,6 +107,11 @@ private void augmentCommit(Context context, Git git, RevCommit commit) throws Re
commit.getCommitterIdent().getWhen(),
commit.getShortMessage()));
git.checkout().setName(commit.getName()).call();
// Don't forget to read schema!
Optional<String> schema = schemaFile.exists()
? Optional.of(FileUtils.readFileToString(schemaFile, "UTF-8"))
: Optional.empty()
;
// Now load artifacts into data structure
List<ArtifactDetails> artifacts = FileHelper.readFromFile(artifactsFile);
// Augment each artifact
Expand All @@ -119,18 +131,24 @@ private void augmentCommit(Context context, Git git, RevCommit commit) throws Re
.call();
// Write the file
FileHelper.writeToFile(augmented, artifactsFile);
// And the schema
schema.ifPresent(Throwing.consumer(s ->
FileUtils.writeStringToFile(schemaFile, s, Charset.forName("UTF-8"))));
// Commit with all values read from initial commit
PersonIdent commiter = commit.getAuthorIdent();
String commitMessage = commit.getFullMessage();
String commitedFile = gitHistory.relativize(artifactsFile.toPath()).toString();
Status response = git.status().call();
if(!response.getAdded().isEmpty()) {
git.add().addFilepattern(commitedFile).call();
AddCommand addCommand = git.add();
for(String s : response.getAdded()) {
addCommand.addFilepattern(s);
}
addCommand.call();
}
git.commit()
.setAuthor(commiter)
.setCommitter(commiter)
.setOnly(commitedFile)
// .setOnly(commitedFile)
.setAllowEmpty(true)
.setMessage(commitMessage)
.call();
Expand Down

0 comments on commit 0eec9ec

Please sign in to comment.