Skip to content

Commit 47e74fd

Browse files
committed
Merge branch 'compat-7.0'
2 parents b351b95 + e3c018b commit 47e74fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+593
-819
lines changed

.idea/misc.xml

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,21 @@ PMD distribution.
4545
## Building from source/ contributing
4646

4747
See [CONTRIBUTING.md](CONTRIBUTING.md) for instructions to build the project from source and setup your IDE.
48+
49+
50+
##### Building a runnable JAR
51+
52+
You can package a runnable jar containing the PMD dependencies with maven. For
53+
now the only option is to build a jar that contains pmd-core and pmd-java:
54+
55+
```
56+
mvn clean package -Dfat-java -Dpmd.core.version=7.0.0-SNAPSHOT
57+
```
58+
The `pmd.core.version` property selects the version of pmd-core *and pmd-java*
59+
that will be included. The built jar can then be found in your `target` directory.
60+
**Such a jar cannot be used in a PMD distribution** and must be used in a
61+
standalone fashion, otherwise classpath conflicts may arise.
62+
63+
You should never run the `install` goal with the `-Dfat-java` property! This
64+
would install the fat jar in your local repo and may cause dependency conflicts.
65+

pom.xml

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>net.sourceforge.pmd</groupId>
55
<artifactId>pmd-ui</artifactId>
66
<name>PMD Designer</name>
7-
<version>6.49.1-SNAPSHOT</version>
7+
<version>7.0.0-SNAPSHOT</version>
88

99
<description>The Rule Designer is a graphical tool that helps PMD users develop their custom rules.</description>
1010
<url>https://pmd.github.io</url>
@@ -54,7 +54,7 @@
5454
</developers>
5555

5656
<properties>
57-
<pmd.core.version>6.27.0</pmd.core.version>
57+
<pmd.core.version>7.0.0-SNAPSHOT</pmd.core.version>
5858
<openjfx.version>11.0.2</openjfx.version>
5959
<java.version>8</java.version>
6060
<kotlin.version>1.7.20</kotlin.version>
@@ -696,6 +696,13 @@
696696
<optional>true</optional>
697697
<scope>${pmd.module.scope}</scope>
698698
</dependency>
699+
<dependency>
700+
<groupId>net.sourceforge.pmd</groupId>
701+
<artifactId>pmd-swift</artifactId>
702+
<version>${pmd.core.version}</version>
703+
<optional>true</optional>
704+
<scope>provided</scope>
705+
</dependency>
699706
<dependency>
700707
<groupId>net.sourceforge.pmd</groupId>
701708
<artifactId>pmd-javascript</artifactId>
@@ -853,6 +860,74 @@
853860
</dependencies>
854861
</profile>
855862

863+
<profile>
864+
<!-- Profile to build a fat runnable jar. -->
865+
<!-- It's kind of shitty that we can't select dependencies to include manually, -->
866+
<!-- a gradle script may help. -->
867+
<id>fat-java-jar</id>
868+
<activation>
869+
<property>
870+
<name>fat-java</name>
871+
</property>
872+
</activation>
873+
<build>
874+
<plugins>
875+
<plugin>
876+
<groupId>org.apache.maven.plugins</groupId>
877+
<artifactId>maven-jar-plugin</artifactId>
878+
<version>${jar.plugin.version}</version>
879+
<configuration>
880+
<archive>
881+
<manifestEntries>
882+
<Multi-Release>true</Multi-Release>
883+
<Main-Class>net.sourceforge.pmd.util.fxdesigner.DesignerStarter</Main-Class>
884+
</manifestEntries>
885+
</archive>
886+
<finalName>pmd-ui-fat-${pmd.core.version}</finalName>
887+
</configuration>
888+
</plugin>
889+
890+
<plugin>
891+
<groupId>org.apache.maven.plugins</groupId>
892+
<artifactId>maven-shade-plugin</artifactId>
893+
<version>3.4.1</version>
894+
<configuration>
895+
896+
<!-- Relocate nothing -->
897+
898+
<!-- Merge resource provider files like Ikonli icon resolvers -->
899+
<transformers>
900+
<transformer
901+
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
902+
</transformers>
903+
</configuration>
904+
<executions>
905+
<execution>
906+
<phase>package</phase>
907+
<goals>
908+
<goal>shade</goal>
909+
</goals>
910+
</execution>
911+
</executions>
912+
</plugin>
913+
</plugins>
914+
</build>
915+
<dependencies>
916+
<dependency>
917+
<groupId>net.sourceforge.pmd</groupId>
918+
<artifactId>pmd-core</artifactId>
919+
<version>${pmd.core.version}</version>
920+
<scope>compile</scope>
921+
</dependency>
922+
<dependency>
923+
<groupId>net.sourceforge.pmd</groupId>
924+
<artifactId>pmd-java</artifactId>
925+
<version>${pmd.core.version}</version>
926+
<optional>true</optional>
927+
<scope>runtime</scope>
928+
</dependency>
929+
</dependencies>
930+
</profile>
856931
<profile>
857932
<id>sign</id>
858933
<build>
@@ -905,7 +980,7 @@
905980
<!-- Eg use -Prun,with-javafx -->
906981
<id>with-javafx</id>
907982
<properties>
908-
<openjfx.scope>runtime</openjfx.scope>
983+
<openjfx.scope>compile</openjfx.scope>
909984
</properties>
910985
</profile>
911986

src/main/java/net/sourceforge/pmd/util/fxdesigner/Designer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java.util.logging.Logger;
1313
import java.util.stream.Collectors;
1414

15-
import net.sourceforge.pmd.lang.ast.xpath.Attribute;
15+
import net.sourceforge.pmd.lang.rule.xpath.Attribute;
1616
import net.sourceforge.pmd.util.fxdesigner.app.DesignerParams;
1717
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRoot;
1818
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRootImpl;

src/main/java/net/sourceforge/pmd/util/fxdesigner/MetricPaneController.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44

55
package net.sourceforge.pmd.util.fxdesigner;
66

7-
import java.util.List;
8-
import java.util.stream.Collectors;
7+
import java.util.ArrayList;
98

9+
import org.checkerframework.checker.nullness.qual.Nullable;
1010
import org.reactfx.EventStreams;
1111
import org.reactfx.value.Val;
1212
import org.reactfx.value.Var;
1313

1414
import net.sourceforge.pmd.lang.ast.Node;
1515
import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider;
16+
import net.sourceforge.pmd.lang.metrics.Metric;
17+
import net.sourceforge.pmd.lang.metrics.MetricOptions;
1618
import net.sourceforge.pmd.util.fxdesigner.app.AbstractController;
1719
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRoot;
1820
import net.sourceforge.pmd.util.fxdesigner.app.NodeSelectionSource;
@@ -39,9 +41,9 @@ public class MetricPaneController extends AbstractController implements NodeSele
3941
@FXML
4042
private ToolbarTitledPane metricsTitledPane;
4143
@FXML
42-
private ListView<MetricResult> metricResultsListView;
44+
private ListView<MetricResult<?>> metricResultsListView;
4345

44-
private Var<Integer> numAvailableMetrics = Var.newSimpleVar(0);
46+
private final Var<Integer> numAvailableMetrics = Var.newSimpleVar(0);
4547

4648

4749
public MetricPaneController(DesignerRoot designerRoot) {
@@ -67,33 +69,42 @@ protected void beforeParentInit() {
6769
@Override
6870
public void setFocusNode(final Node node, DataHolder options) {
6971

70-
ObservableList<MetricResult> metrics = evaluateAllMetrics(node);
72+
ObservableList<MetricResult<?>> metrics = evaluateAllMetrics(node);
7173
metricResultsListView.setItems(metrics);
7274

7375
numAvailableMetrics.setValue((int) metrics.stream()
7476
.map(MetricResult::getValue)
75-
.filter(result -> !result.isNaN())
7677
.count());
7778
}
7879

80+
7981
public Val<Integer> numAvailableMetrics() {
8082
return numAvailableMetrics;
8183
}
8284

8385

84-
85-
private ObservableList<MetricResult> evaluateAllMetrics(Node n) {
86-
LanguageMetricsProvider<?, ?> provider = getGlobalLanguageVersion().getLanguageVersionHandler().getLanguageMetricsProvider();
86+
private ObservableList<MetricResult<?>> evaluateAllMetrics(Node n) {
87+
LanguageMetricsProvider provider = n.getAstInfo().getLanguageProcessor().services().getLanguageMetricsProvider();
8788
if (provider == null) {
8889
return FXCollections.emptyObservableList();
8990
}
90-
List<MetricResult> resultList =
91-
provider.computeAllMetricsFor(n)
92-
.entrySet()
93-
.stream()
94-
.map(e -> new MetricResult(e.getKey(), e.getValue()))
95-
.collect(Collectors.toList());
96-
return FXCollections.observableArrayList(resultList);
91+
ArrayList<MetricResult<?>> results = new ArrayList<>();
92+
for (Metric<?, ?> metric : provider.getMetrics()) {
93+
MetricResult<?> result = computeMetric(metric, n);
94+
if (result != null) {
95+
results.add(result);
96+
}
97+
}
98+
return FXCollections.observableArrayList(results);
99+
}
100+
101+
102+
private <R extends Number> MetricResult<R> computeMetric(Metric<?, R> metric, Node node) {
103+
@Nullable R result = Metric.compute(metric, node, MetricOptions.emptyOptions());
104+
if (result != null) {
105+
return new MetricResult<>(metric, result);
106+
}
107+
return null;
97108
}
98109

99110

src/main/java/net/sourceforge/pmd/util/fxdesigner/NodeDetailPaneController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.reactfx.value.Var;
1616

1717
import net.sourceforge.pmd.lang.ast.Node;
18-
import net.sourceforge.pmd.lang.ast.xpath.Attribute;
18+
import net.sourceforge.pmd.lang.rule.xpath.Attribute;
1919
import net.sourceforge.pmd.util.designerbindings.DesignerBindings;
2020
import net.sourceforge.pmd.util.designerbindings.DesignerBindings.AdditionalInfo;
2121
import net.sourceforge.pmd.util.designerbindings.DesignerBindings.DefaultDesignerBindings;

src/main/java/net/sourceforge/pmd/util/fxdesigner/SourceEditorController.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
import org.reactfx.value.Val;
3030
import org.reactfx.value.Var;
3131

32+
import net.sourceforge.pmd.internal.util.ClasspathClassLoader; // NOPMD
3233
import net.sourceforge.pmd.lang.Language;
3334
import net.sourceforge.pmd.lang.LanguageVersion;
3435
import net.sourceforge.pmd.lang.ast.Node;
35-
import net.sourceforge.pmd.util.ClasspathClassLoader;
3636
import net.sourceforge.pmd.util.fxdesigner.app.AbstractController;
3737
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRoot;
3838
import net.sourceforge.pmd.util.fxdesigner.app.services.ASTManager;
@@ -230,9 +230,7 @@ protected void beforeParentInit() {
230230
DragAndDropUtil.registerAsNodeDragTarget(
231231
violationsButton,
232232
range -> {
233-
LiveViolationRecord record = new LiveViolationRecord();
234-
record.setRange(range);
235-
record.setExactRange(true);
233+
LiveViolationRecord record = new LiveViolationRecord(range, null);
236234
SimplePopups.showActionFeedback(violationsButton, AlertType.CONFIRMATION, "Violation added");
237235
currentlyOpenTestCase.ifPresent(v -> v.getExpectedViolations().add(record));
238236
}, getDesignerRoot());

src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathRuleEditorController.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import java.io.IOException;
1111
import java.time.Duration;
12-
import java.util.ArrayList;
12+
import java.util.Arrays;
1313
import java.util.Collections;
1414
import java.util.List;
1515
import java.util.Objects;
@@ -33,7 +33,7 @@
3333

3434
import net.sourceforge.pmd.lang.Language;
3535
import net.sourceforge.pmd.lang.ast.Node;
36-
import net.sourceforge.pmd.lang.rule.xpath.XPathRuleQuery;
36+
import net.sourceforge.pmd.lang.rule.xpath.XPathVersion;
3737
import net.sourceforge.pmd.util.fxdesigner.app.AbstractController;
3838
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRoot;
3939
import net.sourceforge.pmd.util.fxdesigner.app.NodeSelectionSource;
@@ -97,7 +97,6 @@ public final class XPathRuleEditorController extends AbstractController implemen
9797

9898
private static final String NO_MATCH_MESSAGE = "No match in text";
9999
private static final Duration XPATH_REFRESH_DELAY = Duration.ofMillis(100);
100-
private static final Pattern JAXEN_MISSING_PROPERTY_EXTRACTOR = Pattern.compile("Variable (\\w+)");
101100
private static final Pattern SAXON_MISSING_PROPERTY_EXTRACTOR = Pattern.compile("Undeclared variable in XPath expression: \\$(\\w+)");
102101
private final SoftReferenceCache<ExportXPathWizardController> exportWizard;
103102
private final ObservableXPathRuleBuilder ruleBuilder;
@@ -122,7 +121,7 @@ public final class XPathRuleEditorController extends AbstractController implemen
122121
@FXML
123122
private ListView<TextAwareNodeWrapper> xpathResultListView;
124123
// ui property
125-
private Var<String> xpathVersionUIProperty = Var.newSimpleVar(XPathRuleQuery.XPATH_2_0);
124+
private Var<XPathVersion> xpathVersionUIProperty = Var.newSimpleVar(XPathVersion.DEFAULT);
126125
private SuspendableEventStream<TextAwareNodeWrapper> selectionEvents;
127126

128127
public XPathRuleEditorController(DesignerRoot root) {
@@ -232,21 +231,16 @@ private void bindToParent() {
232231
private void initialiseVersionSelection() {
233232
ToggleGroup xpathVersionToggleGroup = new ToggleGroup();
234233

235-
List<String> versionItems = new ArrayList<>();
236-
versionItems.add(XPathRuleQuery.XPATH_1_0);
237-
versionItems.add(XPathRuleQuery.XPATH_1_0_COMPATIBILITY);
238-
versionItems.add(XPathRuleQuery.XPATH_2_0);
239-
240-
versionItems.forEach(v -> {
241-
RadioMenuItem item = new RadioMenuItem("XPath " + v);
234+
for (XPathVersion v : Arrays.asList(XPathVersion.values())) {
235+
RadioMenuItem item = new RadioMenuItem("XPath " + v.getXmlName());
242236
item.setUserData(v);
243237
item.setToggleGroup(xpathVersionToggleGroup);
244238
xpathVersionMenuButton.getItems().add(item);
245-
});
239+
}
246240

247-
xpathVersionUIProperty = DesignerUtil.mapToggleGroupToUserData(xpathVersionToggleGroup, DesignerUtil::defaultXPathVersion);
241+
xpathVersionUIProperty = DesignerUtil.mapToggleGroupToUserData(xpathVersionToggleGroup, () -> XPathVersion.DEFAULT);
248242

249-
xpathVersionProperty().setValue(XPathRuleQuery.XPATH_2_0);
243+
xpathVersionProperty().setValue(XPathVersion.DEFAULT);
250244
}
251245

252246

@@ -321,7 +315,7 @@ public Var<String> xpathExpressionProperty() {
321315
}
322316

323317

324-
public Var<String> xpathVersionProperty() {
318+
public Var<XPathVersion> xpathVersionProperty() {
325319
return xpathVersionUIProperty;
326320
}
327321

@@ -396,11 +390,7 @@ private javafx.scene.Node getErrorPlaceholder(String message) {
396390

397391

398392
private Optional<String> getMissingPropertyName(String errorMessage) {
399-
Pattern nameExtractor = XPathRuleQuery.XPATH_1_0.equals(getRuleBuilder().getXpathVersion())
400-
? JAXEN_MISSING_PROPERTY_EXTRACTOR
401-
: SAXON_MISSING_PROPERTY_EXTRACTOR;
402-
403-
Matcher matcher = nameExtractor.matcher(errorMessage);
393+
Matcher matcher = SAXON_MISSING_PROPERTY_EXTRACTOR.matcher(errorMessage);
404394
return matcher.matches() ? Optional.of(matcher.group(1)) : Optional.empty();
405395
}
406396

0 commit comments

Comments
 (0)