This is an automated email from the ASF dual-hosted git repository.
davidb pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new c5204a4 SLING-9136 Remove ApiRegionsOverlapCheckMojo and associated
tests
c5204a4 is described below
commit c5204a4742dc305175c935f985cb545ab22cfa76
Author: David Bosschaert <[email protected]>
AuthorDate: Mon Mar 2 10:23:12 2020 +0000
SLING-9136 Remove ApiRegionsOverlapCheckMojo and associated tests
This functionality is moving to a more appropriate place: the API
Regions extension.
---
README.md | 52 ---
.../maven/mojos/ApiRegionsOverlapCheckMojo.java | 297 ----------------
.../mojos/ApiRegionsOverlapCheckMojoTest.java | 383 ---------------------
.../testNoOverlap/test_a.json | 11 -
.../testNoOverlap/test_b.json | 11 -
.../testNoOverlap2/test_a.json | 11 -
.../testNoOverlap2/test_b.json | 11 -
.../testNoOverlap3/test_a.json | 17 -
.../testNoOverlap3/test_b.json | 7 -
.../testNotEnoughFeatureModels/test_a.json | 11 -
.../testOverlap/test_a.json | 11 -
.../testOverlap/test_b.json | 11 -
.../testOverlap2/test_a.json | 11 -
.../testOverlap2/test_b.json | 7 -
.../testOverlap3/test_a.json | 11 -
.../testOverlap3/test_b.json | 11 -
src/test/resources/bundles/feature-export.jar | Bin 431 -> 0 bytes
src/test/resources/bundles/feature-export2.jar | Bin 418 -> 0 bytes
src/test/resources/bundles/no-exports.jar | Bin 387 -> 0 bytes
19 files changed, 873 deletions(-)
diff --git a/README.md b/README.md
index 95d95e1..135109d 100644
--- a/README.md
+++ b/README.md
@@ -268,58 +268,6 @@
https://github.com/apache/sling-org-apache-sling-feature-analyser/blob/master/sr
</execution>
```
-## api-regions-crossfeature-duplicates
-This mojo compares multiple feature models and checks if there is overlap
between exported packages from
-these feature models. It will fail the Maven execution if there is.
-
-It can be used to detect if a feature model provides packages that are already
provided as part of
-some platform and report an error if there is such a case.
-
-It does this by looking at the exports of the api-regions extension in the
feature model and collecting
-the packages listed there. If a feature model does not opt-in to the
api-regions extension, all bundles
-listed as part of that feature are examined for exported packages and these
are added to the global
-region.
-
-If multiple features export the same package in any listed API region then the
mojo will cause the build
-to fail.
-
-Example configuration:
-
-```
-<execution>
- <id>check-overlapping-exports</id>
- <goals><goal>api-regions-crossfeature-duplicates</goal></goals>
- <configuration>
- <selection>
- <!-- Standard feature selection mechanism, as used by other Mojo
-->
- <filesInclude>*.json</filesInclude>
- <includeArtifact>
- <groupId>org.apache.sling</groupId>
- <artifactId>my-feature</artifactId>
- <type>slingosgifeature</type>
- <classifier>some-classifier</classifier>
- <version>1.2.3</version>
- </includeArtifact>
- <includeClassifier>my-aggregate</includeClassifier>
- </selection>
- <regions>
- <region>global</region>
- <region>some.other.region</region>
- </regions>
- <packages>
- <!-- ignore overlaps of the com.foo.bar package -->
- <ignore>com.foo.bar</ignore>
-
- <!-- if multiple feature models export javax.servlet or a
subpackage, produce a warning -->
- <warning>javax.servlet</warning>
- <warning>javax.servlet.*</warning>
-
- <!-- if multiple feature models export any other package, it will
fail the build -->
- </packages>
- </configuration>
-</execution>
-```
-
## attach-features
Attach feature files found in the project to the projects produced artifacts.
This includes features
found in `src/main/features` as well as features produce with the
`aggregate-features` goal if no configuration is specified.
diff --git
a/src/main/java/org/apache/sling/feature/maven/mojos/ApiRegionsOverlapCheckMojo.java
b/src/main/java/org/apache/sling/feature/maven/mojos/ApiRegionsOverlapCheckMojo.java
deleted file mode 100644
index a0b2f49..0000000
---
a/src/main/java/org/apache/sling/feature/maven/mojos/ApiRegionsOverlapCheckMojo.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
under
- * the License.
- */
-package org.apache.sling.feature.maven.mojos;
-
-import org.apache.felix.utils.manifest.Clause;
-import org.apache.felix.utils.manifest.Parser;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.sling.feature.Artifact;
-import org.apache.sling.feature.ArtifactId;
-import org.apache.sling.feature.Extension;
-import org.apache.sling.feature.Extensions;
-import org.apache.sling.feature.Feature;
-import org.apache.sling.feature.extension.apiregions.api.ApiExport;
-import org.apache.sling.feature.extension.apiregions.api.ApiRegion;
-import org.apache.sling.feature.extension.apiregions.api.ApiRegions;
-import org.apache.sling.feature.maven.ProjectHelper;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-import java.util.stream.Collectors;
-
-import javax.json.JsonArray;
-
-
-/**
- * This mojo compares multiple feature models and checks if there is overlap
between exported packages from
- * these feature models. It will fail the Maven execution if there is. <p>
- *
- * It can be used to detect if a feature model provides packages that are
already provided as part of
- * some platform and report an error if there is such a case. <p>
- *
- * It does this by looking at the exports of the api-regions extension in the
feature model and collecting
- * the packages listed there. If a feature model does not opt-in to the
api-regions extension, all bundles
- * listed as part of that feature are examined for exported packages and these
are added to the global
- * region. <p>
- *
- * If multiple features export the same package in any listed API region then
the mojo will cause the build
- * to fail.
- */
-@Mojo(name = "api-regions-crossfeature-duplicates",
- defaultPhase = LifecyclePhase.PROCESS_RESOURCES)
-public class ApiRegionsOverlapCheckMojo extends AbstractIncludingFeatureMojo {
- private static final String GLOBAL_REGION = "global";
-
- @Parameter
- FeatureSelectionConfig selection;
-
- /**
- * The regions to check for overlapping exports
- */
- @Parameter
- Set<String> regions;
-
- /**
- * Special package instructions
- */
- @Parameter
- NoErrorPackageConfig packages;
-
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
- if (regions == null || regions.isEmpty()) {
- throw new MojoExecutionException("Please specify at least one
region to check for duplicate exports");
- }
-
- Map<FeatureIDRegion, Set<String>> featureExports = new HashMap<>();
- Map<String, Feature> fs = getSelectedFeatures(selection);
-
- if (fs.size() < 2) {
- getLog().warn("Comparing feature models for overlapping exports is
only useful for 2 ore more features. "
- + "Number of feature models selected: " + fs.size());
- }
-
- for (Map.Entry<String, Feature> f : fs.entrySet()) {
- Feature feature = f.getValue();
- ApiRegions fRegions = getApiRegions(feature);
- if (fRegions != null) {
- // there are API regions defined
-
- for(ApiRegion r : fRegions.listRegions()) {
- if (!regions.contains(r.getName())) {
- continue;
- }
-
- Set<String> el = new HashSet<>();
- for (ApiExport ex : r.listExports()) {
- el.add(ex.getName());
- }
- featureExports.put(new FeatureIDRegion(f.getKey(),
r.getName()), el);
- }
- } else {
- // no API regions defined, get the exports from all the
bundles and record them for the global region
- Set<String> exports = new HashSet<>();
- for (Artifact bundle : feature.getBundles()) {
- ArtifactId bid = bundle.getId();
- org.apache.maven.artifact.Artifact art =
ProjectHelper.getOrResolveArtifact(
- project, mavenSession, artifactHandlerManager,
artifactResolver, bid);
- File bundleJar = art.getFile();
- try (JarFile jf = new JarFile(bundleJar)) {
- Manifest mf = jf.getManifest();
- if (mf != null) {
- String epHeader =
mf.getMainAttributes().getValue("Export-Package");
- if (epHeader != null) {
- Clause[] clauses =
Parser.parseHeader(epHeader);
- for (Clause c : clauses) {
- exports.add(c.getName());
- }
- }
- }
- } catch (IOException e) {
- throw new MojoExecutionException(e.getMessage(), e);
- }
- }
- featureExports.put(new FeatureIDRegion(f.getKey(),
GLOBAL_REGION), exports);
- }
- }
-
- if (featureExports.size() < 2) {
- // Not 2 or more features, so no overlap to check
- return;
- }
-
- boolean overlapFound = false;
- List<FeatureIDRegion> keyList = new
ArrayList<>(featureExports.keySet());
- for (int i=0; i<keyList.size(); i++) {
- FeatureIDRegion key1 = keyList.get(i);
- for (int j=i+1; j<keyList.size(); j++) {
- FeatureIDRegion key2 = keyList.get(j);
- Set<String> exp1 = featureExports.get(key1);
- Set<String> exp2 = featureExports.get(key2);
- overlapFound |= checkOverlap(key1, exp1, key2, exp2);
- }
- }
-
- if (overlapFound) {
- throw new MojoExecutionException("Errors found, see log");
- }
- }
-
- private boolean checkOverlap(FeatureIDRegion key1, Set<String> exp1,
FeatureIDRegion key2, Set<String> exp2) {
- String msgPrefix = "Overlap found between " + key1 + " and " + key2 +
". Both export: ";
-
- if (key1.equals(key2)) {
- // Don't compare a region with itself
- return false;
- }
-
- Set<String> s = new HashSet<>(exp1);
-
- s.retainAll(exp2);
-
- if (packages != null) {
- // Remove all ignored packages
- s = removeAllMatching(packages.ignored, s);
-
- if (!packages.warnings.isEmpty()) {
- Set<String> ws = new HashSet<>(s);
- ws = retainAllMatching(packages.warnings, ws);
- s = removeAllMatching(packages.warnings, s);
-
- if (!ws.isEmpty()) {
- getLog().warn(msgPrefix + ws);
- }
- }
- }
-
- if (s.isEmpty()) {
- // no overlap
- return false;
- }
-
-
- getLog().error(msgPrefix + s);
- return true;
- }
-
- private Set<String> removeAllMatching(Set<String> toRemove, Set<String>
set) {
- return processAllMatching(toRemove, set, true);
- }
-
- private Set<String> retainAllMatching(Set<String> toRetain, Set<String>
set) {
- return processAllMatching(toRetain, set, false);
- }
-
- private Set<String> processAllMatching(Set<String> toConsider, Set<String>
set, boolean remove) {
- for (String e : toConsider) {
- String element = e.trim();
- if (e.endsWith("*")) {
- String prefix = element.substring(0, e.length() - 1);
- // Reverse the 'x.startsWith()' based on the value of remove
- set = set.stream().filter(
- x -> x.startsWith(prefix) ^
remove).collect(Collectors.toSet());
- } else {
- set = set.stream().filter(
- x -> x.equals(element) ^
remove).collect(Collectors.toSet());
- }
- }
- return set;
- }
-
- /**
- * Get the api regions for a feature.
- *
- * @param feature The feature
- * @return The api regions or {@code null} if the feature is not using API
Regions
- * @throws MojoExecutionException If an error occurs
- */
- private ApiRegions getApiRegions(final Feature feature) throws
MojoExecutionException {
- Extensions extensions = feature.getExtensions();
- Extension apiRegionsExtension =
extensions.getByName(ApiRegions.EXTENSION_NAME);
- if (apiRegionsExtension != null) {
- ApiRegions regions = new ApiRegions();
- if (apiRegionsExtension.getJSONStructure() != null) {
- try {
- regions = ApiRegions.parse((JsonArray)
apiRegionsExtension.getJSONStructure());
- } catch (final IOException ioe) {
- throw new MojoExecutionException(ioe.getMessage(), ioe);
- }
- }
- return regions;
- } else {
- return null;
- }
- }
-
- private static class FeatureIDRegion {
- private final String featureID;
- private final String region;
-
- private FeatureIDRegion(String featureID, String region) {
- this.featureID = featureID;
- this.region = region;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(featureID, region);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- FeatureIDRegion other = (FeatureIDRegion) obj;
- return Objects.equals(featureID, other.featureID) &&
Objects.equals(region, other.region);
- }
-
- @Override
- public String toString() {
- return "Feature: " + featureID + ", Region: " + region;
- }
- }
-
- public static class NoErrorPackageConfig {
- Set<String> ignored = new HashSet<>();
- Set<String> warnings = new HashSet<>();
-
- public void setIgnore(String pkg) {
- ignored.add(pkg);
- }
-
- public void setWarning(String pkg) {
- warnings.add(pkg);
- }
- }
-}
diff --git
a/src/test/java/org/apache/sling/feature/maven/mojos/ApiRegionsOverlapCheckMojoTest.java
b/src/test/java/org/apache/sling/feature/maven/mojos/ApiRegionsOverlapCheckMojoTest.java
deleted file mode 100644
index 33713b2..0000000
---
a/src/test/java/org/apache/sling/feature/maven/mojos/ApiRegionsOverlapCheckMojoTest.java
+++ /dev/null
@@ -1,383 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sling.feature.maven.mojos;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
-import org.apache.sling.feature.Feature;
-import org.apache.sling.feature.io.json.FeatureJSONReader;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import java.io.File;
-import java.io.FileReader;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-public class ApiRegionsOverlapCheckMojoTest {
- @Test
- public void testMustSpecifyRegion() throws Exception {
- ApiRegionsOverlapCheckMojo mojo = new ApiRegionsOverlapCheckMojo();
- mojo.selection = new FeatureSelectionConfig();
-
- try {
- mojo.execute();
- fail("Expected MojoExecutionException");
- } catch (MojoExecutionException mee) {
- assertTrue(mee.getMessage().contains("Please specify at least one
region to check for"));
- }
-
- mojo.regions = Collections.emptySet();
- try {
- mojo.execute();
- fail("Expected MojoExecutionException");
- } catch (MojoExecutionException mee) {
- assertTrue(mee.getMessage().contains("Please specify at least one
region to check for"));
- }
- }
-
- @Test
- public void testOverlap() throws Exception {
- ApiRegionsOverlapCheckMojo mojo = new ApiRegionsOverlapCheckMojo();
-
- mojo.features = new
File(getClass().getResource("/api-regions-crossfeature-duplicates/testOverlap").getFile());
- Map<String, Feature> featureMap = new HashMap<>();
- for (File f : mojo.features.listFiles()) {
- Feature feat = FeatureJSONReader.read(new FileReader(f), null);
- featureMap.put(f.getAbsolutePath(), feat);
- }
-
- mojo.project = Mockito.mock(MavenProject.class);
- Mockito.when(mojo.project.getContextValue(Feature.class.getName() +
"/assembledmain.json-cache"))
- .thenReturn(featureMap);
-
- mojo.regions = Collections.singleton("foo");
- mojo.packages = new ApiRegionsOverlapCheckMojo.NoErrorPackageConfig();
- mojo.packages.ignored = Collections.emptySet();
- mojo.packages.warnings = Collections.emptySet();
- FeatureSelectionConfig cfg = new FeatureSelectionConfig();
- cfg.setFilesInclude("*.json");
- mojo.selection = cfg;
-
- try {
- mojo.execute();
- fail("Expect to fail here as there is overlap");
- } catch (MojoExecutionException mee) {
- assertTrue(mee.getMessage().contains("Errors found"));
- }
- }
-
- @SuppressWarnings({ "unchecked", "deprecation" })
- @Test
- public void testOverlap2() throws Exception {
- ApiRegionsOverlapCheckMojo mojo = new ApiRegionsOverlapCheckMojo();
-
- mojo.features = new
File(getClass().getResource("/api-regions-crossfeature-duplicates/testOverlap2").getFile());
- Map<String, Feature> featureMap = new HashMap<>();
- for (File f : mojo.features.listFiles()) {
- Feature feat = FeatureJSONReader.read(new FileReader(f), null);
- featureMap.put(f.getAbsolutePath(), feat);
- }
-
- ArtifactHandler artifactHandler = Mockito.mock(ArtifactHandler.class);
-
- mojo.mavenSession = Mockito.mock(MavenSession.class);
- mojo.artifactHandlerManager =
Mockito.mock(ArtifactHandlerManager.class);
- Mockito.when(mojo.artifactHandlerManager.getArtifactHandler("jar"))
- .thenReturn(artifactHandler);
- mojo.artifactResolver = Mockito.mock(ArtifactResolver.class);
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(InvocationOnMock invocation) throws Throwable {
- Artifact art = invocation.getArgumentAt(0, Artifact.class);
-
- if ("feature-exports".equals(art.getArtifactId())) {
- art.setFile(new File(getClass().
-
getResource("/bundles/feature-export.jar").getFile()));
- }
- if ("feature-exports2".equals(art.getArtifactId())) {
- art.setFile(new File(getClass().
-
getResource("/bundles/feature-export2.jar").getFile()));
- }
- return null;
- }
-
- }).when(mojo.artifactResolver).resolve(Mockito.isA(Artifact.class),
- Mockito.any(List.class),
Mockito.any(ArtifactRepository.class));
- mojo.project = Mockito.mock(MavenProject.class);
- Mockito.when(mojo.project.getContextValue(Feature.class.getName() +
"/assembledmain.json-cache"))
- .thenReturn(featureMap);
-
- mojo.regions = Collections.singleton("global");
- FeatureSelectionConfig cfg = new FeatureSelectionConfig();
- cfg.setFilesInclude("*.json");
- mojo.selection = cfg;
-
- try {
- mojo.execute();
- fail("Expect to fail here as there is overlap");
- } catch (MojoExecutionException mee) {
- assertTrue(mee.getMessage().contains("Errors found"));
- }
- }
-
- @Test
- public void testOverlap3() throws Exception {
- ApiRegionsOverlapCheckMojo mojo = new ApiRegionsOverlapCheckMojo();
-
- mojo.features = new
File(getClass().getResource("/api-regions-crossfeature-duplicates/testOverlap3").getFile());
- Map<String, Feature> featureMap = new HashMap<>();
- for (File f : mojo.features.listFiles()) {
- Feature feat = FeatureJSONReader.read(new FileReader(f), null);
- featureMap.put(f.getAbsolutePath(), feat);
- }
-
- mojo.project = Mockito.mock(MavenProject.class);
- Mockito.when(mojo.project.getContextValue(Feature.class.getName() +
"/assembledmain.json-cache"))
- .thenReturn(featureMap);
-
- mojo.regions = new HashSet<>(Arrays.asList("bar", "foo"));
- mojo.packages = new ApiRegionsOverlapCheckMojo.NoErrorPackageConfig();
- mojo.packages.ignored = Collections.emptySet();
- mojo.packages.warnings = Collections.emptySet();
- FeatureSelectionConfig cfg = new FeatureSelectionConfig();
- cfg.setFilesInclude("*.json");
- mojo.selection = cfg;
-
- try {
- mojo.execute();
- fail("Expect to fail here as there is overlap");
- } catch (MojoExecutionException mee) {
- assertTrue(mee.getMessage().contains("Errors found"));
- }
- }
-
- @Test
- public void testNotEnoughFeatureModels() throws Exception {
- ApiRegionsOverlapCheckMojo mojo = new ApiRegionsOverlapCheckMojo();
-
- mojo.features = new
File(getClass().getResource("/api-regions-crossfeature-duplicates/testNotEnoughFeatureModels").getFile());
- Map<String, Feature> featureMap = new HashMap<>();
- for (File f : mojo.features.listFiles()) {
- Feature feat = FeatureJSONReader.read(new FileReader(f), null);
- featureMap.put(f.getAbsolutePath(), feat);
- }
-
- mojo.project = Mockito.mock(MavenProject.class);
- Mockito.when(mojo.project.getContextValue(Feature.class.getName() +
"/assembledmain.json-cache"))
- .thenReturn(featureMap);
-
- mojo.regions = Collections.singleton("foo");
- FeatureSelectionConfig cfg = new FeatureSelectionConfig();
- cfg.setFilesInclude("*.json");
- mojo.selection = cfg;
-
- // There is only one feature model, so this should not fail (but
produce a warning)
- mojo.execute();
- }
-
- @Test
- public void testNoOverlap() throws Exception {
- ApiRegionsOverlapCheckMojo mojo = new ApiRegionsOverlapCheckMojo();
-
- mojo.features = new
File(getClass().getResource("/api-regions-crossfeature-duplicates/testNoOverlap").getFile());
- Map<String, Feature> featureMap = new HashMap<>();
- for (File f : mojo.features.listFiles()) {
- Feature feat = FeatureJSONReader.read(new FileReader(f), null);
- featureMap.put(f.getAbsolutePath(), feat);
- }
-
- mojo.project = Mockito.mock(MavenProject.class);
- Mockito.when(mojo.project.getContextValue(Feature.class.getName() +
"/assembledmain.json-cache"))
- .thenReturn(featureMap);
-
- mojo.regions = Collections.singleton("foo");
- FeatureSelectionConfig cfg = new FeatureSelectionConfig();
- cfg.setFilesInclude("*.json");
- mojo.selection = cfg;
-
- // Should not cause an exception as there is no overlap
- mojo.execute();
- }
-
- @Test
- public void testNoOverlap2() throws Exception {
- ApiRegionsOverlapCheckMojo mojo = new ApiRegionsOverlapCheckMojo();
-
- mojo.features = new
File(getClass().getResource("/api-regions-crossfeature-duplicates/testNoOverlap2").getFile());
- Map<String, Feature> featureMap = new HashMap<>();
- for (File f : mojo.features.listFiles()) {
- Feature feat = FeatureJSONReader.read(new FileReader(f), null);
- featureMap.put(f.getAbsolutePath(), feat);
- }
-
- mojo.project = Mockito.mock(MavenProject.class);
- Mockito.when(mojo.project.getContextValue(Feature.class.getName() +
"/assembledmain.json-cache"))
- .thenReturn(featureMap);
-
- mojo.regions = Collections.singleton("foo");
- FeatureSelectionConfig cfg = new FeatureSelectionConfig();
- cfg.setFilesInclude("*.json");
- mojo.selection = cfg;
-
- // Should not cause an exception as there is no overlap
- mojo.execute();
- }
-
- @SuppressWarnings({ "unchecked", "deprecation" })
- @Test
- public void testNoOverlap3() throws Exception {
- ApiRegionsOverlapCheckMojo mojo = new ApiRegionsOverlapCheckMojo();
-
- mojo.features = new
File(getClass().getResource("/api-regions-crossfeature-duplicates/testNoOverlap3").getFile());
- Map<String, Feature> featureMap = new HashMap<>();
- for (File f : mojo.features.listFiles()) {
- Feature feat = FeatureJSONReader.read(new FileReader(f), null);
- featureMap.put(f.getAbsolutePath(), feat);
- }
-
- ArtifactHandler artifactHandler = Mockito.mock(ArtifactHandler.class);
-
- mojo.mavenSession = Mockito.mock(MavenSession.class);
- mojo.artifactHandlerManager =
Mockito.mock(ArtifactHandlerManager.class);
- Mockito.when(mojo.artifactHandlerManager.getArtifactHandler("jar"))
- .thenReturn(artifactHandler);
- mojo.artifactResolver = Mockito.mock(ArtifactResolver.class);
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(InvocationOnMock invocation) throws Throwable {
- Artifact art = invocation.getArgumentAt(0, Artifact.class);
-
- if ("feature-exports".equals(art.getArtifactId())) {
- art.setFile(new File(getClass().
-
getResource("/bundles/feature-export.jar").getFile()));
- }
- if ("no-exports".equals(art.getArtifactId())) {
- art.setFile(new File(getClass().
- getResource("/bundles/no-exports.jar").getFile()));
- }
- return null;
- }
-
- }).when(mojo.artifactResolver).resolve(Mockito.isA(Artifact.class),
- Mockito.any(List.class),
Mockito.any(ArtifactRepository.class));
- mojo.project = Mockito.mock(MavenProject.class);
- Mockito.when(mojo.project.getContextValue(Feature.class.getName() +
"/assembledmain.json-cache"))
- .thenReturn(featureMap);
-
- mojo.regions = new HashSet<>(Arrays.asList("global", "other"));
- FeatureSelectionConfig cfg = new FeatureSelectionConfig();
- cfg.setFilesInclude("*.json");
- mojo.selection = cfg;
-
- // Should not cause an exception as there is no overlap
- mojo.execute();
- }
-
- @Test
- public void testOverlapIgnore() throws Exception {
- ApiRegionsOverlapCheckMojo mojo = new ApiRegionsOverlapCheckMojo();
-
- mojo.features = new
File(getClass().getResource("/api-regions-crossfeature-duplicates/testOverlap").getFile());
- Map<String, Feature> featureMap = new HashMap<>();
- for (File f : mojo.features.listFiles()) {
- Feature feat = FeatureJSONReader.read(new FileReader(f), null);
- featureMap.put(f.getAbsolutePath(), feat);
- }
-
- mojo.project = Mockito.mock(MavenProject.class);
- Mockito.when(mojo.project.getContextValue(Feature.class.getName() +
"/assembledmain.json-cache"))
- .thenReturn(featureMap);
-
- mojo.regions = Collections.singleton("foo");
- mojo.packages = new ApiRegionsOverlapCheckMojo.NoErrorPackageConfig();
- mojo.packages.ignored = Collections.singleton("ding.dong");
- FeatureSelectionConfig cfg = new FeatureSelectionConfig();
- cfg.setFilesInclude("*.json");
- mojo.selection = cfg;
-
- // There is overlap with the ding.dong package, but it's configured as
'ignore', so the build should not fail
- mojo.execute();
- }
-
- @Test
- public void testOverlapWarning() throws Exception {
- ApiRegionsOverlapCheckMojo mojo = new ApiRegionsOverlapCheckMojo();
-
- mojo.features = new
File(getClass().getResource("/api-regions-crossfeature-duplicates/testOverlap").getFile());
- Map<String, Feature> featureMap = new HashMap<>();
- for (File f : mojo.features.listFiles()) {
- Feature feat = FeatureJSONReader.read(new FileReader(f), null);
- featureMap.put(f.getAbsolutePath(), feat);
- }
-
- mojo.project = Mockito.mock(MavenProject.class);
- Mockito.when(mojo.project.getContextValue(Feature.class.getName() +
"/assembledmain.json-cache"))
- .thenReturn(featureMap);
-
- mojo.regions = Collections.singleton("foo");
- mojo.packages = new ApiRegionsOverlapCheckMojo.NoErrorPackageConfig();
- mojo.packages.warnings = Collections.singleton("ding.dong");
- FeatureSelectionConfig cfg = new FeatureSelectionConfig();
- cfg.setFilesInclude("*.json");
- mojo.selection = cfg;
-
- // There is overlap with the ding.dong package, but it's configured as
'ignore', so the build should not fail
- mojo.execute();
- }
-
- @Test
- public void testOverlapWarningWildcard() throws Exception {
- ApiRegionsOverlapCheckMojo mojo = new ApiRegionsOverlapCheckMojo();
-
- mojo.features = new
File(getClass().getResource("/api-regions-crossfeature-duplicates/testOverlap").getFile());
- Map<String, Feature> featureMap = new HashMap<>();
- for (File f : mojo.features.listFiles()) {
- Feature feat = FeatureJSONReader.read(new FileReader(f), null);
- featureMap.put(f.getAbsolutePath(), feat);
- }
-
- mojo.project = Mockito.mock(MavenProject.class);
- Mockito.when(mojo.project.getContextValue(Feature.class.getName() +
"/assembledmain.json-cache"))
- .thenReturn(featureMap);
-
- mojo.regions = Collections.singleton("foo");
- mojo.packages = new ApiRegionsOverlapCheckMojo.NoErrorPackageConfig();
- mojo.packages.warnings = Collections.singleton("ding.*");
- FeatureSelectionConfig cfg = new FeatureSelectionConfig();
- cfg.setFilesInclude("*.json");
- mojo.selection = cfg;
-
- // There is overlap with the ding.dong package, but it's configured as
'ignore', so the build should not fail
- mojo.execute();
- }
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap/test_a.json
b/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap/test_a.json
deleted file mode 100644
index 261eaf2..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap/test_a.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "id":"testing:test:slingfeature:testa:1.0.1",
- "api-regions:JSON|false":[
- {
- "name":"foo",
- "exports":[
- "ding.dong"
- ]
- }
- ]
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap/test_b.json
b/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap/test_b.json
deleted file mode 100644
index 45ada60..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap/test_b.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "id":"testing:test:slingfeature:testb:1.0.1",
- "api-regions:JSON|false":[
- {
- "name":"foo",
- "exports":[
- "a.b.c"
- ]
- }
- ]
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap2/test_a.json
b/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap2/test_a.json
deleted file mode 100644
index 261eaf2..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap2/test_a.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "id":"testing:test:slingfeature:testa:1.0.1",
- "api-regions:JSON|false":[
- {
- "name":"foo",
- "exports":[
- "ding.dong"
- ]
- }
- ]
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap2/test_b.json
b/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap2/test_b.json
deleted file mode 100644
index 9bb3a17..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap2/test_b.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "id":"testing:test:slingfeature:testb:1.0.1",
- "api-regions:JSON|false":[
- {
- "name":"internal",
- "exports":[
- "ding.dong"
- ]
- }
- ]
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap3/test_a.json
b/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap3/test_a.json
deleted file mode 100644
index a57772a..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap3/test_a.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "id":"testing:test:slingfeature:testa:1.0.1",
- "api-regions:JSON|false":[
- {
- "name":"other",
- "exports":[
- "a.b.c",
- "d.e.f"
- ]
- }, {
- "name":"internal",
- "exports":[
- "org.foo.bar.bingo"
- ]
- }
- ]
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap3/test_b.json
b/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap3/test_b.json
deleted file mode 100644
index ddb5958..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testNoOverlap3/test_b.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "id":"testing:test:slingfeature:testb:1.0.1",
- "bundles": [
- "mygroup:feature-exports:1",
- "mygroup:no-exports:1"
- ]
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testNotEnoughFeatureModels/test_a.json
b/src/test/resources/api-regions-crossfeature-duplicates/testNotEnoughFeatureModels/test_a.json
deleted file mode 100644
index 261eaf2..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testNotEnoughFeatureModels/test_a.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "id":"testing:test:slingfeature:testa:1.0.1",
- "api-regions:JSON|false":[
- {
- "name":"foo",
- "exports":[
- "ding.dong"
- ]
- }
- ]
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testOverlap/test_a.json
b/src/test/resources/api-regions-crossfeature-duplicates/testOverlap/test_a.json
deleted file mode 100644
index 261eaf2..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testOverlap/test_a.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "id":"testing:test:slingfeature:testa:1.0.1",
- "api-regions:JSON|false":[
- {
- "name":"foo",
- "exports":[
- "ding.dong"
- ]
- }
- ]
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testOverlap/test_b.json
b/src/test/resources/api-regions-crossfeature-duplicates/testOverlap/test_b.json
deleted file mode 100644
index 9a24306..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testOverlap/test_b.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "id":"testing:test:slingfeature:testb:1.0.1",
- "api-regions:JSON|false":[
- {
- "name":"foo",
- "exports":[
- "ding.dong"
- ]
- }
- ]
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testOverlap2/test_a.json
b/src/test/resources/api-regions-crossfeature-duplicates/testOverlap2/test_a.json
deleted file mode 100644
index bcabeea..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testOverlap2/test_a.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "id":"testing:test:slingfeature:testa:1.0.1",
- "api-regions:JSON|false":[
- {
- "name":"global",
- "exports":[
- "org.foo.bar.bingo"
- ]
- }
- ]
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testOverlap2/test_b.json
b/src/test/resources/api-regions-crossfeature-duplicates/testOverlap2/test_b.json
deleted file mode 100644
index 8a584f3..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testOverlap2/test_b.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "id":"testing:test:slingfeature:testb:1.0.1",
- "bundles": [
- "mygroup:feature-exports:1",
- "somegroup:feature-exports2:1.2.3"
- ]
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testOverlap3/test_a.json
b/src/test/resources/api-regions-crossfeature-duplicates/testOverlap3/test_a.json
deleted file mode 100644
index 261eaf2..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testOverlap3/test_a.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "id":"testing:test:slingfeature:testa:1.0.1",
- "api-regions:JSON|false":[
- {
- "name":"foo",
- "exports":[
- "ding.dong"
- ]
- }
- ]
-}
diff --git
a/src/test/resources/api-regions-crossfeature-duplicates/testOverlap3/test_b.json
b/src/test/resources/api-regions-crossfeature-duplicates/testOverlap3/test_b.json
deleted file mode 100644
index d698d41..0000000
---
a/src/test/resources/api-regions-crossfeature-duplicates/testOverlap3/test_b.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "id":"testing:test:slingfeature:testb:1.0.1",
- "api-regions:JSON|false":[
- {
- "name":"bar",
- "exports":[
- "ding.dong"
- ]
- }
- ]
-}
diff --git a/src/test/resources/bundles/feature-export.jar
b/src/test/resources/bundles/feature-export.jar
deleted file mode 100644
index d75642a..0000000
Binary files a/src/test/resources/bundles/feature-export.jar and /dev/null
differ
diff --git a/src/test/resources/bundles/feature-export2.jar
b/src/test/resources/bundles/feature-export2.jar
deleted file mode 100644
index b26a6c1..0000000
Binary files a/src/test/resources/bundles/feature-export2.jar and /dev/null
differ
diff --git a/src/test/resources/bundles/no-exports.jar
b/src/test/resources/bundles/no-exports.jar
deleted file mode 100644
index c07bf87..0000000
Binary files a/src/test/resources/bundles/no-exports.jar and /dev/null differ