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: /*
043: * DataObjectTestsGenerator.java
044: *
045: * Created on June 26, 2001, 11:25 AM
046: */
047:
048: package DataLoaderTests.DataObjectTest;
049:
050: import org.openide.filesystems.Repository;
051:
052: /**
053: *
054: * @author jzajicek
055: * @version
056: */
057: public class DataObjectTestsGenerator {
058:
059: /** Creates new DataObjectTestsGenerator */
060: public DataObjectTestsGenerator() {
061: }
062:
063: /**
064: * @param args the command line arguments
065: */
066: public static void main(String args[]) {
067: org.openide.filesystems.FileObject fo = Repository.getDefault()
068: .findResource(
069: PACKAGE + "/" + DATAOBJECTS + "/" + "Backup");
070:
071: org.openide.loaders.DataFolder df = null;
072: try {
073: if (fo.isFolder()) {
074: df = (org.openide.loaders.DataFolder) org.openide.loaders.DataFolder
075: .find(fo);
076: //System.out.println(df);
077: org.openide.loaders.DataObject[] dobs = df
078: .getChildren();
079:
080: //java.io.File testlist = new java.io.File(ROOT + "/DataObjectsTests.ttl");
081: //testlist.createNewFile();
082: //java.io.PrintWriter toTestlist = new java.io.PrintWriter(new java.io.FileOutputStream(testlist));
083:
084: for (int j = 0; j < CAT.length; j++) {
085: for (int i = 0; i < dobs.length; i++) {
086: //System.out.println(dobs[i]);
087: String name = dobs[i].getPrimaryFile()
088: .getName();
089: String ext = dobs[i].getPrimaryFile().getExt();
090:
091: java.io.File d = new java.io.File(ROOT + "/"
092: + CAT[j] + "/" + name + "/");
093: d.mkdirs();
094:
095: java.io.File f = new java.io.File(ROOT + "/"
096: + CAT[j] + "/" + name + "/" + name
097: + "_" + CAT[j] + ".java");
098: f.createNewFile();
099:
100: //java.io.File cfg = new java.io.File(ROOT + "/" + CAT[j] + "/" + name + "/" + name /*+ "_" + CAT[j]*/ + ".cfg");
101: //cfg.createNewFile();
102:
103: String clazz = s1 + CAT[j] + "." + name + ";\n"
104: + s2 + name + "_" + CAT[j] + s3
105: + CAT[j] + "{\n" + s4 + name + "_"
106: + CAT[j] + s4_1 + s5 + name + "." + ext
107: + s6 + name + "_" + CAT[j] + s7;
108:
109: java.io.PrintWriter pv = new java.io.PrintWriter(
110: new java.io.FileOutputStream(f));
111: pv.print(clazz);
112: pv.flush();
113: pv.close();
114:
115: //java.io.PrintWriter toCfg = new java.io.PrintWriter(new java.io.FileOutputStream(cfg));
116: //toCfg.print("EXECUTE_CLASS=" + PACKAGE.replace('/','.') + "." + CAT[j] + "." + name + "." + name + "_" + CAT[j]);
117: //toCfg.flush();
118: //toCfg.close();
119:
120: //toTestlist.print(PACKAGE + "/" + CAT[j] + "/" + name + " execute_positive\n");
121: }
122: }
123: //toTestlist.flush();
124: //toTestlist.close();
125: } else {
126: System.out
127: .println("Expecting 'DataObjects' folder in this package!");
128: }
129: } catch (Exception ex) {
130: ex.printStackTrace();
131: }
132: }
133:
134: final static String PACKAGE = new DataObjectTestsGenerator()
135: .getClass().getPackage().getName().replace('.', '/');
136:
137: final static String ROOT = org.openide.filesystems.FileUtil.toFile(
138: Repository.getDefault().findResource(PACKAGE))
139: .getAbsolutePath();
140:
141: final static String DATAOBJECTS = "data";
142: final static String MANIPULATION = "manipulation";
143: final static String MODIFY = "modify";
144: final static String VALIDITY = "validity";
145: final static String DELEGATE = "delegate";
146: final static String OTHERS = "others";
147:
148: final static String[] CAT = new String[] { MANIPULATION, MODIFY,
149: VALIDITY, DELEGATE, OTHERS };
150:
151: final static String s1 = "package DataLoaderTests.DataObjectTest.";
152: final static String s2 = "import junit.framework.*;\nimport org.netbeans.junit.*;\npublic class ";
153: final static String s3 = " extends DataLoaderTests.DataObjectTest.DataObjectTest_";
154: final static String s4 = " public ";
155: final static String s4_1 = "(java.lang.String testName){\n super(testName);\n";
156: final static String s5 = " NAME = \"/" + DATAOBJECTS + "/";
157: final static String s6 = "\";\n }\npublic static Test suite() {\n NbTestSuite suite = new NbTestSuite(";
158: final static String s7 = ".class);\n return suite;\n }\n}";
159:
160: }
|