r390 - in trunk/echobase-services: . src/main/java/fr/ifremer/echobase/services src/main/resources/embedded src/test/java/fr/ifremer/echobase/services
Author: tchemit Date: 2012-03-22 19:11:04 +0100 (Thu, 22 Mar 2012) New Revision: 390 Url: http://forge.codelutin.com/repositories/revision/echobase/390 Log: add db drivers in embedded application Added: trunk/echobase-services/src/main/resources/embedded/README.txt trunk/echobase-services/src/main/resources/embedded/echobase.properties Removed: trunk/echobase-services/src/main/resources/embedded/echobase-embedded.properties Modified: trunk/echobase-services/pom.xml trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceIT.java Modified: trunk/echobase-services/pom.xml =================================================================== --- trunk/echobase-services/pom.xml 2012-03-22 18:10:27 UTC (rev 389) +++ trunk/echobase-services/pom.xml 2012-03-22 18:11:04 UTC (rev 390) @@ -195,6 +195,25 @@ </executions> </plugin> + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>copy-dependencies</goal> + </goals> + </execution> + </executions> + <configuration> + <outputDirectory>${project.build.directory}/classes/embedded</outputDirectory> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>false</overWriteSnapshots> + <overWriteIfNewer>true</overWriteIfNewer> + <includeArtifactIds>h2,postgresql</includeArtifactIds> + <excludeTransitive>true</excludeTransitive> + </configuration> + </plugin> + </plugins> </build> Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2012-03-22 18:10:27 UTC (rev 389) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2012-03-22 18:11:04 UTC (rev 390) @@ -49,6 +49,7 @@ import java.io.OutputStreamWriter; import java.net.URISyntaxException; import java.util.List; +import java.util.Properties; /** * To create embedded application. @@ -65,30 +66,6 @@ public static final String EMBEDDED_PATH = "/embedded/"; - public enum EmbeddedFile { - - ECHOBASE_PROPERTIES("echobase-embedded.properties", "echobase.properties"), - START_BAT("startEchobase.sh", "startEchobase.sh"), - START_SH("startEchobase.bat", "startEchobase.bat"); - - protected final String inputFileName; - - protected final String outputFileName; - - EmbeddedFile(String inputFileName, String outputFileName) { - this.inputFileName = inputFileName; - this.outputFileName = outputFileName; - } - - public String getInputFileName() { - return inputFileName; - } - - public String getOutputFileName() { - return outputFileName; - } - } - public File createEmbeddedApplication(EmbeddedApplicationConfiguration model) { int nbSteps = computeNbSteps(model); @@ -142,12 +119,12 @@ importDb(model, newServiceContext, exportZipFile, admin); } catch (Exception eee) { - throw new EchoBaseTechnicalException("Could not create h2 embedded database at "+dir,eee); + throw new EchoBaseTechnicalException("Could not create h2 embedded database at " + dir, eee); } finally { try { rootContext.closeContext(); } catch (TopiaException eee) { - throw new EchoBaseTechnicalException("Could not close h2 embedded database at "+dir,eee); + throw new EchoBaseTechnicalException("Could not close h2 embedded database at " + dir, eee); } } @@ -172,7 +149,6 @@ protected void createStaticArchiveStructure(EmbeddedApplicationConfiguration model, File dir) { - try { File warLocation = model.getWarLocation(); @@ -180,7 +156,7 @@ FileUtil.createDirectoryIfNecessary(dir); // copy embedded files to / - copyEmbeddedFiles(model, dir); + copyEmbeddedFiles(dir); // copy war to / FileUtil.copy(warLocation, new File(dir, warLocation.getName())); @@ -213,36 +189,54 @@ throw new EchoBaseTechnicalException( "Could not export db to zip", eee); } - - } - protected void copyEmbeddedFiles(EmbeddedApplicationConfiguration model, - File zipDirectory) throws IOException, URISyntaxException { + protected void copyEmbeddedFiles(File zipDirectory) throws IOException, URISyntaxException { - for (EmbeddedFile startFile : EmbeddedFile.values()) { + // config to keep the echobase-embedded values (contains h2 and pg versions) + Properties config = new Properties(); + copyEmbeddedFiles("echobase.properties", zipDirectory, config); + String h2Version = config.getProperty("h2Version"); + String pgVersion = config.getProperty("postgresqlVersion"); - String in = startFile.getInputFileName(); - String out = startFile.getOutputFileName(); + copyEmbeddedFiles("startEchobase.bat", zipDirectory, null); + copyEmbeddedFiles("startEchobase.sh", zipDirectory, null); + copyEmbeddedFiles("README.txt", zipDirectory, null); - InputStream inputStream = - getClass().getResourceAsStream(EMBEDDED_PATH + in); + File driverDir = new File(zipDirectory, "drivers"); + FileUtil.createDirectoryIfNecessary(driverDir); + copyEmbeddedFiles("h2-" + h2Version + ".jar", driverDir, null); + copyEmbeddedFiles("postgresql-" + pgVersion + ".jar", driverDir, null); + } + + protected void copyEmbeddedFiles(String resourceName, + File zipDirectory, + 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(zipDirectory, resourceName); + if (log.isInfoEnabled()) { + log.info("Copy configuration to " + resourceName + " to " + outputFile); + } + OutputStreamWriter outputStream = new OutputStreamWriter( + new FileOutputStream(outputFile), Charsets.UTF_8); try { - Preconditions.checkNotNull(inputStream); - File outputFile = new File(zipDirectory, out); - if (log.isInfoEnabled()) { - log.info("Copy configuration to " + in + " to " + outputFile); - } - OutputStreamWriter outputStream = new OutputStreamWriter( - new FileOutputStream(outputFile), Charsets.UTF_8); - try { + if (config == null) { IOUtils.copy(inputStream, outputStream); - } finally { - outputStream.close(); + } else { + config.store(outputStream, null); } } finally { - inputStream.close(); + outputStream.close(); } + } finally { + inputStream.close(); } } Added: trunk/echobase-services/src/main/resources/embedded/README.txt =================================================================== --- trunk/echobase-services/src/main/resources/embedded/README.txt (rev 0) +++ trunk/echobase-services/src/main/resources/embedded/README.txt 2012-03-22 18:11:04 UTC (rev 390) @@ -0,0 +1,2 @@ +Le répertoire 'drivers' contient les pilotes jdbc à positionner dans libre-office +pour pouvoir interroger l'application embarquée. \ No newline at end of file Deleted: trunk/echobase-services/src/main/resources/embedded/echobase-embedded.properties =================================================================== --- trunk/echobase-services/src/main/resources/embedded/echobase-embedded.properties 2012-03-22 18:10:27 UTC (rev 389) +++ trunk/echobase-services/src/main/resources/embedded/echobase-embedded.properties 2012-03-22 18:11:04 UTC (rev 390) @@ -1,34 +0,0 @@ -### -# #%L -# EchoBase :: Services -# -# $Id$ -# $HeadURL$ -# %% -# Copyright (C) 2011 Ifremer, Codelutin -# %% -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# #L% -### - -data.directory=. - -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.connection.username=sa -hibernate.connection.password=sa -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:file:./db/echobase - -# Replication configuration -topia.service.replication=org.nuiton.topia.replication.TopiaReplicationServiceImpl Copied: trunk/echobase-services/src/main/resources/embedded/echobase.properties (from rev 386, trunk/echobase-services/src/main/resources/embedded/echobase-embedded.properties) =================================================================== --- trunk/echobase-services/src/main/resources/embedded/echobase.properties (rev 0) +++ trunk/echobase-services/src/main/resources/embedded/echobase.properties 2012-03-22 18:11:04 UTC (rev 390) @@ -0,0 +1,34 @@ +### +# #%L +# EchoBase :: Services +# +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2011 Ifremer, Codelutin +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# #L% +### + +postgresqlVersion=${postgresqlVersion} +h2Version=${h2Version} + +data.directory=. + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.connection.username=sa +hibernate.connection.password=sa +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:file:${data.directory}/db/echobase Property changes on: trunk/echobase-services/src/main/resources/embedded/echobase.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceIT.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceIT.java 2012-03-22 18:10:27 UTC (rev 389) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceIT.java 2012-03-22 18:11:04 UTC (rev 390) @@ -41,7 +41,7 @@ protected FakeEchoBaseServiceContext initContext() { return new FakeEchoBaseServiceContext( - AbstractImportDataServiceIT.IMPORT_DATA_ECHOBASE_CATCHES_AND_ACOUSTIC_AND_VOYAGE_RESULT); + AbstractImportDataServiceIT.IMPORT_DATA_ECHOBASE_COMMON_DATA); } @Test
participants (1)
-
tchemit@users.forge.codelutin.com