You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by sa...@apache.org on 2012/05/03 15:01:48 UTC

svn commit: r1333444 - in /axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server: SimpleHttpServerMojo.java util/Axis2Server.java util/Constants.java util/RepoHelper.java

Author: sagara
Date: Thu May  3 13:01:47 2012
New Revision: 1333444

URL: http://svn.apache.org/viewvc?rev=1333444&view=rev
Log:
* For simple server Maven plug- in  Added support to look-up axis2 configuration from a default location (resources/axis2.xml  ). 
* Redirect  info and error messages to Maven log. 
* Improve code quality.

Modified:
    axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/SimpleHttpServerMojo.java
    axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/Axis2Server.java
    axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/Constants.java
    axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/RepoHelper.java

Modified: axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/SimpleHttpServerMojo.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/SimpleHttpServerMojo.java?rev=1333444&r1=1333443&r2=1333444&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/SimpleHttpServerMojo.java (original)
+++ axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/SimpleHttpServerMojo.java Thu May  3 13:01:47 2012
@@ -20,7 +20,6 @@ import java.io.File;
 import java.net.MalformedURLException;
 
 import org.apache.axis2.maven2.server.util.Axis2Server;
-import org.apache.axis2.maven2.server.util.Constants;
 import org.apache.axis2.maven2.server.util.RepoHelper;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -29,6 +28,13 @@ import org.codehaus.plexus.classworlds.C
 import org.codehaus.plexus.classworlds.realm.ClassRealm;
 import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
 
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_PORT;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_CLASSES_DIRECTORY;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_TEST_CLASSES_DIRECTORY;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_REPO_LOCATION;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_CONF_DIR;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_CONF_FILE_NAME;
+
 /**
  * Run simple Axis 2Server.
  * 
@@ -136,7 +142,7 @@ public class SimpleHttpServerMojo extend
    
 
     public RepoHelper getRepoHelper() {
-        RepoHelper repoHelper = new RepoHelper(repoPath);
+        RepoHelper repoHelper = new RepoHelper(repoPath, getLog());
         if (stdServiceSrcDir != null) {
             repoHelper.setStdServiceSrcDir(stdServiceSrcDir);
         }
@@ -166,8 +172,8 @@ public class SimpleHttpServerMojo extend
             getLog().info("conf path : " + confPath);
             getRepoHelper().prepareRepostory();
             extendClassLoader();
-            String serverPort = port == null ? Constants.DEFAULT_PORT : port;
-            server = Axis2Server.newInstance(repoPath, confPath, serverPort );
+            String serverPort = port == null ? DEFAULT_PORT : port;            
+            server = Axis2Server.newInstance(repoPath, checkFordefaultConfFile(confPath), serverPort, getLog());
             if (fork) {
                 new Thread(new Runnable() {
                     public void run() {
@@ -194,8 +200,8 @@ public class SimpleHttpServerMojo extend
             realm = world.newRealm("maven.plugin." + getClass().getSimpleName(), Thread
                     .currentThread().getContextClassLoader());
         }
-        File cls = new File(buildDir + File.separator + Constants.DEFAULT_CLASSES_DIRECTORY);
-        File testCls = new File(buildDir + File.separator + Constants.DEFAULT_TEST_CLASSES_DIRECTORY);
+        File cls = new File(buildDir + File.separator + DEFAULT_CLASSES_DIRECTORY);
+        File testCls = new File(buildDir + File.separator + DEFAULT_TEST_CLASSES_DIRECTORY);
         realm.addURL(cls.toURI().toURL());
         realm.addURL(testCls.toURI().toURL());
         Thread.currentThread().setContextClassLoader(realm);
@@ -225,5 +231,15 @@ public class SimpleHttpServerMojo extend
         getLog().info("Axis2 Simple HTTP server stoped ");
 
     }
+    
+    private String checkFordefaultConfFile(String inPath) {
+        if (inPath != null) {
+            return inPath;
+        } else {
+            String path = repoPath != null ? repoPath : DEFAULT_REPO_LOCATION;
+            return path + File.separator + DEFAULT_CONF_DIR + File.separator
+                    + DEFAULT_CONF_FILE_NAME;
+        }
+    }
 
 }

Modified: axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/Axis2Server.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/Axis2Server.java?rev=1333444&r1=1333443&r2=1333444&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/Axis2Server.java (original)
+++ axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/Axis2Server.java Thu May  3 13:01:47 2012
@@ -20,6 +20,11 @@ import org.apache.axis2.AxisFault;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.TransportInDescription;
 import org.apache.axis2.transport.SimpleAxis2Server;
+import org.apache.maven.plugin.logging.Log;
+
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_REPO_LOCATION;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_PORT_PARAM;
+
 
 /**
  * The Class Axis2Server.
@@ -29,6 +34,7 @@ import org.apache.axis2.transport.Simple
 public class Axis2Server extends SimpleAxis2Server {
 
     private static Axis2Server server;
+    private static Log log;
 
     /**
      * Create new instance of Axis2Server.
@@ -36,12 +42,14 @@ public class Axis2Server extends SimpleA
      * @param repoPath the repo path
      * @param confPath the conf path
      * @param port the port
+     * @param log 
      * @return the axis2 server
      */
-    public static Axis2Server newInstance(String repoPath, String confPath, String port) {
+    public static Axis2Server newInstance(String repoPath, String confPath, String port, Log mavenLog) {
         try {
+            log = mavenLog;
             if (repoPath == null) {
-                repoPath = Constants.DEFAULT_REPO_LOCATION;
+                repoPath = DEFAULT_REPO_LOCATION;
             }
             server = new Axis2Server(repoPath, confPath);
             if (confPath == null) {
@@ -50,13 +58,13 @@ public class Axis2Server extends SimpleA
                  * not specify any port use 8080 as HTTP port.
                  */
                 Parameter parameter = new Parameter();
-                parameter.setName(Constants.DEFAULT_PORT_PARAM);
+                parameter.setName(DEFAULT_PORT_PARAM);
                 parameter.setValue(port);
                 ((TransportInDescription) server.getConfigurationContext().getAxisConfiguration()
                         .getTransportIn("http")).addParameter(parameter);
             }
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e);
         }
         return server;
     }
@@ -68,7 +76,7 @@ public class Axis2Server extends SimpleA
      * @param confPath the conf path
      * @throws Exception the exception
      */
-    private Axis2Server(String repoPath, String confPath) throws Exception {
+    private Axis2Server(String repoPath, String confPath) throws Exception {       
         super(repoPath, confPath);
         server = null;
     }
@@ -80,7 +88,7 @@ public class Axis2Server extends SimpleA
         try {
             server.start();
         } catch (AxisFault e) {
-            e.printStackTrace();
+            log.error(e);
         }
     }
 
@@ -91,7 +99,7 @@ public class Axis2Server extends SimpleA
         try {
             server.stop();
         } catch (AxisFault e) {
-            e.printStackTrace();
+            log.error(e);            
         }
     }
 

Modified: axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/Constants.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/Constants.java?rev=1333444&r1=1333443&r2=1333444&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/Constants.java (original)
+++ axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/Constants.java Thu May  3 13:01:47 2012
@@ -58,5 +58,14 @@ public class Constants {
     
     /** The Constant DEFAULT_PORT. */
     public static final String DEFAULT_PORT = "8080";
+    
+    /** The Constant  DEFAULT_CONF_SRC_DIR. */
+    public static final String DEFAULT_CONF_SRC_DIR = "src/main/resources";
+    
+    /** The Constant  DEFAULT_CONF_DIR. */
+    public static final String DEFAULT_CONF_DIR = "conf";
+    
+    /** The Constant  DEFAULT_CONF_FILE_NAME. */
+    public static final String DEFAULT_CONF_FILE_NAME = "axis2.xml";
 
 }

Modified: axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/RepoHelper.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/RepoHelper.java?rev=1333444&r1=1333443&r2=1333444&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/RepoHelper.java (original)
+++ axis/axis2/java/core/trunk/modules/tool/simple-server-maven-plugin/src/main/java/org/apache/axis2/maven2/server/util/RepoHelper.java Thu May  3 13:01:47 2012
@@ -23,6 +23,18 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.maven.plugin.logging.Log;
+
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_REPO_LOCATION;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_STD_SERVICE_DIRECTORY;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_JAX_WS_SERVICE_DIRECTORY;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_MODULE_REPO_DIRECTORY;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_JAX_WS_SERVICE_SRC_DIRECTORY;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_STD_SERVICE_SRC_DIRECTORY;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_CONF_DIR;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_CONF_FILE_NAME;
+import static org.apache.axis2.maven2.server.util.Constants.DEFAULT_CONF_SRC_DIR;
+
 /**
  * The Class RepoHelper is utility that deal with repo creation.
  * 
@@ -58,6 +70,8 @@ public class RepoHelper {
     private boolean jaxwsService = false;
     
     private int dataBufferSize;
+    
+    private Log log;
 
     public int getDataBufferSize() {
 		return dataBufferSize;
@@ -186,9 +200,11 @@ public class RepoHelper {
      * 
      * @param repoLocation
      *            the repo location
+     * @param log 
      */
-    public RepoHelper(String repoLocation) {
-        this.repoLocation = repoLocation == null ? Constants.DEFAULT_REPO_LOCATION : repoLocation;
+    public RepoHelper(String repoLocation, Log log) {
+        this.repoLocation = repoLocation == null ? DEFAULT_REPO_LOCATION : repoLocation;
+        this.log = log;
         initialize();
 
     }
@@ -210,12 +226,12 @@ public class RepoHelper {
      */
     private void initialize() {
         this.stdServiceDir = repoLocation + File.separator
-                + Constants.DEFAULT_STD_SERVICE_DIRECTORY;
+                + DEFAULT_STD_SERVICE_DIRECTORY;
         this.jaxwsServiceDir = repoLocation + File.separator
-                + Constants.DEFAULT_JAX_WS_SERVICE_DIRECTORY;
-        this.moduleDir = repoLocation + File.separator + Constants.DEFAULT_MODULE_REPO_DIRECTORY;
-        this.stdServiceSrcDir = Constants.DEFAULT_STD_SERVICE_SRC_DIRECTORY;
-        this.jaxwsServiceSrcDir = Constants.DEFAULT_JAX_WS_SERVICE_SRC_DIRECTORY;
+                + DEFAULT_JAX_WS_SERVICE_DIRECTORY;
+        this.moduleDir = repoLocation + File.separator + DEFAULT_MODULE_REPO_DIRECTORY;
+        this.stdServiceSrcDir = DEFAULT_STD_SERVICE_SRC_DIRECTORY;
+        this.jaxwsServiceSrcDir = DEFAULT_JAX_WS_SERVICE_SRC_DIRECTORY;
     }
 
     /**
@@ -231,7 +247,8 @@ public class RepoHelper {
             copyStdServices();
         }
         copyModules();
-    }
+        copyConfFile();
+    }   
 
     /**
      * Copy modules.
@@ -305,11 +322,13 @@ public class RepoHelper {
         File stdServiceFile = new File(stdServiceDir);
         File jaxwsServiceFile = new File(jaxwsServiceDir);
         File moduleFile = new File(moduleDir);
+        File confDir = new File(repoLocation+ File.separator+ DEFAULT_CONF_DIR);
         boolean success = stdServiceFile.mkdirs();
         success = jaxwsServiceFile.mkdirs();
         success = moduleFile.mkdirs();
+        success = confDir.mkdir();
         if (success) {
-            System.out.println("Service directories created");
+            log.info("Service directories created");
         }
     }
 
@@ -351,5 +370,15 @@ public class RepoHelper {
             out.close();
         }
     }
+    
+    private void copyConfFile() throws IOException {
+        // TODO At the moment it assume axis2.xml available on 
+        // top level of the resources directory but this should 
+        // find axis2.file any where on resource directory. 
+        File srcFile = new File(DEFAULT_CONF_SRC_DIR + File.separator + DEFAULT_CONF_FILE_NAME);
+        File desFile = new File(repoLocation + File.separator + DEFAULT_CONF_DIR + File.separator + DEFAULT_CONF_FILE_NAME);
+        copyDirectory(srcFile, desFile, getDataBufferSize());
+        
+    }
 
 }