Skip to content

Commit

Permalink
modest perf improv for launching tests (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
plaird authored Jan 5, 2022
1 parent 9baa902 commit d7c8457
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.salesforce.bazel.eclipse.classpath.IClasspathContainerConstants;
import com.salesforce.bazel.eclipse.component.ComponentContext;
import com.salesforce.bazel.eclipse.component.EclipseBazelWorkspaceContext;
import com.salesforce.bazel.eclipse.launch.BazelTestClasspathProvider;
import com.salesforce.bazel.eclipse.project.EclipseProjectUtils;
import com.salesforce.bazel.eclipse.projectimport.ProjectImporterFactory;
import com.salesforce.bazel.eclipse.runtime.api.JavaCoreHelper;
Expand Down Expand Up @@ -191,8 +192,10 @@ protected void clean(IProgressMonitor monitor) throws CoreException {
// bazelWorkspaceCmdRunner.runBazelClean(null);
}

// TODO implement a clean() listener and let impls register with us, instead of hacking like this
BazelClasspathContainer.clean();
BazelGlobalSearchClasspathContainer.clean();
BazelTestClasspathProvider.clean();
}

private boolean buildProjects(BazelWorkspaceCommandRunner cmdRunner, Collection<IProject> projects,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -86,6 +89,9 @@ public class BazelTestClasspathProvider extends StandardClasspathProvider {

// collaborator for retrieving/analyzing Bazel test param files
BazelJvmTestClasspathHelper bazelJvmTestClasspathHelper = new BazelJvmTestClasspathHelper();

// entry cache
private static Map<String, IRuntimeClasspathEntry[]> resolvedEntriesCache = new HashMap<>();

/**
* Compute classpath entries for test
Expand All @@ -104,12 +110,28 @@ public IRuntimeClasspathEntry[] resolveClasspath(IRuntimeClasspathEntry[] entrie
ILaunchConfiguration configuration) throws CoreException {
List<IRuntimeClasspathEntry> result = new ArrayList<>();

Set<String> addedPaths = new HashSet<>();
for (IRuntimeClasspathEntry entry : entries) {
IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveRuntimeClasspathEntry(entry, configuration);
String path = entry.getClasspathEntry().getPath().toString();

// de-dupe the list
if (addedPaths.contains(path)) {
continue;
}
addedPaths.add(path);

// now check the cache, this will prevent work being redone across invocations of this method
IRuntimeClasspathEntry[] resolved = resolvedEntriesCache.get(path);
if (resolved == null) {
resolved = JavaRuntime.resolveRuntimeClasspathEntry(entry, configuration);
resolvedEntriesCache.put(path, resolved);
}
Collections.addAll(result, resolved);
}

Collections.addAll(result, JavaRuntime.resolveSourceLookupPath(entries, configuration));
// the Bazel param file lists --sources so entries[] should already contain the source paths
// this call is left here for future reference in case a situation is found where it is needed BEF #381
//Collections.addAll(result, JavaRuntime.resolveSourceLookupPath(entries, configuration));

IRuntimeClasspathEntry[] resolvedClasspath = result.toArray(new IRuntimeClasspathEntry[result.size()]);
LOG.info("Test classpath: {}", (Object[]) resolvedClasspath);
Expand Down Expand Up @@ -206,6 +228,13 @@ public static void enable(ILaunchConfiguration config) throws CoreException {
}
}

/**
* Clean caches.
*/
public static void clean() {
resolvedEntriesCache.clear();
}

private void showUnrunnableErrorDialog(StringBuffer unrunnableLabelsString) {
Display.getDefault().asyncExec(new Runnable() {
@Override
Expand Down

0 comments on commit d7c8457

Please sign in to comment.