├── gradle.properties ├── settings.gradle ├── src ├── test │ ├── resources │ │ └── projects │ │ │ ├── clientserver │ │ │ ├── settings.gradle │ │ │ ├── server │ │ │ │ ├── src │ │ │ │ │ └── main │ │ │ │ │ │ ├── webapp │ │ │ │ │ │ └── WEB-INF │ │ │ │ │ │ │ ├── appengine-web.xml │ │ │ │ │ │ │ ├── logging.properties │ │ │ │ │ │ │ └── web.xml │ │ │ │ │ │ └── java │ │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ ├── MyBean.java │ │ │ │ │ │ ├── Test.java │ │ │ │ │ │ └── Test2.java │ │ │ │ └── build.gradle │ │ │ └── client │ │ │ │ ├── build.gradle │ │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── Main.java │ │ │ ├── server │ │ │ ├── src │ │ │ │ └── main │ │ │ │ │ ├── webapp │ │ │ │ │ └── WEB-INF │ │ │ │ │ │ ├── appengine-web.xml │ │ │ │ │ │ ├── logging.properties │ │ │ │ │ │ └── web.xml │ │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ ├── MyBean.java │ │ │ │ │ └── Test.java │ │ │ └── build.gradle │ │ │ └── client │ │ │ ├── build.gradle │ │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── Main.java │ │ │ └── endpoints │ │ │ └── testApi-v1-rest.discovery │ └── java │ │ └── com │ │ └── google │ │ └── cloud │ │ └── tools │ │ └── gradle │ │ └── endpoints │ │ └── framework │ │ ├── EndpointsClientPluginTest.java │ │ ├── EndpointsCombinedPluginTest.java │ │ ├── TestProject.java │ │ └── EndpointsServerPluginTest.java └── main │ ├── resources │ └── META-INF │ │ └── gradle-plugins │ │ ├── com.google.cloud.tools.endpoints-framework-client.properties │ │ ├── com.google.cloud.tools.endpoints-framework-server.properties │ │ └── com.google.cloud.tools.endpoints-framework-android-client.properties │ ├── groovy │ └── com │ │ └── google │ │ └── cloud │ │ └── tools │ │ └── gradle │ │ └── endpoints │ │ └── framework │ │ └── client │ │ └── AndroidEndpointsClientPlugin.groovy │ └── java │ └── com │ └── google │ └── cloud │ └── tools │ └── gradle │ └── endpoints │ └── framework │ ├── client │ ├── EndpointsClientExtension.java │ ├── task │ │ ├── ExtractDiscoveryDocZipsTask.java │ │ ├── GenerateClientLibrarySourceTask.java │ │ └── GenerateClientLibrariesTask.java │ └── EndpointsClientPlugin.java │ └── server │ ├── EndpointsServerExtension.java │ ├── task │ └── EndpointsArtifactTask.java │ └── EndpointsServerPlugin.java ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── kokoro ├── continuous.sh ├── release_build.sh └── continuous.bat ├── CONTRIBUTING.md ├── .github └── workflows │ └── unit-tests.yaml ├── scripts └── prepare_release.sh ├── CHANGELOG.md ├── gradlew.bat ├── README.md ├── gradlew ├── ANDROID_README.md └── LICENSE /gradle.properties: -------------------------------------------------------------------------------- 1 | version = 2.1.1-SNAPSHOT 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "endpoints-framework-gradle-plugin" 2 | -------------------------------------------------------------------------------- /src/test/resources/projects/clientserver/settings.gradle: -------------------------------------------------------------------------------- 1 | include ":server" 2 | include ":client" 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | out/ 3 | bin/ 4 | *.iml 5 | *.ipr 6 | *.iws 7 | .idea 8 | .gradle 9 | /.settings 10 | /.classpath 11 | /.project 12 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /kokoro/continuous.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Fail on any error. 4 | set -e 5 | # Display commands to stderr. 6 | set -x 7 | 8 | cd github/endpoints-framework-gradle-plugin 9 | ./gradlew check 10 | -------------------------------------------------------------------------------- /kokoro/release_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Fail on any error. 4 | set -e 5 | # Display commands to stderr. 6 | set -x 7 | 8 | cd github/endpoints-framework-gradle-plugin 9 | ./gradlew check prepareRelease 10 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /kokoro/continuous.bat: -------------------------------------------------------------------------------- 1 | @echo on 2 | 3 | REM Java 9 does not work with our stuff yet, force java 8 4 | set JAVA_HOME=c:\program files\java\jdk1.8.0_152 5 | set PATH=%JAVA_HOME%\bin;%PATH% 6 | 7 | cd github/endpoints-framework-gradle-plugin 8 | 9 | rem skip format check, because it fails for some line ending weirdness 10 | rem and it's anyway checked on ubuntu 11 | call gradlew.bat check -x verifyGoogleJavaFormat 12 | 13 | exit /b %ERRORLEVEL% 14 | -------------------------------------------------------------------------------- /src/test/resources/projects/clientserver/server/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | true 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/test/resources/projects/server/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/test/resources/projects/clientserver/client/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'war' 4 | id 'com.google.cloud.tools.endpoints-framework-client' 5 | } 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | sourceCompatibility = 1.7 12 | targetCompatibility = 1.7 13 | 14 | dependencies { 15 | endpointsServer project(path: ":server", configuration: "endpoints") 16 | compile "com.google.http-client:google-http-client-gson:1.38.1" 17 | compile "com.google.api-client:google-api-client:1.31.2" 18 | } 19 | -------------------------------------------------------------------------------- /src/test/resources/projects/client/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'war' 4 | id 'com.google.cloud.tools.endpoints-framework-client' 5 | } 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | sourceCompatibility = 1.7 12 | targetCompatibility = 1.7 13 | 14 | endpointsClient { 15 | discoveryDocs = ['src/endpoints/testApi-v1-rest.discovery'] 16 | } 17 | 18 | dependencies { 19 | compile "com.google.http-client:google-http-client-gson:1.38.1" 20 | compile "com.google.api-client:google-api-client:1.31.2" 21 | } 22 | -------------------------------------------------------------------------------- /src/test/resources/projects/server/src/main/webapp/WEB-INF/logging.properties: -------------------------------------------------------------------------------- 1 | # A default java.util.logging configuration. 2 | # (All App Engine logging is through java.util.logging by default). 3 | # 4 | # To use this configuration, copy it into your application's WEB-INF 5 | # folder and add the following to your appengine-web.xml: 6 | # 7 | # 8 | # 9 | # 10 | # 11 | 12 | # Set the default logging level for all loggers to WARNING 13 | .level = WARNING 14 | -------------------------------------------------------------------------------- /src/test/resources/projects/clientserver/server/src/main/webapp/WEB-INF/logging.properties: -------------------------------------------------------------------------------- 1 | # A default java.util.logging configuration. 2 | # (All App Engine logging is through java.util.logging by default). 3 | # 4 | # To use this configuration, copy it into your application's WEB-INF 5 | # folder and add the following to your appengine-web.xml: 6 | # 7 | # 8 | # 9 | # 10 | # 11 | 12 | # Set the default logging level for all loggers to WARNING 13 | .level = WARNING 14 | -------------------------------------------------------------------------------- /src/test/resources/projects/clientserver/server/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | 6 | dependencies { 7 | classpath "com.google.cloud.tools:appengine-gradle-plugin:1.3.0" 8 | } 9 | } 10 | 11 | plugins { 12 | id 'java' 13 | id 'war' 14 | id 'com.google.cloud.tools.endpoints-framework-server' 15 | } 16 | 17 | apply plugin: 'com.google.cloud.tools.appengine' 18 | 19 | repositories { 20 | mavenCentral() 21 | } 22 | 23 | sourceCompatibility = 1.7 24 | targetCompatibility = 1.7 25 | 26 | dependencies { 27 | compile "com.google.endpoints:endpoints-framework:2.0.9" // use latest 28 | compile "com.google.appengine:appengine-api-1.0-sdk:+" // use latest 29 | compile 'javax.servlet:servlet-api:2.5' 30 | compile 'javax.inject:javax.inject:1' 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.endpoints-framework-client.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016 Google Inc. All Right Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # 17 | implementation-class=com.google.cloud.tools.gradle.endpoints.framework.client.EndpointsClientPlugin 18 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.endpoints-framework-server.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016 Google Inc. All Right Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # 17 | implementation-class=com.google.cloud.tools.gradle.endpoints.framework.server.EndpointsServerPlugin 18 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.endpoints-framework-android-client.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016 Google Inc. All Right Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | implementation-class=com.google.cloud.tools.gradle.endpoints.framework.client.AndroidEndpointsClientPlugin 17 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to endpoints-framework-gradle-plugin 2 | 3 | The endpoints-framework-gradle-plugin is an open source project, we appreciate your help! 4 | 5 | ## Contributing code 6 | 7 | 1. First, please [sign either individual or corporate contributor license agreement](https://cla.developers.google.com/), whichever is applicable. 8 | 2. Set your git user.email property to the address used for step 1. E.g. 9 | ``` 10 | git config --global user.email "janedoe@google.com" 11 | ``` 12 | If you're a Googler or other corporate contributor, 13 | use your corporate email address here, not your personal address. 14 | 3. Fork the repository into your own Github account. 15 | 4. Please include unit tests for all new code. 16 | 5. Make sure all existing tests pass. (gradlew test) 17 | 6. Associate the change with an existing issue or file a [new issue](../../issues) 18 | 7. Create a pull request! 19 | -------------------------------------------------------------------------------- /src/test/resources/projects/server/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | EndpointsServlet 4 | com.google.api.server.spi.EndpointsServlet 5 | 6 | services 7 | com.example.Test 8 | 9 | 10 | 11 | EndpointsServlet 12 | /_ah/api/* 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/test/resources/projects/clientserver/server/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | EndpointsServlet 4 | com.google.api.server.spi.EndpointsServlet 5 | 6 | services 7 | com.example.Test, com.example.Test2 8 | 9 | 10 | 11 | EndpointsServlet 12 | /_ah/api/* 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/test/resources/projects/server/src/main/java/com/example/MyBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example; 18 | 19 | public class MyBean { 20 | 21 | public String string; 22 | 23 | public String getString() { 24 | return string; 25 | } 26 | 27 | public void setString(String string) { 28 | this.string = string; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/resources/projects/clientserver/server/src/main/java/com/example/MyBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example; 18 | 19 | public class MyBean { 20 | 21 | public String string; 22 | 23 | public String getString() { 24 | return string; 25 | } 26 | 27 | public void setString(String string) { 28 | this.string = string; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /.github/workflows/unit-tests.yaml: -------------------------------------------------------------------------------- 1 | name: Unit Tests 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | workflow_dispatch: 8 | 9 | jobs: 10 | unit-tests: 11 | runs-on: ubuntu-latest 12 | strategy: 13 | fail-fast: false 14 | matrix: 15 | # Don't let this fool you. We still build to target Java 7. 16 | java: [8] 17 | env: 18 | # for gradle 19 | TERM: dumb 20 | steps: 21 | - uses: actions/checkout@v2 22 | - uses: actions/setup-java@v1 23 | with: 24 | java-version: ${{ matrix.java }} 25 | - uses: actions/cache@v2 26 | with: 27 | path: | 28 | ~/.m2/repository 29 | ~/.gradle/caches 30 | ~/.gradle/wrapper 31 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} 32 | restore-keys: | 33 | ${{ runner.os }}-gradle- 34 | - name: Run tests 35 | run: | 36 | ./gradlew clean build --stacktrace 37 | -------------------------------------------------------------------------------- /src/test/resources/projects/client/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import com.example.testApi.TestApi; 18 | import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; 19 | import com.google.api.client.json.gson.GsonFactory; 20 | import java.io.IOException; 21 | import java.security.GeneralSecurityException; 22 | 23 | public class Main { 24 | public static void main(String[] args) throws GeneralSecurityException, IOException { 25 | new TestApi.Builder(GoogleNetHttpTransport.newTrustedTransport(), new GsonFactory(), null); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/resources/projects/server/src/main/java/com/example/Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example; 18 | 19 | import com.google.api.server.spi.config.Api; 20 | import com.google.api.server.spi.config.ApiMethod; 21 | import com.google.api.server.spi.config.ApiNamespace; 22 | import javax.inject.Named; 23 | 24 | @Api( 25 | name = "testApi", 26 | version = "v1", 27 | namespace = 28 | @ApiNamespace(ownerDomain = "example.com", ownerName = "example.com", packagePath = "")) 29 | public class Test { 30 | 31 | @ApiMethod(name = "echo") 32 | public MyBean echo(@Named("name") String name) { 33 | MyBean response = new MyBean(); 34 | response.setString("ECHO " + name); 35 | 36 | return response; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/resources/projects/clientserver/server/src/main/java/com/example/Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example; 18 | 19 | import com.google.api.server.spi.config.Api; 20 | import com.google.api.server.spi.config.ApiMethod; 21 | import com.google.api.server.spi.config.ApiNamespace; 22 | import javax.inject.Named; 23 | 24 | @Api( 25 | name = "testApi", 26 | version = "v1", 27 | namespace = 28 | @ApiNamespace(ownerDomain = "example.com", ownerName = "example.com", packagePath = "")) 29 | public class Test { 30 | 31 | @ApiMethod(name = "echo") 32 | public MyBean echo(@Named("name") String name) { 33 | MyBean response = new MyBean(); 34 | response.setString("ECHO " + name); 35 | 36 | return response; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/resources/projects/clientserver/server/src/main/java/com/example/Test2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example; 18 | 19 | import com.google.api.server.spi.config.Api; 20 | import com.google.api.server.spi.config.ApiMethod; 21 | import com.google.api.server.spi.config.ApiNamespace; 22 | import javax.inject.Named; 23 | 24 | @Api( 25 | name = "testApi2", 26 | version = "v1", 27 | namespace = 28 | @ApiNamespace(ownerDomain = "example.com", ownerName = "example.com", packagePath = "")) 29 | public class Test2 { 30 | 31 | @ApiMethod(name = "echo2") 32 | public MyBean echo2(@Named("name") String name) { 33 | MyBean response = new MyBean(); 34 | response.setString("ECHO " + name); 35 | 36 | return response; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/resources/projects/clientserver/client/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import com.example.testApi.TestApi; 18 | import com.example.testApi2.TestApi2; 19 | import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; 20 | import com.google.api.client.json.gson.GsonFactory; 21 | import java.io.IOException; 22 | import java.security.GeneralSecurityException; 23 | 24 | public class Main { 25 | public static void main(String[] args) throws GeneralSecurityException, IOException { 26 | new TestApi.Builder(GoogleNetHttpTransport.newTrustedTransport(), new GsonFactory(), null) 27 | .build() 28 | .echo("xyz"); 29 | new TestApi2.Builder(GoogleNetHttpTransport.newTrustedTransport(), new GsonFactory(), null) 30 | .build() 31 | .echo2("lmnop"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/resources/projects/server/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | buildscript { 18 | repositories { 19 | mavenCentral() 20 | } 21 | 22 | dependencies { 23 | classpath "com.google.cloud.tools:appengine-gradle-plugin:1.3.0" 24 | } 25 | } 26 | 27 | plugins { 28 | id 'java' 29 | id 'war' 30 | id 'com.google.cloud.tools.endpoints-framework-server' 31 | } 32 | 33 | apply plugin: 'com.google.cloud.tools.appengine' 34 | 35 | repositories { 36 | mavenCentral() 37 | } 38 | 39 | sourceCompatibility = 1.7 40 | targetCompatibility = 1.7 41 | 42 | dependencies { 43 | compile "com.google.endpoints:endpoints-framework:2.0.9" // use latest 44 | compile 'javax.servlet:servlet-api:2.5' 45 | compile 'javax.inject:javax.inject:1' 46 | } 47 | 48 | /*endpoints-plugin-hostname*/ 49 | /*endpoints-plugin-basePath*/ 50 | -------------------------------------------------------------------------------- /scripts/prepare_release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # Usage: ./prepare_release.sh 3 | 4 | set -e 5 | 6 | Colorize() { 7 | echo "$(tput setff $2)$1$(tput sgr0)" 8 | } 9 | 10 | EchoRed() { 11 | echo "$(tput setaf 1; tput bold)$1$(tput sgr0)" 12 | } 13 | EchoGreen() { 14 | echo "$(tput setaf 2; tput bold)$1$(tput sgr0)" 15 | } 16 | 17 | Die() { 18 | EchoRed "$1" 19 | exit 1 20 | } 21 | 22 | DieUsage() { 23 | Die "Usage: ./prepare_release.sh " 24 | } 25 | 26 | # Usage: CheckVersion 27 | CheckVersion() { 28 | [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || Die "Version not in ###.###.### format." 29 | } 30 | 31 | [ $# -ne 2 ] || DieUsage 32 | 33 | EchoGreen '===== RELEASE SETUP SCRIPT =====' 34 | 35 | VERSION=$1 36 | CheckVersion ${VERSION} 37 | 38 | if [[ $(git status -uno --porcelain) ]]; then 39 | Die 'There are uncommitted changes.' 40 | fi 41 | 42 | # Checks out a new branch for this version release (eg. 1.5.7). 43 | git checkout -b release_v${VERSION} 44 | 45 | # Changes the version for release and creates the commits/tags. 46 | echo | ./gradlew release -Prelease.releaseVersion=${VERSION} 47 | 48 | # Pushes the release branch to Github. 49 | git push --set-upstream origin release_v${VERSION} 50 | 51 | # File a PR on Github for the new branch. Have someone LGTM it, which gives you permission to continue. 52 | EchoGreen 'File a PR for the new release branch:' 53 | echo https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/compare/release_v${VERSION} 54 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | ## [unreleased] 4 | 5 | ### Added 6 | 7 | ### Changed 8 | 9 | ### Fixed 10 | 11 | ## 2.1.0 12 | 13 | ### Changed 14 | - Update endpoints-framework-tools to version 2.2.2 ([#100](https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/pull/100)) 15 | 16 | ## 2.0.1 17 | ### Changed 18 | - Update endpoints-framework-tools to version 2.2.0 ([#90](https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/pull/90)) 19 | 20 | ## 2.0.0 21 | ### Changed 22 | - Update endpoints-framework-tools to version 2.0.14 ([#83](https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/pull/83)) 23 | - Requires Java 8 ([#83](https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/pull/83)) 24 | 25 | 26 | ## 1.0.3 27 | ### Changed 28 | - Updated endpoints-framework-tools to version 2.0.9 ([#70](https://github.com/GoogleCloudPlatform/endpoints-framework-maven-plugin/pull/70)) 29 | - Update endpoints-framework-tools to version 2.0.10 ([#77](https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/pull/79)) 30 | - Update gradle classes output dependency ([#75](https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/issues/75)) 31 | 32 | ## 1.0.2 33 | ### Added 34 | - Add basePath to openApiDocs, clientLibs, and discoveryDocs generation ([#54](https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/issues/54)) 35 | 36 | ## 1.0.1 37 | ### Fixed 38 | - Play better with non-java languages when adding generated client source to a project ([#47](https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/issues/47)) 39 | -------------------------------------------------------------------------------- /src/test/java/com/google/cloud/tools/gradle/endpoints/framework/EndpointsClientPluginTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.net.URISyntaxException; 22 | import org.gradle.testkit.runner.BuildResult; 23 | import org.junit.Assert; 24 | import org.junit.Rule; 25 | import org.junit.Test; 26 | import org.junit.rules.TemporaryFolder; 27 | 28 | /** Test endpoints client plugin builds. */ 29 | public class EndpointsClientPluginTest { 30 | 31 | @Rule public TemporaryFolder testProjectDir = new TemporaryFolder(); 32 | 33 | @Test 34 | public void testClientBuilds() throws IOException, URISyntaxException { 35 | 36 | BuildResult buildResult = 37 | new TestProject(testProjectDir.getRoot(), "projects/client") 38 | .gradleRunnerArguments("assemble") 39 | .build(); 40 | 41 | // Part of what we're testing is that a class with a dependency on generated source will compile 42 | // correctly when the generated source is created at build time. The above build will fail with 43 | // a gradle exception if generation and association of the generated source with the project 44 | // does not happen correctly. 45 | 46 | File genSrcDir = new File(testProjectDir.getRoot(), "build/endpointsGenSrc"); 47 | File genSrcFile = new File(genSrcDir, "com/example/testApi/TestApi.java"); 48 | 49 | Assert.assertTrue(genSrcFile.exists()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/google/cloud/tools/gradle/endpoints/framework/EndpointsCombinedPluginTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.net.URISyntaxException; 22 | import org.gradle.testkit.runner.BuildResult; 23 | import org.junit.Assert; 24 | import org.junit.Rule; 25 | import org.junit.Test; 26 | import org.junit.rules.TemporaryFolder; 27 | 28 | /** Test endpoints client-server plugin integration builds. */ 29 | public class EndpointsCombinedPluginTest { 30 | 31 | @Rule public final TemporaryFolder testProjectDir = new TemporaryFolder(); 32 | 33 | @Test 34 | public void testClientServerIntegrationBuilds() throws IOException, URISyntaxException { 35 | BuildResult buildResult = 36 | new TestProject(testProjectDir.getRoot(), "projects/clientserver") 37 | .gradleRunnerArguments("assemble") 38 | .build(); 39 | 40 | // Part of what we're testing is that a class with a dependency on generated source will compile 41 | // correctly when the generated source is created at build time. The above build will fail with 42 | // a gradle exception if generation and association of the generated source with the project 43 | // does not happen correctly. 44 | 45 | File genSrcDir = new File(testProjectDir.getRoot(), "client/build/endpointsGenSrc"); 46 | File genSrcFile = new File(genSrcDir, "com/example/testApi/TestApi.java"); 47 | 48 | Assert.assertTrue(genSrcFile.exists()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/groovy/com/google/cloud/tools/gradle/endpoints/framework/client/AndroidEndpointsClientPlugin.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework.client 18 | 19 | import org.gradle.api.Plugin 20 | import org.gradle.api.Project 21 | 22 | /** 23 | * Client side extensions for android projects, written in groovy because 24 | * it lets us do the crazy things we do in here 25 | */ 26 | public class AndroidEndpointsClientPlugin implements Plugin { 27 | 28 | @Override 29 | void apply(Project project) { 30 | def endpointsClient = project.extensions.findByType(EndpointsClientExtension) 31 | def android = project.extensions.getByName("android"); 32 | 33 | // up till android studio 2.2, any generated source MUST be specifically in the 34 | // generated/source directory or the IDE wont recognize it. 35 | endpointsClient.genSrcDir = new File(project.buildDir, "generated/source/endpoints"); 36 | 37 | // register our source generating task and outputs with the android model 38 | def genSrcTask = project.tasks.getByName(EndpointsClientPlugin.GENERATE_CLIENT_LIBRARY_SRC_TASK) 39 | if (android.hasProperty("applicationVariants")) { 40 | android.applicationVariants.all { variant -> 41 | variant.registerJavaGeneratingTask(genSrcTask, endpointsClient.genSrcDir) 42 | } 43 | } 44 | 45 | if (android.hasProperty("libraryVariants")) { 46 | android.libraryVariants.all {variant -> 47 | variant.registerJavaGeneratingTask(genSrcTask, endpointsClient.genSrcDir) 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/google/cloud/tools/gradle/endpoints/framework/client/EndpointsClientExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework.client; 18 | 19 | import java.io.File; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import org.gradle.api.Project; 23 | 24 | /** Plugin extension for endpoints client plugin. */ 25 | public class EndpointsClientExtension { 26 | 27 | private File genSrcDir; 28 | private final File clientLibDir; 29 | private final File genDiscoveryDocsDir; 30 | private final Project project; 31 | private List discoveryDocs; 32 | 33 | /** Constructor. */ 34 | public EndpointsClientExtension(Project project) { 35 | this.project = project; 36 | genSrcDir = new File(project.getBuildDir(), "endpointsGenSrc"); 37 | clientLibDir = new File(project.getBuildDir(), "endpointsClientLibs"); 38 | genDiscoveryDocsDir = new File(project.getBuildDir(), "endpointsDiscoveryDocsFromDependencies"); 39 | 40 | discoveryDocs = new ArrayList<>(); 41 | } 42 | 43 | public File getGenSrcDir() { 44 | return genSrcDir; 45 | } 46 | 47 | public void setGenSrcDir(Object genSrcDir) { 48 | this.genSrcDir = project.file(genSrcDir); 49 | } 50 | 51 | public File getClientLibDir() { 52 | return clientLibDir; 53 | } 54 | 55 | public File getGenDiscoveryDocsDir() { 56 | return genDiscoveryDocsDir; 57 | } 58 | 59 | public List getDiscoveryDocs() { 60 | return discoveryDocs; 61 | } 62 | 63 | public void setDiscoveryDocs(Object discoveryDocs) { 64 | this.discoveryDocs.clear(); 65 | this.discoveryDocs.addAll(project.files(discoveryDocs).getFiles()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/google/cloud/tools/gradle/endpoints/framework/client/task/ExtractDiscoveryDocZipsTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework.client.task; 18 | 19 | import java.io.File; 20 | import java.util.Collection; 21 | import java.util.HashMap; 22 | import org.gradle.api.DefaultTask; 23 | import org.gradle.api.tasks.InputFiles; 24 | import org.gradle.api.tasks.OutputDirectory; 25 | import org.gradle.api.tasks.TaskAction; 26 | 27 | /** 28 | * Task to extract all discovery docs from zips generated by other modules in the same gradle 29 | * project. 30 | */ 31 | public class ExtractDiscoveryDocZipsTask extends DefaultTask { 32 | 33 | private Collection discoveryDocZips; 34 | private File discoveryDocsDir; 35 | 36 | @InputFiles 37 | public Collection getDiscoveryDocZips() { 38 | return discoveryDocZips; 39 | } 40 | 41 | public void setDiscoveryDocZips(Collection discoveryDocZips) { 42 | this.discoveryDocZips = discoveryDocZips; 43 | } 44 | 45 | @OutputDirectory 46 | public File getDiscoveryDocsDir() { 47 | return discoveryDocsDir; 48 | } 49 | 50 | public void setDiscoveryDocsDir(File discoveryDocsDir) { 51 | this.discoveryDocsDir = discoveryDocsDir; 52 | } 53 | 54 | /** Task entry point. */ 55 | @TaskAction 56 | public void extractDiscoveryDocs() { 57 | getProject().delete(discoveryDocsDir); 58 | getProject().mkdir(discoveryDocsDir); 59 | 60 | for (final File discoveryDocZip : discoveryDocZips) { 61 | getAnt() 62 | .invokeMethod( 63 | "unzip", 64 | new HashMap() { 65 | { 66 | put("src", discoveryDocZip.getPath()); 67 | put("dest", discoveryDocsDir.getPath()); 68 | } 69 | }); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/main/java/com/google/cloud/tools/gradle/endpoints/framework/server/EndpointsServerExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework.server; 18 | 19 | import java.io.File; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import org.gradle.api.Project; 23 | 24 | /** Plugin extension for endpoints server plugin. */ 25 | public class EndpointsServerExtension { 26 | 27 | private final Project project; 28 | private final File discoveryDocDir; 29 | private final File openApiDocDir; 30 | 31 | private File clientLibDir; 32 | private List serviceClasses; 33 | private String hostname; 34 | private String basePath; 35 | 36 | /** Constructor. */ 37 | public EndpointsServerExtension(Project project) { 38 | this.project = project; 39 | discoveryDocDir = new File(project.getBuildDir(), "endpointsDiscoveryDocs"); 40 | openApiDocDir = new File(project.getBuildDir(), "endpointsOpenApiDocs"); 41 | clientLibDir = new File(project.getBuildDir(), "endpointsClientLibs"); 42 | serviceClasses = new ArrayList<>(); 43 | } 44 | 45 | public File getDiscoveryDocDir() { 46 | return discoveryDocDir; 47 | } 48 | 49 | public File getOpenApiDocDir() { 50 | return openApiDocDir; 51 | } 52 | 53 | public File getClientLibDir() { 54 | return clientLibDir; 55 | } 56 | 57 | public void setClientLibDir(Object clientLibDir) { 58 | this.clientLibDir = project.file(clientLibDir); 59 | } 60 | 61 | public List getServiceClasses() { 62 | return serviceClasses; 63 | } 64 | 65 | public void setServiceClasses(List serviceClasses) { 66 | this.serviceClasses = serviceClasses; 67 | } 68 | 69 | public String getHostname() { 70 | return hostname; 71 | } 72 | 73 | public void setHostname(String hostname) { 74 | this.hostname = hostname; 75 | } 76 | 77 | public String getBasePath() { 78 | return basePath; 79 | } 80 | 81 | public void setBasePath(String basePath) { 82 | this.basePath = basePath; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/test/resources/projects/client/src/endpoints/testApi-v1-rest.discovery: -------------------------------------------------------------------------------- 1 | { 2 | "kind": "discovery#restDescription", 3 | "etag": "\"zRMgE0l9nVDW4S28VYYcYQF9UW4/VN43YJE_4fcDZqzVygXW7-VCkQw\"", 4 | "discoveryVersion": "v1", 5 | "id": "testApi:v1", 6 | "name": "testApi", 7 | "version": "v1", 8 | "description": "This is an API", 9 | "ownerDomain": "example.com", 10 | "ownerName": "example.com", 11 | "icons": { 12 | "x16": "http://www.google.com/images/icons/product/search-16.gif", 13 | "x32": "http://www.google.com/images/icons/product/search-32.gif" 14 | }, 15 | "protocol": "rest", 16 | "baseUrl": "https://some-nonsense.appspot.com/_ah/api/testApi/v1/echo/", 17 | "basePath": "/_ah/api/testApi/v1/echo/", 18 | "rootUrl": "https://some-nonsense.appspot.com/_ah/api/", 19 | "servicePath": "testApi/v1/echo/", 20 | "batchPath": "batch", 21 | "parameters": { 22 | "alt": { 23 | "type": "string", 24 | "description": "Data format for the response.", 25 | "default": "json", 26 | "enum": [ 27 | "json" 28 | ], 29 | "enumDescriptions": [ 30 | "Responses with Content-Type of application/json" 31 | ], 32 | "location": "query" 33 | }, 34 | "fields": { 35 | "type": "string", 36 | "description": "Selector specifying which fields to include in a partial response.", 37 | "location": "query" 38 | }, 39 | "key": { 40 | "type": "string", 41 | "description": "API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.", 42 | "location": "query" 43 | }, 44 | "oauth_token": { 45 | "type": "string", 46 | "description": "OAuth 2.0 token for the current user.", 47 | "location": "query" 48 | }, 49 | "prettyPrint": { 50 | "type": "boolean", 51 | "description": "Returns response with indentations and line breaks.", 52 | "default": "true", 53 | "location": "query" 54 | }, 55 | "quotaUser": { 56 | "type": "string", 57 | "description": "Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.", 58 | "location": "query" 59 | }, 60 | "userIp": { 61 | "type": "string", 62 | "description": "IP address of the site where the request originates. Use this if you want to enforce per-user limits.", 63 | "location": "query" 64 | } 65 | }, 66 | "auth": { 67 | "oauth2": { 68 | "scopes": { 69 | "https://www.googleapis.com/auth/userinfo.email": { 70 | "description": "View your email address" 71 | } 72 | } 73 | } 74 | }, 75 | "schemas": { 76 | "MyBean": { 77 | "id": "MyBean", 78 | "type": "object", 79 | "properties": { 80 | "string": { 81 | "type": "string" 82 | } 83 | } 84 | } 85 | }, 86 | "methods": { 87 | "echo": { 88 | "id": "testApi.echo", 89 | "path": "{name}", 90 | "httpMethod": "POST", 91 | "parameters": { 92 | "name": { 93 | "type": "string", 94 | "required": true, 95 | "location": "path" 96 | } 97 | }, 98 | "parameterOrder": [ 99 | "name" 100 | ], 101 | "response": { 102 | "$ref": "MyBean" 103 | }, 104 | "scopes": [ 105 | "https://www.googleapis.com/auth/userinfo.email" 106 | ] 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/com/google/cloud/tools/gradle/endpoints/framework/client/task/GenerateClientLibrarySourceTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework.client.task; 18 | 19 | import java.io.File; 20 | import java.io.FilenameFilter; 21 | import java.util.HashMap; 22 | import org.gradle.api.Action; 23 | import org.gradle.api.DefaultTask; 24 | import org.gradle.api.file.CopySpec; 25 | import org.gradle.api.tasks.InputDirectory; 26 | import org.gradle.api.tasks.OutputDirectory; 27 | import org.gradle.api.tasks.TaskAction; 28 | 29 | /** Task to populate a generated source folder of client lib code. */ 30 | public class GenerateClientLibrarySourceTask extends DefaultTask { 31 | private File clientLibDir; 32 | private File generatedSrcDir; 33 | 34 | @OutputDirectory 35 | public File getGeneratedSrcDir() { 36 | return generatedSrcDir; 37 | } 38 | 39 | public void setGeneratedSrcDir(File generatedSrcDir) { 40 | this.generatedSrcDir = generatedSrcDir; 41 | } 42 | 43 | @InputDirectory 44 | public File getClientLibDir() { 45 | return clientLibDir; 46 | } 47 | 48 | public void setClientLibDir(File clientLibDir) { 49 | this.clientLibDir = clientLibDir; 50 | } 51 | 52 | /** Task entry point. */ 53 | @TaskAction 54 | public void generateSource() { 55 | boolean x = getProject().delete(generatedSrcDir); 56 | File[] zips = 57 | getClientLibDir() 58 | .listFiles( 59 | new FilenameFilter() { 60 | @Override 61 | public boolean accept(File dir, String name) { 62 | return name.endsWith(".zip"); 63 | } 64 | }); 65 | 66 | final File tmpDir = new File(getTemporaryDir(), "endpoints-tmp"); 67 | getProject().delete(tmpDir); 68 | getProject().mkdir(tmpDir); 69 | for (final File zip : zips) { 70 | // Use ant unzip, gradle unzip is having issues 71 | // with strangely formed client libraries 72 | getAnt() 73 | .invokeMethod( 74 | "unzip", 75 | new HashMap() { 76 | { 77 | put("src", zip.getPath()); 78 | put("dest", tmpDir.getPath()); 79 | } 80 | }); 81 | } 82 | 83 | for (File unzippedDir : tmpDir.listFiles()) { 84 | final File srcDir = new File(unzippedDir, "src/main/java"); 85 | if (srcDir.exists() && srcDir.isDirectory()) { 86 | getProject() 87 | .copy( 88 | new Action() { 89 | @Override 90 | public void execute(CopySpec copySpec) { 91 | copySpec.from(srcDir); 92 | copySpec.into(generatedSrcDir); 93 | } 94 | }); 95 | } 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/com/google/cloud/tools/gradle/endpoints/framework/TestProject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.net.URISyntaxException; 22 | import org.apache.commons.io.FileUtils; 23 | import org.gradle.testkit.runner.BuildResult; 24 | import org.gradle.testkit.runner.GradleRunner; 25 | 26 | /** Test project fixture. */ 27 | public class TestProject { 28 | 29 | private final File testDir; 30 | private final String projectPathInResources; 31 | 32 | private String hostname; 33 | private String basePath; 34 | private String application; 35 | private String[] gradleRunnerArgs = {"assemble"}; 36 | 37 | public TestProject(File testDir, String projectPathInResources) { 38 | this.testDir = testDir; 39 | this.projectPathInResources = projectPathInResources; 40 | } 41 | 42 | public TestProject hostname(String hostname) { 43 | this.hostname = hostname; 44 | return this; 45 | } 46 | 47 | public TestProject basePath(String basePath) { 48 | this.basePath = basePath; 49 | return this; 50 | } 51 | 52 | public TestProject applicationId(String applicationId) { 53 | this.application = applicationId; 54 | return this; 55 | } 56 | 57 | public TestProject gradleRunnerArguments(String... args) { 58 | this.gradleRunnerArgs = args; 59 | return this; 60 | } 61 | 62 | /** Copy project and run gradle build. */ 63 | public BuildResult build() throws URISyntaxException, IOException { 64 | FileUtils.copyDirectory( 65 | new File(getClass().getClassLoader().getResource(projectPathInResources).toURI()), testDir); 66 | if (application != null) { 67 | injectApplicationId(testDir, application); 68 | } 69 | if (hostname != null) { 70 | injectHostname(hostname); 71 | } 72 | if (basePath != null) { 73 | injectBasePath(basePath); 74 | } 75 | return GradleRunner.create() 76 | .withProjectDir(testDir) 77 | .withPluginClasspath() 78 | .withArguments(gradleRunnerArgs) 79 | .build(); 80 | } 81 | 82 | // Inject an endpoints plugin hostname into the build.gradle file. 83 | private void injectHostname(String hostname) throws IOException { 84 | injectIntoBuildGradleFile( 85 | "/\\*endpoints-plugin-hostname\\*/", "endpointsServer.hostname = '" + hostname + "'"); 86 | } 87 | 88 | // Inject an endpoints plugin basePath into the build.gradle file. 89 | private void injectBasePath(String basePath) throws IOException { 90 | injectIntoBuildGradleFile( 91 | "/\\*endpoints-plugin-basePath\\*/", "endpointsServer.basePath = '" + basePath + "'"); 92 | } 93 | 94 | // Helper method to replace text inside the build.gradle file. 95 | private void injectIntoBuildGradleFile(String regex, String replacement) throws IOException { 96 | File buildGradle = new File(testDir, "build.gradle"); 97 | String buildGradleContents = FileUtils.readFileToString(buildGradle); 98 | buildGradleContents = buildGradleContents.replaceAll(regex, replacement); 99 | FileUtils.writeStringToFile(buildGradle, buildGradleContents); 100 | } 101 | 102 | // inject an application tag into the appengine-web.xml 103 | private void injectApplicationId(File projectRoot, String application) throws IOException { 104 | File app = new File(testDir, "src/main/webapp/WEB-INF/appengine-web.xml"); 105 | String appContents = FileUtils.readFileToString(app); 106 | appContents = 107 | appContents.replaceAll( 108 | "", "" + application + ""); 109 | FileUtils.writeStringToFile(app, appContents); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/com/google/cloud/tools/gradle/endpoints/framework/client/task/GenerateClientLibrariesTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework.client.task; 18 | 19 | import com.google.api.server.spi.tools.EndpointsTool; 20 | import com.google.api.server.spi.tools.GenClientLibAction; 21 | import com.google.common.base.Preconditions; 22 | import com.google.common.collect.Lists; 23 | import java.io.File; 24 | import java.io.FileFilter; 25 | import java.util.ArrayList; 26 | import java.util.Arrays; 27 | import java.util.List; 28 | import org.gradle.api.DefaultTask; 29 | import org.gradle.api.tasks.InputDirectory; 30 | import org.gradle.api.tasks.InputFiles; 31 | import org.gradle.api.tasks.OutputDirectory; 32 | import org.gradle.api.tasks.TaskAction; 33 | 34 | /** Endpoints task to download a client library from the endpoints service. */ 35 | public class GenerateClientLibrariesTask extends DefaultTask { 36 | private File clientLibraryDir; 37 | private List discoveryDocs; 38 | private File generatedDiscoveryDocsDir; 39 | 40 | @OutputDirectory 41 | public File getClientLibraryDir() { 42 | return clientLibraryDir; 43 | } 44 | 45 | public void setClientLibraryDir(File clientLibraryDir) { 46 | this.clientLibraryDir = clientLibraryDir; 47 | } 48 | 49 | @InputFiles 50 | public List getDiscoveryDocs() { 51 | return discoveryDocs; 52 | } 53 | 54 | /** 55 | * Set discovery docs as a list of directories and files, will find all discovery docs in 56 | * directories as necessary. 57 | */ 58 | public void setDiscoveryDocs(List discoveryDocs) { 59 | List expandedDiscoveryDocs = new ArrayList<>(); 60 | for (File discoveryDoc : discoveryDocs) { 61 | if (discoveryDoc.isDirectory()) { 62 | expandedDiscoveryDocs.addAll(findDiscoveryDocsInDirectory(discoveryDoc)); 63 | } else { 64 | expandedDiscoveryDocs.add(discoveryDoc); 65 | } 66 | } 67 | this.discoveryDocs = expandedDiscoveryDocs; 68 | } 69 | 70 | @InputDirectory 71 | public File getGeneratedDiscoveryDocsDir() { 72 | return generatedDiscoveryDocsDir; 73 | } 74 | 75 | public void setGeneratedDiscoveryDocs(File generatedDiscoveryDocsDir) { 76 | this.generatedDiscoveryDocsDir = generatedDiscoveryDocsDir; 77 | } 78 | 79 | /** Task entry point. */ 80 | @TaskAction 81 | public void generateClientLibs() throws Exception { 82 | getProject().delete(clientLibraryDir); 83 | getProject().mkdir(clientLibraryDir); 84 | 85 | for (File discoveryDoc : discoveryDocs) { 86 | runEndpointsTools(discoveryDoc); 87 | } 88 | 89 | for (File discoveryDoc : findDiscoveryDocsInDirectory(generatedDiscoveryDocsDir)) { 90 | runEndpointsTools(discoveryDoc); 91 | } 92 | } 93 | 94 | private void runEndpointsTools(File discoveryDoc) throws Exception { 95 | List params = 96 | Lists.newArrayList( 97 | Arrays.asList( 98 | GenClientLibAction.NAME, 99 | "-l", 100 | "java", 101 | "-bs", 102 | "gradle", 103 | "-o", 104 | clientLibraryDir.getAbsolutePath())); 105 | 106 | params.add(discoveryDoc.getAbsolutePath()); 107 | new EndpointsTool().execute(params.toArray(new String[params.size()])); 108 | } 109 | 110 | private static List findDiscoveryDocsInDirectory(File discoveryDocDirectory) { 111 | Preconditions.checkArgument(discoveryDocDirectory.isDirectory()); 112 | 113 | File[] discoveryDocs = 114 | discoveryDocDirectory.listFiles( 115 | new FileFilter() { 116 | @Override 117 | public boolean accept(File pathname) { 118 | return pathname.getName().endsWith(".discovery"); 119 | } 120 | }); 121 | return Arrays.asList(discoveryDocs); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![project status image](https://img.shields.io/badge/stability-stable-brightgreen.svg) 2 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.google.cloud.tools/endpoints-framework-gradle-plugin/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.google.cloud.tools/endpoints-framework-gradle-plugin) 3 | # Endpoints Framework Gradle Plugin 4 | 5 | This Gradle plugin provides tasks and configurations to build and connect Endpoints Framework projects. 6 | 7 | Android Studio users see [transition guide](ANDROID_README.md). 8 | 9 | # Requirements 10 | 11 | [Gradle](http://gradle.org) is required to build and run the plugin. The table below shows the compatibility with Gradle version. 12 | 13 | 14 | 15 | | Gradle version | endpoints-framework-gradle-plugin version | 16 | | ------------- | ------------- | 17 | | 7.x - | 2.2.0 or higher (not yet released) | 18 | | 4.x - 6.x | 2.1.0 or lower | 19 | 20 | # How to use 21 | 22 | The plugin JAR needs to be defined in the classpath of your build script. Alternatively, you can download it from GitHub and deploy it to your local repository. The following code snippet shows an example on how to retrieve it from maven central : 23 | 24 | ```Groovy 25 | buildscript { 26 | repositories { 27 | mavenCentral() 28 | } 29 | 30 | dependencies { 31 | classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2' 32 | } 33 | } 34 | ``` 35 | 36 | ### Server 37 | In your Gradle App Engine Java app, add the following plugin to your build.gradle: 38 | 39 | ```Groovy 40 | apply plugin: 'com.google.cloud.tools.endpoints-framework-server' 41 | ``` 42 | 43 | The plugin exposes the following server side goals 44 | * `endpointsClientLibs` - generate client libraries 45 | * `endpointsDiscoveryDocs` - generate discovery documents 46 | * `endpointsOpenApiDocs` - generate Open Api documents 47 | 48 | The plugin exposes server side configuration through the `endpointsServer` extension 49 | * `serviceClasses` - List of service classes (optional), this can be inferred from web.xml 50 | * `clientLibDir` - Output directory for generated client libraries 51 | * `hostname` - To set the root url for discovery docs and client libs (ex: `hostname = myapp.appspot.com` will result in a default root url of `https://myapp.appspot.com/_ah/api`) 52 | 53 | #### Usage 54 | Make sure your web.xml is [configured to expose your endpoints](https://cloud.google.com/endpoints/docs/frameworks/java/required_files) correctly. 55 | 56 | No configuration paramters are required to run with default values 57 | ``` 58 | $> gradle endpointsClientLibs 59 | ``` 60 | Client libraries will be written to `build/endpointsClientLibs` 61 | 62 | ``` 63 | $> gradle endpointsDiscoveryDocs 64 | ``` 65 | Discovery documents will be written to `build/endpointsDiscoveryDocs` 66 | 67 | 68 | ### Client 69 | In your client Java app, add the following plugin to your build.gradle: 70 | 71 | ```Groovy 72 | // apply this plugin after you have applied other plugins 73 | // because it uses the state of other plugins 74 | apply plugin: 'com.google.cloud.tools.endpoints-framework-client' 75 | ``` 76 | 77 | The plugin exposes **no tasks**. Applying the plugin will generate sources according 78 | to your configuration 79 | 80 | The plugin exposes client side configuration through the `endpointsClient` extension 81 | * `discoveryDocs` - List of discovery docs to generate source from 82 | 83 | The plugin exposes intermodule endpoints configuration through a custom dependency 84 | * `endpointsServer` - Configure generation of source from another module in the project 85 | 86 | #### Usage (from discovery docs) 87 | In your build.gradle define the location of the discovery document in the 88 | `endpointsClient` configuration closure. 89 | 90 | ```Groovy 91 | endpointsClient { 92 | discoveryDocs = ['src/endpoints/myApi-v1-rest.discovery'] 93 | } 94 | ``` 95 | 96 | building your project should inject the correct generated source into your compile path. 97 | 98 | #### Usage (from server module in project) 99 | In your build.gradle define the correct project dependency, the server project must be 100 | an `endpoints-framework-server` module for this to work. 101 | 102 | ```Groovy 103 | dependencies { 104 | endpointsServer project(path: ":server", configuration: "endpoints") 105 | } 106 | ``` 107 | 108 | building your project should inject the correct generated source into your compile path. 109 | 110 | You can use a combination of discovery doc files and server dependencies when building 111 | a client module, make sure you include all the necessary dependencies for building your 112 | endpoints client 113 | 114 | ```Groovy 115 | dependencies { 116 | compile 'com.google.api-client:google-api-client:' // for standard java projects 117 | compile 'com.google.api-client:google-api-client-android:' exclude module: 'httpclient' // for android projects 118 | } 119 | ``` 120 | 121 | ## Contributing 122 | 123 | If you wish to build this plugin from source, please see the [contributor instructions](CONTRIBUTING.md). 124 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/main/java/com/google/cloud/tools/gradle/endpoints/framework/server/task/EndpointsArtifactTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework.server.task; 18 | 19 | import com.google.api.server.spi.tools.EndpointsTool; 20 | import com.google.common.base.Strings; 21 | import java.io.File; 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | import org.gradle.api.DefaultTask; 25 | import org.gradle.api.file.FileCollection; 26 | import org.gradle.api.plugins.JavaPluginConvention; 27 | import org.gradle.api.tasks.Input; 28 | import org.gradle.api.tasks.InputDirectory; 29 | import org.gradle.api.tasks.InputFiles; 30 | import org.gradle.api.tasks.Internal; 31 | import org.gradle.api.tasks.Optional; 32 | import org.gradle.api.tasks.OutputDirectory; 33 | import org.gradle.api.tasks.SourceSet; 34 | import org.gradle.api.tasks.TaskAction; 35 | 36 | public class EndpointsArtifactTask extends DefaultTask { 37 | // classesDir is only for detecting that the project has changed 38 | private FileCollection classesDirs; 39 | 40 | // internal parameters for task configuration 41 | private String command; 42 | private boolean cleanBeforeRun; 43 | private String outputLanguage; 44 | private String outputBuildSystem; 45 | private String outputFileName; 46 | 47 | // user facing options 48 | private File outputDirectory; 49 | private String hostname; 50 | private String basePath; 51 | private List serviceClasses; 52 | private File webAppDir; 53 | 54 | @InputFiles 55 | public FileCollection getClassesDirs() { 56 | return classesDirs; 57 | } 58 | 59 | public void setClassesDirs(FileCollection classesDirs) { 60 | this.classesDirs = classesDirs; 61 | } 62 | 63 | @Internal 64 | public String getCommand() { 65 | return command; 66 | } 67 | 68 | public void setCommand(String command) { 69 | this.command = command; 70 | } 71 | 72 | @OutputDirectory 73 | public File getOutputDirectory() { 74 | return outputDirectory; 75 | } 76 | 77 | public void setOutputDirectory(File outputDirectory) { 78 | this.outputDirectory = outputDirectory; 79 | } 80 | 81 | @InputDirectory 82 | public File getWebAppDir() { 83 | return webAppDir; 84 | } 85 | 86 | public void setWebAppDir(File webAppDir) { 87 | this.webAppDir = webAppDir; 88 | } 89 | 90 | @Input 91 | public List getServiceClasses() { 92 | return serviceClasses; 93 | } 94 | 95 | public void setServiceClasses(List serviceClasses) { 96 | this.serviceClasses = serviceClasses; 97 | } 98 | 99 | @Optional 100 | @Input 101 | public String getHostname() { 102 | return hostname; 103 | } 104 | 105 | public void setHostname(String hostname) { 106 | this.hostname = hostname; 107 | } 108 | 109 | @Optional 110 | @Input 111 | public String getBasePath() { 112 | return basePath; 113 | } 114 | 115 | public void setBasePath(String basePath) { 116 | this.basePath = basePath; 117 | } 118 | 119 | @Internal 120 | public boolean isCleanBeforeRun() { 121 | return cleanBeforeRun; 122 | } 123 | 124 | public void setCleanBeforeRun(boolean cleanBeforeRun) { 125 | this.cleanBeforeRun = cleanBeforeRun; 126 | } 127 | 128 | @Internal 129 | public String getOutputLanguage() { 130 | return outputLanguage; 131 | } 132 | 133 | public void setOutputLanguage(String outputLanguage) { 134 | this.outputLanguage = outputLanguage; 135 | } 136 | 137 | @Internal 138 | public String getOutputBuildSystem() { 139 | return outputBuildSystem; 140 | } 141 | 142 | public void setOutputBuildSystem(String outputBuildSystem) { 143 | this.outputBuildSystem = outputBuildSystem; 144 | } 145 | 146 | @Internal 147 | public String getOutputFileName() { 148 | return outputFileName; 149 | } 150 | 151 | public void setOutputFileName(String outputFileName) { 152 | this.outputFileName = outputFileName; 153 | } 154 | 155 | /** Task entry point. */ 156 | @TaskAction 157 | void generateEndpointsArtifact() throws Exception { 158 | 159 | if (cleanBeforeRun) { 160 | getProject().delete(outputDirectory); 161 | getProject().mkdir(outputDirectory); 162 | } 163 | 164 | List params = new ArrayList<>(); 165 | 166 | params.add(command); 167 | 168 | params.add("-o"); 169 | if (!Strings.isNullOrEmpty(outputFileName)) { 170 | params.add(new File(outputDirectory, outputFileName).getAbsolutePath()); 171 | } else { 172 | params.add(outputDirectory.getAbsolutePath()); 173 | } 174 | 175 | String classpath = 176 | getProject() 177 | .getConvention() 178 | .getPlugin(JavaPluginConvention.class) 179 | .getSourceSets() 180 | .getByName(SourceSet.MAIN_SOURCE_SET_NAME) 181 | .getRuntimeClasspath() 182 | .getAsPath(); 183 | 184 | params.add("-cp"); 185 | params.add(classpath); 186 | 187 | params.add("-w"); 188 | params.add(webAppDir.getAbsolutePath()); 189 | 190 | if (!Strings.isNullOrEmpty(outputBuildSystem)) { 191 | params.add("-bs"); 192 | params.add(outputBuildSystem); 193 | } 194 | if (!Strings.isNullOrEmpty(outputLanguage)) { 195 | params.add("-l"); 196 | params.add(outputLanguage); 197 | } 198 | if (!Strings.isNullOrEmpty(hostname)) { 199 | params.add("-h"); 200 | params.add(hostname); 201 | } 202 | if (!Strings.isNullOrEmpty(basePath)) { 203 | params.add("-p"); 204 | params.add(basePath); 205 | } 206 | params.addAll(serviceClasses); 207 | 208 | new EndpointsTool().execute(params.toArray(new String[params.size()])); 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /ANDROID_README.md: -------------------------------------------------------------------------------- 1 | ![project status image](https://img.shields.io/badge/stability-experimental-orange.svg) 2 | # Transitioning Android Projects 3 | 4 | Moving legacy projects from Android Studio requires a few extra steps. This will guide you through 5 | that process 6 | 7 | Make sure you have the cloud SDK installed (see the [app-gradle-plugin](https://github.com/GoogleCloudPlatform/app-gradle-plugin) for more) 8 | 9 | This guide starts from an existing android studio project with a cloud backend. 10 | The expected structure is 11 | ``` 12 | 13 | ├── app 14 | ├── backend 15 | └── build.gradle 16 | ``` 17 | 18 | Make changes in the backend/appengine module 19 | 20 | **`/backend/build.gradle`** 21 | 22 | Remove the old appengine plugin jar and add in the new appengine and endpoints jars 23 | ```gradle 24 | buildscript { 25 | ... 26 | dependencies { 27 | // delete this 28 | // classpath 'com.google.appengine:gradle-appengine-plugin:1.9.51' 29 | 30 | // add these 31 | classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2' 32 | classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3' 33 | } 34 | } 35 | ``` 36 | 37 | Remove the old plugin and apply the new ones 38 | ```gradle 39 | // delete this 40 | // apply plugin: 'appengine' 41 | 42 | // add these 43 | apply plugin: 'com.google.cloud.tools.appengine' 44 | apply plugin: 'com.google.cloud.tools.endpoints-framework-server' 45 | ``` 46 | 47 | Remove all the old appengine and endpoints dependencies and add the 48 | new endpoints dependencies 49 | ```gradle 50 | dependencies { 51 | // delete these, we are using the cloud SDK and new endpoints tooling now 52 | // appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.51' 53 | // compile 'com.google.appengine:appengine-endpoints:1.9.51' 54 | // compile 'com.google.appengine:appengine-endpoints-deps:1.9.51' 55 | ... 56 | // add these (inject needs to be explicitly included now) 57 | compile 'com.google.endpoints:endpoints-framework:2.0.9' 58 | compile 'javax.inject:javax.inject:1' 59 | ... 60 | } 61 | 62 | ... 63 | // delete this whole block, it's configuration for the older plugin 64 | // appengine { 65 | // downloadSdk = true 66 | // appcfg { 67 | // oauth2 = true 68 | // } 69 | // endpoints { 70 | // getClientLibsOnBuild = true 71 | // getDiscoveryDocsOnBuild = true 72 | // } 73 | // } 74 | ``` 75 | 76 | Make changes in the android client 77 | 78 | **`/app/build.gradle`** 79 | 80 | Add in the new endpoints jar 81 | ```gradle 82 | buildscript { 83 | ... 84 | dependencies { 85 | // add this 86 | classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2' 87 | } 88 | } 89 | ``` 90 | 91 | Apply the endpoints plugin **after** the android plugin 92 | ```gradle 93 | apply plugin: 'com.android.application' 94 | // add this 95 | apply plugin: 'com.google.cloud.tools.endpoints-framework-client' 96 | ``` 97 | Use the new endpointsServer dependency and remove the old compile dependency, 98 | also explicitly add in the google-api-client dependency 99 | ```gradle 100 | dependencies { 101 | ... 102 | // remove this 103 | // compile project(path: ':backend', configuration: 'android-endpoints') 104 | 105 | // add these 106 | endpointsServer project(path: ':backend', configuration: 'endpoints') 107 | compile "com.google.api-client:google-api-client:+" 108 | } 109 | ``` 110 | 111 | If you have a particularly complicated buildscript classpath bringing in a lot of dependencies with cryptic error messages like 112 | ``` 113 | Execution failed for task ':{project-name}:endpointsDiscoveryDocs'. 114 | > com.google.common.reflect.TypeToken.isSubtypeOf(Ljava/lang/reflect/Type;)Z 115 | ``` 116 | ``` 117 | Execution failed for task ':backend:endpointsDiscoveryDocs'. 118 | > com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z 119 | ``` 120 | ``` 121 | java.lang.NoClassDefFoundError: Could not initialize class com.google.api.server.spi.tools.GenClientLibAction 122 | ``` 123 | See [45](https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/issues/45) or [52](https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/issues/52) for more details. 124 | These are consequences of classpath resolution in multimodule builds (see: [gradle forums](https://discuss.gradle.org/t/version-is-root-build-gradle-buildscript-is-overriding-subproject-buildscript-dependency-versions/20746/2)). 125 | 126 | In this case, the best option is take the advice from the gradle forums and move all the buildscript classpath imports out of `/backend/build.gradle` into the root build file at `/build.gradle`. This helps gradle handle versions of buildscript dependencies much better. 127 | 128 | Make changes in the root, backend and android project. 129 | 130 | **`/build.gradle`** 131 | 132 | ```gradle 133 | buildscript { 134 | repositories { 135 | jcenter() 136 | } 137 | dependencies { 138 | classpath 'com.android.tools.build:gradle:2.2.2' 139 | 140 | // add this 141 | classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2' 142 | classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3' 143 | } 144 | } 145 | ``` 146 | 147 | **`/backend/build.gradle`** 148 | 149 | ```gradle 150 | // delete this whole buildscript block 151 | // buildscript { 152 | // ... 153 | // dependencies { 154 | // add these 155 | // classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2' 156 | // classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3' 157 | // } 158 | // } 159 | ``` 160 | 161 | **`/app/build.gradle`** 162 | 163 | The endpoints jar is now brought in by the root, so remove it from here. 164 | ```gradle 165 | buildscript { 166 | ... 167 | dependencies { 168 | // remove this 169 | // classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2' 170 | } 171 | } 172 | ``` 173 | 174 | 175 | ## Android Studio 176 | Android Studio's App Engine tooling will no long *Gradle Sync* with these plugins, and while things may continue to work on stale configuration, it's not safe to depend on it to always work. 177 | 178 | ### Run 179 | In Android Studio, you need to run the local development server using the gradle task `appengineStart` which starts the development server in non-blocking mode, output will be written to a file which you can monitor. It is not recommended to use `appengienRun` from within Android Studio. If you use `appengineRun` you may block Android Studio from using the gradle daemon to launch any gradle further related tasks. 180 | 181 | ### Deploy 182 | For deploy, you must first [login using glcoud](https://cloud.google.com/sdk/gcloud/reference/auth/login) and then deploy using the gradle task `appengineDeploy` 183 | ``` 184 | $ ./gradlew appengineDeploy 185 | ``` 186 | -------------------------------------------------------------------------------- /src/test/java/com/google/cloud/tools/gradle/endpoints/framework/EndpointsServerPluginTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework; 18 | 19 | import com.google.common.base.Charsets; 20 | import com.google.common.io.CharStreams; 21 | import com.google.common.io.Files; 22 | import java.io.File; 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | import java.io.InputStreamReader; 26 | import java.net.URISyntaxException; 27 | import java.util.zip.ZipFile; 28 | import org.hamcrest.CoreMatchers; 29 | import org.junit.Assert; 30 | import org.junit.Rule; 31 | import org.junit.Test; 32 | import org.junit.rules.TemporaryFolder; 33 | 34 | /** Test endpoints server plugin builds. */ 35 | public class EndpointsServerPluginTest { 36 | 37 | private static final String DEFAULT_HOSTNAME = "myapi.appspot.com"; 38 | private static final String DEFAULT_BASEPATH = "/_ah/api"; 39 | private static final String DEFAULT_URL = "https://" + DEFAULT_HOSTNAME + DEFAULT_BASEPATH; 40 | private static final String DEFAULT_URL_PREFIX = "public static final String DEFAULT_ROOT_URL = "; 41 | private static final String DEFAULT_URL_VARIABLE = 42 | DEFAULT_URL_PREFIX + "\"" + DEFAULT_URL + "/\";"; 43 | private static final String CLIENT_LIB_PATH = "build/endpointsClientLibs/testApi-v1-java.zip"; 44 | private static final String DISC_DOC_PATH = 45 | "build/endpointsDiscoveryDocs/testApi-v1-rest.discovery"; 46 | private static final String API_JAVA_FILE_PATH = 47 | "testApi/src/main/java/com/example/testApi/TestApi.java"; 48 | private static final String OPEN_API_DOC_PATH = "build/endpointsOpenApiDocs/openapi.json"; 49 | 50 | @Rule public TemporaryFolder testProjectDir = new TemporaryFolder(); 51 | 52 | @Test 53 | public void testClientLibs() throws IOException, URISyntaxException { 54 | new TestProject(testProjectDir.getRoot(), "projects/server") 55 | .gradleRunnerArguments("endpointsClientLibs") 56 | .build(); 57 | 58 | assertClientLibGeneration(DEFAULT_URL_VARIABLE, null); 59 | } 60 | 61 | @Test 62 | public void testClientLibs_hostname() throws IOException, URISyntaxException { 63 | new TestProject(testProjectDir.getRoot(), "projects/server") 64 | .hostname("my.hostname.com") 65 | .gradleRunnerArguments("endpointsClientLibs", "--stacktrace") 66 | .build(); 67 | 68 | assertClientLibGeneration( 69 | DEFAULT_URL_PREFIX + "\"https://my.hostname.com" + DEFAULT_BASEPATH + "/\";", 70 | DEFAULT_URL_VARIABLE); 71 | } 72 | 73 | @Test 74 | public void testClientLibs_basePath() throws IOException, URISyntaxException { 75 | new TestProject(testProjectDir.getRoot(), "projects/server") 76 | .basePath("/a/different/path") 77 | .gradleRunnerArguments("endpointsClientLibs") 78 | .build(); 79 | 80 | assertClientLibGeneration( 81 | DEFAULT_URL_PREFIX + "\"https://" + DEFAULT_HOSTNAME + "/a/different/path/\";", 82 | DEFAULT_URL_VARIABLE); 83 | } 84 | 85 | @Test 86 | public void testClientLibs_application() throws IOException, URISyntaxException { 87 | new TestProject(testProjectDir.getRoot(), "projects/server") 88 | .applicationId("gradle-test") 89 | .gradleRunnerArguments("endpointsClientLibs") 90 | .build(); 91 | 92 | assertClientLibGeneration( 93 | DEFAULT_URL_PREFIX + "\"https://gradle-test.appspot.com" + DEFAULT_BASEPATH + "/\";", 94 | DEFAULT_URL_VARIABLE); 95 | } 96 | 97 | private void assertClientLibGeneration(String expected, String unexpected) throws IOException { 98 | File clientLib = new File(testProjectDir.getRoot(), CLIENT_LIB_PATH); 99 | Assert.assertTrue(clientLib.exists()); 100 | Assert.assertEquals(1, clientLib.getParentFile().listFiles().length); 101 | String apiJavaFile = getFileContentsInZip(clientLib, API_JAVA_FILE_PATH); 102 | Assert.assertThat(apiJavaFile, CoreMatchers.containsString(expected)); 103 | if (unexpected != null) { 104 | Assert.assertThat(apiJavaFile, CoreMatchers.not(CoreMatchers.containsString(unexpected))); 105 | } 106 | } 107 | 108 | private String getFileContentsInZip(File zipFile, String path) throws IOException { 109 | try (ZipFile zip = new ZipFile(zipFile)) { 110 | InputStream is = zip.getInputStream(zip.getEntry(path)); 111 | return CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8)); 112 | } 113 | } 114 | 115 | @Test 116 | public void testDiscoveryDocs() throws IOException, URISyntaxException { 117 | new TestProject(testProjectDir.getRoot(), "projects/server") 118 | .gradleRunnerArguments("endpointsDiscoveryDocs") 119 | .build(); 120 | 121 | assertDiscoveryDocGeneration(DEFAULT_URL, null); 122 | } 123 | 124 | @Test 125 | public void testDiscoveryDocs_hostname() throws IOException, URISyntaxException { 126 | new TestProject(testProjectDir.getRoot(), "projects/server") 127 | .hostname("my.hostname.com") 128 | .gradleRunnerArguments("endpointsDiscoveryDocs") 129 | .build(); 130 | 131 | assertDiscoveryDocGeneration("https://my.hostname.com/_ah/api", DEFAULT_URL); 132 | } 133 | 134 | @Test 135 | public void testDiscoveryDocs_basePath() throws IOException, URISyntaxException { 136 | new TestProject(testProjectDir.getRoot(), "projects/server") 137 | .basePath("/a/different/path") 138 | .gradleRunnerArguments("endpointsDiscoveryDocs") 139 | .build(); 140 | 141 | assertDiscoveryDocGeneration("https://" + DEFAULT_HOSTNAME + "/a/different/path", DEFAULT_URL); 142 | } 143 | 144 | @Test 145 | public void testDiscoveryDocs_application() throws IOException, URISyntaxException { 146 | new TestProject(testProjectDir.getRoot(), "projects/server") 147 | .applicationId("gradle-test") 148 | .gradleRunnerArguments("endpointsDiscoveryDocs") 149 | .build(); 150 | 151 | assertDiscoveryDocGeneration("https://gradle-test.appspot.com/_ah/api", DEFAULT_URL); 152 | } 153 | 154 | private void assertDiscoveryDocGeneration(String expected, String unexpected) throws IOException { 155 | File discoveryDoc = new File(testProjectDir.getRoot(), DISC_DOC_PATH); 156 | String discovery = Files.toString(discoveryDoc, Charsets.UTF_8); 157 | Assert.assertThat(discovery, CoreMatchers.containsString(expected)); 158 | if (unexpected != null) { 159 | Assert.assertThat(discovery, CoreMatchers.not(CoreMatchers.containsString(unexpected))); 160 | } 161 | } 162 | 163 | @Test 164 | public void testOpenApiDocs() throws IOException, URISyntaxException { 165 | new TestProject(testProjectDir.getRoot(), "projects/server") 166 | .gradleRunnerArguments("endpointsOpenApiDocs", "--stacktrace") 167 | .build(); 168 | 169 | assertOpenApiDocGeneration(DEFAULT_HOSTNAME, null); 170 | } 171 | 172 | @Test 173 | public void testOpenApiDocs_hostname() throws IOException, URISyntaxException { 174 | new TestProject(testProjectDir.getRoot(), "projects/server") 175 | .hostname("my.hostname.com") 176 | .gradleRunnerArguments("endpointsOpenApiDocs") 177 | .build(); 178 | 179 | assertOpenApiDocGeneration("my.hostname.com", DEFAULT_HOSTNAME); 180 | } 181 | 182 | @Test 183 | public void testOpenApiDocs_basePath() throws IOException, URISyntaxException { 184 | new TestProject(testProjectDir.getRoot(), "projects/server") 185 | .basePath("/a/different/path") 186 | .gradleRunnerArguments("endpointsOpenApiDocs") 187 | .build(); 188 | 189 | assertOpenApiDocGeneration("/a/different/path", DEFAULT_BASEPATH); 190 | } 191 | 192 | @Test 193 | public void testOpenApiDocs_application() throws IOException, URISyntaxException { 194 | new TestProject(testProjectDir.getRoot(), "projects/server") 195 | .applicationId("gradle-test") 196 | .gradleRunnerArguments("endpointsOpenApiDocs") 197 | .build(); 198 | 199 | assertOpenApiDocGeneration("gradle-test.appspot.com", DEFAULT_HOSTNAME); 200 | } 201 | 202 | private void assertOpenApiDocGeneration(String expected, String unexpected) throws IOException { 203 | File openApiDoc = new File(testProjectDir.getRoot(), OPEN_API_DOC_PATH); 204 | String openApi = Files.toString(openApiDoc, Charsets.UTF_8); 205 | Assert.assertThat(openApi, CoreMatchers.containsString(expected)); 206 | if (unexpected != null) { 207 | Assert.assertThat(openApi, CoreMatchers.not(CoreMatchers.containsString(unexpected))); 208 | } 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /src/main/java/com/google/cloud/tools/gradle/endpoints/framework/server/EndpointsServerPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework.server; 18 | 19 | import com.google.api.server.spi.tools.GetClientLibAction; 20 | import com.google.api.server.spi.tools.GetDiscoveryDocAction; 21 | import com.google.api.server.spi.tools.GetOpenApiDocAction; 22 | import com.google.cloud.tools.gradle.endpoints.framework.server.task.EndpointsArtifactTask; 23 | import org.gradle.api.Action; 24 | import org.gradle.api.Plugin; 25 | import org.gradle.api.Project; 26 | import org.gradle.api.file.FileCollection; 27 | import org.gradle.api.plugins.JavaPlugin; 28 | import org.gradle.api.plugins.JavaPluginConvention; 29 | import org.gradle.api.plugins.WarPluginConvention; 30 | import org.gradle.api.tasks.SourceSet; 31 | import org.gradle.api.tasks.bundling.Zip; 32 | 33 | /** 34 | * Plugin definition for Endpoints Servers (on App Engine) for generation of client libraries, 35 | * openapi and discovery docs. 36 | * 37 | *

Also provides the artifact "{@value #ARTIFACT_CONFIGURATION}" that is a zip of all the 38 | * discovery docs that this server exposes (as defined in web.xml) 39 | */ 40 | public class EndpointsServerPlugin implements Plugin { 41 | 42 | public static final String GENERATE_OPENAPI_DOC_TASK = "endpointsOpenApiDocs"; 43 | public static final String GENERATE_DISCOVERY_DOC_TASK = "endpointsDiscoveryDocs"; 44 | public static final String GENERATE_CLINT_LIBS_TASK = "endpointsClientLibs"; 45 | public static final String SERVER_EXTENSION = "endpointsServer"; 46 | public static final String ARTIFACT_CONFIGURATION = "endpoints"; 47 | 48 | private static final String APP_ENGINE_ENDPOINTS = "App Engine Endpoints"; 49 | 50 | private Project project; 51 | private EndpointsServerExtension extension; 52 | 53 | /** Plugin entry point. */ 54 | public void apply(Project project) { 55 | this.project = project; 56 | 57 | createExtension(); 58 | configureEndpointsArtifactTaskAdditionCallback(); 59 | createDiscoverDocConfiguration(); 60 | createGenerateDiscoveryDocsTask(); 61 | createGenerateOpenApiDocsTask(); 62 | createGenerateClientLibsTask(); 63 | } 64 | 65 | private void createExtension() { 66 | extension = 67 | project.getExtensions().create(SERVER_EXTENSION, EndpointsServerExtension.class, project); 68 | } 69 | 70 | // populate common configuration for all endpoints tasks 71 | private void configureEndpointsArtifactTaskAdditionCallback() { 72 | project 73 | .getTasks() 74 | .withType(EndpointsArtifactTask.class) 75 | .whenTaskAdded( 76 | new Action() { 77 | @Override 78 | public void execute(final EndpointsArtifactTask task) { 79 | final FileCollection classesDirs = 80 | project 81 | .getConvention() 82 | .getPlugin(JavaPluginConvention.class) 83 | .getSourceSets() 84 | .getByName(SourceSet.MAIN_SOURCE_SET_NAME) 85 | .getOutput() 86 | .getClassesDirs(); 87 | 88 | project.afterEvaluate( 89 | new Action() { 90 | @Override 91 | public void execute(Project project) { 92 | 93 | task.setClassesDirs(classesDirs); 94 | task.setHostname(extension.getHostname()); 95 | task.setBasePath(extension.getBasePath()); 96 | task.setServiceClasses(extension.getServiceClasses()); 97 | task.setWebAppDir( 98 | project 99 | .getConvention() 100 | .getPlugin(WarPluginConvention.class) 101 | .getWebAppDir()); 102 | } 103 | }); 104 | } 105 | }); 106 | } 107 | 108 | private void createDiscoverDocConfiguration() { 109 | project.afterEvaluate( 110 | new Action() { 111 | @Override 112 | public void execute(Project project) { 113 | project.getConfigurations().create(ARTIFACT_CONFIGURATION); 114 | Zip discoveryDocArchive = project.getTasks().create("_zipDiscoveryDocs", Zip.class); 115 | discoveryDocArchive.dependsOn(GENERATE_DISCOVERY_DOC_TASK); 116 | discoveryDocArchive.from(extension.getDiscoveryDocDir()); 117 | discoveryDocArchive 118 | .getArchiveFileName() 119 | .set(project.getName() + "-" + "discoveryDocs.zip"); 120 | 121 | project.getArtifacts().add(ARTIFACT_CONFIGURATION, discoveryDocArchive); 122 | } 123 | }); 124 | } 125 | 126 | private void createGenerateDiscoveryDocsTask() { 127 | project 128 | .getTasks() 129 | .create( 130 | GENERATE_DISCOVERY_DOC_TASK, 131 | EndpointsArtifactTask.class, 132 | new Action() { 133 | @Override 134 | public void execute(final EndpointsArtifactTask genDiscoveryDocs) { 135 | genDiscoveryDocs.setCommand(GetDiscoveryDocAction.NAME); 136 | genDiscoveryDocs.setDescription("Generate endpoints discovery documents"); 137 | genDiscoveryDocs.setCleanBeforeRun(true); 138 | genDiscoveryDocs.setGroup(APP_ENGINE_ENDPOINTS); 139 | genDiscoveryDocs.dependsOn(JavaPlugin.CLASSES_TASK_NAME); 140 | 141 | project.afterEvaluate( 142 | new Action() { 143 | @Override 144 | public void execute(Project project) { 145 | 146 | genDiscoveryDocs.setOutputDirectory(extension.getDiscoveryDocDir()); 147 | } 148 | }); 149 | } 150 | }); 151 | } 152 | 153 | private void createGenerateOpenApiDocsTask() { 154 | project 155 | .getTasks() 156 | .create( 157 | GENERATE_OPENAPI_DOC_TASK, 158 | EndpointsArtifactTask.class, 159 | new Action() { 160 | @Override 161 | public void execute(final EndpointsArtifactTask genOpenApiDocs) { 162 | genOpenApiDocs.setCommand(GetOpenApiDocAction.NAME); 163 | genOpenApiDocs.setDescription("Generate endpoints Open API documents"); 164 | genOpenApiDocs.setCleanBeforeRun(true); 165 | genOpenApiDocs.setGroup(APP_ENGINE_ENDPOINTS); 166 | genOpenApiDocs.dependsOn(JavaPlugin.CLASSES_TASK_NAME); 167 | genOpenApiDocs.setOutputFileName("openapi.json"); 168 | 169 | project.afterEvaluate( 170 | new Action() { 171 | @Override 172 | public void execute(Project project) { 173 | genOpenApiDocs.setOutputDirectory(extension.getOpenApiDocDir()); 174 | } 175 | }); 176 | } 177 | }); 178 | } 179 | 180 | private void createGenerateClientLibsTask() { 181 | project 182 | .getTasks() 183 | .create( 184 | GENERATE_CLINT_LIBS_TASK, 185 | EndpointsArtifactTask.class, 186 | new Action() { 187 | @Override 188 | public void execute(final EndpointsArtifactTask genClientLibs) { 189 | genClientLibs.setCommand(GetClientLibAction.NAME); 190 | genClientLibs.setDescription("Generate endpoints client libraries"); 191 | genClientLibs.setCleanBeforeRun(false); 192 | genClientLibs.setOutputLanguage("java"); 193 | genClientLibs.setOutputBuildSystem("gradle"); 194 | genClientLibs.setGroup(APP_ENGINE_ENDPOINTS); 195 | genClientLibs.dependsOn(JavaPlugin.CLASSES_TASK_NAME); 196 | 197 | project.afterEvaluate( 198 | new Action() { 199 | @Override 200 | public void execute(Project project) { 201 | genClientLibs.setOutputDirectory(extension.getClientLibDir()); 202 | } 203 | }); 204 | } 205 | }); 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /src/main/java/com/google/cloud/tools/gradle/endpoints/framework/client/EndpointsClientPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Google Inc. All Right Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.cloud.tools.gradle.endpoints.framework.client; 18 | 19 | import com.google.cloud.tools.gradle.endpoints.framework.client.task.ExtractDiscoveryDocZipsTask; 20 | import com.google.cloud.tools.gradle.endpoints.framework.client.task.GenerateClientLibrariesTask; 21 | import com.google.cloud.tools.gradle.endpoints.framework.client.task.GenerateClientLibrarySourceTask; 22 | import com.google.cloud.tools.gradle.endpoints.framework.server.EndpointsServerPlugin; 23 | import com.google.common.collect.ImmutableMap; 24 | import java.io.File; 25 | import java.util.Collection; 26 | import org.gradle.api.Action; 27 | import org.gradle.api.Plugin; 28 | import org.gradle.api.Project; 29 | import org.gradle.api.plugins.JavaPluginConvention; 30 | import org.gradle.api.tasks.SourceSet; 31 | import org.gradle.api.tasks.SourceSetContainer; 32 | import org.gradle.api.tasks.compile.AbstractCompile; 33 | 34 | /** 35 | * Plugin definition for Endpoints Clients. All tasks from this plugin are internal, it will 36 | * automatically generate source into build/endpointsGenSrc (see {@link EndpointsClientExtension}) 37 | * based on the user's configuration. 38 | * 39 | *

Configuration of source discovery docs is from two ways: 40 | * 41 | *

1. specify the location of the discovery doc with the extension. 42 | * 43 | *

{@code
 44 |  * endpointsClient {
 45 |  *   discoveryDocs = [file(path/to/xyz.discovery)]
 46 |  * }
 47 |  * }
48 | * 49 | *

2. depend directly on another project that has the endpoints server plugin. 50 | * 51 | *

{@code
 52 |  * dependencies {
 53 |  *   endpointsServer project(path: ":server",
 54 |  *       configuration: {@value EndpointsServerPlugin#ARTIFACT_CONFIGURATION});
 55 |  * }
 56 |  * }
57 | * 58 | *

Independent of what mechanism above is used, the user must still explicitly add a dependency 59 | * on the google api client library. 60 | * 61 | *

{@code
 62 |  * dependencies {
 63 |  *   compile "com.google.api-client:google-api-client:+"
 64 |  * }
 65 |  * }
66 | */ 67 | public class EndpointsClientPlugin implements Plugin { 68 | 69 | public static final String GENERATE_CLIENT_LIBRARY_TASK = "_endpointsClientLibs"; 70 | public static final String GENERATE_CLIENT_LIBRARY_SRC_TASK = "_endpointsClientGenSrc"; 71 | public static final String EXTRACT_SERVER_DISCOVERY_DOCS_TASK = "_extractServerDiscoveryDocs"; 72 | 73 | public static final String ENDPOINTS_CLIENT_EXTENSION = "endpointsClient"; 74 | public static final String ENDPOINTS_SERVER_CONFIGURATION = "endpointsServer"; 75 | 76 | private Project project; 77 | private EndpointsClientExtension extension; 78 | 79 | /** Plugin entry point. */ 80 | public void apply(Project project) { 81 | this.project = project; 82 | createExtension(); 83 | createConfiguration(); 84 | createExtractServerDiscoveryDocsTask(); 85 | createGenerateClientLibTask(); 86 | createGenerateClientLibSrcTask(); 87 | } 88 | 89 | private void createExtension() { 90 | extension = 91 | project 92 | .getExtensions() 93 | .create(ENDPOINTS_CLIENT_EXTENSION, EndpointsClientExtension.class, project); 94 | } 95 | 96 | private void createConfiguration() { 97 | project 98 | .getConfigurations() 99 | .create(ENDPOINTS_SERVER_CONFIGURATION) 100 | .setDescription( 101 | "endpointsServer project(path: ':xyz', configuration: '" 102 | + EndpointsServerPlugin.ARTIFACT_CONFIGURATION 103 | + "')") 104 | .setVisible(false); 105 | } 106 | 107 | // extract discovery docs from "endpointsServer" configurations 108 | private void createExtractServerDiscoveryDocsTask() { 109 | project 110 | .getTasks() 111 | .create( 112 | EXTRACT_SERVER_DISCOVERY_DOCS_TASK, 113 | ExtractDiscoveryDocZipsTask.class, 114 | new Action() { 115 | @Override 116 | public void execute(final ExtractDiscoveryDocZipsTask extractDiscoveryDocs) { 117 | extractDiscoveryDocs.setDescription("_internal"); 118 | // iterate through the configuration and get all artifacts (discovery doc zips) 119 | project.afterEvaluate( 120 | new Action() { 121 | @Override 122 | public void execute(Project project) { 123 | Collection files = 124 | project 125 | .getConfigurations() 126 | .getByName(ENDPOINTS_SERVER_CONFIGURATION) 127 | .getFiles(); 128 | extractDiscoveryDocs.setDiscoveryDocZips(files); 129 | extractDiscoveryDocs.setDiscoveryDocsDir( 130 | extension.getGenDiscoveryDocsDir()); 131 | } 132 | }); 133 | } 134 | }); 135 | 136 | // make sure we depend on the server configuration build tasks, so those get run 137 | // before we run our task to get the discovery docs, for some reason with the android plugin, 138 | // this needs to be done outside the task configuration block above. 139 | project.afterEvaluate( 140 | new Action() { 141 | @Override 142 | public void execute(Project project) { 143 | project 144 | .getTasks() 145 | .getByName(EXTRACT_SERVER_DISCOVERY_DOCS_TASK) 146 | .dependsOn( 147 | project 148 | .getConfigurations() 149 | .getByName(ENDPOINTS_SERVER_CONFIGURATION) 150 | .getBuildDependencies()); 151 | } 152 | }); 153 | } 154 | 155 | private void createGenerateClientLibTask() { 156 | project 157 | .getTasks() 158 | .create( 159 | GENERATE_CLIENT_LIBRARY_TASK, 160 | GenerateClientLibrariesTask.class, 161 | new Action() { 162 | @Override 163 | public void execute(final GenerateClientLibrariesTask genClientLibs) { 164 | genClientLibs.setDescription("_internal"); 165 | genClientLibs.dependsOn(EXTRACT_SERVER_DISCOVERY_DOCS_TASK); 166 | 167 | project.afterEvaluate( 168 | new Action() { 169 | @Override 170 | public void execute(Project project) { 171 | genClientLibs.setClientLibraryDir(extension.getClientLibDir()); 172 | genClientLibs.setDiscoveryDocs(extension.getDiscoveryDocs()); 173 | genClientLibs.setGeneratedDiscoveryDocs(extension.getGenDiscoveryDocsDir()); 174 | } 175 | }); 176 | } 177 | }); 178 | } 179 | 180 | private void createGenerateClientLibSrcTask() { 181 | project 182 | .getTasks() 183 | .create( 184 | GENERATE_CLIENT_LIBRARY_SRC_TASK, 185 | GenerateClientLibrarySourceTask.class, 186 | new Action() { 187 | @Override 188 | public void execute(final GenerateClientLibrarySourceTask genClientLibSrc) { 189 | genClientLibSrc.setDescription("_internal"); 190 | genClientLibSrc.dependsOn(GENERATE_CLIENT_LIBRARY_TASK); 191 | 192 | project.afterEvaluate( 193 | new Action() { 194 | @Override 195 | public void execute(Project project) { 196 | genClientLibSrc.setClientLibDir(extension.getClientLibDir()); 197 | genClientLibSrc.setGeneratedSrcDir(extension.getGenSrcDir()); 198 | } 199 | }); 200 | } 201 | }); 202 | 203 | if (project.getExtensions().findByName("android") != null) { 204 | // special handling for android is done in groovy by the android specific plugin 205 | project.apply( 206 | ImmutableMap.of("plugin", "com.google.cloud.tools.endpoints-framework-android-client")); 207 | } else { 208 | // this is for standard java applications 209 | // since we are generating sources add the gen-src directory to the main java sourceset 210 | project 211 | .getTasks() 212 | .withType( 213 | AbstractCompile.class, 214 | new Action() { 215 | @Override 216 | public void execute(AbstractCompile compile) { 217 | compile.dependsOn(GENERATE_CLIENT_LIBRARY_SRC_TASK); 218 | } 219 | }); 220 | JavaPluginConvention java = project.getConvention().getPlugin(JavaPluginConvention.class); 221 | SourceSetContainer sourceSets = java.getSourceSets(); 222 | SourceSet mainSrc = sourceSets.getByName("main"); 223 | mainSrc.getJava().srcDir(extension.getGenSrcDir()); 224 | } 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------