Skip to content

Commit

Permalink
Only set download/install-size attributes in features if they exist
Browse files Browse the repository at this point in the history
This allows the first step of the degradation of the unused feature
attributes 'install/download-size', 'unpack' and 'fragment'.

In the context of eclipse-pde/eclipse.pde#730
  • Loading branch information
HannesWell committed Oct 12, 2023
1 parent 59abc85 commit ea9107e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public String getWrappedVersion() {

public String getReferenceHint() {
return "The artifact can be referenced in feature files with the following data: <plugin id=\"" + wrappedBsn
+ "\" version=\"" + wrappedVersion + "\" download-size=\"0\" install-size=\"0\" unpack=\"false\"/>";
+ "\" version=\"" + wrappedVersion + "\"/>";
}

public String getGeneratedManifest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public void setArch(String arch) {
dom.setAttribute("arch", arch);
}

@Deprecated
public boolean hasUnpack() {
String value = dom.getAttributeValue("unpack");
return value != null && !value.isBlank();
}

/**
* @deprecated The installation format (packed/unpacked) shall be specified through the bundle's
* Eclipse-BundleShape manifest header. The feature.xml's unpack attribute may not
Expand All @@ -105,6 +111,11 @@ public void setUnpack(boolean unpack) {
dom.setAttribute("unpack", Boolean.toString(unpack));
}

public boolean hasDownloadSize() {
String value = dom.getAttributeValue("download-size");
return value != null && !value.isBlank();
}

public long getDownloadSize() {
return Long.parseLong(dom.getAttributeValue("download-size"));
}
Expand All @@ -113,6 +124,11 @@ public void setDownloadSize(long size) {
dom.setAttribute("download-size", Long.toString(size));
}

public boolean hasInstallSize() {
String value = dom.getAttributeValue("install-size");
return value != null && !value.isBlank();
}

public long getInstallSize() {
return Long.parseLong(dom.getAttributeValue("install-size"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;
import java.util.Objects;
import java.util.function.BinaryOperator;
Expand Down Expand Up @@ -158,7 +157,9 @@ private static String quote(String nullableString) {
}

private void setDownloadAndInstallSize(PluginRef pluginRefToEdit, File artifact) {
// TODO 375111 optionally disable this?
if (!pluginRefToEdit.hasInstallSize() && !pluginRefToEdit.hasDownloadSize()) {
return;
}
long downloadSize = 0;
long installSize = 0;
if (artifact.isFile()) {
Expand All @@ -167,33 +168,23 @@ private void setDownloadAndInstallSize(PluginRef pluginRefToEdit, File artifact)
} else {
log.info("Download/install size is not calculated for directory based bundle " + pluginRefToEdit.getId());
}

pluginRefToEdit.setDownloadSize(downloadSize / KBYTE);
pluginRefToEdit.setInstallSize(installSize / KBYTE);
if (pluginRefToEdit.hasDownloadSize()) {
pluginRefToEdit.setDownloadSize(downloadSize / KBYTE);
}
if (pluginRefToEdit.hasInstallSize()) {
pluginRefToEdit.setInstallSize(installSize / KBYTE);
}
}

protected long getInstallSize(File location) {
long installSize = 0;
FileLocker locker = fileLockService.getFileLocker(location);
locker.lock();
try {
try {
try (JarFile jar = new JarFile(location)) {
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
long entrySize = entry.getSize();
if (entrySize > 0) {
installSize += entrySize;
}
}
}
} catch (IOException e) {
throw new RuntimeException("Could not determine installation size of file " + location, e);
}
try (JarFile jar = new JarFile(location)) {
return jar.stream().mapToLong(JarEntry::getSize).filter(s -> s > 0).sum();
} catch (IOException e) {
throw new RuntimeException("Could not determine installation size of file " + location, e);
} finally {
locker.release();
}
return installSize;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,9 @@ protected void addPlugin(Feature sourceFeature, P2ResolutionResult result, Plugi
if (pluginRef.getArch() != null) {
sourceRef.setArch(pluginRef.getArch());
}
sourceRef.setUnpack(false);

if (pluginRef.hasUnpack()) {
sourceRef.setUnpack(false);
}
sourceFeature.addPlugin(sourceRef);
}

Expand Down

0 comments on commit ea9107e

Please sign in to comment.