mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[workspace model] move CompilerModuleExtensionBridge to Java plugin (IDEA-269975)
It's now possible to register it via ModuleExtensionBridgeFactory, so we can move the implementation of the platform code. This simplifies code and removes dependencies from RootModelBridgeImpl which complicates its relocation to projectModel.impl module. Also, the old unused implementation CompilerModuleExtensionImpl is now removed. GitOrigin-RevId: 7c112cd837624d049c8f7f30ab2c142500edfb5f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9a38edeead
commit
eab75c7118
@@ -86,6 +86,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.codeStyle.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
|
||||
<orderEntry type="module" module-name="intellij.completionMlRanking" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.workspaceModel.storage" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -1071,7 +1071,8 @@
|
||||
<highlightUsagesHandlerFactory implementation="com.intellij.codeInsight.highlighting.HighlightSuppressedWarningsFactory"/>
|
||||
<highlightUsagesHandlerFactory implementation="com.intellij.codeInsight.highlighting.HighlightExceptionsHandlerFactory"/>
|
||||
<highlightUsagesHandlerFactory implementation="com.intellij.codeInsight.highlighting.HighlightRecordComponentsRecordFactory"/>
|
||||
<moduleExtension implementation="com.intellij.openapi.roots.impl.CompilerModuleExtensionImpl"/>
|
||||
<workspaceModel.moduleExtensionBridgeFactory
|
||||
implementation="com.intellij.workspaceModel.ide.legacyBridge.impl.java.CompilerModuleExtensionBridge$Companion"/>
|
||||
<projectExtension implementation="com.intellij.openapi.roots.impl.LanguageLevelProjectExtensionImpl$MyProjectExtension"/>
|
||||
<liveTemplateContext implementation="com.intellij.codeInsight.template.JavaCodeContextType$Generic"/>
|
||||
<liveTemplateContext implementation="com.intellij.codeInsight.template.JavaCodeContextType$Statement"/>
|
||||
|
||||
@@ -1,337 +0,0 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.openapi.roots.impl;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.CompilerModuleExtension;
|
||||
import com.intellij.openapi.roots.CompilerProjectExtension;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.serialization.java.JpsJavaModelSerializerExtension;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
class CompilerModuleExtensionImpl extends CompilerModuleExtension {
|
||||
@NonNls private static final String OUTPUT_TAG = JpsJavaModelSerializerExtension.OUTPUT_TAG;
|
||||
@NonNls private static final String TEST_OUTPUT_TAG = JpsJavaModelSerializerExtension.TEST_OUTPUT_TAG;
|
||||
@NonNls private static final String ATTRIBUTE_URL = JpsJavaModelSerializerExtension.URL_ATTRIBUTE;
|
||||
@NonNls private static final String EXCLUDE_OUTPUT_TAG = JpsJavaModelSerializerExtension.EXCLUDE_OUTPUT_TAG;
|
||||
|
||||
private String myCompilerOutput;
|
||||
private VirtualFilePointer myCompilerOutputPointer;
|
||||
|
||||
private String myCompilerOutputForTests;
|
||||
private VirtualFilePointer myCompilerOutputPathForTestsPointer;
|
||||
|
||||
private boolean myInheritedCompilerOutput = true;
|
||||
private boolean myExcludeOutput = true;
|
||||
@NotNull
|
||||
private final Module myModule;
|
||||
|
||||
private CompilerModuleExtensionImpl mySource;
|
||||
private boolean myWritable;
|
||||
private boolean myDisposed;
|
||||
|
||||
CompilerModuleExtensionImpl(@NotNull Module module) {
|
||||
myModule = module;
|
||||
}
|
||||
|
||||
private CompilerModuleExtensionImpl(@NotNull CompilerModuleExtensionImpl source, final boolean writable) {
|
||||
this(source.myModule);
|
||||
myWritable = writable;
|
||||
myCompilerOutput = source.myCompilerOutput;
|
||||
myCompilerOutputPointer = duplicatePointer(source.myCompilerOutputPointer);
|
||||
myCompilerOutputForTests = source.myCompilerOutputForTests;
|
||||
myCompilerOutputPathForTestsPointer = duplicatePointer(source.myCompilerOutputPathForTestsPointer);
|
||||
myInheritedCompilerOutput = source.myInheritedCompilerOutput;
|
||||
myExcludeOutput = source.myExcludeOutput;
|
||||
mySource = source;
|
||||
}
|
||||
|
||||
private VirtualFilePointer duplicatePointer(VirtualFilePointer pointer) {
|
||||
if (pointer == null) return null;
|
||||
final VirtualFilePointerManager filePointerManager = VirtualFilePointerManager.getInstance();
|
||||
return filePointerManager.duplicate(pointer, this, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(@NotNull Element element) {
|
||||
assert !myDisposed;
|
||||
myInheritedCompilerOutput = Boolean.parseBoolean(element.getAttributeValue(JpsJavaModelSerializerExtension.INHERIT_COMPILER_OUTPUT_ATTRIBUTE, "false"));
|
||||
myExcludeOutput = element.getChild(EXCLUDE_OUTPUT_TAG) != null;
|
||||
|
||||
myCompilerOutputPointer = getOutputPathValue(element, OUTPUT_TAG, !myInheritedCompilerOutput);
|
||||
|
||||
myCompilerOutput = getOutputPathValue(element, OUTPUT_TAG);
|
||||
|
||||
myCompilerOutputPathForTestsPointer = getOutputPathValue(element, TEST_OUTPUT_TAG, !myInheritedCompilerOutput);
|
||||
|
||||
myCompilerOutputForTests = getOutputPathValue(element, TEST_OUTPUT_TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(@NotNull Element element) {
|
||||
assert !myDisposed;
|
||||
if (!myInheritedCompilerOutput) {
|
||||
if (myCompilerOutput != null) {
|
||||
final Element pathElement = new Element(OUTPUT_TAG);
|
||||
pathElement.setAttribute(ATTRIBUTE_URL, myCompilerOutput);
|
||||
element.addContent(pathElement);
|
||||
}
|
||||
if (myCompilerOutputForTests != null) {
|
||||
final Element pathElement = new Element(TEST_OUTPUT_TAG);
|
||||
pathElement.setAttribute(ATTRIBUTE_URL, myCompilerOutputForTests);
|
||||
element.addContent(pathElement);
|
||||
}
|
||||
}
|
||||
else {
|
||||
element.setAttribute(JpsJavaModelSerializerExtension.INHERIT_COMPILER_OUTPUT_ATTRIBUTE, "true");
|
||||
}
|
||||
|
||||
if (myExcludeOutput) {
|
||||
element.addContent(new Element(EXCLUDE_OUTPUT_TAG));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private VirtualFilePointer getOutputPathValue(Element element, String tag, final boolean createPointer) {
|
||||
final Element outputPathChild = element.getChild(tag);
|
||||
VirtualFilePointer vptr = null;
|
||||
if (outputPathChild != null && createPointer) {
|
||||
String outputPath = outputPathChild.getAttributeValue(ATTRIBUTE_URL);
|
||||
vptr = createPointer(outputPath);
|
||||
}
|
||||
return vptr;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getOutputPathValue(@NotNull Element element, @NotNull String tag) {
|
||||
final Element outputPathChild = element.getChild(tag);
|
||||
if (outputPathChild != null) {
|
||||
return outputPathChild.getAttributeValue(ATTRIBUTE_URL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public VirtualFile getCompilerOutputPath() {
|
||||
if (myInheritedCompilerOutput) {
|
||||
final VirtualFile projectOutputPath = CompilerProjectExtension.getInstance(getProject()).getCompilerOutput();
|
||||
if (projectOutputPath == null) return null;
|
||||
return projectOutputPath.findFileByRelativePath(PRODUCTION + "/" + getSanitizedModuleName());
|
||||
}
|
||||
return myCompilerOutputPointer == null ? null : myCompilerOutputPointer.getFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public VirtualFile getCompilerOutputPathForTests() {
|
||||
if (myInheritedCompilerOutput) {
|
||||
final VirtualFile projectOutputPath = CompilerProjectExtension.getInstance(getProject()).getCompilerOutput();
|
||||
if (projectOutputPath == null) return null;
|
||||
return projectOutputPath.findFileByRelativePath(TEST + "/" + getSanitizedModuleName());
|
||||
}
|
||||
return myCompilerOutputPathForTestsPointer == null ? null : myCompilerOutputPathForTestsPointer.getFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getCompilerOutputUrl() {
|
||||
if (myInheritedCompilerOutput) {
|
||||
final String projectOutputPath = CompilerProjectExtension.getInstance(getProject()).getCompilerOutputUrl();
|
||||
if (projectOutputPath == null) return null;
|
||||
return projectOutputPath + "/" + PRODUCTION + "/" + getSanitizedModuleName();
|
||||
}
|
||||
return myCompilerOutputPointer == null ? null : myCompilerOutputPointer.getUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getCompilerOutputUrlForTests() {
|
||||
if (myInheritedCompilerOutput) {
|
||||
final String projectOutputPath = CompilerProjectExtension.getInstance(getProject()).getCompilerOutputUrl();
|
||||
if (projectOutputPath == null) return null;
|
||||
return projectOutputPath + "/" + TEST + "/" + getSanitizedModuleName();
|
||||
}
|
||||
return myCompilerOutputPathForTestsPointer == null ? null : myCompilerOutputPathForTestsPointer.getUrl();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getSanitizedModuleName() {
|
||||
Module module = getModule();
|
||||
VirtualFile file = module.getModuleFile();
|
||||
return file != null ? file.getNameWithoutExtension() : module.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompilerOutputPath(final VirtualFile file) {
|
||||
setCompilerOutputPath(file == null ? null : file.getUrl());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private VirtualFilePointer createPointer(@NotNull String url) {
|
||||
return VirtualFilePointerManager.getInstance().create(url, this, ProjectRootManagerImpl.getInstanceImpl(getProject()).getRootsValidityChangedListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompilerOutputPath(final String url) {
|
||||
assertWritable();
|
||||
myCompilerOutput = url;
|
||||
myCompilerOutputPointer = url == null ? null : createPointer(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompilerOutputPathForTests(final VirtualFile file) {
|
||||
setCompilerOutputPathForTests(file == null ? null : file.getUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompilerOutputPathForTests(final String url) {
|
||||
assertWritable();
|
||||
myCompilerOutputForTests = url;
|
||||
myCompilerOutputPathForTestsPointer = url == null ? null : createPointer(url);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Module getModule() {
|
||||
return myModule;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Project getProject() {
|
||||
return myModule.getProject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inheritCompilerOutputPath(final boolean inherit) {
|
||||
if (myInheritedCompilerOutput == inherit) return;
|
||||
|
||||
assertWritable();
|
||||
myInheritedCompilerOutput = inherit;
|
||||
}
|
||||
|
||||
private void assertWritable() {
|
||||
assert myWritable: "Writable model can be retrieved from writable ModifiableRootModel";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompilerOutputPathInherited() {
|
||||
return myInheritedCompilerOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFilePointer getCompilerOutputPointer() {
|
||||
return myCompilerOutputPointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFilePointer getCompilerOutputForTestsPointer() {
|
||||
return myCompilerOutputPathForTestsPointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExcludeOutput(final boolean exclude) {
|
||||
assertWritable();
|
||||
myExcludeOutput = exclude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExcludeOutput() {
|
||||
return myExcludeOutput;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CompilerModuleExtension getModifiableModel(final boolean writable) {
|
||||
assert !myDisposed;
|
||||
return new CompilerModuleExtensionImpl(this, writable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() {
|
||||
if (mySource != null) {
|
||||
mySource.myCompilerOutput = myCompilerOutput;
|
||||
boolean old = mySource.myWritable;
|
||||
mySource.myWritable = true;
|
||||
mySource.setCompilerOutputPath(myCompilerOutputPointer == null ? null : myCompilerOutputPointer.getUrl());
|
||||
mySource.myCompilerOutputForTests = myCompilerOutputForTests;
|
||||
mySource.setCompilerOutputPathForTests(myCompilerOutputPathForTestsPointer == null ? null : myCompilerOutputPathForTestsPointer.getUrl());
|
||||
mySource.myInheritedCompilerOutput = myInheritedCompilerOutput;
|
||||
mySource.myExcludeOutput = myExcludeOutput;
|
||||
mySource.myWritable = old;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChanged() {
|
||||
if (myInheritedCompilerOutput != mySource.myInheritedCompilerOutput) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!vptrEqual(myCompilerOutputPointer, mySource.myCompilerOutputPointer)) {
|
||||
return true;
|
||||
}
|
||||
if (!vptrEqual(myCompilerOutputPathForTestsPointer, mySource.myCompilerOutputPathForTestsPointer)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return myExcludeOutput != mySource.myExcludeOutput;
|
||||
}
|
||||
|
||||
private static boolean vptrEqual(VirtualFilePointer p1, VirtualFilePointer p2) {
|
||||
String arg1 = p1 == null ? null : p1.getUrl();
|
||||
String arg2 = p2 == null ? null : p2.getUrl();
|
||||
return Objects.equals(arg1, arg2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
myDisposed = true;
|
||||
mySource = null;
|
||||
myCompilerOutput = null;
|
||||
myCompilerOutputForTests = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFile @NotNull [] getOutputRoots(final boolean includeTests) {
|
||||
List<VirtualFile> result = new ArrayList<>();
|
||||
|
||||
final VirtualFile outputPathForTests = includeTests ? getCompilerOutputPathForTests() : null;
|
||||
if (outputPathForTests != null) {
|
||||
result.add(outputPathForTests);
|
||||
}
|
||||
|
||||
VirtualFile outputRoot = getCompilerOutputPath();
|
||||
if (outputRoot != null && !outputRoot.equals(outputPathForTests)) {
|
||||
result.add(outputRoot);
|
||||
}
|
||||
return VfsUtilCore.toVirtualFileArray(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String @NotNull [] getOutputRootUrls(final boolean includeTests) {
|
||||
final List<String> result = new ArrayList<>();
|
||||
|
||||
final String outputPathForTests = includeTests ? getCompilerOutputUrlForTests() : null;
|
||||
if (outputPathForTests != null) {
|
||||
result.add(outputPathForTests);
|
||||
}
|
||||
|
||||
String outputRoot = getCompilerOutputUrl();
|
||||
if (outputRoot != null && !outputRoot.equals(outputPathForTests)) {
|
||||
result.add(outputRoot);
|
||||
}
|
||||
return ArrayUtilRt.toStringArray(result);
|
||||
}
|
||||
}
|
||||
+16
-8
@@ -1,5 +1,5 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.workspaceModel.ide.impl.legacyBridge.module
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.workspaceModel.ide.legacyBridge.impl.java
|
||||
|
||||
import com.intellij.openapi.roots.CompilerModuleExtension
|
||||
import com.intellij.openapi.roots.CompilerProjectExtension
|
||||
@@ -13,21 +13,21 @@ import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerCom
|
||||
import com.intellij.workspaceModel.ide.impl.toVirtualFileUrl
|
||||
import com.intellij.workspaceModel.ide.impl.virtualFile
|
||||
import com.intellij.workspaceModel.ide.legacyBridge.ModuleBridge
|
||||
import com.intellij.workspaceModel.ide.legacyBridge.ModuleExtensionBridge
|
||||
import com.intellij.workspaceModel.ide.legacyBridge.ModuleExtensionBridgeFactory
|
||||
import com.intellij.workspaceModel.storage.VersionedEntityStorage
|
||||
import com.intellij.workspaceModel.storage.WorkspaceEntityStorageDiffBuilder
|
||||
import com.intellij.workspaceModel.storage.bridgeEntities.ModifiableJavaModuleSettingsEntity
|
||||
import com.intellij.workspaceModel.storage.bridgeEntities.addJavaModuleSettingsEntity
|
||||
import com.intellij.workspaceModel.storage.url.VirtualFileUrl
|
||||
import com.intellij.workspaceModel.storage.url.VirtualFileUrlManager
|
||||
|
||||
class CompilerModuleExtensionBridge(
|
||||
private val module: ModuleBridge,
|
||||
private val entityStorage: VersionedEntityStorage,
|
||||
private val diff: WorkspaceEntityStorageDiffBuilder?
|
||||
) : CompilerModuleExtension() {
|
||||
) : CompilerModuleExtension(), ModuleExtensionBridge {
|
||||
|
||||
private var changed = false
|
||||
private val virtualFileManager = VirtualFileUrlManager.getInstance(module.project)
|
||||
private val virtualFileManager = com.intellij.workspaceModel.storage.url.VirtualFileUrlManager.getInstance(module.project)
|
||||
|
||||
private val javaSettings
|
||||
get() = entityStorage.current.findModuleEntity(module)?.javaSettings
|
||||
@@ -76,7 +76,7 @@ class CompilerModuleExtensionBridge(
|
||||
override fun isChanged(): Boolean = changed
|
||||
override fun dispose() = Unit
|
||||
|
||||
private fun updateJavaSettings(updater: ModifiableJavaModuleSettingsEntity.() -> Unit) {
|
||||
private fun updateJavaSettings(updater: com.intellij.workspaceModel.storage.bridgeEntities.ModifiableJavaModuleSettingsEntity.() -> Unit) {
|
||||
if (diff == null) {
|
||||
error("Read-only $javaClass")
|
||||
}
|
||||
@@ -94,7 +94,7 @@ class CompilerModuleExtensionBridge(
|
||||
source = moduleSource
|
||||
)
|
||||
|
||||
diff.modifyEntity(ModifiableJavaModuleSettingsEntity::class.java, oldJavaSettings, updater)
|
||||
diff.modifyEntity(com.intellij.workspaceModel.storage.bridgeEntities.ModifiableJavaModuleSettingsEntity::class.java, oldJavaSettings, updater)
|
||||
changed = true
|
||||
}
|
||||
|
||||
@@ -158,4 +158,12 @@ class CompilerModuleExtensionBridge(
|
||||
|
||||
return ArrayUtilRt.toStringArray(result)
|
||||
}
|
||||
|
||||
companion object : ModuleExtensionBridgeFactory<CompilerModuleExtensionBridge> {
|
||||
override fun createExtension(module: ModuleBridge,
|
||||
entityStorage: VersionedEntityStorage,
|
||||
diff: WorkspaceEntityStorageDiffBuilder?): CompilerModuleExtensionBridge {
|
||||
return CompilerModuleExtensionBridge(module, entityStorage, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,16 @@ package com.intellij.roots
|
||||
import com.intellij.openapi.application.runWriteActionAndWait
|
||||
import com.intellij.openapi.module.LanguageLevelUtil
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.CompilerModuleExtension
|
||||
import com.intellij.openapi.roots.CompilerProjectExtension
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.testFramework.ApplicationRule
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.intellij.testFramework.rules.ProjectModelRule
|
||||
import com.intellij.util.io.systemIndependentPath
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.ClassRule
|
||||
import org.junit.Rule
|
||||
@@ -55,6 +60,39 @@ class JavaModuleExtensionsTest {
|
||||
listener.assertInvoked()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `change module output`() {
|
||||
val module = projectModel.createModule("foo")
|
||||
val outputRoot = projectModel.baseProjectDir.rootPath.resolve("out")
|
||||
CompilerProjectExtension.getInstance(projectModel.project)!!.compilerOutputUrl = VfsUtilCore.pathToUrl(outputRoot.systemIndependentPath)
|
||||
assertThat(CompilerModuleExtension.getInstance(module)!!.compilerOutputUrl).isEqualTo(VfsUtilCore.pathToUrl(outputRoot.resolve("production/foo").systemIndependentPath))
|
||||
assertThat(CompilerModuleExtension.getInstance(module)!!.compilerOutputUrlForTests).isEqualTo(VfsUtilCore.pathToUrl(outputRoot.resolve("test/foo").systemIndependentPath))
|
||||
|
||||
val customOutputUrl = VfsUtilCore.pathToUrl(outputRoot.resolve("custom").systemIndependentPath)
|
||||
ModuleRootModificationUtil.updateModel(module) {
|
||||
it.getModuleExtension(CompilerModuleExtension::class.java).setCompilerOutputPath(customOutputUrl)
|
||||
}
|
||||
assertThat(CompilerModuleExtension.getInstance(module)!!.compilerOutputUrlForTests).isEqualTo(VfsUtilCore.pathToUrl(outputRoot.resolve("test/foo").systemIndependentPath))
|
||||
|
||||
ModuleRootModificationUtil.updateModel(module) {
|
||||
it.getModuleExtension(CompilerModuleExtension::class.java).inheritCompilerOutputPath(false)
|
||||
}
|
||||
assertThat(CompilerModuleExtension.getInstance(module)!!.compilerOutputUrl).isEqualTo(customOutputUrl)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `change project output`() {
|
||||
val module = projectModel.createModule("foo")
|
||||
val outputRoot = projectModel.baseProjectDir.rootPath.resolve("out")
|
||||
CompilerProjectExtension.getInstance(projectModel.project)!!.compilerOutputUrl = VfsUtilCore.pathToUrl(outputRoot.systemIndependentPath)
|
||||
assertThat(CompilerModuleExtension.getInstance(module)!!.compilerOutputUrl).isEqualTo(VfsUtilCore.pathToUrl(outputRoot.resolve("production/foo").systemIndependentPath))
|
||||
|
||||
val newOutputRoot = projectModel.baseProjectDir.rootPath.resolve("out")
|
||||
val newOutputUrl = VfsUtilCore.pathToUrl(newOutputRoot.systemIndependentPath)
|
||||
CompilerProjectExtension.getInstance(projectModel.project)!!.compilerOutputUrl = newOutputUrl
|
||||
assertThat(CompilerModuleExtension.getInstance(module)!!.compilerOutputUrl).isEqualTo(VfsUtilCore.pathToUrl(newOutputRoot.resolve("production/foo").systemIndependentPath))
|
||||
}
|
||||
|
||||
private class MyLanguageLevelListener : LanguageLevelProjectExtension.LanguageLevelChangeListener {
|
||||
private var invoked = false
|
||||
|
||||
|
||||
-12
@@ -28,7 +28,6 @@ import com.intellij.workspaceModel.ide.impl.legacyBridge.LegacyBridgeModifiableB
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.library.LibraryBridge
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.library.LibraryBridgeImpl
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.library.LibraryNameGenerator
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.CompilerModuleExtensionBridge
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerComponentBridge.Companion.findModuleEntity
|
||||
import com.intellij.workspaceModel.ide.legacyBridge.ModifiableRootModelBridge
|
||||
import com.intellij.workspaceModel.ide.legacyBridge.ModuleBridge
|
||||
@@ -77,7 +76,6 @@ class ModifiableRootModelBridgeImpl(
|
||||
private val extensionsDelegate = lazy {
|
||||
RootModelBridgeImpl.loadExtensions(storage = entityStorageOnDiff, module = module, diff = diff, writable = true,
|
||||
parentDisposable = extensionsDisposable)
|
||||
.filterNot { compilerModuleExtensionClass.isAssignableFrom(it.javaClass) }
|
||||
}
|
||||
private val extensions by extensionsDelegate
|
||||
|
||||
@@ -615,21 +613,11 @@ class ModifiableRootModelBridgeImpl(
|
||||
internal val currentModel
|
||||
get() = entityStorageOnDiff.cachedValue(modelValue)
|
||||
|
||||
private val compilerModuleExtension by lazy {
|
||||
CompilerModuleExtensionBridge(moduleBridge, entityStorage = entityStorageOnDiff, diff = diff)
|
||||
}
|
||||
private val compilerModuleExtensionClass = CompilerModuleExtension::class.java
|
||||
|
||||
override fun getExcludeRoots(): Array<VirtualFile> = currentModel.excludeRoots
|
||||
|
||||
override fun orderEntries(): OrderEnumerator = ModuleOrderEnumerator(this, null)
|
||||
|
||||
override fun <T : Any?> getModuleExtension(klass: Class<T>): T? {
|
||||
if (compilerModuleExtensionClass.isAssignableFrom(klass)) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return compilerModuleExtension as T
|
||||
}
|
||||
|
||||
return extensions.filterIsInstance(klass).firstOrNull()
|
||||
}
|
||||
|
||||
|
||||
-12
@@ -12,7 +12,6 @@ import com.intellij.openapi.roots.impl.RootConfigurationAccessor
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.RootConfigurationAccessorForWorkspaceModel
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.CompilerModuleExtensionBridge
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerComponentBridge.Companion.findModuleEntity
|
||||
import com.intellij.workspaceModel.ide.legacyBridge.ModuleBridge
|
||||
import com.intellij.workspaceModel.storage.CachedValue
|
||||
@@ -127,18 +126,7 @@ class ModuleRootComponentBridge(
|
||||
override fun getExcludeRoots(): Array<VirtualFile> = model.excludeRoots
|
||||
override fun orderEntries(): OrderEnumerator = ModuleOrderEnumerator(this, orderRootsCache)
|
||||
|
||||
private val compilerModuleExtension by lazy {
|
||||
CompilerModuleExtensionBridge(moduleBridge, entityStorage = moduleBridge.entityStorage, diff = null)
|
||||
}
|
||||
|
||||
private val compilerModuleExtensionClass = CompilerModuleExtension::class.java
|
||||
|
||||
override fun <T : Any?> getModuleExtension(klass: Class<T>): T? {
|
||||
if (compilerModuleExtensionClass.isAssignableFrom(klass)) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return compilerModuleExtension as T
|
||||
}
|
||||
|
||||
return model.getModuleExtension(klass)
|
||||
}
|
||||
|
||||
|
||||
-13
@@ -11,7 +11,6 @@ import com.intellij.openapi.roots.impl.RootModelBase
|
||||
import com.intellij.openapi.util.Comparing
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.JDOMUtil
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.CompilerModuleExtensionBridge
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerComponentBridge.Companion.findModuleEntity
|
||||
import com.intellij.workspaceModel.ide.legacyBridge.ModuleBridge
|
||||
import com.intellij.workspaceModel.ide.legacyBridge.ModuleExtensionBridgeFactory
|
||||
@@ -79,19 +78,7 @@ internal class RootModelBridgeImpl(internal val moduleEntity: ModuleEntity?,
|
||||
|
||||
override fun getModule(): ModuleBridge = module
|
||||
|
||||
// TODO Deduplicate this code with other two root model implementations
|
||||
private val compilerModuleExtension by lazy {
|
||||
CompilerModuleExtensionBridge(module, entityStorage = VersionedEntityStorageOnStorage(storage), diff = null)
|
||||
}
|
||||
|
||||
private val compilerModuleExtensionClass = CompilerModuleExtension::class.java
|
||||
|
||||
override fun <T : Any?> getModuleExtension(klass: Class<T>): T? {
|
||||
if (compilerModuleExtensionClass.isAssignableFrom(klass)) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return compilerModuleExtension as T
|
||||
}
|
||||
|
||||
return extensions.filterIsInstance(klass).firstOrNull()
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -10,14 +10,14 @@ import com.intellij.openapi.roots.libraries.Library
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.workspaceModel.storage.WorkspaceEntityStorageBuilder
|
||||
import com.intellij.workspaceModel.storage.url.VirtualFileUrlManager
|
||||
import com.intellij.workspaceModel.ide.getInstance
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.CompilerModuleExtensionBridge
|
||||
import com.intellij.workspaceModel.ide.legacyBridge.ModuleBridge
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerComponentBridge
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.roots.ModuleRootComponentBridge
|
||||
import com.intellij.workspaceModel.ide.legacyBridge.ModuleBridge
|
||||
import com.intellij.workspaceModel.ide.legacyBridge.impl.java.CompilerModuleExtensionBridge
|
||||
import com.intellij.workspaceModel.storage.WorkspaceEntityStorageBuilder
|
||||
import com.intellij.workspaceModel.storage.bridgeEntities.*
|
||||
import com.intellij.workspaceModel.storage.url.VirtualFileUrlManager
|
||||
import org.jetbrains.idea.maven.importing.MavenModelUtil
|
||||
import org.jetbrains.idea.maven.importing.MavenRootModelAdapterInterface
|
||||
import org.jetbrains.idea.maven.model.MavenArtifact
|
||||
|
||||
Reference in New Issue
Block a user