-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix addition of unnecessary attributes in source-features and add Tests
Add tests for reduced feature attribute inference.
- Loading branch information
1 parent
284c4ed
commit bae8aa9
Showing
9 changed files
with
237 additions
and
9 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
tycho-its/projects/feature.attributes.inference/.mvn/extensions.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<extensions> | ||
<extension> | ||
<groupId>org.eclipse.tycho</groupId> | ||
<artifactId>tycho-build</artifactId> | ||
<version>${tycho-version}</version> | ||
</extension> | ||
</extensions> |
1 change: 1 addition & 0 deletions
1
tycho-its/projects/feature.attributes.inference/.mvn/maven.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-Dtycho-version=4.0.4-SNAPSHOT |
1 change: 1 addition & 0 deletions
1
tycho-its/projects/feature.attributes.inference/feature/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bin.includes = feature.xml |
23 changes: 23 additions & 0 deletions
23
tycho-its/projects/feature.attributes.inference/feature/feature.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<feature | ||
id="feature.attributes.inference.test" | ||
version="1.0.0"> | ||
|
||
<plugin | ||
id="junit-jupiter-api" | ||
version="0.0.0"/> | ||
|
||
<plugin | ||
id="junit-platform-suite-api" | ||
download-size="0" | ||
install-size="0" | ||
version="0.0.0" | ||
unpack="false"/> | ||
|
||
<plugin | ||
id="org.apiguardian.api" | ||
download-size="0" | ||
install-size="0" | ||
version="0.0.0"/> | ||
|
||
</feature> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.eclipse.tycho.it</groupId> | ||
<artifactId>feature-attributes-inference</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>pom</packaging> | ||
<properties> | ||
<tycho-version>4.0.4-SNAPSHOT</tycho-version> | ||
<target-platform>http://download.eclipse.org/releases/latest/</target-platform> | ||
</properties> | ||
|
||
<modules> | ||
<module>feature</module> | ||
</modules> | ||
<repositories> | ||
<repository> | ||
<id>platform</id> | ||
<url>${target-platform}</url> | ||
<layout>p2</layout> | ||
</repository> | ||
</repositories> | ||
|
||
<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>tycho-source-plugin</artifactId> | ||
<version>${tycho-version}</version> | ||
<executions> | ||
<execution> | ||
<id>feature-source</id> | ||
<goals> | ||
<goal>feature-source</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.eclipse.tycho</groupId> | ||
<artifactId>tycho-p2-plugin</artifactId> | ||
<version>${tycho-version}</version> | ||
<executions> | ||
<execution> | ||
<id>attach-p2-metadata</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>p2-metadata</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
125 changes: 125 additions & 0 deletions
125
tycho-its/src/test/java/org/eclipse/tycho/test/feature/FeatureAttributesInferenceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023, 2023 Hannes Wellmann 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: | ||
* Hannes Wellmann - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.test.feature; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.anyOf; | ||
import static org.hamcrest.Matchers.blankOrNullString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
import org.apache.maven.it.Verifier; | ||
import org.eclipse.tycho.test.AbstractTychoIntegrationTest; | ||
import org.eclipse.tycho.test.util.XMLTool; | ||
import org.hamcrest.Matcher; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.w3c.dom.Attr; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.NamedNodeMap; | ||
|
||
public class FeatureAttributesInferenceTest extends AbstractTychoIntegrationTest { | ||
|
||
@Test | ||
public void testFeatureAttributesInference() throws Exception { | ||
Verifier verifier = getVerifier("feature.attributes.inference", true, true); | ||
verifier.executeGoals(List.of("clean", "package")); | ||
verifier.verifyErrorFreeLog(); | ||
File featureTargetDir = new File(verifier.getBasedir(), "feature/target"); | ||
File featureJar = assertFileExists(featureTargetDir, "feature.attributes.inference.test-1.0.0.jar")[0]; | ||
File featureSourceJar = assertFileExists(featureTargetDir, | ||
"feature.attributes.inference.test-1.0.0-sources-feature.jar")[0]; | ||
|
||
List<Element> pluginNodes = getPluginElements(featureJar); | ||
Assert.assertEquals(3, pluginNodes.size()); | ||
|
||
// Check the feature.xml in the feature-jar | ||
assertAttributesOnlyElementWith(Map.of(// | ||
"id", equalTo("junit-jupiter-api"), // | ||
"version", isSpecificVersion() // | ||
), pluginNodes.get(0)); | ||
|
||
assertAttributesOnlyElementWith(Map.of(// | ||
"id", equalTo("junit-platform-suite-api"), // | ||
"version", isSpecificVersion(), // | ||
"download-size", isInferredSize(), // | ||
"install-size", isInferredSize(), // | ||
"unpack", equalTo("false") // | ||
), pluginNodes.get(1)); | ||
|
||
assertAttributesOnlyElementWith(Map.of(// | ||
"id", equalTo("org.apiguardian.api"), // | ||
"version", isSpecificVersion(), // | ||
"download-size", isInferredSize(), // | ||
"install-size", isInferredSize() // | ||
), pluginNodes.get(2)); | ||
|
||
// Check the feature.xml in the source-feature-jar | ||
List<Element> pluginSourceNodes = getPluginElements(featureSourceJar); | ||
Assert.assertEquals(3, pluginSourceNodes.size()); | ||
|
||
assertAttributesOnlyElementWith(Map.of(// | ||
"id", equalTo("junit-jupiter-api.source"), // | ||
"version", isSpecificVersion() // | ||
), pluginSourceNodes.get(0)); | ||
|
||
assertAttributesOnlyElementWith(Map.of(// | ||
"id", equalTo("junit-platform-suite-api.source"), // | ||
"version", isSpecificVersion(), // | ||
"download-size", equalTo("0"), // | ||
"install-size", equalTo("0"), // | ||
"unpack", equalTo("false") // | ||
), pluginSourceNodes.get(1)); | ||
|
||
assertAttributesOnlyElementWith(Map.of(// | ||
"id", equalTo("org.apiguardian.api.source"), // | ||
"version", isSpecificVersion(), // | ||
"download-size", equalTo("0"), // | ||
"install-size", equalTo("0"), // | ||
"unpack", equalTo("false") // | ||
), pluginSourceNodes.get(2)); | ||
} | ||
|
||
private List<Element> getPluginElements(File featureJar) throws Exception { | ||
Document document = XMLTool.parseXMLDocumentFromJar(featureJar, "feature.xml"); | ||
return XMLTool.getMatchingNodes(document, "/feature/plugin").stream().filter(Element.class::isInstance) | ||
.map(Element.class::cast).toList(); | ||
} | ||
|
||
private Matcher<String> isInferredSize() { | ||
return not(anyOf(blankOrNullString(), equalTo("0"))); | ||
} | ||
|
||
private static Matcher<String> isSpecificVersion() { | ||
return not(anyOf(blankOrNullString(), equalTo("0.0.0"))); | ||
} | ||
|
||
private void assertAttributesOnlyElementWith(Map<String, Matcher<String>> expectedAttributes, Element element) { | ||
assertEquals(0, element.getChildNodes().getLength()); | ||
NamedNodeMap attributes = element.getAttributes(); | ||
Map<String, String> elementAttributes = IntStream.range(0, attributes.getLength()).mapToObj(attributes::item) | ||
.map(Attr.class::cast).collect(Collectors.toMap(Attr::getName, Attr::getValue)); | ||
|
||
expectedAttributes.forEach((name, expectation) -> assertThat(elementAttributes.get(name), expectation)); | ||
assertEquals(expectedAttributes.size(), elementAttributes.size()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
tycho-surefire/org.eclipse.tycho.bnd.executionlistener/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore | ||
org.eclipse.jdt.core.compiler.release=disabled | ||
org.eclipse.jdt.core.compiler.source=1.8 |