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 ve...@apache.org on 2012/01/02 15:06:37 UTC

svn commit: r1226426 - in /axis/axis1/java/trunk: axis-maven-plugin/ axis-maven-plugin/src/main/java/org/apache/axis/maven/ axis-maven-plugin/src/main/resources/ axis-maven-plugin/src/main/resources/META-INF/ axis-maven-plugin/src/main/resources/META-I...

Author: veithen
Date: Mon Jan  2 14:06:36 2012
New Revision: 1226426

URL: http://svn.apache.org/viewvc?rev=1226426&view=rev
Log:
Very early code to start/stop SimpleAxisServer (in a separate JVM) using Maven.

Added:
    axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/AbstractServerMojo.java   (with props)
    axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java   (with props)
    axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/Server.java   (with props)
    axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/ServerManager.java   (with props)
    axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java   (with props)
    axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StopServerMojo.java   (with props)
    axis/axis1/java/trunk/axis-maven-plugin/src/main/resources/
    axis/axis1/java/trunk/axis-maven-plugin/src/main/resources/META-INF/
    axis/axis1/java/trunk/axis-maven-plugin/src/main/resources/META-INF/plexus/
    axis/axis1/java/trunk/axis-maven-plugin/src/main/resources/META-INF/plexus/components.xml   (with props)
Modified:
    axis/axis1/java/trunk/axis-maven-plugin/pom.xml
    axis/axis1/java/trunk/integration/pom.xml

Modified: axis/axis1/java/trunk/axis-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-maven-plugin/pom.xml?rev=1226426&r1=1226425&r2=1226426&view=diff
==============================================================================
--- axis/axis1/java/trunk/axis-maven-plugin/pom.xml (original)
+++ axis/axis1/java/trunk/axis-maven-plugin/pom.xml Mon Jan  2 14:06:36 2012
@@ -44,6 +44,11 @@
             <artifactId>maven-project</artifactId>
             <version>${maven.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-toolchain</artifactId>
+            <version>1.0</version>
+        </dependency>
     </dependencies>
     <properties>
         <maven.version>2.0.9</maven.version>

Added: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/AbstractServerMojo.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/AbstractServerMojo.java?rev=1226426&view=auto
==============================================================================
--- axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/AbstractServerMojo.java (added)
+++ axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/AbstractServerMojo.java Mon Jan  2 14:06:36 2012
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis.maven;
+
+import org.apache.maven.plugin.AbstractMojo;
+
+public abstract class AbstractServerMojo extends AbstractMojo {
+    /**
+     * The port of the Axis server.
+     * 
+     * @parameter default-value="8080"
+     * @required
+     */
+    private int port;
+    
+    /**
+     * @component
+     */
+    private ServerManager serverManager;
+
+    public int getPort() {
+        return port;
+    }
+
+    public ServerManager getServerManager() {
+        return serverManager;
+    }
+}

Propchange: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/AbstractServerMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java?rev=1226426&view=auto
==============================================================================
--- axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java (added)
+++ axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java Mon Jan  2 14:06:36 2012
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis.maven;
+
+import java.io.File;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.axis.client.AdminClient;
+import org.codehaus.plexus.util.StringUtils;
+
+public class DefaultServerManager implements ServerManager {
+    private final Map servers = new HashMap();
+
+    public void startServer(String jvm, String[] classpath, int port) throws Exception {
+        AdminClient adminClient = new AdminClient(true);
+        adminClient.setTargetEndpointAddress(new URL("http://localhost:" + port + "/axis/services/AdminService"));
+        Process process = Runtime.getRuntime().exec(new String[] {
+                jvm,
+                "-cp",
+                StringUtils.join(classpath, File.pathSeparator),
+                "org.apache.axis.transport.http.SimpleAxisServer",
+                "-p",
+                String.valueOf(port)
+        });
+        servers.put(Integer.valueOf(port), new Server(process, adminClient));
+        // TODO: need to set up stdout/stderr forwarding; otherwise the process will hang
+        // TODO: need to ping the server and wait until it becomes ready
+        Thread.sleep(5000);
+    }
+    
+    public void stopServer(int port) throws Exception {
+        Server server = (Server)servers.remove(Integer.valueOf(port));
+        server.getAdminClient().quit();
+        server.getProcess().waitFor();
+    }
+}

Propchange: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/Server.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/Server.java?rev=1226426&view=auto
==============================================================================
--- axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/Server.java (added)
+++ axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/Server.java Mon Jan  2 14:06:36 2012
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis.maven;
+
+import org.apache.axis.client.AdminClient;
+
+public class Server {
+    private final Process process;
+    private final AdminClient adminClient;
+
+    public Server(Process process, AdminClient adminClient) {
+        this.process = process;
+        this.adminClient = adminClient;
+    }
+
+    public Process getProcess() {
+        return process;
+    }
+
+    public AdminClient getAdminClient() {
+        return adminClient;
+    }
+}

Propchange: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/Server.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/ServerManager.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/ServerManager.java?rev=1226426&view=auto
==============================================================================
--- axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/ServerManager.java (added)
+++ axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/ServerManager.java Mon Jan  2 14:06:36 2012
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis.maven;
+
+public interface ServerManager {
+    void startServer(String jvm, String[] classpath, int port) throws Exception;
+    void stopServer(int port) throws Exception;
+}

Propchange: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/ServerManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java?rev=1226426&view=auto
==============================================================================
--- axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java (added)
+++ axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java Mon Jan  2 14:06:36 2012
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis.maven;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.axis.transport.http.SimpleAxisServer;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.ToolchainManager;
+
+/**
+ * Start a {@link SimpleAxisServer} instance in a separate JVM.
+ * 
+ * @goal start-server
+ * @phase pre-integration-test
+ * @requiresDependencyResolution test
+ */
+public class StartServerMojo extends AbstractServerMojo {
+    /**
+     * The maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+    
+    /**
+     * The current build session instance. This is used for toolchain manager API calls.
+     * 
+     * @parameter default-value="${session}"
+     * @required
+     * @readonly
+     */
+    private MavenSession session;
+    
+    /**
+     * @component
+     */
+    private ToolchainManager toolchainManager;
+    
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        String executable;
+        Toolchain tc = toolchainManager.getToolchainFromBuildContext("jdk", session);
+        if (tc != null) {
+            executable = tc.findTool("java");
+        } else {
+            executable = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
+        }
+        getLog().debug("Java executable: " + executable);
+        List classPathElements;
+        try {
+            classPathElements = project.getTestClasspathElements();
+        } catch (DependencyResolutionRequiredException ex) {
+            throw new MojoExecutionException("Unexpected exception", ex);
+        }
+        getLog().debug("Class path elements: " + classPathElements);
+        try {
+            getServerManager().startServer(executable, (String[])classPathElements.toArray(new String[classPathElements.size()]), getPort());
+        } catch (Exception ex) {
+            throw new MojoFailureException("Failed to start server", ex);
+        }
+    }
+}

Propchange: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StopServerMojo.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StopServerMojo.java?rev=1226426&view=auto
==============================================================================
--- axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StopServerMojo.java (added)
+++ axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StopServerMojo.java Mon Jan  2 14:06:36 2012
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis.maven;
+
+import org.apache.axis.transport.http.SimpleAxisServer;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Stop a {@link SimpleAxisServer} instance.
+ * 
+ * @goal stop-server
+ * @phase post-integration-test
+ */
+public class StopServerMojo extends AbstractServerMojo {
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        try {
+            getServerManager().stopServer(getPort());
+        } catch (Exception ex) {
+            throw new MojoFailureException("Failed to stop server", ex);
+        }
+    }
+}

Propchange: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StopServerMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: axis/axis1/java/trunk/axis-maven-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-maven-plugin/src/main/resources/META-INF/plexus/components.xml?rev=1226426&view=auto
==============================================================================
--- axis/axis1/java/trunk/axis-maven-plugin/src/main/resources/META-INF/plexus/components.xml (added)
+++ axis/axis1/java/trunk/axis-maven-plugin/src/main/resources/META-INF/plexus/components.xml Mon Jan  2 14:06:36 2012
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License. You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied. See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<component-set>
+    <components>
+        <component>
+            <role>org.apache.axis.maven.ServerManager</role>
+            <implementation>org.apache.axis.maven.DefaultServerManager</implementation>
+        </component>
+    </components>
+</component-set>
\ No newline at end of file

Propchange: axis/axis1/java/trunk/axis-maven-plugin/src/main/resources/META-INF/plexus/components.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: axis/axis1/java/trunk/integration/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/integration/pom.xml?rev=1226426&r1=1226425&r2=1226426&view=diff
==============================================================================
--- axis/axis1/java/trunk/integration/pom.xml (original)
+++ axis/axis1/java/trunk/integration/pom.xml Mon Jan  2 14:06:36 2012
@@ -89,6 +89,18 @@
                             </mappings>
                         </configuration>
                     </execution>
+                    <execution>
+                        <id>start-server</id>
+                        <goals>
+                            <goal>start-server</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>stop-server</id>
+                        <goals>
+                            <goal>stop-server</goal>
+                        </goals>
+                    </execution>
                 </executions>
             </plugin>
             <plugin>