Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal code simplificatons in equinox.p2.publisher.eclipse #550

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: org.eclipse.equinox.p2.publisher.eclipse;singleton:=true
Bundle-Version: 1.6.200.qualifier
Bundle-Version: 1.6.300.qualifier
Bundle-Activator: org.eclipse.pde.internal.publishing.Activator
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,8 @@ private Collection<IVersionedId> versionElements(Collection<IVersionedId> elemen
for (IVersionedId element : elements) {
Version elementVersion = element.getVersion();
if (elementVersion == null || Version.emptyVersion.equals(elementVersion)) {
Iterator<IVersionAdvice> advice = versionAdvice.iterator();
while (advice.hasNext()) {
elementVersion = advice.next().getVersion(namespace, element.getId());
for (IVersionAdvice advice : versionAdvice) {
elementVersion = advice.getVersion(namespace, element.getId());
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,25 @@
*******************************************************************************/
package org.eclipse.pde.internal.publishing;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Dictionary;
import java.util.Enumeration;

import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.BundleException;

public final class Utils {

static public void copy(File source, File destination) throws IOException {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(source));
out = new BufferedOutputStream(new FileOutputStream(destination));
final byte[] buffer = new byte[8192];
while (true) {
int bytesRead = -1;
bytesRead = in.read(buffer);
if (bytesRead == -1)
break;
out.write(buffer, 0, bytesRead);
}
} finally {
try {
if (in != null)
in.close();
} finally {
if (out != null)
out.close();
}
}
Files.copy(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
}

public static boolean guessUnpack(BundleDescription bundle, String[] classpath) {
if (bundle == null)
public static boolean guessUnpack(BundleDescription bundle, List<String> classpath) {
if (bundle == null) {
return true;

}
@SuppressWarnings("unchecked")
Dictionary<String, String> properties = (Dictionary<String, String>) bundle.getUserObject();
String shape = null;
Expand All @@ -68,39 +41,26 @@ public static boolean guessUnpack(BundleDescription bundle, String[] classpath)
}

// launcher fragments are a special case, they have no bundle-classpath
if (bundle.getHost() != null && bundle.getName().startsWith(Constants.BUNDLE_EQUINOX_LAUNCHER))
if (bundle.getHost() != null && bundle.getName().startsWith(Constants.BUNDLE_EQUINOX_LAUNCHER)) {
return true;

if (new File(bundle.getLocation()).isFile())
return false;

if (classpath.length == 0)
}
if (new File(bundle.getLocation()).isFile()) {
return false;

for (String classpath1 : classpath) {
if (classpath1.equals(".")) { //$NON-NLS-1$
return false;
}
}
return true;
return !classpath.isEmpty() && classpath.stream().noneMatch("."::equals); //$NON-NLS-1$
}

public static String[] getBundleClasspath(Dictionary<String, String> manifest) {
public static List<String> getBundleClasspath(Dictionary<String, String> manifest) {
String fullClasspath = getBundleManifestHeader(manifest, Constants.BUNDLE_CLASSPATH);
String[] result = new String[0];
try {
if (fullClasspath != null) {
ManifestElement[] classpathEntries;
classpathEntries = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, fullClasspath);
result = new String[classpathEntries.length];
for (int i = 0; i < classpathEntries.length; i++) {
result[i] = classpathEntries[i].getValue();
}
return Arrays.stream(ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH,
fullClasspath)).map(ManifestElement::getValue).toList();
}
} catch (BundleException e) {
//Ignore
}
return result;
return List.of();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ public static Collection<IconResInfo> replaceIcons(File launcherFile, ImageData[
raf.close();
return Collections.emptyList();
}
Iterator<IconResInfo> originalIconsIterator = iconInfo.iterator();
while (originalIconsIterator.hasNext()) {
for (Iterator<IconResInfo> originalIconsIterator = iconInfo.iterator(); originalIconsIterator.hasNext();) {
IconResInfo iconToReplace = originalIconsIterator.next();
for (ImageData iconToWrite : Arrays.asList(icons)) {
if (iconToWrite == null)
Expand Down
Loading