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-2007 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.junit;
043:
044: import java.util.prefs.Preferences;
045: import org.openide.nodes.BeanNode;
046: import org.openide.util.HelpCtx;
047: import org.openide.util.NbBundle;
048: import org.openide.util.NbPreferences;
049:
050: /** Options for JUnit module, control behavior of test creation and execution.
051: *
052: * @author vstejskal
053: * @author Marian Petras
054: */
055: public class JUnitSettings {
056: private static final JUnitSettings INSTANCE = new JUnitSettings();
057:
058: /** prefix for names of generated test classes */
059: static final String TEST_CLASSNAME_PREFIX = NbBundle.getMessage(
060: JUnitSettings.class, "PROP_test_classname_prefix"); //NOI18N
061: /** suffix for names of generated test classes */
062: static final String TEST_CLASSNAME_SUFFIX = NbBundle.getMessage(
063: JUnitSettings.class, "PROP_test_classname_suffix"); //NOI18N
064: /** prefix for names of generated test suites */
065: static final String SUITE_CLASSNAME_PREFIX = NbBundle.getMessage(
066: JUnitSettings.class, "PROP_suite_classname_prefix"); //NOI18N
067: /** suffix for names of generated test suites */
068: static final String SUITE_CLASSNAME_SUFFIX = NbBundle.getMessage(
069: JUnitSettings.class, "PROP_suite_classname_suffix"); //NOI18N
070: /** should it be possible to create tests for tests? */
071: static final boolean GENERATE_TESTS_FROM_TEST_CLASSES = NbBundle
072: .getMessage(JUnitSettings.class,
073: "PROP_generate_tests_from_test_classes").equals(
074: "true"); //NOI18N
075: /** generate test initializer method by default? */
076: static final boolean DEFAULT_GENERATE_SETUP = NbBundle.getMessage(
077: JUnitSettings.class, "PROP_generate_setUp_default").equals(
078: "true"); //NOI18N
079: /** generate test finalizer method by default? */
080: static final boolean DEFAULT_GENERATE_TEARDOWN = NbBundle
081: .getMessage(JUnitSettings.class,
082: "PROP_generate_tearDown_default").equals("true"); //NOI18N
083: /** generate test class initializer method by default? */
084: static final boolean DEFAULT_GENERATE_CLASS_SETUP = NbBundle
085: .getMessage(JUnitSettings.class,
086: "PROP_generate_class_setUp_default").equals("true"); //NOI18N
087: /** generate test class finalizer method by default? */
088: static final boolean DEFAULT_GENERATE_CLASS_TEARDOWN = NbBundle
089: .getMessage(JUnitSettings.class,
090: "PROP_generate_class_tearDown_default").equals(
091: "true"); //NOI18N
092: /** */
093: static final String JUNIT3_GENERATOR = JUnitVersion.JUNIT3.name()
094: .toLowerCase();
095: /** */
096: static final String JUNIT4_GENERATOR = JUnitVersion.JUNIT4.name()
097: .toLowerCase();
098: /** */
099: static final String JUNIT_GENERATOR_ASK_USER = "ask"; //NOI18N
100: /** */
101: static final String DEFAULT_GENERATOR = JUNIT_GENERATOR_ASK_USER;
102:
103: // XXX this property has to go too - will not work any longer, need some src -> test query
104: private static final String PROP_FILE_SYSTEM = "fileSystem";
105: public static final String PROP_MEMBERS_PUBLIC = "membersPublic";
106: public static final String PROP_MEMBERS_PROTECTED = "membersProtected";
107: public static final String PROP_MEMBERS_PACKAGE = "membersPackage";
108: public static final String PROP_BODY_COMMENTS = "bodyComments";
109: public static final String PROP_BODY_CONTENT = "bodyContent";
110: public static final String PROP_JAVADOC = "javaDoc";
111: public static final String PROP_GENERATE_EXCEPTION_CLASSES = "generateExceptionClasses";
112: public static final String PROP_GENERATE_ABSTRACT_IMPL = "generateAbstractImpl";
113: public static final String PROP_GENERATE_SUITE_CLASSES = "generateSuiteClasses";
114:
115: public static final String PROP_INCLUDE_PACKAGE_PRIVATE_CLASSES = "includePackagePrivateClasses";
116: public static final String PROP_GENERATE_MAIN_METHOD = "generateMainMethod";
117: public static final String PROP_GENERATE_MAIN_METHOD_BODY = "generateMainMethodBody";
118: public static final String PROP_GENERATE_SETUP = "generateSetUp";
119: public static final String PROP_GENERATE_TEARDOWN = "generateTearDown";
120: public static final String PROP_GENERATE_CLASS_SETUP = "generateClassSetUp";
121: public static final String PROP_GENERATE_CLASS_TEARDOWN = "generateClassTearDown";
122: public static final String PROP_GENERATOR = "generator";
123: public static final String PROP_ROOT_SUITE_CLASSNAME = "rootSuiteClassName";
124:
125: public static final String PROP_RESULTS_SPLITPANE_DIVIDER = "resultsSplitDivider";
126:
127: public String displayName() {
128: return NbBundle.getMessage(JUnitSettings.class,
129: "LBL_junit_settings");
130: }
131:
132: public HelpCtx getHelpCtx() {
133: return new HelpCtx(JUnitSettings.class);
134: }
135:
136: private static Preferences getPreferences() {
137: return NbPreferences.forModule(JUnitSettings.class);
138: }
139:
140: /** Default instance of this system option, for the convenience of associated classes. */
141: public static JUnitSettings getDefault() {
142: return INSTANCE;
143: }
144:
145: public boolean isMembersPublic() {
146: return getPreferences().getBoolean(PROP_MEMBERS_PUBLIC, true);
147: }
148:
149: public void setMembersPublic(boolean newVal) {
150: getPreferences().putBoolean(PROP_MEMBERS_PUBLIC, newVal);
151: }
152:
153: public boolean isMembersProtected() {
154: return getPreferences()
155: .getBoolean(PROP_MEMBERS_PROTECTED, true);
156: }
157:
158: public void setMembersProtected(boolean newVal) {
159: getPreferences().putBoolean(PROP_MEMBERS_PROTECTED, newVal);
160: }
161:
162: public boolean isMembersPackage() {
163: return getPreferences().getBoolean(PROP_MEMBERS_PACKAGE, true);
164: }
165:
166: public void setMembersPackage(boolean newVal) {
167: getPreferences().putBoolean(PROP_MEMBERS_PACKAGE, newVal);
168: }
169:
170: public boolean isBodyComments() {
171: return getPreferences().getBoolean(PROP_BODY_COMMENTS, true);
172:
173: }
174:
175: public void setBodyComments(boolean newVal) {
176: getPreferences().putBoolean(PROP_BODY_COMMENTS, newVal);
177: }
178:
179: public boolean isBodyContent() {
180: return getPreferences().getBoolean(PROP_BODY_CONTENT, true);
181: }
182:
183: public void setBodyContent(boolean newVal) {
184: getPreferences().putBoolean(PROP_BODY_CONTENT, newVal);
185: }
186:
187: public boolean isJavaDoc() {
188: return getPreferences().getBoolean(PROP_JAVADOC, true);
189: }
190:
191: public void setJavaDoc(boolean newVal) {
192: getPreferences().putBoolean(PROP_JAVADOC, newVal);
193: }
194:
195: public boolean isGenerateExceptionClasses() {
196: return getPreferences().getBoolean(
197: PROP_GENERATE_EXCEPTION_CLASSES, true);
198: }
199:
200: public void setGenerateExceptionClasses(boolean newVal) {
201: getPreferences().putBoolean(PROP_GENERATE_EXCEPTION_CLASSES,
202: newVal);
203: }
204:
205: public boolean isGenerateAbstractImpl() {
206: return getPreferences().getBoolean(PROP_GENERATE_ABSTRACT_IMPL,
207: true);
208: }
209:
210: public void setGenerateAbstractImpl(boolean newVal) {
211: getPreferences()
212: .putBoolean(PROP_GENERATE_ABSTRACT_IMPL, newVal);
213: }
214:
215: public boolean isGenerateSuiteClasses() {
216: return getPreferences().getBoolean(PROP_GENERATE_SUITE_CLASSES,
217: true);
218: }
219:
220: public void setGenerateSuiteClasses(boolean newVal) {
221: getPreferences()
222: .putBoolean(PROP_GENERATE_SUITE_CLASSES, newVal);
223: }
224:
225: public boolean isIncludePackagePrivateClasses() {
226: return getPreferences().getBoolean(
227: PROP_INCLUDE_PACKAGE_PRIVATE_CLASSES, true);
228: }
229:
230: public void setIncludePackagePrivateClasses(boolean newVal) {
231: getPreferences().putBoolean(
232: PROP_INCLUDE_PACKAGE_PRIVATE_CLASSES, newVal);
233: }
234:
235: public boolean isGenerateMainMethod() {
236: return getPreferences().getBoolean(PROP_GENERATE_MAIN_METHOD,
237: true);
238: }
239:
240: public void setGenerateMainMethod(boolean newVal) {
241: getPreferences().putBoolean(PROP_GENERATE_MAIN_METHOD, newVal);
242: }
243:
244: public boolean isGenerateSetUp() {
245: return getPreferences().getBoolean(PROP_GENERATE_SETUP,
246: DEFAULT_GENERATE_SETUP);
247: }
248:
249: public void setGenerateSetUp(boolean newVal) {
250: getPreferences().putBoolean(PROP_GENERATE_SETUP, newVal);
251: }
252:
253: public boolean isGenerateTearDown() {
254: return getPreferences().getBoolean(PROP_GENERATE_TEARDOWN,
255: DEFAULT_GENERATE_TEARDOWN);
256: }
257:
258: public void setGenerateTearDown(boolean newVal) {
259: getPreferences().putBoolean(PROP_GENERATE_TEARDOWN, newVal);
260: }
261:
262: public boolean isGenerateClassSetUp() {
263: return getPreferences().getBoolean(PROP_GENERATE_CLASS_SETUP,
264: DEFAULT_GENERATE_CLASS_SETUP);
265: }
266:
267: public void setGenerateClassSetUp(boolean newVal) {
268: getPreferences().putBoolean(PROP_GENERATE_CLASS_SETUP, newVal);
269: }
270:
271: public boolean isGenerateClassTearDown() {
272: return getPreferences().getBoolean(
273: PROP_GENERATE_CLASS_TEARDOWN,
274: DEFAULT_GENERATE_CLASS_TEARDOWN);
275: }
276:
277: public void setGenerateClassTearDown(boolean newVal) {
278: getPreferences().putBoolean(PROP_GENERATE_CLASS_TEARDOWN,
279: newVal);
280: }
281:
282: public String getGenerator() {
283: return getPreferences().get(PROP_GENERATOR, DEFAULT_GENERATOR);
284: }
285:
286: public void setGenerator(String generator) {
287: getPreferences().put(PROP_GENERATOR, generator);
288: }
289:
290: public String getGenerateMainMethodBody() {
291: return getPreferences()
292: .get(
293: PROP_GENERATE_MAIN_METHOD_BODY,
294: NbBundle
295: .getMessage(JUnitSettings.class,
296: "PROP_generate_main_method_body_default_value"));
297: }
298:
299: public void setGenerateMainMethodBody(String newVal) {
300: getPreferences().put(PROP_GENERATE_MAIN_METHOD_BODY, newVal);
301: }
302:
303: public String getRootSuiteClassName() {
304: return getPreferences().get(
305: PROP_ROOT_SUITE_CLASSNAME,
306: NbBundle.getMessage(JUnitSettings.class,
307: "PROP_root_suite_classname_default_value"));
308: }
309:
310: public void setRootSuiteClassName(String newVal) {
311: getPreferences().put(PROP_ROOT_SUITE_CLASSNAME, newVal);
312: }
313:
314: public int getResultsSplitPaneDivider() {
315: return getPreferences().getInt(PROP_RESULTS_SPLITPANE_DIVIDER,
316: -1);
317: }
318:
319: public void setResultsSplitPaneDivider(int newVal) {
320: getPreferences().putInt(PROP_RESULTS_SPLITPANE_DIVIDER, newVal);
321: }
322:
323: private static BeanNode createViewNode()
324: throws java.beans.IntrospectionException {
325: return new BeanNode<JUnitSettings>(JUnitSettings.getDefault());
326: }
327: }
|