You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2016/09/14 03:59:01 UTC

[2/2] logging-log4j2 git commit: Deprecate factory method in favor of a builder.

Deprecate factory method in favor of a builder.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3846e2a8
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3846e2a8
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3846e2a8

Branch: refs/heads/master
Commit: 3846e2a87b94639466c7ab25b333fdb4ded8defc
Parents: 981677f
Author: Gary Gregory <gg...@apache.org>
Authored: Tue Sep 13 20:58:56 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Tue Sep 13 20:58:56 2016 -0700

----------------------------------------------------------------------
 .../log4j/core/appender/routing/Routes.java     | 51 ++++++++++++++++++--
 1 file changed, 47 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3846e2a8/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java
index aae4087..c95b64a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java
@@ -21,8 +21,8 @@ import java.util.Objects;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.status.StatusLogger;
 
 /**
@@ -31,6 +31,48 @@ import org.apache.logging.log4j.status.StatusLogger;
 @Plugin(name = "Routes", category = "Core", printObject = true)
 public final class Routes {
 
+    public static class Builder implements org.apache.logging.log4j.core.util.Builder<Routes>  {
+
+        @PluginAttribute("pattern") 
+        private String pattern;
+        
+        @PluginElement("Routes") 
+        private Route[] routes;
+
+        @Override
+        public Routes build() {
+            if (routes == null || routes.length == 0) {
+                LOGGER.error("No routes configured");
+                return null;
+            }
+            return new Routes(pattern, routes);
+        }
+
+        public String getPattern() {
+            return pattern;
+        }
+
+        public Route[] getRoutes() {
+            return routes;
+        }
+
+        public Builder withPattern(@SuppressWarnings("hiding") String pattern) {
+            this.pattern = pattern;
+            return this;
+        }
+
+        public Builder withRoutes(@SuppressWarnings("hiding") Route[] routes) {
+            this.routes = routes;
+            return this;
+        }
+        
+    }
+
+    @PluginBuilderFactory
+    public static Builder newBuilder() {
+        return new Builder();
+    }
+
     private static final Logger LOGGER = StatusLogger.getLogger();
 
     private final String pattern;
@@ -90,11 +132,12 @@ public final class Routes {
      * @param pattern The pattern.
      * @param routes An array of Route elements.
      * @return The Routes container.
+     * @deprecated since 2.7; use {@link #newBuilder()}.
      */
-    @PluginFactory
+    @Deprecated
     public static Routes createRoutes(
-            @PluginAttribute("pattern") final String pattern,
-            @PluginElement("Routes") final Route... routes) {
+            final String pattern,
+            final Route... routes) {
         if (routes == null || routes.length == 0) {
             LOGGER.error("No routes configured");
             return null;


Re: [2/2] logging-log4j2 git commit: Deprecate factory method in favor of a builder.

Posted by Matt Sicker <bo...@gmail.com>.
There's an enum converter that supports all enums, so yeah, it should work.

On 14 September 2016 at 12:06, Gary Gregory <ga...@gmail.com> wrote:

> Nah, builders and factories should use the best type possible.
>
> I have seen the light WRT Builders. It is the best way to provide some
> kind of easy migration and adding new features. You never need to deprecate
> a factory method.
>
> I'd like to be able to use a TimeUnit as a Builder arg. Will that work out
> of the box? I recall I wrote some conversion code for other classes
> someplace at some time in the past...
>
> Gary
>
> On Wed, Sep 14, 2016 at 6:45 AM, Matt Sicker <bo...@gmail.com> wrote:
>
>> We'll need a different solution for programmatic configuration. The
>> current main supported programmatic config is via the configuration builder
>> classes which rely on strings more so than objects.
>>
>> On 13 September 2016 at 23:26, Gary Gregory <ga...@gmail.com>
>> wrote:
>>
>>> Good to know, I'll add that. But... we still need the check in the
>>> builders for programmatic configurations.
>>>
>>> Gary
>>>
>>> On Tue, Sep 13, 2016 at 9:11 PM, Matt Sicker <bo...@gmail.com> wrote:
>>>
>>>> If you use @Required on an array, it checks for non-null and non-empty.
>>>> Works on strings, collections, and maps with the same semantics.
>>>>
>>>> ---------- Forwarded message ----------
>>>> From: <gg...@apache.org>
>>>> Date: 13 September 2016 at 22:59
>>>> Subject: [2/2] logging-log4j2 git commit: Deprecate factory method in
>>>> favor of a builder.
>>>> To: commits@logging.apache.org
>>>>
>>>>
>>>> Deprecate factory method in favor of a builder.
>>>>
>>>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>>>> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit
>>>> /3846e2a8
>>>> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3
>>>> 846e2a8
>>>> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3
>>>> 846e2a8
>>>>
>>>> Branch: refs/heads/master
>>>> Commit: 3846e2a87b94639466c7ab25b333fdb4ded8defc
>>>> Parents: 981677f
>>>> Author: Gary Gregory <gg...@apache.org>
>>>> Authored: Tue Sep 13 20:58:56 2016 -0700
>>>> Committer: Gary Gregory <gg...@apache.org>
>>>> Committed: Tue Sep 13 20:58:56 2016 -0700
>>>>
>>>> ----------------------------------------------------------------------
>>>>  .../log4j/core/appender/routing/Routes.java     | 51
>>>> ++++++++++++++++++--
>>>>  1 file changed, 47 insertions(+), 4 deletions(-)
>>>> ----------------------------------------------------------------------
>>>>
>>>>
>>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3
>>>> 846e2a8/log4j-core/src/main/java/org/apache/logging/log4j/co
>>>> re/appender/routing/Routes.java
>>>> ----------------------------------------------------------------------
>>>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java
>>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/app
>>>> ender/routing/Routes.java
>>>> index aae4087..c95b64a 100644
>>>> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/app
>>>> ender/routing/Routes.java
>>>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/app
>>>> ender/routing/Routes.java
>>>> @@ -21,8 +21,8 @@ import java.util.Objects;
>>>>  import org.apache.logging.log4j.Logger;
>>>>  import org.apache.logging.log4j.core.config.plugins.Plugin;
>>>>  import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>>>> +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFa
>>>> ctory;
>>>>  import org.apache.logging.log4j.core.config.plugins.PluginElement;
>>>> -import org.apache.logging.log4j.core.config.plugins.PluginFactory;
>>>>  import org.apache.logging.log4j.status.StatusLogger;
>>>>
>>>>  /**
>>>> @@ -31,6 +31,48 @@ import org.apache.logging.log4j.status.StatusLogger;
>>>>  @Plugin(name = "Routes", category = "Core", printObject = true)
>>>>  public final class Routes {
>>>>
>>>> +    public static class Builder implements
>>>> org.apache.logging.log4j.core.util.Builder<Routes>  {
>>>> +
>>>> +        @PluginAttribute("pattern")
>>>> +        private String pattern;
>>>> +
>>>> +        @PluginElement("Routes")
>>>> +        private Route[] routes;
>>>> +
>>>> +        @Override
>>>> +        public Routes build() {
>>>> +            if (routes == null || routes.length == 0) {
>>>> +                LOGGER.error("No routes configured");
>>>> +                return null;
>>>> +            }
>>>> +            return new Routes(pattern, routes);
>>>> +        }
>>>> +
>>>> +        public String getPattern() {
>>>> +            return pattern;
>>>> +        }
>>>> +
>>>> +        public Route[] getRoutes() {
>>>> +            return routes;
>>>> +        }
>>>> +
>>>> +        public Builder withPattern(@SuppressWarnings("hiding") String
>>>> pattern) {
>>>> +            this.pattern = pattern;
>>>> +            return this;
>>>> +        }
>>>> +
>>>> +        public Builder withRoutes(@SuppressWarnings("hiding") Route[]
>>>> routes) {
>>>> +            this.routes = routes;
>>>> +            return this;
>>>> +        }
>>>> +
>>>> +    }
>>>> +
>>>> +    @PluginBuilderFactory
>>>> +    public static Builder newBuilder() {
>>>> +        return new Builder();
>>>> +    }
>>>> +
>>>>      private static final Logger LOGGER = StatusLogger.getLogger();
>>>>
>>>>      private final String pattern;
>>>> @@ -90,11 +132,12 @@ public final class Routes {
>>>>       * @param pattern The pattern.
>>>>       * @param routes An array of Route elements.
>>>>       * @return The Routes container.
>>>> +     * @deprecated since 2.7; use {@link #newBuilder()}.
>>>>       */
>>>> -    @PluginFactory
>>>> +    @Deprecated
>>>>      public static Routes createRoutes(
>>>> -            @PluginAttribute("pattern") final String pattern,
>>>> -            @PluginElement("Routes") final Route... routes) {
>>>> +            final String pattern,
>>>> +            final Route... routes) {
>>>>          if (routes == null || routes.length == 0) {
>>>>              LOGGER.error("No routes configured");
>>>>              return null;
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Matt Sicker <bo...@gmail.com>
>>>>
>>>
>>>
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition
>>> <http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
Matt Sicker <bo...@gmail.com>

Re: [2/2] logging-log4j2 git commit: Deprecate factory method in favor of a builder.

Posted by Gary Gregory <ga...@gmail.com>.
Nah, builders and factories should use the best type possible.

I have seen the light WRT Builders. It is the best way to provide some kind
of easy migration and adding new features. You never need to deprecate a
factory method.

I'd like to be able to use a TimeUnit as a Builder arg. Will that work out
of the box? I recall I wrote some conversion code for other classes
someplace at some time in the past...

Gary

On Wed, Sep 14, 2016 at 6:45 AM, Matt Sicker <bo...@gmail.com> wrote:

> We'll need a different solution for programmatic configuration. The
> current main supported programmatic config is via the configuration builder
> classes which rely on strings more so than objects.
>
> On 13 September 2016 at 23:26, Gary Gregory <ga...@gmail.com>
> wrote:
>
>> Good to know, I'll add that. But... we still need the check in the
>> builders for programmatic configurations.
>>
>> Gary
>>
>> On Tue, Sep 13, 2016 at 9:11 PM, Matt Sicker <bo...@gmail.com> wrote:
>>
>>> If you use @Required on an array, it checks for non-null and non-empty.
>>> Works on strings, collections, and maps with the same semantics.
>>>
>>> ---------- Forwarded message ----------
>>> From: <gg...@apache.org>
>>> Date: 13 September 2016 at 22:59
>>> Subject: [2/2] logging-log4j2 git commit: Deprecate factory method in
>>> favor of a builder.
>>> To: commits@logging.apache.org
>>>
>>>
>>> Deprecate factory method in favor of a builder.
>>>
>>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>>> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit
>>> /3846e2a8
>>> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3
>>> 846e2a8
>>> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3
>>> 846e2a8
>>>
>>> Branch: refs/heads/master
>>> Commit: 3846e2a87b94639466c7ab25b333fdb4ded8defc
>>> Parents: 981677f
>>> Author: Gary Gregory <gg...@apache.org>
>>> Authored: Tue Sep 13 20:58:56 2016 -0700
>>> Committer: Gary Gregory <gg...@apache.org>
>>> Committed: Tue Sep 13 20:58:56 2016 -0700
>>>
>>> ----------------------------------------------------------------------
>>>  .../log4j/core/appender/routing/Routes.java     | 51
>>> ++++++++++++++++++--
>>>  1 file changed, 47 insertions(+), 4 deletions(-)
>>> ----------------------------------------------------------------------
>>>
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3
>>> 846e2a8/log4j-core/src/main/java/org/apache/logging/log4j/co
>>> re/appender/routing/Routes.java
>>> ----------------------------------------------------------------------
>>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java
>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/app
>>> ender/routing/Routes.java
>>> index aae4087..c95b64a 100644
>>> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/app
>>> ender/routing/Routes.java
>>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/app
>>> ender/routing/Routes.java
>>> @@ -21,8 +21,8 @@ import java.util.Objects;
>>>  import org.apache.logging.log4j.Logger;
>>>  import org.apache.logging.log4j.core.config.plugins.Plugin;
>>>  import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>>> +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFa
>>> ctory;
>>>  import org.apache.logging.log4j.core.config.plugins.PluginElement;
>>> -import org.apache.logging.log4j.core.config.plugins.PluginFactory;
>>>  import org.apache.logging.log4j.status.StatusLogger;
>>>
>>>  /**
>>> @@ -31,6 +31,48 @@ import org.apache.logging.log4j.status.StatusLogger;
>>>  @Plugin(name = "Routes", category = "Core", printObject = true)
>>>  public final class Routes {
>>>
>>> +    public static class Builder implements
>>> org.apache.logging.log4j.core.util.Builder<Routes>  {
>>> +
>>> +        @PluginAttribute("pattern")
>>> +        private String pattern;
>>> +
>>> +        @PluginElement("Routes")
>>> +        private Route[] routes;
>>> +
>>> +        @Override
>>> +        public Routes build() {
>>> +            if (routes == null || routes.length == 0) {
>>> +                LOGGER.error("No routes configured");
>>> +                return null;
>>> +            }
>>> +            return new Routes(pattern, routes);
>>> +        }
>>> +
>>> +        public String getPattern() {
>>> +            return pattern;
>>> +        }
>>> +
>>> +        public Route[] getRoutes() {
>>> +            return routes;
>>> +        }
>>> +
>>> +        public Builder withPattern(@SuppressWarnings("hiding") String
>>> pattern) {
>>> +            this.pattern = pattern;
>>> +            return this;
>>> +        }
>>> +
>>> +        public Builder withRoutes(@SuppressWarnings("hiding") Route[]
>>> routes) {
>>> +            this.routes = routes;
>>> +            return this;
>>> +        }
>>> +
>>> +    }
>>> +
>>> +    @PluginBuilderFactory
>>> +    public static Builder newBuilder() {
>>> +        return new Builder();
>>> +    }
>>> +
>>>      private static final Logger LOGGER = StatusLogger.getLogger();
>>>
>>>      private final String pattern;
>>> @@ -90,11 +132,12 @@ public final class Routes {
>>>       * @param pattern The pattern.
>>>       * @param routes An array of Route elements.
>>>       * @return The Routes container.
>>> +     * @deprecated since 2.7; use {@link #newBuilder()}.
>>>       */
>>> -    @PluginFactory
>>> +    @Deprecated
>>>      public static Routes createRoutes(
>>> -            @PluginAttribute("pattern") final String pattern,
>>> -            @PluginElement("Routes") final Route... routes) {
>>> +            final String pattern,
>>> +            final Route... routes) {
>>>          if (routes == null || routes.length == 0) {
>>>              LOGGER.error("No routes configured");
>>>              return null;
>>>
>>>
>>>
>>>
>>> --
>>> Matt Sicker <bo...@gmail.com>
>>>
>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition
>> <http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: [2/2] logging-log4j2 git commit: Deprecate factory method in favor of a builder.

Posted by Matt Sicker <bo...@gmail.com>.
We'll need a different solution for programmatic configuration. The current
main supported programmatic config is via the configuration builder classes
which rely on strings more so than objects.

On 13 September 2016 at 23:26, Gary Gregory <ga...@gmail.com> wrote:

> Good to know, I'll add that. But... we still need the check in the
> builders for programmatic configurations.
>
> Gary
>
> On Tue, Sep 13, 2016 at 9:11 PM, Matt Sicker <bo...@gmail.com> wrote:
>
>> If you use @Required on an array, it checks for non-null and non-empty.
>> Works on strings, collections, and maps with the same semantics.
>>
>> ---------- Forwarded message ----------
>> From: <gg...@apache.org>
>> Date: 13 September 2016 at 22:59
>> Subject: [2/2] logging-log4j2 git commit: Deprecate factory method in
>> favor of a builder.
>> To: commits@logging.apache.org
>>
>>
>> Deprecate factory method in favor of a builder.
>>
>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit
>> /3846e2a8
>> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3846e2a8
>> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3846e2a8
>>
>> Branch: refs/heads/master
>> Commit: 3846e2a87b94639466c7ab25b333fdb4ded8defc
>> Parents: 981677f
>> Author: Gary Gregory <gg...@apache.org>
>> Authored: Tue Sep 13 20:58:56 2016 -0700
>> Committer: Gary Gregory <gg...@apache.org>
>> Committed: Tue Sep 13 20:58:56 2016 -0700
>>
>> ----------------------------------------------------------------------
>>  .../log4j/core/appender/routing/Routes.java     | 51
>> ++++++++++++++++++--
>>  1 file changed, 47 insertions(+), 4 deletions(-)
>> ----------------------------------------------------------------------
>>
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3
>> 846e2a8/log4j-core/src/main/java/org/apache/logging/log4j/co
>> re/appender/routing/Routes.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java
>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/app
>> ender/routing/Routes.java
>> index aae4087..c95b64a 100644
>> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/app
>> ender/routing/Routes.java
>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/app
>> ender/routing/Routes.java
>> @@ -21,8 +21,8 @@ import java.util.Objects;
>>  import org.apache.logging.log4j.Logger;
>>  import org.apache.logging.log4j.core.config.plugins.Plugin;
>>  import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>> +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFa
>> ctory;
>>  import org.apache.logging.log4j.core.config.plugins.PluginElement;
>> -import org.apache.logging.log4j.core.config.plugins.PluginFactory;
>>  import org.apache.logging.log4j.status.StatusLogger;
>>
>>  /**
>> @@ -31,6 +31,48 @@ import org.apache.logging.log4j.status.StatusLogger;
>>  @Plugin(name = "Routes", category = "Core", printObject = true)
>>  public final class Routes {
>>
>> +    public static class Builder implements org.apache.logging.log4j.core.util.Builder<Routes>
>> {
>> +
>> +        @PluginAttribute("pattern")
>> +        private String pattern;
>> +
>> +        @PluginElement("Routes")
>> +        private Route[] routes;
>> +
>> +        @Override
>> +        public Routes build() {
>> +            if (routes == null || routes.length == 0) {
>> +                LOGGER.error("No routes configured");
>> +                return null;
>> +            }
>> +            return new Routes(pattern, routes);
>> +        }
>> +
>> +        public String getPattern() {
>> +            return pattern;
>> +        }
>> +
>> +        public Route[] getRoutes() {
>> +            return routes;
>> +        }
>> +
>> +        public Builder withPattern(@SuppressWarnings("hiding") String
>> pattern) {
>> +            this.pattern = pattern;
>> +            return this;
>> +        }
>> +
>> +        public Builder withRoutes(@SuppressWarnings("hiding") Route[]
>> routes) {
>> +            this.routes = routes;
>> +            return this;
>> +        }
>> +
>> +    }
>> +
>> +    @PluginBuilderFactory
>> +    public static Builder newBuilder() {
>> +        return new Builder();
>> +    }
>> +
>>      private static final Logger LOGGER = StatusLogger.getLogger();
>>
>>      private final String pattern;
>> @@ -90,11 +132,12 @@ public final class Routes {
>>       * @param pattern The pattern.
>>       * @param routes An array of Route elements.
>>       * @return The Routes container.
>> +     * @deprecated since 2.7; use {@link #newBuilder()}.
>>       */
>> -    @PluginFactory
>> +    @Deprecated
>>      public static Routes createRoutes(
>> -            @PluginAttribute("pattern") final String pattern,
>> -            @PluginElement("Routes") final Route... routes) {
>> +            final String pattern,
>> +            final Route... routes) {
>>          if (routes == null || routes.length == 0) {
>>              LOGGER.error("No routes configured");
>>              return null;
>>
>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
Matt Sicker <bo...@gmail.com>

Re: [2/2] logging-log4j2 git commit: Deprecate factory method in favor of a builder.

Posted by Gary Gregory <ga...@gmail.com>.
Good to know, I'll add that. But... we still need the check in the builders
for programmatic configurations.

Gary

On Tue, Sep 13, 2016 at 9:11 PM, Matt Sicker <bo...@gmail.com> wrote:

> If you use @Required on an array, it checks for non-null and non-empty.
> Works on strings, collections, and maps with the same semantics.
>
> ---------- Forwarded message ----------
> From: <gg...@apache.org>
> Date: 13 September 2016 at 22:59
> Subject: [2/2] logging-log4j2 git commit: Deprecate factory method in
> favor of a builder.
> To: commits@logging.apache.org
>
>
> Deprecate factory method in favor of a builder.
>
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit
> /3846e2a8
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3846e2a8
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3846e2a8
>
> Branch: refs/heads/master
> Commit: 3846e2a87b94639466c7ab25b333fdb4ded8defc
> Parents: 981677f
> Author: Gary Gregory <gg...@apache.org>
> Authored: Tue Sep 13 20:58:56 2016 -0700
> Committer: Gary Gregory <gg...@apache.org>
> Committed: Tue Sep 13 20:58:56 2016 -0700
>
> ----------------------------------------------------------------------
>  .../log4j/core/appender/routing/Routes.java     | 51 ++++++++++++++++++--
>  1 file changed, 47 insertions(+), 4 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3
> 846e2a8/log4j-core/src/main/java/org/apache/logging/log4j/co
> re/appender/routing/Routes.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/app
> ender/routing/Routes.java
> index aae4087..c95b64a 100644
> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/app
> ender/routing/Routes.java
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/app
> ender/routing/Routes.java
> @@ -21,8 +21,8 @@ import java.util.Objects;
>  import org.apache.logging.log4j.Logger;
>  import org.apache.logging.log4j.core.config.plugins.Plugin;
>  import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
> +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
>  import org.apache.logging.log4j.core.config.plugins.PluginElement;
> -import org.apache.logging.log4j.core.config.plugins.PluginFactory;
>  import org.apache.logging.log4j.status.StatusLogger;
>
>  /**
> @@ -31,6 +31,48 @@ import org.apache.logging.log4j.status.StatusLogger;
>  @Plugin(name = "Routes", category = "Core", printObject = true)
>  public final class Routes {
>
> +    public static class Builder implements org.apache.logging.log4j.core.util.Builder<Routes>
> {
> +
> +        @PluginAttribute("pattern")
> +        private String pattern;
> +
> +        @PluginElement("Routes")
> +        private Route[] routes;
> +
> +        @Override
> +        public Routes build() {
> +            if (routes == null || routes.length == 0) {
> +                LOGGER.error("No routes configured");
> +                return null;
> +            }
> +            return new Routes(pattern, routes);
> +        }
> +
> +        public String getPattern() {
> +            return pattern;
> +        }
> +
> +        public Route[] getRoutes() {
> +            return routes;
> +        }
> +
> +        public Builder withPattern(@SuppressWarnings("hiding") String
> pattern) {
> +            this.pattern = pattern;
> +            return this;
> +        }
> +
> +        public Builder withRoutes(@SuppressWarnings("hiding") Route[]
> routes) {
> +            this.routes = routes;
> +            return this;
> +        }
> +
> +    }
> +
> +    @PluginBuilderFactory
> +    public static Builder newBuilder() {
> +        return new Builder();
> +    }
> +
>      private static final Logger LOGGER = StatusLogger.getLogger();
>
>      private final String pattern;
> @@ -90,11 +132,12 @@ public final class Routes {
>       * @param pattern The pattern.
>       * @param routes An array of Route elements.
>       * @return The Routes container.
> +     * @deprecated since 2.7; use {@link #newBuilder()}.
>       */
> -    @PluginFactory
> +    @Deprecated
>      public static Routes createRoutes(
> -            @PluginAttribute("pattern") final String pattern,
> -            @PluginElement("Routes") final Route... routes) {
> +            final String pattern,
> +            final Route... routes) {
>          if (routes == null || routes.length == 0) {
>              LOGGER.error("No routes configured");
>              return null;
>
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Fwd: [2/2] logging-log4j2 git commit: Deprecate factory method in favor of a builder.

Posted by Matt Sicker <bo...@gmail.com>.
If you use @Required on an array, it checks for non-null and non-empty.
Works on strings, collections, and maps with the same semantics.

---------- Forwarded message ----------
From: <gg...@apache.org>
Date: 13 September 2016 at 22:59
Subject: [2/2] logging-log4j2 git commit: Deprecate factory method in favor
of a builder.
To: commits@logging.apache.org


Deprecate factory method in favor of a builder.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/
commit/3846e2a8
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3846e2a8
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3846e2a8

Branch: refs/heads/master
Commit: 3846e2a87b94639466c7ab25b333fdb4ded8defc
Parents: 981677f
Author: Gary Gregory <gg...@apache.org>
Authored: Tue Sep 13 20:58:56 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Tue Sep 13 20:58:56 2016 -0700

----------------------------------------------------------------------
 .../log4j/core/appender/routing/Routes.java     | 51 ++++++++++++++++++--
 1 file changed, 47 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/
3846e2a8/log4j-core/src/main/java/org/apache/logging/log4j/
core/appender/routing/Routes.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/
appender/routing/Routes.java
index aae4087..c95b64a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/
appender/routing/Routes.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/
appender/routing/Routes.java
@@ -21,8 +21,8 @@ import java.util.Objects;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.status.StatusLogger;

 /**
@@ -31,6 +31,48 @@ import org.apache.logging.log4j.status.StatusLogger;
 @Plugin(name = "Routes", category = "Core", printObject = true)
 public final class Routes {

+    public static class Builder implements
org.apache.logging.log4j.core.util.Builder<Routes>
{
+
+        @PluginAttribute("pattern")
+        private String pattern;
+
+        @PluginElement("Routes")
+        private Route[] routes;
+
+        @Override
+        public Routes build() {
+            if (routes == null || routes.length == 0) {
+                LOGGER.error("No routes configured");
+                return null;
+            }
+            return new Routes(pattern, routes);
+        }
+
+        public String getPattern() {
+            return pattern;
+        }
+
+        public Route[] getRoutes() {
+            return routes;
+        }
+
+        public Builder withPattern(@SuppressWarnings("hiding") String
pattern) {
+            this.pattern = pattern;
+            return this;
+        }
+
+        public Builder withRoutes(@SuppressWarnings("hiding") Route[]
routes) {
+            this.routes = routes;
+            return this;
+        }
+
+    }
+
+    @PluginBuilderFactory
+    public static Builder newBuilder() {
+        return new Builder();
+    }
+
     private static final Logger LOGGER = StatusLogger.getLogger();

     private final String pattern;
@@ -90,11 +132,12 @@ public final class Routes {
      * @param pattern The pattern.
      * @param routes An array of Route elements.
      * @return The Routes container.
+     * @deprecated since 2.7; use {@link #newBuilder()}.
      */
-    @PluginFactory
+    @Deprecated
     public static Routes createRoutes(
-            @PluginAttribute("pattern") final String pattern,
-            @PluginElement("Routes") final Route... routes) {
+            final String pattern,
+            final Route... routes) {
         if (routes == null || routes.length == 0) {
             LOGGER.error("No routes configured");
             return null;




-- 
Matt Sicker <bo...@gmail.com>