2121package com .dtstack .flink .sql .util ;
2222
2323import com .dtstack .flink .sql .classloader .DtClassLoader ;
24+ import org .apache .commons .lang3 .StringUtils ;
2425import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .core .JsonGenerationException ;
2526import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .core .JsonParseException ;
2627import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .databind .JsonMappingException ;
2728import org .apache .flink .shaded .jackson2 .com .fasterxml .jackson .databind .ObjectMapper ;
2829
2930import java .io .ByteArrayInputStream ;
3031import java .io .File ;
32+ import java .io .FilenameFilter ;
3133import java .io .IOException ;
3234import java .net .MalformedURLException ;
3335import java .net .URL ;
@@ -105,15 +107,19 @@ public static Properties stringToProperties(String str) throws IOException{
105107 return properties ;
106108 }
107109
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 {
109111 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 );
111115 return new URL ("file:" + remoteSqlRootDir + SP + dirName + SP + jarName );
112116 }
113117
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 {
115119 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 );
117123 return new URL ("file:" + remoteSqlRootDir + SP + dirName + SP + jarName );
118124 }
119125
@@ -138,4 +144,27 @@ public static void addPluginJar(String pluginDir, DtClassLoader classLoader) thr
138144 }
139145 }
140146
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+
141170}
0 commit comments