diff --git a/core/src/main/java/org/wildfly/glow/DeploymentScanner.java b/core/src/main/java/org/wildfly/glow/DeploymentScanner.java index 64e29a19..d6e08a6e 100644 --- a/core/src/main/java/org/wildfly/glow/DeploymentScanner.java +++ b/core/src/main/java/org/wildfly/glow/DeploymentScanner.java @@ -165,14 +165,14 @@ private void scanAnnotations(DeploymentScanContext ctx) throws IOException { handleResourceInjectionAnnotations(ai, ctx); //System.out.println(" " + ai.name().packagePrefix()); - Layer l = ctx.mapping.getAnnotations().get(ai.name().toString()); + Set l = ctx.mapping.getAnnotations().get(ai.name().toString()); if (l != null) { - ctx.layers.add(l); + ctx.layers.addAll(l); //System.out.println("Find an annotation " + ai.name().toString() + " layer being " + l); } else { l = ctx.mapping.getAnnotations().get(ai.name().packagePrefix()); if (l != null) { - ctx.layers.add(l); + ctx.layers.addAll(l); //System.out.println("Find an annotation " + ai.name().packagePrefix() + " layer being " + l); } else { // Pattern? @@ -180,7 +180,7 @@ private void scanAnnotations(DeploymentScanContext ctx) throws IOException { if (Utils.isPattern(s)) { Pattern p = Pattern.compile(s); if (p.matcher(ai.name().toString()).matches()) { - ctx.layers.add(ctx.mapping.getAnnotations().get(s)); + ctx.layers.addAll(ctx.mapping.getAnnotations().get(s)); } } } @@ -240,9 +240,9 @@ private void handleResourceInjectionAnnotations(AnnotationInstance annotationIns } } if (resourceClassName != null) { - Layer layer = lookup(resourceClassName, ctx); + Set layer = lookup(resourceClassName, ctx); if (layer != null) { - resourceLayers.add(layer); + resourceLayers.addAll(layer); } ResourceInjectionJndiInfo info = new ResourceInjectionJndiInfo(resourceLayers, resourceClassName, injectionPoint, jndiName); //System.out.println(info); @@ -561,10 +561,10 @@ private Layer lookupJndi(String jndiName, DeploymentScanContext ctx) { return layer; } - private Layer lookup(String className, DeploymentScanContext ctx) { - Map map = ctx.mapping.getConstantPoolClassInfos(); + private Set lookup(String className, DeploymentScanContext ctx) { + Map> map = ctx.mapping.getConstantPoolClassInfos(); - Layer l = map.get(className); + Set l = map.get(className); if (l == null) { int index = className.lastIndexOf("."); if (index != -1) { @@ -584,7 +584,7 @@ private Layer lookup(String className, DeploymentScanContext ctx) { } } if (l != null) { - ctx.layers.add(l); + ctx.layers.addAll(l); } return l; } diff --git a/core/src/main/java/org/wildfly/glow/LayerMapping.java b/core/src/main/java/org/wildfly/glow/LayerMapping.java index aed47a24..f2009345 100644 --- a/core/src/main/java/org/wildfly/glow/LayerMapping.java +++ b/core/src/main/java/org/wildfly/glow/LayerMapping.java @@ -29,10 +29,10 @@ */ public class LayerMapping { - private final Map constantPoolClassInfos = new HashMap<>(); - private final Map annotations = new HashMap<>(); - private final Map activeProfilesLayers = new HashMap(); - private final Map> allProfilesLayers = new HashMap(); + private final Map> constantPoolClassInfos = new HashMap<>(); + private final Map> annotations = new HashMap<>(); + private final Map activeProfilesLayers = new HashMap<>(); + private final Map> allProfilesLayers = new HashMap<>(); private Layer defaultBaseLayer; private final Set layersIncludedIfAllDeps = new TreeSet<>(); @@ -50,14 +50,14 @@ public class LayerMapping { /** * @return the constantPoolClassInfos */ - public Map getConstantPoolClassInfos() { + public Map> getConstantPoolClassInfos() { return constantPoolClassInfos; } /** * @return the annotations */ - public Map getAnnotations() { + public Map> getAnnotations() { return annotations; } diff --git a/core/src/main/java/org/wildfly/glow/Utils.java b/core/src/main/java/org/wildfly/glow/Utils.java index 16b362da..e418e63f 100644 --- a/core/src/main/java/org/wildfly/glow/Utils.java +++ b/core/src/main/java/org/wildfly/glow/Utils.java @@ -405,7 +405,8 @@ public static LayerMapping buildMapping(Map layers, Set p String[] split = val.split(","); for (String s : split) { s = escapePattern(s); - mapping.getAnnotations().put(s, l); + Set ll = mapping.getAnnotations().computeIfAbsent(s, value -> new HashSet<>()); + ll.add(l); } continue; } @@ -414,7 +415,8 @@ public static LayerMapping buildMapping(Map layers, Set p String[] split = val.split(","); for (String s : split) { s = escapePattern(s); - mapping.getConstantPoolClassInfos().put(s, l); + Set ll = mapping.getConstantPoolClassInfos().computeIfAbsent(s, value -> new HashSet<>()); + ll.add(l); } continue; } diff --git a/tests/test-feature-pack/galleon-pack/src/main/resources/layers/standalone/multiple1/layer-spec.xml b/tests/test-feature-pack/galleon-pack/src/main/resources/layers/standalone/multiple1/layer-spec.xml new file mode 100644 index 00000000..bcf4f599 --- /dev/null +++ b/tests/test-feature-pack/galleon-pack/src/main/resources/layers/standalone/multiple1/layer-spec.xml @@ -0,0 +1,23 @@ + + + + + + + + \ No newline at end of file diff --git a/tests/test-feature-pack/galleon-pack/src/main/resources/layers/standalone/multiple2/layer-spec.xml b/tests/test-feature-pack/galleon-pack/src/main/resources/layers/standalone/multiple2/layer-spec.xml new file mode 100644 index 00000000..3646b933 --- /dev/null +++ b/tests/test-feature-pack/galleon-pack/src/main/resources/layers/standalone/multiple2/layer-spec.xml @@ -0,0 +1,23 @@ + + + + + + + + \ No newline at end of file diff --git a/tests/test-feature-pack/layer-metadata-tests/src/test/java/org/wildfly/glow/rules/test/AbstractLayerMetaDataTestCase.java b/tests/test-feature-pack/layer-metadata-tests/src/test/java/org/wildfly/glow/rules/test/AbstractLayerMetaDataTestCase.java index 23fa8a98..05b8c34d 100644 --- a/tests/test-feature-pack/layer-metadata-tests/src/test/java/org/wildfly/glow/rules/test/AbstractLayerMetaDataTestCase.java +++ b/tests/test-feature-pack/layer-metadata-tests/src/test/java/org/wildfly/glow/rules/test/AbstractLayerMetaDataTestCase.java @@ -195,12 +195,12 @@ protected ArchiveBuilder createArchiveBuilder(String name, ArchiveType type) { protected void testSingleClassWar(Class clazz) { testSingleClassWar(clazz, null); } - protected void testSingleClassWar(Class clazz, String layer) { + protected void testSingleClassWar(Class clazz, String... layers) { Path p = createArchiveBuilder(ArchiveType.WAR) .addClasses(clazz) .build(); - String[] layers = layer == null ? new String[0] : new String[]{layer}; - checkLayersForArchive(p, layers); + String[] layersArray = layers == null ? new String[0] : layers; + checkLayersForArchive(p, layersArray); } public class ArchiveBuilder { diff --git a/tests/test-feature-pack/layer-metadata-tests/src/test/java/org/wildfly/glow/rules/test/multiple/MultipleAnnotationClassUsage.java b/tests/test-feature-pack/layer-metadata-tests/src/test/java/org/wildfly/glow/rules/test/multiple/MultipleAnnotationClassUsage.java new file mode 100644 index 00000000..69dcd4c2 --- /dev/null +++ b/tests/test-feature-pack/layer-metadata-tests/src/test/java/org/wildfly/glow/rules/test/multiple/MultipleAnnotationClassUsage.java @@ -0,0 +1,24 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2023 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed 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.wildfly.glow.rules.test.multiple; + +import org.wildfly.glow.test.rules.classes.annotations.multiple.Multiple; + +@Multiple +public class MultipleAnnotationClassUsage { +} diff --git a/tests/test-feature-pack/layer-metadata-tests/src/test/java/org/wildfly/glow/rules/test/multiple/MultipleLayersTestCase.java b/tests/test-feature-pack/layer-metadata-tests/src/test/java/org/wildfly/glow/rules/test/multiple/MultipleLayersTestCase.java new file mode 100644 index 00000000..d3a2306c --- /dev/null +++ b/tests/test-feature-pack/layer-metadata-tests/src/test/java/org/wildfly/glow/rules/test/multiple/MultipleLayersTestCase.java @@ -0,0 +1,44 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2023 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed 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.wildfly.glow.rules.test.multiple; + +import org.junit.Test; +import org.wildfly.glow.rules.test.AbstractLayerMetaDataTestCase; +import org.wildfly.glow.test.rules.classes.classrule.multiple.ClassMultipleClass; + +/** + * This class tests that multiple layers defining the same class rule are discovered. + * + */ +public class MultipleLayersTestCase extends AbstractLayerMetaDataTestCase { + + @Test + public void testMultipleLayersSameClass() { + testSingleClassWar(ClassMultipleClass.class); + } + + @Test + public void testMultipleLayersSameAnnotation() { + testSingleClassWar(MultipleAnnotationClassUsage.class); + } + + @Override + protected void testSingleClassWar(Class clazz) { + super.testSingleClassWar(clazz, "multiple1", "multiple2"); + } +} diff --git a/tests/test-feature-pack/test-classes/src/main/java/org/wildfly/glow/test/rules/classes/annotations/multiple/Multiple.java b/tests/test-feature-pack/test-classes/src/main/java/org/wildfly/glow/test/rules/classes/annotations/multiple/Multiple.java new file mode 100644 index 00000000..1788eb31 --- /dev/null +++ b/tests/test-feature-pack/test-classes/src/main/java/org/wildfly/glow/test/rules/classes/annotations/multiple/Multiple.java @@ -0,0 +1,28 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2023 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed 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.wildfly.glow.test.rules.classes.annotations.multiple; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Multiple { +} diff --git a/tests/test-feature-pack/test-classes/src/main/java/org/wildfly/glow/test/rules/classes/classrule/multiple/ClassMultipleClass.java b/tests/test-feature-pack/test-classes/src/main/java/org/wildfly/glow/test/rules/classes/classrule/multiple/ClassMultipleClass.java new file mode 100644 index 00000000..fa3ba4c3 --- /dev/null +++ b/tests/test-feature-pack/test-classes/src/main/java/org/wildfly/glow/test/rules/classes/classrule/multiple/ClassMultipleClass.java @@ -0,0 +1,21 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2023 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed 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.wildfly.glow.test.rules.classes.classrule.multiple; + +public class ClassMultipleClass { +}