Skip to content

Commit

Permalink
Enable Emojis even on Windows, when run via Eclipse and IntelliJ
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Jun 9, 2024
1 parent 2408478 commit 804f16a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import net.neoforged.elc.configs.JavaApplicationLaunchConfig;
import net.neoforged.moddevgradle.dsl.InternalModelHelper;
import net.neoforged.moddevgradle.dsl.NeoForgeExtension;
import net.neoforged.moddevgradle.dsl.Parchment;
import net.neoforged.moddevgradle.dsl.RunModel;
import net.neoforged.moddevgradle.internal.utils.ExtensionUtils;
import net.neoforged.moddevgradle.internal.utils.IdeDetection;
import net.neoforged.moddevgradle.tasks.JarJar;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
Expand Down Expand Up @@ -456,8 +456,9 @@ private void configureArtifactManifestTask(CreateArtifactManifestTask task, NeoF
}

private static boolean shouldUseCombinedSourcesAndClassesArtifact() {
return true;
// return Boolean.getBoolean("idea.active");
// Only IntelliJ needs the combined artifact
// For Eclipse, we can attach the sources via the Eclipse project model.
return IdeDetection.isIntelliJ();
}

private void addTemporaryRepositories(RepositoryHandler repositories) {
Expand Down Expand Up @@ -692,7 +693,7 @@ private static void configureIntelliJModel(Project project, TaskProvider<Task> i
// IDEA Sync has no real notion of tasks or providers or similar
project.afterEvaluate(ignored -> {
var settings = getIntelliJProjectSettings(rootProject);
if (settings != null && Boolean.getBoolean("idea.sync.active")) {
if (settings != null && IdeDetection.isIntelliJSync()) {
// Also run the sync task directly as part of the sync. (Thanks Loom).
var startParameter = project.getGradle().getStartParameter();
var taskRequests = new ArrayList<>(startParameter.getTaskRequests());
Expand Down Expand Up @@ -803,7 +804,6 @@ private static void configureEclipseModel(Project project,
var sourcesPath = createArtifacts.get().getSourcesArtifact().get().getAsFile();

for (var entry : classpath.getEntries()) {
System.out.println(entry);
if (entry instanceof Library library && classesPath.equals(new File(library.getPath()))) {
library.setSourcePath(classpath.fileReference(sourcesPath));
}
Expand All @@ -813,8 +813,7 @@ private static void configureEclipseModel(Project project,

// Set up runs if running under buildship
// TODO: This should be moved into its own task being triggered via eclipseModel.synchronizationTask
System.out.println(System.getProperties());
if (System.getProperty("eclipse.application") != null) {
if (IdeDetection.isEclipse()) {
project.afterEvaluate(ignored -> {
for (var run : extension.getRuns()) {
var prepareTask = prepareRunTasks.get(run).get();
Expand Down Expand Up @@ -851,7 +850,6 @@ private static void addEclipseLaunchConfiguration(Project project,
var filename = run.getIdeName().get();

var file = project.file(".eclipse/configurations/" + filename + ".launch");
System.out.println("Writing eclipse run " + file);

file.getParentFile().mkdirs();
try (var writer = new FileWriter(file, false)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.neoforged.moddevgradle.internal;

import net.neoforged.moddevgradle.internal.utils.IdeDetection;
import net.neoforged.moddevgradle.internal.utils.NetworkSettingPassthrough;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.ConfigurableFileCollection;
Expand Down Expand Up @@ -81,6 +82,12 @@ protected final void run(List<String> args) {

// See https://github.com/gradle/gradle/issues/28959
execSpec.jvmArgs("-Dstdout.encoding=UTF-8", "-Dstderr.encoding=UTF-8");

// When running through IJ or Eclipse, always enable emojis
if (IdeDetection.isIntelliJ() || IdeDetection.isEclipse()) {
execSpec.args("--emojis");
}

execSpec.executable(getNeoFormRuntimeLauncher().get().getExecutablePath().getAsFile());
execSpec.classpath(getNeoFormRuntime());
execSpec.args(realArgs);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.neoforged.moddevgradle.internal.utils;

/**
* Utilities for trying to detect in which IDE Gradle is running.
*/
public final class IdeDetection {
private IdeDetection() {
}

/**
* @return true if IntelliJ is running Gradle. This is true both during sync and execution of other Gradle tasks.
*/
public static boolean isIntelliJ() {
return Boolean.getBoolean("idea.active");
}

/**
* @return true if IntelliJ is syncing its project model with Gradle.
*/
public static boolean isIntelliJSync() {
return Boolean.getBoolean("idea.sync.active");
}

/**
* @return true if running under Eclipse (either Task execution or otherwise)
*/
public static boolean isEclipse() {
return System.getProperty("eclipse.application") != null;
}
}
2 changes: 1 addition & 1 deletion testproject/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ neoForge {
neoFormRuntime {
useEclipseCompiler = true
// enableCache = false
verbose = true
// verbose = true
}

parchment {
Expand Down

0 comments on commit 804f16a

Please sign in to comment.