KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ant > Deploy


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ant;
21
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.Task;
24
25 import org.openide.util.Lookup;
26 import org.netbeans.modules.j2ee.deployment.devmodules.api.*;
27 import org.netbeans.api.project.FileOwnerQuery;
28 import org.openide.filesystems.*;
29 import org.apache.tools.ant.Project;
30 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
31 import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo;
32
33 /**
34  * Ant task that starts the server if needed and deploys module to the server
35  * @author Martin Grebac
36  */

37 public class Deploy extends Task implements Deployment.Logger {
38     
39     /**
40      * Holds value of property debugmode.
41      */

42     private boolean debugmode = false;
43     
44     private boolean forceRedeploy = false;
45     
46     /**
47      * URI of the web client or rich client in J2EE application to execute after deployment.
48      */

49     private String JavaDoc clientModuleUri;
50     
51     /**
52      * Part to build returned property client.url
53      */

54     private String JavaDoc clientUrlPart;
55
56     
57     public void execute() throws BuildException {
58         
59         ClassLoader JavaDoc originalLoader = null;
60         
61         try {
62             // see issue #62448
63
ClassLoader JavaDoc current = (ClassLoader JavaDoc)Lookup.getDefault().lookup(ClassLoader JavaDoc.class);
64             if (current == null) {
65                 current = ClassLoader.getSystemClassLoader();
66             }
67             if (current != null) {
68                 originalLoader = Thread.currentThread().getContextClassLoader();
69                 Thread.currentThread().setContextClassLoader(current);
70             }
71
72             J2eeModuleProvider jmp = null;
73             try {
74                 FileObject fob = FileUtil.toFileObject(getProject().getBaseDir());
75                 fob.refresh(); // without this the "build" directory is not found in filesystems
76
jmp = (J2eeModuleProvider) FileOwnerQuery.getOwner(fob).getLookup().lookup(J2eeModuleProvider.class);
77             } catch (Exception JavaDoc e) {
78                 throw new BuildException(e);
79             }
80
81             try {
82                 String JavaDoc clientUrl = Deployment.getDefault ().deploy (jmp, debugmode, clientModuleUri, clientUrlPart, forceRedeploy, this);
83                 if (clientUrl != null) {
84                     getProject().setProperty("client.url", clientUrl);
85                 }
86
87                 ServerDebugInfo sdi = jmp.getServerDebugInfo();
88
89                 if (sdi != null) { //fix for bug 57854, this can be null
90
String JavaDoc h = sdi.getHost();
91                     String JavaDoc transport = sdi.getTransport();
92                     String JavaDoc address = ""; //NOI18N
93

94                     if (transport.equals(ServerDebugInfo.TRANSPORT_SHMEM)) {
95                         address = sdi.getShmemName();
96                     } else {
97                         address = Integer.toString(sdi.getPort());
98                     }
99
100                     getProject().setProperty("jpda.transport", transport);
101                     getProject().setProperty("jpda.host", h);
102                     getProject().setProperty("jpda.address", address);
103                 }
104             } catch (Exception JavaDoc ex) {
105                 throw new BuildException(ex);
106             }
107         } finally {
108             if (originalLoader != null) {
109                 Thread.currentThread().setContextClassLoader(originalLoader);
110             }
111         }
112     }
113
114     /**
115      * Getter for property debugmode.
116      * @return Value of property debugmode.
117      */

118     public boolean getDebugmode() {
119         return this.debugmode;
120     }
121     
122     /**
123      * Setter for property debugmode.
124      * @param debugmode New value of property debugmode.
125      */

126     public void setDebugmode(boolean debugmode) {
127         this.debugmode = debugmode;
128     }
129         
130     public boolean getForceRedeploy() {
131         return this.forceRedeploy;
132     }
133     
134     public void setForceRedeploy(boolean forceRedeploy) {
135         this.forceRedeploy = forceRedeploy;
136     }
137     
138     /**
139      * Getter for property clientUrl.
140      * @return Value of property clientUrl.
141      */

142     public String JavaDoc getClientUrlPart() {
143         return this.clientUrlPart;
144     }
145     
146     /**
147      * Setter for property clientUrl.
148      * @param clientUrl New value of property clientUrl.
149      */

150     public void setClientUrlPart(String JavaDoc clientUrlPart) {
151         this.clientUrlPart = clientUrlPart;
152     }
153     
154     /**
155      * Get/setter for task parameter 'clientUri'
156      */

157     public String JavaDoc getClientModuleUri() {
158         return this.clientModuleUri;
159     }
160     
161     public void setClientModuleUri(String JavaDoc clientModuleUri) {
162         this.clientModuleUri = clientModuleUri;
163     }
164 }
165
Popular Tags