Skip to content

Commit

Permalink
[test] Reduce dom log output
Browse files Browse the repository at this point in the history
in logfile org.eclipse.jdt.core.tests.dom.RunAllTests.txt

5082 times "Aborted waitForSnapShot() because running with the workspace
rule"

9902 times duplicate "!MESSAGE TEARDOWN" + "!MESSAGE SETUP"
  • Loading branch information
jukzi committed Jan 6, 2025
1 parent c928ff1 commit 2da6950
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -2031,7 +2032,7 @@ public void run(IProgressMonitor monitor) throws CoreException {
if (locationURI != null)
createExternalProject(projectName, locationURI);
else
createProject(projectName);
createProjectInWorkspaceRunnnable(projectName);

// set java nature
addJavaNature(projectName);
Expand Down Expand Up @@ -2377,19 +2378,17 @@ protected IJavaProject importJavaProject(String projectName, String[] sourceFold
/*
* Create simple project.
*/
protected IProject createProject(final String projectName) throws CoreException {
protected void createProjectInWorkspaceRunnnable(String projectName) throws CoreException {
assertTrue(isWorkspaceRuleAlreadyInUse(getWorkspaceRoot()));
final IProject project = getProject(projectName);
IWorkspaceRunnable create = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
project.create(null);
project.open(null);
}
};
if(isWorkspaceRuleAlreadyInUse(getWorkspaceRoot())) {
create.run(null);
} else {
getWorkspace().run(create, null);
}
project.create(null);
project.open(null);
}

protected IProject createProject(String projectName) throws CoreException {
assertFalse(isWorkspaceRuleAlreadyInUse(getWorkspaceRoot()));
final IProject project = getProject(projectName);
getWorkspace().run(m -> createProjectInWorkspaceRunnnable(projectName), null);
List<IJavaProject> javaProjects = List.of(getJavaModel().getJavaProjects());
boolean foundInModel = javaProjects.stream().anyMatch(p -> projectName.equals(p.getElementName()));
if (!foundInModel) {
Expand Down Expand Up @@ -3730,7 +3729,7 @@ protected void setUp () throws Exception {
System.out.println("--------------------------------------------------------------------------------");
System.out.println("Running test "+getName()+"...");
}
logInfo("SETUP " + getName());
logInfo("SETUP " + getClass().getSimpleName() + "." + getName());
}

private static void printSystemEnv() {
Expand Down Expand Up @@ -3948,7 +3947,7 @@ protected String toString(String[] strings) {
}
@Override
protected void tearDown() throws Exception {
logInfo("TEARDOWN " + getName());
logInfo("TDOWN " + getClass().getSimpleName() + "." + getName());
if (this.workingCopies != null) {
discardWorkingCopies(this.workingCopies);
this.workingCopies = null;
Expand Down Expand Up @@ -4128,22 +4127,11 @@ protected void makeJCLModular(IJavaProject javaProject) throws JavaModelExceptio
}

private static void logError(String errorMessage, CoreException e) {
Plugin plugin = JavaCore.getPlugin();
if (plugin != null) {
ILog log = plugin.getLog();
Status status = new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, errorMessage, e);
log.log(status);
} else {
System.out.println(errorMessage);
e.printStackTrace(System.out);
}
logInfo(errorMessage);
e.printStackTrace(System.out);
}

private static void logInfo(String message) {
Plugin plugin = JavaCore.getPlugin();
if (plugin != null) {
plugin.getLog().log(new Status(IStatus.INFO, JavaCore.PLUGIN_ID, message));
}
System.out.println(message);
System.out.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " " + message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public void initialize(IPath containerPath, IJavaProject project) throws CoreExc
JavaCore.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
for (int i = 0; i < projectLength; i++) {
createProject(projects[i]);
createProjectInWorkspaceRunnnable(projects[i]);
editFile(
"/" + projects[i] + "/.project",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
Expand Down Expand Up @@ -463,7 +463,7 @@ public IClasspathEntry[] getClasspathEntries() {
ContainerInitializer.setInitializer(initializer);
JavaCore.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
createProject("P1");
createProjectInWorkspaceRunnnable("P1");
editFile(
"/P1/.project",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
Expand Down Expand Up @@ -528,7 +528,7 @@ public void initialize(IPath containerPath, IJavaProject project) throws CoreExc
getWorkspace().run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
p2.setRawClasspath(new IClasspathEntry[] {JavaCore.newSourceEntry(new Path("/P2/src"))}, new Path("/P2/bin"), null);
createProject("P3");
createProjectInWorkspaceRunnnable("P3");
editFile(
"/P3/.project",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@ public void resourceChanged(IResourceChangeEvent event) {
createFile("/P1/lib.jar", "");
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
createProject("P2");
createProjectInWorkspaceRunnnable("P2");
createFile(
"/P2/.classpath",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
Expand Down

0 comments on commit 2da6950

Please sign in to comment.