Skip to content

Commit 31348f8

Browse files
jtkbvpisarev
authored andcommitted
Removed hard-coded version from integration test. (opencv#9335)
Documented how to change the version of Maven to match OpenCV core and modified bash scripts accordingly. Extracted integration test module and placed into own profile. Configured CMake Maven plugin to use native CMake by default. Updated documentation.
1 parent bc09d1b commit 31348f8

File tree

8 files changed

+100
-29
lines changed

8 files changed

+100
-29
lines changed

platforms/maven/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/*.iml
2+
.idea/
3+
**/*.versionsBackup

platforms/maven/README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ By default the following build directories are created.
4747

4848
`<OpenCV_root_dir>/build/maven/opencv-it/target`
4949

50-
Under `build` are the standard OpenCV artifacts. Under `build/maven/opencv/target` can be found the OSGi compatible Java bundle. When deploying the bundle into an OSGi framework e.g. [Apache Karaf](http://karaf.apache.org/), loading of the native library is automatically taken care of. An integration testing module is created under the `open-cv` directory and is only of use during the build. The standard Java library as created by the CMake process is also available as specified in the existing OpenCV documentation.
50+
Under `build` are the standard OpenCV artifacts. Under `build/maven/opencv/target` can be found the OSGi compatible Java bundle. When deploying the bundle into an OSGi framework e.g. [Apache Karaf](http://karaf.apache.org/), loading of the native library is automatically taken care of. An integration testing module is created under the `opencv-it` directory and is only of use during the build but is disabled by fault. The standard Java library as created by the CMake process is also available as specified in the existing OpenCV documentation.
5151

5252
The Maven build is initiated from the directory contain the `pom.xml` file.
5353
#### 3.3 - x86 or x86_64 Architecture:
5454
Generally all that is required is the standard Maven command:
5555

56-
`mvn clean install -Ddownload.cmake=false`
56+
`mvn clean install`
5757

5858
One of the first things the build will do is check the required native dependencies. The Maven build indicates the status of the required dependencies and will fail at this point if any are missing. Install using the package manager e.g. aptitude or apt-get, and restart the build with the above command.
5959

@@ -64,8 +64,32 @@ Similar to the x86 architecture the native dependencies are first checked so ins
6464

6565
**PLEASE NOTE THESE ARE NOT OFFICIAL RASPBIAN PACKAGES. INSTALL AT YOUR OWN RISK.**
6666

67-
OpenCV is built using CMake and the Maven build process uses the the [cmake-maven plugin](https://github.com/cmake-maven-project/cmake-maven-project). The cmake-maven plugin by default downloads CMake at build time but unfortunately there is no binary for ARM architecture currently available. As a work around it is possible to use the native CMake (which is checked for availability in the above dependency checks). Assuming all native dependencies are available the build can be started with the following command:
67+
The build can be started with the following command:
6868

69-
`mvn clean install -Ddownload.cmake=false`
69+
`mvn clean install`
7070

7171
Upon a successful build the libraries will be available as described above in 'Build Directory'.
72+
73+
#### 3.5 CMake
74+
**Applicability:** x86 processors
75+
76+
The CMake Maven plugin is configured to use the native CMake package (recommended) i.e. it will NOT download the latest CMake binary. Should you require CMake download then include the following Maven commandline switch when building:
77+
78+
`-Ddownload.cmake=true`
79+
80+
#### 3.6 Integration Tests
81+
**Applicability:** All processors
82+
83+
OSGi integration tests can be run as part of the build by including the following commandline switch to Maven:
84+
85+
`-Pintegration`
86+
87+
### 4.0 Maintainer Notes
88+
This section is relevant to those maintaining the Maven platform build. If you just want to build the library then you do not need to refer to this section.
89+
90+
#### 4.1 Updating POM Version to Match Core Version
91+
Maven requires the version to be hard-coded in the POM or in otherwords it cannot be changed at runtime. When the core C/C++ code version changes it is easy to forget to update the Maven version. The POM utilises the enforcer plugin to ensure the POM and Core versions match causing the build to fail if they do not.
92+
93+
Should the POM version require updating then this can be done utilising the Maven 'versions' plugin and this will apply the correct version to all POMs within the project. Execute the following Maven command from the root directory of the Maven project:
94+
95+
`mvn versions:set -DnewVersion=$(. ./opencv/scripts/functions && cd ./opencv/scripts && extract_version && echo $REPLY)`

platforms/maven/opencv-it/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@
8888
<testSourceDirectory>src/test/java</testSourceDirectory>
8989
<testOutputDirectory>../../../build/maven/opencv-it/target</testOutputDirectory>
9090
<plugins>
91+
<plugin>
92+
<groupId>org.apache.servicemix.tooling</groupId>
93+
<artifactId>depends-maven-plugin</artifactId>
94+
<version>1.4.0</version>
95+
<executions>
96+
<execution>
97+
<id>generate-depends-file</id>
98+
<goals>
99+
<goal>generate-depends-file</goal>
100+
</goals>
101+
</execution>
102+
</executions>
103+
</plugin>
91104
<plugin>
92105
<groupId>org.apache.maven.plugins</groupId>
93106
<artifactId>maven-surefire-plugin</artifactId>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static Option[] configuration() throws Exception {
6565
mavenBundle()
6666
.groupId("org.opencv")
6767
.artifactId("opencv")
68-
.version("3.3.0"),
68+
.versionAsInProject(),
6969
logLevel(LogLevelOption.LogLevel.INFO)
7070
};
7171
}

platforms/maven/opencv/pom.xml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
<workingDirectory>${project.basedir}/scripts</workingDirectory>
5151
<arguments>
5252
<argument>properties</argument>
53-
<argument>../../../../modules/core/include/opencv2/core/version.hpp</argument>
5453
<argument>${build.directory}</argument>
5554
<argument>build.properties</argument>
5655
</arguments>
@@ -66,6 +65,8 @@
6665
<executable>bash</executable>
6766
<workingDirectory>${project.basedir}/scripts</workingDirectory>
6867
<arguments>
68+
<!-- Optional packages should be placed BEFORE required ones
69+
in the following argument list. -->
6970
<argument>deb_package_check</argument>
7071
<argument>-olibpng-dev|libpng12-dev</argument>
7172
<argument>-olibopenjp2-7-dev|libjasper-dev</argument>
@@ -175,14 +176,14 @@
175176
<configuration>
176177
<rules>
177178
<requireEnvironmentVariable>
178-
<level>WARN</level>
179+
<level>ERROR</level>
179180
<variableName>ANT_HOME</variableName>
180181
<message>$ANT_HOME is not set. Build may fail.</message>
181182
</requireEnvironmentVariable>
182183
<requireEnvironmentVariable>
183-
<level>WARN</level>
184+
<level>ERROR</level>
184185
<variableName>JAVA_HOME</variableName>
185-
<message>$JAVA_HOME is not set. Build may fail.</message>
186+
<message>$JAVA_HOME is not set. Build will fail.</message>
186187
</requireEnvironmentVariable>
187188
<requireEnvironmentVariable>
188189
<level>WARN</level>
@@ -204,7 +205,9 @@ To speed up the build you can try exporting MAKEFLAGS=-jX where X equals the num
204205
<requireProperty>
205206
<property>project.version</property>
206207
<regex>${opencv.version}</regex>
207-
<regexMessage>The Maven POM version ${project.version} does not match the extracted OpenCV version ${opencv.version}.</regexMessage>
208+
<regexMessage>The Maven POM version ${project.version} does not match the extracted OpenCV version ${opencv.version}.
209+
To correct this please execute the following Maven command from the Maven root directory:
210+
mvn versions:set -DnewVersion=$(. ./opencv/scripts/functions &amp;&amp; cd ./opencv/scripts &amp;&amp; extract_version &amp;&amp; echo $REPLY)</regexMessage>
208211
</requireProperty>
209212
</rules>
210213
</configuration>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
###############################################################
3+
#
4+
# Defines some common functions.
5+
#
6+
# Kerry Billingham <contact [At] AvionicEngineers.{com]>
7+
#
8+
##############################################################
9+
majorHashDefine="#define CV_VERSION_MAJOR"
10+
minorHashDefine="#define CV_VERSION_MINOR"
11+
revisionHashDefine="#define CV_VERSION_REVISION"
12+
statusHashDefine="#define CV_VERSION_STATUS"
13+
versionHeader="../../../../modules/core/include/opencv2/core/version.hpp"
14+
15+
function extract_version() {
16+
minorVersion=$(grep "${minorHashDefine}" $versionHeader | grep -o ".$")
17+
majorVersion=$(grep "${majorHashDefine}" $versionHeader | grep -o ".$")
18+
revision=$(grep "${revisionHashDefine}" $versionHeader | grep -o ".$")
19+
20+
REPLY="${majorVersion}.${minorVersion}.${revision}"
21+
}

platforms/maven/opencv/scripts/properties

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
# called during the Maven build process.
1414
#
1515
# Command-line parameters:
16-
# $1 - Absolute path to the file containing Open CV version
17-
# $2 - The build directory and where the output file will be written
18-
# $3 - The name of the output file to write to.
16+
# $1 - The build directory and where the output file will be written
17+
# $2 - The name of the output file to write to.
1918
#
2019
# Returns:
2120
# 0 - Successfully written the properties file.
@@ -28,21 +27,18 @@
2827
#
2928
#####################################################################
3029

31-
majorHashDefine="#define CV_VERSION_MAJOR"
32-
minorHashDefine="#define CV_VERSION_MINOR"
33-
revisionHashDefine="#define CV_VERSION_REVISION"
34-
statusHashDefine="#define CV_VERSION_STATUS"
30+
# Include some external functions and variables
31+
. ./functions
3532

3633
#Test build directory exists
37-
if [ ! -n "$2" ] || [ ! -d $2 ];then
34+
if [ ! -n "$1" ] || [ ! -d $1 ];then
3835
echo "Build directory not specified or does not exist!"
3936
exit 1
4037
fi
4138

42-
if [ -n "$1" ] && [ -e $1 ];then
43-
minorVersion=$(grep "${minorHashDefine}" $1 | grep -o ".$")
44-
majorVersion=$(grep "${majorHashDefine}" $1 | grep -o ".$")
45-
revision=$(grep "${revisionHashDefine}" $1 | grep -o ".$")
39+
if [ -n "${versionHeader}" ] && [ -e ${versionHeader} ];then
40+
41+
extract_version
4642

4743
bits=$(getconf LONG_BIT)
4844
architecture=$(arch)
@@ -78,13 +74,13 @@ if [ -n "$1" ] && [ -e $1 ];then
7874
esac
7975

8076
echo "The version number will be ${majorVersion}.${minorVersion}.${revision}"
81-
echo "opencv.version=${majorVersion}.${minorVersion}.${revision}" > ${2}/${3}
82-
echo "lib.version.string=${majorVersion}${minorVersion}${revision}" >> ${2}/${3}
83-
echo "bits=${bits}" >> ${2}/${3}
84-
echo "architecture=$(arch)" >> ${2}/${3}
85-
echo "osgi.processor=${osgiProcessor}" >> ${2}/${3}
77+
echo "opencv.version=${majorVersion}.${minorVersion}.${revision}" > ${1}/${2}
78+
echo "lib.version.string=${majorVersion}${minorVersion}${revision}" >> ${1}/${2}
79+
echo "bits=${bits}" >> ${1}/${2}
80+
echo "architecture=$(arch)" >> ${1}/${2}
81+
echo "osgi.processor=${osgiProcessor}" >> ${1}/${2}
8682
exit 0
8783
else
88-
echo "Could not locate file $1 to determine versioning."
84+
echo "Could not locate file ${versionHeader} to determine versioning."
8985
exit 1
9086
fi

platforms/maven/pom.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<pax.exam.version>4.8.0</pax.exam.version>
3232
<maven.compiler.source>1.7</maven.compiler.source>
3333
<maven.compiler.target>1.7</maven.compiler.target>
34+
<download.cmake>false</download.cmake>
3435
</properties>
3536
<distributionManagement>
3637
<snapshotRepository>
@@ -41,6 +42,16 @@
4142

4243
<modules>
4344
<module>opencv</module>
44-
<module>opencv-it</module>
4545
</modules>
46+
<profiles>
47+
<profile>
48+
<id>integration</id>
49+
<activation>
50+
<activeByDefault>false</activeByDefault>
51+
</activation>
52+
<modules>
53+
<module>opencv-it</module>
54+
</modules>
55+
</profile>
56+
</profiles>
4657
</project>

0 commit comments

Comments
 (0)