forked from salesforce/bazel-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 3
Fix unit test execution error issue #47
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
Open
runchen0919
wants to merge
2
commits into
eclipseguru:main
Choose a base branch
from
runchen0919:issue-46
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,6 +243,18 @@ private boolean populateWithSavedContainer(IJavaProject project, ContainerResolu | |
| case IClasspathEntry.CPE_PROJECT: { | ||
| // projects need to be resolved properly so we have all the output folders and exported jars on the classpath | ||
| var sourceProject = workspaceRoot.getProject(e.getPath().segment(0)); | ||
|
|
||
| // Check for cycles BEFORE calling beginResolvingProject to avoid depth counter issues | ||
| if (resolutionContext.processedProjects.contains(sourceProject)) { | ||
| if (LOG.isDebugEnabled()) { | ||
| LOG.debug( | ||
| "Skipping already processed project '{}' in thread '{}' to avoid cycle", | ||
| sourceProject.getName(), | ||
| Thread.currentThread().getName()); | ||
| } | ||
| break; | ||
| } | ||
|
|
||
| if (resolutionContext.beginResolvingProjectIfNeverProcessedBefore(sourceProject)) { | ||
| try { | ||
| // only resolve and add the projects if it was never attempted before | ||
|
|
@@ -252,10 +264,9 @@ private boolean populateWithSavedContainer(IJavaProject project, ContainerResolu | |
| resolutionContext.endResolvingProject(sourceProject); | ||
| } | ||
| } else if (LOG.isDebugEnabled()) { | ||
| // this should not happen in theory because Bazel is an acyclic graph as well as Eclipse doesn't like it but who knows... | ||
| LOG.debug( | ||
| "Skipping recursive resolution attempt for project '{}' in thread '{}' ({})", | ||
| sourceProject, | ||
| "Skipping already processed project '{}' in thread '{}' to avoid cycle", | ||
| sourceProject.getName(), | ||
| Thread.currentThread().getName()); | ||
| } | ||
| break; | ||
|
|
@@ -275,9 +286,74 @@ private boolean populateWithSavedContainer(IJavaProject project, ContainerResolu | |
| } | ||
| } | ||
|
|
||
| // Add the project's own output folders to the runtime classpath | ||
| // This ensures that Eclipse-compiled classes (including test classes) are available at runtime | ||
| addProjectOutputFolders(project, resolutionContext); | ||
|
|
||
| // Note: Test framework dependencies (like JUnit) are now pre-cached in the container during | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is weird. Why wouldn't they come from regular Bazel dependencies?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| // the container build phase (see BazelClasspathManager.saveAndSetContainer), so we no longer | ||
| // need to resolve them at runtime. This significantly improves performance for large projects. | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the given project is a test project based on naming conventions. | ||
| * | ||
| * Note: This method is kept for potential future use, but test framework dependencies are now handled during | ||
| * container creation rather than runtime resolution. | ||
| * | ||
| * @param project | ||
| * the project to check | ||
| * @return <code>true</code> if this appears to be a test project, <code>false</code> otherwise | ||
| */ | ||
| @SuppressWarnings("unused") | ||
| private boolean isTestProject(IJavaProject project) { | ||
| var projectName = project.getProject().getName(); | ||
| // Check if project name contains "test" or ends with "-test" | ||
| return projectName.contains("test") || projectName.contains("Test"); | ||
| } | ||
|
|
||
| /** | ||
| * Adds the project's own output folders to the runtime classpath. This includes both the regular output folder | ||
| * (eclipse-bin) and the test output folder (eclipse-testbin). | ||
| * | ||
| * @param project | ||
| * the project whose output folders should be added | ||
| * @param resolutionContext | ||
| * the resolution context | ||
| * @throws CoreException | ||
| */ | ||
| private void addProjectOutputFolders(IJavaProject project, ContainerResolutionContext resolutionContext) | ||
| throws CoreException { | ||
| // Add the project's default output location (main compiled classes) | ||
| var defaultOutputLocation = project.getOutputLocation(); | ||
| if (defaultOutputLocation != null) { | ||
| var outputEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(defaultOutputLocation); | ||
| outputEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); | ||
| resolutionContext.add(outputEntry); | ||
| if (LOG.isDebugEnabled()) { | ||
| LOG.debug("Added default output location to runtime classpath: {}", defaultOutputLocation); | ||
| } | ||
| } | ||
|
|
||
| // For Bazel projects, also add the test output folder explicitly | ||
| var bazelProject = BazelCore.create(project.getProject()); | ||
| if (bazelProject != null) { | ||
| var fileSystemMapper = bazelProject.getBazelWorkspace().getBazelProjectFileSystemMapper(); | ||
| var testOutputFolder = fileSystemMapper.getOutputFolderForTests(bazelProject); | ||
| // Test output folder might be different from the default output location | ||
| if (!testOutputFolder.getFullPath().equals(defaultOutputLocation)) { | ||
| var testOutputEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(testOutputFolder.getFullPath()); | ||
| testOutputEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); | ||
| resolutionContext.add(testOutputEntry); | ||
| if (LOG.isDebugEnabled()) { | ||
| LOG.debug("Added test output folder to runtime classpath: {}", testOutputFolder.getFullPath()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entry, IJavaProject project) | ||
| throws CoreException { | ||
|
|
@@ -300,15 +376,21 @@ public IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEn | |
| // this method can be entered recursively; luckily only within the same thread | ||
| // therefore we use a ThreadLocal LinkedHashSet to keep track of recursive attempts | ||
| var resolutionContext = currentThreadResolutionContet.get(); | ||
|
|
||
| // CRITICAL: Check if this is top-level BEFORE calling beginResolvingProject | ||
| // This ensures ThreadLocal cleanup happens correctly | ||
| var isTopLevelResolution = resolutionContext.currentDepth == 0; | ||
|
|
||
| // Check for recursive resolution BEFORE calling beginResolvingProject | ||
| // to avoid depth counter mismatch | ||
| if (!resolutionContext.beginResolvingProjectIfNeverProcessedBefore(project.getProject())) { | ||
| LOG.warn( | ||
| "Detected recursive resolution attempt for project '{}' in thread '{}' ({})", | ||
| "Detected recursive resolution attempt for project '{}' in thread '{}' - skipping to avoid cycle", | ||
| project.getProject().getName(), | ||
| Thread.currentThread().getName()); | ||
| return new IRuntimeClasspathEntry[0]; | ||
| } | ||
|
|
||
| var isTopLevelResolution = resolutionContext.currentDepth == 0; | ||
| var stopWatch = StopWatch.startNewStopWatch(); | ||
| try { | ||
| // try the saved container | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(IRuntimeClasspathEntry, IJavaProject, boolean)would add the output folders alread. I don't think we should be doing this.I wonder if the error reported in #46 is caused by missing test dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I comment out this line of code, I encounter the following problem.