Hi. Maven repo is now at http://qtjambi.sourceforge.net/maven2/.
Plugin artifactId was renamed to "qtjambi-maven-plugin", libraries wrapper to "qtjambi", group for both is "net.sf.qtjambi". Here is patch adding all scripts used to build this repo, I am not able to push it and haven't time to learn how to do it now. There is a readme.txt file explaining how things work, main scripts you need to have in mind are env_releases release_all.sh. Check out http://qtjambi.sourceforge.net/maven2/net/sf/qtjambi/testapp/SimpleQtApplication/0.1/SimpleQtApplication-0.1.pom to see how to create a simple app. Also, there is NO mac support at all. Contributors welcomed. -- Dusan
From 1c40900ed101085e143d5581b631d8e2627e55d5 Mon Sep 17 00:00:00 2001 From: Dusan Zatkovsky <[email protected]> Date: Thu, 21 Jan 2010 09:58:47 +0100 Subject: [PATCH] Added maven qtjambi stuff. --- maven/clean_binaries.sh | 5 + maven/env_releases | 17 + maven/import_binaries.sh | 33 ++ maven/mavenize_qtjambi.sh | 36 ++ maven/misc/qtjambi-base.pom | 8 + maven/misc/qtjambi-platform.pom | 20 + maven/plugin/pom.in | 147 ++++++ .../src/main/java/cz/dalvi/qtjambiplugin/Main.java | 19 + .../java/cz/dalvi/qtjambiplugin/QtJambiMOJO.java | 513 ++++++++++++++++++++ maven/pom.in | 31 ++ maven/qtjambi/pom.in | 110 +++++ maven/readme.txt | 74 +++ maven/release_all.sh | 30 ++ maven/resources-linux32/pom.in | 16 + maven/resources-linux64/pom.in | 16 + maven/resources-win32/pom.in | 16 + maven/resources-win64/pom.in | 17 + maven/set_version.sh | 9 + maven/simpleTestingApp/pom.in | 81 +++ .../src/main/java/test/HelloDialog.java | 26 + .../simpleTestingApp/src/main/java/test/Main.java | 29 ++ .../src/main/java/test/ui/HelloDialog.jui | 85 ++++ 22 files changed, 1338 insertions(+), 0 deletions(-) create mode 100755 maven/clean_binaries.sh create mode 100644 maven/env_releases create mode 100755 maven/import_binaries.sh create mode 100755 maven/mavenize_qtjambi.sh create mode 100644 maven/misc/qtjambi-base.pom create mode 100644 maven/misc/qtjambi-platform.pom create mode 100644 maven/plugin/pom.in create mode 100644 maven/plugin/src/main/java/cz/dalvi/qtjambiplugin/Main.java create mode 100644 maven/plugin/src/main/java/cz/dalvi/qtjambiplugin/QtJambiMOJO.java create mode 100755 maven/pom.in create mode 100644 maven/qtjambi/pom.in create mode 100755 maven/readme.txt create mode 100755 maven/release_all.sh create mode 100644 maven/resources-linux32/pom.in create mode 100644 maven/resources-linux64/pom.in create mode 100644 maven/resources-win32/pom.in create mode 100644 maven/resources-win64/pom.in create mode 100755 maven/set_version.sh create mode 100644 maven/simpleTestingApp/pom.in create mode 100644 maven/simpleTestingApp/src/main/java/test/HelloDialog.java create mode 100644 maven/simpleTestingApp/src/main/java/test/Main.java create mode 100644 maven/simpleTestingApp/src/main/java/test/ui/HelloDialog.jui diff --git a/maven/clean_binaries.sh b/maven/clean_binaries.sh new file mode 100755 index 0000000..69573f8 --- /dev/null +++ b/maven/clean_binaries.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +for i in resources-linux32 resources-linux64 resources-win32 resources-win64; do + rm -rf ${i}/src/main/resources +done \ No newline at end of file diff --git a/maven/env_releases b/maven/env_releases new file mode 100644 index 0000000..542adac --- /dev/null +++ b/maven/env_releases @@ -0,0 +1,17 @@ + +# you need to configure following variables + +QTJAMBI_VERSION=4.5.2_01 + +QTJAMBI_LINUX32_RELEASE=~/qtjambi/qtjambi-linux32-lgpl-4.5.2_01 +QTJAMBI_LINUX64_RELEASE=~/qtjambi/qtjambi-linux64-lgpl-4.5.2_01 +QTJAMBI_WIN32_RELEASE=~/qtjambi/qtjambi-win32-lgpl-4.5.2_01 +QTJAMBI_WIN64_RELEASE=~/qtjambi/qtjambi-win64-lgpl-4.5.2_01 +QTJAMBI_MAC_RELEASE= + +# Maven stuff +# TODO: this should be used as deploy-deploy file together with REPO in the future, now should stay install:install-file +MAVEN_ACTION="install" +MAVEN_SUBACTION="install-file" +MAVEN_REPO="" + diff --git a/maven/import_binaries.sh b/maven/import_binaries.sh new file mode 100755 index 0000000..34ed100 --- /dev/null +++ b/maven/import_binaries.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# TODO mac + +source env_releases + +function die { + echo "ERROR!" + exit 1 +} + +for i in resources-linux32 resources-linux64 resources-win32 resources-win64; do + mkdir -p ${i}/src/main/resources +done + +for i in bin/juic bin/lupdate bin/lrelease lib/libQtCore.so.4 lib/libQtXml.so.4; do + cp ${QTJAMBI_LINUX32_RELEASE}/${i} resources-linux32/src/main/resources || die +done + +for i in bin/juic bin/lupdate bin/lrelease lib/libQtCore.so.4 lib/libQtXml.so.4; do + cp ${QTJAMBI_LINUX64_RELEASE}/${i} resources-linux64/src/main/resources || die +done + +for i in bin/juic.exe bin/lupdate.exe bin/lrelease.exe bin/QtCore4.dll bin/QtXml4.dll; do + cp ${QTJAMBI_WIN32_RELEASE}/${i} resources-win32/src/main/resources || die +done + +for i in bin/juic.exe bin/lupdate.exe bin/lrelease.exe bin/QtCore4.dll bin/QtXml4.dll; do + cp ${QTJAMBI_WIN64_RELEASE}/${i} resources-win64/src/main/resources || die +done + + + diff --git a/maven/mavenize_qtjambi.sh b/maven/mavenize_qtjambi.sh new file mode 100755 index 0000000..4438055 --- /dev/null +++ b/maven/mavenize_qtjambi.sh @@ -0,0 +1,36 @@ +#!/bin/bash -x + +source env_releases + +function die { + echo "ERROR!" + exit 1 +} + + +# prepare poms +rm -rf tmp +mkdir -p tmp +for platform in linux32 linux64 win32 win64; do + cat misc/qtjambi-base.pom | sed s/%PLATFORM%/$platform/ | sed s/%QTJAMBI_VERSION%/$QTJAMBI_VERSION/ > tmp/qtjambi-base-$platform.pom || die + cat misc/qtjambi-platform.pom | sed s/%PLATFORM%/$platform/ | sed s/%QTJAMBI_VERSION%/$QTJAMBI_VERSION/ > tmp/qtjambi-$platform.pom || die +done + + +# release qt libs +cd tmp +mvn ${MAVEN_ACTION}:${MAVEN_SUBACTION} -Dfile=${QTJAMBI_LINUX32_RELEASE}/qtjambi-${QTJAMBI_VERSION}.jar -DpomFile=qtjambi-base-linux32.pom $MAVEN_REPO || die +mvn ${MAVEN_ACTION}:${MAVEN_SUBACTION} -Dfile=${QTJAMBI_LINUX32_RELEASE}/qtjambi-linux32-gcc-${QTJAMBI_VERSION}.jar -DpomFile=qtjambi-linux32.pom $MAVEN_REPO || die + +mvn ${MAVEN_ACTION}:${MAVEN_SUBACTION} -Dfile=${QTJAMBI_LINUX64_RELEASE}/qtjambi-${QTJAMBI_VERSION}.jar -DpomFile=qtjambi-base-linux64.pom $MAVEN_REPO || die +mvn ${MAVEN_ACTION}:${MAVEN_SUBACTION} -Dfile=${QTJAMBI_LINUX64_RELEASE}/qtjambi-linux64-gcc-${QTJAMBI_VERSION}.jar -DpomFile=qtjambi-linux64.pom $MAVEN_REPO || die + +mvn ${MAVEN_ACTION}:${MAVEN_SUBACTION} -Dfile=${QTJAMBI_WIN32_RELEASE}/qtjambi-${QTJAMBI_VERSION}.jar -DpomFile=qtjambi-base-win32.pom $MAVEN_REPO || die +mvn ${MAVEN_ACTION}:${MAVEN_SUBACTION} -Dfile=${QTJAMBI_WIN32_RELEASE}/qtjambi-win32-msvc2005-${QTJAMBI_VERSION}.jar -DpomFile=qtjambi-win32.pom $MAVEN_REPO || die + + +mvn ${MAVEN_ACTION}:${MAVEN_SUBACTION} -Dfile=${QTJAMBI_WIN64_RELEASE}/qtjambi-${QTJAMBI_VERSION}.jar -DpomFile=qtjambi-base-win64.pom $MAVEN_REPO || die +mvn ${MAVEN_ACTION}:${MAVEN_SUBACTION} -Dfile=${QTJAMBI_WIN64_RELEASE}/qtjambi-win64-msvc2005x64-${QTJAMBI_VERSION}.jar -DpomFile=qtjambi-win64.pom $MAVEN_REPO || die + +cd .. +rm -rf tmp diff --git a/maven/misc/qtjambi-base.pom b/maven/misc/qtjambi-base.pom new file mode 100644 index 0000000..f91378c --- /dev/null +++ b/maven/misc/qtjambi-base.pom @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>net.sf.qtjambi</groupId> + <artifactId>qtjambi-base-%PLATFORM%</artifactId> + <version>%QTJAMBI_VERSION%</version> + <description>QtJambi %PLATFORM% base libraries</description> +</project> \ No newline at end of file diff --git a/maven/misc/qtjambi-platform.pom b/maven/misc/qtjambi-platform.pom new file mode 100644 index 0000000..5bcb521 --- /dev/null +++ b/maven/misc/qtjambi-platform.pom @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>net.sf.qtjambi</groupId> + <artifactId>qtjambi-platform-%PLATFORM%</artifactId> + <version>%QTJAMBI_VERSION%</version> + <description>QtJambi %PLATFORM% libraries</description> + + + <dependencies> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>qtjambi-base-%PLATFORM%</artifactId> + <version>%VERSION%</version> + <type>jar</type> + </dependency> + </dependencies> + +</project> \ No newline at end of file diff --git a/maven/plugin/pom.in b/maven/plugin/pom.in new file mode 100644 index 0000000..3a764b2 --- /dev/null +++ b/maven/plugin/pom.in @@ -0,0 +1,147 @@ + +<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> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambiMavenPlugin</artifactId> + <version>0.1</version> + <packaging>maven-plugin</packaging> + <name>QtJambiMavenPlugin</name> + <url>http://maven.apache.org</url> + + + + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.6</source> + <target>1.6</target> + <encoding>${project.build.sourceEncoding}</encoding> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <version>2.3</version> + <configuration> + <encoding>${project.build.sourceEncoding}</encoding> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.2.1</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.2.1</version> + <type>jar</type> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.4</version> + </dependency> + </dependencies> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + + + <!-- OS and platform specific profiles for tool resources --> + <profiles> + + <profile> + <id>linux-32</id> + <activation> + <os> + <name>Linux</name> + <arch>x86</arch> + </os> + </activation> + <dependencies> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambiMavenPlugin-linux32</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + </dependencies> + </profile> + + <profile> + <id>linux-64</id> + <activation> + <os> + <name>Linux</name> + <arch>amd64</arch> + </os> + </activation> + <dependencies> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambiMavenPlugin-linux64</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + + </dependencies> + </profile> + + <profile> + <id>win32</id> + <activation> + <os> + <!-- <name>Windows XP</name> --> + <family>windows</family> + <arch>x86</arch> + </os> + </activation> + <dependencies> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambiMavenPlugin-win32</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + </dependencies> + </profile> + + + <profile> + <id>win64</id> + <activation> + <os> + <family>windows</family> + <arch>amd64</arch> + </os> + </activation> + <dependencies> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambiMavenPlugin-win64</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + </dependencies> + </profile> + + </profiles> + +</project> + + + + diff --git a/maven/plugin/src/main/java/cz/dalvi/qtjambiplugin/Main.java b/maven/plugin/src/main/java/cz/dalvi/qtjambiplugin/Main.java new file mode 100644 index 0000000..e108cf4 --- /dev/null +++ b/maven/plugin/src/main/java/cz/dalvi/qtjambiplugin/Main.java @@ -0,0 +1,19 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package cz.dalvi.qtjambiplugin; + +/** + * + * @author admin + */ +public class Main { + + public static void main(String[] args) throws Exception { + + QtJambiMOJO m = new QtJambiMOJO(); + m.execute(); + + } +} diff --git a/maven/plugin/src/main/java/cz/dalvi/qtjambiplugin/QtJambiMOJO.java b/maven/plugin/src/main/java/cz/dalvi/qtjambiplugin/QtJambiMOJO.java new file mode 100644 index 0000000..b00730b --- /dev/null +++ b/maven/plugin/src/main/java/cz/dalvi/qtjambiplugin/QtJambiMOJO.java @@ -0,0 +1,513 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package cz.dalvi.qtjambiplugin; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; + +/** + * + * @author admin + * @goal generate + * @phase generate-sources + */ +public class QtJambiMOJO extends AbstractMojo { + + /** + * Path to sources dir. If not specified, ./src/main/java is used. + * + * @parameter expression="${qtjambi.sourcesDir}" + */ + private File sourcesDir; + /** + * Destination directory. Default the same as sourceDir. + * + * @parameter expression="${basedir}/target/generated-sources/qtjambi" + * @required + */ + private File destinationDir; + /** + * Base directory. + * + * @parameter expression="${basedir}" + * @required + */ + private File baseDir; + /** + * Package name of generated files + * @parameter expression="${qtjambi.packageName}" + */ + private String packageName; + /** + * @parameter expression="${project}" + * @required + * @readonly + * @since 1.0 + */ + private MavenProject project; + /** + * @parameter expression="${qtjambi.noObsoleteTranslations}" default-value=false + */ + private boolean noObsoleteTranslations; + + /* + * + */ + private enum Platforms { + + WIN32, WIN64, LIN32, LIN64, MAC32, MAC64 + }; + + private enum Tools { + + JUIC, LUPDATE, LRELEASE; + private File tool_file = null; + + public void setFile(File f) { + tool_file = f; + } + + public File getFile() { + return tool_file; + } + }; + private static final String dotJui = ".jui"; + private static final String dotJava = ".java"; + private static final String dotTs = ".ts"; + private Platforms platform; + private File binariesDir; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + + // setup platform + setupPlatform(); + + // compile jui files + compileJuiFiles(); + + // process translations + processTranslations(); + + // add created jars to project + project.addCompileSourceRoot(destinationDir.getAbsolutePath()); + + // delete temp dir + org.apache.commons.io.FileUtils.deleteQuietly(binariesDir); + + + } + + private void setupPlatform() throws MojoExecutionException { + + // platform specific set of tools + String platform_bits = System.getProperty("os.arch"); + String platform_name = System.getProperty("os.name").toLowerCase(); + + // setup propper file names for current platform + String[] tool_files; + if (platform_name.contains("windows") && platform_bits.equals("x86")) { + platform = Platforms.WIN32; + tool_files = new String[]{"juic.exe", "lupdate.exe", "lrelease.exe", "QtCore4.dll", "QtXml4.dll"}; + } else if (platform_name.contains("windows") && platform_bits.contains("64")) { + platform = Platforms.WIN64; + tool_files = new String[]{"juic.exe", "lupdate.exe", "lrelease.exe", "QtCore4.dll", "QtXml4.dll"}; + } else if (platform_name.contains("linux") && platform_bits.equals("x86")) { + platform = Platforms.LIN32; + tool_files = new String[]{"juic", "lupdate", "lrelease", "libQtCore.so.4", "libQtXml.so.4"}; + } else if (platform_name.contains("linux") && platform_bits.contains("64")) { + platform = Platforms.LIN64; + tool_files = new String[]{"juic", "lupdate", "lrelease", "libQtCore.so.4", "libQtXml.so.4"}; + } else if (platform_name.contains("mac") && platform_bits.equals("x86")) { + throw new MojoExecutionException("Platform mac32 not yet supported"); + } else if (platform_name.contains("mac") && platform_bits.contains("64")) { + throw new MojoExecutionException("Platform mac64 not yet supported"); + } else { + throw new MojoExecutionException("Uknown platform"); + } + + try { + + if (sourcesDir == null) { + throw new MojoExecutionException("You must specify sourcesDir"); + } + if (destinationDir == null) { + destinationDir = new File(sourcesDir.getAbsolutePath()); + } + + // create temp directory where qtjambi tools should be extracted + binariesDir = File.createTempFile("qtjambi_tools", ""); + binariesDir.delete(); + if (!binariesDir.mkdirs()) { + throw new IOException("Failed to create directory " + binariesDir.getAbsolutePath()); + } + + // extract tools there, setup path to tools + int idx = 0; + for (String s : tool_files) { + File tool = saveResource(s, binariesDir); + switch (idx++) { + case 0: + Tools.JUIC.setFile(tool); + break; + case 1: + Tools.LUPDATE.setFile(tool); + break; + case 2: + Tools.LRELEASE.setFile(tool); + break; + + } + } + + // make binaries executable on linux + // TODO what about mac? + if (platform_name.toLowerCase().contains("linux")) { + Tools.JUIC.getFile().setExecutable(true); + Tools.LRELEASE.getFile().setExecutable(true); + Tools.LUPDATE.getFile().setExecutable(true); + } + + + } catch (IOException ex) { + throw new MojoExecutionException("Failed to initialize plugin", ex); + } + + getLog().debug("QtJambiPlugin initialized successfully"); + + } + + private void compileJuiFiles() throws MojoExecutionException { + + Process process; + int retval; + FileOutputStream fos; + + try { + + // find jui files in source dir + getLog().info("Looking for jui files in " + sourcesDir.getAbsolutePath()); + ArrayList<File> jui_lst = new ArrayList<File>(); + findFiles(sourcesDir, jui_lst, dotJui); + + + /* + * this is a little tricky. It seems that "-a" option doesn't work as I expected, + * so I must detect modifications myself. I'll do this because all .jui files + * are re-generated on each build and they are everytime compiled. This should slow down + * the build process dramatically when developing application. + * So: i'll find NEWEST file in source and destination dir and + * if there exists a newer file in source dir, all juis will be recompiled. + * I must do so because I can't create destination filename by source filename, + * because destination filename is created by class name _inside_ the .jui file, + * not by source filename. + */ + + ArrayList<File> dst_lst = new ArrayList<File>(); + findFiles(destinationDir, dst_lst, dotJava); + + long highest_src = 0, highest_dst = 0; + for (File s : jui_lst) { + long mtime = s.lastModified(); + if (mtime > highest_src) { + highest_src = mtime; + } + } + for (File s : dst_lst) { + long mtime = s.lastModified(); + if (mtime > highest_dst) { + highest_dst = mtime; + } + } + + // if no source modifications, return + if (highest_dst >= highest_src) { + getLog().debug("No files modified, skipping juic"); + return; + } + + getLog().debug("Sources modified, compiling all form files"); + + + // compile all jui files + for (File jui_file : jui_lst) { + + String[] cmdarray = new String[]{ + "-d", + destinationDir.getAbsolutePath(), + "-p", + getPackageForJuiFile(jui_file.getAbsolutePath()), + jui_file.getAbsolutePath() + }; + + // execute juic + executeTool(Tools.JUIC, cmdarray); + + } + + // now recode generated files to project sources encoding ( qtjambi 4.5 bug on non-us systems with datetime format in comment ) + ArrayList<File> java_lst = new ArrayList<File>(); + findFiles(destinationDir, java_lst, dotJava); + + for (File f : java_lst) { + if (f.getName().startsWith("Ui_") && f.getName().endsWith(".java")) { + + getLog().debug("Recoding " + f.getAbsolutePath() + " to right encoding"); + + BufferedReader r = new BufferedReader(new FileReader(f)); + StringBuilder b = new StringBuilder(); + String line; + while (null != (line = r.readLine())) { + b.append(line + "\n"); + //getLog().debug("Read: " + line); + } + r.close(); + + getLog().debug("Readed"); + + // write back in right encoding + fos = new FileOutputStream(f); + String encoding = project.getProperties().getProperty("project.build.sourceEncoding"); + if (encoding == null) { + encoding = "utf-8"; + } + fos.write(b.toString().getBytes(encoding)); + fos.close(); + + } + } + + + + } catch (Exception ex) { + throw new MojoExecutionException("Failed to convert jui files", ex); + } + + } + + /** + * Searches recursively the whole directory tree pointed by + * <code>srcDir</code>. + * + * @param srcDir + * source directory to search under. + * @param files + * list to which all found files will be put. + * @param extension + * filter files by extension + */ + private void findFiles(File srcDir, List<File> files, String extension) { + if (srcDir != null && srcDir.isDirectory()) { + for (File f : srcDir.listFiles()) { + if (f.isDirectory()) { + findFiles(f, files, extension); + } else if (f.getName().endsWith(extension)) { + getLog().debug("found file: " + f.getName()); + files.add(f); + } + } + } + } + + /** + * Derives the package name for the given <code>juiFile</code>. + * + * @param juiFile + * the file for which the package is being derived + * @return + */ + private String getPackageForJuiFile(String juiFile) { + + if (packageName != null && packageName.trim().length() > 0) { + return packageName; + } + + /* removing the sourceDirectory path */ + String pkgName = juiFile.substring(sourcesDir.getAbsolutePath().length() + 1); + /* removing the file name with preceding separator */ + pkgName = pkgName.substring(0, pkgName.lastIndexOf(File.separatorChar)); + /* replacing file separators with dots */ + pkgName = pkgName.replace(File.separatorChar, '.'); + getLog().debug("derived package name for: " + juiFile + " is: " + pkgName); + + return pkgName; + } + + private void executeTool(Tools tool, String[] arguments) throws IOException, InterruptedException, MojoExecutionException { + + LinkedList<String> cmd = new LinkedList<String>(); + cmd.add(tool.getFile().getAbsolutePath()); + for (String arg : arguments) { + cmd.add(arg); + } + + getLog().debug("Executing: " + cmd.toString()); + + ProcessBuilder b = new ProcessBuilder(cmd); + + // export LD_LIBRARY_PATH on linux + // TODO what about mac? + if (platform.equals(Platforms.LIN32) || platform.equals(Platforms.LIN64)) { + b.environment().put("LD_LIBRARY_PATH", binariesDir.getAbsolutePath()); + } + + // run process + Process process = b.start(); + int retval = process.waitFor(); + + // check exit code + if (retval != 0) { + System.err.println("\n\n"); + org.apache.commons.io.IOUtils.copy(process.getErrorStream(), System.err); + org.apache.commons.io.IOUtils.copy(process.getInputStream(), System.err); + System.err.println("\n\n"); + throw new MojoExecutionException(tool.name() + " execution failed!"); + } + + } + + private void processTranslations() throws MojoExecutionException { + + try { + + // ts files will be in src/main/resources/translations + File tsDir = new File(this.baseDir, "src/main/resources/translations"); + + + if (!tsDir.isDirectory()) { + getLog().info("No translations found in " + tsDir.getAbsolutePath()); + return; + } + Process process; + int retval; + + // get list of sources and forms + //ArrayList<File> lst = new ArrayList<File>(); + //findFiles(sourcesDir, lst, dotJava); + //findFiles(sourcesDir, lst, dotJava); + + // for all ts files + for (File ts : tsDir.listFiles()) { + + if (ts.getName().endsWith(dotTs)) { + + // if file is zero-length, delete it before calling lupdate + if (ts.isFile() && ts.length() == 0) { + ts.delete(); + } + + getLog().debug("Updating translation " + ts.getAbsolutePath()); + + // [-noobsolete] -extensions java %sourcedir %dstdir -ts test.ts + String[] args = new String[]{ + noObsoleteTranslations ? "-noobsolete" : "", + "-extensions", + dotJava.replace(".", ""), + sourcesDir.getAbsolutePath(), + destinationDir.getAbsolutePath(), + "-ts", + ts.getAbsolutePath() + }; + + getLog().debug("Executing: lupdate " + java.util.Arrays.toString(args)); + + + executeTool(Tools.LUPDATE, args); + } + } + + } catch (Exception ex) { + throw new MojoExecutionException("Translation failed", ex); + } + + + /* + + // ts will reside in the same dir where pm + File ts = new File(qmDirectory.getAbsolutePath(), "app.ts"); + File qm = new File(qmDirectory.getAbsolutePath(), "app.qm"); + + + try { + + List<String> javaFiles = new LinkedList<String>(); + findFiles(sourceDirectory, javaFiles, ".java"); + + List<String> cmd = new ArrayList<String>(); + cmd.add(lupdatePath.getAbsolutePath()); + + for (String f : javaFiles) { + cmd.add(f); + } + + cmd.add("-ts"); + cmd.add(ts.getAbsolutePath()); + + getLog().debug(cmd.toString()); + + Runtime.getRuntime().exec(cmd.toArray(new String[0])); + + + + cmd.clear(); + + cmd.add(lreleasePath.getAbsolutePath()); + cmd.add(ts.getAbsolutePath()); + cmd.add("-qm"); + cmd.add(qm.getAbsolutePath()); + + getLog().debug(cmd.toString()); + + Runtime.getRuntime().exec(cmd.toArray(new String[0])); + + + } catch (IOException ex) { + Logger.getLogger(JUICMojo.class.getName()).log(Level.SEVERE, null, ex); + throw new MojoExecutionException("Error has occured", ex); + } + */ + } + + private File saveResource(String resourceName, File outputDir) throws MojoExecutionException { + + InputStream in = QtJambiMOJO.class.getResourceAsStream("/" + resourceName); + + if (in == null) { + throw new MojoExecutionException("Can't find resource named '" + resourceName + "'"); + } + File outfile = new File(outputDir, resourceName); + + outfile.deleteOnExit(); + try { + + FileOutputStream out = new FileOutputStream(outfile); + org.apache.commons.io.IOUtils.copy(in, out); + + out.close(); + in.close(); + + return outfile; + + } catch (IOException ex) { + throw new MojoExecutionException("Can't write to " + outfile.getAbsolutePath()); + } + } +} + + diff --git a/maven/pom.in b/maven/pom.in new file mode 100755 index 0000000..a2f74e4 --- /dev/null +++ b/maven/pom.in @@ -0,0 +1,31 @@ +<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> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambiMavenPluginParent</artifactId> + <packaging>pom</packaging> + <version>%QTJAMBI_VERSION%</version> + <name>QtJambiMavenPluginParent</name> + <url>http://maven.apache.org</url> + + <modules> + <!-- maven plugin project --> + <module>plugin</module> + + <!-- qt resources ( binaries and libraries for misc tools ) --> + <module>resources-win32</module> + <module>resources-win64</module> + <module>resources-linux32</module> + <module>resources-linux64</module> + + <!-- this project is the main library what applications should use. + It handles dependency on qtjambi jars for each platform --> + <module>qtjambi</module> + + <!-- simple example qtjambi app using mavenized qtjambi --> + <module>simpleTestingApp</module> + </modules> + + + +</project> diff --git a/maven/qtjambi/pom.in b/maven/qtjambi/pom.in new file mode 100644 index 0000000..4152067 --- /dev/null +++ b/maven/qtjambi/pom.in @@ -0,0 +1,110 @@ +<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> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambi</artifactId> + <version>%QTJAMBI_VERSION%</version> + <packaging>jar</packaging> + <name>QtJambi</name> + <url>http://maven.apache.org</url> + + <!-- OS and platform specific profiles for QtJambi binaries --> + <profiles> + + <profile> + <id>linux-32</id> + <activation> + <os> + <name>Linux</name> + <arch>x86</arch> + </os> + </activation> + <dependencies> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>qtjambi-base-linux32</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>qtjambi-platform-linux32</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + </dependencies> + </profile> + + <profile> + <id>linux-64</id> + <activation> + <os> + <name>Linux</name> + <arch>amd64</arch> + </os> + </activation> + <dependencies> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>qtjambi-base-linux64</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>qtjambi-platform-linux64</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + </dependencies> + </profile> + + <profile> + <id>win32</id> + <activation> + <os> + <name>Windows XP</name> + <family>windows</family> + <arch>x86</arch> + <!-- <version>5.1.2600</version> --> + </os> + </activation> + <dependencies> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>qtjambi-base-win32</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>qtjambi-platform-win32</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + </dependencies> + </profile> + + + <profile> + <id>win64</id> + <activation> + <os> + <name>Windows XP</name> + <family>windows</family> + <arch>amd64</arch> + <!-- <version>5.1.2600</version> --> + </os> + </activation> + <dependencies> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>qtjambi-base-win64</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>qtjambi-platform-win64</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + </dependencies> + </profile> + + </profiles> + +</project> diff --git a/maven/readme.txt b/maven/readme.txt new file mode 100755 index 0000000..2883402 --- /dev/null +++ b/maven/readme.txt @@ -0,0 +1,74 @@ +This is QTJambi maven stuff. + + ** For quickstart, go to "INSTALLATION" section... + + +It consists of 2 main sections: + +1. Stuff used to mavenize QtJambi libraries + + It consists of directory misc and mavenize_qtjambi script. + "misc" directory contains pom template files used to mavenize + qtjambi-VERSION.jar and qtjambi-PLATFORM-VERSION.jar files. + + +2. QtJambiMavenPlugin + + It handles .jui->.java conversion and translations. + + Project is multi-module maven project, containing following modules": + + - plugin + This is qtjambi maven plugin code. This plugin uses ( depending on platform ) + resources-* artifact, which contains required binaries such as juic, lupdate and others. + You must use this plugin in your maven app to handle .jui and .ts files. + + - resources-* + These modules are simple jar modules, which contains qtjambi binary resources + for each plaform ( juic, lupdate, lrelease... ). + Splitting it into modules should save space and download time when building + qtjambi application, because only binaries for current platform are downloaded + from maven repo. + Do not forget to call import_binaries.sh BEFORE you build this project. + + - qtjambi + This module is simple jar module, containing no sources. It only handles + dependencies on misc qtjambi packages for each platform. This saves time + to a application developer, because he doesn't need to care about platform. + Just include groupId=net.sf.qtjambi, artifactId=QtJambi into your project + and maven will handle platform itself. + Name of build target is net.sf.qtjambi/QtJambi and this is the only project + you need to include into your maven app. + + - simpleTestingApp + This is an example qtjambi application using designer forms and translation + files. Take a look into the pom.xml how things works and try to run it. + + + Limitations: + + - currently based on qtjambi 4.5 + - only win32 and linux64 tested + - mac not implemented at all + - it doesn't produce .qm files yet, only .ts + + +INSTALLATION: + + You don't need to know details about stuff here. It is not depending on current qtjambi + sources so you don't need to build anything in qtjambi sources. + + Just follow these steps: + + - download all [linux,windows][32,64] + mac releases into one directory + ( for example ~/qtjambi/ ) + + - unpack all .tar.gz and .zip there + + - properly set version and path to all releases in env_releases file + + - run release_all.sh + + If no error occure, all mavenized stuff is now in your local maven repository (~/.m2/repository/net/sf/qtjambi). + All artifacts from that directory should be published on some public/shared maven repository. + diff --git a/maven/release_all.sh b/maven/release_all.sh new file mode 100755 index 0000000..cbfa281 --- /dev/null +++ b/maven/release_all.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +source env_releases + +bash set_version.sh + +# mavenize qtjambi libraries +bash mavenize_qtjambi.sh + +# release qtjambi maven plugin +bash import_binaries.sh +mvn ${MAVEN_ACTION} +bash clean_binaries.sh + +# prepare maven repo for upload +rm -rf tmp +mkdir -p tmp/maven2/net/sf/qtjambi/ +cp -a ~/.m2/repository/net/sf/qtjambi/* tmp/maven2/net/sf/qtjambi/ +echo "Options +Indexes" > tmp/maven2/.htaccess +cd tmp + +# upload maven repo to sf.net +read -p "sf.net username: " uname +stty -echo +read -p "password: " passw; echo +stty echo + +scp -r maven2 ${uname},[email protected]://home/groups/q/qt/qtjambi/htdocs + +# repo is at http://qtjambi.sourceforge.net/maven2/ diff --git a/maven/resources-linux32/pom.in b/maven/resources-linux32/pom.in new file mode 100644 index 0000000..96a3941 --- /dev/null +++ b/maven/resources-linux32/pom.in @@ -0,0 +1,16 @@ +<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> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambiMavenPlugin-linux32</artifactId> + <version>%QTJAMBI_VERSION%</version> + <packaging>jar</packaging> + <name>QtJambiMavenPlugin-linux32</name> + + +</project> + + + + diff --git a/maven/resources-linux64/pom.in b/maven/resources-linux64/pom.in new file mode 100644 index 0000000..16a2f14 --- /dev/null +++ b/maven/resources-linux64/pom.in @@ -0,0 +1,16 @@ + +<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> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambiMavenPlugin-linux64</artifactId> + <version>%QTJAMBI_VERSION%</version> + <packaging>jar</packaging> + <name>QtJambiMavenPlugin-linux64</name> + +</project> + + + + diff --git a/maven/resources-win32/pom.in b/maven/resources-win32/pom.in new file mode 100644 index 0000000..549f8e0 --- /dev/null +++ b/maven/resources-win32/pom.in @@ -0,0 +1,16 @@ + +<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> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambiMavenPlugin-win32</artifactId> + <version>%QTJAMBI_VERSION%</version> + <packaging>jar</packaging> + <name>QtJambiMavenPlugin-win32</name> + <url>http://maven.apache.org</url> + +</project> + + + + diff --git a/maven/resources-win64/pom.in b/maven/resources-win64/pom.in new file mode 100644 index 0000000..5ba7d2c --- /dev/null +++ b/maven/resources-win64/pom.in @@ -0,0 +1,17 @@ + +<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> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambiMavenPlugin-win64</artifactId> + <version>%QTJAMBI_VERSION%</version> + <packaging>jar</packaging> + <name>QtJambiMavenPlugin-win64</name> + + + +</project> + + + + diff --git a/maven/set_version.sh b/maven/set_version.sh new file mode 100755 index 0000000..cd13528 --- /dev/null +++ b/maven/set_version.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +source env_releases + +for i in `find . -name pom.in`; do + cat $i | sed s/%QTJAMBI_VERSION%/${QTJAMBI_VERSION}/g > `dirname $i`/pom.xml + +done + diff --git a/maven/simpleTestingApp/pom.in b/maven/simpleTestingApp/pom.in new file mode 100644 index 0000000..e5bfd11 --- /dev/null +++ b/maven/simpleTestingApp/pom.in @@ -0,0 +1,81 @@ +<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> + <groupId>net.sf.qtjambi.testapp</groupId> + <artifactId>SimpleQtApplication</artifactId> + <version>0.1</version> + <packaging>jar</packaging> + <name>SimpleQtApplication</name> + <url>http://maven.apache.org</url> + + <properties> + <!-- specify full path to your main class --> + <mainClass>test.Main</mainClass> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + + <!-- project dependencies --> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambi</artifactId> + <version>%QTJAMBI_VERSION%</version> + </dependency> + </dependencies> + + + <!-- build configuration --> + <build> + + <plugins> + + <!-- gtjambi plugin --> + <plugin> + <groupId>net.sf.qtjambi</groupId> + <artifactId>QtJambiMavenPlugin</artifactId> + <executions> + <execution> + <id>qtjambi</id> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + <configuration> + <sourcesDir>src/main/java</sourcesDir> + <qmDirectory>src/main/resources/translations</qmDirectory> + <noObsoleteTranslations>true</noObsoleteTranslations> + </configuration> + </plugin> + + <!-- only specifying syntax and encoding of sources --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.0.2</version> + <configuration> + <source>1.6</source> + <target>1.6</target> + <encoding>${project.build.sourceEncoding}</encoding> + </configuration> + </plugin> + + </plugins> + + </build> + + +</project> + + + + + \ No newline at end of file diff --git a/maven/simpleTestingApp/src/main/java/test/HelloDialog.java b/maven/simpleTestingApp/src/main/java/test/HelloDialog.java new file mode 100644 index 0000000..5e2e1ab --- /dev/null +++ b/maven/simpleTestingApp/src/main/java/test/HelloDialog.java @@ -0,0 +1,26 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package test; + +import com.trolltech.qt.gui.QDialog; +import test.ui.Ui_HelloDialog; + +/** + * + * @author admin + */ +public class HelloDialog extends QDialog { + private final Ui_HelloDialog ui; + + public HelloDialog() { + this.ui = new Ui_HelloDialog(); + ui.setupUi(this); + } + + + + +} diff --git a/maven/simpleTestingApp/src/main/java/test/Main.java b/maven/simpleTestingApp/src/main/java/test/Main.java new file mode 100644 index 0000000..45f604f --- /dev/null +++ b/maven/simpleTestingApp/src/main/java/test/Main.java @@ -0,0 +1,29 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package test; + +import com.trolltech.qt.gui.QApplication; +import com.trolltech.qt.gui.QMessageBox; + +/** + * + * @author admin + */ +public class Main { + + public static void main(String[] args) { + + QApplication.initialize(args); + + HelloDialog d = new HelloDialog(); + d.show(); + + QApplication.exec(); + + + } + +} diff --git a/maven/simpleTestingApp/src/main/java/test/ui/HelloDialog.jui b/maven/simpleTestingApp/src/main/java/test/ui/HelloDialog.jui new file mode 100644 index 0000000..196e490 --- /dev/null +++ b/maven/simpleTestingApp/src/main/java/test/ui/HelloDialog.jui @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0" language="jambi"> + <class>HelloDialog</class> + <widget class="QDialog" name="HelloDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>This is text</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>This is another text</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QCheckBox" name="checkBox"> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>com.trolltech.qt.core.Qt.Orientation.Horizontal</enum> + </property> + <property name="standardButtons"> + <set>com.trolltech.qt.gui.QDialogButtonBox.StandardButton.Cancel|com.trolltech.qt.gui.QDialogButtonBox.StandardButton.Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted</signal> + <receiver>HelloDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected</signal> + <receiver>HelloDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> -- 1.5.6.5
_______________________________________________ Qt-jambi-interest mailing list [email protected] http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest
