Bug 578820 - Use new FileLocator.getBundleFileLocation(Bundle)

Change-Id: Ia594bd07cce59263175600b6c7c265b94bc716fd
Signed-off-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
Reviewed-on: https://git.eclipse.org/r/c/pde/eclipse.pde.ui/+/191875
Tested-by: PDE Bot <pde-bot@eclipse.org>
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/ApiTestingEnvironment.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/ApiTestingEnvironment.java
index 07d8a94..8affb50 100644
--- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/ApiTestingEnvironment.java
+++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/ApiTestingEnvironment.java
@@ -16,7 +16,6 @@
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -737,7 +736,7 @@
 		fRevert = revert;
 	}
 
-	public static void setTargetPlatform() throws CoreException, InterruptedException, IOException {
+	public static void setTargetPlatform() throws CoreException, InterruptedException {
 		ITargetPlatformService tpService = PDECore.getDefault().acquireService(ITargetPlatformService.class);
 		ITargetDefinition workspaceTarget = tpService.getWorkspaceTargetDefinition();
 		if (workspaceTarget != null && workspaceTarget.getBundles() == null) {
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/model/tests/TestSuiteHelper.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/model/tests/TestSuiteHelper.java
index 32f6b0f..098d40e 100644
--- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/model/tests/TestSuiteHelper.java
+++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/model/tests/TestSuiteHelper.java
@@ -452,11 +452,7 @@
 		} else {
 			Bundle bundle = Platform.getBundle(bundleName);
 			if (bundle != null) {
-				try {
-					return FileLocator.getBundleFile(bundle);
-				} catch (IOException e) {
-					e.printStackTrace();
-				}
+				return FileLocator.getBundleFileLocation(bundle).orElse(null);
 			}
 		}
 		return null;
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/ApiAnalysisApplication.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/ApiAnalysisApplication.java
index 287dadb..3795bdb 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/ApiAnalysisApplication.java
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/ApiAnalysisApplication.java
@@ -229,14 +229,14 @@
 		});
 	}
 
-	private IApiBaseline setBaseline(File baselinePath) throws CoreException, IOException {
+	private IApiBaseline setBaseline(File baselinePath) throws CoreException {
 		if (baselinePath == null) {
 			ApiBaseline baseline = new ApiBaseline("current running application"); //$NON-NLS-1$
 			for (Bundle bundle : ApiPlugin.getDefault().getBundle().getBundleContext().getBundles()) {
 				if (bundle.getBundleId() != 0) {
+					String bundleFile = FileLocator.getBundleFileLocation(bundle).orElseThrow().getAbsolutePath();
 					baseline.addApiComponents(
-							new IApiComponent[] { new BundleComponent(baseline,
-									FileLocator.getBundleFile(bundle).getAbsolutePath(), bundle.getBundleId()) });
+							new IApiComponent[] { new BundleComponent(baseline, bundleFile, bundle.getBundleId()) });
 				}
 			}
 			ApiBaselineManager.getManager().addApiBaseline(baseline);
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetWeaver.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetWeaver.java
index 7650867..b34ef7d 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetWeaver.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetWeaver.java
@@ -26,6 +26,7 @@
 import java.nio.file.Path;
 import java.util.Arrays;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Properties;
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.Platform;
@@ -195,8 +196,8 @@
 		Bundle platformBundle = findRunningPlatformBundle(id, version);
 		if (platformBundle != null) {
 			try {
-				File bundleBaseFile = FileLocator.getBundleFile(platformBundle);
-				return Files.isSameFile(pluginLocation, bundleBaseFile.toPath());
+				Optional<File> bundleFile = FileLocator.getBundleFileLocation(platformBundle);
+				return bundleFile.isPresent() && Files.isSameFile(pluginLocation, bundleFile.get().toPath());
 			} catch (IOException e) {
 				PDECore.logException(e);
 			}
diff --git a/ui/org.eclipse.pde.ui.tests/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.ui.tests/META-INF/MANIFEST.MF
index a804e85..fdcb898 100644
--- a/ui/org.eclipse.pde.ui.tests/META-INF/MANIFEST.MF
+++ b/ui/org.eclipse.pde.ui.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: PDE JUnit Tests
 Bundle-SymbolicName: org.eclipse.pde.ui.tests; singleton:=true
-Bundle-Version: 3.11.700.qualifier
+Bundle-Version: 3.11.800.qualifier
 Bundle-ClassPath: tests.jar
 Bundle-Activator: org.eclipse.pde.ui.tests.PDETestsPlugin
 Bundle-Vendor: Eclipse.org
diff --git a/ui/org.eclipse.pde.ui.tests/pom.xml b/ui/org.eclipse.pde.ui.tests/pom.xml
index 71ae92e..89bfea6 100644
--- a/ui/org.eclipse.pde.ui.tests/pom.xml
+++ b/ui/org.eclipse.pde.ui.tests/pom.xml
@@ -18,7 +18,7 @@
     <relativePath>../../tests-pom/</relativePath>
   </parent>
   <artifactId>org.eclipse.pde.ui.tests</artifactId>
-  <version>3.11.700-SNAPSHOT</version>
+  <version>3.11.800-SNAPSHOT</version>
   <packaging>eclipse-test-plugin</packaging>
 
   <properties>
diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/util/TargetPlatformUtil.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/util/TargetPlatformUtil.java
index ed8218a..7173c3b 100644
--- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/util/TargetPlatformUtil.java
+++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/util/TargetPlatformUtil.java
@@ -46,12 +46,12 @@
 
 	private static final String RUNNING_PLATFORM_TARGET_NAME = TargetPlatformUtil.class + "_RunningPlatformTarget";
 
-	public static void setRunningPlatformAsTarget() throws IOException, CoreException, InterruptedException {
+	public static void setRunningPlatformAsTarget() throws CoreException, InterruptedException {
 		setRunningPlatformSubSetAsTarget(RUNNING_PLATFORM_TARGET_NAME, null);
 	}
 
 	public static void setRunningPlatformSubSetAsTarget(String name, Predicate<Bundle> bundleFilter)
-			throws IOException, CoreException, InterruptedException {
+			throws CoreException, InterruptedException {
 		ITargetDefinition currentTarget = TPS.getWorkspaceTargetDefinition();
 		if (name.equals(currentTarget.getName())) {
 			return;
@@ -88,20 +88,16 @@
 	}
 
 	private static void addRunningPlatformBundles(Collection<ITargetLocation> bundleContainers,
-			Collection<NameVersionDescriptor> included, Predicate<Bundle> bundleFilter) throws IOException {
+			Collection<NameVersionDescriptor> included, Predicate<Bundle> bundleFilter) {
 		Bundle[] installedBundles = FrameworkUtil.getBundle(TargetPlatformUtil.class).getBundleContext().getBundles();
 		List<Bundle> targetBundles = Arrays.asList(installedBundles);
 		if (bundleFilter != null) {
 			targetBundles = targetBundles.stream().filter(bundleFilter).collect(Collectors.toList());
 		}
 
-		Set<File> bundleContainerDirectories = new HashSet<>();
-		for (Bundle bundle : targetBundles) {
-			File bundleContainer = FileLocator.getBundleFile(bundle).getParentFile();
-			bundleContainerDirectories.add(bundleContainer);
-		}
-		bundleContainerDirectories.stream().map(dir -> TPS.newDirectoryLocation(dir.getAbsolutePath()))
-		.forEach(bundleContainers::add);
+		var containerDirs = targetBundles.stream().map(FileLocator::getBundleFileLocation).map(Optional::orElseThrow)
+				.map(File::getParentFile).distinct();
+		containerDirs.map(dir -> TPS.newDirectoryLocation(dir.getAbsolutePath())).forEach(bundleContainers::add);
 
 		for (Bundle bundle : targetBundles) {
 			included.add(new NameVersionDescriptor(bundle.getSymbolicName(), bundle.getVersion().toString()));