Skip to content

Commit

Permalink
Allow multiple input dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
kikugie committed Jul 21, 2024
1 parent 1459138 commit 2f5834b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
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

0 comments on commit 2f5834b

Please sign in to comment.