Code Monkey home page Code Monkey logo

pmd-designer's Introduction

PMD - source code analyzer

PMD Logo

Join the chat Build Status Maven Central Reproducible Builds Coverage Status Codacy Badge Contributor Covenant Documentation (latest)

PMD is an extensible multilanguage static code analyzer. It finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and so forth. It's mainly concerned with Java and Apex, but supports 16 other languages. It comes with 400+ built-in rules. It can be extended with custom rules. It uses JavaCC and Antlr to parse source files into abstract syntax trees (AST) and runs rules against them to find violations. Rules can be written in Java or using a XPath query.

Currently, PMD supports Java, JavaScript, Salesforce.com Apex and Visualforce, Kotlin, Swift, Modelica, PLSQL, Apache Velocity, JSP, WSDL, Maven POM, HTML, XML and XSL. Scala is supported, but there are currently no Scala rules available.

Additionally, it includes CPD, the copy-paste-detector. CPD finds duplicated code in Coco, C/C++, C#, Dart, Fortran, Gherkin, Go, Groovy, HTML, Java, JavaScript, JSP, Julia, Kotlin, Lua, Matlab, Modelica, Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex and Visualforce, Scala, Swift, T-SQL, Typescript, Apache Velocity, WSDL, XML and XSL.

🚀 Installation and Usage

Download the latest binary zip from the releases and extract it somewhere.

Execute bin/pmd check or bin\pmd.bat check.

See also Getting Started

Demo:

This shows how PMD analyses openjdk:

Demo

There are plugins for Maven and Gradle as well as for various IDEs. See Tools / Integrations

ℹ️ How to get support?

🤝 Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Our latest source of PMD can be found on GitHub. Fork us!

The rule designer is developed over at pmd/pmd-designer. Please see its README for developer documentation.

💵 Financial Contributors

Become a financial contributor and help us sustain our community. Contribute

✨ Contributors

This project follows the all-contributors specification. Contributions of any kind welcome!

See credits for the complete list.

📝 License

BSD Style

pmd-designer's People

Contributors

adangel avatar akshatbahety avatar atrosinenko avatar gitter-badger avatar jsotuyod avatar matiascomercio avatar oowekyala avatar reudismam avatar thunderforge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pmd-designer's Issues

Designer uses internal PropertyTypeId

With pmd/pmd#4809 the class PropertyTypeId has been internalized in pmd-core and should not be used by downstream projects.

From the class doc of PropertyTypeId:

This class' API is mainly provided to build GUIs for XPath rules like the rule designer, so that they have info about the available properties from XML. As such, the number of clients are probably low. Fow now, this stays as Internal API and might be changed.

PropertyTypeId is used by pmd-designer and by pmd-eclipse-plugin.

Maybe we can provide a public API for this. Or maybe this can be avoided by leveraging the serialization mechanism (PropertyDescriptor#serializer()) directly.

[ui] New rule designer pending issues

This is a placeholder issue to keep track of the different smaller issues / nice to haves we find as we work on the new rule designer. None of these are blocking issues, they are small improvements to usability and user experience.

Usability

  • (PR #1053) Clicking on the AST or Scopes produces the Source panel to scroll to show the selected scope / node. However, if clicking again the already selected node, no scroll happens. When using both panels this means there is no easy way to jump from the scope back to the AST node or viceversa. Also selection highlighting is not reset, which is particularly visible when selecting the SourceFileScope
  • When selecting a field or variable from a Scope, the highlighting of selection works fine, but the code panel scrolls to the last occurrence instead of to the declaration.
  • The designer doesn't remember the language last used. This means that unless using Java 9, the last code will be reloaded, but parsed using a different grammar.
  • The scopes tab should hide away leaf Scopes that are empty
  • XML ASTs are currently very messy, since eg line breaks are parsed as a separate text node and displayed in the TreeView. There is also a virtual root node (named document) that is displayed but ignored by the XPath engine, which makes XPath rules confusing to write.
  • The property edition dialog doesn't handle additionnal configuration like min and max for numeric descriptors

Visual

  • The scopes tab has a small visual glitch on the final "s", at least on my machine
    image
  • Upon opening the designer and clicking the language dropdown, it is shown at an incorrect location, floating over the source editor. Future displays of the dropdown show correctly.

Ideas

  • Automatically reparse the code when the Source panel contents change. Removing the need for the "Refresh AST" button (via #1137)
  • Automatically match AST nodes as we edit the XPath editor (via #1137)
  • Right click on the AST -> generate XPath to this node, as an easier starting point for new rules
  • Right click on the AST -> generate ASCII, which lets you select a part of the tree and generates an ascii representation of the tree, with the attributes you want. This would make it easier to describe an AST without ambiguity, to communicate on github issues
  • Right click on Source panel -> locate in AST
  • Better defaults on which nodes are expanded by default on the AST panel. We currently show all nodes expanded by default, but this means we usually need to scroll to get to anything other than imports. Maybe we can be smarter on this...
    • Not a problem of the designer, mainly a problem of the AST being too verbose. pmd/pmd#1888 improves the situation
  • Showing matched nodes on the source panel (with a box outline, like IntelliJ does). This should be in addition to other style rules already applied (syntax coloring / usages form scopes / selected node from the AST).

Features

  • Setting up the auxclasspath. We currently include the typeof() info as part of the XPath Attributes, but these will only be non-null if using JRE / PMD classes. We need to be able to set it up manually. (via #1159)
  • Add a properties tab to the XPath panel, to enable XPath developers to define properties and test them (via #801)
  • Allow testing of the violation suppress Regex and XPath. (This is already kindof supported, the properties panel can be used for that even though these properties are not mentioned)
  • Code completion when writing an XPath query (considering valid node types for the language, or better, the successors of a node permitted by the grammar) (via #1182).
  • Save a number of snippets as test cases and edit them/ check that the XPath rule verifies all of them
  • Exporting the XPath rule doesn't include the version property, so all rules are exported as 1.0

Issue with codes indented with tab-characters (v6.12.0)

Having issue with xpath execution if source codes are indented with tab-characters.

Steps to reproduce the behaviour:

  1. Launch the designer from run.sh
  2. Entered a sample class indented with tabs, AST generated fine.
  3. Entered in XPathExpression, //MethodDeclaration
  4. Matched Nodes panel shown 'No match in text'
  5. Replaces all the tabs with space-chars, all method nodes were correctly found.

Expected behaviour
Indentation characters should not cause inconsistent behaviour in nodes detection.

  • OS: MacOS Mojave
  • Java:
    java version "1.8.0_192"
    Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)

There is a null pointer generated during scanning go

PMDConfiguration configuration = new PMDConfiguration();
LanguageVersion goLanguageVersion = LanguageRegistry.getLanguage("java").getDefaultVersion();
configuration.setDefaultLanguageVersion(goLanguageVersion);
configuration.setReportFormat("json");

The above is when I write scanning methods through java, the language selected java can scan, but when I change to go or C#, it will report a null pointer, no clue about this, this is my personal reason

This is the only hint 【java.lang.NullPointerException】

Counterintuitive language management

Language controls in the toolbar only sets the language used to parse / syntax color the editor:

image

But the XPath autocomplete / actual rule language is managed separately down here:

image

it's fixed upon creation. So if I change the language in the toolbar, the editor will immediately respond, but the XPath editor will continue working on the previous language until I manually click on the "+" to create a new rule for the current language.

This is particularly bad considering that the XPath expression will match against the current code regardless of the target language, so I can write an expression, have it work, but then upon exporting it, have it published for a separate language.

I think the most intuitive thing would be to drop the language from the xpath editor, and have it bound to always match the language set in the code editor.

To Reproduce
Steps to reproduce the behavior:

  1. Launch the designer from pmd designer
  2. Notice the current language. If Java switch to XML. If not Java, switch to Java.
  3. Notice the editor automatically matches the new language.
  4. Notice the rule tab says "java/NewRule" or "xml/NewRule", and this is a mismatch to the current editor language.
  5. Click "+" to add a new rule tab, which should now be "java/NewRule" or "xml/NewRule", this time matching the current editor language.
  6. In the "java/NewRule" editor, notice it suggests to autocomplete with Java AST nodes.
  7. Write any valid expression for the current editor language into both rules. Notice they match regardless of current language.
  8. Try and export both "working" rules for the current editor language. Notice them being exported for either "java" or "xml" accordingly.

Remove commons-io dependency

Describe the bug
There seems to be a security (?) issue with commons-io 2.7 - see pmd/pmd#4691

After googling (VULNDB-239195 is behind a paywall) I found this:

https://issues.apache.org/jira/browse/FLINK-22747

VULNDB-239195
"Vendor Specific News/Changelog Entry
https://commons.apache.org/proper/commons-io/changes-report.html#a2.8.0
Vendor Specific Solution URL
apache/commons-io@0de91c0
Vendor Specific Solution URL
apache/commons-io@97ae01c
Bug Tracker
https://issues.apache.org/jira/browse/IO-675"

In PMD, we already removed commons-io some time ago. I think, we should do the same in pmd-designer.

NPE when launching Designer

Describe the bug

./pmd designer
[main] INFO net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand - Log level is at INFO
java.lang.NullPointerException
	at java.util.Properties$LineReader.readLine(Properties.java:434)
	at java.util.Properties.load0(Properties.java:353)
	at java.util.Properties.load(Properties.java:341)
	at net.sourceforge.pmd.util.fxdesigner.DesignerStarter.getJavaFxVersion(DesignerStarter.java:116)
	at net.sourceforge.pmd.util.fxdesigner.DesignerStarter.isCompatibleJavaFxVersion(DesignerStarter.java:100)
	at net.sourceforge.pmd.util.fxdesigner.DesignerStarter.launchGui(DesignerStarter.java:153)
	at net.sourceforge.pmd.cli.commands.internal.DesignerCommand.execute(DesignerCommand.java:28)
	at net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand.call(AbstractPmdSubcommand.java:35)
	at net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand.call(AbstractPmdSubcommand.java:20)
	at picocli.CommandLine.executeUserObject(CommandLine.java:2041)
	at picocli.CommandLine.access$1500(CommandLine.java:148)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
	at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
	at picocli.CommandLine.execute(CommandLine.java:2170)
	at net.sourceforge.pmd.cli.PmdCli.main(PmdCli.java:18)

Version:
7.0.0-rc3

To Reproduce
Steps to reproduce the behavior:
run command "pmd designer"

Desktop:

  • Mac OS: 13.4 (22F66)
  • Java: java version : "1.8.0_291"
    Java(TM) SE Runtime Environment (build 1.8.0_291-b10)
    Java HotSpot(TM) 64-Bit Server VM (build 25.291-b10, mixed mode)

JavaFx:
javafx.runtime.version=8.0.291
javafx.runtime.build=b09

Remove dependency to jcommander

Recent PMD 7.0.0-rc3 has removed the dependency to com.beust:jcommander:1.48 (see pmd/pmd#4523),
which is transitively used by pmd-designer. It's added back for now, so that the shipped pmd-designer can be
started, but should be removed eventually.
net.sourceforge.pmd.util.fxdesigner.MainCliArgs is anyway deprecated already.
See pmd/pmd@25e230a

Rule export escapes special characters in rules unnecessarily

Describe the bug
When trying to export the following rule:

//PrimaryPrefix/Name[@Image[ends-with(., 'Instant.now')]][pmd-java:typeIs('java.time.Instant')]|
//PrimaryPrefix/Name[@Image='now'][//ImportDeclaration[@Static=true()]/Name[@Image='java.time.Instant.now' or @Image='java.time.Instant']]

The export result pane displays the rule incorrectly escaped:

         <value>
<![CDATA[
//PrimaryPrefix/Name[@Image[ends-with(., &apos;Instant.now&apos;)]][pmd-java:typeIs(&apos;java.time.Instant&apos;)]|
//PrimaryPrefix/Name[@Image=&apos;now&apos;][//ImportDeclaration[@Static=true()]/Name[@Image=&apos;java.time.Instant.now&apos; or @Image=&apos;java.time.Instant&apos;]]
]]>
         </value>

Within a CDATA it should not be necessary to escape apostrophe as &apos;, and the same seemed to happen with double quotes as well.

To Reproduce
Steps to reproduce the behavior:

  1. Launch the designer from run.sh designer
  2. Specify rule as above
  3. Click on Export XPath to XML rule
  4. Look at Export result pane
  5. When you try to use the rule as is with pmd, the rule parser will blow up with an XPath parsing exception.

Expected behavior
The CDATA body is not escaped unnecessarily.

Screenshots
Let me know if you need one.

Desktop (please complete the following information):

  • OS: macOS Mojave 10.14.6
  • Java:
    openjdk version "11.0.3" 2019-04-16
    OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.3+7)
    OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.3+7, mixed mode)

Problems with launching the app

I have trouble launching the designer both from within an IDE, from the maven exec task, and from the binary distribution.
I tried with a JDK 11 and 17 packaged by Amazon Zulu, which comes with JavaFX included, and got various errors. I also tried with a manual install of the JavaFX 17 SDK and with the JAVAFX_HOME env var that is recognized by our launch script and got the same errors.

@adangel can you describe your setup to run the designer with JavaFX 17?

Using pmd-dist-bin

Launches with JDK 11, but I get the following warning:

On JRE 9+, the following VM argument makes the controls smarter:
--add-opens javafx.controls/javafx.scene.control.skin=ALL-UNNAMED

Apparently this check doesn't match. The reported $java_vendor $java_ver is openjdk 110.

With JDK 17 I get the following:

PMD Rule Designer (v 7.0.0-rc1) initializing... 
Exception in Application start method
java.lang.RuntimeException: Exception in Application start method
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalAccessError: class net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil (in unnamed module @0x26ea8c2b) cannot access class com.sun.javafx.fxml.builder.ProxyBuilder (in module javafx.fxml) because module javafx.fxml does not export com.sun.javafx.fxml.builder to unnamed module @0x26ea8c2b

When adding --add-opens javafx.fxml/com.sun.javafx.fxml.builder=ALL-UNNAMED explicitly I get

Caused by: javafx.fxml.LoadException: 
file:/home/clem/Documents/PMD/pmd/sandbox/pmd-bin-7.0.0-SNAPSHOT/lib/pmd-ui-7.0.0-rc1.jar!/net/sourceforge/pmd/util/fxdesigner/fxml/editor.fxml:143
file:/home/clem/Documents/PMD/pmd/sandbox/pmd-bin-7.0.0-SNAPSHOT/lib/pmd-ui-7.0.0-rc1.jar!/net/sourceforge/pmd/util/fxdesigner/fxml/designer.fxml:118
...
Caused by: java.lang.RuntimeException: Cannot create instance of net.sourceforge.pmd.util.fxdesigner.util.controls.NodeParentageCrumbBar with given set of properties: [prefHeight, stylesheets, designerRoot, id]
	at javafx.fxml/com.sun.javafx.fxml.builder.ProxyBuilder.build(ProxyBuilder.java:272)
	at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:776)

Using the maven task / IDE

./mvnw -Prunning,with-javafx exec:java

With both JDKs I get the following:

Caused by: javafx.fxml.LoadException: 
/home/clem/Documents/PMD/designer/target/classes/net/sourceforge/pmd/util/fxdesigner/fxml/node-details.fxml:20
/home/clem/Documents/PMD/designer/target/classes/net/sourceforge/pmd/util/fxdesigner/fxml/designer.fxml:108

	at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2722)
	at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1024)
	at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:759)
	at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2853)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2649)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2563)
	at javafx.fxml/javafx.fxml.FXMLLoader$IncludeElement.constructValue(FXMLLoader.java:1155)
	at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:759)
	at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2853)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2649)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2563)
	at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2531)
	at net.sourceforge.pmd.util.fxdesigner.Designer.start(Designer.java:107)
	at net.sourceforge.pmd.util.fxdesigner.Designer.start(Designer.java:65)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
	at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
	at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
	at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:316)
	... 1 more
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
	at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1022)
	... 21 more
Caused by: java.lang.NullPointerException
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil.addCustomStyleSheets(DesignerUtil.java:139)
	at net.sourceforge.pmd.util.fxdesigner.util.controls.ToolbarTitledPane.<init>(ToolbarTitledPane.java:50)
	... 27 more

This exception also happens when I launch the app from within Intellij using the provided run configurations.

Java 17 warning

I get the following warning on app startup with JDK 17

OpenJDK 64-Bit Server VM warning: Ignoring option --illegal-access=warn; support was removed in 17.0

Extension points for the designer

pmd/pmd#2118 introduces a mechanism to add extension points for the designer.

Goal

Let language implementations provide language-specific insights to the designer without needing the designer to know about them

Mechanism

Adding an extension point

  • Publish an interface in pmd-core. The interface should be the smallest possible, different interfaces should be used for orthogonal services
  • Add it to DesignerBindings, which is provided by a LanguageVersionHandler
  • Implement the feature in the designer by using instances of the interface provided by the language modules

Implementing an extension point

  • Implement the interface somewhere
  • Return an instance of it in the correct method of the DesignerBindings for the language

Candidates for being extension points

  • Usage highlight (pmd/pmd#2118)
  • XPath functions (currently typeIs is hard-coded for java, and accessed through reflection)
  • Logic for describing a node in the treeview (currently getImage, this will be deprecated in 7.0)
  • Listing the available node names for XPath completion. Currently looks into the AST package, this is not appropriate for some languages (XML, or Swift in the antlr impl, because node classes are nested in the parser class)
  • Syntax highlighters. This is not trivial and needs pmd-core to publish an API to represent "colors", or css classes. Some points that jump to mind:
    • The highlighters have a small dependency on the code area library, which shouldn't be a dependency of pmd-core
    • The highlighters rely on Java 8 so this is anyway out of the question until 7.0 unless someone wants to rewrite them
    • How does this interact with css, and will we still be able to use it?

Non-candidates

  • The scopes view. Doing that would require an API in pmd-core to represent tree items somehow, and it feels like too much work for something that ultimately should be internal to the language implementation. I think it should be removed entirely at some point.

Exceptions and errors are not always logged

When trying the Designer 7.0.0-rc1 against PMD 7.0.0-rc3 (without the backwards compatible changes), it just
does nothing. Even with --verbose, no exceptions are logged. I would expect some MethodNotFoundErrors or
ClassNotFoundErrors.

The backwards compatible change is: pmd/pmd@17beee6

[ui] Functions like `typeIsExactly` and alike are not available in the designer

If you try to use those functions, you just get an exception in the exception log that the function is missing:

net.sourceforge.pmd.util.fxdesigner.model.XPathEvaluationException: java.lang.RuntimeException: org.jaxen.UnresolvableException: No Such Function typeIsExactly
	at net.sourceforge.pmd.util.fxdesigner.model.XPathEvaluator.evaluateQuery(XPathEvaluator.java:89)
	at net.sourceforge.pmd.util.fxdesigner.XPathPanelController.evaluateXPath(XPathPanelController.java:250)
	at net.sourceforge.pmd.util.fxdesigner.MainDesignerController.lambda$refreshXPathResults$10(MainDesignerController.java:210)
	at java.util.Optional.ifPresent(Optional.java:159)
	at net.sourceforge.pmd.util.fxdesigner.MainDesignerController.refreshXPathResults(MainDesignerController.java:210)
	at net.sourceforge.pmd.util.fxdesigner.XPathPanelController.lambda$beforeParentInit$4(XPathPanelController.java:137)
	at org.reactfx.util.NonAccumulativeStreamNotifications.lambda$head$0(NotificationAccumulator.java:134)
	at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)
	at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:57)
	at org.reactfx.ProperEventStream.emit(ProperEventStream.java:18)
	at org.reactfx.EventStream$1.lambda$observeInputs$0(EventStream.java:423)
	at org.reactfx.util.NonAccumulativeStreamNotifications.lambda$head$0(NotificationAccumulator.java:134)
	at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)
	at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:57)
	at org.reactfx.ProperEventStream.emit(ProperEventStream.java:18)
	at org.reactfx.SuccessionReducingStream.handleTimeout(SuccessionReducingStream.java:73)
	at org.reactfx.util.FxTimer.lambda$restart$0(FxTimer.java:89)
	at com.sun.scenario.animation.shared.TimelineClipCore.visitKeyFrame(TimelineClipCore.java:239)
	at com.sun.scenario.animation.shared.TimelineClipCore.playTo(TimelineClipCore.java:180)
	at javafx.animation.Timeline.impl_playTo(Timeline.java:176)
	at javafx.animation.AnimationAccessorImpl.playTo(AnimationAccessorImpl.java:39)
	at com.sun.scenario.animation.shared.SingleLoopClipEnvelope.timePulse(SingleLoopClipEnvelope.java:99)
	at javafx.animation.Animation.impl_timePulse(Animation.java:1102)
	at javafx.animation.Animation$1.lambda$timePulse$25(Animation.java:186)
	at java.security.AccessController.doPrivileged(Native Method)
	at javafx.animation.Animation$1.timePulse(Animation.java:185)
	at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:344)
	at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
	at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:506)
	at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
	at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run$$$capture(InvokeLaterDispatcher.java:95)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: org.jaxen.UnresolvableException: No Such Function typeIsExactly
	at net.sourceforge.pmd.lang.rule.xpath.JaxenXPathRuleQuery.evaluate(JaxenXPathRuleQuery.java:73)
	at net.sourceforge.pmd.lang.rule.XPathRule.evaluate(XPathRule.java:114)
	at net.sourceforge.pmd.lang.java.rule.JavaRuleChainVisitor.visit(JavaRuleChainVisitor.java:42)
	at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:96)
	at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:67)
	at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:140)
	at net.sourceforge.pmd.util.fxdesigner.model.XPathEvaluator.evaluateQuery(XPathEvaluator.java:84)
	... 35 more
Caused by: org.jaxen.UnresolvableException: No Such Function typeIsExactly
	at org.jaxen.SimpleFunctionContext.getFunction(SimpleFunctionContext.java:127)
	at org.jaxen.ContextSupport.getFunction(ContextSupport.java:242)
	at org.jaxen.Context.getFunction(Context.java:216)
	at org.jaxen.expr.DefaultFunctionCallExpr.evaluate(DefaultFunctionCallExpr.java:176)
	at org.jaxen.expr.DefaultAndExpr.evaluate(DefaultAndExpr.java:91)
	at org.jaxen.expr.DefaultPredicate.evaluate(DefaultPredicate.java:95)
	at org.jaxen.expr.PredicateSet.applyPredicate(PredicateSet.java:269)
	at org.jaxen.expr.PredicateSet.evaluatePredicates(PredicateSet.java:244)
	at org.jaxen.expr.DefaultStep.evaluate(DefaultStep.java:164)
	at org.jaxen.expr.DefaultLocationPath.evaluate(DefaultLocationPath.java:140)
	at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:102)
	at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:677)
	at org.jaxen.BaseXPath.selectNodes(BaseXPath.java:216)
	at net.sourceforge.pmd.lang.rule.xpath.JaxenXPathRuleQuery.evaluate(JaxenXPathRuleQuery.java:69)
	... 41 more

Support for other languages

I only see support in the designer for a few languages, but PMD supports many more.
It would be good to be able to use any of the languages that are supported.

Wrong qualified name?

Describe the bug
The designer tool is nice but i think it might show the wrong class

To Reproduce
Steps to reproduce the behavior:
1.

export JAVAFX_HOME=/Users/nbaumgartner/Library/Java/JavaVirtualMachines/javafx-sdk-17.0.7 pmd-bin-6.55.0/bin/run.sh designer

package com.example;

import javafx.scene.control.Button;

public class Test {
    private String foo;

    class Button{

    }

    public Button button;
}

Expected behavior
Altough there is a import for Button in the class we define an own class Button. The expected qualified name should be: "com.example.Text.Button" and not "javafx.scene.control.Button"

Screenshots
Bildschirmfoto 2023-05-14 um 18 27 59

Additional context
Bildschirmfoto 2023-05-14 um 18 28 58

Bug with property description being unwritable

Describe the bug
When editing a property through the popover, the description/default value are unwritable (reset themselves). Sometimes the property is deleted from the list (yet still apparently bound to the edit popover). This doesn't happen when editing properties from the rule export wizard. Possibly caused by popover focus issues (eg key press event bubbled up to the parent popover, which opens a new edit wizard?). Why doesn't this happen for the name property though? Very weird :(

To Reproduce
Steps to reproduce the behavior:

  1. Launch the designer from anywhere
  2. Click on properties button (XPath bottom panel)
  3. Click "Add property"
  4. Click edit button of new property
  5. Try to edit the description. In particular try to insert a space somewhere / backspace. Description jumps back to previous state

Expected behavior
Description should be editable, changes should be synchronized with the rest of the app.

Screenshots
bugreport_designer

Desktop (please complete the following information):
Ubuntu 18.04, OpenJDK 13.0.1 w/ OpenJFX 13. Never seen that issue on my previous config (Ubuntu 16.04 + OpenJDK 11 w/ OpenJFX 11)

JVM crash when starting designer under Linux with Wayland

Describe the bug
Just ran into this problem: Starting the designer resulted in a JVM crash:

$ pmd-bin-6.53.0/bin/run.sh designer

(java:51994): Gdk-CRITICAL **: 12:27:28.594: gdk_x11_display_set_window_scale: assertion 'GDK_IS_X11_DISPLAY (display)' failed

(java:51994): GLib-GObject-WARNING **: 12:27:28.594: invalid cast from 'GdkWaylandDisplay' to 'GdkX11Display'
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f1cb7cec53c, pid=51994, tid=52023
#
# JRE version: OpenJDK Runtime Environment Temurin-17.0.5+8 (17.0.5+8) (build 17.0.5+8)
# Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.5+8 (17.0.5+8, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# C  [libX11.so.6+0x2e53c]
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/andreas/Dokumente/Projekte/2023-PMD/binaries/hs_err_pid51994.log
#
# If you would like to submit a bug report, please visit:
#   https://github.com/adoptium/adoptium-support/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
pmd-bin-6.53.0/bin/run.sh: line 231: 51994 Aborted                 java ${HEAPSIZE} ${PMD_JAVA_OPTS} $(jre_specific_vm_options) -cp "${classpath}" "${CLASSNAME}" "$@"

Expected behavior
The designer should start without any problems.

Desktop (please complete the following information):

  • OS: Linux with Gnome 3 and GTK3 and Wayland
  • Java: 11 or 17
  • JavaFX: 11

Additional context

  • This seems to be the bug reported here: https://bugs.openjdk.org/browse/JDK-8210411
  • The workaround is, to set the environment variable GDK_BACKEND=x11 before starting the designer. This works for both java 11 and 17
  • It also works, when using OpenJFX 19 (both with java 11 and 17)

Horizontal scroll bars

Is your feature request related to a problem? Please describe.
When the source has long lines or the xpath expression is too long, there is no easy way to scroll.

Describe the solution you'd like
Scroll bar would be enough.

Describe alternatives you've considered
We could also wrap the lines (soft-wrap)

[ui] Designer font display

PMD designer v6.11.0

OS:Ubuntu16.04

2019-02-24 17-35-42

The font in the designer is too difficult to read,so i come for help.
thank you

TypeResolution is enabled by default in designer, but exported rule does not enable it

Describe the bug
When using a rule that has pmd-java:typeIs checks, the rules are working fine in the designer, however the exported rules are not working later on when testing the rules in Java unit tests.
The rule would look something like:

//PrimaryPrefix/Name[@Image[ends-with(., 'Instant.now')]][pmd-java:typeIs('java.time.Instant')]

and the example code:

package foo;

public class Hello {

public static void main(String[] args) {
    java.time.Instant.now();
}
}

This file fails validation as expected in the designer, but when the rule is exported, the rule no longer works, and violation is no longer reported. After debugging TypeIsFunction, it turned out that this happened because the rule was not set up to perform typeResolution. Manually adding the typeResolution="true" attribute to the rule definition appears to fix this problem.

To Reproduce
Steps to reproduce the behavior:

  1. Launch the designer from run.sh designer
  2. Specify the above code snippet for the example
  3. Use the rule listed above
  4. There should be a matching node
  5. Try to Export XPath to XML rule
  6. Notice how the exported rule does not have typeResolution="true" flag

Expected behavior
Either the UI should run the queries with typeResolution disabled (and have a visible enable flag), or the export view should add the required attribute to the rule definition.

Screenshots
Let me know if you need one.

Desktop (please complete the following information):

  • OS: macOS 10.14.6
  • Java:
    openjdk version "11.0.3" 2019-04-16
    OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.3+7)
    OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.3+7, mixed mode)

Upgrade openjfx to 17

Running on Mac OSX with a version of JavaFX older than 14 produces garbled text as shown below.

image

In #53 we introduce a check to avoid running unsupported JavaFX versions under Mac OSX, but that currently means it's only possible to develop under Mac OSX by manually changing the referenced JavaFX libraries.

Bumping org.openjfx to 14.0.2.1 fixes this, but unfortunately introduces a number of new issues.

Firstly, the first test to use CodeArea will fail, as internally it will try to animate the text, find that the JFX toolkit was never initialized and incur in a NPE. This is down to internal changes in JavaFX.

Fixing this by manually initializing the platform through Platform.startup(new Runnable() {}) will work locally, but fail in CI, as it can't run in headless mode. Therefore, it seems we need to introduce TestFX to properly support JavaFX testing and headless support.

Provide replacement attribute for deprecated XPath attributes

With pmd/pmd#4809 the method Attribute#replacementIfDeprecated() of a XPath attribute has been internalized.

Previously the Designer used this to display the info, what should be used instead.
Now, it will only display, that the attribute is deprecated, but no further info.

Ideally the designer would display the javadoc of the attributes... then we don't need this method as the public API.

With PMD 7.0.0, there won't be any deprecated attributes for the beginning, so it's not a blocker that this method is gone.

Designer won't start on macOS 11.3 (M1)

Describe the bug
Running the designer fails with the following output
(sorry if this is a dumb question, I couldn't find anything related to it and I'm not familiar with it)

run.sh designer                                                                    
Graphics Device initialization failed for :  es2, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
	at com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:280)
	at com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:222)
	at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:260)
	at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
	at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
	at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
	at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
	at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
	at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:94)
	at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)
	... 1 more
java.lang.RuntimeException: No toolkit found
	at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:272)
	at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
	at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
	at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
	at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
	at java.base/java.lang.Thread.run(Thread.java:831)

Additional context

  • OS: macOS 11.3, Macbook Air M1 2020
  • Java:
openjdk version "16" 2021-03-16
OpenJDK Runtime Environment (build 16+14)
OpenJDK 64-Bit Server VM (build 16+14, mixed mode)
  • JavaFX: 16 (although also tried with 11.0.2)

Designer doesn't start under Linux with Wayland

Describe the bug
When starting, JDK crashes. This happens when using Wayland. It works under X.

To Reproduce
bin/run.sh designer

Result:

(java:11347): Gdk-CRITICAL **: 10:23:53.849: gdk_x11_display_set_window_scale: assertion 'GDK_IS_X11_DISPLAY (display)' failed
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fde040c0afb, pid=11347, tid=11376
#
# JRE version: OpenJDK Runtime Environment (12.0.2+10) (build 12.0.2+10)
# Java VM: OpenJDK 64-Bit Server VM (12.0.2+10, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C  [libX11.so.6+0x2eafb]  XInternAtom+0x3b
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/andreas/PMD/source/pmd-github/pmd-dist/target/pmd-bin-6.18.0-SNAPSHOT/hs_err_pid11347.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
bin/run.sh: Zeile 218: 11347 Abgebrochen             java ${HEAPSIZE} ${PMD_JAVA_OPTS} $(jre_specific_vm_options) -cp "${classpath}" "${CLASSNAME}" "$@"

Workaround
Start with PMD_JAVA_OPTS=-Djdk.gtk.version=2 bin/run.sh designer

Additional context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.