static

in src/main/java/org/jetbrains/plugins/spotbugs/core/FindBugsCompileAfterHook.java [63:107]


	static {
		/*
		 * Note that ProjectData is cleared before BuildManagerListener#buildStarted is invoked,
		 * so we can not use BuildManager.getInstance().getFilesChangedSinceLastCompilation(project).
		 * There is no way to get the affect/compiled files (check with source of IC-140.2285.5).
		 * As a workaround, {@link ChangeCollector} will collect the changes.
		 */
		ApplicationManager.getApplication().getMessageBus().connect().subscribe(BuildManagerListener.TOPIC, new BuildManagerListener() {

			@Override
			public void beforeBuildProcessStarted(final @NotNull Project project, final @NotNull UUID sessionId) {
			}

			@Override
			public void buildStarted(final @NotNull Project project, final @NotNull UUID sessionId, final boolean isAutomake) {
				if (isAutomake && isAfterAutoMakeEnabled(project)) {
					final Set<VirtualFile> changed = Changes.INSTANCE.getAndRemoveChanged(project);
					if (changed != null) {
						CHANGED_BY_SESSION_ID.put(sessionId, changed);
					}
				}
			}

			@Override
			public void buildFinished(final @NotNull Project project, final @NotNull UUID sessionId, final boolean isAutomake) {
				if (isAutomake) {
					final Set<VirtualFile> changed = CHANGED_BY_SESSION_ID.remove(sessionId);
					if (changed != null) {
						if (DELAY_MS <= 0) {
							initWorkerForAutoMake(project, changed);
						} else {
							synchronized (DELAYED_EXECUTOR_BY_PROJECT) {
								DelayedExecutor task = DELAYED_EXECUTOR_BY_PROJECT.get(project);
								if (task == null) {
									task = new DelayedExecutor(project);
									DELAYED_EXECUTOR_BY_PROJECT.put(project, task);
								}
								task.schedule(changed);
							}
						}
					}
				} // else do nothing
			}
		});
	}