diff --git a/plugins/graphql-java-codegen-gradle-plugin/graphql-codegen-gradle-plugin/src/main/java/io/github/kobylynskyi/graphql/codegen/gradle/GraphqlCodegenGradleTask.java b/plugins/graphql-java-codegen-gradle-plugin/graphql-codegen-gradle-plugin/src/main/java/io/github/kobylynskyi/graphql/codegen/gradle/GraphqlCodegenGradleTask.java index 743f48457651ac3c59807c9b2ad30c8729c40f8e..0b8655e156acea47a6665172ced61d6d5feb52d2 100644 --- a/plugins/graphql-java-codegen-gradle-plugin/graphql-codegen-gradle-plugin/src/main/java/io/github/kobylynskyi/graphql/codegen/gradle/GraphqlCodegenGradleTask.java +++ b/plugins/graphql-java-codegen-gradle-plugin/graphql-codegen-gradle-plugin/src/main/java/io/github/kobylynskyi/graphql/codegen/gradle/GraphqlCodegenGradleTask.java @@ -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 graphqlSchemaPaths; + private final SchemaFinderConfig graphqlSchemas = new SchemaFinderConfig(); private File outputDir; private Map customTypesMapping = new HashMap<>(); private Map 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 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 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 action) { + action.execute(graphqlSchemas); + } + @OutputDirectory public File getOutputDir() { return outputDir; diff --git a/plugins/graphql-java-codegen-gradle-plugin/graphql-codegen-gradle-plugin/src/main/java/io/github/kobylynskyi/graphql/codegen/gradle/SchemaFinderConfig.java b/plugins/graphql-java-codegen-gradle-plugin/graphql-codegen-gradle-plugin/src/main/java/io/github/kobylynskyi/graphql/codegen/gradle/SchemaFinderConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..9bbb9b7430732b79f4d2b1b297704774ddd4bb18 --- /dev/null +++ b/plugins/graphql-java-codegen-gradle-plugin/graphql-codegen-gradle-plugin/src/main/java/io/github/kobylynskyi/graphql/codegen/gradle/SchemaFinderConfig.java @@ -0,0 +1,49 @@ +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 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 getExcludedFiles() { + return excludedFiles; + } + + public void setExcludedFiles(Set excludedFiles) { + this.excludedFiles = excludedFiles; + } +}