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 ;
15+ import java .util .OptionalInt ;
1016import java .util .Set ;
1117import java .util .function .Function ;
18+ import java .util .stream .Collectors ;
19+ import java .util .stream .IntStream ;
1220
1321@ Singleton
1422public class OfferingPlatformOverride implements PlatformOverride {
1523
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-
8024 @ Inject
8125 OfferingConfig config ;
8226
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-
8827 @ Override
8928 public Function <CodeQuarkusExtension , CodeQuarkusExtension > extensionMapper () {
9029 return Function .identity ();
@@ -94,19 +33,54 @@ public Function<CodeQuarkusExtension, CodeQuarkusExtension> extensionMapper() {
9433 public List <Preset > presets () {
9534 switch (config .id ()) {
9635 case "ibm" :
97- return IBM_PRESETS ;
36+ return IBMConstants . IBM_PRESETS ;
9837 case "redhat-camel" :
99- return REDHAT_CAMEL_PRESETS ;
38+ return RedHatCamelConstants . REDHAT_CAMEL_PRESETS ;
10039 default :
10140 return PlatformService .DEFAULT_PRESETS .stream ()
10241 .map (p -> new Preset (p .key (), p .title (), p .icon ().replace ("_neg" , "_pos" ), p .extensions ()))
10342 .toList ();
10443 }
10544 }
10645
46+ @ Override
47+ public void onNewProject (ProjectDefinition projectDefinition , Path dir ) {
48+ final List <String > repositories = getRepositories ();
49+ if (repositories == null ) {
50+ return ;
51+ }
52+ final Path pom = dir .resolve ("pom.xml" );
53+ if (Files .isRegularFile (pom )) {
54+ try {
55+ final List <String > strings = Files .readAllLines (pom );
56+ if (strings .stream ().anyMatch (s -> s .contains ("<repositories>" ))) {
57+ return ;
58+ }
59+ OptionalInt lineNumber = IntStream .range (0 , strings .size ())
60+ .filter (i -> strings .get (i ).contains ("<dependencyManagement>" ))
61+ .findFirst ();
62+ if (lineNumber .isEmpty ()) {
63+ throw new RuntimeException (
64+ "Platform generated pom.xml is not valid, please, report this error to the administrator." );
65+ }
66+ strings .addAll (lineNumber .getAsInt (), repositories );
67+ Files .writeString (pom , String .join ("\n " , strings ), StandardOpenOption .TRUNCATE_EXISTING );
68+ } catch (IOException e ) {
69+ throw new RuntimeException (e );
70+ }
71+ }
72+ }
73+
74+ private List <String > getRepositories () {
75+ return switch (config .id ()) {
76+ case "ibm" -> IBMConstants .IBM_POM_REPOSITORIES ;
77+ default -> null ;
78+ };
79+ }
80+
10781 @ Override
10882 public List <String > extensionTagsMapper (List <String > tags ) {
109- return tags .stream ().map (this ::mapTag ).filter (Objects ::nonNull ).filter (TAGS ::contains ).toList ();
83+ return tags .stream ().map (this ::mapTag ).filter (Objects ::nonNull ).filter (GlobalConstants . TAGS ::contains ).toList ();
11084 }
11185
11286 private String mapTag (String s ) {
0 commit comments