21
21
package com .dtstack .flink .sql .util ;
22
22
23
23
import com .dtstack .flink .sql .classloader .DtClassLoader ;
24
+ import org .apache .commons .lang3 .StringUtils ;
24
25
import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .core .JsonGenerationException ;
25
26
import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .core .JsonParseException ;
26
27
import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .databind .JsonMappingException ;
27
28
import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .databind .ObjectMapper ;
28
29
29
30
import java .io .ByteArrayInputStream ;
30
31
import java .io .File ;
32
+ import java .io .FilenameFilter ;
31
33
import java .io .IOException ;
32
34
import java .net .MalformedURLException ;
33
35
import java .net .URL ;
@@ -105,15 +107,19 @@ public static Properties stringToProperties(String str) throws IOException{
105
107
return properties ;
106
108
}
107
109
108
- public static URL getRemoteJarFilePath (String pluginType , String tableType , String remoteSqlRootDir ) throws MalformedURLException {
110
+ public static URL getRemoteJarFilePath (String pluginType , String tableType , String remoteSqlRootDir ) throws Exception {
109
111
String dirName = pluginType + tableType .toLowerCase ();
110
- String jarName = String .format ("%s-%s.jar" , pluginType , tableType .toLowerCase ());
112
+ String prefix = String .format ("%s-%s" , pluginType , tableType .toLowerCase ());
113
+ String jarPath = remoteSqlRootDir + SP + dirName ;
114
+ String jarName = getCoreJarFileName (jarPath , prefix );
111
115
return new URL ("file:" + remoteSqlRootDir + SP + dirName + SP + jarName );
112
116
}
113
117
114
- public static URL getRemoteSideJarFilePath (String pluginType , String sideOperator , String tableType , String remoteSqlRootDir ) throws MalformedURLException {
118
+ public static URL getRemoteSideJarFilePath (String pluginType , String sideOperator , String tableType , String remoteSqlRootDir ) throws Exception {
115
119
String dirName = pluginType + sideOperator + tableType .toLowerCase ();
116
- String jarName = String .format ("%s-%s-%s.jar" , pluginType , sideOperator , tableType .toLowerCase ());
120
+ String prefix = String .format ("%s-%s-%s" , pluginType , sideOperator , tableType .toLowerCase ());
121
+ String jarPath = remoteSqlRootDir + SP + dirName ;
122
+ String jarName = getCoreJarFileName (jarPath , prefix );
117
123
return new URL ("file:" + remoteSqlRootDir + SP + dirName + SP + jarName );
118
124
}
119
125
@@ -138,4 +144,27 @@ public static void addPluginJar(String pluginDir, DtClassLoader classLoader) thr
138
144
}
139
145
}
140
146
147
+ public static String getCoreJarFileName (String path , String prefix ) throws Exception {
148
+ String coreJarFileName = null ;
149
+ File pluginDir = new File (path );
150
+ if (pluginDir .exists () && pluginDir .isDirectory ()){
151
+ File [] jarFiles = pluginDir .listFiles (new FilenameFilter () {
152
+ @ Override
153
+ public boolean accept (File dir , String name ) {
154
+ return name .toLowerCase ().startsWith (prefix ) && name .toLowerCase ().endsWith (".jar" );
155
+ }
156
+ });
157
+
158
+ if (jarFiles != null && jarFiles .length > 0 ){
159
+ coreJarFileName = jarFiles [0 ].getName ();
160
+ }
161
+ }
162
+
163
+ if (StringUtils .isEmpty (coreJarFileName )){
164
+ throw new Exception ("Can not find core jar file in path:" + path );
165
+ }
166
+
167
+ return coreJarFileName ;
168
+ }
169
+
141
170
}
0 commit comments