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

Slf4j support #342

Merged
merged 9 commits into from
Feb 10, 2019
Merged

Slf4j support #342

merged 9 commits into from
Feb 10, 2019

Conversation

fvgh
Copy link
Member

@fvgh fvgh commented Jan 27, 2019

The PR provides the Spotless features with access to the SLF4J interface of the underlying build tool.

In case the build tools associated to a Spotless plugin does not provide SLF4J, the Spotless plugin must provide an implementation mapping to the logging feature of the build tool.

The changes fixing #236 and are the result of the discussion and POC provided for that issue.

For the new Eclipse-Base service, UTs have been provided. The Maven and Gradle plugin have been tested with a patched Spotless Eclipse-JDT. Since the changes to the Spotless LIB are quite simple, UTs are currently not foreseen.

@nedtwigg Please provide a new release of Eclipse-Base. It's change log still contains a TDB for the release date.

@fvgh fvgh requested a review from nedtwigg January 27, 2019 17:48
Copy link
Member

@nedtwigg nedtwigg left a comment

Choose a reason for hiding this comment

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

This looks great! My only requested changes are about documentation. We should keep it package-private to give ourselves as much flexibility as possible.

Also, the only way that lib consumers can access this is through the public API, so we should document this change there.

I would change the wording in JarState.getClassLoader which explains that the slf4j package will be punched through from the host classloader. I would also add a comment at FeatureClassLoader.BUILD_TOOLS_PACKAGES which says "if this ever changes, make sure to update docs at JarState.getClassLoader.

* the build tool and the provided URLs are ignored. This allows the feature to use
* distinct functionality of the build tool.
*/
public class FeatureClassLoader extends URLClassLoader {
Copy link
Member

Choose a reason for hiding this comment

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

Better to be package-private?

@@ -16,12 +16,9 @@
package com.diffplug.spotless.extra.eclipse.base.osgi;

import org.osgi.framework.Bundle;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.packageadmin.RequiredBundle;
Copy link
Member

Choose a reason for hiding this comment

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

What's up with this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, been lazy. Changed this because of deprecation warnings. But I looked it up again. Was actually a bug in an Open-JDK version I used on one system. The standard states that the @SuppressWarnings("deprecation") on the outer class should be sufficient. Will undo it.

//Configure SLF4J-Simple
System.setProperty(SimpleLogger.LOG_FILE_KEY, "System.out");
System.setProperty(SimpleLogger.SHOW_SHORT_LOG_NAME_KEY, "true");
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "warn");
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to remove these system props after the test is done?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since it is the only logging test... and the only test where the Eclipse-SLF4J logging service is temporarily applied... Let's leave it.

try {
ClassLoader.registerAsParallelCapable();
} catch (NoSuchMethodError ignore) {
// Not supported on Java 6
Copy link
Member

Choose a reason for hiding this comment

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

Any value in logging that this functionality is disabled because of the version of Java?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, the comment is misleading. The feature was introduced with Java 7. Will update the comment.

Copy link
Member

Choose a reason for hiding this comment

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

Also, Spotless requires Java 8 - heavy usage of lambdas and functional types. I'm fine with this backcompat if you want to keep it, but I'd also be fine with removing it if it's easier.

public void log(LogEntry entry) {
synchronized (listener) {
listener.stream().forEach(l -> l.logged(entry));
}
Copy link
Member

@JLLeitschuh JLLeitschuh Jan 29, 2019

Choose a reason for hiding this comment

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

Consider using a ReadWriteLock instead of synchronizing on listener.
If you use a ReadWriteLock you can have multiple threads logging at the same time.

Copy link
Member Author

@fvgh fvgh Jan 30, 2019

Choose a reason for hiding this comment

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

Principally a good idea, but I think Java 8 does not provide guards for it, or does it?
If not, I find to verbose (guards implementation) or to error prone (without guards).
Eclipse code checks whether debug level is enabled. The formatter anyhow just log warnings. And most of the underlying Eclipse functionality is stubbed by my framework. So this should really not be performance critical.
OK?

Copy link
Member

Choose a reason for hiding this comment

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

Could it be a bottleneck in a large multi-project build where spotless is running in parallel on a lot of projects?

Copy link
Member Author

Choose a reason for hiding this comment

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

Would doubt it. Warnings I saw so far end up in not formatted files (and then due to null-edits in exceptions the Spotless wrapper throw on purpose).
One reason I wanted this logger was that I found bugs in my wrapper implementation quite late and then realized that I just missed a warning.

@nedtwigg
Copy link
Member

nedtwigg commented Feb 5, 2019

Sorry for slow response @fvgh, I missed the notification about new commits. I just added a small commit tweaking the docs. This LGTM, feel free to merge whenever you'd like.

@nedtwigg
Copy link
Member

nedtwigg commented Feb 9, 2019

I've got a few hours to spare, to so I'm gonna take on some of our low-hanging fruit. Please let me know if there's anything you'd like me to publish from ext, or if you're ready for me to merge this one in @fvgh. Depending on how many issues I close out, we should have enough bug fixes and performance enhancements to warrant a release.

@fvgh fvgh merged commit 66dccd6 into master Feb 10, 2019
@fvgh fvgh deleted the slf4j_support branch February 10, 2019 20:04
@fvgh fvgh mentioned this pull request Apr 9, 2019
5 tasks
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