Skip to content

Commit

Permalink
⬆️ Change CSB archetype, from TNB to CSB one
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarlett authored and avano committed Sep 14, 2023
1 parent fa36154 commit b00427e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 37 deletions.
2 changes: 1 addition & 1 deletion fuse-products/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ inside the product's package.
The integrations are created differently for each product:

- `camel on springboot`:
- an application skeleton is generated from the [archetype](https://github.com/tnb-software/camel3-archetype-spring-boot)
- an application skeleton is generated from the [archetype](https://github.com/apache/camel-spring-boot/tree/main/archetypes/camel-archetype-spring-boot)
- the `integration code` is dumped as a `java file` in the app skeleton
- `camel quarkus`:
- an application skeleton is generated from the `io.quarkus:quarkus-maven-plugin:<version>:create` maven plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package software.tnb.product.csb.application;

import software.tnb.common.config.OpenshiftConfiguration;
import software.tnb.common.config.TestConfiguration;
import software.tnb.common.utils.IOUtils;
import software.tnb.product.application.App;
Expand All @@ -15,6 +16,7 @@
import software.tnb.product.util.maven.BuildRequest;
import software.tnb.product.util.maven.Maven;

import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.slf4j.Logger;
Expand Down Expand Up @@ -63,16 +65,7 @@ public SpringBootApp(AbstractIntegrationBuilder<?> integrationBuilder) {
"groupId", TestConfiguration.appGroupId(),
"artifactId", name,
"version", "1.0.0-SNAPSHOT",
"package", TestConfiguration.appGroupId(),
"maven-compiler-plugin-version", SpringBootConfiguration.mavenCompilerPluginVersion(),
"default-spring-boot-version", SpringBootConfiguration.springBootVersion(),
"default-camel-spring-boot-version", SpringBootConfiguration.camelSpringBootVersion()));
if (SpringBootConfiguration.camelSpringBootVersion().contains("redhat")) {
properties.put("dependencies-resolution", "redhat-platform");
}
if (Integer.parseInt(System.getProperty("java.version").split("\\.")[0]) >= 17) {
properties.put("java-version", "17");
}
"package", TestConfiguration.appGroupId()));
properties.put("archetypeCatalog", "internal");

Maven.invoke(new BuildRequest.Builder()
Expand All @@ -83,16 +76,22 @@ public SpringBootApp(AbstractIntegrationBuilder<?> integrationBuilder) {
.withLogMarker(LogStream.marker(name, Phase.GENERATE))
.build());

IntegrationGenerator.toFile(integrationBuilder, TestConfiguration.appLocation().resolve(name));
final Path basePath = TestConfiguration.appLocation().resolve(name);

removeExistingTests(basePath);

keepWebLayerOnlyForOcp(OpenshiftConfiguration.isOpenshift(), basePath);

IntegrationGenerator.toFile(integrationBuilder, basePath);

customizeMain(integrationBuilder, TestConfiguration.appLocation().resolve(name));
customizeMain(integrationBuilder, basePath);

customizeDependencies(integrationBuilder.getDependencies());

customizePlugins(integrationBuilder.getPlugins());

BuildRequest.Builder requestBuilder = new BuildRequest.Builder()
.withBaseDirectory(TestConfiguration.appLocation().resolve(name))
.withBaseDirectory(basePath)
.withGoals("clean", "package")
.withProperties(Map.of(
"skipTests", "true"
Expand All @@ -105,6 +104,41 @@ public SpringBootApp(AbstractIntegrationBuilder<?> integrationBuilder) {
}
}

private void keepWebLayerOnlyForOcp(boolean isOpenShift, Path location) {
final List<String> artifactsToRemove = new ArrayList<>(List.of("camel-stream-starter"));

if (!isOpenShift) {
artifactsToRemove.addAll(List.of("spring-boot-starter-web", "spring-boot-starter-undertow"
, "spring-boot-starter-actuator"));
}
File pom = location.resolve("pom.xml").toFile();
Model model = Maven.loadPom(pom);

artifactsToRemove.stream().forEach(artifact -> {
model.getDependencies().stream()
.filter(dependency -> artifact.equals(dependency.getArtifactId()))
.findFirst().ifPresent(dependency -> model.removeDependency(dependency));
});

Maven.writePom(pom, model);

}

private void removeExistingTests(final Path location) {
FileUtils.deleteQuietly(location.resolve(Path.of("src", "test")).toFile());
final String[] packages = TestConfiguration.appGroupId().split("\\.");
Path basePackagePath = location.resolve(Path.of("src", "main", "java"));
for (String aPackage : packages) {
basePackagePath = basePackagePath.resolve(aPackage);
}
final Path finalBasePackagePath = basePackagePath;
List.of("MySpringBean.java", "MySpringBootRouter.java")
.stream()
.map(f -> finalBasePackagePath.resolve(f).toFile())
.filter(File::exists)
.forEach(File::delete);
}

protected Path getExistingJar(AbstractIntegrationBuilder<?> integrationBuilder) {
return integrationBuilder instanceof SpringBootIntegrationBuilder
? ((SpringBootIntegrationBuilder) integrationBuilder).getExistingJar() : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static String springBootVersion() {
}

public static String camelSpringBootVersion() {
return getProperty(CAMEL_SPRINGBOOT_VERSION, "3.14.0");
return getProperty(CAMEL_SPRINGBOOT_VERSION, "4.0.0");
}

public static String getCamelSpringbootExamplesRepo() {
Expand Down Expand Up @@ -62,15 +62,15 @@ public static String camelPlatformArtifactId() {
}

public static String camelSpringBootArchetypeGroupId() {
return getProperty(CAMEL_SPRINGBOOT_ARCHETYPE_GROUP_ID, "software.tnb");
return getProperty(CAMEL_SPRINGBOOT_ARCHETYPE_GROUP_ID, "org.apache.camel.archetypes");
}

public static String camelSpringBootArchetypeArtifactId() {
return getProperty(CAMEL_SPRINGBOOT_ARCHETYPE_ARTIFACT_ID, "camel3-archetype-spring-boot");
return getProperty(CAMEL_SPRINGBOOT_ARCHETYPE_ARTIFACT_ID, "camel-archetype-spring-boot");
}

public static String camelSpringBootArchetypeVersion() {
return getProperty(CAMEL_SPRINGBOOT_ARCHETYPE_VERSION, "0.1.9");
return getProperty(CAMEL_SPRINGBOOT_ARCHETYPE_VERSION, camelSpringBootVersion());
}

public static String openshiftMavenPluginGroupId() {
Expand All @@ -79,7 +79,7 @@ public static String openshiftMavenPluginGroupId() {

public static String openshiftMavenPluginVersion() {
return getProperty(OPENSHIFT_MAVEN_PLUGIN_VERSION, () -> StringUtils.removeStart(VersionUtils.getInstance()
.getLatestGitHubReleaseTag("eclipse/jkube", "1.9.1"), "v"));
.getLatestGitHubReleaseTag("eclipse/jkube", "1.13.1"), "v"));
}

public static String mavenCompilerPluginVersion() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package software.tnb.product.deploystrategy.impl;

import software.tnb.common.product.ProductType;
import software.tnb.product.csb.configuration.SpringBootConfiguration;
import software.tnb.product.deploystrategy.OpenshiftDeployStrategy;
import software.tnb.product.deploystrategy.OpenshiftDeployStrategyType;
import software.tnb.product.deploystrategy.impl.custom.CustomJKubeStrategy;
Expand All @@ -11,14 +10,8 @@
@AutoService(OpenshiftDeployStrategy.class)
public class JKubeStrategy extends CustomJKubeStrategy {

public static final String OPENSHIFT_MAVEN_PLUGIN_AID = "openshift-maven-plugin";

private static final String oc = String.format("%s:%s:%s", SpringBootConfiguration.openshiftMavenPluginGroupId()
, OPENSHIFT_MAVEN_PLUGIN_AID
, SpringBootConfiguration.openshiftMavenPluginVersion());

public JKubeStrategy() {
super(new String[]{"clean", "package", oc + ":resource", oc + ":build", oc + ":apply"}, new String[]{"openshift"});
super(new String[]{"clean", "install"}, new String[]{"openshift"});
createTnbDeployment(true);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package software.tnb.product.deploystrategy.impl.custom;

import software.tnb.common.product.ProductType;
import software.tnb.product.csb.configuration.SpringBootConfiguration;
import software.tnb.product.deploystrategy.OpenshiftDeployStrategy;
import software.tnb.product.deploystrategy.OpenshiftDeployStrategyType;

import com.google.auto.service.AutoService;

@AutoService(OpenshiftDeployStrategy.class)
public class JKubeCliStrategy extends CustomJKubeStrategy {

public static final String OPENSHIFT_MAVEN_PLUGIN_AID = "openshift-maven-plugin";

private static final String oc = String.format("%s:%s:%s", SpringBootConfiguration.openshiftMavenPluginGroupId()
, OPENSHIFT_MAVEN_PLUGIN_AID
, SpringBootConfiguration.openshiftMavenPluginVersion());

public JKubeCliStrategy() {
super(new String[]{"clean", "package", oc + ":resource", oc + ":build", oc + ":apply"}, new String[]{"openshift"});
createTnbDeployment(true);
}

@Override
public ProductType[] products() {
return new ProductType[] {ProductType.CAMEL_SPRINGBOOT};
}

@Override
public OpenshiftDeployStrategyType deployType() {
return OpenshiftDeployStrategyType.CUSTOM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,7 @@ public void shouldCreateSpringBootAppTest() {
"groupId", TestConfiguration.appGroupId(),
"artifactId", name(),
"version", "1.0.0-SNAPSHOT",
"package", TestConfiguration.appGroupId(),
"maven-compiler-plugin-version", SpringBootConfiguration.mavenCompilerPluginVersion(),
"default-spring-boot-version", SpringBootConfiguration.springBootVersion(),
"default-camel-spring-boot-version", SpringBootConfiguration.camelSpringBootVersion()));
if (SpringBootConfiguration.camelSpringBootVersion().contains("redhat")) {
properties.put("dependencies-resolution", "redhat-platform");
}
if (Integer.parseInt(System.getProperty("java.version").split("\\.")[0]) >= 17) {
properties.put("java-version", "17");
}
"package", TestConfiguration.appGroupId()));
properties.put("archetypeCatalog", "internal");

SoftAssertions sa = new SoftAssertions();
Expand Down

0 comments on commit b00427e

Please sign in to comment.