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

Only set download/install-size attributes in features if they exist #2917

Merged
Merged
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 @@ -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
Loading