2788N/A/*
2788N/A * CDDL HEADER START
2788N/A *
2788N/A * The contents of this file are subject to the terms of the
2788N/A * Common Development and Distribution License, Version 1.0 only
2788N/A * (the "License"). You may not use this file except in compliance
2788N/A * with the License.
2788N/A *
2788N/A * You can obtain a copy of the license at
2788N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
2788N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
2788N/A * See the License for the specific language governing permissions
2788N/A * and limitations under the License.
2788N/A *
2788N/A * When distributing Covered Code, include this CDDL HEADER in each
2788N/A * file and include the License file at
2788N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
2788N/A * add the following below this CDDL HEADER, with the fields enclosed
2788N/A * by brackets "[]" replaced with your own identifying information:
2788N/A * Portions Copyright [yyyy] [name of copyright owner]
2788N/A *
2788N/A * CDDL HEADER END
2788N/A *
2788N/A *
5061N/A * Copyright 2008-2010 Sun Microsystems, Inc.
2788N/A */
2788N/Aimport java.io.*;
2788N/Aimport java.lang.*;
2788N/Aimport java.util.ArrayList;
2907N/Aimport javax.xml.transform.*;
2788N/A
2788N/Apublic class GenerateOpenDSTestSpecs
2788N/A{
2788N/A private static String strParentDirName;
2788N/A private static String strOutputDirName;
2788N/A private static String strFileFormat;
2788N/A private static String strTestType;
2788N/A private static File fileList;
2788N/A private ArrayList <Object> arrayParsedData;
2788N/A
2788N/A public GenerateOpenDSTestSpecs()
2788N/A {
2788N/A }
2907N/A
2788N/A public static void main(String[] args)
2788N/A {
2788N/A // retrieve input
2788N/A if(args.length == 3)
2788N/A {
2788N/A strParentDirName = new String(args[0]);
2788N/A strOutputDirName = new String(args[1]);
2788N/A strFileFormat = new String(args[2]);
2788N/A }
2788N/A else
2788N/A {
2788N/A usage();
2788N/A System.exit(0);
2788N/A }
2788N/A
2788N/A // validate input
2788N/A File fileDirName = new File(strParentDirName);
2907N/A
2788N/A if(!fileDirName.isDirectory())
2788N/A {
2788N/A fatalMsg(fileDirName + " is not a directory.");
2788N/A System.exit(0);
2788N/A }
2788N/A else
2788N/A {
2788N/A System.out.println("Using file directory, " + strParentDirName);
2788N/A }
2788N/A
2788N/A File outputDirName = new File(strOutputDirName);
2788N/A if(!outputDirName.isDirectory())
2788N/A {
2788N/A fatalMsg(outputDirName + " is not a directory.");
2788N/A System.exit(0);
2788N/A }
2788N/A else
2788N/A {
2788N/A System.out.println("Using output directory, " + strOutputDirName);
2788N/A }
2788N/A
2788N/A // java files are assumed to be from the unit-integration tests.
2788N/A // xml files are assumed to be from the functional tests.
2788N/A if((strFileFormat.startsWith("java")) || (strFileFormat.startsWith("xml")))
2788N/A {
2788N/A System.out.println("Using file format " + strFileFormat.toString());
2788N/A if (strFileFormat.startsWith("java"))
2788N/A strTestType = "Int";
2788N/A else if (strFileFormat.startsWith("xml"))
2788N/A strTestType = "Func";
2788N/A }
2788N/A else
2788N/A {
2788N/A fatalMsg(strFileFormat + " is not supported in this version");
2788N/A System.exit(0);
2788N/A }
2788N/A System.out.println("Now running......");
2788N/A
2788N/A // create list of files to parse
2788N/A TestFileList listFiles = new TestFileList(strParentDirName);
2788N/A listFiles.createFileArray();
2788N/A
2788N/A // clean out the list of files
2788N/A listFiles.purgeFilesWithSubstring("svn");
2788N/A if(strFileFormat.startsWith("java"))
2788N/A {
2788N/A listFiles.keepFilesWithSubstring("java");
2788N/A }
2788N/A else if(strFileFormat.startsWith("xml"))
2788N/A {
2788N/A listFiles.keepFilesWithSubstring("xml");
2788N/A }
2788N/A
2788N/A // The ArrayList object, arrayFiles, contains the list of files that must be parsed.
2788N/A ArrayList arrayFiles = listFiles.getFileArray();
2788N/A
2788N/A // print out list of files
2788N/A //for(int i=0; i<arrayFiles.size(); i++)
2788N/A //{
2788N/A // File gotFile = (File)(arrayFiles.get(i));
2788N/A // System.out.println("File number " + Integer.toString(i) + " is " + gotFile.toString());
2788N/A //}
2788N/A
2788N/A // The ArrayList object, arrayDirs, contains the list of directories where the files will be found.
2788N/A ArrayList arrayDirs = listFiles.getDirArray();
2788N/A listFiles.purgeDirsWithSubstring("svn");
2788N/A
2788N/A // print out list of directories
2788N/A //for(int i=0; i<arrayDirs.size(); i++)
2788N/A //{
2788N/A // File gotDir = (File)(arrayDirs.get(i));
2788N/A // System.out.println("Directory number " + Integer.toString(i) + " is " + gotDir.toString());
2788N/A //}
2788N/A
2788N/A // Assume each directory will result in an output xml file
2788N/A // There will be one ParseData object for each directory.
2788N/A // Each ParseData object holds the test specs for all tests in that directory.
2788N/A // The ArrayList object, arrayTests, contains all the ParseData objects.
2788N/A ArrayList <Object>arrayTests = new ArrayList<Object>();
2788N/A
2788N/A // For each directory, parse out the data from each file within that directory.
2788N/A for(int i=0; i<arrayDirs.size(); i++)
2788N/A {
2788N/A // parse out data from all java files in a directory
2788N/A File gotDir = (File)(arrayDirs.get(i));
2788N/A String parsedDir = parseSuite(gotDir, strParentDirName);
2788N/A ParseData parseData = new ParseData(parsedDir, strFileFormat);
2788N/A
2788N/A try
2788N/A {
2788N/A arrayTests.add((ArrayData)(parseData.ParseFile(parsedDir, arrayFiles, strParentDirName)));
2788N/A }
2788N/A catch(Exception e)
2788N/A {
2788N/A e.printStackTrace();
2788N/A System.exit(0);
2788N/A }
2788N/A
2788N/A }
2788N/A
2788N/A // create the output xml files from the ParsedData objects
2788N/A for(int i = 0; i < arrayTests.size(); i++)
2788N/A {
2788N/A ArrayData arrayData = (ArrayData)(arrayTests.get(i));
2788N/A if(arrayData.size() > 0)
2788N/A {
2788N/A if(strFileFormat.startsWith("java"))
2788N/A {
2788N/A WriteXMLFile_int xmlFile = new WriteXMLFile_int(arrayData.getTestSuite(0));
2788N/A try
2788N/A {
2788N/A xmlFile.MakeXMLFile(arrayData, strOutputDirName);
2788N/A }
2788N/A catch(Exception e)
2788N/A {
2788N/A e.printStackTrace();
2788N/A }
2788N/A }
2788N/A else if(strFileFormat.startsWith("xml"))
2788N/A {
2788N/A WriteXMLFile_xml xmlFile = new WriteXMLFile_xml(arrayData.getTestSuite(0));
2907N/A WriteHTMLFile htmlFile = new WriteHTMLFile(arrayData.getTestSuite(0));
2788N/A try
2788N/A {
2788N/A xmlFile.MakeXMLFile(arrayData, strOutputDirName);
2907N/A htmlFile.MakeHTMLFile(arrayData, strOutputDirName,strParentDirName);
2788N/A }
2788N/A catch(Exception e)
2788N/A {
2788N/A e.printStackTrace();
2788N/A }
2788N/A }
2907N/A
2788N/A }
2907N/A
2788N/A }
2907N/A
2907N/A // Write the index file
2907N/A if(strFileFormat.startsWith("xml"))
2907N/A {
2907N/A
2907N/A // Index.xml
2907N/A try {
2907N/A File indexFile = new File(strOutputDirName + "/index.xml");
2907N/A FileWriter indexFileout = new FileWriter(indexFile);
2907N/A
2907N/A indexFileout.write("<?xml version=\"1.0\"?>\n\n");
2907N/A indexFileout.write("<qa>\n");
2907N/A indexFileout.write(" <doc>\n");
2788N/A
2907N/A for(int k = 0; k < arrayTests.size(); k++)
2907N/A {
2907N/A
2907N/A ArrayData testSuitePath = (ArrayData)(arrayTests.get(k));
2907N/A if(testSuitePath.size() > 0)
2907N/A {
2907N/A
2907N/A String specPath=testSuitePath.getTestSuite(0);
2907N/A
2907N/A String specName = (new File(specPath)).getName();
2907N/A
2907N/A String specFile=strOutputDirName + "/" + specPath + "/" + specName + ".html";
2907N/A
2907N/A indexFileout.write(" <testspec name=\"" + specName + "\" location=\"" + specFile + "\"/>\n");
2907N/A }
2907N/A }
2907N/A
2907N/A indexFileout.write(" </doc>\n");
2907N/A indexFileout.write("</qa>\n");
2907N/A indexFileout.close();
2907N/A
2907N/A }
2907N/A catch (Exception e) {
2907N/A e.printStackTrace( );
2907N/A }
2907N/A
2907N/A // Index.html
2907N/A File xmlFilename= new File(strOutputDirName + "/index.xml");
5061N/A File xslFilename = new File(strParentDirName + "/../../shared/xsl/testspec-index-stylesheet.xsl");
2907N/A File htmlFilename = new File(strOutputDirName + "/index.html");
2907N/A try{
2907N/A TransformerFactory transFactory = TransformerFactory.newInstance();
2907N/A
2907N/A Transformer transformer = transFactory.newTransformer
2907N/A (new javax.xml.transform.stream.StreamSource(xslFilename));
2907N/A
2907N/A transformer.transform
2907N/A (new javax.xml.transform.stream.StreamSource(xmlFilename),
2907N/A new javax.xml.transform.stream.StreamResult
2907N/A (new FileOutputStream(htmlFilename))
2907N/A );
2907N/A }
2907N/A
2907N/A catch (Exception e) {
2907N/A e.printStackTrace( );
2907N/A }
2907N/A
2907N/A }
2907N/A
2788N/A System.out.println("Files successfully written to the output directory.");
2788N/A
2788N/A }
2788N/A
2788N/A private static void usage()
2788N/A {
2788N/A System.out.println("Version 01202007");
2788N/A System.out.println("This program will parse files that are used for testing and create an xml file that is used for generating test specification html pages.");
2788N/A System.out.println("The program will recursively search for files from the directory that is passed in from the parameter.");
2788N/A System.out.println("This version will only recursively search one or two levels below the \"directory to files\" which is passed in as a parameter.");
2788N/A System.out.println("The file formats that are currently supported are \"java\" and \"xml\".");
2788N/A System.out.println("Usage:");
2788N/A System.out.println(" java GenerateOpenDSTestSpecs [directory to files] [directory for output files] [file format]");
2788N/A }
2788N/A
2788N/A private static void fatalMsg(String str)
2788N/A {
2788N/A System.out.println(str);
2788N/A System.out.println("exiting.....");
2788N/A }
2907N/A
2788N/A private static String parseSuite(File inDir, String strParentDir)
2788N/A {
2788N/A String tmpStr = new String(inDir.toString());
2788N/A int index = tmpStr.indexOf(strParentDir) + strParentDir.length() + 1;
2788N/A String subStr = tmpStr.substring(index);
2788N/A
2788N/A return subStr;
2788N/A
2788N/A }
2907N/A
2788N/A}