Skip to content

Commit

Permalink
Change the android-volley client codegen to an Android library
Browse files Browse the repository at this point in the history
  • Loading branch information
xhh committed Jan 4, 2016
1 parent 563cabe commit 0103c2f
Show file tree
Hide file tree
Showing 89 changed files with 139 additions and 468 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ samples/client/petstore/qt5cpp/build-*
samples/client/petstore/qt5cpp/PetStore/PetStore
samples/client/petstore/qt5cpp/PetStore/Makefile
samples/client/petstore/java/hello.txt
samples/client/petstore/android-java/hello.txt
samples/client/petstore/android/default/hello.txt
samples/client/petstore/objc/Build
samples/client/petstore/objc/Pods
samples/server/petstore/nodejs/node_modules
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ samples/client/petstore/qt5cpp/build-*
samples/client/petstore/qt5cpp/PetStore/PetStore
samples/client/petstore/qt5cpp/PetStore/Makefile
samples/client/petstore/java/hello.txt
samples/client/petstore/android-java/hello.txt
samples/client/petstore/android/default/hello.txt
samples/client/petstore/objc/SwaggerClientTests/Build
samples/client/petstore/objc/SwaggerClientTests/Pods
samples/client/petstore/objc/SwaggerClientTests/SwaggerClient.xcworkspace
Expand Down
2 changes: 1 addition & 1 deletion bin/all-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fi

cd $APP_DIR
./bin/akka-scala-petstore.sh
./bin/android-java-petstore.sh
./bin/android-petstore.sh
./bin/clojure-petstore.sh
./bin/csharp-petstore.sh
./bin/dynamic-html.sh
Expand Down
4 changes: 4 additions & 0 deletions bin/android-petstore-volley.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"library": "volley",
"artifactId": "swagger-petstore-android-volley"
}
4 changes: 2 additions & 2 deletions bin/android-volley-petstore.sh → bin/android-petstore-volley.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t ../modules/swagger-codegen/src/main/resources/android-volley -i ../modules/swagger-codegen/src/test/resources/2_0/petstore.json -l android-volley -o samples/client/petstore/android-volley"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l android -c bin/android-petstore-volley.json -o samples/client/petstore/android/volley"

java $JAVA_OPTS -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
2 changes: 1 addition & 1 deletion bin/android-java-petstore.sh → bin/android-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/android-java -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l android -o samples/client/petstore/android-java"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/android -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l android -o samples/client/petstore/android/default"

java $JAVA_OPTS -jar $executable $ags
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ If Not Exist %executable% (
)

set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
set ags=generate -t modules\swagger-codegen\src\main\resources\android-java -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l android -o samples\client\petstore\android-java
set ags=generate -t modules\swagger-codegen\src\main\resources\android -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l android -o samples\client\petstore\android\default

java %JAVA_OPTS% -jar %executable% %ags%
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
protected String sourceFolder = projectFolder + "/java";
protected Boolean useAndroidMavenGradlePlugin = true;

// requestPackage and authPackage are used by the "volley" template/library
protected String requestPackage = "io.swagger.client.request";
protected String authPackage = "io.swagger.client.auth";

public AndroidClientCodegen() {
super();
outputFolder = "generated-code/android";
modelTemplateFiles.put("model.mustache", ".java");
apiTemplateFiles.put("api.mustache", ".java");
embeddedTemplateDir = templateDir = "android-java";
embeddedTemplateDir = templateDir = "android";
apiPackage = "io.swagger.client.api";
modelPackage = "io.swagger.client.model";

Expand Down Expand Up @@ -70,6 +74,12 @@ public AndroidClientCodegen() {
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC));
cliOptions.add(new CliOption(USE_ANDROID_MAVEN_GRADLE_PLUGIN, "A flag to toggle android-maven gradle plugin.",
BooleanProperty.TYPE).defaultValue(Boolean.TRUE.toString()));

supportedLibraries.put("<default>", "HTTP client: Apache HttpClient 4.3.6. JSON processing: Gson 2.3.1");
supportedLibraries.put("volley", "HTTP client: Volley 1.0.19");
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
library.setEnum(supportedLibraries);
cliOptions.add(library);
}

@Override
Expand Down Expand Up @@ -236,22 +246,67 @@ public void processOpts() {
additionalProperties.put(USE_ANDROID_MAVEN_GRADLE_PLUGIN, useAndroidMavenGradlePlugin);
}

supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
additionalProperties.put(USE_ANDROID_MAVEN_GRADLE_PLUGIN, useAndroidMavenGradlePlugin);
if (additionalProperties.containsKey(CodegenConstants.LIBRARY)) {
this.setLibrary((String) additionalProperties.get(CodegenConstants.LIBRARY));
}

if (StringUtils.isEmpty(getLibrary())) {
addSupportingFilesForDefault();
} else if ("volley".equals(getLibrary())) {
addSupportingFilesForVolley();
}
}

private void addSupportingFilesForDefault() {
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
supportingFiles.add(new SupportingFile("build.mustache", "", "build.gradle"));
supportingFiles.add(new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
supportingFiles.add(new SupportingFile("apiInvoker.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiInvoker.java"));
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "ApiInvoker.java"));
supportingFiles.add(new SupportingFile("httpPatch.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "HttpPatch.java"));
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "HttpPatch.java"));
supportingFiles.add(new SupportingFile("jsonUtil.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "JsonUtil.java"));
supportingFiles.add(new SupportingFile("apiException.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "ApiException.java"));
supportingFiles.add(new SupportingFile("Pair.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "Pair.java"));
}

private void addSupportingFilesForVolley() {
// supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
// supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
supportingFiles.add(new SupportingFile("build.mustache", "", "build.gradle"));
supportingFiles.add(new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
supportingFiles.add(new SupportingFile("apiInvoker.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "ApiInvoker.java"));
supportingFiles.add(new SupportingFile("responses.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "Responses.java"));
// supportingFiles.add(new SupportingFile("httpPatch.mustache",
// (sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "HttpPatch.java"));
supportingFiles.add(new SupportingFile("jsonUtil.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "JsonUtil.java"));
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "JsonUtil.java"));
supportingFiles.add(new SupportingFile("apiException.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiException.java"));
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "ApiException.java"));
supportingFiles.add(new SupportingFile("Pair.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "Pair.java"));
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "Pair.java"));
supportingFiles.add(new SupportingFile("request/getrequest.mustache",
(sourceFolder + File.separator + requestPackage).replace(".", File.separator), "GetRequest.java"));
supportingFiles.add(new SupportingFile("request/postrequest.mustache",
(sourceFolder + File.separator + requestPackage).replace(".", File.separator), "PostRequest.java"));
supportingFiles.add(new SupportingFile("request/putrequest.mustache",
(sourceFolder + File.separator + requestPackage).replace(".", File.separator), "PutRequest.java"));
supportingFiles.add(new SupportingFile("request/deleterequest.mustache",
(sourceFolder + File.separator + requestPackage).replace(".", File.separator), "DeleteRequest.java"));
supportingFiles.add(new SupportingFile("request/patchrequest.mustache",
(sourceFolder + File.separator + requestPackage).replace(".", File.separator), "PatchRequest.java"));
supportingFiles.add(new SupportingFile("auth/apikeyauth.mustache",
(sourceFolder + File.separator + authPackage).replace(".", File.separator), "ApiKeyAuth.java"));
supportingFiles.add(new SupportingFile("auth/httpbasicauth.mustache",
(sourceFolder + File.separator + authPackage).replace(".", File.separator), "HttpBasicAuth.java"));
supportingFiles.add(new SupportingFile("auth/authentication.mustache",
(sourceFolder + File.separator + authPackage).replace(".", File.separator), "Authentication.java"));
}

public Boolean getUseAndroidMavenGradlePlugin() {
Expand Down
Loading

0 comments on commit 0103c2f

Please sign in to comment.