├── samples ├── jvm │ ├── gcp │ │ ├── src │ │ │ ├── main │ │ │ │ ├── resources │ │ │ │ │ ├── application.properties │ │ │ │ │ └── logback-spring.xml │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── gcp │ │ │ │ │ ├── GcpApplication.java │ │ │ │ │ └── HelloController.java │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── gcp │ │ │ │ └── GcpApplicationTests.java │ │ ├── settings.gradle │ │ ├── scripts │ │ │ ├── probe.sh │ │ │ ├── node-remote-upload-restart.sh │ │ │ ├── node-remote-setup.sh │ │ │ └── node-local-setup.sh │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── spring.service │ │ ├── .gitignore │ │ ├── example.com.conf │ │ ├── build.gradle │ │ ├── gradlew.bat │ │ └── gradlew │ ├── cors │ │ ├── settings.gradle │ │ ├── src │ │ │ ├── main │ │ │ │ ├── resources │ │ │ │ │ └── application.properties │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── cors │ │ │ │ │ ├── ExampleController.java │ │ │ │ │ ├── DebugFilter.java │ │ │ │ │ └── CorsApplication.java │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── cors │ │ │ │ └── CorsApplicationTests.java │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── gradlew.bat │ │ └── gradlew │ ├── daw-spring-1 │ │ ├── settings.gradle │ │ ├── src │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── pt │ │ │ │ └── isel │ │ │ │ └── daw │ │ │ │ └── samples │ │ │ │ ├── Student.java │ │ │ │ ├── CommandRequest.java │ │ │ │ ├── CommandResult.java │ │ │ │ ├── StudentsRepo.java │ │ │ │ ├── CourseRepo.java │ │ │ │ ├── EmailSender.java │ │ │ │ ├── Command.java │ │ │ │ ├── SomeEmailSender.java │ │ │ │ ├── App.java │ │ │ │ ├── Shutdown.java │ │ │ │ ├── SomeCloseableThing.java │ │ │ │ ├── RequestCustomScopeConfigurer.java │ │ │ │ ├── commands │ │ │ │ ├── SomeCommand.java │ │ │ │ ├── GetStudentByNumber.java │ │ │ │ ├── CreateStudent.java │ │ │ │ ├── ShutdownCommand.java │ │ │ │ └── GetStudents.java │ │ │ │ ├── CourseRepoImpl.java │ │ │ │ ├── StudentsRepoImpl.java │ │ │ │ ├── Router.java │ │ │ │ ├── Config.java │ │ │ │ ├── Server.java │ │ │ │ └── RequestScope.java │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── build.gradle │ │ └── gradlew.bat │ ├── sample-spring-0 │ │ ├── settings.gradle │ │ ├── src │ │ │ ├── main │ │ │ │ └── java │ │ │ │ │ └── pt │ │ │ │ │ └── isel │ │ │ │ │ └── daw │ │ │ │ │ └── samples │ │ │ │ │ └── spring │ │ │ │ │ └── context │ │ │ │ │ ├── Service1.java │ │ │ │ │ ├── Service2.java │ │ │ │ │ ├── Service3.java │ │ │ │ │ ├── SomeService1.java │ │ │ │ │ ├── SomeService2.java │ │ │ │ │ ├── MyConfig.java │ │ │ │ │ ├── scanning │ │ │ │ │ └── SomeService3.java │ │ │ │ │ └── JavaBasedConfigurationExample.java │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── pt │ │ │ │ └── isel │ │ │ │ └── daw │ │ │ │ └── samples │ │ │ │ └── spring │ │ │ │ └── context │ │ │ │ └── ContextTests.java │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── build.gradle │ │ └── gradlew.bat │ └── sample-spring-boot-0 │ │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── pt │ │ │ │ └── isel │ │ │ │ └── daw │ │ │ │ └── samplespringboot0 │ │ │ │ ├── ClientIp.java │ │ │ │ ├── QueryString.java │ │ │ │ ├── RequiresAuthentication.java │ │ │ │ ├── ResourceController.java │ │ │ │ ├── MyExceptionResolver.java │ │ │ │ ├── MyExceptionHandlerAdvice.java │ │ │ │ ├── QueryStringArgumentResolver.java │ │ │ │ ├── ClientIpArgumentResolver.java │ │ │ │ ├── ExampleFilter.java │ │ │ │ ├── ICalMessageConverter.java │ │ │ │ ├── ExampleInterceptor.java │ │ │ │ ├── SampleSpringBoot0Application.java │ │ │ │ └── MvcConfig.java │ │ └── test │ │ │ └── java │ │ │ └── pt │ │ │ └── isel │ │ │ └── daw │ │ │ └── samplespringboot0 │ │ │ └── SampleSpringBoot0ApplicationTests.java │ │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── http │ │ ├── post1.http │ │ └── req1.http │ │ ├── .gitignore │ │ ├── build.gradle │ │ └── gradlew.bat ├── js │ ├── building │ │ ├── js │ │ │ ├── arith.js │ │ │ └── index.js │ │ ├── index.html │ │ ├── webpack.config.js │ │ └── package.json │ ├── react │ │ ├── index.html │ │ ├── webpack.config.js │ │ ├── package.json │ │ ├── readme.md │ │ └── js │ │ │ └── index.js │ └── es.next │ │ ├── strings.test.js │ │ ├── package.json │ │ ├── async-await.test.js │ │ ├── destructuring.test.js │ │ ├── fetch.test.js │ │ ├── rest-spread.test.js │ │ ├── promises.test.js │ │ └── classes.test.js └── http-requests │ ├── graphql.query.viewer.http │ ├── graphql.query.repo.http │ ├── graphql.query.user.http │ ├── example2.graphql │ └── example1.graphql ├── demos ├── demos-spring-boot-0 │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── pt │ │ │ │ └── isel │ │ │ │ └── daw │ │ │ │ └── demosspringboot0 │ │ │ │ ├── Service1.java │ │ │ │ ├── SomeService1Impl.java │ │ │ │ ├── DemosSpringBoot0Application.java │ │ │ │ └── ResourceController.java │ │ └── test │ │ │ └── java │ │ │ └── pt │ │ │ └── isel │ │ │ └── daw │ │ │ └── demosspringboot0 │ │ │ └── DemosSpringBoot0ApplicationTests.java │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── .gitignore │ ├── build.gradle │ └── gradlew.bat ├── sample-spring-boot-pl-0 │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── pt │ │ │ │ └── isel │ │ │ │ └── daw │ │ │ │ └── samplespringbootpl0 │ │ │ │ ├── Service1.java │ │ │ │ ├── SomeService1Impl.java │ │ │ │ ├── SampleSpringBootPl0Application.java │ │ │ │ └── ExampleController.java │ │ └── test │ │ │ └── java │ │ │ └── pt │ │ │ └── isel │ │ │ └── daw │ │ │ └── samplespringbootpl0 │ │ │ └── SampleSpringBootPl0ApplicationTests.java │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── .gitignore │ ├── build.gradle │ └── gradlew.bat ├── examples-spring-context-0 │ ├── settings.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── pt │ │ │ └── isel │ │ │ └── daw │ │ │ └── examples │ │ │ ├── Service1.java │ │ │ ├── Service2.java │ │ │ ├── Settings.java │ │ │ ├── SomeService1Impl.java │ │ │ ├── MainClass.java │ │ │ ├── SomeService2Impl.java │ │ │ ├── MyConfig.java │ │ │ └── MyDataSource.java │ ├── build.gradle │ └── gradlew.bat ├── samples-spring-context-pl-0 │ ├── settings.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── pt │ │ │ └── isel │ │ │ └── daw │ │ │ └── samples │ │ │ ├── Service1.java │ │ │ ├── Service2.java │ │ │ ├── SomeService2Impl.java │ │ │ ├── App.java │ │ │ ├── SomeService1Impl.java │ │ │ ├── MainClass.java │ │ │ ├── MyConfig.java │ │ │ └── MyDataSource.java │ ├── build.gradle │ └── gradlew.bat └── js │ ├── react │ ├── js │ │ ├── ui │ │ │ ├── line.js │ │ │ ├── clock.js │ │ │ ├── nav.js │ │ │ ├── show-hide.js │ │ │ ├── clock2.js │ │ │ ├── app.js │ │ │ ├── counter.js │ │ │ ├── shooping-cart.js │ │ │ └── issue-list.js │ │ └── index.js │ ├── index.html │ ├── webpack.config.js │ └── package.json │ ├── react-pl │ ├── js │ │ ├── ui │ │ │ ├── line.js │ │ │ ├── paginator-panel.js │ │ │ ├── ShowHide.js │ │ │ ├── comp1.js │ │ │ ├── app.js │ │ │ ├── repo-select.js │ │ │ ├── counter.js │ │ │ ├── clock.js │ │ │ ├── comp2.js │ │ │ ├── issue-state-filter-panel.js │ │ │ ├── counter-example.js │ │ │ └── issue-list.js │ │ └── index.js │ ├── index.html │ ├── webpack.config.js │ └── package.json │ ├── es-next │ ├── package.json │ ├── async-await.test.js │ ├── destructuring.test.js │ ├── spread-rest.test.js │ ├── promises.test.js │ └── classes.test.js │ └── es-next-pl │ ├── package.json │ ├── classes.test.js │ ├── async-await.test.js │ ├── destructuring.test.js │ ├── rest-spread.test.js │ └── promises.test.js ├── imgs └── react-lifecycle-dan-abramov.jpg ├── .gitignore └── README.md /samples/jvm/gcp/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /samples/jvm/cors/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'cors' 2 | -------------------------------------------------------------------------------- /samples/jvm/gcp/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'gcp' 2 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'daw-spring-1' 2 | 3 | -------------------------------------------------------------------------------- /demos/demos-spring-boot-0/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 3 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'sample-spring-0' 2 | 3 | -------------------------------------------------------------------------------- /demos/sample-spring-boot-pl-0/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 3 | -------------------------------------------------------------------------------- /demos/examples-spring-context-0/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'examples-spring-context-0' 2 | 3 | -------------------------------------------------------------------------------- /samples/jvm/cors/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.mvc.dispatch-options-request=true 2 | -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'samples-spring-context-pl-0' 2 | 3 | -------------------------------------------------------------------------------- /imgs/react-lifecycle-dan-abramov.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isel-leic-daw/1718v-public/HEAD/imgs/react-lifecycle-dan-abramov.jpg -------------------------------------------------------------------------------- /samples/jvm/gcp/scripts/probe.sh: -------------------------------------------------------------------------------- 1 | for i in `seq 1 1000`; do 2 | curl -s http://35.230.153.60/hello 3 | printf "\n" 4 | done 5 | 6 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/Student.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | public class Student { 4 | } 5 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 3 | spring: 4 | resources: 5 | add-mappings: true 6 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/CommandRequest.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | public class CommandRequest { 4 | } 5 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/CommandResult.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | public class CommandResult { 4 | } 5 | -------------------------------------------------------------------------------- /samples/jvm/cors/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isel-leic-daw/1718v-public/HEAD/samples/jvm/cors/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/jvm/gcp/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isel-leic-daw/1718v-public/HEAD/samples/jvm/gcp/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isel-leic-daw/1718v-public/HEAD/samples/jvm/daw-spring-1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/demos-spring-boot-0/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isel-leic-daw/1718v-public/HEAD/demos/demos-spring-boot-0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/src/main/java/pt/isel/daw/samples/spring/context/Service1.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.spring.context; 2 | 3 | public interface Service1 { 4 | } 5 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/src/main/java/pt/isel/daw/samples/spring/context/Service2.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.spring.context; 2 | 3 | public interface Service2 { 4 | } 5 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/src/main/java/pt/isel/daw/samples/spring/context/Service3.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.spring.context; 2 | 3 | public interface Service3 { 4 | } 5 | -------------------------------------------------------------------------------- /demos/sample-spring-boot-pl-0/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isel-leic-daw/1718v-public/HEAD/demos/sample-spring-boot-pl-0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/StudentsRepo.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | public interface StudentsRepo { 4 | void doSomething(); 5 | } 6 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isel-leic-daw/1718v-public/HEAD/samples/jvm/sample-spring-0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/examples-spring-context-0/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isel-leic-daw/1718v-public/HEAD/demos/examples-spring-context-0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/CourseRepo.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | public interface CourseRepo { 4 | 5 | void doSomething(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isel-leic-daw/1718v-public/HEAD/demos/samples-spring-context-pl-0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/src/main/java/pt/isel/daw/samples/Service1.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | public interface Service1 { 4 | 5 | void doSomething(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isel-leic-daw/1718v-public/HEAD/samples/jvm/sample-spring-boot-0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/demos-spring-boot-0/src/main/java/pt/isel/daw/demosspringboot0/Service1.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.demosspringboot0; 2 | 3 | public interface Service1 { 4 | 5 | int add(int a, int b); 6 | } 7 | -------------------------------------------------------------------------------- /demos/examples-spring-context-0/src/main/java/pt/isel/daw/examples/Service1.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.examples; 2 | 3 | public interface Service1 { 4 | 5 | public void doSomething(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /demos/examples-spring-context-0/src/main/java/pt/isel/daw/examples/Service2.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.examples; 2 | 3 | public interface Service2 { 4 | 5 | public void doAnotherThing(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/src/main/java/pt/isel/daw/samples/Service2.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | public interface Service2 { 4 | 5 | public void doAnotherThing(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/http/post1.http: -------------------------------------------------------------------------------- 1 | POST http://localhost:8081/examples/8 2 | Content-Type: application/json 3 | Accept: application/xml 4 | 5 | { 6 | "i": 42, 7 | "s": "hello" 8 | } 9 | -------------------------------------------------------------------------------- /demos/sample-spring-boot-pl-0/src/main/java/pt/isel/daw/samplespringbootpl0/Service1.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringbootpl0; 2 | 3 | public interface Service1 { 4 | 5 | void doSomething(); 6 | } 7 | -------------------------------------------------------------------------------- /samples/js/building/js/arith.js: -------------------------------------------------------------------------------- 1 | export default function (a, b) { 2 | return a + b 3 | } 4 | 5 | export function sub (a, b) { 6 | return a - b 7 | } 8 | 9 | export const mult = (a, b) => a * b 10 | -------------------------------------------------------------------------------- /demos/js/react/js/ui/line.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default function ({count}) { 4 | return
5 | {[...Array(count).keys()].map(i => {`(${i})`})} 6 |
7 | } 8 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/EmailSender.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | public interface EmailSender { 4 | 5 | void send(String recipient, String subject, String body); 6 | } 7 | -------------------------------------------------------------------------------- /samples/js/building/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Build example 4 | 5 | 6 |

Build example

7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /samples/http-requests/graphql.query.viewer.http: -------------------------------------------------------------------------------- 1 | POST https://api.github.com/graphql HTTP/1.1 2 | Authorization: Bearer TO BE DEFINED 3 | Content-Type: application/json 4 | 5 | { 6 | "query":"query { viewer {name location login} }" 7 | } 8 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/ui/line.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default function ({seconds, reverse}) { 4 | const value = i => reverse ? 60 - i : i 5 | return [...new Array(seconds).keys()].map(i => {` (${value(i)}) `}) 6 | } 7 | -------------------------------------------------------------------------------- /samples/js/react/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Build example 4 | 5 | 6 |

React example

7 |
8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /demos/js/react-pl/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | React example 4 | 5 | 6 |

React example

7 |
8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /demos/js/react/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | React example 4 | 5 | 6 |

React example

7 |
8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /samples/http-requests/graphql.query.repo.http: -------------------------------------------------------------------------------- 1 | POST https://api.github.com/graphql HTTP/1.1 2 | Authorization: Bearer TO BE DEFINED 3 | Content-Type: application/json 4 | 5 | { 6 | "query":"query { repository(name:\"drum\", owner:\"pmhsfelix\") {name} }" 7 | } -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/Command.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | public interface Command { 4 | 5 | CommandResult execute(CommandRequest req); 6 | String getPathTemplate(); 7 | String getMethod(); 8 | } 9 | -------------------------------------------------------------------------------- /samples/jvm/gcp/scripts/node-remote-upload-restart.sh: -------------------------------------------------------------------------------- 1 | gcloud compute scp build/libs/gcp-0.0.1-SNAPSHOT.jar $1:~ 2 | gcloud compute ssh $1 --command 'sudo cp gcp-0.0.1-SNAPSHOT.jar /var/spring' 3 | gcloud compute ssh $1 --command 'sudo systemctl restart spring' 4 | -------------------------------------------------------------------------------- /samples/jvm/gcp/scripts/node-remote-setup.sh: -------------------------------------------------------------------------------- 1 | gcloud compute scp spring.service $1:~ 2 | gcloud compute scp build/libs/gcp-0.0.1-SNAPSHOT.jar $1:~ 3 | gcloud compute scp scripts/node-local-setup.sh $1:~ 4 | gcloud compute ssh $1 --command "sudo sh node-local-setup.sh" 5 | -------------------------------------------------------------------------------- /demos/sample-spring-boot-pl-0/src/main/java/pt/isel/daw/samplespringbootpl0/SomeService1Impl.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringbootpl0; 2 | 3 | public class SomeService1Impl implements Service1 { 4 | @Override 5 | public void doSomething() { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /samples/http-requests/graphql.query.user.http: -------------------------------------------------------------------------------- 1 | POST https://api.github.com/graphql HTTP/1.1 2 | Authorization: Bearer TO BE DEFINED 3 | Content-Type: application/json 4 | 5 | { 6 | "query":"query { user(login:\"mr-barata\") {name location} viewer {email name} }" 7 | } 8 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/http/req1.http: -------------------------------------------------------------------------------- 1 | GET http://feeds.feedburner.com/se-radio?format=xml HTTP/1.1 2 | Accept: application/rss+xml 3 | User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /samples/jvm/cors/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Feb 06 12:27:20 CET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip 7 | -------------------------------------------------------------------------------- /samples/jvm/gcp/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Feb 06 12:27:20 CET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip 7 | -------------------------------------------------------------------------------- /demos/demos-spring-boot-0/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Feb 06 12:27:20 CET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip 7 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Mar 03 23:22:02 WET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip 7 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Mar 03 15:12:46 WET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip 7 | -------------------------------------------------------------------------------- /demos/examples-spring-context-0/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Mar 05 14:55:22 WET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip 7 | -------------------------------------------------------------------------------- /demos/sample-spring-boot-pl-0/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Feb 06 12:27:20 CET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip 7 | -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Mar 05 20:47:23 WET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip 7 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Mar 04 21:57:08 WET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-all.zip 7 | -------------------------------------------------------------------------------- /demos/js/react/js/ui/clock.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Line from './line' 3 | 4 | export default function ({date}) { 5 | const seconds = date.getSeconds() 6 | return
7 |

Example 3

8 |

Some paragraph

9 |

{date.toLocaleString()}

10 | 11 |
12 | } 13 | -------------------------------------------------------------------------------- /samples/jvm/gcp/spring.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=The DAW HTTP API 3 | After=syslog.target 4 | 5 | [Service] 6 | User=spring 7 | Type=idle 8 | ExecStart=/usr/bin/java -jar /var/spring/gcp-0.0.1-SNAPSHOT.jar --server.port=8080 --spring.profiles.active=gcp 9 | SuccessExitStatus=143 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /samples/jvm/gcp/scripts/node-local-setup.sh: -------------------------------------------------------------------------------- 1 | sudo yum -y update 2 | sudo yum -y install java-1.8.0-openjdk 3 | sudo useradd spring 4 | sudo mkdir /var/spring 5 | sudo cp gcp-0.0.1-SNAPSHOT.jar /var/spring 6 | sudo chown spring:spring /var/spring 7 | sudo cp spring.service /etc/systemd/system 8 | sudo systemctl enable spring 9 | sudo systemctl start spring 10 | -------------------------------------------------------------------------------- /demos/demos-spring-boot-0/src/main/java/pt/isel/daw/demosspringboot0/SomeService1Impl.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.demosspringboot0; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class SomeService1Impl implements Service1{ 7 | 8 | @Override 9 | public int add(int a, int b) { 10 | return a + b; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/http-requests/example2.graphql: -------------------------------------------------------------------------------- 1 | mutation { 2 | mutation1: addComment(input:{ 3 | body:"Final comment 2", 4 | subjectId:"MDU6SXNzdWUzMDY4NTg4ODc="}) { 5 | clientMutationId 6 | } 7 | mutation2: addComment(input:{ 8 | body:"Final comment 3", 9 | subjectId:"MDU6SXNzdWUzMDY4NTg4ODc="}) { 10 | clientMutationId 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/ClientIp.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | public class ClientIp { 4 | 5 | private final String ip; 6 | 7 | public ClientIp(String ip) { 8 | 9 | this.ip = ip; 10 | } 11 | 12 | @Override 13 | public String toString() { 14 | return ip; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/QueryString.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | public class QueryString { 4 | 5 | private final String qs; 6 | 7 | public QueryString(String qs) { 8 | 9 | this.qs = qs; 10 | } 11 | 12 | @Override 13 | public String toString() { 14 | return qs; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /demos/demos-spring-boot-0/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ -------------------------------------------------------------------------------- /demos/js/react/js/ui/nav.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | // [{name, url}] 4 | export default ({repos, selected, onChange}) => { 5 | return ( 6 |
7 | 11 |
12 |
13 | ) 14 | } 15 | -------------------------------------------------------------------------------- /demos/sample-spring-boot-pl-0/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/SomeEmailSender.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class SomeEmailSender implements EmailSender { 7 | 8 | @Override 9 | public void send(String recipient, String subject, String body) { 10 | // pretend that we sending something 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/jvm/gcp/src/main/java/com/example/gcp/GcpApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.gcp; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class GcpApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(GcpApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/RequiresAuthentication.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | import org.springframework.stereotype.Indexed; 4 | 5 | import java.lang.annotation.*; 6 | 7 | @Target(ElementType.METHOD) 8 | @Retention(RetentionPolicy.RUNTIME) 9 | public @interface RequiresAuthentication { 10 | 11 | String value() default ""; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /samples/jvm/cors/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | /out/ 20 | 21 | ### NetBeans ### 22 | /nbproject/private/ 23 | /build/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ -------------------------------------------------------------------------------- /samples/jvm/gcp/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | /out/ 20 | 21 | ### NetBeans ### 22 | /nbproject/private/ 23 | /build/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | **/out 19 | **/bin 20 | 21 | ### NetBeans ### 22 | nbproject/private/ 23 | build/ 24 | nbbuild/ 25 | dist/ 26 | nbdist/ 27 | .nb-gradle/ 28 | 29 | node_modules 30 | 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 1718v-public 2 | Web Application Development - Spring 2018 3 | 4 | 5 | [Samples](https://github.com/isel-leic-daw/1718v-public/tree/master/samples) folder contains code samples, typically prepared before classes. 6 | 7 | [Demos](https://github.com/isel-leic-daw/1718v-public/tree/master/demos) folder contains demos done during the classes. 8 | 9 | 10 | See the [wiki](https://github.com/isel-leic-daw/1718v-public/wiki) for more information. 11 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/ResourceController.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | public class ResourceController { 8 | 9 | @GetMapping("hello") 10 | public String get() { 11 | return "hello world"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /samples/jvm/gcp/src/test/java/com/example/gcp/GcpApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.gcp; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class GcpApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/src/main/java/pt/isel/daw/samples/spring/context/SomeService1.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.spring.context; 2 | 3 | 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | public class SomeService1 implements Service1 { 8 | 9 | public static final Logger log = LoggerFactory.getLogger(SomeService1.class); 10 | 11 | public SomeService1() { 12 | log.info("ctor called on {}", this); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /samples/jvm/cors/src/test/java/com/example/cors/CorsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.cors; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CorsApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /samples/jvm/gcp/example.com.conf: -------------------------------------------------------------------------------- 1 | upstream nodes { 2 | server 10.154.0.8:8080 max_fails=20; 3 | server 10.154.0.12:8080 max_fails=20; 4 | } 5 | 6 | server { 7 | listen 80; 8 | listen [::]:80; 9 | server_name 35.230.154.115; 10 | 11 | location / { 12 | proxy_pass http://nodes/; 13 | proxy_next_upstream error timeout http_500; 14 | } 15 | 16 | location /static/ { 17 | root /var/www/; 18 | try_files $uri /static/index.html; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /demos/js/es-next/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "es-next", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "jest": "^22.4.3", 13 | "standard": "^11.0.1" 14 | }, 15 | "standard": { 16 | "env": [ 17 | "jest" 18 | ] 19 | }, 20 | "dependencies": { 21 | "isomorphic-fetch": "^2.2.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /demos/js/es-next-pl/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "es-next-pl", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "jest": "^22.4.3", 13 | "standard": "^11.0.1" 14 | }, 15 | "standard": { 16 | "env": [ 17 | "jest" 18 | ] 19 | }, 20 | "dependencies": { 21 | "isomorphic-fetch": "^2.2.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/src/main/java/pt/isel/daw/samples/spring/context/SomeService2.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.spring.context; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | public class SomeService2 implements Service2 { 7 | 8 | public static final Logger log = LoggerFactory.getLogger(SomeService2.class); 9 | 10 | public SomeService2(Service1 svc1) { 11 | log.info("ctor called on {}, with svc1={}", this, svc1); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/App.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 4 | 5 | public class App { 6 | 7 | public static void main(String[] args) throws InterruptedException { 8 | AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class); 9 | Server server = ctx.getBean(Server.class); 10 | server.start(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /demos/demos-spring-boot-0/src/test/java/pt/isel/daw/demosspringboot0/DemosSpringBoot0ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.demosspringboot0; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DemosSpringBoot0ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /demos/examples-spring-context-0/src/main/java/pt/isel/daw/examples/Settings.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.examples; 2 | 3 | public class Settings { 4 | 5 | private final String connString; 6 | 7 | public Settings(String connString) { 8 | 9 | this.connString = connString; 10 | } 11 | 12 | public String getConnString() { 13 | return connString; 14 | } 15 | 16 | public static Settings fromEnvironment() { 17 | return new Settings(System.getenv("CONN_STRING")); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /samples/js/es.next/strings.test.js: -------------------------------------------------------------------------------- 1 | test('simple literals', () => { 2 | const alice = {name: 'Alice', number: 12345} 3 | const s = `Student '${alice.name}' with number ${alice.number}` 4 | expect(s).toEqual('Student \'Alice\' with number 12345') 5 | }) 6 | 7 | test('tagged literals', () => { 8 | function f (parts, name, number) { 9 | expect(parts).toEqual(['Student \'', '\' with number ', '']) 10 | } 11 | const alice = {name: 'Alice', number: 12345} 12 | f`Student '${alice.name}' with number ${alice.number}` 13 | }) 14 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/test/java/pt/isel/daw/samplespringboot0/SampleSpringBoot0ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SampleSpringBoot0ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /demos/sample-spring-boot-pl-0/src/test/java/pt/isel/daw/samplespringbootpl0/SampleSpringBootPl0ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringbootpl0; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SampleSpringBootPl0ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/build.gradle: -------------------------------------------------------------------------------- 1 | group 'pt.isel.daw' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | sourceCompatibility = 1.8 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' 14 | compile group: 'org.springframework', name: 'spring-context', version: '5.0.4.RELEASE' 15 | runtime group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25' 16 | testCompile group: 'junit', name: 'junit', version: '4.12' 17 | } 18 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/Shutdown.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.util.concurrent.Semaphore; 6 | 7 | @Component 8 | public class Shutdown { 9 | 10 | private final Semaphore sem; 11 | 12 | public Shutdown() { 13 | this.sem = new Semaphore(0); 14 | } 15 | 16 | public void start() { 17 | sem.release(); 18 | } 19 | 20 | public void await() throws InterruptedException { 21 | sem.acquire(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /demos/js/react/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | 3 | module.exports = { 4 | entry: './js/index.js', 5 | output: { 6 | filename: 'bundle.js', 7 | path: path.resolve(__dirname, 'dist') 8 | }, 9 | module: { 10 | rules: [ 11 | { 12 | test: /\.js$/, 13 | exclude: /(node_modules)/, 14 | use: { 15 | loader: 'babel-loader', 16 | options: { 17 | presets: ['env', 'react'] 18 | } 19 | } 20 | } 21 | ] 22 | }, 23 | devServer: { 24 | port: 9000 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /samples/js/building/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | 3 | module.exports = { 4 | entry: './js/index.js', 5 | output: { 6 | filename: 'bundle.js', 7 | path: path.resolve(__dirname, 'dist') 8 | }, 9 | module: { 10 | rules: [ 11 | { 12 | test: /\.js$/, 13 | exclude: /(node_modules)/, 14 | use: { 15 | loader: 'babel-loader', 16 | options: { 17 | presets: ['env'] 18 | } 19 | } 20 | } 21 | ] 22 | }, 23 | devServer: { 24 | port: 9000 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /demos/js/react-pl/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | 3 | module.exports = { 4 | entry: './js/index.js', 5 | output: { 6 | filename: 'bundle.js', 7 | path: path.resolve(__dirname, 'dist') 8 | }, 9 | module: { 10 | rules: [ 11 | { 12 | test: /\.js$/, 13 | exclude: /(node_modules)/, 14 | use: { 15 | loader: 'babel-loader', 16 | options: { 17 | presets: ['env', 'react'] 18 | } 19 | } 20 | } 21 | ] 22 | }, 23 | devServer: { 24 | port: 9000 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /samples/js/es.next/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "es6-examples", 3 | "version": "1.0.0", 4 | "description": "ES6 examples", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "bluebird": "^3.5.1", 13 | "jest": "^22.4.3", 14 | "standard": "^11.0.1" 15 | }, 16 | "dependencies": { 17 | "isomorphic-fetch": "^2.2.1" 18 | }, 19 | "standard": { 20 | "env": [ 21 | "jest" 22 | ], 23 | "globals": [ 24 | "Request" 25 | ] 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /samples/js/react/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | 3 | module.exports = { 4 | entry: './js/index.js', 5 | output: { 6 | filename: 'bundle.js', 7 | path: path.resolve(__dirname, 'dist') 8 | }, 9 | module: { 10 | rules: [ 11 | { 12 | test: /\.js$/, 13 | exclude: /(node_modules)/, 14 | use: { 15 | loader: 'babel-loader', 16 | options: { 17 | presets: ['env', 'react'] 18 | } 19 | } 20 | } 21 | ] 22 | }, 23 | devServer: { 24 | port: 9000 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/ui/paginator-panel.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import parser from 'parse-link-header' 3 | 4 | export default ({response, onClick}) => { 5 | const linkHeader = response && response.headers.get('Link') 6 | const parsed = linkHeader && parser(linkHeader) 7 | return ( 8 |
9 | 11 | 13 |
14 | ) 15 | } 16 | -------------------------------------------------------------------------------- /demos/demos-spring-boot-0/src/main/java/pt/isel/daw/demosspringboot0/DemosSpringBoot0Application.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.demosspringboot0; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.ApplicationContext; 6 | 7 | @SpringBootApplication 8 | // @Configuration 9 | public class DemosSpringBoot0Application { 10 | 11 | public static void main(String[] args) { 12 | 13 | SpringApplication.run(DemosSpringBoot0Application.class, args); 14 | } 15 | 16 | // @Bean... 17 | } 18 | -------------------------------------------------------------------------------- /demos/js/react/js/ui/show-hide.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default class extends React.Component { 4 | constructor (props) { 5 | super(props) 6 | this.state = {show: false} 7 | this.toggle = this.toggle.bind(this) 8 | } 9 | 10 | toggle () { 11 | this.setState(oldState => ({show: !oldState.show})) 12 | } 13 | 14 | render () { 15 | const show = this.state.show 16 | const text = show ? 'hide' : 'show' 17 | return
18 | 19 | {show ? this.props.children :
...
} 20 |
21 | } 22 | } 23 | -------------------------------------------------------------------------------- /samples/js/building/js/index.js: -------------------------------------------------------------------------------- 1 | import soma from './arith' 2 | import {sub, mult} from './arith' 3 | import * as arith from './arith' 4 | 5 | import leftpad from 'left-pad' 6 | 7 | console.log(arith) 8 | 9 | document.write('change3') 10 | document.write(`

40 + 2 = ${soma(40, 2)}

`) 11 | document.write(`

40 + 2 = ${arith.default(40, 2)}

`) 12 | document.write(`

44 - 2 = ${arith.sub(44, 2)}

`) 13 | document.write(`

7 * 6 = ${arith.mult(7, 6)}

`) 14 | document.write(`

44 - 2 = ${sub(44, 2)}

`) 15 | document.write(`

7 * 6 = ${mult(7, 6)}

`) 16 | 17 | document.write(`

leftpad('a', 5, '-') = ${leftpad('a', 5, '-')}

`) 18 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/ui/ShowHide.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default class extends React.Component { 4 | constructor (props) { 5 | super(props) 6 | this.state = {show: true} 7 | this.onClickHandler = this.onClickHandler.bind(this) 8 | } 9 | 10 | render () { 11 | const text = this.state.show ? 'hide' : 'show' 12 | const inner = this.state.show ? this.props.children :
...
13 | return
14 | 15 | {inner} 16 |
17 | } 18 | 19 | onClickHandler () { 20 | this.setState(oldState => ({show: !oldState.show})) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /demos/sample-spring-boot-pl-0/src/main/java/pt/isel/daw/samplespringbootpl0/SampleSpringBootPl0Application.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringbootpl0; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | 7 | @SpringBootApplication 8 | public class SampleSpringBootPl0Application { 9 | 10 | public static void main(String[] args) { 11 | 12 | SpringApplication.run(SampleSpringBootPl0Application.class, args); 13 | } 14 | 15 | @Bean 16 | Service1 getService1() { 17 | return new SomeService1Impl(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/src/main/java/pt/isel/daw/samples/SomeService2Impl.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class SomeService2Impl implements Service2 { 9 | 10 | private static final Logger log = LoggerFactory.getLogger(SomeService2Impl.class); 11 | 12 | private final Service1 svc1; 13 | 14 | public SomeService2Impl(Service1 svc1) { 15 | this.svc1 = svc1; 16 | log.info("ctor"); 17 | } 18 | 19 | @Override 20 | public void doAnotherThing() { 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/SomeCloseableThing.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.annotation.Scope; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | @Scope("request") 10 | public class SomeCloseableThing implements AutoCloseable { 11 | 12 | private static final Logger log = LoggerFactory.getLogger(SomeCloseableThing.class); 13 | 14 | public SomeCloseableThing() { 15 | log.info("ctor {}", this); 16 | } 17 | 18 | public void close() { 19 | log.info("close {}", this); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/src/main/java/pt/isel/daw/samples/spring/context/MyConfig.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.spring.context; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | @ComponentScan(basePackages = "pt.isel.daw.samples.spring.context.scanning") 9 | public class MyConfig { 10 | 11 | @Bean 12 | Service1 service1() { 13 | return new SomeService1(); 14 | } 15 | 16 | @Bean 17 | Service2 service2(Service1 svc1) { 18 | return new SomeService2(svc1); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/RequestCustomScopeConfigurer.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.springframework.beans.factory.config.CustomScopeConfigurer; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /* 10 | Bean used to register the "request" scope 11 | */ 12 | @Component 13 | public class RequestCustomScopeConfigurer extends CustomScopeConfigurer { 14 | 15 | public RequestCustomScopeConfigurer() { 16 | Map map = new HashMap<>(); 17 | map.put("request", new RequestScope()); 18 | setScopes(map); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /demos/examples-spring-context-0/src/main/java/pt/isel/daw/examples/SomeService1Impl.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.examples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.sql.DataSource; 8 | 9 | @Component 10 | public class SomeService1Impl implements Service1{ 11 | 12 | private static final Logger log = LoggerFactory.getLogger(SomeService1Impl.class); 13 | private final DataSource ds; 14 | 15 | public SomeService1Impl(DataSource ds) { 16 | this.ds = ds; 17 | log.info("ctor"); 18 | } 19 | 20 | @Override 21 | public void doSomething() { 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/commands/SomeCommand.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.commands; 2 | 3 | import org.springframework.stereotype.Component; 4 | import pt.isel.daw.samples.Command; 5 | import pt.isel.daw.samples.CommandRequest; 6 | import pt.isel.daw.samples.CommandResult; 7 | 8 | @Component 9 | public class SomeCommand implements Command { 10 | @Override 11 | public CommandResult execute(CommandRequest req) { 12 | return null; 13 | } 14 | 15 | @Override 16 | public String getPathTemplate() { 17 | return "/some/path"; 18 | } 19 | 20 | @Override 21 | public String getMethod() { 22 | return "PUT"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/build.gradle: -------------------------------------------------------------------------------- 1 | group 'pt.isel.daw' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | sourceCompatibility = 1.8 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | 14 | // The Spring IoC/DI library 15 | compile group: 'org.springframework', name: 'spring-context', version: '5.0.4.RELEASE' 16 | 17 | // Just for logging 18 | compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' 19 | runtime group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25' 20 | 21 | testCompile group: 'junit', name: 'junit', version: '4.12' 22 | testCompile group: 'org.springframework', name: 'spring-test', version: '5.0.4.RELEASE' 23 | } 24 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/commands/GetStudentByNumber.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.commands; 2 | 3 | import org.springframework.stereotype.Component; 4 | import pt.isel.daw.samples.Command; 5 | import pt.isel.daw.samples.CommandRequest; 6 | import pt.isel.daw.samples.CommandResult; 7 | 8 | @Component 9 | public class GetStudentByNumber implements Command { 10 | 11 | @Override 12 | public CommandResult execute(CommandRequest req) { 13 | return null; 14 | } 15 | 16 | @Override 17 | public String getPathTemplate() { 18 | return "/students/{num}"; 19 | } 20 | 21 | @Override 22 | public String getMethod() { 23 | return "GET"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /demos/examples-spring-context-0/build.gradle: -------------------------------------------------------------------------------- 1 | group 'pt.isel.daw' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | apply plugin: 'maven-publish' 6 | 7 | sourceCompatibility = 1.8 8 | 9 | repositories { 10 | mavenCentral() 11 | } 12 | 13 | publishing { 14 | publications { 15 | mavenJava(MavenPublication) { 16 | from components.java 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile group: 'org.springframework', name: 'spring-context', version: '5.0.4.RELEASE' 23 | compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' 24 | runtime group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25' 25 | testCompile group: 'junit', name: 'junit', version: '4.12' 26 | } 27 | -------------------------------------------------------------------------------- /samples/jvm/cors/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.0.1.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'org.springframework.boot' 16 | apply plugin: 'io.spring.dependency-management' 17 | 18 | group = 'com.example' 19 | version = '0.0.1-SNAPSHOT' 20 | sourceCompatibility = 1.8 21 | 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | 27 | dependencies { 28 | compile('org.springframework.boot:spring-boot-starter-web') 29 | testCompile('org.springframework.boot:spring-boot-starter-test') 30 | } 31 | -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/src/main/java/pt/isel/daw/samples/App.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | //@Bean 4 | //App getApp(Service2 svc) { 5 | // return new App(svc); 6 | //} 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.stereotype.Component; 11 | 12 | @Component 13 | public class App { 14 | 15 | private static final Logger log = LoggerFactory.getLogger(App.class); 16 | 17 | private final Service2 svc2; 18 | private final Service1 svc1; 19 | 20 | public App(Service1 svc1, Service2 svc2) { 21 | log.info("ctor"); 22 | this.svc2 = svc2; 23 | this.svc1 = svc1; 24 | } 25 | 26 | public void run() { 27 | // ... 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /demos/examples-spring-context-0/src/main/java/pt/isel/daw/examples/MainClass.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.examples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 7 | 8 | public class MainClass { 9 | 10 | private static Logger log = LoggerFactory.getLogger(MainClass.class); 11 | 12 | public static void main(String[] args) { 13 | 14 | ApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class); 15 | log.info("before getBean"); 16 | Service2 svc2 = ctx.getBean(Service2.class); 17 | log.info("The service2 is {}", svc2); 18 | 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/src/main/java/pt/isel/daw/samples/spring/context/scanning/SomeService3.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.spring.context.scanning; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Component; 6 | import pt.isel.daw.samples.spring.context.Service1; 7 | import pt.isel.daw.samples.spring.context.Service2; 8 | import pt.isel.daw.samples.spring.context.Service3; 9 | 10 | @Component 11 | public class SomeService3 implements Service3 { 12 | 13 | public static final Logger log = LoggerFactory.getLogger(SomeService3.class); 14 | 15 | public SomeService3(Service1 svc1, Service2 svc2) { 16 | log.info("ctor called on {}, with svc1={}, svc2={}", this, svc1, svc2); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/ui/comp1.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Comp2 from './comp2' 3 | 4 | export default class extends React.Component { 5 | constructor (props) { 6 | console.log('Comp1 ctor') 7 | super(props) 8 | this.state = {counter: 0} 9 | this.handleOnClick = this.handleOnClick.bind(this) 10 | } 11 | 12 | render () { 13 | console.log('Comp1 render') 14 | return
15 | 16 |
State counter: {this.state.counter}
17 |

Child component

18 | {this.state.counter % 3 === 3 ?
: } 19 |
20 | } 21 | 22 | handleOnClick () { 23 | this.setState(old => ({counter: old.counter + 1})) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/src/main/java/pt/isel/daw/samples/SomeService1Impl.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.annotation.Scope; 6 | import org.springframework.stereotype.Component; 7 | 8 | import javax.sql.DataSource; 9 | 10 | @Component 11 | @Scope("prototype") 12 | public class SomeService1Impl implements Service1 { 13 | 14 | private static final Logger log = LoggerFactory.getLogger(SomeService1Impl.class); 15 | 16 | private final DataSource ds; 17 | 18 | public SomeService1Impl(DataSource ds) { 19 | 20 | this.ds = ds; 21 | log.info("ctor"); 22 | } 23 | 24 | @Override 25 | public void doSomething() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/ui/app.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ShowHide from './ShowHide' 3 | import Clock from './clock' 4 | import Counter from './counter' 5 | import CounterExample from './counter-example' 6 | import Comp2 from './comp2' 7 | import Comp1 from './comp1' 8 | import IssueList from './issue-list' 9 | import RepoSelect from './repo-select' 10 | 11 | export default function (props) { 12 | const repos = [ 13 | {name: 'react', url: 'https://api.github.com/repos/facebook/react/issues'}, 14 | {name: 'daw', url: 'https://api.github.com/repos/isel-leic-daw/1718v-public/issues'} 15 | ] 16 | return ( 17 | } 19 | /> 20 | 21 | 23 | ) 24 | } 25 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/ui/repo-select.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | // {repos:[{name, url}], render} 4 | export default class extends React.Component { 5 | constructor (props) { 6 | super() 7 | this.state = { 8 | url: props.repos[0].url 9 | } 10 | this.handleChange = this.handleChange.bind(this) 11 | } 12 | 13 | handleChange (ev) { 14 | this.setState({ 15 | url: ev.target.value 16 | }) 17 | } 18 | 19 | render () { 20 | return ( 21 |
22 | 26 | {this.props.render({url: this.state.url})} 27 |
28 | ) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /samples/jvm/gcp/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.0.2.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'org.springframework.boot' 16 | apply plugin: 'io.spring.dependency-management' 17 | 18 | group = 'com.example' 19 | version = '0.0.1-SNAPSHOT' 20 | sourceCompatibility = 1.8 21 | 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | 27 | dependencies { 28 | compile('org.springframework.boot:spring-boot-starter-web') 29 | runtime('com.google.cloud:google-cloud-logging-logback:0.46.0-alpha') 30 | testCompile('org.springframework.boot:spring-boot-starter-test') 31 | } 32 | -------------------------------------------------------------------------------- /samples/js/building/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "building", 3 | "version": "1.0.0", 4 | "description": "Examples for the build process", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "webpack-dev-server --config ./webpack.config.js --mode development", 9 | "build-dev": "webpack --mode development", 10 | "build": "webpack --mode production" 11 | }, 12 | "author": "", 13 | "license": "ISC", 14 | "devDependencies": { 15 | "babel-loader": "^7.1.4", 16 | "babel-preset-env": "^1.6.1", 17 | "standard": "^11.0.1", 18 | "webpack": "^4.5.0", 19 | "webpack-cli": "^2.0.14", 20 | "webpack-dev-server": "^3.1.3" 21 | }, 22 | "dependencies": { 23 | "isomorphic-fetch": "^2.2.1", 24 | "left-pad": "^1.2.0" 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/src/main/java/pt/isel/daw/samples/spring/context/JavaBasedConfigurationExample.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.spring.context; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 7 | 8 | public class JavaBasedConfigurationExample { 9 | 10 | public static final Logger log = LoggerFactory.getLogger(JavaBasedConfigurationExample.class); 11 | 12 | public static void main(String[] args) { 13 | 14 | log.info("before creating context"); 15 | ApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class); 16 | 17 | log.info("before getBean"); 18 | Service3 bean = ctx.getBean(Service3.class); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /demos/demos-spring-boot-0/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.0.0.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'org.springframework.boot' 16 | apply plugin: 'io.spring.dependency-management' 17 | 18 | group = 'pt.isel.daw' 19 | version = '0.0.1-SNAPSHOT' 20 | sourceCompatibility = 1.8 21 | 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | 27 | dependencies { 28 | compile('org.springframework.boot:spring-boot-starter-web') 29 | runtime group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: '2.9.4' 30 | testCompile('org.springframework.boot:spring-boot-starter-test') 31 | } 32 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/CourseRepoImpl.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.inject.Provider; 8 | import java.sql.Connection; 9 | 10 | @Component 11 | public class CourseRepoImpl implements CourseRepo { 12 | 13 | private static final Logger log = LoggerFactory.getLogger(CourseRepoImpl.class); 14 | 15 | private final Provider connProv; 16 | 17 | public CourseRepoImpl(Provider connProv) { 18 | 19 | this.connProv = connProv; 20 | } 21 | 22 | @Override 23 | public void doSomething() { 24 | 25 | Connection conn = connProv.get(); 26 | log.info("using connection {}", conn.hashCode()); 27 | // use conn 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/MyExceptionResolver.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | import org.springframework.core.Ordered; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.servlet.HandlerExceptionResolver; 6 | import org.springframework.web.servlet.ModelAndView; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | //@Component 12 | public class MyExceptionResolver implements HandlerExceptionResolver, Ordered { 13 | 14 | @Override 15 | public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { 16 | return null; 17 | } 18 | 19 | @Override 20 | public int getOrder() { 21 | return -1000; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/StudentsRepoImpl.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.inject.Provider; 8 | import java.sql.Connection; 9 | 10 | @Component 11 | public class StudentsRepoImpl implements StudentsRepo { 12 | 13 | private static final Logger log = LoggerFactory.getLogger(StudentsRepoImpl.class); 14 | 15 | 16 | private final Provider connProv; 17 | 18 | public StudentsRepoImpl(Provider connProv) { 19 | 20 | this.connProv = connProv; 21 | } 22 | 23 | @Override 24 | public void doSomething() { 25 | 26 | Connection conn = connProv.get(); 27 | log.info("using connection {}", conn.hashCode()); 28 | // use conn 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/ui/counter.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | // 4 | export default class extends React.Component { 5 | constructor (props) { 6 | const {value} = props 7 | super(props) 8 | this.state = {value: value} 9 | this.inc = this.inc.bind(this) 10 | this.dec = this.dec.bind(this) 11 | } 12 | 13 | inc () { 14 | this.props.onChange(this.state.value, this.state.value + 1) 15 | this.setState(old => ({value: old.value + 1})) 16 | } 17 | 18 | dec () { 19 | this.props.onChange(this.state.value, this.state.value - 1) 20 | this.setState(old => ({value: old.value - 1})) 21 | } 22 | 23 | render () { 24 | return ( 25 |
26 | 27 | 28 | {this.state.value} 29 |
30 | ) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /demos/js/react/js/ui/clock2.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Line from './line' 3 | 4 | export default class extends React.Component { 5 | constructor (props) { 6 | super(props) 7 | this.state = {date: new Date()} 8 | this.tick = this.tick.bind(this) 9 | console.log('ctor') 10 | } 11 | 12 | render () { 13 | const date = this.state.date 14 | const seconds = date.getSeconds() 15 | console.log('render') 16 | return
17 |

{date.toLocaleString()}

18 | 19 |
20 | } 21 | 22 | tick () { 23 | console.log('tick') 24 | this.setState({date: new Date()}) 25 | } 26 | 27 | componentDidMount () { 28 | console.log('CDM') 29 | this.interval = setInterval(this.tick, 1000) 30 | } 31 | 32 | componentWillUnmount () { 33 | console.log('CWU') 34 | clearInterval(this.interval) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /samples/js/es.next/async-await.test.js: -------------------------------------------------------------------------------- 1 | test('functions always return a promise', done => { 2 | async function f () { return 42 } 3 | const val1 = f() 4 | expect(val1.then).toBeDefined() 5 | 6 | async function g () { throw new Error('the error') } 7 | const val2 = g() 8 | expect(val2.then).toBeDefined() 9 | // reject promises need to be handled! 10 | val2.catch(() => done()) 11 | }) 12 | 13 | function delay (result, delay) { 14 | return new Promise((resolve, reject) => { 15 | setTimeout(() => resolve(typeof result === 'function' ? result() : result), delay) 16 | }) 17 | } 18 | 19 | test('await example', async () => { 20 | expect.assertions(2) 21 | let res = await delay(42, 100) 22 | expect(res).toBe(42) 23 | let state = 0 24 | try { 25 | await Promise.reject(new Error()) 26 | state = 1 27 | } catch (e) { 28 | state = 2 29 | } 30 | expect(state).toBe(2) 31 | }) 32 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/ui/clock.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Line from './line' 3 | 4 | export default class extends React.Component { 5 | constructor (props) { 6 | console.log('ctor') 7 | super(props) 8 | this.state = {date: new Date()} 9 | this.tick = this.tick.bind(this) 10 | } 11 | 12 | render () { 13 | console.log('render') 14 | const date = this.state.date 15 | const seconds = date.getSeconds() 16 | return
17 |

Clock

18 |

{date.toLocaleString()}

19 |

20 |
21 | } 22 | 23 | componentDidMount () { 24 | console.log('CDM') 25 | this.interval = setInterval(this.tick, 100) 26 | } 27 | 28 | componentWillUnmount () { 29 | console.log('CWU') 30 | clearInterval(this.interval) 31 | } 32 | 33 | tick () { 34 | this.setState({date: new Date()}) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/src/test/java/pt/isel/daw/samples/spring/context/ContextTests.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.spring.context; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.test.context.ContextConfiguration; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | import static org.junit.Assert.assertNotNull; 11 | 12 | @RunWith(SpringRunner.class) 13 | @ContextConfiguration(classes=UsingJavaMethods.Config.class) 14 | public class ContextTests { 15 | 16 | @Autowired 17 | public ApplicationContext ctx; 18 | 19 | @Test 20 | public void context_is_correctly_configured() { 21 | UsingJavaMethods.Service3 svc3 = ctx.getBean(UsingJavaMethods.Service3.class); 22 | assertNotNull(svc3); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/commands/CreateStudent.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.commands; 2 | 3 | import org.springframework.stereotype.Component; 4 | import pt.isel.daw.samples.Command; 5 | import pt.isel.daw.samples.CommandRequest; 6 | import pt.isel.daw.samples.CommandResult; 7 | import pt.isel.daw.samples.EmailSender; 8 | 9 | @Component 10 | public class CreateStudent implements Command { 11 | 12 | private final EmailSender emailSender; 13 | 14 | public CreateStudent(EmailSender emailSender) { 15 | this.emailSender = emailSender; 16 | } 17 | 18 | @Override 19 | public CommandResult execute(CommandRequest req) { 20 | return null; 21 | } 22 | 23 | @Override 24 | public String getPathTemplate() { 25 | return "/students"; 26 | } 27 | 28 | @Override 29 | public String getMethod() { 30 | return "POST"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/commands/ShutdownCommand.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.commands; 2 | 3 | import org.springframework.stereotype.Component; 4 | import pt.isel.daw.samples.Command; 5 | import pt.isel.daw.samples.CommandRequest; 6 | import pt.isel.daw.samples.CommandResult; 7 | import pt.isel.daw.samples.Shutdown; 8 | 9 | @Component 10 | public class ShutdownCommand implements Command { 11 | 12 | private final Shutdown shutdown; 13 | 14 | public ShutdownCommand(Shutdown shutdown) { 15 | 16 | this.shutdown = shutdown; 17 | } 18 | 19 | @Override 20 | public CommandResult execute(CommandRequest req) { 21 | shutdown.start(); 22 | return null; 23 | } 24 | 25 | @Override 26 | public String getPathTemplate() { 27 | return "/shutdown"; 28 | } 29 | 30 | @Override 31 | public String getMethod() { 32 | return "POST"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /demos/js/react-pl/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-demo", 3 | "version": "1.0.0", 4 | "description": "React class demo", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "webpack-dev-server --config ./webpack.config.js --mode development", 9 | "build-dev": "webpack --mode development", 10 | "build": "webpack --mode production" 11 | }, 12 | "author": "", 13 | "license": "ISC", 14 | "devDependencies": { 15 | "babel-loader": "^7.1.4", 16 | "babel-preset-env": "^1.6.1", 17 | "babel-preset-react": "^6.24.1", 18 | "isomorphic-fetch": "^2.2.1", 19 | "parse-link-header": "^1.0.1", 20 | "react": "^16.3.2", 21 | "react-dom": "^16.3.2", 22 | "standard": "^11.0.1", 23 | "webpack": "^4.5.0", 24 | "webpack-cli": "^2.0.14", 25 | "webpack-dev-server": "^3.1.3" 26 | }, 27 | "dependencies": { 28 | "left-pad": "^1.2.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /demos/examples-spring-context-0/src/main/java/pt/isel/daw/examples/SomeService2Impl.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.examples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.stereotype.Component; 7 | 8 | import javax.sql.DataSource; 9 | 10 | //@Bean 11 | //public Service2 service2(Service1 svc1) { 12 | // return new SomeService2Impl(svc1); 13 | //} 14 | 15 | @Component 16 | public class SomeService2Impl implements Service2 { 17 | 18 | private static final Logger log = LoggerFactory.getLogger(SomeService2Impl.class); 19 | 20 | private final Service1 svc1; 21 | private final DataSource ds; 22 | 23 | public SomeService2Impl(Service1 svc1, DataSource ds) { 24 | 25 | this.svc1 = svc1; 26 | this.ds = ds; 27 | log.info("ctor"); 28 | } 29 | 30 | @Override 31 | public void doAnotherThing() { 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /samples/js/react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "building", 3 | "version": "1.0.0", 4 | "description": "Examples for the build process", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "webpack-dev-server --config ./webpack.config.js --mode development", 9 | "build-dev": "webpack --mode development", 10 | "build": "webpack --mode production" 11 | }, 12 | "author": "", 13 | "license": "ISC", 14 | "devDependencies": { 15 | "babel-loader": "^7.1.4", 16 | "babel-preset-env": "^1.6.1", 17 | "babel-preset-react": "^6.24.1", 18 | "react": "^16.3.1", 19 | "react-doc": "^1.2.6", 20 | "react-dom": "^16.3.1", 21 | "standard": "^11.0.1", 22 | "webpack": "^4.5.0", 23 | "webpack-cli": "^2.0.14", 24 | "webpack-dev-server": "^3.1.3" 25 | }, 26 | "dependencies": { 27 | "isomorphic-fetch": "^2.2.1", 28 | "left-pad": "^1.2.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /demos/js/react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-example", 3 | "version": "1.0.0", 4 | "description": "Examples for the build process", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "webpack-dev-server --config ./webpack.config.js --mode development", 9 | "build-dev": "webpack --mode development", 10 | "build": "webpack --mode production" 11 | }, 12 | "author": "", 13 | "license": "ISC", 14 | "devDependencies": { 15 | "babel-loader": "^7.1.4", 16 | "babel-preset-env": "^1.6.1", 17 | "babel-preset-react": "^6.24.1", 18 | "isomorphic-fetch": "^2.2.1", 19 | "parse-link-header": "^1.0.1", 20 | "react": "^16.3.1", 21 | "react-dom": "^16.3.1", 22 | "standard": "^11.0.1", 23 | "webpack": "^4.5.0", 24 | "webpack-cli": "^2.0.14", 25 | "webpack-dev-server": "^3.1.3" 26 | }, 27 | "dependencies": { 28 | "left-pad": "^1.2.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/Router.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | import java.util.Optional; 11 | 12 | @Component 13 | public class Router { 14 | 15 | private static final Logger log = LoggerFactory.getLogger(Router.class); 16 | 17 | private final Map map = new HashMap<>(); 18 | 19 | public Router(List cmds) { 20 | for(Command cmd : cmds) { 21 | log.info("registering {} on path template {}", cmd.getClass().getSimpleName(), cmd.getPathTemplate()); 22 | map.put(cmd.getMethod() + " " + cmd.getPathTemplate(), cmd); 23 | } 24 | } 25 | 26 | public void run(String s) { 27 | Optional.ofNullable(map.get(s)).ifPresent(cmd -> cmd.execute(null)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/src/main/java/pt/isel/daw/samples/MainClass.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 7 | 8 | public class MainClass { 9 | 10 | private static final Logger log = LoggerFactory.getLogger(MainClass.class); 11 | 12 | public static void main(String[] args) { 13 | 14 | ApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class); 15 | 16 | log.info("before getBean"); 17 | App app = ctx.getBean(App.class); 18 | log.info("recipe count = {}", ctx.getBeanDefinitionCount()); 19 | 20 | app = ctx.getBean(App.class); 21 | app = ctx.getBean(App.class); 22 | app = ctx.getBean(App.class); 23 | log.info("app instance is {}", app); 24 | app.run(); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/build.gradle: -------------------------------------------------------------------------------- 1 | group 'pt.isel.daw' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | sourceCompatibility = 1.8 7 | 8 | repositories { 9 | mavenCentral() 10 | 11 | } 12 | 13 | dependencies { 14 | 15 | // The Spring IoC/DI library 16 | compile group: 'org.springframework', name: 'spring-context', version: '5.0.4.RELEASE' 17 | 18 | compile group: 'javax.inject', name: 'javax.inject', version: '1' 19 | 20 | // Just for logging 21 | compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' 22 | runtime group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25' 23 | 24 | compile group: 'com.h2database', name: 'h2', version: '1.4.196' 25 | compile group: 'org.eclipse.jetty.aggregate', name: 'jetty-all', version: '9.4.8.v20171121', ext: 'pom' 26 | 27 | testCompile group: 'junit', name: 'junit', version: '4.12' 28 | testCompile group: 'org.springframework', name: 'spring-test', version: '5.0.4.RELEASE' 29 | } 30 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.0.0.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'org.springframework.boot' 16 | apply plugin: 'io.spring.dependency-management' 17 | 18 | group = 'pt.isel.daw' 19 | version = '0.0.1-SNAPSHOT' 20 | sourceCompatibility = 1.8 21 | 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | 27 | dependencies { 28 | compile('org.springframework.boot:spring-boot-starter-web') 29 | compile('io.springfox:springfox-swagger2:2.8.0') 30 | compile('io.springfox:springfox-swagger-ui:2.8.0') 31 | //runtime('com.fasterxml.jackson.dataformat:jackson-dataformat-xml') 32 | compile('net.sf.biweekly:biweekly:0.6.1') 33 | testCompile('org.springframework.boot:spring-boot-starter-test') 34 | } 35 | -------------------------------------------------------------------------------- /demos/js/react/js/ui/app.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import IssueList from './issue-list' 3 | import Nav from './nav' 4 | 5 | const repos = [ 6 | {name: 'react', url: 'https://api.github.com/repos/facebook/react/issues'}, 7 | {name: 'DAW', url: 'https://api.github.com/repos/isel-leic-daw/1718v-public/issues'} 8 | ] 9 | 10 | export default class extends React.Component { 11 | constructor (props) { 12 | super(props) 13 | this.state = {selected: repos[0].url} 14 | this.changeHandler = this.changeHandler.bind(this) 15 | } 16 | 17 | changeHandler (ev) { 18 | console.log('changeHandler' + ev.target.value) 19 | this.setState({ 20 | selected: ev.target.value 21 | }) 22 | } 23 | 24 | render () { 25 | return ( 26 |
27 |
URL: {this.state.selected}
28 |
31 | ) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /demos/js/react/js/ui/counter.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | // ({counter: old.counter + 1})) 19 | } 20 | 21 | dec () { 22 | this.onChange(this.id, this.state.counter, this.state.counter - 1) 23 | // this.setState(old => ({counter: old.counter - 1})) 24 | } 25 | 26 | render () { 27 | return ( 28 | 29 | 30 | 31 | {this.state.counter} 32 | 33 | ) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /samples/http-requests/example1.graphql: -------------------------------------------------------------------------------- 1 | query { 2 | node(id:"MDQ6VXNlcjM2NDYwMA=="){ 3 | ...on User { 4 | login 5 | name 6 | location 7 | } 8 | } 9 | repository(name:"1718v-public",owner:"isel-leic-daw") { 10 | name 11 | createdAt 12 | issues(first:5) { 13 | nodes { 14 | id 15 | title 16 | comments(first:5) { 17 | nodes { 18 | body 19 | createdAt 20 | author { 21 | login 22 | ...on User { 23 | id 24 | name 25 | organizations(first:5) { 26 | nodes { 27 | name 28 | } 29 | } 30 | } 31 | } 32 | } 33 | } 34 | } 35 | } 36 | } 37 | viewer { 38 | name 39 | location 40 | login 41 | repositories(first:5) { 42 | nodes { 43 | name 44 | createdAt 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /demos/sample-spring-boot-pl-0/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.0.0.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | mavenLocal() 8 | } 9 | dependencies { 10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 11 | } 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'eclipse' 16 | apply plugin: 'org.springframework.boot' 17 | apply plugin: 'io.spring.dependency-management' 18 | apply plugin: 'maven-publish' 19 | 20 | group = 'pt.isel.daw' 21 | version = '0.0.1-SNAPSHOT' 22 | sourceCompatibility = 1.8 23 | 24 | repositories { 25 | mavenCentral() 26 | } 27 | 28 | publishing { 29 | publications { 30 | mavenJava(MavenPublication) { 31 | from components.java 32 | } 33 | } 34 | } 35 | 36 | 37 | dependencies { 38 | compile('org.springframework.boot:spring-boot-starter-web') 39 | runtime group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: '2.9.4' 40 | testCompile('org.springframework.boot:spring-boot-starter-test') 41 | } 42 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/Config.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.h2.jdbcx.JdbcDataSource; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.context.annotation.Scope; 8 | 9 | import javax.sql.DataSource; 10 | import java.sql.Connection; 11 | import java.sql.SQLException; 12 | 13 | @Configuration 14 | @ComponentScan(basePackages = "pt.isel.daw.samples") 15 | public class Config { 16 | 17 | @Bean 18 | public DataSource sqlServerDataSource() { 19 | JdbcDataSource ds = new JdbcDataSource(); 20 | ds.setURL("jdbc:h2:mem:test"); 21 | ds.setUser("sa"); 22 | ds.setPassword("sa"); 23 | return ds; 24 | } 25 | 26 | @Bean 27 | @Scope("request") 28 | public Connection recipeForConnections(DataSource ds) throws SQLException { 29 | return ds.getConnection(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /demos/examples-spring-context-0/src/main/java/pt/isel/daw/examples/MyConfig.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.examples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.ComponentScan; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.Scope; 9 | 10 | import javax.sql.DataSource; 11 | 12 | @Configuration 13 | @ComponentScan 14 | public class MyConfig { 15 | 16 | private static final Logger log = LoggerFactory.getLogger(MyConfig.class); 17 | 18 | @Bean 19 | @Scope("prototype") 20 | DataSource createDataSource(Settings settings) { 21 | MyDataSource ds = new MyDataSource(); 22 | ds.configure(settings.getConnString()); 23 | log.info("ctor MyDataSource"); 24 | return ds; 25 | } 26 | 27 | @Bean 28 | Settings getSettings() { 29 | log.info("creating settings from environment"); 30 | return Settings.fromEnvironment(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /samples/jvm/cors/src/main/java/com/example/cors/ExampleController.java: -------------------------------------------------------------------------------- 1 | package com.example.cors; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PostMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import javax.servlet.http.Cookie; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | @RestController 14 | @RequestMapping("/example") 15 | public class ExampleController { 16 | 17 | private static final Logger log = LoggerFactory.getLogger(ExampleController.class); 18 | 19 | @GetMapping 20 | public String get(HttpServletResponse res) { 21 | log.info("get"); 22 | // res.addHeader("Access-Control-Allow-Origin", "https://www.isel.pt"); 23 | // res.addCookie(new Cookie("cookie-name", "cookie-value")); 24 | return "OK"; 25 | } 26 | 27 | @PostMapping 28 | public String post() { 29 | return "Ok"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/MyExceptionHandlerAdvice.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.http.ResponseEntity; 5 | import org.springframework.web.bind.annotation.ControllerAdvice; 6 | import org.springframework.web.bind.annotation.ExceptionHandler; 7 | import org.springframework.web.context.request.WebRequest; 8 | 9 | @ControllerAdvice 10 | public class MyExceptionHandlerAdvice { 11 | 12 | public static class ErrorModel { 13 | public String type; 14 | public int status = 400; 15 | public String message; 16 | } 17 | 18 | @ExceptionHandler(Throwable.class) 19 | public final ResponseEntity handle( 20 | Throwable ex, 21 | WebRequest request) { 22 | ex.printStackTrace(); 23 | ErrorModel error = new ErrorModel(); 24 | error.message = ex.getMessage(); 25 | error.type = "http://example.com/error/types/rels/some-type"; 26 | 27 | return new ResponseEntity(error, HttpStatus.BAD_REQUEST); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /demos/js/react/js/ui/shooping-cart.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Counter from './counter' 3 | 4 | // const purchase = [{name: 'product', initial: 1}, ] 5 | // 6 | export default class extends React.Component { 7 | constructor (props) { 8 | super(props) 9 | this.state = {sum: 3} 10 | this.changeHandler = this.changeHandler.bind(this) 11 | this.db = props.purchase.map(product => ({name: product.name, units: product.initial})) 12 | console.log(this.db) 13 | } 14 | 15 | changeHandler (key, oldValue, newValue) { 16 | this.db[key].units += newValue - oldValue 17 | this.setState(old => ({sum: old.sum + (newValue - oldValue)})) 18 | console.log(this.db[key]) 19 | } 20 | 21 | render () { 22 | console.log('ShoopingCart render') 23 | const line = (prod, index) => 24 | (
{prod.name}
) 26 | 27 | return ( 28 |
29 | {this.db.map((prod, index) => line(prod, index))} 30 |
Sum: {this.state.sum}
31 |
32 | ) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/ui/comp2.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default class Comp2 extends React.Component { 4 | constructor (props) { 5 | console.log('Comp2 ctor') 6 | super(props) 7 | this.handleOnClick = this.handleOnClick.bind(this) 8 | this.state = {} 9 | } 10 | 11 | static getDerivedStateFromProps (nextProps, prevState) { 12 | console.log('Comp2 GDSFP') 13 | return {counter: nextProps.counter * 10} 14 | } 15 | 16 | render () { 17 | console.log('Comp2 render') 18 | return
19 | 20 |
Props counter: {this.props.counter}
21 |
State counter: {this.state.counter}
22 |
23 | } 24 | 25 | handleOnClick () { 26 | this.setState(old => ({counter: old.counter + 1})) 27 | } 28 | 29 | componentDidMount () { 30 | console.log('Comp2 CDM') 31 | } 32 | 33 | shouldComponentUpdate () { 34 | console.log('Comp2 SCU') 35 | return true 36 | } 37 | 38 | componentDidUpdate () { 39 | console.log('Comp2 CDU') 40 | } 41 | 42 | componentWillUnmount () { 43 | console.log('Comp2 CWU') 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/Server.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import javax.sql.DataSource; 6 | 7 | @Component 8 | public class Server { 9 | 10 | private final Router router; 11 | private final DataSource dataSource; 12 | private final Shutdown shutdown; 13 | private final RequestScope requestScope; 14 | 15 | public Server(Router router, DataSource dataSource, Shutdown shutdown, RequestScope requestScope) { 16 | 17 | this.router = router; 18 | this.dataSource = dataSource; 19 | this.shutdown = shutdown; 20 | this.requestScope = requestScope; 21 | } 22 | 23 | public void start() throws InterruptedException { 24 | // Lets pretend we startup a server and then a couple of requests come in 25 | // on different threads... 26 | for(int i = 0 ; i<2 ; ++i) { 27 | new Thread(()-> { 28 | router.run("GET /students"); 29 | requestScope.destroyRequestScopedBeans(); 30 | 31 | }).start(); 32 | } 33 | 34 | 35 | shutdown.await(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/src/main/java/pt/isel/daw/samples/MyConfig.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.ComponentScan; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import javax.sql.DataSource; 10 | 11 | @Configuration 12 | @ComponentScan 13 | public class MyConfig { 14 | 15 | private static final Logger log = LoggerFactory.getLogger(MyConfig.class); 16 | 17 | 18 | @Bean 19 | DataSource getDataSource() { 20 | MyDataSource ds = new MyDataSource(); 21 | ds.setConfiguration(System.getenv("CONN_STRING")); 22 | 23 | log.info("MyDataSource ctored and configured"); 24 | return ds; 25 | } 26 | 27 | //@Bean 28 | //App getApp(Service2 svc) { 29 | // return new App(svc); 30 | //} 31 | 32 | //@Bean 33 | //Service1 getService1() { 34 | // return new SomeService1Impl(); 35 | //} 36 | 37 | //@Bean 38 | //Service2 getService2(Service1 svc) { 39 | // return new SomeService2Impl(svc); 40 | //} 41 | 42 | } 43 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/QueryStringArgumentResolver.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | import org.springframework.core.MethodParameter; 4 | import org.springframework.web.bind.support.WebDataBinderFactory; 5 | import org.springframework.web.context.request.NativeWebRequest; 6 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 7 | import org.springframework.web.method.support.ModelAndViewContainer; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | 11 | public class QueryStringArgumentResolver implements HandlerMethodArgumentResolver { 12 | 13 | @Override 14 | public boolean supportsParameter(MethodParameter parameter) { 15 | return parameter.getParameterType().equals(QueryString.class); 16 | } 17 | 18 | @Override 19 | public Object resolveArgument( 20 | MethodParameter parameter, 21 | ModelAndViewContainer mavContainer, 22 | NativeWebRequest webRequest, 23 | WebDataBinderFactory binderFactory) throws Exception { 24 | 25 | return new QueryString(webRequest.getNativeRequest(HttpServletRequest.class).getQueryString()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/ClientIpArgumentResolver.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | import org.springframework.core.MethodParameter; 4 | import org.springframework.web.bind.support.WebDataBinderFactory; 5 | import org.springframework.web.context.request.NativeWebRequest; 6 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 7 | import org.springframework.web.method.support.ModelAndViewContainer; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | 11 | public class ClientIpArgumentResolver implements HandlerMethodArgumentResolver { 12 | @Override 13 | public boolean supportsParameter(MethodParameter parameter) { 14 | return parameter.getParameterType().equals(ClientIp.class); 15 | } 16 | 17 | @Override 18 | public Object resolveArgument( 19 | MethodParameter parameter, 20 | ModelAndViewContainer mavContainer, 21 | NativeWebRequest webRequest, 22 | WebDataBinderFactory binderFactory) throws Exception { 23 | return new ClientIp( 24 | webRequest.getNativeRequest(HttpServletRequest.class) 25 | .getRemoteAddr()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /demos/js/es-next/async-await.test.js: -------------------------------------------------------------------------------- 1 | test('async functions always return a promise', () => { 2 | async function f () { 3 | return 2 4 | } 5 | 6 | const res = f() 7 | 8 | expect(res).not.toBe(2) 9 | expect(res.then).toBeDefined() 10 | }) 11 | 12 | test('async functions unwrap promises', () => { 13 | async function f () { 14 | return Promise.resolve(2) 15 | } 16 | const res = f() 17 | return res.then(v => { 18 | expect(v).toBe(2) 19 | }) 20 | }) 21 | 22 | test('async functions wrap exceptions into promises', () => { 23 | async function f () { 24 | throw new Error('the error') 25 | } 26 | const res = f() 27 | return res.catch(e => { 28 | expect(e.message).toBe('the error') 29 | }) 30 | }) 31 | 32 | function delay (result, time) { 33 | return new Promise((resolve, reject) => { 34 | setTimeout(() => resolve(result), time) 35 | }) 36 | } 37 | 38 | function log (msg) { 39 | console.log(`[${Date.now()}] ${msg}`) 40 | } 41 | 42 | test('await example', () => { 43 | async function f () { 44 | log('step 1') 45 | await delay(1, 100) 46 | log('step 2') 47 | await delay(1, 100) 48 | log('step 3') 49 | await delay(1, 100) 50 | log('step 4') 51 | } 52 | 53 | log('before call') 54 | const p = f() 55 | log('after call') 56 | return p 57 | }) 58 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/ExampleFilter.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.servlet.HandlerMapping; 7 | 8 | import javax.servlet.*; 9 | import java.io.IOException; 10 | import java.util.Optional; 11 | 12 | // It is enough to mark the filter has a Bean for it to be registered 13 | @Component 14 | public class ExampleFilter implements Filter { 15 | 16 | private static final Logger log = LoggerFactory.getLogger(ExampleFilter.class); 17 | 18 | @Override 19 | public void init(FilterConfig filterConfig) throws ServletException { 20 | 21 | } 22 | 23 | @Override 24 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 25 | log.info("before"); 26 | 27 | chain.doFilter(request, response); 28 | 29 | String pattern = (String) Optional.ofNullable(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)) 30 | .orElse("[unknown]"); 31 | log.info("after, pattern = {}", pattern); 32 | } 33 | 34 | @Override 35 | public void destroy() { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /samples/jvm/gcp/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | INFO 16 | 17 | application.log 18 | gae_app 19 | com.example.logging.logback.enhancers.ExampleEnhancer 20 | WARN 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /demos/js/es-next/destructuring.test.js: -------------------------------------------------------------------------------- 1 | test('some test', () => { 2 | expect(2 + 3).toBe(5) 3 | }) 4 | 5 | test('simple destructuring', () => { 6 | function createStudent () { 7 | return { 8 | name: 'Alice', 9 | number: 12345 10 | } 11 | } 12 | 13 | const {name, number} = createStudent() 14 | expect(name).toBe('Alice') 15 | expect(number).toBe(12345) 16 | }) 17 | 18 | test('array deconstruction', () => { 19 | function createArray () { 20 | return [1, 2, 3] 21 | } 22 | 23 | const [first, second] = createArray() 24 | expect(first).toBe(1) 25 | expect(second).toBe(2) 26 | }) 27 | 28 | test('destructuring on args', () => { 29 | function createStudent () { 30 | return { 31 | name: 'Alice', 32 | number: 12345 33 | } 34 | } 35 | 36 | function showStudent ({name, number}) { 37 | return `Student '${name}' with number ${number}` 38 | } 39 | 40 | const str = showStudent(createStudent()) 41 | expect(str).toEqual('Student \'Alice\' with number 12345') 42 | }) 43 | 44 | test('destructuring renaming', () => { 45 | function createStudent () { 46 | return { 47 | name: 'Alice', 48 | number: 12345 49 | } 50 | } 51 | 52 | const {name: studentName, number: studentNumber} = createStudent() 53 | expect(studentName).toBe('Alice') 54 | expect(studentNumber).toBe(12345) 55 | }) 56 | -------------------------------------------------------------------------------- /samples/js/es.next/destructuring.test.js: -------------------------------------------------------------------------------- 1 | test('basic object destructuring', () => { 2 | function getStudent () { 3 | return {name: 'Alice', number: 12345} 4 | } 5 | 6 | const {name, number} = getStudent() 7 | expect(name).toBe('Alice') 8 | expect(number).toBe(12345) 9 | }) 10 | 11 | test('basic object destructuring with renaming', () => { 12 | function getStudent () { 13 | return {name: 'Alice', number: 12345} 14 | } 15 | 16 | const {name: studentName, number: studentNumber} = getStudent() 17 | expect(studentName).toBe('Alice') 18 | expect(studentNumber).toBe(12345) 19 | }) 20 | 21 | test('object destructuring with coertion', () => { 22 | const {length, toUpperCase} = 'abc' 23 | expect(length).toBe(3) 24 | expect(toUpperCase.apply('abc')).toBe('ABC') 25 | }) 26 | 27 | test('array destructuring', () => { 28 | function doSomething () { 29 | return [1, 2] 30 | } 31 | 32 | const [first, second] = doSomething() 33 | expect(first).toBe(1) 34 | expect(second).toBe(2) 35 | }) 36 | 37 | test('nested destructuring', () => { 38 | const [{a, b}, c] = [{a: 1, b: 'a'}, 1] 39 | expect(a).toBe(1) 40 | expect(b).toBe('a') 41 | expect(c).toBe(1) 42 | }) 43 | 44 | test('destructuring in function arguments', () => { 45 | function doSomething ({name, number}) { 46 | expect(name).toBe('Alice') 47 | expect(number).toBe(12345) 48 | } 49 | const alice = {name: 'Alice', number: 12345} 50 | doSomething(alice) 51 | }) 52 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/ui/issue-state-filter-panel.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | // {names, values, onChange} 4 | export default class extends React.Component { 5 | constructor (props) { 6 | super(props) 7 | this.state = { 8 | open: true, 9 | closed: false 10 | } 11 | this.onOpenClick = this.onOpenClick.bind(this) 12 | this.onClosedClick = this.onClosedClick.bind(this) 13 | } 14 | 15 | onOpenClick (ev) { 16 | this.onClick('open', 'closed') 17 | } 18 | 19 | onClosedClick (ev) { 20 | this.onClick('closed', 'open') 21 | } 22 | 23 | onClick (cb1, cb2) { 24 | console.log(`onClick ${cb1} ${cb2}`) 25 | this.setState(old => ({ 26 | [cb1]: !old[cb1], 27 | [cb2]: old[cb1] ? true : old[cb2] 28 | })) 29 | } 30 | 31 | render () { 32 | return ( 33 |
34 | {this.props.names[0]} 35 | {this.props.names[1]} 36 |
37 | ) 38 | } 39 | 40 | componentDidUpdate (oldProps, oldState) { 41 | const value = this.state.open && this.state.closed 42 | ? this.props.values[2] 43 | : this.state.open ? this.props.values[0] : this.props.values[1] 44 | if (this.state.open !== oldState.open || this.state.closed !== oldState.closed) { 45 | this.props.onChange(value) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /demos/examples-spring-context-0/src/main/java/pt/isel/daw/examples/MyDataSource.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.examples; 2 | 3 | import javax.sql.DataSource; 4 | import java.io.PrintWriter; 5 | import java.sql.Connection; 6 | import java.sql.SQLException; 7 | import java.sql.SQLFeatureNotSupportedException; 8 | import java.util.logging.Logger; 9 | 10 | public class MyDataSource implements DataSource { 11 | 12 | public void configure(String s){} 13 | public Connection getConnection(){return null;} 14 | 15 | @Override 16 | public Connection getConnection(String username, String password) throws SQLException { 17 | return null; 18 | } 19 | 20 | @Override 21 | public T unwrap(Class iface) throws SQLException { 22 | return null; 23 | } 24 | 25 | @Override 26 | public boolean isWrapperFor(Class iface) throws SQLException { 27 | return false; 28 | } 29 | 30 | @Override 31 | public PrintWriter getLogWriter() throws SQLException { 32 | return null; 33 | } 34 | 35 | @Override 36 | public void setLogWriter(PrintWriter out) throws SQLException { 37 | 38 | } 39 | 40 | @Override 41 | public void setLoginTimeout(int seconds) throws SQLException { 42 | 43 | } 44 | 45 | @Override 46 | public int getLoginTimeout() throws SQLException { 47 | return 0; 48 | } 49 | 50 | @Override 51 | public Logger getParentLogger() throws SQLFeatureNotSupportedException { 52 | return null; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /samples/js/es.next/fetch.test.js: -------------------------------------------------------------------------------- 1 | const fetch = require('isomorphic-fetch') 2 | 3 | test('GET and check 200 status', async () => { 4 | expect.assertions(1) 5 | const resp = await fetch('https://httpbin.org/get') 6 | expect(resp.status).toBe(200) 7 | }) 8 | 9 | test('GET and check 400 status', async () => { 10 | expect.assertions(1) 11 | // a non-200 does not throw 12 | const resp = await fetch('https://httpbin.org/status/400') 13 | expect(resp.status).toBe(400) 14 | }) 15 | 16 | test('GET and access body', async () => { 17 | expect.assertions(1) 18 | const resp = await fetch('https://httpbin.org/get') 19 | const body = await resp.json() 20 | expect(body.url).toBe('https://httpbin.org/get') 21 | }) 22 | 23 | test('GET and request headers', async () => { 24 | expect.assertions(1) 25 | const resp = await fetch('https://httpbin.org/get', { 26 | headers: { 27 | Authorization: 'bearer the-access-token' 28 | } 29 | }) 30 | const body = await resp.json() 31 | expect(body.headers.Authorization).toBe('bearer the-access-token') 32 | }) 33 | 34 | test('Using a request object directly', async () => { 35 | expect.assertions(2) 36 | const req = new Request('https://httpbin.org/post', { 37 | headers: { 38 | Authorization: 'bearer the-access-token' 39 | }, 40 | method: 'POST' 41 | }) 42 | const resp = await fetch(req) 43 | expect(resp.status).toBe(200) 44 | const body = await resp.json() 45 | expect(body.headers.Authorization).toBe('bearer the-access-token') 46 | }) 47 | -------------------------------------------------------------------------------- /samples/jvm/gcp/src/main/java/com/example/gcp/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.example.gcp; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | 12 | @RestController 13 | @RequestMapping("/hello") 14 | public class HelloController { 15 | 16 | private static final Logger log = LoggerFactory.getLogger(HelloController.class); 17 | 18 | private int counter = 0; 19 | 20 | @GetMapping 21 | public String get(HttpServletRequest req){ 22 | return "hello new version from " + req.getLocalAddr(); 23 | } 24 | 25 | @GetMapping("/fault") 26 | public String getWithFault(HttpServletRequest req) { 27 | log.info("Handling get from {}", req.getRemoteAddr()); 28 | counter += 1; 29 | boolean fail = counter % 10 == 0; 30 | if(fail) throw new RuntimeException("failing"); 31 | return String.format("Hello from %s on iteration %d", req.getLocalAddr(), counter); 32 | } 33 | 34 | @GetMapping("/delay/{delay}") 35 | public String getDelay(HttpServletRequest req, @PathVariable("delay") int delay) throws InterruptedException { 36 | Thread.sleep(delay); 37 | return String.format("waited (%s)", req.getLocalAddr()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /demos/js/es-next-pl/classes.test.js: -------------------------------------------------------------------------------- 1 | test('simple class', () => { 2 | class Student { 3 | constructor (name, number) { 4 | this.name = name 5 | this.number = number 6 | } 7 | 8 | toString () { 9 | return `Student ${this.name} with number ${this.number}` 10 | } 11 | } 12 | 13 | const student = new Student('Alice', 12345) 14 | expect(student.toString()).toBe('Student Alice with number 12345') 15 | expect(typeof Student).toBe('function') 16 | }) 17 | 18 | test('Concrete class is a function', () => { 19 | class Student { 20 | constructor (name, number) { 21 | this.name = name 22 | this.number = number 23 | } 24 | 25 | toString () { 26 | return `Student ${this.name} with number ${this.number}` 27 | } 28 | } 29 | 30 | function f (TheClass, ...prms) { 31 | return new TheClass(...prms) 32 | } 33 | 34 | const student = f(Student, 'Alice', 12345) 35 | expect(student.toString()).toBe('Student Alice with number 12345') 36 | }) 37 | 38 | test('Class can extend', () => { 39 | class User { 40 | constructor (number) { 41 | this.number = number 42 | } 43 | } 44 | 45 | class Student extends User { 46 | constructor (name, number) { 47 | super(number) 48 | this.name = name 49 | } 50 | 51 | toString () { 52 | return `Student ${this.name} with number ${this.number}` 53 | } 54 | } 55 | 56 | const student = new Student('Alice', 12345) 57 | expect(student.toString()).toBe('Student Alice with number 12345') 58 | }) 59 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/commands/GetStudents.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples.commands; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Component; 6 | import pt.isel.daw.samples.*; 7 | 8 | import javax.inject.Provider; 9 | import java.sql.Connection; 10 | 11 | @Component 12 | public class GetStudents implements Command { 13 | 14 | private static final Logger log = LoggerFactory.getLogger(GetStudents.class); 15 | 16 | 17 | private final StudentsRepo studentsRepo; 18 | private final CourseRepo courseRepo; 19 | private final Provider anotherProvider; 20 | 21 | public GetStudents( 22 | StudentsRepo studentsRepo, 23 | CourseRepo courseRepo, 24 | Provider anotherProvider) { 25 | this.studentsRepo = studentsRepo; 26 | this.courseRepo = courseRepo; 27 | 28 | this.anotherProvider = anotherProvider; 29 | } 30 | 31 | @Override 32 | public CommandResult execute(CommandRequest req) { 33 | 34 | studentsRepo.doSomething(); 35 | // (...) 36 | courseRepo.doSomething(); 37 | 38 | 39 | anotherProvider.get(); 40 | anotherProvider.get(); 41 | 42 | return null; 43 | } 44 | 45 | @Override 46 | public String getPathTemplate() { 47 | return "/students"; 48 | } 49 | 50 | @Override 51 | public String getMethod() { 52 | return "GET"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /samples/js/es.next/rest-spread.test.js: -------------------------------------------------------------------------------- 1 | // functions 2 | test('rest operator in parameters', () => { 3 | function f (args) { 4 | return args 5 | } 6 | 7 | function g (...args) { 8 | return args 9 | } 10 | 11 | function h (a, ...args) { 12 | return args 13 | } 14 | 15 | expect(f(1, 2, 3, 4)).toEqual(1) 16 | expect(g(1, 2, 3, 4)).toEqual([1, 2, 3, 4]) 17 | expect(h(1, 2, 3, 4)).toEqual([2, 3, 4]) 18 | }) 19 | 20 | test('spread operator in calls', () => { 21 | function f (a, b, c) { 22 | return [a, b, c] 23 | } 24 | const arr = [1, 2, 3] 25 | expect(f(arr)).toEqual([[1, 2, 3], undefined, undefined]) 26 | expect(f(...arr)).toEqual([1, 2, 3]) 27 | }) 28 | 29 | // arrays 30 | test('rest operator in array deconstruction', () => { 31 | const arr = [1, 2, 3, 4] 32 | const [a, b, ...c] = arr 33 | expect(a).toBe(1) 34 | expect(b).toBe(2) 35 | expect(c).toEqual([3, 4]) 36 | }) 37 | 38 | test('spread operator in arrays', () => { 39 | const arr = [1, 2, 3] 40 | const res1 = [arr, arr] 41 | expect(res1).toEqual([[1, 2, 3], [1, 2, 3]]) 42 | const res2 = [...arr, ...arr] 43 | expect(res2).toEqual([1, 2, 3, 1, 2, 3]) 44 | }) 45 | 46 | // objects 47 | test('rest operator in object deconstruction', () => { 48 | const o = {a: 1, b: 2, c: 3, d: 4} 49 | const {a: x, b: y, ...z} = o 50 | expect(x).toBe(1) 51 | expect(y).toBe(2) 52 | expect(z).toEqual({c: 3, d: 4}) 53 | }) 54 | 55 | test('spread operator in objects', () => { 56 | const o1 = {a: 1, b: 2} 57 | const o2 = {...o1, c: 3} 58 | expect(o2).toEqual({a: 1, b: 2, c: 3}) 59 | }) 60 | -------------------------------------------------------------------------------- /samples/js/react/readme.md: -------------------------------------------------------------------------------- 1 | # Introduction to React # 2 | 3 | Create a project folder, do `npm init` and configure a Webpack and Babel based build environment. 4 | 5 | Do `npm install babel-preset-react --save-dev`to add the Babel support for JSX. 6 | 7 | Add `react` to the babel configuration inside the Webpack configuration 8 | 9 | ``` 10 | (...) 11 | use: { 12 | loader: 'babel-loader', 13 | options: { 14 | presets: ['env', 'react'] 15 | } 16 | } 17 | (...) 18 | ``` 19 | 20 | On the `index.html` file, add the following `div` somewhere inside the `body` 21 | 22 | ```html 23 |
24 | ``` 25 | 26 | This defines the HTML container element where React will render its elements. 27 | 28 | Define the following content on the `index.js` file. 29 | 30 | ```js 31 | import React from 'react' 32 | import ReactDOM from 'react-dom' 33 | 34 | ReactDOM.render( 35 | React.createElement('h1', {}, 'Hello World'), 36 | document.getElementById('root') 37 | ) 38 | ``` 39 | 40 | This does the following: 41 | * imports `React` and `ReactDOM` NPM modules. The first contains the DOM independent React supports, which is also used on React Native to build Android and iOS applications. The second contains the DOM specific functionality needed when using React on a browser. 42 | 43 | * Calls the `ReactDOM.render` function passing in a _react element_ and the DOM element where to add the react managed elements. 44 | 45 | * The _react element_ is created via the `React.createElement`. In this case it describes a `h1` HTML element with no attributes (the empty object passed as the second parameter) and with the `'Hello World'` child text. 46 | 47 | Run the project and observe the result. 48 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/ICalMessageConverter.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | import biweekly.Biweekly; 4 | import biweekly.ICalendar; 5 | import org.springframework.http.HttpInputMessage; 6 | import org.springframework.http.HttpOutputMessage; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.http.converter.AbstractGenericHttpMessageConverter; 9 | import org.springframework.http.converter.HttpMessageNotReadableException; 10 | import org.springframework.http.converter.HttpMessageNotWritableException; 11 | 12 | import java.io.IOException; 13 | import java.lang.reflect.Type; 14 | 15 | public class ICalMessageConverter extends AbstractGenericHttpMessageConverter { 16 | 17 | public ICalMessageConverter() { 18 | super(new MediaType("text","calendar")); 19 | } 20 | 21 | @Override 22 | public boolean supports(Class type) { 23 | 24 | return ICalendar.class.isAssignableFrom(type); 25 | } 26 | 27 | @Override 28 | protected void writeInternal(ICalendar iCalendar, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { 29 | Biweekly.write(iCalendar).go(outputMessage.getBody()); 30 | } 31 | 32 | @Override 33 | protected ICalendar readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { 34 | return null; 35 | } 36 | 37 | @Override 38 | public ICalendar read(Type type, Class contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { 39 | return null; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/src/main/java/pt/isel/daw/samples/MyDataSource.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import javax.sql.DataSource; 6 | import java.io.PrintWriter; 7 | import java.sql.Connection; 8 | import java.sql.SQLException; 9 | import java.sql.SQLFeatureNotSupportedException; 10 | import java.util.logging.Logger; 11 | 12 | 13 | public class MyDataSource implements DataSource { 14 | 15 | public MyDataSource() {} 16 | 17 | public void setConfiguration(String config) { 18 | // ... 19 | } 20 | 21 | @Override 22 | public Connection getConnection() throws SQLException { 23 | return null; 24 | } 25 | 26 | @Override 27 | public Connection getConnection(String username, String password) throws SQLException { 28 | return null; 29 | } 30 | 31 | @Override 32 | public T unwrap(Class iface) throws SQLException { 33 | return null; 34 | } 35 | 36 | @Override 37 | public boolean isWrapperFor(Class iface) throws SQLException { 38 | return false; 39 | } 40 | 41 | @Override 42 | public PrintWriter getLogWriter() throws SQLException { 43 | return null; 44 | } 45 | 46 | @Override 47 | public void setLogWriter(PrintWriter out) throws SQLException { 48 | 49 | } 50 | 51 | @Override 52 | public void setLoginTimeout(int seconds) throws SQLException { 53 | 54 | } 55 | 56 | @Override 57 | public int getLoginTimeout() throws SQLException { 58 | return 0; 59 | } 60 | 61 | @Override 62 | public Logger getParentLogger() throws SQLFeatureNotSupportedException { 63 | return null; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /demos/demos-spring-boot-0/src/main/java/pt/isel/daw/demosspringboot0/ResourceController.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.demosspringboot0; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | @RestController 9 | public class ResourceController { 10 | 11 | private static final Logger log = LoggerFactory.getLogger(ResourceController.class); 12 | 13 | private final Service1 svc1; 14 | 15 | public ResourceController(Service1 svc1) { 16 | this.svc1 = svc1; 17 | log.info("ctor"); 18 | } 19 | 20 | @GetMapping("/greetings") 21 | public String greetings() { 22 | return "yet another hello world"; 23 | } 24 | 25 | @GetMapping("/resource/{id}") 26 | public String get1(@PathVariable("id") String id) { 27 | return "the id is " + id; 28 | } 29 | 30 | @GetMapping("/add/{a}/{b}") 31 | public int add( 32 | @PathVariable("a") int a, 33 | @PathVariable("b") int b 34 | ){ 35 | return svc1.add(a,b); 36 | } 37 | 38 | @JsonInclude(JsonInclude.Include.NON_NULL) 39 | public static class OutputModel { 40 | public int i = 42; 41 | public String s = null; 42 | } 43 | 44 | @GetMapping("/ex1") 45 | public OutputModel get1(){ 46 | return new OutputModel(); 47 | } 48 | 49 | public static class InputModel { 50 | public int i; 51 | public String s; 52 | } 53 | 54 | @PostMapping("/ex2/{p}") 55 | public String post2( 56 | @PathVariable String p, 57 | @RequestBody InputModel input) { 58 | return input.s + input.i + p; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /demos/js/es-next-pl/async-await.test.js: -------------------------------------------------------------------------------- 1 | test('async function always return a promise', () => { 2 | expect.assertions(3) 3 | async function f () { 4 | return 2 5 | } 6 | const res = f() 7 | expect(res).not.toBe(2) 8 | expect(res.then).toBeDefined() 9 | return res.then(v => { 10 | expect(v).toBe(2) 11 | }) 12 | }) 13 | 14 | test('async function always return a promise of a value', () => { 15 | expect.assertions(3) 16 | async function f () { 17 | return Promise.resolve(2) 18 | } 19 | const res = f() 20 | expect(res).not.toBe(2) 21 | expect(res.then).toBeDefined() 22 | return res.then(v => { 23 | expect(v).toBe(2) 24 | }) 25 | }) 26 | 27 | test('async function always return a promise of a value', () => { 28 | expect.assertions(2) 29 | async function f () { 30 | throw new Error('the error') 31 | } 32 | const res = f() 33 | expect(res.then).toBeDefined() 34 | return res.catch(e => { 35 | expect(e.message).toBe('the error') 36 | }) 37 | }) 38 | 39 | function delay (result, time) { 40 | return new Promise((resolve, reject) => { 41 | setTimeout(() => resolve(result), time) 42 | }) 43 | } 44 | 45 | function log (msg) { 46 | console.log(`[${Date.now()}] ${msg}`) 47 | } 48 | 49 | test('await example', () => { 50 | async function f () { 51 | for (let i = 1; i < 5; ++i) { 52 | log(`step ${i}`) 53 | await delay(1, 100) 54 | } 55 | // log('step 1') 56 | // await delay(1, 100) 57 | // log('step 2') 58 | // await delay(1, 100) 59 | // log('step 3') 60 | // await delay(1, 100) 61 | // log('step 4') 62 | } 63 | 64 | log('before call') 65 | const p = f() 66 | log('after call') 67 | return p 68 | .then(v => { 69 | log(`final ${v}`) 70 | }) 71 | }) 72 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/ui/counter-example.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Counter from './counter' 3 | 4 | export default class extends React.Component { 5 | constructor (props) { 6 | super(props) 7 | this.state = {sum: 0, input: '0', inError: false} 8 | this.handleChange = this.handleChange.bind(this) 9 | this.handleInputChange = this.handleInputChange.bind(this) 10 | this.clearError = this.clearError.bind(this) 11 | } 12 | 13 | isDigit (c) { 14 | if (c.length === 0) return true 15 | for (let i = 0; i < c.length; ++i) { 16 | if (c[i] < '0' || c[i] > '9') return false 17 | } 18 | return true 19 | } 20 | 21 | handleChange (oldValue, newValue) { 22 | this.setState(old => ({sum: old.sum + (newValue - oldValue)})) 23 | } 24 | 25 | clearError () { 26 | this.setState({inError: false, abc: 1}) 27 | } 28 | 29 | handleInputChange (ev) { 30 | console.log('handleInputChange') 31 | if (!this.isDigit(ev.target.value)) { 32 | this.setState({inError: true}) 33 | if (this.timeout) clearTimeout(this.timeout) 34 | this.timeout = setTimeout(this.clearError, 3000) 35 | } else { 36 | if (this.timeout) clearTimeout(this.timeout) 37 | this.setState({input: ev.target.value, inError: false}) 38 | } 39 | } 40 | 41 | render () { 42 | return ( 43 |
44 | 45 | 46 | 47 |
48 |
{this.state.inError ? Only digits : }
49 | Sum is: {this.state.sum} 50 |
51 | ) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/ExampleInterceptor.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.lang.Nullable; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.web.method.HandlerMethod; 8 | import org.springframework.web.servlet.HandlerInterceptor; 9 | import org.springframework.web.servlet.HandlerMapping; 10 | import org.springframework.web.servlet.ModelAndView; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.util.Optional; 15 | 16 | @Component 17 | public class ExampleInterceptor implements HandlerInterceptor{ 18 | 19 | private static final Logger log = LoggerFactory.getLogger(ExampleInterceptor.class); 20 | 21 | @Override 22 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) 23 | throws Exception { 24 | String pattern = (String) Optional.ofNullable(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)) 25 | .orElse("[unknown]"); 26 | log.info("on preHandle for {}", pattern); 27 | HandlerMethod hm = (HandlerMethod) handler; 28 | RequiresAuthentication methodAnnotation = hm.getMethodAnnotation(RequiresAuthentication.class); 29 | if(methodAnnotation != null) { 30 | log.info("!!! Requires authentication !!!"); 31 | } 32 | return true; 33 | } 34 | 35 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, 36 | @Nullable ModelAndView modelAndView) throws Exception { 37 | log.info("on postHandle"); 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /demos/js/es-next/spread-rest.test.js: -------------------------------------------------------------------------------- 1 | test('rest operator on arrays', () => { 2 | function createArray () { 3 | return [1, 2, 3, 4] 4 | } 5 | 6 | const [first, second, ...remaining] = createArray() 7 | expect(first).toBe(1) 8 | expect(second).toBe(2) 9 | expect(remaining).toEqual([3, 4]) 10 | }) 11 | 12 | test('rest operator on objects', () => { 13 | function createStudent () { 14 | return { 15 | name: 'Alice', 16 | number: 12345, 17 | programme: 'LEIC', 18 | year: 2015 19 | } 20 | } 21 | 22 | const {name, number, ...remaining} = createStudent() 23 | expect(name).toBe('Alice') 24 | expect(number).toBe(12345) 25 | expect(remaining).toEqual({programme: 'LEIC', year: 2015}) 26 | }) 27 | 28 | test('rest operator on arguments', () => { 29 | function f (a, b, ...rem) { 30 | return rem 31 | } 32 | 33 | const res = f(1, 2, 3, 4) 34 | expect(res).toEqual([3, 4]) 35 | }) 36 | 37 | test('spread operator on arrays', () => { 38 | const a1 = [1, 2] 39 | const a2 = ['a', 'b'] 40 | const res1 = [a1, a2] 41 | const res2 = [...a1, ...a2] 42 | expect(res1).toEqual([[1, 2], ['a', 'b']]) 43 | expect(res2).toEqual([1, 2, 'a', 'b']) 44 | }) 45 | 46 | test('spread operator on objects', () => { 47 | const o1 = {name: 'Alice', number: 12345} 48 | const o2 = {programme: 'LEIC', year: 2015} 49 | const res = {...o1, ...o2} 50 | expect(res).toEqual({ 51 | name: 'Alice', 52 | number: 12345, 53 | programme: 'LEIC', 54 | year: 2015 55 | }) 56 | }) 57 | 58 | test('spream operator in calls', () => { 59 | function f (a, b, c, d) { 60 | return [a, b, c, d] 61 | } 62 | const arr = [1, 2, 3] 63 | const res = f(arr) 64 | expect(res).toEqual([[1, 2, 3], undefined, undefined, undefined]) 65 | const res2 = f(...arr) 66 | expect(res2).toEqual([1, 2, 3, undefined]) 67 | }) 68 | -------------------------------------------------------------------------------- /samples/jvm/cors/src/main/java/com/example/cors/DebugFilter.java: -------------------------------------------------------------------------------- 1 | package com.example.cors; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.servlet.*; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.Collection; 12 | import java.util.Collections; 13 | import java.util.function.Function; 14 | 15 | @Component 16 | public class DebugFilter implements Filter { 17 | 18 | private static final Logger log = LoggerFactory.getLogger(DebugFilter.class); 19 | 20 | @Override 21 | public void init(FilterConfig filterConfig) throws ServletException { 22 | 23 | } 24 | 25 | @Override 26 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 27 | HttpServletRequest hreq = (HttpServletRequest) request; 28 | HttpServletResponse hres = (HttpServletResponse) response; 29 | log.info("\nrequest {} on {} with headers \n{} ", hreq.getMethod(), hreq.getRequestURI(), 30 | headers(Collections.list(hreq.getHeaderNames()), hreq::getHeader)); 31 | 32 | chain.doFilter(request, response); 33 | 34 | log.info("\nresponse {} with headers \n{}", hres.getStatus(), headers(hres.getHeaderNames(), hres::getHeader)); 35 | } 36 | 37 | private String headers(Collection headerNames, Function getHeader) { 38 | StringBuffer buf = new StringBuffer(); 39 | for(String name : headerNames) { 40 | buf.append(name).append(":").append(getHeader.apply(name)).append("\n"); 41 | } 42 | return buf.toString(); 43 | } 44 | 45 | @Override 46 | public void destroy() { 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /samples/jvm/cors/src/main/java/com/example/cors/CorsApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.cors; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.config.BeanPostProcessor; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; 8 | import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.web.cors.CorsConfiguration; 11 | import org.springframework.web.cors.CorsProcessor; 12 | import org.springframework.web.servlet.DispatcherServlet; 13 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 14 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 15 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; 16 | 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import java.io.IOException; 20 | 21 | @SpringBootApplication 22 | public class CorsApplication { 23 | 24 | public static void main(String[] args) { 25 | 26 | SpringApplication.run(CorsApplication.class, args); 27 | } 28 | 29 | @Bean 30 | WebMvcConfigurer mvcConfig() { 31 | return new WebMvcConfigurer() { 32 | @Override 33 | public void addCorsMappings(CorsRegistry registry) { 34 | registry.addMapping("/**") 35 | .allowedOrigins("https://www.isel.pt", "https://developer.mozilla.org") 36 | .allowedHeaders("Some-Header", "Authorization") 37 | .allowCredentials(false); 38 | 39 | 40 | } 41 | }; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom' 3 | 4 | import Line from './ui/line' 5 | import Clock from './ui/clock' 6 | import ShowHide from './ui/ShowHide' 7 | import App from './ui/App' 8 | 9 | function demo0 () { 10 | const tree = React.createElement('div', {}, 11 | React.createElement('h2', {}, 'Rendered by React'), 12 | React.createElement('p', {}, 'Some paragraph') 13 | ) 14 | 15 | ReactDOM.render(tree, document.getElementById('root')) 16 | } 17 | 18 | function demo1 () { 19 | setInterval(tick, 1000) 20 | function tick () { 21 | const date = new Date() 22 | const seconds = date.getSeconds() 23 | const line = [...new Array(seconds).keys()].map(i => React.createElement('span', {}, ` (${i}) `)) 24 | const tree = React.createElement('div', {}, 25 | React.createElement('h2', {}, 'Clock'), 26 | React.createElement('p', {}, date.toLocaleString()), 27 | React.createElement('p', {}, line) 28 | ) 29 | ReactDOM.render(tree, document.getElementById('root')) 30 | } 31 | } 32 | 33 | function demo2 () { 34 | setInterval(tick, 1000) 35 | function tick () { 36 | const date = new Date() 37 | const seconds = date.getSeconds() 38 | const tree =
39 |

Clock

40 |

{date.toLocaleString()}

41 |

42 |
43 | ReactDOM.render(tree, document.getElementById('root')) 44 | } 45 | } 46 | 47 | function demo3 () { 48 | ReactDOM.render( 49 |
50 |

The clock

51 |

Before the clock

52 | 53 |

After the clock

54 |
, 55 | document.getElementById('root') 56 | ) 57 | } 58 | 59 | function demo4 () { 60 | ReactDOM.render( 61 | , 62 | document.getElementById('root') 63 | ) 64 | } 65 | 66 | // demo to run 67 | demo4() 68 | -------------------------------------------------------------------------------- /samples/js/es.next/promises.test.js: -------------------------------------------------------------------------------- 1 | test('promise creation from callbacks', done => { 2 | function delay (ms) { 3 | return new Promise((resolve, reject) => { 4 | setTimeout(() => resolve(42), 1000) 5 | }) 6 | } 7 | 8 | let a = 1 9 | delay(100) 10 | .then(r => { 11 | expect(a).toBe(2) 12 | expect(r).toBe(42) 13 | done() 14 | }) 15 | a = 2 16 | expect(a).toBe(2) 17 | }) 18 | 19 | function delay (result, delay) { 20 | return new Promise((resolve, reject) => { 21 | setTimeout(() => resolve(typeof result === 'function' ? result() : result), delay) 22 | }) 23 | } 24 | 25 | test('promise chaining - map', done => { 26 | delay(42, 100) 27 | .then(r => r + 1) 28 | .then(r => r + 1) 29 | .then(r => { 30 | expect(r).toBe(44) 31 | done() 32 | }) 33 | }) 34 | 35 | test('promise chaining - flatMap', done => { 36 | delay(42, 100) 37 | .then(r => delay(r + 1, 100)) 38 | .then(r => delay(r + 1, 100)) 39 | .then(r => { 40 | expect(r).toBe(44) 41 | done() 42 | }) 43 | }) 44 | 45 | test('promise chaining and errors', done => { 46 | let state = 0 47 | let incrState = () => { state += 1 } 48 | delay(42, 100) 49 | .then(() => incrState()) 50 | .then(() => incrState()) 51 | .then(() => { throw new Error() }) 52 | .then(() => incrState()) 53 | .then(() => incrState()) 54 | .catch(e => { 55 | expect(state).toBe(2) 56 | done() 57 | }) 58 | }) 59 | 60 | test('Promise.all', done => { 61 | let state = 0 62 | let incrState = () => { state += 1 } 63 | Promise.all([delay(incrState, 100), delay(incrState, 200)]) 64 | .then(() => { 65 | expect(state).toBe(2) 66 | done() 67 | }) 68 | }) 69 | 70 | test('Promise.race', done => { 71 | let state = 0 72 | let incrState = () => { state += 1 } 73 | Promise.race([delay(incrState, 100), delay(incrState, 200)]) 74 | .then(() => { 75 | expect(state).toBe(1) 76 | done() 77 | }) 78 | }) 79 | -------------------------------------------------------------------------------- /demos/js/es-next/promises.test.js: -------------------------------------------------------------------------------- 1 | const fetch = require('isomorphic-fetch') 2 | 3 | test('Promise creation', () => { 4 | function delay (result, time) { 5 | return new Promise((resolve, reject) => { 6 | setTimeout(() => resolve(result), time) 7 | }) 8 | } 9 | 10 | console.log(Date.now()) 11 | return delay(1, 100) 12 | .then(_ => { 13 | console.log(Date.now()) 14 | return delay(1, 100) 15 | }) 16 | .then(_ => { 17 | console.log(Date.now()) 18 | }) 19 | }) 20 | 21 | test = function(){} 22 | 23 | test('Simple futures example', () => { 24 | expect.assertions(1) 25 | return fetch('https://api.github.com/users/pedrofelix') 26 | .then(resp => resp.json()) 27 | .then(body => fetch(body.repos_url)) 28 | .then(resp => resp.json()) 29 | .then(body => { 30 | expect(body[0].name).toBe('CompSec-CodeSamples') 31 | }) 32 | }) 33 | 34 | test('Simple catch example', () => { 35 | return fetch('https://api.github.com/users/pedrofelix12345') 36 | .then(resp => resp.json()) 37 | .then(body => fetch(body.repos_url)) 38 | .then(resp => resp.json()) 39 | .then(body => { 40 | expect(body[0].name).toBe('CompSec-CodeSamples') 41 | }) 42 | .catch(e => {}) 43 | }) 44 | 45 | test('Promises.all example', () => { 46 | const f1 = fetch('https://api.github.com/users/pedrofelix') 47 | const f2 = fetch('https://api.github.com/users/pmhsfelix') 48 | const res = Promise.all([f1, f2]) 49 | return res 50 | .then((resps) => Promise.all(resps.map(resp => resp.json()))) 51 | .then(([b1, b2]) => { 52 | expect(b1.type).toBe('User') 53 | expect(b2.type).toBe('User') 54 | }) 55 | }) 56 | 57 | test('Promises.race example', () => { 58 | const f1 = fetch('https://api.github.com/users/pedrofelix') 59 | const f2 = fetch('https://api.github.com/users/pmhsfelix') 60 | const res = Promise.race([f1, f2]) 61 | return res 62 | .then(resp => { 63 | expect(resp.status).toBe(403) 64 | return resp.json() 65 | }) 66 | .then(body => { 67 | console.log(body) 68 | expect(body.login).toBe('pedrofelix') 69 | }) 70 | }) 71 | -------------------------------------------------------------------------------- /demos/js/es-next-pl/destructuring.test.js: -------------------------------------------------------------------------------- 1 | test('simple destructuring for objects', () => { 2 | function createStudent (name, number) { 3 | return { 4 | name: name, 5 | number: number 6 | } 7 | } 8 | 9 | const {name, number} = createStudent('Alice', 12345) 10 | // const obj = createStudent('Alice', 12345) 11 | // const name = obj.name 12 | // const number = obj.number 13 | expect(name).toBe('Alice') 14 | expect(number).toBe(12345) 15 | }) 16 | 17 | test('simple destructuring for objects', () => { 18 | function createArray () { 19 | return [1, 2, 3, 4] 20 | } 21 | 22 | const [first, second] = createArray() 23 | // const obj = createStudent('Alice', 12345) 24 | // const name = obj.name 25 | // const number = obj.number 26 | expect(first).toBe(1) 27 | expect(second).toBe(2) 28 | }) 29 | 30 | test('destructuring with renaming for objects', () => { 31 | function createStudent (name, number) { 32 | return { 33 | name: name, 34 | number: number 35 | } 36 | } 37 | 38 | const {name: studentName, number: studentNumber} = createStudent('Alice', 12345) 39 | expect(studentName).toBe('Alice') 40 | expect(studentNumber).toBe(12345) 41 | }) 42 | 43 | test('more complex destructuring for objects', () => { 44 | function createStudent (name, number) { 45 | return { 46 | name: name, 47 | number: number, 48 | programme: { 49 | name: 'LEIC', 50 | year: 2015 51 | }, 52 | enrollments: [2015, 2016] 53 | } 54 | } 55 | 56 | const {name, number, programme: {name: pname, year}, enrollments: [first]} = createStudent('Alice', 12345) 57 | expect(name).toBe('Alice') 58 | expect(number).toBe(12345) 59 | expect(pname).toBe('LEIC') 60 | expect(year).toBe(2015) 61 | expect(first).toBe(2015) 62 | }) 63 | 64 | test('destructuring in parameters', () => { 65 | function createStudent (name, number) { 66 | return { 67 | name: name, 68 | number: number 69 | } 70 | } 71 | 72 | function show ({name, number}) { 73 | return `Student ${name} with number ${number}` 74 | } 75 | 76 | expect(show(createStudent('Alice', 12345))).toBe('Student Alice with number 12345') 77 | }) 78 | -------------------------------------------------------------------------------- /demos/js/es-next-pl/rest-spread.test.js: -------------------------------------------------------------------------------- 1 | test('rest oper in arrays', () => { 2 | const arr = [1, 2, 3, 4] 3 | const [a, b, c] = arr 4 | const [x, y, ...z] = arr 5 | 6 | expect(c).toBe(3) 7 | expect(z).toEqual([3, 4]) 8 | 9 | expect(a).toBe(1) 10 | expect(x).toBe(1) 11 | expect(b).toBe(2) 12 | expect(y).toBe(2) 13 | }) 14 | 15 | test('rest oper in objects', () => { 16 | function createStudent (name, number) { 17 | return { 18 | name: name, 19 | number: number, 20 | programme: 'LEIC', 21 | year: 2015 22 | } 23 | } 24 | 25 | const {name, number, ...rem} = createStudent('Alice', 12345) 26 | 27 | expect(name).toBe('Alice') 28 | expect(number).toBe(12345) 29 | expect(rem).toEqual({ 30 | programme: 'LEIC', 31 | year: 2015 32 | 33 | }) 34 | }) 35 | 36 | test('rest operator in functions', () => { 37 | function f (a, b, ...rem) { 38 | return [a, b, rem] 39 | } 40 | 41 | const res = f(1, 2, 3, 4, 5) 42 | expect(res).toEqual([1, 2, [3, 4, 5]]) 43 | }) 44 | 45 | test('spread oper in arrays', () => { 46 | const a1 = [1, 2] 47 | const a2 = ['a', 'b'] 48 | const res1 = [a1, a2] 49 | const res2 = [...a1, ...a2] 50 | 51 | expect(res1).toEqual([[1, 2], ['a', 'b']]) 52 | expect(res2).toEqual([1, 2, 'a', 'b']) 53 | }) 54 | 55 | test('spread oper in objects', () => { 56 | const student = {name: 'Alice', number: 12345} 57 | const programme = {programName: 'LEIC', year: 2015} 58 | 59 | const res1 = {student, programme} 60 | const res2 = {...student, ...programme} 61 | expect(res1).toEqual({ 62 | student: { 63 | name: 'Alice', 64 | number: 12345 65 | }, 66 | programme: { 67 | programName: 'LEIC', 68 | year: 2015 69 | } 70 | }) 71 | expect(res2).toEqual({ 72 | name: 'Alice', 73 | number: 12345, 74 | programName: 'LEIC', 75 | year: 2015 76 | }) 77 | }) 78 | 79 | test('spread in functions', () => { 80 | function f (a, b, c, d) { 81 | return [a, b, c, d] 82 | } 83 | 84 | const a1 = [1, 2] 85 | const a2 = ['a', 'b'] 86 | // const res1 = f(student, programme) 87 | const res2 = f(...a1, ...a2) 88 | expect(res2).toEqual([ 89 | 1, 2, 'a', 'b' 90 | ]) 91 | }) 92 | -------------------------------------------------------------------------------- /samples/js/es.next/classes.test.js: -------------------------------------------------------------------------------- 1 | class Student { 2 | // constructor has a special name 3 | constructor (name, number) { 4 | this.name = name 5 | this.number = number 6 | } 7 | 8 | // methods don't need any special keyword 9 | toString () { return `Student '${this.name}' with number ${this.number}` } 10 | } 11 | 12 | test('simple class', () => { 13 | const student = new Student('Alice', 12345) 14 | expect(student.toString()).toEqual('Student \'Alice\' with number 12345') 15 | }) 16 | 17 | test('class is a function', () => { 18 | expect(typeof Student).toBe('function') 19 | expect(Student.prototype.toString).toBeDefined() 20 | }) 21 | 22 | test('result is an object with only the defined fields ', () => { 23 | const student = new Student('Alice', 12345) 24 | expect(Object.getOwnPropertyNames(student).length).toBe(2) 25 | expect(Object.getOwnPropertyNames(student)).toEqual(['name', 'number']) 26 | }) 27 | 28 | // not ethat this is an "asynchronous" test 29 | test('beware of this', done => { 30 | class SomeClass { 31 | constructor () { 32 | this.field = 42 33 | setTimeout(this.someMethod, 10) 34 | } 35 | someMethod () { 36 | expect(this.field).toBe(undefined) 37 | done() 38 | } 39 | } 40 | const o = new SomeClass() 41 | expect(o.field).toBe(42) 42 | }) 43 | 44 | test('Since class definitions are expression, some unusual things are possible', () => { 45 | const showable = aClass => class extends aClass { 46 | equals (other) { 47 | if (this.constructor !== other.constructor) return false 48 | for (let name of Object.getOwnPropertyNames(this)) { 49 | if (this[name] !== other[name]) return false 50 | return true 51 | } 52 | } 53 | } 54 | 55 | // yes, this is perfectly valid Javascript 56 | // notice that the function argument is a class 57 | const SomeClass = showable(class { 58 | constructor (a, b) { 59 | this.a = a 60 | this.b = b 61 | } 62 | }) 63 | 64 | const o1 = new SomeClass(1, 2) 65 | const o2 = new SomeClass(1, 2) 66 | const o3 = new SomeClass(2, 3) 67 | expect(o1.equals(o2)).toBeTruthy() 68 | expect(o2.equals(o3)).toBeFalsy() 69 | expect(o3.equals(42)).toBeFalsy() 70 | }) 71 | -------------------------------------------------------------------------------- /demos/js/es-next-pl/promises.test.js: -------------------------------------------------------------------------------- 1 | const fetch = require('isomorphic-fetch') 2 | 3 | const ignore = () => {} 4 | 5 | ignore('promises', () => { 6 | return fetch('https://api.github.com/users/pedrofelix') 7 | .then(resp => resp.json()) 8 | .then(body => fetch(body.repos_url)) 9 | .then(resp => resp.json()) 10 | .then(body => { 11 | console.log(body[0].name) 12 | expect(body[0].name).toBe('CompSec-CodeSamples') 13 | }) 14 | }) 15 | 16 | function delay (result, time) { 17 | return new Promise((resolve, reject) => { 18 | setTimeout(() => { 19 | resolve(result) 20 | }, time) 21 | }) 22 | } 23 | 24 | ignore('Promise creation', () => { 25 | function showAndIncrement (i) { 26 | console.log(Date.now()) 27 | return delay(i + 1, 100) 28 | } 29 | 30 | return delay(1, 100) 31 | .then(r => showAndIncrement(r)) 32 | .then(r => showAndIncrement(r)) 33 | .then(r => showAndIncrement(r)) 34 | }) 35 | 36 | ignore('promise chaining and errors', () => { 37 | let state = 0 38 | let incrState = () => { state += 1 } 39 | return delay(42, 100) 40 | .then(() => incrState()) 41 | .then(() => incrState()) 42 | .then(() => { throw new Error() }) 43 | .then(() => incrState()) 44 | .then(() => incrState()) 45 | .catch(e => { 46 | expect(state).toBe(2) 47 | }) 48 | }) 49 | 50 | test('Promise.all', () => { 51 | console.log(Date.now()) 52 | const p1 = delay(1, 2000) 53 | const p2 = delay(2, 1000) 54 | return Promise.all([p1, p2]) 55 | .then(([v1, v2]) => { 56 | console.log(Date.now()) 57 | expect(v1).toBe(1) 58 | expect(v2).toBe(2) 59 | }) 60 | }) 61 | 62 | test('Promise.all with rejection', () => { 63 | console.log(Date.now()) 64 | const p1 = delay(1, 2000) 65 | const p2 = delay(2, 1000) 66 | const p3 = Promise.reject(new Error('the error')) 67 | return Promise.all([p1, p2, p3]) 68 | .then(([v1, v2]) => { 69 | console.log(Date.now()) 70 | expect(true).toBeFalsy() 71 | }) 72 | .catch(e => { 73 | console.log(Date.now()) 74 | expect(e.message).toBe('the error') 75 | }) 76 | }) 77 | 78 | test('Promise.race', () => { 79 | console.log(Date.now()) 80 | const p1 = delay(1, 2000) 81 | const p2 = delay(2, 1000) 82 | return Promise.race([p1, p2]) 83 | .then(v => { 84 | console.log(Date.now()) 85 | expect(v).toBe(2) 86 | }) 87 | }) 88 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/SampleSpringBoot0Application.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.core.Ordered; 7 | import org.springframework.web.method.HandlerMethod; 8 | import org.springframework.web.method.support.InvocableHandlerMethod; 9 | import org.springframework.web.servlet.HandlerAdapter; 10 | import org.springframework.web.servlet.HandlerExecutionChain; 11 | import org.springframework.web.servlet.HandlerMapping; 12 | import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer; 13 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 14 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 15 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 16 | import org.springframework.web.servlet.mvc.method.annotation.*; 17 | import springfox.documentation.builders.PathSelectors; 18 | import springfox.documentation.builders.RequestHandlerSelectors; 19 | import springfox.documentation.spi.DocumentationType; 20 | import springfox.documentation.spring.web.plugins.Docket; 21 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 22 | 23 | import javax.servlet.http.HttpServletRequest; 24 | import java.lang.reflect.Method; 25 | import java.util.Collections; 26 | 27 | @SpringBootApplication 28 | @EnableSwagger2 29 | public class SampleSpringBoot0Application { 30 | 31 | public static void main(String[] args) { 32 | SpringApplication.run(SampleSpringBoot0Application.class, args); 33 | } 34 | 35 | @Bean 36 | public ICalMessageConverter iCalConverter() { 37 | return new ICalMessageConverter(); 38 | } 39 | 40 | @Bean 41 | public Docket api() { 42 | return new Docket(DocumentationType.SWAGGER_2) 43 | .select() 44 | .apis(RequestHandlerSelectors.any()) 45 | .paths(PathSelectors.any()) 46 | .build(); 47 | } 48 | 49 | @Bean 50 | public WebMvcConfigurer corsConfigurer() { 51 | return new WebMvcConfigurer() { 52 | @Override 53 | public void addCorsMappings(CorsRegistry registry) { 54 | registry.addMapping("/**").allowedOrigins("http://localhost:9000").allowCredentials(true); 55 | } 56 | }; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/src/main/java/pt/isel/daw/samples/RequestScope.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.ObjectFactory; 6 | import org.springframework.beans.factory.config.Scope; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | @Component 13 | public class RequestScope implements Scope { 14 | 15 | private static Logger log = LoggerFactory.getLogger(RequestScope.class); 16 | 17 | private static final ThreadLocal> beanMap = 18 | ThreadLocal.withInitial(() -> new HashMap<>()); 19 | 20 | private static final ThreadLocal> destructionMap = 21 | ThreadLocal.withInitial(() -> new HashMap<>()); 22 | 23 | @Override 24 | public Object get(String name, ObjectFactory objectFactory) { 25 | // get the map associated to the current thread 26 | // no concurrent access exists, since we are using a different map per thread 27 | Map mapForThisThread = beanMap.get(); 28 | 29 | Object obj = mapForThisThread.get(name); 30 | if(obj != null) { 31 | log.info("get {} resolved from scope", name); 32 | return obj; 33 | } 34 | obj = objectFactory.getObject(); 35 | mapForThisThread.put(name, obj); 36 | log.info("get {} resolved from factory", name); 37 | return obj; 38 | } 39 | 40 | @Override 41 | public Object remove(String name) { 42 | beanMap.get().remove(name); 43 | return null; 44 | } 45 | 46 | @Override 47 | public void registerDestructionCallback(String name, Runnable callback) { 48 | log.info("registering destruction callback for {}: {}", name, callback); 49 | destructionMap.get().put(name, callback); 50 | } 51 | 52 | @Override 53 | public Object resolveContextualObject(String key) { 54 | return null; 55 | } 56 | 57 | @Override 58 | public String getConversationId() { 59 | return null; 60 | } 61 | 62 | public void destroyRequestScopedBeans() { 63 | Map destructionMapForThisThread = destructionMap.get(); 64 | for(Map.Entry e : destructionMapForThisThread.entrySet()) { 65 | log.info("destroying {}", e.getKey()); 66 | e.getValue().run(); 67 | } 68 | destructionMapForThisThread.clear(); 69 | beanMap.get().clear(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /samples/jvm/gcp/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/jvm/cors/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /demos/demos-spring-boot-0/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/jvm/daw-spring-1/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /demos/sample-spring-boot-pl-0/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-0/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /demos/examples-spring-context-0/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /demos/samples-spring-context-pl-0/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /demos/sample-spring-boot-pl-0/src/main/java/pt/isel/daw/samplespringbootpl0/ExampleController.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringbootpl0; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import org.springframework.http.HttpHeaders; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.util.MultiValueMap; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import java.util.Optional; 12 | import java.util.stream.Collectors; 13 | 14 | @RestController 15 | @RequestMapping("/examples") 16 | public class ExampleController { 17 | 18 | private final Service1 svc; 19 | 20 | public ExampleController(Service1 svc) { 21 | 22 | this.svc = svc; 23 | } 24 | 25 | @GetMapping("/ex1/{id}") 26 | public String get( 27 | @PathVariable("id") int id, 28 | @RequestParam("name") Optional name 29 | 30 | ){ 31 | return String.format( 32 | "hello world with id=%d and name=%s", 33 | id, 34 | name.orElse("[absent]")); 35 | } 36 | 37 | @GetMapping("/ex2") 38 | public String get2( 39 | @RequestParam 40 | MultiValueMap qs 41 | 42 | ) { 43 | return qs.entrySet().stream() 44 | .map(e -> e.getKey() + "->" + e.getValue()) 45 | .collect(Collectors.joining()); 46 | } 47 | 48 | 49 | 50 | @JsonInclude(JsonInclude.Include.NON_NULL) 51 | public static class OutputModel { 52 | public int i = 42; 53 | public String s = null; 54 | @JsonProperty("another-field") 55 | public String anotherField = "another"; 56 | } 57 | 58 | @GetMapping("/ex3") 59 | public OutputModel get3() { 60 | return new OutputModel(); 61 | } 62 | 63 | public static class InputModel { 64 | public int i; 65 | public String s; 66 | } 67 | 68 | @PostMapping("/ex4/{path}") 69 | public String post4( 70 | @PathVariable("path") String path, 71 | @RequestBody InputModel im 72 | ) { 73 | return im.s + im.i + path; 74 | } 75 | 76 | @PostMapping("/ex5/{path}") 77 | public ResponseEntity post5( 78 | @PathVariable("path") String path, 79 | @RequestBody InputModel im 80 | ) { 81 | String s = im.s + im.i + path; 82 | HttpHeaders headers = new HttpHeaders(); 83 | headers.add("My-Header", "My-Value"); 84 | ResponseEntity res = 85 | new ResponseEntity(new OutputModel(), headers, HttpStatus.CREATED); 86 | return res; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /demos/js/react/js/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom' 3 | import Clock from './ui/clock' 4 | import App from './ui/app' 5 | 6 | function example0 () { 7 | const tree = React.createElement('div', {}, 8 | React.createElement('h2', {}, 'Example'), 9 | React.createElement('p', {}, 'Some paragraph')) 10 | 11 | ReactDOM.render(tree, document.getElementById('root')) 12 | } 13 | 14 | function example1 () { 15 | setInterval(update, 1000) 16 | function update () { 17 | const date = new Date() 18 | const seconds = date.getSeconds() 19 | const line = [...Array(seconds).keys()].map(i => React.createElement('span', {}, `(${i})`)) 20 | const tree = React.createElement('div', {}, 21 | React.createElement('h2', {}, 'Example'), 22 | React.createElement('p', {}, 'Some paragraph'), 23 | React.createElement('p', {}, date.toLocaleString()), 24 | React.createElement('div', {}, line) 25 | ) 26 | ReactDOM.render(tree, document.getElementById('root')) 27 | } 28 | } 29 | 30 | function example2 () { 31 | setInterval(update, 1000) 32 | 33 | function Line ({count}) { 34 | return React.createElement('div', {}, 35 | [...Array(count).keys()].map(i => React.createElement('span', {}, `(${i})`))) 36 | } 37 | 38 | function update () { 39 | const date = new Date() 40 | const seconds = date.getSeconds() 41 | const tree = React.createElement('div', {}, 42 | React.createElement('h2', {}, 'Example'), 43 | React.createElement('p', {}, 'Some paragraph'), 44 | React.createElement('p', {}, date.toLocaleString()), 45 | React.createElement(Line, {count: seconds}), 46 | React.createElement(Line, {count: seconds}) 47 | ) 48 | ReactDOM.render(tree, document.getElementById('root')) 49 | } 50 | } 51 | 52 | // JSX - extension to JS 53 | function example3 () { 54 | setInterval(update, 1000) 55 | 56 | function Line ({count}) { 57 | return React.createElement('div', {}, 58 | [...Array(count).keys()].map(i => React.createElement('span', {}, `(${i})`))) 59 | } 60 | 61 | function update () { 62 | const date = new Date() 63 | const seconds = date.getSeconds() 64 | const tree =
65 |

Example 3

66 |

Some paragraph

67 |

{date.toLocaleString()}

68 | 69 | 70 | 71 | 72 |
73 | ReactDOM.render(tree, document.getElementById('root')) 74 | } 75 | } 76 | 77 | function example4 () { 78 | setInterval(update, 1000) 79 | 80 | function update () { 81 | const date = new Date() 82 | ReactDOM.render(, 83 | document.getElementById('root')) 84 | } 85 | } 86 | 87 | function example5 () { 88 | ReactDOM.render( 89 | , 90 | document.getElementById('root') 91 | ) 92 | } 93 | 94 | example5() 95 | -------------------------------------------------------------------------------- /samples/jvm/sample-spring-boot-0/src/main/java/pt/isel/daw/samplespringboot0/MvcConfig.java: -------------------------------------------------------------------------------- 1 | package pt.isel.daw.samplespringboot0; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.core.Ordered; 7 | import org.springframework.http.converter.HttpMessageConverter; 8 | import org.springframework.web.method.HandlerMethod; 9 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 10 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 11 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 12 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 13 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; 14 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; 15 | import org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod; 16 | 17 | import java.util.List; 18 | 19 | //@Configuration 20 | public class MvcConfig extends WebMvcConfigurationSupport { 21 | 22 | private final ExampleInterceptor interceptor; 23 | private final ICalMessageConverter icalMessageConverter; 24 | 25 | // do not forget to explain this ctor 26 | public MvcConfig( 27 | ExampleInterceptor interceptor, 28 | ICalMessageConverter icalMessageConverter) { 29 | 30 | this.interceptor = interceptor; 31 | this.icalMessageConverter = icalMessageConverter; 32 | } 33 | 34 | @Override 35 | public void addInterceptors(InterceptorRegistry registry) { 36 | registry.addInterceptor(interceptor); 37 | } 38 | 39 | @Override 40 | public void addArgumentResolvers(List resolvers) { 41 | //resolvers.add(new QueryStringArgumentResolver()); 42 | resolvers.add(new ClientIpArgumentResolver()); 43 | } 44 | 45 | @Override 46 | public void extendMessageConverters(List> converters) { 47 | converters.add(icalMessageConverter); 48 | } 49 | 50 | @Override 51 | protected RequestMappingHandlerAdapter createRequestMappingHandlerAdapter() { 52 | return new MyRequestMappingHandlerAdapter(); 53 | } 54 | 55 | private static class MyRequestMappingHandlerAdapter extends RequestMappingHandlerAdapter { 56 | 57 | @Override 58 | protected ServletInvocableHandlerMethod createInvocableHandlerMethod(HandlerMethod handlerMethod) { 59 | return new MyServletInvocableHandlerMethod(handlerMethod); 60 | } 61 | } 62 | 63 | private static class MyServletInvocableHandlerMethod extends ServletInvocableHandlerMethod { 64 | 65 | private static final Logger log = LoggerFactory.getLogger(MyServletInvocableHandlerMethod.class); 66 | 67 | public MyServletInvocableHandlerMethod(HandlerMethod handlerMethod) { 68 | super(handlerMethod); 69 | } 70 | 71 | @Override 72 | protected Object doInvoke(Object... args) throws Exception { 73 | for(Object arg : args) { 74 | if(arg == null) continue; 75 | log.info("parameter: {} -> {}", arg.getClass().getSimpleName(), arg); 76 | } 77 | return super.doInvoke(args); 78 | } 79 | } 80 | 81 | 82 | } 83 | -------------------------------------------------------------------------------- /demos/js/react-pl/js/ui/issue-list.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import fetch from 'isomorphic-fetch' 3 | 4 | import IssueStateFilterPanel from './issue-state-filter-panel' 5 | import PaginatorPanel from './paginator-panel' 6 | 7 | const FetchStates = { 8 | loading: 'loading', 9 | loaded: 'loaded', 10 | error: 'error' 11 | } 12 | 13 | export default class extends React.Component { 14 | // props = {url} 15 | constructor (props) { 16 | super(props) 17 | this.state = { 18 | fetchState: FetchStates.loading, 19 | queryString: '' 20 | } 21 | this.handleFilterChange = this.handleFilterChange.bind(this) 22 | this.handlePagination = this.handlePagination.bind(this) 23 | } 24 | 25 | static getDerivedStateFromProps (nextProps, prevState) { 26 | return { 27 | fetchState: FetchStates.loading, 28 | url: undefined 29 | } 30 | } 31 | 32 | componentDidMount () { 33 | this.loadIfNeeded() 34 | } 35 | 36 | componentDidUpdate () { 37 | this.loadIfNeeded() 38 | } 39 | 40 | loadIfNeeded () { 41 | if (this.state.fetchState !== FetchStates.loading) return 42 | const url = this.state.url || (this.props.url + '?' + this.state.queryString) 43 | console.log(url) 44 | return fetch(url) 45 | .then(resp => { 46 | if (resp.status !== 200) { 47 | throw new Error() 48 | } 49 | return resp.json().then(json => { 50 | this.setState({ 51 | fetchState: FetchStates.loaded, 52 | json: json, 53 | response: resp 54 | }) 55 | }) 56 | }) 57 | .catch(error => { 58 | this.setState({fetchState: FetchStates.error, error: error}) 59 | }) 60 | } 61 | 62 | handleFilterChange (value) { 63 | console.log('handleFilterChange') 64 | this.setState({ 65 | queryString: value, 66 | url: undefined, 67 | fetchState: FetchStates.loading 68 | }) 69 | } 70 | 71 | handlePagination (url) { 72 | this.setState({ 73 | url: url, 74 | fetchState: FetchStates.loading 75 | }) 76 | } 77 | 78 | render () { 79 | return ( 80 |
81 |
82 | 85 | 86 |
87 | {this.renderContent()} 88 |
89 | ) 90 | } 91 | 92 | renderContent () { 93 | switch (this.state.fetchState) { 94 | case FetchStates.loading: 95 | return this.renderLoading() 96 | case FetchStates.loaded: 97 | return this.renderLoaded() 98 | case FetchStates.error: 99 | return this.renderError() 100 | } 101 | } 102 | 103 | renderLoading () { 104 | return
... loading ...
105 | } 106 | 107 | renderLoaded () { 108 | const issues = this.state.json 109 | const style = { 110 | marginTop: '10px' 111 | } 112 | return ( 113 |
114 | {issues.map(issue =>
{issue.state}-{issue.title}
)} 115 |
116 | ) 117 | } 118 | 119 | renderError () { 120 | return
ERROR
121 | } 122 | } 123 | -------------------------------------------------------------------------------- /demos/js/es-next/classes.test.js: -------------------------------------------------------------------------------- 1 | test('simple class', () => { 2 | class Student { 3 | constructor (name, number) { 4 | this.name = name 5 | this.number = number 6 | } 7 | 8 | toString () { 9 | return `Student ${this.name} with number ${this.number}` 10 | } 11 | } 12 | 13 | const student = new Student('Alice', 12345) 14 | const s = student.toString() 15 | expect(s).toEqual('Student Alice with number 12345') 16 | expect(typeof Student).toEqual('function') 17 | }) 18 | 19 | test('inheritance', () => { 20 | class User { 21 | constructor (number) { 22 | this.number = number 23 | } 24 | getNumber () { return this.number } 25 | } 26 | 27 | class Student extends User { 28 | constructor (name, number) { 29 | super(number) 30 | this.name = name 31 | } 32 | getName () { return this.name } 33 | } 34 | 35 | const student = new Student('Alice', 12345) 36 | expect(student.getName()).toBe('Alice') 37 | expect(student.getNumber()).toBe(12345) 38 | }) 39 | 40 | test('classes are functions', () => { 41 | class Student { 42 | constructor (name, number) { 43 | this.name = name 44 | this.number = number 45 | } 46 | 47 | toString () { 48 | return `Student ${this.name} with number ${this.number}` 49 | } 50 | } 51 | 52 | function equatable (base) { 53 | return class extends base { 54 | equals (other) { 55 | if (this.constructor !== other.constructor) return false 56 | for (let name of Object.getOwnPropertyNames(this)) { 57 | if (this[name] !== other[name]) return false 58 | } 59 | return true 60 | } 61 | } 62 | } 63 | 64 | const EStudent = equatable(Student) 65 | const student1 = new EStudent('Alice', 12345) 66 | const student2 = new EStudent('Alice', 12345) 67 | const student3 = new EStudent('Alice', 12346) 68 | expect(student1.equals(student2)).toBeTruthy() 69 | expect(student1.equals(student3)).toBeFalsy() 70 | }) 71 | 72 | test('beware of the this', done => { 73 | class Student { 74 | constructor (name, number) { 75 | this.name = name 76 | this.number = number 77 | this.someMethod = this.someMethod.bind(this) 78 | setTimeout(this.someMethod, 100) 79 | // setTimeout(() => this.someMethod(), 100) 80 | // setTimeout(this.someMethod.bind(this), 100) 81 | } 82 | 83 | someMethod () { 84 | expect(this.name).toBe('Alice') 85 | done() 86 | } 87 | 88 | toString () { 89 | return `Student ${this.name} with number ${this.number}` 90 | } 91 | } 92 | 93 | const student = new Student('Alice', 12345) 94 | expect(student.name).toBe('Alice') 95 | }) 96 | 97 | test('another example §', () => { 98 | class Student { 99 | constructor (name, number) { 100 | this.name = name 101 | this.number = number 102 | } 103 | 104 | toString () { 105 | return `Student ${this.name} with number ${this.number}` 106 | } 107 | } 108 | 109 | function create (Ctor, ...args) { 110 | return new Ctor(...args) 111 | } 112 | 113 | const student = create(Student, 'Alice', 12345) 114 | expect(student.toString()).toBe('Student Alice with number 12345') 115 | }) 116 | 117 | test('Extend from a parameter ', () => { 118 | class Student { 119 | constructor (name, number) { 120 | this.name = name 121 | this.number = number 122 | } 123 | 124 | toString () { 125 | return `Student ${this.name} with number ${this.number}` 126 | } 127 | } 128 | 129 | function f (SomeClass) { 130 | return class extends SomeClass { 131 | constructor (...args) { 132 | super(...args) 133 | this.foo = 'bar' 134 | } 135 | } 136 | } 137 | 138 | const AnotherClass = f(Student) 139 | const s = new AnotherClass('Alice', 12345) 140 | expect(s.toString()).toBe('Student Alice with number 12345') 141 | }) 142 | -------------------------------------------------------------------------------- /demos/js/react/js/ui/issue-list.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import fetch from 'isomorphic-fetch' 3 | import parser from 'parse-link-header' 4 | 5 | const LoadStates = { 6 | loading: 'loading', 7 | loaded: 'loaded', 8 | error: 'error' 9 | } 10 | 11 | // props = {url} 12 | export default class extends React.Component { 13 | constructor (props) { 14 | super(props) 15 | this.changeHandler = this.changeHandler.bind(this) 16 | this.state = { 17 | url: props.url, 18 | loadState: LoadStates.loading, 19 | filter: { 20 | open: true, 21 | closed: false 22 | } 23 | } 24 | } 25 | 26 | static getDerivedStateFromProps (nextProps, prevState) { 27 | return {url: nextProps.url, loadState: LoadStates.loading} 28 | } 29 | 30 | componentDidMount () { 31 | this.loadIfNeeded() 32 | } 33 | 34 | componentDidUpdate () { 35 | this.loadIfNeeded() 36 | } 37 | 38 | loadIfNeeded () { 39 | if (this.state.loadState !== LoadStates.loading) return 40 | const open = this.state.filter.open 41 | const closed = this.state.filter.closed 42 | const value = open && closed ? 'all' : open ? 'open' : 'closed' 43 | const url = this.state.url === this.props.url 44 | ? this.state.url + '?' + `state=${value}` 45 | : this.state.url 46 | console.log('loading ' + url) 47 | fetch(url) 48 | .then(resp => { 49 | if (resp.status >= 400) { 50 | console.log(resp.status) 51 | throw new Error(resp) 52 | } 53 | return resp.json().then(json => { 54 | const linkHeader = resp.headers.get('Link') 55 | const parsed = (linkHeader && parser(linkHeader)) || {} 56 | this.setState({ 57 | issues: json, 58 | next: parsed.next ? parsed.next.url : undefined, 59 | previous: parsed.prev ? parsed.prev.url : undefined, 60 | loadState: LoadStates.loaded 61 | }) 62 | }) 63 | }) 64 | .catch(error => { 65 | console.log(error) 66 | this.setState({ 67 | loadState: LoadStates.error, 68 | error: error 69 | }) 70 | }) 71 | } 72 | 73 | changeHandler (ev) { 74 | const name = ev.target.name 75 | const self = name 76 | const other = name === 'open' ? 'closed' : 'open' 77 | this.setState(old => ({ 78 | url: this.props.url, 79 | loadState: LoadStates.loading, 80 | filter: { 81 | [self]: !old.filter[self], 82 | [other]: !old.filter[self] === false ? true : old.filter[other] 83 | } 84 | })) 85 | } 86 | 87 | reload (url) { 88 | this.setState({ 89 | url: url, 90 | loadState: LoadStates.loading 91 | }) 92 | } 93 | 94 | render () { 95 | const loaded = this.state.loadState === LoadStates.loaded 96 | return ( 97 |
98 |

Issue list

99 | open: 100 | closed: 101 |
102 | 104 | 106 |
107 | {this.renderBody()} 108 |
109 | ) 110 | } 111 | 112 | renderBody () { 113 | switch (this.state.loadState) { 114 | case LoadStates.loading: 115 | return this.renderLoading() 116 | case LoadStates.loaded: 117 | return this.renderLoaded() 118 | case LoadStates.error: 119 | return this.renderError() 120 | } 121 | } 122 | 123 | renderLoading () { 124 | return
... loading ...
125 | } 126 | 127 | renderError () { 128 | return
Error
129 | } 130 | 131 | renderLoaded () { 132 | return ( 133 |
134 |
    135 | {this.state.issues.map(issue => ( 136 |
  • {issue.title} - {issue.state.toUpperCase()}
  • 137 | ))} 138 |
139 |
140 | ) 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /samples/js/react/js/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom' 3 | 4 | // Based on the React documents at https://reactjs.org/docs/hello-world.html 5 | 6 | // Render a single element with text inside 7 | function example0 () { 8 | ReactDOM.render( 9 | React.createElement('h1', {}, 'Hello world'), 10 | document.getElementById('root') 11 | ) 12 | } 13 | 14 | // Repeated rendering of a more complex tree where only an element changes 15 | function example1 () { 16 | setInterval(() => { 17 | ReactDOM.render( 18 | React.createElement('div', {}, 19 | React.createElement('h1', {}, 'Current date and time'), 20 | React.createElement('p', {}, `${new Date().toLocaleString()}`)), 21 | document.getElementById('root')) 22 | }, 1000) 23 | } 24 | 25 | // Slightly more complex tree 26 | function example2 () { 27 | setInterval(() => { 28 | const date = new Date() 29 | const seconds = date.getSeconds() 30 | const line = [...Array(seconds).keys()].map(i => React.createElement('span', {key: i}, ` ${i} `)) 31 | ReactDOM.render( 32 | React.createElement('div', {}, 33 | React.createElement('h1', {}, 'Current date and time'), 34 | React.createElement('p', {}, `${date.toLocaleString()}`), 35 | React.createElement('div', {}, line)), 36 | document.getElementById('root')) 37 | }, 1000) 38 | } 39 | 40 | // Making it syntactlically simpler by using JSX 41 | function example3 () { 42 | setInterval(() => { 43 | const date = new Date() 44 | const seconds = date.getSeconds() 45 | const line = [...Array(seconds).keys()].map(i => {` ${60 - i} `}) 46 | ReactDOM.render( 47 |
48 |

Current date and time

49 |

{date.toLocaleString()}

50 | {line} 51 |
, 52 | document.getElementById('root')) 53 | }, 1000) 54 | } 55 | 56 | // Extracting line as a *component* 57 | function example4 () { 58 | const Line = (props) => [...Array(props.s).keys()].map(i => ({60 - i})) 59 | setInterval(() => { 60 | const date = new Date() 61 | const seconds = date.getSeconds() 62 | ReactDOM.render( 63 |
64 |

Current date and time

65 |

{date.toLocaleString()}

66 | 67 |
, 68 | document.getElementById('root')) 69 | }, 1000) 70 | } 71 | 72 | // Understanding the render call sequence 73 | function example5 () { 74 | const Block = (props) => { 75 | console.log('render Block') 76 | return 77 | } 78 | const Line = (props) => { 79 | console.log('render Line') 80 | return [...Array(props.s).keys()].map(i => ({60 - i})) 81 | } 82 | setInterval(() => { 83 | const date = new Date() 84 | const seconds = date.getSeconds() 85 | console.log('-- creating the tree --') 86 | const tree = 87 |
88 |

Current date and time

89 |

{date.toLocaleString()}

90 | 91 |
92 | console.log('calling ReactDOM.render') 93 | ReactDOM.render( 94 | tree, 95 | document.getElementById('root')) 96 | }, 1000) 97 | } 98 | 99 | // Adding state to components 100 | 101 | const Line = (props) => [...Array(props.s).keys()].map(i => ({i})) 102 | 103 | class Clock extends React.Component { 104 | constructor (props) { 105 | console.log('ctor') 106 | super(props) 107 | this.state = {date: new Date()} 108 | } 109 | 110 | render () { 111 | console.log('render') 112 | const seconds = this.state.date.getSeconds() 113 | return
114 |

Current date and time

115 |

{this.state.date.toLocaleString()}

116 | 117 |
118 | } 119 | 120 | componentDidMount () { 121 | console.log('CDM') 122 | this.timer = setInterval( 123 | () => this.tick(), 124 | 1000 125 | ) 126 | } 127 | 128 | componentWillUnmount () { 129 | console.log('CWU') 130 | clearInterval(this.timer) 131 | } 132 | 133 | tick () { 134 | console.log('tick') 135 | this.setState({date: new Date()}) 136 | } 137 | } 138 | 139 | function example6 () { 140 | ReactDOM.render( 141 | , 142 | document.getElementById('root')) 143 | } 144 | 145 | class ShowHide extends React.Component { 146 | constructor (props) { 147 | super(props) 148 | this.state = {show: props.show} 149 | this.toggle = this.toggle.bind(this) 150 | } 151 | 152 | render () { 153 | const text = this.state.show ? 'hide' : 'show' 154 | const child = this.state.show ? this.props.children :
...
155 | return
156 | 157 | {child} 158 |
159 | } 160 | 161 | toggle () { 162 | this.setState(state => ({show: !state.show})) 163 | } 164 | } 165 | 166 | function example7 () { 167 | console.log(Clock) 168 | ReactDOM.render( 169 | 170 | 171 | , 172 | document.getElementById('root')) 173 | } 174 | 175 | // Example to run 176 | example7() 177 | -------------------------------------------------------------------------------- /samples/jvm/cors/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /samples/jvm/gcp/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | --------------------------------------------------------------------------------