Skip to content

Commit fddd7aa

Browse files
authored
[STAGE] Add support for custom repositories per offering (#212)
* Add support for custom repositories
1 parent 47c8796 commit fddd7aa

15 files changed

+318
-101
lines changed

deploy/build_deploy.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ GIT_REV_SHORT=$(git rev-parse --short=7 HEAD)
77
IMAGE=${IMAGE-"quay.io/redhat-developer/code-quarkus"}
88
IMAGE_TAG=${IMAGE_TAG-$GIT_REV_SHORT}
99

10-
docker build --compress -f docker/Dockerfile.redhat-app.multistage --build-arg MAVEN_BUILD_EXTRA_ARGS="-Dgit.commit.id=$GIT_REV" -t "${IMAGE}:${IMAGE_TAG}" .
10+
STAGE=false
11+
12+
if [[ $(git --no-pager log --oneline -1) == *[STAGE]* ]]; then
13+
echo "This commit is flagged with [STAGE] and won't go to production"
14+
STAGE=true
15+
fi
16+
17+
docker build --compress -f docker/Dockerfile.redhat-app.multistage --build-arg MAVEN_BUILD_EXTRA_ARGS="-Dgit.commit.id=$GIT_REV -Dio.quarkus.code.build.stage=$STAGE" -t "${IMAGE}:${IMAGE_TAG}" .
1118

1219
if [[ -n "$QUAY_USER" && -n "$QUAY_TOKEN" ]]; then
1320
DOCKER_CONF="$PWD/.docker"

justfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ export QUARKUS_REGISTRY_REGISTRY_QUARKUS_IO_RECOMMEND_STREAMS_FROM_COM_REDHAT_QU
66

77

88
dev-rh:
9-
export IO_QUARKUS_CODE_OFFERING_SUPPORT_TAG="redhat-support"
9+
export QUARKUS_REGISTRY_REGISTRY_QUARKUS_REDHAT_COM_OFFERING="redhat"
1010
quarkus dev -Dquarkus.profile=dev,redhat
1111

1212
dev-ibm:
13-
export IO_QUARKUS_CODE_OFFERING_SUPPORT_TAG="ibm-support"
13+
export QUARKUS_REGISTRY_REGISTRY_QUARKUS_REDHAT_COM_OFFERING="ibm"
1414
quarkus dev -Dquarkus.profile=dev,ibm
1515

1616
dev-camel:
17-
export IO_QUARKUS_CODE_OFFERING_SUPPORT_TAG="camel-support"
17+
export QUARKUS_REGISTRY_REGISTRY_QUARKUS_REDHAT_COM_OFFERING="redhat-camel"
1818
quarkus dev -Dquarkus.profile=dev,redhat-camel
1919
build:
2020
quarkus build -DskipTests
2121
start-ibm:
22-
export IO_QUARKUS_CODE_OFFERING_SUPPORT_TAG="ibm-support"
22+
export QUARKUS_REGISTRY_REGISTRY_QUARKUS_REDHAT_COM_OFFERING="ibm"
2323
QUARKUS_PROFILE="prod,ibm" java -jar target/quarkus-app/quarkus-run.jar
2424
start-rh:
25-
export IO_QUARKUS_CODE_OFFERING_SUPPORT_TAG="redhat-support"
25+
export QUARKUS_REGISTRY_REGISTRY_QUARKUS_REDHAT_COM_OFFERING="redhat"
2626
QUARKUS_PROFILE="prod,redhat" java -jar target/quarkus-app/quarkus-run.jar
2727
start-camel:
28-
export IO_QUARKUS_CODE_OFFERING_SUPPORT_TAG="redhat-camel-support"
28+
export QUARKUS_REGISTRY_REGISTRY_QUARKUS_REDHAT_COM_OFFERING="redhat-camel"
2929
QUARKUS_PROFILE="prod,redhat-camel" java -jar target/quarkus-app/quarkus-run.jar
3030

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.quarkus.code</groupId>
88
<artifactId>code-quarkus-parent</artifactId>
9-
<version>59</version>
9+
<version>61</version>
1010
</parent>
1111

1212
<artifactId>code-quarkus-redhat-app</artifactId>
@@ -151,6 +151,7 @@
151151
<maven.home>${maven.home}</maven.home>
152152
</systemPropertyVariables>
153153
</configuration>
154+
154155
</execution>
155156
</executions>
156157
</plugin>

src/main/java/GlobalConstants.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.util.Set;
2+
3+
class GlobalConstants {
4+
5+
private GlobalConstants() {
6+
}
7+
8+
static final String ICONS_ASSETS_URL = "/assets/icons";
9+
10+
static final Set<String> TAGS = Set.of(
11+
"with:starter-code", "status:stable", "status:preview", "status:experimental", "status:deprecated",
12+
"support:full-support", "support:supported-in-jvm", "support:dev-support", "support:tech-preview",
13+
"support:deprecated");
14+
}

src/main/java/IBMConstants.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import io.quarkus.code.model.Preset;
2+
3+
import java.util.List;
4+
5+
class IBMConstants {
6+
7+
private IBMConstants() {
8+
}
9+
10+
public static final List<Preset> IBM_PRESETS = List.of(
11+
// Some presets are duplicated to support platforms before and after the Big Reactive Renaming
12+
new Preset("rest-service", "REST service",
13+
GlobalConstants.ICONS_ASSETS_URL + "/ibm-presets/rest-service.svg",
14+
List.of("io.quarkus:quarkus-rest")),
15+
new Preset("db-service", "REST service with database",
16+
GlobalConstants.ICONS_ASSETS_URL + "/ibm-presets/db-service.svg",
17+
List.of("io.quarkus:quarkus-rest", "io.quarkus:quarkus-rest-jackson",
18+
"io.quarkus:quarkus-hibernate-orm-panache", "io.quarkus:quarkus-jdbc-postgresql")),
19+
new Preset("event-driven-kafka", "Event driven service with Kafka",
20+
GlobalConstants.ICONS_ASSETS_URL + "/ibm-presets/event-driven.svg",
21+
List.of("io.quarkus:quarkus-messaging-kafka")),
22+
new Preset("cli", "Command-line tool",
23+
GlobalConstants.ICONS_ASSETS_URL + "/ibm-presets/cli.svg",
24+
List.of("io.quarkus:quarkus-picocli")),
25+
new Preset("webapp-mvc", "Web app with Model-View-Controller",
26+
GlobalConstants.ICONS_ASSETS_URL + "/ibm-presets/webapp-mvc.svg",
27+
List.of("io.quarkiverse.renarde:quarkus-renarde", "io.quarkiverse.web-bundler:quarkus-web-bundler")),
28+
new Preset("webapp-npm", "Web app with NPM UI",
29+
GlobalConstants.ICONS_ASSETS_URL + "/ibm-presets/webapp-npm.svg",
30+
List.of("io.quarkus:quarkus-rest", "io.quarkus:quarkus-rest-jackson",
31+
"io.quarkiverse.quinoa:quarkus-quinoa")),
32+
new Preset("webapp-qute", "Web app with ServerSide Rendering",
33+
GlobalConstants.ICONS_ASSETS_URL + "/ibm-presets/webapp-qute.svg",
34+
List.of("io.quarkiverse.qute.web:quarkus-qute-web", "io.quarkiverse.web-bundler:quarkus-web-bundler")),
35+
new Preset("ai-infused", "AI Infused service",
36+
GlobalConstants.ICONS_ASSETS_URL + "/ibm-presets/ai-infused.svg",
37+
List.of("io.quarkiverse.langchain4j:quarkus-langchain4j-openai",
38+
"io.quarkiverse.langchain4j:quarkus-langchain4j-easy-rag")));
39+
40+
//language=xml
41+
static final List<String> IBM_POM_REPOSITORIES = """
42+
<repositories>
43+
<repository>
44+
<id>ibm-enterprise-maven-repository</id>
45+
<url>https://maven.repository.ibm.com/releases/</url>
46+
<releases>
47+
<enabled>true</enabled>
48+
</releases>
49+
<snapshots>
50+
<enabled>true</enabled>
51+
</snapshots>
52+
</repository>
53+
</repositories>
54+
<pluginRepositories>
55+
<pluginRepository>
56+
<id>ibm-enterprise-maven-repository</id>
57+
<url>https://maven.repository.ibm.com/releases/</url>
58+
<releases>
59+
<enabled>true</enabled>
60+
</releases>
61+
<snapshots>
62+
<enabled>true</enabled>
63+
</snapshots>
64+
</pluginRepository>
65+
</pluginRepositories>
66+
67+
""".lines().toList();
68+
69+
}

src/main/java/OfferingPlatformOverride.java

Lines changed: 45 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,27 @@
11
import io.quarkus.code.model.CodeQuarkusExtension;
22
import io.quarkus.code.model.Preset;
3+
import io.quarkus.code.model.ProjectDefinition;
34
import io.quarkus.code.service.PlatformOverride;
45
import io.quarkus.code.service.PlatformService;
56
import jakarta.inject.Inject;
67
import jakarta.inject.Singleton;
78

9+
import java.io.IOException;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
import java.nio.file.StandardOpenOption;
813
import java.util.List;
914
import java.util.Objects;
10-
import java.util.Set;
15+
import java.util.OptionalInt;
1116
import java.util.function.Function;
17+
import java.util.stream.IntStream;
1218

1319
@Singleton
1420
public class OfferingPlatformOverride implements PlatformOverride {
1521

16-
public static final String ICONS_ASSETS_URL = "/assets/icons";
17-
18-
public static final List<Preset> IBM_PRESETS = List.of(
19-
// Some presets are duplicated to support platforms before and after the Big Reactive Renaming
20-
new Preset("rest-service", "REST service",
21-
ICONS_ASSETS_URL + "/ibm-presets/rest-service.svg",
22-
List.of("io.quarkus:quarkus-rest")),
23-
new Preset("db-service", "REST service with database",
24-
ICONS_ASSETS_URL + "/ibm-presets/db-service.svg",
25-
List.of("io.quarkus:quarkus-rest", "io.quarkus:quarkus-rest-jackson",
26-
"io.quarkus:quarkus-hibernate-orm-panache", "io.quarkus:quarkus-jdbc-postgresql")),
27-
new Preset("event-driven-kafka", "Event driven service with Kafka",
28-
ICONS_ASSETS_URL + "/ibm-presets/event-driven.svg",
29-
List.of("io.quarkus:quarkus-messaging-kafka")),
30-
new Preset("cli", "Command-line tool",
31-
ICONS_ASSETS_URL + "/ibm-presets/cli.svg",
32-
List.of("io.quarkus:quarkus-picocli")),
33-
new Preset("webapp-mvc", "Web app with Model-View-Controller",
34-
ICONS_ASSETS_URL + "/ibm-presets/webapp-mvc.svg",
35-
List.of("io.quarkiverse.renarde:quarkus-renarde", "io.quarkiverse.web-bundler:quarkus-web-bundler")),
36-
new Preset("webapp-npm", "Web app with NPM UI",
37-
ICONS_ASSETS_URL + "/ibm-presets/webapp-npm.svg",
38-
List.of("io.quarkus:quarkus-rest", "io.quarkus:quarkus-rest-jackson",
39-
"io.quarkiverse.quinoa:quarkus-quinoa")),
40-
new Preset("webapp-qute", "Web app with ServerSide Rendering",
41-
ICONS_ASSETS_URL + "/ibm-presets/webapp-qute.svg",
42-
List.of("io.quarkiverse.qute.web:quarkus-qute-web", "io.quarkiverse.web-bundler:quarkus-web-bundler")),
43-
new Preset("ai-infused", "AI Infused service",
44-
ICONS_ASSETS_URL + "/ibm-presets/ai-infused.svg",
45-
List.of("io.quarkiverse.langchain4j:quarkus-langchain4j-openai",
46-
"io.quarkiverse.langchain4j:quarkus-langchain4j-easy-rag")));
47-
48-
public static final List<Preset> REDHAT_CAMEL_PRESETS = List.of(
49-
// Some presets are duplicated to support platforms before and after the Big Reactive Renaming
50-
new Preset("web-service", "Web service",
51-
ICONS_ASSETS_URL + "/redhat-camel-presets/orange-rest_pos.svg",
52-
List.of("org.apache.camel.quarkus:camel-quarkus-rest",
53-
"org.apache.camel.quarkus:camel-quarkus-rest-openapi",
54-
"org.apache.camel.quarkus:camel-quarkus-cxf-soap",
55-
"io.quarkiverse.cxf:quarkus-cxf")),
56-
new Preset("db-service", "REST service with database",
57-
ICONS_ASSETS_URL + "/redhat-camel-presets/orange-db-service_pos.svg",
58-
List.of("org.apache.camel.quarkus:camel-quarkus-rest",
59-
"org.apache.camel.quarkus:camel-quarkus-aws2-ddb",
60-
"org.apache.camel.quarkus:camel-quarkus-cassandraql",
61-
"org.apache.camel.quarkus:camel-quarkus-jdbc",
62-
"org.apache.camel.quarkus:camel-quarkus-jpa",
63-
"org.apache.camel.quarkus:camel-quarkus-kudu",
64-
"org.apache.camel.quarkus:camel-quarkus-ldap",
65-
"org.apache.camel.quarkus:camel-quarkus-mongodb",
66-
"org.apache.camel.quarkus:camel-quarkus-mybatis",
67-
"org.apache.camel.quarkus:camel-quarkus-sql")),
68-
new Preset("event-driven-kafka", "Event driven service with Kafka",
69-
ICONS_ASSETS_URL + "/redhat-camel-presets/orange-event-driven-kafka_pos.svg",
70-
List.of("org.apache.camel.quarkus:camel-quarkus-kafka",
71-
"org.apache.camel.quarkus:camel-quarkus-jms")),
72-
new Preset("ai-infused", "AI Infused service",
73-
ICONS_ASSETS_URL + "/redhat-camel-presets/orange-ai-infused_pos.svg",
74-
List.of("org.apache.camel.quarkus:camel-quarkus-langchain4j-agent",
75-
"org.apache.camel.quarkus:camel-quarkus-langchain4j-chat",
76-
"org.apache.camel.quarkus:camel-quarkus-langchain4j-tokenizer",
77-
"org.apache.camel.quarkus:camel-quarkus-langchain4j-tools",
78-
"org.apache.camel.quarkus:camel-quarkus-langchain4j-web-search")));
79-
8022
@Inject
8123
OfferingConfig config;
8224

83-
private static final Set<String> TAGS = Set.of(
84-
"with:starter-code", "status:stable", "status:preview", "status:experimental", "status:deprecated",
85-
"support:full-support", "support:supported-in-jvm", "support:dev-support", "support:tech-preview",
86-
"support:deprecated");
87-
8825
@Override
8926
public Function<CodeQuarkusExtension, CodeQuarkusExtension> extensionMapper() {
9027
return Function.identity();
@@ -94,19 +31,54 @@ public Function<CodeQuarkusExtension, CodeQuarkusExtension> extensionMapper() {
9431
public List<Preset> presets() {
9532
switch (config.id()) {
9633
case "ibm":
97-
return IBM_PRESETS;
34+
return IBMConstants.IBM_PRESETS;
9835
case "redhat-camel":
99-
return REDHAT_CAMEL_PRESETS;
36+
return RedHatCamelConstants.REDHAT_CAMEL_PRESETS;
10037
default:
10138
return PlatformService.DEFAULT_PRESETS.stream()
10239
.map(p -> new Preset(p.key(), p.title(), p.icon().replace("_neg", "_pos"), p.extensions()))
10340
.toList();
10441
}
10542
}
10643

44+
@Override
45+
public void onNewProject(ProjectDefinition projectDefinition, Path dir) {
46+
final List<String> repositories = getRepositories();
47+
if (repositories == null) {
48+
return;
49+
}
50+
final Path pom = dir.resolve("pom.xml");
51+
if (Files.isRegularFile(pom)) {
52+
try {
53+
final List<String> pomLines = Files.readAllLines(pom);
54+
if (pomLines.stream().anyMatch(s -> s.contains("<repositories>"))) {
55+
return;
56+
}
57+
OptionalInt lineNumber = IntStream.range(0, pomLines.size())
58+
.filter(i -> pomLines.get(i).contains("<dependencyManagement>"))
59+
.findFirst();
60+
if (lineNumber.isEmpty()) {
61+
throw new RuntimeException(
62+
"Platform generated pom.xml is not valid, please, report this error to the administrator.");
63+
}
64+
pomLines.addAll(lineNumber.getAsInt(), repositories);
65+
Files.writeString(pom, String.join("\n", pomLines), StandardOpenOption.TRUNCATE_EXISTING);
66+
} catch (IOException e) {
67+
throw new RuntimeException(e);
68+
}
69+
}
70+
}
71+
72+
private List<String> getRepositories() {
73+
return switch (config.id()) {
74+
case "ibm" -> IBMConstants.IBM_POM_REPOSITORIES;
75+
default -> null;
76+
};
77+
}
78+
10779
@Override
10880
public List<String> extensionTagsMapper(List<String> tags) {
109-
return tags.stream().map(this::mapTag).filter(Objects::nonNull).filter(TAGS::contains).toList();
81+
return tags.stream().map(this::mapTag).filter(Objects::nonNull).filter(GlobalConstants.TAGS::contains).toList();
11082
}
11183

11284
private String mapTag(String s) {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import io.quarkus.code.model.Preset;
2+
3+
import java.util.List;
4+
5+
public class RedHatCamelConstants {
6+
7+
private RedHatCamelConstants() {
8+
}
9+
10+
static final List<Preset> REDHAT_CAMEL_PRESETS = List.of(
11+
// Some presets are duplicated to support platforms before and after the Big Reactive Renaming
12+
new Preset("web-service", "Web service",
13+
GlobalConstants.ICONS_ASSETS_URL + "/redhat-camel-presets/orange-rest_pos.svg",
14+
List.of("org.apache.camel.quarkus:camel-quarkus-rest",
15+
"org.apache.camel.quarkus:camel-quarkus-rest-openapi",
16+
"org.apache.camel.quarkus:camel-quarkus-cxf-soap",
17+
"io.quarkiverse.cxf:quarkus-cxf")),
18+
new Preset("db-service", "REST service with database",
19+
GlobalConstants.ICONS_ASSETS_URL + "/redhat-camel-presets/orange-db-service_pos.svg",
20+
List.of("org.apache.camel.quarkus:camel-quarkus-rest",
21+
"org.apache.camel.quarkus:camel-quarkus-aws2-ddb",
22+
"org.apache.camel.quarkus:camel-quarkus-cassandraql",
23+
"org.apache.camel.quarkus:camel-quarkus-jdbc",
24+
"org.apache.camel.quarkus:camel-quarkus-jpa",
25+
"org.apache.camel.quarkus:camel-quarkus-kudu",
26+
"org.apache.camel.quarkus:camel-quarkus-ldap",
27+
"org.apache.camel.quarkus:camel-quarkus-mongodb",
28+
"org.apache.camel.quarkus:camel-quarkus-mybatis",
29+
"org.apache.camel.quarkus:camel-quarkus-sql")),
30+
new Preset("event-driven-kafka", "Event driven service with Kafka",
31+
GlobalConstants.ICONS_ASSETS_URL + "/redhat-camel-presets/orange-event-driven-kafka_pos.svg",
32+
List.of("org.apache.camel.quarkus:camel-quarkus-kafka",
33+
"org.apache.camel.quarkus:camel-quarkus-jms")),
34+
new Preset("ai-infused", "AI Infused service",
35+
GlobalConstants.ICONS_ASSETS_URL + "/redhat-camel-presets/orange-ai-infused_pos.svg",
36+
List.of("org.apache.camel.quarkus:camel-quarkus-langchain4j-agent",
37+
"org.apache.camel.quarkus:camel-quarkus-langchain4j-chat",
38+
"org.apache.camel.quarkus:camel-quarkus-langchain4j-tokenizer",
39+
"org.apache.camel.quarkus:camel-quarkus-langchain4j-tools",
40+
"org.apache.camel.quarkus:camel-quarkus-langchain4j-web-search")));
41+
}

src/main/java/RedHatConstants.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import io.quarkus.code.model.Preset;
2+
3+
import java.util.List;
4+
5+
public class RedHatConstants {
6+
7+
private RedHatConstants() {
8+
}
9+
10+
//language=xml
11+
static final List<String> REDHAT_POM_REPOSITORIES = """
12+
<repositories>
13+
<repository>
14+
<id>red-hat-enterprise-maven-repository</id>
15+
<url>https://maven.repository.redhat.com/ga/</url>
16+
<releases>
17+
<enabled>true</enabled>
18+
</releases>
19+
<snapshots>
20+
<enabled>true</enabled>
21+
</snapshots>
22+
</repository>
23+
</repositories>
24+
<pluginRepositories>
25+
<pluginRepository>
26+
<id>red-hat-enterprise-maven-repository</id>
27+
<url>https://maven.repository.redhat.com/ga/</url>
28+
<releases>
29+
<enabled>true</enabled>
30+
</releases>
31+
<snapshots>
32+
<enabled>true</enabled>
33+
</snapshots>
34+
</pluginRepository>
35+
</pluginRepositories>
36+
37+
""".lines().toList();
38+
}

0 commit comments

Comments
 (0)