<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
-->
<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>
  <parent>
    <groupId>org.apache.myfaces.tobago</groupId>
    <artifactId>tobago</artifactId>
    <version>4.5.4</version>
  </parent>
  <packaging>pom</packaging>
  <name>Tobago Themes</name>
  <artifactId>tobago-theme</artifactId>

  <properties>
    <bootstrap.version>4.6.0</bootstrap.version>
    <theme.name>undefined-theme-name</theme.name>
  </properties>

  <modules>
    <module>tobago-theme-standard</module>
    <module>tobago-theme-scarborough</module>
    <module>tobago-theme-speyside</module>
    <module>tobago-theme-roxborough</module>
    <module>tobago-theme-charlotteville</module>
  </modules>

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>META-INF/tobago-config.xml</include>
        </includes>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>src/main/resources/META-INF/resources/tobago/${theme.name}</directory>
        <excludes>
          <exclude>**/tobago-bootstrap/_version/**</exclude>
        </excludes>
        <filtering>false</filtering>
        <targetPath>META-INF/resources/tobago/${theme.name}</targetPath>
      </resource>
      <resource>
        <directory>src/main/resources/META-INF/resources/tobago/${theme.name}/tobago-bootstrap/_version</directory>
        <filtering>false</filtering>
        <targetPath>META-INF/resources/tobago/${theme.name}/tobago-bootstrap/${project.version}</targetPath>
      </resource>
    </resources>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <executions>
            <execution>
              <phase>validate</phase>
              <goals>
                <goal>copy</goal>
              </goals>
              <configuration>
                <artifactItems>
                  <artifactItem>
                    <groupId>com.google.javascript</groupId>
                    <artifactId>closure-compiler</artifactId>
                    <version>v20190415</version>
                    <overWrite>true</overWrite>
                    <outputDirectory>${project.build.directory}/javascript-min</outputDirectory>
                    <destFileName>closure-compiler.jar</destFileName>
                  </artifactItem>
                </artifactItems>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  <profiles>

    <profile>
      <id>rebuild-theme</id>
      <build>
        <plugins>

          <plugin>
            <groupId>com.googlecode.maven-download-plugin</groupId>
            <artifactId>download-maven-plugin</artifactId>
            <version>1.6.3</version>
            <executions>
              <execution>
                <id>step #1: download-bootstrap</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>wget</goal>
                </goals>
                <configuration>
                  <url>https://github.com/twbs/bootstrap/archive/v${bootstrap.version}.zip</url>
                  <unpack>true</unpack>
                  <outputDirectory>${project.build.directory}</outputDirectory>
                  <md5>4304c073e2890cdb9ede8c1ebf9f5bfd</md5>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <!-- alternative way, if there is no direct download of a release (e.g. to test current snapshot) -->
<!--
          <plugin>
            <artifactId>maven-scm-plugin</artifactId>
            <version>1.9.5</version>
            <executions>
              <execution>
                &lt;!&ndash;load Bootstrap sources via git to target/checkout &ndash;&gt;
                <id>step #1: checkout-bootstrap</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>checkout</goal>
                </goals>
                <configuration>
                  <connectionUrl>scm:git:https://github.com/twbs/bootstrap</connectionUrl>
                  <skipCheckoutIfExists>true</skipCheckoutIfExists>
                  <scmVersion>v${bootstrap.version}</scmVersion>
                  <scmVersionType>branch</scmVersionType>
                  <checkoutDirectory>${project.build.directory}/bootstrap-${bootstrap.version}</checkoutDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
-->

          <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.2.0</version>
            <executions>
              <execution>
                <!-- copy Bootstrap to target/bootstrap -->
                <id>step #2: copy-bootstrap</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/bootstrap</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${project.build.directory}/bootstrap-${bootstrap.version}</directory>
                      <exclude>scss/_custom.scss</exclude>
                    </resource>
                  </resources>
                </configuration>
              </execution>
              <execution>
                <!-- copy customization to target/bootstrap -->
                <id>step #3: copy-custom</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/bootstrap</outputDirectory>
                  <resources>
                    <resource>
                      <directory>src/main</directory>
                      <includes>
                        <include>scss/*</include>
                      </includes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
              <execution>
                <!-- copy the result to src to be under source control -->
                <id>step #12: copy-bootstrap-dist to src</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>
                    ${basedir}/src/main/resources/META-INF/resources/tobago/${theme.name}/tobago-bootstrap/_version
                  </outputDirectory>
                  <resources>
                    <resource>
                      <directory>${project.build.directory}/bootstrap/dist</directory>
                      <includes>
                        <include>css/bootstrap.css</include>
                        <include>css/bootstrap.min.css</include>
                        <include>css/bootstrap.css.map</include>
                        <include>css/bootstrap.min.css.map</include>
                        <include>js/bootstrap.js</include>
                        <include>js/bootstrap.min.js</include>
                      </includes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
              <execution>
                <!-- copy the result to target/classes -->
                <id>step #13: copy-bootstrap-dist to target</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>
                    ${project.build.outputDirectory}/META-INF/resources/tobago/${theme.name}/tobago-bootstrap/${project.version}
                  </outputDirectory>
                  <resources>
                    <resource>
                      <directory>${project.build.directory}/bootstrap/dist</directory>
                      <includes>
                        <include>css/bootstrap.css</include>
                        <include>css/bootstrap.min.css</include>
                        <include>css/bootstrap.css.map</include>
                        <include>css/bootstrap.min.css.map</include>
                        <include>js/bootstrap.js</include>
                        <include>js/bootstrap.min.js</include>
                      </includes>
                    </resource>
                  </resources>
                  <!-- overwrite, because the default maven-resources-plugin step copies an older version to here -->
                  <overwrite>true</overwrite>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-patch-plugin</artifactId>
            <version>1.2</version>
            <configuration>
              <patches>
                <patch>append-tobago-theme-to-bootstrap.patch</patch>
              </patches>
              <targetDirectory>${project.build.directory}/bootstrap</targetDirectory>
            </configuration>
            <executions>
              <execution>
                <!-- copy the result to target/classes -->
                <id>step #4: append-tobago-theme-to-bootstrap</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>apply</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.1.2</version>
            <executions>
              <execution>
                <!-- copy customization to target/bootstrap -->
                <id>step #5: unpack-custom</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/bootstrap</outputDirectory>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.apache.myfaces.tobago</groupId>
                      <artifactId>tobago-core</artifactId>
                      <version>${project.version}</version>
                    </artifactItem>
                  </artifactItems>
                  <includes>**/*.scss</includes>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>1.12.0</version>

            <!-- optional -->
            <configuration>
              <nodeVersion>v14.15.4</nodeVersion> <!-- contains npm version 6.14.10 -->

              <!-- optional: Where to download Node.js binary from. Defaults to http://nodejs.org/dist/ -->
              <!--<nodeDownloadRoot>https://nodejs.org/dist/</nodeDownloadRoot>-->

              <!-- optional: Where to download NPM binary from. Defaults to http://registry.npmjs.org/npm/-/ -->
              <!--<npmDownloadRoot>https://registry.npmjs.org/npm/-/</npmDownloadRoot>-->

              <!-- optional: Registry override, passed as the registry option during npm install if set. -->
              <!--<npmRegistryURL>https://registry.npmjs.org/</npmRegistryURL>-->

              <!-- optional: where to install node and npm. Defaults to the working directory -->
              <installDirectory>${project.build.directory}/frontend</installDirectory>
              <workingDirectory>${project.build.directory}/bootstrap</workingDirectory>
            </configuration>

            <executions>

              <execution>
                <!-- install "node" and "npm" -->
                <id>step #6: install node and npm</id>
                <goals>
                  <goal>install-node-and-npm</goal>
                </goals>
                <phase>generate-resources</phase>
              </execution>

              <execution>
                <!-- install all other required stuff for "bootstrap" -->
                <id>step #7: npm install</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                  <arguments>install</arguments>
                </configuration>
              </execution>

              <execution>
                <!-- build "bootstrap" -->
                <id>step #8: npm run css-compile</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                  <arguments>run css-compile</arguments>
                </configuration>
              </execution>

              <execution>
                <!-- build "bootstrap" -->
                <id>step #9: npm run css-prefix</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                  <arguments>run css-prefix</arguments>
                </configuration>
              </execution>

              <execution>
                <!-- build "bootstrap" -->
                <id>step #10: npm run css-minify</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                  <arguments>run css-minify</arguments>
                </configuration>
              </execution>

              <execution>
                <!-- build "bootstrap" -->
                <id>step #11: npm run js</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                  <arguments>run js</arguments>
                </configuration>
              </execution>

            </executions>
          </plugin>

        </plugins>
      </build>
    </profile>
  </profiles>

</project>
