build script clean up and improved debugging support
authorLukas Jungmann <jungi@netbeans.org>
Mon, 06 Feb 2012 00:24:04 +0100
changeset 17781b4619fb1e7af
parent 17780 d3b4e8dfcd7c
child 17782 7a2aa0757a7e
build script clean up and improved debugging support
testng.ant/src/org/netbeans/modules/contrib/testng/ant/AntTestNGSupport.java
testng.ant/src/org/netbeans/modules/contrib/testng/ant/testng-build.xml
     1.1 --- a/testng.ant/src/org/netbeans/modules/contrib/testng/ant/AntTestNGSupport.java	Sun Feb 05 23:59:19 2012 +0100
     1.2 +++ b/testng.ant/src/org/netbeans/modules/contrib/testng/ant/AntTestNGSupport.java	Mon Feb 06 00:24:04 2012 +0100
     1.3 @@ -165,9 +165,11 @@
     1.4                  FileObject failedTestsConfig = projectHome.getFileObject(failedConfPath);
     1.5                  props.put("testng.config", FileUtil.getRelativePath(projectHome, failedTestsConfig));
     1.6              } else {
     1.7 -                if (Action.RUN_TESTSUITE.equals(action) || Action.DEBUG_TESTSUITE.equals(action)) {
     1.8 +                if (Action.RUN_TESTSUITE.equals(action)) {
     1.9                      props.put("testng.config", FileUtil.toFile(config.getTest()).getAbsolutePath());
    1.10 -                } else {
    1.11 +                } else if (Action.DEBUG_TESTSUITE.equals(action)) {
    1.12 +                    props.put("test.class.or.method", FileUtil.toFile(config.getTest()).getAbsolutePath());
    1.13 +                } else if (Action.RUN_TESTMETHOD.equals(action)) {
    1.14                      File f = XMLSuiteSupport.createSuiteforMethod(
    1.15                          FileUtil.normalizeFile(new File(System.getProperty("java.io.tmpdir"))), //NOI18N
    1.16                          ProjectUtils.getInformation(p).getDisplayName(),
    1.17 @@ -176,6 +178,14 @@
    1.18                          config.getMethodName());
    1.19                      f = FileUtil.normalizeFile(f);
    1.20                      props.put("testng.config", f.getAbsolutePath());
    1.21 +                } else {
    1.22 +                    String cls = config.getPackageName() != null
    1.23 +                            ? config.getPackageName() + "." + config.getClassName()
    1.24 +                            : config.getClassName();
    1.25 +                    props.put("test.class", cls);
    1.26 +                    if (config.getMethodName() != null && config.getMethodName().trim().length() > 0) {
    1.27 +                        props.put("test.class.or.method", "-methods " + cls + "." + config.getMethodName());
    1.28 +                    }
    1.29                  }
    1.30              }
    1.31              try {
     2.1 --- a/testng.ant/src/org/netbeans/modules/contrib/testng/ant/testng-build.xml	Sun Feb 05 23:59:19 2012 +0100
     2.2 +++ b/testng.ant/src/org/netbeans/modules/contrib/testng/ant/testng-build.xml	Mon Feb 06 00:24:04 2012 +0100
     2.3 @@ -51,6 +51,9 @@
     2.4          </condition>
     2.5          <!-- IDE sets this when CoS off + CTRL+F6 -->
     2.6          <property name="test.includes" value="**/*.java"/>
     2.7 +        <condition property="test.name.arg" value="-testname ${test.class}" else="">
     2.8 +            <isset property="test.class"/>
     2.9 +        </condition>
    2.10      </target>
    2.11  
    2.12      <!-- Call testng ant task -->
    2.13 @@ -64,7 +67,7 @@
    2.14                      <filename name="@{testincludes}"/>
    2.15                  </fileset>
    2.16                  <taskdef name="testng" classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}"/>
    2.17 -                <testng mode="MIXED" classfilesetref="mixed.tests" workingDir="${basedir}" failureProperty="testng.tests.failed" outputdir="${build.test.results.dir}">
    2.18 +                <testng mode="MIXED" classfilesetref="mixed.tests" workingDir="${basedir}" failureProperty="tests.failed" outputdir="${build.test.results.dir}">
    2.19                      <classpath>
    2.20                          <pathelement path="${run.test.classpath}"/>
    2.21                          <pathelement path="${j2ee.platform.classpath}"/>
    2.22 @@ -83,7 +86,7 @@
    2.23              <attribute name="testSuite" default="${build.dir}/generated/testng/temp-testng-customsuite.xml"/>
    2.24              <sequential>
    2.25                  <taskdef name="testng" classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}"/>
    2.26 -                <testng workingDir="${basedir}" failureProperty="testng.tests.failed" outputdir="${build.test.results.dir}">
    2.27 +                <testng workingDir="${basedir}" failureProperty="tests.failed" outputdir="${build.test.results.dir}">
    2.28                      <classpath>
    2.29                          <pathelement path="${run.test.classpath}"/>
    2.30                          <pathelement path="${j2ee.platform.classpath}"/>
    2.31 @@ -94,7 +97,6 @@
    2.32                          <propertyref prefix="test-sys-prop."/>
    2.33                          <mapper from="test-sys-prop.*" to="*" type="glob"/>
    2.34                      </propertyset>
    2.35 -                    <jvmarg value="-ea"/>
    2.36                      <jvmarg line="${run.jvmargs.prop}"/>
    2.37                      <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
    2.38                  </testng>
    2.39 @@ -102,6 +104,33 @@
    2.40          </macrodef>
    2.41      </target>
    2.42  
    2.43 +    <target name="-init-macrodef-testng-debug">
    2.44 +        <macrodef name="testng-debug">
    2.45 +            <attribute default="${main.class}" name="classname"/>
    2.46 +            <attribute default="${debug.classpath}" name="classpath"/>
    2.47 +            <element name="customize" optional="true"/>
    2.48 +            <sequential>
    2.49 +                <java classname="@{classname}" dir="${work.dir}" fork="true">
    2.50 +                    <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
    2.51 +                    <jvmarg line="${debug-args-line}"/>
    2.52 +                    <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
    2.53 +                    <jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
    2.54 +                    <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
    2.55 +                    <jvmarg line="${run.jvmargs.prop}"/>
    2.56 +                    <classpath>
    2.57 +                        <path path="@{classpath}"/>
    2.58 +                    </classpath>
    2.59 +                    <syspropertyset>
    2.60 +                        <propertyref prefix="run-sys-prop."/>
    2.61 +                        <mapper from="run-sys-prop.*" to="*" type="glob"/>
    2.62 +                    </syspropertyset>
    2.63 +                    <customize/>
    2.64 +                </java>
    2.65 +            </sequential>
    2.66 +        </macrodef>
    2.67 +    </target>
    2.68 +
    2.69 +    <!-- redefine project specific junit macros to run testng instead -->
    2.70      <target name="-testng">
    2.71          <!-- Java SE projects -->
    2.72          <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
    2.73 @@ -109,12 +138,7 @@
    2.74              <attribute default="${excludes}" name="excludes"/>
    2.75              <attribute default="**" name="testincludes"/>
    2.76              <sequential>
    2.77 -                <testng-ant/>
    2.78 -                <condition property="tests.failed">
    2.79 -                    <and>
    2.80 -                        <isset property="testng.tests.failed"/>
    2.81 -                    </and>
    2.82 -                </condition>
    2.83 +                <testng-ant includes="@{includes}" excludes="@{excludes}" testincludes="@{testincludes}"/>
    2.84              </sequential>
    2.85          </macrodef>
    2.86  
    2.87 @@ -124,12 +148,7 @@
    2.88              <attribute default="${excludes}" name="excludes"/>
    2.89              <attribute default="**" name="testincludes"/>
    2.90              <sequential>
    2.91 -                <testng-ant/>
    2.92 -                <condition property="tests.failed">
    2.93 -                    <and>
    2.94 -                        <isset property="testng.tests.failed"/>
    2.95 -                    </and>
    2.96 -                </condition>
    2.97 +                <testng-ant includes="@{includes}" excludes="@{excludes}" testincludes="@{testincludes}"/>
    2.98              </sequential>
    2.99          </macrodef>
   2.100  
   2.101 @@ -139,12 +158,7 @@
   2.102              <attribute default="${excludes}" name="excludes"/>
   2.103              <attribute default="**" name="testincludes"/>
   2.104              <sequential>
   2.105 -                <testng-ant/>
   2.106 -                <condition property="tests.failed">
   2.107 -                    <and>
   2.108 -                        <isset property="testng.tests.failed"/>
   2.109 -                    </and>
   2.110 -                </condition>
   2.111 +                <testng-ant includes="@{includes}" excludes="@{excludes}" testincludes="@{testincludes}"/>
   2.112              </sequential>
   2.113          </macrodef>
   2.114  
   2.115 @@ -154,17 +168,12 @@
   2.116              <attribute default="${excludes}" name="excludes"/>
   2.117              <attribute default="**" name="testincludes"/>
   2.118              <sequential>
   2.119 -                <testng-ant/>
   2.120 -                <condition property="tests.failed">
   2.121 -                    <and>
   2.122 -                        <isset property="testng.tests.failed"/>
   2.123 -                    </and>
   2.124 -                </condition>
   2.125 +                <testng-ant includes="@{includes}" excludes="@{excludes}" testincludes="@{testincludes}"/>
   2.126              </sequential>
   2.127          </macrodef>
   2.128      </target>
   2.129  
   2.130 -    <target name="-reinit-tasks" depends="-init-env, -init-macrodef-testng, -testng" />
   2.131 +    <target name="-reinit-tasks" depends="-init-env, -init-macrodef-testng, -init-macrodef-testng-debug, -testng" />
   2.132  
   2.133      <target name="-run-testng-default" unless="testng.config">
   2.134          <testng-ant/>
   2.135 @@ -176,93 +185,36 @@
   2.136  
   2.137      <target name="run-testng" depends="compile-test, -init-macrodef-testng, -run-testng-default, -run-testng-custom"/>
   2.138  
   2.139 -    <!-- Call testng from java -->
   2.140 -    <target name="-init-macrodef-testng-java">
   2.141 -        <macrodef name="testng-java">
   2.142 -            <sequential>
   2.143 -                <pathconvert property="testng.classnames" pathsep=" ">
   2.144 -                    <path>
   2.145 -                        <fileset dir="${build.test.classes.dir}" includes="**/*.class"/>
   2.146 -                    </path>
   2.147 -                    <map from="${basedir}${file.separator}" to="-testclass "/>
   2.148 -                </pathconvert>
   2.149 -                <java classname="org.testng.TestNG" dir="${basedir}">
   2.150 -                    <classpath>
   2.151 -                        <path path="${run.test.classpath}:${j2ee.platform.classpath}"/>
   2.152 -                    </classpath>
   2.153 -                    <arg line="-d ${build.test.results.dir}"/>
   2.154 -                    <arg line="-sourcedir ${test.src.dir}"/>
   2.155 -                    <arg line="-log 2"/>
   2.156 -                    <arg line="${testng.classnames}"/>
   2.157 -                    <syspropertyset>
   2.158 -                        <propertyref prefix="test-sys-prop."/>
   2.159 -                        <mapper from="test-sys-prop.*" to="*" type="glob"/>
   2.160 -                    </syspropertyset>
   2.161 -                    <jvmarg value="-Dtestng.test.classpath=${build.test.classes.dir}"/>
   2.162 -                    <jvmarg value="-ea"/>
   2.163 -                    <jvmarg line="${run.jvmargs.prop}"/>
   2.164 -                </java>
   2.165 -            </sequential>
   2.166 -        </macrodef>
   2.167 -    </target>
   2.168 +    <!-- DEBUG -->
   2.169 +    <target name="debug-testng" depends="-init-env, init, compile-test-single, -debug-start-debugger-test, -debug-start-debuggee-testng"/>
   2.170  
   2.171 -    <target name="-init-macrodef-testng-java-xml">
   2.172 -        <macrodef name="testng-java-xml">
   2.173 -            <attribute name="testSuite" default="${build.dir}/generated/testng/temp-testng-customsuite.xml"/>
   2.174 -            <sequential>
   2.175 -                <java classname="org.testng.TestNG" dir="${basedir}">
   2.176 -                    <classpath>
   2.177 -                        <path path="${run.test.classpath}:${j2ee.platform.classpath}"/>
   2.178 -                    </classpath>
   2.179 -                    <arg line="-d ${build.test.results.dir}"/>
   2.180 -                    <arg line="-sourcedir ${test.src.dir}"/>
   2.181 -                    <arg line="@{testSuite}"/>
   2.182 -                    <syspropertyset>
   2.183 -                        <propertyref prefix="test-sys-prop."/>
   2.184 -                        <mapper from="test-sys-prop.*" to="*" type="glob"/>
   2.185 -                    </syspropertyset>
   2.186 -                    <jvmarg value="-Dtestng.test.classpath=${build.test.classes.dir}"/>
   2.187 -                    <jvmarg value="-ea"/>
   2.188 -                    <jvmarg line="${run.jvmargs.prop}"/>
   2.189 -                </java>
   2.190 -            </sequential>
   2.191 -        </macrodef>
   2.192 -    </target>
   2.193 -
   2.194 -    <!-- DEBUG -->
   2.195 -    <target depends="-init-env, init, compile-test-single, -debug-start-debugger-test, -debug-start-debuggee-testng" name="debug-testng"/>
   2.196 +    <target depends="init,compile-test,-debug-start-debuggee-testng" if="have.tests" name="-debug-start-debuggee-test"/>
   2.197  
   2.198      <target depends="init,compile-test" if="have.tests" name="-debug-start-debuggee-testng">
   2.199 -        <fail unless="testng.config">Must select test class in the IDE or set testng.config</fail>
   2.200 +        <condition property="valid.test.in">
   2.201 +            <or>
   2.202 +                <isset property="test.class"/>
   2.203 +                <isset property="test.class.or.method"/>
   2.204 +            </or>
   2.205 +        </condition>
   2.206 +        <fail unless="valid.test.in">Must select one file in the IDE or set test.class or testng.config</fail>
   2.207          <delete dir="${build.test.results.dir}" quiet="true"/>
   2.208          <mkdir dir="${build.test.results.dir}"/>
   2.209 -        <java classname="org.testng.TestNG" dir="${basedir}" fork="true">
   2.210 -            <classpath>
   2.211 -                <pathelement path="${ant.home}/lib/ant.jar"/>
   2.212 -                <pathelement path="${ant.home}/lib/ant-junit.jar"/>
   2.213 -                <pathelement path="${debug.test.classpath}"/>
   2.214 -                <pathelement path="${j2ee.platform.classpath}"/>
   2.215 -            </classpath>
   2.216 -            <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
   2.217 -            <syspropertyset>
   2.218 -                <propertyref prefix="test-sys-prop."/>
   2.219 -                <mapper from="test-sys-prop.*" to="*" type="glob"/>
   2.220 -            </syspropertyset>
   2.221 -            <syspropertyset>
   2.222 -                <propertyref prefix="run-sys-prop."/>
   2.223 -                <mapper from="run-sys-prop.*" to="*" type="glob"/>
   2.224 -            </syspropertyset>
   2.225 -            <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
   2.226 -            <jvmarg line="${debug-args-line}"/>
   2.227 -            <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
   2.228 -            <jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
   2.229 -            <jvmarg line="${run.jvmargs.prop}"/>
   2.230 -            <jvmarg value="-Dtestng.test.classpath=${build.test.classes.dir}"/>
   2.231 -            <jvmarg value="-ea"/>
   2.232 -            <arg line="-d ${build.test.results.dir}"/>
   2.233 -            <arg line="-listener org.testng.reporters.VerboseReporter"/>
   2.234 -            <arg line="${testng.config}"/>
   2.235 -        </java>
   2.236 +        <property name="test.class.or.method" value="-testclass ${test.class}"/>
   2.237 +        <testng-debug classname="org.testng.TestNG" classpath="${debug.test.classpath}:${j2ee.platform.classpath}">
   2.238 +            <customize>
   2.239 +                <syspropertyset>
   2.240 +                    <propertyref prefix="test-sys-prop."/>
   2.241 +                    <mapper from="test-sys-prop.*" to="*" type="glob"/>
   2.242 +                </syspropertyset>
   2.243 +                <jvmarg value="-ea"/>
   2.244 +                <arg line="-mixed"/>
   2.245 +                <arg line="-d ${build.test.results.dir}"/>
   2.246 +                <arg line="-listener org.testng.reporters.VerboseReporter"/>
   2.247 +                <arg line="${test.name.arg}"/>
   2.248 +                <arg line="${test.class.or.method}"/>
   2.249 +            </customize>
   2.250 +        </testng-debug>
   2.251      </target>
   2.252  
   2.253  </project>