Create custom analyze actions - ml-in-programming/MetricsReloaded GitHub Wiki
- Create class inherited from BaseAnalysisAction (see
com.sixrr.metrics.plugin.ProjectMetricsActionfor example) - Override
analyze()method. This method will be called after pressing button "Ok" in plugin. - Optional: override
getAdditionalActionSettings()method. In this method you can create UI components that will be displayed after "Metrics scope" in plugin. - In
src\META-INF\plugin.xmlin tagactionsreplace propertyclassto name of created class.
Metrics calculation runs in analyze() by call method execute() from MetricsExecutionContextImpl class. You need MetricsProfile and MetricsResultsHolder objects. You can get metrics profile using pre-built profiles (this is the only way i know for now). You just need create pre-built profile in JavaMetricProvider and add it to the list in getPrebuiltProfiles(). After this, you can get your profile by name using MetricsProfileRepository.getInstance().getProfileForName(). Also you can use ProfileSelectionPanel in overriding method getAdditionalActionSettings() and choose profile in runtime. This panel sets choosen profile in MetricsProfileRepository, so you can get choosen profile by getCurrentProfile() call. As result holder you can use MetricsRunImpl in the same way as in ProjectMetricsAction.
Due to the fact that calculating metrics is a background task, you need to override onFinish() method for access to results. MetricsResultsHolder keeps metrics results, but it cannot return results, so we will use MetricsRun interface. You can get results for specific category by 'getResultsForCategory()' call. It can be represented as a table where rows are results of all metric (for this category) for specific object. getMeasuredObjects() returns you names of all objects for which was calculated at least one metric. getMetrics() returns you all metrics for current category, getValueForMetric() returns you value of specific metric for specific object.