Commit 10bb623c authored by Brian Panneton's avatar Brian Panneton Committed by Kenneth Leiter

Added Ken Renards Java Updates from a patch

Ken sent me a manual patch, which I applied to grab the Java Changes.
parent d5dced0e
......@@ -42,11 +42,6 @@ if(XDMF_BUILD_DOCUMENTATION)
add_subdirectory(doc)
endif(XDMF_BUILD_DOCUMENTATION)
if(XDMF_BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif(XDMF_BUILD_TESTING)
if(XDMF_WRAP_PYTHON)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
......@@ -60,6 +55,30 @@ if(XDMF_WRAP_PYTHON)
install(TARGETS ${SWIG_MODULE_Xdmf_REAL_NAME} DESTINATION lib/python)
endif(XDMF_WRAP_PYTHON)
if(XDMF_WRAP_JAVA)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR})
set_source_files_properties(Xdmf.i PROPERTIES CPLUSPLUS ON)
find_package(Java REQUIRED)
find_package(JNI REQUIRED)
set(CMAKE_SWIG_FLAGS -v -make_default -package mil.army.arl.xdmf)
set(XDMF_JAVA_PACKAGE_DIR mil/army/arl/xdmf)
set(XDMF_JAVA_DIR ${CMAKE_CURRENT_BINARY_DIR}/${XDMF_JAVA_PACKAGE_DIR})
file(MAKE_DIRECTORY ${XDMF_JAVA_DIR})
set(CMAKE_SWIG_OUTDIR ${XDMF_JAVA_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
swig_add_module(XdmfJava java Xdmf.i)
swig_link_libraries(XdmfJava Xdmf)
add_dependencies(XdmfJava XdmfCoreJava)
set(XDMF_JAVA_JAR ${CMAKE_BINARY_DIR}/Xdmf.jar CACHE INTERNAL "")
add_custom_command(TARGET XdmfJava
POST_BUILD
DEPENDS ${XDMF_CORE_JAVA_JAR}
COMMAND ${JAVA_COMPILE} ARGS -cp ${XDMF_CORE_JAVA_JAR} "${CMAKE_CURRENT_BINARY_DIR}/mil/army/arl/xdmf/*.java"
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR} ${JAVA_ARCHIVE} -cvf ${XDMF_JAVA_JAR} "mil/army/arl/xdmf/*.class")
endif(XDMF_WRAP_JAVA)
option(XDMF_BUILD_UTILS OFF)
if(XDMF_BUILD_UTILS)
add_subdirectory(utils)
......@@ -69,3 +88,8 @@ file(GLOB XdmfHeaders *.hpp)
install(FILES ${XdmfHeaders} DESTINATION include)
install(TARGETS Xdmf LIBRARY DESTINATION lib)
if(XDMF_BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif(XDMF_BUILD_TESTING)
......@@ -41,6 +41,7 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
%import XdmfCore.i
#ifdef SWIGPYTHON
%pythoncode {
from XdmfCore import *
}
......@@ -91,6 +92,139 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
$result = SWIG_NewPointerObj(SWIG_as_voidptr(new boost::shared_ptr<XdmfItem>($1)), SWIGTYPE_p_boost__shared_ptrT_XdmfItem_t, SWIG_POINTER_OWN);
}
}
#endif
#if 0
%include std_set.i
%template(std_set_uint) std::set<unsigned int>;
// Abstract Base Classes
%template() Loki::Visitor<XdmfSet>;
#endif
#ifdef SWIGJAVA
// Typemaps that work for Java
%typemap(out) boost::shared_ptr<XdmfItem> {
if(boost::shared_ptr<XdmfAttribute> value = boost::shared_dynamic_cast<XdmfAttribute>($1))
{
*(boost::shared_ptr< XdmfAttribute > **)&($result) = value ? new boost::shared_ptr< XdmfAttribute >(value) : 0;
}
else if(boost::shared_ptr<XdmfDomain> value = boost::shared_dynamic_cast<XdmfDomain>($1))
{
*(boost::shared_ptr< XdmfDomain > **)&($result) = value ? new boost::shared_ptr< XdmfDomain >(value) : 0;
}
else if(boost::shared_ptr<XdmfGeometry> value = boost::shared_dynamic_cast<XdmfGeometry>($1))
{
*(boost::shared_ptr< XdmfGeometry > **)&($result) = value ? new boost::shared_ptr< XdmfGeometry >(value) : 0;
}
else if(boost::shared_ptr<XdmfGrid> value = boost::shared_dynamic_cast<XdmfGrid>($1))
{
*(boost::shared_ptr< XdmfGrid > **)&($result) = value ? new boost::shared_ptr< XdmfGrid >(value) : 0;
}
else if(boost::shared_ptr<XdmfGridCollection> value = boost::shared_dynamic_cast<XdmfGridCollection>($1))
{
*(boost::shared_ptr< XdmfGridCollection > **)&($result) = value ? new boost::shared_ptr< XdmfGridCollection >(value) : 0;
}
else if(boost::shared_ptr<XdmfInformation> value = boost::shared_dynamic_cast<XdmfInformation>($1))
{
*(boost::shared_ptr< XdmfInformation > **)&($result) = value ? new boost::shared_ptr< XdmfInformation >(value) : 0;
}
else if(boost::shared_ptr<XdmfSet> value = boost::shared_dynamic_cast<XdmfSet>($1))
{
*(boost::shared_ptr< XdmfSet > **)&($result) = value ? new boost::shared_ptr< XdmfSet >(value) : 0;
}
else if(boost::shared_ptr<XdmfTime> value = boost::shared_dynamic_cast<XdmfTime>($1))
{
*(boost::shared_ptr< XdmfTime > **)&($result) = value ? new boost::shared_ptr< XdmfTime >(value) : 0;
}
else if(boost::shared_ptr<XdmfTopology> value = boost::shared_dynamic_cast<XdmfTopology>($1))
{
*(boost::shared_ptr< XdmfTopology > **)&($result) = value ? new boost::shared_ptr< XdmfTopology >(value) : 0;
}
else
{
*(boost::shared_ptr< XdmfItem > **)&($result) = &($1);
}
}
// Swig+Java will automatically create 'getter' functions for static
// variables in a class (in this case the ItemTag member variable).
// This happens to conflict with the getters that Xdmf implements to
// override the otherwise virtual functions of the parent class. Here,
// we ask swig to ignore the static variable (thereby removing direct
// access to the variable, but leaving access to our getter function
%ignore XdmfAttribute::ItemTag;
%ignore XdmfDomain::ItemTag;
%ignore XdmfGeometry::ItemTag;
%ignore XdmfGrid::ItemTag;
%ignore XdmfGridCollection::ItemTag;
%ignore XdmfSet::ItemTag;
%ignore XdmfTime::ItemTag;
%ignore XdmfTopology::ItemTag;
%ignore XdmfMap::ItemTag;
// Swig+Java does not like 2 functions with the same prototype that
// simply return const/non-const versions of the same type. We
// ask Swig to ignore one of the two getter functions. We may
// have to change this to rename the function to a new name such
// that we preserve the ability to get a constant variable
%ignore XdmfDomain::getGrid(const unsigned int index) const;
%ignore XdmfDomain::getGridCollection(unsigned int const) const;
%ignore XdmfGrid::getAttribute(const unsigned int index) const;
%ignore XdmfGrid::getAttribute(const std::string & name) const;
%ignore XdmfGrid::getSet(const unsigned int index) const;
%ignore XdmfGrid::getSet(const std::string & name) const;
%ignore XdmfGrid::getGeometry() const;
%ignore XdmfGrid::getTime() const;
%ignore XdmfGrid::getTopology() const;
%ignore XdmfGridCollection::getGrid(const unsigned int index) const;
#endif
#ifdef SWIGJAVA
%ignore XdmfAttribute::ItemTag;
%ignore XdmfDomain::ItemTag;
%ignore XdmfGeometry::ItemTag;
%ignore XdmfGrid::ItemTag;
%ignore XdmfGridCollection::ItemTag;
%ignore XdmfSet::ItemTag;
%ignore XdmfTime::ItemTag;
%ignore XdmfTopology::ItemTag;
%ignore XdmfDomain::getGrid(const unsigned int index) const;
%ignore XdmfGrid::getAttribute(const unsigned int index) const;
%ignore XdmfGrid::getAttribute(const std::string & name) const;
%ignore XdmfGrid::getSet(const unsigned int index) const;
%ignore XdmfGrid::getSet(const std::string & name) const;
%ignore XdmfGrid::getGeometry() const;
%ignore XdmfGrid::getTime() const;
%ignore XdmfGrid::getTopology() const;
%ignore XdmfGrid::getMap() const;
%ignore XdmfGridCollection::getGrid(const unsigned int index) const;
%ignore XdmfSet::getHDF5Controller() const;
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("XdmfCoreJava");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load for XdmfCoreJava\n" + e);
System.exit(1);
}
try {
System.loadLibrary("XdmfJava");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load for XdmfJava\n" + e);
System.exit(1);
}
}
%}
#endif
// Shared Pointer Templates
%shared_ptr(XdmfAttribute)
......@@ -127,4 +261,4 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
%include XdmfSetType.hpp
%include XdmfTime.hpp
%include XdmfTopology.hpp
%include XdmfTopologyType.hpp
\ No newline at end of file
%include XdmfTopologyType.hpp
# Add a Java test
# One cannot simply do:
# SET(ENV{LD_LIBRARY_PATH} ${LIBRARY_OUTPUT_PATH})
# SET(my_test foo)
# ADD_TEST(JAVA_TEST_1 java ${my_test})
# Since cmake is only transmitting the ADD_TEST line to ctest thus you are loosing
# the env var. The only way to store the env var is to physically write in the cmake script
# whatever LD_LIBRARY_PATH you want and then add the test as 'cmake -P java_test.cmake'
#
# Usage:
# set (JAVA_TEST_DEPENDENCIES ${XDMF_CORE_JAVA_JAR} ${NETDMF_JAVA_JAR})
# set_source_files_properties(${test}.java PROPERTIES CLASSPATH "${XDMF_CORE_JAVA_JAR}:${NETDMF_JAVA_JAR}")
# set_source_files_properties(${test}.java PROPERTIES LDPATH "${CMAKE_BINARY_DIR}:${XDMF_LIBRARY_DIRS}")
# build_java_test(${test} ${test}.java ${JAVA_TEST_DEPENDENCIES})
# add_java_test(${test} ${test}.java)
#
# Modified by Zacarias Ojeda <zojeda@gmail.com>
MACRO(BUILD_JAVA_TEST TESTNAME FILENAME DEPS)
GET_SOURCE_FILE_PROPERTY(src_file ${FILENAME} LOCATION)
GET_SOURCE_FILE_PROPERTY(classpath ${FILENAME} CLASSPATH)
GET_FILENAME_COMPONENT(FILENAME_BASE ${src_file} NAME_WE)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME_BASE}.class
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${JAVA_COMPILE}
ARGS ${src_file} -d ${CMAKE_CURRENT_BINARY_DIR} -cp ${classpath} ${wo_semicolumn}
DEPENDS ${FILENAME} ${DEPS}
)
ADD_CUSTOM_TARGET("${FILENAME_BASE}_target" ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME_BASE}.class)
ENDMACRO(BUILD_JAVA_TEST TESTNAME FILENAME)
MACRO(ADD_JAVA_TEST TESTNAME FILENAME)
GET_SOURCE_FILE_PROPERTY(loc ${FILENAME} LOCATION)
GET_SOURCE_FILE_PROPERTY(classpath ${FILENAME} CLASSPATH)
GET_SOURCE_FILE_PROPERTY(ldpath ${FILENAME} LDPATH)
GET_SOURCE_FILE_PROPERTY(args ${FILENAME} ARGS)
GET_FILENAME_COMPONENT(loc2 ${loc} NAME_WE)
IF (NOT args)
SET(args "")
ENDIF (NOT args)
STRING(REGEX REPLACE ";" " " wo_semicolumn "${ARGN}")
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake
"
SET(ENV{LD_LIBRARY_PATH} ${ldpath}:$ENV{LD_LIBRARY_PATH})
MESSAGE("Running Compiled File" )
EXECUTE_PROCESS(
COMMAND ${JAVA_RUNTIME} -cp .:${classpath} ${loc2} ${args}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
RESULT_VARIABLE my_result
OUTPUT_VARIABLE my_output
ERROR_VARIABLE my_error
)
MESSAGE(\"result is \${my_result}\")
MESSAGE(\"output is \${my_output}\")
MESSAGE(\"error is \${my_error}\")
if(my_result)
MESSAGE(SEND_ERROR "\${result}")
endif(my_result)
"
)
ADD_TEST(${TESTNAME} ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake)
ENDMACRO(ADD_JAVA_TEST)
......@@ -49,6 +49,28 @@ if(XDMF_BUILD_TESTING)
add_subdirectory(tests)
endif(XDMF_BUILD_TESTING)
option(XDMF_WRAP_JAVA "Wrap Xdmf with Java" ON)
if(XDMF_WRAP_JAVA)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(Java REQUIRED)
find_package(JNI REQUIRED)
set(CMAKE_SWIG_FLAGS -v -make_default -package mil.army.arl.xdmf)
set(XDMF_CORE_JAVA_PACKAGE_DIR mil/army/arl/xdmf)
set(XDMF_CORE_JAVA_DIR ${CMAKE_CURRENT_BINARY_DIR}/${XDMF_CORE_JAVA_PACKAGE_DIR})
file(MAKE_DIRECTORY ${XDMF_CORE_JAVA_DIR})
set(CMAKE_SWIG_OUTDIR ${XDMF_CORE_JAVA_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
set_source_files_properties(XdmfCore.i PROPERTIES CPLUSPLUS ON)
swig_add_module(XdmfCoreJava java XdmfCore.i)
swig_link_libraries(XdmfCoreJava XdmfCore)
set(XDMF_CORE_JAVA_JAR ${CMAKE_BINARY_DIR}/XdmfCore.jar CACHE INTERNAL "")
add_custom_command(TARGET XdmfCoreJava
POST_BUILD
COMMAND ${JAVA_COMPILE} ARGS "${CMAKE_CURRENT_BINARY_DIR}/mil/army/arl/xdmf/*.java"
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR} ${JAVA_ARCHIVE} -cvf ${XDMF_CORE_JAVA_JAR} "mil/army/arl/xdmf/*.class")
endif(XDMF_WRAP_JAVA)
option(XDMF_WRAP_PYTHON OFF)
if(XDMF_WRAP_PYTHON)
find_package(SWIG REQUIRED)
......
......@@ -413,6 +413,11 @@ std::map<std::string, std::string> XdmfArray::getItemProperties() const
return arrayProperties;
}
std::string XdmfArray::getDimensionString() const
{
return(mDimensionString);
}
std::string XdmfArray::getItemTag() const
{
return ItemTag;
......@@ -573,6 +578,7 @@ void XdmfArray::populateItem(const std::map<std::string, std::string> & itemProp
{
sizeVal *= atoi((*iter).c_str());
}
mDimensionString = size->second;
}
else
{
......
......@@ -307,6 +307,8 @@ public:
template<typename T>
bool swap(std::vector<T> & array);
std::string getDimensionString() const;
/**
* Exchange the contents of the vector with the contents of this XdmfArray. No copy is made. The internal arrays are swapped.
*
......@@ -412,6 +414,7 @@ private:
boost::shared_ptr<XdmfHDF5Controller> mHDF5Controller;
std::string mName;
unsigned int mTmpReserveSize;
std::string mDimensionString;
};
#include "XdmfArray.tpp"
......
......@@ -43,6 +43,26 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>;
#ifdef SWIGJAVA
%ignore XdmfArray::ItemTag;
%ignore XdmfInformation::ItemTag;
%ignore XdmfDataItem::getArray() const;
%ignore XdmfArray::getHDF5Controller() const;
%ignore XdmfArray::getValuesPointer() const;
%ignore XdmfWriter::getHDF5Writer() const;
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("XdmfCoreJava");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load for XdmfCoreJava\n" + e);
System.exit(1);
}
}
%}
#endif
%include XdmfItem.hpp
%include XdmfItemProperty.hpp
%include XdmfVisitor.hpp
......@@ -87,6 +107,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%template(resizeAsUInt16) XdmfArray::resize<unsigned short>;
%template(resizeAsUInt32) XdmfArray::resize<unsigned int>;
#ifndef SWIGJAVA
// Provide accessors from python lists to XdmfArrays
%extend XdmfArray {
void copyValueAsInt8(int index, char value) {
......@@ -165,3 +186,4 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
self.copyValueAsUInt32(i+startIndex, values[i])
};
};
#endif /* SWIGJAVA */
......@@ -3,3 +3,6 @@ add_subdirectory(Cxx)
if(XDMF_WRAP_PYTHON)
add_subdirectory(Python)
endif(XDMF_WRAP_PYTHON)
if(XDMF_WRAP_JAVA)
add_subdirectory(Java)
endif(XDMF_WRAP_JAVA)
set(XdmfJavaTests
TestXdmfJava
)
include (UseJavaTest)
set(JAVA_TEST_DEPENDENCIES ${XDMF_CORE_JAVA_JAR} ${XDMF_JAVA_JAR})
foreach (test ${XdmfJavaTests})
set_source_files_properties(${test}.java PROPERTIES CLASSPATH "${XDMF_CORE_JAVA_JAR}:${XDMF_JAVA_JAR}")
set_source_files_properties(${test}.java PROPERTIES LDPATH "${CMAKE_BINARY_DIR}")
build_java_test(${test} ${test}.java ${JAVA_TEST_DEPENDENCIES})
add_java_test(${test} ${test}.java)
endforeach (test ${XdmfJavaTests})
import mil.army.arl.xdmf.*;
public class TestXdmfJava {
static {
System.loadLibrary("XdmfJava");
System.loadLibrary("XdmfCoreJava");
}
public static void main (String argv[]) {
System.out.println("Hello World");
XdmfWriter writer = XdmfWriter.New("outputJavaTest.xmf");
writer.setLightDataLimit((long)10);
XdmfGrid grid = XdmfGrid.New();
grid.setName("test");
grid.getGeometry().setType(XdmfGeometryType.XYZ());
XdmfDomain domain = XdmfDomain.New();
domain.insert(grid);
domain.accept(writer);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment