Skip to content

Commit

Permalink
Handle bundle folders in VirtualArtifactRepository.transferArtifact
Browse files Browse the repository at this point in the history
The implementation currently assumes all bundles are jars, but bundles
from the shared bundle pool may be unpacked as folders.

eclipse-pde#962
  • Loading branch information
merks committed Dec 14, 2023
1 parent 75fdc0d commit 77bb7b8
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,9 +23,11 @@
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipOutputStream;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -34,6 +37,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;
Expand Down Expand Up @@ -123,8 +127,17 @@ 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 {
ZipOutputStream zip = new ZipOutputStream(destination);
FileUtils.zip(zip, bundleLocation, Set.of(), FileUtils.createRootPathComputer(bundleLocation));
zip.finish();
zip.flush();
}
} else if (artifactModel instanceof IFeatureModel featureModel) {
String installLocation = featureModel.getInstallLocation();
Expand Down

0 comments on commit 77bb7b8

Please sign in to comment.