From c048aa23af2daeb3806bf45a6733e87addbd39d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 22 Feb 2022 13:55:54 +0100 Subject: [PATCH] Add a test-case for #658 (property propagation) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christoph Läubrich --- .../category.xml | 4 ++ .../p2Repository.propertyPropagation/pom.xml | 48 +++++++++++++ .../test.target | 10 +++ .../P2RepositoryPropertiesTest.java | 71 +++++++++++++------ 4 files changed, 110 insertions(+), 23 deletions(-) create mode 100644 tycho-its/projects/p2Repository.propertyPropagation/category.xml create mode 100644 tycho-its/projects/p2Repository.propertyPropagation/pom.xml create mode 100644 tycho-its/projects/p2Repository.propertyPropagation/test.target diff --git a/tycho-its/projects/p2Repository.propertyPropagation/category.xml b/tycho-its/projects/p2Repository.propertyPropagation/category.xml new file mode 100644 index 0000000000..16fde6f684 --- /dev/null +++ b/tycho-its/projects/p2Repository.propertyPropagation/category.xml @@ -0,0 +1,4 @@ + + + + diff --git a/tycho-its/projects/p2Repository.propertyPropagation/pom.xml b/tycho-its/projects/p2Repository.propertyPropagation/pom.xml new file mode 100644 index 0000000000..b9548fa925 --- /dev/null +++ b/tycho-its/projects/p2Repository.propertyPropagation/pom.xml @@ -0,0 +1,48 @@ + + + + 4.0.0 + + org.eclipse.tycho.its + issue-658 + 1.0.0-SNAPSHOT + eclipse-repository + + + 3.0.0-SNAPSHOT + + + + + + org.eclipse.tycho + tycho-maven-plugin + ${tycho-version} + true + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + test.target + + + + + org.eclipse.tycho + tycho-p2-repository-plugin + ${tycho-version} + + false + + + + + diff --git a/tycho-its/projects/p2Repository.propertyPropagation/test.target b/tycho-its/projects/p2Repository.propertyPropagation/test.target new file mode 100644 index 0000000000..a3c25c7860 --- /dev/null +++ b/tycho-its/projects/p2Repository.propertyPropagation/test.target @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/P2RepositoryPropertiesTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/P2RepositoryPropertiesTest.java index 3edcb108b8..cf89a2d347 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/P2RepositoryPropertiesTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/P2RepositoryPropertiesTest.java @@ -18,39 +18,64 @@ import java.io.File; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; import org.apache.maven.it.Verifier; +import org.eclipse.tycho.TychoConstants; import org.eclipse.tycho.test.AbstractTychoIntegrationTest; import org.eclipse.tycho.test.util.ResourceUtil.P2Repositories; import org.junit.Test; import de.pdark.decentxml.Document; +import de.pdark.decentxml.Element; import de.pdark.decentxml.XMLParser; public class P2RepositoryPropertiesTest extends AbstractTychoIntegrationTest { - @Test - public void testArtifactRepositoryExtraProperties() throws Exception { - Verifier verifier = getVerifier("p2Repository.reactor", false); - verifier.getSystemProperties().put("e352-repo", P2Repositories.ECLIPSE_352.toString()); - verifier.executeGoal("package"); - verifier.verifyErrorFreeLog(); - File artifactXml = new File(verifier.getBasedir(), "eclipse-repository/target/repository/artifacts.xml"); - assertTrue(artifactXml.exists()); - Map expected = new HashMap<>(3, 1.f); - expected.put("p2.statsURI", "http://some.where"); - expected.put("p2.mirrorsURL", "http://some.where.else"); - expected.put("foo", "bar"); - Document artifactsDocument = XMLParser.parse(artifactXml); - artifactsDocument.getChild("repository").getChild("properties").getChildren("property").forEach(element -> { - String propertyName = element.getAttributeValue("name"); - if (expected.containsKey(propertyName) - && expected.get(propertyName).equals(element.getAttributeValue("value"))) { - expected.remove(propertyName); - } - }); - assertEquals("Missing properties in artifact repository", Collections.emptyMap(), expected); - - } + @Test + public void testArtifactRepositoryExtraProperties() throws Exception { + Verifier verifier = getVerifier("p2Repository.reactor", false); + verifier.getSystemProperties().put("e352-repo", P2Repositories.ECLIPSE_352.toString()); + verifier.executeGoal("package"); + verifier.verifyErrorFreeLog(); + File artifactXml = new File(verifier.getBasedir(), "eclipse-repository/target/repository/artifacts.xml"); + assertTrue(artifactXml.exists()); + Map expected = new HashMap<>(3, 1.f); + expected.put("p2.statsURI", "http://some.where"); + expected.put("p2.mirrorsURL", "http://some.where.else"); + expected.put("foo", "bar"); + Document artifactsDocument = XMLParser.parse(artifactXml); + artifactsDocument.getChild("repository").getChild("properties").getChildren("property").forEach(element -> { + String propertyName = element.getAttributeValue("name"); + if (expected.containsKey(propertyName) + && expected.get(propertyName).equals(element.getAttributeValue("value"))) { + expected.remove(propertyName); + } + }); + assertEquals("Missing properties in artifact repository", Collections.emptyMap(), expected); + + } + + @Test + public void testPropertyPropagation() throws Exception { + Verifier verifier = getVerifier("p2Repository.propertyPropagation", false); + verifier.executeGoals(List.of("clean", "package")); + verifier.verifyErrorFreeLog(); + File artifactXml = new File(verifier.getBasedir(), "target/repository/artifacts.xml"); + assertTrue(artifactXml.exists()); + Document artifactsDocument = XMLParser.parse(artifactXml); + Optional optional = artifactsDocument.getChild("repository").getChild("artifacts") + .getChildren("artifact").stream() + .filter(element -> element.getAttributeValue("id").equals("org.objenesis")).findAny(); + assertTrue("artifact org.objenesis not found", optional.isPresent()); + Element element = optional.get(); + Map properties = element.getChild("properties").getChildren("property").stream() + .collect(Collectors.toMap(e -> e.getAttributeValue("name"), e -> e.getAttributeValue("value"))); + assertEquals("org.objenesis", properties.get("maven-groupId")); + assertTrue(properties.containsKey(TychoConstants.PROP_PGP_SIGNATURES) + && !properties.get(TychoConstants.PROP_PGP_SIGNATURES).isBlank()); + } }