Skip to content

Commit

Permalink
Internal code simplificatons in equinox.p2.publisher.eclipse
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Sep 27, 2024
1 parent 385d266 commit e86710c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 60 deletions.
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

0 comments on commit e86710c

Please sign in to comment.