mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Workspace Model] [Artifact] Detect removing of artifact in modifiable bridge
GitOrigin-RevId: a7ba8a3418f9771b73e30dde4faae64bb5530062
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f6ec6553ca
commit
dc870efda5
+5
-1
@@ -29,6 +29,7 @@ open class ArtifactBridge(
|
||||
var entityStorage: VersionedEntityStorage,
|
||||
val project: Project,
|
||||
val eventDispatcher: EventDispatcher<ArtifactListener>?,
|
||||
val originalArtifact: ArtifactBridge?,
|
||||
) : ModifiableArtifact, UserDataHolderBase() {
|
||||
|
||||
init {
|
||||
@@ -42,7 +43,10 @@ open class ArtifactBridge(
|
||||
// In this case two artifact bridges exists with the same ArtifactId: one for removed artifact and one for newly created
|
||||
// We should make sure that we "disable" removed artifact bridge
|
||||
if (event.storageAfter.resolve(artifactId) != null
|
||||
&& event.storageBefore.artifactsMap.getDataByEntity(it.entity) != this@ArtifactBridge) return@forEach
|
||||
&& event.storageBefore.artifactsMap.getDataByEntity(it.entity) != this@ArtifactBridge
|
||||
&& event.storageBefore.artifactsMap.getDataByEntity(it.entity) != originalArtifact) {
|
||||
return@forEach
|
||||
}
|
||||
|
||||
entityStorage = VersionedEntityStorageOnStorage(event.storageBefore)
|
||||
assert(entityStorage.current.resolve(artifactId) != null) { "Cannot resolve artifact $artifactId." }
|
||||
|
||||
+2
-2
@@ -148,7 +148,7 @@ class ArtifactModifiableModelBridge(
|
||||
)
|
||||
|
||||
val persistentId = artifactEntity.persistentId()
|
||||
val modifiableArtifact = ArtifactBridge(persistentId, versionedOnBuilder, project, eventDispatcher)
|
||||
val modifiableArtifact = ArtifactBridge(persistentId, versionedOnBuilder, project, eventDispatcher, null)
|
||||
modifiableToOriginal[modifiableArtifact] = modifiableArtifact
|
||||
diff.mutableArtifactsMap.addMapping(artifactEntity, modifiableArtifact)
|
||||
|
||||
@@ -186,7 +186,7 @@ class ArtifactModifiableModelBridge(
|
||||
val existingModifiableArtifact = modifiableToOriginal.getKeysByValue(artifact)?.singleOrNull()
|
||||
if (existingModifiableArtifact != null) return existingModifiableArtifact
|
||||
|
||||
val modifiableArtifact = ArtifactBridge(artifactId, versionedOnBuilder, project, eventDispatcher)
|
||||
val modifiableArtifact = ArtifactBridge(artifactId, versionedOnBuilder, project, eventDispatcher, artifact)
|
||||
modifiableToOriginal[modifiableArtifact] = artifact
|
||||
eventDispatcher.multicaster.artifactChanged(modifiableArtifact, artifact.name)
|
||||
return modifiableArtifact
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ internal fun createArtifactBridge(it: ArtifactEntity, entityStorage: VersionedEn
|
||||
JavaCompilerBundle.message("unknown.artifact.properties.0", unknownProperty))
|
||||
}
|
||||
|
||||
return ArtifactBridge(it.persistentId(), entityStorage, project, null)
|
||||
return ArtifactBridge(it.persistentId(), entityStorage, project, null, null)
|
||||
}
|
||||
|
||||
fun PackagingElement<*>.forThisAndFullTree(action: (PackagingElement<*>) -> Unit) {
|
||||
|
||||
+1
-1
@@ -17,6 +17,6 @@ class InvalidArtifactBridge(
|
||||
|
||||
@Nls(capitalization = Nls.Capitalization.Sentence)
|
||||
private val _errorMessage: String,
|
||||
) : InvalidArtifact, ArtifactBridge(_artifactId, entityStorage, project, eventDispatcher) {
|
||||
) : InvalidArtifact, ArtifactBridge(_artifactId, entityStorage, project, eventDispatcher, null) {
|
||||
override fun getErrorMessage(): String = _errorMessage
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.intellij.packaging.impl.artifacts.PlainArtifactType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
public class ArtifactsModelTest extends ArtifactsTestCase {
|
||||
public void testAddArtifact() {
|
||||
@@ -145,6 +146,24 @@ public class ArtifactsModelTest extends ArtifactsTestCase {
|
||||
assertTrue(newModifiableArtifact.isBuildOnMake());
|
||||
}
|
||||
|
||||
public void testReplaceArtifactWithCheckingModifiableArtifactData() {
|
||||
// This test checks if the recreation of the artifact with the same name doesn't replace the new artifact with the new one
|
||||
Artifact artifact = addArtifact("A");
|
||||
assertSame(artifact, assertOneElement(getArtifacts()));
|
||||
final ModifiableArtifactModel model = getArtifactManager().createModifiableModel();
|
||||
// Just create a modifiable artifact
|
||||
ModifiableArtifact newArtifact = model.getOrCreateModifiableArtifact(artifact);
|
||||
model.removeArtifact(artifact);
|
||||
ModifiableArtifact newModifiableArtifact = model.addArtifact("A", PlainArtifactType.getInstance());
|
||||
newModifiableArtifact.setBuildOnMake(true);
|
||||
newModifiableArtifact.setOutputPath("B");
|
||||
commit(model);
|
||||
assertEquals("B", newModifiableArtifact.getOutputPath());
|
||||
assertTrue(newModifiableArtifact.isBuildOnMake());
|
||||
assertFalse(newArtifact.isBuildOnMake());
|
||||
assertNotEquals("B", newArtifact.getOutputPath());
|
||||
}
|
||||
|
||||
private Artifact[] getArtifacts() {
|
||||
return getArtifactManager().getArtifacts();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user