Skip to content

Commit dd4568f

Browse files
committed
Write trace messages to the trace log for ClasspathComputer
Currently PDE uses System.out to print trace messages, that has the problem that id the user has configured a trace file it does not show up there. This now acquire a DebugTrace instance that can be used and use that in the ClasspathComputer.
1 parent 88e3ed7 commit dd4568f

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathComputer.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void resourceChanged(IResourceChangeEvent event) {
9999
IResource resource = event.getResource();
100100
if (resource instanceof IProject project) {
101101
if (PDECore.DEBUG_STATE) {
102-
System.out.println(String.format("Project %s was deleted.", project.getName())); //$NON-NLS-1$
102+
PDECore.TRACE.trace(null, String.format("Project %s was deleted.", project.getName())); //$NON-NLS-1$
103103
}
104104
getStateFile(project).delete();
105105
}
@@ -650,15 +650,15 @@ private static boolean isUpToDate(IProject project, IClasspathEntry[] currentEnt
650650
IClasspathContainer previousClasspathContainer) {
651651
if (previousClasspathContainer == null) {
652652
if (PDECore.DEBUG_STATE) {
653-
System.out
654-
.println(String.format("%s need update because it has no state to compare", project.getName())); //$NON-NLS-1$
653+
PDECore.TRACE.trace(null,
654+
String.format("%s need update because it has no state to compare", project.getName())); //$NON-NLS-1$
655655
}
656656
return false;
657657
}
658658
IClasspathEntry[] previousEntries = previousClasspathContainer.getClasspathEntries();
659659
if (previousEntries == null || previousEntries.length != currentEntries.length) {
660660
if (PDECore.DEBUG_STATE) {
661-
System.out.println(String.format("%s need update because entries do not match in size!", //$NON-NLS-1$
661+
PDECore.TRACE.trace(null, String.format("%s need update because entries do not match in size!", //$NON-NLS-1$
662662
project.getName()));
663663
}
664664
return false;
@@ -668,7 +668,7 @@ private static boolean isUpToDate(IProject project, IClasspathEntry[] currentEnt
668668
IClasspathEntry current = currentEntries[i];
669669
if (!Objects.equals(current, previous)) {
670670
if (PDECore.DEBUG_STATE) {
671-
System.out.println(
671+
PDECore.TRACE.trace(null,
672672
String.format("%s need update because entry at position %d is different:\n\t%s\n\t%s", //$NON-NLS-1$
673673
project.getName(), i, current, previous));
674674
}
@@ -689,8 +689,8 @@ private static void saveState(IProject project, RequiredPluginsClasspathContaine
689689
} catch (Exception e) {
690690
// can't write then...
691691
if (PDECore.DEBUG_STATE) {
692-
System.err.println(String.format("Writing project state for %s failed!", project.getName())); //$NON-NLS-1$
693-
e.printStackTrace();
692+
PDECore.TRACE.trace(null, String.format("Writing project state for %s failed!", project.getName()), //$NON-NLS-1$
693+
e);
694694
}
695695
}
696696
}
@@ -704,17 +704,18 @@ static IClasspathContainer readState(IProject project) {
704704
IClasspathContainer container = Objects
705705
.requireNonNull(PDEClasspathContainerSaveHelper.readContainer(stream));
706706
if (PDECore.DEBUG_STATE) {
707-
System.out.println(String.format("%s is restored from previous state.", project.getName())); //$NON-NLS-1$
707+
PDECore.TRACE.trace(null,
708+
String.format("%s is restored from previous state.", project.getName())); //$NON-NLS-1$
708709
}
709710
return container;
710711
}
711712
} catch (Exception e) {
712713
if (PDECore.DEBUG_STATE) {
713714
if (e instanceof FileNotFoundException) {
714-
System.out.println(String.format("%s has no saved state!", project.getName())); //$NON-NLS-1$
715+
PDECore.TRACE.trace(null, String.format("%s has no saved state!", project.getName())); //$NON-NLS-1$
715716
} else {
716-
System.err.println(String.format("Restoring project state for %s failed!", project.getName())); //$NON-NLS-1$
717-
e.printStackTrace();
717+
PDECore.TRACE.trace(null,
718+
String.format("Restoring project state for %s failed!", project.getName()), e); //$NON-NLS-1$
718719
}
719720
}
720721
return PDEClasspathContainerSaveHelper.emptyContainer();

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.eclipse.jdt.launching.JavaRuntime;
3737
import org.eclipse.osgi.service.debug.DebugOptions;
3838
import org.eclipse.osgi.service.debug.DebugOptionsListener;
39+
import org.eclipse.osgi.service.debug.DebugTrace;
3940
import org.eclipse.pde.core.IBundleClasspathResolver;
4041
import org.eclipse.pde.core.IClasspathContributor;
4142
import org.eclipse.pde.core.plugin.IPluginModelBase;
@@ -83,6 +84,7 @@ public class PDECore extends Plugin implements DebugOptionsListener {
8384
public static boolean DEBUG_TARGET_PROFILE = false;
8485
public static boolean DEBUG_VALIDATION = false;
8586
public static boolean DEBUG_STATE = false;
87+
public static DebugTrace TRACE;
8688
private static final String DEBUG_FLAG = PLUGIN_ID + "/debug"; //$NON-NLS-1$
8789
private static final String CLASSPATH_DEBUG = PLUGIN_ID + "/classpath"; //$NON-NLS-1$
8890
private static final String MODEL_DEBUG = PLUGIN_ID + "/model"; //$NON-NLS-1$
@@ -455,6 +457,9 @@ public <T> T acquireService(Class<T> serviceClass) {
455457
@Override
456458
public void optionsChanged(DebugOptions options) {
457459
boolean DEBUG = options.getBooleanOption(DEBUG_FLAG, false);
460+
if (DEBUG) {
461+
TRACE = options.newDebugTrace(PLUGIN_ID);
462+
}
458463
DEBUG_CLASSPATH = DEBUG && options.getBooleanOption(CLASSPATH_DEBUG, false);
459464
DEBUG_MODEL = DEBUG && options.getBooleanOption(MODEL_DEBUG, false);
460465
DEBUG_TARGET_PROFILE = DEBUG && options.getBooleanOption(TARGET_PROFILE_DEBUG, false);

0 commit comments

Comments
 (0)