Skip to content

Commit c6c90b8

Browse files
[hotfix][clients] Refactor PackagedProgram#getJobJarAndDependencies to reduce some redundant lines. (#26238)
Co-authored-by: Rui Fan <[email protected]>
1 parent a5d4194 commit c6c90b8

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java

+8-21
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,12 @@ public ClassLoader getUserCodeClassLoader() {
246246

247247
/** Returns all provided libraries needed to run the program. */
248248
public List<URL> getJobJarAndDependencies() {
249-
List<URL> libs = new ArrayList<URL>(extractedTempLibraries.size() + 1);
249+
return getJobJarAndDependencies(jarFile, extractedTempLibraries, isPython);
250+
}
251+
252+
private static List<URL> getJobJarAndDependencies(
253+
URL jarFile, List<File> extractedTempLibraries, boolean isPython) {
254+
List<URL> libs = new ArrayList<>(extractedTempLibraries.size() + 2);
250255

251256
if (jarFile != null) {
252257
libs.add(jarFile);
@@ -258,11 +263,9 @@ public List<URL> getJobJarAndDependencies() {
258263
throw new RuntimeException("URL is invalid. This should not happen.", e);
259264
}
260265
}
261-
262266
if (isPython) {
263267
libs.add(PackagedProgramUtils.getPythonJar());
264268
}
265-
266269
return libs;
267270
}
268271

@@ -276,24 +279,8 @@ public static List<URL> getJobJarAndDependencies(
276279
? Collections.emptyList()
277280
: extractContainedLibraries(jarFileUrl);
278281

279-
List<URL> libs = new ArrayList<URL>(extractedTempLibraries.size() + 1);
280-
281-
if (jarFileUrl != null) {
282-
libs.add(jarFileUrl);
283-
}
284-
for (File tmpLib : extractedTempLibraries) {
285-
try {
286-
libs.add(tmpLib.getAbsoluteFile().toURI().toURL());
287-
} catch (MalformedURLException e) {
288-
throw new RuntimeException("URL is invalid. This should not happen.", e);
289-
}
290-
}
291-
292-
if (isPython(entryPointClassName)) {
293-
libs.add(PackagedProgramUtils.getPythonJar());
294-
}
295-
296-
return libs;
282+
return getJobJarAndDependencies(
283+
jarFileUrl, extractedTempLibraries, isPython(entryPointClassName));
297284
}
298285

299286
/** Deletes all temporary files created for contained packaged libraries. */

0 commit comments

Comments
 (0)