Index: tests/tools/harness/org/apache/harmony/harness/plugins/TestHandler.java =================================================================== --- tests/tools/harness/org/apache/harmony/harness/plugins/TestHandler.java (revision 575039) +++ tests/tools/harness/org/apache/harmony/harness/plugins/TestHandler.java (working copy) @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ /** * @author A.Tyuryushkin * @version $Revision: 1.15 $ @@ -36,51 +36,50 @@ public class TestHandler extends DefaultHandler { - private final String classID = "TestHandler"; + private final String classID = "TestHandler"; - private TestIR theTestIR; - private String keyName = ""; - private String keyValue = ""; - private ArrayList copyrights = new ArrayList(); - private ArrayList authors = new ArrayList(); - private ArrayList keywords = new ArrayList(); - private ArrayList sources = new ArrayList(); - private ArrayList resources = new ArrayList(); - private ArrayList modifications = new ArrayList(); - private ArrayList modification = new ArrayList(); - private ArrayList runner = new ArrayList(); - private ArrayList options = new ArrayList(); - private ArrayList parameters = new ArrayList(); - private boolean inToParam = false; - private boolean finishOptions = false; - private Logging log = Main.getCurCore() - .getInternalLogger(); + private TestIR theTestIR; + private String keyName = ""; + private String keyValue = ""; + private ArrayList copyrights = new ArrayList(); + private ArrayList authors = new ArrayList(); + private ArrayList keywords = new ArrayList(); + private ArrayList sources = new ArrayList(); + private ArrayList resources = new ArrayList(); + private ArrayList modifications = new ArrayList(); + private ArrayList modification = new ArrayList(); + private ArrayList runner = new ArrayList(); + private ArrayList options = new ArrayList(); + private ArrayList parameters = new ArrayList(); + private boolean inToParam = false; + private boolean finishOptions = false; + private Logging log = Main.getCurCore().getInternalLogger(); - protected CharArrayWriter context = new CharArrayWriter(); + protected CharArrayWriter context = new CharArrayWriter(); public TestHandler(TestIR curTestIR) { theTestIR = curTestIR; } public void characters(char[] character, int start, int length) - throws SAXException { + throws SAXException { context.write(character, start, length); } public void startDocument() throws SAXException { log.add(Level.FINER, MessageInfo.MSG_PREFIX + "<" - + this.getClass().getName() + ">"); + + this.getClass().getName() + ">"); } public void endDocument() throws SAXException { log.add(Level.FINER, MessageInfo.MSG_PREFIX + ""); + + this.getClass().getName() + ">"); } public void startElement(String uri, String localName, String qName, - Attributes attrs) throws SAXException { + Attributes attrs) throws SAXException { final String methodLogPrefix = MessageInfo.MSG_PREFIX + classID - + "\tstartElement(): "; + + "\tstartElement(): "; context.reset(); if (localName.equals("Test")) { int attrCount = attrs.getLength(); @@ -90,32 +89,33 @@ if (keyName.equalsIgnoreCase("id")) { theTestIR.setTestID(keyValue); log.add(Level.FINER, methodLogPrefix + "\tsetTestID(" - + keyValue + ") -> " + theTestIR.getTestID()); + + keyValue + ") -> " + theTestIR.getTestID()); } else if (keyName.equalsIgnoreCase("timeout")) { try { float timeoutValue = Float.parseFloat(keyValue); theTestIR.setTestTimeout(timeoutValue); log.add(Level.FINEST, methodLogPrefix - + "\tsetTestTimeout(" + keyValue + ") -> " - + theTestIR.getTestTimeout()); + + "\tsetTestTimeout(" + keyValue + ") -> " + + theTestIR.getTestTimeout()); } catch (NumberFormatException e) { try { theTestIR.setTestTimeout(keyValue); log.add(Level.FINEST, methodLogPrefix - + "\tsetTestTimeout(" + keyValue + ") -> 1.0"); + + "\tsetTestTimeout(" + keyValue + + ") -> 1.0"); } catch (IllegalArgumentException iae) { log - .add( - Level.FINEST, - methodLogPrefix - + "Warning: NumberFormatException - attribute 'timeout' is not number. Timeout was set to 1.0."); + .add( + Level.FINEST, + methodLogPrefix + + "Warning: NumberFormatException - attribute 'timeout' is not number. Timeout was set to 1.0."); } } } else { theTestIR.setProperty(keyName, keyValue); log.add(Level.FINEST, methodLogPrefix + "\tsetProperty('" - + keyName + "', '" + keyValue + "') -> " - + theTestIR.getProperty(keyName)); + + keyName + "', '" + keyValue + "') -> " + + theTestIR.getProperty(keyName)); } } } @@ -139,9 +139,9 @@ String idValue = attrs.getValue("ID"); String tmp = theTestIR.setRunnerID(idValue); if (tmp != null && !tmp.equals(idValue)) { - throw new SAXException( - methodLogPrefix - + "The test has 2 Runner's element: " + tmp + " and " + idValue + " that illegal"); + throw new SAXException(methodLogPrefix + + "The test has 2 Runner's element: " + tmp + " and " + + idValue + " that illegal"); } } if (localName.equals("Param")) { @@ -151,23 +151,26 @@ } options = new ArrayList(); if (attrs.getValue("name") == null - || attrs.getValue("name").trim() == "") { + || attrs.getValue("name").trim() == "") { throw new SAXException( - methodLogPrefix - + "The attribute 'name' of Runner's element 'parameter' in this test is absent or empty"); - } else if (!(attrs.getValue("name").equalsIgnoreCase(RunDRL.COMMAND) || - attrs.getValue("name").equalsIgnoreCase(DistributedRunner.EXEC_CMD) || - attrs.getValue("name").equalsIgnoreCase(CompDRL.COMMAND) || - attrs.getValue("name").equalsIgnoreCase(JUExecDRL.COMMAND))) { - log.add(Level.WARNING, methodLogPrefix + "\tPlease, check the parameter name: " - + attrs.getValue("name") + ". Standard value expected"); + methodLogPrefix + + "The attribute 'name' of Runner's element 'parameter' in this test is absent or empty"); + } else if (!(attrs.getValue("name") + .equalsIgnoreCase(RunDRL.COMMAND) + || attrs.getValue("name").equalsIgnoreCase( + DistributedRunner.EXEC_CMD) + || attrs.getValue("name").equalsIgnoreCase(CompDRL.COMMAND) || attrs + .getValue("name").equalsIgnoreCase(JUExecDRL.COMMAND))) { + log.add(Level.WARNING, methodLogPrefix + + "\tPlease, check the parameter name: " + + attrs.getValue("name") + ". Standard value expected"); } parameters.add(attrs.getValue("name")); if (attrs.getValue("value") == null - || attrs.getValue("value").trim() == "") { + || attrs.getValue("value").trim() == "") { throw new SAXException( - methodLogPrefix - + "The attribute 'value' of Runner's element 'parameter' in this test is absent or empty"); + methodLogPrefix + + "The attribute 'value' of Runner's element 'parameter' in this test is absent or empty"); } parameters.add(attrs.getValue("value")); inToParam = true; @@ -195,25 +198,29 @@ String propertyName = attrs.getValue("name"); // setter must be PUBLIC java.lang.reflect.Method[] methods = theTestIR.getClass() - .getMethods(); + .getMethods(); int methodsCount = methods.length; boolean stop = false; for (int i = 0; i < methodsCount && !stop; i++) { if (methods[i].getName().equalsIgnoreCase("set" + propertyName)) { Object[] objects = { new Boolean(true) }; log.add(Level.FINE, "\t" + methods[i].getName() + "(" - + objects[0] + ")"); + + objects[0] + ")"); try { methods[i].invoke(theTestIR, objects); } catch (InvocationTargetException e) { - log.add(Level.SEVERE, methodLogPrefix - + "Error in ENV configuration: setter 'set" - + propertyName + "' have been return exception", e - .getTargetException()); + log + .add( + Level.SEVERE, + methodLogPrefix + + "Error in ENV configuration: setter 'set" + + propertyName + + "' have been return exception", + e.getTargetException()); } catch (IllegalAccessException e) { log.add(Level.SEVERE, methodLogPrefix - + "Error in ENV configuration: setter 'set" - + propertyName + "' is inaccessible in class"); + + "Error in ENV configuration: setter 'set" + + propertyName + "' is inaccessible in class"); } stop = true; } @@ -222,133 +229,140 @@ } public void endElement(String uri, String localName, String qName) - throws SAXException { + throws SAXException { final String methodLogPrefix = MessageInfo.MSG_PREFIX + classID - + "\tendElement(): "; + + "\tendElement(): "; try { if (localName.equals("Test")) { theTestIR.setProperty("copyrights", copyrights); log.add(Level.FINEST, methodLogPrefix - + "setProperty(copyrights, set to ArrayList[" - + copyrights.size() + "])"); + + "setProperty(copyrights, set to ArrayList[" + + copyrights.size() + "])"); theTestIR.setProperty("authors", authors); log.add(Level.FINEST, methodLogPrefix - + "setProperty(authors, set to ArrayList[" + authors.size() - + "])"); + + "setProperty(authors, set to ArrayList[" + + authors.size() + "])"); String[] keywords = new String[this.keywords.size()]; for (int i = 0; i < this.keywords.size(); i++) { - keywords[i] = (String)this.keywords.get(i); + keywords[i] = (String) this.keywords.get(i); } theTestIR.setKeywords(keywords); log.add(Level.FINEST, methodLogPrefix + "setKeywords(String[" - + parameters.size() + "])"); + + parameters.size() + "])"); theTestIR.setProperty("sources", sources); log.add(Level.FINEST, methodLogPrefix - + "setProperty(sources, set to ArrayList[" + sources.size() - + "])"); + + "setProperty(sources, set to ArrayList[" + + sources.size() + "])"); theTestIR.setModifications(modifications); log.add(Level.FINEST, methodLogPrefix - + "\tsetModifications(set to ArrayList[" - + modifications.size() + "])"); + + "\tsetModifications(set to ArrayList[" + + modifications.size() + "])"); String[] resources = new String[this.resources.size()]; for (int i = 0; i < this.resources.size(); i++) { - resources[i] = (String)this.resources.get(i); + resources[i] = (String) this.resources.get(i); } theTestIR.setResources(resources); log.add(Level.FINEST, methodLogPrefix - + "\tsetResources(String[" + resources.length + "])"); + + "\tsetResources(String[" + resources.length + "])"); if (theTestIR.getTestID() == null) { throw new SAXException(methodLogPrefix - + "The attribute 'ID' of test is null"); + + "The attribute 'ID' of test is null"); } if (theTestIR.getTestID() == "") { throw new SAXException(methodLogPrefix - + "The attribute 'ID' of test is empty"); + + "The attribute 'ID' of test is empty"); } if (theTestIR.getRunnerID() == null) { - throw new SAXException( - methodLogPrefix + throw new SAXException(methodLogPrefix + "The attribute 'ID' of element 'Runner' of test " - + theTestIR.getTestID() + " is null"); + + theTestIR.getTestID() + " is null"); } if (theTestIR.getRunnerID() == "") { - throw new SAXException( - methodLogPrefix + throw new SAXException(methodLogPrefix + "The attribute 'ID' of element 'Runner' of test " - + theTestIR.getTestID() + " is empty"); + + theTestIR.getTestID() + " is empty"); } if (theTestIR.getProperty("date-of-creation") == null - || theTestIR.getProperty("date-of-creation").trim() == "") { + || theTestIR.getProperty("date-of-creation").trim() == "") { log.add(Level.INFO, methodLogPrefix - + "The attribute 'date-of-creation' of the test '" - + theTestIR.getTestID() + "' is absent or empty"); + + "The attribute 'date-of-creation' of the test '" + + theTestIR.getTestID() + "' is absent or empty"); } if (theTestIR.getProperty("Description") == null - || theTestIR.getProperty("Description").trim() == "") { + || theTestIR.getProperty("Description").trim() == "") { log.add(Level.INFO, methodLogPrefix - + "The element 'Description' of the test '" - + theTestIR.getTestID() + "' is absent or empty"); + + "The element 'Description' of the test '" + + theTestIR.getTestID() + "' is absent or empty"); } - if (theTestIR.getProperty((Object)"copyrights") == null - || ((ArrayList)theTestIR.getProperty((Object)"copyrights")) - .size() <= 0) { - //log.add(Level.INFO, methodLogPrefix - // + "The elements 'Copyright' of test '" - // + theTestIR.getTestID() + "' is empty"); + if (theTestIR.getProperty((Object) "copyrights") == null + || ((ArrayList) theTestIR + .getProperty((Object) "copyrights")).size() <= 0) { + // log.add(Level.INFO, methodLogPrefix + // + "The elements 'Copyright' of test '" + // + theTestIR.getTestID() + "' is empty"); } else { boolean empty = false; - for (int i = 0; i < ((ArrayList)theTestIR - .getProperty((Object)"copyrights")).size(); i++) { - if (((String)((ArrayList)theTestIR - .getProperty((Object)"copyrights")).get(i)).trim() == "") + for (int i = 0; i < ((ArrayList) theTestIR + .getProperty((Object) "copyrights")).size(); i++) { + if (((String) ((ArrayList) theTestIR + .getProperty((Object) "copyrights")).get(i)) + .trim() == "") empty = true; } if (empty) log.add(Level.INFO, methodLogPrefix - + "The element 'Copyright' of the test '" - + theTestIR.getTestID() + "' is empty"); + + "The element 'Copyright' of the test '" + + theTestIR.getTestID() + "' is empty"); } - if (theTestIR.getProperty((Object)"authors") == null - || ((ArrayList)theTestIR.getProperty((Object)"authors")) - .size() <= 0) { + if (theTestIR.getProperty((Object) "authors") == null + || ((ArrayList) theTestIR + .getProperty((Object) "authors")).size() <= 0) { log.add(Level.INFO, methodLogPrefix - + "The element 'Author' of the test '" - + theTestIR.getTestID() + "' is empty"); + + "The element 'Author' of the test '" + + theTestIR.getTestID() + "' is empty"); } else { boolean empty = false; - for (int i = 0; i < ((ArrayList)theTestIR - .getProperty((Object)"authors")).size(); i++) { - if (((String)((ArrayList)theTestIR - .getProperty((Object)"authors")).get(i)).trim() == "") + for (int i = 0; i < ((ArrayList) theTestIR + .getProperty((Object) "authors")).size(); i++) { + if (((String) ((ArrayList) theTestIR + .getProperty((Object) "authors")).get(i)) + .trim() == "") empty = true; } if (empty) - log.add(Level.INFO, methodLogPrefix - + "There are empty elements 'Author' in the test '" - + theTestIR.getTestID() + "'"); + log + .add( + Level.INFO, + methodLogPrefix + + "There are empty elements 'Author' in the test '" + + theTestIR.getTestID() + "'"); } - if (theTestIR.getProperty((Object)"sources") == null - || ((ArrayList)theTestIR.getProperty((Object)"sources")) - .size() <= 0) { + if (theTestIR.getProperty((Object) "sources") == null + || ((ArrayList) theTestIR + .getProperty((Object) "sources")).size() <= 0) { log.add(Level.INFO, methodLogPrefix - + "The element 'Source' of the test '" - + theTestIR.getTestID() + "' is absent"); + + "The element 'Source' of the test '" + + theTestIR.getTestID() + "' is absent"); } else { - for (int i = 0; i < ((ArrayList)theTestIR - .getProperty((Object)"sources")).size(); i++) { - String src = ((String)((ArrayList)theTestIR - .getProperty((Object)"sources")).get(i)); + for (int i = 0; i < ((ArrayList) theTestIR + .getProperty((Object) "sources")).size(); i++) { + String src = ((String) ((ArrayList) theTestIR + .getProperty((Object) "sources")).get(i)); if (src == null) { - log.add(Level.INFO, methodLogPrefix - + "incorrect element 'Source' of the test '" - + theTestIR.getTestID() + "'"); + log + .add( + Level.INFO, + methodLogPrefix + + "incorrect element 'Source' of the test '" + + theTestIR.getTestID() + + "'"); } else if (src.trim() == "") { log.add(Level.INFO, methodLogPrefix - + "empty element 'Source' of the test '" - + theTestIR.getTestID() + "'"); + + "empty element 'Source' of the test '" + + theTestIR.getTestID() + "'"); } } } @@ -359,40 +373,45 @@ empty = true; } if (empty) - log.add(Level.INFO, methodLogPrefix - + "There are empty elements 'Keyword' in the test '" - + theTestIR.getTestID() + "'"); + log + .add( + Level.INFO, + methodLogPrefix + + "There are empty elements 'Keyword' in the test '" + + theTestIR.getTestID() + "'"); } - if (((ArrayList)theTestIR.getModifications()).size() > 0) { + if (((ArrayList) theTestIR.getModifications()).size() > 0) { boolean emptyDate = false; boolean emptyAuthor = false; - for (int i = 0; i < ((ArrayList)theTestIR - .getModifications()).size(); i++) { - if (((ArrayList)theTestIR.getModifications().get(i)) - .get(0) == null - || ((String)((ArrayList)theTestIR - .getModifications().get(i)).get(0)).trim() == "") + for (int i = 0; i < ((ArrayList) theTestIR + .getModifications()).size(); i++) { + if (((ArrayList) theTestIR.getModifications().get(i)) + .get(0) == null + || ((String) ((ArrayList) theTestIR + .getModifications().get(i)).get(0)) + .trim() == "") emptyDate = true; - if (((ArrayList)theTestIR.getModifications().get(i)) - .get(1) == null - || ((String)((ArrayList)theTestIR - .getModifications().get(i)).get(1)).trim() == "") + if (((ArrayList) theTestIR.getModifications().get(i)) + .get(1) == null + || ((String) ((ArrayList) theTestIR + .getModifications().get(i)).get(1)) + .trim() == "") emptyAuthor = true; } if (emptyDate) log - .add( - Level.INFO, - methodLogPrefix - + "There are empty attributes 'date' of element 'Modification' in the test '" - + theTestIR.getTestID() + "'"); + .add( + Level.INFO, + methodLogPrefix + + "There are empty attributes 'date' of element 'Modification' in the test '" + + theTestIR.getTestID() + "'"); if (emptyAuthor) log - .add( - Level.INFO, - methodLogPrefix - + "There are empty attributes 'author' of element 'Modification' in the test '" - + theTestIR.getTestID() + "'"); + .add( + Level.INFO, + methodLogPrefix + + "There are empty attributes 'author' of element 'Modification' in the test '" + + theTestIR.getTestID() + "'"); } } if (localName.equals("Description")) { @@ -400,7 +419,7 @@ keyValue = context.toString().trim(); theTestIR.setProperty(keyName, keyValue); log.add(Level.FINEST, "\tsetProperty('" + keyName + "', '" - + keyValue + "') -> " + theTestIR.getProperty(keyName)); + + keyValue + "') -> " + theTestIR.getProperty(keyName)); } if (localName.equals("Modification")) { modifications.add(modification); @@ -411,31 +430,31 @@ if (runner.size() > 1) { theTestIR.setRunnerParam(runner); log.add(Level.FINEST, "\tsetRunnerParam(ArrayList[" - + runner.size() + "])"); + + runner.size() + "])"); runner = theTestIR.getRunnerParam(); log.add(Level.FINEST, "\tRunner parameters:"); if (runner.get(0) != null - && ((ArrayList)runner.get(0)).size() > 0) { - for (int j = 0; j < ((ArrayList)runner.get(0)).size(); j++) { + && ((ArrayList) runner.get(0)).size() > 0) { + for (int j = 0; j < ((ArrayList) runner.get(0)).size(); j++) { log.add(Level.FINEST, "\t\t - '" - + (String)((ArrayList)runner.get(0)).get(j) - + "'"); + + (String) ((ArrayList) runner.get(0)) + .get(j) + "'"); } } for (int i = 1; i < runner.size(); i++) { log.add(Level.FINEST, "\tParam - " - + ((ArrayList)runner.get(i)).get(0).toString() - + ":"); - for (int j = 1; j < ((ArrayList)runner.get(i)).size(); j++) { + + ((ArrayList) runner.get(i)).get(0).toString() + + ":"); + for (int j = 1; j < ((ArrayList) runner.get(i)).size(); j++) { log.add(Level.FINEST, "\t\t - '" - + (String)((ArrayList)runner.get(i)).get(j) - + "'"); + + (String) ((ArrayList) runner.get(i)) + .get(j) + "'"); } } } else { throw new SAXException( - methodLogPrefix - + "There are no execution parameter ('Param') of Runner in this test"); + methodLogPrefix + + "There are no execution parameter ('Param') of Runner in this test"); } } if (localName.equals("Param")) { @@ -447,7 +466,7 @@ throw e; } catch (Exception e) { log.add(Level.WARNING, methodLogPrefix + MessageInfo.UNEX_EXCEPTION - + e); + + e); } } } \ No newline at end of file