onami-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1503141 - in /onami/sandbox/console/src/main/java/org/apache/onami/console: OnamiConsole.java commands/Version.java
Date Mon, 15 Jul 2013 08:53:30 GMT
Author: simonetripodi
Date: Mon Jul 15 08:53:30 2013
New Revision: 1503141

URL: http://svn.apache.org/r1503141
Log:
demonstrate the @Inject potentialities via the Version command, where properties are just
injected and not manually discovered

Modified:
    onami/sandbox/console/src/main/java/org/apache/onami/console/OnamiConsole.java
    onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Version.java

Modified: onami/sandbox/console/src/main/java/org/apache/onami/console/OnamiConsole.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/OnamiConsole.java?rev=1503141&r1=1503140&r2=1503141&view=diff
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/OnamiConsole.java (original)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/OnamiConsole.java Mon Jul
15 08:53:30 2013
@@ -19,16 +19,14 @@ package org.apache.onami.console;
  * under the License.
  */
 
-import static java.lang.System.out;
 import static java.lang.System.getProperty;
-
-import org.apache.onami.console.commands.ConsoleRunner;
-import org.apache.onami.console.commands.Version;
-
+import static java.lang.System.out;
 import io.airlift.command.Cli;
 import io.airlift.command.Help;
 import io.airlift.command.ParseArgumentsUnexpectedException;
 
+import org.apache.onami.console.commands.ConsoleRunner;
+
 public final class OnamiConsole
 {
 
@@ -42,7 +40,6 @@ public final class OnamiConsole
             Cli.<Runnable> builder( getProperty( "app.name" ) )
                .withCommand( Help.class )
                .withCommand( ConsoleRunner.class )
-               .withCommand( Version.class )
                .withDefaultCommand( Help.class )
                .build()
                .parse( args )

Modified: onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Version.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Version.java?rev=1503141&r1=1503140&r2=1503141&view=diff
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Version.java (original)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Version.java Mon
Jul 15 08:53:30 2013
@@ -19,38 +19,135 @@ package org.apache.onami.console.command
  * under the License.
  */
 
-import static java.lang.System.getProperty;
-import static java.lang.System.out;
 import io.airlift.command.Command;
 
+import org.apache.onami.logging.core.InjectLogger;
+import org.slf4j.Logger;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+
 @Command( name = "version", description = "Display version information." )
 public final class Version
     implements Runnable
 {
 
+    @InjectLogger
+    private Logger logger;
+
+    @Inject
+    @Named( "project.version" )
+    private String projectVersion;
+
+    @Inject
+    @Named( "java.version" )
+    private String javaVersion;
+
+    @Inject
+    @Named( "java.vendor" )
+    private String javaVendor;
+
+    @Inject
+    @Named( "java.home" )
+    private String javaHome;
+
+    @Inject
+    @Named( "user.language" )
+    private String userLanguage;
+
+    @Inject
+    @Named( "user.country" )
+    private String userCountry;
+
+    @Inject
+    @Named( "sun.jnu.encoding" )
+    private String encoding;
+
+    @Inject
+    @Named( "os.name" )
+    private String osName;
+
+    @Inject
+    @Named( "os.version" )
+    private String osVersion;
+
+    @Inject
+    @Named( "os.arch" )
+    private String osArch;
+
+    @Inject
+    @Named( "path.separator" )
+    private String pathSeparathor;
+
+    public void setProjectVersion( String projectVersion )
+    {
+        this.projectVersion = projectVersion;
+    }
+
+    public void setJavaVersion( String javaVersion )
+    {
+        this.javaVersion = javaVersion;
+    }
+
+    public void setJavaVendor( String javaVendor )
+    {
+        this.javaVendor = javaVendor;
+    }
+
+    public void setJavaHome( String javaHome )
+    {
+        this.javaHome = javaHome;
+    }
+
+    public void setUserLanguage( String userLanguage )
+    {
+        this.userLanguage = userLanguage;
+    }
+
+    public void setUserCountry( String userCountry )
+    {
+        this.userCountry = userCountry;
+    }
+
+    public void setEncoding( String encoding )
+    {
+        this.encoding = encoding;
+    }
+
+    public void setOsName( String osName )
+    {
+        this.osName = osName;
+    }
+
+    public void setOsVersion( String osVersion )
+    {
+        this.osVersion = osVersion;
+    }
+
+    public void setOsArch( String osArch )
+    {
+        this.osArch = osArch;
+    }
+
+    public void setPathSeparathor( String pathSeparathor )
+    {
+        this.pathSeparathor = pathSeparathor;
+    }
+
     public void run()
     {
-        out.printf( "Apache Onami-Console %s%n",
-                    getProperty( "project.version" ) );
-        out.printf( "Java version: %s, vendor: %s%n",
-                    getProperty( "java.version" ),
-                    getProperty( "java.vendor" ) );
-        out.printf( "Java home: %s%n", getProperty( "java.home" ) );
-        out.printf( "Default locale: %s_%s, platform encoding: %s%n",
-                    getProperty( "user.language" ),
-                    getProperty( "user.country" ),
-                    getProperty( "sun.jnu.encoding" ) );
-        out.printf( "OS name: \"%s\", version: \"%s\", arch: \"%s\", family: \"%s\"%n",
-                    getProperty( "os.name" ),
-                    getProperty( "os.version" ),
-                    getProperty( "os.arch" ),
-                    getOsFamily() );
+        logger.info( "Apache Onami Console {}", projectVersion );
+        logger.info( "Java version: {}, vendor: {}", javaVersion, javaVendor );
+        logger.info( "Java home: {}", javaHome );
+        logger.info( "Default locale: {}_{}, platform encoding: {}",
+                     userLanguage, userCountry, encoding );
+        logger.info( "OS name: \"{}\", version: \"{}\", arch: \"{}\", family: \"{}\"",
+                     osName, osVersion, osArch, getOsFamily() );
     }
 
-    private static final String getOsFamily()
+    private String getOsFamily()
     {
-        String osName = getProperty( "os.name" ).toLowerCase();
-        String pathSep = getProperty( "path.separator" );
+        String osName = this.osName.toLowerCase();
 
         if ( osName.indexOf( "windows" ) != -1 )
         {
@@ -68,7 +165,7 @@ public final class Version
         {
             return "os/400";
         }
-        else if ( pathSep.equals( ";" ) )
+        else if ( pathSeparathor.equals( ";" ) )
         {
             return "dos";
         }
@@ -88,7 +185,7 @@ public final class Version
         {
             return "openvms";
         }
-        else if ( pathSep.equals( ":" ) )
+        else if ( pathSeparathor.equals( ":" ) )
         {
             return "unix";
         }



Mime
View raw message