Search in sources :

Example 1 with CoverageRunner

use of com.intellij.coverage.CoverageRunner in project intellij-community by JetBrains.

the class CoverageConfigurable method resetEditorFrom.

protected void resetEditorFrom(@NotNull final RunConfigurationBase runConfiguration) {
    final boolean isJre50;
    if (runConfiguration instanceof CommonJavaRunConfigurationParameters && myVersionDetector.isJre50Configured((CommonJavaRunConfigurationParameters) runConfiguration)) {
        isJre50 = true;
    } else if (runConfiguration instanceof ModuleBasedConfiguration) {
        isJre50 = myVersionDetector.isModuleJre50Configured((ModuleBasedConfiguration) runConfiguration);
    } else {
        isJre50 = true;
    }
    myCoverageNotSupportedLabel.setVisible(!isJre50);
    final JavaCoverageEnabledConfiguration configuration = (JavaCoverageEnabledConfiguration) CoverageEnabledConfiguration.getOrCreate(runConfiguration);
    CoverageRunner runner = configuration.getCoverageRunner();
    if (runner != null) {
        myCoverageRunnerCb.setSelectedItem(new CoverageRunnerItem(runner));
    } else {
        final String runnerId = configuration.getRunnerId();
        if (runnerId != null) {
            final CoverageRunnerItem runnerItem = new CoverageRunnerItem(runnerId);
            final DefaultComboBoxModel model = (DefaultComboBoxModel) myCoverageRunnerCb.getModel();
            if (model.getIndexOf(runnerItem) == -1) {
                model.addElement(runnerItem);
            }
            myCoverageRunnerCb.setSelectedItem(runnerItem);
        } else {
            myCoverageRunnerCb.setSelectedIndex(0);
        }
        runner = ((CoverageRunnerItem) myCoverageRunnerCb.getSelectedItem()).getRunner();
    }
    UIUtil.setEnabled(myRunnerPanel, isJre50, true);
    myClassFilterEditor.setFilters(configuration.getCoveragePatterns());
    final boolean isCoverageByTestApplicable = runner != null && runner.isCoverageByTestApplicable();
    myTracingRb.setEnabled(myTracingRb.isEnabled() && isCoverageByTestApplicable);
    mySamplingRb.setSelected(configuration.isSampling() || !isCoverageByTestApplicable);
    myTracingRb.setSelected(!mySamplingRb.isSelected());
    myTrackPerTestCoverageCb.setSelected(configuration.isTrackPerTestCoverage());
    myTrackPerTestCoverageCb.setEnabled(myTracingRb.isEnabled() && myTracingRb.isSelected() && canHavePerTestCoverage());
    myTrackTestSourcesCb.setSelected(configuration.isTrackTestFolders());
}
Also used : CommonJavaRunConfigurationParameters(com.intellij.execution.CommonJavaRunConfigurationParameters) CoverageRunner(com.intellij.coverage.CoverageRunner) ModuleBasedConfiguration(com.intellij.execution.configurations.ModuleBasedConfiguration)

Example 2 with CoverageRunner

use of com.intellij.coverage.CoverageRunner in project intellij-community by JetBrains.

the class CoverageConfigurable method createEditor.

@NotNull
protected JComponent createEditor() {
    JPanel result = new JPanel(new GridBagLayout());
    final DefaultComboBoxModel runnersModel = new DefaultComboBoxModel();
    myCoverageRunnerCb = new JComboBox(runnersModel);
    final JavaCoverageEnabledConfiguration javaCoverageEnabledConfiguration = JavaCoverageEnabledConfiguration.getFrom(myConfig);
    LOG.assertTrue(javaCoverageEnabledConfiguration != null);
    final JavaCoverageEngine provider = javaCoverageEnabledConfiguration.getCoverageProvider();
    for (CoverageRunner runner : Extensions.getExtensions(CoverageRunner.EP_NAME)) {
        if (runner.acceptsCoverageEngine(provider)) {
            runnersModel.addElement(new CoverageRunnerItem(runner));
        }
    }
    myCoverageRunnerCb.setRenderer(new ListCellRendererWrapper<CoverageRunnerItem>() {

        @Override
        public void customize(JList list, CoverageRunnerItem value, int index, boolean selected, boolean hasFocus) {
            if (value != null) {
                setText(value.getPresentableName());
            }
        }
    });
    myCoverageRunnerCb.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            final CoverageRunner runner = getSelectedRunner();
            enableTracingPanel(runner != null && runner.isCoverageByTestApplicable());
            myTrackPerTestCoverageCb.setEnabled(myTracingRb.isSelected() && canHavePerTestCoverage() && runner != null && runner.isCoverageByTestApplicable());
        }
    });
    myRunnerPanel = new JPanel(new GridBagLayout());
    myRunnerPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    myRunnerPanel.add(new JLabel("Choose coverage runner:"), new GridBagConstraints(0, 0, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insetsRight(10), 0, 0));
    myRunnerPanel.add(myCoverageRunnerCb, new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
    final JPanel cPanel = new JPanel(new VerticalFlowLayout());
    mySamplingRb = new JRadioButton("Sampling");
    cPanel.add(mySamplingRb);
    myTracingRb = new JRadioButton("Tracing");
    cPanel.add(myTracingRb);
    final ButtonGroup group = new ButtonGroup();
    group.add(mySamplingRb);
    group.add(myTracingRb);
    ActionListener samplingListener = new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            final CoverageRunner runner = getSelectedRunner();
            myTrackPerTestCoverageCb.setEnabled(canHavePerTestCoverage() && myTracingRb.isSelected() && runner != null && runner.isCoverageByTestApplicable());
        }
    };
    mySamplingRb.addActionListener(samplingListener);
    myTracingRb.addActionListener(samplingListener);
    myTrackPerTestCoverageCb = new JCheckBox("Track per test coverage");
    final JBPanel tracingPanel = JBUI.Panels.simplePanel(myTrackPerTestCoverageCb).withBorder(JBUI.Borders.emptyLeft(15));
    cPanel.add(tracingPanel);
    myRunnerPanel.add(cPanel, new GridBagConstraints(0, 1, GridBagConstraints.REMAINDER, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
    final GridBagConstraints gc = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0);
    result.add(myRunnerPanel, gc);
    JPanel panel = new JPanel(new GridBagLayout());
    panel.setBorder(IdeBorderFactory.createTitledBorder(ExecutionBundle.message("record.coverage.filters.title"), false));
    myClassFilterEditor = new MyClassFilterEditor(myProject);
    final GridBagConstraints bagConstraints = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, JBUI.emptyInsets(), 0, 0);
    panel.add(myClassFilterEditor, bagConstraints);
    bagConstraints.weighty = 0;
    myTrackTestSourcesCb = new JCheckBox("Enable coverage in test folders");
    panel.add(myTrackTestSourcesCb, bagConstraints);
    gc.weighty = 1;
    gc.fill = GridBagConstraints.BOTH;
    result.add(panel, gc);
    myCoverageNotSupportedLabel = new JLabel(CodeInsightBundle.message("code.coverage.is.not.supported"));
    myCoverageNotSupportedLabel.setIcon(AllIcons.General.WarningDialog);
    result.add(myCoverageNotSupportedLabel, gc);
    return result;
}
Also used : JavaCoverageEngine(com.intellij.coverage.JavaCoverageEngine) CoverageRunner(com.intellij.coverage.CoverageRunner) ActionEvent(java.awt.event.ActionEvent) JBPanel(com.intellij.ui.components.JBPanel) ActionListener(java.awt.event.ActionListener) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CoverageRunner

use of com.intellij.coverage.CoverageRunner in project intellij-community by JetBrains.

the class JavaCoverageEnabledConfiguration method writeExternal.

@Override
public void writeExternal(Element element) throws WriteExternalException {
    // just for backward compatibility with settings format before "Huge Coverage Refactoring"
    // see [IDEA-56800] ProjectRunConfigurationManager component: "coverage" extension: "merge" attribute is misplaced
    // here we can't use super.writeExternal(...) due to differences in format between IDEA 10 and IDEA 9.x
    // enabled
    element.setAttribute(COVERAGE_ENABLED_ATTRIBUTE_NAME, String.valueOf(isCoverageEnabled()));
    // merge with prev
    element.setAttribute(COVERAGE_MERGE_ATTRIBUTE_NAME, String.valueOf(myIsMergeWithPreviousResults));
    if (myIsMergeWithPreviousResults && mySuiteToMergeWith != null) {
        element.setAttribute(COVERAGE_MERGE_SUITE_ATT_NAME, mySuiteToMergeWith);
    }
    // track per test
    final boolean trackPerTestCoverage = isTrackPerTestCoverage();
    if (!trackPerTestCoverage) {
        element.setAttribute(TRACK_PER_TEST_COVERAGE_ATTRIBUTE_NAME, String.valueOf(trackPerTestCoverage));
    }
    // sampling
    final boolean sampling = isSampling();
    if (sampling) {
        element.setAttribute(SAMPLING_COVERAGE_ATTRIBUTE_NAME, String.valueOf(sampling));
    }
    // test folders
    final boolean trackTestFolders = isTrackTestFolders();
    if (trackTestFolders) {
        element.setAttribute(TRACK_TEST_FOLDERS, String.valueOf(trackTestFolders));
    }
    // runner
    final CoverageRunner coverageRunner = getCoverageRunner();
    final String runnerId = getRunnerId();
    if (coverageRunner != null) {
        element.setAttribute(COVERAGE_RUNNER, coverageRunner.getId());
    } else if (runnerId != null) {
        element.setAttribute(COVERAGE_RUNNER, runnerId);
    }
    // patterns
    if (myCoveragePatterns != null) {
        for (ClassFilter pattern : myCoveragePatterns) {
            @NonNls final Element patternElement = new Element(COVERAGE_PATTERN_ELEMENT_NAME);
            DefaultJDOMExternalizer.writeExternal(pattern, patternElement);
            element.addContent(patternElement);
        }
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) CoverageRunner(com.intellij.coverage.CoverageRunner) IDEACoverageRunner(com.intellij.coverage.IDEACoverageRunner) JavaCoverageRunner(com.intellij.coverage.JavaCoverageRunner) ClassFilter(com.intellij.ui.classFilter.ClassFilter) Element(org.jdom.Element)

Example 4 with CoverageRunner

use of com.intellij.coverage.CoverageRunner in project intellij-community by JetBrains.

the class CoverageEnabledConfiguration method readExternal.

public void readExternal(Element element) throws InvalidDataException {
    // is enabled
    final String coverageEnabledValueStr = element.getAttributeValue(COVERAGE_ENABLED_ATTRIBUTE_NAME);
    myIsCoverageEnabled = Boolean.valueOf(coverageEnabledValueStr).booleanValue();
    // track per test coverage
    final String collectLineInfoAttribute = element.getAttributeValue(TRACK_PER_TEST_COVERAGE_ATTRIBUTE_NAME);
    myTrackPerTestCoverage = collectLineInfoAttribute == null || Boolean.valueOf(collectLineInfoAttribute).booleanValue();
    // sampling
    final String sampling = element.getAttributeValue(SAMPLING_COVERAGE_ATTRIBUTE_NAME);
    mySampling = sampling != null && Boolean.valueOf(sampling).booleanValue();
    // track test folders
    final String trackTestFolders = element.getAttributeValue(TRACK_TEST_FOLDERS);
    myTrackTestFolders = trackTestFolders != null && Boolean.valueOf(trackTestFolders).booleanValue();
    // coverage runner
    final String runnerId = element.getAttributeValue(COVERAGE_RUNNER);
    if (runnerId != null) {
        myRunnerId = runnerId;
        myCoverageRunner = null;
        for (CoverageRunner coverageRunner : Extensions.getExtensions(CoverageRunner.EP_NAME)) {
            if (Comparing.strEqual(coverageRunner.getId(), myRunnerId)) {
                myCoverageRunner = coverageRunner;
                break;
            }
        }
    }
}
Also used : CoverageRunner(com.intellij.coverage.CoverageRunner)

Example 5 with CoverageRunner

use of com.intellij.coverage.CoverageRunner in project intellij-community by JetBrains.

the class JavaCoverageEnabledConfiguration method appendCoverageArgument.

public void appendCoverageArgument(RunConfigurationBase configuration, final SimpleJavaParameters javaParameters) {
    final CoverageRunner runner = getCoverageRunner();
    try {
        if (runner != null && runner instanceof JavaCoverageRunner) {
            final String path = getCoverageFilePath();
            // cannot be null here if runner != null
            assert path != null;
            String sourceMapPath = null;
            if (myCoverageProvider.isSourceMapNeeded(configuration)) {
                sourceMapPath = getSourceMapPath(path);
            }
            ((JavaCoverageRunner) runner).appendCoverageArgument(new File(path).getCanonicalPath(), getPatterns(), javaParameters, isTrackPerTestCoverage() && !isSampling(), isSampling(), sourceMapPath);
        }
    } catch (IOException e) {
        LOG.info(e);
    }
}
Also used : CoverageRunner(com.intellij.coverage.CoverageRunner) IDEACoverageRunner(com.intellij.coverage.IDEACoverageRunner) JavaCoverageRunner(com.intellij.coverage.JavaCoverageRunner) JavaCoverageRunner(com.intellij.coverage.JavaCoverageRunner) IOException(java.io.IOException) File(java.io.File)

Aggregations

CoverageRunner (com.intellij.coverage.CoverageRunner)5 IDEACoverageRunner (com.intellij.coverage.IDEACoverageRunner)2 JavaCoverageRunner (com.intellij.coverage.JavaCoverageRunner)2 JavaCoverageEngine (com.intellij.coverage.JavaCoverageEngine)1 CommonJavaRunConfigurationParameters (com.intellij.execution.CommonJavaRunConfigurationParameters)1 ModuleBasedConfiguration (com.intellij.execution.configurations.ModuleBasedConfiguration)1 VerticalFlowLayout (com.intellij.openapi.ui.VerticalFlowLayout)1 ClassFilter (com.intellij.ui.classFilter.ClassFilter)1 JBPanel (com.intellij.ui.components.JBPanel)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 IOException (java.io.IOException)1 Element (org.jdom.Element)1 NonNls (org.jetbrains.annotations.NonNls)1 NotNull (org.jetbrains.annotations.NotNull)1