Skip to content

Commit

Permalink
Add a test-case for #658 (property propagation)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi committed Feb 22, 2022
1 parent abe9f2a commit 2a62c5b
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<site>
<bundle id="org.objenesis" version="0.0.0"/>
</site>
48 changes: 48 additions & 0 deletions tycho-its/projects/p2Repository.propertyPropagation/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2022 Mat Booth. 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 -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.eclipse.tycho.its</groupId>
<artifactId>issue-658</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-repository</packaging>

<properties>
<tycho-version>3.0.0-SNAPSHOT</tycho-version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<target>
<file>test.target</file>
</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<compress>false</compress>
</configuration>
</plugin>
</plugins>
</build>
</project>
10 changes: 10 additions & 0 deletions tycho-its/projects/p2Repository.propertyPropagation/test.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target includeMode="feature" name="target-platform">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="slicer" includeSource="false" type="InstallableUnit">
<repository location="https://download.eclipse.org/eclipse/updates/4.23-I-builds/"/>
<unit id="org.objenesis" version="0.0.0"/>
</location>
</locations>
</target>
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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<String, String> 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<Element> 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<String, String> 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());
}
}

0 comments on commit 2a62c5b

Please sign in to comment.