diff --git a/glassfish.common/src/org/netbeans/modules/glassfish/common/CommandRunner.java b/glassfish.common/src/org/netbeans/modules/glassfish/common/CommandRunner.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/CommandRunner.java +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/CommandRunner.java @@ -390,16 +390,17 @@ } public Future deploy(File dir, String moduleName, String contextRoot) { - return deploy(dir, moduleName, contextRoot, null); + return deploy(dir, moduleName, contextRoot, null, new File[0]); } - Future deploy(File dir, String moduleName, String contextRoot, Map properties) { + public Future deploy(File dir, String moduleName, String contextRoot, Map properties, File[] libraries) { return execute(new Commands.DeployCommand(dir, moduleName, - contextRoot, computePreserveSessions(ip), properties)); + contextRoot, computePreserveSessions(ip), properties, libraries)); } - public Future redeploy(String moduleName, String contextRoot) { + + public Future redeploy(String moduleName, String contextRoot, File[] libraries) { return execute(new Commands.RedeployCommand(moduleName, contextRoot, - computePreserveSessions(ip))); + computePreserveSessions(ip), libraries)); } private static Boolean computePreserveSessions(Map ip) { diff --git a/glassfish.common/src/org/netbeans/modules/glassfish/common/Commands.java b/glassfish.common/src/org/netbeans/modules/glassfish/common/Commands.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/Commands.java +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/Commands.java @@ -287,6 +287,18 @@ } }; + private static void appendLibraries(StringBuilder cmd, File[] libraries) { + cmd.append(ServerCommand.PARAM_SEPARATOR).append("libraries="); // NOI18N + boolean firstOne = true; + for (File f : libraries) { + if (!firstOne) { + cmd.append(","); + } + cmd.append(f.getPath()); // NOI18N + firstOne = false; + } + } + /** * Command to deploy a directory */ @@ -295,7 +307,7 @@ private final boolean isDirDeploy; private final File path; - public DeployCommand(final File path, final String name, final String contextRoot, final Boolean preserveSessions, final Map properties) { + public DeployCommand(final File path, final String name, final String contextRoot, final Boolean preserveSessions, final Map properties, File[] libraries) { super("deploy"); // NOI18N this.isDirDeploy = path.isDirectory(); @@ -312,6 +324,9 @@ cmd.append(PARAM_SEPARATOR).append("contextroot="); // NOI18N cmd.append(contextRoot); } + if (libraries.length > 0) { + appendLibraries(cmd, libraries); + } cmd.append(PARAM_SEPARATOR).append("force=true"); // NOI18N addProperties(cmd,properties); query = cmd.toString(); @@ -377,7 +392,7 @@ */ public static final class RedeployCommand extends ServerCommand { - public RedeployCommand(final String name, final String contextRoot, final Boolean preserveSessions) { + public RedeployCommand(final String name, final String contextRoot, final Boolean preserveSessions, File[] libraries) { super("redeploy"); // NOI18N StringBuilder cmd = new StringBuilder(128); @@ -387,6 +402,9 @@ cmd.append(PARAM_SEPARATOR).append("contextroot="); // NOI18N cmd.append(contextRoot); } + if (libraries.length > 0) { + appendLibraries(cmd, libraries); + } addKeepSessions(cmd, preserveSessions); query = cmd.toString(); } diff --git a/glassfish.common/src/org/netbeans/modules/glassfish/common/CommonServerSupport.java b/glassfish.common/src/org/netbeans/modules/glassfish/common/CommonServerSupport.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/CommonServerSupport.java +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/CommonServerSupport.java @@ -75,6 +75,7 @@ import org.netbeans.modules.glassfish.spi.ServerCommand; import org.netbeans.modules.glassfish.spi.ServerCommand.GetPropertyCommand; import org.netbeans.modules.glassfish.spi.CommandFactory; +import org.netbeans.modules.glassfish.spi.GlassfishModule2; import org.netbeans.modules.glassfish.spi.Utils; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; @@ -90,7 +91,7 @@ * * @author Peter Williams */ -public class CommonServerSupport implements GlassfishModule, RefreshModulesCookie { +public class CommonServerSupport implements GlassfishModule2, RefreshModulesCookie { private final transient Lookup lookup; private final Map properties = @@ -420,9 +421,14 @@ @Override public Future deploy(final OperationStateListener stateListener, final File application, final String name, final String contextRoot, Map properties) { + return deploy(stateListener, application, name, contextRoot, null, new File[0]); + } + + @Override + public Future deploy(OperationStateListener stateListener, File application, String name, String contextRoot, Map properties, File[] libraries) { CommandRunner mgr = new CommandRunner(isReallyRunning(), getCommandFactory(), getInstanceProperties(), stateListener); - return mgr.deploy(application, name, contextRoot, properties); + return mgr.deploy(application, name, contextRoot, properties, libraries); } @Override @@ -434,8 +440,13 @@ @Override public Future redeploy(final OperationStateListener stateListener, final String name, final String contextRoot) { + return redeploy(stateListener, name, contextRoot, new File[0]); + } + + @Override + public Future redeploy(OperationStateListener stateListener, String name, String contextRoot, File[] libraries) { CommandRunner mgr = new CommandRunner(isReallyRunning(), getCommandFactory(), getInstanceProperties(), stateListener); - return mgr.redeploy(name, contextRoot); + return mgr.redeploy(name, contextRoot, libraries); } @Override diff --git a/glassfish.common/src/org/netbeans/modules/glassfish/spi/GlassfishModule2.java b/glassfish.common/src/org/netbeans/modules/glassfish/spi/GlassfishModule2.java new file mode 100644 --- /dev/null +++ b/glassfish.common/src/org/netbeans/modules/glassfish/spi/GlassfishModule2.java @@ -0,0 +1,64 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2010 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 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.glassfish.spi; + +import java.io.File; +import java.util.Map; +import java.util.concurrent.Future; + + +/** + * Extended version of GlassfishModule supporting deployment of standalone + * EE module with libraries they require. + * + */ +public interface GlassfishModule2 extends GlassfishModule { + + public Future deploy(OperationStateListener stateListener, + File application, String name, String contextRoot, Map properties, + File[] libraries); + + public Future redeploy(final OperationStateListener stateListener, + final String name, final String contextRoot, File[] libraries); + +} diff --git a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/ide/FastDeploy.java b/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/ide/FastDeploy.java --- a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/ide/FastDeploy.java +++ b/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/ide/FastDeploy.java @@ -46,6 +46,7 @@ import java.io.File; import java.io.IOException; +import java.util.Collections; import java.util.logging.Level; import java.util.logging.Logger; import javax.enterprise.deploy.shared.CommandType; @@ -65,6 +66,7 @@ import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment; import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration; import org.netbeans.modules.glassfish.spi.GlassfishModule; +import org.netbeans.modules.glassfish.spi.GlassfishModule2; import org.netbeans.modules.j2ee.deployment.plugins.api.DeploymentChangeDescriptor; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -98,7 +100,7 @@ * @param file * @return */ - public ProgressObject initialDeploy(Target target, J2eeModule module, ModuleConfiguration configuration, final File dir) { + public ProgressObject initialDeploy(Target target, final J2eeModule module, ModuleConfiguration configuration, final File dir) { final String moduleName = org.netbeans.modules.glassfish.spi.Utils.sanitizeName(Utils.computeModuleID(module, dir, Integer.toString(hashCode()))); String contextRoot = null; // XXX fix cast -- need error instance for ProgressObject to return errors @@ -110,6 +112,8 @@ MonitorProgressObject restartProgress = new MonitorProgressObject(dm, moduleId); final GlassfishModule commonSupport = dm.getCommonServerSupport(); + final GlassfishModule2 commonSupport2 = (commonSupport instanceof GlassfishModule2 ? + (GlassfishModule2)commonSupport : null); boolean restart = false; try { restart = HttpMonitorHelper.synchronizeMonitor(commonSupport.getInstanceProperties().get(GlassfishModule.DOMAINS_FOLDER_ATTR), @@ -126,7 +130,11 @@ restartProgress.addProgressListener(new ProgressListener() { public void handleProgressEvent(ProgressEvent event) { if (event.getDeploymentStatus().isCompleted()) { + if (commonSupport2 != null) { + commonSupport2.deploy(deployProgress, dir, moduleName, null, Collections.emptyMap(), module.getRequiredLibraries()); + } else { commonSupport.deploy(deployProgress, dir, moduleName); + } } else { deployProgress.fireHandleProgressEvent(event.getDeploymentStatus()); } @@ -135,7 +143,11 @@ commonSupport.restartServer(restartProgress); return updateCRProgress; } else { + if (commonSupport2 != null) { + commonSupport2.deploy(deployProgress, dir, moduleName, null, Collections.emptyMap(), module.getRequiredLibraries()); + } else { commonSupport.deploy(deployProgress, dir, moduleName); + } return updateCRProgress; } } diff --git a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientProvider.java b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientProvider.java --- a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientProvider.java +++ b/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/AppClientProvider.java @@ -49,6 +49,7 @@ import java.beans.PropertyChangeSupport; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Date; import java.util.Enumeration; import java.util.Iterator; @@ -77,14 +78,16 @@ import org.netbeans.modules.j2ee.deployment.devmodules.api.ModuleChangeReporter; import org.netbeans.modules.j2ee.deployment.devmodules.api.ResourceChangeReporter; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleFactory; -import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleImplementation2; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleImplementation3; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.deployment.devmodules.spi.ResourceChangeReporterFactory; import org.netbeans.modules.j2ee.deployment.devmodules.spi.ResourceChangeReporterImplementation; import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel; import org.netbeans.modules.java.api.common.project.ProjectProperties; import org.netbeans.modules.websvc.api.client.WebServicesClientConstants; +import org.netbeans.spi.java.classpath.ClassPathFactory; import org.netbeans.spi.java.classpath.ClassPathProvider; +import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; import org.openide.DialogDisplayer; @@ -97,7 +100,7 @@ * @author jungi */ public final class AppClientProvider extends J2eeModuleProvider - implements J2eeModuleImplementation2, ModuleChangeReporter, EjbChangeDescriptor, PropertyChangeListener { + implements J2eeModuleImplementation3, ModuleChangeReporter, EjbChangeDescriptor, PropertyChangeListener { public static final String FILE_DD = "application-client.xml";//NOI18N @@ -176,6 +179,22 @@ return project.getClassPathProvider(); } + @Override + public File[] getRequiredLibraries() { + ClassPath cp = ClassPathFactory.createClassPath( + ProjectClassPathSupport.createPropertyBasedClassPathImplementation( + FileUtil.toFile(project.getProjectDirectory()), project.evaluator(), new String[]{"javac.classpath"})); + List files = new ArrayList(); + for (FileObject fo : cp.getRoots()) { + fo = FileUtil.getArchiveFile(fo); + if (fo == null) { + continue; + } + files.add(FileUtil.toFile(fo)); + } + return files.toArray(new File[files.size()]); + } + public FileObject getArchive() { return getFileObject(AppClientProjectProperties.DIST_JAR); } diff --git a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarProvider.java b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarProvider.java --- a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarProvider.java +++ b/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarProvider.java @@ -42,6 +42,7 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.File; +import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.LinkedList; @@ -79,11 +80,13 @@ import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.j2ee.deployment.devmodules.api.ModuleChangeReporter; import org.netbeans.modules.j2ee.deployment.devmodules.api.ResourceChangeReporter; -import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleImplementation2; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleImplementation3; import org.netbeans.modules.j2ee.deployment.devmodules.spi.ResourceChangeReporterFactory; import org.netbeans.modules.j2ee.deployment.devmodules.spi.ResourceChangeReporterImplementation; import org.netbeans.modules.java.api.common.project.ProjectProperties; import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants; +import org.netbeans.spi.java.classpath.ClassPathFactory; +import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport; /** A ejb module implementation on top of project. @@ -91,7 +94,7 @@ * @author Pavel Buzek */ public final class EjbJarProvider extends J2eeModuleProvider - implements J2eeModuleImplementation2, ModuleChangeReporter, EjbChangeDescriptor, PropertyChangeListener { + implements J2eeModuleImplementation3, ModuleChangeReporter, EjbChangeDescriptor, PropertyChangeListener { public static final String FILE_DD = "ejb-jar.xml";//NOI18N @@ -187,6 +190,7 @@ return project.getClassPathProvider(); } + @Override public FileObject getArchive() { return getFileObject(EjbJarProjectProperties.DIST_JAR); } @@ -477,6 +481,22 @@ } } + @Override + public File[] getRequiredLibraries() { + ClassPath cp = ClassPathFactory.createClassPath( + ProjectClassPathSupport.createPropertyBasedClassPathImplementation( + FileUtil.toFile(project.getProjectDirectory()), project.evaluator(), new String[]{"javac.classpath"})); + List files = new ArrayList(); + for (FileObject fo : cp.getRoots()) { + fo = FileUtil.getArchiveFile(fo); + if (fo == null) { + continue; + } + files.add(FileUtil.toFile(fo)); + } + return files.toArray(new File[files.size()]); + } + private class EjbJarResourceChangeReporter implements ResourceChangeReporterImplementation { public boolean isServerResourceChanged(long lastDeploy) { diff --git a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/J2eeModule.java b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/J2eeModule.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/J2eeModule.java +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/J2eeModule.java @@ -55,8 +55,10 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.j2ee.core.Profile; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleBase; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleImplementation2; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleImplementation3; import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel; import org.openide.util.Parameters; @@ -213,6 +215,17 @@ } } + public File[] getRequiredLibraries() { + if (impl instanceof J2eeModuleImplementation3) { + File libs[] = ((J2eeModuleImplementation3) impl).getRequiredLibraries(); + assert libs != null; + assert (getType() == J2eeModule.Type.WAR || getType() == J2eeModule.Type.EAR) && libs.length == 0; + return libs; + } else { + return new File[0]; + } + } + /** * Returns module type. * diff --git a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleImplementation3.java b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleImplementation3.java new file mode 100644 --- /dev/null +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleImplementation3.java @@ -0,0 +1,62 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2010 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]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * 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. + */ + +package org.netbeans.modules.j2ee.deployment.devmodules.spi; + +import java.io.File; + +/** + * Standalone EJB and AppClient module can describe library jars they depend on. + */ +public interface J2eeModuleImplementation3 extends J2eeModuleImplementation2 { + + /** + * Returns array of jar files this standalone EE module depends on. + * @return never null; can be empty array; file must be absolute and + * a jar file and never a folder; libraries can be returned only for EJB or + * APPCLIENT module + */ + File[] getRequiredLibraries(); + +}