mirror of https://github.com/opencv/opencv.git
Merge pull request #8386 from jtkb:feature/cmake-maven-it-module
commit
9f0bbdada2
11 changed files with 576 additions and 245 deletions
@ -0,0 +1,8 @@ |
||||
package org.opencv.osgi; |
||||
|
||||
/** |
||||
* Dummy interface to allow some integration testing within OSGi implementation. |
||||
*/ |
||||
public interface OpenCVInterface |
||||
{ |
||||
} |
@ -0,0 +1,18 @@ |
||||
package org.opencv.osgi; |
||||
|
||||
import java.util.logging.Level; |
||||
import java.util.logging.Logger; |
||||
|
||||
/** |
||||
* This class is intended to provide a convenient way to load OpenCV's native |
||||
* library from the Java bundle. If Blueprint is enabled in the OSGi container |
||||
* this class will be instantiated automatically and the init() method called |
||||
* loading the native library. |
||||
*/ |
||||
public class OpenCVNativeLoader implements OpenCVInterface { |
||||
|
||||
public void init() { |
||||
System.loadLibrary("opencv_java320"); |
||||
Logger.getLogger("org.opencv.osgi").log(Level.INFO, "Successfully loaded OpenCV native library."); |
||||
} |
||||
} |
@ -0,0 +1,98 @@ |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<parent> |
||||
<groupId>org.opencv</groupId> |
||||
<artifactId>opencv-parent</artifactId> |
||||
<version>3.2.0</version> |
||||
</parent> |
||||
<groupId>org.opencv</groupId> |
||||
<artifactId>opencv-it</artifactId> |
||||
<name>OpenCV Integration Test</name> |
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.ops4j.pax.exam</groupId> |
||||
<artifactId>pax-exam-container-karaf</artifactId> |
||||
<version>${pax.exam.version}</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.ops4j.pax.exam</groupId> |
||||
<artifactId>pax-exam-junit4</artifactId> |
||||
<version>${pax.exam.version}</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.geronimo.specs</groupId> |
||||
<artifactId>geronimo-atinject_1.0_spec</artifactId> |
||||
<version>1.0</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.ops4j.pax.url</groupId> |
||||
<artifactId>pax-url-aether</artifactId> |
||||
<version>1.6.0</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.osgi</groupId> |
||||
<artifactId>org.osgi.core</artifactId> |
||||
<version>4.3.1</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.osgi</groupId> |
||||
<artifactId>org.osgi.compendium</artifactId> |
||||
<version>4.3.0</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>slf4j-api</artifactId> |
||||
<version>1.7.24</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>slf4j-simple</artifactId> |
||||
<version>1.7.24</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<artifactId>org.apache.karaf.log.core</artifactId> |
||||
<groupId>org.apache.karaf.log</groupId> |
||||
<version>4.0.6</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.ops4j.pax.logging</groupId> |
||||
<artifactId>pax-logging-api</artifactId> |
||||
<version>1.8.0</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>junit</groupId> |
||||
<artifactId>junit</artifactId> |
||||
<version>4.8.1</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>${project.groupId}</groupId> |
||||
<artifactId>opencv</artifactId> |
||||
<version>${project.version}</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
<build> |
||||
<directory>../../../build/maven/opencv-it/target</directory> |
||||
<testSourceDirectory>src/test/java</testSourceDirectory> |
||||
<testOutputDirectory>../../../build/maven/opencv-it/target</testOutputDirectory> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-surefire-plugin</artifactId> |
||||
<version>2.15</version> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
</project> |
@ -0,0 +1,97 @@ |
||||
package org.opencv.osgi; |
||||
|
||||
import java.io.File; |
||||
import javax.inject.Inject; |
||||
import junit.framework.TestCase; |
||||
import org.apache.karaf.log.core.LogService; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.ops4j.pax.exam.Configuration; |
||||
import static org.ops4j.pax.exam.CoreOptions.maven; |
||||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle; |
||||
import org.ops4j.pax.exam.Option; |
||||
import org.ops4j.pax.exam.junit.PaxExam; |
||||
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration; |
||||
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder; |
||||
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel; |
||||
import org.ops4j.pax.exam.karaf.options.LogLevelOption; |
||||
import org.ops4j.pax.exam.options.MavenArtifactUrlReference; |
||||
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; |
||||
import org.ops4j.pax.exam.spi.reactors.PerClass; |
||||
import org.ops4j.pax.logging.spi.PaxLoggingEvent; |
||||
import org.osgi.framework.BundleContext; |
||||
|
||||
/** |
||||
* |
||||
* @author Kerry Billingham <contact@AvionicEngineers.com> |
||||
*/ |
||||
@ExamReactorStrategy(PerClass.class) |
||||
@RunWith(PaxExam.class) |
||||
public class DeployOpenCVTest { |
||||
|
||||
/* |
||||
The expected string in Karaf logs when the bundle has deployed and native library loaded. |
||||
*/ |
||||
private static final String OPEN_CV_SUCCESSFUL_LOAD_STRING = "Successfully loaded OpenCV native library."; |
||||
|
||||
private static final String KARAF_VERSION = "4.0.6"; |
||||
|
||||
@Inject |
||||
protected BundleContext bundleContext; |
||||
|
||||
@Inject |
||||
private LogService logService; |
||||
|
||||
/* |
||||
This service is required to ensure that the native library has been loaded |
||||
before any test is carried out. |
||||
*/ |
||||
@Inject |
||||
private OpenCVInterface openCVInterface; |
||||
|
||||
@Configuration |
||||
public static Option[] configuration() throws Exception { |
||||
MavenArtifactUrlReference karafUrl = maven() |
||||
.groupId("org.apache.karaf") |
||||
.artifactId("apache-karaf") |
||||
.version(KARAF_VERSION) |
||||
.type("tar.gz"); |
||||
return new Option[]{ |
||||
karafDistributionConfiguration() |
||||
.frameworkUrl(karafUrl) |
||||
.unpackDirectory(new File("../../../build/target/exam")) |
||||
.useDeployFolder(false), |
||||
keepRuntimeFolder(), |
||||
mavenBundle() |
||||
.groupId("org.opencv") |
||||
.artifactId("opencv") |
||||
.version("3.2.0"), |
||||
logLevel(LogLevelOption.LogLevel.INFO) |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* Tests that the OpenCV bundle has been successfully deployed and that the |
||||
* native library has been loaded. |
||||
*/ |
||||
@Test |
||||
public void testOpenCVNativeLibraryLoadSuccess() { |
||||
|
||||
Iterable<PaxLoggingEvent> loggingEvents = logService.getEvents(); |
||||
boolean loadSuccessful = logsContainsMessage(loggingEvents, OPEN_CV_SUCCESSFUL_LOAD_STRING); |
||||
|
||||
TestCase.assertTrue("Could not determine if OpenCV library successfully loaded from the logs.", loadSuccessful); |
||||
|
||||
} |
||||
|
||||
private boolean logsContainsMessage(Iterable<PaxLoggingEvent> logEnumeration, final String logMessageString) { |
||||
boolean contains = false; |
||||
for (PaxLoggingEvent logEntry : logEnumeration) { |
||||
if (logEntry.getMessage().contains(logMessageString)) { |
||||
contains = true; |
||||
break; |
||||
} |
||||
} |
||||
return contains; |
||||
} |
||||
} |
@ -0,0 +1,279 @@ |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<parent> |
||||
<groupId>org.opencv</groupId> |
||||
<artifactId>opencv-parent</artifactId> |
||||
<version>3.2.0</version> |
||||
</parent> |
||||
<groupId>org.opencv</groupId> |
||||
<artifactId>opencv</artifactId> |
||||
<packaging>bundle</packaging> |
||||
<name>OpenCV</name> |
||||
|
||||
<properties> |
||||
<source.path>../../..</source.path> |
||||
<build.directory>${source.path}/build</build.directory> |
||||
<nativelibrary.name>libopencv_java${lib.version.string}.so</nativelibrary.name> |
||||
<resources.directory>${build.directory}/src</resources.directory> |
||||
</properties> |
||||
<build> |
||||
<directory>../../../build/maven/opencv/target</directory> |
||||
<outputDirectory>../../../build/src</outputDirectory> |
||||
<sourceDirectory>../../../build/src</sourceDirectory> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-clean-plugin</artifactId> |
||||
<version>3.0.0</version> |
||||
<configuration> |
||||
<filesets> |
||||
<fileset> |
||||
<directory>${build.directory}</directory> |
||||
</fileset> |
||||
</filesets> |
||||
</configuration> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.codehaus.mojo</groupId> |
||||
<artifactId>exec-maven-plugin</artifactId> |
||||
<version>1.4.0</version> |
||||
<executions> |
||||
<execution> |
||||
<id>get-opencv-version</id> |
||||
<phase>generate-resources</phase> |
||||
<goals> |
||||
<goal>exec</goal> |
||||
</goals> |
||||
<configuration> |
||||
<executable>bash</executable> |
||||
<workingDirectory>${project.basedir}/scripts</workingDirectory> |
||||
<arguments> |
||||
<argument>properties</argument> |
||||
<argument>../../../../modules/core/include/opencv2/core/version.hpp</argument> |
||||
<argument>${build.directory}</argument> |
||||
<argument>build.properties</argument> |
||||
</arguments> |
||||
</configuration> |
||||
</execution> |
||||
<execution> |
||||
<id>setup-environment</id> |
||||
<phase>validate</phase> |
||||
<goals> |
||||
<goal>exec</goal> |
||||
</goals> |
||||
<configuration> |
||||
<executable>bash</executable> |
||||
<workingDirectory>${project.basedir}/scripts</workingDirectory> |
||||
<arguments> |
||||
<argument>deb_package_check</argument> |
||||
<argument>build-essential</argument> |
||||
<argument>cmake</argument> |
||||
<argument>git</argument> |
||||
<argument>libgtk2.0-dev</argument> |
||||
<argument>pkg-config</argument> |
||||
<argument>libavcodec-dev</argument> |
||||
<argument>libavformat-dev</argument> |
||||
<argument>libswscale-dev</argument> |
||||
<argument>python-dev</argument> |
||||
<argument>python-numpy</argument> |
||||
<argument>libtbb2</argument> |
||||
<argument>libtbb-dev</argument> |
||||
<argument>libjpeg-dev</argument> |
||||
<argument>libpng12-dev</argument> |
||||
<argument>libtiff5-dev</argument> |
||||
<argument>libjasper-dev</argument> |
||||
<argument>libdc1394-22-dev</argument> |
||||
<argument>execstack</argument> |
||||
<argument>ant</argument> |
||||
</arguments> |
||||
</configuration> |
||||
</execution> |
||||
<execution> |
||||
<id>execstack</id> |
||||
<phase>process-classes</phase> |
||||
<goals> |
||||
<goal>exec</goal> |
||||
</goals> |
||||
<configuration> |
||||
<workingDirectory>${build.directory}/lib</workingDirectory> |
||||
<executable>execstack</executable> |
||||
<arguments> |
||||
<argument>-c</argument> |
||||
<argument>libopencv_java320.so</argument> |
||||
</arguments> |
||||
</configuration> |
||||
</execution> |
||||
<execution> |
||||
<id>check-execstack</id> |
||||
<phase>process-classes</phase> |
||||
<goals> |
||||
<goal>exec</goal> |
||||
</goals> |
||||
<configuration> |
||||
<workingDirectory>${project.basedir}/scripts</workingDirectory> |
||||
<executable>bash</executable> |
||||
<arguments> |
||||
<argument>execstack_check</argument> |
||||
<argument>${build.directory}/lib/libopencv_java320.so</argument> |
||||
</arguments> |
||||
</configuration> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
<plugin> |
||||
<artifactId>maven-resources-plugin</artifactId> |
||||
<version>3.0.2</version> |
||||
<executions> |
||||
<execution> |
||||
<id>copy-resources</id> |
||||
<phase>generate-resources</phase> |
||||
<goals> |
||||
<goal>copy-resources</goal> |
||||
</goals> |
||||
<configuration> |
||||
<outputDirectory>${resources.directory}</outputDirectory> |
||||
<resources> |
||||
<resource> |
||||
<directory>resources</directory> |
||||
</resource> |
||||
</resources> |
||||
</configuration> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.codehaus.mojo</groupId> |
||||
<artifactId>properties-maven-plugin</artifactId> |
||||
<version>1.0.0</version> |
||||
<executions> |
||||
<execution> |
||||
<id>set-arch-properties</id> |
||||
<phase>process-resources</phase> |
||||
<goals> |
||||
<goal>read-project-properties</goal> |
||||
</goals> |
||||
<configuration> |
||||
<files> |
||||
<file>${build.directory}/build.properties</file> |
||||
</files> |
||||
</configuration> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-enforcer-plugin</artifactId> |
||||
<version>1.4.1</version> |
||||
<executions> |
||||
<execution> |
||||
<phase>validate</phase> |
||||
<id>enforce-os</id> |
||||
<goals> |
||||
<goal>enforce</goal> |
||||
</goals> |
||||
<configuration> |
||||
<rules> |
||||
<requireOS> |
||||
<family>unix</family> |
||||
<message>This POM is written to function on UNIX family of OS. |
||||
More specifically it should be a Debian flavour of Linux.</message> |
||||
</requireOS> |
||||
</rules> |
||||
</configuration> |
||||
</execution> |
||||
<execution> |
||||
<id>enforce-environment</id> |
||||
<goals> |
||||
<goal>enforce</goal> |
||||
</goals> |
||||
<configuration> |
||||
<rules> |
||||
<requireEnvironmentVariable> |
||||
<variableName>ANT_HOME</variableName> |
||||
<message>$ANT_HOME is not set. Build may fail.</message> |
||||
</requireEnvironmentVariable> |
||||
<requireEnvironmentVariable> |
||||
<variableName>JAVA_HOME</variableName> |
||||
<message>$JAVA_HOME is not set. Build WILL fail.</message> |
||||
</requireEnvironmentVariable> |
||||
<requireEnvironmentVariable> |
||||
<level>WARN</level> |
||||
<variableName>MAKEFLAGS</variableName> |
||||
<message>No MAKEFLAGS environment variable. Build may be slow. |
||||
To speed up the build you can try exporting MAKEFLAGS=-jX where X equals the number of parallel builds.</message> |
||||
</requireEnvironmentVariable> |
||||
</rules> |
||||
</configuration> |
||||
</execution> |
||||
<execution> |
||||
<phase>process-resources</phase> |
||||
<id>check-versions-match</id> |
||||
<goals> |
||||
<goal>enforce</goal> |
||||
</goals> |
||||
<configuration> |
||||
<rules> |
||||
<requireProperty> |
||||
<property>project.version</property> |
||||
<regex>${opencv.version}</regex> |
||||
<regexMessage>The Maven POM version ${project.version} does not match the extracted OpenCV version ${opencv.version}.</regexMessage> |
||||
</requireProperty> |
||||
</rules> |
||||
</configuration> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.apache.felix</groupId> |
||||
<artifactId>maven-bundle-plugin</artifactId> |
||||
<version>2.3.7</version> |
||||
<extensions>true</extensions> |
||||
<configuration> |
||||
<instructions> |
||||
<Export-Package>*</Export-Package> |
||||
<Bundle-NativeCode>${nativelibrary.name};osname=linux;processor=${osgi.processor}</Bundle-NativeCode> |
||||
<Include-Resource>${build.directory}/lib/${nativelibrary.name}</Include-Resource> |
||||
</instructions> |
||||
<manifestLocation>${build.directory}/manifest</manifestLocation> |
||||
<niceManifest>true</niceManifest> |
||||
</configuration> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>com.googlecode.cmake-maven-project</groupId> |
||||
<artifactId>cmake-maven-plugin</artifactId> |
||||
<version>3.4.1-b2</version> |
||||
<executions> |
||||
<execution> |
||||
<id>cmake-generate</id> |
||||
<goals> |
||||
<goal>generate</goal> |
||||
</goals> |
||||
<configuration> |
||||
<sourcePath>../../..</sourcePath> |
||||
<targetPath>../../../build</targetPath> |
||||
<generator>Unix Makefiles</generator> |
||||
<options> |
||||
<option>-DBUILD_SHARED_LIBS:BOOL=OFF</option> |
||||
</options> |
||||
</configuration> |
||||
</execution> |
||||
<execution> |
||||
<id>cmake-compile</id> |
||||
<goals> |
||||
<goal>compile</goal> |
||||
</goals> |
||||
<configuration> |
||||
<projectDirectory>../../../build</projectDirectory> |
||||
</configuration> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-surefire-plugin</artifactId> |
||||
<version>2.15</version> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
</project> |
@ -0,0 +1,11 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<blueprint |
||||
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' |
||||
xmlns='http://www.osgi.org/xmlns/blueprint/v1.0.0' |
||||
xsi:schemaLocation='http://www.osgi.org/xmlns/blueprint/v1.0.0 https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd'> |
||||
|
||||
<bean id="opencvnativeloader" class="org.opencv.osgi.OpenCVNativeLoader" scope="singleton" init-method="init" /> |
||||
|
||||
<service id="opencvtestservice" ref="opencvnativeloader" interface="org.opencv.osgi.OpenCVInterface" /> |
||||
|
||||
</blueprint> |
@ -0,0 +1,30 @@ |
||||
#!/bin/bash |
||||
|
||||
################################################################## |
||||
# |
||||
# This script will clear the executable flag on |
||||
# the specified library and then check it has |
||||
# been cleared as a separate operation. |
||||
# |
||||
# $1 - The absolute path to the OpenCV native library. |
||||
# |
||||
# Returns: |
||||
# 0 - The executable flag has been cleared |
||||
# 1 - The executable flag could NOT be cleared (failure). |
||||
# |
||||
# Kerry Billingham <contact (at) avionicengineers (d0t) com> |
||||
# 11 March 2017 |
||||
# |
||||
################################################################## |
||||
red=$'\e[1;31m' |
||||
green=$'\e[1;32m' |
||||
end=$'\e[0m' |
||||
echo "${green}[INFO] Checking that the native library executable stack flag is NOT set.${end}" |
||||
execstack -c $1 |
||||
execstack -q $1 | grep -o ^- |
||||
if [ $? -ne 0 ]; then |
||||
echo |
||||
echo "${red}[ERROR] The Executable Flag could not be cleared on the library $1.${end}" |
||||
exit 1 |
||||
fi |
||||
exit 0 |
Loading…
Reference in new issue