Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe

Commits:

9 changed files:

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 {
    71 71
         @Test
    
    72 72
         public void build() throws SQLException, IOException {
    
    73 73
             Path avdthFile = AvdthFixtures.getAvdthCachePath()
    
    74
    -                .resolve("avdth-gen-35_74.mdb");
    
    74
    +                .resolve("OA/OA_2020_V35.mdb");
    
    75 75
             Assume.assumeTrue("Skip, avdth file " + avdthFile + " not found", Files.exists(avdthFile));
    
    76 76
             Path scriptPath = localTestMethodResource.getTestDirectory().toPath().resolve("export-" + avdthFile.toFile().getName().replace(".mdb", ".sql"));
    
    77 77
             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}
    25 25
     observetest.previous.model.version=${persistence.previous.model.version}
    
    26 26
     observetest.tck.cache.path=${tck.cache.path}
    
    27 27
     observetest.tck.credentials.path=${tck.credentials.store.path}
    
    28
    -observetest.avdth.cache.path=${avdth.cache.path}
    
    28
    +observetest.avdth.cache.path=${avdth.cache.path}/data
    
    29 29
     observetest.first.model.version=7.0
    
    30 30
     observetest.h2.login=sa
    
    31 31
     observetest.h2.password=sa
    

  • pom.xml
    ... ... @@ -98,13 +98,11 @@
    98 98
         <persistence.previous.model.version>9.2</persistence.previous.model.version>
    
    99 99
         <tck.filename>tck-v${persistence.model.version}.zip</tck.filename>
    
    100 100
         <tck.updated.filename>updated-${tck.filename}</tck.updated.filename>
    
    101
    -    <tck.remote.path>/var/www/html/private/ird-observe/tck</tck.remote.path>
    
    101
    +    <tck.remote.path>/var/www/html/private/ird-observe/tck/tck</tck.remote.path>
    
    102 102
         <tck.cache.path>${user.home}/.mvn/tck-cache/${model.name}/tck</tck.cache.path>
    
    103 103
         <tck.credentials.store.path>${user.home}/.mvn/tck-cache/${model.name}/credentials.properties</tck.credentials.store.path>
    
    104
    -    <!-- FIXME Create new mojo to deal with avdth cache like for tck -->
    
    105
    -    <avdth.filename>avdth-v${persistence.model.version}.zip</avdth.filename>
    
    106
    -    <!-- FIXME Create new mojo to deal with avdth cache like for tck -->
    
    107
    -    <avdth.remote.path>/var/www/html/private/ird-observe/avdth</avdth.remote.path>
    
    104
    +    <avdth.filename>avdth-v9.3.6.zip</avdth.filename>
    
    105
    +    <avdth.remote.path>/var/www/html/private/ird-observe/tck/avdth</avdth.remote.path>
    
    108 106
         <avdth.cache.path>${user.home}/.mvn/tck-cache/${model.name}/avdth</avdth.cache.path>
    
    109 107
         <!-- Do assert in tests-->
    
    110 108
         <test.skipAsserts>false</test.skipAsserts>
    
    ... ... @@ -1589,6 +1587,66 @@
    1589 1587
             </plugins>
    
    1590 1588
           </build>
    
    1591 1589
         </profile>
    
    1590
    +    <profile>
    
    1591
    +      <id>get-avdth</id>
    
    1592
    +      <activation>
    
    1593
    +        <file>
    
    1594
    +          <exists>.mvn/need-avdth</exists>
    
    1595
    +        </file>
    
    1596
    +      </activation>
    
    1597
    +      <build>
    
    1598
    +        <plugins>
    
    1599
    +          <plugin>
    
    1600
    +            <groupId>org.codehaus.mojo</groupId>
    
    1601
    +            <artifactId>wagon-maven-plugin</artifactId>
    
    1602
    +            <executions>
    
    1603
    +              <execution>
    
    1604
    +                <id>download-avdth</id>
    
    1605
    +                <goals>
    
    1606
    +                  <goal>download-single</goal>
    
    1607
    +                </goals>
    
    1608
    +                <phase>initialize</phase>
    
    1609
    +                <configuration>
    
    1610
    +                  <skipIfExists>true</skipIfExists>
    
    1611
    +                  <url>scpexe://ultreia.io</url>
    
    1612
    +                  <serverId>doc.ultreia.io</serverId>
    
    1613
    +                  <fromFile>${avdth.remote.path}/${avdth.filename}</fromFile>
    
    1614
    +                  <toDir>${avdth.cache.path}</toDir>
    
    1615
    +                </configuration>
    
    1616
    +              </execution>
    
    1617
    +            </executions>
    
    1618
    +          </plugin>
    
    1619
    +          <plugin>
    
    1620
    +            <groupId>${project.groupId}</groupId>
    
    1621
    +            <artifactId>toolkit-maven-plugin</artifactId>
    
    1622
    +            <version>${project.version}</version>
    
    1623
    +            <dependencies>
    
    1624
    +              <dependency>
    
    1625
    +                <groupId>com.h2database</groupId>
    
    1626
    +                <artifactId>h2</artifactId>
    
    1627
    +                <version>${lib.version.h2}</version>
    
    1628
    +              </dependency>
    
    1629
    +              <dependency>
    
    1630
    +                <groupId>org.postgresql</groupId>
    
    1631
    +                <artifactId>postgresql</artifactId>
    
    1632
    +                <version>${lib.version.postgresql}</version>
    
    1633
    +              </dependency>
    
    1634
    +            </dependencies>
    
    1635
    +            <executions>
    
    1636
    +              <execution>
    
    1637
    +                <id>default-avdth-create-databases</id>
    
    1638
    +                <goals>
    
    1639
    +                  <goal>avdth-create-databases</goal>
    
    1640
    +                </goals>
    
    1641
    +                <configuration>
    
    1642
    +                  <skipIfExists>true</skipIfExists>
    
    1643
    +                </configuration>
    
    1644
    +              </execution>
    
    1645
    +            </executions>
    
    1646
    +          </plugin>
    
    1647
    +        </plugins>
    
    1648
    +      </build>
    
    1649
    +    </profile>
    
    1592 1650
         <profile>
    
    1593 1651
           <id>delete-tck</id>
    
    1594 1652
           <activation>
    
    ... ... @@ -1616,6 +1674,33 @@
    1616 1674
             </plugins>
    
    1617 1675
           </build>
    
    1618 1676
         </profile>
    
    1677
    +    <profile>
    
    1678
    +      <id>delete-avdth</id>
    
    1679
    +      <activation>
    
    1680
    +        <property>
    
    1681
    +          <name>delete-avdth</name>
    
    1682
    +          <value>true</value>
    
    1683
    +        </property>
    
    1684
    +      </activation>
    
    1685
    +      <build>
    
    1686
    +        <defaultGoal>initialize</defaultGoal>
    
    1687
    +        <plugins>
    
    1688
    +          <plugin>
    
    1689
    +            <groupId>${project.groupId}</groupId>
    
    1690
    +            <artifactId>toolkit-maven-plugin</artifactId>
    
    1691
    +            <version>${project.version}</version>
    
    1692
    +            <executions>
    
    1693
    +              <execution>
    
    1694
    +                <id>default-avdth-delete-cache</id>
    
    1695
    +                <goals>
    
    1696
    +                  <goal>avdth-delete-cache</goal>
    
    1697
    +                </goals>
    
    1698
    +              </execution>
    
    1699
    +            </executions>
    
    1700
    +          </plugin>
    
    1701
    +        </plugins>
    
    1702
    +      </build>
    
    1703
    +    </profile>
    
    1619 1704
         <profile>
    
    1620 1705
           <id>documentation-generate-html</id>
    
    1621 1706
           <activation>
    

  • toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/PersistenceRunner.java
    ... ... @@ -115,7 +115,21 @@ public abstract class PersistenceRunner extends MojoRunnable {
    115 115
                     throw new IllegalStateException(e);
    
    116 116
                 }
    
    117 117
             }
    
    118
    -        return exploded;
    
    118
    +        return explodeArchive(archiveFile,exploded);
    
    119
    +    }
    
    120
    +
    
    121
    +    protected Path explodeArchive(Path archiveFile, Path target) {
    
    122
    +        if (Files.notExists(target)) {
    
    123
    +            try {
    
    124
    +                Files.createDirectories(target);
    
    125
    +                try (InputStream inputStream = Files.newInputStream(archiveFile)) {
    
    126
    +                    Zips.uncompress(inputStream, target.toFile());
    
    127
    +                }
    
    128
    +            } catch (IOException e) {
    
    129
    +                throw new IllegalStateException(e);
    
    130
    +            }
    
    131
    +        }
    
    132
    +        return target;
    
    119 133
         }
    
    120 134
     
    
    121 135
         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
    1
    +package fr.ird.observe.toolkit.maven.plugin.avdth;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe Toolkit :: Maven plugin
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2023 IRD, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import fr.ird.observe.toolkit.maven.plugin.PersistenceMojoSupport;
    
    26
    +import fr.ird.observe.toolkit.maven.plugin.PersistenceRunner;
    
    27
    +import io.ultreia.java4all.i18n.spi.builder.I18nKeySet;
    
    28
    +import org.apache.maven.plugins.annotations.LifecyclePhase;
    
    29
    +import org.apache.maven.plugins.annotations.Mojo;
    
    30
    +import org.apache.maven.plugins.annotations.Parameter;
    
    31
    +
    
    32
    +import java.io.File;
    
    33
    +import java.io.IOException;
    
    34
    +import java.nio.file.Files;
    
    35
    +import java.nio.file.Path;
    
    36
    +
    
    37
    +/**
    
    38
    + * Created on 29/06/2024.
    
    39
    + *
    
    40
    + * @author Tony Chemit - dev@tchemit.fr
    
    41
    + * @since 9.4.0
    
    42
    + */
    
    43
    +@Mojo(name = "avdth-create-databases", threadSafe = true, defaultPhase = LifecyclePhase.INITIALIZE)
    
    44
    +public class AvdthCreateDatabasesMojo extends PersistenceMojoSupport {
    
    45
    +
    
    46
    +    @Parameter(property = "runner.archiveFile", defaultValue = "${avdth.cache.path}/${avdth.filename}", required = true)
    
    47
    +    private File archiveFile;
    
    48
    +
    
    49
    +    @Parameter(property = "runner.avdthRootPath", defaultValue = "${avdth.cache.path}/data", required = true)
    
    50
    +    private File avdthRootPath;
    
    51
    +
    
    52
    +    @Parameter(property = "runner.skipIfExists", defaultValue = "false")
    
    53
    +    private boolean skipIfExists;
    
    54
    +
    
    55
    +    @Override
    
    56
    +    protected void doAction(I18nKeySet getterFile, ClassLoader classLoader) throws IOException {
    
    57
    +        Path resolve = avdthRootPath.toPath().resolve(getModelVersion().getVersion());
    
    58
    +        if (skipIfExists && Files.exists(resolve)) {
    
    59
    +            getLog().info(String.format("Skip - files already at: %s", resolve));
    
    60
    +            return;
    
    61
    +        }
    
    62
    +        super.doAction(getterFile, classLoader);
    
    63
    +    }
    
    64
    +
    
    65
    +    @Override
    
    66
    +    protected CreateAvdthDatabases createRunner() {
    
    67
    +        CreateAvdthDatabases runner = new CreateAvdthDatabases();
    
    68
    +        runner.setArchiveFile(archiveFile.toPath());
    
    69
    +        return runner;
    
    70
    +    }
    
    71
    +
    
    72
    +    @Override
    
    73
    +    protected void prepare(PersistenceRunner runner) {
    
    74
    +        super.prepare(runner);
    
    75
    +        runner.setSourceDirectory(avdthRootPath.toPath());
    
    76
    +    }
    
    77
    +}
    
    78
    +

  • toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/avdth/AvdthDeleteCacheMojo.java
    1
    +package fr.ird.observe.toolkit.maven.plugin.avdth;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe Toolkit :: Maven plugin
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2023 IRD, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import fr.ird.observe.toolkit.maven.plugin.PersistenceMojoSupport;
    
    26
    +import org.apache.maven.plugins.annotations.LifecyclePhase;
    
    27
    +import org.apache.maven.plugins.annotations.Mojo;
    
    28
    +import org.apache.maven.plugins.annotations.Parameter;
    
    29
    +
    
    30
    +import java.io.File;
    
    31
    +
    
    32
    +/**
    
    33
    + * Created on 29/06/2024.
    
    34
    + *
    
    35
    + * @author Tony Chemit - dev@tchemit.fr
    
    36
    + * @since 9.4.0
    
    37
    + */
    
    38
    +@Mojo(name = "avdth-delete-cache", threadSafe = true, defaultPhase = LifecyclePhase.INITIALIZE)
    
    39
    +public class AvdthDeleteCacheMojo extends PersistenceMojoSupport {
    
    40
    +
    
    41
    +    @Parameter(property = "runner.avdthRootPath", defaultValue = "${avdth.cache.path}", required = true)
    
    42
    +    private File avdthRootPath;
    
    43
    +
    
    44
    +    @Override
    
    45
    +    protected DeleteAvdthCache createRunner() {
    
    46
    +        DeleteAvdthCache runner = new DeleteAvdthCache();
    
    47
    +        runner.setAvdthRootPath(avdthRootPath.toPath());
    
    48
    +        return runner;
    
    49
    +    }
    
    50
    +}

  • toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/avdth/CreateAvdthDatabases.java
    1
    +package fr.ird.observe.toolkit.maven.plugin.avdth;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe Toolkit :: Maven plugin
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2023 IRD, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import fr.ird.observe.toolkit.maven.plugin.PersistenceRunner;
    
    26
    +
    
    27
    +import java.nio.file.Path;
    
    28
    +import java.util.Objects;
    
    29
    +
    
    30
    +/**
    
    31
    + * To create avdth databases from the avdth archive.
    
    32
    + * <p>
    
    33
    + * Created on 29/06/2024.
    
    34
    + *
    
    35
    + * @author Tony Chemit - dev@tchemit.fr
    
    36
    + * @since 9.4.0
    
    37
    + */
    
    38
    +public class CreateAvdthDatabases extends PersistenceRunner {
    
    39
    +    protected Path archiveFile;
    
    40
    +
    
    41
    +    public void setArchiveFile(Path archiveFile) {
    
    42
    +        this.archiveFile = archiveFile;
    
    43
    +    }
    
    44
    +
    
    45
    +    @Override
    
    46
    +    public void init() {
    
    47
    +        super.init();
    
    48
    +        Objects.requireNonNull(archiveFile);
    
    49
    +    }
    
    50
    +
    
    51
    +    @Override
    
    52
    +    public void run() {
    
    53
    +        Path exploded = explodeArchive(archiveFile, sourceDirectory);
    
    54
    +        log.info(String.format("Load avdth databases for version %s to %s", modelVersion, exploded));
    
    55
    +    }
    
    56
    +}

  • toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/avdth/DeleteAvdthCache.java
    1
    +package fr.ird.observe.toolkit.maven.plugin.avdth;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe Toolkit :: Maven plugin
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2023 IRD, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import fr.ird.observe.test.DataSourcesForTestManager;
    
    26
    +import fr.ird.observe.toolkit.maven.plugin.PersistenceRunner;
    
    27
    +
    
    28
    +import java.io.IOException;
    
    29
    +import java.nio.file.Path;
    
    30
    +import java.util.Objects;
    
    31
    +
    
    32
    +/**
    
    33
    + * Created on 29/06/2024.
    
    34
    + *
    
    35
    + * @author Tony Chemit - dev@tchemit.fr
    
    36
    + * @since 9.4.0
    
    37
    + */
    
    38
    +public class DeleteAvdthCache extends PersistenceRunner {
    
    39
    +
    
    40
    +    private Path avdthRootPath;
    
    41
    +
    
    42
    +    public void setAvdthRootPath(Path avdthRootPath) {
    
    43
    +        this.avdthRootPath = avdthRootPath;
    
    44
    +    }
    
    45
    +
    
    46
    +    @Override
    
    47
    +    public void init() {
    
    48
    +        super.init();
    
    49
    +        Objects.requireNonNull(avdthRootPath);
    
    50
    +    }
    
    51
    +
    
    52
    +    @Override
    
    53
    +    public void run() {
    
    54
    +        try {
    
    55
    +            DataSourcesForTestManager.clearCache(avdthRootPath);
    
    56
    +        } catch (IOException e) {
    
    57
    +            throw new IllegalStateException(String.format("Can't delete avdth cache at: %s", avdthRootPath), e);
    
    58
    +        }
    
    59
    +    }
    
    60
    +}
    
    61
    +