From 6081458c0aabfb4b33a123f813e34fe093d80a8e Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sat, 7 Oct 2023 16:36:41 +0200 Subject: [PATCH] Only set download/install-size attributes in features if they exist This allows the first step of the degradation of the unused feature attributes 'install/download-size', 'unpack' and 'fragment'. In the context of https://github.com/eclipse-pde/eclipse.pde/issues/730 --- .../tycho/p2/resolver/WrappedArtifact.java | 2 +- .../org/eclipse/tycho/model/PluginRef.java | 16 +++++++++ .../packaging/FeatureXmlTransformer.java | 35 +++++++------------ .../tycho/source/SourceFeatureMojo.java | 5 +-- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/WrappedArtifact.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/WrappedArtifact.java index 6ecc5b68cb..4c9484d8a7 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/WrappedArtifact.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/WrappedArtifact.java @@ -76,7 +76,7 @@ public String getWrappedVersion() { public String getReferenceHint() { return "The artifact can be referenced in feature files with the following data: "; + + "\" version=\"" + wrappedVersion + "\"/>"; } public String getGeneratedManifest() { diff --git a/tycho-metadata-model/src/main/java/org/eclipse/tycho/model/PluginRef.java b/tycho-metadata-model/src/main/java/org/eclipse/tycho/model/PluginRef.java index 1ade5c933d..8afd13d9a1 100644 --- a/tycho-metadata-model/src/main/java/org/eclipse/tycho/model/PluginRef.java +++ b/tycho-metadata-model/src/main/java/org/eclipse/tycho/model/PluginRef.java @@ -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 @@ -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")); } @@ -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")); } diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/FeatureXmlTransformer.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/FeatureXmlTransformer.java index 7dd4099b9d..4486197a25 100644 --- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/FeatureXmlTransformer.java +++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/FeatureXmlTransformer.java @@ -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; @@ -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()) { @@ -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 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; } } diff --git a/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/SourceFeatureMojo.java b/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/SourceFeatureMojo.java index d216946fc5..1a5cd6e2e5 100644 --- a/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/SourceFeatureMojo.java +++ b/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/SourceFeatureMojo.java @@ -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); }