-
Notifications
You must be signed in to change notification settings - Fork 21
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
Recursively and continously watch for file change #35
Conversation
juseppe-cli/pom.xml
Outdated
@@ -3,7 +3,7 @@ | |||
<parent> | |||
<artifactId>juseppe</artifactId> | |||
<groupId>ru.lanwen.jenkins</groupId> | |||
<version>1.1.2-SNAPSHOT</version> | |||
<version>1.2-SNAPSHOT</version> |
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.
will be updated automatically on release, please revert
|
||
key.reset(); | ||
key = watcher.take(); | ||
private static final Logger LOG = LoggerFactory.getLogger(WatchFiles.class); |
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.
please avoid indentation changes - it is hard to review actual changes in this case...
@Override | ||
public void run() { | ||
LOG.info("Start to watch for changes: {}", path); | ||
while (true) { |
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.
don't do that ever - always put real condition (originally key != null
)
Path dir = keys.get(key); | ||
|
||
if (dir == null) { | ||
LOG.error(String.format("%s: WatchKey not recognized!!", getClass())); |
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.
why !!
? :) Key should be logged too, i think
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.
Honestly a typo :)
} | ||
|
||
for (WatchEvent<?> event : key.pollEvents()) { | ||
@SuppressWarnings("rawtypes") |
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.
put this on the method - its not very helpful to see it in the middle of the method
} catch (IOException e) { | ||
throw new RuntimeException(format("Can't read path %s", pluginsDir.toAbsolutePath()), e); | ||
} | ||
try (Stream<Path> paths = Files.walk(pluginsDir)) { |
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.
will it be recursive walk?
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.
Yes it will
Thanks for changes, really appreciate this functionality! But please fix some style issues |
Also, whould you mind to add ability to disable recursive scan (to allow for example serve different plugins from different folders in one tree with different juseppes - some can already use this scheme)19:10, 6 сентября 2017 г., Valentine Nwachukwu <[email protected]>:@valdiz777 commented on this pull request.
In juseppe-core/src/main/java/ru/lanwen/jenkins/juseppe/gen/source/PathPluginSource.java:
- return StreamSupport.stream(paths.spliterator(), false).map(path -> {
- try {
- LOG.trace("Process file {}", path);
-
- return HPI.loadHPI(path.toFile())
- .withUrl(pluginsDir.relativize(path).toString());
-
- } catch (Exception e) {
- LOG.error("Fail to get the {} info", path.toAbsolutePath(), e);
- return null;
- }
- }).filter(Objects::nonNull).collect(Collectors.toList());
- } catch (IOException e) {
- throw new RuntimeException(format("Can't read path %s", pluginsDir.toAbsolutePath()), e);
- }
+ try (Stream<Path> paths = Files.walk(pluginsDir)) {
Yes it will
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or mute the thread.
|
Updated |
Path dir = keys.get(key); | ||
|
||
if (dir == null) { | ||
LOG.error(String.format("%s: WatchKey: %s is not recognized!", getClass(), key.toString())); |
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.
one more thing - sorry for not noticed it earlier
slf4j supports placeholders with {}
instead of %s
- so you can omit String.format
) { | ||
@Override | ||
public String resolved() { | ||
return String.valueOf(populated().getPort()); |
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.
should be getRecursiveWatch
i think
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.
yes you're right.
For anyone looking for this functionality. This will enable people to be able to structure their local repositories however they wish.