PDE should not warn if resource URI of unknown scheme cannot be found#2032
Conversation
|
Could someone help my try to understand the test failures? I would like to see the test details for judgment on whether it is possibly caused by my changes or not - Thanks! |
|
Any help would be appreciated. |
cfd0eec to
dd902cc
Compare
HannesWell
left a comment
There was a problem hiding this comment.
Sorry for the late reply, the past few days have been busy.
I have added a few general comments, altough I think we should revisite the proposed solution as discussed in #2031 (comment) ff.
But still I think this is a good enhancement if we find a suitable solution that fits all cases.
| if (bundleJar == null && isValidUriOfUnknownProtocol(location)) { | ||
| return true; | ||
| } | ||
|
|
||
| return false; |
There was a problem hiding this comment.
This can be more compact, as if true then return true is a bit cumbersome.
| if (bundleJar == null && isValidUriOfUnknownProtocol(location)) { | |
| return true; | |
| } | |
| return false; | |
| return bundleJar == null && isValidUriOfUnknownProtocol(location); |
| boolean isKnownProtocol = false; | ||
| // Exclude those URI forms where we have already special | ||
| // handling for or where we are sure that they are known URLs: | ||
| for (String knownScheme : KNOWN_URI_SCHEMES) { | ||
| if (knownScheme.equalsIgnoreCase(scheme)) { | ||
| isKnownProtocol = true; | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
I know large parts of the PDE code-base are still in an old Java style, but that shouldn't prevent us from using newer, more readable styles in new or modified parts of the code:
| boolean isKnownProtocol = false; | |
| // Exclude those URI forms where we have already special | |
| // handling for or where we are sure that they are known URLs: | |
| for (String knownScheme : KNOWN_URI_SCHEMES) { | |
| if (knownScheme.equalsIgnoreCase(scheme)) { | |
| isKnownProtocol = true; | |
| break; | |
| } | |
| } | |
| boolean isKnownProtocol = KNOWN_URI_SCHEMES.stream().anyMatch(scheme::equalsIgnoreCase); |
ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/ExtensionsErrorReporter.java
Outdated
Show resolved
Hide resolved
|
I don't understand how I got this merge mess. Any suggestions? |
Don't merge but rebase your commit on top of master. |
|
And, once you have PR started, use amend and force push for any subsequent changes. Sometimes when I get into this state, I rename the branch to which I pushed my PR changes. check out master, do a pull, create a new branch with exactly the same name as the one I was using, apply the changes, then commit and force push by my fork. This will overwrite all the commits in that branch in your force and will update this existing PR. |
|
Actually I did ammend, but somehow a previous PULL must have happened. I follow now Ed's approach, thank you! |
e94873d to
e3d5fea
Compare
|
@HannesWell : A friendly reminder for a second review - Thanks! |
I plan to have a look at it this evening. |
HannesWell
left a comment
There was a problem hiding this comment.
Thank you for the update and your patience (Sorry last week was busy).
Generally this looks already quite good, but the new preference page don't look nice at the moment and the method that performs the actual check can be simpler.
Please see my comments below.
| private static Key[] fgAllKeys = {KEY_F_UNRESOLVED_FEATURES, KEY_F_UNRESOLVED_PLUGINS, KEY_P_BUILD, KEY_P_BUILD_MISSING_OUTPUT, KEY_P_BUILD_SOURCE_LIBRARY, KEY_P_BUILD_OUTPUT_LIBRARY, KEY_P_BUILD_SRC_INCLUDES, KEY_P_BUILD_BIN_INCLUDES, KEY_P_BUILD_JAVA_COMPLIANCE, KEY_P_BUILD_JAVA_COMPILER, KEY_P_BUILD_ENCODINGS, KEY_P_INTERNAL, KEY_P_SERVICE_COMP_WITHOUT_LAZY, KEY_P_NO_AUTOMATIC_MODULE_NAME, KEY_P_DEPRECATED, KEY_P_DISCOURAGED_CLASS, KEY_P_INCOMPATIBLE_ENV, KEY_P_MISSING_EXPORT_PKGS, KEY_P_NO_REQUIRED_ATT, KEY_P_NOT_EXTERNALIZED, KEY_P_UNKNOWN_ATTRIBUTE, KEY_P_UNKNOWN_CLASS, KEY_P_UNKNOWN_ELEMENT, KEY_P_UNKNOWN_IDENTIFIER, KEY_P_UNKNOWN_RESOURCE, KEY_P_UNRESOLVED_EX_POINTS, KEY_P_UNRESOLVED_IMPORTS, KEY_P_VERSION_EXP_PKG, KEY_P_VERSION_IMP_PKG, KEY_P_VERSION_REQ_BUNDLE, KEY_P_VERSION_EXEC_ENV_TOO_LOW, KEY_S_CREATE_DOCS, KEY_S_DOC_FOLDER, KEY_S_OPEN_TAGS }; | ||
| private static Key[] fgAllKeys = { KEY_F_UNRESOLVED_FEATURES, KEY_F_UNRESOLVED_PLUGINS, KEY_P_BUILD, | ||
| KEY_P_BUILD_MISSING_OUTPUT, KEY_P_BUILD_SOURCE_LIBRARY, KEY_P_BUILD_OUTPUT_LIBRARY, | ||
| KEY_P_BUILD_SRC_INCLUDES, KEY_P_BUILD_BIN_INCLUDES, KEY_P_BUILD_JAVA_COMPLIANCE, | ||
| KEY_P_BUILD_JAVA_COMPILER, KEY_P_BUILD_ENCODINGS, KEY_P_INTERNAL, KEY_P_SERVICE_COMP_WITHOUT_LAZY, | ||
| KEY_P_NO_AUTOMATIC_MODULE_NAME, KEY_P_DEPRECATED, KEY_P_DISCOURAGED_CLASS, KEY_P_INCOMPATIBLE_ENV, | ||
| KEY_P_MISSING_EXPORT_PKGS, KEY_P_NO_REQUIRED_ATT, KEY_P_NOT_EXTERNALIZED, KEY_P_UNKNOWN_ATTRIBUTE, | ||
| KEY_P_UNKNOWN_CLASS, KEY_P_UNKNOWN_ELEMENT, KEY_P_UNKNOWN_IDENTIFIER, KEY_P_UNKNOWN_RESOURCE, | ||
| KEY_P_IGNORED_RESOURCE_PROTOCOLS, KEY_P_UNRESOLVED_EX_POINTS, KEY_P_UNRESOLVED_IMPORTS, | ||
| KEY_P_VERSION_EXP_PKG, KEY_P_VERSION_IMP_PKG, KEY_P_VERSION_REQ_BUNDLE, | ||
| KEY_P_VERSION_EXEC_ENV_TOO_LOW, KEY_S_CREATE_DOCS, KEY_S_DOC_FOLDER, KEY_S_OPEN_TAGS }; |
There was a problem hiding this comment.
Please don't indent this field so deep.
I know this is result of just formatting the fields lines, but this is just because the previous field isn't properly formatted (and somehow this confuses the formattter).
This can be avoided if you format the field above too.
If you want to you can also include a 'formatting'-fix of the previous field in this change.
There was a problem hiding this comment.
Thanks for the hint how to solve this - done.
There was a problem hiding this comment.
Great 👍🏽
Since you've modified this and the field above already, you could make it final too.
| Composite comp = SWTFactory.createComposite(client, 2, 2, GridData.FILL_HORIZONTAL, 0, 0); | ||
| createTextControl(comp, PDEUIMessages.compilers_p_ignored_uri_protocols, | ||
| KEY_P_IGNORED_RESOURCE_PROTOCOLS, CompilerFlags.PLUGIN_FLAGS); | ||
| SWTFactory.createLabel(comp, PDEUIMessages.compilers_p_ignored_uri_protocols_details, 2); |
There was a problem hiding this comment.
On Windows-11 this doesn't look good:

The label shouldn't be in bold case and I think the details shouldn't be in a separate line. Instead I think you should provide the details as a tool-tip. It could be set after returning the created Text from the createTextControl() method.
I cannot tell immediately why the label is bold, but maybe it's related to how the previous elements are created (cascaded into each other).
There was a problem hiding this comment.
Oops, I'll need to look deeper into that - tomorrow.
There was a problem hiding this comment.
I understand now where the bold font is coming from: It is caused by the usage of the SWTFactory methods which all have in common to set the font of the created widget based on the font of its parent. But the parent in this case is the one created from createExpansibleComposite, which sets a bold font. This explains why the existing methods in PDECompilersConfigurationBlock such as createComboControl do not use the SWTFactory methods for label and combo creation. My current approach to fix this is to create my intermediate Composite manually without SWTFactory being involved and intentionally do not set the parent font. Is this an acceptable approach (See my last commit) or what would you suggest as an alternative here?
There was a problem hiding this comment.
Good investigation. Now this looks nice. :)
| final var ignoredProtocols = CompilerFlags.getString(fProject, CompilerFlags.P_IGNORED_RESOURCE_PROTOCOLS); | ||
| final var st = new StringTokenizer(ignoredProtocols, ","); //$NON-NLS-1$ | ||
| if (!st.hasMoreTokens()) { | ||
| return false; | ||
| } | ||
| try { | ||
| final var uri = new URI(location); | ||
| if (uri.isAbsolute()) { | ||
| // Exclude syntactically valid file paths that are also | ||
| // syntactically valid URIs, such as "C:/somePath" where | ||
| // "C" would be interpreted as URI protocol: | ||
| try { | ||
| java.nio.file.Path.of(location); | ||
| } catch (java.nio.file.InvalidPathException e) { | ||
| // OK, location does not match a file path | ||
| final var scheme = uri.getScheme(); | ||
| while (st.hasMoreElements()) { | ||
| String protocol = st.nextToken().trim(); | ||
| if (scheme.equalsIgnoreCase(protocol)) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } catch (URISyntaxException e) { | ||
| // location is not a valid URI | ||
| } | ||
| return false; |
There was a problem hiding this comment.
As RFC 2396 specifies that the scheme must be followed by a colon (for absolute URIs) I think this entire method can be simplified to just
| final var ignoredProtocols = CompilerFlags.getString(fProject, CompilerFlags.P_IGNORED_RESOURCE_PROTOCOLS); | |
| final var st = new StringTokenizer(ignoredProtocols, ","); //$NON-NLS-1$ | |
| if (!st.hasMoreTokens()) { | |
| return false; | |
| } | |
| try { | |
| final var uri = new URI(location); | |
| if (uri.isAbsolute()) { | |
| // Exclude syntactically valid file paths that are also | |
| // syntactically valid URIs, such as "C:/somePath" where | |
| // "C" would be interpreted as URI protocol: | |
| try { | |
| java.nio.file.Path.of(location); | |
| } catch (java.nio.file.InvalidPathException e) { | |
| // OK, location does not match a file path | |
| final var scheme = uri.getScheme(); | |
| while (st.hasMoreElements()) { | |
| String protocol = st.nextToken().trim(); | |
| if (scheme.equalsIgnoreCase(protocol)) { | |
| return true; | |
| } | |
| } | |
| } | |
| } | |
| } catch (URISyntaxException e) { | |
| // location is not a valid URI | |
| } | |
| return false; | |
| String ignoredProtocols = CompilerFlags.getString(fProject, CompilerFlags.P_IGNORED_RESOURCE_PROTOCOLS); | |
| if (ignoredProtocols.isEmpty()) { | |
| return false; | |
| } | |
| return Arrays.stream(ignoredProtocols.split(",")).map(p -> p + ":").anyMatch(location::startsWith); //$NON-NLS-1$ //$NON-NLS-2$ |
I.e. it just checks if the location starts with any protocol plus a colon.
There was a problem hiding this comment.
There are two issues with this alternative solution: (1) It doesn't trim any leading or trailing spaces (and this seems to be done everywhere else) and (2) it doesn't do a case-insensitive match (protocol comparison is defined to be case-insensitive). So I'm working on a modified approach now.
There was a problem hiding this comment.
That's both correct.
But your modifications to refine this approach look good. :)
15f65d5 to
e67db37
Compare
|
@HannesWell Could you please proceed with the review? |
HannesWell
left a comment
There was a problem hiding this comment.
Thank you for the update.
The UI looks better now, but it still has to be improved further. Please see my remarks below.
Do you also have a simple example at hand to try out the possibly ignored URI protocols, i.e. a corresponding plugin.xml snippet?
| Composite comp = createComposite(client, 2, 2, GridData.FILL_HORIZONTAL, 0, 0); | ||
| createTextControl(comp, PDEUIMessages.compilers_p_ignored_uri_protocols, | ||
| KEY_P_IGNORED_RESOURCE_PROTOCOLS, CompilerFlags.PLUGIN_FLAGS); | ||
| SWTFactory.createLabel(comp, PDEUIMessages.compilers_p_ignored_uri_protocols_details, 2); |
There was a problem hiding this comment.
This label should be a tool-tip of the text field instead.
Not having an extra description field makes the UI cleaner.
And it maybe makes the code even simpler as you can maybe even skip the extra container/Composite. But I'm not sure about the latter and it would have to be investigated/tried out.
You can get the text-field by returning it from the createTextControl() method.
There was a problem hiding this comment.
This label should be a tool-tip of the text field instead. Not having an extra description field makes the UI cleaner.
All existing comparable text fields in the Eclipse wizards providing comma-separated lists use an extra label to explain the usage. See for example:
In the File Search dialog we have a comparable pattern:

In the rarer case were no such a label is provided the Eclipse UI does not show a tool tip. I would like to point these out before we change the design. So, given this additional information, do we still want to user your alternative approach?
There was a problem hiding this comment.
This label should be a tool-tip of the text field instead. Not having an extra description field makes the UI cleaner.
All existing comparable text fields in the Eclipse wizards providing comma-separated lists use an extra label to explain the usage. See for example:
In the File Search dialog we have a comparable pattern:

In the rarer case were no such a label is provided the Eclipse UI does not show a tool tip. I would like to point these out before we change the design. So, given this additional information, do we still want to user your alternative approach?
There was a problem hiding this comment.
In the rarer case were no such a label is provided the Eclipse UI does not show a tool tip. I would like to point these out before we change the design. So, given this additional information, do we still want to user your alternative approach?
Thanks for the analysis and comparison.
I would argue that wizards are also a bit different preferences and I have to admit it looked a bit strange to me at this point respectively it stand out from the rest, which I think shouldn't be the case. If you really prefer to have the description as a label, maybe it's better to have it above?
There was a problem hiding this comment.
I'm personally completely open to any direction. I just pointed out the seemingly existing practice so that we have a complete picture to argue about and I will apply any preferred UI approach that you reviewers would like to see.
There was a problem hiding this comment.
I have now moved the explanatory label before the text field in my last ammendment. Does this look better to you? (It doesn't to me but again, please decide yourself)
There was a problem hiding this comment.
I just pointed out the seemingly existing practice so that we have a complete picture to argue about and I will apply any preferred UI approach that you reviewers would like to see.
I have looked through the other pages in the PDE section and not found a fully comparable case and I still have the impression that a separate label text 'breaks the pattern' on this page compared to the other entries (which admittedly are all similar but different to this one):
With my proposal to use a tool tip, I still think this fits best into the existing page, even though this is handled differently in some other wizards:
...lipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/PDECompilersConfigurationBlock.java
Show resolved
Hide resolved
|
@HannesWell Could you please proceed with the review?
Yes, in the original example is a complete example project, here is a link to it. |
e0a569c to
d86589b
Compare
d86589b to
13c3829
Compare
13c3829 to
e7f3431
Compare
HannesWell
left a comment
There was a problem hiding this comment.
@Dani-Hub I have now pushed an update to your branch that uses the a tool-tip to add the explanation to the preference, as per other thread in this PR.
Furthermore I added a default value initialization which was missing and broke the restore of defaults for the PDE preference page that hosts the new option.
Also thank you for providing your example, that showed that this works as intended.
With all that the current state is ready for submission from my POV.
Unless you'd like to have things differently I'll submit this tomorrow evening.
If you want to push further updates to this PR, please make sure to fetch the latest state from your fork first.
Looks good to me!
Thanks for that fix!
No, I have nothing to change, thanks for your help! |
|
Great, submitting it then. |
Fixes #2031