Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 63170 invoked from network); 21 Jun 2007 23:19:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Jun 2007 23:19:13 -0000 Received: (qmail 44892 invoked by uid 500); 21 Jun 2007 23:19:15 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 44849 invoked by uid 500); 21 Jun 2007 23:19:14 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 44837 invoked by uid 99); 21 Jun 2007 23:19:14 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jun 2007 16:19:14 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jun 2007 16:19:06 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 79BEF1A9820; Thu, 21 Jun 2007 16:18:46 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r549644 [3/8] - in /geronimo/sandbox/geronimo-netbeans-plugin: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/geronimo/ src/main/java/org/apache/geronimo/netbeans/ src/main/java/org/ap... Date: Thu, 21 Jun 2007 23:18:41 -0000 To: scm@geronimo.apache.org From: jlaskowski@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070621231846.79BEF1A9820@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Propchange: geronimo/sandbox/geronimo-netbeans-plugin/LICENSE.txt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/geronimo-netbeans-plugin/LICENSE.txt ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/sandbox/geronimo-netbeans-plugin/LICENSE.txt ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/geronimo-netbeans-plugin/NOTICE.txt URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/NOTICE.txt?view=auto&rev=549644 ============================================================================== --- geronimo/sandbox/geronimo-netbeans-plugin/NOTICE.txt (added) +++ geronimo/sandbox/geronimo-netbeans-plugin/NOTICE.txt Thu Jun 21 16:18:31 2007 @@ -0,0 +1,10 @@ +========================================================================= +== NOTICE file corresponding to section 4(d) of the Apache License, == +== Version 2.0, in this case for the Apache Geronimo distribution. == +========================================================================= + +Apache Geronimo +Copyright 2003-2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). Propchange: geronimo/sandbox/geronimo-netbeans-plugin/NOTICE.txt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/geronimo-netbeans-plugin/NOTICE.txt ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/sandbox/geronimo-netbeans-plugin/NOTICE.txt ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/geronimo-netbeans-plugin/pom.xml URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/pom.xml?view=auto&rev=549644 ============================================================================== --- geronimo/sandbox/geronimo-netbeans-plugin/pom.xml (added) +++ geronimo/sandbox/geronimo-netbeans-plugin/pom.xml Thu Jun 21 16:18:31 2007 @@ -0,0 +1,128 @@ + + + 4.0.0 + org.apache.geronimo.netbeans + geronimo-netbeans-plugin + nbm + 1.0-SNAPSHOT + geronimo-netbeans-plugin + http://geronimo.apache.org/devtools/netbeans + + RELEASE60-M9 + + + + + org.codehaus.mojo + nbm-maven-plugin + true + + src/main/nbm/module.xml + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.3 + + + org.apache.maven.surefire + surefire-booter + 2.3 + + + + + + + + netbeans + repository hosting netbeans.org api artifacts + http://208.44.201.216:18080/maven + + never + + + false + never + + + + netbeans2 + repository hosting netbeans.org api artifacts + https://maven-repository.dev.java.net/nonav/repository + + + + false + + + + mevenide + Mevenide's M2 repo + http://mevenide.codehaus.org/m2-repository + + + + + org.netbeans.api + org-netbeans-api-java + ${netbeans.release} + + + org.netbeans.api + org-netbeans-modules-projectapi + ${netbeans.release} + + + org.netbeans.api + org-netbeans-modules-java-project + ${netbeans.release} + + + org.netbeans.api + org-netbeans-api-java + ${netbeans.release} + + + org.netbeans.api + org-netbeans-modules-java-platform + ${netbeans.release} + + + org.netbeans.api + org-netbeans-modules-j2ee-dd + ${netbeans.release} + + + org.netbeans.api + org-netbeans-modules-j2eeserver + ${netbeans.release} + + + org.netbeans.api + org-netbeans-modules-j2eeapis + ${netbeans.release} + + + org.apache.geronimo.specs + geronimo-j2ee-deployment_1.1_spec + 1.1 + + + org.testng + testng + 5.1 + jdk15 + test + + + Propchange: geronimo/sandbox/geronimo-netbeans-plugin/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/geronimo-netbeans-plugin/pom.xml ------------------------------------------------------------------------------ svn:executable = * Propchange: geronimo/sandbox/geronimo-netbeans-plugin/pom.xml ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/sandbox/geronimo-netbeans-plugin/pom.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeployer.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeployer.java?view=auto&rev=549644 ============================================================================== --- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeployer.java (added) +++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeployer.java Thu Jun 21 16:18:31 2007 @@ -0,0 +1,233 @@ +/** + * 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.geronimo.netbeans; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collections; +import java.util.MissingResourceException; +import javax.management.ObjectName; +import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; +import java.util.Vector; +import java.io.File; +import java.util.Set; +import javax.enterprise.deploy.spi.Target; +import javax.enterprise.deploy.spi.TargetModuleID; +import javax.enterprise.deploy.spi.status.ProgressEvent; +import javax.enterprise.deploy.spi.status.ProgressListener; +import javax.enterprise.deploy.spi.status.ProgressObject; +import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException; +import javax.enterprise.deploy.spi.status.ClientConfiguration; +import javax.enterprise.deploy.spi.status.DeploymentStatus; +import org.openide.ErrorManager; +import org.openide.util.RequestProcessor; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import javax.enterprise.deploy.shared.ActionType; +import javax.enterprise.deploy.shared.CommandType; +import javax.enterprise.deploy.shared.StateType; +import javax.management.QueryExp; +import org.apache.geronimo.netbeans.ide.GeronimoDeploymentStatus; +import org.apache.geronimo.netbeans.ide.ui.GeronimoPluginProperties; +import org.apache.geronimo.netbeans.nodes.Util; +import org.openide.util.NbBundle; + +/** + * @version $Rev$ $Date$ + */ +public class GeronimoDeployer implements ProgressObject, Runnable { + + private static final String AUTO_DEPLOY_DIR = "/hotdeploy"; + + /** timeout for waiting for URL connection */ + private static final int TIMEOUT = 60000; + + GeronimoDeploymentManager dm; + + File file; + String uri; + GeronimoTargetModuleID module_id; + + public GeronimoDeployer(String serverUri, GeronimoDeploymentManager dm) { + uri = serverUri; + this.dm = dm; + } + + public ProgressObject deploy(Target[] target, File file, File file2, String host, int port) { + System.out.println("TODO: Deploying..."); + return null; + } + + public ProgressObject redeploy(TargetModuleID module_id[], File file, File file2) { + this.file = file; + this.module_id = (GeronimoTargetModuleID) module_id[0]; + fireHandleProgressEvent(null, + new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, StateType.RUNNING, NbBundle + .getMessage(GeronimoDeployer.class, "MSG_DEPLOYING", file.getAbsolutePath()))); + RequestProcessor.getDefault().post(this, 0, Thread.NORM_PRIORITY); + return this; + } + + public void run() { + + String deployDir = InstanceProperties.getInstanceProperties(uri).getProperty( + GeronimoPluginProperties.PROPERTY_DEPLOY_DIR); + FileObject foIn = FileUtil.toFileObject(file); + FileObject foDestDir = FileUtil.toFileObject(new File(deployDir)); + String fileName = file.getName(); + + File toDeploy = new File(deployDir + File.separator + fileName); + if (toDeploy.exists()) { + toDeploy.delete(); + } + + fileName = fileName.substring(0, fileName.lastIndexOf('.')); + String msg = NbBundle.getMessage(GeronimoDeployer.class, "MSG_DEPLOYING", file.getAbsolutePath()); + fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, + StateType.RUNNING, msg)); + + try { + org.openide.filesystems.FileUtil.copyFile(foIn, foDestDir, fileName); // copy version + TargetModuleID moduleID = module_id; + String webUrl = module_id.getWebURL(); + if (webUrl == null) { + TargetModuleID ch[] = module_id.getChildTargetModuleID(); + if (ch != null) { + for (int i = 0; i < ch.length; i++) { + webUrl = ch[i].getWebURL(); + if (webUrl != null) { + moduleID = ch[i]; + break; + } + } + } + + } + if (webUrl != null) { + URL url = new URL(webUrl); + String waitingMsg = NbBundle.getMessage(GeronimoDeployer.class, "MSG_Waiting_For_Url", url); + fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, + StateType.RUNNING, waitingMsg)); + // delay to prevent hitting the old content before reload + for (int i = 0; i < 3; i++) { + try { + Thread.sleep(1000); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + } + // wait until the url becomes active + checkUrlReady(moduleID); + } + } catch (MalformedURLException ex) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); + fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, + StateType.FAILED, "Failed")); + } catch (MissingResourceException ex) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); + fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, + StateType.FAILED, "Failed")); + } catch (IOException ex) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); + fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, + StateType.FAILED, "Failed")); + } + + fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, + StateType.COMPLETED, "Applicaton Deployed")); + } + + private void checkUrlReady(TargetModuleID moduleID) { + try { + String warName = moduleID.getModuleID(); + ObjectName searchPattern = new ObjectName("geronimo.FIXME.web.deployment:war=" + warName + ",*"); // NOI18N + Object server = Util.getRMIServer(dm); + long start = System.currentTimeMillis(); + Set managedObj = Collections.emptySet(); + while (managedObj.size() == 0 && System.currentTimeMillis() - start < TIMEOUT) { + managedObj = (Set) server.getClass().getMethod("queryMBeans", + new Class[] { ObjectName.class, QueryExp.class }).invoke(server, + new Object[] { searchPattern, null }); + } + } catch (Exception ex) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); + } + } + + // ---------- Implementation of ProgressObject interface + private Vector listeners = new Vector(); + private DeploymentStatus deploymentStatus; + + public void addProgressListener(ProgressListener pl) { + listeners.add(pl); + } + + public void removeProgressListener(ProgressListener pl) { + listeners.remove(pl); + } + + public void stop() throws OperationUnsupportedException { + throw new OperationUnsupportedException(""); + } + + public boolean isStopSupported() { + return false; + } + + public void cancel() throws OperationUnsupportedException { + throw new OperationUnsupportedException(""); + } + + public boolean isCancelSupported() { + return false; + } + + public ClientConfiguration getClientConfiguration(TargetModuleID targetModuleID) { + return null; + } + + public TargetModuleID[] getResultTargetModuleIDs() { + return new TargetModuleID[] { module_id }; + } + + public DeploymentStatus getDeploymentStatus() { + return deploymentStatus; + } + + /** Report event to any registered listeners. */ + public void fireHandleProgressEvent(TargetModuleID targetModuleID, DeploymentStatus deploymentStatus) { + ProgressEvent evt = new ProgressEvent(this, targetModuleID, deploymentStatus); + + this.deploymentStatus = deploymentStatus; + + java.util.Vector targets = null; + synchronized (this) { + if (listeners != null) { + targets = (java.util.Vector) listeners.clone(); + } + } + + if (targets != null) { + for (int i = 0; i < targets.size(); i++) { + ProgressListener target = (ProgressListener) targets.elementAt(i); + target.handleProgressEvent(evt); + } + } + } + +} Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeployer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeployer.java ------------------------------------------------------------------------------ svn:executable = * Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeployer.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeployer.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentFactory.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentFactory.java?view=auto&rev=549644 ============================================================================== --- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentFactory.java (added) +++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentFactory.java Thu Jun 21 16:18:31 2007 @@ -0,0 +1,311 @@ +package org.apache.geronimo.netbeans; + +import java.util.HashMap; +import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.security.AllPermission; +import java.security.CodeSource; +import java.security.PermissionCollection; +import java.security.Permissions; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Logger; +import org.openide.ErrorManager; +import org.openide.util.NbBundle; +import javax.enterprise.deploy.spi.DeploymentManager; +import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException; +import javax.enterprise.deploy.spi.factories.DeploymentFactory; +import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager; +import org.apache.geronimo.netbeans.ide.ui.GeronimoPluginProperties; +import org.apache.geronimo.netbeans.ide.ui.GeronimoPluginUtils; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.Repository; +import org.openide.util.Lookup; + +/** + * The DeploymentFactory interface is a deployment driver for a J2EE plaform product. It returns a DeploymentManager + * object which represents a connection to a specific J2EE platform product. + * + * Each application server vendor must provide an implementation of this class in order for the J2EE Deployment API to + * work with their product. + * + * The class implementing this interface should have a public no-argument constructor, and it should be stateless (two + * instances of the class should always behave the same). It is suggested but not required that the class have a static + * initializer that registers an instance of the class with the DeploymentFactoryManager class. + * + * @version $Rev$ $Date$ + */ +public class GeronimoDeploymentFactory implements DeploymentFactory { + + final static Logger logger = Logger.getLogger(GeronimoDeploymentFactory.class.toString()); + + public static final String URI_PREFIX = "deployer:geronimo:"; // NOI18N + + private static final String DISCONNECTED_URI = "deployer:geronimo:http://localhost:8080&"; // NOI18N + + private static final String DEPLOYMENT_FACTORY_CLASS_NAME = "org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl"; + + private static final String DEPLOY_JSR88_JAR_PATH = "/repository/org/apache/geronimo/modules/geronimo-deploy-jsr88/2.0-M6/geronimo-deploy-jsr88-2.0-M6.jar"; + + private static final String DEPLOYER_JAR_PATH = "/bin/deployer.jar"; + + private static final String SERVER_JAR_PATH = "/bin/server.jar"; + + private static GeronimoDeploymentFactory instance; + + public static synchronized DeploymentFactory create() { + if (instance == null) { + instance = new GeronimoDeploymentFactory(); + DeploymentFactoryManager.getInstance().registerDeploymentFactory(instance); + registerDefaultServerInstance(); + } + return instance; + } + + /** + * Map of a server installation directory to a deployment factory + */ + private Map factories = new HashMap(); + + public static class GeronimoClassLoader extends URLClassLoader { + + public GeronimoClassLoader(URL[] urls, ClassLoader parent) throws MalformedURLException, RuntimeException { + super(urls, parent); + } + + protected PermissionCollection getPermissions(CodeSource codeSource) { + Permissions p = new Permissions(); + p.add(new AllPermission()); + return p; + } + + public Enumeration getResources(String name) throws IOException { + // get rid of annoying warnings + if (name.indexOf("jndi.properties") != -1 || name.indexOf("log4j.xml") != -1) { + return Collections.enumeration(Collections. emptyList()); + } + return super.getResources(name); + } + } + + public static URLClassLoader getGeronimoClassLoader(String serverRoot) { + try { + List urlList = new ArrayList(); + + File[] libs = new File(serverRoot + "/lib").listFiles(); + for (File lib : libs) { + urlList.add(lib.toURI().toURL()); + } + urlList.add(new File(serverRoot + DEPLOYER_JAR_PATH).toURI().toURL()); + urlList.add(new File(serverRoot + SERVER_JAR_PATH).toURI().toURL()); + urlList.add(new File(serverRoot + DEPLOY_JSR88_JAR_PATH).toURI().toURL()); + + URLClassLoader loader = new GeronimoClassLoader(urlList.toArray(new URL[] {}), + GeronimoDeploymentFactory.class.getClassLoader()); + return loader; + } catch (Exception e) { + ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); + } + return null; + } + + public DeploymentFactory getFactory(String instanceURL) { + DeploymentFactory factory = null; + try { + String serverDir = InstanceProperties.getInstanceProperties(instanceURL).getProperty( + GeronimoPluginProperties.PROPERTY_SERVER_DIR); + + // if root is null, then we are in a server instance registration + // process, thus this call + // is made from InstanceProperties creation -> + // GeronimoPluginProperties singleton contains + // install location of the instance being registered + if (serverDir == null) { + serverDir = GeronimoPluginProperties.getInstance().getInstallLocation(); + } + + factory = (DeploymentFactory) factories.get(serverDir); + if (factory == null) { + URLClassLoader loader = getGeronimoClassLoader(serverDir); + factory = (DeploymentFactory) loader.loadClass(DEPLOYMENT_FACTORY_CLASS_NAME).newInstance(); + factories.put(serverDir, factory); + } + } catch (Exception e) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); + } + + return factory; + } + + public boolean handlesURI(String uri) { + if (uri != null && uri.startsWith(URI_PREFIX)) { + return true; + } + + return false; + } + + /** + * Return a connected DeploymentManager instance. + */ + public DeploymentManager getDeploymentManager(String uri, String username, String password) + throws DeploymentManagerCreationException { + if (!handlesURI(uri)) { + throw new DeploymentManagerCreationException(NbBundle.getMessage(GeronimoDeploymentFactory.class, + "MSG_INVALID_URI", uri)); // NOI18N + } + + DeploymentFactory df = getFactory(uri); + if (df == null) { + throw new DeploymentManagerCreationException(NbBundle.getMessage(GeronimoDeploymentFactory.class, + "MSG_ERROR_CREATING_DM", uri)); + } + + String geronimoURI = uri; + try { + geronimoURI = uri.substring(0, uri.indexOf("&")); + } catch (Exception e) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); + } + + return new GeronimoDeploymentManager(df.getDeploymentManager(geronimoURI, username, password), uri, username, + password); + } + + public DeploymentManager getDisconnectedDeploymentManager(String uri) throws DeploymentManagerCreationException { + if (!handlesURI(uri)) { + throw new DeploymentManagerCreationException(NbBundle.getMessage(GeronimoDeploymentFactory.class, + "MSG_INVALID_URI", uri)); // NOI18N + } + + DeploymentFactory df = null; + InstanceProperties ip = InstanceProperties.getInstanceProperties(uri); + if (ip == null) { + // null ip either means that the instance is not registered, or that + // this is the disconnected URL + if (!DISCONNECTED_URI.equals(uri)) { + throw new DeploymentManagerCreationException("Geronimo instance " + uri + + " is not registered in the IDE."); // NOI18N + } + } else { + df = getFactory(uri); + if (df == null) { + throw new DeploymentManagerCreationException(NbBundle.getMessage(GeronimoDeploymentFactory.class, + "MSG_ERROR_CREATING_DM", uri)); // NOI18N + } + } + + String geronimoURI = uri; + try { + geronimoURI = uri.substring(0, uri.indexOf("&")); // NOI18N + } catch (Exception e) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); + } + + return new GeronimoDeploymentManager((df != null ? df.getDisconnectedDeploymentManager(geronimoURI) : null), + uri, null, null); + } + + public String getProductVersion() { + return NbBundle.getMessage(GeronimoDeploymentFactory.class, "LBL_FactoryVersion"); + } + + public String getDisplayName() { + return NbBundle.getMessage(GeronimoDeploymentFactory.class, "SERVER_NAME"); // NOI18N + } + + private static final String INSTALL_ROOT_PROP_NAME = "org.apache.geronimo.netbeans.installRoot"; + + private static void registerDefaultServerInstance() { + try { + FileObject serverInstanceDir = getServerInstanceDir(); + String serverLocation = getDefaultInstallLocation(); + // TODO: setRemovability(serverInstanceDir); + if (GeronimoPluginUtils.isGoodServerLocation(new File(serverLocation))) { + if (!isAlreadyRegistered(serverInstanceDir)) { + String host = "localhost"; // NOI18N + String port = GeronimoPluginUtils.getHTTPConnectorPort(serverLocation); // NOI18N + register(serverInstanceDir, serverLocation, host, port); + } + } + } catch (IOException ioe) { + ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ioe.getMessage()); + } + } + + private static String getDefaultInstallLocation() { + String installRoot = System.getProperty(INSTALL_ROOT_PROP_NAME); + if (installRoot != null && new File(installRoot).exists()) { + return installRoot; + } + return ""; + } + + private static boolean isAlreadyRegistered(FileObject serverInstanceDir) throws IOException { + return false; + } + + private static void register(FileObject serverInstanceDir, String serverLocation, String host, String port) + throws IOException { + String displayName = generateDisplayName(serverInstanceDir); + + String url = URI_PREFIX + host + ":" + port + "#default&" + serverLocation; // NOI18N + + String name = FileUtil.findFreeFileName(serverInstanceDir, "instance", null); // NOI18N + FileObject instanceFO = serverInstanceDir.createData(name); + + instanceFO.setAttribute(InstanceProperties.URL_ATTR, url); + instanceFO.setAttribute(InstanceProperties.USERNAME_ATTR, ""); + instanceFO.setAttribute(InstanceProperties.PASSWORD_ATTR, ""); + instanceFO.setAttribute(InstanceProperties.DISPLAY_NAME_ATTR, displayName); + instanceFO.setAttribute(InstanceProperties.REMOVE_FORBIDDEN, "true"); + + instanceFO.setAttribute(GeronimoPluginProperties.PROPERTY_SERVER, "default"); // NOI18N + String deployDir = GeronimoPluginUtils.getDeployDir(serverLocation); + instanceFO.setAttribute(GeronimoPluginProperties.PROPERTY_DEPLOY_DIR, deployDir); + instanceFO.setAttribute(GeronimoPluginProperties.PROPERTY_SERVER_DIR, serverLocation); + instanceFO.setAttribute(GeronimoPluginProperties.PROPERTY_HOST, host); + instanceFO.setAttribute(GeronimoPluginProperties.PROPERTY_PORT, port); + } + + private static FileObject getServerInstanceDir() { + Repository rep = (Repository) Lookup.getDefault().lookup(Repository.class); + FileObject dir = rep.getDefaultFileSystem().findResource("/J2EE/InstalledServers"); // NOI18N + return dir; + } + + private static String generateDisplayName(FileObject serverInstanceDir) { + final String serverName = NbBundle.getMessage(GeronimoDeploymentFactory.class, "SERVER_NAME"); // NOI18N + + String instanceName = serverName; + int counter = 1; + Set registeredInstances = getServerInstancesNames(serverInstanceDir); + + while (registeredInstances.contains(instanceName.toUpperCase())) { + instanceName = serverName + " (" + String.valueOf(counter++) + ")"; + } + + return instanceName; + } + + private static Set getServerInstancesNames(FileObject serverInstanceDir) { + Set names = new HashSet(); + for (FileObject instanceFO : serverInstanceDir.getChildren()) { + String instanceName = (String) instanceFO.getAttribute(InstanceProperties.DISPLAY_NAME_ATTR); + names.add(instanceName.toUpperCase()); + } + + return names; + } + +} Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentFactory.java ------------------------------------------------------------------------------ svn:executable = * Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentFactory.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentFactory.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentManager.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentManager.java?view=auto&rev=549644 ============================================================================== --- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentManager.java (added) +++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentManager.java Thu Jun 21 16:18:31 2007 @@ -0,0 +1,286 @@ +package org.apache.geronimo.netbeans; + +import java.io.File; +import java.io.InputStream; +import java.net.URLClassLoader; +import java.util.Collections; +import java.util.Hashtable; +import java.util.Locale; +import java.util.Map; +import java.util.WeakHashMap; + +import javax.enterprise.deploy.model.DeployableObject; +import javax.enterprise.deploy.shared.DConfigBeanVersionType; +import javax.enterprise.deploy.shared.ModuleType; +import javax.enterprise.deploy.spi.DeploymentConfiguration; +import javax.enterprise.deploy.spi.DeploymentManager; +import javax.enterprise.deploy.spi.Target; +import javax.enterprise.deploy.spi.TargetModuleID; +import javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException; +import javax.enterprise.deploy.spi.exceptions.InvalidModuleException; +import javax.enterprise.deploy.spi.exceptions.TargetException; +import javax.enterprise.deploy.spi.status.ProgressObject; +import javax.management.MBeanServerConnection; +import javax.naming.InitialContext; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; + +import org.apache.geronimo.netbeans.ide.GeronimoJ2eePlatformFactory; +import org.apache.geronimo.netbeans.ide.ui.GeronimoPluginProperties; +import org.apache.geronimo.netbeans.util.GeronimoProperties; +import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; + +/** + * The DeploymentManager object provides the core set of functions a J2EE platform must provide for J2EE application + * deployment. It provides server related information, such as, a list of deployment targets, and vendor unique runtime + * configuration information. + */ +public class GeronimoDeploymentManager implements DeploymentManager { + + private DeploymentManager dm; + private String realUri; + private MBeanServerConnection rmiServer; + + private int debuggingPort = 8787; + + private InstanceProperties instanceProperties; + + /** + * Stores information about running instances. instance is represented by its InstanceProperties, running state by + * Boolean.TRUE, stopped state Boolean.FALSE. WeakHashMap should guarantee erasing of an unregistered server + * instance bcs instance properties are also removed along with instance. + */ + private static Map propertiesToIsRunning = Collections + .synchronizedMap(new WeakHashMap()); + + public GeronimoDeploymentManager(DeploymentManager dm, String uri, String username, String password) { + this.realUri = uri; + this.dm = dm; + this.rmiServer = null; + } + + // ////////////////////////////////////////////////////////////////////////// + // Connection data methods + // ////////////////////////////////////////////////////////////////////////// + public String getHost() { + String host = InstanceProperties.getInstanceProperties(realUri).getProperty( + GeronimoPluginProperties.PROPERTY_HOST); + return host; + } + + public int getPort() { + String port = InstanceProperties.getInstanceProperties(realUri).getProperty( + GeronimoPluginProperties.PROPERTY_PORT); + return new Integer(port).intValue(); + } + + public int getDebuggingPort() { + return debuggingPort; + } + + public String getUrl() { + return realUri; + } + + public InstanceProperties getInstanceProperties() { + if (instanceProperties == null) + instanceProperties = InstanceProperties.getInstanceProperties(realUri); + + return instanceProperties; + } + + public synchronized MBeanServerConnection getRMIServer() { + if (rmiServer == null) { + ClassLoader oldLoader = null; + + try { + oldLoader = Thread.currentThread().getContextClassLoader(); + InstanceProperties ip = this.getInstanceProperties(); + URLClassLoader loader = GeronimoDeploymentFactory.getGeronimoClassLoader(ip + .getProperty(GeronimoPluginProperties.PROPERTY_SERVER_DIR)); + Thread.currentThread().setContextClassLoader(loader); + + GeronimoProperties props = getProperties(); + Hashtable env = new Hashtable(); + + final String JAVA_SEC_AUTH_LOGIN_CONF = "java.security.auth.login.config"; // NOI18N + String oldAuthConf = System.getProperty(JAVA_SEC_AUTH_LOGIN_CONF); + + InitialContext ctx = new InitialContext(env); + + // restore java.security.auth.login.config system property + if (oldAuthConf != null) { + System.setProperty(JAVA_SEC_AUTH_LOGIN_CONF, oldAuthConf); + } else { + System.clearProperty(JAVA_SEC_AUTH_LOGIN_CONF); + } + rmiServer = (MBeanServerConnection) ctx.lookup("/jmx/invoker/RMIAdaptor"); + } catch (NameNotFoundException ex) { + } catch (NamingException ex) { + // Nothing to do + } finally { + if (oldLoader != null) + Thread.currentThread().setContextClassLoader(oldLoader); + } + } + + return rmiServer; + } + + public synchronized MBeanServerConnection refreshRMIServer() { + rmiServer = null; + return getRMIServer(); + } + + // ////////////////////////////////////////////////////////////////////////// + // Methods for retrieving server instance state + // ////////////////////////////////////////////////////////////////////////// + /** + * Returns true if the given instance properties are present in the map and value equals true. Otherwise return + * false. + */ + public static boolean isRunningLastCheck(InstanceProperties ip) { + boolean isRunning = propertiesToIsRunning.containsKey(ip) && propertiesToIsRunning.get(ip).equals(Boolean.TRUE); + return isRunning; + } + + /** + * Stores state of an instance represented by InstanceProperties. + */ + public static void setRunningLastCheck(InstanceProperties ip, Boolean isRunning) { + assert (ip != null); + propertiesToIsRunning.put(ip, isRunning); + } + + // ////////////////////////////////////////////////////////////////////////// + // DeploymentManager Implementation + // ////////////////////////////////////////////////////////////////////////// + public ProgressObject distribute(Target[] target, File file, File file2) throws IllegalStateException { + return new GeronimoDeployer(realUri, this).deploy(target, file, file2, getHost(), getPort()); + } + + public DeploymentConfiguration createConfiguration(DeployableObject deployableObject) throws InvalidModuleException { + ModuleType type = deployableObject.getType(); + throw new InvalidModuleException("Unsupported module type: " + type.toString()); + } + + public ProgressObject redeploy(TargetModuleID[] targetModuleID, InputStream inputStream, InputStream inputStream2) + throws UnsupportedOperationException, IllegalStateException { + return dm.redeploy(targetModuleID, inputStream, inputStream2); + } + + public ProgressObject distribute(Target[] target, InputStream inputStream, InputStream inputStream2) + throws IllegalStateException { + return dm.distribute(target, inputStream, inputStream2); + } + + public ProgressObject distribute(Target[] target, ModuleType moduleType, InputStream inputStream, + InputStream inputStream0) throws IllegalStateException { + return distribute(target, inputStream, inputStream0); + } + + public ProgressObject undeploy(TargetModuleID[] targetModuleID) throws IllegalStateException { + return dm.undeploy(targetModuleID); + } + + public ProgressObject stop(TargetModuleID[] targetModuleID) throws IllegalStateException { + return dm.stop(targetModuleID); + } + + public ProgressObject start(TargetModuleID[] targetModuleID) throws IllegalStateException { + return dm.start(targetModuleID); + } + + public void setLocale(Locale locale) throws UnsupportedOperationException { + dm.setLocale(locale); + } + + public boolean isLocaleSupported(Locale locale) { + return dm.isLocaleSupported(locale); + } + + public TargetModuleID[] getAvailableModules(ModuleType moduleType, Target[] target) throws TargetException, + IllegalStateException { + // return dm.getAvailableModules(moduleType, target); + return new TargetModuleID[] {}; + } + + public TargetModuleID[] getNonRunningModules(ModuleType moduleType, Target[] target) throws TargetException, + IllegalStateException { + // return dm.getNonRunningModules(moduleType, target); + return new TargetModuleID[] {}; + } + + public TargetModuleID[] getRunningModules(ModuleType moduleType, Target[] target) throws TargetException, + IllegalStateException { + return dm.getRunningModules(moduleType, target); + } + + public ProgressObject redeploy(TargetModuleID[] targetModuleID, File file, File file2) + throws UnsupportedOperationException, IllegalStateException { + return new GeronimoDeployer(realUri, this).redeploy(targetModuleID, file, file2); + } + + public void setDConfigBeanVersion(DConfigBeanVersionType dConfigBeanVersionType) + throws DConfigBeanVersionUnsupportedException { + dm.setDConfigBeanVersion(dConfigBeanVersionType); + } + + public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType dConfigBeanVersionType) { + return dm.isDConfigBeanVersionSupported(dConfigBeanVersionType); + } + + public void release() { + if (dm != null) { + dm.release(); + } + } + + public boolean isRedeploySupported() { + return dm.isRedeploySupported(); + } + + public Locale getCurrentLocale() { + return dm.getCurrentLocale(); + } + + public DConfigBeanVersionType getDConfigBeanVersion() { + return dm.getDConfigBeanVersion(); + } + + public Locale getDefaultLocale() { + return dm.getDefaultLocale(); + } + + public Locale[] getSupportedLocales() { + return dm.getSupportedLocales(); + } + + public Target[] getTargets() throws IllegalStateException { + return new Target[] { new Target() { + public String getName() { + return "Testowa instancja Jacka"; + } + + public String getDescription() { + return "Opis Jacka"; + } + } }; + // return dm.getTargets(); + } + + private GeronimoJ2eePlatformFactory.J2eePlatformImplImpl platform; + + public GeronimoJ2eePlatformFactory.J2eePlatformImplImpl getPlatform() { + if (platform == null) { + platform = (GeronimoJ2eePlatformFactory.J2eePlatformImplImpl) new GeronimoJ2eePlatformFactory() + .getJ2eePlatformImpl(this); + } + return platform; + } + + public GeronimoProperties getProperties() { + return new GeronimoProperties(this); + } + +} Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentManager.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentManager.java ------------------------------------------------------------------------------ svn:executable = * Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentManager.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoDeploymentManager.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoTargetModuleID.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoTargetModuleID.java?view=auto&rev=549644 ============================================================================== --- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoTargetModuleID.java (added) +++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoTargetModuleID.java Thu Jun 21 16:18:31 2007 @@ -0,0 +1,73 @@ +package org.apache.geronimo.netbeans; + +import java.util.Vector; +import javax.enterprise.deploy.spi.Target; +import javax.enterprise.deploy.spi.TargetModuleID; + +public class GeronimoTargetModuleID implements TargetModuleID { + private Target target; + private String jar_name; + private String context_url; + + Vector childs = new Vector(); + TargetModuleID parent = null; + + GeronimoTargetModuleID(Target target) { + this(target, ""); + + } + + GeronimoTargetModuleID(Target target, String jar_name) { + this.target = target; + this.setJARName(jar_name); + + } + + public void setContextURL(String context_url) { + this.context_url = context_url; + } + + public void setJARName(String jar_name) { + this.jar_name = jar_name; + } + + public void setParent(GeronimoTargetModuleID parent) { + this.parent = parent; + + } + + public void addChild(GeronimoTargetModuleID child) { + childs.add(child); + child.setParent(this); + } + + public TargetModuleID[] getChildTargetModuleID() { + return (TargetModuleID[]) childs.toArray(new TargetModuleID[childs.size()]); + } + + // Retrieve a list of identifiers of the children of this deployed module. + public java.lang.String getModuleID() { + return jar_name; + } + + // Retrieve the id assigned to represent the deployed module. + public TargetModuleID getParentTargetModuleID() { + + return parent; + } + + // Retrieve the identifier of the parent object of this deployed module. + public Target getTarget() { + return target; + } + + // Retrieve the name of the target server. + public java.lang.String getWebURL() { + return context_url;// "http://" + module_id; //NOI18N + } + + // If this TargetModulID represents a web module retrieve the URL for it. + public java.lang.String toString() { + return getModuleID() + hashCode(); + } +} \ No newline at end of file Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoTargetModuleID.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoTargetModuleID.java ------------------------------------------------------------------------------ svn:executable = * Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoTargetModuleID.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/GeronimoTargetModuleID.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/config/GeronimoDeploymentConfiguration.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/config/GeronimoDeploymentConfiguration.java?view=auto&rev=549644 ============================================================================== --- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/config/GeronimoDeploymentConfiguration.java (added) +++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/config/GeronimoDeploymentConfiguration.java Thu Jun 21 16:18:31 2007 @@ -0,0 +1,133 @@ +package org.apache.geronimo.netbeans.config; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import javax.enterprise.deploy.model.DDBeanRoot; +import javax.enterprise.deploy.model.DeployableObject; +import javax.enterprise.deploy.spi.DConfigBeanRoot; +import javax.enterprise.deploy.spi.DeploymentConfiguration; +import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException; +import javax.enterprise.deploy.spi.exceptions.ConfigurationException; +import org.netbeans.modules.schema2beans.BaseBean; +import org.openide.filesystems.FileLock; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; +import org.openide.loaders.DataObject; +import org.openide.util.NbBundle; + +public abstract class GeronimoDeploymentConfiguration implements DeploymentConfiguration { + + protected static final String DATASOURCE_JNDI_PREFIX = "java:"; // NOI18N + protected static final String MAIL_SERVICE_JNDI_NAME = "java:Mail"; // NOI18N + protected static final String CONNECTION_FACTORY_JNDI_NAME = "ConnectionFactory"; // NOI18N + protected static final String EJB_JNDI_PREFIX = "java:comp/env/"; // NOI18N + + static final String MSG_QUEUE_JNDI_PREFIX = "queue/"; // NOI18N + static final String MSG_TOPIC_JNDI_PREFIX = "topic/"; // NOI18N + + // JSR-88 deployable object - initialized when instance is constructed + protected DeployableObject deplObj; + + // cached data object for the server-specific configuration file + // (initialized by the subclasses) + protected DataObject deploymentDescriptorDO; + + // the directory with resources - supplied by the configuration support in + // the construction time + private File resourceDir; + + public GeronimoDeploymentConfiguration(DeployableObject deplObj) { + this.deplObj = deplObj; + } + + /** + * Initialization of the common data used by the subclasses. + * + * @param resourceDir + * directory containing definition for enterprise resources. + */ + protected void init(File resourceDir) { + this.resourceDir = resourceDir; + throw new IllegalArgumentException("TODO"); + } + + // JSR-88 methods --------------------------------------------------------- + + public DeployableObject getDeployableObject() { + return deplObj; + } + + // JSR-88 methods empty implementation ------------------------------------ + + public DConfigBeanRoot getDConfigBeanRoot(DDBeanRoot dDBeanRoot) throws ConfigurationException { + return null; + } + + public void removeDConfigBean(DConfigBeanRoot dConfigBeanRoot) throws BeanNotFoundException { + throw new BeanNotFoundException("bean not found " + dConfigBeanRoot); // NOI18N + } + + public void restore(InputStream is) throws ConfigurationException { + } + + public DConfigBeanRoot restoreDConfigBean(InputStream is, DDBeanRoot dDBeanRoot) throws ConfigurationException { + return null; + } + + public void saveDConfigBean(OutputStream os, DConfigBeanRoot dConfigBeanRoot) throws ConfigurationException { + } + + // helper methods ------------------------------------------------- + + protected void writefile(final File file, final BaseBean bean) throws ConfigurationException { + try { + FileObject cfolder = FileUtil.toFileObject(file.getParentFile()); + if (cfolder == null) { + File parentFile = file.getParentFile(); + try { + cfolder = FileUtil.toFileObject(parentFile.getParentFile()).createFolder(parentFile.getName()); + } catch (IOException ioe) { + throw new ConfigurationException(NbBundle.getMessage(GeronimoDeploymentConfiguration.class, + "MSG_FailedToCreateConfigFolder", parentFile.getAbsolutePath())); + } + } + final FileObject folder = cfolder; + FileSystem fs = folder.getFileSystem(); + fs.runAtomicAction(new FileSystem.AtomicAction() { + public void run() throws IOException { + OutputStream os = null; + FileLock lock = null; + try { + String name = file.getName(); + FileObject configFO = folder.getFileObject(name); + if (configFO == null) { + configFO = folder.createData(name); + } + lock = configFO.lock(); + os = new BufferedOutputStream(configFO.getOutputStream(lock), 4086); + // TODO notification needed + if (bean != null) { + bean.write(os); + } + } finally { + if (os != null) { + try { + os.close(); + } catch (IOException ioe) { + } + } + if (lock != null) + lock.releaseLock(); + } + } + }); + } catch (IOException e) { + throw new ConfigurationException(e.getLocalizedMessage()); + } + } + +} Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/config/GeronimoDeploymentConfiguration.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/config/GeronimoDeploymentConfiguration.java ------------------------------------------------------------------------------ svn:executable = * Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/config/GeronimoDeploymentConfiguration.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/config/GeronimoDeploymentConfiguration.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/Customizer.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/Customizer.java?view=auto&rev=549644 ============================================================================== --- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/Customizer.java (added) +++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/Customizer.java Thu Jun 21 16:18:31 2007 @@ -0,0 +1,60 @@ +package org.apache.geronimo.netbeans.customizer; + +import javax.swing.JTabbedPane; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import org.openide.util.NbBundle; +import org.netbeans.modules.j2ee.deployment.common.api.J2eeLibraryTypeProvider; +import org.netbeans.modules.j2ee.deployment.plugins.spi.J2eePlatformImpl; + +/** + * Instance customizer which is accessible from server manager. + */ +public class Customizer extends JTabbedPane { + + private static final String CLASSPATH = J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH; + private static final String SOURCES = J2eeLibraryTypeProvider.VOLUME_TYPE_SRC; + private static final String JAVADOC = J2eeLibraryTypeProvider.VOLUME_TYPE_JAVADOC; + + private final J2eePlatformImpl platform; + private final CustomizerDataSupport custData; + + public Customizer(CustomizerDataSupport custData, J2eePlatformImpl platform) { + this.custData = custData; + this.platform = platform; + initComponents(); + } + + private void initComponents() { + getAccessibleContext().setAccessibleName(NbBundle.getMessage(Customizer.class, "ACS_Customizer")); + getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(Customizer.class, "ACS_Customizer")); + // set help ID according to selected tab + addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + String helpID = null; + switch (getSelectedIndex()) { + case 0: + helpID = "geronimo_customizer_platform"; // NOI18N + break; + case 1: + helpID = "geronimo_customizer_classes"; // NOI18N + break; + case 2: + helpID = "geronimo_customizer_sources"; // NOI18N + break; + case 3: + helpID = "geronimo_customizer_javadoc"; // NOI18N + break; + } + putClientProperty("HelpID", helpID); // NOI18N + } + }); + addTab(NbBundle.getMessage(Customizer.class, "TXT_Platform"), new CustomizerJVM(custData)); + addTab(NbBundle.getMessage(Customizer.class, "TXT_Tab_Classes"), CustomizerSupport + .createClassesCustomizer(custData.getClassModel())); + addTab(NbBundle.getMessage(Customizer.class, "TXT_Tab_Sources"), CustomizerSupport.createSourcesCustomizer( + custData.getSourceModel(), null)); + addTab(NbBundle.getMessage(Customizer.class, "TXT_Tab_Javadoc"), CustomizerSupport.createJavadocCustomizer( + custData.getJavadocsModel(), null)); + } +} Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/Customizer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/Customizer.java ------------------------------------------------------------------------------ svn:executable = * Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/Customizer.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/Customizer.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/CustomizerDataSupport.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/CustomizerDataSupport.java?view=auto&rev=549644 ============================================================================== --- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/CustomizerDataSupport.java (added) +++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/CustomizerDataSupport.java Thu Jun 21 16:18:31 2007 @@ -0,0 +1,310 @@ +package org.apache.geronimo.netbeans.customizer; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.Arrays; +import javax.swing.ButtonModel; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JToggleButton; +import javax.swing.event.ChangeListener; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.event.ListDataEvent; +import javax.swing.event.ListDataListener; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import javax.swing.text.PlainDocument; +import org.apache.geronimo.netbeans.util.GeronimoProperties; +import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.java.platform.JavaPlatformManager; +import org.netbeans.api.java.platform.Specification; +import org.openide.ErrorManager; + +/** + * Customizer data support keeps models for all the customizer components, initializes them, tracks model changes and + * performs save. + */ +public class CustomizerDataSupport { + + // models + private DefaultComboBoxModel jvmModel; + private Document javaOptsModel; + private ButtonModel proxyModel; + private CustomizerSupport.PathModel sourceModel; + private CustomizerSupport.PathModel classModel; + private CustomizerSupport.PathModel javadocModel; + + // model dirty flags + private boolean jvmModelFlag; + private boolean javaOptsModelFlag; + private boolean proxyModelFlag; + private boolean sourceModelFlag; + private boolean javadocModelFlag; + + private GeronimoProperties properties; + + /** + * Creates a new instance of CustomizerDataSupport + */ + public CustomizerDataSupport(GeronimoProperties properties) { + this.properties = properties; + init(); + } + + /** Initialize the customizer models. */ + private void init() { + + // jvmModel + jvmModel = new DefaultComboBoxModel(); + loadJvmModel(); + jvmModel.addListDataListener(new ListDataListener() { + public void contentsChanged(ListDataEvent e) { + jvmModelFlag = true; + store(); // This is just temporary until the server manager + // has OK and Cancel buttons + } + + public void intervalAdded(ListDataEvent e) { + } + + public void intervalRemoved(ListDataEvent e) { + } + }); + + // javaOptions + javaOptsModel = createDocument(properties.getJavaOpts()); + javaOptsModel.addDocumentListener(new ModelChangeAdapter() { + public void modelChanged() { + javaOptsModelFlag = true; + store(); // This is just temporary until the server manager + // has OK and Cancel buttons + } + }); + + // proxyModel + proxyModel = createToggleButtonModel(properties.getProxyEnabled()); + proxyModel.addItemListener(new ModelChangeAdapter() { + public void modelChanged() { + proxyModelFlag = true; + store(); // This is just temporary until the server manager + // has OK and Cancel buttons + } + }); + + // classModel + classModel = new CustomizerSupport.PathModel(properties.getClasses()); + + // sourceModel + sourceModel = new CustomizerSupport.PathModel(properties.getSources()); + sourceModel.addListDataListener(new ModelChangeAdapter() { + public void modelChanged() { + sourceModelFlag = true; + store(); // This is just temporary until the server manager + // has OK and Cancel buttons + } + }); + + // javadocModel + javadocModel = new CustomizerSupport.PathModel(properties.getJavadocs()); + javadocModel.addListDataListener(new ModelChangeAdapter() { + public void modelChanged() { + javadocModelFlag = true; + store(); // This is just temporary until the server manager + // has OK and Cancel buttons + } + }); + } + + /** Update the jvm model */ + public void loadJvmModel() { + JavaPlatformManager jpm = JavaPlatformManager.getDefault(); + JavaPlatformAdapter curJvm = (JavaPlatformAdapter) jvmModel.getSelectedItem(); + String curPlatformName = null; + if (curJvm != null) { + curPlatformName = curJvm.getName(); + } else { + curPlatformName = (String) properties.getJavaPlatform().getProperties().get( + GeronimoProperties.PLAT_PROP_ANT_NAME); + } + + jvmModel.removeAllElements(); + + // feed the combo with sorted platform list + JavaPlatform[] j2sePlatforms = jpm.getPlatforms(null, new Specification("J2SE", null)); // NOI18N + JavaPlatformAdapter[] platformAdapters = new JavaPlatformAdapter[j2sePlatforms.length]; + for (int i = 0; i < platformAdapters.length; i++) { + platformAdapters[i] = new JavaPlatformAdapter(j2sePlatforms[i]); + } + Arrays.sort(platformAdapters); + for (int i = 0; i < platformAdapters.length; i++) { + JavaPlatformAdapter platformAdapter = platformAdapters[i]; + jvmModel.addElement(platformAdapter); + // try to set selected item + if (curPlatformName != null) { + if (curPlatformName.equals(platformAdapter.getName())) { + jvmModel.setSelectedItem(platformAdapter); + } + } + } + } + + // model getters ---------------------------------------------------------- + + public DefaultComboBoxModel getJvmModel() { + return jvmModel; + } + + public Document getJavaOptsModel() { + return javaOptsModel; + } + + public ButtonModel getProxyModel() { + return proxyModel; + } + + public CustomizerSupport.PathModel getClassModel() { + return classModel; + } + + public CustomizerSupport.PathModel getSourceModel() { + return sourceModel; + } + + public CustomizerSupport.PathModel getJavadocsModel() { + return javadocModel; + } + + // private helper methods ------------------------------------------------- + + /** Save all changes */ + private void store() { + + if (jvmModelFlag) { + JavaPlatformAdapter platformAdapter = (JavaPlatformAdapter) jvmModel.getSelectedItem(); + properties.setJavaPlatform(platformAdapter.getJavaPlatform()); + jvmModelFlag = false; + } + + if (javaOptsModelFlag) { + properties.setJavaOpts(getText(javaOptsModel)); + javaOptsModelFlag = false; + } + + if (proxyModelFlag) { + properties.setProxyEnabled(proxyModel.isSelected()); + proxyModelFlag = false; + } + + if (sourceModelFlag) { + properties.setSources(sourceModel.getData()); + sourceModelFlag = false; + } + + if (javadocModelFlag) { + properties.setJavadocs(javadocModel.getData()); + javadocModelFlag = false; + } + } + + /** + * Create a Document initialized by the specified text parameter, which may be null + */ + private Document createDocument(String text) { + PlainDocument doc = new PlainDocument(); + if (text != null) { + try { + doc.insertString(0, text, null); + } catch (BadLocationException e) { + ErrorManager.getDefault().notify(e); + } + } + return doc; + } + + /** Get the text value from the document */ + private String getText(Document doc) { + try { + return doc.getText(0, doc.getLength()); + } catch (BadLocationException e) { + ErrorManager.getDefault().notify(e); + return null; + } + } + + /** + * Create a ToggleButtonModel inilialized by the specified selected parameter. + */ + private JToggleButton.ToggleButtonModel createToggleButtonModel(boolean selected) { + JToggleButton.ToggleButtonModel model = new JToggleButton.ToggleButtonModel(); + model.setSelected(selected); + return model; + } + + // private helper class --------------------------------------------------- + + /** + * Adapter that implements several listeners, which is useful for dirty model monitoring. + */ + private abstract class ModelChangeAdapter implements ListDataListener, DocumentListener, ItemListener, + ChangeListener { + + public abstract void modelChanged(); + + public void contentsChanged(ListDataEvent e) { + modelChanged(); + } + + public void intervalAdded(ListDataEvent e) { + modelChanged(); + } + + public void intervalRemoved(ListDataEvent e) { + modelChanged(); + } + + public void changedUpdate(DocumentEvent e) { + modelChanged(); + } + + public void removeUpdate(DocumentEvent e) { + modelChanged(); + } + + public void insertUpdate(DocumentEvent e) { + modelChanged(); + } + + public void itemStateChanged(ItemEvent e) { + modelChanged(); + } + + public void stateChanged(javax.swing.event.ChangeEvent e) { + modelChanged(); + } + } + + /** Java platform combo box model helper */ + private static class JavaPlatformAdapter implements Comparable { + private JavaPlatform platform; + + public JavaPlatformAdapter(JavaPlatform platform) { + this.platform = platform; + } + + public JavaPlatform getJavaPlatform() { + return platform; + } + + public String getName() { + return (String) platform.getProperties().get(GeronimoProperties.PLAT_PROP_ANT_NAME); + } + + public String toString() { + return platform.getDisplayName(); + } + + public int compareTo(Object o) { + return toString().compareTo(o.toString()); + } + } +} Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/CustomizerDataSupport.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/CustomizerDataSupport.java ------------------------------------------------------------------------------ svn:executable = * Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/CustomizerDataSupport.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/customizer/CustomizerDataSupport.java ------------------------------------------------------------------------------ svn:mime-type = text/plain