crossminer / scava

https://eclipse.org/scava/
Eclipse Public License 2.0
18 stars 13 forks source link

API task creation with list of metrics dependency #345

Closed borisbaldassari closed 4 years ago

borisbaldassari commented 5 years ago

When creating a new analysis task for a project using the platform API, one has to provide the list of the metrics she wants, and all their (transitive) dependencies. It is a time-consuming and difficult task, since one has to manually look for dependencies in the metricProviders API call and rebuild the full tree -- which can be quite large.

In the web admin UI, we simply need to add the metrics we need and the dependencies are automatically computed.. We need the same functionality in the API, since it is not really workable when mass-importing or creating projects..

borisbaldassari commented 5 years ago

As an example for the sentiment.SentimentHistoricMetricProvider metric we have the following tree:

creat89 commented 5 years ago

Hello,

I agree with Boris that manually adding the dependencies of metrics is very tiring. In my case, as many things I test them from Eclipse rather than the UI (before pushing them to Jenkins), I have a code that add to MongoDB the metrics as well as their dependencies automatically. Here is the code that I use to get the dependencies:

private static List<String> getMetricDependencies(List<String> metricProviders, Boolean print) throws InstantiationException, IllegalAccessException, ClassNotFoundException
    {
        Set<String> metricsUnique = new HashSet<String>();
        while(metricProviders.size()>0)
        {
            List<String> tempMetricProviders = new ArrayList<String>();
            for(String metricProviderName : metricProviders)
            {
                if(metricProviderName.contains("rascal"))
                    metricsUnique.add(metricProviderName);
                else
                {
                    Class metricProviderClass = Class.forName(metricProviderName);
                    IMetricProvider metricProvider = (IMetricProvider) metricProviderClass.newInstance();
                    metricsUnique.add(metricProvider.getIdentifier());
                    for(String dependency : metricProvider.getIdentifiersOfUses())
                    {
                        tempMetricProviders.add(dependency);
                    }
                }
            }
            metricProviders=tempMetricProviders;
        }
        if(print)
            printMetricsToBeExecuted(metricsUnique);
        return new ArrayList<String>(metricsUnique);

    }

So, if, for example, I want to just analyze the historic metrics for sentiment, I just add that to List<String> metricProviders and call the method getMetricDependencies.

Maybe the charged of the API could add a similar function.

ambpro commented 5 years ago

Hi @borisbaldassari , the commit cc6f24c should fix this issue.

borisbaldassari commented 5 years ago

Hi @ambpro, you rock! I'll try that asap. Thanks for the work!

borisbaldassari commented 4 years ago

Fixed. :-)