From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- qadevOOo/runner/stats/InternalLogWriter.java | 101 +++++++++++++++++++++ qadevOOo/runner/stats/OutProducerFactory.java | 121 ++++++++++++++++++++++++++ qadevOOo/runner/stats/SimpleLogWriter.java | 94 ++++++++++++++++++++ qadevOOo/runner/stats/SimpleOutProducer.java | 61 +++++++++++++ qadevOOo/runner/stats/Summarizer.java | 104 ++++++++++++++++++++++ 5 files changed, 481 insertions(+) create mode 100644 qadevOOo/runner/stats/InternalLogWriter.java create mode 100644 qadevOOo/runner/stats/OutProducerFactory.java create mode 100644 qadevOOo/runner/stats/SimpleLogWriter.java create mode 100644 qadevOOo/runner/stats/SimpleOutProducer.java create mode 100644 qadevOOo/runner/stats/Summarizer.java (limited to 'qadevOOo/runner/stats') diff --git a/qadevOOo/runner/stats/InternalLogWriter.java b/qadevOOo/runner/stats/InternalLogWriter.java new file mode 100644 index 000000000..a39e372a6 --- /dev/null +++ b/qadevOOo/runner/stats/InternalLogWriter.java @@ -0,0 +1,101 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package stats; + +import java.io.PrintWriter; +import java.io.StringWriter; + +/** + * Write all logs into a java.io.PrintWriter, i.e. a StringBuffer. + * Log is gathered there. + */ +public class InternalLogWriter implements share.LogWriter { + /** log active **/ + private boolean active; + /** write all output to a StringBuffer **/ + private StringWriter writer = new StringWriter(); + private PrintWriter printWriter; + + /** + * c'*tor + */ + public InternalLogWriter() { + printWriter = new PrintWriter(writer); + active = true; + } + + /** + * Initialization. + * @param entry The description entry. + * @param active Logging is active. + * @return True, if initialize worked. + */ + public boolean initialize(share.DescEntry entry, boolean active) { + this.active = active; + return true; + } + + /** + * Method to print a line that is added to the StringBuffer. + * @param msg The message that is printed. + */ + public void println(String msg) { + if (active) + printWriter.println(msg); + } + + /** + * Is used to sum up the information. + * The summary is also added to the StringBuffer. + * @param entry The description entry. + * @return True, if a summary could be created. + */ + public boolean summary(share.DescEntry entry) { +// linePrefix = ""; + String header = "***** State for "+entry.longName+" ******"; + printWriter.println(header); + if (entry.hasErrorMsg) { + printWriter.println(entry.ErrorMsg); + printWriter.println("Whole "+entry.EntryType+": "+entry.State); + } else { + printWriter.println("Whole "+entry.EntryType+": "+entry.State); + } + for (int i=0;i + *
  • DataBaseOut - If set to true, a database outproducer is created. + *
  • OutProducer - The value of this parameter names the class that is created. + * + * @param param Parameters of the test. + * @return The created out producer. + */ + public static LogWriter createOutProducer(HashMap param) { + LogWriter dbOut = null; + boolean getDatabase = convertToBool(param.get("DataBaseOut")); + if (getDatabase) { + dbOut = createDataBaseOutProducer(param); + } + if (dbOut == null) { + DynamicClassLoader dcl = new DynamicClassLoader(); + String outProducerName = (String)param.get("OutProducer"); + if (outProducerName != null) { + try { + dbOut = (LogWriter)dcl.getInstance(outProducerName); + } + catch(IllegalArgumentException e) { + e.printStackTrace(); + } + } + } + if (dbOut == null) { + dbOut = createSimpleOutProducer(); + } + return dbOut; + } + + /** + * Create a database out producer. + * @param param The test parameters + * @return The database out producer, or null if it couldn't be created. + */ + private static LogWriter createDataBaseOutProducer(HashMap param) { + String dataProducerName = (String)param.get("DataBaseOutProducer"); + if (dataProducerName == null) { + String testBaseName = (String)param.get("TestBase"); + dataProducerName = testBaseName.substring(testBaseName.indexOf('_')+1); + dataProducerName = "stats." + makeFirstCharUpperCase(dataProducerName) + + "DataBaseOutProducer"; + } + DynamicClassLoader dcl = new DynamicClassLoader(); + LogWriter dbOut = null; + try { + dbOut = (LogWriter)dcl.getInstance(dataProducerName, + new Class[]{HashMap.class}, new Object[]{param}); + } + catch(IllegalArgumentException e) { + e.printStackTrace(); + } + return dbOut; + } + + /** + * As a fallback, create a simple out producer, if all else failed. + * @return A simple out producer, writing to the screen. + */ + private static LogWriter createSimpleOutProducer() { + return new SimpleOutProducer(); + } + + private static boolean convertToBool(Object val) { + if(val != null) { + if ( val instanceof String ) { + String sVal = (String)val; + if ( sVal.equalsIgnoreCase("true") || sVal.equalsIgnoreCase("yes") ) { + return true; + } + + } + else if (val instanceof Boolean) { + return ((Boolean)val).booleanValue(); + } + } + return false; + } + + /** + * Make the first character to an upper case char. + * @param name The String to change + * @return The String with an upper case first char. + */ + private static String makeFirstCharUpperCase(String name) { + return name.substring(0,1).toUpperCase() + name.substring(1); + } + +} diff --git a/qadevOOo/runner/stats/SimpleLogWriter.java b/qadevOOo/runner/stats/SimpleLogWriter.java new file mode 100644 index 000000000..46e18527b --- /dev/null +++ b/qadevOOo/runner/stats/SimpleLogWriter.java @@ -0,0 +1,94 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package stats; + +import share.LogWriter; + +import java.io.PrintWriter; +import java.text.DecimalFormat; +import java.util.Calendar; +import java.util.GregorianCalendar; + +public class SimpleLogWriter extends PrintWriter implements LogWriter { + + private boolean m_bLogging = false; + private share.DescEntry entry = null; + private share.Watcher ow = null; + + public SimpleLogWriter() { + super(System.out); + Calendar cal = new GregorianCalendar(); + DecimalFormat dfmt = new DecimalFormat("00"); + super.println("LOG> Log started " + + dfmt.format(cal.get(Calendar.DAY_OF_MONTH)) + "." + + dfmt.format(cal.get(Calendar.MONTH)) + "." + + dfmt.format(cal.get(Calendar.YEAR)) + " - " + + dfmt.format(cal.get(Calendar.HOUR_OF_DAY)) + ":" + + dfmt.format(cal.get(Calendar.MINUTE)) + ":" + + dfmt.format(cal.get(Calendar.SECOND))); + super.flush(); + } + + public boolean initialize(share.DescEntry _entry, boolean _bLogging) { + m_bLogging = _bLogging; + entry = _entry; + + return true; + } + + @Override + public void println(String msg) { + if ((ow == null) && (entry != null)) + { + this.ow = (share.Watcher) entry.UserDefinedParams.get("Watcher"); + if (this.ow != null) + { + this.ow.ping(); + } + } + else + { + if (ow != null) + { + this.ow.ping(); + } + else + { + // special case: ow == null && entry == null + System.out.println(msg); + } + } + + if (m_bLogging) { + super.println("LOG> " + msg); + super.flush(); + } + } + + public boolean summary(share.DescEntry entry) { + return true; + } + + public void setWatcher(Object watcher) + { + if (watcher != null) + { + entry.UserDefinedParams.put("Watcher", watcher); + } + } +} diff --git a/qadevOOo/runner/stats/SimpleOutProducer.java b/qadevOOo/runner/stats/SimpleOutProducer.java new file mode 100644 index 000000000..93ca0503c --- /dev/null +++ b/qadevOOo/runner/stats/SimpleOutProducer.java @@ -0,0 +1,61 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package stats; + +import share.LogWriter; + +public class SimpleOutProducer implements LogWriter { + + + /** initialization, here a filename might be given + * or a dbUrL + */ + public boolean initialize(share.DescEntry entry, boolean active) { + return true; + } + + /** Method to print + */ + public void println(String msg) { + + } + + /** will mostly be used by outproducers to sum up + * the information, maybe write them to a db + */ + public boolean summary(share.DescEntry entry) { + String header = "***** State for "+entry.longName+" ******"; + System.out.println(header); + if (entry.hasErrorMsg) { + System.out.println(entry.ErrorMsg); + System.out.println("Whole "+entry.EntryType+": "+entry.State); + } else { + System.out.println("Whole "+entry.EntryType+": "+entry.State); + } + for (int i=0;i failures = new ArrayList(); + ArrayList states = new ArrayList(); + for (int i = 0; i < count; i++) + { + if (entry.SubEntries[i].State == null) + { + entry.SubEntries[i].State = "COMPLETED.FAILED"; + } + if (entry.SubEntries[i].State.equals("known issue")) + { + entry.SubEntries[i].State = "COMPLETED.OK"; + knownIssues++; + } + if (!entry.SubEntries[i].State.endsWith("OK")) + { + String sFailure = "[" + entry.SubEntries[i].longName + "]" + " is testcode: [" + entry.SubEntries[i].entryName + "]"; + failures.add(sFailure); + states.add(entry.SubEntries[i].State); + } + } + if (failures.size() > 0) + { + StringBuilder errMsg = new StringBuilder(); + String state = "COMPLETED.FAILED"; + for (int j = 0; j < failures.size(); j++) + { + if (states.get(j).equals("not part of the job")) + { + state = "COMPLETED(some interfaces/services not tested).OK"; + } + else + { + errMsg.append(failures.get(j)).append(" - ").append(states.get(j)).append("\r\n"); + } + } + entry.hasErrorMsg = true; + entry.ErrorMsg = errMsg.toString(); + entry.State = state; + } + else if (entry.EntryType.equals("component") && knownIssues > 0) + { + entry.State = "COMPLETED(with known issues).OK"; + } + else + { + entry.State = "COMPLETED.OK"; + } + } + + public static void summarizeDown(DescEntry entry, String state) + { + if ((entry.State == null) || entry.State.equals("UNKNOWN")) + { + entry.State = state; + } + for (int i = 0; i < entry.SubEntryCount; i++) + { + summarizeDown(entry.SubEntries[i], entry.State); + } + } +} -- cgit v1.2.3