-
-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AddonFinderProcess fixes #4061
AddonFinderProcess fixes #4061
Conversation
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@holgerfriedrich / @mherwege for info.. |
@holgerfriedrich as mentioned elsewhere I have some doubts about whether your usage of Therefore I think the first code block quoted below should probably be replaced by the second code block below. However I did not make that change (yet) because you may have a good explanation about why Doubtful Code
Possible Replacement
EDIT: below is a log on Linux showing
|
I checked both of my test setups:
Regarding scripts: On Windows, we just get the Python executable, not the script which is called... It seems we cannot get the arguments or commandLine using this API. Or have I overlooked something again? |
Split will certainly NOT work on Windows since path names of the executable may include spaces. However Windows always has the command populated so split is never actually needed. By contrast on Linux path names cannot contain spaces. So split always works.
That seems indeed to be the case. |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@holgerfriedrich -- I made some changes today. The Windows
Other OS
|
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@holgerfriedrich apropos Windows there is a thread on StackOverflow (below) .. it contains a post that suggests a hack to get the command line .. but I am not sure if we should go that far. => WDYT? https://stackoverflow.com/questions/46767418/how-to-get-commandline-arguments-of-process-in-java-9 EDIT: it seems the Windows 'wmic' console command is anyway deprecated, and will be removed from future Windows versions. |
I think this is too much of a hack. Too much platform specific complexity, unless we have a clear need for that. |
@holgerfriedrich just so you know: the change that I made from args[0] to commandLine[0] means that now on Linux systems those bindings that already have discovery info in their addons.xml will now be properly suggested (they were not suggested previously) e.g. MQTT .. |
Not sure if the implementation of Linux paths can contain spaces as well, I just tried out and got a |
👍 Maybe we can ask to get this cherry picked to the 4.1 branch. I have not yet looked at the code, maybe I can do later today. |
Yes. That is the case.
Ok. I think I may have a solution for that. We could split the commandLine at the position where the string in arg[0] is located. Or on space if args are null.. |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
See my latest commit. Please read the javadoc.. |
...rocess/src/main/java/org/openhab/core/config/discovery/addon/process/ProcessAddonFinder.java
Outdated
Show resolved
Hide resolved
Is the path in the command relevant? I would argue it is not because you do not want to match on something that can be different by installation. If not, you could split on file separator character first before separating on whitespace. That would eliminate the paths with whitespace problem.
|
Who knows? Depending on the addon, it may indeed be so. So I will try to keep it. Also splitting on slash characters would IMHO make the parsing yet more complex. |
I think you should be able to do it with one regex (not tested):
Of course the pattern can be compiled in advance. |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@mherwege I did test it .. and unfortunately it doesn't work. Anyway, I just pushed another commit that I think resolves the issue in faster resp. better way. |
...rocess/src/main/java/org/openhab/core/config/discovery/addon/process/ProcessAddonFinder.java
Show resolved
Hide resolved
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@mherwege I think for safety sake I need to check that lastIndexOf(args[i]) does not return -1 .. it might be the case that args has a String that is somehow not in the commandLine.. |
Would be unexpected, but indeed, defensive programming. |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrewfg I tried parts of the code with Linux and Windows.
It seems that Set is no longer removing the duplicates.
Could you pls double check?
For me, Windows returned dozens of (null, null), and also other duplicate objects, in spite of the conversion .collect(Collectors.toUnmodifiableSet());
.
May be caused by our helper lass which does not properly implement comparison.
Using a record is one way to fix this.
...rocess/src/main/java/org/openhab/core/config/discovery/addon/process/ProcessAddonFinder.java
Outdated
Show resolved
Hide resolved
...rocess/src/main/java/org/openhab/core/config/discovery/addon/process/ProcessAddonFinder.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
...rocess/src/main/java/org/openhab/core/config/discovery/addon/process/ProcessAddonFinder.java
Show resolved
Hide resolved
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
...rocess/src/main/java/org/openhab/core/config/discovery/addon/process/ProcessAddonFinder.java
Outdated
Show resolved
Hide resolved
...rocess/src/main/java/org/openhab/core/config/discovery/addon/process/ProcessAddonFinder.java
Outdated
Show resolved
Hide resolved
...rocess/src/main/java/org/openhab/core/config/discovery/addon/process/ProcessAddonFinder.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@mherwege / @holgerfriedrich UPDATE: OK all is good. (My test environment was wrong..) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I just copied the record into my plugin for a quick test and tried it on Linux and Windows, works fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes!
See #3904 (comment)
Signed-off-by: Andrew Fiddian-Green software@whitebear.ch