diff --git a/src/test/JDJSTPTestcase.java b/src/test/JDJSTPTestcase.java index fef36c4..d3818b6 100644 --- a/src/test/JDJSTPTestcase.java +++ b/src/test/JDJSTPTestcase.java @@ -35,7 +35,6 @@ import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.sql.CallableStatement; import java.sql.Connection; diff --git a/src/test/JDRunit.java b/src/test/JDRunit.java index 1727145..1c83ff0 100644 --- a/src/test/JDRunit.java +++ b/src/test/JDRunit.java @@ -2267,7 +2267,7 @@ public JDRunitGoOutput go() throws Exception { if (JTOpenTestEnvironment.isWindows && (vmInitials.endsWith("3") || vmInitials.endsWith("6"))) { runNativeTestFromWindows = true; testcaseHome="/home/jdbctest"; - testcaseClasspath="/home/jdbctest"; + testcaseClasspath="/home/jdbctest:/home/jdbctest/JTOpen-test.jar"; } diff --git a/src/test/JTOpenDownloadDevJars.java b/src/test/JTOpenDownloadDevJars.java index 8cab841..929d921 100644 --- a/src/test/JTOpenDownloadDevJars.java +++ b/src/test/JTOpenDownloadDevJars.java @@ -11,18 +11,6 @@ // /////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// -// JTOpen (IBM Toolbox for Java - OSS version) -// -// Filename: JTOpenDownloadDevJars -// -// The source code contained herein is licensed under the IBM Public License -// Version 1.0, which has been approved by the Open Source Initiative. -// Copyright (C) 1997-2023 International Business Machines Corporation and -// others. All rights reserved. -// -/////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// // // File Name: JTOpenDownloadDevJars.java @@ -34,6 +22,8 @@ // This class is designed to run on an IBM i and download the latest development // toolbox jar files from git and install them on the system. // +// This tool requires a GITHUB token to be set in ini/netrc.ini to prevent problems with rate limiting. +// // // This can be automated using the following. // ADDJOBSCDE JOB(JDUPDJAR) CMD(JAVA CLASS(test.JTOpenDownloadDevJars) CLASSPATH('/home/jdbctest')) FRQ(*WEEKLY) SCDDATE(*NONE) SCDDAY(*ALL) SCDTIME('19:00') @@ -147,11 +137,21 @@ public static void main(String args[]) { // run the query to show the possible URLS. String sql; Statement stmt = connection.createStatement(); + Properties iniProperties = getIniProperties(); + githubAuth=iniProperties.getProperty("GITHUBTOKEN"); + if (githubAuth == null) { + stmt.close(); + connection.close(); + throw new Exception("Unable to get GITHUBTOKEN from ini/netrc.ini"); + } + System.out.println("Authorization set to "+githubAuth); + sql = "SELECT URL," + "TIMESTAMP( SUBSTRING(UPDATED_AT,1,10) || ' ' || SUBSTRING(UPDATED_AT,12,8)) + CURRENT TIMEZONE AS UPDATED , " + "CURRENT TIMEZONE as CURRENT_TIMEZONE, " + " NAME, BRANCH" - + " FROM JSON_TABLE( HTTP_GET('"+artifactsUrl+"','{\"headers\":{\"Accept\":\"application/vnd.github+json\"}, \"sslTolerate\":true}'), '$.artifacts[*]' " + + " FROM JSON_TABLE( HTTP_GET('"+artifactsUrl+"','{\"headers\":{\"Accept\":\"application/vnd.github+json\"" + + ",\"authorization\":\""+githubAuth+"\"}, \"sslTolerate\":true}'), '$.artifacts[*]' " + "COLUMNS ( " + "URL VARCHAR(200) CCSID 1208 PATH '$.url', " + "UPDATED_AT VARCHAR(40) PATH '$.updated_at', " @@ -172,7 +172,7 @@ public static void main(String args[]) { } if (branch == null) { sql = "SELECT * FROM JSON_TABLE( HTTP_GET('"+artifactsUrl+"'," - + "'{\"headers\":{\"Accept\":\"application/vnd.github+json\"}, \"sslTolerate\":true}'), " + + "'{\"headers\":{\"Accept\":\"application/vnd.github+json\",\"authorization\":\""+githubAuth+"\"}, \"sslTolerate\":true}'), " + "'$.artifacts[*]' " + "COLUMNS ( " + "URL VARCHAR(200) CCSID 1208 PATH '$.url', " @@ -180,12 +180,12 @@ public static void main(String args[]) { + "NAME VARCHAR(40) PATH '$.name'," + "BRANCH VARCHAR(120) PATH '$.workflow_run.head_branch' )) WHERE BRANCH='main' AND NAME='Package' ORDER BY UPDATED_AT desc FETCH FIRST 1 ROWS ONLY"; } else if ("ANY".equalsIgnoreCase(branch)) { - sql = "SELECT * FROM JSON_TABLE( HTTP_GET('"+artifactsUrl+"','{\"headers\":{\"Accept\":\"application/vnd.github+json\"}, \"sslTolerate\":true}'), '$.artifacts[*]' " + sql = "SELECT * FROM JSON_TABLE( HTTP_GET('"+artifactsUrl+"','{\"headers\":{\"Accept\":\"application/vnd.github+json\",\"authorization\":\""+githubAuth+"\"}, \"sslTolerate\":true}'), '$.artifacts[*]' " + "COLUMNS ( URL VARCHAR(200) CCSID 1208 PATH '$.url', UPDATED_AT VARCHAR(40) PATH '$.updated_at', " + "NAME VARCHAR(40) PATH '$.name'," + "BRANCH VARCHAR(120) PATH '$.workflow_run.head_branch' )) WHERE NAME='Package' ORDER BY UPDATED_AT desc FETCH FIRST 1 ROWS ONLY"; } else { - sql = "SELECT * FROM JSON_TABLE( HTTP_GET('"+artifactsUrl+"','{\"headers\":{\"Accept\":\"application/vnd.github+json\"}, \"sslTolerate\":true}'), '$.artifacts[*]' " + sql = "SELECT * FROM JSON_TABLE( HTTP_GET('"+artifactsUrl+"','{\"headers\":{\"Accept\":\"application/vnd.github+json\",\"authorization\":\""+githubAuth+"\"}, \"sslTolerate\":true}'), '$.artifacts[*]' " + "COLUMNS ( URL VARCHAR(200) CCSID 1208 PATH '$.url', UPDATED_AT VARCHAR(40) PATH '$.updated_at', " + "NAME VARCHAR(40) PATH '$.name'," + "BRANCH VARCHAR(120) PATH '$.workflow_run.head_branch' )) WHERE NAME='Package' and BRANCH='"+branch+"' ORDER BY UPDATED_AT desc FETCH FIRST 1 ROWS ONLY"; @@ -236,7 +236,7 @@ public static void main(String args[]) { // // Repeat for the test jar files // - sql = "SELECT * FROM JSON_TABLE( HTTP_GET('"+artifactsTestUrl+"','{\"headers\":{\"Accept\":\"application/vnd.github+json\"}, \"sslTolerate\":true}'), '$.artifacts[*]' COLUMNS ( URL VARCHAR(200) CCSID 1208 PATH '$.url', UPDATED_AT VARCHAR(40) PATH '$.updated_at', BRANCH VARCHAR(40) PATH '$.workflow_run.head_branch' )) WHERE BRANCH='main' ORDER BY UPDATED_AT desc FETCH FIRST 1 ROWS ONLY"; + sql = "SELECT * FROM JSON_TABLE( HTTP_GET('"+artifactsTestUrl+"','{\"headers\":{\"Accept\":\"application/vnd.github+json\",\"authorization\":\""+githubAuth+"\"}, \"sslTolerate\":true}'), '$.artifacts[*]' COLUMNS ( URL VARCHAR(200) CCSID 1208 PATH '$.url', UPDATED_AT VARCHAR(40) PATH '$.updated_at', BRANCH VARCHAR(40) PATH '$.workflow_run.head_branch' )) WHERE BRANCH='main' ORDER BY UPDATED_AT desc FETCH FIRST 1 ROWS ONLY"; stmt = connection.createStatement(); System.out.println("Running to get latest artifact: "+sql); rs = stmt.executeQuery(sql); @@ -361,6 +361,23 @@ private static void unzip(String zipFile, String targetDir) throws IOException { } + public static Properties getIniProperties() throws Exception { + /* Github requires authorization to download a non-release artifacte */ + Properties iniProperties = new Properties(); + + { + String filename = "ini/netrc.ini"; + File file = new File(filename); + if (!file.exists()) { + throw new Exception("Unable to load ini/netrc.ini to get GITHUB token"); + } + InputStream fileInputStream= new FileInputStream(filename); + iniProperties.load(fileInputStream); + fileInputStream.close(); + } + + return iniProperties; + } public static void fetchFile(String destinationDirectory, String fileName, @@ -371,19 +388,8 @@ public static void fetchFile(String destinationDirectory, URL url = new URL(urlPath); URLConnection connection = url.openConnection(); - /* Github requires authorization to download a non-release artifacte */ - Properties iniProperties = new Properties(); - - { - String filename = "ini/netrc.ini"; - File file = new File(filename); - if (!file.exists()) { - throw new Exception("Unable to load ini/netrc.ini to get GITHUB token"); - } - InputStream fileInputStream= new FileInputStream(filename); - iniProperties.load(fileInputStream); - fileInputStream.close(); - } + Properties iniProperties = getIniProperties(); + githubAuth=iniProperties.getProperty("GITHUBTOKEN"); if (githubAuth == null) { throw new Exception("Unable to get GITHUBTOKEN from ini/netrc.ini");