Author: tchemit Date: 2012-09-04 08:50:16 +0200 (Tue, 04 Sep 2012) New Revision: 610 Url: http://forge.codelutin.com/repositories/revision/echobase/610 Log: improve embeddedzip application + fix internal schema to create Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/EchobaseTopiaContexts.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationService.java trunk/echobase-services/src/main/resources/embedded/startEchobase.bat trunk/echobase-services/src/main/resources/embedded/startEchobase.sh trunk/echobase-services/src/test/resources/log4j.properties trunk/echobase-ui/pom.xml trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/EchobaseTopiaContexts.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/EchobaseTopiaContexts.java 2012-09-04 06:14:33 UTC (rev 609) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/EchobaseTopiaContexts.java 2012-09-04 06:50:16 UTC (rev 610) @@ -66,6 +66,58 @@ // should not be instanciated } + /** + * Open a new topia root context from the given jdbc configuration. + * + * @param jdbcConfiguration jdbc configuration + * @return the new fresh root context + */ + public static TopiaContext newWorkingDb(JdbcConfiguration jdbcConfiguration) { + + Properties properties = loadWorkingDbConfiguration(jdbcConfiguration); + TopiaContext result = newDb(properties); + + try { + if (!EchoBaseEntityHelper.isWorkingDbSchemaCreated(result)) { + + if (log.isInfoEnabled()) { + log.info("Will create schema for " + + jdbcConfiguration.getUrl()); + } + result.createSchema(); + } + } catch (TopiaException e) { + throw new EchoBaseTechnicalException("Could not create db schema", e); + } + return result; + } + + /** + * Open a new topia root context for the internal db of t3 (this should be + * a h2 db used only for security). + * + * @param internalDbDirectory directory of the internal db + * @return the new fresh root context of the internal db + */ + public static TopiaContext newInternalDb(File internalDbDirectory) { + + Properties properties = loadInternalDbconfiguration(internalDbDirectory); + TopiaContext result = newDb(properties); + try { + if (!EchoBaseEntityHelper.isInternalSchemaCreated(result)) { + + if (log.isInfoEnabled()) { + log.info("Will create schema for " + + properties.get(TopiaContextFactory.CONFIG_URL)); + } + result.createSchema(); + } + } catch (TopiaException e) { + throw new EchoBaseTechnicalException("Could not create db schema", e); + } + return result; + } + public static Properties loadWorkingDbConfiguration(JdbcConfiguration conf) { Properties result = new RecursiveProperties(); @@ -91,7 +143,7 @@ return result; } - public static Properties loadInternalDbconfiguration(File internalDbDirectory) { + protected static Properties loadInternalDbconfiguration(File internalDbDirectory) { Properties result = new RecursiveProperties(); String key = EchoBaseConfigurationOption.INTERNAL_DB_DIRECTORY.getKey(); @@ -104,45 +156,6 @@ return result; } - /** - * Open a new topia root context from the given jdbc configuration. - * - * @param jdbcConfiguration jdbc configuration - * @return the new fresh root context - */ - public static TopiaContext newWorkingDb(JdbcConfiguration jdbcConfiguration) { - - Properties properties = loadWorkingDbConfiguration(jdbcConfiguration); - TopiaContext result = newDb(properties); - - try { - if (!EchoBaseEntityHelper.isWorkingDbSchemaCreated(result)) { - - if (log.isInfoEnabled()) { - log.info("Will create schema for " + - jdbcConfiguration.getUrl()); - } - result.createSchema(); - } - } catch (TopiaException e) { - throw new EchoBaseTechnicalException("Could not create db schema", e); - } - return result; - } - - /** - * Open a new topia root context for the internal db of t3 (this should be - * a h2 db used only for security). - * - * @param internalDbDirectory directory of the internal db - * @return the new fresh root context of the internal db - */ - public static TopiaContext newInternalDb(File internalDbDirectory) { - - Properties result = loadInternalDbconfiguration(internalDbDirectory); - return newDb(result); - } - protected static void loadProperties(Properties result, String path, String entities) { Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationService.java 2012-09-04 06:14:33 UTC (rev 609) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationService.java 2012-09-04 06:50:16 UTC (rev 610) @@ -292,14 +292,11 @@ FileUtil.createDirectoryIfNecessary(dir); // copy embedded files to / - copyEmbeddedTextFile("echobase.properties", dir); - copyEmbeddedTextFile("startEchobase.bat", dir); - copyEmbeddedTextFile("startEchobase.sh", dir); - copyEmbeddedTextFile("README.txt", dir); + copyEmbeddedTextFile("echobase.properties", dir, false); + copyEmbeddedTextFile("startEchobase.bat", dir, true); + copyEmbeddedTextFile("startEchobase.sh", dir, true); + copyEmbeddedTextFile("README.txt", dir, false); -// Properties config = new Properties(); -// copyEmbeddedTextFile("echobase.properties", dir, config); - // copy war to / File warLocation = model.getWarLocation(); FileUtils.copyFile(warLocation, @@ -354,50 +351,9 @@ } } -// protected void copyEmbeddedFiles(File zipDirectory) throws IOException, URISyntaxException { -// -// // config to keep the echobase-embedded values (contains h2 and pg versions) -// Properties config = new Properties(); -// copyEmbeddedTextFile("echobase.properties", zipDirectory, config); -// -// copyEmbeddedTextFile("startEchobase.bat", zipDirectory, null); -// copyEmbeddedTextFile("startEchobase.sh", zipDirectory, null); -// copyEmbeddedTextFile("README.txt", zipDirectory, null); -// } - -// public void copyEmbeddedTextFile(String resourceName, -// File targetDirectory, -// Properties config) throws IOException { -// String resourcePath = EMBEDDED_PATH + resourceName; -// InputStream inputStream = getClass().getResourceAsStream(resourcePath); -// Preconditions.checkNotNull(inputStream, -// "could not find resource " + resourcePath); -// try { -// if (config != null) { -// config.load(inputStream); -// } -// File outputFile = new File(targetDirectory, resourceName); -// if (log.isInfoEnabled()) { -// log.info("Copy configuration to " + resourceName + " to " + outputFile); -// } -// OutputStreamWriter outputStream = new OutputStreamWriter( -// new FileOutputStream(outputFile), Charsets.UTF_8); -// try { -// if (config == null) { -// IOUtils.copy(inputStream, outputStream); -// } else { -// config.store(outputStream, null); -// } -// } finally { -// outputStream.close(); -// } -// } finally { -// inputStream.close(); -// } -// } - public void copyEmbeddedTextFile(String resourceName, - File targetDirectory) throws IOException { + File targetDirectory, + boolean executable) throws IOException { String resourcePath = EMBEDDED_PATH + resourceName; InputStream inputStream = getClass().getResourceAsStream(resourcePath); Preconditions.checkNotNull(inputStream, @@ -414,6 +370,9 @@ } finally { outputStream.close(); } + if (executable) { + outputFile.setExecutable(true); + } } finally { inputStream.close(); } Modified: trunk/echobase-services/src/main/resources/embedded/startEchobase.bat =================================================================== --- trunk/echobase-services/src/main/resources/embedded/startEchobase.bat 2012-09-04 06:14:33 UTC (rev 609) +++ trunk/echobase-services/src/main/resources/embedded/startEchobase.bat 2012-09-04 06:50:16 UTC (rev 610) @@ -39,7 +39,7 @@ set ECHOBASE_OPTS="-Xms512m -Xmx1024m -Dechobase.log.dir=./logs" echo java options used : %ECHOBASE_OPTS% -%JAVA_COMMAND% "%ECHOBASE_OPTS%" -jar echobase-ui-${project.version}.war +%JAVA_COMMAND% "%ECHOBASE_OPTS%" -jar echobase-ui-${project.version}-embedded.war %1 %2 %3 %4 %5 %6 %7 %8 %9 goto end :end Modified: trunk/echobase-services/src/main/resources/embedded/startEchobase.sh =================================================================== --- trunk/echobase-services/src/main/resources/embedded/startEchobase.sh 2012-09-04 06:14:33 UTC (rev 609) +++ trunk/echobase-services/src/main/resources/embedded/startEchobase.sh 2012-09-04 06:50:16 UTC (rev 610) @@ -11,6 +11,6 @@ cd `dirname $0` CURRENTPWD=`pwd` ECHOBASE_OPTS="$JAVA_OPTS -Xms512m -Xmx10242m -Dechobase.log.dir=$CURRENTPWD/logs" -$JAVA_EXEC $ECHOBASE_OPTS -jar echobase-ui-${project.version}.war $* +$JAVA_EXEC $ECHOBASE_OPTS -jar echobase-ui-${project.version}-embedded.war $* cd "$OLDPWD" Modified: trunk/echobase-services/src/test/resources/log4j.properties =================================================================== --- trunk/echobase-services/src/test/resources/log4j.properties 2012-09-04 06:14:33 UTC (rev 609) +++ trunk/echobase-services/src/test/resources/log4j.properties 2012-09-04 06:50:16 UTC (rev 610) @@ -30,5 +30,4 @@ # package level log4j.logger.fr.ifremer.echobase=INFO -#log4j.logger.fr.ifremer.echobase.services.ReplicateEntityVisitor=DEBUG -#log4j.logger.fr.ifremer.echobase.services.importdata.AcousticImportServiceUG +log4j.logger.org.nuiton.topia.migration=INFO Modified: trunk/echobase-ui/pom.xml =================================================================== --- trunk/echobase-ui/pom.xml 2012-09-04 06:14:33 UTC (rev 609) +++ trunk/echobase-ui/pom.xml 2012-09-04 06:50:16 UTC (rev 610) @@ -326,13 +326,13 @@ <id>assembly</id> <activation> <property> - <name>performRelease</name> - <value>true</value> + <name>skipAssembly</name> + <value>!true</value> </property> </activation> <properties> <embeddedWarDir> - ${project.build.directory}/echobase-embedded-${project.version} + ${project.build.directory}/echobase-${project.version}-embedded </embeddedWarDir> </properties> <build> @@ -469,8 +469,8 @@ </configuration> <executions> <execution> - <id>create-assemblies</id> - <phase>verify</phase> + <id>create-embedded-zip</id> + <phase>package</phase> <goals> <goal>single</goal> </goals> Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java 2012-09-04 06:14:33 UTC (rev 609) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java 2012-09-04 06:50:16 UTC (rev 610) @@ -194,22 +194,11 @@ TopiaContext rootContext = context.getInternalRootContext(); Preconditions.checkNotNull(rootContext); - boolean schemaExist = - EchoBaseEntityHelper.isInternalSchemaCreated(rootContext); - - if (schemaExist) { - - if (configuration.isUpdateSchema()) { - if (log.isInfoEnabled()) { - log.info("Will update schema..."); - } - rootContext.updateSchema(); - } - } else { + if (configuration.isUpdateSchema()) { if (log.isInfoEnabled()) { - log.info("Will create schema..."); + log.info("Will update schema..."); } - rootContext.createSchema(); + rootContext.updateSchema(); } TopiaContext tx = rootContext.beginTransaction();