Skip to content

Commit

Permalink
[update] Add cxf-rest customizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Veres authored and mcarlett committed Dec 7, 2022
1 parent 726f60b commit be3fcf2
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
16 changes: 11 additions & 5 deletions common/src/main/java/software/tnb/common/utils/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.Properties;
Expand All @@ -32,17 +33,22 @@ private IOUtils() {

public static void writeFile(Path file, String content) {
try {
Path dir = file.getParent();
if (!Files.exists(dir)) {
LOG.debug("Creating directory " + dir);
Files.createDirectory(dir);
}
Files.createDirectories(file.getParent());
Files.write(file, content.getBytes());
} catch (IOException e) {
throw new RuntimeException("Unable to write to " + file, e);
}
}

public static void copyFile(Path source, Path target) {
try {
Files.createDirectories(target.getParent());
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new RuntimeException("Unable to copy to " + source, e);
}
}

public static String readFile(Path file) {
try {
return Files.readString(file);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package software.tnb.product.customizer.component.cxf;

import software.tnb.product.customizer.ProductsCustomizer;
import software.tnb.product.cxf.CxfConfiguration;
import software.tnb.product.util.maven.Maven;

public class CxfRestCustomizer extends ProductsCustomizer {

@Override
public void customizeCamelK() {
}

@Override
public void customizeQuarkus() {
}

@Override
public void customizeSpringboot() {
getIntegrationBuilder().dependencies(
Maven.createDependency("org.apache.cxf:cxf-spring-boot-starter-jaxrs:" + CxfConfiguration.cxfVersion(),
"org.springframework.boot:spring-boot-starter-tomcat")
)
.dependencies(
Maven.createDependency("org.apache.camel.springboot:camel-cxf-rest-starter")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public void customizeQuarkus() {
public void customizeSpringboot() {
if (!OpenshiftConfiguration.isOpenshift()) {
getIntegrationBuilder().dependencies(Maven.createDependency("org.springframework.boot:spring-boot-starter-web",
"org.springframework.boot:spring-boot-starter-tomcat"),
Maven.createDependency("org.springframework.boot:spring-boot-starter-undertow"));
"org.springframework.boot:spring-boot-starter-tomcat")
)
.dependencies(
Maven.createDependency("org.springframework.boot:spring-boot-starter-undertow")
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import software.tnb.common.config.OpenshiftConfiguration;
import software.tnb.common.openshift.OpenshiftClient;
import software.tnb.common.utils.IOUtils;
import software.tnb.product.endpoint.Endpoint;
import software.tnb.product.integration.builder.AbstractIntegrationBuilder;
import software.tnb.product.integration.builder.AbstractMavenGitIntegrationBuilder;
Expand Down Expand Up @@ -121,7 +122,7 @@ protected void copyResources(Path contextPath, String destinationFolder) {
resources.forEach(resource -> {
try {
if (resource.getIsContentPath()) {
Files.copy(Paths.get(resource.getContent()), resFolder.resolve(resource.getName()));
IOUtils.copyFile(Paths.get(resource.getContent()), resFolder.resolve(resource.getName()));
} else {
FileUtils.writeStringToFile(new File(resFolder.resolve(resource.getName()).toUri()), resource.getContent(),
StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package software.tnb.product.integration.generator;

import software.tnb.product.ck.integration.builder.CamelKIntegrationBuilder;
import software.tnb.product.integration.builder.AbstractIntegrationBuilder;

import software.tnb.common.config.TestConfiguration;
import software.tnb.common.utils.IOUtils;
import software.tnb.common.utils.PropertiesUtils;
import software.tnb.product.ck.customizer.DependenciesToModelineCustomizer;
import software.tnb.product.ck.customizer.TraitCustomizer;
import software.tnb.product.ck.integration.builder.CamelKIntegrationBuilder;
import software.tnb.product.cq.utils.ApplicationScopeCustomizer;
import software.tnb.product.csb.customizer.CamelMainCustomizer;
import software.tnb.product.csb.customizer.ComponentCustomizer;
import software.tnb.product.customizer.Customizer;
import software.tnb.product.customizer.Customizers;
import software.tnb.product.integration.Resource;
import software.tnb.product.integration.builder.AbstractIntegrationBuilder;
import software.tnb.product.util.InlineCustomizer;
import software.tnb.product.util.RemoveQuarkusAnnotationsCustomizer;

Expand All @@ -28,6 +27,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -41,6 +41,14 @@ public final class IntegrationGenerator {
private IntegrationGenerator() {
}

private static void doWriteResource(Path resourcesPath, Resource resource) {
if (resource.getIsContentPath()) {
IOUtils.copyFile(Paths.get(resource.getContent()), resourcesPath.resolve(resource.getName()));
} else {
IOUtils.writeFile(resourcesPath.resolve(resource.getName()), resource.getContent());
}
}

/**
* Dumps the integration class into a file.
*
Expand All @@ -52,7 +60,7 @@ public static void toFile(AbstractIntegrationBuilder<?> integrationBuilder, Path

// Add additional resources to the application
final Path resourcesPath = location.resolve("src/main/resources");
integrationBuilder.getResources().forEach(resource -> IOUtils.writeFile(resourcesPath.resolve(resource.getName()), resource.getContent()));
integrationBuilder.getResources().forEach(resource -> doWriteResource(resourcesPath, resource));

if (!integrationBuilder.getResources().isEmpty()) {
integrationBuilder.addCustomizer(Customizers.QUARKUS.customize(i ->
Expand Down

0 comments on commit be3fcf2

Please sign in to comment.