Skip to content

Commit

Permalink
Merge pull request #873 from stuartwdouglas/fix-discovery
Browse files Browse the repository at this point in the history
Change build discovery algorithm
  • Loading branch information
stuartwdouglas authored Oct 19, 2023
2 parents 5b72d57 + cdeebfd commit 0d6050c
Show file tree
Hide file tree
Showing 29 changed files with 809 additions and 401 deletions.
16 changes: 16 additions & 0 deletions deploy/crds/base/jvmbuildservice.io_dependencybuilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ spec:
type: string
toolVersion:
type: string
toolVersions:
additionalProperties:
type: string
type: object
type: object
type: object
type: array
Expand Down Expand Up @@ -316,6 +320,10 @@ spec:
type: string
toolVersion:
type: string
toolVersions:
additionalProperties:
type: string
type: object
type: object
deployedArtifacts:
items:
Expand Down Expand Up @@ -394,6 +402,10 @@ spec:
type: string
toolVersion:
type: string
toolVersions:
additionalProperties:
type: string
type: object
type: object
type: array
failedVerification:
Expand Down Expand Up @@ -463,6 +475,10 @@ spec:
type: string
toolVersion:
type: string
toolVersions:
additionalProperties:
type: string
type: object
type: object
type: array
state:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
github.com/google/go-containerregistry v0.15.2
github.com/redhat-appstudio/image-controller v0.0.0-20231003082540-48893226ba8b
go.uber.org/zap v1.24.0
k8s.io/utils v0.0.0-20230209194617-a36077c30491
sigs.k8s.io/yaml v1.3.0
)

Expand Down Expand Up @@ -112,7 +113,6 @@ require (
k8s.io/component-base v0.26.1 // indirect
k8s.io/gengo v0.0.0-20221011193443-fad74ee6edd9 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public interface RecipeDirectory {

Optional<Path> getRepositoryPaths(String name);

Optional<Path> getBuildToolInfo(String name);

List<Path> getAllRepositoryPaths();

default <T> void writeArtifactData(AddRecipeRequest<T> data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ public class RecipeLayoutManager implements RecipeDirectory {
private final Path scmInfoDirectory;
private final Path buildInfoDirectory;
private final Path repositoryInfoDirectory;
private final Path buildToolInfoDirectory;

public RecipeLayoutManager(Path baseDirectory) {
this.scmInfoDirectory = baseDirectory.resolve(RecipeRepositoryManager.SCM_INFO);
this.buildInfoDirectory = baseDirectory.resolve(RecipeRepositoryManager.BUILD_INFO);
this.repositoryInfoDirectory = baseDirectory.resolve(RecipeRepositoryManager.REPOSITORY_INFO);
this.buildToolInfoDirectory = baseDirectory.resolve(RecipeRepositoryManager.BUILD_TOOL_INFO);
}

/**
Expand Down Expand Up @@ -95,6 +97,15 @@ public Optional<Path> getRepositoryPaths(String name) {
return Optional.empty();
}

@Override
public Optional<Path> getBuildToolInfo(String name) {
Path target = buildToolInfoDirectory.resolve(name).resolve("tool.yaml");
if (Files.exists(target)) {
return Optional.of(target);
}
return Optional.empty();
}

@Override
public List<Path> getAllRepositoryPaths() {
try (Stream<Path> list = Files.list(repositoryInfoDirectory)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class RecipeRepositoryManager implements RecipeDirectory {
public static final String SCM_INFO = "scm-info";
public static final String BUILD_INFO = "build-info";
public static final String BUILD_TOOL_INFO = "build-tool-info";
public static final String REPOSITORY_INFO = "repository-info";
private final Git git;
private final String remote;
Expand Down Expand Up @@ -114,6 +115,12 @@ public List<Path> getAllRepositoryPaths() {
return recipeLayoutManager.getAllRepositoryPaths();
}

@Override
public Optional<Path> getBuildToolInfo(String name) {
doUpdate();
return recipeLayoutManager.getBuildToolInfo(name);
}

@Override
public void update() {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.redhat.hacbs.recipies.tools;

public class BuildToolInfo {

private String version;
private String releaseDate;
private String minJdkVersion;
private String maxJdkVersion;

public String getVersion() {
return version;
}

public BuildToolInfo setVersion(String version) {
this.version = version;
return this;
}

public String getReleaseDate() {
return releaseDate;
}

public BuildToolInfo setReleaseDate(String releaseDate) {
this.releaseDate = releaseDate;
return this;
}

public String getMinJdkVersion() {
return minJdkVersion;
}

public BuildToolInfo setMinJdkVersion(String minJdkVersion) {
this.minJdkVersion = minJdkVersion;
return this;
}

public String getMaxJdkVersion() {
return maxJdkVersion;
}

public BuildToolInfo setMaxJdkVersion(String maxJdkVersion) {
this.maxJdkVersion = maxJdkVersion;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.redhat.hacbs.recipies.tools;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.redhat.hacbs.recipies.RecipeManager;

public class BuildToolInfoManager implements RecipeManager<List<BuildToolInfo>> {

public static BuildToolInfoManager INSTANCE = new BuildToolInfoManager();

private static final ObjectMapper MAPPER = new ObjectMapper(new YAMLFactory())
.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);

@Override
public List<BuildToolInfo> parse(Path file) throws IOException {
return MAPPER.readerForListOf(BuildToolInfo.class).readValue(file.toFile());
}

@Override
public void write(List<BuildToolInfo> data, Path file) throws IOException {
MAPPER.writeValue(file.toFile(), data);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.redhat.hacbs.container.analyser.build;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.redhat.hacbs.container.analyser.location.VersionRange;
import com.redhat.hacbs.recipies.build.AdditionalDownload;

public class BuildInfo {
Expand All @@ -15,15 +12,11 @@ public class BuildInfo {
public static final String GRADLE = "gradle";
public static final String SBT = "sbt";
public static final String ANT = "ant";
/**
* Possible build tools, including the JDK. This is represented
*/
Map<String, VersionRange> tools = new HashMap<>();
/**
* List of commands to try. Normally there is only one, but if there is both maven, gradle, sbt, ant
* present then we might try to invoke them all.
*/
List<List<String>> invocations = new ArrayList<>();
List<Invocation> invocations = new ArrayList<>();

/**
* Additional repositories to use in the rebuild.
Expand All @@ -32,15 +25,6 @@ public class BuildInfo {

String enforceVersion;

public Map<String, VersionRange> getTools() {
return tools;
}

/**
* Version of the build tool.
*/
String toolVersion;

long commitTime;

String preBuildScript;
Expand All @@ -58,26 +42,21 @@ public Map<String, VersionRange> getTools() {

String image;

public BuildInfo setTools(Map<String, VersionRange> tools) {
this.tools = tools;
return this;
}

public List<List<String>> getInvocations() {
return invocations;
public String getPreBuildScript() {
return preBuildScript;
}

public BuildInfo setInvocations(List<List<String>> invocations) {
this.invocations = invocations;
public BuildInfo setPreBuildScript(String preBuildScript) {
this.preBuildScript = preBuildScript;
return this;
}

public String getPreBuildScript() {
return preBuildScript;
public List<Invocation> getInvocations() {
return invocations;
}

public BuildInfo setPreBuildScript(String preBuildScript) {
this.preBuildScript = preBuildScript;
public BuildInfo setInvocations(List<Invocation> invocations) {
this.invocations = invocations;
return this;
}

Expand All @@ -99,15 +78,6 @@ public BuildInfo setEnforceVersion(String enforceVersion) {
return this;
}

public String getToolVersion() {
return toolVersion;
}

public BuildInfo setToolVersion(String toolVersion) {
this.toolVersion = toolVersion;
return this;
}

public long getCommitTime() {
return commitTime;
}
Expand Down Expand Up @@ -192,11 +162,9 @@ public BuildInfo setImage(String image) {
@Override
public String toString() {
return "BuildInfo{" +
"tools=" + tools +
", invocations=" + invocations +
", repositories=" + repositories +
", enforceVersion='" + enforceVersion + '\'' +
", toolVersion='" + toolVersion + '\'' +
", commitTime=" + commitTime +
", preBuildScript='" + preBuildScript + '\'' +
", postBuildScript='" + postBuildScript + '\'' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import com.redhat.hacbs.recipies.build.BuildRecipeInfo;
import com.redhat.hacbs.recipies.tools.BuildToolInfo;

@RegisterRestClient()
@Path("/v2/recipe-lookup")
Expand All @@ -25,4 +26,9 @@ public interface CacheBuildInfoLocator {
@Produces(MediaType.APPLICATION_JSON)
@Path("repository-info")
List<String> findRepositories(@QueryParam("repositories") Set<String> repositories);

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("build-tool-info")
public List<BuildToolInfo> lookupBuildToolInfo(@QueryParam("name") String name);
}

This file was deleted.

Loading

0 comments on commit 0d6050c

Please sign in to comment.