From cfd6f72c0d4a5bae75346468ca7a301eee648cbe Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Thu, 12 Oct 2023 23:19:59 +0200 Subject: [PATCH] Remove support for unused attributes in feature.xml This removes support for the following attributes of plugin elements in feature.xml: - install/download-size - unpack - fragment The written values are not relevant anymore and therefore can be removed. In the context of https://github.com/eclipse-pde/eclipse.pde/issues/730 --- .../AbstractArtifactDependencyWalker.java | 1 - .../tycho/p2/resolver/FeatureGenerator.java | 6 --- .../tycho/p2/resolver/WrappedArtifact.java | 2 +- .../org/eclipse/tycho/model/PluginRef.java | 36 ---------------- .../packaging/FeatureXmlTransformer.java | 43 ------------------- .../tycho/packaging/UpdateSiteAssembler.java | 21 +++------ .../packaging/FeatureXmlTransformerTest.java | 6 --- .../featureXmlVersionExpansion/feature.xml | 5 +-- .../tycho/source/SourceFeatureMojo.java | 4 -- 9 files changed, 7 insertions(+), 117 deletions(-) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/AbstractArtifactDependencyWalker.java b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/AbstractArtifactDependencyWalker.java index befe4e65d2..bf634a276c 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/AbstractArtifactDependencyWalker.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/AbstractArtifactDependencyWalker.java @@ -162,7 +162,6 @@ protected void traverseProduct(ProductConfiguration product, ArtifactDependencyV ref.setOs(os); ref.setWs(ws); ref.setArch(arch); - ref.setUnpack(true); traversePlugin(ref, visitor, visited); } } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/FeatureGenerator.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/FeatureGenerator.java index 4e14fc0695..23decd6f3f 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/FeatureGenerator.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/FeatureGenerator.java @@ -45,7 +45,6 @@ import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.metadata.IVersionedId; import org.eclipse.equinox.p2.metadata.VersionedId; -import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction; import org.eclipse.equinox.p2.publisher.eclipse.Feature; import org.eclipse.tycho.core.MavenModelFacade; import org.eclipse.tycho.core.MavenModelFacade.MavenLicense; @@ -93,14 +92,9 @@ private static Feature createFeature(Element featureElement, List capability.getNamespace().equals(BundlesAction.CAPABILITY_NS_OSGI_FRAGMENT)); Element pluginElement = doc.createElement(ELEMENT_PLUGIN); pluginElement.setAttribute(ATTR_ID, bundle.getId()); pluginElement.setAttribute(ATTR_VERSION, bundle.getVersion().toString()); - if (isFragment) { - pluginElement.setAttribute(ATTR_FRAGMENT, String.valueOf(true)); - } //TODO can we check form the IU if we need to unpack? Or is the bundle info required here? Does it actually matter at all? pluginElement.setAttribute(ATTR_UNPACK, String.valueOf(false)); featureElement.appendChild(pluginElement); 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..3dc760b8db 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,42 +85,6 @@ public void setArch(String arch) { dom.setAttribute("arch", arch); } - /** - * @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 - * be supported in a future version of Tycho. - */ - @Deprecated - public boolean isUnpack() { - return Boolean.parseBoolean(dom.getAttributeValue("unpack")); - } - - /** - * @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 - * be supported in a future version of Tycho. - */ - @Deprecated - public void setUnpack(boolean unpack) { - dom.setAttribute("unpack", Boolean.toString(unpack)); - } - - public long getDownloadSize() { - return Long.parseLong(dom.getAttributeValue("download-size")); - } - - public void setDownloadSize(long size) { - dom.setAttribute("download-size", Long.toString(size)); - } - - public long getInstallSize() { - return Long.parseLong(dom.getAttributeValue("install-size")); - } - - public void setInstallSize(long size) { - dom.setAttribute("install-size", Long.toString(size)); - } - Element getDom() { return dom; } 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 ef56b2192e..73aba9458d 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 @@ -13,15 +13,10 @@ *******************************************************************************/ package org.eclipse.tycho.packaging; -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; import java.util.function.Function; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; import java.util.stream.Collectors; import org.apache.maven.plugin.MojoFailureException; @@ -84,12 +79,6 @@ public Feature expandReferences(Feature feature, TargetPlatform targetPlatform) } ArtifactKey plugin = resolvePluginReference(targetPlatform, pluginRef, version); pluginRef.setVersion(plugin.getVersion()); - - File location = targetPlatform.getArtifactLocation(plugin); - if (location == null) { - throw new MojoFailureException("location is missing for plugin " + plugin); - } - setDownloadAndInstallSize(pluginRef, location); } for (FeatureRef featureRef : feature.getIncludedFeatures()) { @@ -156,36 +145,4 @@ private static String quote(String nullableString) { return "\"" + nullableString + "\""; } - private void setDownloadAndInstallSize(PluginRef pluginRefToEdit, File artifact) { - // TODO 375111 optionally disable this? - long downloadSize = 0; - long installSize = 0; - if (artifact.isFile()) { - installSize = getInstallSize(artifact); - downloadSize = artifact.length(); - } else { - log.info("Download/install size is not calculated for directory based bundle " + pluginRefToEdit.getId()); - } - - pluginRefToEdit.setDownloadSize(downloadSize / KBYTE); - pluginRefToEdit.setInstallSize(installSize / KBYTE); - } - - protected long getInstallSize(File location) { - long installSize = 0; - try (var locked = fileLockService.lock(location); // - 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); - } - return installSize; - } } diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/UpdateSiteAssembler.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/UpdateSiteAssembler.java index bd22800ab7..f2beb2fd73 100644 --- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/UpdateSiteAssembler.java +++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/UpdateSiteAssembler.java @@ -12,13 +12,12 @@ *******************************************************************************/ package org.eclipse.tycho.packaging; -import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.Map; import org.codehaus.plexus.PlexusContainer; @@ -32,7 +31,6 @@ import org.eclipse.tycho.core.ArtifactDependencyVisitor; import org.eclipse.tycho.core.FeatureDescription; import org.eclipse.tycho.core.PluginDescription; -import org.eclipse.tycho.model.PluginRef; /** * Assembles standard eclipse update site directory structure on local filesystem. @@ -154,7 +152,7 @@ public void visitPlugin(PluginDescription plugin) { location = plugin.getLocation(true); } - if (unpackPlugins && isDirectoryShape(plugin, location)) { + if (unpackPlugins && location.isDirectory()) { // need a directory File outputJar = getOutputFile(PLUGINS_DIR, bundleId, version, null); @@ -175,11 +173,6 @@ public void visitPlugin(PluginDescription plugin) { } } - protected boolean isDirectoryShape(PluginDescription plugin, File location) { - PluginRef pluginRef = plugin.getPluginRef(); - return ((pluginRef != null && pluginRef.isUnpack()) || location.isDirectory()); - } - private void unpackJar(File location, File outputJar) { ZipUnArchiver unzip; FileLockService fileLockService; @@ -214,12 +207,8 @@ private void copyDir(File location, File outputJar) { } private void copyUrl(String source, File destination) { - try { - URL url = new URL(source); - try (InputStream is = url.openStream(); - OutputStream os = new BufferedOutputStream(new FileOutputStream(destination))) { - is.transferTo(os); - } + try (InputStream is = new URL(source).openStream()) { + Files.copy(is, destination.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new RuntimeException("Could not copy URL contents", e); } diff --git a/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/packaging/FeatureXmlTransformerTest.java b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/packaging/FeatureXmlTransformerTest.java index dc260d1335..d6d9ac7662 100644 --- a/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/packaging/FeatureXmlTransformerTest.java +++ b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/packaging/FeatureXmlTransformerTest.java @@ -15,7 +15,6 @@ import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -50,7 +49,6 @@ public static void initTestResources() throws Exception { junit4JarLocation = TestUtil.getTestResourceLocation("eclipse/plugins/org.junit4_4.8.1.v20100302.jar"); } - @SuppressWarnings("deprecation") @Test public void testExpandReferences() throws Exception { subject = new FeatureXmlTransformer(new SilentLog(), new NoopFileLockService()); @@ -69,10 +67,6 @@ public void testExpandReferences() throws Exception { assertThat(feature.getPlugins(), hasItem(plugin("org.junit4", "4.8.1.v20100302"))); PluginRef plugin = feature.getPlugins().get(0); assertEquals("org.junit4", plugin.getId()); - assertEquals(1L, plugin.getDownloadSize()); // 1720 bytes rounded to kiB - assertEquals(2L, plugin.getInstallSize()); // 2419 bytes rounded to kiB // TODO shouldn't - // installSize=downloadSize for unpack=false? - assertFalse(plugin.isUnpack()); } private static Matcher feature(final String id, final String version) { diff --git a/tycho-packaging-plugin/src/test/resources/projects/featureXmlVersionExpansion/feature.xml b/tycho-packaging-plugin/src/test/resources/projects/featureXmlVersionExpansion/feature.xml index eeed7534f3..490aa91e40 100644 --- a/tycho-packaging-plugin/src/test/resources/projects/featureXmlVersionExpansion/feature.xml +++ b/tycho-packaging-plugin/src/test/resources/projects/featureXmlVersionExpansion/feature.xml @@ -10,9 +10,6 @@ + version="4.8.1.qualifier"/> 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 88be9dd4d8..ffce719fd3 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 @@ -564,8 +564,6 @@ protected void addPlugin(Feature sourceFeature, P2ResolutionResult result, Plugi PluginRef sourceRef = new PluginRef("plugin"); sourceRef.setId(sourceBundle.getId()); sourceRef.setVersion(sourceBundle.getVersion()); - sourceRef.setDownloadSize(0); - sourceRef.setInstallSize(0); if (pluginRef.getOs() != null) { sourceRef.setOs(pluginRef.getOs()); } @@ -575,8 +573,6 @@ protected void addPlugin(Feature sourceFeature, P2ResolutionResult result, Plugi if (pluginRef.getArch() != null) { sourceRef.setArch(pluginRef.getArch()); } - sourceRef.setUnpack(false); - sourceFeature.addPlugin(sourceRef); }