ndex: apichanges.xml =================================================================== RCS file: /cvs/j2eeserver/apichanges.xml,v retrieving revision 1.16.6.3.2.2 retrieving revision 1.16.6.3.8.2 diff -u -r1.16.6.3.2.2 -r1.16.6.3.8.2 --- apichanges.xml 30 Mar 2006 16:48:54 -0000 1.16.6.3.2.2 +++ apichanges.xml 4 Apr 2006 14:20:54 -0000 1.16.6.3.8.2 @@ -80,6 +80,27 @@ + + + + Added support for Ant (headless) deployment. + + + + + + +

+ Ant deployment support allows to generate Ant deployment build + scripts that can be used to deploy j2ee modules to the + server. The generated deployment build script can run in a headless + mode - without the IDE. The IDE does not even have to be installed. +

+
+ + + +
Index: src/org/netbeans/modules/j2ee/deployment/devmodules/api/AntDeploymentHelper.java =================================================================== RCS file: src/org/netbeans/modules/j2ee/deployment/devmodules/api/AntDeploymentHelper.java diff -N src/org/netbeans/modules/j2ee/deployment/devmodules/api/AntDeploymentHelper.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/j2ee/deployment/devmodules/api/AntDeploymentHelper.java 4 Apr 2006 14:20:54 -0000 1.1.2.3 @@ -0,0 +1,128 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + +package org.netbeans.modules.j2ee.deployment.devmodules.api; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import javax.enterprise.deploy.shared.ModuleType; +import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; +import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; +import org.netbeans.modules.j2ee.deployment.plugins.api.AntDeploymentProvider; +import org.openide.filesystems.FileLock; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; + +/** + * Helps to generate Ant deployment build scripts. + * + * @author sherold + * + * @since 1.17 + */ +public final class AntDeploymentHelper { + + /** + * Generates the Ant deployment build script for the given module type for + * the specified server instance to the specified file. If the specified + * serverInstanceID is null or no server instance of the specified ID exists + * a default deployment build script will be generated. + *

+ * The Ant deployment build script requires the following properties to be + * defined. + *

    + *
  • deploy.ant.properties.file - Path to the server instance + * specific deployment properties file, see {@link #getDeploymentPropertiesFile}. + *
  • deploy.ant.archive - The deployable archive. + *
  • deploy.ant.resource.dir - The server resources directory. + *
  • deploy.ant.enabled - The Ant deployment targets should be + * executed only if this property has been set. + *
+ *

+ * The Ant deployment build script is bound to provide the following targets. + *

    + *
  • -deploy-ant - Deploys the deployable archive defined by the + * deploy.ant.archive property. If the deployable archive is a web + * module or an enterprise application with a web module the + * deploy.ant.client.url property is set by this target. + *
  • -undeploy-ant - Undeploys the deployable archive defined + * by the deploy.ant.archive property. + *
+ * + * @param file the file to which the deployment build script will be generated. + * If the file does not exist, it will be created. + * @param moduleType the module type the build script should handle. Use the + * constants defined in the {@link org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule}. + * @param serverInstanceID the server instance for which the build script will + * be generated. + * @throws IOException if a problem during generating the build script occurs. + */ + public static void writeDeploymentScript(File file, Object moduleType, String serverInstanceID) + throws IOException { + AntDeploymentProvider provider = null; + if (serverInstanceID != null) { + ServerInstance si = ServerRegistry.getInstance().getServerInstance(serverInstanceID); + if (si != null) { + provider = si.getAntDeploymentProvider(); + } + } + file.createNewFile(); + FileObject fo = FileUtil.toFileObject(file); + FileLock lock = fo.lock(); + try { + OutputStream os = fo.getOutputStream(lock); + try { + if (provider == null) { + InputStream is = ServerInstance.class.getResourceAsStream("resources/default-ant-deploy.xml"); // NOI18N + try { + FileUtil.copy(is, os); + } finally { + is.close(); + } + } else { + provider.writeDeploymentScript(os, moduleType); + } + } finally { + os.close(); + } + } finally { + lock.releaseLock(); + } + } + + /** + * Returns the server instance specific deployment properties file used by + * the deployment build script generated by the {@link #writeDeploymentScript(File,Object,String)}. + * + * @param serverInstanceID specifies the server instance. + * + * @return the deployment properties file for the specified server instance, + * if such instance exists and supports Ant deployment, null otherwise. + * + * @throws NullPointerException if the specified serverInstanceID is null. + */ + public static File getDeploymentPropertiesFile(String serverInstanceID) { + if (serverInstanceID == null) { + throw new NullPointerException("The serverInstanceID must not be null"); // NOI18N + } + ServerInstance si = ServerRegistry.getInstance().getServerInstance(serverInstanceID); + if (si == null) { + return null; + } + AntDeploymentProvider sup = si.getAntDeploymentProvider(); + return sup == null ? null : sup.getDeploymentPropertiesFile(); + } +} Index: src/org/netbeans/modules/j2ee/deployment/impl/resources/default-ant-deploy.xml =================================================================== RCS file: src/org/netbeans/modules/j2ee/deployment/impl/resources/default-ant-deploy.xml diff -N src/org/netbeans/modules/j2ee/deployment/impl/resources/default-ant-deploy.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/j2ee/deployment/impl/resources/default-ant-deploy.xml 4 Apr 2006 15:11:28 -0000 1.1.2.2 @@ -0,0 +1,9 @@ + + + + + + + + + Index: src/org/netbeans/modules/j2ee/deployment/plugins/api/AntDeploymentProvider.java =================================================================== RCS file: src/org/netbeans/modules/j2ee/deployment/plugins/api/AntDeploymentProvider.java diff -N src/org/netbeans/modules/j2ee/deployment/plugins/api/AntDeploymentProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/j2ee/deployment/plugins/api/AntDeploymentProvider.java 4 Apr 2006 14:20:54 -0000 1.1.2.3 @@ -0,0 +1,56 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + +package org.netbeans.modules.j2ee.deployment.plugins.api; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; + +/** + * This interface represents a "provider" for the Ant deployment. + *

+ * The j2eeserver uses {@link OptionalDeploymentManagerFactory} to optains an + * instance of the AntDeploymentProvider from the server integration plugin. + * + * @author sherold + * + * @since 1.17 + */ +public interface AntDeploymentProvider { + + /** + * Generates the Ant deployment build script for the given module type to + * the specified output stream. + *

+ * See {@link org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper#writeDeploymentScript(File,Object,String)} + * for what targets and properties is the Ant deployment build script required + * to define and what predefined properties it might use. + * + * @param os the output stream the deployment build script should be generated + * to. + * @param moduleType the module type the build script should handle. Use the + * constants defined in the {@link J2eeModule}. + * @throws IOException if a problem during generating the build script occurs. + */ + void writeDeploymentScript(OutputStream os, Object moduleType) throws IOException; + + /** + * Return the server instance specific deployment properties file used by + * the deployment build script generated by the {@link #writeDeploymentScript(OutputStream,Object)}. + * + * @return the deployment properties file. + */ + File getDeploymentPropertiesFile(); +} Index: src/org/netbeans/modules/j2ee/deployment/plugins/api/OptionalDeploymentManagerFactory.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/api/OptionalDeploymentManagerFactory.java,v retrieving revision 1.4.34.1 retrieving revision 1.4.40.4 diff -u -r1.4.34.1 -r1.4.40.4 --- src/org/netbeans/modules/j2ee/deployment/plugins/api/OptionalDeploymentManagerFactory.java 29 Mar 2006 13:31:23 -0000 1.4.34.1 +++ src/org/netbeans/modules/j2ee/deployment/plugins/api/OptionalDeploymentManagerFactory.java 4 Apr 2006 15:59:37 -0000 1.4.40.4 @@ -60,6 +60,18 @@ } /** + * Creates an Ant deployment provider for the specified deployment manager. + * + * @param dm deployment manager. + * @return an instance of the AntDeploymentProvider if Ant deployment + * is supported for the specified deployment manager, null otherwise. + * @since 1.17 + */ + public AntDeploymentProvider getAntDeploymentProvider(DeploymentManager dm) { + return null; + } + + /** * Creates a DatasourceManager for the given deployment manager * or null if data source management is not supported * @@ -73,5 +85,4 @@ public DatasourceManager getDatasourceManager(DeploymentManager dm) { return null; } - }