8157061: Add support for running jtreg tests from IntelliJ project
authormcimadamore
Thu, 19 May 2016 16:48:43 +0100
changeset 37976 9cc5debe0f47
parent 37975 551c5d86de79
child 37977 2d1762634bf1
8157061: Add support for running jtreg tests from IntelliJ project Summary: Add basic capabilities for running jtreg tests from the IDE using a custom ant target Reviewed-by: chegar
common/bin/idea.sh
make/idea/idea.gmk
make/idea/template/ant.xml
make/idea/template/build.xml
make/idea/template/src/idea/JdkIdeaAntLogger.java
make/idea/template/workspace.xml
--- a/common/bin/idea.sh	Thu May 19 17:24:50 2016 +0200
+++ b/common/bin/idea.sh	Thu May 19 16:48:43 2016 +0100
@@ -155,6 +155,14 @@
   printf "%s\n" "$mn" >> $IDEA_ANT
 }
 
+JTREG_HOME="        <property name=\"jtreg.home\" value=\"####\" />"
+
+addJtregHome() {
+  DIR=`dirname $SPEC`
+  mn="`echo "$JTREG_HOME" | sed -e s@"\(.*\)####\(.*\)"@"\1$JT_HOME\2"@`"
+  printf "%s\n" "$mn" >> $IDEA_ANT
+}
+
 ### Generate ant.xml
 
 rm -f $IDEA_ANT
@@ -162,6 +170,8 @@
 do
   if echo "$line" | egrep "^ .* <property name=\"module.name\"" > /dev/null ; then
     addModuleName
+  elif echo "$line" | egrep "^ .* <property name=\"jtreg.home\"" > /dev/null ; then
+    addJtregHome
   elif echo "$line" | egrep "^ .* <property name=\"build.target.dir\"" > /dev/null ; then
     addBuildDir
   else
--- a/make/idea/idea.gmk	Thu May 19 17:24:50 2016 +0200
+++ b/make/idea/idea.gmk	Thu May 19 16:48:43 2016 +0100
@@ -35,5 +35,6 @@
 	$(ECHO) "BOOT_JDK=\"$(BOOT_JDK)\"" >> $(OUT)
 	$(ECHO) "CYGPATH=\"$(CYGPATH)\"" >> $(OUT)
 	$(ECHO) "SPEC=\"$(SPEC)\"" >> $(OUT)
+	$(ECHO) "JT_HOME=\"$(JT_HOME)\"" >> $(OUT)
 
 endif
--- a/make/idea/template/ant.xml	Thu May 19 17:24:50 2016 +0200
+++ b/make/idea/template/ant.xml	Thu May 19 16:48:43 2016 +0100
@@ -5,9 +5,8 @@
       <properties>
         <property name="boot.java.home" value="$JDKPath$" />
         <property name="jtreg.tests" value="$FilePath$" />
-        <property name="jtreg.home" value="###" />
+        <property name="jtreg.home" value="jtreg.home" />
         <property name="build.target.dir" value="specDir" /> <!-- this will be replaced --> 
-        <property name="jtreg.jpda.jvmargs" value="-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5900,suspend=y" />
         <property name="module.name" value="java.base" /> <!-- this will be replaced -->
       </properties>
       <executeOn event="afterCompilation" target="post-make" />
--- a/make/idea/template/build.xml	Thu May 19 17:24:50 2016 +0200
+++ b/make/idea/template/build.xml	Thu May 19 16:48:43 2016 +0100
@@ -16,6 +16,10 @@
         <os family="windows"/>
     </condition>
 
+    <target name="-check-jtreg.home" depends="-def-check">
+        <check name="jtreg" property="jtreg.home" marker="lib/jtreg.jar"/>
+    </target>
+
     <property name="test.dir" value="${basedir}/jdk/test"/>
 
     <macrodef name="call-make">
@@ -29,26 +33,6 @@
             </sequential>
         </macrodef>
 
-    <macrodef name="exec-target">
-        <attribute name="antfile" default="${ant.file}" />
-        <attribute name="target" />
-        <sequential>
-            <java classname="org.apache.tools.ant.Main" fork="true" spawn="true">
-                <arg value="-f"/>
-                <arg value="@{antfile}"/>  
-                <arg value="-Dboot.java.home=${boot.java.home}"/>
-                <arg value="-Dbuild.target.dir=${build.target.dir}"/>
-                <arg value="-Djtreg.home=${jtreg.home}"/>
-                <arg value="-Djtreg.tests=${jtreg.tests}"/>
-                <arg value="-Djtreg.jpda.jvmargs=${jtreg.jpda.jvmargs}"/>
-                <arg value="@{target}"/>
-                <classpath>           
-                    <pathelement path="${java.class.path}"/>
-                </classpath>
-            </java>
-        </sequential>
-    </macrodef>
-
     <target name="post-make" depends="build-module"/>
 
     <!--
@@ -59,7 +43,7 @@
         <echo message="base = ${basedir}"/>
         <call-make dir = "${build.target.dir}" args = "clean"/>
     </target>
-    
+
     <target name="-do-configure">
         <echo message="base = ${basedir}"/>
         <fail message="Not part of a full JDK forest">
@@ -122,5 +106,68 @@
             </sequential>
         </macrodef>
     </target>
+
+    <macrodef name="exec-target">
+        <attribute name="antfile" default="${ant.file}" />
+        <attribute name="target" />
+        <sequential>
+            <java classname="org.apache.tools.ant.Main" fork="true" spawn="true">
+                <arg value="-f"/>
+                <arg value="@{antfile}"/>
+                <arg value="-Dbuild.target.dir=${build.target.dir}"/>
+                <arg value="-Djtreg.home=${jtreg.home}"/>
+                <arg value="-Djtreg.tests=${jtreg.tests}"/>
+                <arg value="-Djtreg.jpda.jvmargs=${jtreg.jpda.jvmargs}"/>
+                <arg value="@{target}"/>
+                <classpath>
+                    <pathelement path="${java.class.path}"/>
+                </classpath>
+            </java>
+        </sequential>
+    </macrodef>
+
+    <target name="jtreg" depends="images,-def-jtreg">
+        <jtreg-tool name="all" tests="${jtreg.tests}"/>
+    </target>
+
+    <target name="-def-jtreg" unless="jtreg.defined" depends="-check-jtreg.home">
+        <taskdef name="jtreg" classname="com.sun.javatest.regtest.Main$$Ant">
+            <classpath>
+                <pathelement location="${jtreg.home}/lib/jtreg.jar"/>
+                <pathelement location="${jtreg.home}/lib/javatest.jar"/>
+            </classpath>
+        </taskdef>
+        <macrodef name="jtreg-tool">
+            <attribute name="name"/>
+            <attribute name="tests"/>
+            <attribute name="jdk" default="${build.target.dir}/images/jdk"/>
+            <attribute name="agentvm" default="true"/>
+            <attribute name="verbose" default="${default.jtreg.verbose}"/>
+            <attribute name="options" default="${other.jtreg.options}"/>
+            <attribute name="keywords" default="-keywords:!ignore"/>
+            <attribute name="jpda.jvmargs" default=""/>
+            <attribute name="extra.jvmargs" default=""/>
+            <attribute name="build.modules" default="${build.modules}"/>
+            <sequential>
+                <property name="coverage.options" value=""/>              <!-- default -->
+                <property name="coverage.classpath" value=""/>            <!-- default -->
+                <property name="default.jtreg.verbose" value="summary"/>  <!-- default -->
+                <property name="other.jtreg.options" value=""/>           <!-- default -->
+                <property name="jtreg.classfiles.to.modules" value="@{agentvm}"/>
+                <jtreg
+                    dir="${test.dir}"
+                    workDir="${build.target.dir}/idea/@{name}/work"
+                    reportDir="${build.target.dir}/idea/@{name}/report"
+                    jdk="@{jdk}"
+                    agentvm="@{agentvm}" verbose="@{verbose}"
+                    failonerror="false" resultproperty="jtreg.@{name}.result">
+                    <arg value="-debug:@{jpda.jvmargs}"/>
+                    <arg line="@{keywords}"/>
+                    <arg line="@{options}"/>
+                    <arg line="@{tests}"/>
+                </jtreg>
+            </sequential>
+        </macrodef>
+        <property name="jtreg.defined" value="true"/>
+    </target>
 </project>
-
--- a/make/idea/template/src/idea/JdkIdeaAntLogger.java	Thu May 19 17:24:50 2016 +0200
+++ b/make/idea/template/src/idea/JdkIdeaAntLogger.java	Thu May 19 16:48:43 2016 +0100
@@ -99,7 +99,9 @@
         /** jtreg test failure */
         JTREG_TEST_FAILED(StringBinaryPredicate.STARTS_WITH, MSG_ERR, "FAILED: "),
         /** jtreg test error */
-        JTREG_TEST_ERROR(StringBinaryPredicate.STARTS_WITH, MSG_ERR, "Error: ");
+        JTREG_TEST_ERROR(StringBinaryPredicate.STARTS_WITH, MSG_ERR, "Error: "),
+        /** jtreg report */
+        JTREG_TEST_REPORT(StringBinaryPredicate.STARTS_WITH, MSG_INFO, "Report written");
 
         StringBinaryPredicate sbp;
         int priority;
@@ -132,7 +134,7 @@
         MAKE("exec", MessageKind.MAKE_ERROR, MessageKind.MAKE_WARNING, MessageKind.MAKE_NOTE,
                        MessageKind.MAKE_OTHER, MessageKind.JAVAC_CRASH),
         /** jtreg task - invoked during test execution */
-        JTREG("jtreg", MessageKind.JTREG_TEST_PASSED, MessageKind.JTREG_TEST_FAILED, MessageKind.JTREG_TEST_ERROR),
+        JTREG("jtreg", MessageKind.JTREG_TEST_PASSED, MessageKind.JTREG_TEST_FAILED, MessageKind.JTREG_TEST_ERROR, MessageKind.JTREG_TEST_REPORT),
         /** initial synthetic task when the logger is created */
         ROOT("") {
             @Override
--- a/make/idea/template/workspace.xml	Thu May 19 17:24:50 2016 +0200
+++ b/make/idea/template/workspace.xml	Thu May 19 16:48:43 2016 +0100
@@ -8,6 +8,14 @@
   <component name="StructureViewFactory">
     <option name="ACTIVE_ACTIONS" value=",ALPHA_COMPARATOR" />
   </component>
+  <component name="RunManager" selected="Ant Target.jtreg">
+    <configuration default="false" name="jtreg" type="AntRunConfiguration" factoryName="Ant Target">
+      <antsettings antfile="file://$PROJECT_DIR$/.idea/build.xml" target="jtreg" />
+      <method>
+        <option name="Make" enabled="false" />
+      </method>
+    </configuration>
+  </component>
   <component name="antWorkspaceConfiguration">
     <option name="IS_AUTOSCROLL_TO_SOURCE" value="false" />
     <option name="FILTER_TARGETS" value="false" />