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

Allow specifiying multiple input directories #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/main/java/me/fallenbreath/yamlang/YamlangConvertor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import org.gradle.api.tasks.TaskAction;

import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.function.Function;

public abstract class YamlangConvertor extends DefaultTask
{
Expand Down Expand Up @@ -40,14 +39,28 @@ private void doConversionImpl()
YamlangExtension extension = this.getProject().getExtensions().getByType(YamlangExtension.class);
String inputDir = extension.getInputDir().getOrElse("");
String outputDir = extension.getOutputDir().getOrElse(inputDir);
String targetFilePattern = extension.getTargetFilePattern().getOrElse("*" + YAML_PREFIX);
boolean preserveYaml = extension.getPreserveYaml().getOrElse(false);

List<String> inputDirs = extension.getInputDirs().getOrElse(Collections.emptyList());
Function<String, String> outputTransformer = extension.getMoveOutputDirs().getOrElse(in -> in);

convertDirectory(extension, inputDir, outputDir);
for (String additionalInput : inputDirs)
{
String destinationDir = outputTransformer.apply(additionalInput);
convertDirectory(extension, additionalInput, destinationDir);
}
}

private void convertDirectory(YamlangExtension extension, String inputDir, String outputDir)
{
if (inputDir.isEmpty() || outputDir.isEmpty())
{
return;
}

String targetFilePattern = extension.getTargetFilePattern().getOrElse("*" + YAML_PREFIX);
boolean preserveYaml = extension.getPreserveYaml().getOrElse(false);

Path basePath = Objects.requireNonNull(this.sourceSet.getOutput().getResourcesDir()).toPath();

this.getProject().copy(copySpec -> {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/me/fallenbreath/yamlang/YamlangExtension.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package me.fallenbreath.yamlang;

import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.SourceSet;

import java.util.Collection;
import java.util.function.Function;

public interface YamlangExtension
{
Expand All @@ -28,6 +30,24 @@ public interface YamlangExtension
*/
Property<String> getOutputDir();

/**
* Input directories containing yaml files.
* <p>
* Paths are relative to the resources directory in the specified source sets.
* <p>
* These directories are processed separately. To change the output directory use {@link YamlangExtension#getMoveOutputDirs()}
*/
ListProperty<String> getInputDirs();

/**
* Moves the output files to another directory.
* <p>
* Accepts every path specified in {@link YamlangExtension#getInputDirs()} and returns a destination for each.
* <p>
* By default, keeps the same file location.
*/
Property<Function<String, String>> getMoveOutputDirs();

/**
* The file name pattern of the language files in yaml
* <p>
Expand Down