use of com.intellij.openapi.application.WriteAction in project intellij-community 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));
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 com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class GradleImportingTestCase method tearDown.
@Override
public void tearDown() throws Exception {
if (myJdkHome == null) {
//super.setUp() wasn't called
return;
}
try {
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
Sdk old = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
if (old != null) {
SdkConfigurationUtil.removeSdk(old);
}
}
}.execute();
Messages.setTestDialog(TestDialog.DEFAULT);
FileUtil.delete(BuildManager.getInstance().getBuildSystemDirectory());
} finally {
super.tearDown();
}
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class GradleImportingTestCase method configureWrapper.
private void configureWrapper() throws IOException, URISyntaxException {
final URI distributionUri = new DistributionLocator().getDistributionFor(GradleVersion.version(gradleVersion));
myProjectSettings.setDistributionType(DistributionType.DEFAULT_WRAPPED);
final VirtualFile wrapperJarFrom = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(wrapperJar());
assert wrapperJarFrom != null;
final VirtualFile wrapperJarFromTo = createProjectSubFile("gradle/wrapper/gradle-wrapper.jar");
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
wrapperJarFromTo.setBinaryContent(wrapperJarFrom.contentsToByteArray());
}
}.execute().throwException();
Properties properties = new Properties();
properties.setProperty("distributionBase", "GRADLE_USER_HOME");
properties.setProperty("distributionPath", "wrapper/dists");
properties.setProperty("zipStoreBase", "GRADLE_USER_HOME");
properties.setProperty("zipStorePath", "wrapper/dists");
properties.setProperty("distributionUrl", distributionUri.toString());
StringWriter writer = new StringWriter();
properties.store(writer, null);
createProjectSubFile("gradle/wrapper/gradle-wrapper.properties", writer.toString());
WrapperConfiguration wrapperConfiguration = GradleUtil.getWrapperConfiguration(getProjectPath());
PathAssembler.LocalDistribution localDistribution = new PathAssembler(StartParameter.DEFAULT_GRADLE_USER_HOME).getDistribution(wrapperConfiguration);
File zip = localDistribution.getZipFile();
try {
if (zip.exists()) {
ZipFile zipFile = new ZipFile(zip);
zipFile.close();
}
} catch (ZipException e) {
e.printStackTrace();
System.out.println("Corrupted file will be removed: " + zip.getPath());
FileUtil.delete(zip);
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class AddCustomLibraryDialog method doOKAction.
@Override
protected void doOKAction() {
final LibraryCompositionSettings settings = myPanel.apply();
if (settings != null && settings.downloadFiles(myPanel.getMainPanel())) {
if (myModifiableRootModel == null) {
final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
new WriteAction() {
@Override
protected void run(@NotNull final Result result) {
addLibraries(model, settings);
model.commit();
}
}.execute();
} else {
addLibraries(myModifiableRootModel, settings);
}
}
super.doOKAction();
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class CreateNewLibraryDialog method createLibrary.
@NotNull
public Library createLibrary() {
final LibraryTable.ModifiableModel modifiableModel = getTableModifiableModel();
final LibraryType<?> type = myLibraryEditor.getType();
final Library library = modifiableModel.createLibrary(myLibraryEditor.getName(), type != null ? type.getKind() : null);
final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx) library.getModifiableModel();
myLibraryEditor.applyTo(model);
new WriteAction() {
@Override
protected void run(@NotNull final Result result) {
model.commit();
}
}.execute();
return library;
}
Aggregations