From 7e279bc106b7636543be2c1cd2ee3816cc073397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 7 May 2024 16:36:25 +0200 Subject: [PATCH] Refresh the bundle model after building the automatic manifest --- .../pde/internal/core/PluginModelManager.java | 11 +++++ .../core/WorkspacePluginModelManager.java | 48 ++++++++++--------- .../pde/internal/core/bnd/BndBuilder.java | 3 ++ .../pde/internal/core/bnd/ProjectJar.java | 4 ++ 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java index 4511a39cd2..52d143995c 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginModelManager.java @@ -1261,4 +1261,15 @@ public void addExtensionDeltaListener(IExtensionDeltaListener listener) { public void removeExtensionDeltaListener(IExtensionDeltaListener listener) { fWorkspaceManager.removeExtensionDeltaListener(listener); } + + public void update(IProject project) { + synchronized (fEntriesSynchronizer) { + IPluginModelBase model = fWorkspaceManager.getModel(project); + if (model == null) { + fWorkspaceManager.createModel(project, true); + } else { + fWorkspaceManager.updateModel(project, model); + } + } + } } diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/WorkspacePluginModelManager.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/WorkspacePluginModelManager.java index eb549c4a3b..713c8b96a4 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/WorkspacePluginModelManager.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/WorkspacePluginModelManager.java @@ -332,29 +332,33 @@ private void handleBundleManifestDelta(IFile file, IResourceDelta delta) { } else if (kind == IResourceDelta.ADDED || model == null) { createModel(project, true); } else if (kind == IResourceDelta.CHANGED && (IResourceDelta.CONTENT & delta.getFlags()) != 0) { - if (model instanceof IBundlePluginModelBase) { - // check to see if localization changed (bug 146912) - String oldLocalization = ((IBundlePluginModelBase) model).getBundleLocalization(); - IBundleModel bmodel = ((IBundlePluginModelBase) model).getBundleModel(); - boolean wasFragment = bmodel.isFragmentModel(); - Map oldHeaders = bmodel.getBundle().getManifestHeaders(); - - loadModel(bmodel, true); - String newLocalization = ((IBundlePluginModelBase) model).getBundleLocalization(); - - // Fragment-Host header was added or removed - if (wasFragment != bmodel.isFragmentModel()) { - removeModel(project); - createModel(project, true); - } else { - if (model instanceof AbstractNLModel && (oldLocalization != null && (newLocalization == null || !oldLocalization.equals(newLocalization))) || (newLocalization != null && (oldLocalization == null || !newLocalization.equals(oldLocalization)))) { - ((AbstractNLModel) model).resetNLResourceHelper(); - } + updateModel(project, model); + } + } - Map newHeaders = bmodel.getBundle().getManifestHeaders(); - if (hasModelChanged(oldHeaders, newHeaders)) { - addChange(model, IModelProviderEvent.MODELS_CHANGED); - } + protected void updateModel(IProject project, IPluginModelBase model) { + if (model instanceof IBundlePluginModelBase) { + // check to see if localization changed (bug 146912) + String oldLocalization = ((IBundlePluginModelBase) model).getBundleLocalization(); + IBundleModel bmodel = ((IBundlePluginModelBase) model).getBundleModel(); + boolean wasFragment = bmodel.isFragmentModel(); + Map oldHeaders = bmodel.getBundle().getManifestHeaders(); + + loadModel(bmodel, true); + String newLocalization = ((IBundlePluginModelBase) model).getBundleLocalization(); + + // Fragment-Host header was added or removed + if (wasFragment != bmodel.isFragmentModel()) { + removeModel(project); + createModel(project, true); + } else { + if (model instanceof AbstractNLModel && (oldLocalization != null && (newLocalization == null || !oldLocalization.equals(newLocalization))) || (newLocalization != null && (oldLocalization == null || !newLocalization.equals(oldLocalization)))) { + ((AbstractNLModel) model).resetNLResourceHelper(); + } + + Map newHeaders = bmodel.getBundle().getManifestHeaders(); + if (hasModelChanged(oldHeaders, newHeaders)) { + addChange(model, IModelProviderEvent.MODELS_CHANGED); } } } diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/BndBuilder.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/BndBuilder.java index 0cd4f2aecc..9947cf28dc 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/BndBuilder.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/BndBuilder.java @@ -38,6 +38,7 @@ import org.eclipse.pde.internal.core.ICoreConstants; import org.eclipse.pde.internal.core.PDECore; import org.eclipse.pde.internal.core.PDECoreMessages; +import org.eclipse.pde.internal.core.PluginModelManager; import org.eclipse.pde.internal.core.builders.PDEMarkerFactory; import org.eclipse.pde.internal.core.natures.BndProject; import org.eclipse.pde.internal.core.project.PDEProject; @@ -188,6 +189,8 @@ public void addClasspath(aQute.bnd.osgi.Jar jar) { } } } + PluginModelManager modelManager = PDECore.getDefault().getModelManager(); + modelManager.update(project); } if (monitor.isCanceled()) { return; diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/ProjectJar.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/ProjectJar.java index d7b3e94881..5179fdf9f5 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/ProjectJar.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/ProjectJar.java @@ -190,4 +190,8 @@ private void cleanup() { } } + public IFile getManifestFile() { + return manifestFile; + } + }