未验证 提交 477a375b 编写于 作者: J Joffrey Bion 提交者: GitHub

Add Gradle plugin parameters for directory support (#44)

Resolves:
https://github.com/kobylynskyi/graphql-java-codegen/issues/30Co-authored-by: NJoffrey Bion <joffrey.bion@booking.com>
上级 889b2246
......@@ -4,13 +4,18 @@ import com.kobylynskyi.graphql.codegen.GraphqlCodegen;
import com.kobylynskyi.graphql.codegen.model.MappingConfig;
import com.kobylynskyi.graphql.codegen.supplier.JsonMappingConfigSupplier;
import com.kobylynskyi.graphql.codegen.supplier.MappingConfigSupplier;
import com.kobylynskyi.graphql.codegen.supplier.SchemaFinder;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.*;
/**
......@@ -21,6 +26,7 @@ import java.util.*;
public class GraphqlCodegenGradleTask extends DefaultTask {
private List<String> graphqlSchemaPaths;
private final SchemaFinderConfig graphqlSchemas = new SchemaFinderConfig();
private File outputDir;
private Map<String, String> customTypesMapping = new HashMap<>();
private Map<String, String> customAnnotationsMapping = new HashMap<>();
......@@ -56,7 +62,21 @@ public class GraphqlCodegenGradleTask extends DefaultTask {
mappingConfig.setGenerateToString(generateToString);
mappingConfig.setGenerateAsyncApi(generateAsyncApi);
new GraphqlCodegen(graphqlSchemaPaths, outputDir, mappingConfig, buildJsonSupplier()).generate();
new GraphqlCodegen(getSchemas(), outputDir, mappingConfig, buildJsonSupplier()).generate();
}
private List<String> getSchemas() throws IOException {
if (graphqlSchemaPaths != null) {
return graphqlSchemaPaths;
}
if (graphqlSchemas != null) {
SchemaFinder finder = new SchemaFinder(Paths.get(graphqlSchemas.getRootDir()));
finder.setRecursive(graphqlSchemas.isRecursive());
finder.setIncludePattern(graphqlSchemas.getIncludePattern());
finder.setExcludedFiles(graphqlSchemas.getExcludedFiles());
return finder.findSchemas();
}
throw new IllegalStateException("One of graphqlSchemaPaths or graphqlSchemas parameters must be provided");
}
private MappingConfigSupplier buildJsonSupplier() {
......@@ -67,6 +87,7 @@ public class GraphqlCodegenGradleTask extends DefaultTask {
}
@Input
@Optional
public List<String> getGraphqlSchemaPaths() {
return graphqlSchemaPaths;
}
......@@ -75,6 +96,16 @@ public class GraphqlCodegenGradleTask extends DefaultTask {
this.graphqlSchemaPaths = graphqlSchemaPaths;
}
@Nested
@Optional
public SchemaFinderConfig getGraphqlSchemas() {
return graphqlSchemas;
}
public void graphqlSchemas(Action<? super SchemaFinderConfig> action) {
action.execute(graphqlSchemas);
}
@OutputDirectory
public File getOutputDir() {
return outputDir;
......
package io.github.kobylynskyi.graphql.codegen.gradle;
import com.kobylynskyi.graphql.codegen.supplier.SchemaFinder;
import java.util.Collections;
import java.util.Set;
public class SchemaFinderConfig {
private String rootDir;
private boolean recursive = SchemaFinder.DEFAULT_RECURSIVE;
private String includePattern = SchemaFinder.DEFAULT_INCLUDE_PATTERN;
private Set<String> excludedFiles = Collections.emptySet();
public String getRootDir() {
return rootDir;
}
public void setRootDir(String rootDir) {
this.rootDir = rootDir;
}
public boolean isRecursive() {
return recursive;
}
public void setRecursive(boolean recursive) {
this.recursive = recursive;
}
public String getIncludePattern() {
return includePattern;
}
public void setIncludePattern(String includePattern) {
this.includePattern = includePattern;
}
public Set<String> getExcludedFiles() {
return excludedFiles;
}
public void setExcludedFiles(Set<String> excludedFiles) {
this.excludedFiles = excludedFiles;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册