Skip to content
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

Merged
merged 14 commits into from
Sep 8, 2017

Conversation

valdiz777
Copy link

For anyone looking for this functionality. This will enable people to be able to structure their local repositories however they wish.

@@ -3,7 +3,7 @@
<parent>
<artifactId>juseppe</artifactId>
<groupId>ru.lanwen.jenkins</groupId>
<version>1.1.2-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
Copy link
Member

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);
Copy link
Member

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) {
Copy link
Member

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()));
Copy link
Member

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

Copy link
Author

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")
Copy link
Member

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)) {
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it will

@lanwen
Copy link
Member

lanwen commented Sep 6, 2017

Thanks for changes, really appreciate this functionality! But please fix some style issues

@lanwen
Copy link
Member

lanwen commented Sep 6, 2017 via email

@valdiz777
Copy link
Author

Updated

Path dir = keys.get(key);

if (dir == null) {
LOG.error(String.format("%s: WatchKey: %s is not recognized!", getClass(), key.toString()));
Copy link
Member

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());
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes you're right.

@lanwen lanwen merged commit 5c5e240 into jenkinsci:master Sep 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants