├── .github ├── CODEOWNERS ├── PULL_REQUEST_TEMPLATE.md ├── workflows │ └── main.yml └── ISSUE_TEMPLATE.md ├── dashboard ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ ├── maven-wrapper.properties │ │ └── MavenWrapperDownloader.java ├── src │ ├── main │ │ ├── resources │ │ │ ├── data.sql │ │ │ ├── schema.sql │ │ │ ├── logback.xml │ │ │ ├── static │ │ │ │ ├── index.html │ │ │ │ └── style.css │ │ │ ├── application.properties │ │ │ ├── banner_custom.txt │ │ │ ├── templates │ │ │ │ ├── error.html │ │ │ │ └── dashboard.html │ │ │ └── META-INF │ │ │ │ └── spring │ │ │ │ ├── integration │ │ │ │ ├── http-api.xml │ │ │ │ ├── jdbc.xml │ │ │ │ ├── status-monitor.xml │ │ │ │ └── twitter.xml │ │ │ │ └── application.xml │ │ └── java │ │ │ └── com │ │ │ └── lil │ │ │ └── springintegration │ │ │ ├── domain │ │ │ ├── AppProperties.java │ │ │ └── AppSupportStatus.java │ │ │ ├── endpoint │ │ │ ├── JdbcMessageTransformer.java │ │ │ ├── AppStatusMessageHandler.java │ │ │ └── AppStatusMessageFilter.java │ │ │ ├── service │ │ │ ├── CustomerAccountService.java │ │ │ ├── StatusMonitorService.java │ │ │ └── ViewService.java │ │ │ ├── DashboardApplication.java │ │ │ └── manage │ │ │ └── DashboardManager.java │ └── test │ │ └── java │ │ └── com │ │ └── lil │ │ └── springintegration │ │ └── DashboardApplicationTests.java ├── pom.xml ├── mvnw.cmd └── mvnw ├── .gitignore ├── CONTRIBUTING.md ├── NOTICE ├── CODE_CHALLENGE_02_04.MD ├── CODE_CHALLENGE_03_04.MD ├── README.md └── LICENSE /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Codeowners for these exercise files: 2 | # * (asterisk) deotes "all files and folders" 3 | # Example: * @producer @instructor 4 | -------------------------------------------------------------------------------- /dashboard/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInLearning/spring-spring-integration-2848253/HEAD/dashboard/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO DEVICE (name, display, isUp) VALUES 2 | ('solar_1', 'House Solar', 1), 3 | ('solar_2', 'Office Solar', 0), 4 | ('store_1', 'Main Battery', 1); -------------------------------------------------------------------------------- /dashboard/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS DEVICE; 2 | 3 | CREATE TABLE DEVICE ( 4 | id INT AUTO_INCREMENT PRIMARY KEY, 5 | name VARCHAR(250) NOT NULL, 6 | display VARCHAR(250) NOT NULL, 7 | isUp BIT NOT NULL 8 | ); 9 | -------------------------------------------------------------------------------- /dashboard/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Copy To Branches 2 | on: 3 | workflow_dispatch: 4 | jobs: 5 | copy-to-branches: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | with: 10 | fetch-depth: 0 11 | - name: Copy To Branches Action 12 | uses: planetoftheweb/copy-to-branches@v1 13 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Kinetico Power Grid: Dashboard 5 | 6 | 7 | 8 | 9 |

Get your dashboard here

10 | 11 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.root = WARN 2 | logging.level.com.lil=INFO 3 | spring.banner.location = classpath:banner_custom.txt 4 | server.port = 9090 5 | server.error.whitelabel.enabled=false 6 | spring.jpa.open-in-view= 7 | twitter.oauth.consumerKey=fill_me 8 | twitter.oauth.consumerSecret=fill_me 9 | twitter.oauth.accessToken=fill_me 10 | twitter.oauth.accessTokenSecret=fill_me 11 | software.build = CH.FINAL 12 | -------------------------------------------------------------------------------- /dashboard/src/main/java/com/lil/springintegration/domain/AppProperties.java: -------------------------------------------------------------------------------- 1 | package com.lil.springintegration.domain; 2 | 3 | import java.util.Properties; 4 | 5 | public class AppProperties { 6 | 7 | private Properties runtimeProperties; 8 | 9 | public void setRuntimeProperties(Properties props) { 10 | this.runtimeProperties = props; 11 | } 12 | 13 | public Properties getRuntimeProperties() { 14 | return runtimeProperties; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/banner_custom.txt: -------------------------------------------------------------------------------- 1 | . ____ _ __ _ _ 2 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ 3 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ 4 | \\/ ___)| |_)| | | | | || (_| | ) ) ) ) 5 | ' |____| .__|_| |_|_| |_\__, | / / / / 6 | =========|_|==============|___/=/_/_/_/ 7 | :: Spring Boot :: (v2.3.3.RELEASE) 8 | :: Spring Integration :: (v5.3.2 RELEASE) 9 | :: LinkedIn Learning :: Course 2848253 10 | :: Spring Integration :: Kathy D. Flint 11 | ========================================= 12 | -------------------------------------------------------------------------------- /dashboard/src/main/java/com/lil/springintegration/endpoint/JdbcMessageTransformer.java: -------------------------------------------------------------------------------- 1 | package com.lil.springintegration.endpoint; 2 | 3 | import com.lil.springintegration.domain.AppSupportStatus; 4 | import org.springframework.util.LinkedCaseInsensitiveMap; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class JdbcMessageTransformer { 9 | 10 | public AppSupportStatus transform(ArrayList> outList) { 11 | AppSupportStatus x = new AppSupportStatus(); 12 | x.setDeviceOut(outList); 13 | return x; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | SPRING_GUIDES.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 | 35 | ### Misc ### 36 | *scratch* 37 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | Contribution Agreement 3 | ====================== 4 | 5 | This repository does not accept pull requests (PRs). All pull requests will be closed. 6 | 7 | However, if any contributions (through pull requests, issues, feedback or otherwise) are provided, as a contributor, you represent that the code you submit is your original work or that of your employer (in which case you represent you have the right to bind your employer). By submitting code (or otherwise providing feedback), you (and, if applicable, your employer) are licensing the submitted code (and/or feedback) to LinkedIn and the open source community subject to the BSD 2-Clause license. 8 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2021 LinkedIn Corporation 2 | All Rights Reserved. 3 | 4 | Licensed under the LinkedIn Learning Exercise File License (the "License"). 5 | See LICENSE in the project root for license information. 6 | 7 | Please note, this project may automatically load third party code from external 8 | repositories (for example, NPM modules, Composer packages, or other dependencies). 9 | If so, such third party code may be subject to other license terms than as set 10 | forth above. In addition, such third party code may also depend on and load 11 | multiple tiers of dependencies. Please review the applicable licenses of the 12 | additional dependencies. 13 | 14 | 15 | -------------------------------------------------------------------------------- /dashboard/src/main/java/com/lil/springintegration/endpoint/AppStatusMessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.lil.springintegration.endpoint; 2 | 3 | import com.lil.springintegration.domain.AppSupportStatus; 4 | import org.springframework.integration.MessageRejectedException; 5 | import org.springframework.messaging.Message; 6 | import org.springframework.messaging.MessageHandler; 7 | import org.springframework.messaging.MessagingException; 8 | 9 | public abstract class AppStatusMessageHandler implements MessageHandler { 10 | 11 | @Override 12 | public void handleMessage(Message message) throws MessagingException { 13 | Object payload = message.getPayload(); 14 | if (payload instanceof AppSupportStatus) { 15 | receive((AppSupportStatus) payload); 16 | } else { 17 | throw new MessageRejectedException(message, "Unknown data type has been received."); 18 | } 19 | } 20 | 21 | protected abstract void receive(AppSupportStatus status); 22 | 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /dashboard/src/main/java/com/lil/springintegration/endpoint/AppStatusMessageFilter.java: -------------------------------------------------------------------------------- 1 | package com.lil.springintegration.endpoint; 2 | 3 | import com.lil.springintegration.domain.AppSupportStatus; 4 | import org.springframework.integration.MessageRejectedException; 5 | import org.springframework.integration.core.MessageSelector; 6 | import org.springframework.messaging.Message; 7 | import org.springframework.messaging.MessagingException; 8 | 9 | public abstract class AppStatusMessageFilter implements MessageSelector { 10 | 11 | @Override 12 | public boolean accept(Message message) throws MessagingException { 13 | Object payload = message.getPayload(); 14 | if (payload instanceof AppSupportStatus) { 15 | return filterMessage((AppSupportStatus) payload); 16 | } else { 17 | throw new MessageRejectedException(message, "Unknown data type has been received: " + payload.getClass()); 18 | } 19 | } 20 | 21 | protected abstract boolean filterMessage(AppSupportStatus status); 22 | } 23 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Kinetico Power Grid: Dashboard 5 | 6 | 7 | 8 | 9 |
10 | 11 |
12 | Consumer Power Grid Dashboard 13 | featuring Spring Integration! 14 |
15 |
16 |
17 | 18 |
19 |

Something went wrong :(

20 |

Go Home

21 |
22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /dashboard/src/main/java/com/lil/springintegration/service/CustomerAccountService.java: -------------------------------------------------------------------------------- 1 | package com.lil.springintegration.service; 2 | 3 | import com.lil.springintegration.domain.AppSupportStatus; 4 | 5 | public class CustomerAccountService { 6 | 7 | private static double mockPersistedCredit = 0.0; 8 | 9 | public static double getAccountCredit() { return mockPersistedCredit; } 10 | 11 | public static boolean isAccountCredit() { return mockPersistedCredit > 0; } 12 | 13 | public void creditCustomerAccount(Object payload) throws IllegalArgumentException { 14 | if (payload instanceof AppSupportStatus) { 15 | AppSupportStatus customerStatus = (AppSupportStatus) payload; 16 | if (customerStatus.getAccountCreditEarned() > 0) { 17 | // Simulates a back-end account credit 18 | mockPersistedCredit += customerStatus.getAccountCreditEarned(); 19 | } 20 | } else { 21 | throw new IllegalArgumentException("Unknown data type has been received: " + payload.getClass()); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CODE_CHALLENGE_02_04.MD: -------------------------------------------------------------------------------- 1 | # CODE CHALLENGE 02_04 2 | 3 | ## Instructions 4 | 5 | Your challenge is to change the Subscribable DirectChannel implementation that we built in 02_02 into a Subscribable PublishSubscribeChannel implementation. 6 | 7 | This way we can consume the same Channel broadcast message by two different subscribers. 8 | 9 | Start in the spring configuration file named `tech-support.xml`. On line 13 you will find instructions and a hint. 10 | 11 | Then move to these files for more instructions and hints. 12 | 13 | * ViewService.java:31 14 | * TechSupportService.java:24 15 | * DashboardManager:64 16 | 17 | (You will need to alter 4 files in total.) 18 | 19 | When you are done, start the application and open your browser to `http://localhost:9090`. In your system out console, you should see a system log message generated by TechSupportService.java:57. You should also see the current build stamp `CH.02_04` reflected in the user interface. 20 | 21 | Congrats! Thanks to the multi-broadcast capabilities of a PublishSubscribeChannel, now you have two different system responses to a single message send event. 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | ## Issue Overview 9 | 10 | 11 | ## Describe your environment 12 | 13 | 14 | ## Steps to Reproduce 15 | 16 | 1. 17 | 2. 18 | 3. 19 | 4. 20 | 21 | ## Expected Behavior 22 | 23 | 24 | ## Current Behavior 25 | 26 | 27 | ## Possible Solution 28 | 29 | 30 | ## Screenshots / Video 31 | 32 | 33 | ## Related Issues 34 | 35 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/static/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: "Lato", sans-serif; 3 | } 4 | .logo { 5 | margin-right: 10%; 6 | float: right; 7 | width: 80px; 8 | } 9 | .h1 { 10 | float: left; 11 | color: #007089; 12 | margin-left: 20%; 13 | font-size: 120%; 14 | font-weight: bold; 15 | margin-top: 10px; 16 | margin-bottom: 10px; 17 | } 18 | .h2 { 19 | float: left; 20 | color: #8bca00; 21 | margin-left: 20%; 22 | font-size: 110%; 23 | font-style: italic; 24 | } 25 | 26 | .header { 27 | position: relative; 28 | height: 90px; 29 | } 30 | 31 | .header div { 32 | float: left; 33 | width: 60%; 34 | } 35 | .grid_shell { 36 | position: relative; 37 | width: 50%; 38 | left: 25%; 39 | padding: 10px; 40 | } 41 | .grid_row { 42 | width: 100%; 43 | height: 200px; 44 | } 45 | 46 | .grid_background { 47 | position: relative; 48 | width: 100%; 49 | overflow: hidden; 50 | } 51 | 52 | .grid_background img { 53 | position: absolute; 54 | left: 0; 55 | top: 0; 56 | width: auto; 57 | height: 400px; 58 | opacity: 0.6; 59 | } 60 | 61 | .grid_container { 62 | width: 45%; 63 | height: 170px; 64 | border: 1px dashed; 65 | border-radius: 5px; 66 | padding: 5px; 67 | background-color: #eeeeee; 68 | } 69 | .col_1 { 70 | float: left; 71 | } 72 | .col_2 { 73 | float: right; 74 | } 75 | 76 | .grid_header { 77 | color: #007089; 78 | font-size: 90%; 79 | font-weight: bold; 80 | margin-top: 5px; 81 | } 82 | 83 | .grid_body { 84 | color: #222222; 85 | font-size: 70%; 86 | } -------------------------------------------------------------------------------- /CODE_CHALLENGE_03_04.MD: -------------------------------------------------------------------------------- 1 | # CODE CHALLENGE 03_04 2 | 3 | ## Instructions 4 | 5 | Your challenge is to add a ServiceActivator to the message flow so that our statusMonitor channel will automatically cause a customer account credit to be applied. 6 | 7 | This way the account credit functionality can be activated as a by-product of the existing message flow, without manual invocation inside our business logic. 8 | 9 | These supporting classes have been supplied 10 | 11 | * CustomerAccountService.java 12 | 13 | Your ServiceActivator should respond to messages on the statusMonitor channel. It should invoke the creditCustomerAccount() method of the CustomerAccountService class. No reply messaging is required. 14 | 15 | Start in the spring configuration file named `status-monitor.xml`. On line 24 you will find additional instructions and hints. 16 | 17 | Files you will need to alter for this challenge 18 | 19 | * status-monitor.xml 20 | 21 | To test your work, run the tests in 22 | 23 | * DashboardApplicationTests.java 24 | 25 | Once your tests are successful, start the application and open your browser to `http://localhost:9090`. In your system out console, you should see a system log message generated by CustomerAccountService.java:23. You should also see the (simulated) account credit balance accumulating in the user interface. 26 | 27 | Congrats! Thanks Spring Integration's ServiceActivator implementation, you have successfully achieved a significant business process invocation with very little development effort required. You have also practiced applying technical directives using the official Spring Integraton technical documentation. 28 | -------------------------------------------------------------------------------- /dashboard/src/test/java/com/lil/springintegration/DashboardApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.lil.springintegration; 2 | 3 | import com.lil.springintegration.service.CustomerAccountService; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.beans.factory.NoSuchBeanDefinitionException; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.context.support.AbstractApplicationContext; 8 | import org.springframework.context.support.ClassPathXmlApplicationContext; 9 | import org.springframework.integration.channel.DirectChannel; 10 | import org.springframework.messaging.support.MessageBuilder; 11 | 12 | @SpringBootTest 13 | class DashboardApplicationTests { 14 | 15 | AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/application.xml", DashboardApplicationTests.class); 16 | 17 | @Test 18 | void springIntegrationContextLoads() { 19 | try { 20 | context.getBean("testMessageFlowImports"); 21 | System.out.println("Spring Integration message flows imported successfully."); 22 | assert(true); 23 | } catch(NoSuchBeanDefinitionException e) { 24 | System.out.println(e.toString()); 25 | assert(false); 26 | } finally { 27 | context.close(); 28 | } 29 | } 30 | 31 | @Test 32 | void customerAccountServiceCreditApplied() { 33 | DirectChannel apiInputChannel = (DirectChannel) context.getBean("apiInputChannel"); 34 | String apiResponse = "{\"runningVersion\":\"CH.03_03\",\"updateRequired\":true,\"netWind\":36,\"netSolar\":11,\"snapTime\":\"Fri Oct 30 12:29:26 CDT 2020\"}"; 35 | assert(!CustomerAccountService.isAccountCredit()); 36 | apiInputChannel.send(MessageBuilder.withPayload(apiResponse).build()); 37 | assert(CustomerAccountService.isAccountCredit()); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /dashboard/src/main/java/com/lil/springintegration/service/StatusMonitorService.java: -------------------------------------------------------------------------------- 1 | package com.lil.springintegration.service; 2 | 3 | import com.lil.springintegration.endpoint.AppStatusMessageFilter; 4 | import com.lil.springintegration.endpoint.AppStatusMessageHandler; 5 | import com.lil.springintegration.manage.DashboardManager; 6 | import com.lil.springintegration.domain.AppSupportStatus; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.integration.channel.*; 10 | 11 | public class StatusMonitorService { 12 | 13 | static Logger logger = LoggerFactory.getLogger(DashboardManager.class); 14 | 15 | private AppSupportStatus currentLocalStatus; 16 | 17 | // TODO - refactor to use Spring Dependency Injection 18 | private AbstractSubscribableChannel statusMonitorChannel; 19 | private DirectChannel apiInputChannel; 20 | 21 | public StatusMonitorService() { 22 | apiInputChannel = (DirectChannel) DashboardManager.getDashboardContext().getBean("apiInputChannel"); 23 | statusMonitorChannel = (PublishSubscribeChannel) DashboardManager.getDashboardContext().getBean("statusMonitorChannel"); 24 | statusMonitorChannel.subscribe(new ServiceMessageHandler()); 25 | } 26 | 27 | public static class ServiceMessageFilter extends AppStatusMessageFilter { 28 | protected boolean filterMessage(AppSupportStatus status) { 29 | return status.isUpdateRequired() || status.isDeviceOut(); 30 | } 31 | } 32 | 33 | private class ServiceMessageHandler extends AppStatusMessageHandler { 34 | protected void receive(AppSupportStatus status) { 35 | setCurrentSupportStatus(status); 36 | } 37 | } 38 | 39 | private void setCurrentSupportStatus(AppSupportStatus status) { 40 | this.currentLocalStatus = status; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/META-INF/spring/integration/http-api.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 35 | 36 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/META-INF/spring/integration/jdbc.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/META-INF/spring/integration/status-monitor.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 29 | 30 | 31 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/META-INF/spring/integration/twitter.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 19 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /dashboard/src/main/java/com/lil/springintegration/domain/AppSupportStatus.java: -------------------------------------------------------------------------------- 1 | package com.lil.springintegration.domain; 2 | 3 | import org.springframework.util.LinkedCaseInsensitiveMap; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Date; 7 | 8 | public class AppSupportStatus { 9 | 10 | private String runningVersion; 11 | private Date snapTime = new Date(); 12 | private boolean updateRequired = false; 13 | private int netSolar = 0; 14 | private int netWind = 0; 15 | private ArrayList> deviceOut = new ArrayList<>(); 16 | 17 | public String getRunningVersion() { 18 | return runningVersion; 19 | } 20 | public void setRunningVersion(String version) { this.runningVersion = version; } 21 | 22 | public Date getTime() { 23 | return snapTime; 24 | } 25 | public void setTime(Date dttm) { this.snapTime = dttm; } 26 | 27 | public boolean isUpdateRequired() { return updateRequired; } 28 | public void setIsUpdateRequired(boolean update) { this.updateRequired = update; } 29 | 30 | public int getNetSolar() { return netSolar; } 31 | public void setNetSolar(int solar) { this.netSolar = solar; } 32 | 33 | public int getNetWind() { return netWind; } 34 | public void setNetWind(int wind) { this.netWind = wind; } 35 | 36 | public ArrayList> getDeviceOut() { return this.deviceOut; } 37 | public void setDeviceOut(ArrayList> out) { this.deviceOut = out; } 38 | 39 | public double getAccountCreditEarned() { 40 | return (netSolar + netWind) * .0001; 41 | } 42 | 43 | public boolean isDeviceOut() { return deviceOut.iterator().hasNext(); } 44 | 45 | public String getCustomerSoftwareNotification() { 46 | if (updateRequired) { 47 | return "A software update is required."; 48 | } 49 | return "(none)"; 50 | } 51 | 52 | public String getCustomerDeviceNotification() { 53 | if (!deviceOut.isEmpty()) { 54 | return "Your power grid has one or more devices offline."; 55 | } 56 | return null; 57 | } 58 | 59 | public String toString() { return runningVersion + "@" + snapTime.toString() + (updateRequired ? "|update" : "|current") + "|" + netSolar + "|" + netWind + "|" + deviceOut.toString(); } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/META-INF/spring/application.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | ${software.build} 22 | ${server.port} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/templates/dashboard.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | kinetECO Consumer Power Grid (Spring Integration Learning Application) 5 | 6 | 7 | 8 | 9 |
10 | 11 |
12 | Consumer Power Grid Dashboard 13 | featuring Spring Integration! 14 |
15 |
16 |
17 | 18 |
19 |
20 |
21 |

Grid Status

22 |

Your device status.

23 |
24 |

25 |
26 |
27 |

kinetECO News

28 |

kinetECO on Twitter.

29 |
30 |

31 |
32 |
33 |
34 |
35 |

Power Usage

36 |

Your net community grid contribution.

37 |
38 |

39 |
40 |
41 |

Tech Support

42 |

System support information.

43 |
44 |

45 |

46 |
47 |
48 |
49 |
50 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /dashboard/src/main/java/com/lil/springintegration/DashboardApplication.java: -------------------------------------------------------------------------------- 1 | package com.lil.springintegration; 2 | 3 | import com.lil.springintegration.manage.DashboardManager; 4 | import com.lil.springintegration.domain.AppProperties; 5 | import org.json.JSONException; 6 | import org.json.JSONObject; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.boot.SpringApplication; 10 | import org.springframework.boot.autoconfigure.SpringBootApplication; 11 | import org.springframework.context.support.AbstractApplicationContext; 12 | import org.springframework.context.support.ClassPathXmlApplicationContext; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.stereotype.Controller; 16 | import org.springframework.ui.Model; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.RequestMapping; 19 | 20 | import java.util.Date; 21 | import java.util.Random; 22 | 23 | @SpringBootApplication 24 | @Controller 25 | public class DashboardApplication { 26 | 27 | private static DashboardManager dashboardManager; 28 | 29 | private static Logger logger = LoggerFactory.getLogger(DashboardApplication.class); 30 | 31 | public static void main(String[] args) { 32 | AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/application.xml", DashboardApplication.class); 33 | AppProperties props = (AppProperties) context.getBean("appProperties"); 34 | dashboardManager = new DashboardManager(); 35 | SpringApplication.run(DashboardApplication.class, args); 36 | logger.info("Open this application in your browser at http://localhost:" + props.getRuntimeProperties().getProperty("server.port", "") + ". (Modify port number in src/main/resources/application.properties)"); 37 | dashboardManager.initCallback(); 38 | context.close(); 39 | } 40 | 41 | @GetMapping("/") 42 | public String dashboard(Model model) { 43 | model.addAttribute("status", DashboardManager.getDashboardStatus()); 44 | return "dashboard"; 45 | } 46 | 47 | @RequestMapping(value = "/api") 48 | public ResponseEntity getProducts() { 49 | String payload = simulateRestApiResponse(); 50 | return new ResponseEntity<>(payload, HttpStatus.OK); 51 | } 52 | 53 | private static String simulateRestApiResponse() { 54 | Random random = new Random(); 55 | JSONObject json = new JSONObject(); 56 | try { 57 | json.put("snapTime", new Date().toString()); 58 | json.put("updateRequired", random.nextBoolean()); 59 | json.put("netSolar", random.nextInt(40)); 60 | json.put("netWind", random.nextInt(40)); 61 | } catch (JSONException e) { 62 | logger.info(e.toString()); 63 | } 64 | return json.toString(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /dashboard/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.3.3.RELEASE 9 | 10 | 11 | com.lil.springintegration 12 | dashboard 13 | 0.0.1-SNAPSHOT 14 | dashboard 15 | Learning project for Spring Integration 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-data-jpa 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-integration 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-thymeleaf 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | org.junit.vintage 45 | junit-vintage-engine 46 | 47 | 48 | 49 | 50 | org.springframework.integration 51 | spring-integration-http 52 | 5.4.0 53 | 54 | 55 | org.springframework.integration 56 | spring-integration-social-twitter 57 | 1.0.0.RELEASE 58 | 59 | 60 | org.springframework.integration 61 | spring-integration-jdbc 62 | 5.4.0 63 | 64 | 65 | org.springframework.integration 66 | spring-integration-test 67 | test 68 | 69 | 70 | com.h2database 71 | h2 72 | runtime 73 | 74 | 75 | com.fasterxml.jackson.module 76 | jackson-module-kotlin 77 | 2.11.3 78 | 79 | 80 | com.vaadin.external.google 81 | android-json 82 | 0.0.20131108.vaadin1 83 | compile 84 | 85 | 86 | 87 | 88 | 89 | 90 | org.springframework.boot 91 | spring-boot-maven-plugin 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /dashboard/src/main/java/com/lil/springintegration/service/ViewService.java: -------------------------------------------------------------------------------- 1 | package com.lil.springintegration.service; 2 | 3 | import com.lil.springintegration.endpoint.AppStatusMessageHandler; 4 | import com.lil.springintegration.manage.DashboardManager; 5 | import com.lil.springintegration.domain.AppSupportStatus; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.integration.channel.*; 9 | import org.springframework.messaging.support.GenericMessage; 10 | import org.springframework.social.twitter.api.Tweet; 11 | 12 | import java.text.NumberFormat; 13 | import java.util.Locale; 14 | import java.util.Timer; 15 | import java.util.TimerTask; 16 | 17 | public class ViewService { 18 | 19 | static Logger logger = LoggerFactory.getLogger(DashboardManager.class); 20 | private Timer timer = new Timer(); 21 | 22 | // TODO - refactor to use Spring Dependency Injection 23 | private AbstractSubscribableChannel statusMonitorChannel; 24 | private QueueChannel updateNotificationChannel; 25 | 26 | public ViewService() { 27 | updateNotificationChannel = (QueueChannel) DashboardManager.getDashboardContext().getBean("updateNotificationQueueChannel"); 28 | statusMonitorChannel = (PublishSubscribeChannel) DashboardManager.getDashboardContext().getBean("statusMonitorChannel"); 29 | statusMonitorChannel.subscribe(new ViewMessageHandler()); 30 | this.start(); 31 | } 32 | 33 | private void start() { 34 | /* Represents long-running process thread */ 35 | timer.schedule(new TimerTask() { 36 | public void run() { 37 | // Would typically be dependent on some external service resource where throttling was a factor, like email 38 | checkForNotifications(); 39 | } 40 | }, 3000, 3000); 41 | } 42 | 43 | private void checkForNotifications() { 44 | /* Check queue for notifications */ 45 | GenericMessage message = (GenericMessage) updateNotificationChannel.receive(1000); 46 | if (message != null) { 47 | if (message.getPayload() instanceof AppSupportStatus ) { 48 | AppSupportStatus payload = (AppSupportStatus) message.getPayload(); 49 | DashboardManager.setDashboardStatus("softwareNotification", payload.getCustomerSoftwareNotification()); 50 | DashboardManager.setDashboardStatus("deviceNotification", payload.getCustomerDeviceNotification()); 51 | } else if (message.getPayload() instanceof Tweet) { 52 | Tweet payload = (Tweet) message.getPayload(); 53 | DashboardManager.setDashboardStatus("latestTweets", payload.getText()); 54 | } 55 | } 56 | } 57 | 58 | private static class ViewMessageHandler extends AppStatusMessageHandler { 59 | protected void receive(AppSupportStatus status) { 60 | if (status.getRunningVersion() != null) { 61 | DashboardManager.setDashboardStatus("softwareBuild", status.getRunningVersion()); 62 | } 63 | DashboardManager.setDashboardStatus("solarUsage", String.valueOf(status.getNetSolar())); 64 | DashboardManager.setDashboardStatus("windUsage", String.valueOf(status.getNetWind())); 65 | DashboardManager.setDashboardStatus("creditsToDate", NumberFormat.getCurrencyInstance(Locale.UK).format(CustomerAccountService.getAccountCredit())); 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring: Spring Integration 2 | This is the repository for the LinkedIn Learning course Spring: Spring Integration. The full course is available from [LinkedIn Learning][lil-course-url]. 3 | 4 | ![Spring: Spring Integration][lil-thumbnail-url] 5 | In this course, instructor Kathy Flint shows how Spring Integration fits into the overall Spring framework. Kathy covers realistic use cases that warrant the use of Spring Integration, such as APIs, reactive websites, and database-integrated systems. Kathy demonstrates the full capabilities of Spring Integration by building a demonstration application; she starts with an empty Spring Boot application and adds Spring Integration components in increasing complexity, ending with a substantive demonstration application. She covers key features like message channels, message transformation, routing, and aggregation. Kathy finishes the course by identifying practical challenges and choices that an architect or engineer may encounter during the design and implementation of a Spring Integration system. 6 | 7 | ## Instructions 8 | This repository has branches for each of the code lesson videos in the course. You can use the branch pop up menu in github to switch to a specific branch and take a look at the course at that stage, or you can add `/tree/BRANCH_NAME` to the URL to go to the branch you want to access. 9 | 10 | ## Branches 11 | The branches are structured to correspond to the videos in the course. The naming convention is `CHAPTER#_MOVIE#`. As an example, the branch named `02_03` corresponds to the second chapter and the third video in that chapter. 12 | 13 | Some branches will have a beginning and end state. These are marked with the letters `b` for "beginning" and `e` for "end". The `b` branch contains the code as it is at the beginning of the movie. The `e` branch contains the code as it is at the end of the movie. 14 | 15 | The `main` branch holds the final state of the code when the course is complete. 16 | 17 | When switching from one exercise files branch to the next after making changes to the files, you may get a message like this: 18 | 19 | error: Your local changes to the following files would be overwritten by checkout: [files] 20 | Please commit your changes or stash them before you switch branches. 21 | Aborting 22 | 23 | To resolve this issue: 24 | 25 | Add changes to git using this command: git add . 26 | Commit changes using this command: git commit -m "some message" 27 | 28 | ## Installing 29 | 1. To use these exercise files, you must have the following installed: 30 | - Java 8 or higher 31 | - Maven 32 | 2. Clone this repository into your local machine using the terminal (Mac), CMD (Windows), or a GUI tool like SourceTree. 33 | 34 | ## Run and Edit 35 | 36 | ### Intellij IDEA 37 | 38 | 1. From IDEA Welcome screen, select **Open or Import** 39 | 2. Choose the root directory of your newly cloned repository: `spring-spring-integration-28748253` 40 | 3. Within IntelliJ, make sure your Project SDK is set to Java 1.8 or higher. (File > Project Structure) 41 | 3. From the Project View, context-click on the file `dashboard/pom.xml` 42 | 4. Select **+ Add as Maven project**. This will cause project dependencies to download from the internet. Minimize the resulting Maven view pane if you wish. 43 | 5. Context-click on the file `dashboard/src/main/java/com.lil.springintegration.DashboardApplication.java` 44 | 6. Select **Run** 45 | 7. Open the application in your browser at `http://localhost:9090` 46 | 47 | ### Run from Command Line 48 | 49 | 1. In your terminal, navigate to directory `spring-spring-integration-28748253/dashboard` 50 | 2. Execute `mvn clean package` 51 | 3. Execute `mvn spring-boot:run` 52 | 4. Open the app in your browser at `http://localhost:9090` 53 | 54 | 55 | ### Instructor 56 | 57 | **Kathy D. Flint** 58 | 59 | _Software Engineer and Application Architect_ 60 | 61 | Check out my other courses on [LinkedIn Learning](https://www.linkedin.com/learning/instructors/kathy-flint?u=104). 62 | 63 | [lil-course-url]: https://www.linkedin.com/learning/spring-spring-integration 64 | [lil-thumbnail-url]: https://cdn.lynda.com/course/2848253/2848253-1611257542249-16x9.jpg 65 | 66 | -------------------------------------------------------------------------------- /dashboard/src/main/java/com/lil/springintegration/manage/DashboardManager.java: -------------------------------------------------------------------------------- 1 | package com.lil.springintegration.manage; 2 | 3 | import com.lil.springintegration.service.StatusMonitorService; 4 | import com.lil.springintegration.service.ViewService; 5 | import com.lil.springintegration.domain.AppProperties; 6 | import com.lil.springintegration.domain.AppSupportStatus; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.context.support.AbstractApplicationContext; 10 | import org.springframework.context.support.ClassPathXmlApplicationContext; 11 | import org.springframework.integration.channel.AbstractSubscribableChannel; 12 | import org.springframework.integration.channel.PublishSubscribeChannel; 13 | import org.springframework.integration.endpoint.SourcePollingChannelAdapter; 14 | import org.springframework.messaging.support.GenericMessage; 15 | import org.springframework.messaging.support.MessageBuilder; 16 | 17 | import java.util.Date; 18 | import java.util.Properties; 19 | 20 | public class DashboardManager { 21 | 22 | static Properties dashboardStatusDao = new Properties(); 23 | static Logger logger = LoggerFactory.getLogger(DashboardManager.class); 24 | private static AbstractApplicationContext context; 25 | 26 | // TODO - refactor to use Spring Dependency Injection 27 | private static ViewService viewService; 28 | private static StatusMonitorService statusMonitorService; 29 | private static SourcePollingChannelAdapter dataPoller, twitterPoller, apiPoller; 30 | 31 | public DashboardManager() { 32 | DashboardManager.context = new ClassPathXmlApplicationContext("/META-INF/spring/application.xml", DashboardManager.class); 33 | dataPoller = (SourcePollingChannelAdapter) DashboardManager.getDashboardContext().getBean("gridStatusPoller"); 34 | apiPoller = (SourcePollingChannelAdapter) DashboardManager.getDashboardContext().getBean("apiPoller"); 35 | if (DashboardManager.getDashboardContext().containsBean("twitterPoller")) { 36 | twitterPoller = (SourcePollingChannelAdapter) DashboardManager.getDashboardContext().getBean("twitterPoller"); 37 | } 38 | initializeServices(); 39 | initializeView(); 40 | } 41 | 42 | public static ClassPathXmlApplicationContext getDashboardContext() { return (ClassPathXmlApplicationContext) DashboardManager.context; } 43 | 44 | public static void setDashboardStatus(String key, String value) { 45 | String v = (value != null ? value : ""); 46 | DashboardManager.dashboardStatusDao.setProperty(key, v); 47 | } 48 | 49 | public static Properties getDashboardStatus() { 50 | return DashboardManager.dashboardStatusDao; 51 | } 52 | 53 | private void initializeServices() { 54 | viewService = new ViewService(); 55 | statusMonitorService = new StatusMonitorService(); 56 | dataPoller.start(); 57 | if (twitterPoller != null) { 58 | twitterPoller.start(); 59 | } 60 | } 61 | 62 | public void initCallback() { 63 | apiPoller.start(); 64 | } 65 | 66 | private void initializeView() { 67 | DashboardManager.setDashboardStatus("softwareBuild", "..."); 68 | DashboardManager.setDashboardStatus("softwareNotification", "(none)"); 69 | DashboardManager.setDashboardStatus("solarUsage", "..."); 70 | DashboardManager.setDashboardStatus("windUsage", "..."); 71 | DashboardManager.setDashboardStatus("creditsToDate", "..."); 72 | DashboardManager.setDashboardStatus("devicesNotification", ""); 73 | if (twitterPoller != null) { 74 | DashboardManager.setDashboardStatus("latestTweets", ""); 75 | } else { 76 | DashboardManager.setDashboardStatus("latestTweets", "README: To activate live Twitter feed, see instructions at application.xml, line 41."); 77 | } 78 | 79 | AppProperties props = (AppProperties) DashboardManager.getDashboardContext().getBean("appProperties"); 80 | String v = props.getRuntimeProperties().getProperty("software.build", "unknown"); 81 | Date d = new Date(); 82 | 83 | // Make a status domain object 84 | AppSupportStatus status = new AppSupportStatus(); 85 | status.setRunningVersion(v); 86 | status.setTime(d); 87 | 88 | // Use MessageBuilder utility class to construct a Message with our domain object as payload 89 | GenericMessage message = (GenericMessage) MessageBuilder 90 | .withPayload(status) 91 | .build(); 92 | 93 | // Now, to send our message, we need a channel! (We also need subscribers before this send will be successful.) 94 | AbstractSubscribableChannel statusMonitorChannel = (PublishSubscribeChannel) DashboardManager.getDashboardContext().getBean("statusMonitorChannel"); 95 | statusMonitorChannel.send(message); 96 | } 97 | 98 | } 99 | 100 | 101 | -------------------------------------------------------------------------------- /dashboard/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.net.*; 17 | import java.io.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.6"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 26 | */ 27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 29 | 30 | /** 31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 32 | * use instead of the default one. 33 | */ 34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 35 | ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = 41 | ".mvn/wrapper/maven-wrapper.jar"; 42 | 43 | /** 44 | * Name of the property which should be used to override the default download url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 54 | // wrapperUrl parameter. 55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 56 | String url = DEFAULT_DOWNLOAD_URL; 57 | if(mavenWrapperPropertyFile.exists()) { 58 | FileInputStream mavenWrapperPropertyFileInputStream = null; 59 | try { 60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 61 | Properties mavenWrapperProperties = new Properties(); 62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 64 | } catch (IOException e) { 65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 66 | } finally { 67 | try { 68 | if(mavenWrapperPropertyFileInputStream != null) { 69 | mavenWrapperPropertyFileInputStream.close(); 70 | } 71 | } catch (IOException e) { 72 | // Ignore ... 73 | } 74 | } 75 | } 76 | System.out.println("- Downloading from: " + url); 77 | 78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 79 | if(!outputFile.getParentFile().exists()) { 80 | if(!outputFile.getParentFile().mkdirs()) { 81 | System.out.println( 82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 83 | } 84 | } 85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 86 | try { 87 | downloadFileFromURL(url, outputFile); 88 | System.out.println("Done"); 89 | System.exit(0); 90 | } catch (Throwable e) { 91 | System.out.println("- Error downloading"); 92 | e.printStackTrace(); 93 | System.exit(1); 94 | } 95 | } 96 | 97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 99 | String username = System.getenv("MVNW_USERNAME"); 100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 101 | Authenticator.setDefault(new Authenticator() { 102 | @Override 103 | protected PasswordAuthentication getPasswordAuthentication() { 104 | return new PasswordAuthentication(username, password); 105 | } 106 | }); 107 | } 108 | URL website = new URL(urlString); 109 | ReadableByteChannel rbc; 110 | rbc = Channels.newChannel(website.openStream()); 111 | FileOutputStream fos = new FileOutputStream(destination); 112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 113 | fos.close(); 114 | rbc.close(); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | LinkedIn Learning Exercise Files License Agreement 2 | ================================================== 3 | 4 | This License Agreement (the "Agreement") is a binding legal agreement 5 | between you (as an individual or entity, as applicable) and LinkedIn 6 | Corporation (“LinkedIn”). By downloading or using the LinkedIn Learning 7 | exercise files in this repository (“Licensed Materials”), you agree to 8 | be bound by the terms of this Agreement. If you do not agree to these 9 | terms, do not download or use the Licensed Materials. 10 | 11 | 1. License. 12 | - a. Subject to the terms of this Agreement, LinkedIn hereby grants LinkedIn 13 | members during their LinkedIn Learning subscription a non-exclusive, 14 | non-transferable copyright license, for internal use only, to 1) make a 15 | reasonable number of copies of the Licensed Materials, and 2) make 16 | derivative works of the Licensed Materials for the sole purpose of 17 | practicing skills taught in LinkedIn Learning courses. 18 | - b. Distribution. Unless otherwise noted in the Licensed Materials, subject 19 | to the terms of this Agreement, LinkedIn hereby grants LinkedIn members 20 | with a LinkedIn Learning subscription a non-exclusive, non-transferable 21 | copyright license to distribute the Licensed Materials, except the 22 | Licensed Materials may not be included in any product or service (or 23 | otherwise used) to instruct or educate others. 24 | 25 | 2. Restrictions and Intellectual Property. 26 | - a. You may not to use, modify, copy, make derivative works of, publish, 27 | distribute, rent, lease, sell, sublicense, assign or otherwise transfer the 28 | Licensed Materials, except as expressly set forth above in Section 1. 29 | - b. Linkedin (and its licensors) retains its intellectual property rights 30 | in the Licensed Materials. Except as expressly set forth in Section 1, 31 | LinkedIn grants no licenses. 32 | - c. You indemnify LinkedIn and its licensors and affiliates for i) any 33 | alleged infringement or misappropriation of any intellectual property rights 34 | of any third party based on modifications you make to the Licensed Materials, 35 | ii) any claims arising from your use or distribution of all or part of the 36 | Licensed Materials and iii) a breach of this Agreement. You will defend, hold 37 | harmless, and indemnify LinkedIn and its affiliates (and our and their 38 | respective employees, shareholders, and directors) from any claim or action 39 | brought by a third party, including all damages, liabilities, costs and 40 | expenses, including reasonable attorneys’ fees, to the extent resulting from, 41 | alleged to have resulted from, or in connection with: (a) your breach of your 42 | obligations herein; or (b) your use or distribution of any Licensed Materials. 43 | 44 | 3. Open source. This code may include open source software, which may be 45 | subject to other license terms as provided in the files. 46 | 47 | 4. Warranty Disclaimer. LINKEDIN PROVIDES THE LICENSED MATERIALS ON AN “AS IS” 48 | AND “AS AVAILABLE” BASIS. LINKEDIN MAKES NO REPRESENTATION OR WARRANTY, 49 | WHETHER EXPRESS OR IMPLIED, ABOUT THE LICENSED MATERIALS, INCLUDING ANY 50 | REPRESENTATION THAT THE LICENSED MATERIALS WILL BE FREE OF ERRORS, BUGS OR 51 | INTERRUPTIONS, OR THAT THE LICENSED MATERIALS ARE ACCURATE, COMPLETE OR 52 | OTHERWISE VALID. TO THE FULLEST EXTENT PERMITTED BY LAW, LINKEDIN AND ITS 53 | AFFILIATES DISCLAIM ANY IMPLIED OR STATUTORY WARRANTY OR CONDITION, INCLUDING 54 | ANY IMPLIED WARRANTY OR CONDITION OF MERCHANTABILITY OR FITNESS FOR A 55 | PARTICULAR PURPOSE, AVAILABILITY, SECURITY, TITLE AND/OR NON-INFRINGEMENT. 56 | YOUR USE OF THE LICENSED MATERIALS IS AT YOUR OWN DISCRETION AND RISK, AND 57 | YOU WILL BE SOLELY RESPONSIBLE FOR ANY DAMAGE THAT RESULTS FROM USE OF THE 58 | LICENSED MATERIALS TO YOUR COMPUTER SYSTEM OR LOSS OF DATA. NO ADVICE OR 59 | INFORMATION, WHETHER ORAL OR WRITTEN, OBTAINED BY YOU FROM US OR THROUGH OR 60 | FROM THE LICENSED MATERIALS WILL CREATE ANY WARRANTY OR CONDITION NOT 61 | EXPRESSLY STATED IN THESE TERMS. 62 | 63 | 5. Limitation of Liability. LINKEDIN SHALL NOT BE LIABLE FOR ANY INDIRECT, 64 | INCIDENTAL, SPECIAL, PUNITIVE, CONSEQUENTIAL OR EXEMPLARY DAMAGES, INCLUDING 65 | BUT NOT LIMITED TO, DAMAGES FOR LOSS OF PROFITS, GOODWILL, USE, DATA OR OTHER 66 | INTANGIBLE LOSSES . IN NO EVENT WILL LINKEDIN'S AGGREGATE LIABILITY TO YOU 67 | EXCEED $100. THIS LIMITATION OF LIABILITY SHALL: 68 | - i. APPLY REGARDLESS OF WHETHER (A) YOU BASE YOUR CLAIM ON CONTRACT, TORT, 69 | STATUTE, OR ANY OTHER LEGAL THEORY, (B) WE KNEW OR SHOULD HAVE KNOWN ABOUT 70 | THE POSSIBILITY OF SUCH DAMAGES, OR (C) THE LIMITED REMEDIES PROVIDED IN THIS 71 | SECTION FAIL OF THEIR ESSENTIAL PURPOSE; AND 72 | - ii. NOT APPLY TO ANY DAMAGE THAT LINKEDIN MAY CAUSE YOU INTENTIONALLY OR 73 | KNOWINGLY IN VIOLATION OF THESE TERMS OR APPLICABLE LAW, OR AS OTHERWISE 74 | MANDATED BY APPLICABLE LAW THAT CANNOT BE DISCLAIMED IN THESE TERMS. 75 | 76 | 6. Termination. This Agreement automatically terminates upon your breach of 77 | this Agreement or termination of your LinkedIn Learning subscription. On 78 | termination, all licenses granted under this Agreement will terminate 79 | immediately and you will delete the Licensed Materials. Sections 2-7 of this 80 | Agreement survive any termination of this Agreement. LinkedIn may discontinue 81 | the availability of some or all of the Licensed Materials at any time for any 82 | reason. 83 | 84 | 7. Miscellaneous. This Agreement will be governed by and construed in 85 | accordance with the laws of the State of California without regard to conflict 86 | of laws principles. The exclusive forum for any disputes arising out of or 87 | relating to this Agreement shall be an appropriate federal or state court 88 | sitting in the County of Santa Clara, State of California. If LinkedIn does 89 | not act to enforce a breach of this Agreement, that does not mean that 90 | LinkedIn has waived its right to enforce this Agreement. The Agreement does 91 | not create a partnership, agency relationship, or joint venture between the 92 | parties. Neither party has the power or authority to bind the other or to 93 | create any obligation or responsibility on behalf of the other. You may not, 94 | without LinkedIn’s prior written consent, assign or delegate any rights or 95 | obligations under these terms, including in connection with a change of 96 | control. Any purported assignment and delegation shall be ineffective. The 97 | Agreement shall bind and inure to the benefit of the parties, their respective 98 | successors and permitted assigns. If any provision of the Agreement is 99 | unenforceable, that provision will be modified to render it enforceable to the 100 | extent possible to give effect to the parties’ intentions and the remaining 101 | provisions will not be affected. This Agreement is the only agreement between 102 | you and LinkedIn regarding the Licensed Materials, and supersedes all prior 103 | agreements relating to the Licensed Materials. 104 | 105 | Last Updated: March 2019 106 | -------------------------------------------------------------------------------- /dashboard/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 "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\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/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "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%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.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% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /dashboard/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 /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | --------------------------------------------------------------------------------