You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2008/09/22 19:02:03 UTC
svn commit: r697899 [2/2] - in
/openejb/trunk/sandbox/openejb-eclipse-plugin: assembly/
assembly/src/main/assembly/ features/org.apache.openejb.feature/ plugins/
plugins/org.apache.openejb.server/
plugins/org.apache.openejb.server/META-INF/ plugins/org...
Added: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/java/org/apache/openejb/eclipse/server/OpenEJBServerBehaviour.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/java/org/apache/openejb/eclipse/server/OpenEJBServerBehaviour.java?rev=697899&view=auto
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/java/org/apache/openejb/eclipse/server/OpenEJBServerBehaviour.java (added)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/java/org/apache/openejb/eclipse/server/OpenEJBServerBehaviour.java Mon Sep 22 10:02:02 2008
@@ -0,0 +1,304 @@
+/*
+ * 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.openejb.eclipse.server;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jst.j2ee.application.internal.operations.EARComponentExportDataModelProvider;
+import org.eclipse.jst.j2ee.ejb.datamodel.properties.IEJBComponentExportDataModelProperties;
+import org.eclipse.jst.j2ee.internal.ejb.project.operations.EJBComponentExportDataModelProvider;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
+
+public class OpenEJBServerBehaviour extends ServerBehaviourDelegate {
+
+ @SuppressWarnings("serial")
+ public class ServerStoppedException extends Exception {
+ }
+
+ private class ServerMonitor extends Thread {
+
+ private static final int ONE_SECOND = 1000;
+ private boolean running = false;
+ private int adminPort = getAdminPort();
+
+ @Override
+ public void run() {
+ while (true) {
+ try {
+ Thread.sleep(ONE_SECOND);
+ } catch (Exception e) {
+ }
+
+ try {
+ check();
+ } catch (ServerStoppedException e) {
+ // break out the loop and stop monitoring
+ // a restart will start a new monitor
+ break;
+ }
+ }
+ }
+
+ private void check() throws ServerStoppedException {
+ // connect to admin interface
+ try {
+ Socket socket = new Socket("localhost", adminPort);
+ socket.close();
+
+ // update the server status if this is first time we've connected
+ if (! running) {
+ running = true;
+ setState(IServer.STATE_STARTED);
+
+ // republish everything
+ doFullPublish();
+ }
+ } catch (IOException e) {
+ if (running) {
+ // looks like server has started successfully, but has died
+ setServerState(IServer.STATE_STOPPED);
+ running = false;
+ cleanup();
+ throw new ServerStoppedException();
+ }
+ // server might not be started yet
+ }
+ // if success, server is running
+ }
+
+ public void terminate() {
+ this.interrupt();
+ }
+
+ public ServerMonitor() {
+ super();
+ }
+ }
+
+ private ServerMonitor monitor;
+ private Map<IModule, String> publishedModules = new HashMap<IModule, String>();
+
+ private int getAdminPort() {
+ try {
+ OpenEJBServer openEJBServer = (OpenEJBServer) (getServer().getAdapter(OpenEJBServer.class));
+ return Integer.parseInt(openEJBServer.getAdminPort());
+ } catch (NumberFormatException e) {
+ return 4200;
+ }
+ }
+
+ private int getEJBDPort() {
+ try {
+ OpenEJBServer openEJBServer = (OpenEJBServer) (getServer().getAdapter(OpenEJBServer.class));
+ return Integer.parseInt(openEJBServer.getEJBPort());
+ } catch (NumberFormatException e) {
+ return 4201;
+ }
+ }
+
+ @Override
+ public void stop(boolean force) {
+ stopServer();
+ }
+
+ /*
+ * @see org.apache.openejb.server.admin.AdminDaemon.service(Socket socket)
+ */
+ private void stopServer() {
+ // connect to admin interface, and send 'Q' to stop the server
+ try {
+ Socket socket = new Socket("localhost", getAdminPort());
+ socket.getOutputStream().write('Q');
+ socket.close();
+
+ setState(IServer.STATE_STOPPING);
+ } catch (IOException e) {
+ // we're really stuck
+ }
+ }
+
+
+ @Override
+ public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProgressMonitor monitor) throws CoreException {
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.apache.openejb.cli.Bootstrap");
+
+ OpenEJBRuntimeDelegate runtime = getRuntimeDelegate();
+ OpenEJBServer openejbServer = (OpenEJBServer) (getServer().getAdapter(OpenEJBServer.class));
+
+ IVMInstall vmInstall = runtime.getVMInstall();
+ if (vmInstall != null)
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, JavaRuntime.newJREContainerPath(vmInstall).toPortableString());
+
+ String args = " start";
+ if (openejbServer.getConfigFile() != null && openejbServer.getConfigFile().length() > 0) {
+ args += " --conf=\"" + openejbServer.getConfigFile() + "\"";
+ }
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, args);
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "-Dejbd.port=" + openejbServer.getEJBPort() +
+ " -Dhttpejbd.port=" + openejbServer.getHTTPEJBPort() +
+ " -Dhsql.port=" + openejbServer.getHSQLPort() +
+ " -Dtelnet.port=" + openejbServer.getTelnetPort() +
+ " -Dadmin.port=" + openejbServer.getAdminPort() +
+ " -Dopenejb.home=\"" + getServer().getRuntime().getLocation().toString() +
+ "\" -javaagent:\"" + runtime.getJavaAgent() + "\"");
+
+ List<IRuntimeClasspathEntry> cp = new ArrayList<IRuntimeClasspathEntry>();
+ IPath serverJar = new Path(runtime.getCore());
+ cp.add(JavaRuntime.newArchiveRuntimeClasspathEntry(serverJar));
+
+ List<String> classPath = new ArrayList<String>();
+ for (IRuntimeClasspathEntry entry : cp) {
+ classPath.add(entry.getMemento());
+ }
+
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classPath);
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
+ }
+
+ private OpenEJBRuntimeDelegate getRuntimeDelegate() {
+ OpenEJBRuntimeDelegate rd = (OpenEJBRuntimeDelegate) getServer().getRuntime().getAdapter(OpenEJBRuntimeDelegate.class);
+ if (rd == null)
+ rd = (OpenEJBRuntimeDelegate) getServer().getRuntime().loadAdapter(OpenEJBRuntimeDelegate.class, new NullProgressMonitor());
+ return rd;
+ }
+
+ public void setState(int state) {
+ setServerState(state);
+ }
+
+ public void start(ILaunch launch) {
+ monitor = new ServerMonitor();
+ monitor.start();
+ }
+
+ private void doFullPublish() {
+ Iterator<IModule> iterator = publishedModules.keySet().iterator();
+ while (iterator.hasNext()) {
+ IModule module = (IModule) iterator.next();
+ doPublish(module, ADDED);
+ }
+ }
+
+ private void cleanup() {
+ Iterator<IModule> iterator = publishedModules.keySet().iterator();
+ while (iterator.hasNext()) {
+ IModule module = (IModule) iterator.next();
+ String publishedFile = publishedModules.get(module);
+ if (publishedFile != null) {
+ new File(publishedFile).delete();
+ }
+ }
+
+ publishedModules.clear();
+ }
+
+ private void doPublish(IModule module, int kind) {
+ ServerDeployer serverDeployer = new ServerDeployer(getRuntimeDelegate().getRuntime().getLocation().toFile().getAbsolutePath(), getEJBDPort());
+
+ // if module already published, try an undeploy first, and cleanup temp file
+ String jarFile = publishedModules.get(module);
+ if (jarFile != null) {
+ serverDeployer.undeploy(jarFile);
+ new File(jarFile).delete();
+ publishedModules.remove(module);
+ }
+
+ if (kind == REMOVED) {
+ return;
+ }
+
+ // now do the export
+ String newJarFile = exportModule(module);
+
+ // publish the new export
+ if (newJarFile != null) {
+ String path = serverDeployer.deploy(newJarFile);
+ publishedModules.put(module, path);
+ }
+ }
+
+ @Override
+ protected IStatus publishModule(int kind, IModule[] modules, int deltaKind, IProgressMonitor monitor) {
+ if (IServer.STATE_STARTED != getServer().getServerState()) {
+ for (IModule module : modules) {
+ if (deltaKind == REMOVED) {
+ String jarFile = publishedModules.get(module);
+ if (jarFile != null) {
+ new File(jarFile).delete();
+ }
+
+ publishedModules.remove(module);
+ } else {
+ publishedModules.put(module, null);
+ }
+ }
+ } else {
+ for (IModule module : modules) {
+ doPublish(module, deltaKind);
+ }
+ }
+
+ return super.publishModule(kind, modules, deltaKind, monitor);
+ }
+
+ protected String exportModule(IModule module) {
+ IDataModel model;
+ File tempJarFile;
+
+ try {
+ if ("jst.ear".equals(module.getModuleType().getId())) {
+ model = DataModelFactory.createDataModel(new EARComponentExportDataModelProvider());
+ tempJarFile = File.createTempFile("oejb", ".ear");
+ } else {
+ model = DataModelFactory.createDataModel(new EJBComponentExportDataModelProvider());
+ tempJarFile = File.createTempFile("oejb", ".jar");
+ }
+
+ model.setProperty(IEJBComponentExportDataModelProperties.PROJECT_NAME, module.getProject().getName());
+ model.setProperty(IEJBComponentExportDataModelProperties.ARCHIVE_DESTINATION, tempJarFile.getAbsolutePath());
+ model.getDefaultOperation().execute(null, null);
+
+ return tempJarFile.getAbsolutePath();
+ } catch (Exception e) {
+ return null;
+ }
+ }
+}
Added: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/java/org/apache/openejb/eclipse/server/OpenEJBServerFragment.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/java/org/apache/openejb/eclipse/server/OpenEJBServerFragment.java?rev=697899&view=auto
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/java/org/apache/openejb/eclipse/server/OpenEJBServerFragment.java (added)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/java/org/apache/openejb/eclipse/server/OpenEJBServerFragment.java Mon Sep 22 10:02:02 2008
@@ -0,0 +1,249 @@
+/*
+ * 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.openejb.eclipse.server;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.core.TaskModel;
+import org.eclipse.wst.server.ui.wizard.IWizardHandle;
+import org.eclipse.wst.server.ui.wizard.WizardFragment;
+
+public class OpenEJBServerFragment extends WizardFragment implements ModifyListener {
+
+ private IWizardHandle handle;
+ private Label portLabel;
+ private Text portText;
+ private Label httpEjbPortLabel;
+ private Text httpEjbPort;
+ private Label hsqlPortLabel;
+ private Text hsqlPort;
+ private Label telnetPortLabel;
+ private Text telnetPort;
+ private Label adminPortLabel;
+ private Text adminPort;
+ private Label configFileLabel;
+ private Text configFile;
+ private Button configFileBrowseButton;
+
+ @Override
+ public Composite createComposite(Composite parent, IWizardHandle handle) {
+ OpenEJBServer server = getServer();
+
+ this.handle = handle;
+ handle.setTitle("OpenEJB Server");
+ handle.setImageDescriptor(Activator.getDefault().getImageDescriptor("RUNTIME"));
+ final Composite serverComposite = new Composite(parent, SWT.NULL);
+
+ portLabel = new Label(serverComposite, SWT.NONE);
+ portLabel.setText(Messages.getString("org.apache.openejb.eclipse.server.ejbPort"));
+ portText = new Text(serverComposite, SWT.BORDER);
+ portText.addModifyListener(this);
+ Label filler5 = new Label(serverComposite, SWT.NONE);
+ httpEjbPortLabel = new Label(serverComposite, SWT.NONE);
+ httpEjbPortLabel.setText("HTTP EJB Port");
+ httpEjbPort = new Text(serverComposite, SWT.BORDER);
+ httpEjbPort.addModifyListener(this);
+ Label filler4 = new Label(serverComposite, SWT.NONE);
+ hsqlPortLabel = new Label(serverComposite, SWT.NONE);
+ hsqlPortLabel.setText("HSQL Port");
+ hsqlPort = new Text(serverComposite, SWT.BORDER);
+ hsqlPort.addModifyListener(this);
+ Label filler3 = new Label(serverComposite, SWT.NONE);
+ telnetPortLabel = new Label(serverComposite, SWT.NONE);
+ telnetPortLabel.setText("Telnet Port");
+ telnetPort = new Text(serverComposite, SWT.BORDER);
+ telnetPort.addModifyListener(this);
+ Label filler2 = new Label(serverComposite, SWT.NONE);
+ adminPortLabel = new Label(serverComposite, SWT.NONE);
+ adminPortLabel.setText("Admin Port");
+ adminPort = new Text(serverComposite, SWT.BORDER);
+ adminPort.addModifyListener(this);
+ Label filler1 = new Label(serverComposite, SWT.NONE);
+ configFileLabel = new Label(serverComposite, SWT.NONE);
+ configFileLabel.setText("Configuration file");
+ configFile = new Text(serverComposite, SWT.BORDER);
+ configFile.addModifyListener(this);
+ configFileBrowseButton = new Button(serverComposite, SWT.NONE);
+ configFileBrowseButton.setText("...");
+ configFileBrowseButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(serverComposite.getShell());
+ dialog.setFilterExtensions(new String[] {"*.xml", "*.*"});
+ dialog.setFilterNames(new String[] {"XML files", "All files"});
+ dialog.setText("Selection openejb.xml configuration file");
+ String selectedFile = dialog.open();
+ if (selectedFile != null)
+ configFile.setText(selectedFile);
+ }
+
+ });
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ serverComposite.setLayout(gridLayout);
+
+ String ejbPortNum = "4201";
+ String httpEjbPortNum = "4204";
+ String hsqlPortNum = "9001";
+ String telnetPortNum = "4202";
+ String adminPortNum = "4200";
+ String alternateConfigFile = "";
+
+ try {
+ ejbPortNum = server.getEJBPort();
+ httpEjbPortNum = server.getHTTPEJBPort();
+ hsqlPortNum = server.getHSQLPort();
+ telnetPortNum = server.getTelnetPort();
+ adminPortNum = server.getAdminPort();
+ alternateConfigFile = server.getConfigFile();
+ } catch (Exception e) {
+ }
+
+ portText.setText(ejbPortNum);
+ httpEjbPort.setText(httpEjbPortNum);
+ hsqlPort.setText(hsqlPortNum);
+ telnetPort.setText(telnetPortNum);
+ adminPort.setText(adminPortNum);
+ configFile.setText(alternateConfigFile);
+
+ validate();
+
+ return serverComposite;
+ }
+
+ @Override
+ public boolean hasComposite() {
+ return true;
+ }
+
+ @Override
+ public void performFinish(IProgressMonitor monitor) throws CoreException {
+ super.performFinish(monitor);
+ }
+
+ private OpenEJBServer getServer() {
+ IServerWorkingCopy wc = (IServerWorkingCopy) getTaskModel().getObject(TaskModel.TASK_SERVER);
+ if (wc == null) {
+ }
+
+ OpenEJBServer server = (OpenEJBServer) wc.loadAdapter(OpenEJBServer.class, new NullProgressMonitor());
+ return server;
+ }
+
+ private void validate() {
+ if (configFile.getText() != null && configFile.getText().length() > 0) {
+ File config = new File(configFile.getText());
+ if (! config.exists()) {
+ handle.setMessage("Directory does not exist", IMessageProvider.ERROR);
+ return;
+ }
+ }
+
+ String ejbdPortNum = portText.getText();
+ if (! checkPort(ejbdPortNum)) {
+ handle.setMessage("Invalid EJBD port", IMessageProvider.ERROR);
+ return;
+ }
+
+
+ String httpEjbdPortNum = httpEjbPort.getText();
+ if (! checkPort(httpEjbdPortNum)) {
+ handle.setMessage("Invalid HTTP EJB port", IMessageProvider.ERROR);
+ return;
+ }
+
+ String hsqlPortNum = hsqlPort.getText();
+ if (! checkPort(hsqlPortNum)) {
+ handle.setMessage("Invalid HSQL port", IMessageProvider.ERROR);
+ return;
+ }
+
+ String telnetPortNum = telnetPort.getText();
+ if (! checkPort(telnetPortNum)) {
+ handle.setMessage("Invalid Telnet port", IMessageProvider.ERROR);
+ return;
+ }
+
+ String adminPortNum = adminPort.getText();
+ if (! checkPort(adminPortNum)) {
+ handle.setMessage("Invalid Admin port", IMessageProvider.ERROR);
+ return;
+ }
+
+ Set<String> ports = new HashSet<String>();
+ ports.add(ejbdPortNum);
+ ports.add(httpEjbdPortNum);
+ ports.add(hsqlPortNum);
+ ports.add(telnetPortNum);
+ ports.add(adminPortNum);
+
+ if (ports.size() != 5) {
+ handle.setMessage("Ports must be unique", IMessageProvider.ERROR);
+ return;
+ }
+
+ OpenEJBServer server = getServer();
+ server.setEJBPort(portText.getText());
+ server.setHTTPEJBPort(httpEjbPort.getText());
+ server.setHSQLPort(hsqlPort.getText());
+ server.setTelnetPort(telnetPort.getText());
+ server.setAdminPort(adminPort.getText());
+ server.setConfigFile(configFile.getText());
+
+ handle.setMessage("", IMessageProvider.NONE);
+ }
+
+ private boolean checkPort(String portNum) {
+ try {
+ int port = Integer.parseInt(portNum);
+ return (port > 0 && port < 65535);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ public void modifyText(ModifyEvent e) {
+ validate();
+ }
+
+ @Override
+ public boolean isComplete() {
+ return IMessageProvider.NONE == handle.getMessageType();
+ }
+
+
+}
Added: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/java/org/apache/openejb/eclipse/server/ServerDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/java/org/apache/openejb/eclipse/server/ServerDeployer.java?rev=697899&view=auto
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/java/org/apache/openejb/eclipse/server/ServerDeployer.java (added)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/java/org/apache/openejb/eclipse/server/ServerDeployer.java Mon Sep 22 10:02:02 2008
@@ -0,0 +1,100 @@
+/*
+ * 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.openejb.eclipse.server;
+
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+
+
+public class ServerDeployer {
+ private String openejbDir;
+ private final int ejbdPort;
+
+ public ServerDeployer(String openejbDir, int ejbdPort) {
+ super();
+ this.openejbDir = openejbDir;
+ this.ejbdPort = ejbdPort;
+ }
+
+ public String deploy(String filename) {
+ Object obj = callDeployerBusinessRemote("deploy", filename);
+ if (obj == null) {
+ return null;
+ }
+
+ try {
+ return (String) obj.getClass().getDeclaredField("jarPath").get(obj);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ private Object callDeployerBusinessRemote(String methodName, String filename) {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Properties properties = new Properties();
+ properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.RemoteInitialContextFactory");
+ properties.put(Context.PROVIDER_URL, "ejbd://localhost:" + ejbdPort);
+
+ URL[] urls = getUrls(openejbDir);
+ URLClassLoader cl = new URLClassLoader(urls, classLoader);
+ Thread.currentThread().setContextClassLoader(cl);
+
+ InitialContext context = new InitialContext(properties);
+ Object ref = context.lookup("openejb/DeployerBusinessRemote");
+
+ Method method = ref.getClass().getMethod(methodName, String.class);
+ return method.invoke(ref, filename);
+ } catch (Exception e) {
+ return null;
+ } finally {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ }
+ }
+
+ public boolean undeploy(String filename) {
+ return callDeployerBusinessRemote("undeploy", filename) != null;
+ }
+
+ private URL[] getUrls(String directory) {
+ List<URL> urlList = new ArrayList<URL>();
+ File openEjbDir = new File(directory + File.separator + "lib");
+ File[] files = openEjbDir.listFiles();
+
+ for (File file : files) {
+ if (file.getName().endsWith(".jar")) {
+ try {
+ urlList.add(file.getAbsoluteFile().toURL());
+ } catch (MalformedURLException e) {
+ }
+ }
+ }
+
+ return urlList.toArray(new URL[urlList.size()]);
+ }
+}
Added: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/resources/org/apache/openejb/eclipse/server/messages.properties
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/resources/org/apache/openejb/eclipse/server/messages.properties?rev=697899&view=auto
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/resources/org/apache/openejb/eclipse/server/messages.properties (added)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/resources/org/apache/openejb/eclipse/server/messages.properties Mon Sep 22 10:02:02 2008
@@ -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.
+#
+# $Rev: 577442 $ $Date: 2007-09-19 21:43:00 +0100 (Wed, 19 Sep 2007) $
+#
+#######################################################################
+org.apache.openejb.eclipse.server.runtimeTitle=OpenEJB Runtime
+org.apache.openejb.eclipse.server.runtimeDescription=Set configuration options for the OpenEJB runtime
+org.apache.openejb.eclipse.server.openejbhomelabel=OpenEJB home directory
+org.apache.openejb.eclipse.server.ejbPort=EJB Port
Added: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/resources/org/apache/openejb/eclipse/server/messages_de.properties
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/resources/org/apache/openejb/eclipse/server/messages_de.properties?rev=697899&view=auto
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/resources/org/apache/openejb/eclipse/server/messages_de.properties (added)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/resources/org/apache/openejb/eclipse/server/messages_de.properties Mon Sep 22 10:02:02 2008
@@ -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.
+#
+# $Rev: 577442 $ $Date: 2007-09-19 21:43:00 +0100 (Wed, 19 Sep 2007) $
+#
+#######################################################################
+org.apache.openejb.eclipse.server.runtimeTitle=OpenEJB Runtime
+org.apache.openejb.eclipse.server.runtimeDescription=Set configuration options for the OpenEJB runtime
+org.apache.openejb.eclipse.server.openejbhomelabel=OpenEJB home directory
+org.apache.openejb.eclipse.server.ejbPort=EJB Port
Added: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/resources/org/apache/openejb/eclipse/server/runtime.gif
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/resources/org/apache/openejb/eclipse/server/runtime.gif?rev=697899&view=auto
==============================================================================
Binary file - no diff available.
Propchange: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.server/src/main/resources/org/apache/openejb/eclipse/server/runtime.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/pom.xml?rev=697899&r1=697898&r2=697899&view=diff
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/pom.xml (original)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/pom.xml Mon Sep 22 10:02:02 2008
@@ -17,141 +17,141 @@
-->
<!-- $Rev: 577554 $ $Date: 2007-09-20 06:35:12 +0100 (Thu, 20 Sep 2007) $ -->
<project>
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.openejb</groupId>
- <artifactId>eclipse-plugins-parent</artifactId>
- <packaging>pom</packaging>
- <name>${artifactId}</name>
- <parent>
- <groupId>org.apache.openejb</groupId>
- <artifactId>eclipse-plugins</artifactId>
- <version>1.0.0</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-clean-plugin</artifactId>
- <inherited>false</inherited>
- <configuration>
- <filesets>
- <fileset>
- <directory>.</directory>
- <includes>
- <include>.metadata</include>
- </includes>
- </fileset>
- </filesets>
- </configuration>
- </plugin>
- </plugins>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-eclipse-plugin</artifactId>
- <configuration>
- <additionalProjectnatures>
- <projectnature>org.eclipse.pde.PluginNature</projectnature>
- </additionalProjectnatures>
- <classpathContainers>
- <classpathContainer>org.eclipse.pde.core.requiredPlugins</classpathContainer>
- <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
- </classpathContainers>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.geronimo.devtools</groupId>
- <artifactId>maven-eclipsepde-plugin</artifactId>
- <executions>
- <execution>
- <id>initialize</id>
- <phase>validate</phase>
- <goals>
- <goal>manifestbundles</goal>
- <goal>install</goal>
- </goals>
- </execution>
- <execution>
- <id>validate-bundle-classpath</id>
- <phase>process-resources</phase>
- <goals>
- <goal>validatemanifest</goal>
- </goals>
- <configuration>
- <classpathEntriesDir>lib</classpathEntriesDir>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifestFile>${basedir}/META-INF/MANIFEST.MF</manifestFile>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <!-- workaround for bugzilla 147936 -->
- <execution>
- <id>backup</id>
- <phase>process-sources</phase>
- <configuration>
- <tasks>
- <copy file="${basedir}/.classpath" todir="${project.build.directory}" overwrite="false" failonerror="false"/>
- <copy file="${basedir}/.project" todir="${project.build.directory}" overwrite="false" failonerror="false"/>
- </tasks>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- <execution>
- <id>restore</id>
- <phase>compile</phase>
- <configuration>
- <tasks>
- <copy file="${project.build.directory}/.classpath" todir="${basedir}" overwrite="true" failonerror="false"/>
- <copy file="${project.build.directory}/.project" todir="${basedir}" overwrite="true" failonerror="false"/>
- </tasks>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
-
- </execution>
- <!-- /workaround -->
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-clean-plugin</artifactId>
- <configuration>
- <filesets>
- <fileset>
- <directory>.</directory>
- <includes>
- <include>lib</include>
- </includes>
- </fileset>
- </filesets>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
- <modules>
- <module>org.apache.openejb.branding</module>
- <module>org.apache.openejb.helper.annotation</module>
- <module>org.apache.openejb.builder</module>
- <module>org.apache.openejb.helper.annotation.test</module>
- <module>org.eclipse.jst.server.generic.openejb</module>
- <module>org.apache.openejb.help</module>
- <module>org.apache.openejb.help.nl1</module>
- <module>org.apache.openejb.help.nl2</module>
- <module>org.apache.openejb.help.nl2a</module>
- <module>org.apache.openejb.help.nlBidi</module>
- </modules>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>eclipse-plugins-parent</artifactId>
+ <packaging>pom</packaging>
+ <name>${artifactId}</name>
+ <parent>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>eclipse-plugins</artifactId>
+ <version>1.0.0</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <inherited>false</inherited>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>.</directory>
+ <includes>
+ <include>.metadata</include>
+ </includes>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ </plugins>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <configuration>
+ <additionalProjectnatures>
+ <projectnature>org.eclipse.pde.PluginNature</projectnature>
+ </additionalProjectnatures>
+ <classpathContainers>
+ <classpathContainer>org.eclipse.pde.core.requiredPlugins</classpathContainer>
+ <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
+ </classpathContainers>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.geronimo.devtools</groupId>
+ <artifactId>maven-eclipsepde-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>initialize</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>manifestbundles</goal>
+ <goal>install</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>validate-bundle-classpath</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>validatemanifest</goal>
+ </goals>
+ <configuration>
+ <classpathEntriesDir>lib</classpathEntriesDir>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifestFile>${basedir}/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <!-- workaround for bugzilla 147936 -->
+ <execution>
+ <id>backup</id>
+ <phase>process-sources</phase>
+ <configuration>
+ <tasks>
+ <copy file="${basedir}/.classpath" todir="${project.build.directory}" overwrite="false" failonerror="false"/>
+ <copy file="${basedir}/.project" todir="${project.build.directory}" overwrite="false" failonerror="false"/>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>restore</id>
+ <phase>compile</phase>
+ <configuration>
+ <tasks>
+ <copy file="${project.build.directory}/.classpath" todir="${basedir}" overwrite="true" failonerror="false"/>
+ <copy file="${project.build.directory}/.project" todir="${basedir}" overwrite="true" failonerror="false"/>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+
+ </execution>
+ <!-- /workaround -->
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>.</directory>
+ <includes>
+ <include>lib</include>
+ </includes>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ <modules>
+ <module>org.apache.openejb.branding</module>
+ <module>org.apache.openejb.helper.annotation</module>
+ <module>org.apache.openejb.builder</module>
+ <module>org.apache.openejb.helper.annotation.test</module>
+ <module>org.apache.openejb.server</module>
+ <module>org.apache.openejb.help</module>
+ <module>org.apache.openejb.help.nl1</module>
+ <module>org.apache.openejb.help.nl2</module>
+ <module>org.apache.openejb.help.nl2a</module>
+ <module>org.apache.openejb.help.nlBidi</module>
+ </modules>
</project>