diff -r 4ba4ac2a22d7 nbjunit/apichanges.xml --- a/nbjunit/apichanges.xml Thu Aug 07 16:57:52 2008 +0400 +++ b/nbjunit/apichanges.xml Thu Aug 07 17:01:57 2008 +0400 @@ -55,6 +55,21 @@ made subject to such option by the copyr + + + NbModuleSuite.Configuration.skipWarmup(boolean reuse) + + + + + +

NbModuleSuite.Configuration now has + skipWarmup(boolean) + method which disables NetBeans warm-up. +

+
+ +
NbModuleSuite.Configuration.reuseUserDir(boolean reuse) diff -r 4ba4ac2a22d7 nbjunit/manifest.mf --- a/nbjunit/manifest.mf Thu Aug 07 16:57:52 2008 +0400 +++ b/nbjunit/manifest.mf Thu Aug 07 17:01:57 2008 +0400 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.nbjunit/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/junit/Bundle.properties -OpenIDE-Module-Specification-Version: 1.52 +OpenIDE-Module-Specification-Version: 1.53 diff -r 4ba4ac2a22d7 nbjunit/src/org/netbeans/junit/NbModuleSuite.java --- a/nbjunit/src/org/netbeans/junit/NbModuleSuite.java Thu Aug 07 16:57:52 2008 +0400 +++ b/nbjunit/src/org/netbeans/junit/NbModuleSuite.java Thu Aug 07 17:01:57 2008 +0400 @@ -106,6 +106,7 @@ public class NbModuleSuite { final ClassLoader parentClassLoader; final boolean reuseUserDir; final boolean gui; + final boolean skipWarmup; private Configuration( String clusterRegExp, @@ -114,7 +115,8 @@ public class NbModuleSuite { List testItems, Class latestTestCase, boolean reuseUserDir, - boolean gui + boolean gui, + boolean skipWarmup ) { this.clusterRegExp = clusterRegExp; this.moduleRegExp = moduleRegExp; @@ -123,10 +125,11 @@ public class NbModuleSuite { this.reuseUserDir = reuseUserDir; this.latestTestCaseClass = latestTestCase; this.gui = gui; + this.skipWarmup = skipWarmup; } - static Configuration create(Class clazz) { - return new Configuration(null, null, ClassLoader.getSystemClassLoader().getParent(), Collections.emptyList(), clazz, false, true); + static Configuration create(Class clazz) { + return new Configuration(null, null, ClassLoader.getSystemClassLoader().getParent(), Collections.emptyList(), clazz, false, true, false); } /** Regular expression to match clusters that shall be enabled. @@ -139,7 +142,7 @@ public class NbModuleSuite { * @return clone of this configuration with cluster set to regExp value */ public Configuration clusters(String regExp) { - return new Configuration(regExp, moduleRegExp, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui); + return new Configuration(regExp, moduleRegExp, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui, skipWarmup); } /** By default only modules on classpath of the test are enabled, @@ -150,11 +153,11 @@ public class NbModuleSuite { * @return clone of this configuration with enable modules set to regExp value */ public Configuration enableModules(String regExp) { - return new Configuration(clusterRegExp, regExp, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui); + return new Configuration(clusterRegExp, regExp, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui, skipWarmup); } Configuration classLoader(ClassLoader parent) { - return new Configuration(clusterRegExp, moduleRegExp, parent, tests, latestTestCaseClass, reuseUserDir, gui); + return new Configuration(clusterRegExp, moduleRegExp, parent, tests, latestTestCaseClass, reuseUserDir, gui, skipWarmup); } /** Adds new test name, or array of names into the configuration. By @@ -174,7 +177,7 @@ public class NbModuleSuite { } List newTests = new ArrayList(tests); newTests.add(new Item(true, latestTestCaseClass, testNames)); - return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, newTests, latestTestCaseClass, reuseUserDir, gui); + return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, newTests, latestTestCaseClass, reuseUserDir, gui, skipWarmup); } /** Adds new test class to run, together with a list of its methods @@ -197,7 +200,7 @@ public class NbModuleSuite { if ((testNames != null) && (testNames.length != 0)){ newTests.add(new Item(true, test, testNames)); } - return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, newTests, test, reuseUserDir, gui); + return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, newTests, test, reuseUserDir, gui, skipWarmup); } /** @@ -218,7 +221,7 @@ public class NbModuleSuite { } List newTests = new ArrayList(tests); newTests.add(new Item(false, test, null)); - return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, newTests, latestTestCaseClass, reuseUserDir, gui); + return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, newTests, latestTestCaseClass, reuseUserDir, gui, skipWarmup); } private void addLatest(List newTests) { @@ -236,7 +239,7 @@ public class NbModuleSuite { private Configuration getReady() { List newTests = new ArrayList(tests); addLatest(newTests); - return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, newTests, latestTestCaseClass, reuseUserDir, gui); + return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, newTests, latestTestCaseClass, reuseUserDir, gui, skipWarmup); } /** Should the system run with GUI or without? The default behaviour @@ -249,7 +252,7 @@ public class NbModuleSuite { * @return clone of this configuration with gui mode associated */ public Configuration gui(boolean gui) { - return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui); + return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui, skipWarmup); } /** @@ -259,10 +262,20 @@ public class NbModuleSuite { * @since 1.52 */ public Configuration reuseUserDir(boolean reuse) { - return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, tests, latestTestCaseClass, reuse, gui); - } + return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, tests, latestTestCaseClass, reuse, gui, skipWarmup); } + /** + * Enables or disables NetBeans warm-up + * @param skipWarmup true or false + * @return clone of this configuration with skipWarmup mode associated + * @since 1.53 + */ + public Configuration skipWarmup(boolean skipWarmup) { + return new Configuration(clusterRegExp, moduleRegExp, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui, skipWarmup); + } + } + /** Factory method to create wrapper test that knows how to setup proper * NetBeans Runtime Container environment. * Wraps the provided class into a test that set ups properly the @@ -490,6 +503,11 @@ public class NbModuleSuite { args.add("--nosplash"); if (!config.gui) { args.add("--nogui"); + } + if (config.skipWarmup) { + System.setProperty("netbeans.warmup.skip", "true"); + } else { + System.clearProperty("netbeans.warmup.skip"); } m.invoke(null, (Object)args.toArray(new String[0])); diff -r 4ba4ac2a22d7 nbjunit/test/unit/src/org/netbeans/junit/NbModuleSuiteTest.java --- a/nbjunit/test/unit/src/org/netbeans/junit/NbModuleSuiteTest.java Thu Aug 07 16:57:52 2008 +0400 +++ b/nbjunit/test/unit/src/org/netbeans/junit/NbModuleSuiteTest.java Thu Aug 07 17:01:57 2008 +0400 @@ -45,6 +45,10 @@ import test.pkg.not.in.junit.NbModuleSui import test.pkg.not.in.junit.NbModuleSuiteT; import test.pkg.not.in.junit.NbModuleSuiteS; import java.io.File; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.FileReader; +import java.io.PrintStream; import org.netbeans.testjunit.AskForOrgOpenideUtilEnumClass; import java.util.Properties; import java.util.Set; @@ -60,6 +64,52 @@ public class NbModuleSuiteTest extends T public NbModuleSuiteTest(String testName) { super(testName); + } + + public void testSkipWarmup() throws IOException { + PrintStream temperr = System.err; + File tempfile = File.createTempFile("startuplog", null); + try { + Test instance = NbModuleSuite.create(NbModuleSuite.createConfiguration(NbModuleSuiteT.class).gui(true)); + PrintStream ps = new PrintStream(tempfile); + System.out.println(tempfile.getPath()); + System.setProperty("org.netbeans.log.startup", "print"); + System.setProperty("t.warmup", "true"); + System.setErr(ps); + junit.textui.TestRunner.run(instance); + System.setErr(temperr); + ps.flush(); + assertEquals(true, wasWarmup(tempfile)); + tempfile.delete(); + + instance = NbModuleSuite.create(NbModuleSuite.createConfiguration(NbModuleSuiteT.class).gui(true).skipWarmup(true)); + tempfile = File.createTempFile("startuplog", null); + ps = new PrintStream(tempfile); + System.out.println(tempfile.getPath()); + System.setProperty("org.netbeans.log.startup", "print"); + System.setProperty("t.warmup", "true"); + System.setErr(ps); + junit.textui.TestRunner.run(instance); + System.setErr(temperr); + ps.flush(); + assertEquals(false, wasWarmup(tempfile)); + } finally { + System.clearProperty("org.netbeans.log.startup"); + System.clearProperty("t.warmup"); + System.setErr(temperr); + tempfile.delete(); + } + } + + boolean wasWarmup(File file) throws IOException { + BufferedReader r = new BufferedReader(new FileReader(file)); + + for(String line = r.readLine(); line != null; line = r.readLine()) { + if (line.contains("Warmup started")) { + return true; + } + } + return false; } public void testUserDir() { diff -r 4ba4ac2a22d7 nbjunit/test/unit/src/test/pkg/not/in/junit/NbModuleSuiteT.java --- a/nbjunit/test/unit/src/test/pkg/not/in/junit/NbModuleSuiteT.java Thu Aug 07 16:57:52 2008 +0400 +++ b/nbjunit/test/unit/src/test/pkg/not/in/junit/NbModuleSuiteT.java Thu Aug 07 17:01:57 2008 +0400 @@ -15,4 +15,10 @@ public class NbModuleSuiteT extends Test public void testFullhack() { System.setProperty("t.hack", System.getProperty("netbeans.full.hack")); } + + public void testWarmup() throws InterruptedException { + if (System.getProperty("t.warmup", "false").equalsIgnoreCase("true")) { + Thread.sleep(10000); + } + } }