use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class MavenDependencyCompletionAndResolutionTest method testRemovingExistingProjects.
public void testRemovingExistingProjects() throws Exception {
final VirtualFile m = createModulePom("m1", "<groupId>project-group</groupId>" + "<artifactId>m1</artifactId>" + "<version>1</version>");
createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + " <dependency>" + " <groupId>project-group</groupId>" + " <artifactId><caret></artifactId>" + " </dependency>" + "</dependencies>");
importProjects(myProjectPom, m);
assertCompletionVariants(myProjectPom, "m1");
myProjectsManager.listenForExternalChanges();
new WriteAction() {
protected void run(@NotNull Result result) throws Throwable {
m.delete(null);
}
}.execute();
waitForReadingCompletion();
createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + " <dependency>" + " <groupId>project-group</groupId>" + " <artifactId><caret></artifactId>" + " </dependency>" + "</dependencies>");
assertCompletionVariants(myProjectPom);
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class ResourceFilteringTest method testUpdatingWhenPropertiesInFiltersAreChanged.
public void testUpdatingWhenPropertiesInFiltersAreChanged() throws Exception {
final VirtualFile filter = createProjectSubFile("filters/filter.properties", "xxx=1");
createProjectSubFile("resources/file.properties", "value=${xxx}");
importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<build>" + " <filters>" + " <filter>filters/filter.properties</filter>" + " </filters>" + " <resources>" + " <resource>" + " <directory>resources</directory>" + " <filtering>true</filtering>" + " </resource>" + " </resources>" + "</build>");
compileModules("project");
assertResult("target/classes/file.properties", "value=1");
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
VfsUtil.saveText(filter, "xxx=2");
}
}.execute().throwException();
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
compileModules("project");
assertResult("target/classes/file.properties", "value=2");
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class MavenProjectsManagerWatcher method start.
public synchronized void start() {
final MessageBusConnection myBusConnection = myProject.getMessageBus().connect(myChangedDocumentsQueue);
myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new MyFileChangeListener());
myBusConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyRootChangesListener());
myChangedDocumentsQueue.makeUserAware(myProject);
myChangedDocumentsQueue.activate();
myBusConnection.subscribe(ProjectTopics.MODULES, new ModuleListener() {
@Override
public void moduleRemoved(@NotNull Project project, @NotNull Module module) {
MavenProject mavenProject = myManager.findProject(module);
if (mavenProject != null && !myManager.isIgnored(mavenProject)) {
VirtualFile file = mavenProject.getFile();
if (myManager.isManagedFile(file) && myManager.getModules(mavenProject).isEmpty()) {
myManager.removeManagedFiles(Collections.singletonList(file));
} else {
myManager.setIgnoredState(Collections.singletonList(mavenProject), true);
}
}
}
@Override
public void moduleAdded(@NotNull final Project project, @NotNull final Module module) {
// this method is needed to return non-ignored status for modules that were deleted (and thus ignored) and then created again with a different module type
if (myManager.isMavenizedModule(module)) {
MavenProject mavenProject = myManager.findProject(module);
if (mavenProject != null)
myManager.setIgnoredState(Collections.singletonList(mavenProject), false);
}
}
});
DocumentAdapter myDocumentListener = new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent event) {
Document doc = event.getDocument();
VirtualFile file = FileDocumentManager.getInstance().getFile(doc);
if (file == null)
return;
String fileName = file.getName();
boolean isMavenFile = fileName.equals(MavenConstants.POM_XML) || fileName.equals(MavenConstants.PROFILES_XML) || isSettingsFile(file) || fileName.startsWith("pom.");
if (!isMavenFile)
return;
synchronized (myChangedDocuments) {
myChangedDocuments.add(doc);
}
myChangedDocumentsQueue.queue(new Update(MavenProjectsManagerWatcher.this) {
@Override
public void run() {
final Document[] copy;
synchronized (myChangedDocuments) {
copy = myChangedDocuments.toArray(new Document[myChangedDocuments.size()]);
myChangedDocuments.clear();
}
MavenUtil.invokeLater(myProject, () -> new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
for (Document each : copy) {
PsiDocumentManager.getInstance(myProject).commitDocument(each);
((FileDocumentManagerImpl) FileDocumentManager.getInstance()).saveDocument(each, false);
}
}
}.execute());
}
});
}
};
EditorFactory.getInstance().getEventMulticaster().addDocumentListener(myDocumentListener, myBusConnection);
final MavenGeneralSettings.Listener mySettingsPathsChangesListener = new MavenGeneralSettings.Listener() {
@Override
public void changed() {
updateSettingsFilePointers();
onSettingsChange();
}
};
myGeneralSettings.addListener(mySettingsPathsChangesListener);
Disposer.register(myChangedDocumentsQueue, new Disposable() {
@Override
public void dispose() {
myGeneralSettings.removeListener(mySettingsPathsChangesListener);
mySettingsFilesPointers.clear();
}
});
updateSettingsFilePointers();
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class EditorTextFieldControl method setValue.
@Override
protected void setValue(final String value) {
CommandProcessor.getInstance().runUndoTransparentAction(() -> new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
final T component = getComponent();
final Document document = getEditorTextField(component).getDocument();
document.replaceString(0, document.getTextLength(), value == null ? "" : value);
}
}.execute());
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class StructureImportingTest method testParentInLocalRepository.
public void testParentInLocalRepository() throws Exception {
if (!hasMavenInstallation())
return;
final VirtualFile parent = createModulePom("parent", "<groupId>test</groupId>" + "<artifactId>parent</artifactId>" + "<version>1</version>" + "<packaging>pom</packaging>" + "<dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.0</version>" + " </dependency>" + "</dependencies>");
executeGoal("parent", "install");
new WriteAction() {
protected void run(@NotNull Result result) throws Throwable {
parent.delete(null);
}
}.execute();
createProjectPom("<groupId>test</groupId>" + "<artifactId>m</artifactId>" + "<version>1</version>" + "<parent>" + " <groupId>test</groupId>" + " <artifactId>parent</artifactId>" + " <version>1</version>" + "</parent>");
importProject();
assertModules("m");
assertModuleLibDeps("m", "Maven: junit:junit:4.0");
}
Aggregations