11import io .quarkus .code .model .CodeQuarkusExtension ;
22import io .quarkus .code .model .Preset ;
3+ import io .quarkus .code .model .ProjectDefinition ;
34import io .quarkus .code .service .PlatformOverride ;
45import io .quarkus .code .service .PlatformService ;
56import jakarta .inject .Inject ;
67import 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 ;
813import java .util .List ;
914import java .util .Objects ;
10- import java .util .Set ;
15+ import java .util .OptionalInt ;
1116import java .util .function .Function ;
17+ import java .util .stream .IntStream ;
1218
1319@ Singleton
1420public 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 ) {
0 commit comments