Open sewe opened 7 years ago
- I haven’t found a way to get at a
UserPreferences
object from within aDetector
Found a way:
AnalysisContext.currentAnalysisContext().getSourceFinder().getProject().getConfiguration()
Given the length of the call chain, I’m not sure whether I would call this a “best practice,” however.
Yep. It would make more sense if we would have this: AnalysisContext.currentAnalysisContext().getProject().getConfiguration()
This issue is meant to discuss best practices for how to pass additional, user-configurable options to a detector. As far as I can see, there are three alternatives to do so:
-jvmArgs -Dkey=value
command line option)-userPrefs
command line option)<GlobalOption>
(-choosePlugins
command line option)The preferred alternative should offer a straight-forward way to access the value in the detector:
SystemProperties.getProperty(String)
UserPreferences
object from within aDetector
DetectorCollectionFactory.getGlobalOption
)Moreover, the preferred alternative should not only work when SpotBugs is invoked from the command line, but should also be settable from within Eclipse, e.g., through a preference page.
findbugsPlugins
extension point to load a SpotBugs plugin doesn’t mean that the surrounding Eclipse plug-in wrapper’s Activator is run; so you can’t set the system property anew on demand when the wrapper is activated.)FindbugsPlugin.getUserPreferences(...)
andsaveUserPreferences(...)
called from the preference page or even (per-project) from the project’s Properties pageAm I missing any other alternatives? How can alternatives 2 and 3 above access the configured value in the detector? And which alternative should in your opinion be considered a best practice?