Skip to content

Commit c7a9906

Browse files
committed
Merge branch 'pr-98'
2 parents e86a858 + b445044 commit c7a9906

16 files changed

+197
-219
lines changed

ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This is a bugfix release.
1313

1414
### Fixed Issues
1515

16+
* [#85](https://github.com/pmd/pmd-eclipse-plugin/issues/85): Gutter Markers not Configured Color
1617
* [#96](https://github.com/pmd/pmd-eclipse-plugin/issues/96): Wrong auxclasspath if project is stored outside of workspace
1718

1819
## 31-March-2019: 4.2.0.v20190331-1136

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import net.sourceforge.pmd.eclipse.ui.ShapePainter;
8282
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
8383
import net.sourceforge.pmd.eclipse.ui.nls.StringTable;
84+
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptorCache;
8485
import net.sourceforge.pmd.eclipse.util.ResourceManager;
8586
import net.sourceforge.pmd.lang.LanguageRegistry;
8687
import net.sourceforge.pmd.lang.LanguageVersion;
@@ -330,8 +331,8 @@ public static IViewPart getView(String id) {
330331
*
331332
* @param viewId id of the view
332333
*/
333-
public void refreshView(final String viewId) {
334-
Display.getDefault().asyncExec(new Runnable() {
334+
public void refreshView(final String viewId) {
335+
Display.getCurrent().asyncExec(new Runnable() {
335336
@Override
336337
public void run() {
337338
try {
@@ -371,6 +372,7 @@ public void stop(BundleContext context) throws Exception {
371372
disposeResources();
372373
ShapePainter.disposeAll();
373374
ResourceManager.dispose();
375+
PriorityDescriptorCache.INSTANCE.dispose();
374376
super.stop(context);
375377
}
376378

@@ -734,5 +736,4 @@ public void removedMarkersIn(IResource resource) {
734736

735737
decorator.changed(changes);
736738
}
737-
738739
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/plugin/UISettings.java

Lines changed: 44 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package net.sourceforge.pmd.eclipse.plugin;
66

7-
import java.net.MalformedURLException;
8-
import java.net.URL;
97
import java.util.ArrayList;
108
import java.util.Arrays;
119
import java.util.Comparator;
@@ -23,7 +21,6 @@
2321
import org.eclipse.swt.widgets.Display;
2422

2523
import net.sourceforge.pmd.RulePriority;
26-
import net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences;
2724
import net.sourceforge.pmd.eclipse.runtime.preferences.IPreferencesManager;
2825
import net.sourceforge.pmd.eclipse.ui.Shape;
2926
import net.sourceforge.pmd.eclipse.ui.ShapeDescriptor;
@@ -45,32 +42,16 @@ private UISettings() {
4542

4643
private static String[] priorityLabels;
4744

48-
private static Map<Object, ShapeDescriptor> shapesByPriority;
49-
private static Map<Integer, RulePriority> prioritiesByIntValue;
5045
private static Map<RulePriority, String> labelsByPriority = new HashMap<RulePriority, String>();
5146

5247
private static final int MAX_MARKER_DIMENSION = 9;
5348
private static IPreferencesManager preferencesManager = PMDPlugin.getDefault().getPreferencesManager();
54-
private static final Map<RulePriority, PriorityDescriptor> UI_DESCRIPTORS_BY_PRIORITY = new HashMap<RulePriority, PriorityDescriptor>(
55-
5);
5649

5750
public static final FontBuilder CODE_FONT_BUILDER = new FontBuilder("Courier", 11, SWT.NORMAL);
5851

52+
@Deprecated
5953
public static void reloadPriorities() {
60-
UI_DESCRIPTORS_BY_PRIORITY.clear();
61-
uiDescriptorsByPriority(); // cause a reload
62-
}
63-
64-
private static Map<RulePriority, PriorityDescriptor> uiDescriptorsByPriority() {
65-
66-
if (UI_DESCRIPTORS_BY_PRIORITY.isEmpty()) {
67-
IPreferences preferences = preferencesManager.loadPreferences();
68-
for (RulePriority rp : currentPriorities(true)) {
69-
UI_DESCRIPTORS_BY_PRIORITY.put(rp, preferences.getPriorityDescriptor(rp));
70-
}
71-
}
72-
73-
return UI_DESCRIPTORS_BY_PRIORITY;
54+
// no-op - nothing to be done anymore. The priority descriptor are cached by PriorityDescriptorCache and not here.
7455
}
7556

7657
public static Shape[] allShapes() {
@@ -103,34 +84,37 @@ public static Map<Shape, ShapeDescriptor> shapeSet(RGB color, int size) {
10384
return shapes;
10485
}
10586

87+
/**
88+
* @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
89+
*/
90+
@Deprecated
10691
public static String markerFilenameFor(RulePriority priority) {
10792
String fileDir = PMDPlugin.getPluginFolder().getAbsolutePath();
10893
return fileDir + "/" + relativeMarkerFilenameFor(priority);
10994
}
11095

96+
/**
97+
* @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
98+
*/
99+
@Deprecated
111100
public static String relativeMarkerFilenameFor(RulePriority priority) {
112101
return "icons/markerP" + priority.getPriority() + ".png";
113102
}
114103

115-
private static ImageDescriptor getImageDescriptor(final String fileName) {
116-
117-
URL installURL = PMDPlugin.getDefault().getBundle().getEntry("/");
118-
try {
119-
URL url = new URL(installURL, fileName);
120-
return ImageDescriptor.createFromURL(url);
121-
} catch (MalformedURLException mue) {
122-
mue.printStackTrace();
123-
return null;
124-
}
125-
}
126-
104+
/**
105+
* @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
106+
*/
107+
@Deprecated
127108
public static ImageDescriptor markerDescriptorFor(RulePriority priority) {
128-
String path = relativeMarkerFilenameFor(priority);
129-
return getImageDescriptor(path);
109+
PriorityDescriptor pd = PriorityDescriptorCache.INSTANCE.descriptorFor(priority);
110+
return pd.getAnnotationImageDescriptor();
130111
}
131112

113+
/**
114+
* @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
115+
*/
116+
@Deprecated
132117
public static Map<Integer, ImageDescriptor> markerImgDescriptorsByPriority() {
133-
134118
RulePriority[] priorities = currentPriorities(true);
135119
Map<Integer, ImageDescriptor> overlaysByPriority = new HashMap<Integer, ImageDescriptor>(priorities.length);
136120
for (RulePriority priority : priorities) {
@@ -139,19 +123,22 @@ public static Map<Integer, ImageDescriptor> markerImgDescriptorsByPriority() {
139123
return overlaysByPriority;
140124
}
141125

126+
/**
127+
* Marker Icons are not stored to files anymore. They are generated on the fly and cached by {@link PriorityDescriptorCache}.
128+
* @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
129+
*/
130+
@Deprecated
142131
public static void createRuleMarkerIcons(Display display) {
143-
144132
ImageLoader loader = new ImageLoader();
145133

146134
PriorityDescriptorCache pdc = PriorityDescriptorCache.INSTANCE;
147135

148136
for (RulePriority priority : currentPriorities(true)) {
149-
Image image = pdc.descriptorFor(priority).getImage(display, MAX_MARKER_DIMENSION);
137+
Image image = pdc.descriptorFor(priority).getAnnotationImage();
150138
loader.data = new ImageData[] { image.getImageData() };
151139
String fullPath = markerFilenameFor(priority);
152140
PMDPlugin.getDefault().logInformation("Writing marker icon to: " + fullPath);
153141
loader.save(fullPath, SWT.IMAGE_PNG);
154-
155142
image.dispose();
156143
}
157144
}
@@ -175,12 +162,20 @@ public static void useCustomPriorityLabels(boolean flag) {
175162
}
176163
}
177164

165+
/**
166+
* @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor#description}.
167+
*/
168+
@Deprecated
178169
public static String descriptionFor(RulePriority priority) {
179170
return descriptorFor(priority).description;
180171
}
181172

173+
/**
174+
* @deprecated Use {@link PriorityDescriptorCache#descriptorFor(RulePriority)} to retrieve the {@link PriorityDescriptor}.
175+
*/
176+
@Deprecated
182177
public static PriorityDescriptor descriptorFor(RulePriority priority) {
183-
return uiDescriptorsByPriority().get(priority);
178+
return PriorityDescriptorCache.INSTANCE.descriptorFor(priority);
184179
}
185180

186181
public static String labelFor(RulePriority priority) {
@@ -191,36 +186,27 @@ public static String labelFor(RulePriority priority) {
191186
}
192187

193188
public static Map<Object, ShapeDescriptor> shapesByPriority() {
194-
195-
if (shapesByPriority != null) {
196-
return shapesByPriority;
197-
}
198-
199-
Map<Object, ShapeDescriptor> shapesByPriority = new HashMap<Object, ShapeDescriptor>(
200-
uiDescriptorsByPriority().size());
201-
for (Map.Entry<RulePriority, PriorityDescriptor> entry : uiDescriptorsByPriority().entrySet()) {
202-
shapesByPriority.put(entry.getKey(), entry.getValue().shape);
189+
Map<Object, ShapeDescriptor> shapesByPriority = new HashMap<Object, ShapeDescriptor>(RulePriority.values().length);
190+
for (RulePriority priority : RulePriority.values()) {
191+
shapesByPriority.put(priority, PriorityDescriptorCache.INSTANCE.descriptorFor(priority).shape);
203192
}
204-
205193
return shapesByPriority;
206194
}
207195

196+
/**
197+
* @deprecated Use {@link RulePriority#valueOf(int)} directly.
198+
*/
199+
@Deprecated
208200
public static RulePriority priorityFor(int value) {
209-
210-
if (prioritiesByIntValue == null) {
211-
prioritiesByIntValue = new HashMap<Integer, RulePriority>(uiDescriptorsByPriority().size());
212-
for (Map.Entry<RulePriority, PriorityDescriptor> entry : uiDescriptorsByPriority().entrySet()) {
213-
prioritiesByIntValue.put(entry.getKey().getPriority(), entry.getKey());
214-
}
215-
}
216-
return prioritiesByIntValue.get(value);
201+
return RulePriority.valueOf(value);
217202
}
218203

219204
/**
220205
* Return the priority labels
221206
*
222207
* @deprecated - not referenced in the modern UI
223208
*/
209+
@Deprecated
224210
public static String[] getPriorityLabels() {
225211
if (priorityLabels == null) {
226212
final StringTable stringTable = PMDPlugin.getDefault().getStringTable();

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/PMDMarkerImageProvider.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import org.eclipse.swt.graphics.Image;
1010
import org.eclipse.ui.texteditor.IAnnotationImageProvider;
1111

12-
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
12+
import net.sourceforge.pmd.RulePriority;
13+
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptorCache;
1314

1415
public class PMDMarkerImageProvider implements IAnnotationImageProvider {
1516

@@ -25,19 +26,20 @@ public String getImageDescriptorId(Annotation annotation) {
2526

2627
@Override
2728
public Image getManagedImage(Annotation annotation) {
28-
PMDPlugin plugin = PMDPlugin.getDefault();
2929
String type = annotation.getType();
30+
RulePriority priority = RulePriority.HIGH;
31+
3032
if ("net.sourceforge.pmd.eclipse.plugin.annotation.prio1".equals(type)) {
31-
return plugin.getImage(type, "icons/markerP1.png");
33+
priority = RulePriority.HIGH;
3234
} else if ("net.sourceforge.pmd.eclipse.plugin.annotation.prio2".equals(type)) {
33-
return plugin.getImage(type, "icons/markerP2.png");
35+
priority = RulePriority.MEDIUM_HIGH;
3436
} else if ("net.sourceforge.pmd.eclipse.plugin.annotation.prio3".equals(type)) {
35-
return plugin.getImage(type, "icons/markerP3.png");
37+
priority = RulePriority.MEDIUM;
3638
} else if ("net.sourceforge.pmd.eclipse.plugin.annotation.prio4".equals(type)) {
37-
return plugin.getImage(type, "icons/markerP4.png");
39+
priority = RulePriority.MEDIUM_LOW;
3840
} else if ("net.sourceforge.pmd.eclipse.plugin.annotation.prio5".equals(type)) {
39-
return plugin.getImage(type, "icons/markerP5.png");
41+
priority = RulePriority.LOW;
4042
}
41-
return null;
43+
return PriorityDescriptorCache.INSTANCE.descriptorFor(priority).getAnnotationImage();
4244
}
4345
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/RuleLabelDecorator.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.util.Collection;
88
import java.util.HashSet;
9-
import java.util.Map;
109
import java.util.Set;
1110

1211
import org.eclipse.core.resources.IResource;
@@ -17,24 +16,19 @@
1716
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
1817
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
1918

20-
import net.sourceforge.pmd.eclipse.plugin.UISettings;
19+
import net.sourceforge.pmd.RulePriority;
20+
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
2121
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
2222
import net.sourceforge.pmd.eclipse.runtime.builder.MarkerUtil;
23+
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptorCache;
2324

2425
/**
2526
*
2627
* @author Brian Remedios
2728
*/
2829
public class RuleLabelDecorator implements ILightweightLabelDecorator {
29-
3030
private Collection<ILabelProviderListener> listeners;
3131

32-
private Map<Integer, ImageDescriptor> overlaysByPriority;
33-
34-
public RuleLabelDecorator() {
35-
reloadDecorators();
36-
}
37-
3832
public void addListener(ILabelProviderListener listener) {
3933
if (listeners == null) {
4034
listeners = new HashSet<ILabelProviderListener>();
@@ -59,8 +53,11 @@ public void changed(Collection<IResource> resources) {
5953

6054
}
6155

56+
/**
57+
* reloading is not necessary anymore
58+
*/
59+
@Deprecated
6260
public void reloadDecorators() {
63-
overlaysByPriority = UISettings.markerImgDescriptorsByPriority();
6461
}
6562

6663
public boolean isLabelProperty(Object element, String property) {
@@ -93,18 +90,15 @@ public void decorate(Object element, IDecoration decoration) {
9390
}
9491

9592
Integer first = range.iterator().next();
96-
ImageDescriptor overlay = overlaysByPriority.get(first);
93+
ImageDescriptor overlay = PriorityDescriptorCache.INSTANCE.descriptorFor(RulePriority.valueOf(first)).getAnnotationImageDescriptor();
9794

9895
try {
9996
boolean hasMarkers = MarkerUtil.hasAnyRuleMarkers(resource);
10097
if (hasMarkers) {
10198
decoration.addOverlay(overlay);
10299
}
103100
} catch (CoreException e) {
104-
// TODO Auto-generated catch block
105-
e.printStackTrace();
101+
PMDPlugin.getDefault().logError("Error while adding overlay icon", e);
106102
}
107-
108103
}
109-
110104
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/ShapeDescriptor.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ public ShapeDescriptor(Shape theShape, RGB theColor, int theSize) {
2222
size = theSize;
2323
}
2424

25-
private ShapeDescriptor() {
26-
27-
}
28-
2925
public boolean equals(Object other) {
3026
if (other == null) {
3127
return false;
@@ -47,11 +43,7 @@ public int hashCode() {
4743
}
4844

4945
public ShapeDescriptor clone() {
50-
51-
ShapeDescriptor copy = new ShapeDescriptor();
52-
copy.shape = shape;
53-
copy.rgbColor = new RGB(rgbColor.red, rgbColor.green, rgbColor.blue);
54-
copy.size = size;
46+
ShapeDescriptor copy = new ShapeDescriptor(shape, new RGB(rgbColor.red, rgbColor.green, rgbColor.blue), size);
5547
return copy;
5648
}
5749

0 commit comments

Comments
 (0)