-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy published data files prior to publishing.
- Loading branch information
1 parent
4bd8be7
commit 12c8d92
Showing
3 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/net/neoforged/moddevgradle/tasks/CopyDataFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package net.neoforged.moddevgradle.tasks; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.StandardCopyOption; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.file.ConfigurableFileCollection; | ||
import org.gradle.api.file.RegularFile; | ||
import org.gradle.api.provider.ListProperty; | ||
import org.gradle.api.tasks.InputFiles; | ||
import org.gradle.api.tasks.OutputFiles; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
public abstract class CopyDataFile extends DefaultTask { | ||
@InputFiles // Exists to implicitly declare task dependencies. | ||
public abstract ConfigurableFileCollection getRawInputs(); | ||
|
||
@InputFiles | ||
public abstract ListProperty<RegularFile> getInputFiles(); | ||
|
||
@OutputFiles | ||
public abstract ListProperty<RegularFile> getOutputFiles(); | ||
|
||
@TaskAction | ||
public void doCopy() throws IOException { | ||
var inputs = getInputFiles().get(); | ||
var outputs = getOutputFiles().get(); | ||
if (inputs.size() != outputs.size()) throw new RuntimeException("Lists length dont match."); | ||
|
||
for (int i = 0; i < inputs.size(); i++) { | ||
var in = inputs.get(i).getAsFile().toPath(); | ||
var out = outputs.get(i).getAsFile().toPath(); | ||
Files.createDirectories(out.getParent()); | ||
Files.copy(in, out, StandardCopyOption.REPLACE_EXISTING); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters