<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.yamcs</groupId>
    <artifactId>yamcs</artifactId>
    <version>5.9.6</version>
  </parent>

  <artifactId>yamcs-web</artifactId>
  <packaging>jar</packaging>
  <name>Yamcs :: Web UI</name>
  <description>
    Web UI for managing and monitoring Yamcs
  </description>

  <properties>
    <webdir>${basedir}/src/main/webapp/dist/webapp</webdir>
    <javaModuleName>org.yamcs.web</javaModuleName>
  </properties>

  <!--
    This maven module is used to publish a compiled version of the webapp during
    release. It does not actually compile the webapp. We don't use Maven for that.
  -->

  <dependencies>
    <dependency>
      <groupId>org.yamcs</groupId>
      <artifactId>yamcs-core</artifactId>
      <version>${project.version}</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <resources>
      <resource>
        <directory>${basedir}/src/main/resources</directory>
      </resource>
      <resource>
        <directory>${basedir}/target/webapp</directory>
      </resource>
      <resource>
        <directory>${project.build.directory}/generated-resources/protobuf</directory>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <!-- Sets the 'os.detected.classifier' maven property (needed to fetch native protoc) -->
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <!-- Generate Protobuf java sources -->
        <groupId>org.xolstice.maven.plugins</groupId>
        <artifactId>protobuf-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <writeDescriptorSet>true</writeDescriptorSet>
          <descriptorSetFileName>${project.artifactId}.protobin</descriptorSetFileName>
          <descriptorSetOutputDirectory>${project.build.directory}/generated-resources/protobuf</descriptorSetOutputDirectory>
          <includeDependenciesInDescriptorSet>false</includeDependenciesInDescriptorSet>
          <includeSourceInfoInDescriptorSet>true</includeSourceInfoInDescriptorSet>
          <protocPlugins>
            <protocPlugin>
              <id>yamcs</id>
              <groupId>org.yamcs</groupId>
              <artifactId>yamcs-protoc-plugin</artifactId>
              <version>5.3.1</version>
              <mainClass>org.yamcs.protoc.ServiceGenerator</mainClass>
            </protocPlugin>
          </protocPlugins>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.yamcs</groupId>
        <artifactId>yamcs-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>detect</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  
  <profiles>
    <profile>
      <activation>
        <file>
          <exists>${webdir}</exists>
        </file>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-resources</id>
                <phase>validate</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${basedir}/target/webapp/static</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${webdir}</directory>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>generate-manifest</id>
                <phase>validate</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target>
                    <fileset id="webfiles" dir="${basedir}/target/webapp/static" />
                    <property name="prop.webfiles" refid="webfiles" />
                    <echo file="${basedir}/target/webapp/static/manifest.txt">${prop.webfiles}</echo>
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
