tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-1957 adding @Args for tomee embedded
Date Sun, 09 Oct 2016 16:23:18 GMT
Repository: tomee
Updated Branches:
  refs/heads/master fb545612f -> 14c7483b9


TOMEE-1957 adding @Args for tomee embedded


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/14c7483b
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/14c7483b
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/14c7483b

Branch: refs/heads/master
Commit: 14c7483b9a972a4b60795c5c3cde363061abc4dd
Parents: fb54561
Author: rmannibucau <rmannibucau@apache.org>
Authored: Sun Oct 9 18:23:09 2016 +0200
Committer: rmannibucau <rmannibucau@apache.org>
Committed: Sun Oct 9 18:23:09 2016 +0200

----------------------------------------------------------------------
 .../embedded/TomEEEmbeddedApplicationRunner.java      | 14 ++++++++++++++
 .../tomee/embedded/NoScannerSingleRunnerTest.java     |  4 ++++
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/14c7483b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
index ffc4dcd..62f305d 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
@@ -445,6 +445,15 @@ public class TomEEEmbeddedApplicationRunner implements AutoCloseable
{
                     final Class type = f.getType();
                     final Object taskByType = accessor.getTaskByType(type);
                     f.set(target, taskByType);
+                } else if (f.isAnnotationPresent(Args.class)) {
+                    if (String[].class != f.getType()) {
+                        throw new IllegalArgumentException("@Args can only be used for String[]
field, not on " + f.getType());
+                    }
+                    if (!f.isAccessible()) {
+                        f.setAccessible(true);
+                    }
+                    final TomEEEmbeddedArgs args = SystemInstance.get().getComponent(TomEEEmbeddedArgs.class);
+                    f.set(target, args == null ? new String[0] : args.getArgs());
                 }
             }
             aClass = aClass.getSuperclass();
@@ -465,6 +474,11 @@ public class TomEEEmbeddedApplicationRunner implements AutoCloseable
{
     }
 
     @Retention(RUNTIME)
+    @Target(FIELD)
+    public @interface Args {
+    }
+
+    @Retention(RUNTIME)
     @Target(TYPE)
     public @interface Configurers {
         Class<? extends Configurer>[] value();

http://git-wip-us.apache.org/repos/asf/tomee/blob/14c7483b/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/NoScannerSingleRunnerTest.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/NoScannerSingleRunnerTest.java
b/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/NoScannerSingleRunnerTest.java
index 570f88a..78927db 100644
--- a/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/NoScannerSingleRunnerTest.java
+++ b/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/NoScannerSingleRunnerTest.java
@@ -37,8 +37,12 @@ public class NoScannerSingleRunnerTest {
     @Application // app can have several injections/helpers
     private ScanApp app;
 
+    @TomEEEmbeddedApplicationRunner.Args
+    private String[] args;
+
     @Test
     public void run() {
+        assertNotNull(app);
         app.check();
     }
 


Mime
View raw message