Skip to content
Merged
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
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version=1.4
release=false
org.gradle.configuration-cache=true
version=1.5
release=false
org.gradle.configuration-cache=true
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public class Discombobulator implements Plugin<Project> {
*/
private static String discoVersion;

/**
* Versions where the accessor is changed to official mappings
*/
public static List<String> accessWidenerOfficialList = new ArrayList<>();

/**
* Apply the gradle plugin to the project
*/
Expand Down Expand Up @@ -111,7 +116,7 @@ public void apply(Project project) {
List<Task> compileTaskList = new ArrayList<>();
Map<String, Path> buildDirs = new HashMap<>();
for (Project subProject : project.getSubprojects()) {
Task compileTask = subProject.getTasksByName("remapJar", false).iterator().next();
Task compileTask = subProject.getTasksByName("build", false).iterator().next();
compileTaskList.add(compileTask);

buildDirs.put(subProject.getName(), getBuildDir(subProject).resolve("libs"));
Expand Down Expand Up @@ -153,12 +158,16 @@ public void apply(Project project) {
return;
}
List<String> versionStrings = new ArrayList<>(versionPairs.keySet());
LinePreprocessor processor = new LinePreprocessor(versionStrings, config.getPatterns().get(), inverted);
LinePreprocessor lineProcessor = new LinePreprocessor(versionStrings, config.getPatterns().get(), inverted);

List<String> ignored = config.getIgnoredFileFormats().getOrElse(new ArrayList<>());
WildcardFileFilter fileFilter = WildcardFileFilter.builder().setWildcards(ignored).get();

fileProcessor = new FilePreprocessor(processor, fileFilter);
// Map<String, Map<String, Pair<String, String>>> emergencyTransformConfig = config.getEmergencyTransform().getOrNull();
// EmergencyTransformer emergencyTransformer = new EmergencyTransformer(emergencyTransformConfig, versionStrings);
accessWidenerOfficialList = config.getAccessWidenerOfficial().get();

fileProcessor = new FilePreprocessor(lineProcessor, fileFilter);

// Yes this is yoinked from the gradle forums to get the disco version. Is there
// a better method? Probably. Do I care? Currently, no.
Expand All @@ -172,7 +181,7 @@ public void apply(Project project) {

public static String getSplash() {
return "\n" + (DISABLE_ANSI ? getColorLessSplash() : getColoredSplash()) + "\n\n"
+ getCenterText(String.format("Enable configuration cache today!")) + "\n"
+ getCenterText(String.format("Now with unobfuscated support!")) + "\n"
+ getCenterText("Created by Pancake and Scribble") + "\n"
+ getCenterText(discoVersion) + "\n\n";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,16 @@ public abstract class PreprocessingConfiguration {
* @return The line feed string
*/
public abstract Property<String> getDefaultLineFeed();

// /**
// * <p>If a file needs transforming but does not support comments
// * @return A map with the version number as key and a map as value which contains the filename and a pair of strings with search and replace respectively
// */
// public abstract MapProperty<String, Map<String, Pair<String, String>>> getEmergencyTransform();

/**
* @return Versions where the accesswidener is changed to official mappings
*/
public abstract ListProperty<String> getAccessWidenerOfficial();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.minecrafttas.discombobulator.Discombobulator;
import com.minecrafttas.discombobulator.tasks.TaskPreprocessWatch.CurrentFilePreprocessAction;
import com.minecrafttas.discombobulator.utils.BetterFileWalker;
import com.minecrafttas.discombobulator.utils.EmergencyTransformer;
import com.minecrafttas.discombobulator.utils.LineFeedHelper;
import com.minecrafttas.discombobulator.utils.SafeFileOperations;

Expand All @@ -45,6 +46,7 @@ public class FilePreprocessor {
* Creates a new {@link FilePreprocessor}
* @param processor The {@link #lineProcessor}
* @param fileFilter The {@link #fileFilter}
* @param emergencyTransformer The {@link EmergencyTransformer}
*/
public FilePreprocessor(LinePreprocessor processor, WildcardFileFilter fileFilter) {
this.lineProcessor = processor;
Expand Down Expand Up @@ -179,6 +181,7 @@ public CurrentFilePreprocessAction preprocessVersions(Path inFile, Map<String, P
*/
public List<String> preprocessLines(List<String> inLines, Path outFile, String version, String extension) throws Exception {
List<String> lines = lineProcessor.preprocess(version, inLines, extension);

writeLines(lines, outFile);
return lines;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.minecrafttas.discombobulator.Discombobulator;
import com.minecrafttas.discombobulator.utils.Pair;

/*
Expand Down Expand Up @@ -227,6 +228,9 @@ public List<String> preprocess(String targetVersion, List<String> lines, String
out.add(line);
}

//TODO Very dumb, very temporary method to fix accesswideners
out = makeAccessWidenerOfficial(fileending, targetVersion, out);

return out;
}

Expand Down Expand Up @@ -1000,4 +1004,29 @@ private String searchPatternsInverted(int targetIndex, Map<String, String> patte
}
return replacement;
}

/**
* Very temporary method to support unobfuscated mcversions, by changing the "named" in the first line of the accesswidener to "official"
* if a version is declared in the build.gradle
*
* @param extension
* @param targetVersion
* @param lines
* @return
*/
private List<String> makeAccessWidenerOfficial(String extension, String targetVersion, List<String> lines) {
if (!"accesswidener".equals(extension)) {
return lines;
}

if (Discombobulator.accessWidenerOfficialList.contains(targetVersion)) {
String line = lines.get(0).replace("named", "official");
lines.set(0, line);
} else {
String line = lines.get(0).replace("official", "named");
lines.set(0, line);
}

return lines;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.gradle.api.DefaultTask;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.TaskAction;

Expand All @@ -19,6 +20,7 @@
*
* @author Pancake
*/
@CacheableTask
public abstract class TaskCollectBuilds extends DefaultTask {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.apache.commons.io.FilenameUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.TaskAction;

import com.minecrafttas.discombobulator.Discombobulator;
Expand All @@ -30,6 +31,7 @@
*
* @author Pancake, Scribble
*/
@CacheableTask
public class TaskPreprocessBase extends DefaultTask {

@TaskAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import org.apache.commons.io.FilenameUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.TaskAction;

import com.minecrafttas.discombobulator.Discombobulator;
Expand All @@ -35,8 +38,10 @@
*
* @author Scribble
*/
@CacheableTask
public abstract class TaskPreprocessVersion extends DefaultTask {

@PathSensitive(PathSensitivity.RELATIVE)
@InputDirectory
abstract DirectoryProperty getVersionDirectory();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.minecrafttas.discombobulator.tasks;

import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.TaskAction;

/**
Expand All @@ -11,6 +12,7 @@
* <p>But you can register separate tasks to the root project, that will execute before everything else, so to stop it,<br>
* we just need to throw an exception and it will stop all following tasks. Thanks Gradle!
*/
@CacheableTask
public class TaskPreprocessVersionError extends DefaultTask {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.commons.io.FilenameUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.TaskAction;

Expand All @@ -42,6 +43,7 @@
*
* @author Pancake, Scribble
*/
@CacheableTask
public abstract class TaskPreprocessWatch extends DefaultTask {

private List<FileWatcherThread> threads = new ArrayList<>();
Expand Down Expand Up @@ -152,7 +154,7 @@ protected void onModifyFile(Path path) {
// Get path relative to the root dir
String extension = FilenameUtils.getExtension(path.getFileName().toString());
try {
System.out.println(String.format("[%s%s%s]", PURPLE_BRIGHT, TaskPreprocessWatch.findVersionFromPath(path, versions), WHITE));
System.out.println(String.format("\n[%s%s%s]", PURPLE_BRIGHT, TaskPreprocessWatch.findVersionFromPath(path, versions), WHITE));
// Preprocess in all sub versions
currentFileAction = Discombobulator.fileProcessor.preprocessVersions(path, versions, extension, subSourceDir, true);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.minecrafttas.discombobulator.utils;

import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.io.filefilter.WildcardFileFilter;

public class EmergencyTransformer {

private Map<String, Map<String, Pair<String, String>>> config;

public EmergencyTransformer(Map<String, Map<String, Pair<String, String>>> config, List<String> versionStrings) {
this.config = config;
}

public List<String> transform(String sourceVersion, String targetVersion, Path file, List<String> lines) {

for (Entry<String, Map<String, Pair<String, String>>> filePattern : config.entrySet()) {
WildcardFileFilter filter = WildcardFileFilter.builder().setWildcards(filePattern.getKey()).get();
if (filter.matches(file)) {
Map<String, Pair<String, String>> versions = filePattern.getValue();
replaceVersion(targetVersion, lines, versions);
}
}

return lines;
}

private void replaceVersion(String targetVersion, List<String> lines, Map<String, Pair<String, String>> versions) {
for (Entry<String, Pair<String, String>> version : versions.entrySet()) {
if (targetVersion.equals(version.getKey())) {
replaceLines(lines, version);
}
}
}

private void replaceLines(List<String> lines, Entry<String, Pair<String, String>> version) {
Pair<String, String> searchReplace = version.getValue();
String search = searchReplace.left();
String replace = searchReplace.right();

lines.forEach(line -> {
line = line.replace(search, replace);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

import org.junit.jupiter.api.Test;

import com.minecrafttas.discombobulator.Discombobulator;
import com.minecrafttas.discombobulator.processor.LinePreprocessor;
import com.minecrafttas.discombobulator.utils.Pair;

class ProcessorTestAccessWidener extends TestBase {

private List<String> allVersions = Arrays.asList("1.20.0", "1.19.3", "1.19.2", "1.19.0", "1.18.2", "1.18.1", "1.17.1", "1.16.5", "1.16.1", "infinity", "1.15.2", "1.14.4");
private List<String> allVersions = Arrays.asList("26.1", "1.20.0", "1.19.3", "1.19.2", "1.19.0", "1.18.2", "1.18.1", "1.17.1", "1.16.5", "1.16.1", "infinity", "1.15.2", "1.14.4");

private LinePreprocessor processor = new LinePreprocessor(allVersions, null);

Expand Down Expand Up @@ -81,4 +82,22 @@ void testTargetVersionBeingNull() throws Exception {

assertEquals(expected, actual);
}

@Test
void testAccessWidenerChange() throws Exception {
String folder = "TestAccesswidener";
String actualName = "test.accesswidener";
String expectedName = "Expected26.1.txt";
String targetVersion = "26.1";

Discombobulator.accessWidenerOfficialList.add("26.1");
Pair<List<String>, List<String>> lines = getLines(folder, actualName, expectedName);

List<String> linesActual = processor.preprocess(targetVersion, lines.left(), getExtension(actualName));

String actual = String.join("\n", linesActual);
String expected = String.join("\n", lines.right());

assertEquals(expected, actual);
}
}
11 changes: 11 additions & 0 deletions src/test/resources/TestAccesswidener/Expected26.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
accessWidener v1 official

# Savestate Mod
## 1.16.1
Ac code for 1.16.1
## 1.14.4
#$$Ac code for 1.14.4
## end

# Dragon Manipulation
accessible field net/minecraft/world/level/pathfinder/Path nodes Ljava/util/List;
Loading