/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 |
--------------------------------------------------------------------------------