From e7a9535e26e8f9dcb9a591dc8f5bfe99aa4fd7b7 Mon Sep 17 00:00:00 2001 From: Michał Lenart <michall@ipipan.waw.pl> Date: Mon, 13 Jan 2014 16:02:46 +0000 Subject: [PATCH] - praca nad paczkowaniem pythona do .deb - porządki w paczkowaniu Javy (wyrzucenie mavenowej maszynerii, użycie tylko cmake-owego add_jar) --- CMakeLists.txt | 27 ++++----------------------- CPackConfig.txt | 10 ++++++++++ jmorfeusz/nb-configuration.xml | 18 ------------------ jmorfeusz/nbactions.xml | 46 ---------------------------------------------- jmorfeusz/pom.xml | 115 ------------------------------------------------------------------------------------------------------------------- morfeusz/CMakeLists.txt | 6 +++--- morfeusz/java/CMakeLists.txt | 34 ++++++++++++++-------------------- morfeusz/java/pl/waw/ipipan/morfeusz/app/App.java | 22 ++++++++++++++++++++++ morfeusz/java/pl/waw/ipipan/morfeusz/app/MorfeuszUtils.java | 26 ++++++++++++++++++++++++++ morfeusz/python/CMakeLists.txt | 63 +++++++++++++++++++++++++++++++++++++++++++++++---------------- morfeusz/python/setup.py.in | 4 ++-- nbproject/configurations.xml | 2 +- 12 files changed, 129 insertions(+), 244 deletions(-) create mode 100644 CPackConfig.txt delete mode 100644 jmorfeusz/nb-configuration.xml delete mode 100644 jmorfeusz/nbactions.xml delete mode 100644 jmorfeusz/pom.xml create mode 100644 morfeusz/java/pl/waw/ipipan/morfeusz/app/App.java create mode 100644 morfeusz/java/pl/waw/ipipan/morfeusz/app/MorfeuszUtils.java diff --git a/CMakeLists.txt b/CMakeLists.txt index 7af245f..451981f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required (VERSION 2.8) -project (Morfeusz) +project (Morfeusz) + set (Morfeusz_VERSION_MAJOR 0) set (Morfeusz_VERSION_MINOR 1) set (CMAKE_BUILD_TYPE "Release") @@ -53,30 +54,9 @@ set (PYMORFEUSZ pymorfeusz) set (JMORFEUSZ jmorfeusz) ###### add some dependencies for SWIG modules ###### -add_dependencies (${PYMORFEUSZ} morfeusz) +#~ add_dependencies (${PYMORFEUSZ} morfeusz) add_dependencies (${JMORFEUSZ} morfeusz) -########## PYTHON ########## - -# find out library suffix -#~ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - #~ set (CMAKE_PYTHON_LIBRARY_SUFFIX ".so") -#~ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - #~ set (CMAKE_PYTHON_LIBRARY_SUFFIX ".pyd") -#~ else () - #~ set (CMAKE_PYTHON_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}) -#~ endif () - -# copy python->c++ bindings -#~ add_custom_target (copy-pymorfeusz-libs ALL - #~ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/morfeusz/python/pymorfeusz${CMAKE_PYTHON_LIBRARY_SUFFIX} ${PROJECT_BINARY_DIR}/pymorfeusz - #~ DEPENDS ${PYMORFEUSZ}) -#~ add_custom_target (copy-pymorfeusz-wrapper ALL - #~ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/morfeusz/python/morfeusz.py ${PROJECT_BINARY_DIR}/pymorfeusz - #~ DEPENDS ${PYMORFEUSZ}) -#~ -#~ add_test (TestPyMorfeusz python pymorfeusz/test.py) - ########## tests ########## macro (test_build_and_recognize fname method) @@ -104,3 +84,4 @@ set (CPACK_GENERATOR "DEB" "TGZ" "NSIS") set (CPACK_DEBIAN_PACKAGE_MAINTAINER "Michał Lenart") #required include (CPack) +set (CPACK_PROJECT_CONFIG_FILE PackConfig.txt) diff --git a/CPackConfig.txt b/CPackConfig.txt new file mode 100644 index 0000000..e74d89a --- /dev/null +++ b/CPackConfig.txt @@ -0,0 +1,10 @@ +set (CPACK_COMPONENTS_ALL baseasdfa) +#~ if (CPACK_GENERATOR STREQUAL "DEB") + #~ set (CPACK_COMPONENTS_ALL base pythondeb) +#~ elseif (CPACK_GENERATOR STREQUAL "TGZ") + #~ set (CPACK_COMPONENTS_ALL base pythontgz) +#~ elseif (CPACK_GENERATOR STREQUAL "NSIS") + #~ set (CPACK_COMPONENTS_ALL base) +#~ else + #~ set (CPACK_COMPONENTS_ALL base) +#~ endif () diff --git a/jmorfeusz/nb-configuration.xml b/jmorfeusz/nb-configuration.xml deleted file mode 100644 index c3e8f4d..0000000 --- a/jmorfeusz/nb-configuration.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project-shared-configuration> - <!-- -This file contains additional configuration written by modules in the NetBeans IDE. -The configuration is intended to be shared among all the users of project and -therefore it is assumed to be part of version control checkout. -Without this configuration present, some functionality in the IDE may be limited or fail altogether. ---> - <properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1"> - <!-- -Properties that influence various parts of the IDE, especially code formatting and the like. -You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up. -That way multiple projects can share the same settings (useful for formatting rules for example). -Any value defined here will override the pom.xml file value but is only applicable to the current project. ---> - <org-netbeans-modules-whitelist.whitelist-oracle>false</org-netbeans-modules-whitelist.whitelist-oracle> - </properties> -</project-shared-configuration> diff --git a/jmorfeusz/nbactions.xml b/jmorfeusz/nbactions.xml deleted file mode 100644 index f708a9f..0000000 --- a/jmorfeusz/nbactions.xml +++ /dev/null @@ -1,46 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<actions> - <action> - <actionName>run</actionName> - <packagings> - <packaging>jar</packaging> - </packagings> - <goals> - <goal>process-classes</goal> - <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal> - </goals> - <properties> - <exec.args>-Djava.library.path=target -classpath %classpath ${packageClassName}</exec.args> - <exec.executable>java</exec.executable> - </properties> - </action> - <action> - <actionName>debug</actionName> - <packagings> - <packaging>jar</packaging> - </packagings> - <goals> - <goal>process-classes</goal> - <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal> - </goals> - <properties> - <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -Djava.library.path=target -classpath %classpath ${packageClassName}</exec.args> - <exec.executable>java</exec.executable> - <jpda.listen>true</jpda.listen> - </properties> - </action> - <action> - <actionName>profile</actionName> - <packagings> - <packaging>jar</packaging> - </packagings> - <goals> - <goal>process-classes</goal> - <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal> - </goals> - <properties> - <exec.args>-Djava.library.path=target -classpath %classpath ${packageClassName}</exec.args> - <exec.executable>java</exec.executable> - </properties> - </action> - </actions> diff --git a/jmorfeusz/pom.xml b/jmorfeusz/pom.xml deleted file mode 100644 index 1aa3cfe..0000000 --- a/jmorfeusz/pom.xml +++ /dev/null @@ -1,115 +0,0 @@ -<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/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>pl.waw.ipipan.morfeusz</groupId> - <artifactId>jmorfeusz</artifactId> - <version>1.0</version> - <packaging>jar</packaging> - - <name>jmorfeusz</name> - <url>http://maven.apache.org</url> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.11</version> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>2.3.2</version> - <configuration> - <source>1.5</source> - <target>1.5</target> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.16</version> - <configuration> - <argLine>-Djava.library.path=src/main/native</argLine> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>2.4</version> - <configuration> - <archive> - <manifest> - <mainClass>pl.waw.ipipan.morfeusz.app.App</mainClass> - </manifest> - </archive> - </configuration> - </plugin> - - <plugin> - <artifactId>maven-resources-plugin</artifactId> - <version>2.6</version> - <executions> - <execution> - <id>copy-resources</id> - <!-- here the phase you need --> - <phase>validate</phase> - <goals> - <goal>copy-resources</goal> - </goals> - <configuration> - <outputDirectory>${project.build.directory}</outputDirectory> - <resources> - <resource> - <directory>src/main/resources</directory> - <!--<filtering>true</filtering>--> - </resource> - </resources> - </configuration> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-assembly-plugin</artifactId> - <configuration> - <descriptor>src/main/assembly/bin.xml</descriptor> - <outputDirectory>${packageDir}</outputDirectory> -<!-- - <finalName>apache-maven-cookbook-${pom.version}</finalName> ---> - </configuration> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>single</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - - - <profiles> - <profile> - <id>otherOutputDir</id> - <build> - <directory>${buildDir}</directory> - </build> - </profile> - </profiles> -</project> diff --git a/morfeusz/CMakeLists.txt b/morfeusz/CMakeLists.txt index efbe8e8..e178fa6 100644 --- a/morfeusz/CMakeLists.txt +++ b/morfeusz/CMakeLists.txt @@ -62,6 +62,6 @@ endif () add_subdirectory (java) add_subdirectory (python) -install (FILES ${INCLUDE_FILES} DESTINATION include/morfeusz) -install (TARGETS libmorfeusz DESTINATION lib) -install (TARGETS morfeusz DESTINATION bin) +install (FILES ${INCLUDE_FILES} DESTINATION include/morfeusz COMPONENT base) +install (TARGETS libmorfeusz DESTINATION lib COMPONENT base) +install (TARGETS morfeusz DESTINATION bin COMPONENT base) diff --git a/morfeusz/java/CMakeLists.txt b/morfeusz/java/CMakeLists.txt index 559d562..d7355c0 100644 --- a/morfeusz/java/CMakeLists.txt +++ b/morfeusz/java/CMakeLists.txt @@ -1,9 +1,11 @@ # SWIG #set(CMAKE_SWIG_OUTDIR swig) #FIND_PACKAGE(SWIG REQUIRED) -FIND_PACKAGE(JNI REQUIRED) +set (JMORFEUSZ_VERSION "0.1.0") +find_package(JNI REQUIRED) #INCLUDE(${SWIG_USE_FILE}) include(UseJava) +find_package(Java REQUIRED) # SWIG Java include_directories (${JAVA_INCLUDE_PATH}) @@ -11,10 +13,11 @@ include_directories (${JAVA_INCLUDE_PATH2}) include_directories (..) set (SWIG_JAVA_OUTFILE swigJAVA.cpp) +set (JAVA_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/pl/waw/ipipan/morfeusz") # set (JAVA_WRAPPER_FILE ${CMAKE_SHARED_LIBRARY_PREFIX}morfeusz${CMAKE_SHARED_LIBRARY_SUFFIX}) add_custom_command ( OUTPUT ${SWIG_JAVA_OUTFILE} - COMMAND swig -java -c++ -package pl.waw.ipipan.morfeusz -o ${SWIG_JAVA_OUTFILE} -outdir ${CMAKE_SOURCE_DIR}/jmorfeusz/src/main/java/pl/waw/ipipan/morfeusz ${CMAKE_SOURCE_DIR}/morfeusz/morfeusz.i + COMMAND swig -java -c++ -package pl.waw.ipipan.morfeusz -o ${SWIG_JAVA_OUTFILE} -outdir ${JAVA_SRC_DIR} ${CMAKE_SOURCE_DIR}/morfeusz/morfeusz.i DEPENDS libmorfeusz ) #set (CMAKE_SHARED_LINKER_FLAGS "-s -Os -static-libstdc++ -static-libgcc") @@ -38,23 +41,14 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set (CMAKE_SHARED_LIBRARY_SUFFIX ".jnilib") endif () +set (CMAKE_JAVA_TARGET_VERSION ${JMORFEUSZ_VERSION}) +set (CMAKE_JAVA_TARGET_OUTPUT_NAME jmorfeusz) + # build jmorfeusz -add_custom_target ( jmorfeusz-maven-package package - COMMAND mvn package -PotherOutputDir -DbuildDir=${CMAKE_CURRENT_BINARY_DIR} -DpackageDir=${PROJECT_BINARY_DIR} -DskipTests=true - DEPENDS ${JMORFEUSZ} - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/jmorfeusz) - -#~ file(GLOB JMORFEUSZ_PACKAGE_FILES "${CMAKE_CURRENT_BINARY_DIR}/*.tar.gz") -#~ -#~ add_custom_target(jmorfeusz-maven-package-copy ALL - #~ DEPENDS jmorfeusz-maven-package) -#~ -#~ foreach (f ${JMORFEUSZ_PACKAGE_FILES}) - #~ MESSAGE ("COPY ${f} TO ${PROJECT_BINARY_DIR}") - #~ add_custom_command ( - #~ TARGET jmorfeusz-maven-package-copy - #~ COMMAND ${CMAKE_COMMAND} -E copy ${f} ${PROJECT_BINARY_DIR} - #~ - #~ ) -#~ endforeach () +add_jar (jmorfeusz-jar + SOURCES ${JAVA_SRC_DIR}/*.java ${JAVA_SRC_DIR}/app/*.java ) +file (GLOB FILES_TO_TAR "*.jar *.so *.dylib *.jnilib *.dll README*") +add_custom_target(package-java + COMMAND ${CMAKE_COMMAND} -E tar "cfvz" "${PROJECT_BINARY_DIR}/jmorfeusz-${JMORFEUSZ_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}.tgz" "${FILES_TO_TAR}" + DEPENDS jmorfeusz-jar jmorfeusz) diff --git a/morfeusz/java/pl/waw/ipipan/morfeusz/app/App.java b/morfeusz/java/pl/waw/ipipan/morfeusz/app/App.java new file mode 100644 index 0000000..adbc13b --- /dev/null +++ b/morfeusz/java/pl/waw/ipipan/morfeusz/app/App.java @@ -0,0 +1,22 @@ +package pl.waw.ipipan.morfeusz.app; + +import pl.waw.ipipan.morfeusz.Morfeusz; +import pl.waw.ipipan.morfeusz.ResultsIterator; + +/** + * Hello world! + * + */ +public class App { + + public static void main(String[] args) { + System.err.println("Working Directory = " + + System.getProperty("user.dir")); + System.err.println("java.library.path="+System.getProperty("java.library.path")); + Morfeusz morfeusz = new Morfeusz(); + ResultsIterator it = morfeusz.analyze("Ala ma kota i żółć."); + while (it.hasNext()) { + System.out.println(MorfeuszUtils.getInterpretationString(it.getNext())); + } + } +} diff --git a/morfeusz/java/pl/waw/ipipan/morfeusz/app/MorfeuszUtils.java b/morfeusz/java/pl/waw/ipipan/morfeusz/app/MorfeuszUtils.java new file mode 100644 index 0000000..86022a9 --- /dev/null +++ b/morfeusz/java/pl/waw/ipipan/morfeusz/app/MorfeuszUtils.java @@ -0,0 +1,26 @@ +package pl.waw.ipipan.morfeusz.app; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import pl.waw.ipipan.morfeusz.MorphInterpretation; + +/** + * + * @author mlenart + */ +public class MorfeuszUtils { + + public static String getInterpretationString(MorphInterpretation interp) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos); + ps.printf("%d %d %s %s %s %s", + interp.getStartNode(), + interp.getEndNode(), + interp.getOrth(), + interp.getLemma(), + interp.getTag(), + interp.getName()); + ps.flush(); + return baos.toString(); + } +} diff --git a/morfeusz/python/CMakeLists.txt b/morfeusz/python/CMakeLists.txt index 4304d07..6e72edc 100644 --- a/morfeusz/python/CMakeLists.txt +++ b/morfeusz/python/CMakeLists.txt @@ -1,13 +1,15 @@ # SWIG #set(CMAKE_SWIG_OUTDIR swig) -FIND_PACKAGE(SWIG REQUIRED) -FIND_PACKAGE(PythonLibs) -INCLUDE(${SWIG_USE_FILE}) +FIND_PACKAGE (SWIG REQUIRED) +FIND_PACKAGE (PythonLibs) +INCLUDE (${SWIG_USE_FILE}) + +set (PYMORFEUSZ_VERSION "0.1.0") # SWIG Java -INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) -INCLUDE_DIRECTORIES(..) +INCLUDE_DIRECTORIES (${PYTHON_INCLUDE_PATH}) +INCLUDE_DIRECTORIES (..) set (SWIG_PYTHON_OUTFILE swigPYTHON.cpp) # set (JAVA_WRAPPER_FILE ${CMAKE_SHARED_LIBRARY_PREFIX}morfeusz${CMAKE_SHARED_LIBRARY_SUFFIX}) @@ -35,21 +37,50 @@ add_custom_command ( #~ #~ endif () -set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in") -set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py") -set(DEPS "${CMAKE_CURRENT_BINARY_DIR}/morfeusz.py" "${SWIG_PYTHON_OUTFILE}") -set(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build") +set (SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in") +set (SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py") +set (DEPS "${CMAKE_CURRENT_BINARY_DIR}/morfeusz.py" "${SWIG_PYTHON_OUTFILE}") +set (OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build") -configure_file(${SETUP_PY_IN} ${SETUP_PY}) +configure_file (${SETUP_PY_IN} ${SETUP_PY}) -add_custom_command(OUTPUT ${OUTPUT} +add_custom_command (OUTPUT ${OUTPUT} COMMAND python ARGS setup.py build DEPENDS ${DEPS}) -add_custom_target(pymorfeusz ALL DEPENDS ${OUTPUT}) +add_custom_target (pymorfeusz ALL DEPENDS ${OUTPUT} morfeusz) + + +#~ install(CODE "execute_process(COMMAND python ${SETUP_PY} install --home=${CMAKE_INSTALL_PREFIX})" COMPONENT pythonapi DEPENDS ${OUTPUT} MESSAGE "DUPA") +#~ install(CODE "execute_process(COMMAND python ${SETUP_PY} --command-packages=stdeb.command bdist_deb)" COMPONENT pythondeb DEPENDS ${OUTPUT}) +#~ install(CODE "execute_process(COMMAND python ${SETUP_PY} bdist -d ${PROJECT_BINARY_DIR})" COMPONENT pythontgz DEPENDS ${OUTPUT}) + +if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + add_custom_target (install-python + COMMAND python ${SETUP_PY} install --home=${CMAKE_INSTALL_PREFIX} + DEPENDS ${pymorfeusz} + ) + add_custom_target (package-python-bin + COMMAND python ${SETUP_PY} bdist -d ${PROJECT_BINARY_DIR} + DEPENDS pymorfeusz + ) + add_custom_target (package-python-src + COMMAND python ${SETUP_PY} sdist -d ${PROJECT_BINARY_DIR} + DEPENDS pymorfeusz + ) + add_custom_target (package-python + DEPENDS package-python-bin package-python-src) + + set (PYMORFEUSZ_SRC_PACKAGE "${PROJECT_BINARY_DIR}/pymorfeusz-${PYMORFEUSZ_VERSION}.tar.gz") + add_custom_target (package-python-deb-src + COMMAND py2dsc ${PYMORFEUSZ_SRC_PACKAGE} + ) +endif () +#~ install (install-python + #~ COMMAND python ${SETUP_PY} install --home=${CMAKE_INSTALL_PREFIX} + #~ DEPENDS pymorfeusz) -set (CPACK_PACKAGE_NAME "dupa") -install (FILES setup.py.in DESTINATION bin) -include (CPack) -#install(CODE "execute_process(COMMAND python ${SETUP_PY} install --home=${CMAKE_INSTALL_PREFIX})") +#~ install (CODE + #~ COMMAND python ${SETUP_PY} install --home=${CMAKE_INSTALL_PREFIX} + #~ DEPENDS pymorfeusz) diff --git a/morfeusz/python/setup.py.in b/morfeusz/python/setup.py.in index b4c5e2c..d6a3fda 100644 --- a/morfeusz/python/setup.py.in +++ b/morfeusz/python/setup.py.in @@ -7,8 +7,8 @@ morfeusz = Extension('pymorfeusz', sources=['${CMAKE_CURRENT_BINARY_DIR}/${SWIG_PYTHON_OUTFILE}']) if __name__ == '__main__': - setup(name='morfeusz', - version='${PACKAGE_VERSION}', + setup(name='pymorfeusz', + version='${PYMORFEUSZ_VERSION}', package_dir={ '': '${CMAKE_CURRENT_BINARY_DIR}'}, py_modules = ['morfeusz'], ext_modules = [morfeusz]) diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 5ec4d34..9220c53 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <configurationDescriptor version="90"> <logicalFolder name="root" displayName="root" projectFiles="true" kind="ROOT"> - <logicalFolder name="f1" displayName="input" projectFiles="true" kind="ROOT"> + <logicalFolder name="f1" displayName="input" projectFiles="true"> </logicalFolder> <df root="morfeusz" name="0"> <df name="charset"> -- libgit2 0.22.2