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: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.modules.profiler.j2ee;
042:
043: import org.netbeans.lib.profiler.common.AttachSettings;
044: import org.netbeans.lib.profiler.common.integration.IntegrationUtils;
045: import java.text.MessageFormat;
046: import java.util.ResourceBundle;
047: import org.netbeans.modules.profiler.attach.providers.AbstractIntegrationProvider;
048: import org.netbeans.modules.profiler.attach.providers.IntegrationCategorizer;
049: import org.netbeans.modules.profiler.attach.providers.TargetPlatformEnum;
050: import org.netbeans.modules.profiler.attach.spi.IntegrationProvider;
051: import org.netbeans.modules.profiler.attach.wizard.steps.NullWizardStep;
052: import org.netbeans.modules.profiler.attach.wizard.steps.WizardStep;
053:
054: /**
055: *
056: * @author Tomas Hurka
057: * @author Jaroslav Bachorik
058: */
059: public class GenericWebAppServerIntegrationProvider extends
060: AbstractIntegrationProvider {
061: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
062:
063: private static final ResourceBundle messages = ResourceBundle
064: .getBundle("org.netbeans.modules.profiler.j2ee.Bundle"); // NOI18N
065: private static final String GENERIC_WEBAPP_SERVER_STRING = messages
066: .getString("GenericWebAppServerIntegrationProvider_GenericWebappServerString"); // NOI18N
067: private static final String PATH_TO_JDK_DIRECTORY_STRING = messages
068: .getString("GenericWebAppServerIntegrationProvider_PathToJdkDirectory"); // NOI18N
069: private static final String MANUAL_REMOTE_STEP3_MESSAGE = messages
070: .getString("GenericWebAppServerIntegrationProvider_ManualRemoteStep3Message"); // NOI18N
071: private static final String MANUAL_REMOTE_STEP4_MESSAGE = messages
072: .getString("GenericWebAppServerIntegrationProvider_ManualRemoteStep4Message"); // NOI18N
073: private static final String MANUAL_REMOTE_STEP5_MESSAGE = messages
074: .getString("GenericWebAppServerIntegrationProvider_ManualRemoteStep5Message"); // NOI18N
075: private static final String MANUAL_DIRECT_STEP1_MESSAGE = messages
076: .getString("GenericWebAppServerIntegrationProvider_ManualDirectStep1Message"); // NOI18N
077: private static final String MANUAL_DIRECT_STEP2_MESSAGE = messages
078: .getString("GenericWebAppServerIntegrationProvider_ManualDirectStep2Message"); // NOI18N
079: private static final String MANUAL_DIRECT_STEP3_MESSAGE = messages
080: .getString("GenericWebAppServerIntegrationProvider_ManualDirectStep3Message"); // NOI18N
081: private static final String MANUAL_DYNAMIC_STEP1_MESSAGE = messages
082: .getString("GenericWebAppServerIntegrationProvider_ManualDynamicStep1Message"); // NOI18N
083: private static final String MANUAL_DYNAMIC_STEP2_MESSAGE = messages
084: .getString("GenericWebAppServerIntegrationProvider_ManualDynamicStep2Message"); // NOI18N
085: private static final String DYNAMIC_WARNING_MESSAGE = messages
086: .getString("GenericWebAppServerIntegrationProvider_DynamicWarningMessage"); // NOI18N
087: private static final WizardStep NULL_WIZARD_STEP = new NullWizardStep();
088:
089: //~ Methods ------------------------------------------------------------------------------------------------------------------
090:
091: public IntegrationProvider.IntegrationHints getAfterInstallationHints(
092: AttachSettings attachSettings, boolean b) {
093: return new IntegrationProvider.IntegrationHints();
094: }
095:
096: public WizardStep getAttachedWizard() {
097: return NULL_WIZARD_STEP;
098: }
099:
100: // <editor-fold defaultstate="collapsed" desc="WizardIntegrationProvider implementation">
101: public IntegrationProvider.IntegrationHints getIntegrationReview(
102: AttachSettings attachSettings) {
103: return null;
104: }
105:
106: public IntegrationProvider.IntegrationHints getModificationHints(
107: AttachSettings attachSettings) {
108: String targetOS = attachSettings.getHostOS();
109:
110: // Remote attach instructions
111: if (attachSettings.isRemote()) {
112: return getManualRemoteIntegrationStepsInstructions(
113: targetOS, attachSettings);
114: }
115: // Local direct attach
116: else if (attachSettings.isDirect()) {
117: return getManualLocalDirectIntegrationStepsInstructions(
118: targetOS, attachSettings);
119: }
120: // Local dynamic attach
121: else {
122: return getManualLocalDynamicIntegrationStepsInstructions(
123: targetOS, attachSettings);
124: }
125: }
126:
127: public String getTitle() {
128: return GENERIC_WEBAPP_SERVER_STRING;
129: }
130:
131: public void categorize(IntegrationCategorizer integrationCategorizer) {
132: integrationCategorizer.addAppserver(this ,
133: getAttachWizardPriority());
134: }
135:
136: public void modify(AttachSettings attachSettings) {
137: }
138:
139: public void run(AttachSettings attachSettings) {
140: }
141:
142: public boolean supportsAutomation() {
143: return false;
144: }
145:
146: public boolean supportsDirect() {
147: return true;
148: }
149:
150: public boolean supportsDynamic() {
151: return true;
152: }
153:
154: public boolean supportsDynamicPid() {
155: return true;
156: }
157:
158: public boolean supportsJVM(TargetPlatformEnum jvm) {
159: return true;
160: }
161:
162: public boolean supportsLocal() {
163: return true;
164: }
165:
166: public boolean supportsManual() {
167: return true;
168: }
169:
170: public boolean supportsRemote() {
171: return true;
172: }
173:
174: protected int getAttachWizardPriority() {
175: return 1;
176: }
177:
178: private IntegrationProvider.IntegrationHints getManualLocalDirectIntegrationStepsInstructions(
179: String targetOS, AttachSettings attachSettings) {
180: IntegrationProvider.IntegrationHints instructions = new IntegrationProvider.IntegrationHints();
181:
182: // Step 1
183: String pathToJDKDirectory = "<"
184: + MessageFormat
185: .format(
186: PATH_TO_JDK_DIRECTORY_STRING,
187: new Object[] { IntegrationUtils
188: .getJavaPlatformName(getTargetJava()) })
189: + ">"; // NOI18N
190: instructions.addStep(MessageFormat.format(
191: MANUAL_DIRECT_STEP1_MESSAGE, new Object[] {
192: IntegrationUtils
193: .getJavaPlatformName(getTargetJava()),
194: IntegrationUtils
195: .getExportEnvVariableValueString(
196: targetOS, "JAVA_HOME",
197: pathToJDKDirectory, true) })); // NOI18N
198:
199: // Step 2
200: instructions.addStep(MessageFormat.format(
201: MANUAL_DIRECT_STEP2_MESSAGE,
202: new Object[] { IntegrationUtils
203: .getProfilerAgentCommandLineArgs(targetOS,
204: getTargetJava(), attachSettings
205: .isRemote(), attachSettings
206: .getPort()) }));
207:
208: // Step 3
209: instructions.addStep(MANUAL_DIRECT_STEP3_MESSAGE);
210:
211: // Note about spaces in path when starting Profiler agent
212: if (IntegrationUtils.isWindowsPlatform(targetOS)) {
213: instructions.addWarning(SPACES_IN_PATH_WARNING_MSG);
214: }
215:
216: // Note about decreasing CPU profiling overhead
217: instructions.addHint(REDUCE_OVERHEAD_MSG);
218:
219: // Note about export vs. setenv on UNIXes
220: if (!IntegrationUtils.isWindowsPlatform(targetOS)) {
221: instructions.addHint(EXPORT_SETENV_MSG);
222: }
223:
224: return instructions;
225: }
226:
227: private IntegrationProvider.IntegrationHints getManualLocalDynamicIntegrationStepsInstructions(
228: String targetOS, AttachSettings attachSettings) {
229: IntegrationProvider.IntegrationHints instructions = new IntegrationProvider.IntegrationHints();
230:
231: // Step 1
232: instructions.addStep(MessageFormat.format(
233: MANUAL_DYNAMIC_STEP1_MESSAGE,
234: new Object[] { IntegrationUtils
235: .getJavaPlatformName(getTargetJava()) }));
236: // Step 2
237: instructions.addStep(MANUAL_DYNAMIC_STEP2_MESSAGE);
238:
239: // Note about spaces in path when starting Profiler agent
240: if (IntegrationUtils.isWindowsPlatform(targetOS)) {
241: instructions.addWarning(SPACES_IN_PATH_WARNING_MSG);
242: }
243:
244: // Note about decreasing CPU profiling overhead
245: instructions.addHint(REDUCE_OVERHEAD_MSG);
246:
247: // Note about export vs. setenv on UNIXes
248: if (!IntegrationUtils.isWindowsPlatform(targetOS)) {
249: instructions.addHint(EXPORT_SETENV_MSG);
250: }
251:
252: instructions.addWarning(MessageFormat.format(
253: DYNAMIC_WARNING_MESSAGE, new Object[] {
254: IntegrationUtils
255: .getJavaPlatformName(getTargetJava()),
256: IntegrationUtils
257: .getProfilerAgentCommandLineArgs(
258: targetOS, getTargetJava(),
259: attachSettings.isRemote(),
260: attachSettings.getPort()) }));
261:
262: return instructions;
263: }
264:
265: // </editor-fold>
266: private IntegrationProvider.IntegrationHints getManualRemoteIntegrationStepsInstructions(
267: String targetOS, AttachSettings attachSettings) {
268: IntegrationProvider.IntegrationHints instructions = new IntegrationProvider.IntegrationHints();
269:
270: // Step 1
271: instructions.addStep(getManualRemoteStep1(targetOS));
272:
273: // Step 2
274: instructions.addStep(getManualRemoteStep2(targetOS));
275:
276: // Step 3
277: String pathToJDKDirectory = "<"
278: + MessageFormat
279: .format(
280: PATH_TO_JDK_DIRECTORY_STRING,
281: new Object[] { IntegrationUtils
282: .getJavaPlatformName(getTargetJava()) })
283: + ">"; // NOI18N
284: instructions.addStep(MessageFormat.format(
285: MANUAL_REMOTE_STEP3_MESSAGE, new Object[] {
286: IntegrationUtils
287: .getJavaPlatformName(getTargetJava()),
288: IntegrationUtils
289: .getExportEnvVariableValueString(
290: targetOS, "JAVA_HOME",
291: pathToJDKDirectory, true) })); // NOI18N
292:
293: // Step 4
294: instructions.addStep(MessageFormat.format(
295: MANUAL_REMOTE_STEP4_MESSAGE, new Object[] {
296: IntegrationUtils
297: .getProfilerAgentCommandLineArgs(
298: targetOS, getTargetJava(),
299: attachSettings.isRemote(),
300: attachSettings.getPort()),
301: REMOTE_ABSOLUTE_PATH_HINT }));
302:
303: // Step 5
304: instructions.addStep(MANUAL_REMOTE_STEP5_MESSAGE);
305:
306: // Note about spaces in path when starting Profiler agent
307: if (IntegrationUtils.isWindowsPlatform(targetOS)) {
308: instructions.addWarning(SPACES_IN_PATH_WARNING_MSG);
309: }
310:
311: // Note about decreasing CPU profiling overhead
312: instructions.addHint(REDUCE_OVERHEAD_MSG);
313:
314: // Note about export vs. setenv on UNIXes
315: if (!IntegrationUtils.isWindowsPlatform(targetOS)) {
316: instructions.addHint(EXPORT_SETENV_MSG);
317: }
318:
319: return instructions;
320: }
321: }
|