001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.tomcat5.ide;
043:
044: import java.io.File;
045: import javax.enterprise.deploy.shared.ActionType;
046: import javax.enterprise.deploy.shared.CommandType;
047: import javax.enterprise.deploy.shared.ModuleType;
048: import javax.enterprise.deploy.shared.StateType;
049: import javax.enterprise.deploy.spi.DeploymentManager;
050: import javax.enterprise.deploy.spi.Target;
051: import javax.enterprise.deploy.spi.TargetModuleID;
052: import javax.enterprise.deploy.spi.status.ProgressObject;
053: import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException;
054: import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
055: import org.netbeans.modules.j2ee.deployment.plugins.api.AppChangeDescriptor;
056: import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment;
057: import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration;
058: import org.netbeans.modules.tomcat5.TomcatManager;
059: import org.netbeans.modules.tomcat5.TomcatManagerImpl;
060: import org.netbeans.modules.tomcat5.TomcatModule;
061: import org.openide.util.RequestProcessor;
062: import org.netbeans.modules.tomcat5.progress.ProgressEventSupport;
063: import org.netbeans.modules.tomcat5.progress.Status;
064:
065: /**
066: *
067: * @author Pavel Buzek
068: */
069: public class TomcatIncrementalDeployment extends IncrementalDeployment {
070:
071: private TomcatManager tm;
072:
073: /** Creates a new instance of TomcatIncrementaDeployment */
074: public TomcatIncrementalDeployment(DeploymentManager dm) {
075: this .tm = (TomcatManager) dm;
076: }
077:
078: public boolean canFileDeploy(Target target, J2eeModule j2eeModule) {
079: return j2eeModule.getModuleType().equals(
080: javax.enterprise.deploy.shared.ModuleType.WAR);
081:
082: }
083:
084: public File getDirectoryForModule(TargetModuleID module) {
085: return null;
086: /*TomcatModule tModule = (TomcatModule) module;
087: String moduleFolder = tm.getCatalinaBaseDir ().getAbsolutePath ()
088: + System.getProperty("file.separator") + "webapps" //NOI18N
089: + System.getProperty("file.separator") + tModule.getPath ().substring (1); //NOI18N
090: File f = new File (moduleFolder);
091: return f;*/
092: }
093:
094: public File getDirectoryForNewApplication(Target target,
095: J2eeModule module, ModuleConfiguration configuration) {
096: if (module.getModuleType().equals(ModuleType.WAR)) {
097: return null;
098: /*if (configuration instanceof WebappConfiguration) {
099: String moduleFolder = tm.getCatalinaBaseDir ().getAbsolutePath ()
100: + System.getProperty("file.separator") + "webapps" //NOI18N
101: + System.getProperty("file.separator") + ((WebappConfiguration)configuration).getPath ().substring (1); //NOI18N
102: File f = new File (moduleFolder);
103: return f;
104: }*/
105: }
106: throw new IllegalArgumentException(
107: "ModuleType:" + module == null ? null : module
108: .getModuleType()
109: + " Configuration:" + configuration); //NOI18N
110: }
111:
112: public java.io.File getDirectoryForNewModule(java.io.File appDir,
113: String uri, J2eeModule module,
114: ModuleConfiguration configuration) {
115: throw new UnsupportedOperationException();
116: }
117:
118: public ProgressObject incrementalDeploy(
119: final TargetModuleID module, AppChangeDescriptor changes) {
120: if (changes.descriptorChanged()
121: || changes.serverDescriptorChanged()
122: || changes.classesChanged()) {
123: TomcatManagerImpl tmi = new TomcatManagerImpl(tm);
124: if (changes.serverDescriptorChanged()) {
125: new TomcatManagerImpl(tm).remove((TomcatModule) module);
126: tmi.incrementalRedeploy((TomcatModule) module);
127: } else if (changes.descriptorChanged()) {
128: new TomcatManagerImpl(tm).stop((TomcatModule) module);
129: tmi.start((TomcatModule) module);
130: } else {
131: tmi.reload((TomcatModule) module);
132: }
133: return tmi;
134: } else {
135: final P p = new P(module);
136: p.supp.fireHandleProgressEvent(module, new Status(
137: ActionType.EXECUTE, CommandType.DISTRIBUTE, "",
138: StateType.COMPLETED));
139: RequestProcessor.getDefault().post(new Runnable() {
140: public void run() {
141: try {
142: p.supp.fireHandleProgressEvent(module,
143: new Status(ActionType.EXECUTE,
144: CommandType.DISTRIBUTE, "",
145: StateType.COMPLETED));
146:
147: } catch (Throwable e) {
148: e.printStackTrace();
149: }
150: }
151: });
152: return p;
153: }
154: }
155:
156: public ProgressObject initialDeploy(Target target, J2eeModule app,
157: ModuleConfiguration configuration, File dir) {
158: TomcatManagerImpl tmi = new TomcatManagerImpl(tm);
159: File contextXml = new File(dir.getAbsolutePath()
160: + "/META-INF/context.xml"); //NOI18N
161: tmi.initialDeploy(target, contextXml, dir);
162: return tmi;
163: }
164:
165: public void notifyDeployment(TargetModuleID module) {
166: if (tm.isTomcat50()
167: && tm.getTomcatProperties().getOpenContextLogOnRun()) {
168: tm.openLog(module);
169: }
170: }
171:
172: private static class P implements ProgressObject {
173:
174: ProgressEventSupport supp = new ProgressEventSupport(this );
175: TargetModuleID tmid;
176:
177: P(TargetModuleID tmid) {
178: this .tmid = tmid;
179: }
180:
181: public void addProgressListener(
182: javax.enterprise.deploy.spi.status.ProgressListener progressListener) {
183: supp.addProgressListener(progressListener);
184: }
185:
186: public void removeProgressListener(
187: javax.enterprise.deploy.spi.status.ProgressListener progressListener) {
188: supp.removeProgressListener(progressListener);
189: }
190:
191: public javax.enterprise.deploy.spi.status.ClientConfiguration getClientConfiguration(
192: javax.enterprise.deploy.spi.TargetModuleID targetModuleID) {
193: return null;
194: }
195:
196: public javax.enterprise.deploy.spi.status.DeploymentStatus getDeploymentStatus() {
197: return supp.getDeploymentStatus();
198: }
199:
200: public javax.enterprise.deploy.spi.TargetModuleID[] getResultTargetModuleIDs() {
201: return new TargetModuleID[] { tmid };
202: }
203:
204: public boolean isCancelSupported() {
205: return false;
206: }
207:
208: public boolean isStopSupported() {
209: return false;
210: }
211:
212: public void cancel()
213: throws javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException {
214: throw new OperationUnsupportedException("");
215: }
216:
217: public void stop()
218: throws javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException {
219: throw new OperationUnsupportedException("");
220: }
221:
222: }
223: }
|