-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
393 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 27 additions & 25 deletions
52
src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusPostStartupActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019-2020 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.quarkus; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.module.ModuleManager; | ||
import com.intellij.openapi.project.DumbAware; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.startup.StartupActivity; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class QuarkusPostStartupActivity implements StartupActivity, DumbAware { | ||
@Override | ||
public void runActivity(@NotNull Project project) { | ||
QuarkusProjectService.getInstance(project); | ||
} | ||
} | ||
/******************************************************************************* | ||
* Copyright (c) 2019-2020 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.quarkus; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.module.ModuleManager; | ||
import com.intellij.openapi.project.DumbAware; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.startup.StartupActivity; | ||
import com.redhat.devtools.intellij.quarkus.classpath.ClasspathResourceChangeManager; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class QuarkusPostStartupActivity implements StartupActivity, DumbAware { | ||
@Override | ||
public void runActivity(@NotNull Project project) { | ||
ClasspathResourceChangeManager.getInstance(project); | ||
QuarkusProjectService.getInstance(project); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...n/java/com/redhat/devtools/intellij/quarkus/classpath/ClasspathResourceChangeManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.redhat.devtools.intellij.quarkus.classpath; | ||
|
||
import com.intellij.openapi.Disposable; | ||
import com.intellij.openapi.components.ServiceManager; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.openapi.vfs.VirtualFileManager; | ||
import com.intellij.psi.PsiManager; | ||
import com.intellij.util.messages.MessageBusConnection; | ||
import com.intellij.util.messages.Topic; | ||
import com.intellij.workspaceModel.ide.WorkspaceModelTopics; | ||
|
||
import java.util.Set; | ||
|
||
public class ClasspathResourceChangeManager implements Disposable { | ||
|
||
public static final Topic<ClasspathResourceChangeManager.Listener> TOPIC = Topic.create(ClasspathResourceChangeManager.class.getName(), ClasspathResourceChangeManager.Listener.class); | ||
|
||
private final SourceFileChangeNotifier sourcesChanged; | ||
private final MessageBusConnection connection; | ||
private final ClasspathRessourceChangedListener listener; | ||
|
||
public static ClasspathResourceChangeManager getInstance(Project project) { | ||
return ServiceManager.getService(project, ClasspathResourceChangeManager.class); | ||
} | ||
|
||
public interface Listener { | ||
|
||
void librariesChanged(); | ||
|
||
void sourceFilesChanged(Set<VirtualFile> sources); | ||
} | ||
|
||
private final Project project; | ||
|
||
public ClasspathResourceChangeManager(Project project) { | ||
this.project = project; | ||
// Send source files changed in debounce mode | ||
this.sourcesChanged = new SourceFileChangeNotifier(files -> | ||
project.getMessageBus().syncPublisher(ClasspathResourceChangeManager.TOPIC).sourceFilesChanged(files) | ||
); | ||
listener = new ClasspathRessourceChangedListener(project, sourcesChanged); | ||
connection = project.getMessageBus().connect(); | ||
// Track delete, create, update of file | ||
connection.subscribe(VirtualFileManager.VFS_CHANGES, listener); | ||
// Track end of Java libraries update | ||
WorkspaceModelTopics.getInstance(project).subscribeAfterModuleLoading(connection, listener); | ||
// Track update of update of Psi Java, properties files | ||
PsiManager.getInstance(project).addPsiTreeChangeListener(listener, project); | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
this.sourcesChanged.dispose(); | ||
this.connection.disconnect(); | ||
PsiManager.getInstance(project).removePsiTreeChangeListener(listener); | ||
} | ||
} |
Oops, something went wrong.