|
12 | 12 | *******************************************************************************/
|
13 | 13 | package org.eclipse.tycho.test;
|
14 | 14 |
|
| 15 | +import static org.junit.Assert.assertFalse; |
| 16 | +import static org.junit.Assert.assertTrue; |
| 17 | + |
15 | 18 | import java.io.File;
|
| 19 | +import java.io.IOException; |
| 20 | +import java.nio.file.Path; |
16 | 21 | import java.util.ArrayList;
|
17 | 22 | import java.util.List;
|
| 23 | +import java.util.Optional; |
18 | 24 |
|
19 | 25 | import org.apache.maven.it.VerificationException;
|
20 | 26 | import org.apache.maven.it.Verifier;
|
21 | 27 | import org.junit.Test;
|
22 | 28 |
|
| 29 | +import de.pdark.decentxml.Document; |
| 30 | +import de.pdark.decentxml.Element; |
| 31 | +import de.pdark.decentxml.XMLIOSource; |
| 32 | +import de.pdark.decentxml.XMLParser; |
| 33 | + |
23 | 34 | public class P2ExtrasPlugin extends AbstractTychoIntegrationTest {
|
24 | 35 |
|
25 | 36 | @Test
|
@@ -129,4 +140,38 @@ private void execute(Verifier verifier, boolean success, String project, String
|
129 | 140 | }
|
130 | 141 | }
|
131 | 142 |
|
| 143 | + @Test |
| 144 | + public void testPublishFeaturesAndBundles_noUnpack() throws Exception { |
| 145 | + final String pluginId = "test_plugin"; |
| 146 | + final String featureId = "test_feature.feature.jar"; |
| 147 | + |
| 148 | + Verifier verifier = getVerifier("p2extra/publisherNoUnpack", false, true); |
| 149 | + verifier.executeGoals(List.of("clean", "package")); |
| 150 | + |
| 151 | + Path contentXml = Path.of(verifier.getBasedir()).resolve("target/repository").resolve("content.xml"); |
| 152 | + Element pluginUnitInContentXml = extractUnitFromContentXml(contentXml, pluginId); |
| 153 | + assertFalse("test plugin should not be marked as zipped", hasChildWithZippedAttribute(pluginUnitInContentXml)); |
| 154 | + Element featureUnitInContentXml = extractUnitFromContentXml(contentXml, featureId); |
| 155 | + assertTrue("test feature should be marked as zipped", hasChildWithZippedAttribute(featureUnitInContentXml)); |
| 156 | + } |
| 157 | + |
| 158 | + private static Element extractUnitFromContentXml(Path contentXml, String unitName) throws IOException { |
| 159 | + XMLParser parser = new XMLParser(); |
| 160 | + Document document = parser.parse(new XMLIOSource(contentXml.toFile())); |
| 161 | + Element unitElement = document.getChild("repository/units"); |
| 162 | + List<Element> units = unitElement.getChildren("unit"); |
| 163 | + Optional<Element> extractedUnit = units.stream() |
| 164 | + .filter(element -> unitName.equals(element.getAttribute("id").getValue())).findFirst(); |
| 165 | + assertTrue(String.format("Unit with name '%s' not found in content.xml with units: %s", unitName, units), |
| 166 | + extractedUnit.isPresent()); |
| 167 | + return extractedUnit.get(); |
| 168 | + } |
| 169 | + |
| 170 | + private static boolean hasChildWithZippedAttribute(Element element) { |
| 171 | + if ("zipped".equals(element.getAttributeValue("key"))) { |
| 172 | + return true; |
| 173 | + } |
| 174 | + return element.getChildren().stream().anyMatch(P2ExtrasPlugin::hasChildWithZippedAttribute); |
| 175 | + } |
| 176 | + |
132 | 177 | }
|
0 commit comments