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.web.project;
043:
044: import java.io.IOException;
045: import java.io.File;
046: import javax.swing.Action;
047: import org.netbeans.api.project.ProjectManager;
048: import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties;
049: import org.netbeans.spi.project.support.ant.EditableProperties;
050: import org.netbeans.spi.project.support.ant.PropertyUtils;
051: import org.openide.modules.InstalledFileLocator;
052: import org.openide.modules.ModuleInstall;
053: import org.netbeans.spi.project.ActionProvider;
054: import org.netbeans.spi.project.ui.support.FileSensitiveActions;
055: import org.openide.NotifyDescriptor;
056: import org.openide.DialogDisplayer;
057: import org.openide.util.Exceptions;
058: import org.openide.util.NbBundle;
059:
060: /**
061: * Startup and shutdown hooks for web project module. It defines
062: * the project specific actions (e.g.compile/run/debug file) for the
063: * nodes representing JSP and html files. These actions are registered
064: * for their mime types in layer.
065: *
066: * @author Martin Grebac
067: */
068: public class WebProjectModule extends ModuleInstall {
069: public static final String JSPC_CLASSPATH = "jspc.classpath"; //NOI18N
070: public static final String COPYFILES_CLASSPATH = "copyfiles.classpath"; //NOI18N
071:
072: public void restored() {
073:
074: ProjectManager.mutex().postWriteRequest(new Runnable() {
075: public void run() {
076: try {
077: EditableProperties ep = PropertyUtils
078: .getGlobalProperties();
079: boolean changed = false;
080: // JSPC classpath
081: StringBuffer sb = new StringBuffer(450);
082: // Ant is needed in classpath if we are forking JspC into another process
083: sb
084: .append(
085: InstalledFileLocator.getDefault()
086: .locate("ant/lib/ant.jar",
087: null, false))
088: //NOI18N
089: .append(':')
090: // NOI18N
091: //XXX This is fix for issue #74250. This is a hack and should be solved in the glassfish's jasper
092: // also it must be moved before J2EE_PLATFORM_CLASSPATH, because a server (JBoss) can expose
093: // old jsp api, and the compiler is not then able compile some jsp pages with tag lib declarations
094: .append(
095: InstalledFileLocator
096: .getDefault()
097: .locate(
098: "modules/ext/servlet2.5-jsp2.1-api.jar",
099: null, false))
100: //NOI18N
101: .append(":${")
102: .append(
103: WebProjectProperties.J2EE_PLATFORM_CLASSPATH)
104: .append("}:") // NOI18N
105: .append(
106: InstalledFileLocator
107: .getDefault()
108: .locate(
109: "modules/ext/glassfish-jspparser-2.0.jar",
110: null, false)) //NOI18N
111: .append(':') // NOI18N
112: .append(
113: InstalledFileLocator
114: .getDefault()
115: .locate(
116: "modules/ext/glassfish-logging-2.0.jar",
117: null, false)) //NOI18N
118: .append(':') // NOI18N
119: .append(
120: InstalledFileLocator
121: .getDefault()
122: .locate(
123: "modules/ext/commons-logging-1.0.4.jar",
124: null, false)) //NOI18N
125: .append(':') // NOI18N
126: .append(
127: InstalledFileLocator
128: .getDefault()
129: .locate(
130: "ant/lib/ant-launcher.jar",
131: null, false)); //NOI18N
132: String jspc_cp_old = ep.getProperty(JSPC_CLASSPATH);
133: String jspc_cp = sb.toString();
134: if (jspc_cp_old == null
135: || !jspc_cp_old.equals(jspc_cp)) {
136: ep.setProperty(JSPC_CLASSPATH, jspc_cp);
137: changed = true;
138: }
139: File copy_files = InstalledFileLocator.getDefault()
140: .locate("ant/extra/copyfiles.jar", null,
141: false); //NOI18N
142: if (copy_files == null) {
143: String msg = NbBundle.getMessage(
144: WebProjectModule.class,
145: "MSG_CopyFileMissing"); //NOI18N
146: DialogDisplayer
147: .getDefault()
148: .notify(
149: new NotifyDescriptor.Message(
150: msg,
151: NotifyDescriptor.ERROR_MESSAGE));
152: } else {
153: String copy_files_old = ep
154: .getProperty(COPYFILES_CLASSPATH);
155: if (copy_files_old == null
156: || !copy_files_old.equals(copy_files
157: .toString())) {
158: ep.setProperty(COPYFILES_CLASSPATH,
159: copy_files.toString());
160: changed = true;
161: }
162: }
163: if (changed) {
164: PropertyUtils.putGlobalProperties(ep);
165: }
166: } catch (IOException ioe) {
167: Exceptions.printStackTrace(ioe);
168: }
169: }
170: });
171: }
172:
173: public static Action compile() {
174: return FileSensitiveActions.fileCommandAction(
175: ActionProvider.COMMAND_COMPILE_SINGLE, NbBundle
176: .getMessage(WebProjectModule.class,
177: "LBL_CompileFile_Action"), // NOI18N
178: null);
179: }
180:
181: public static Action run() {
182: return FileSensitiveActions.fileCommandAction(
183: ActionProvider.COMMAND_RUN_SINGLE, NbBundle.getMessage(
184: WebProjectModule.class, "LBL_RunFile_Action"), // NOI18N
185: null);
186: }
187:
188: public static Action debug() {
189: return FileSensitiveActions.fileCommandAction(
190: ActionProvider.COMMAND_DEBUG_SINGLE, NbBundle
191: .getMessage(WebProjectModule.class,
192: "LBL_DebugFile_Action"), // NOI18N
193: null);
194: }
195:
196: public static Action htmlRun() {
197: return FileSensitiveActions.fileCommandAction(
198: ActionProvider.COMMAND_RUN_SINGLE, NbBundle.getMessage(
199: WebProjectModule.class, "LBL_RunFile_Action"), // NOI18N
200: null);
201: }
202:
203: public static Action htmlDebug() {
204: return FileSensitiveActions.fileCommandAction(
205: ActionProvider.COMMAND_DEBUG_SINGLE, NbBundle
206: .getMessage(WebProjectModule.class,
207: "LBL_DebugFile_Action"), // NOI18N
208: null);
209: }
210:
211: }
|