-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from jfdenise/issue_98
Fix for Issue #98, Introduce a rule that discover layer based on an Annotated type
- Loading branch information
Showing
10 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.wildfly.glow; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Contains the content of the rule that identify layers based on an annotated type. | ||
* @author jdenise | ||
*/ | ||
public class AnnotatedType { | ||
|
||
private final String type; | ||
private final Map<String, String> fields; | ||
private final String annotation; | ||
private final Layer layer; | ||
|
||
/** | ||
* | ||
* @param type The java type | ||
* @param annotation The annotation applied to the type | ||
* @param fields Annotation field values (can be empty). | ||
* @param layer The layer associated to the rule. | ||
*/ | ||
public AnnotatedType(String type, String annotation, Map<String, String> fields, Layer layer) { | ||
this.type = type; | ||
this.annotation = annotation; | ||
this.fields = fields; | ||
this.layer = layer; | ||
} | ||
|
||
/** | ||
* @return The annotation full class name. | ||
*/ | ||
public String getAnnotation() { | ||
return annotation; | ||
} | ||
|
||
/** | ||
* @return The annotation fields. | ||
*/ | ||
public Map<String, String> getFields() { | ||
return fields; | ||
} | ||
|
||
/** | ||
* @return The layer | ||
*/ | ||
public Layer getLayer() { | ||
return layer; | ||
} | ||
|
||
/** | ||
* @return The java type. | ||
*/ | ||
public String getType() { | ||
return type; | ||
} | ||
} |
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
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
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,46 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.wildfly.glow; | ||
|
||
import java.util.Map; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* | ||
* @author jdenise | ||
*/ | ||
public class UtilsTestCase { | ||
@Test | ||
public void testParseAnnotationFields() { | ||
{ | ||
String str = "type,annotation"; | ||
AnnotatedType type = Utils.parseAnnotatedType(str, null); | ||
Assert.assertEquals("type", type.getType()); | ||
Assert.assertEquals("annotation", type.getAnnotation()); | ||
Assert.assertEquals(0, type.getFields().size()); | ||
} | ||
{ | ||
String fields = "type,annotation[foo=bar]"; | ||
Map<String, String> results = Utils.parseAnnotatedType(fields, null).getFields(); | ||
Assert.assertEquals(1, results.size()); | ||
Assert.assertEquals("bar", results.get("foo")); | ||
} | ||
{ | ||
String fields = "type,annotation[foo=bar,foo2=bar2]"; | ||
Map<String, String> results = Utils.parseAnnotatedType(fields, null).getFields(); | ||
Assert.assertEquals(2, results.size()); | ||
Assert.assertEquals("bar", results.get("foo")); | ||
Assert.assertEquals("bar2", results.get("foo2")); | ||
} | ||
{ | ||
String fields = "type,annotation[foo=bar*,foo2=\\=b\\,a\\]r2]"; | ||
Map<String, String> results = Utils.parseAnnotatedType(fields, null).getFields(); | ||
Assert.assertEquals(2, results.size()); | ||
Assert.assertEquals("bar.*", results.get("foo")); | ||
Assert.assertEquals("=b,a]r2", results.get("foo2")); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ture-pack/galleon-pack/src/main/resources/layers/standalone/annotated-type/layer-spec.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,11 @@ | ||
<!-- | ||
~ Copyright The WildFly Authors | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<layer-spec xmlns="urn:jboss:galleon:layer-spec:2.0" name="annotated-type"> | ||
<props> | ||
<prop name="org.wildfly.rule.annotated.type" value="java.lang.Object,org.wildfly.glow.test.rules.classes.annotation.field.value.FieldValue[prop=coco]"/> | ||
|
||
</props> | ||
</layer-spec> |
18 changes: 18 additions & 0 deletions
18
...tests/src/test/java/org/wildfly/glow/rules/test/annotated/type/AnnotatedTypeTestCase.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,18 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.wildfly.glow.rules.test.annotated.type; | ||
|
||
import org.junit.Test; | ||
import org.wildfly.glow.rules.test.AbstractLayerMetaDataTestCase; | ||
|
||
public class AnnotatedTypeTestCase extends AbstractLayerMetaDataTestCase { | ||
|
||
@Test | ||
public void testValueAnnotationUsage() { | ||
testSingleClassWar(AnnotatedTypeUsage.class, "annotated-type"); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...ta-tests/src/test/java/org/wildfly/glow/rules/test/annotated/type/AnnotatedTypeUsage.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,14 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.wildfly.glow.rules.test.annotated.type; | ||
|
||
import org.wildfly.glow.test.rules.classes.annotation.field.value.FieldValue; | ||
|
||
|
||
public class AnnotatedTypeUsage { | ||
@FieldValue(prop = "coco") | ||
private Object foo; | ||
} |