From 955611036c407891c0308be8e320d5d820079e6e Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Thu, 9 Aug 2012 23:46:34 -0500
Subject: [PATCH] Updated test build scripts.

The build scripts for test, util test, and common test
components have been updated to automatically find the
source codes and not create unnecessary test jar files.

Ticket #62
---
 base/common/test/CMakeLists.txt | 65 ++++++++++++-----------------------------
 base/test/src/CMakeLists.txt    | 26 ++++++-----------
 base/util/test/CMakeLists.txt   | 49 ++++++++++---------------------
 cmake/Modules/Java.cmake        |  3 ++
 4 files changed, 47 insertions(+), 96 deletions(-)

diff --git a/base/common/test/CMakeLists.txt b/base/common/test/CMakeLists.txt
index 2f7b4fa4eb601c1da736cc1b43596a03eda39e1f..181c7530fc5bee501974b58096ef0fdf18a01a4e 100644
--- a/base/common/test/CMakeLists.txt
+++ b/base/common/test/CMakeLists.txt
@@ -28,50 +28,24 @@ find_file(PKI_CMSBUNDLE_JAR
         ${JAVA_JAR_INSTALL_DIR}/pki
 )
 
-# TODO: create CMake function to find all Java files
-set(pki-common-test_SRCS
-    com/netscape/certsrv/app/CMSEngineDefaultStub.java
-    com/netscape/certsrv/authentication/AuthTokenTest.java
-    com/netscape/certsrv/logging/LoggerDefaultStub.java
-    com/netscape/certsrv/request/AgentApprovalsTest.java
-    com/netscape/cmscore/dbs/CertRecordListTest.java
-    com/netscape/cmscore/dbs/DBRegistryDefaultStub.java
-    com/netscape/cmscore/dbs/DBRegistryTest.java
-    com/netscape/cmscore/dbs/DBSSessionDefaultStub.java
-    com/netscape/cmscore/dbs/DBSubsystemDefaultStub.java
-    com/netscape/cmscore/dbs/DBVirtualListDefaultStub.java
-    com/netscape/cmscore/dbs/RequestRecordDefaultStub.java
-    com/netscape/cmscore/request/DBDynAttrMapperDefaultStub.java
-    com/netscape/cmscore/request/ExtAttrDynMapperTest.java
-    com/netscape/cmscore/request/ExtDataHashtableTest.java
-    com/netscape/cmscore/request/RequestDefaultStub.java
-    com/netscape/cmscore/request/RequestModDefaultStub.java
-    com/netscape/cmscore/request/RequestQueueTest.java
-    com/netscape/cmscore/request/RequestRecordTest.java
-    com/netscape/cmscore/request/RequestTest.java
-    com/netscape/cmscore/test/CMSBaseTestCase.java
-    com/netscape/cmscore/test/TestHelper.java
-)
-
-set(CMAKE_JAVA_INCLUDE_PATH
-    ${PKI_NSUTIL_JAR} ${PKI_CMSUTIL_JAR}
-    ${PKI_CERTSRV_JAR} ${PKI_CMS_JAR} ${PKI_CMSCORE_JAR} ${PKI_CMSBUNDLE_JAR}
-    ${LDAPJDK_JAR} ${SERVLET_JAR} ${VELOCITY_JAR} ${XALAN_JAR} ${XERCES_JAR}
-    ${JSS_JAR} ${COMMONS_CODEC_JAR} ${SYMKEY_JAR}
-    ${PKI_TEST_JAR} ${JUNIT_JAR}
-)
-
-set(CMAKE_JAVA_TARGET_VERSION ${APPLICATION_VERSION})
-
-# build test jar file
-# TODO: create CMake function to compile without building jar file
+# build pki-common-test
 # TODO: build test only when the test is invoked
-set(CMAKE_JAR_CLASSES_PREFIX com/netscape)
-add_jar(pki-common-test ${pki-common-test_SRCS})
-add_dependencies(pki-common-test
-    pki-nsutil pki-cmsutil
-    pki-certsrv pki-cms pki-cmscore pki-cmsbundle
-    pki-test
+javac(pki-common-test-classes
+    SOURCES
+        com/netscape/certsrv/*.java
+        com/netscape/cmscore/*.java
+    CLASSPATH
+        ${PKI_NSUTIL_JAR} ${PKI_CMSUTIL_JAR}
+        ${PKI_CERTSRV_JAR} ${PKI_CMS_JAR} ${PKI_CMSCORE_JAR} ${PKI_CMSBUNDLE_JAR}
+        ${LDAPJDK_JAR} ${SERVLET_JAR} ${VELOCITY_JAR} ${XALAN_JAR} ${XERCES_JAR}
+        ${JSS_JAR} ${COMMONS_CODEC_JAR} ${SYMKEY_JAR} ${JUNIT_JAR}
+        ${CMAKE_BINARY_DIR}/test/classes
+    OUTPUT_DIR
+        ${CMAKE_BINARY_DIR}/test/classes
+    DEPENDS
+        pki-test-classes
+        pki-nsutil pki-cmsutil
+        pki-certsrv pki-cms pki-cmscore pki-cmsbundle
 )
 
 # create test target
@@ -79,12 +53,11 @@ add_dependencies(pki-common-test
 # TODO: create CMake function to find all JUnit test classes
 add_junit_test(test-pki-common
     CLASSPATH
-        ${pki-common-test_JAR_FILE}
         ${PKI_NSUTIL_JAR} ${PKI_CMSUTIL_JAR}
         ${PKI_CERTSRV_JAR} ${PKI_CMS_JAR} ${PKI_CMSCORE_JAR} ${PKI_CMSBUNDLE_JAR}
         ${LDAPJDK_JAR} ${SERVLET_JAR} ${VELOCITY_JAR}
-        ${JSS_JAR} ${COMMONS_CODEC_JAR} ${SYMKEY_JAR}
-        ${PKI_TEST_JAR} ${JUNIT_JAR}
+        ${JSS_JAR} ${COMMONS_CODEC_JAR} ${SYMKEY_JAR} ${JUNIT_JAR}
+        ${CMAKE_BINARY_DIR}/test/classes
     TESTS
         com.netscape.certsrv.authentication.AuthTokenTest
         com.netscape.certsrv.request.AgentApprovalsTest
diff --git a/base/test/src/CMakeLists.txt b/base/test/src/CMakeLists.txt
index 3631baa73e528afb279c01d015170b0388baa001..5e7c12d6448191bdc9475d4b3aa3911f5041696a 100644
--- a/base/test/src/CMakeLists.txt
+++ b/base/test/src/CMakeLists.txt
@@ -1,20 +1,12 @@
 project(pki-test_java Java)
 
-# TODO: create CMake function to find all Java files
-set(pki-test_java_SRCS
-    com/netscape/test/TestListener.java
-    com/netscape/test/TestRunner.java
-)
-
-set(CMAKE_JAVA_INCLUDE_PATH
-    ${XALAN_JAR} ${XERCES_JAR} ${JUNIT_JAR}
-)
-
-set(CMAKE_JAVA_TARGET_VERSION ${APPLICATION_VERSION})
-
-# build test jar file
-# TODO: create CMake function to compile without building jar file
+# build pki-test
 # TODO: build test only when the test is invoked
-set(CMAKE_JAR_CLASSES_PREFIX com/netscape)
-add_jar(pki-test ${pki-test_java_SRCS})
-set(PKI_TEST_JAR ${pki-test_JAR_FILE} CACHE INTERNAL "pki-test jar file")
\ No newline at end of file
+javac(pki-test-classes
+    SOURCES
+        com/netscape/test/*.java
+    CLASSPATH
+        ${XALAN_JAR} ${XERCES_JAR} ${JUNIT_JAR}
+    OUTPUT_DIR
+        ${CMAKE_BINARY_DIR}/test/classes
+)
diff --git a/base/util/test/CMakeLists.txt b/base/util/test/CMakeLists.txt
index 592f3dbbb807a004a9655429fad4a9f2e494a9ad..28aae0a14a726c388696cd75dd72d1c464a72089 100644
--- a/base/util/test/CMakeLists.txt
+++ b/base/util/test/CMakeLists.txt
@@ -1,46 +1,29 @@
 project(pki-util-test Java)
 
-# TODO: create CMake function to find all Java files
-set(pki-util-test_SRCS
-    com/netscape/security/util/BMPStringTest.java
-    com/netscape/security/util/IA5StringTest.java
-    com/netscape/security/util/JSSUtil.java
-    com/netscape/security/util/PrintableStringTest.java
-    com/netscape/security/util/StringTestUtil.java
-    com/netscape/security/util/TeletexStringTest.java
-    com/netscape/security/util/UniversalStringTest.java
-    com/netscape/security/util/UTF8StringTest.java
-    com/netscape/security/x509/ConverterTestUtil.java
-    com/netscape/security/x509/DirStrConverterTest.java
-    com/netscape/security/x509/GenericValueConverterTest.java
-    com/netscape/security/x509/IA5StringConverterTest.java
-    com/netscape/security/x509/PrintableConverterTest.java
-)
-
-set(CMAKE_JAVA_INCLUDE_PATH
-    ${PKI_NSUTIL_JAR} ${PKI_CMSUTIL_JAR}
-    ${JSS_JAR} ${LDAPJDK_JAR} ${COMMONS_CODEC_JAR} ${XALAN_JAR} ${XERCES_JAR}
-    ${PKI_TEST_JAR} ${JUNIT_JAR}
-)
-
-set(CMAKE_JAVA_TARGET_VERSION ${APPLICATION_VERSION})
-
-# build test jar file
-# TODO: create CMake function to compile without building jar file
+# build pki-util-test
 # TODO: build test only when the test is invoked
-set(CMAKE_JAR_CLASSES_PREFIX com/netscape)
-add_jar(pki-util-test ${pki-util-test_SRCS})
-add_dependencies(pki-util-test pki-nsutil pki-cmsutil pki-test)
+javac(pki-util-test-classes
+    SOURCES
+        com/netscape/security/util/*.java
+        com/netscape/security/x509/*.java
+    CLASSPATH
+        ${PKI_NSUTIL_JAR} ${PKI_CMSUTIL_JAR}
+        ${JSS_JAR} ${LDAPJDK_JAR} ${COMMONS_CODEC_JAR} ${XALAN_JAR} ${XERCES_JAR}
+        ${PKI_TEST_JAR} ${JUNIT_JAR}
+    OUTPUT_DIR
+        ${CMAKE_BINARY_DIR}/test/classes
+    DEPENDS
+        pki-test-classes pki-nsutil pki-cmsutil
+)
 
 # create test target
 # do not include xalan and xerces in class path
 # TODO: create CMake function to find all JUnit test classes
 add_junit_test(test-pki-util
     CLASSPATH
-        ${pki-util-test_JAR_FILE}
         ${PKI_NSUTIL_JAR} ${PKI_CMSUTIL_JAR}
-        ${JSS_JAR} ${LDAPJDK_JAR} ${COMMONS_CODEC_JAR}
-        ${PKI_TEST_JAR} ${JUNIT_JAR}
+        ${JSS_JAR} ${LDAPJDK_JAR} ${COMMONS_CODEC_JAR} ${JUNIT_JAR}
+        ${CMAKE_BINARY_DIR}/test/classes
     TESTS
         com.netscape.security.util.BMPStringTest
         com.netscape.security.util.IA5StringTest
diff --git a/cmake/Modules/Java.cmake b/cmake/Modules/Java.cmake
index bd2855baf9adbe5b464a6add1db7f66ef784923b..78f14a22a183ad69c89182732abc73f5408409cc 100644
--- a/cmake/Modules/Java.cmake
+++ b/cmake/Modules/Java.cmake
@@ -67,6 +67,8 @@ function(javac target)
 
     add_custom_target(${target} ALL DEPENDS ${depends})
 
+    file(MAKE_DIRECTORY ${output_dir})
+
     add_custom_command(
         TARGET ${target}
         COMMAND ${CMAKE_COMMAND}
@@ -77,6 +79,7 @@ function(javac target)
             -P ${CMAKE_MODULE_PATH}/JavaFileList.cmake
         COMMAND ${CMAKE_Java_COMPILER}
             ${CMAKE_JAVA_COMPILE_FLAGS}
+            -encoding UTF-8
             -cp ${native_classpath}
             -d ${output_dir}
             @${file_list}
-- 
1.7.11.2

