mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
gradle: merge gradle args defined in gradle.properties
This commit is contained in:
+20
-1
@@ -29,6 +29,9 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.ContainerUtilRt;
|
||||
import org.gradle.initialization.BuildLayoutParameters;
|
||||
import org.gradle.internal.nativeintegration.services.NativeServices;
|
||||
import org.gradle.process.internal.JvmOptions;
|
||||
import org.gradle.tooling.*;
|
||||
import org.gradle.tooling.internal.consumer.DefaultExecutorServiceFactory;
|
||||
import org.gradle.tooling.internal.consumer.DefaultGradleConnector;
|
||||
@@ -49,6 +52,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -132,8 +136,14 @@ public class GradleExecutionHelper {
|
||||
jvmArgs.addAll(extraJvmArgs);
|
||||
|
||||
if (!jvmArgs.isEmpty()) {
|
||||
// merge gradle args e.g. defined in gradle.properties
|
||||
BuildEnvironment buildEnvironment = getBuildEnvironment(connection);
|
||||
Collection<String> merged = buildEnvironment != null
|
||||
? mergeJvmArgs(settings.getServiceDirectory(), buildEnvironment.getJava().getJvmArguments(), jvmArgs)
|
||||
: jvmArgs;
|
||||
|
||||
// filter nulls and empty strings
|
||||
List<String> filteredArgs = ContainerUtil.mapNotNull(jvmArgs, new Function<String, String>() {
|
||||
List<String> filteredArgs = ContainerUtil.mapNotNull(merged, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String s) {
|
||||
return StringUtil.isEmpty(s) ? null : s;
|
||||
@@ -284,6 +294,15 @@ public class GradleExecutionHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> mergeJvmArgs(String serviceDirectory, Iterable<String> jvmArgs1, Iterable<String> jvmArgs2) {
|
||||
File gradleUserHomeDir = serviceDirectory != null ? new File(serviceDirectory) : new BuildLayoutParameters().getGradleUserHomeDir();
|
||||
LOG.debug("Gradle home: " + gradleUserHomeDir);
|
||||
NativeServices.initialize(gradleUserHomeDir, false);
|
||||
JvmOptions jvmOptions = new JvmOptions(null);
|
||||
jvmOptions.setAllJvmArgs(ContainerUtil.concat(jvmArgs1, jvmArgs2));
|
||||
return jvmOptions.getAllJvmArgs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to retrieve gradle api connection to use for the given project.
|
||||
*
|
||||
|
||||
+4
-6
@@ -23,15 +23,16 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.ui.TextComponentAccessor;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.components.JBTextField;
|
||||
import org.gradle.initialization.BuildLayoutParameters;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.gradle.settings.GradleSettings;
|
||||
import org.jetbrains.plugins.gradle.util.GradleBundle;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
@@ -214,11 +215,8 @@ public class IdeaGradleSystemSettingsControlBuilder implements GradleSystemSetti
|
||||
}
|
||||
|
||||
private static void deduceServiceDirectory(@NotNull TextFieldWithBrowseButton serviceDirectoryPathField) {
|
||||
String path = System.getenv().get(GradleConstants.SYSTEM_DIRECTORY_PATH_KEY);
|
||||
if (StringUtil.isEmpty(path)) {
|
||||
path = new File(System.getProperty("user.home"), ".gradle").getAbsolutePath();
|
||||
}
|
||||
serviceDirectoryPathField.setText(path);
|
||||
File gradleUserHomeDir = new BuildLayoutParameters().getGradleUserHomeDir();
|
||||
serviceDirectoryPathField.setText(FileUtil.toSystemIndependentName(gradleUserHomeDir.getPath()));
|
||||
serviceDirectoryPathField.getTextField().setForeground(LocationSettingType.DEDUCED.getColor());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user