diff --git a/src/main/java/com/smartbear/jenkins/plugins/testcomplete/Utils.java b/src/main/java/com/smartbear/jenkins/plugins/testcomplete/Utils.java index a8ebe36..d0c9be5 100644 --- a/src/main/java/com/smartbear/jenkins/plugins/testcomplete/Utils.java +++ b/src/main/java/com/smartbear/jenkins/plugins/testcomplete/Utils.java @@ -33,6 +33,8 @@ import org.jenkinsci.remoting.RoleChecker; import javax.crypto.Cipher; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; import java.lang.ref.WeakReference; import java.security.Key; import java.security.KeyFactory; @@ -53,6 +55,16 @@ public class Utils { private static final int ENC_CHUNK_MAX_SIZE = 116; + private static final DatatypeFactory XML_DATATYPE_FACTORY = createXmlDatatypeFactory(); + + private static DatatypeFactory createXmlDatatypeFactory() { + try { + return DatatypeFactory.newInstance(); + } catch (DatatypeConfigurationException e) { + throw new IllegalStateException("Failed to obtain a DatatypeFactory instance for XML date/time conversion", e); + } + } + private Utils() { } @@ -178,6 +190,13 @@ private static long OLEDateToMillis(double dSerialDate) return (long) ((dSerialDate - 25569) * 24 * 3600 * 1000); } + public static String printDateTime(Calendar cal) { + GregorianCalendar gc = new GregorianCalendar(); + gc.setTimeZone(cal.getTimeZone()); + gc.setTimeInMillis(cal.getTimeInMillis()); + return XML_DATATYPE_FACTORY.newXMLGregorianCalendar(gc).toXMLFormat(); + } + static String encryptPassword(String password) throws Exception { byte[] keyRawData = Base64.getDecoder().decode(PUBLIC_KEY); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); diff --git a/src/main/java/com/smartbear/jenkins/plugins/testcomplete/parser/LogNodeUtils.java b/src/main/java/com/smartbear/jenkins/plugins/testcomplete/parser/LogNodeUtils.java index ba93a2a..5e2151b 100644 --- a/src/main/java/com/smartbear/jenkins/plugins/testcomplete/parser/LogNodeUtils.java +++ b/src/main/java/com/smartbear/jenkins/plugins/testcomplete/parser/LogNodeUtils.java @@ -28,7 +28,6 @@ import org.w3c.dom.*; import org.xml.sax.SAXException; -import javax.xml.bind.DatatypeConverter; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -422,7 +421,7 @@ static public String startTimeToTimestamp(String startTime) { long startDate = Utils.safeConvertDate(startTime); Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(startDate); - return DatatypeConverter.printDateTime(cal); + return Utils.printDateTime(cal); } } diff --git a/src/main/java/com/smartbear/jenkins/plugins/testcomplete/parser/LogParser.java b/src/main/java/com/smartbear/jenkins/plugins/testcomplete/parser/LogParser.java index a712cbc..6b48015 100644 --- a/src/main/java/com/smartbear/jenkins/plugins/testcomplete/parser/LogParser.java +++ b/src/main/java/com/smartbear/jenkins/plugins/testcomplete/parser/LogParser.java @@ -32,7 +32,6 @@ import org.apache.commons.lang.StringUtils; import org.w3c.dom.*; -import javax.xml.bind.DatatypeConverter; import javax.xml.stream.*; import java.io.IOException; @@ -283,7 +282,7 @@ private void processProject(ZipFile logArchive, Node rootOwnerNode, Node rootOwn String projectName = LogNodeUtils.getTextProperty(rootOwnerNodeInfoSummary, "test"); Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(startDate); - String timestamp = DatatypeConverter.printDateTime(cal); + String timestamp = Utils.printDateTime(cal); String rootOwnerNodeFileName = LogNodeUtils.getTextProperty(rootOwnerNode, "filename"); if (rootOwnerNodeFileName == null || rootOwnerNodeFileName.isEmpty()) {