-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new goal to generate sources locally
- add the goal clientSrc to generate client API code locally. Requires the installation of the code generator (python module) - fix warnings in unit tests - clean config files: README, poms
- Loading branch information
Loïc Lambert
committed
Jan 29, 2020
1 parent
ba97513
commit 8d047e3
Showing
12 changed files
with
219 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
.idea | ||
target | ||
*.iml | ||
.classpath | ||
.project | ||
.settings/ | ||
.checkstyle | ||
log.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,12 @@ | |
<groupId>com.google.cloud.tools</groupId> | ||
<artifactId>endpoints-framework-maven-plugin</artifactId> | ||
<!--Version must be in sync with the endpoints framework version--> | ||
<version>2.4.1-aodocs</version> | ||
<version>2.4.2-aodocs-SNAPSHOT</version> | ||
<packaging>maven-plugin</packaging> | ||
|
||
<name>Endpoints Framework Maven Plugin</name> | ||
<description>This Maven plugin provides goals to generate Google Cloud Endpoints Framework client code and discovery docs</description> | ||
<url>https://github.com/GoogleCloudPlatform/endpoints-framework-maven-plugin</url> | ||
<url>https://github.com/AODocs/endpoints-framework-maven-plugin</url> | ||
|
||
<licenses> | ||
<license> | ||
|
@@ -19,33 +19,27 @@ | |
</license> | ||
</licenses> | ||
|
||
<developers> | ||
<developer> | ||
<id>loosebazooka</id> | ||
<name>Appu Goundan</name> | ||
<email>[email protected]</email> | ||
</developer> | ||
</developers> | ||
|
||
<scm> | ||
<connection>scm:git:https://github.com/GoogleCloudPlatform/endpoints-framework-maven-plugin.git | ||
<connection>scm:git:https://github.com/AODocs/endpoints-framework-maven-plugin.git | ||
</connection> | ||
<developerConnection>scm:git:https://github.com/GoogleCloudPlatform/endpoints-framework-maven-plugin.git | ||
<developerConnection>scm:git:https://github.com/AODocs/endpoints-framework-maven-plugin.git | ||
</developerConnection> | ||
<url>https://github.com/GoogleCloudPlatform/endpoints-framework-maven-plugin</url> | ||
<url>https://github.com/AODocs/endpoints-framework-maven-plugin</url> | ||
</scm> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<!-- Should update this version in src/test/resources/projects/server/pom.xml --> | ||
<endpoints-framework.version>2.4.2</endpoints-framework.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.aodocs.endpoints</groupId> | ||
<artifactId>endpoints-framework-tools</artifactId> | ||
<version>2.4.1</version> | ||
<version>${endpoints-framework.version}</version> | ||
</dependency> | ||
|
||
<!--Maven API--> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/com/google/cloud/tools/maven/endpoints/framework/ClientSrcMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.google.cloud.tools.maven.endpoints.framework; | ||
|
||
import com.google.api.server.spi.tools.GetClientSrcAction; | ||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.plugins.annotations.ResolutionScope; | ||
|
||
/** Maven goal to create generated source dir from endpoints. */ | ||
@Mojo( | ||
name = "clientSrc", | ||
requiresDependencyResolution = ResolutionScope.COMPILE, | ||
defaultPhase = LifecyclePhase.GENERATE_SOURCES) | ||
public class ClientSrcMojo extends AbstractEndpointsWebAppMojo { | ||
|
||
/** Output directory for generated sources. */ | ||
@Parameter( | ||
defaultValue = "${project.build.directory}/generated-sources/endpoints", | ||
property = "endpoints.generatedSrcDir", | ||
required = true) | ||
private File generatedSrcDir; | ||
|
||
@Override | ||
protected void preExecute() throws MojoExecutionException { | ||
if (!generatedSrcDir.exists() && !generatedSrcDir.mkdirs()) { | ||
throw new MojoExecutionException( | ||
"Failed to create output directory: " + generatedSrcDir.getAbsolutePath()); | ||
} | ||
project.addCompileSourceRoot(generatedSrcDir.getAbsolutePath()); | ||
} | ||
|
||
@Override | ||
protected String getActionName() { | ||
return GetClientSrcAction.NAME; | ||
} | ||
|
||
@Override | ||
protected File getOutputDirectory() { | ||
return generatedSrcDir; | ||
} | ||
|
||
@Override | ||
protected String getAdditionalParameters() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected void addSpecificParameters(List<String> params) { | ||
params.addAll(Arrays.asList("-l", "java")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/java/com/google/cloud/tools/maven/endpoints/framework/ClientSrcMojoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2017 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.google.cloud.tools.maven.endpoints.framework; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import org.apache.maven.it.VerificationException; | ||
import org.apache.maven.it.Verifier; | ||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
public class ClientSrcMojoTest { | ||
|
||
private static final String GEN_DIR_DEFAULT = "target/generated-sources/endpoints"; | ||
private static final String GEN_DIR_MODIFIED = "src-gen"; | ||
private static final String GENERATED_FILE_PATH = "/com/example/testApi/v1/TestApi.java"; | ||
|
||
@Rule public TemporaryFolder tmpDir = new TemporaryFolder(); | ||
|
||
private void buildAndVerify(File projectDir, String genDir) throws VerificationException { | ||
Verifier verifier = new Verifier(projectDir.getAbsolutePath()); | ||
verifier.executeGoals(Arrays.asList("compile", "endpoints-framework:clientSrc")); | ||
verifier.verifyErrorFreeLog(); | ||
verifier.assertFilePresent(genDir + GENERATED_FILE_PATH); | ||
} | ||
|
||
@Test | ||
public void testDefault() throws XmlPullParserException, IOException, VerificationException { | ||
File testDir = new TestProject(tmpDir.getRoot(), "/projects/server").build(); | ||
|
||
buildAndVerify(testDir, GEN_DIR_DEFAULT); | ||
} | ||
|
||
@Test | ||
public void testGeneratedSrcDir() | ||
throws XmlPullParserException, IOException, VerificationException { | ||
File testDir = | ||
new TestProject(tmpDir.getRoot(), "/projects/server") | ||
.configuration( | ||
"<configuration><generatedSrcDir>" | ||
+ GEN_DIR_MODIFIED | ||
+ "</generatedSrcDir></configuration>") | ||
.build(); | ||
|
||
buildAndVerify(testDir, GEN_DIR_MODIFIED); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.