This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 74387
Collapse All | Expand All

(-)apichanges.xml (+21 lines)
Lines 80-85 Link Here
80
    <!-- ACTUAL CHANGES BEGIN HERE: -->
80
    <!-- ACTUAL CHANGES BEGIN HERE: -->
81
81
82
    <changes>
82
    <changes>
83
        <change id="antDeployment">
84
            <api name="j2eeserver"/>
85
            <summary>
86
                Added support for Ant (headless) deployment.
87
            </summary>
88
            <version major="1" minor="17"/>
89
            <date day="4" month="4" year="2006"/>
90
            <author login="sherold"/>
91
            <compatibility binary="compatible" source="compatible" semantic="compatible" addition="yes"/>
92
            <description>
93
                <p>
94
                    Ant deployment support allows to generate Ant deployment build
95
                    scripts that can be used to deploy j2ee modules to the
96
                    server. The generated deployment build script can run in a headless 
97
                    mode - without the IDE. The IDE does not even have to be installed.
98
                </p>
99
            </description>
100
            <class package="org.netbeans.modules.j2ee.deployment.devmodules.api" name="AntDeploymentHelper"/>
101
            <class package="org.netbeans.modules.j2ee.deployment.plugins.api" name="AntDeploymentProvider"/>
102
            <class package="org.netbeans.modules.j2ee.deployment.plugins.api" name="OptionalDeploymentManagerFactory"/>
103
        </change>
83
        <change id="j2eePlatformTools">
104
        <change id="j2eePlatformTools">
84
            <api name="j2eeserver"/>
105
            <api name="j2eeserver"/>
85
            <summary>
106
            <summary>
(-)src/org/netbeans/modules/j2ee/deployment/devmodules/api/AntDeploymentHelper.java (+128 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
15
package org.netbeans.modules.j2ee.deployment.devmodules.api;
16
17
import java.io.File;
18
import java.io.IOException;
19
import java.io.InputStream;
20
import java.io.OutputStream;
21
import javax.enterprise.deploy.shared.ModuleType;
22
import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
23
import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
24
import org.netbeans.modules.j2ee.deployment.plugins.api.AntDeploymentProvider;
25
import org.openide.filesystems.FileLock;
26
import org.openide.filesystems.FileObject;
27
import org.openide.filesystems.FileUtil;
28
29
/**
30
 * Helps to generate Ant deployment build scripts.
31
 *
32
 * @author sherold
33
 *
34
 * @since 1.17
35
 */
36
public final class AntDeploymentHelper {
37
    
38
    /**
39
     * Generates the Ant deployment build script for the given module type for 
40
     * the specified server instance to the specified file. If the specified 
41
     * serverInstanceID is null or no server instance of the specified ID exists 
42
     * a default deployment build script will be generated.
43
     * <p>
44
     * The Ant deployment build script requires the following properties to be
45
     * defined.
46
     * <ul>
47
     * <li><code>deploy.ant.properties.file</code> - Path to the server instance 
48
     * specific deployment properties file, see {@link #getDeploymentPropertiesFile}.
49
     * <li><code>deploy.ant.archive</code> - The deployable archive.
50
     * <li><code>deploy.ant.resource.dir</code> - The server resources directory.
51
     * <li><code>deploy.ant.enabled</code> - The Ant deployment targets should be
52
     * executed only if this property has been set.
53
     * </ul>
54
     * <p>
55
     * The Ant deployment build script is bound to provide the following targets.
56
     * <ul>
57
     * <li><code>-deploy-ant</code> - Deploys the deployable archive defined by the 
58
     * <code>deploy.ant.archive</code> property. If the deployable archive is a web 
59
     * module or an enterprise application with a web module the 
60
     * <code>deploy.ant.client.url</code> property is set by this target.
61
     * <li><code>-undeploy-ant</code> - Undeploys the deployable archive defined 
62
     * by the <code>deploy.ant.archive</code> property.
63
     * </ul>
64
     *
65
     * @param file the file to which the deployment build script will be generated.
66
     *             If the file does not exist, it will be created.
67
     * @param moduleType the module type the build script should handle. Use the
68
     *                   constants defined in the {@link org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule}.
69
     * @param serverInstanceID the server instance for which the build script will
70
     *                         be generated.
71
     * @throws IOException if a problem during generating the build script occurs.
72
     */
73
    public static void writeDeploymentScript(File file, Object moduleType, String serverInstanceID) 
74
    throws IOException {
75
        AntDeploymentProvider provider = null;
76
        if (serverInstanceID != null) {
77
            ServerInstance si = ServerRegistry.getInstance().getServerInstance(serverInstanceID);
78
            if (si != null) {
79
                provider = si.getAntDeploymentProvider();
80
            }
81
        }
82
        file.createNewFile();
83
        FileObject fo = FileUtil.toFileObject(file);
84
        FileLock lock = fo.lock();
85
        try {
86
            OutputStream os = fo.getOutputStream(lock);
87
            try {
88
                if (provider == null) {
89
                    InputStream is = ServerInstance.class.getResourceAsStream("resources/default-ant-deploy.xml"); // NOI18N
90
                    try {
91
                        FileUtil.copy(is, os);
92
                    } finally {
93
                        is.close();
94
                    }
95
                } else {
96
                    provider.writeDeploymentScript(os, moduleType);
97
                }
98
            } finally {
99
                os.close();
100
            }
101
        } finally {
102
            lock.releaseLock();
103
        }
104
    }
105
    
106
    /**
107
     * Returns the server instance specific deployment properties file used by 
108
     * the deployment build script generated by the {@link #writeDeploymentScript(File,Object,String)}. 
109
     *
110
     * @param serverInstanceID specifies the server instance.
111
     *
112
     * @return the deployment properties file for the specified server instance, 
113
     *         if such instance exists and supports Ant deployment, null otherwise.
114
     *
115
     * @throws NullPointerException if the specified serverInstanceID is null.
116
     */
117
    public static File getDeploymentPropertiesFile(String serverInstanceID) {
118
        if (serverInstanceID == null) {
119
            throw new NullPointerException("The serverInstanceID must not be null"); // NOI18N
120
        }
121
        ServerInstance si = ServerRegistry.getInstance().getServerInstance(serverInstanceID);
122
        if (si == null) {
123
            return null;
124
        }
125
        AntDeploymentProvider sup = si.getAntDeploymentProvider();
126
        return sup == null ? null : sup.getDeploymentPropertiesFile();
127
    }
128
}
(-)src/org/netbeans/modules/j2ee/deployment/impl/resources/default-ant-deploy.xml (+9 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project name="ant-deploy" default="-deploy-ant" basedir=".">
3
    <target name="-deploy-ant" unless="netbeans.home">
4
        <fail message="Deploy is not supported for the current target server"/>
5
    </target>
6
    <target name="-undeploy-ant" unless="netbeans.home">
7
        <fail message="Undeploy is not supported for the current target server"/>
8
    </target>
9
</project>
(-)src/org/netbeans/modules/j2ee/deployment/plugins/api/AntDeploymentProvider.java (+56 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
15
package org.netbeans.modules.j2ee.deployment.plugins.api;
16
17
import java.io.File;
18
import java.io.IOException;
19
import java.io.OutputStream;
20
21
/**
22
 * This interface represents a "provider" for the Ant deployment.
23
 * <p>
24
 * The j2eeserver uses {@link OptionalDeploymentManagerFactory} to optains an 
25
 * instance of the AntDeploymentProvider from the server integration plugin.
26
 *
27
 * @author sherold
28
 *
29
 * @since 1.17
30
 */
31
public interface AntDeploymentProvider {
32
    
33
    /**
34
     * Generates the Ant deployment build script for the given module type to 
35
     * the specified output stream.
36
     * <p>
37
     * See {@link org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper#writeDeploymentScript(File,Object,String)}
38
     * for what targets and properties is the Ant deployment build script required 
39
     * to define and what predefined properties it might use.
40
     *
41
     * @param os the output stream the deployment build script should be generated 
42
     *           to.
43
     * @param moduleType the module type the build script should handle. Use the
44
     *                   constants defined in the {@link J2eeModule}.
45
     * @throws IOException if a problem during generating the build script occurs.
46
     */
47
    void writeDeploymentScript(OutputStream os, Object moduleType) throws IOException;
48
    
49
    /**
50
     * Return the server instance specific deployment properties file used by 
51
     * the deployment build script generated by the {@link #writeDeploymentScript(OutputStream,Object)}.
52
     *
53
     * @return the deployment properties file.
54
     */
55
    File getDeploymentPropertiesFile();
56
}
(-)src/org/netbeans/modules/j2ee/deployment/plugins/api/OptionalDeploymentManagerFactory.java (-1 / +12 lines)
Lines 60-65 Link Here
60
    }
60
    }
61
    
61
    
62
    /**
62
    /**
63
     * Creates an Ant deployment provider for the specified deployment manager.
64
     *
65
     * @param dm deployment manager.
66
     * @return an instance of the AntDeploymentProvider if Ant deployment
67
     *         is supported for the specified deployment manager, null otherwise.
68
     * @since 1.17
69
     */
70
    public AntDeploymentProvider getAntDeploymentProvider(DeploymentManager dm) {
71
        return null;
72
    }
73
    
74
    /**
63
     * Creates a <code>DatasourceManager</code> for the given deployment manager
75
     * Creates a <code>DatasourceManager</code> for the given deployment manager
64
     * or <code>null</code> if data source management is not supported
76
     * or <code>null</code> if data source management is not supported
65
     *
77
     *
Lines 73-77 Link Here
73
    public DatasourceManager getDatasourceManager(DeploymentManager dm) {
85
    public DatasourceManager getDatasourceManager(DeploymentManager dm) {
74
        return null;
86
        return null;
75
    }
87
    }
76
    
77
}
88
}

Return to bug 74387