From 969368feb4fe88d13a14bead53ee201d55765251 Mon Sep 17 00:00:00 2001 From: Michael Keppler Date: Sat, 30 Nov 2024 11:10:51 +0100 Subject: [PATCH] avoid try-with-resource compiler warning --- .../tycho/p2maven/tmp/BundlesAction.java | 51 +++++++------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/tmp/BundlesAction.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/tmp/BundlesAction.java index 9731a12b14..99918a9444 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/tmp/BundlesAction.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/tmp/BundlesAction.java @@ -13,7 +13,7 @@ * Code 9 - initial API and implementation * IBM - ongoing development * SAP AG - make optional dependencies non-greedy by default; allow setting greedy through directive (bug 247099) - * Red Hat Inc. - Bug 460967 + * Red Hat Inc. - Bug 460967 * Christoph Läubrich - Bug 574952 p2 should distinguish between "product plugins" and "configuration plugins" (gently sponsored by Compart AG) ******************************************************************************/ package org.eclipse.tycho.p2maven.tmp; @@ -121,7 +121,7 @@ public class BundlesAction extends AbstractPublisherAction { /** * A capability name in the {@link PublisherHelper#NAMESPACE_ECLIPSE_TYPE} * namespace representing and OSGi bundle resource - * + * * @see IProvidedCapability#getName() */ public static final String TYPE_ECLIPSE_BUNDLE = "bundle"; //$NON-NLS-1$ @@ -129,7 +129,7 @@ public class BundlesAction extends AbstractPublisherAction { /** * A capability name in the {@link PublisherHelper#NAMESPACE_ECLIPSE_TYPE} * namespace representing a source bundle - * + * * @see IProvidedCapability#getName() */ public static final String TYPE_ECLIPSE_SOURCE = "source"; //$NON-NLS-1$ @@ -159,7 +159,7 @@ public class BundlesAction extends AbstractPublisherAction { /** * Manifest header directive for specifying how optional runtime requirements * shall be handled during installation. - * + * * @see #INSTALLATION_GREEDY */ public static final String INSTALLATION_DIRECTIVE = "x-installation"; //$NON-NLS-1$ @@ -541,13 +541,13 @@ private IInstallableUnitFragment createHostLocalizationFragment(IInstallableUnit /* * @param hostId - * + * * @param bd - * + * * @param locale - * + * * @param localizedStrings - * + * * @return installableUnitFragment */ private static IInstallableUnitFragment createLocalizationFragmentOfHost(BundleDescription bd, String hostId, @@ -876,35 +876,20 @@ public static Dictionary basicLoadManifestIgnoringExceptions(Fil public static Dictionary basicLoadManifest(File bundleLocation) throws IOException, BundleException { - InputStream manifestStream = null; - ZipFile jarFile = null; if ("jar".equalsIgnoreCase(IPath.fromOSString(bundleLocation.getName()).getFileExtension()) && bundleLocation.isFile()) { //$NON-NLS-1$ - jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ); - ZipEntry manifestEntry = jarFile.getEntry(JarFile.MANIFEST_NAME); - if (manifestEntry != null) { - manifestStream = jarFile.getInputStream(manifestEntry); + try (ZipFile jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ)) { + ZipEntry manifestEntry = jarFile.getEntry(JarFile.MANIFEST_NAME); + if (manifestEntry != null) { + return parseBundleManifestIntoModifyableDictionaryWithCaseInsensitiveKeys(jarFile.getInputStream(manifestEntry)); + } } } else { File manifestFile = new File(bundleLocation, JarFile.MANIFEST_NAME); if (manifestFile.exists()) { - manifestStream = new BufferedInputStream(new FileInputStream(manifestFile)); - } - } - try { - if (manifestStream != null) { - return parseBundleManifestIntoModifyableDictionaryWithCaseInsensitiveKeys(manifestStream); - } - } finally { - try { - if (jarFile != null) - jarFile.close(); - } catch (IOException e2) { - // Ignore + return parseBundleManifestIntoModifyableDictionaryWithCaseInsensitiveKeys(new BufferedInputStream(new FileInputStream(manifestFile))); } } - return null; - } private static Dictionary parseBundleManifestIntoModifyableDictionaryWithCaseInsensitiveKeys( @@ -1019,13 +1004,13 @@ else if (new File(location, "plugin.xml").exists() || new File(location, "fragme /** * Publishes bundle IUs to the p2 metadata and artifact repositories. - * + * * @param bundleDescriptions Equinox framework descriptions of the bundles to * publish. * @param result Used to attach status for the publication * operation. * @param monitor Used to fire progress events. - * + * * @deprecated Use * {@link #generateBundleIUs(BundleDescription[] bundleDescriptions, IPublisherInfo info, IPublisherResult result, IProgressMonitor monitor)} * with {@link IPublisherInfo} set to null @@ -1038,10 +1023,10 @@ protected void generateBundleIUs(BundleDescription[] bundleDescriptions, IPublis /** * Publishes bundle IUs to the p2 metadata and artifact repositories. - * + * * @param bundleDescriptions Equinox framework descriptions of the bundles to * publish. - * @param publisherInfo Configuration and publication advice information. + * @param publisherInfo Configuration and publication advice information. * @param result Used to attach status for the publication * operation. * @param monitor Used to fire progress events.