From d07bc99b4ae4e3b8e71379959670bd74f8d02c2a Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sun, 27 Nov 2022 10:54:20 +0100 Subject: [PATCH] [PDE-Connector] simplify bundle-root set to make activator obsolete We already use the internal class org.eclipse.pde.internal.core.project.PDEProject to get the Bundle-Root, so we can also it to set the Bundle-Root, which makes the activator for m2e.pde.connector obsolete. --- .../META-INF/MANIFEST.MF | 1 - .../eclipse/m2e/pde/connector/Activator.java | 44 ------------------- .../m2e/pde/connector/PDEProjectHelper.java | 13 ++---- 3 files changed, 4 insertions(+), 54 deletions(-) delete mode 100644 org.eclipse.m2e.pde.connector/src/org/eclipse/m2e/pde/connector/Activator.java diff --git a/org.eclipse.m2e.pde.connector/META-INF/MANIFEST.MF b/org.eclipse.m2e.pde.connector/META-INF/MANIFEST.MF index df569b1223..f63b9e48f1 100644 --- a/org.eclipse.m2e.pde.connector/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.pde.connector/META-INF/MANIFEST.MF @@ -15,5 +15,4 @@ Require-Bundle: org.eclipse.m2e.core;bundle-version="[2.0.0,3.0.0)", org.eclipse.pde.core, org.eclipse.jdt.core, org.eclipse.pde.ds.annotations -Bundle-Activator: org.eclipse.m2e.pde.connector.Activator Service-Component: OSGI-INF/org.eclipse.m2e.pde.connector.PDEBuildProjectFileResolver.xml diff --git a/org.eclipse.m2e.pde.connector/src/org/eclipse/m2e/pde/connector/Activator.java b/org.eclipse.m2e.pde.connector/src/org/eclipse/m2e/pde/connector/Activator.java deleted file mode 100644 index 0a49a4ced5..0000000000 --- a/org.eclipse.m2e.pde.connector/src/org/eclipse/m2e/pde/connector/Activator.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021 Christoph Läubrich - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-v20.html - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Christoph Läubrich - initial API and implementation - *******************************************************************************/ -package org.eclipse.m2e.pde.connector; - -import java.util.Optional; - -import org.eclipse.pde.core.project.IBundleProjectService; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.util.tracker.ServiceTracker; - -public class Activator implements BundleActivator { - - private static volatile ServiceTracker bundleProjectServiceTracker; - - @Override - public void start(BundleContext context) throws Exception { - bundleProjectServiceTracker = new ServiceTracker<>(context, IBundleProjectService.class, null); - bundleProjectServiceTracker.open(); - } - - @Override - public void stop(BundleContext context) throws Exception { - bundleProjectServiceTracker.close(); - } - - public static Optional getBundleProjectService() { - if (bundleProjectServiceTracker == null) { - return Optional.empty(); - } - return Optional.ofNullable(bundleProjectServiceTracker.getService()); - } - -} diff --git a/org.eclipse.m2e.pde.connector/src/org/eclipse/m2e/pde/connector/PDEProjectHelper.java b/org.eclipse.m2e.pde.connector/src/org/eclipse/m2e/pde/connector/PDEProjectHelper.java index 08c15f9858..4acee0558f 100644 --- a/org.eclipse.m2e.pde.connector/src/org/eclipse/m2e/pde/connector/PDEProjectHelper.java +++ b/org.eclipse.m2e.pde.connector/src/org/eclipse/m2e/pde/connector/PDEProjectHelper.java @@ -42,7 +42,6 @@ import org.eclipse.pde.core.build.IBuildModel; import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.PluginRegistry; -import org.eclipse.pde.core.project.IBundleProjectService; public class PDEProjectHelper { @@ -155,27 +154,23 @@ static void addPDENature(IProject project, IPath manifestPath, IProgressMonitor setManifestLocaton(project, manifestPath, monitor); } + @SuppressWarnings("restriction") private static void setManifestLocaton(IProject project, IPath manifestPath, IProgressMonitor monitor) throws CoreException { - IBundleProjectService projectService = Activator.getBundleProjectService().orElseThrow(); + IContainer bundleRoot = null; // in case of configuration update, reset to the default value if (manifestPath != null) { - IPath bundleRootPath; IFile manifest; if (manifestPath.toFile().toPath().endsWith("META-INF")) { - bundleRootPath = manifestPath.removeLastSegments(1); manifest = project.getFolder(manifestPath).getFile("MANIFEST.MF"); } else if (manifestPath.toFile().toPath().endsWith(Path.of("META-INF", "MANIFEST.MF"))) { - bundleRootPath = manifestPath.removeLastSegments(2); manifest = project.getFile(manifestPath); } else { return; } manifest.refreshLocal(IResource.DEPTH_ZERO, monitor); - projectService.setBundleRoot(project, bundleRootPath.isEmpty() ? null : bundleRootPath); - } else { - // in case of configuration update, reset to the default value - projectService.setBundleRoot(project, null); + bundleRoot = manifest.getParent().getParent(); } + org.eclipse.pde.internal.core.project.PDEProject.setBundleRoot(project, bundleRoot); } /**