This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 235112
Collapse All | Expand All

(-)gsf.testrunner/src/org/netbeans/modules/gsf/testrunner/api/UnitTestsUsage.java (+91 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.gsf.testrunner.api;
43
44
import java.net.URI;
45
import java.util.ArrayList;
46
import java.util.HashMap;
47
import java.util.logging.Level;
48
import java.util.logging.LogRecord;
49
import java.util.logging.Logger;
50
51
/**
52
 *
53
 * @author theofanis
54
 */
55
public class UnitTestsUsage {
56
    
57
    private static UnitTestsUsage INSTANCE;
58
    private static HashMap<URI, String> projectsAlreadyLogged = new HashMap<URI, String>();
59
60
    private UnitTestsUsage() { }
61
    
62
    public static UnitTestsUsage getInstance() {
63
        if(INSTANCE != null) {
64
            return INSTANCE;
65
        }
66
        return new UnitTestsUsage();
67
    }
68
    
69
    public void logUnitTestUsage(URI projectURI, String unitTestLibrary) {
70
        Logger logger = Logger.getLogger("org.netbeans.ui.metrics.unittestslibrary");   // NOI18N
71
        LogRecord rec = new LogRecord(Level.INFO, "USG_UNIT_TESTS_LIBRARY"); //NOI18N
72
        if (unitTestLibrary.isEmpty()) {
73
            return;
74
        }
75
76
        if (!projectsAlreadyLogged.containsKey(projectURI)) {
77
            projectsAlreadyLogged.put(projectURI, unitTestLibrary.toString());
78
        } else {
79
            String unitTestLibrariesUsed = projectsAlreadyLogged.get(projectURI);
80
            if (unitTestLibrariesUsed.equals(unitTestLibrary)) {
81
                return;
82
            } else {
83
                projectsAlreadyLogged.put(projectURI, unitTestLibrary);
84
            }
85
        }
86
        rec.setParameters(new Object[]{unitTestLibrary.toString()});
87
        rec.setLoggerName(logger.getName());
88
        logger.log(rec);
89
    }
90
    
91
}
(-)junit/src/org/netbeans/modules/junit/DefaultPlugin.java (-2 / +30 lines)
Lines 48-54 Link Here
48
import java.awt.BorderLayout;
48
import java.awt.BorderLayout;
49
import java.awt.GridLayout;
49
import java.awt.GridLayout;
50
import java.awt.event.ActionListener;
50
import java.awt.event.ActionListener;
51
import java.io.File;
51
import java.io.IOException;
52
import java.io.IOException;
53
import java.net.URI;
52
import java.net.URL;
54
import java.net.URL;
53
import java.util.ArrayList;
55
import java.util.ArrayList;
54
import java.util.Collection;
56
import java.util.Collection;
Lines 119-129 Link Here
119
import static org.netbeans.api.java.classpath.ClassPath.SOURCE;
121
import static org.netbeans.api.java.classpath.ClassPath.SOURCE;
120
import static org.netbeans.api.java.classpath.ClassPath.COMPILE;
122
import static org.netbeans.api.java.classpath.ClassPath.COMPILE;
121
import static org.netbeans.api.java.project.JavaProjectConstants.SOURCES_TYPE_JAVA;
123
import static org.netbeans.api.java.project.JavaProjectConstants.SOURCES_TYPE_JAVA;
124
import org.netbeans.modules.gsf.testrunner.api.UnitTestsUsage;
122
import org.netbeans.modules.java.testrunner.GuiUtils;
125
import org.netbeans.modules.java.testrunner.GuiUtils;
123
import static org.openide.ErrorManager.ERROR;
126
import static org.openide.ErrorManager.ERROR;
124
import static org.openide.ErrorManager.WARNING;
127
import static org.openide.ErrorManager.WARNING;
125
import static org.openide.NotifyDescriptor.CANCEL_OPTION;
128
import static org.openide.NotifyDescriptor.CANCEL_OPTION;
126
import static org.openide.NotifyDescriptor.WARNING_MESSAGE;
129
import static org.openide.NotifyDescriptor.WARNING_MESSAGE;
130
import org.openide.util.Utilities;
127
131
128
/**
132
/**
129
 * Default JUnit plugin.
133
 * Default JUnit plugin.
Lines 145-151 Link Here
145
                                = "org/junit/Test.class";               //NOI18N
149
                                = "org/junit/Test.class";               //NOI18N
146
    
150
    
147
    /** */
151
    /** */
148
    private JUnitVersion junitVer;
152
    private static JUnitVersion junitVer;
149
153
150
    /** name of FreeMarker template property - generate {@code &#64;BeforeClass} method? */
154
    /** name of FreeMarker template property - generate {@code &#64;BeforeClass} method? */
151
    private static final String templatePropBeforeClass = "classSetUp"; //NOI18N
155
    private static final String templatePropBeforeClass = "classSetUp"; //NOI18N
Lines 173-178 Link Here
173
    private static java.util.ResourceBundle bundle = org.openide.util.NbBundle.getBundle(
177
    private static java.util.ResourceBundle bundle = org.openide.util.NbBundle.getBundle(
174
            DefaultPlugin.class);
178
            DefaultPlugin.class);
175
179
180
    public static void logJUnitUsage(URI projectURI) {
181
        String version = "";
182
        if (junitVer == null) {
183
            Project project = FileOwnerQuery.getOwner(projectURI);
184
            final ClassPath classPath = getTestClassPath(project);
185
            if (classPath != null) {
186
                if (classPath.findResource(JUNIT4_SPECIFIC) != null) {
187
                    version = JUnitVersion.JUNIT4.toString();
188
                } else if (classPath.findResource(JUNIT3_SPECIFIC) != null) {
189
                    version = JUnitVersion.JUNIT3.toString();
190
                }
191
            }
192
        } else {
193
            version = junitVer.toString();
194
        }
195
        UnitTestsUsage.getInstance().logUnitTestUsage(projectURI, version);
196
    }
197
176
    /**
198
    /**
177
     * 
199
     * 
178
     */
200
     */
Lines 813-819 Link Here
813
                                final Map<CreateTestParam, Object> params) {
835
                                final Map<CreateTestParam, Object> params) {
814
        //XXX: not documented that in case that if filesToTest is <null>,
836
        //XXX: not documented that in case that if filesToTest is <null>,
815
        //the target root param works as a target folder
837
        //the target root param works as a target folder
816
        
838
        Project project = FileOwnerQuery.getOwner(targetRoot);
839
        if (project != null) {
840
            File projectFile = FileUtil.toFile(project.getProjectDirectory());
841
            if (projectFile != null) {
842
                logJUnitUsage(Utilities.toURI(projectFile));
843
            }
844
        }
817
        ProgressIndicator progress = new ProgressIndicator();
845
        ProgressIndicator progress = new ProgressIndicator();
818
        progress.show();
846
        progress.show();
819
847
(-)junit/src/org/netbeans/modules/junit/output/JUnitOutputReader.java (+6 lines)
Lines 84-89 Link Here
84
import org.openide.util.NbBundle;
84
import org.openide.util.NbBundle;
85
import org.xml.sax.SAXException;
85
import org.xml.sax.SAXException;
86
import static java.util.logging.Level.FINER;
86
import static java.util.logging.Level.FINER;
87
import org.netbeans.modules.junit.DefaultPlugin;
87
import static org.netbeans.modules.junit.output.RegexpUtils.ADD_ERROR_PREFIX;
88
import static org.netbeans.modules.junit.output.RegexpUtils.ADD_ERROR_PREFIX;
88
import static org.netbeans.modules.junit.output.RegexpUtils.ADD_FAILURE_PREFIX;
89
import static org.netbeans.modules.junit.output.RegexpUtils.ADD_FAILURE_PREFIX;
89
import static org.netbeans.modules.junit.output.RegexpUtils.END_OF_TEST_PREFIX;
90
import static org.netbeans.modules.junit.output.RegexpUtils.END_OF_TEST_PREFIX;
Lines 94-99 Link Here
94
import static org.netbeans.modules.junit.output.RegexpUtils.TESTSUITE_PREFIX;
95
import static org.netbeans.modules.junit.output.RegexpUtils.TESTSUITE_PREFIX;
95
import static org.netbeans.modules.junit.output.RegexpUtils.TESTSUITE_STATS_PREFIX;
96
import static org.netbeans.modules.junit.output.RegexpUtils.TESTSUITE_STATS_PREFIX;
96
import org.openide.util.Lookup;
97
import org.openide.util.Lookup;
98
import org.openide.util.Utilities;
97
99
98
/**
100
/**
99
 * Obtains events from a single session of an Ant <code>junit</code> task
101
 * Obtains events from a single session of an Ant <code>junit</code> task
Lines 183-189 Link Here
183
185
184
        this.testSession = new JUnitTestSession(sName, project, sessionType, new JUnitTestRunnerNodeFactory()); //NOI18N
186
        this.testSession = new JUnitTestSession(sName, project, sessionType, new JUnitTestRunnerNodeFactory()); //NOI18N
185
        testSession.setRerunHandler(new JUnitExecutionManager(session, testSession, props));
187
        testSession.setRerunHandler(new JUnitExecutionManager(session, testSession, props));
188
        File projectFile = FileUtil.toFile(project.getProjectDirectory());
189
        if(projectFile != null) {
190
            DefaultPlugin.logJUnitUsage(Utilities.toURI(projectFile));
186
    }
191
    }
192
    }
187
193
188
    TestSession getTestSession() {
194
    TestSession getTestSession() {
189
        return testSession;
195
        return testSession;
(-)maven.junit/src/org/netbeans/modules/maven/junit/JUnitOutputListenerProvider.java (+21 lines)
Lines 78-83 Link Here
78
import org.netbeans.modules.gsf.testrunner.api.TestSuite;
78
import org.netbeans.modules.gsf.testrunner.api.TestSuite;
79
import org.netbeans.modules.gsf.testrunner.api.Testcase;
79
import org.netbeans.modules.gsf.testrunner.api.Testcase;
80
import org.netbeans.modules.gsf.testrunner.api.Trouble;
80
import org.netbeans.modules.gsf.testrunner.api.Trouble;
81
import org.netbeans.modules.gsf.testrunner.api.UnitTestsUsage;
81
import org.netbeans.modules.maven.api.Constants;
82
import org.netbeans.modules.maven.api.Constants;
82
import org.netbeans.modules.maven.api.NbMavenProject;
83
import org.netbeans.modules.maven.api.NbMavenProject;
83
import org.netbeans.modules.maven.api.PluginPropertyUtils;
84
import org.netbeans.modules.maven.api.PluginPropertyUtils;
Lines 175-180 Link Here
175
	    if (prj != null) {
176
	    if (prj != null) {
176
		NbMavenProject mvnprj = prj.getLookup().lookup(NbMavenProject.class);
177
		NbMavenProject mvnprj = prj.getLookup().lookup(NbMavenProject.class);
177
		if (mvnprj != null) {
178
		if (mvnprj != null) {
179
                    File projectFile = FileUtil.toFile(prj.getProjectDirectory());
180
                    if (projectFile != null) {
181
                        UnitTestsUsage.getInstance().logUnitTestUsage(Utilities.toURI(projectFile), getJUnitVersion(config.getMavenProject()));
182
                    }
178
		    TestSession.SessionType type = TestSession.SessionType.TEST;
183
		    TestSession.SessionType type = TestSession.SessionType.TEST;
179
		    String action = config.getActionName();
184
		    String action = config.getActionName();
180
		    if (action != null) { //custom
185
		    if (action != null) { //custom
Lines 295-300 Link Here
295
        return false;
300
        return false;
296
    }   
301
    }   
297
302
303
    private String getJUnitVersion(MavenProject prj) {
304
        String juVersion = "";
305
        for (Artifact a : prj.getArtifacts()) {
306
            if ("junit".equals(a.getGroupId()) && ("junit".equals(a.getArtifactId()) || "junit-dep".equals(a.getArtifactId()))) { //junit-dep  see #214238
307
                String version = a.getVersion();
308
                if (version != null && new ComparableVersion(version).compareTo(new ComparableVersion("4.8")) >= 0) {
309
                    return "JUNIT4";
310
                }
311
                if (version != null && new ComparableVersion(version).compareTo(new ComparableVersion("3.8")) >= 0) {
312
                    return "JUNIT3";
313
                }
314
            }
315
        }
316
        return juVersion;
317
    }
318
298
    private boolean usingJUnit4(MavenProject prj) { // SUREFIRE-724
319
    private boolean usingJUnit4(MavenProject prj) { // SUREFIRE-724
299
        for (Artifact a : prj.getArtifacts()) {
320
        for (Artifact a : prj.getArtifacts()) {
300
            if ("junit".equals(a.getGroupId()) && ("junit".equals(a.getArtifactId()) || "junit-dep".equals(a.getArtifactId()))) { //junit-dep  see #214238
321
            if ("junit".equals(a.getGroupId()) && ("junit".equals(a.getArtifactId()) || "junit-dep".equals(a.getArtifactId()))) { //junit-dep  see #214238

Return to bug 235112