Skip to content

Commit

Permalink
[NSE-778] Failed to find include file while running code gen (oap-pro…
Browse files Browse the repository at this point in the history
…ject#779)

* fix can not find include file

* add maven test content back
  • Loading branch information
jackylee-ch authored and zhouyuan committed Mar 30, 2022
1 parent 1b42014 commit 039d751
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,24 @@ private static void loadIncludeFromJar(String tmp_dir) throws IOException, Illeg
tmp_dir = System.getProperty("java.io.tmpdir");
}
final String folderToLoad = "include";
final URLConnection urlConnection = JniUtils.class.getClassLoader().getResource("include").openConnection();
if (urlConnection instanceof JarURLConnection) {
final JarFile jarFile = ((JarURLConnection) urlConnection).getJarFile();
extractResourcesToDirectory(jarFile, folderToLoad, tmp_dir + "/" + "nativesql_include");
// only find all include file in the jar that contains JniUtils.class
final String jarPath =
JniUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath();
if (jarPath.endsWith(".jar")) {
extractResourcesToDirectory(
new JarFile(new File(jarPath)), folderToLoad, tmp_dir + "/" + "nativesql_include");
} else {
// For Maven test only
final URLConnection urlConnection =
JniUtils.class.getClassLoader().getResource("include").openConnection();
String path = urlConnection.getURL().toString();
if (urlConnection.getURL().toString().startsWith("file:")) {
// remove the prefix of "file:" from includePath
path = urlConnection.getURL().toString().substring(5);
}
final File folder = new File(path);
copyResourcesToDirectory(urlConnection,
tmp_dir + "/" + "nativesql_include", folder);
tmp_dir + "/" + "nativesql_include", folder);
}
}
}
Expand Down

0 comments on commit 039d751

Please sign in to comment.