From 77df22c235f4866d06a644f489e928237f493987 Mon Sep 17 00:00:00 2001 From: Ed Merks Date: Thu, 14 Dec 2023 15:19:57 +0100 Subject: [PATCH] Handle bundle folders in VirtualArtifactRepository.transferArtifact The implementation currently assumes all bundles are jars, but bundles from the shared bundle pool may be unpacked as folders. https://github.com/eclipse-pde/eclipse.pde/pull/962 --- .../target/VirtualArtifactRepository.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/VirtualArtifactRepository.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/VirtualArtifactRepository.java index 5a44adad062..bb10f2cdcd2 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/VirtualArtifactRepository.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/VirtualArtifactRepository.java @@ -14,6 +14,7 @@ package org.eclipse.pde.internal.core.target; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.OutputStream; @@ -34,6 +35,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.equinox.frameworkadmin.BundleInfo; +import org.eclipse.equinox.internal.p2.core.helpers.FileUtils; import org.eclipse.equinox.internal.p2.metadata.expression.QueryResult; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; @@ -123,8 +125,25 @@ private void transferArtifact(Object artifactModel, OutputStream destination) th if (location == null) { throw new FileNotFoundException(bundleInfo.getSymbolicName()); } - try (InputStream is = location.toURL().openStream()) { - is.transferTo(destination); + + File bundleLocation = new File(location); + if (bundleLocation.isFile()) { + try (InputStream is = new FileInputStream(bundleLocation)) { + is.transferTo(destination); + } + } else { + File zipFile = null; + try { + zipFile = File.createTempFile(bundleLocation.getName(), ".jar", null); //$NON-NLS-1$ + FileUtils.zip(bundleLocation.listFiles(), null, zipFile, + FileUtils.createRootPathComputer(bundleLocation)); + FileInputStream fis = new FileInputStream(zipFile); + FileUtils.copyStream(fis, true, destination, false); + } finally { + if (zipFile != null) { + zipFile.delete(); + } + } } } else if (artifactModel instanceof IFeatureModel featureModel) { String installLocation = featureModel.getInstallLocation();