[jps build] provide a way to pass workspace model to the JPS build process in serialized way (IJPL-409)

If newly introduced 'jps.build.use.workspace.model' registry option is enabled, required modules and libraries are added to the JPS build classpath, paths to global and project cache file for the workspace model are passed to the build process, and it loads the project model from them instead of reading the project configuration files.

It's an experimental approach, and it isn't fully implemented yet:
 * it doesn't ensure that caches are up-to-date;
 * the cache currently cannot be loaded by the build process because it references entities and other classes aren't available in the build process (e.g. ScratchRootsEntity and VirtualFileUrlBridge).

GitOrigin-RevId: 54a4a49566ca9dd0433c7a13251c2e28fc051e78
This commit is contained in:
Nikolay Chashnikov
2024-06-27 18:39:11 +02:00
committed by intellij-monorepo-bot
parent 3dd4206d54
commit f3ab5a172e
11 changed files with 95 additions and 4 deletions

View File

@@ -0,0 +1,24 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:JvmName("CompilerTests")
package com.intellij.compiler
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.registry.Registry
import com.intellij.platform.backend.workspace.GlobalWorkspaceModelCache.Companion.getInstance
import com.intellij.platform.backend.workspace.WorkspaceModel
import com.intellij.platform.backend.workspace.WorkspaceModelCache
import com.intellij.platform.ide.progress.runWithModalProgressBlocking
fun saveWorkspaceModelCaches(project: Project) {
if (Registry.`is`("jps.build.use.workspace.model")) {
val cache = WorkspaceModelCache.getInstance(project)
checkNotNull(cache) { "Workspace model cache is not enabled for project" }
cache.setVirtualFileUrlManager(WorkspaceModel.getInstance(project).getVirtualFileUrlManager())
cache.saveCacheNow()
val globalCache = getInstance()
checkNotNull(globalCache) { "Workspace model cache is not enabled for global storage" }
runWithModalProgressBlocking(project, "Save workspace model cache") {
globalCache.saveCacheNow()
}
}
}

View File

@@ -3,6 +3,7 @@ package com.intellij.testFramework;
import com.intellij.compiler.CompilerManagerImpl;
import com.intellij.compiler.CompilerTestUtil;
import com.intellij.compiler.CompilerTests;
import com.intellij.compiler.server.BuildManager;
import com.intellij.diagnostic.ThreadDumper;
import com.intellij.execution.wsl.WslPath;
@@ -194,6 +195,7 @@ public final class CompilerTester {
ErrorReportingCallback callback = new ErrorReportingCallback(semaphore);
PlatformTestUtil.saveProject(getProject(), false);
CompilerTestUtil.saveApplicationSettings();
CompilerTests.saveWorkspaceModelCaches(getProject());
EdtTestUtil.runInEdtAndWait(() -> {
// for now directory based project is used for external storage
if (!ProjectKt.isDirectoryBased(myProject)) {