Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding two new static file extension folders for Java Specific Workflows #97

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/apis/recognizer/language_recognizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func AnalyzeFile(configFile string, targetLanguage string) (model.Language, erro
}

func isStaticFileExtension(path string) bool {
staticDirs := [2]string{"static/", "templates/"}
staticDirs := [4]string{"static/", "templates/", "META-INF/resources/", "public/"}
for _, dir := range staticDirs {
if strings.Contains(path, dir) {
return true
Expand Down
160 changes: 160 additions & 0 deletions resources/projects/js-static-files-in-java-app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.redhat.coolstore</groupId>
<artifactId>coolstore</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>coolstore-quarkus</name>
<properties>
<compiler-plugin.version>3.13.0</compiler-plugin.version>
<maven.compiler.release>21</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.12.3</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.2.5</surefire-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus.platform</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-client-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-flyway</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
<version>10.12.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-messaging</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-docker</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-minikube</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
<goal>native-image-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<skipITs>false</skipITs>
<quarkus.native.enabled>true</quarkus.native.enabled>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.redhat.coolstore.utils;

import jakarta.enterprise.inject.Produces;
import jakarta.enterprise.inject.spi.InjectionPoint;
import java.util.logging.Logger;


public class Producers {

Logger log = Logger.getLogger(Producers.class.getName());

@Produces
public Logger produceLog(InjectionPoint injectionPoint) {
return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.redhat.coolstore.utils;

import com.redhat.coolstore.model.CatalogItemEntity;
import com.redhat.coolstore.model.Order;
import com.redhat.coolstore.model.OrderItem;
import com.redhat.coolstore.model.Product;
import com.redhat.coolstore.model.ShoppingCart;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import jakarta.json.Json;
import jakarta.json.JsonArray;
import jakarta.json.JsonArrayBuilder;
import jakarta.json.JsonObject;
import jakarta.json.JsonReader;
import jakarta.json.JsonWriter;

import java.util.concurrent.ThreadLocalRandom;
import java.util.logging.Logger;

/**
* Created by tqvarnst on 2017-03-30.
*/
public class Transformers {

private static final String[] RANDOM_NAMES = {"Sven Karlsson","Johan Andersson","Karl Svensson","Anders Johansson","Stefan Olson","Martin Ericsson"};
private static final String[] RANDOM_EMAILS = {"[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"};

private static Logger log = Logger.getLogger(Transformers.class.getName());

public static Product toProduct(CatalogItemEntity entity) {
Product prod = new Product();
prod.setItemId(entity.getItemId());
prod.setName(entity.getName());
prod.setDesc(entity.getDesc());
prod.setPrice(entity.getPrice());
if (entity.getInventory() != null) {
prod.setLocation(entity.getInventory().getLocation());
prod.setLink(entity.getInventory().getLink());
prod.setQuantity(entity.getInventory().getQuantity());
} else {
log.warning("Inventory for " + entity.getName() + "[" + entity.getItemId()+ "] unknown and missing");
}
return prod;
}

public static String shoppingCartToJson(ShoppingCart cart) {
JsonArrayBuilder cartItems = Json.createArrayBuilder();
cart.getShoppingCartItemList().forEach(item -> {
cartItems.add(Json.createObjectBuilder()
.add("productSku",item.getProduct().getItemId())
.add("quantity",item.getQuantity())
);
});

int randomNameAndEmailIndex = ThreadLocalRandom.current().nextInt(RANDOM_NAMES.length);

JsonObject jsonObject = Json.createObjectBuilder()
.add("orderValue", Double.valueOf(cart.getCartTotal()))
.add("customerName",RANDOM_NAMES[randomNameAndEmailIndex])
.add("customerEmail",RANDOM_EMAILS[randomNameAndEmailIndex])
.add("retailPrice", cart.getShoppingCartItemList().stream().mapToDouble(i -> i.getQuantity()*i.getPrice()).sum())
.add("discount", Double.valueOf(cart.getCartItemPromoSavings()))
.add("shippingFee", Double.valueOf(cart.getShippingTotal()))
.add("shippingDiscount", Double.valueOf(cart.getShippingPromoSavings()))
.add("items",cartItems)
.build();
StringWriter w = new StringWriter();
try (JsonWriter writer = Json.createWriter(w)) {
writer.write(jsonObject);
}
return w.toString();
}

public static Order jsonToOrder(String json) {
JsonReader jsonReader = Json.createReader(new StringReader(json));
JsonObject rootObject = jsonReader.readObject();
Order order = new Order();
order.setCustomerName(rootObject.getString("customerName"));
order.setCustomerEmail(rootObject.getString("customerEmail"));
order.setOrderValue(rootObject.getJsonNumber("orderValue").doubleValue());
order.setRetailPrice(rootObject.getJsonNumber("retailPrice").doubleValue());
order.setDiscount(rootObject.getJsonNumber("discount").doubleValue());
order.setShippingFee(rootObject.getJsonNumber("shippingFee").doubleValue());
order.setShippingDiscount(rootObject.getJsonNumber("shippingDiscount").doubleValue());
JsonArray jsonItems = rootObject.getJsonArray("items");
List<OrderItem> items = new ArrayList<OrderItem>(jsonItems.size());
for (JsonObject jsonItem : jsonItems.getValuesAs(JsonObject.class)) {
OrderItem oi = new OrderItem();
oi.setProductId(jsonItem.getString("productSku"));
oi.setQuantity(jsonItem.getInt("quantity"));
items.add(oi);
}
order.setItemList(items);
return order;
}


}
Loading
Loading