<?xml version="1.0" encoding="UTF-8"?>

<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.kuali.coeus</groupId>
    <artifactId>coeus</artifactId>
        <version>2601.0021</version>
  </parent>
  <artifactId>coeus-webapp</artifactId>
  <packaging>war</packaging>
  <name>Kuali Coeus Webapp</name>
  <description>
    The Kuali Coeus Webapp module contains web artifacts for the Kuali Coeus application.
  </description>

  <properties>
    <web.xml.dir>src/main/webapp/WEB-INF</web.xml.dir>
    <jsfrontend.sources>src/main/jsfrontend</jsfrontend.sources>
    <generated.web.sources>${project.build.directory}/generated-web-sources</generated.web.sources>
    <help.web.sources>${project.build.directory}/generated-web-sources/help-web-sources</help.web.sources>
    <rice.web.sources>${project.build.directory}/generated-web-sources/rice-web-sources</rice.web.sources>

    <rice.web.excludes>
      <!-- Exclude for the time being to use local file -->
      rice-portal/scripts/easyXDM/resize_intermediate.html,
      META-INF/,
      WEB-INF/classes/,
      WEB-INF/lib/,

      WEB-INF/tags/rice-portal/mainTab.tag,
      WEB-INF/struts-config.xml,
      kr/WEB-INF/struts-config.xml,
      WEB-INF/validator-rules.xml,
      WEB-INF/web.xml,

      acknowledgments.jsp,
      index.jsp,
      WEB-INF/tags/rice-portal/portalBody.tag,
      WEB-INF/tags/rice-portal/portalTabs.tag,
      WEB-INF/tags/rice-portal/portalTop.tag,
      kr/WEB-INF/jsp/KualiLookup.jsp,
      kr/WEB-INF/jsp/KualiMultipleValueLookup.jsp,
      WEB-INF/tags/kr/page.tag,
      krad/WEB-INF/ftl/lib/backdoor.ftl
    </rice.web.excludes>

    <rice.output.dir>${project.build.directory}/rice-server</rice.output.dir>
    <rice.war.file>${rice.output.dir}/rice-standalone.war</rice.war.file>
    <rice.war.dir>${rice.output.dir}/rice-standalone</rice.war.dir>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.kuali.coeus</groupId>
      <artifactId>coeus-impl</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>


  <!--
   Using dependency unpack as opposed to war overlay for a number of reasons
   1) overlay requires the packaging phase - tomcat plugin run goal does not work with overlays.
   2) overlayed resources are not placed in a directory (like generated code) making
   it difficult for developers to look at the overlayed resources
   3) our unit test's application server lifecycle assume all web content resides in directories (see point 3)
   -->
  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
      </resource>
      <resource>
        <filtering>true</filtering>
        <directory>src/main/resources</directory>
        <includes>
          <include>META-INF/kc-config-build.xml</include>
        </includes>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack-help-web-sources</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.kuali.coeus</groupId>
                  <artifactId>coeus-help</artifactId>
                  <version>${project.version}</version>
                  <type>jar</type>
                  <overWrite>false</overWrite>
                </artifactItem>
              </artifactItems>
              <outputDirectory>${help.web.sources}/static/help</outputDirectory>
              <overWriteReleases>false</overWriteReleases>
            </configuration>
          </execution>

          <execution>
            <id>unpack-rice-web-sources</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.kuali.rice</groupId>
                  <artifactId>rice-standalone</artifactId>
                  <version>${rice.version}</version>
                  <type>war</type>
                  <overWrite>false</overWrite>
                  <outputDirectory>${rice.web.sources}</outputDirectory>
                </artifactItem>
              </artifactItems>
              <includes>*/**</includes>
              <excludes>${rice.web.excludes}</excludes>
            </configuration>
          </execution>

        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <webResources>
            <resource>
              <directory>${help.web.sources}</directory>
            </resource>
            <resource>
              <directory>${rice.web.sources}</directory>
            </resource>
            <resource>
              <directory>${web.xml.dir}</directory>
              <includes>
                <include>web.xml</include>
              </includes>
              <targetPath>WEB-INF</targetPath>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>build-jsfrontend-node</id>
      <activation>
        <property>
          <name>!build-jsfrontend-node.off</name>
        </property>
      </activation>
      <properties>
        <frontend-maven-plugin.version>2.0.0</frontend-maven-plugin.version>
        <frontend-maven-plugin.node.version>v22.16.0</frontend-maven-plugin.node.version>
        <frontend-maven-plugin.npm.version>10.9.2</frontend-maven-plugin.npm.version>
        <jsfrontend.web.sources>${project.build.directory}/generated-web-sources/jsfrontend-web-sources</jsfrontend.web.sources>
      </properties>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
              <webResources>
                <resource>
                  <directory>${help.web.sources}</directory>
                  <targetPath>.</targetPath>
                </resource>
                <resource>
                  <directory>${rice.web.sources}</directory>
                  <targetPath>.</targetPath>
                </resource>
                <resource>
                  <directory>${jsfrontend.web.sources}</directory>
                  <filtering>true</filtering>
                  <includes>
                    <include>apidocs/*.html</include>
                  </includes>
                  <targetPath>.</targetPath>
                </resource>
                <resource>
                  <directory>${jsfrontend.web.sources}</directory>
                  <filtering>true</filtering>
                  <includes>
                    <include>**/*.html</include>
                  </includes>
                  <targetPath>WEB-INF</targetPath>
                </resource>
                <resource>
                  <directory>${jsfrontend.web.sources}</directory>
                  <filtering>false</filtering>
                  <excludes>
                    <exclude>**/*.html</exclude>
                  </excludes>
                  <targetPath>.</targetPath>
                </resource>
                <resource>
                  <directory>${web.xml.dir}</directory>
                  <includes>
                    <include>web.xml</include>
                  </includes>
                  <targetPath>WEB-INF</targetPath>
                </resource>
              </webResources>
            </configuration>
          </plugin>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>${frontend-maven-plugin.version}</version>
            <configuration>
              <installDirectory>${project.build.directory}</installDirectory>
              <workingDirectory>${jsfrontend.sources}</workingDirectory>
            </configuration>
            <executions>
              <execution>
                <id>install node and npm</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>install-node-and-npm</goal>
                </goals>
                <configuration>
                  <nodeVersion>${frontend-maven-plugin.node.version}</nodeVersion>
                  <npmVersion>${frontend-maven-plugin.npm.version}</npmVersion>
                </configuration>
              </execution>

              <execution>
                <id>npm install</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <configuration>
                  <arguments>install</arguments>
                </configuration>
              </execution>
              <execution>
                <id>gulp build</id>
                <goals>
                  <goal>gulp</goal>
                </goals>
                <configuration>
                  <environmentVariables>
                    <VERSION>${project.version}</VERSION>
                  </environmentVariables>
                  <srcdir>${jsfrontend.sources}</srcdir>
                  <outputdir>${jsfrontend.web.sources}</outputdir>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>clean-jsfrontend-node</id>
      <activation>
        <property>
          <name>!clean-jsfrontend-node.off</name>
        </property>
      </activation>
      <build>
        <plugins>
          <!-- this special clean step is required because npm can't be configured to
               install into the target dir. To avoid node_modules from being downloaded after a ./mvnw clean you can
               turn off this clean step -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <version>${maven-clean-plugin.version}</version>
            <configuration>
              <filesets>
                <fileset>
                  <directory>${jsfrontend.sources}</directory>
                  <includes>
                    <include>**/etc/**</include>
                    <include>**/node_modules/**</include>
                  </includes>
                  <followSymlinks>false</followSymlinks>
                </fileset>
              </filesets>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>precompile-jsp-tomcat-9</id>
      <properties>
        <web.xml.dir>${project.build.directory}</web.xml.dir>
        <precompile.jsp.keep.sources>false</precompile.jsp.keep.sources>
      </properties>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>${maven-resources-plugin.version}</version>
            <executions>
              <execution>
                <id>copy-resources-for-precompile</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/precompiletomcat</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${basedir}/src/main/webapp</directory>
                      <filtering>false</filtering>
                    </resource>
                    <resource>
                      <directory>${rice.web.sources}</directory>
                      <filtering>false</filtering>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>io.leonard.maven.plugins</groupId>
            <artifactId>jspc-maven-plugin</artifactId>
            <version>${jspc-maven-plugin.version}</version>
            <configuration>
              <webAppSourceDirectory>${project.build.directory}/precompiletomcat</webAppSourceDirectory>
              <validateXml>true</validateXml>
              <validateWebXmlWithXsdAfterMerge>true</validateWebXmlWithXsdAfterMerge>
              <webXmlXsdSchema>http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd</webXmlXsdSchema>
              <verbose>true</verbose>
              <javaEncoding>${project.encoding}</javaEncoding>
              <keepSources>${precompile.jsp.keep.sources}</keepSources>
              <packageRoot>org.apache.jsp</packageRoot>
              <compilerVersion>${project.java.version}</compilerVersion>
              <genStringAsCharArray>true</genStringAsCharArray>
            </configuration>
            <executions>
              <execution>
                <id>precompile</id>
                <goals>
                  <goal>compile</goal>
                </goals>
              </execution>
            </executions>
            <dependencies>
              <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-jasper</artifactId>
                <version>${tomcat.version}</version>
              </dependency>
              <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <scope>runtime</scope>
                <version>1.3.5</version>
              </dependency>
            </dependencies>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
