Skip to content

Optimize jar discovery #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package com.amazonaws.services.lambda.runtime.api.client;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -18,6 +19,18 @@ class CustomerClassLoader extends URLClassLoader {
* does not depend on the underlying filesystem.
*/
private final static Comparator<String> LEXICAL_SORT_ORDER = Comparator.comparing(String::toString);
private final static FilenameFilter JAR_FILE_NAME_FILTER = new FilenameFilter() {

@Override
public boolean accept(File dir, String name) {
int offset = name.length() - 4;
if (offset <= 0) { /* must be at least A.jar */
return false;
} else {
return name.startsWith(".jar", offset);
}
}
};

CustomerClassLoader(String taskRoot, String optRoot, ClassLoader parent) throws IOException {
super(getUrls(taskRoot, optRoot), parent);
Expand All @@ -36,15 +49,14 @@ private static void appendJars(File dir, List<URL> result) throws MalformedURLEx
if (!dir.isDirectory()) {
return;
}
String[] names = dir.list();
String[] names = dir.list(CustomerClassLoader.JAR_FILE_NAME_FILTER);
if (names == null) {
return;
}
Arrays.sort(names, CustomerClassLoader.LEXICAL_SORT_ORDER);
for(String path : names) {
if(path.endsWith(".jar")) {
result.add(newURL(dir, path));
}

for (String path : names) {
result.add(newURL(dir, path));
}
}

Expand Down