Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 8c311f15 by Tony Chemit at 2024-06-29T12:01:03+02:00 Externaliser les bases avdth utilisées dans les tests - Closes #2912 - - - - - 9 changed files: - + core/persistence/test/.mvn/need-avdth - core/persistence/test/src/test/java/fr/ird/observe/persistence/avdth/referential/AvdthWeightCategoryBuilderTest.java - model/src/main/filtered-resources/observetest.properties - pom.xml - toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/PersistenceRunner.java - + toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/avdth/AvdthCreateDatabasesMojo.java - + toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/avdth/AvdthDeleteCacheMojo.java - + toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/avdth/CreateAvdthDatabases.java - + toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/avdth/DeleteAvdthCache.java Changes: ===================================== core/persistence/test/.mvn/need-avdth ===================================== ===================================== core/persistence/test/src/test/java/fr/ird/observe/persistence/avdth/referential/AvdthWeightCategoryBuilderTest.java ===================================== @@ -71,7 +71,7 @@ public class AvdthWeightCategoryBuilderTest extends TestSupportWithConfig { @Test public void build() throws SQLException, IOException { Path avdthFile = AvdthFixtures.getAvdthCachePath() - .resolve("avdth-gen-35_74.mdb"); + .resolve("OA/OA_2020_V35.mdb"); Assume.assumeTrue("Skip, avdth file " + avdthFile + " not found", Files.exists(avdthFile)); Path scriptPath = localTestMethodResource.getTestDirectory().toPath().resolve("export-" + avdthFile.toFile().getName().replace(".mdb", ".sql")); Path scriptTemporaryDirectory = scriptPath.getParent().resolve(scriptPath.toFile().getName().replace(".sql", "-tmp")); ===================================== model/src/main/filtered-resources/observetest.properties ===================================== @@ -25,7 +25,7 @@ observetest.model.version=${persistence.model.version} observetest.previous.model.version=${persistence.previous.model.version} observetest.tck.cache.path=${tck.cache.path} observetest.tck.credentials.path=${tck.credentials.store.path} -observetest.avdth.cache.path=${avdth.cache.path} +observetest.avdth.cache.path=${avdth.cache.path}/data observetest.first.model.version=7.0 observetest.h2.login=sa observetest.h2.password=sa ===================================== pom.xml ===================================== @@ -98,13 +98,11 @@ <persistence.previous.model.version>9.2</persistence.previous.model.version> <tck.filename>tck-v${persistence.model.version}.zip</tck.filename> <tck.updated.filename>updated-${tck.filename}</tck.updated.filename> - <tck.remote.path>/var/www/html/private/ird-observe/tck</tck.remote.path> + <tck.remote.path>/var/www/html/private/ird-observe/tck/tck</tck.remote.path> <tck.cache.path>${user.home}/.mvn/tck-cache/${model.name}/tck</tck.cache.path> <tck.credentials.store.path>${user.home}/.mvn/tck-cache/${model.name}/credentials.properties</tck.credentials.store.path> - <!-- FIXME Create new mojo to deal with avdth cache like for tck --> - <avdth.filename>avdth-v${persistence.model.version}.zip</avdth.filename> - <!-- FIXME Create new mojo to deal with avdth cache like for tck --> - <avdth.remote.path>/var/www/html/private/ird-observe/avdth</avdth.remote.path> + <avdth.filename>avdth-v9.3.6.zip</avdth.filename> + <avdth.remote.path>/var/www/html/private/ird-observe/tck/avdth</avdth.remote.path> <avdth.cache.path>${user.home}/.mvn/tck-cache/${model.name}/avdth</avdth.cache.path> <!-- Do assert in tests--> <test.skipAsserts>false</test.skipAsserts> @@ -1589,6 +1587,66 @@ </plugins> </build> </profile> + <profile> + <id>get-avdth</id> + <activation> + <file> + <exists>.mvn/need-avdth</exists> + </file> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>wagon-maven-plugin</artifactId> + <executions> + <execution> + <id>download-avdth</id> + <goals> + <goal>download-single</goal> + </goals> + <phase>initialize</phase> + <configuration> + <skipIfExists>true</skipIfExists> + <url>scpexe://ultreia.io</url> + <serverId>doc.ultreia.io</serverId> + <fromFile>${avdth.remote.path}/${avdth.filename}</fromFile> + <toDir>${avdth.cache.path}</toDir> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>${project.groupId}</groupId> + <artifactId>toolkit-maven-plugin</artifactId> + <version>${project.version}</version> + <dependencies> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>${lib.version.h2}</version> + </dependency> + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>${lib.version.postgresql}</version> + </dependency> + </dependencies> + <executions> + <execution> + <id>default-avdth-create-databases</id> + <goals> + <goal>avdth-create-databases</goal> + </goals> + <configuration> + <skipIfExists>true</skipIfExists> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> <profile> <id>delete-tck</id> <activation> @@ -1616,6 +1674,33 @@ </plugins> </build> </profile> + <profile> + <id>delete-avdth</id> + <activation> + <property> + <name>delete-avdth</name> + <value>true</value> + </property> + </activation> + <build> + <defaultGoal>initialize</defaultGoal> + <plugins> + <plugin> + <groupId>${project.groupId}</groupId> + <artifactId>toolkit-maven-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <id>default-avdth-delete-cache</id> + <goals> + <goal>avdth-delete-cache</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> <profile> <id>documentation-generate-html</id> <activation> ===================================== toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/PersistenceRunner.java ===================================== @@ -115,7 +115,21 @@ public abstract class PersistenceRunner extends MojoRunnable { throw new IllegalStateException(e); } } - return exploded; + return explodeArchive(archiveFile,exploded); + } + + protected Path explodeArchive(Path archiveFile, Path target) { + if (Files.notExists(target)) { + try { + Files.createDirectories(target); + try (InputStream inputStream = Files.newInputStream(archiveFile)) { + Zips.uncompress(inputStream, target.toFile()); + } + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + return target; } protected void createForVersion(Version version, Path exploded, Path targetPath, DatabaseName... databaseNames) { ===================================== toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/avdth/AvdthCreateDatabasesMojo.java ===================================== @@ -0,0 +1,78 @@ +package fr.ird.observe.toolkit.maven.plugin.avdth; + +/*- + * #%L + * ObServe Toolkit :: Maven plugin + * %% + * Copyright (C) 2008 - 2023 IRD, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.toolkit.maven.plugin.PersistenceMojoSupport; +import fr.ird.observe.toolkit.maven.plugin.PersistenceRunner; +import io.ultreia.java4all.i18n.spi.builder.I18nKeySet; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * Created on 29/06/2024. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 9.4.0 + */ +@Mojo(name = "avdth-create-databases", threadSafe = true, defaultPhase = LifecyclePhase.INITIALIZE) +public class AvdthCreateDatabasesMojo extends PersistenceMojoSupport { + + @Parameter(property = "runner.archiveFile", defaultValue = "${avdth.cache.path}/${avdth.filename}", required = true) + private File archiveFile; + + @Parameter(property = "runner.avdthRootPath", defaultValue = "${avdth.cache.path}/data", required = true) + private File avdthRootPath; + + @Parameter(property = "runner.skipIfExists", defaultValue = "false") + private boolean skipIfExists; + + @Override + protected void doAction(I18nKeySet getterFile, ClassLoader classLoader) throws IOException { + Path resolve = avdthRootPath.toPath().resolve(getModelVersion().getVersion()); + if (skipIfExists && Files.exists(resolve)) { + getLog().info(String.format("Skip - files already at: %s", resolve)); + return; + } + super.doAction(getterFile, classLoader); + } + + @Override + protected CreateAvdthDatabases createRunner() { + CreateAvdthDatabases runner = new CreateAvdthDatabases(); + runner.setArchiveFile(archiveFile.toPath()); + return runner; + } + + @Override + protected void prepare(PersistenceRunner runner) { + super.prepare(runner); + runner.setSourceDirectory(avdthRootPath.toPath()); + } +} + ===================================== toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/avdth/AvdthDeleteCacheMojo.java ===================================== @@ -0,0 +1,50 @@ +package fr.ird.observe.toolkit.maven.plugin.avdth; + +/*- + * #%L + * ObServe Toolkit :: Maven plugin + * %% + * Copyright (C) 2008 - 2023 IRD, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.toolkit.maven.plugin.PersistenceMojoSupport; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +import java.io.File; + +/** + * Created on 29/06/2024. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 9.4.0 + */ +@Mojo(name = "avdth-delete-cache", threadSafe = true, defaultPhase = LifecyclePhase.INITIALIZE) +public class AvdthDeleteCacheMojo extends PersistenceMojoSupport { + + @Parameter(property = "runner.avdthRootPath", defaultValue = "${avdth.cache.path}", required = true) + private File avdthRootPath; + + @Override + protected DeleteAvdthCache createRunner() { + DeleteAvdthCache runner = new DeleteAvdthCache(); + runner.setAvdthRootPath(avdthRootPath.toPath()); + return runner; + } +} ===================================== toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/avdth/CreateAvdthDatabases.java ===================================== @@ -0,0 +1,56 @@ +package fr.ird.observe.toolkit.maven.plugin.avdth; + +/*- + * #%L + * ObServe Toolkit :: Maven plugin + * %% + * Copyright (C) 2008 - 2023 IRD, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.toolkit.maven.plugin.PersistenceRunner; + +import java.nio.file.Path; +import java.util.Objects; + +/** + * To create avdth databases from the avdth archive. + * <p> + * Created on 29/06/2024. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 9.4.0 + */ +public class CreateAvdthDatabases extends PersistenceRunner { + protected Path archiveFile; + + public void setArchiveFile(Path archiveFile) { + this.archiveFile = archiveFile; + } + + @Override + public void init() { + super.init(); + Objects.requireNonNull(archiveFile); + } + + @Override + public void run() { + Path exploded = explodeArchive(archiveFile, sourceDirectory); + log.info(String.format("Load avdth databases for version %s to %s", modelVersion, exploded)); + } +} ===================================== toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/avdth/DeleteAvdthCache.java ===================================== @@ -0,0 +1,61 @@ +package fr.ird.observe.toolkit.maven.plugin.avdth; + +/*- + * #%L + * ObServe Toolkit :: Maven plugin + * %% + * Copyright (C) 2008 - 2023 IRD, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.test.DataSourcesForTestManager; +import fr.ird.observe.toolkit.maven.plugin.PersistenceRunner; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Objects; + +/** + * Created on 29/06/2024. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 9.4.0 + */ +public class DeleteAvdthCache extends PersistenceRunner { + + private Path avdthRootPath; + + public void setAvdthRootPath(Path avdthRootPath) { + this.avdthRootPath = avdthRootPath; + } + + @Override + public void init() { + super.init(); + Objects.requireNonNull(avdthRootPath); + } + + @Override + public void run() { + try { + DataSourcesForTestManager.clearCache(avdthRootPath); + } catch (IOException e) { + throw new IllegalStateException(String.format("Can't delete avdth cache at: %s", avdthRootPath), e); + } + } +} + View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/8c311f15d3bbb8458227a7bd18... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/8c311f15d3bbb8458227a7bd18... You're receiving this email because of your account on gitlab.com.