Skip to content

Commit

Permalink
Merge pull request #22 from jfdenise/main
Browse files Browse the repository at this point in the history
Multiple layers could share the same rules
  • Loading branch information
jfdenise authored Nov 15, 2023
2 parents 4412b08 + ff5120f commit a4b1d74
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 21 deletions.
20 changes: 10 additions & 10 deletions core/src/main/java/org/wildfly/glow/DeploymentScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,22 @@ 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<Layer> 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?
for (String s : ctx.mapping.getAnnotations().keySet()) {
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));
}
}
}
Expand Down Expand Up @@ -240,9 +240,9 @@ private void handleResourceInjectionAnnotations(AnnotationInstance annotationIns
}
}
if (resourceClassName != null) {
Layer layer = lookup(resourceClassName, ctx);
Set<Layer> 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);
Expand Down Expand Up @@ -561,10 +561,10 @@ private Layer lookupJndi(String jndiName, DeploymentScanContext ctx) {
return layer;
}

private Layer lookup(String className, DeploymentScanContext ctx) {
Map<String, Layer> map = ctx.mapping.getConstantPoolClassInfos();
private Set<Layer> lookup(String className, DeploymentScanContext ctx) {
Map<String, Set<Layer>> map = ctx.mapping.getConstantPoolClassInfos();

Layer l = map.get(className);
Set<Layer> l = map.get(className);
if (l == null) {
int index = className.lastIndexOf(".");
if (index != -1) {
Expand All @@ -584,7 +584,7 @@ private Layer lookup(String className, DeploymentScanContext ctx) {
}
}
if (l != null) {
ctx.layers.add(l);
ctx.layers.addAll(l);
}
return l;
}
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/org/wildfly/glow/LayerMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
*/
public class LayerMapping {

private final Map<String, Layer> constantPoolClassInfos = new HashMap<>();
private final Map<String, Layer> annotations = new HashMap<>();
private final Map<String, Layer> activeProfilesLayers = new HashMap();
private final Map<String, Set<Layer>> allProfilesLayers = new HashMap();
private final Map<String, Set<Layer>> constantPoolClassInfos = new HashMap<>();
private final Map<String, Set<Layer>> annotations = new HashMap<>();
private final Map<String, Layer> activeProfilesLayers = new HashMap<>();
private final Map<String, Set<Layer>> allProfilesLayers = new HashMap<>();
private Layer defaultBaseLayer;

private final Set<Layer> layersIncludedIfAllDeps = new TreeSet<>();
Expand All @@ -50,14 +50,14 @@ public class LayerMapping {
/**
* @return the constantPoolClassInfos
*/
public Map<String, Layer> getConstantPoolClassInfos() {
public Map<String, Set<Layer>> getConstantPoolClassInfos() {
return constantPoolClassInfos;
}

/**
* @return the annotations
*/
public Map<String, Layer> getAnnotations() {
public Map<String, Set<Layer>> getAnnotations() {
return annotations;
}

Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/org/wildfly/glow/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ public static LayerMapping buildMapping(Map<String, Layer> layers, Set<String> p
String[] split = val.split(",");
for (String s : split) {
s = escapePattern(s);
mapping.getAnnotations().put(s, l);
Set<Layer> ll = mapping.getAnnotations().computeIfAbsent(s, value -> new HashSet<>());
ll.add(l);
}
continue;
}
Expand All @@ -414,7 +415,8 @@ public static LayerMapping buildMapping(Map<String, Layer> layers, Set<String> p
String[] split = val.split(",");
for (String s : split) {
s = escapePattern(s);
mapping.getConstantPoolClassInfos().put(s, l);
Set<Layer> ll = mapping.getConstantPoolClassInfos().computeIfAbsent(s, value -> new HashSet<>());
ll.add(l);
}
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
~ 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.
-->

<layer-spec xmlns="urn:jboss:galleon:layer-spec:2.0" name="multiple1">
<props>
<prop name="org.wildfly.rule.class" value="org.wildfly.glow.test.rules.classes.classrule.multiple"/>
<prop name="org.wildfly.rule.annotations" value="org.wildfly.glow.test.rules.classes.annotations.multiple.*"/>
</props>
</layer-spec>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
~ 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.
-->

<layer-spec xmlns="urn:jboss:galleon:layer-spec:2.0" name="multiple2">
<props>
<prop name="org.wildfly.rule.class" value="org.wildfly.glow.test.rules.classes.classrule.multiple"/>
<prop name="org.wildfly.rule.annotations" value="org.wildfly.glow.test.rules.classes.annotations.multiple.*"/>
</props>
</layer-spec>
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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 {
}

0 comments on commit a4b1d74

Please sign in to comment.