Skip to content

Commit

Permalink
Merge branch 'NG_7.0' into feature/primary-sourceset-selector
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans authored Jun 24, 2024
2 parents 4c80b5c + 5565e87 commit a6f9996
Show file tree
Hide file tree
Showing 21 changed files with 179 additions and 66 deletions.
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
api "org.apache.ivy:ivy:${project.ivy_artifact_version}"
api "org.apache.httpcomponents:httpclient:${project.httpclient_version}"
api "net.minecraftforge:srgutils:${project.srgutils_version}"
api "codechicken:DiffPatch:${project.diffpatch_version}"
api "io.codechicken:DiffPatch:${project.diffpatch_version}"
api "commons-codec:commons-codec:${project.commons_codec_version}"
api "net.neoforged:EclipseLaunchConfigs:${project.eclipse_launch_configs_version}"
api "net.neoforged:JarJarMetadata:${project.jarjar_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.neoforged.gradle.dsl.common.util.GameArtifact;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.tasks.TaskProvider;
Expand Down Expand Up @@ -55,6 +56,9 @@ public abstract class CommonRuntimeDefinition<S extends CommonRuntimeSpecificati

@NotNull
private final Consumer<TaskProvider<? extends Runtime>> associatedTaskConsumer;

@NotNull
private final ConfigurableFileCollection allDependencies;

@NotNull
private final VersionJson versionJson;
Expand All @@ -76,6 +80,9 @@ protected CommonRuntimeDefinition(
this.minecraftDependenciesConfiguration = minecraftDependenciesConfiguration;
this.associatedTaskConsumer = associatedTaskConsumer;
this.versionJson = versionJson;

this.allDependencies = specification.getProject().files();
this.allDependencies.from(getMinecraftDependenciesConfiguration());
}

@Override
Expand Down Expand Up @@ -152,6 +159,12 @@ public VersionJson getVersionJson() {
return versionJson;
}

@NotNull
@Override
public final ConfigurableFileCollection getAllDependencies() {
return allDependencies;
}

public void configureRun(RunImpl run) {
final Map<String, String> runtimeInterpolationData = buildRunInterpolationData(run);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public DefaultExecute() {

getRuntimeProgramArguments().convention(getProgramArguments());
getMultiRuntimeArguments().convention(getMultiArguments().AsMap());

getLogLevel().convention(LogLevel.ERROR);
}

@ServiceReference(CommonProjectPlugin.EXECUTE_SERVICE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.SkipWhenEmpty;
import org.gradle.api.tasks.*;

import java.io.File;
import java.util.List;
Expand All @@ -38,6 +33,15 @@ public SourceAccessTransformer() {

args.add("--libraries-list=" + getLibraries().get().getAsFile().getAbsolutePath());

final StringBuilder builder = new StringBuilder();
getClasspath().forEach(f -> {
if (!builder.isEmpty()) {
builder.append(File.pathSeparator);
}
builder.append(f.getAbsolutePath());
});
args.add("--classpath=" + builder.toString());

args.add(inputFile.getAsFile().getAbsolutePath());
args.add(outputFile.getAbsolutePath());

Expand All @@ -48,6 +52,7 @@ public SourceAccessTransformer() {

getJavaVersion().convention(getProject().getExtensions().getByType(JavaPluginExtension.class).getToolchain().getLanguageVersion());
getTransformers().finalizeValueOnRead();
getLogLevel().set(LogLevel.DISABLED);
}

@InputFile
Expand All @@ -58,6 +63,11 @@ public SourceAccessTransformer() {
@PathSensitive(PathSensitivity.NONE)
public abstract RegularFileProperty getLibraries();

@InputFiles
@Optional
@PathSensitive(PathSensitivity.NONE)
public abstract ConfigurableFileCollection getClasspath();

@InputFiles
@SkipWhenEmpty
@PathSensitive(PathSensitivity.NONE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.neoforged.gradle.dsl.common.tasks.WithOutput;
import net.neoforged.gradle.dsl.common.util.CommonRuntimeUtils;
import net.neoforged.gradle.util.StringCapitalizationUtils;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.tasks.TaskProvider;

Expand All @@ -21,7 +22,7 @@ private CommonRuntimeTaskUtils() {
throw new IllegalStateException("Can not instantiate an instance of: CommonRuntimeTaskUtils. This is a utility class");
}

public static TaskProvider<? extends SourceAccessTransformer> createSourceAccessTransformer(Definition<?> definition, String namePreFix, File workspaceDirectory, Consumer<TaskProvider<? extends Runtime>> dependentTaskConfigurationHandler, FileTree files, Collection<String> data, TaskProvider<? extends WithOutput> listLibs) {
public static TaskProvider<? extends SourceAccessTransformer> createSourceAccessTransformer(Definition<?> definition, String namePreFix, File workspaceDirectory, Consumer<TaskProvider<? extends Runtime>> dependentTaskConfigurationHandler, FileTree files, Collection<String> data, TaskProvider<? extends WithOutput> listLibs, FileCollection additionalClasspathElements) {
final TaskProvider<AccessTransformerFileGenerator> generator;
if (!data.isEmpty()) {
generator = definition.getSpecification().getProject().getTasks().register(CommonRuntimeUtils.buildTaskName(definition.getSpecification(), namePreFix + "AccessTransformerGenerator"), AccessTransformerFileGenerator.class, task -> {
Expand All @@ -41,6 +42,7 @@ public static TaskProvider<? extends SourceAccessTransformer> createSourceAccess
}
task.dependsOn(listLibs);
task.getLibraries().set(listLibs.flatMap(WithOutput::getOutput));
task.getClasspath().from(additionalClasspathElements);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import net.neoforged.gradle.dsl.common.tasks.WithOutput
import net.neoforged.gradle.dsl.common.util.GameArtifact
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.TaskProvider
import org.jetbrains.annotations.NotNull

Expand Down Expand Up @@ -87,4 +89,13 @@ interface Definition<S extends Specification> {
*/
@NotNull
abstract TaskProvider<? extends WithOutput> getListLibrariesTaskProvider();

/**
* Returns all the files which should be considered dependencies of the runtime.
* This includes the runtime's own dependencies, as well as the dependencies of the minecraft dependency.
*
* @return The dependencies of the runtime.
*/
@NotNull
ConfigurableFileCollection getAllDependencies()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import net.minecraftforge.gdi.annotations.DefaultMethods
import net.neoforged.gradle.dsl.common.tasks.specifications.ExecuteSpecification
import net.neoforged.gradle.dsl.common.util.RegexUtils
import org.gradle.api.file.FileTree
import org.gradle.api.logging.Logger
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskAction
import org.gradle.process.JavaExecSpec
Expand All @@ -22,7 +23,6 @@ import java.util.stream.Collectors
@DefaultMethods
interface Execute extends WithWorkspace, WithOutput, WithJavaVersion, ExecuteSpecification {


default List<String> interpolateVariableSubstitution(String value, String previous) {
final Map<String, Provider<String>> runtimeArguments = getRuntimeArguments().get()
final Map<String, Provider<List<String>>> multiRuntimeArguments = getMultiRuntimeArguments().get()
Expand Down Expand Up @@ -87,7 +87,7 @@ interface Execute extends WithWorkspace, WithOutput, WithJavaVersion, ExecuteSpe
final List<String> substituted = ((Execute) this).interpolateVariableSubstitution(value, previous)

if (substituted.size() != 1) {
interpolated.removeAt(interpolated.size() - 1);
interpolated.removeAt(interpolated.size() - 1)
}

interpolated.addAll(substituted)
Expand All @@ -110,10 +110,12 @@ interface Execute extends WithWorkspace, WithOutput, WithJavaVersion, ExecuteSpe

final Execute me = this

try (BufferedOutputStream log_out = new BufferedOutputStream(new FileOutputStream(consoleLogFile))) {
try (LoggerOutputStream error_out = new LoggerOutputStream(me.getLogger(), me.getLogLevel().get())
BufferedOutputStream log_out = new BufferedOutputStream(new FileOutputStream(consoleLogFile))
LogLevelAwareOutputStream standard_out = new LogLevelAwareOutputStream(log_out, ExecuteSpecification.LogLevel.WARN, getLogLevel().get()) ){
getExecuteOperation().javaexec({ JavaExecSpec java ->
PrintWriter writer = new PrintWriter(log_out)
Function<String, CharSequence> quote = s -> (CharSequence)('"' + s + '"')
Function<String, CharSequence> quote = s -> (CharSequence) ('"' + s + '"')
writer.println("JVM Args: " + jvmArgs.get().stream().map(quote).collect(Collectors.joining(", ")))
writer.println("Run Args: " + programArgs.get().stream().map(quote).collect(Collectors.joining(", ")))
writer.println("JVM: " + executable.get())
Expand All @@ -130,11 +132,71 @@ interface Execute extends WithWorkspace, WithOutput, WithJavaVersion, ExecuteSpe
java.setClasspath(me.getObjectFactory().fileCollection().from(me.getExecutingJar().get()))
java.setWorkingDir(me.getOutputDirectory().get())
java.getMainClass().set(mainClass)
java.setStandardOutput(log_out)
java.setStandardOutput(standard_out)
java.setErrorOutput(error_out)
}).rethrowFailure().assertNormalExitValue()

return outputFile;
return outputFile
}
}

private static final class LogLevelAwareOutputStream extends OutputStream {

private final OutputStream target;
private final boolean shouldLog;

public LogLevelAwareOutputStream(OutputStream target, ExecuteSpecification.LogLevel minLevel, ExecuteSpecification.LogLevel currentLevel) {
this.target = target;
this.shouldLog = minLevel.ordinal() > currentLevel.ordinal(); //Inverse selection logic, if current is error and min is warn then it should not log.
}

@Override
void write(int b) throws IOException {
if (shouldLog) {
target.write(b);
}
}
}

private static final class LoggerOutputStream
extends OutputStream {
private final ByteArrayOutputStream baos = new ByteArrayOutputStream(1000)
private final Logger logger
private final ExecuteSpecification.LogLevel level

LoggerOutputStream(Logger logger, ExecuteSpecification.LogLevel level) {
this.logger = logger
this.level = level
}

@Override
void write(int b) {
if (level == ExecuteSpecification.LogLevel.DISABLED) return

if (((char) b) == '\n') {
String line = baos.toString()
baos.reset()

switch (level) {
case ExecuteSpecification.LogLevel.TRACE:
logger.trace(line)
break
case ExecuteSpecification.LogLevel.DEBUG:
logger.debug(line)
break
case ExecuteSpecification.LogLevel.ERROR:
logger.error(line)
break
case ExecuteSpecification.LogLevel.INFO:
logger.info(line)
break
case ExecuteSpecification.LogLevel.WARN:
logger.warn(line)
break
}
} else {
baos.write(b)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import org.gradle.api.tasks.PathSensitivity

interface ExecuteSpecification extends ProjectSpecification, OutputSpecification, JavaVersionSpecification {

enum LogLevel {
TRACE, DEBUG, INFO, WARN, ERROR, DISABLED
}


/**
* Defines the jvm arguments in a list which are passed to the java executable.
*
Expand Down Expand Up @@ -114,4 +119,8 @@ interface ExecuteSpecification extends ProjectSpecification, OutputSpecification
*/
@Internal
MapProperty<String, Provider<List<String>>> getMultiRuntimeArguments();

@DSLProperty
@Input
Property<LogLevel> getLogLevel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Constants {
public static final String DEFAULT_PARCHMENT_GROUP = "org.parchmentmc.data"
public static final String DEFAULT_PARCHMENT_ARTIFACT_PREFIX = "parchment-"
public static final String DEFAULT_PARCHMENT_MAVEN_URL = "https://maven.parchmentmc.org/"
public static final String JST_TOOL_ARTIFACT = "net.neoforged.jst:jst-cli-bundle:1.0.38"
public static final String JST_TOOL_ARTIFACT = "net.neoforged.jst:jst-cli-bundle:1.0.39"
public static final String DEVLOGIN_TOOL_ARTIFACT = "net.covers1624:DevLogin:0.1.0.4"
public static final String DEVLOGIN_MAIN_CLASS = "net.covers1624.devlogin.DevLogin"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.neoforged.gradle.dsl.userdev.runtime.specification;

import groovy.transform.CompileStatic
import net.neoforged.gradle.dsl.common.runtime.spec.Specification;
import org.gradle.api.provider.Provider;
import net.neoforged.gradle.dsl.common.runtime.spec.Specification
import net.neoforged.gradle.dsl.neoform.runtime.specification.NeoFormSpecification;
import org.gradle.api.provider.Provider
import org.gradle.api.specs.Spec;
import org.jetbrains.annotations.NotNull;

/**
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ maven_artifact_version=3.8.5
ivy_artifact_version=2.5.1
httpclient_version=4.5.13
srgutils_version=0.4.13
diffpatch_version=1.5.0.29
diffpatch_version=2.0.0.34
jarjar_version=0.4.1
jetbrains_annotations_version=23.0.0
gradle_idea_extension_version=1.1.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class NeoFormRuntimeDefinition extends CommonRuntimeDefinition<NeoFormRun

private final TaskProvider<DownloadAssets> assetsTaskProvider;
private final TaskProvider<ExtractNatives> nativesTaskProvider;
private TaskProvider<? extends WithOutput> debuggingMappingsTaskProvider;

public NeoFormRuntimeDefinition(@NotNull NeoFormRuntimeSpecification specification,
@NotNull LinkedHashMap<String, TaskProvider<? extends WithOutput>> taskOutputs,
Expand All @@ -47,6 +46,8 @@ public NeoFormRuntimeDefinition(@NotNull NeoFormRuntimeSpecification specificati
this.neoform = neoform;
this.assetsTaskProvider = assetsTaskProvider;
this.nativesTaskProvider = nativesTaskProvider;

this.getAllDependencies().from(getSpecification().getAdditionalRecompileDependencies());
}

@Override
Expand All @@ -58,11 +59,9 @@ public NeoFormConfigConfigurationSpecV2 getNeoFormConfig() {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NeoFormRuntimeDefinition)) return false;
if (!(o instanceof NeoFormRuntimeDefinition that)) return false;
if (!super.equals(o)) return false;

NeoFormRuntimeDefinition that = (NeoFormRuntimeDefinition) o;

return neoform.equals(that.neoform);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Provider<File> getNeoFormArchive() {
}

@Override
public FileCollection getAdditionalRecompileDependencies() {
public @NotNull FileCollection getAdditionalRecompileDependencies() {
return additionalRecompileDependencies;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package net.neoforged.gradle.neoform.runtime.tasks;

import codechicken.diffpatch.cli.CliOperation;
import codechicken.diffpatch.cli.PatchOperation;
import codechicken.diffpatch.util.LoggingOutputStream;
import codechicken.diffpatch.util.PatchMode;
import io.codechicken.diffpatch.cli.CliOperation;
import io.codechicken.diffpatch.cli.PatchOperation;
import io.codechicken.diffpatch.util.Input.MultiInput;
import io.codechicken.diffpatch.util.Output.MultiOutput;
import io.codechicken.diffpatch.util.PatchMode;
import net.neoforged.gradle.common.CommonProjectPlugin;
import net.neoforged.gradle.common.caching.CentralCacheService;
import net.neoforged.gradle.common.runtime.tasks.DefaultRuntime;
Expand Down Expand Up @@ -61,13 +62,13 @@ public File doRun() throws Exception {
}

PatchOperation.Builder builder = PatchOperation.builder()
.logTo(new LoggingOutputStream(getLogger(), LogLevel.LIFECYCLE))
.basePath(input.toPath())
.patchesPath(patchArchiveLocator.directory.toPath())
.outputPath(output.toPath())
.level(getIsVerbose().get() ? codechicken.diffpatch.util.LogLevel.ALL : codechicken.diffpatch.util.LogLevel.WARN)
.mode(PatchMode.OFFSET)
.rejectsPath(rejects.toPath());
.logTo(getLogger()::lifecycle)
.baseInput(MultiInput.detectedArchive(input.toPath()))
.patchesInput(MultiInput.folder(patchArchiveLocator.directory.toPath()))
.patchedOutput(MultiOutput.detectedArchive(output.toPath()))
.rejectsOutput(MultiOutput.detectedArchive(rejects.toPath()))
.level(getIsVerbose().get() ? io.codechicken.diffpatch.util.LogLevel.ALL : io.codechicken.diffpatch.util.LogLevel.WARN)
.mode(PatchMode.OFFSET);

if (getPatchesModifiedPrefix().isPresent()) {
builder = builder.bPrefix(getPatchesModifiedPrefix().get());
Expand Down
Loading

0 comments on commit a6f9996

Please sign in to comment.