├── barista ├── src │ ├── test │ │ ├── resources │ │ │ ├── spring.properties │ │ │ ├── application-contracts.yml │ │ │ ├── contracts │ │ │ │ ├── shouldSendError.groovy │ │ │ │ └── shouldSendServing.groovy │ │ │ └── application-integration.yml │ │ └── java │ │ │ └── io │ │ │ └── spring │ │ │ └── barcelona │ │ │ └── coffee │ │ │ └── barista │ │ │ └── BaseTestClass.java │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── io │ │ └── spring │ │ └── barcelona │ │ └── coffee │ │ └── barista │ │ ├── coffee │ │ ├── BrewingDevice.java │ │ ├── Alternative.java │ │ ├── Coffees.java │ │ ├── Traditional.java │ │ └── Coffee.java │ │ ├── exceptions │ │ └── CoffeeNotAvailableException.java │ │ ├── orders │ │ ├── Order.java │ │ └── OrderEntry.java │ │ ├── service │ │ ├── Serving.java │ │ ├── CoffeeService.java │ │ ├── Beverage.java │ │ └── KafkaHandler.java │ │ └── BaristaApplication.java ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── .gitignore ├── docker-compose.yml ├── pom.xml ├── mvnw.cmd └── mvnw ├── waiter ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── application.yml │ │ └── java │ │ │ └── io │ │ │ └── spring │ │ │ └── barcelona │ │ │ └── coffee │ │ │ └── waiter │ │ │ ├── coffee │ │ │ ├── BrewingDevice.java │ │ │ ├── Alternative.java │ │ │ ├── Traditional.java │ │ │ └── Coffee.java │ │ │ ├── orders │ │ │ ├── Order.java │ │ │ └── OrderEntry.java │ │ │ ├── service │ │ │ ├── Serving.java │ │ │ └── Beverage.java │ │ │ ├── controller │ │ │ └── OrderController.java │ │ │ └── WaiterApplication.java │ └── test │ │ ├── resources │ │ ├── application-contracts.yml │ │ └── application-integration.yml │ │ └── java │ │ └── io │ │ └── spring │ │ └── barcelona │ │ └── coffee │ │ └── waiter │ │ ├── TestApplication.java │ │ ├── ContainersConfig.java │ │ └── WaiterApplicationIntegrationTests.java ├── .gitignore ├── pom.xml ├── mvnw.cmd └── mvnw ├── .idea ├── vcs.xml ├── jpa-buddy.xml ├── .gitignore ├── aws.xml ├── encodings.xml ├── libraries │ ├── Maven__org_springframework_spring_tx_6_0_8_SNAPSHOT.xml │ ├── Maven__org_springframework_spring_aop_6_0_8_SNAPSHOT.xml │ ├── Maven__org_springframework_spring_jcl_6_0_8_SNAPSHOT.xml │ ├── Maven__org_springframework_spring_web_6_0_8_SNAPSHOT.xml │ ├── Maven__org_springframework_spring_core_6_0_8_SNAPSHOT.xml │ ├── Maven__org_springframework_spring_test_6_0_8_SNAPSHOT.xml │ ├── Maven__org_springframework_spring_beans_6_0_8_SNAPSHOT.xml │ ├── Maven__org_springframework_spring_webmvc_6_0_8_SNAPSHOT.xml │ ├── Maven__org_springframework_spring_context_6_0_8_SNAPSHOT.xml │ ├── Maven__org_springframework_spring_messaging_6_0_8_SNAPSHOT.xml │ └── Maven__org_springframework_spring_expression_6_0_8_SNAPSHOT.xml ├── compiler.xml ├── misc.xml ├── jarRepositories.xml └── uiDesigner.xml ├── .gitignore ├── pom.xml └── README.md /barista/src/test/resources/spring.properties: -------------------------------------------------------------------------------- 1 | spring.test.context.failure.threshold = 10 -------------------------------------------------------------------------------- /barista/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OlgaMaciaszek/coffee/HEAD/barista/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /waiter/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OlgaMaciaszek/coffee/HEAD/waiter/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /barista/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | kafka: 3 | producer: 4 | value-serializer: org.springframework.kafka.support.serializer.JsonSerializer -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/jpa-buddy.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /waiter/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 3 | spring: 4 | main: 5 | allow-circular-references: true 6 | kafka: 7 | producer: 8 | value-serializer: org.springframework.kafka.support.serializer.JsonSerializer 9 | -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/coffee/BrewingDevice.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista.coffee; 2 | 3 | /** 4 | * @author Olga Maciaszek-Sharma 5 | */ 6 | public enum BrewingDevice { 7 | 8 | V60, CHEMEX, AERO_PRESS; 9 | } 10 | -------------------------------------------------------------------------------- /waiter/src/main/java/io/spring/barcelona/coffee/waiter/coffee/BrewingDevice.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter.coffee; 2 | 3 | /** 4 | * @author Olga Maciaszek-Sharma 5 | */ 6 | public enum BrewingDevice { 7 | 8 | V60, CHEMEX, AERO_PRESS; 9 | } 10 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | # Zeppelin ignored files 10 | /ZeppelinRemoteNotebooks/ 11 | -------------------------------------------------------------------------------- /.idea/aws.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | -------------------------------------------------------------------------------- /waiter/src/test/resources/application-contracts.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | lifecycle: 3 | timeout-per-shutdown-phase: 1s 4 | kafka: 5 | consumer: 6 | properties: 7 | "key.serializer": "org.springframework.kafka.support.serializer.JsonSerializer" 8 | "key.deserializer": "org.springframework.kafka.support.serializer.JsonDeserializer" 9 | group-id: groupId -------------------------------------------------------------------------------- /barista/src/test/resources/application-contracts.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | lifecycle: 3 | timeout-per-shutdown-phase: 1s 4 | kafka: 5 | consumer: 6 | properties: 7 | "key.serializer": "org.springframework.kafka.support.serializer.JsonSerializer" 8 | "key.deserializer": "org.springframework.kafka.support.serializer.JsonDeserializer" 9 | group-id: groupId -------------------------------------------------------------------------------- /waiter/src/test/resources/application-integration.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | lifecycle: 3 | timeout-per-shutdown-phase: 1s 4 | kafka: 5 | consumer: 6 | properties: 7 | "key.serializer": "org.springframework.kafka.support.serializer.JsonSerializer" 8 | "key.deserializer": "org.springframework.kafka.support.serializer.JsonDeserializer" 9 | group-id: groupId -------------------------------------------------------------------------------- /waiter/src/test/java/io/spring/barcelona/coffee/waiter/TestApplication.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | 5 | public class TestApplication { 6 | public static void main(String[] args) { 7 | SpringApplication 8 | .from(WaiterApplication::main) 9 | .with(ContainersConfig.class) 10 | .run(args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/exceptions/CoffeeNotAvailableException.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista.exceptions; 2 | 3 | /** 4 | * @author Olga Maciaszek-Sharma 5 | */ 6 | public class CoffeeNotAvailableException extends RuntimeException { 7 | 8 | public CoffeeNotAvailableException(String coffeeName) { 9 | super("We currently do not have the following coffee in our menu: " + coffeeName); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /barista/src/test/resources/contracts/shouldSendError.groovy: -------------------------------------------------------------------------------- 1 | package contracts 2 | 3 | import org.springframework.cloud.contract.spec.Contract 4 | 5 | /** 6 | * @author Olga Maciaszek-Sharma 7 | */ 8 | 9 | Contract.make { 10 | label("error") 11 | input { 12 | triggeredBy("triggerError()") 13 | } 14 | outputMessage { 15 | sentTo("errors") 16 | body([ 17 | message: "We currently do not have the following coffee in our menu: expresso" 18 | ]) 19 | } 20 | } -------------------------------------------------------------------------------- /barista/src/test/resources/application-integration.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | lifecycle: 3 | timeout-per-shutdown-phase: 1s 4 | kafka: 5 | producer: 6 | value-serializer: io.spring.barcelona.coffee.barista.config.CustomSerializer 7 | consumer: 8 | properties: 9 | "key.serializer": "org.springframework.kafka.support.serializer.JsonSerializer" 10 | "key.deserializer": "org.springframework.kafka.support.serializer.JsonDeserializer" 11 | group-id: groupId -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /waiter/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /barista/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/orders/Order.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista.orders; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | /** 7 | * @author Olga Maciaszek-Sharma 8 | */ 9 | public class Order { 10 | 11 | private Set entries = new HashSet<>(); 12 | 13 | public void add(OrderEntry orderEntry) { 14 | entries.add(orderEntry); 15 | } 16 | 17 | public Set getEntries() { 18 | return entries; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "Order{" + 24 | "entries=" + entries + 25 | '}'; 26 | } 27 | } -------------------------------------------------------------------------------- /waiter/src/main/java/io/spring/barcelona/coffee/waiter/orders/Order.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter.orders; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | /** 7 | * @author Olga Maciaszek-Sharma 8 | */ 9 | public class Order { 10 | 11 | private Set entries = new HashSet<>(); 12 | 13 | public void add(OrderEntry orderEntry) { 14 | entries.add(orderEntry); 15 | } 16 | 17 | public Set getEntries() { 18 | return entries; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "Order{" + 24 | "entries=" + entries + 25 | '}'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /waiter/src/main/java/io/spring/barcelona/coffee/waiter/service/Serving.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter.service; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | /** 7 | * @author Olga Maciaszek-Sharma 8 | */ 9 | public class Serving { 10 | 11 | private final Set beverages = new HashSet<>(); 12 | 13 | Serving() { 14 | } 15 | 16 | public void add(Beverage beverage) { 17 | beverages.add(beverage); 18 | } 19 | 20 | public Set getBeverages() { 21 | return beverages; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "Serving{" + 27 | "beverages=" + beverages + 28 | '}'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/service/Serving.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista.service; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | /** 7 | * @author Olga Maciaszek-Sharma 8 | */ 9 | public class Serving { 10 | 11 | private final Set beverages = new HashSet<>(); 12 | 13 | Serving() { 14 | } 15 | 16 | public void add(Beverage beverage) { 17 | beverages.add(beverage); 18 | } 19 | 20 | public Set getBeverages() { 21 | return beverages; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "Serving{" + 27 | "beverages=" + beverages + 28 | '}'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | io.spring.barcelona 8 | coffee 9 | pom 10 | 0.0.1-SNAPSHOT 11 | 12 | Coffee 13 | Spring Cloud Contract and Testcontainers sample repo 14 | 15 | 16 | barista 17 | waiter 18 | 19 | 20 | -------------------------------------------------------------------------------- /waiter/src/test/java/io/spring/barcelona/coffee/waiter/ContainersConfig.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter; 2 | 3 | import org.springframework.boot.test.context.TestConfiguration; 4 | import org.springframework.boot.testcontainers.service.connection.ServiceConnection; 5 | import org.springframework.context.annotation.Bean; 6 | import org.testcontainers.containers.KafkaContainer; 7 | import org.testcontainers.utility.DockerImageName; 8 | 9 | @TestConfiguration(proxyBeanMethods = false) 10 | public class ContainersConfig { 11 | 12 | @Bean 13 | @ServiceConnection 14 | public KafkaContainer getKafka() { 15 | 16 | return new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka")); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_tx_6_0_8_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_aop_6_0_8_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_jcl_6_0_8_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_web_6_0_8_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_core_6_0_8_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_test_6_0_8_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_beans_6_0_8_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /waiter/src/main/java/io/spring/barcelona/coffee/waiter/orders/OrderEntry.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter.orders; 2 | 3 | /** 4 | * @author Olga Maciaszek-Sharma 5 | */ 6 | public class OrderEntry { 7 | 8 | private final String beverageName; 9 | private final int count; 10 | 11 | public OrderEntry(String beverageName, int count) { 12 | this.beverageName = beverageName; 13 | this.count = count; 14 | } 15 | 16 | public String getBeverageName() { 17 | return beverageName; 18 | } 19 | 20 | public int getCount() { 21 | return count; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "OrderEntry{" + 27 | "beverageName='" + beverageName + '\'' + 28 | ", count=" + count + 29 | '}'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_webmvc_6_0_8_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/coffee/Alternative.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista.coffee; 2 | 3 | /** 4 | * @author Olga Maciaszek-Sharma 5 | */ 6 | public class Alternative extends Coffee { 7 | 8 | private BrewingDevice device; 9 | 10 | Alternative() { 11 | } 12 | 13 | Alternative(String name, int coffeeContent, BrewingDevice device) { 14 | super(name, coffeeContent); 15 | this.device = device; 16 | } 17 | 18 | public BrewingDevice getDevice() { 19 | return device; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "Alternative Coffee{" + 25 | "name='" + getName() + '\'' + 26 | ", coffeeContent=" + getCoffeeContent() + 27 | ", device=" + device + 28 | '}'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /waiter/src/main/java/io/spring/barcelona/coffee/waiter/coffee/Alternative.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter.coffee; 2 | 3 | /** 4 | * @author Olga Maciaszek-Sharma 5 | */ 6 | public class Alternative extends Coffee { 7 | 8 | private BrewingDevice device; 9 | 10 | Alternative() { 11 | } 12 | 13 | Alternative(String name, int coffeeContent, BrewingDevice device) { 14 | super(name, coffeeContent); 15 | this.device = device; 16 | } 17 | 18 | public BrewingDevice getDevice() { 19 | return device; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "Alternative Coffee{" + 25 | "name='" + getName() + '\'' + 26 | ", coffeeContent=" + getCoffeeContent() + 27 | ", device=" + device + 28 | '}'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_6_0_8_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/orders/OrderEntry.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista.orders; 2 | 3 | /** 4 | * @author Olga Maciaszek-Sharma 5 | */ 6 | public class OrderEntry { 7 | 8 | private String beverageName; 9 | private int count; 10 | 11 | OrderEntry() { 12 | } 13 | 14 | public OrderEntry(String beverageName, int count) { 15 | this.beverageName = beverageName; 16 | this.count = count; 17 | } 18 | 19 | public String getBeverageName() { 20 | return beverageName; 21 | } 22 | 23 | public int getCount() { 24 | return count; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return "OrderEntry{" + 30 | "beverageName='" + beverageName + '\'' + 31 | ", count=" + count + 32 | '}'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_messaging_6_0_8_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_expression_6_0_8_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Coffee Demo App 2 | 3 | Both apps are producers and consumers at the same time, but for the purposes of the demo, producer side contract testing is set up for `barista` module and consumer-side contract testing is set up for `waiter` module. 4 | 5 | ## FLOW 6 | 7 | * Trigger new order via HTTP call in Waiter app (`@PostMapping("/order/{name}/{count}"`), eg. `http POST :8081/order/espresso/1` 8 | * `KafkaTemplate` is used to place a new `Order` on `orders` topic 9 | * The Barista app listens on `orders`; when a new order appears, it processes it into a `Serving` and sends it to `servings` topic; if the beverage name is not matched, a `CoffeeNotAvailableException` is thrown and sent to `errors` topic 10 | * The Waiter app listens on `servings` and `errors` and logs information based on messages received on these topics -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/service/CoffeeService.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista.service; 2 | 3 | import io.spring.barcelona.coffee.barista.coffee.Coffees; 4 | import io.spring.barcelona.coffee.barista.orders.Order; 5 | import org.springframework.stereotype.Service; 6 | 7 | import java.util.Locale; 8 | import java.util.stream.IntStream; 9 | 10 | /** 11 | * @author Olga Maciaszek-Sharma 12 | */ 13 | @Service 14 | public class CoffeeService { 15 | 16 | public Serving prepareServing(Order order) { 17 | Serving serving = new Serving(); 18 | order.getEntries().forEach(entry -> 19 | IntStream.range(0, entry.getCount()) 20 | .forEach(i -> 21 | serving.add(Beverage.of(Coffees.forName(entry.getBeverageName() 22 | .toLowerCase(Locale.getDefault())))))); 23 | return serving; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 20 | -------------------------------------------------------------------------------- /barista/src/test/resources/contracts/shouldSendServing.groovy: -------------------------------------------------------------------------------- 1 | package contracts 2 | 3 | import org.springframework.cloud.contract.spec.Contract 4 | 5 | /** 6 | * @author Olga Maciaszek-Sharma 7 | */ 8 | 9 | Contract.make { 10 | label("serving") 11 | input { 12 | triggeredBy("triggerServing()") 13 | } 14 | outputMessage { 15 | sentTo("servings") 16 | body([beverages: 17 | [[uuid : $(anyUuid()), 18 | coffee: [ 19 | name : "V60", 20 | coffeeContent: "500", 21 | device : "V60" 22 | ]], 23 | [uuid : $(anyUuid()), 24 | coffee: [ 25 | name : "Latte", 26 | coffeeContent : "60", 27 | steamedMilkContent: "180", 28 | milkFoamContent : "5" 29 | ]] 30 | ]]) 31 | headers { 32 | messagingContentType(applicationJson()) 33 | header 'testKey1', 'testValue1' 34 | } 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /waiter/src/main/java/io/spring/barcelona/coffee/waiter/service/Beverage.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter.service; 2 | 3 | import io.spring.barcelona.coffee.waiter.coffee.Coffee; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author Olga Maciaszek-Sharma 9 | */ 10 | public class Beverage { 11 | 12 | private UUID uuid; 13 | private Coffee coffee; 14 | 15 | public static Beverage of(Coffee coffee) { 16 | return new Beverage(UUID.randomUUID(), coffee); 17 | } 18 | 19 | Beverage(UUID uuid, Coffee coffee) { 20 | this.uuid = uuid; 21 | this.coffee = coffee; 22 | } 23 | 24 | Beverage() { 25 | } 26 | 27 | public UUID getUuid() { 28 | return uuid; 29 | } 30 | 31 | public Coffee getCoffee() { 32 | return coffee; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "Beverage{" + 38 | "uuid=" + uuid + 39 | ", coffee=" + coffee + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /barista/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | kafka: 4 | image: wurstmeister/kafka 5 | hostname: kafka 6 | ports: 7 | - '9092:9092' 8 | volumes: 9 | - /var/run/docker.sock:/var/run/docker.sock 10 | environment: 11 | KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 12 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT 13 | KAFKA_LISTENERS: PLAINTEXT://:29092,PLAINTEXT_HOST://:9092 14 | KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:_{PORT_COMMAND} 15 | KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT 16 | PORT_COMMAND: "docker ps | egrep 'kafka(-|_)1' | cut -d: -f 2 | cut -d- -f 1" 17 | depends_on: 18 | - zookeeper 19 | 20 | zookeeper: 21 | image: wurstmeister/zookeeper 22 | ports: 23 | - '2181:2181' 24 | environment: 25 | - KAFKA_ADVERTISED_HOST_NAME=zookeeper 26 | -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/service/Beverage.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista.service; 2 | 3 | import io.spring.barcelona.coffee.barista.coffee.Coffee; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * @author Olga Maciaszek-Sharma 9 | */ 10 | public class Beverage { 11 | 12 | private UUID uuid; 13 | private Coffee coffee; 14 | 15 | public static Beverage of(Coffee coffee) { 16 | return new Beverage(UUID.randomUUID(), coffee); 17 | } 18 | 19 | Beverage(UUID uuid, Coffee coffee) { 20 | this.uuid = uuid; 21 | this.coffee = coffee; 22 | } 23 | 24 | Beverage() { 25 | } 26 | 27 | public UUID getUuid() { 28 | return uuid; 29 | } 30 | 31 | public Coffee getCoffee() { 32 | return coffee; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "Beverage{" + 38 | "uuid=" + uuid + 39 | ", coffee=" + coffee + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/coffee/Coffees.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista.coffee; 2 | 3 | import io.spring.barcelona.coffee.barista.exceptions.CoffeeNotAvailableException; 4 | 5 | import java.util.Map; 6 | 7 | import static io.spring.barcelona.coffee.barista.coffee.Coffee.*; 8 | 9 | /** 10 | * @author Olga Maciaszek-Sharma 11 | */ 12 | public final class Coffees { 13 | 14 | private Coffees() { 15 | throw new IllegalStateException("Do not instantiate utility class"); 16 | } 17 | 18 | private static final Map coffees = Map.of("espresso", espresso(), 19 | "cappuccino", cappuccino(), 20 | "latte", latte(), 21 | "v60", v60(), 22 | "aeropress", aeroPress()); 23 | 24 | public static Coffee forName(String name) { 25 | if (!coffees.containsKey(name)) { 26 | throw new CoffeeNotAvailableException(name); 27 | } 28 | return coffees.get(name); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /barista/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar 19 | -------------------------------------------------------------------------------- /waiter/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar 19 | -------------------------------------------------------------------------------- /waiter/src/main/java/io/spring/barcelona/coffee/waiter/coffee/Traditional.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter.coffee; 2 | 3 | /** 4 | * @author Olga Maciaszek-Sharma 5 | */ 6 | public class Traditional extends Coffee { 7 | 8 | 9 | private int steamedMilkContent; 10 | private int milkFoamContent; 11 | 12 | Traditional() { 13 | } 14 | 15 | Traditional(String name, int coffeeContent, int steamedMilkContent, int milkFoamContent) { 16 | super(name, coffeeContent); 17 | this.steamedMilkContent = steamedMilkContent; 18 | this.milkFoamContent = milkFoamContent; 19 | } 20 | 21 | Traditional(String espresso, int coffeeContent) { 22 | super(espresso, coffeeContent); 23 | } 24 | 25 | public int getSteamedMilkContent() { 26 | return steamedMilkContent; 27 | } 28 | 29 | public int getMilkFoamContent() { 30 | return milkFoamContent; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "Traditional Coffee{" + 36 | "name='" + getName() + '\'' + 37 | ", coffeeContent=" + getCoffeeContent() + 38 | ", steamedMilkContent=" + steamedMilkContent + 39 | ", milkFoamContent=" + milkFoamContent + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/coffee/Traditional.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista.coffee; 2 | 3 | /** 4 | * @author Olga Maciaszek-Sharma 5 | */ 6 | public class Traditional extends Coffee { 7 | 8 | 9 | private int steamedMilkContent; 10 | private int milkFoamContent; 11 | 12 | Traditional() { 13 | } 14 | 15 | Traditional(String name, int coffeeContent, int steamedMilkContent, int milkFoamContent) { 16 | super(name, coffeeContent); 17 | this.steamedMilkContent = steamedMilkContent; 18 | this.milkFoamContent = milkFoamContent; 19 | } 20 | 21 | Traditional(String espresso, int coffeeContent) { 22 | super(espresso, coffeeContent); 23 | } 24 | 25 | public int getSteamedMilkContent() { 26 | return steamedMilkContent; 27 | } 28 | 29 | public int getMilkFoamContent() { 30 | return milkFoamContent; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "Traditional Coffee{" + 36 | "name='" + getName() + '\'' + 37 | ", coffeeContent=" + getCoffeeContent() + 38 | ", steamedMilkContent=" + steamedMilkContent + 39 | ", milkFoamContent=" + milkFoamContent + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /waiter/src/main/java/io/spring/barcelona/coffee/waiter/coffee/Coffee.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter.coffee; 2 | 3 | /** 4 | * @author Olga Maciaszek-Sharma 5 | */ 6 | public class Coffee { 7 | 8 | private String name; 9 | 10 | private int coffeeContent; 11 | 12 | Coffee() { 13 | } 14 | 15 | public static Coffee espresso() { 16 | return new Traditional("Espresso", 30); 17 | } 18 | 19 | public static Coffee cappuccino() { 20 | return new Traditional("Cappuccino", 60, 60, 60); 21 | } 22 | 23 | public static Coffee latte() { 24 | return new Traditional("Latte", 60, 180, 5); 25 | } 26 | 27 | public static Coffee v60() { 28 | return new Alternative("V60", 500, BrewingDevice.V60); 29 | } 30 | 31 | public static Coffee aeroPress() { 32 | return new Alternative("AeroPress", 200, BrewingDevice.AERO_PRESS); 33 | } 34 | 35 | 36 | Coffee(String name, int coffeeContent) { 37 | this.name = name; 38 | this.coffeeContent = coffeeContent; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public int getCoffeeContent() { 46 | return coffeeContent; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "Coffee{" + 52 | "name='" + name + '\'' + 53 | ", coffeeContent=" + coffeeContent + 54 | '}'; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/coffee/Coffee.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista.coffee; 2 | 3 | /** 4 | * @author Olga Maciaszek-Sharma 5 | */ 6 | public class Coffee { 7 | 8 | private String name; 9 | 10 | private int coffeeContent; 11 | 12 | Coffee() { 13 | } 14 | 15 | public static Coffee espresso() { 16 | return new Traditional("Espresso", 30); 17 | } 18 | 19 | public static Coffee cappuccino() { 20 | return new Traditional("Cappuccino", 60, 60, 60); 21 | } 22 | 23 | public static Coffee latte() { 24 | return new Traditional("Latte", 60, 180, 5); 25 | } 26 | 27 | public static Coffee v60() { 28 | return new Alternative("V60", 500, BrewingDevice.V60); 29 | } 30 | 31 | public static Coffee aeroPress() { 32 | return new Alternative("AeroPress", 200, BrewingDevice.AERO_PRESS); 33 | } 34 | 35 | 36 | Coffee(String name, int coffeeContent) { 37 | this.name = name; 38 | this.coffeeContent = coffeeContent; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public int getCoffeeContent() { 46 | return coffeeContent; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "Coffee{" + 52 | "name='" + name + '\'' + 53 | ", coffeeContent=" + coffeeContent + 54 | '}'; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /waiter/src/main/java/io/spring/barcelona/coffee/waiter/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter.controller; 2 | 3 | import io.spring.barcelona.coffee.waiter.orders.Order; 4 | import io.spring.barcelona.coffee.waiter.orders.OrderEntry; 5 | import org.apache.juli.logging.Log; 6 | import org.apache.juli.logging.LogFactory; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.http.HttpStatus; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.kafka.core.KafkaTemplate; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.PathVariable; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | /** 17 | * @author Olga Maciaszek-Sharma 18 | */ 19 | @RestController 20 | public class OrderController { 21 | 22 | private static final Log LOG = LogFactory.getLog(OrderController.class); 23 | 24 | @Autowired 25 | private KafkaTemplate template; 26 | 27 | @GetMapping("/order/{name}/{count}") 28 | public ResponseEntity order(@PathVariable("name") String beverageName, @PathVariable int count) { 29 | Order order = new Order(); 30 | order.add(new OrderEntry(beverageName, count)); 31 | LOG.info("Sending order: " + order); 32 | template.send("orders", order); 33 | return ResponseEntity.status(HttpStatus.CREATED).build(); 34 | } 35 | 36 | @GetMapping("/order") 37 | public ResponseEntity testOrder() { 38 | Order order = new Order(); 39 | order.add(new OrderEntry("latte", 6)); 40 | order.add(new OrderEntry("v60", 8)); 41 | LOG.info("Sending order: " + order); 42 | template.send("orders", order); 43 | return ResponseEntity.status(HttpStatus.CREATED).build(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/BaristaApplication.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista; 2 | 3 | import org.apache.kafka.clients.admin.NewTopic; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.autoconfigure.kafka.ConcurrentKafkaListenerContainerFactoryConfigurer; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; 9 | import org.springframework.kafka.core.ConsumerFactory; 10 | import org.springframework.kafka.core.KafkaTemplate; 11 | import org.springframework.kafka.support.converter.RecordMessageConverter; 12 | import org.springframework.kafka.support.converter.StringJsonMessageConverter; 13 | 14 | @SpringBootApplication 15 | public class BaristaApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(BaristaApplication.class, args); 19 | } 20 | 21 | @Bean 22 | public ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory( 23 | ConcurrentKafkaListenerContainerFactoryConfigurer configurer, 24 | ConsumerFactory kafkaConsumerFactory, 25 | KafkaTemplate template) { 26 | ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>(); 27 | configurer.configure(factory, kafkaConsumerFactory); 28 | return factory; 29 | } 30 | 31 | @Bean 32 | NewTopic orders() { 33 | return new NewTopic("orders", 1, (short) 1); 34 | } 35 | 36 | @Bean 37 | NewTopic servings() { 38 | return new NewTopic("servings", 1, (short) 1); 39 | } 40 | 41 | @Bean 42 | NewTopic errors() { 43 | return new NewTopic("errors", 1, (short) 1); 44 | } 45 | 46 | @Bean 47 | public RecordMessageConverter converter() { 48 | return new StringJsonMessageConverter(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /barista/src/main/java/io/spring/barcelona/coffee/barista/service/KafkaHandler.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista.service; 2 | 3 | import io.spring.barcelona.coffee.barista.exceptions.CoffeeNotAvailableException; 4 | import io.spring.barcelona.coffee.barista.orders.Order; 5 | import org.apache.commons.logging.Log; 6 | import org.apache.commons.logging.LogFactory; 7 | import org.springframework.kafka.annotation.KafkaListener; 8 | import org.springframework.kafka.core.KafkaTemplate; 9 | import org.springframework.kafka.support.KafkaHeaders; 10 | import org.springframework.messaging.MessageHeaders; 11 | import org.springframework.messaging.support.GenericMessage; 12 | import org.springframework.stereotype.Component; 13 | 14 | import java.util.Map; 15 | 16 | /** 17 | * @author Olga Maciaszek-Sharma 18 | */ 19 | @Component 20 | public class KafkaHandler { 21 | 22 | private static final Log LOG = LogFactory.getLog(KafkaHandler.class); 23 | 24 | private final CoffeeService coffeeService; 25 | private final KafkaTemplate template; 26 | 27 | public KafkaHandler(CoffeeService coffeeService, KafkaTemplate template) { 28 | this.coffeeService = coffeeService; 29 | this.template = template; 30 | } 31 | 32 | @KafkaListener(id = "baristaOrders", topics = "orders") 33 | public void listen(Order order) { 34 | LOG.info("Order received: " + order); 35 | process(order); 36 | } 37 | 38 | // Visible for testing 39 | public void process(Order order) { 40 | Serving serving; 41 | try { 42 | serving = coffeeService.prepareServing(order); 43 | } 44 | catch (CoffeeNotAvailableException exception) { 45 | template.send("errors", exception); 46 | return; 47 | } 48 | Map headers = Map.of(KafkaHeaders.TOPIC, "servings", 49 | "testKey1", "testValue1", 50 | "contentType", "application/json"); 51 | template.send(new GenericMessage<>(serving, new MessageHeaders(headers))); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | 39 | 40 | 44 | 45 | 49 | 50 | 54 | 55 | -------------------------------------------------------------------------------- /waiter/src/main/java/io/spring/barcelona/coffee/waiter/WaiterApplication.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter; 2 | 3 | import io.spring.barcelona.coffee.waiter.service.Serving; 4 | import org.apache.commons.logging.Log; 5 | import org.apache.commons.logging.LogFactory; 6 | import org.apache.kafka.clients.admin.NewTopic; 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.boot.autoconfigure.kafka.ConcurrentKafkaListenerContainerFactoryConfigurer; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.kafka.annotation.KafkaListener; 12 | import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; 13 | import org.springframework.kafka.core.ConsumerFactory; 14 | import org.springframework.kafka.core.KafkaTemplate; 15 | import org.springframework.kafka.support.converter.RecordMessageConverter; 16 | import org.springframework.kafka.support.converter.StringJsonMessageConverter; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | @SpringBootApplication 20 | @RestController 21 | public class WaiterApplication { 22 | 23 | private static final Log LOG = LogFactory.getLog(WaiterApplication.class); 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(WaiterApplication.class, args); 27 | } 28 | 29 | @Bean 30 | public ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory( 31 | ConcurrentKafkaListenerContainerFactoryConfigurer configurer, 32 | ConsumerFactory kafkaConsumerFactory, 33 | KafkaTemplate template) { 34 | ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>(); 35 | configurer.configure(factory, kafkaConsumerFactory); 36 | return factory; 37 | } 38 | 39 | @Bean 40 | NewTopic orders() { 41 | return new NewTopic("orders", 1, (short) 1); 42 | } 43 | 44 | @Bean 45 | public RecordMessageConverter converter() { 46 | return new StringJsonMessageConverter(); 47 | } 48 | 49 | @Bean 50 | NewTopic servings() { 51 | return new NewTopic("servings", 1, (short) 1); 52 | } 53 | 54 | @Bean 55 | NewTopic errors() { 56 | return new NewTopic("errors", 1, (short) 1); 57 | } 58 | 59 | @KafkaListener(id = "waiterServings", topics = "servings") 60 | public void servings(Serving serving) { 61 | LOG.info("Here you are: " + serving); 62 | } 63 | 64 | @KafkaListener(id = "waiterErrors", topics = "errors") 65 | public void errors(Exception exception) { 66 | LOG.info("We apologise : " + exception.getMessage()); 67 | } 68 | 69 | } 70 | 71 | 72 | -------------------------------------------------------------------------------- /waiter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 3.2.0-M1 10 | 11 | 12 | io.spring.barcelona 13 | waiter 14 | 0.0.1-SNAPSHOT 15 | waiter 16 | waiter 17 | 18 | 17 19 | 2023.0.0-M1 20 | 1.18.3 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter 26 | 27 | 28 | org.springframework.kafka 29 | spring-kafka 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-web 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-test 39 | test 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-contract-stub-runner 44 | test 45 | 46 | 47 | org.testcontainers 48 | junit-jupiter 49 | test 50 | 51 | 52 | org.assertj 53 | assertj-core 54 | test 55 | 56 | 57 | org.testcontainers 58 | kafka 59 | test 60 | 61 | 62 | io.rest-assured 63 | rest-assured 64 | test 65 | 66 | 67 | org.awaitility 68 | awaitility 69 | test 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-testcontainers 74 | test 75 | 76 | 77 | 78 | 79 | 80 | org.springframework.cloud 81 | spring-cloud-dependencies 82 | ${spring-cloud.version} 83 | pom 84 | import 85 | 86 | 87 | org.testcontainers 88 | testcontainers-bom 89 | ${testcontainers.version} 90 | pom 91 | import 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | org.springframework.boot 100 | spring-boot-maven-plugin 101 | 102 | 103 | 104 | 105 | 106 | 107 | sonatype 108 | https://oss.sonatype.org/content/repositories/snapshots/ 109 | 110 | 111 | 112 | spring-snapshots 113 | Spring Snapshots 114 | https://repo.spring.io/snapshot 115 | 116 | true 117 | 118 | 119 | 120 | spring-milestones 121 | Spring Milestones 122 | https://repo.spring.io/milestone 123 | 124 | false 125 | 126 | 127 | 128 | spring-releases 129 | Spring Releases 130 | https://repo.spring.io/release 131 | 132 | false 133 | 134 | 135 | 136 | 137 | 138 | spring-snapshots 139 | Spring Snapshots 140 | https://repo.spring.io/snapshot 141 | 142 | true 143 | 144 | 145 | 146 | spring-milestones 147 | Spring Milestones 148 | https://repo.spring.io/milestone 149 | 150 | false 151 | 152 | 153 | 154 | spring-plugin-snapshots 155 | Spring Snapshots 156 | https://repo.spring.io/snapshot 157 | 158 | true 159 | 160 | 161 | 162 | spring-plugin-milestones 163 | Spring Milestones 164 | https://repo.spring.io/release 165 | 166 | false 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /barista/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 3.2.0-M1 10 | 11 | 12 | io.spring.barcelona 13 | barista 14 | 0.0.1-SNAPSHOT 15 | barista 16 | barista 17 | 18 | 17 19 | 2023.0.0-M1 20 | 1.18.3 21 | 4.1.0-M1 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | org.springframework.kafka 34 | spring-kafka 35 | 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-contract-stub-runner 40 | test 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-starter-contract-verifier 50 | test 51 | 52 | 53 | org.testcontainers 54 | junit-jupiter 55 | test 56 | 57 | 58 | org.testcontainers 59 | kafka 60 | test 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-testcontainers 65 | test 66 | 67 | 68 | 69 | 70 | 71 | org.springframework.cloud 72 | spring-cloud-dependencies 73 | ${spring-cloud.version} 74 | pom 75 | import 76 | 77 | 78 | org.testcontainers 79 | testcontainers-bom 80 | ${testcontainers.version} 81 | pom 82 | import 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | org.springframework.boot 91 | spring-boot-maven-plugin 92 | 93 | 94 | org.springframework.cloud 95 | spring-cloud-contract-maven-plugin 96 | ${spring-cloud-contract-maven-plugin.version} 97 | true 98 | 99 | JUNIT5 100 | io.spring.barcelona.coffee.barista.BaseTestClass 101 | 102 | 103 | 104 | 105 | 106 | 107 | sonatype 108 | https://oss.sonatype.org/content/repositories/snapshots/ 109 | 110 | 111 | 112 | spring-snapshots 113 | Spring Snapshots 114 | https://repo.spring.io/snapshot 115 | 116 | true 117 | 118 | 119 | 120 | spring-milestones 121 | Spring Milestones 122 | https://repo.spring.io/milestone 123 | 124 | false 125 | 126 | 127 | 128 | spring-releases 129 | Spring Releases 130 | https://repo.spring.io/release 131 | 132 | false 133 | 134 | 135 | 136 | 137 | 138 | spring-snapshots 139 | Spring Snapshots 140 | https://repo.spring.io/snapshot 141 | 142 | true 143 | 144 | 145 | 146 | spring-milestones 147 | Spring Milestones 148 | https://repo.spring.io/milestone 149 | 150 | false 151 | 152 | 153 | 154 | spring-plugin-snapshots 155 | Spring Snapshots 156 | https://repo.spring.io/snapshot 157 | 158 | true 159 | 160 | 161 | 162 | spring-plugin-milestones 163 | Spring Milestones 164 | https://repo.spring.io/release 165 | 166 | false 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /barista/src/test/java/io/spring/barcelona/coffee/barista/BaseTestClass.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.barista; 2 | 3 | import io.spring.barcelona.coffee.barista.orders.Order; 4 | import io.spring.barcelona.coffee.barista.orders.OrderEntry; 5 | import io.spring.barcelona.coffee.barista.service.KafkaHandler; 6 | import org.apache.commons.logging.Log; 7 | import org.apache.commons.logging.LogFactory; 8 | import org.apache.kafka.clients.consumer.ConsumerRecord; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | import org.springframework.boot.testcontainers.service.connection.ServiceConnection; 12 | import org.springframework.cloud.contract.verifier.converter.YamlContract; 13 | import org.springframework.cloud.contract.verifier.messaging.MessageVerifierReceiver; 14 | import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureMessageVerifier; 15 | import org.springframework.context.annotation.Bean; 16 | import org.springframework.context.annotation.Configuration; 17 | import org.springframework.context.annotation.Primary; 18 | import org.springframework.kafka.annotation.EnableKafka; 19 | import org.springframework.kafka.annotation.KafkaListener; 20 | import org.springframework.kafka.support.DefaultKafkaHeaderMapper; 21 | import org.springframework.kafka.support.KafkaHeaders; 22 | import org.springframework.kafka.support.converter.JsonMessageConverter; 23 | import org.springframework.messaging.Message; 24 | import org.springframework.messaging.MessageHeaders; 25 | import org.springframework.messaging.handler.annotation.Header; 26 | import org.springframework.messaging.support.MessageBuilder; 27 | import org.springframework.test.context.ActiveProfiles; 28 | import org.testcontainers.containers.KafkaContainer; 29 | import org.testcontainers.junit.jupiter.Container; 30 | import org.testcontainers.junit.jupiter.Testcontainers; 31 | import org.testcontainers.utility.DockerImageName; 32 | 33 | import javax.annotation.Nullable; 34 | import java.util.HashMap; 35 | import java.util.Map; 36 | import java.util.concurrent.ArrayBlockingQueue; 37 | import java.util.concurrent.BlockingQueue; 38 | import java.util.concurrent.ConcurrentHashMap; 39 | import java.util.concurrent.TimeUnit; 40 | 41 | /** 42 | * @author Olga Maciaszek-Sharma 43 | */ 44 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = {BaristaApplication.class, BaseTestClass.TestConfig.class}) 45 | @Testcontainers 46 | @AutoConfigureMessageVerifier 47 | @ActiveProfiles("contracts") 48 | public abstract class BaseTestClass { 49 | 50 | @Autowired 51 | KafkaHandler kafkaHandler; 52 | 53 | @Container 54 | @ServiceConnection 55 | static KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka")); 56 | 57 | public void triggerServing() { 58 | Order order = new Order(); 59 | order.add(new OrderEntry("latte", 1)); 60 | order.add(new OrderEntry("v60", 2)); 61 | kafkaHandler.process(order); 62 | } 63 | 64 | public void triggerError() { 65 | Order order = new Order(); 66 | order.add(new OrderEntry("expresso", 1)); 67 | kafkaHandler.process(order); 68 | } 69 | 70 | @Configuration 71 | @EnableKafka 72 | static class TestConfig { 73 | 74 | @Bean 75 | KafkaMessageVerifier kafkaTemplateMessageVerifier() { 76 | return new KafkaMessageVerifier(); 77 | } 78 | 79 | @Bean 80 | @Primary 81 | JsonMessageConverter noopMessageConverter() { 82 | return new NoopJsonMessageConverter(); 83 | } 84 | 85 | } 86 | 87 | static class KafkaMessageVerifier implements MessageVerifierReceiver> { 88 | 89 | private static final Log LOG = LogFactory.getLog(KafkaMessageVerifier.class); 90 | 91 | Map>> broker = new ConcurrentHashMap<>(); 92 | 93 | 94 | @Override 95 | public Message receive(String destination, long timeout, TimeUnit timeUnit, @Nullable YamlContract contract) { 96 | broker.putIfAbsent(destination, new ArrayBlockingQueue<>(1)); 97 | BlockingQueue> messageQueue = broker.get(destination); 98 | Message message; 99 | try { 100 | message = messageQueue.poll(timeout, timeUnit); 101 | } catch (InterruptedException e) { 102 | throw new RuntimeException(e); 103 | } 104 | if (message != null) { 105 | LOG.info("Removed a message from a topic [" + destination + "]"); 106 | LOG.info(message.getPayload().toString()); 107 | } 108 | return message; 109 | } 110 | 111 | 112 | @KafkaListener(id = "baristaContractTestListener", topics = {"errors", "servings"}) 113 | public void listen(ConsumerRecord payload, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) { 114 | LOG.info("Got a message from a topic [" + topic + "]"); 115 | Map headers = new HashMap<>(); 116 | new DefaultKafkaHeaderMapper().toHeaders(payload.headers(), headers); 117 | broker.putIfAbsent(topic, new ArrayBlockingQueue<>(1)); 118 | BlockingQueue> messageQueue = broker.get(topic); 119 | messageQueue.add(MessageBuilder.createMessage(payload.value(), new MessageHeaders(headers))); 120 | } 121 | 122 | @Override 123 | public Message receive(String destination, YamlContract contract) { 124 | return receive(destination, 15, TimeUnit.SECONDS, contract); 125 | } 126 | 127 | } 128 | } 129 | 130 | class NoopJsonMessageConverter extends JsonMessageConverter { 131 | 132 | NoopJsonMessageConverter() { 133 | } 134 | 135 | @Override 136 | protected Object convertPayload(Message message) { 137 | return message.getPayload(); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /waiter/src/test/java/io/spring/barcelona/coffee/waiter/WaiterApplicationIntegrationTests.java: -------------------------------------------------------------------------------- 1 | package io.spring.barcelona.coffee.waiter; 2 | 3 | import io.restassured.RestAssured; 4 | import io.restassured.builder.RequestSpecBuilder; 5 | import io.restassured.specification.RequestSpecification; 6 | import org.apache.kafka.clients.producer.ProducerConfig; 7 | import org.apache.kafka.common.serialization.StringSerializer; 8 | import org.awaitility.Awaitility; 9 | import org.junit.jupiter.api.BeforeEach; 10 | import org.junit.jupiter.api.Test; 11 | import org.junit.jupiter.api.extension.ExtendWith; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.autoconfigure.kafka.KafkaConnectionDetails; 14 | import org.springframework.boot.autoconfigure.kafka.KafkaProperties; 15 | import org.springframework.boot.test.context.SpringBootTest; 16 | import org.springframework.boot.test.system.CapturedOutput; 17 | import org.springframework.boot.test.system.OutputCaptureExtension; 18 | import org.springframework.boot.test.web.server.LocalServerPort; 19 | import org.springframework.cloud.contract.stubrunner.StubTrigger; 20 | import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; 21 | import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; 22 | import org.springframework.cloud.contract.verifier.converter.YamlContract; 23 | import org.springframework.cloud.contract.verifier.messaging.MessageVerifierSender; 24 | import org.springframework.context.annotation.Bean; 25 | import org.springframework.context.annotation.Configuration; 26 | import org.springframework.context.annotation.Primary; 27 | import org.springframework.http.HttpHeaders; 28 | import org.springframework.http.MediaType; 29 | import org.springframework.kafka.core.DefaultKafkaProducerFactory; 30 | import org.springframework.kafka.core.KafkaTemplate; 31 | import org.springframework.kafka.support.KafkaHeaders; 32 | import org.springframework.kafka.support.converter.JsonMessageConverter; 33 | import org.springframework.messaging.Message; 34 | import org.springframework.messaging.MessageHeaders; 35 | import org.springframework.messaging.support.MessageBuilder; 36 | import org.springframework.test.context.ActiveProfiles; 37 | 38 | import javax.annotation.Nullable; 39 | import java.time.Duration; 40 | import java.util.HashMap; 41 | import java.util.Map; 42 | 43 | import static io.restassured.RestAssured.given; 44 | import static org.assertj.core.api.Assertions.assertThat; 45 | 46 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, 47 | classes = {WaiterApplicationIntegrationTests.TestConfig.class, WaiterApplication.class, ContainersConfig.class}) 48 | @AutoConfigureStubRunner(ids = "io.spring.barcelona:barista", 49 | stubsMode = StubRunnerProperties.StubsMode.LOCAL) 50 | @ActiveProfiles("integration") 51 | @ExtendWith(OutputCaptureExtension.class) 52 | class WaiterApplicationIntegrationTests { 53 | 54 | @Autowired 55 | StubTrigger trigger; 56 | 57 | @Test 58 | void shouldProcessServing(CapturedOutput output) { 59 | given(requestSpecification) 60 | .pathParam("order", "V60") 61 | .pathParam("count", "60") 62 | .when().get("/order/{order}/{count}") 63 | .then().statusCode(201); 64 | 65 | trigger.trigger("serving"); 66 | 67 | Awaitility.await().atMost(Duration.ofSeconds(10)) 68 | .pollInterval(Duration.ofMillis(500)) 69 | .untilAsserted(() -> assertThat(output).contains(""" 70 | Here you are: Serving{beverages=[Beverage{""", """ 71 | coffee=Coffee{name='Latte', coffeeContent=60}}""", """ 72 | coffee=Coffee{name='V60', coffeeContent=500}}""")); 73 | } 74 | 75 | @Test 76 | void shouldProcessError(CapturedOutput output) { 77 | trigger.trigger("error"); 78 | 79 | Awaitility.await().atMost(Duration.ofSeconds(30)) 80 | .pollInterval(Duration.ofSeconds(5)) 81 | .untilAsserted(() -> assertThat(output).contains("We currently do not have the following coffee in our menu: expresso")); 82 | } 83 | 84 | // RestAssured config 85 | protected RequestSpecification requestSpecification; 86 | 87 | @LocalServerPort 88 | protected int localServerPort; 89 | 90 | @BeforeEach 91 | public void setUpAbstractIntegrationTest() { 92 | RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); 93 | requestSpecification = new RequestSpecBuilder() 94 | .setPort(localServerPort) 95 | .addHeader( 96 | HttpHeaders.CONTENT_TYPE, 97 | MediaType.APPLICATION_JSON_VALUE 98 | ) 99 | .build(); 100 | } 101 | 102 | @Configuration 103 | static class TestConfig { 104 | 105 | 106 | @Bean 107 | MessageVerifierSender> standaloneMessageVerifier(KafkaProperties properties, KafkaConnectionDetails connectionDetails) { 108 | return new MessageVerifierSender<>() { 109 | 110 | @Override 111 | public void send(Message message, String destination, @Nullable YamlContract contract) { 112 | } 113 | 114 | @Override 115 | public void send(T payload, Map headers, String destination, @Nullable YamlContract contract) { 116 | Map newHeaders = headers != null ? new HashMap<>(headers) : new HashMap<>(); 117 | newHeaders.put(KafkaHeaders.TOPIC, destination); 118 | Map map = properties.buildProducerProperties(); 119 | applyKafkaConnectionDetailsForProducer(map, connectionDetails); 120 | DefaultKafkaProducerFactory factory = new DefaultKafkaProducerFactory<>(map, new StringSerializer(), new StringSerializer()); 121 | KafkaTemplate kafkaTemplate = new KafkaTemplate<>(factory); 122 | kafkaTemplate.send(MessageBuilder.createMessage(payload, new MessageHeaders(newHeaders))); 123 | } 124 | 125 | private void applyKafkaConnectionDetailsForProducer(Map properties, 126 | KafkaConnectionDetails connectionDetails) { 127 | properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, connectionDetails.getProducerBootstrapServers()); 128 | } 129 | }; 130 | } 131 | 132 | @Bean 133 | @Primary 134 | JsonMessageConverter noopMessageConverter() { 135 | return new NoopJsonMessageConverter(); 136 | } 137 | } 138 | 139 | 140 | } 141 | 142 | 143 | class NoopJsonMessageConverter extends JsonMessageConverter { 144 | 145 | NoopJsonMessageConverter() { 146 | } 147 | 148 | @Override 149 | protected Object convertPayload(Message message) { 150 | return message.getPayload(); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /barista/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /waiter/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /waiter/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /barista/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | --------------------------------------------------------------------------------