Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle support: Refactor configuration #295

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Issue #274 Extract a common interface for getting configuration prope…
…rites

- Extract ConfigSource interface which is implemented by DefaultConfig, MavenDefaultConfig and the Mojo
- MavenDefaultConfig: Replace usages of SpringMvcEndpointGeneratorMojo with ConfigSource, so we can still overlay properties from DefaultConfig
  • Loading branch information
tburny committed Jan 2, 2019
commit fec42c54a3262cc63252456511e7276350017f7a
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.phoenixnap.oss.ramlplugin.raml2code.plugin;

import com.phoenixnap.oss.ramlplugin.raml2code.helpers.NamingHelper;

public interface ConfigSource {
PojoGenerationConfig getPojoConfig();

Boolean isSeperateMethodsByContentType();

Boolean isInjectHttpHeadersParameter();

Integer getResourceDepthInClassNames();

Integer getResourceTopLevelInClassNames();

Boolean isReverseOrderInClassNames();

String getBasePackage();

MethodsNamingLogic getMethodsNamingLogic();

OverrideNamingLogicWith getOverrideNamingLogicWith();

String getDontGenerateForAnnotation();

Boolean isInjectHttpRequestParameter();

default String getPojoPackage() {
return getBasePackage() + NamingHelper.getDefaultModelPackage();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.phoenixnap.oss.ramlplugin.raml2code.plugin;

import com.phoenixnap.oss.ramlplugin.raml2code.helpers.NamingHelper;

// TODO Extract interface
class DefaultConfig {
class DefaultConfig implements ConfigSource {

private PojoGenerationConfig pojoGenerationConfig = new PojoGenerationConfig();

Expand Down Expand Up @@ -41,6 +38,7 @@ public void setPojoConfig(PojoGenerationConfig pojoGenerationConfig) {
this.pojoGenerationConfig = pojoGenerationConfig;
}

@Override
public PojoGenerationConfig getPojoConfig() {
return pojoGenerationConfig;
}
Expand All @@ -49,6 +47,7 @@ public void setSeperateMethodsByContentType(Boolean seperateMethodsByContentType
this.seperateMethodsByContentType = seperateMethodsByContentType;
}

@Override
public Boolean isSeperateMethodsByContentType() {
return seperateMethodsByContentType;
}
Expand All @@ -57,6 +56,7 @@ public void setInjectHttpHeadersParameter(Boolean injectHttpHeadersParameter) {
this.injectHttpHeadersParameter = injectHttpHeadersParameter;
}

@Override
public Boolean isInjectHttpHeadersParameter() {
return injectHttpHeadersParameter;
}
Expand All @@ -65,6 +65,7 @@ public void setResourceDepthInClassNames(Integer resourceDepthInClassNames) {
this.resourceDepthInClassNames = resourceDepthInClassNames;
}

@Override
public Integer getResourceDepthInClassNames() {
return resourceDepthInClassNames;
}
Expand All @@ -73,6 +74,7 @@ public void setResourceTopLevelInClassNames(Integer resourceTopLevelInClassNames
this.resourceTopLevelInClassNames = resourceTopLevelInClassNames;
}

@Override
public Integer getResourceTopLevelInClassNames() {
return resourceTopLevelInClassNames;
}
Expand All @@ -81,6 +83,7 @@ public void setReverseOrderInClassNames(Boolean reverseOrderInClassNames) {
this.reverseOrderInClassNames = reverseOrderInClassNames;
}

@Override
public Boolean isReverseOrderInClassNames() {
return reverseOrderInClassNames;
}
Expand All @@ -89,10 +92,12 @@ public void setBasePackage(String basePackage) {
this.basePackage = basePackage;
}

@Override
public String getBasePackage() {
return basePackage;
}

@Override
public MethodsNamingLogic getMethodsNamingLogic() {
if (methodsNamingLogic == null) {
return DEFAULT_METHODS_NAMING_LOGIC;
Expand All @@ -104,6 +109,7 @@ public void setMethodsNamingLogic(MethodsNamingLogic methodsNamingLogic) {
this.methodsNamingLogic = methodsNamingLogic;
}

@Override
public OverrideNamingLogicWith getOverrideNamingLogicWith() {
return overrideNamingLogicWith;
}
Expand All @@ -112,6 +118,7 @@ public void setOverrideNamingLogicWith(OverrideNamingLogicWith overrideNamingLog
this.overrideNamingLogicWith = overrideNamingLogicWith;
}

@Override
public String getDontGenerateForAnnotation() {
return dontGenerateForAnnotation;
}
Expand All @@ -120,16 +127,12 @@ public void setDontGenerateForAnnotation(String dontGenerateForAnnotation) {
this.dontGenerateForAnnotation = dontGenerateForAnnotation;
}

@Override
public Boolean isInjectHttpRequestParameter() {
return injectHttpRequestParameter;
}

public void setInjectHttpRequestParameter(Boolean injectHttpRequestParameter) {
this.injectHttpRequestParameter = injectHttpRequestParameter;
}

public String getPojoPackage() {
return getBasePackage() + NamingHelper.getDefaultModelPackage();
}

}
Original file line number Diff line number Diff line change
@@ -1,93 +1,91 @@
package com.phoenixnap.oss.ramlplugin.raml2code.plugin;

import com.phoenixnap.oss.ramlplugin.raml2code.helpers.NamingHelper;
/**
* A {@link ConfigSource} which allows overriding the default configuration with
* values from a delegate {@link ConfigSource}.
*/
class MavenDefaultConfig extends DefaultConfig implements ConfigSource {

class MavenDefaultConfig extends DefaultConfig {
private final ConfigSource delegate;

private final SpringMvcEndpointGeneratorMojo springMvcEndpointGeneratorMojo;
MavenDefaultConfig(ConfigSource delegate) {
this.delegate = delegate;

MavenDefaultConfig(SpringMvcEndpointGeneratorMojo springMvcEndpointGeneratorMojo) {
this.springMvcEndpointGeneratorMojo = springMvcEndpointGeneratorMojo;

if (springMvcEndpointGeneratorMojo != null) {
setPojoConfig(springMvcEndpointGeneratorMojo.generationConfig);
if (delegate != null) {
setPojoConfig(delegate.getPojoConfig());
} else {
setPojoConfig(null);
}
}

public Boolean isSeperateMethodsByContentType() {
if (springMvcEndpointGeneratorMojo != null) {
return springMvcEndpointGeneratorMojo.seperateMethodsByContentType;
if (delegate != null) {
return delegate.isSeperateMethodsByContentType();
}
return super.isSeperateMethodsByContentType();
}

public Boolean isInjectHttpHeadersParameter() {
if (springMvcEndpointGeneratorMojo != null) {
return springMvcEndpointGeneratorMojo.injectHttpHeadersParameter;
if (delegate != null) {
return delegate.isInjectHttpHeadersParameter();
}
return super.isInjectHttpHeadersParameter();
}

public Integer getResourceDepthInClassNames() {
if (springMvcEndpointGeneratorMojo != null) {
return springMvcEndpointGeneratorMojo.resourceDepthInClassNames;
if (delegate != null) {
return delegate.getResourceDepthInClassNames();
}
return super.getResourceDepthInClassNames();
}

public Integer getResourceTopLevelInClassNames() {
if (springMvcEndpointGeneratorMojo != null) {
return springMvcEndpointGeneratorMojo.resourceTopLevelInClassNames;
if (delegate != null) {
return delegate.getResourceTopLevelInClassNames();
}
return super.getResourceTopLevelInClassNames();
}

public Boolean isReverseOrderInClassNames() {
if (springMvcEndpointGeneratorMojo != null) {
return springMvcEndpointGeneratorMojo.reverseOrderInClassNames;
if (delegate != null) {
return delegate.isReverseOrderInClassNames();
}
return super.isReverseOrderInClassNames();
}

public String getBasePackage() {
if (springMvcEndpointGeneratorMojo != null) {
return springMvcEndpointGeneratorMojo.basePackage;
if (delegate != null) {
return delegate.getBasePackage();
}
return super.getBasePackage();
}

public MethodsNamingLogic getMethodsNamingLogic() {
if (springMvcEndpointGeneratorMojo != null) {
return springMvcEndpointGeneratorMojo.methodsNamingLogic;
if (delegate != null) {
return delegate.getMethodsNamingLogic();
}
return super.getMethodsNamingLogic();
}

public OverrideNamingLogicWith getOverrideNamingLogicWith() {
if (springMvcEndpointGeneratorMojo != null) {
return springMvcEndpointGeneratorMojo.overrideNamingLogicWith;
if (delegate != null) {
return delegate.getOverrideNamingLogicWith();
}
return super.getOverrideNamingLogicWith();
}

public String getDontGenerateForAnnotation() {
if (springMvcEndpointGeneratorMojo != null) {
return springMvcEndpointGeneratorMojo.dontGenerateForAnnotation;
if (delegate != null) {
return delegate.getDontGenerateForAnnotation();
}
return super.getDontGenerateForAnnotation();
}

public Boolean isInjectHttpRequestParameter() {
if (springMvcEndpointGeneratorMojo != null) {
return springMvcEndpointGeneratorMojo.injectHttpRequestParameter;
if (delegate != null) {
return delegate.isInjectHttpRequestParameter();
}
return super.isInjectHttpRequestParameter();
}

public String getPojoPackage() {
return getBasePackage() + NamingHelper.getDefaultModelPackage();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
* @since 0.2.1
*/
@Mojo(name = "generate-springmvc-endpoints", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, threadSafe = true, requiresProject = false)
public class SpringMvcEndpointGeneratorMojo extends AbstractMojo {
public class SpringMvcEndpointGeneratorMojo extends AbstractMojo implements ConfigSource {

/**
* Maven project - required for project info
Expand Down Expand Up @@ -540,4 +540,59 @@ public void execute() throws MojoExecutionException, MojoFailureException {
this.getLog().info("Endpoint Generation Completed in:" + (System.currentTimeMillis() - startTime) + "ms");
}

@Override
public PojoGenerationConfig getPojoConfig() {
return generationConfig;
}

@Override
public Boolean isSeperateMethodsByContentType() {
return seperateMethodsByContentType;
}

@Override
public Boolean isInjectHttpHeadersParameter() {
return injectHttpHeadersParameter;
}

@Override
public Integer getResourceDepthInClassNames() {
return resourceDepthInClassNames;
}

@Override
public Integer getResourceTopLevelInClassNames() {
return resourceTopLevelInClassNames;
}

@Override
public Boolean isReverseOrderInClassNames() {
return reverseOrderInClassNames;
}

@Override
public String getBasePackage() {
return basePackage;
}

@Override
public MethodsNamingLogic getMethodsNamingLogic() {
return methodsNamingLogic;
}

@Override
public OverrideNamingLogicWith getOverrideNamingLogicWith() {
return overrideNamingLogicWith;
}

@Override
public String getDontGenerateForAnnotation() {
return dontGenerateForAnnotation;
}

@Override
public Boolean isInjectHttpRequestParameter() {
return injectHttpRequestParameter;
}

}