diff --git a/src/test/JDJSTPTestcase.java b/src/test/JDJSTPTestcase.java index 2cb769c..5f8a7e7 100644 --- a/src/test/JDJSTPTestcase.java +++ b/src/test/JDJSTPTestcase.java @@ -1256,6 +1256,7 @@ public static void link(String javaSource, String javacOptions, int javaVersion1 // Check to see if the file needs to be recompiled // String sourceFile = sourcepath+"/"+javaSource; + refreshLocalFile(sourceFile); String destFile = nativeBaseDir+"/"+sourcepath+"/"+javaSource; String destClasses = nativeBaseDir+"/"+sourcepath+"/"+ javaSource.substring(0, javaSource.lastIndexOf(".java")) + "*.class"; String serverPf = genPfName(javaSource); @@ -1343,6 +1344,7 @@ public static void link(String javaSource, String javacOptions, int javaVersion1 // Check to see if the file needs to be recompiled // String sourceFile = sourcepath + "/" + javaSource; + refreshLocalFile(sourceFile); String destFile; if (usePase) { destFile = "/QOpenSys" + nativeBaseDir + "/" + sourcepath + "/" + javaSource; @@ -1407,6 +1409,7 @@ public static void link(String javaSource, String javacOptions, int javaVersion1 // Check to see if the file needs to be recompiled // String sourceFile = sourcepath+"/"+javaSource; + refreshLocalFile(sourceFile); String destFile = nativeBaseDir+"/"+sourcepath+"/"+javaSource; if (usePase) { destFile = "/QOpenSys/"+nativeBaseDir+"/"+sourcepath+"/"+javaSource; @@ -1575,6 +1578,7 @@ public static void link(String javaSource, String javacOptions, int javaVersion1 String upperBase = base.toUpperCase(); String sourceFile = sourcepath+"/"+javaSource; + refreshLocalFile(sourceFile); String destFile = nativeBaseDir+"/"+sourcepath+"/"+javaSource; String serverPf = upperBase; String command = ""; @@ -1645,6 +1649,7 @@ public static void link(String javaSource, String javacOptions, int javaVersion1 // load the file on the system // String sourceFile = sourcepath+"/"+javaSource; + refreshLocalFile(sourceFile); String destFile = nativeBaseDir+"/"+sourcepath+"/"+javaSource; String serverPf = upperBase; try { @@ -1679,6 +1684,8 @@ public static void crtsrvpgm(String library1, String srvpgm, String source) thro String destFile = nativeBaseDir + "/" + sourcepath + "/" + source; String serverPf = genPfName(source); + refreshLocalFile(sourceFile); + boolean updated = updateServerFile(sourceFile, serverPf, destFile, destFile); if (!updated) { if (debug) @@ -1705,6 +1712,7 @@ public static void crtsrvpgmCPP(String library1, String srvpgm, String source) t // transfer the file up String sourceFile = sourcepath + "/" + source; + refreshLocalFile(sourceFile); String destFile = nativeBaseDir + "/" + sourcepath + "/" + source; String serverPf = genPfName(source); @@ -1759,6 +1767,7 @@ public static void linkClient(String javaSource, String javacOptions) throws Exc // Check to see if the file needs to be recompiled // File sourceFile = new File( sourcepath+"/"+javaSource); + refreshLocalFile( sourcepath+"/"+javaSource); File newSourceFile = new File (javaRunPath+"/"+javaSource); File destFile = new File( javaRunPath+"/"+classFilename); if (destFile.exists()) { @@ -1905,6 +1914,7 @@ public static void linkClient(String javaSource, String javacOptions) throws Exc rs.close(); File sourceFile = new File( sourcepath+"/"+javaSource); + refreshLocalFile(sourcepath+"/"+javaSource); File newSourceFile = new File (javaRunPath+"/"+javaSource); File destFile = new File( javaRunPath+"/"+classFilename); if (destFile.exists()) { @@ -2106,6 +2116,7 @@ public static void linkSqlj(String sqljSource) throws Exception { // String base = sqljSource.substring(0, sqljSource.lastIndexOf(".sqlj")); String sourceFile = sourcepath+"/"+sqljSource; + refreshLocalFile(sourceFile); String serverFile = nativeBaseDir+"/"+base+".sqlj"; String destFile = nativeBaseDir+"/"+base+".class"; String javaFile = nativeBaseDir+"/"+base+".java"; @@ -2633,6 +2644,44 @@ public boolean updateBinaryServerFile(String localFile, String serverFile) thro } + public static void refreshLocalFile(String localFile) throws Exception { + // + // Determine if the local file needs to be extracted from the classpath + // + // Get the URL of the resource inside the JAR file + URL url = JDJSTPTestcase.class.getResource(localFile); + File file = new File(localFile); + long currentTime = file.lastModified(); + long lastJarModifiedMs = 0; + if (url != null) { + // If url indicates a jar file, when we will copy to local filesystem + if (url.getProtocol().equals("jar")) { + URLConnection connection = url.openConnection(); + lastJarModifiedMs = connection.getLastModified(); + } + } else { + System.out.println("Resource not found."); + } + if (lastJarModifiedMs > currentTime) { + int lastSlashIndex = localFile.lastIndexOf('/'); + if (lastSlashIndex > 0) { + String directory = localFile.substring(0,lastSlashIndex); + File directoryFile = new File(directory); + if (!directoryFile.exists()) { + directoryFile.mkdirs(); + } + } + + InputStream is = url.openStream(); + FileSystem fsDefault = FileSystems.getDefault(); + Files.copy(is, fsDefault.getPath(localFile), StandardCopyOption.REPLACE_EXISTING); + fsDefault.close(); + is.close(); + currentTime = file.lastModified(); + } + + + } /** * Assures that a file on the server is up to date. @@ -2683,7 +2732,6 @@ public static boolean updateServerFile(String localFile, String serverPf, String // // Determine if server file needs to be updated // - if (currentTime == 0L) { throw new Exception("File "+localFile+" not found"); } @@ -6289,9 +6337,11 @@ public static void RasUser(String testpgm, String userId, char[] encryptedPasswo // if (testext.equals("clp")) { command = sourcepath+"/"+testpgm; + refreshLocalFile(command); JDSQL400.run(command, output, userId, PasswordVault.decryptPasswordLeak(encryptedPassword, "JDJSTPTestcase.rau.1") ); } else if (testext.equals("jdbc")) { command = sourcepath+"/"+testpgm; + refreshLocalFile(command); runJdbcClient(command, output, userId, encryptedPassword); } else { throw new Exception("Cannot run test "+testpgm+". Extension "+testext+" not recognized");