defaulted sources to go to src/gen/main and added possibility to set impl folder via system property at command-line

This commit is contained in:
Ole Lensmar 2015-05-20 16:49:50 -06:00
parent adcd0f4bb8
commit 17d8d14cc8
3 changed files with 61 additions and 11 deletions

View File

@ -54,10 +54,16 @@ public class Generate implements Runnable {
"Pass in a URL-encoded string of name:header with a comma separating multiple values")
private String auth;
@Option( name= {"-D"}, title = "system properties", description = "sets specified system properties in " +
"the format of name=value,name=value")
private String systemProperties;
@Override
public void run() {
verbosed(verbose);
setSystemProperties();
ClientOptInput input = new ClientOptInput();
if (isNotEmpty(auth)) {
@ -77,6 +83,17 @@ public class Generate implements Runnable {
new DefaultGenerator().opts(input.opts(new ClientOpts()).swagger(swagger)).generate();
}
private void setSystemProperties() {
if( systemProperties != null && systemProperties.length() > 0 ){
for( String property : systemProperties.split(",")) {
int ix = property.indexOf('=');
if( ix > 0 && ix < property.length()-1 ){
System.setProperty( property.substring(0, ix), property.substring(ix+1) );
}
}
}
}
/**
* If true parameter, adds system properties which enables debug mode in generator
* @param verbose - if true, enables debug mode

View File

@ -1,8 +1,6 @@
package com.wordnik.swagger.codegen.languages;
import com.wordnik.swagger.models.Operation;
import com.wordnik.swagger.models.Path;
import com.wordnik.swagger.util.Json;
import com.wordnik.swagger.codegen.*;
import com.wordnik.swagger.models.properties.*;
@ -14,7 +12,6 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
protected String groupId = "io.swagger";
protected String artifactId = "swagger-jaxrs-server";
protected String artifactVersion = "1.0.0";
protected String sourceFolder = "src/main/java";
protected String title = "Swagger Server";
public CodegenType getTag() {
@ -32,7 +29,9 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
public JaxRSServerCodegen() {
super();
outputFolder = "generated-code/javaJaxRS";
sourceFolder = "src/gen/java";
outputFolder = System.getProperty( "swagger.codegen.jaxrs.genfolder", "generated-code/javaJaxRS" );
modelTemplateFiles.put("model.mustache", ".java");
apiTemplateFiles.put("api.mustache", ".java");
apiTemplateFiles.put("apiService.mustache", ".java");
@ -40,8 +39,8 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
apiTemplateFiles.put("apiServiceFactory.mustache", ".java");
templateDir = "JavaJaxRS";
apiPackage = "io.swagger.api";
modelPackage = "io.swagger.model";
apiPackage = System.getProperty( "swagger.codegen.jaxrs.apipackage", "io.swagger.api") ;
modelPackage = System.getProperty( "swagger.codegen.jaxrs.modelpackage", "io.swagger.model" );
additionalProperties.put("invokerPackage", invokerPackage);
additionalProperties.put("groupId", groupId);
@ -158,20 +157,35 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
String result = super.apiFilename(templateName, tag);
if( templateName.endsWith( "Impl.mustache")){
int ix = result.lastIndexOf( '/' );
result = result.substring( 0, ix ) + "/impl" + result.substring( ix, result.length()-5 ) + "ServiceImpl.java";
} else if( templateName.endsWith( "Service.mustache")){
int ix = result.lastIndexOf( '.' );
result = result.substring( 0, ix ) + "Service.java";
int ix = result.lastIndexOf( '/' );
result = result.substring( 0, ix ) + "/impl" + result.substring( ix, result.length()-5 ) + "ServiceImpl.java";
String output = System.getProperty( "swagger.codegen.jaxrs.impl.source" );
if( output != null ){
result = result.replace( apiFileFolder(), implFileFolder(output));
}
}
else if( templateName.endsWith( "Factory.mustache")){
int ix = result.lastIndexOf( '/' );
result = result.substring( 0, ix ) + "/factories" + result.substring( ix, result.length()-5 ) + "ServiceFactory.java";
String output = System.getProperty( "swagger.codegen.jaxrs.impl.source" );
if( output != null ){
result = result.replace( apiFileFolder(), implFileFolder(output));
}
}
else if( templateName.endsWith( "Service.mustache")) {
int ix = result.lastIndexOf('.');
result = result.substring(0, ix) + "Service.java";
}
return result;
}
private String implFileFolder(String output) {
return outputFolder + "/" + output + "/" + apiPackage().replace('.', File.separatorChar);
}
public boolean shouldOverwrite( String filename ){
return !filename.endsWith( "ServiceImpl.java") && !filename.endsWith( "ServiceFactory.java");

View File

@ -62,6 +62,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/gen/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>