Skip to content

Commit 4c4ad88

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. Also fixed missing passing of restored state.
1 parent 88e3ed7 commit 4c4ad88

4 files changed

Lines changed: 29 additions & 15 deletions

File tree

ui/org.eclipse.pde.core/.options

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ org.eclipse.pde.core/target/profile=false
88
# trace when validating plugin.xml contents
99
org.eclipse.pde.core/validation=false
1010
# trace when read/save the current state of the plugin resolution
11-
org.eclipse.pde.core/state=false
11+
org.eclipse.pde.core/debug/state=false

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ 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(PDECore.KEY_DEBUG_STATE,
103+
String.format("Project %s was deleted.", project.getName())); //$NON-NLS-1$
103104
}
104105
getStateFile(project).delete();
105106
}
@@ -650,15 +651,16 @@ private static boolean isUpToDate(IProject project, IClasspathEntry[] currentEnt
650651
IClasspathContainer previousClasspathContainer) {
651652
if (previousClasspathContainer == null) {
652653
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$
654+
PDECore.TRACE.trace(PDECore.KEY_DEBUG_STATE,
655+
String.format("%s need update because it has no state to compare", project.getName())); //$NON-NLS-1$
655656
}
656657
return false;
657658
}
658659
IClasspathEntry[] previousEntries = previousClasspathContainer.getClasspathEntries();
659660
if (previousEntries == null || previousEntries.length != currentEntries.length) {
660661
if (PDECore.DEBUG_STATE) {
661-
System.out.println(String.format("%s need update because entries do not match in size!", //$NON-NLS-1$
662+
PDECore.TRACE.trace(PDECore.KEY_DEBUG_STATE,
663+
String.format("%s need update because entries do not match in size!", //$NON-NLS-1$
662664
project.getName()));
663665
}
664666
return false;
@@ -668,7 +670,7 @@ private static boolean isUpToDate(IProject project, IClasspathEntry[] currentEnt
668670
IClasspathEntry current = currentEntries[i];
669671
if (!Objects.equals(current, previous)) {
670672
if (PDECore.DEBUG_STATE) {
671-
System.out.println(
673+
PDECore.TRACE.trace(PDECore.KEY_DEBUG_STATE,
672674
String.format("%s need update because entry at position %d is different:\n\t%s\n\t%s", //$NON-NLS-1$
673675
project.getName(), i, current, previous));
674676
}
@@ -689,8 +691,9 @@ private static void saveState(IProject project, RequiredPluginsClasspathContaine
689691
} catch (Exception e) {
690692
// can't write then...
691693
if (PDECore.DEBUG_STATE) {
692-
System.err.println(String.format("Writing project state for %s failed!", project.getName())); //$NON-NLS-1$
693-
e.printStackTrace();
694+
PDECore.TRACE.trace(PDECore.KEY_DEBUG_STATE,
695+
String.format("Writing project state for %s failed!", project.getName()), //$NON-NLS-1$
696+
e);
694697
}
695698
}
696699
}
@@ -704,17 +707,19 @@ static IClasspathContainer readState(IProject project) {
704707
IClasspathContainer container = Objects
705708
.requireNonNull(PDEClasspathContainerSaveHelper.readContainer(stream));
706709
if (PDECore.DEBUG_STATE) {
707-
System.out.println(String.format("%s is restored from previous state.", project.getName())); //$NON-NLS-1$
710+
PDECore.TRACE.trace(PDECore.KEY_DEBUG_STATE,
711+
String.format("%s is restored from previous state.", project.getName())); //$NON-NLS-1$
708712
}
709713
return container;
710714
}
711715
} catch (Exception e) {
712716
if (PDECore.DEBUG_STATE) {
713717
if (e instanceof FileNotFoundException) {
714-
System.out.println(String.format("%s has no saved state!", project.getName())); //$NON-NLS-1$
718+
PDECore.TRACE.trace(PDECore.KEY_DEBUG_STATE,
719+
String.format("%s has no saved state!", project.getName())); //$NON-NLS-1$
715720
} else {
716-
System.err.println(String.format("Restoring project state for %s failed!", project.getName())); //$NON-NLS-1$
717-
e.printStackTrace();
721+
PDECore.TRACE.trace(PDECore.KEY_DEBUG_STATE,
722+
String.format("Restoring project state for %s failed!", project.getName()), e); //$NON-NLS-1$
718723
}
719724
}
720725
return PDEClasspathContainerSaveHelper.emptyContainer();

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

Lines changed: 11 additions & 2 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;
@@ -62,6 +63,7 @@
6263
import aQute.bnd.service.clipboard.Clipboard;
6364

6465
public class PDECore extends Plugin implements DebugOptionsListener {
66+
6567
public static final String PLUGIN_ID = "org.eclipse.pde.core"; //$NON-NLS-1$
6668

6769
public static final IPath REQUIRED_PLUGINS_CONTAINER_PATH = IPath.fromOSString(PLUGIN_ID + ".requiredPlugins"); //$NON-NLS-1$
@@ -83,12 +85,16 @@ public class PDECore extends Plugin implements DebugOptionsListener {
8385
public static boolean DEBUG_TARGET_PROFILE = false;
8486
public static boolean DEBUG_VALIDATION = false;
8587
public static boolean DEBUG_STATE = false;
86-
private static final String DEBUG_FLAG = PLUGIN_ID + "/debug"; //$NON-NLS-1$
88+
public static DebugTrace TRACE;
89+
private static final String DEBUG = "/debug"; //$NON-NLS-1$
90+
91+
public static final String KEY_DEBUG_STATE = DEBUG + "/state"; //$NON-NLS-1$
92+
private static final String DEBUG_FLAG = PLUGIN_ID + DEBUG;
8793
private static final String CLASSPATH_DEBUG = PLUGIN_ID + "/classpath"; //$NON-NLS-1$
8894
private static final String MODEL_DEBUG = PLUGIN_ID + "/model"; //$NON-NLS-1$
8995
private static final String TARGET_PROFILE_DEBUG = PLUGIN_ID + "/target/profile"; //$NON-NLS-1$
9096
private static final String VALIDATION_DEBUG = PLUGIN_ID + "/validation"; //$NON-NLS-1$
91-
private static final String STATE_DEBUG = PLUGIN_ID + "/state"; //$NON-NLS-1$
97+
private static final String STATE_DEBUG = PLUGIN_ID + KEY_DEBUG_STATE;
9298

9399
// Shared instance
94100
private static PDECore inst;
@@ -455,6 +461,9 @@ public <T> T acquireService(Class<T> serviceClass) {
455461
@Override
456462
public void optionsChanged(DebugOptions options) {
457463
boolean DEBUG = options.getBooleanOption(DEBUG_FLAG, false);
464+
if (DEBUG) {
465+
TRACE = options.newDebugTrace(PLUGIN_ID);
466+
}
458467
DEBUG_CLASSPATH = DEBUG && options.getBooleanOption(CLASSPATH_DEBUG, false);
459468
DEBUG_MODEL = DEBUG && options.getBooleanOption(MODEL_DEBUG, false);
460469
DEBUG_TARGET_PROFILE = DEBUG && options.getBooleanOption(TARGET_PROFILE_DEBUG, false);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void initialize(IPath containerPath, IJavaProject javaProject) throws Cor
3434
new IClasspathContainer[] { savedState }, null);
3535
// The saved state might be stale, request a classpath update here, this
3636
// will run in a background job and update the classpath if needed.
37-
ClasspathComputer.requestClasspathUpdate(project);
37+
ClasspathComputer.requestClasspathUpdate(project, savedState);
3838
}
3939

4040
@Override

0 commit comments

Comments
 (0)