From d564019b93c930086d4c4e9ae6f42e43e4fcdce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Wed, 9 Oct 2024 08:36:47 +0300 Subject: [PATCH] Get rid of deprecated Utils class Inline the methods in the single test using them. --- .../test/product/Tycho465RootFilesTest.java | 128 +++++++++++++++--- .../org/eclipse/tycho/test/product/Util.java | 113 ---------------- 2 files changed, 106 insertions(+), 135 deletions(-) delete mode 100644 tycho-its/src/test/java/org/eclipse/tycho/test/product/Util.java diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/product/Tycho465RootFilesTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/product/Tycho465RootFilesTest.java index 67358b98b9..ce3906f2b3 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/product/Tycho465RootFilesTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/product/Tycho465RootFilesTest.java @@ -17,8 +17,12 @@ import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.util.HashSet; import java.util.Set; +import java.util.zip.ZipEntry; import java.util.zip.ZipException; +import java.util.zip.ZipFile; import org.apache.maven.it.Verifier; import org.eclipse.tycho.test.AbstractTychoIntegrationTest; @@ -27,6 +31,8 @@ import de.pdark.decentxml.Document; import de.pdark.decentxml.Element; +import de.pdark.decentxml.XMLIOSource; +import de.pdark.decentxml.XMLParser; public class Tycho465RootFilesTest extends AbstractTychoIntegrationTest { @@ -102,29 +108,28 @@ static void assertContainsEntry(File dir, String prefix) { static void assertFeatureIU(Document contentXml, File assembledRepoDir, String featureId, String... requiredIus) { String featureIuId = featureId + ".feature.group"; - Set featureIus = Util.findIU(contentXml, featureIuId); + Set featureIus = findIU(contentXml, featureIuId); assertEquals("Feature iu with id = '" + featureIuId + "' does not occur exactly once in content.xml", 1, featureIus.size()); Element featureIu = featureIus.iterator().next(); - assertTrue(Util.containsIUWithProperty(contentXml, featureIuId, "org.eclipse.equinox.p2.type.group", "true")); - assertTrue(Util.iuHasAllRequirements(featureIu, requiredIus)); + assertTrue(containsIUWithProperty(contentXml, featureIuId, "org.eclipse.equinox.p2.type.group", "true")); + assertTrue(iuHasAllRequirements(featureIu, requiredIus)); String featureArtifactPrefix = featureId + "_1.0.0"; assertContainsEntry(new File(assembledRepoDir, "features/"), featureArtifactPrefix); } static void assertCategoryIU(Document contentXml, String categoryIuId, String featureIuId) { - Set categoryIus = Util.findIU(contentXml, categoryIuId); + Set categoryIus = findIU(contentXml, categoryIuId); assertEquals("Unique category iu not found", 1, categoryIus.size()); Element categoryIu = categoryIus.iterator().next(); assertTrue("IU not typed as category", - Util.iuHasProperty(categoryIu, "org.eclipse.equinox.p2.type.category", "true")); - assertTrue("Category name missing", - Util.iuHasProperty(categoryIu, "org.eclipse.equinox.p2.name", "A Category")); - assertTrue(Util.iuHasAllRequirements(categoryIu, featureIuId)); + iuHasProperty(categoryIu, "org.eclipse.equinox.p2.type.category", "true")); + assertTrue("Category name missing", iuHasProperty(categoryIu, "org.eclipse.equinox.p2.name", "A Category")); + assertTrue(iuHasAllRequirements(categoryIu, featureIuId)); } static void assertAddedRootFile(File targetDir) { @@ -203,7 +208,7 @@ static void assertInstalledWinConfigRootFile(File targetDir) { static void assertRootIuMetaData(Document contentXml) { String featureId = "prf.feature"; String featureIuId = featureId + ".feature.group"; - Set featureIus = Util.findIU(contentXml, featureIuId); + Set featureIus = findIU(contentXml, featureIuId); assertEquals("Feature iu with id = '" + featureIuId + "' does not occur exactly once in content.xml", 1, featureIus.size()); @@ -214,17 +219,17 @@ static void assertRootIuMetaData(Document contentXml) { assertTrue( "Verifying content.xml failed because feature iu with id = '" + featureIuId + "' does not contain required root iu with id = '" + rootWinConfigFeatureIuId + "'", - Util.iuHasAllRequirements(featureIu, rootWinConfigFeatureIuId)); + iuHasAllRequirements(featureIu, rootWinConfigFeatureIuId)); String rootLinuxConfigFeatureIuId = featureId + "_root.gtk.linux.x86_64"; assertTrue( "Verifying content.xml failed because feature iu with id = '" + featureIuId + "' does not contain required root iu with id = '" + rootLinuxConfigFeatureIuId + "'", - Util.iuHasAllRequirements(featureIu, rootLinuxConfigFeatureIuId)); + iuHasAllRequirements(featureIu, rootLinuxConfigFeatureIuId)); String featureIuRootId = featureId + "_root"; - Set featureRootIus = Util.findIU(contentXml, featureIuRootId); + Set featureRootIus = findIU(contentXml, featureIuRootId); assertEquals("Feature root iu with id = '" + featureIuRootId + "' does not occur exactly once in content.xml", 1, featureRootIus.size()); @@ -232,46 +237,45 @@ static void assertRootIuMetaData(Document contentXml) { static void assertRootIuPermissionsMetaData(Document contentXml) { // permission defined in build.properties: root.permissions.755 = file5.txt - Set featureRootIus = Util.findIU(contentXml, "prf.feature_root"); + Set featureRootIus = findIU(contentXml, "prf.feature_root"); String expectedTouchpointDataInstruction = "chmod(targetDir:${installFolder}, targetFile:file5.txt, permissions:755);"; assertTrue("Expected chmod touchpointData instruction '" + expectedTouchpointDataInstruction + "' not found.", - Util.iuHasTouchpointDataInstruction(featureRootIus.iterator().next(), - expectedTouchpointDataInstruction)); + iuHasTouchpointDataInstruction(featureRootIus.iterator().next(), expectedTouchpointDataInstruction)); // permission defined in build.properties: root.linux.gtk.x86_64.permissions.555 // = **/*.so - Element linuxRootIu = Util.findIU(contentXml, "prf.feature_root.gtk.linux.x86_64").iterator().next(); + Element linuxRootIu = findIU(contentXml, "prf.feature_root.gtk.linux.x86_64").iterator().next(); String chmod555Instruction = "chmod(targetDir:${installFolder}, targetFile:dir/test.so, permissions:555);"; assertTrue("Expected chmod touchpointData instruction '" + chmod555Instruction + "' not found.", - Util.iuHasTouchpointDataInstruction(linuxRootIu, chmod555Instruction)); + iuHasTouchpointDataInstruction(linuxRootIu, chmod555Instruction)); } static void assertRootIuLinksMetaData(Document contentXml) { // global link defined in build.properties: root.link = // dir/file6.txt,alias_file6.txt - Set globalFeatureRootIus = Util.findIU(contentXml, "prf.feature_root"); + Set globalFeatureRootIus = findIU(contentXml, "prf.feature_root"); String expectedGlobalTouchpointDataInstruction = "ln(linkTarget:dir/file6.txt,targetDir:${installFolder},linkName:alias_file6.txt);"; assertTrue( "Expected link (ln) touchpointData instruction '" + expectedGlobalTouchpointDataInstruction + "' not found.", - Util.iuHasTouchpointDataInstruction(globalFeatureRootIus.iterator().next(), + iuHasTouchpointDataInstruction(globalFeatureRootIus.iterator().next(), expectedGlobalTouchpointDataInstruction)); // specific link defined in build.properties: root.linux.gtk.x86_64.link = // file1.txt,alias_file1.txt - Set specificRootfeatureIus = Util.findIU(contentXml, "prf.feature_root.gtk.linux.x86_64"); + Set specificRootfeatureIus = findIU(contentXml, "prf.feature_root.gtk.linux.x86_64"); String expectedSpecificTouchpointDataInstruction = "ln(linkTarget:file1.txt,targetDir:${installFolder},linkName:alias_file1.txt);"; assertTrue( "Expected link (ln) touchpointData instruction '" + expectedSpecificTouchpointDataInstruction + "' not found.", - Util.iuHasTouchpointDataInstruction(specificRootfeatureIus.iterator().next(), + iuHasTouchpointDataInstruction(specificRootfeatureIus.iterator().next(), expectedSpecificTouchpointDataInstruction)); } @@ -281,6 +285,86 @@ private static Document openMetadataRepositoryDocument(File repositoryTargetDire File contentJar = new File(repositoryTargetDirectory, "content.jar"); assertTrue("content.jar not found \n" + contentJar.getAbsolutePath(), contentJar.isFile()); - return Util.openXmlFromZip(contentJar, "content.xml"); + return openXmlFromZip(contentJar, "content.xml"); + } + + private static Document openXmlFromZip(File zipFile, String xmlFile) throws IOException, ZipException { + XMLParser parser = new XMLParser(); + try (ZipFile zip = new ZipFile(zipFile)) { + ZipEntry contentXmlEntry = zip.getEntry(xmlFile); + InputStream entryStream = zip.getInputStream(contentXmlEntry); + return parser.parse(new XMLIOSource(entryStream)); + } + } + + private static boolean containsIUWithProperty(Document contentXML, String iuId, String propName, String propValue) { + Set ius = findIU(contentXML, iuId); + for (Element unitElement : ius) { + if (iuHasProperty(unitElement, propName, propValue)) + return true; + } + return false; + } + + private static Set findIU(Document contentXML, String iuId) { + Set foundIUs = new HashSet<>(); + + Element repository = contentXML.getRootElement(); + for (Element unit : repository.getChild("units").getChildren("unit")) { + if (iuId.equals(unit.getAttributeValue("id"))) { + foundIUs.add(unit); + } + } + return foundIUs; + } + + private static boolean iuHasProperty(Element unit, String propName, String propValue) { + boolean foundIU = false; + + if (propName != null) { + for (Element property : unit.getChild("properties").getChildren("property")) { + if (propName.equals(property.getAttributeValue("name")) + && propValue.equals((property.getAttributeValue("value")))) { + foundIU = true; + break; + } + } + } else { + foundIU = true; + } + return foundIU; + } + + private static boolean iuHasAllRequirements(Element unit, String... requiredIus) { + boolean hasAllRequirements = true; + for (String requiredIu : requiredIus) { + boolean foundIU = false; + for (Element property : unit.getChild("requires").getChildren("required")) { + if (requiredIu.equals(property.getAttributeValue("name"))) { + foundIU = true; + break; + } + } + if (!foundIU) { + hasAllRequirements = false; + break; + } + } + return hasAllRequirements; + } + + private static boolean iuHasTouchpointDataInstruction(Element unit, String instructionTrimmedText) { + Element touchpointDataElem = unit.getChild("touchpointData"); + + if (touchpointDataElem != null) { + for (Element instructions : touchpointDataElem.getChildren("instructions")) { + for (Element instruction : instructions.getChildren("instruction")) { + if (instructionTrimmedText.equals(instruction.getTrimmedText())) { + return true; + } + } + } + } + return false; } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/product/Util.java b/tycho-its/src/test/java/org/eclipse/tycho/test/product/Util.java deleted file mode 100644 index ef05535942..0000000000 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/product/Util.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2022 SAP AG and others. - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * SAP AG - initial API and implementation - *******************************************************************************/ -package org.eclipse.tycho.test.product; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashSet; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipException; -import java.util.zip.ZipFile; - -import de.pdark.decentxml.Document; -import de.pdark.decentxml.Element; -import de.pdark.decentxml.XMLIOSource; -import de.pdark.decentxml.XMLParser; - -/** - * @deprecated use {@link org.eclipse.tycho.test.util.P2RepositoryTool} instead - */ -@Deprecated -class Util { - public static Document openXmlFromZip(File zipFile, String xmlFile) throws IOException, ZipException { - XMLParser parser = new XMLParser(); - try (ZipFile zip = new ZipFile(zipFile)) { - ZipEntry contentXmlEntry = zip.getEntry(xmlFile); - InputStream entryStream = zip.getInputStream(contentXmlEntry); - return parser.parse(new XMLIOSource(entryStream)); - } - } - - static public boolean containsIUWithProperty(Document contentXML, String iuId, String propName, String propValue) { - Set ius = findIU(contentXML, iuId); - for (Element unitElement : ius) { - if (iuHasProperty(unitElement, propName, propValue)) - return true; - } - return false; - } - - static public Set findIU(Document contentXML, String iuId) { - Set foundIUs = new HashSet<>(); - - Element repository = contentXML.getRootElement(); - for (Element unit : repository.getChild("units").getChildren("unit")) { - if (iuId.equals(unit.getAttributeValue("id"))) { - foundIUs.add(unit); - } - } - return foundIUs; - } - - static public boolean iuHasProperty(Element unit, String propName, String propValue) { - boolean foundIU = false; - - if (propName != null) { - for (Element property : unit.getChild("properties").getChildren("property")) { - if (propName.equals(property.getAttributeValue("name")) - && propValue.equals((property.getAttributeValue("value")))) { - foundIU = true; - break; - } - } - } else { - foundIU = true; - } - return foundIU; - } - - static public boolean iuHasAllRequirements(Element unit, String... requiredIus) { - boolean hasAllRequirements = true; - for (String requiredIu : requiredIus) { - boolean foundIU = false; - for (Element property : unit.getChild("requires").getChildren("required")) { - if (requiredIu.equals(property.getAttributeValue("name"))) { - foundIU = true; - break; - } - } - if (!foundIU) { - hasAllRequirements = false; - break; - } - } - return hasAllRequirements; - } - - static public boolean iuHasTouchpointDataInstruction(Element unit, String instructionTrimmedText) { - Element touchpointDataElem = unit.getChild("touchpointData"); - - if (touchpointDataElem != null) { - for (Element instructions : touchpointDataElem.getChildren("instructions")) { - for (Element instruction : instructions.getChildren("instruction")) { - if (instructionTrimmedText.equals(instruction.getTrimmedText())) { - return true; - } - } - } - } - return false; - } -}