Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
}

Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down