Skip to content

Commit 2360291

Browse files
committed
java: update source files processing, maven stuff
1 parent 02829f7 commit 2360291

File tree

10 files changed

+78
-54
lines changed

10 files changed

+78
-54
lines changed

modules/java/CMakeLists.txt

+45-18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ if(EXISTS ${CMAKE_BINARY_DIR}/gen)
1818
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_BINARY_DIR}/gen")
1919
endif()
2020

21+
if(ANDROID)
22+
set(LIB_NAME_SUFIX "${OPENCV_VERSION_MAJOR}")
23+
else()
24+
set(LIB_NAME_SUFIX "${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}")
25+
endif()
26+
2127
ocv_module_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp")
2228
ocv_module_include_directories("${OpenCV_SOURCE_DIR}/include")
2329

@@ -69,7 +75,7 @@ macro(glob_more_specific_sources _type _root _output)
6975
elseif(${_type} STREQUAL "CPP")
7076
set(_masks "${_root}/src/cpp/*.cpp")
7177
elseif(${_type} STREQUAL "JAVA")
72-
set(_masks "${_root}/src/java/*.java")
78+
set(_masks "${_root}/src/java/*.java" "${_root}/src/java/*.java.in")
7379
elseif(${_type} STREQUAL "AIDL")
7480
set(_masks "${_root}/src/java/*.aidl")
7581
endif()
@@ -257,22 +263,49 @@ endforeach()
257263
# step 3: copy files to destination
258264
set(step3_input_files ${generated_java_sources} ${handwritten_java_sources} ${handwritten_aidl_sources})
259265
set(copied_files "")
266+
set(java_src_dir "${OpenCV_BINARY_DIR}/src")
260267
foreach(java_file ${step3_input_files})
261268
get_filename_component(java_file_name "${java_file}" NAME)
269+
set(__configure 0)
270+
if (java_file_name MATCHES "\\.in$")
271+
string(REGEX REPLACE "\\.in$" "" java_file_name "${java_file_name}")
272+
set(__configure 1)
273+
endif()
262274
string(REPLACE "-jdoc.java" ".java" java_file_name "${java_file_name}")
263-
string(REPLACE "+" "/" java_file_name "${java_file_name}")
264-
set(output_name "${OpenCV_BINARY_DIR}/src/org/opencv/${java_file_name}")
265-
add_custom_command(OUTPUT "${output_name}"
266-
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${java_file}" "${output_name}"
267-
MAIN_DEPENDENCY "${java_file}"
268-
DEPENDS ${step1_depends} ${generated_java_sources} ${handwritten_java_sources}
269-
COMMENT "Generating src/org/opencv/${java_file_name}"
270-
)
271-
list(APPEND copied_files "${output_name}")
275+
if(EXISTS "${java_file}")
276+
file(STRINGS "${java_file}" PACKAGE_STR LIMIT_COUNT 1 REGEX "package.*;$")
277+
else()
278+
set(PACKAGE_STR "")
279+
endif()
280+
if(PACKAGE_STR)
281+
list(GET PACKAGE_STR 0 package_name)
282+
string(REGEX REPLACE "^package[ ]+" "" package_name "${package_name}")
283+
string(REGEX REPLACE ";$" "" package_name "${package_name}")
284+
285+
string(REGEX REPLACE ".*\\+" "" java_file_name "${java_file_name}")
286+
string(REPLACE "." "/" package_path "${package_name}")
287+
set(output_name "${package_path}/${java_file_name}")
288+
else()
289+
string(REPLACE "+" "/" java_file_name "${java_file_name}")
290+
set(output_name "org/opencv/${java_file_name}")
291+
endif()
292+
if(__configure)
293+
configure_file("${java_file}" "${java_src_dir}/${output_name}" @ONLY)
294+
elseif(NOT "${java_file}" MATCHES "${OpenCV_BINARY_DIR}/")
295+
configure_file("${java_file}" "${java_src_dir}/${output_name}" COPYONLY)
296+
else()
297+
add_custom_command(OUTPUT "${java_src_dir}/${output_name}"
298+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${java_file}" "${java_src_dir}/${output_name}"
299+
MAIN_DEPENDENCY "${java_file}"
300+
DEPENDS "${java_file}"
301+
COMMENT "Generating src/${output_name}"
302+
)
303+
endif()
304+
list(APPEND copied_files "${java_src_dir}/${output_name}")
272305

273306
if(ANDROID)
274-
get_filename_component(install_subdir "${java_file_name}" PATH)
275-
install(FILES "${output_name}" DESTINATION "${JAVA_INSTALL_ROOT}/src/org/opencv/${install_subdir}" COMPONENT java)
307+
get_filename_component(install_subdir "${output_name}" PATH)
308+
install(FILES "${java_src_dir}/${output_name}" DESTINATION "${JAVA_INSTALL_ROOT}/src/${install_subdir}" COMPONENT java)
276309
endif()
277310
endforeach()
278311

@@ -334,12 +367,6 @@ endif(ANDROID AND ANDROID_EXECUTABLE)
334367

335368
set(step3_depends ${step2_depends} ${step3_input_files} ${copied_files})
336369

337-
if(ANDROID)
338-
set(LIB_NAME_SUFIX "${OPENCV_VERSION_MAJOR}")
339-
else()
340-
set(LIB_NAME_SUFIX "${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}")
341-
endif()
342-
343370
file(MAKE_DIRECTORY "${OpenCV_BINARY_DIR}/bin")
344371

345372
# step 4: build jar

modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void onStart() {
8282
// Using OpenCV Manager for initialization;
8383

8484
Log("Internal OpenCV library not found. Using OpenCV Manager for initialization");
85-
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, getContext(), mLoaderCallback);
85+
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION, getContext(), mLoaderCallback);
8686

8787
synchronized (this) {
8888
try {

modules/java/generator/src/java/android+OpenCVLoader.java modules/java/generator/src/java/android+OpenCVLoader.java.in

+11
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ public class OpenCVLoader
8282
*/
8383
public static final String OPENCV_VERSION_3_2_0 = "3.2.0";
8484

85+
/**
86+
* OpenCV Library version 3.3.0.
87+
*/
88+
public static final String OPENCV_VERSION_3_3_0 = "3.3.0";
89+
90+
/**
91+
* Current OpenCV Library version
92+
*/
93+
public static final String OPENCV_VERSION = "@OPENCV_VERSION_MAJOR@.@OPENCV_VERSION_MINOR@.@OPENCV_VERSION_PATCH@";
94+
95+
8596
/**
8697
* Loads and initializes OpenCV library from current application package. Roughly, it's an analog of system.loadLibrary("opencv_java").
8798
* @return Returns true is initialization of OpenCV was successful.

modules/java/generator/src/java/android+sync.py

-7
This file was deleted.

modules/java/generator/src/java/osgi+OpenCVNativeLoader.java modules/java/generator/src/java/osgi+OpenCVNativeLoader.java.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public class OpenCVNativeLoader implements OpenCVInterface {
1313

1414
public void init() {
15-
System.loadLibrary("opencv_java320");
15+
System.loadLibrary("opencv_java@LIB_NAME_SUFIX@");
1616
Logger.getLogger("org.opencv.osgi").log(Level.INFO, "Successfully loaded OpenCV native library.");
1717
}
1818
}

platforms/maven/opencv-it/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.opencv</groupId>
66
<artifactId>opencv-parent</artifactId>
7-
<version>3.2.0</version>
7+
<version>3.3.0</version>
88
</parent>
99
<groupId>org.opencv</groupId>
1010
<artifactId>opencv-it</artifactId>

platforms/maven/opencv-it/src/test/java/org/opencv/osgi/DeployOpenCVTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class DeployOpenCVTest {
3232
/*
3333
The expected string in Karaf logs when the bundle has deployed and native library loaded.
3434
*/
35-
private static final String OPEN_CV_SUCCESSFUL_LOAD_STRING = "Successfully loaded OpenCV native library.";
35+
private static final String OPENCV_SUCCESSFUL_LOAD_STRING = "Successfully loaded OpenCV native library.";
3636

3737
private static final String KARAF_VERSION = "4.0.6";
3838

@@ -65,7 +65,7 @@ public static Option[] configuration() throws Exception {
6565
mavenBundle()
6666
.groupId("org.opencv")
6767
.artifactId("opencv")
68-
.version("3.2.0"),
68+
.version("3.3.0"),
6969
logLevel(LogLevelOption.LogLevel.INFO)
7070
};
7171
}
@@ -78,7 +78,7 @@ public static Option[] configuration() throws Exception {
7878
public void testOpenCVNativeLibraryLoadSuccess() {
7979

8080
Iterable<PaxLoggingEvent> loggingEvents = logService.getEvents();
81-
boolean loadSuccessful = logsContainsMessage(loggingEvents, OPEN_CV_SUCCESSFUL_LOAD_STRING);
81+
boolean loadSuccessful = logsContainsMessage(loggingEvents, OPENCV_SUCCESSFUL_LOAD_STRING);
8282

8383
TestCase.assertTrue("Could not determine if OpenCV library successfully loaded from the logs.", loadSuccessful);
8484

platforms/maven/opencv/pom.xml

+8-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.opencv</groupId>
66
<artifactId>opencv-parent</artifactId>
7-
<version>3.2.0</version>
7+
<version>3.3.0</version>
88
</parent>
99
<groupId>org.opencv</groupId>
1010
<artifactId>opencv</artifactId>
@@ -89,21 +89,6 @@
8989
</arguments>
9090
</configuration>
9191
</execution>
92-
<execution>
93-
<id>execstack</id>
94-
<phase>process-classes</phase>
95-
<goals>
96-
<goal>exec</goal>
97-
</goals>
98-
<configuration>
99-
<workingDirectory>${build.directory}/lib</workingDirectory>
100-
<executable>execstack</executable>
101-
<arguments>
102-
<argument>-c</argument>
103-
<argument>libopencv_java320.so</argument>
104-
</arguments>
105-
</configuration>
106-
</execution>
10792
<execution>
10893
<id>check-execstack</id>
10994
<phase>process-classes</phase>
@@ -115,7 +100,7 @@
115100
<executable>bash</executable>
116101
<arguments>
117102
<argument>execstack_check</argument>
118-
<argument>${build.directory}/lib/libopencv_java320.so</argument>
103+
<argument>${build.directory}/lib/libopencv_java${lib.version.string}.so</argument>
119104
</arguments>
120105
</configuration>
121106
</execution>
@@ -190,10 +175,12 @@
190175
<configuration>
191176
<rules>
192177
<requireEnvironmentVariable>
178+
<level>WARN</level>
193179
<variableName>ANT_HOME</variableName>
194180
<message>$ANT_HOME is not set. Build may fail.</message>
195181
</requireEnvironmentVariable>
196182
<requireEnvironmentVariable>
183+
<level>WARN</level>
197184
<variableName>JAVA_HOME</variableName>
198185
<message>$JAVA_HOME is not set. Build WILL fail.</message>
199186
</requireEnvironmentVariable>
@@ -245,6 +232,7 @@
245232
<version>3.4.1-b2</version>
246233
<executions>
247234
<execution>
235+
<phase>generate-sources</phase>
248236
<id>cmake-generate</id>
249237
<goals>
250238
<goal>generate</goal>
@@ -255,15 +243,18 @@
255243
<generator>Unix Makefiles</generator>
256244
<options>
257245
<option>-DBUILD_SHARED_LIBS:BOOL=OFF</option>
246+
<option>-DWITH_CUDA=OFF</option>
258247
</options>
259248
</configuration>
260249
</execution>
261250
<execution>
251+
<phase>generate-sources</phase>
262252
<id>cmake-compile</id>
263253
<goals>
264254
<goal>compile</goal>
265255
</goals>
266256
<configuration>
257+
<target>opencv_java</target>
267258
<projectDirectory>../../../build</projectDirectory>
268259
</configuration>
269260
</execution>

platforms/maven/opencv/scripts/execstack_check

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ red=$'\e[1;31m'
2020
green=$'\e[1;32m'
2121
end=$'\e[0m'
2222
echo "${green}[INFO] Checking that the native library executable stack flag is NOT set.${end}"
23-
execstack -c $1
24-
execstack -q $1 | grep -o ^-
23+
BINARY=execstack
24+
$BINARY --help > /dev/null || BINARY=/usr/sbin/execstack
25+
$BINARY -c $1
26+
$BINARY -q $1 | grep -o ^-
2527
if [ $? -ne 0 ]; then
2628
echo
2729
echo "${red}[ERROR] The Executable Flag could not be cleared on the library $1.${end}"

platforms/maven/pom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.opencv</groupId>
55
<artifactId>opencv-parent</artifactId>
6-
<version>3.2.0</version>
6+
<version>3.3.0</version>
77
<packaging>pom</packaging>
88
<name>OpenCV Parent POM</name>
99
<licenses>
1010
<license>
1111
<name>License Agreement For Open Source Computer Vision Library (3-clause BSD License)</name>
12-
<url></url>
12+
<url>http://opencv.org/license.html</url>
1313
</license>
1414
</licenses>
1515
<url>http://opencv.org/</url>
@@ -29,8 +29,8 @@
2929
<properties>
3030
<nativelibrary.name>libopencv_java${lib.version.string}.so</nativelibrary.name>
3131
<pax.exam.version>4.8.0</pax.exam.version>
32-
<maven.compiler.source>1.8</maven.compiler.source>
33-
<maven.compiler.target>1.8</maven.compiler.target>
32+
<maven.compiler.source>1.7</maven.compiler.source>
33+
<maven.compiler.target>1.7</maven.compiler.target>
3434
</properties>
3535
<distributionManagement>
3636
<snapshotRepository>

0 commit comments

Comments
 (0)