diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JB7Deployer.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JB7Deployer.java new file mode 100644 --- /dev/null +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JB7Deployer.java @@ -0,0 +1,142 @@ +package org.netbeans.modules.j2ee.jboss4; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.MissingResourceException; +import java.util.concurrent.Callable; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.enterprise.deploy.shared.ActionType; +import javax.enterprise.deploy.shared.CommandType; +import javax.enterprise.deploy.shared.ModuleType; +import javax.enterprise.deploy.shared.StateType; +import javax.enterprise.deploy.spi.Target; +import javax.enterprise.deploy.spi.TargetModuleID; +import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; +import org.netbeans.modules.j2ee.jboss4.ide.JBDeploymentStatus; +import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.NbBundle; + +/** + * + * @author Pragalathan M + */ +public class JB7Deployer extends JBDeployer { + + private static final Logger LOGGER = Logger.getLogger(JB7Deployer.class.getName()); + protected TargetModuleID deployedModuleID; + + public JB7Deployer(String serverUri, JBDeploymentManager dm) { + super(serverUri, dm); + } + + @Override + public void run() { + if (dm == null) { + return; + } + final String deployDir = InstanceProperties.getInstanceProperties(uri).getProperty(JBPluginProperties.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(JBDeployer.class, "MSG_DEPLOYING", file.getAbsolutePath()); + fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, StateType.RUNNING, msg)); + + try { + FileUtil.copyFile(foIn, foDestDir, fileName); + String webUrl = mainModuleID.getWebURL(); + if (webUrl == null) { + TargetModuleID[] ch = mainModuleID.getChildTargetModuleID(); + if (ch != null) { + for (int i = 0; i < ch.length; i++) { + webUrl = ch[i].getWebURL(); + if (webUrl != null) { + break; + } + } + } + + } + + final String finalWebUrl = webUrl; + //Deploy file + dm.invokeLocalAction(new Callable() { + + @Override + public Void call() throws Exception { + File statusFile = new File(deployDir, file.getName() + ".deployed"); + + for (int i = 0, limit = (int) TIMEOUT / POLLING_INTERVAL; i < limit && !statusFile.exists(); i++) { + Thread.sleep(POLLING_INTERVAL); + } + + Target[] targets = dm.getTargets(); + ModuleType moduleType = getModuleType(file.getName().substring(file.getName().lastIndexOf(".") + 1)); + TargetModuleID[] modules = dm.getAvailableModules(moduleType, targets); + for (TargetModuleID targetModuleID : modules) { + if (targetModuleID.getModuleID().equals(mainModuleID.getModuleID())) { + deployedModuleID = new WrappedTargetModuleID(targetModuleID, finalWebUrl); + break; + } + } + return null; + } + }); + + if (webUrl != null) { + URL url = new URL(webUrl); + String waitingMsg = NbBundle.getMessage(JBDeployer.class, "MSG_Waiting_For_Url", url); + fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, StateType.RUNNING, waitingMsg)); + } + } catch (MalformedURLException ex) { + LOGGER.log(Level.INFO, null, ex); + fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, StateType.FAILED, "Failed")); + } catch (MissingResourceException ex) { + LOGGER.log(Level.INFO, null, ex); + fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, StateType.FAILED, "Failed")); + } catch (Exception ex) { + LOGGER.log(Level.INFO, null, ex); + fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, StateType.FAILED, "Failed")); + } + + fireHandleProgressEvent(null, new JBDeploymentStatus(ActionType.EXECUTE, CommandType.DISTRIBUTE, StateType.COMPLETED, "Applicaton Deployed")); + } + + private ModuleType getModuleType(String extension) { + if (extension.equals("war")) { + return ModuleType.WAR; + } + + if (extension.equals("ear")) { + return ModuleType.EAR; + } + + if (extension.equals("car")) { + return ModuleType.CAR; + } + + if (extension.equals("ejb")) { + return ModuleType.EJB; + } + + if (extension.equals("rar")) { + return ModuleType.RAR; + } + return null; + } + + @Override + public TargetModuleID[] getResultTargetModuleIDs() { + return new TargetModuleID[]{deployedModuleID}; + } +} diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeployer.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeployer.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeployer.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeployer.java @@ -89,17 +89,17 @@ */ public class JBDeployer implements ProgressObject, Runnable { /** timeout for waiting for URL connection */ - private static final int TIMEOUT = 60000; + protected static final int TIMEOUT = 60000; - private static final int POLLING_INTERVAL = 1000; + protected static final int POLLING_INTERVAL = 1000; private static final Logger LOGGER = Logger.getLogger(JBDeployer.class.getName()); - private final JBDeploymentManager dm; + protected final JBDeploymentManager dm; - private File file; - private String uri; - private JBTargetModuleID mainModuleID; + protected File file; + protected String uri; + protected JBTargetModuleID mainModuleID; /** Creates a new instance of JBDeployer */ public JBDeployer(String serverUri, JBDeploymentManager dm) { diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeploymentFactory.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeploymentFactory.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeploymentFactory.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeploymentFactory.java @@ -81,7 +81,7 @@ public class JBDeploymentFactory implements DeploymentFactory { public static final String URI_PREFIX = "jboss-deployer:"; // NOI18N - + private static final String DISCONNECTED_URI = "jboss-deployer:http://localhost:8080&"; // NOI18N private static final Logger LOGGER = Logger.getLogger(JBDeploymentFactory.class.getName()); @@ -156,6 +156,11 @@ // dom4j.jar library for JBoss Application Server 4.0.5 domFile = new File(domainRoot, JBPluginUtils.LIB + "dom4j.jar"); // NOI18N } + + String sep = File.separator; + if (!domFile.exists() && "7".equals(JBVer.getMajorNumber())) { + domFile = new File(serverRoot, JBPluginUtils.MODULES + "org" + sep + "dom4j" + sep + "main" + sep + "dom4j-1.6.1.jar"); // NOI18N + } if (!domFile.exists()) { domFile = null; LOGGER.log(Level.INFO, "No dom4j.jar availabale on classpath"); // NOI18N @@ -179,7 +184,31 @@ urlList.add(domFile.toURI().toURL()); } - if (version5Above) { + if ("7".equals(JBVer.getMajorNumber())) { + File org = new File(serverRoot, JBPluginUtils.MODULES + "org"); + File jboss = new File(org, "jboss"); + File as = new File(jboss, "as"); + String versionString = JBVer.getMajorNumber()+"."+JBVer.getMinorNumber()+"."+JBVer.getMicroNumber()+"."+JBVer.getUpdate(); + + if (domFile.exists()) { + urlList.add(domFile.toURI().toURL()); + } + + urlList.add(new File(serverRoot, "jboss-modules.jar").toURI().toURL()); + urlList.add(new File(serverRoot, "bin"+sep+"client"+sep+"jboss-client.jar").toURI().toURL()); + urlList.add(new File(jboss, "logging" + sep + "main" + sep + "jboss-logging-3.1.0.GA.jar").toURI().toURL()); + urlList.add(new File(jboss, "threads" + sep + "main" + sep + "jboss-threads-2.0.0.GA.jar").toURI().toURL()); + urlList.add(new File(jboss, "remoting3" + sep + "main" + sep + "jboss-remoting-3.2.3.GA.jar").toURI().toURL()); + urlList.add(new File(jboss, "xnio" + sep + "main" + sep + "xnio-api-3.0.3.GA.jar").toURI().toURL()); + urlList.add(new File(jboss, "xnio" + sep + "nio" + sep + "main" + sep + "xnio-nio-3.0.3.GA.jar").toURI().toURL()); + urlList.add(new File(jboss, "dmr" + sep + "main"+ sep + "jboss-dmr-1.1.1.Final.jar").toURI().toURL()); + urlList.add(new File(jboss, "msc" + sep + "main" + sep + "jboss-msc-1.0.2.GA.jar").toURI().toURL()); + urlList.add(new File(jboss, "common-core" + sep + "main" + sep + "jboss-common-core-2.2.17.GA.jar").toURI().toURL()); + urlList.add(new File(as, "ee" + sep + "deployment" + sep + "main" + sep + "jboss-as-ee-deployment-" + versionString + ".jar").toURI().toURL()); + urlList.add(new File(as, "naming" + sep + "main" + sep + "jboss-as-naming-" + versionString + ".jar").toURI().toURL()); + urlList.add(new File(as, "controller-client" + sep + "main" + sep + "jboss-as-controller-client-" + versionString + ".jar").toURI().toURL()); + urlList.add(new File(as, "protocol" + sep + "main" + sep + "jboss-as-protocol-" + versionString + ".jar").toURI().toURL()); + } else if (version5Above) { // get lient class path for Jboss 5.0 List clientClassUrls = JBPluginUtils.getJB5ClientClasspath( serverRoot); @@ -274,9 +303,16 @@ jbossFactory = (DeploymentFactory) FACTORIES_CACHE.get(ip); } if (jbossFactory == null) { + Version version = JBPluginUtils.getServerVersion(new File(jbossRoot)); URLClassLoader loader = (ip != null) ? getJBClassLoader(ip) : createJBClassLoader(jbossRoot, domainRoot); - jbossFactory = (DeploymentFactory) loader.loadClass("org.jboss.deployment.spi.factories.DeploymentFactoryImpl").newInstance();//NOI18N - + if(version!= null && "7".equals(version.getMajorNumber())) { + Class c = loader.loadClass("org.jboss.as.ee.deployment.spi.factories.DeploymentFactoryImpl"); + c.getMethod("register").invoke(null); + jbossFactory = (DeploymentFactory) c.newInstance();//NOI18N + } else { + jbossFactory = (DeploymentFactory) loader.loadClass("org.jboss.deployment.spi.factories.DeploymentFactoryImpl").newInstance();//NOI18N + } + if (ip != null) { FACTORIES_CACHE.put(ip, jbossFactory); diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeploymentManager.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeploymentManager.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeploymentManager.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/JBDeploymentManager.java @@ -42,6 +42,7 @@ * made subject to such option by the copyright holder. */ package org.netbeans.modules.j2ee.jboss4; + import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; @@ -55,6 +56,7 @@ import java.net.URLClassLoader; import java.util.Locale; import java.util.Properties; +import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.logging.Level; import java.util.logging.Logger; @@ -78,6 +80,7 @@ import javax.naming.NamingException; import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils; +import org.openide.util.Exceptions; /** * @@ -94,14 +97,14 @@ private InstanceProperties instanceProperties; private boolean needsRestart; - + private Boolean as7; /** * 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 final Map propertiesToIsRunning = Collections.synchronizedMap(new WeakHashMap()); - + /** Creates a new instance of JBDeploymentManager */ public JBDeploymentManager(DeploymentManager dm, String uri, String username, String password) { realUri = uri; @@ -139,6 +142,25 @@ return instanceProperties; } + /** + * This is a handy method to execute the any {@code action} within JBoss's class loader. + * + * @param action the action to be executed + * @return T + * @throws ExecutionException + */ + public T invokeLocalAction(Callable action) throws Exception { + ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); + try { + InstanceProperties ip = getInstanceProperties(); + URLClassLoader loader = JBDeploymentFactory.getJBClassLoader(ip); + Thread.currentThread().setContextClassLoader(loader); + return action.call(); + } finally { + Thread.currentThread().setContextClassLoader(oldLoader); + } + } + public T invokeRemoteAction(JBRemoteAction action) throws ExecutionException { ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); @@ -177,8 +199,10 @@ System.setProperty(JAVA_SEC_AUTH_LOGIN_CONF, securityConf.getAbsolutePath()); // NOI18N } - // Gets naming context - ctx = new InitialContext(env); + if (!props.isVersion(JBPluginUtils.JBOSS_7_0_0)) { + // Gets naming context + ctx = new InitialContext(env); + } //restore java.security.auth.login.config system property if (oldAuthConf != null) { @@ -189,30 +213,44 @@ MBeanServerConnection rmiServer = null; try { - conn = JMXConnectorFactory.connect(new JMXServiceURL( - "service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi")); + JMXServiceURL url; + if (props.isVersion(JBPluginUtils.JBOSS_7_0_0)) { + // using management-native port + url = new JMXServiceURL( + System.getProperty("jmx.service.url", "service:jmx:remoting-jmx://localhost:9999")); // NOI18N + } else { + url = new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi"); // NOI18N + } + conn = JMXConnectorFactory.connect(url); rmiServer = conn.getMBeanServerConnection(); } catch (IOException ex) { LOGGER.log(Level.FINE, null, ex); } - if (rmiServer == null) { + if (rmiServer == null && ctx != null) { // Lookup RMI Adaptor rmiServer = (MBeanServerConnection) ctx.lookup("/jmx/invoker/RMIAdaptor"); // NOI18N } JBoss5ProfileServiceProxy profileService = null; try { - Object service = ctx.lookup("ProfileService"); // NOI18N - if (service != null) { - profileService = new JBoss5ProfileServiceProxy(service); + if (ctx != null) { + Object service = ctx.lookup("ProfileService"); // NOI18N + if (service != null) { + profileService = new JBoss5ProfileServiceProxy(service); + } } } catch (NameNotFoundException ex) { LOGGER.log(Level.FINE, null, ex); } - return action.action(rmiServer, profileService); + if (rmiServer != null) { + return action.action(rmiServer, profileService); + } else { + throw new IllegalStateException("No rmi server acquired for " + realUri); + } } catch (NameNotFoundException ex) { LOGGER.log(Level.FINE, null, ex); throw new ExecutionException(ex); @@ -261,13 +299,26 @@ propertiesToIsRunning.put(ip, isRunning); } + boolean isAs7() { + if (as7 == null) { + as7 = getProperties().isVersion(JBPluginUtils.JBOSS_7_0_0); + } + return as7; + } //////////////////////////////////////////////////////////////////////////// // DeploymentManager Implementation //////////////////////////////////////////////////////////////////////////// public ProgressObject distribute(Target[] target, File file, File file2) throws IllegalStateException { + if (isAs7()) { + return new JB7Deployer(realUri, this).deploy(target, file, file2, getHost(), getPort()); + } return new JBDeployer(realUri, this).deploy(target, file, file2, getHost(), getPort()); } + public ProgressObject distributeTarget(Target[] target, File file, File file2) throws IllegalStateException { + return dm.distribute(target, file, file2); + } + public DeploymentConfiguration createConfiguration(DeployableObject deployableObject) throws InvalidModuleException { throw new RuntimeException("This method should never be called."); // NOI18N } @@ -292,7 +343,21 @@ return dm.stop(targetModuleID); } - public ProgressObject start(TargetModuleID[] targetModuleID) throws IllegalStateException { + public ProgressObject start(final TargetModuleID[] targetModuleID) throws IllegalStateException { + if (isAs7()) { + try { + return invokeLocalAction(new Callable() { + + @Override + public ProgressObject call() { + return dm.start(unwrap(targetModuleID)); + } + }); + } catch (Exception ex) { + LOGGER.log(Level.INFO, null, ex); + } + } + return dm.start(targetModuleID); } @@ -305,12 +370,16 @@ } public TargetModuleID[] getAvailableModules(ModuleType moduleType, Target[] target) throws TargetException, IllegalStateException { - //return dm.getAvailableModules(moduleType, target); + if (isAs7()) { + return dm.getAvailableModules(moduleType, target); + } return new TargetModuleID[]{}; } public TargetModuleID[] getNonRunningModules(ModuleType moduleType, Target[] target) throws TargetException, IllegalStateException { - //return dm.getNonRunningModules(moduleType, target); + if (isAs7()) { + return dm.getAvailableModules(moduleType, target); + } return new TargetModuleID[]{}; } @@ -319,6 +388,9 @@ } public ProgressObject redeploy(TargetModuleID[] targetModuleID, File file, File file2) throws UnsupportedOperationException, IllegalStateException { + if (isAs7()) { + return new JB7Deployer(realUri, this).redeploy(targetModuleID, file, file2); + } return new JBDeployer(realUri, this).redeploy(targetModuleID, file, file2); } @@ -388,4 +460,19 @@ public synchronized boolean getNeedsRestart() { return needsRestart; } + + private static TargetModuleID[] unwrap(TargetModuleID[] ids) { + if (ids == null || ids.length == 0) { + return ids; + } + TargetModuleID[] ret = new TargetModuleID[ids.length]; + for (int i = 0; i < ids.length; i++) { + if (ids[i] instanceof WrappedTargetModuleID) { + ret[i] = ((WrappedTargetModuleID) ids[i]).getOriginal(); + } else { + ret[i] = ids[i]; + } + } + return ret; + } } diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/WrappedTargetModuleID.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/WrappedTargetModuleID.java new file mode 100644 --- /dev/null +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/WrappedTargetModuleID.java @@ -0,0 +1,98 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.j2ee.jboss4; + +import javax.enterprise.deploy.spi.Target; +import javax.enterprise.deploy.spi.TargetModuleID; + +/** + * + * @author Petr Hejl + */ +public class WrappedTargetModuleID implements TargetModuleID { + + private final TargetModuleID original; + + private final String webUrl; + + public WrappedTargetModuleID(TargetModuleID original, String webUrl) { + this.original = original; + this.webUrl = webUrl; + } + + @Override + public Target getTarget() { + return original.getTarget(); + } + + @Override + public String getModuleID() { + return original.getModuleID(); + } + + @Override + public String getWebURL() { + if (webUrl != null) { + return webUrl; + } + return original.getWebURL(); + } + + @Override + public String toString() { + return original.toString(); + } + + @Override + public TargetModuleID getParentTargetModuleID() { + return original.getParentTargetModuleID(); + } + + @Override + public TargetModuleID[] getChildTargetModuleID() { + return original.getChildTargetModuleID(); + } + + public TargetModuleID getOriginal() { + return original; + } +} diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBOutputSupport.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBOutputSupport.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBOutputSupport.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBOutputSupport.java @@ -309,10 +309,13 @@ || line.indexOf("Starting JBossAS") > -1) { // JBoss 6.0 message // NOI18N LOGGER.log(Level.FINER, "STARTING message fired"); // NOI18N //fireStartProgressEvent(StateType.RUNNING, createProgressMessage("MSG_START_SERVER_IN_PROGRESS")); // NOI18N - } else if ((line.indexOf("JBoss (MX MicroKernel)") > -1 // JBoss 4.x message // NOI18N + } else if ( ((line.indexOf("JBoss (MX MicroKernel)") > -1 // JBoss 4.x message // NOI18N || line.indexOf("JBoss (Microcontainer)") > -1 // JBoss 5.0 message // NOI18N - || line.indexOf("JBossAS") > -1) // JBoss 6.0 message // NOI18N - && line.indexOf("Started in") > -1) { // NOI18N + || line.indexOf("JBossAS") > -1 // JBoss 6.0 message // NOI18N + || line.indexOf("JBoss AS") > -1)// JBoss 7.0 message // NOI18N + && (line.indexOf("Started in") > -1) // NOI18N + || line.indexOf("started in") > -1 // NOI18N + || line.indexOf("started (with errors) in") > -1)) { // JBoss 7 with some errors (include wrong deployments) // NOI18N LOGGER.log(Level.FINER, "STARTED message fired"); // NOI18N synchronized (JBOutputSupport.this) { diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartRunnable.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartRunnable.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartRunnable.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartRunnable.java @@ -100,8 +100,12 @@ private final static String STARTUP_SH = File.separator + "bin" + File.separator + "run.sh"; // NOI18N + private final static String STANDALONE_SH = File.separator + + "bin" + File.separator + "standalone.sh"; // NOI18N private final static String STARTUP_BAT = File.separator + "bin" + File.separator + RUN_FILE_NAME; // NOI18N + private final static String STANDALONE_BAT = File.separator + + "bin" + File.separator + "standalone.bat"; // NOI18N private final static String CONF_BAT = File.separator + "bin" + File.separator + CONF_FILE_NAME; // NOI18N @@ -316,7 +320,7 @@ final String instanceName = ip.getProperty(JBPluginProperties.PROPERTY_SERVER); String args = ("all".equals(instanceName) ? "-b 127.0.0.1 " : "") + "-c " + instanceName; // NOI18N - return new NbProcessDescriptor(serverRunFileName, args); + return new NbProcessDescriptor(serverRunFileName, isJBoss7()? "" : args); } private String getRunFileName( InstanceProperties ip, String[] envp ){ @@ -359,13 +363,17 @@ Logger.getLogger("global").log(Level.INFO, null, ioe); final String serverLocation = ip.getProperty(JBPluginProperties.PROPERTY_ROOT_DIR); - final String serverRunFileName = serverLocation + (Utilities.isWindows() ? STARTUP_BAT : STARTUP_SH); + final String serverRunFileName = serverLocation + (isJBoss7() ? Utilities.isWindows() ? STANDALONE_BAT : STANDALONE_SH : Utilities.isWindows() ? STARTUP_BAT : STARTUP_SH); fireStartProgressEvent(StateType.FAILED, createProgressMessage("MSG_START_SERVER_FAILED_PD", serverRunFileName)); return null; } } + private boolean isJBoss7() { + return dm.getProperties().isVersion(JBPluginUtils.JBOSS_7_0_0); + } + private InputOutput openConsole() { InputOutput io = UISupport.getServerIO(dm.getUrl()); if (io == null) { @@ -422,7 +430,7 @@ String serverLocation = getProperties().getProperty( JBPluginProperties.PROPERTY_ROOT_DIR); String serverRunFileName = serverLocation + - (Utilities.isWindows() ? STARTUP_BAT : STARTUP_SH); + (isJBoss7() ? Utilities.isWindows() ? STANDALONE_BAT : STANDALONE_SH : Utilities.isWindows() ? STARTUP_BAT : STARTUP_SH); if ( needChange ){ String contentRun = readFile(serverRunFileName); String contentConf = readFile(serverLocation + CONF_BAT); diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartServer.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartServer.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartServer.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStartServer.java @@ -75,6 +75,8 @@ import javax.management.MBeanServerConnection; import org.netbeans.modules.j2ee.jboss4.JBRemoteAction; import org.netbeans.modules.j2ee.jboss4.JBoss5ProfileServiceProxy; +import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils; +import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils.Version; import org.openide.util.NbBundle; import org.netbeans.modules.j2ee.jboss4.nodes.Util; @@ -252,22 +254,32 @@ @Override public Void action(MBeanServerConnection connection, JBoss5ProfileServiceProxy profileService) throws Exception { - Object serverName = Util.getMBeanParameter(connection, "ServerName", "jboss.system:type=ServerConfig"); //NOI18N - Object serverHome = Util.getMBeanParameter(connection, "ServerHomeLocation", "jboss.system:type=ServerConfig"); //NOI18N - boolean isJBoss6 = serverHome != null; - if (!isJBoss6) { - serverHome = Util.getMBeanParameter(connection, "ServerHomeDir", "jboss.system:type=ServerConfig"); //NOI18N - } - try { - if (serverHome != null) { - if (isJBoss6) { - serverHome = new File(((URL) serverHome).toURI()).getAbsolutePath(); - } else { - serverHome = ((File) serverHome).getAbsolutePath(); + Object serverName = null; + Object serverHome = null; + if (dm.getProperties().isVersion(JBPluginUtils.JBOSS_7_0_0)) { + serverHome = Util.getMBeanParameter(connection, "baseDir", "jboss.as:core-service=server-environment"); //NOI18N + serverName = Util.getMBeanParameter(connection, "launchType", "jboss.as:core-service=server-environment"); //NOI18N + if (serverName != null) { + serverName = serverName.toString().toLowerCase(); + } + } else { + serverName = Util.getMBeanParameter(connection, "ServerName", "jboss.system:type=ServerConfig"); //NOI18N + serverHome = Util.getMBeanParameter(connection, "ServerHomeLocation", "jboss.system:type=ServerConfig"); //NOI18N + boolean isJBoss6 = serverHome != null; + if (!isJBoss6) { + serverHome = Util.getMBeanParameter(connection, "ServerHomeDir", "jboss.system:type=ServerConfig"); //NOI18N + } + try { + if (serverHome != null) { + if (isJBoss6) { + serverHome = new File(((URL) serverHome).toURI()).getAbsolutePath(); + } else { + serverHome = ((File) serverHome).getAbsolutePath(); + } } + } catch (URISyntaxException use) { + LOGGER.log(Level.WARNING, "error getting file from URI: " + serverHome, use); //NOI18N } - } catch (URISyntaxException use) { - LOGGER.log(Level.WARNING, "error getting file from URI: " + serverHome, use); //NOI18N } if (serverName == null || serverHome == null) { diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStopRunnable.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStopRunnable.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStopRunnable.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/JBStopRunnable.java @@ -77,7 +77,9 @@ private static final Logger LOGGER = Logger.getLogger(JBStopRunnable.class.getName()); private static final String SHUTDOWN_SH = "/bin/shutdown.sh"; // NOI18N + private static final String JBOSS_CLI_SH = "/bin/jboss-cli.sh"; // NOI18N private static final String SHUTDOWN_BAT = "/bin/shutdown.bat"; // NOI18N + private static final String JBOSS_CLI_BAT = "/bin/jboss-cli.bat"; // NOI18N private static final int TIMEOUT = 300000; @@ -89,6 +91,10 @@ this.startServer = startServer; } + private boolean isJBoss7() { + return dm.getProperties().isVersion(JBPluginUtils.JBOSS_7_0_0); + } + private String[] createEnvironment() { JBProperties properties = dm.getProperties(); @@ -120,7 +126,7 @@ String serverName = ip.getProperty(InstanceProperties.DISPLAY_NAME_ATTR); String serverLocation = ip.getProperty(JBPluginProperties.PROPERTY_ROOT_DIR); - String serverStopFileName = serverLocation + (Utilities.isWindows() ? SHUTDOWN_BAT : SHUTDOWN_SH); + String serverStopFileName = serverLocation + (isJBoss7() ? Utilities.isWindows() ? JBOSS_CLI_BAT : JBOSS_CLI_SH :Utilities.isWindows() ? SHUTDOWN_BAT : SHUTDOWN_SH); File serverStopFile = new File(serverStopFileName); if (!serverStopFile.exists()){ @@ -131,6 +137,10 @@ JBProperties properties = dm.getProperties(); StringBuilder additionalParams = new StringBuilder(32); int jnpPort = JBPluginUtils.getJnpPortNumber(ip.getProperty(JBPluginProperties.PROPERTY_SERVER_DIR)); + NbProcessDescriptor pd; + if(isJBoss7()) { + pd = new NbProcessDescriptor(serverStopFileName, "--connect --command=:shutdown"); // NOI18N + } else { if (dm.getProperties().getServerVersion().compareTo(JBPluginUtils.JBOSS_6_0_0) < 0) { additionalParams.append(" -s jnp://localhost:").append(jnpPort); // NOI18N } else { @@ -150,9 +160,9 @@ /* 2008-09-10 The usage of --halt doesn't solve the problem on Windows; it even creates another problem of NB Profiler not being notified about the fact that the server was stopped */ - NbProcessDescriptor pd = new NbProcessDescriptor( + pd = new NbProcessDescriptor( serverStopFileName, "--shutdown " + additionalParams); // NOI18N - + } Process stoppingProcess = null; try { String envp[] = createEnvironment(); diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/ui/Bundle.properties b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/ui/Bundle.properties --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/ui/Bundle.properties +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/ui/Bundle.properties @@ -56,9 +56,9 @@ LBL_BrowseButton=Br&owse... -MSG_InvalidServerLocation=Provide a valid JBoss Application Server 6, 5 or 4 Location +MSG_InvalidServerLocation=Provide a valid JBoss Application Server 7, 6, 5 or 4 Location -MSG_SpecifyServerLocation=Please specify JBoss Application Server 6, 5 or 4 Location +MSG_SpecifyServerLocation=Please specify JBoss Application Server 7, 6, 5 or 4 Location LBL_ChooserName=Choose JBoss Server Location diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/ui/JBInstantiatingIterator.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/ui/JBInstantiatingIterator.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/ui/JBInstantiatingIterator.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/ui/JBInstantiatingIterator.java @@ -146,15 +146,18 @@ Set result = new HashSet(); String displayName = (String)wizard.getProperty(PROP_DISPLAY_NAME); - - String url = JBDeploymentFactory.URI_PREFIX + host + ":" + port; // NOI18N + JBPluginUtils.Version version = JBPluginUtils.getServerVersion(new File(installLocation)); + String url = JBDeploymentFactory.URI_PREFIX; + if(version != null && "7".equals(version.getMajorNumber())){ + url += "//"+host + ":" + port+"?targetType=as7&serverPort="+port; // NOI18N + } else { + url += host + ":" + port; // NOI18N + } if (server != null && !server.equals("")) // NOI18N url += "#" + server; // NOI18N url += "&"+ installLocation; // NOI18N try { - JBPluginUtils.Version version = JBPluginUtils.getServerVersion(new File(installLocation)); - Map initialProperties = new HashMap(); initialProperties.put(JBPluginProperties.PROPERTY_SERVER, server); initialProperties.put(JBPluginProperties.PROPERTY_DEPLOY_DIR, deployDir); @@ -286,6 +289,13 @@ private String deployDir; private String serverPath; + public void setPassword(String password) { + this.password = password; + } + + public void setUserName(String userName) { + this.userName = userName; + } public void setHost(String host){ this.host = host.trim(); diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/ui/JBPluginUtils.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/ui/JBPluginUtils.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/ui/JBPluginUtils.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/ide/ui/JBPluginUtils.java @@ -91,6 +91,8 @@ public static final Version JBOSS_5_0_1 = new Version("5.0.1"); // NOI18N public static final Version JBOSS_6_0_0 = new Version("6.0.0"); // NOI18N + + public static final Version JBOSS_7_0_0 = new Version("7.0.0"); // NOI18N private static final Logger LOGGER = Logger.getLogger(JBPluginUtils.class.getName()); @@ -98,6 +100,8 @@ public static final String LIB = "lib" + File.separator; + public static final String MODULES = "modules" + File.separator; + public static final String CLIENT = "client" + File.separator; public static final String COMMON = "common" + File.separator; @@ -195,6 +199,21 @@ return domainRequirements6x; } + private static List domainRequirements7x; + + private static synchronized List getDomainRequirements7x() { + if (domainRequirements7x == null) { + domainRequirements7x = new ArrayList(11); + Collections.addAll(domainRequirements7x, + "configuration", // NOI18N + "deployments", // NOI18N + "lib" // NOI18N + ); + } + return domainRequirements7x; + } + + //--------------- checking for possible server directory ------------- private static List serverRequirements4x; @@ -249,6 +268,18 @@ return serverRequirements5And6x; } + private static List serverRequirements7x; + private static synchronized List getServerRequirements7x() { + if (serverRequirements7x == null) { + serverRequirements7x = new ArrayList(6); + Collections.addAll(serverRequirements7x, + "bin", // NOI18N + "modules", // NOI18N + "jboss-modules.jar"); // NOI18N + } + return serverRequirements7x; + } + //------------ getting exists servers--------------------------- /** * returns Hashmap @@ -262,14 +293,22 @@ File serverDirectory = new File(serverLocation); if (isGoodJBServerLocation(serverDirectory)) { - File file = new File(serverLocation + File.separator + "server"); // NOI18N - - String[] files = file.list(new FilenameFilter(){ - public boolean accept(File dir, String name){ - if ((new File(dir.getAbsolutePath()+File.separator+name)).isDirectory()) return true; - return false; - } - }); + Version version = getServerVersion(serverDirectory); + File file; + String[] files; + if("7".equals(version.getMajorNumber())) { + files = new String[]{"standalone", "domain"}; + file = serverDirectory; + } else { + file = new File(serverLocation + File.separator + "server"); // NOI18N + files = file.list(new FilenameFilter(){ + @Override + public boolean accept(File dir, String name){ + if ((new File(dir.getAbsolutePath()+File.separator+name)).isDirectory()) return true; + return false; + } + }); + } for(int i = 0; i requirements){ @@ -372,19 +418,26 @@ return isGoodJBServerLocation(candidate, getServerRequirements5And6x()); } + private static boolean isGoodJBServerLocation7x(File candidate){ + return isGoodJBServerLocation(candidate, getServerRequirements7x()); + } + public static boolean isGoodJBServerLocation(File candidate) { Version version = getServerVersion(candidate); if (version == null || (!"4".equals(version.getMajorNumber()) && !"5".equals(version.getMajorNumber()) - && !"6".equals(version.getMajorNumber()))) { // NOI18N + && !"6".equals(version.getMajorNumber()) + && !"7".equals(version.getMajorNumber()))) { // NOI18N return JBPluginUtils.isGoodJBServerLocation4x(candidate) || JBPluginUtils.isGoodJBServerLocation5x(candidate) - || JBPluginUtils.isGoodJBServerLocation6x(candidate); + || JBPluginUtils.isGoodJBServerLocation5x(candidate) + || JBPluginUtils.isGoodJBServerLocation7x(candidate); } return ("4".equals(version.getMajorNumber()) && JBPluginUtils.isGoodJBServerLocation4x(candidate)) // NOI18n || ("5".equals(version.getMajorNumber()) && JBPluginUtils.isGoodJBServerLocation5x(candidate)) // NOI18N - || ("6".equals(version.getMajorNumber()) && JBPluginUtils.isGoodJBServerLocation6x(candidate)); // NOI18N + || ("6".equals(version.getMajorNumber()) && JBPluginUtils.isGoodJBServerLocation6x(candidate)) // NOI18N + || ("7".equals(version.getMajorNumber()) && JBPluginUtils.isGoodJBServerLocation7x(candidate)); // NOI18N } public static boolean isJB4(JBDeploymentManager dm) { @@ -435,6 +488,10 @@ * */ public static String getDeployDir(String domainDir){ + Version version = JBPluginUtils.getServerVersion(new File(JBPluginProperties.getInstance().getInstallLocation())); + if("7".equals(version.getMajorNumber())) { + return domainDir + File.separator + "deployments"; //NOI18N + } return domainDir + File.separator + "deploy"; //NOI18N //todo: get real deploy path } @@ -675,7 +732,26 @@ assert serverPath != null : "Can't determine version with null server path"; // NOI18N File systemJarFile = new File(serverPath, "lib/jboss-system.jar"); // NOI18N - return getVersion(systemJarFile); + Version version = getVersion(systemJarFile); + if(version == null) { + // check for JBoss AS 7 + File serverDir = new File(serverPath, "modules/org/jboss/as/server/main"); + for (File jarFile : serverDir.listFiles(new JarFileFilter())) { + version = getVersion(jarFile); + if(version != null) { + break; + } + } + } + return version; + } + + static class JarFileFilter implements FilenameFilter { + + @Override + public boolean accept(File dir, String name) { + return name.endsWith(".jar"); + } } private static Version getVersion(File systemJarFile) { diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBAbilitiesSupport.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBAbilitiesSupport.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBAbilitiesSupport.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBAbilitiesSupport.java @@ -44,7 +44,7 @@ * * @author Petr Hejl */ -class JBAbilitiesSupport { +public class JBAbilitiesSupport { private final Lookup lookup; @@ -54,6 +54,8 @@ private Boolean isJB6x = null; + private Boolean isJB7x= null; + /** * Constructs the JBAbilitiesSupport. * @@ -101,6 +103,14 @@ isJB6x = version != null && JBPluginUtils.JBOSS_6_0_0.compareTo(version) <= 0; } return isJB6x; + } + + public boolean isJB7x() { + if (isJB7x == null) { + JBDeploymentManager dm = lookup.lookup(JBDeploymentManager.class); + Version version = dm.getProperties().getServerVersion(); + isJB7x = version != null && JBPluginUtils.JBOSS_7_0_0.compareTo(version) <= 0; + } + return isJB7x; } - } diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBEarApplicationsChildren.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBEarApplicationsChildren.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBEarApplicationsChildren.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBEarApplicationsChildren.java @@ -45,12 +45,15 @@ package org.netbeans.modules.j2ee.jboss4.nodes; import java.lang.reflect.Method; -import java.util.Iterator; -import java.util.Set; -import java.util.Vector; +import java.util.*; +import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.logging.Level; import java.util.logging.Logger; +import javax.enterprise.deploy.shared.ModuleType; +import javax.enterprise.deploy.spi.Target; +import javax.enterprise.deploy.spi.TargetModuleID; +import javax.enterprise.deploy.spi.exceptions.TargetException; import javax.management.MBeanServerConnection; import javax.management.ObjectInstance; import javax.management.ObjectName; @@ -61,6 +64,7 @@ import org.netbeans.modules.j2ee.jboss4.nodes.actions.Refreshable; import org.openide.nodes.Children; import org.openide.nodes.Node; +import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.RequestProcessor; @@ -83,75 +87,121 @@ this.abilitiesSupport = new JBAbilitiesSupport(lookup); } - public void updateKeys(){ - setKeys(new Object[] {Util.WAIT_NODE}); + @Override + public void updateKeys() { + setKeys(new Object[]{Util.WAIT_NODE}); + RequestProcessor.getDefault().post(abilitiesSupport.isJB7x() ? new JBoss7EarApplicationNodeUpdater() : new JBossEarApplicationNodeUpdater(), 0); + } - RequestProcessor.getDefault().post(new Runnable() { - Vector keys = new Vector(); + class JBossEarApplicationNodeUpdater implements Runnable { - public void run() { - try { - lookup.lookup(JBDeploymentManager.class).invokeRemoteAction(new JBRemoteAction() { + List keys = new ArrayList(); - @Override - public Void action(MBeanServerConnection connection, JBoss5ProfileServiceProxy profileService) throws Exception { - // Query to the jboss4 server - ObjectName searchPattern; - String propertyName; - if (abilitiesSupport.isRemoteManagementSupported() - && (abilitiesSupport.isJB4x() || abilitiesSupport.isJB6x())) { - searchPattern = new ObjectName("jboss.management.local:j2eeType=J2EEApplication,*"); // NOI18N - propertyName = "name"; // NOI18N - } else { - searchPattern = new ObjectName("jboss.j2ee:service=EARDeployment,*"); // NOI18N - propertyName = "url"; // NOI18N + @Override + public void run() { + try { + lookup.lookup(JBDeploymentManager.class).invokeRemoteAction(new JBRemoteAction() { + + @Override + public Void action(MBeanServerConnection connection, JBoss5ProfileServiceProxy profileService) throws Exception { + // Query to the jboss4 server + ObjectName searchPattern; + String propertyName; + if (abilitiesSupport.isRemoteManagementSupported() + && (abilitiesSupport.isJB4x() || abilitiesSupport.isJB6x())) { + searchPattern = new ObjectName("jboss.management.local:j2eeType=J2EEApplication,*"); // NOI18N + propertyName = "name"; // NOI18N + } else { + searchPattern = new ObjectName("jboss.j2ee:service=EARDeployment,*"); // NOI18N + propertyName = "url"; // NOI18N + } + + Method method = connection.getClass().getMethod("queryMBeans", new Class[] {ObjectName.class, QueryExp.class}); + method = Util.fixJava4071957(method); + Set managedObj = (Set) method.invoke(connection, new Object[] {searchPattern, null}); + + // Query results processing + for (Iterator it = managedObj.iterator(); it.hasNext();) { + try { + ObjectName elem = ((ObjectInstance) it.next()).getObjectName(); + String name = elem.getKeyProperty(propertyName); + + if (abilitiesSupport.isRemoteManagementSupported() + && (abilitiesSupport.isJB4x() || abilitiesSupport.isJB6x())) { + if (name.endsWith(".sar") || name.endsWith(".deployer")) { // NOI18N + continue; + } + } else { + name = name.substring(1, name.length() - 1); // NOI18N + } + + keys.add(new JBEarApplicationNode(name, lookup)); + } catch (Exception ex) { + LOGGER.log(Level.INFO, null, ex); } + } + return null; + } + }); + } catch (ExecutionException ex) { + LOGGER.log(Level.INFO, null, ex); + } - Method method = connection.getClass().getMethod("queryMBeans", new Class[] {ObjectName.class, QueryExp.class}); - method = Util.fixJava4071957(method); - Set managedObj = (Set) method.invoke(connection, new Object[] {searchPattern, null}); + setKeys(keys); + } + } - // Query results processing - for (Iterator it = managedObj.iterator(); it.hasNext();) { - try { - ObjectName elem = ((ObjectInstance) it.next()).getObjectName(); - String name = elem.getKeyProperty(propertyName); + class JBoss7EarApplicationNodeUpdater implements Runnable { - if (abilitiesSupport.isRemoteManagementSupported() - && (abilitiesSupport.isJB4x() || abilitiesSupport.isJB6x())) { - if (name.endsWith(".sar") || name.endsWith(".deployer")) { // NOI18N - continue; - } - } else { - name = name.substring(1, name.length() - 1); // NOI18N - } + List keys = new ArrayList(); - keys.add(new JBEarApplicationNode(name, lookup)); - } catch (Exception ex) { - LOGGER.log(Level.INFO, null, ex); + @Override + public void run() { + try { + final JBDeploymentManager dm = (JBDeploymentManager) lookup.lookup(JBDeploymentManager.class); + dm.invokeLocalAction(new Callable() { + + @Override + public Void call() { + try { + Target[] targets = dm.getTargets(); + ModuleType moduleType = ModuleType.EAR; + + //Get all deployed EAR files. + TargetModuleID[] modules = dm.getAvailableModules(moduleType, targets); + // Module list may be null if nothing is deployed. + if (modules != null) { + for (int intModule = 0; intModule < modules.length; intModule++) { + keys.add(new JBEarApplicationNode(modules[intModule].getModuleID(), lookup)); } } - return null; + } catch (TargetException ex) { + Exceptions.printStackTrace(ex); + } catch (IllegalStateException ex) { + Exceptions.printStackTrace(ex); } - }); - } catch (ExecutionException ex) { - LOGGER.log(Level.INFO, null, ex); - } + return null; + } + }); + } catch (Exception ex) { + LOGGER.log(Level.INFO, null, ex); + } - setKeys(keys); - } - }, 0); - + setKeys(keys); + } } + @Override protected void addNotify() { updateKeys(); } + @Override protected void removeNotify() { setKeys(java.util.Collections.EMPTY_SET); } + @Override protected org.openide.nodes.Node[] createNodes(Object key) { if (key instanceof JBEarApplicationNode){ return new Node[]{(JBEarApplicationNode)key}; diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBEjbModulesChildren.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBEjbModulesChildren.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBEjbModulesChildren.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBEjbModulesChildren.java @@ -45,13 +45,15 @@ package org.netbeans.modules.j2ee.jboss4.nodes; import java.lang.reflect.Method; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; +import java.util.*; +import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.logging.Level; import java.util.logging.Logger; +import javax.enterprise.deploy.shared.ModuleType; +import javax.enterprise.deploy.spi.Target; +import javax.enterprise.deploy.spi.TargetModuleID; +import javax.enterprise.deploy.spi.exceptions.TargetException; import javax.management.MBeanServerConnection; import javax.management.ObjectInstance; import javax.management.ObjectName; @@ -62,6 +64,7 @@ import org.netbeans.modules.j2ee.jboss4.nodes.actions.Refreshable; import org.openide.nodes.Children; import org.openide.nodes.Node; +import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.RequestProcessor; @@ -87,7 +90,7 @@ public void updateKeys(){ setKeys(new Object[] {Util.WAIT_NODE}); - RequestProcessor.getDefault().post(new Runnable() { + RequestProcessor.getDefault().post(abilitiesSupport.isJB7x() ? new JBoss7EjbApplicationNodeUpdater() : new Runnable() { public void run() { List keys = new LinkedList(); JBDeploymentManager dm = lookup.lookup(JBDeploymentManager.class); @@ -170,7 +173,45 @@ LOGGER.log(Level.INFO, null, ex); } } - + class JBoss7EjbApplicationNodeUpdater implements Runnable { + + List keys = new ArrayList(); + + @Override + public void run() { + try { + final JBDeploymentManager dm = (JBDeploymentManager) lookup.lookup(JBDeploymentManager.class); + dm.invokeLocalAction(new Callable() { + + @Override + public Void call() { + try { + Target[] targets = dm.getTargets(); + ModuleType moduleType = ModuleType.EJB; + + //Get all deployed EAR files. + TargetModuleID[] modules = dm.getAvailableModules(moduleType, targets); + // Module list may be null if nothing is deployed. + if (modules != null) { + for (int intModule = 0; intModule < modules.length; intModule++) { + keys.add(new JBEjbModuleNode(modules[intModule].getModuleID(), lookup)); // TODO: how to check ejb3? + } + } + } catch (TargetException ex) { + Exceptions.printStackTrace(ex); + } catch (IllegalStateException ex) { + Exceptions.printStackTrace(ex); + } + return null; + } + }); + } catch (Exception ex) { + LOGGER.log(Level.INFO, null, ex); + } + + setKeys(keys); + } + } protected void addNotify() { updateKeys(); } diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBManagerNode.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBManagerNode.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBManagerNode.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBManagerNode.java @@ -74,6 +74,7 @@ private static final String ADMIN_URL_60 = "/admin-console/"; //NOI18N private static final String JMX_CONSOLE_URL = "/jmx-console/"; //NOI18N private static final String HTTP_HEADER = "http://"; + private Boolean as7; public JBManagerNode(Children children, Lookup lookup) { super(children); @@ -199,8 +200,18 @@ return sheet; } + boolean isAs7() { + if (as7 == null) { + as7 = getDeploymentManager().getProperties().isVersion(JBPluginUtils.JBOSS_7_0_0); + } + return as7; + } + public Image getIcon(int type) { if (type == BeanInfo.ICON_COLOR_16x16) { + if (isAs7()) { + return ImageUtilities.loadImage("org/netbeans/modules/j2ee/jboss4/resources/as7_16x16.png"); // NOI18N + } return ImageUtilities.loadImage("org/netbeans/modules/j2ee/jboss4/resources/16x16.gif"); // NOI18N } return super.getIcon(type); diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBServletsChildren.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBServletsChildren.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBServletsChildren.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBServletsChildren.java @@ -45,9 +45,11 @@ package org.netbeans.modules.j2ee.jboss4.nodes; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Set; -import java.util.Vector; +import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.logging.Level; import java.util.logging.Logger; @@ -78,19 +80,25 @@ private String name; private Lookup lookup; + private final JBAbilitiesSupport abilitiesSupport; JBServletsChildren(String name, Lookup lookup) { this.lookup = lookup; this.name = name; + this.abilitiesSupport = new JBAbilitiesSupport(lookup); } public void updateKeys(){ setKeys(new Object[] {WAIT_NODE}); - - RequestProcessor.getDefault().post(new Runnable() { - Vector keys = new Vector(); - - public void run() { + RequestProcessor.getDefault().post(abilitiesSupport.isJB7x() ? new JB7ServletNodeUpdater() : new JBServletNodeUpdater(), 0); + } + + class JBServletNodeUpdater implements Runnable { + + List keys = new ArrayList(); + + @Override + public void run() { try { // Query to the jboss4 server lookup.lookup(JBDeploymentManager.class).invokeRemoteAction(new JBRemoteAction() { @@ -121,7 +129,31 @@ setKeys(keys); } - }, 0); + } + + class JB7ServletNodeUpdater implements Runnable { + + List keys = new ArrayList(); + + @Override + public void run() { + try { + // Query to the jboss4 server + lookup.lookup(JBDeploymentManager.class).invokeLocalAction(new Callable() { + + @Override + public Void call() { + // TODO: add as7 logic here + return null; + } + }); + + } catch (Exception ex) { + LOGGER.log(Level.INFO, null, ex); + } + + setKeys(keys); + } } protected void addNotify() { diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBWebApplicationsChildren.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBWebApplicationsChildren.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBWebApplicationsChildren.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/JBWebApplicationsChildren.java @@ -45,14 +45,20 @@ package org.netbeans.modules.j2ee.jboss4.nodes; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Set; -import java.util.Vector; +import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.logging.Level; import java.util.logging.Logger; +import javax.enterprise.deploy.shared.ModuleType; +import javax.enterprise.deploy.spi.Target; +import javax.enterprise.deploy.spi.TargetModuleID; +import javax.enterprise.deploy.spi.exceptions.TargetException; import javax.management.MBeanServerConnection; import javax.management.ObjectInstance; import javax.management.ObjectName; @@ -63,12 +69,14 @@ import org.netbeans.modules.j2ee.jboss4.nodes.actions.Refreshable; import org.openide.nodes.Children; import org.openide.nodes.Node; +import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.RequestProcessor; /** * It describes children nodes of the Web Applications node. Implements - * Refreshable interface and due to it can be refreshed via ResreshModulesAction. + * Refreshable interface and due to it can be refreshed via + * ResreshModulesAction. * * @author Michal Mocnak */ @@ -92,84 +100,139 @@ this.abilitiesSupport = new JBAbilitiesSupport(lookup); } - public void updateKeys(){ - setKeys(new Object[] {Util.WAIT_NODE}); + public void updateKeys() { + setKeys(new Object[]{Util.WAIT_NODE}); + RequestProcessor.getDefault().post(abilitiesSupport.isJB7x() ? new JBoss7WebNodeUpdater() : new JBossWebNodeUpdater(), 0); + } - RequestProcessor.getDefault().post(new Runnable() { - Vector keys = new Vector(); + class JBossWebNodeUpdater implements Runnable { - public void run() { - try { - lookup.lookup(JBDeploymentManager.class).invokeRemoteAction(new JBRemoteAction() { + List keys = new ArrayList(); - @Override - public Void action(MBeanServerConnection connection, JBoss5ProfileServiceProxy profileService) throws Exception { - // Query to the jboss server - ObjectName searchPattern; - if (abilitiesSupport.isRemoteManagementSupported() - && (abilitiesSupport.isJB4x() || abilitiesSupport.isJB6x())) { - searchPattern = new ObjectName("jboss.management.local:j2eeType=WebModule,J2EEApplication=null,*"); // NOI18N + @Override + public void run() { + try { + final JBDeploymentManager dm = (JBDeploymentManager) lookup.lookup(JBDeploymentManager.class); + dm.invokeRemoteAction(new JBRemoteAction() { + + @Override + public Void action(MBeanServerConnection connection, JBoss5ProfileServiceProxy profileService) throws Exception { + // Query to the jboss server + ObjectName searchPattern; + if (abilitiesSupport.isRemoteManagementSupported() + && (abilitiesSupport.isJB4x() || abilitiesSupport.isJB6x())) { + searchPattern = new ObjectName("jboss.management.local:j2eeType=WebModule,J2EEApplication=null,*"); // NOI18N } else { - searchPattern = new ObjectName("jboss.web:j2eeType=WebModule,J2EEApplication=none,*"); // NOI18N + searchPattern = new ObjectName("jboss.web:j2eeType=WebModule,J2EEApplication=none,*"); // NOI18N + } + + Method method = connection.getClass().getMethod("queryMBeans", new Class[] {ObjectName.class, QueryExp.class}); + method = Util.fixJava4071957(method); + Set managedObj = (Set) method.invoke(connection, new Object[] {searchPattern, null}); + + // Query results processing + for (Iterator it = managedObj.iterator(); it.hasNext();) { + try { + ObjectName elem = ((ObjectInstance) it.next()).getObjectName(); + String name = elem.getKeyProperty("name"); + String url = "http://" + dm.getHost() + ":" + dm.getPort(); + String context = null; + + if (name.endsWith(".war")) { + name = name.substring(0, name.lastIndexOf(".war")); + } + + if (abilitiesSupport.isRemoteManagementSupported() + && (abilitiesSupport.isJB4x() || abilitiesSupport.isJB6x())) { + if (SYSTEM_WEB_APPLICATIONS.contains(name)) { // Excluding it. It's system package + continue; + } + String descr = (String) Util.getMBeanParameter(connection, "jbossWebDeploymentDescriptor", elem.getCanonicalName()); // NOI18N + context = Util.getWebContextRoot(descr, name); + } else { + if (name.startsWith("//localhost/")) { // NOI18N + name = name.substring("//localhost/".length()); // NOI18N + } + if ("".equals(name)) { + name = "ROOT"; // NOI18N // consistent with JBoss4 + } + if (SYSTEM_WEB_APPLICATIONS.contains(name)) { // Excluding it. It's system package + continue; + } + + context = (String) Util.getMBeanParameter(connection, "path", elem.getCanonicalName()); // NOI18N + } + + name += ".war"; // NOI18N + keys.add(new JBWebModuleNode(name, lookup, (context == null ? null : url + context))); + } catch (Exception ex) { + LOGGER.log(Level.INFO, null, ex); } + } + return null; + } + }); - Method method = connection.getClass().getMethod("queryMBeans", new Class[] {ObjectName.class, QueryExp.class}); - method = Util.fixJava4071957(method); - Set managedObj = (Set) method.invoke(connection, new Object[] {searchPattern, null}); + } catch (ExecutionException ex) { + LOGGER.log(Level.INFO, null, ex); + } - JBDeploymentManager dm = (JBDeploymentManager) lookup.lookup(JBDeploymentManager.class); + setKeys(keys); + } + } - // Query results processing - for (Iterator it = managedObj.iterator(); it.hasNext();) { - try { - ObjectName elem = ((ObjectInstance) it.next()).getObjectName(); - String name = elem.getKeyProperty("name"); - String url = "http://" + dm.getHost() + ":" + dm.getPort(); - String context = null; + class JBoss7WebNodeUpdater implements Runnable { + List keys = new ArrayList(); + + @Override + public void run() { + + try { + final JBDeploymentManager dm = (JBDeploymentManager) lookup.lookup(JBDeploymentManager.class); + dm.invokeLocalAction(new Callable() { + + @Override + public Void call() { + try { + Target[] targets = dm.getTargets(); + ModuleType moduleType = ModuleType.WAR; + + //Get all deployed WAR files. + TargetModuleID[] modules = dm.getAvailableModules(moduleType, targets); + // Module list may be null if nothing is deployed. + if (modules != null) { + String url = "http://" + dm.getHost() + ":" + dm.getPort(); + for (int intModule = 0; intModule < modules.length; intModule++) { + String name = modules[intModule].getModuleID(); if (name.endsWith(".war")) { name = name.substring(0, name.lastIndexOf(".war")); } - - if (abilitiesSupport.isRemoteManagementSupported() - && (abilitiesSupport.isJB4x() || abilitiesSupport.isJB6x())) { - if (SYSTEM_WEB_APPLICATIONS.contains(name)) { // Excluding it. It's system package - continue; - } - String descr = (String) Util.getMBeanParameter(connection, "jbossWebDeploymentDescriptor", elem.getCanonicalName()); // NOI18N - context = Util.getWebContextRoot(descr, name); - } else { - if (name.startsWith("//localhost/")) { // NOI18N - name = name.substring("//localhost/".length()); // NOI18N - } - if ("".equals(name)) { - name = "ROOT"; // NOI18N // consistent with JBoss4 - } - if (SYSTEM_WEB_APPLICATIONS.contains(name)) { // Excluding it. It's system package - continue; - } - - context = (String) Util.getMBeanParameter(connection, "path", elem.getCanonicalName()); // NOI18N + if ("".equals(name)) { + name = "ROOT"; // NOI18N // consistent with JBoss4 } - + if (SYSTEM_WEB_APPLICATIONS.contains(name)) { // Excluding it. It's system package + continue; + } name += ".war"; // NOI18N - keys.add(new JBWebModuleNode(name, lookup, (context == null ? null : url + context))); - } catch (Exception ex) { - LOGGER.log(Level.INFO, null, ex); + keys.add(new JBWebModuleNode(name, lookup, url)); } } - return null; + } catch (TargetException ex) { + Exceptions.printStackTrace(ex); + } catch (IllegalStateException ex) { + Exceptions.printStackTrace(ex); } - }); - - } catch (ExecutionException ex) { - LOGGER.log(Level.INFO, null, ex); - } + return null; + } + }); + } catch (Exception ex) { + LOGGER.log(Level.INFO, null, ex); + } - setKeys(keys); - } - }, 0); + setKeys(keys); + } } protected void addNotify() { diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/actions/UndeployModuleCookieImpl.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/actions/UndeployModuleCookieImpl.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/actions/UndeployModuleCookieImpl.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/nodes/actions/UndeployModuleCookieImpl.java @@ -52,6 +52,7 @@ import org.netbeans.api.progress.ProgressHandleFactory; import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager; import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; +import org.netbeans.modules.j2ee.jboss4.nodes.JBAbilitiesSupport; import org.netbeans.modules.j2ee.jboss4.nodes.Util; import org.openide.util.Lookup; import org.openide.util.NbBundle; @@ -69,6 +70,7 @@ private ModuleType type; private final boolean isEJB3; private boolean isRunning; + private final JBAbilitiesSupport abilitiesSupport; public UndeployModuleCookieImpl(String fileName, ModuleType type, Lookup lookup) { this(fileName, type, false, lookup); @@ -84,6 +86,7 @@ this.type = type; this.isEJB3 = isEJB3; this.isRunning = false; + this.abilitiesSupport = new JBAbilitiesSupport(lookup); } public Task undeploy() { @@ -100,28 +103,10 @@ if(file.exists() && file.canWrite()) { file.delete(); - - try { - ObjectName searchPattern = null; - if (Util.isRemoteManagementSupported(lookup) && !isEJB3) { - searchPattern = new ObjectName("jboss.management.local:"+(!type.equals(ModuleType.EAR) ? - "J2EEApplication=null," : "")+"j2eeType="+Util.getModuleTypeString(type)+",name=" + fileName + ",*"); - } else { - if (type.equals(ModuleType.EAR)) { - searchPattern = new ObjectName("jboss.j2ee:service=EARDeployment,url='" + fileName + "'"); // NOI18N - } - else - if (type.equals(ModuleType.WAR)) { - searchPattern = new ObjectName("jboss.web:j2eeType=WebModule,J2EEApplication=none,name=//localhost/" + nameWoExt + ",*"); // NOI18N - } - else - if (type.equals(ModuleType.EJB)) { - searchPattern = new ObjectName("jboss.j2ee:service=" + (isEJB3 ? "EJB3" : "EjbModule") + ",module=" + fileName); // NOI18N - } - } - + if(abilitiesSupport.isJB7x()) { + File statusFile = new File(file.getAbsolutePath()+File.pathSeparator+ ".undeployed"); int time = 0; - while(Util.isObjectDeployed(dm, searchPattern) && time < 30000) { + while (statusFile.exists() && time < 30000) { try { Thread.sleep(2000); time += 2000; @@ -129,9 +114,39 @@ // Nothing to do } } - } catch (MalformedObjectNameException ex) { - } catch (NullPointerException ex) { - // Nothing to do + } else { + try { + ObjectName searchPattern = null; + if (Util.isRemoteManagementSupported(lookup) && !isEJB3) { + searchPattern = new ObjectName("jboss.management.local:"+(!type.equals(ModuleType.EAR) ? + "J2EEApplication=null," : "")+"j2eeType="+Util.getModuleTypeString(type)+",name=" + fileName + ",*"); + } else { + if (type.equals(ModuleType.EAR)) { + searchPattern = new ObjectName("jboss.j2ee:service=EARDeployment,url='" + fileName + "'"); // NOI18N + } + else + if (type.equals(ModuleType.WAR)) { + searchPattern = new ObjectName("jboss.web:j2eeType=WebModule,J2EEApplication=none,name=//localhost/" + nameWoExt + ",*"); // NOI18N + } + else + if (type.equals(ModuleType.EJB)) { + searchPattern = new ObjectName("jboss.j2ee:service=" + (isEJB3 ? "EJB3" : "EjbModule") + ",module=" + fileName); // NOI18N + } + } + + int time = 0; + while(Util.isObjectDeployed(dm, searchPattern) && time < 30000) { + try { + Thread.sleep(2000); + time += 2000; + } catch (InterruptedException ex) { + // Nothing to do + } + } + } catch (MalformedObjectNameException ex) { + } catch (NullPointerException ex) { + // Nothing to do + } } } diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/resources/as7_16x16.png b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/resources/as7_16x16.png new file mode 100644 index 0000000000000000000000000000000000000000..bc98bc04d255bb7b261aa92fa2fea824c0d29f78 GIT binary patch literal 654 zc$@)_0&)F`P)%c=coj!FxpLLBTEPAyiQDpjMC;8noJ` zsUN|mt_k@vc-VDzZPsnO2Yu|!?99CPdvE5wAy|>j>+BdCM)B`bVy%~Y7Ea>-M6^5J zvvAQ*%e1VNXp~0wFX-DHU&woJH%Vjjs3XVgVdS5$g=QYsE?(_Z~g5e{F!a0w5ri zV)SMjva}7numL9y_MpGJ3kzSD@#cLVb4xnnii}dVj`{p&7wF!B6l%k*%NJM#EvxQe zNjGq~FNS1Hapu)}13b^N|H}igOcRnAaEx!?&*1s=2c-H{98d1YgQssX@nQz;fz9ZN z?!>9VK14fqIQQ@uV40ZzRDf=jFmigxX|@>U8tz;t(q zPI2W7+tTzdMo1d(%k#a{qF6!FdT% znpfAikXV^I?_!pv@z8-NE1ovnQz;qWrLEOn2bg-dm|)6^UaUY>!q^j$nqg{w&ej2_ oT@!3<5qPLwvUe-(2ly?(02Ga{@V;1?G5`Po07*qoM6N<$f`Dih($ diff --git a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/util/JBProperties.java b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/util/JBProperties.java --- a/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/util/JBProperties.java +++ b/j2ee.jboss4/src/org/netbeans/modules/j2ee/jboss4/util/JBProperties.java @@ -241,7 +241,7 @@ addFiles(new File(rootDir, "lib"), list); // NOI18N addFiles(new File(serverDir, "lib"), list); // NOI18N - + addFiles(new File(new File(rootDir, "modules"), "javax"), list); // NOI18N Set commonLibs = new HashSet();