mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-127797 Support opening Gradle projects in headless mode
This commit is contained in:
+5
@@ -193,6 +193,11 @@ public abstract class AbstractImportFromExternalSystemControl<
|
||||
return myProjectSettingsControl;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ExternalSystemSettingsControl<SystemSettings> getSystemSettingsControl() {
|
||||
return mySystemSettingsControl;
|
||||
}
|
||||
|
||||
public void setLinkedProjectPath(@NotNull String path) {
|
||||
myProjectSettings.setExternalProjectPath(path);
|
||||
myLinkedProjectPathField.setText(path);
|
||||
|
||||
+86
-11
@@ -16,17 +16,26 @@
|
||||
package org.jetbrains.plugins.gradle.service.project.wizard;
|
||||
|
||||
import com.intellij.ide.util.newProjectWizard.AddModuleWizard;
|
||||
import com.intellij.ide.util.projectWizard.ProjectBuilder;
|
||||
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
||||
import com.intellij.ide.util.projectWizard.WizardContext;
|
||||
import com.intellij.ide.wizard.Step;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.externalSystem.service.project.wizard.SelectExternalProjectStep;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.projectImport.ProjectOpenProcessorBase;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.gradle.service.settings.GradleProjectSettingsControl;
|
||||
import org.jetbrains.plugins.gradle.service.settings.GradleSystemSettingsControl;
|
||||
import org.jetbrains.plugins.gradle.service.settings.ImportFromGradleControl;
|
||||
import org.jetbrains.plugins.gradle.settings.DistributionType;
|
||||
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings;
|
||||
import org.jetbrains.plugins.gradle.settings.GradleSettings;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
import static org.jetbrains.plugins.gradle.util.GradleEnvironment.Headless.*;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
@@ -61,24 +70,90 @@ public class GradleProjectOpenProcessor extends ProjectOpenProcessorBase<GradleP
|
||||
|
||||
@Override
|
||||
protected boolean doQuickImport(VirtualFile file, WizardContext wizardContext) {
|
||||
AddModuleWizard dialog = new AddModuleWizard(null, file.getPath(), new GradleProjectImportProvider(getBuilder()));
|
||||
final GradleProjectImportProvider projectImportProvider = new GradleProjectImportProvider(getBuilder());
|
||||
getBuilder().prepare(wizardContext);
|
||||
getBuilder().getControl(null).setLinkedProjectPath(file.getPath());
|
||||
dialog.getWizardContext().setProjectBuilder(getBuilder());
|
||||
dialog.navigateToStep(new Function<Step, Boolean>() {
|
||||
@Override
|
||||
public Boolean fun(Step step) {
|
||||
return step instanceof SelectExternalProjectStep;
|
||||
}
|
||||
});
|
||||
|
||||
boolean result = dialog.showAndGet();
|
||||
final boolean result;
|
||||
if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
|
||||
result = setupGradleProjectSettingsInHeadlessMode(file, projectImportProvider, wizardContext);
|
||||
}
|
||||
else {
|
||||
AddModuleWizard dialog = new AddModuleWizard(null, file.getPath(), projectImportProvider);
|
||||
dialog.getWizardContext().setProjectBuilder(getBuilder());
|
||||
dialog.navigateToStep(new Function<Step, Boolean>() {
|
||||
@Override
|
||||
public Boolean fun(Step step) {
|
||||
return step instanceof SelectExternalProjectStep;
|
||||
}
|
||||
});
|
||||
result = dialog.showAndGet();
|
||||
}
|
||||
if (result && getBuilder().getExternalProjectNode() != null) {
|
||||
wizardContext.setProjectName(getBuilder().getExternalProjectNode().getData().getInternalName());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean setupGradleProjectSettingsInHeadlessMode(VirtualFile file,
|
||||
GradleProjectImportProvider projectImportProvider,
|
||||
WizardContext wizardContext) {
|
||||
getBuilder().setFileToImport(file.getPath());
|
||||
final ModuleWizardStep[] wizardSteps = projectImportProvider.createSteps(wizardContext);
|
||||
if (wizardSteps.length > 0 && wizardSteps[0] instanceof SelectExternalProjectStep) {
|
||||
SelectExternalProjectStep selectExternalProjectStep = (SelectExternalProjectStep)wizardSteps[0];
|
||||
wizardContext.setProjectBuilder(getBuilder());
|
||||
try {
|
||||
selectExternalProjectStep.updateStep();
|
||||
final ImportFromGradleControl importFromGradleControl = getBuilder().getControl(wizardContext.getProject());
|
||||
|
||||
GradleProjectSettingsControl gradleProjectSettingsControl =
|
||||
(GradleProjectSettingsControl)importFromGradleControl.getProjectSettingsControl();
|
||||
|
||||
final GradleProjectSettings projectSettings = gradleProjectSettingsControl.getInitialSettings();
|
||||
|
||||
if (GRADLE_DISTRIBUTION_TYPE != null) {
|
||||
for (DistributionType type : DistributionType.values()) {
|
||||
if (type.name().equals(GRADLE_DISTRIBUTION_TYPE)) {
|
||||
projectSettings.setDistributionType(type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (GRADLE_HOME != null) {
|
||||
projectSettings.setGradleHome(GRADLE_HOME);
|
||||
}
|
||||
gradleProjectSettingsControl.reset();
|
||||
|
||||
final GradleSystemSettingsControl systemSettingsControl =
|
||||
(GradleSystemSettingsControl)importFromGradleControl.getSystemSettingsControl();
|
||||
assert systemSettingsControl != null;
|
||||
final GradleSettings gradleSettings = systemSettingsControl.getInitialSettings();
|
||||
if (GRADLE_VM_OPTIONS != null) {
|
||||
gradleSettings.setGradleVmOptions(GRADLE_VM_OPTIONS);
|
||||
}
|
||||
if (GRADLE_OFFLINE != null) {
|
||||
gradleSettings.setOfflineWork(Boolean.parseBoolean(GRADLE_OFFLINE));
|
||||
}
|
||||
String serviceDirectory = GRADLE_SERVICE_DIRECTORY;
|
||||
if (GRADLE_SERVICE_DIRECTORY != null) {
|
||||
gradleSettings.setServiceDirectoryPath(serviceDirectory);
|
||||
}
|
||||
systemSettingsControl.reset();
|
||||
|
||||
if (!selectExternalProjectStep.validate()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (ConfigurationException e) {
|
||||
Messages.showErrorDialog(wizardContext.getProject(), e.getMessage(), e.getTitle());
|
||||
return false;
|
||||
}
|
||||
selectExternalProjectStep.updateDataModel();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean lookForProjectsInDirectory() {
|
||||
return false;
|
||||
|
||||
+5
@@ -173,4 +173,9 @@ public class GradleSystemSettingsControl implements ExternalSystemSettingsContro
|
||||
public void disposeUIResources() {
|
||||
ExternalSystemUiUtil.disposeUi(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GradleSettings getInitialSettings() {
|
||||
return myInitialSettings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,18 @@ public class GradleEnvironment {
|
||||
@NonNls public static final boolean DISABLE_ENHANCED_TOOLING_API = Boolean.getBoolean("gradle.disable.enhanced.tooling.api");
|
||||
@NonNls public static final boolean ADJUST_USER_DIR = Boolean.getBoolean("gradle.adjust.userdir");
|
||||
|
||||
public static class Headless {
|
||||
@NonNls public static final String GRADLE_DISTRIBUTION_TYPE = System.getProperty("idea.gradle.distributionType");
|
||||
@NonNls public static final String GRADLE_HOME = System.getProperty("idea.gradle.home");
|
||||
@NonNls public static final String GRADLE_VM_OPTIONS = System.getProperty("idea.gradle.vmOptions");
|
||||
@NonNls public static final String GRADLE_OFFLINE = System.getProperty("idea.gradle.offline");
|
||||
@NonNls public static final String GRADLE_SERVICE_DIRECTORY = System.getProperty("idea.gradle.serviceDirectory");
|
||||
|
||||
private Headless() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private GradleEnvironment() {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user