use of org.jetbrains.plugins.gradle.settings.GradleProjectSettings in project kotlin by JetBrains.
the class GradleImportingTestCase method setUp.
@Override
public void setUp() throws Exception {
myJdkHome = IdeaTestUtil.requireRealJdkHome();
super.setUp();
assumeThat(gradleVersion, versionMatcherRule.getMatcher());
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
Sdk oldJdk = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
if (oldJdk != null) {
ProjectJdkTable.getInstance().removeJdk(oldJdk);
}
VirtualFile jdkHomeDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(myJdkHome));
assert jdkHomeDir != null;
Sdk jdk = SdkConfigurationUtil.setupSdk(new Sdk[0], jdkHomeDir, JavaSdk.getInstance(), true, null, GRADLE_JDK_NAME);
assertNotNull("Cannot create JDK for " + myJdkHome, jdk);
ProjectJdkTable.getInstance().addJdk(jdk);
}
}.execute();
myProjectSettings = new GradleProjectSettings();
GradleSettings.getInstance(myProject).setGradleVmOptions("-Xmx128m -XX:MaxPermSize=64m");
System.setProperty(ExternalSystemExecutionSettings.REMOTE_PROCESS_IDLE_TTL_IN_MS_KEY, String.valueOf(GRADLE_DAEMON_TTL_MS));
configureWrapper();
}
use of org.jetbrains.plugins.gradle.settings.GradleProjectSettings in project kotlin by JetBrains.
the class GradleImportingTestCase method importProject.
@Override
protected void importProject() {
ExternalSystemApiUtil.subscribe(myProject, GradleConstants.SYSTEM_ID, new ExternalSystemSettingsListenerAdapter() {
@Override
public void onProjectsLinked(@NotNull Collection settings) {
Object item = ContainerUtil.getFirstItem(settings);
if (item instanceof GradleProjectSettings) {
((GradleProjectSettings) item).setGradleJvm(GRADLE_JDK_NAME);
}
}
});
super.importProject();
}
use of org.jetbrains.plugins.gradle.settings.GradleProjectSettings in project intellij-community by JetBrains.
the class GradleInstallationManager method doGetGradleJdk.
@Nullable
private Sdk doGetGradleJdk(@Nullable Project project, String linkedProjectPath) {
if (project == null) {
return null;
}
final GradleProjectSettings settings = GradleSettings.getInstance(project).getLinkedProjectSettings(linkedProjectPath);
if (settings == null) {
return null;
}
final String gradleJvm = settings.getGradleJvm();
final Sdk sdk;
try {
sdk = ExternalSystemJdkUtil.getJdk(project, gradleJvm);
} catch (ExternalSystemJdkException e) {
throw new ExternalSystemJdkException(String.format("Invalid Gradle JDK configuration found. <a href='%s'>Open Gradle Settings</a> \n", OpenExternalSystemSettingsCallback.ID), linkedProjectPath, e, OpenExternalSystemSettingsCallback.ID);
}
if (sdk == null && gradleJvm != null) {
throw new ExternalSystemJdkException(String.format("Invalid Gradle JDK configuration found. <a href='%s'>Open Gradle Settings</a> \n", OpenExternalSystemSettingsCallback.ID), linkedProjectPath, null, OpenExternalSystemSettingsCallback.ID);
}
final File sdkHomePath = sdk != null && sdk.getHomePath() != null ? new File(sdk.getHomePath()) : null;
if (sdkHomePath != null && JdkUtil.checkForJre(sdkHomePath.getPath()) && !JdkUtil.checkForJdk(sdkHomePath)) {
throw new ExternalSystemJdkException(String.format("Please, use JDK instead of JRE for Gradle importer. <a href='%s'>Open Gradle Settings</a> \n", OpenExternalSystemSettingsCallback.ID), linkedProjectPath, null, OpenExternalSystemSettingsCallback.ID);
}
return sdk;
}
use of org.jetbrains.plugins.gradle.settings.GradleProjectSettings in project intellij-community by JetBrains.
the class CompositeBuildDataService method importData.
public void importData(@NotNull final Collection<DataNode<CompositeBuildData>> toImport, @Nullable ProjectData projectData, @NotNull final Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
if (toImport.isEmpty()) {
if (projectData != null) {
GradleProjectSettings projectSettings = GradleSettings.getInstance(project).getLinkedProjectSettings(projectData.getLinkedExternalProjectPath());
if (projectSettings != null && projectSettings.getCompositeBuild() != null && projectSettings.getCompositeBuild().getCompositeDefinitionSource() == CompositeDefinitionSource.SCRIPT) {
projectSettings.setCompositeBuild(null);
}
}
return;
}
if (toImport.size() != 1) {
throw new IllegalArgumentException(String.format("Expected to get a single composite data node but got %d: %s", toImport.size(), toImport));
}
CompositeBuildData compositeBuildData = toImport.iterator().next().getData();
GradleProjectSettings projectSettings = GradleSettings.getInstance(project).getLinkedProjectSettings(compositeBuildData.getRootProjectPath());
if (projectSettings != null) {
GradleProjectSettings.CompositeBuild compositeBuild = new GradleProjectSettings.CompositeBuild();
compositeBuild.setCompositeDefinitionSource(CompositeDefinitionSource.SCRIPT);
for (BuildParticipant buildParticipant : compositeBuildData.getCompositeParticipants()) {
compositeBuild.getCompositeParticipants().add(buildParticipant.copy());
}
projectSettings.setCompositeBuild(compositeBuild);
}
}
use of org.jetbrains.plugins.gradle.settings.GradleProjectSettings in project intellij-community by JetBrains.
the class GradleModuleBuilder method setupModule.
@Override
protected void setupModule(Module module) throws ConfigurationException {
super.setupModule(module);
assert rootProjectPath != null;
VirtualFile buildScriptFile = null;
final BuildScriptDataBuilder buildScriptDataBuilder = getBuildScriptData(module);
try {
if (buildScriptDataBuilder != null) {
buildScriptFile = buildScriptDataBuilder.getBuildScriptFile();
final String text = buildScriptDataBuilder.build();
appendToFile(buildScriptFile, "\n" + text);
}
} catch (IOException e) {
LOG.warn("Unexpected exception on applying frameworks templates", e);
}
final Project project = module.getProject();
if (myWizardContext.isCreatingNewProject()) {
getExternalProjectSettings().setExternalProjectPath(rootProjectPath);
AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
project.putUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT, Boolean.TRUE);
//noinspection unchecked
settings.linkProject(getExternalProjectSettings());
} else {
FileDocumentManager.getInstance().saveAllDocuments();
final GradleProjectSettings gradleProjectSettings = getExternalProjectSettings();
final VirtualFile finalBuildScriptFile = buildScriptFile;
Runnable runnable = () -> {
if (myParentProject == null) {
gradleProjectSettings.setExternalProjectPath(rootProjectPath);
AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
//noinspection unchecked
settings.linkProject(gradleProjectSettings);
}
ImportSpec importSpec = new ImportSpecBuilder(project, GradleConstants.SYSTEM_ID).use(ProgressExecutionMode.IN_BACKGROUND_ASYNC).createDirectoriesForEmptyContentRoots().useDefaultCallback().build();
ExternalSystemUtil.refreshProject(rootProjectPath, importSpec);
final PsiFile psiFile;
if (finalBuildScriptFile != null) {
psiFile = PsiManager.getInstance(project).findFile(finalBuildScriptFile);
if (psiFile != null) {
EditorHelper.openInEditor(psiFile);
}
}
};
// execute when current dialog is closed
ExternalSystemUtil.invokeLater(project, ModalityState.NON_MODAL, runnable);
}
}
Aggregations