Search in sources :

Example 1 with JavaCoverageEnabledConfiguration

use of com.intellij.execution.configurations.coverage.JavaCoverageEnabledConfiguration in project intellij-community by JetBrains.

the class CoverageJavaRunConfigurationExtension method updateJavaParameters.

public void updateJavaParameters(RunConfigurationBase configuration, JavaParameters params, RunnerSettings runnerSettings) {
    if (!isApplicableFor(configuration)) {
        return;
    }
    final JavaCoverageEnabledConfiguration coverageConfig = JavaCoverageEnabledConfiguration.getFrom(configuration);
    //noinspection ConstantConditions
    coverageConfig.setCurrentCoverageSuite(null);
    final CoverageRunner coverageRunner = coverageConfig.getCoverageRunner();
    if (runnerSettings instanceof CoverageRunnerData && coverageRunner != null) {
        final CoverageDataManager coverageDataManager = CoverageDataManager.getInstance(configuration.getProject());
        coverageConfig.setCurrentCoverageSuite(coverageDataManager.addCoverageSuite(coverageConfig));
        coverageConfig.appendCoverageArgument(configuration, params);
        final Sdk jdk = params.getJdk();
        if (jdk != null && JavaSdk.getInstance().isOfVersionOrHigher(jdk, JavaSdkVersion.JDK_1_7) && coverageRunner instanceof JavaCoverageRunner && !((JavaCoverageRunner) coverageRunner).isJdk7Compatible()) {
            Notifications.Bus.notify(new Notification("Coverage", "Coverage instrumentation is not fully compatible with JDK 7", coverageRunner.getPresentableName() + " coverage instrumentation can lead to java.lang.VerifyError errors with JDK 7. If so, please try IDEA coverage runner.", NotificationType.WARNING));
        }
    }
}
Also used : JavaCoverageEnabledConfiguration(com.intellij.execution.configurations.coverage.JavaCoverageEnabledConfiguration) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Notification(com.intellij.notification.Notification)

Example 2 with JavaCoverageEnabledConfiguration

use of com.intellij.execution.configurations.coverage.JavaCoverageEnabledConfiguration in project intellij-community by JetBrains.

the class CoverageJavaRunConfigurationExtension method wrapElementListener.

@Override
public RefactoringElementListener wrapElementListener(PsiElement element, RunConfigurationBase configuration, RefactoringElementListener listener) {
    if (!isApplicableFor(configuration)) {
        return listener;
    }
    final JavaCoverageEnabledConfiguration coverageEnabledConfiguration = JavaCoverageEnabledConfiguration.getFrom(configuration);
    if (coverageEnabledConfiguration != null) {
        final Project project = configuration.getProject();
        final ClassFilter[] patterns = coverageEnabledConfiguration.getCoveragePatterns();
        final String[] filters = getFilters(coverageEnabledConfiguration);
        if (patterns != null) {
            assert filters != null;
            if (element instanceof PsiClass) {
                final String qualifiedName = ((PsiClass) element).getQualifiedName();
                final int idx = ArrayUtil.find(filters, qualifiedName);
                if (idx > -1) {
                    final RefactoringListeners.Accessor<PsiClass> accessor = new MyClassAccessor(project, patterns, idx, filters);
                    final RefactoringElementListener classListener = RefactoringListeners.getClassOrPackageListener(element, accessor);
                    if (classListener != null) {
                        listener = appendListener(listener, classListener);
                    }
                } else if (qualifiedName != null) {
                    final String packageName = StringUtil.getPackageName(qualifiedName);
                    if (!StringUtil.isEmpty(packageName)) {
                        for (int i = 0; i < filters.length; i++) {
                            String filter = filters[i];
                            if (filter.equals(packageName + ".*")) {
                                listener = appendListener(listener, new RefactoringListeners.RefactorPackageByClass(new MyClassAccessor(project, patterns, i, filters)));
                                break;
                            }
                        }
                    }
                }
            } else if (element instanceof PsiPackage) {
                final String qualifiedName = ((PsiPackage) element).getQualifiedName();
                for (int i = 0, filtersLength = filters.length; i < filtersLength; i++) {
                    if (filters[i].startsWith(qualifiedName + ".")) {
                        final RefactoringElementListener packageListener;
                        if (filters[i].endsWith("*")) {
                            packageListener = RefactoringListeners.getListener((PsiPackage) element, new MyPackageAccessor(project, patterns, i, filters));
                        } else {
                            packageListener = RefactoringListeners.getClassOrPackageListener(element, new MyClassAccessor(project, patterns, i, filters));
                        }
                        if (packageListener != null) {
                            listener = appendListener(listener, packageListener);
                        }
                    }
                }
            }
        }
    }
    return listener;
}
Also used : RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) JavaCoverageEnabledConfiguration(com.intellij.execution.configurations.coverage.JavaCoverageEnabledConfiguration) Project(com.intellij.openapi.project.Project) ClassFilter(com.intellij.ui.classFilter.ClassFilter) RefactoringListeners(com.intellij.execution.junit.RefactoringListeners)

Aggregations

JavaCoverageEnabledConfiguration (com.intellij.execution.configurations.coverage.JavaCoverageEnabledConfiguration)2 RefactoringListeners (com.intellij.execution.junit.RefactoringListeners)1 Notification (com.intellij.notification.Notification)1 Project (com.intellij.openapi.project.Project)1 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 PsiClass (com.intellij.psi.PsiClass)1 PsiPackage (com.intellij.psi.PsiPackage)1 RefactoringElementListener (com.intellij.refactoring.listeners.RefactoringElementListener)1 ClassFilter (com.intellij.ui.classFilter.ClassFilter)1