<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright (C) 2006-2019 Talend Inc. - www.talend.com
   Licensed 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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.talend.sdk.component</groupId>
    <artifactId>component-server-parent</artifactId>
    <version>1.1.6</version>
  </parent>

  <artifactId>component-server</artifactId>

  <name>Component Runtime :: Server Parent :: Server</name>
  <description>The Web server of the framework. Mainly provides UI interaction hooks.</description>

  <properties>
    <talend.icon.output>${project.build.outputDirectory}</talend.icon.output>
    <talend.build.name>${talend.build.name.base}.server</talend.build.name>
    <sample.beam.groupId>org.talend.sdk.components</sample.beam.groupId>
    <sample.beam.artifactId>sample-beam</sample.beam.artifactId>
    <sample.beam.location>${project.build.directory}${file.separator}lib</sample.beam.location>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.talend.sdk.component</groupId>
      <artifactId>component-runtime-manager</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency><!-- extends runtime manager with design time data -->
      <groupId>org.talend.sdk.component</groupId>
      <artifactId>component-runtime-design-extension</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.talend.sdk.component</groupId>
      <artifactId>component-server-api</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.talend.ui</groupId>
      <artifactId>talend-icon</artifactId>
      <version>${talend-ui.version}</version>
      <scope>provided</scope>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>commons-cli</groupId>
      <artifactId>commons-cli</artifactId>
      <version>${commons-cli.version}</version>
    </dependency>

    <dependency><!-- override until we upgrade meecrowave -->
      <groupId>org.apache.johnzon</groupId>
      <artifactId>johnzon-jsonb</artifactId>
      <version>${johnzon.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.meecrowave</groupId>
      <artifactId>meecrowave-core</artifactId>
      <version>${meecrowave.version}</version>
    </dependency>
    <dependency>
      <groupId>org.eclipse.microprofile.config</groupId>
      <artifactId>microprofile-config-api</artifactId>
    </dependency>
    <dependency><!-- just to generate the openapi.json -->
      <groupId>org.eclipse.microprofile.openapi</groupId>
      <artifactId>microprofile-openapi-api</artifactId>
      <version>${microprofile-openapi-api.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.geronimo.config</groupId>
      <artifactId>geronimo-config-impl</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <version>${log4j2.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-web</artifactId>
      <version>${log4j2.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>${log4j2.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>${log4j2.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-jul</artifactId>
      <version>${log4j2.version}</version>
    </dependency>

    <dependency>
      <groupId>org.apache.tomcat</groupId>
      <artifactId>tomcat-websocket</artifactId>
      <version>${tomcat.version}</version>
    </dependency>

    <dependency>
      <groupId>org.apache.meecrowave</groupId>
      <artifactId>meecrowave-junit</artifactId>
      <version>${meecrowave.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.tomee</groupId>
      <artifactId>ziplock</artifactId>
      <version>${ziplock.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.talend.sdk.component</groupId>
      <artifactId>component-runtime-junit-base</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>

    <!-- just here to ensure the reactor is well structured, but shouldnt be in the classpath! -->
    <dependency>
      <groupId>org.talend.sdk.component</groupId>
      <artifactId>sample-beam</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.talend.sdk.component</groupId>
      <artifactId>component-runtime-beam</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>pl.project13.maven</groupId>
        <artifactId>git-commit-id-plugin</artifactId>
        <version>${git-commit-id-plugin.version}</version>
        <executions>
          <execution>
            <id>generate-the-git-infos</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>revision</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <generateGitPropertiesFile>true</generateGitPropertiesFile>
          <generateGitPropertiesFilename>${project.build.outputDirectory}/TALEND-INF/git.properties</generateGitPropertiesFilename>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.geronimo</groupId>
        <artifactId>geronimo-openapi-maven-plugin</artifactId>
        <version>${geronimo-openapi.version}</version>
        <executions>
          <execution>
            <id>generate-openapi.json</id>
            <goals>
              <goal>openapi.json</goal>
            </goals>
            <configuration>
              <output>${project.build.outputDirectory}/META-INF/resources/documentation/openapi.json</output>
              <application>org.talend.sdk.component.server.front.TalendComponentApplication</application>
              <endpointClasses>
                <endpointClass>org.talend.sdk.component.server.front.ActionResourceImpl</endpointClass>
                <endpointClass>org.talend.sdk.component.server.front.ComponentResourceImpl</endpointClass>
                <endpointClass>org.talend.sdk.component.server.front.ConfigurationTypeResourceImpl</endpointClass>
                <endpointClass>org.talend.sdk.component.server.front.DocumentationResourceImpl</endpointClass>
                <endpointClass>org.talend.sdk.component.server.front.EnvironmentResourceImpl</endpointClass>
              </endpointClasses>
              <info>
                <version>1</version>
                <title>Talend Component Server</title>
                <description>UI related component server to provide metadata about component and callback for the forms.</description>
              </info>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>${build-helper-maven-plugin.version}</version>
        <executions>
          <execution>
            <id>attach-artifacts</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${project.build.outputDirectory}/META-INF/resources/documentation/openapi.json</file>
                  <type>json</type>
                  <classifier>openapi</classifier>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <version>${gmavenplus.version}</version>
        <executions>
          <execution>
            <id>setup-deps-and-copy-icons</id>
            <phase>initialize</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <allowSystemExits>true</allowSystemExits>
              <scripts>
                <script>${project.parent.parent.basedir}/build/CreatePNGIcons.groovy</script>
              </scripts>
            </configuration>
          </execution>
          <execution>
            <id>openapi-customizations</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <allowSystemExits>true</allowSystemExits>
              <scripts>
                <script><![CDATA[
                  import java.nio.file.Files
                  import java.nio.file.StandardCopyOption
                  import javax.imageio.ImageIO
                  import net.sf.image4j.codec.ico.ICOEncoder
                  import org.apache.maven.project.MavenProjectHelper

                  // create the demo openapi.json
                  def openapiJson = new File(project.build.outputDirectory, 'META-INF/resources/documentation/openapi.json')
                  def content = openapiJson.text

                  def openapiDemo = new File(project.build.directory, 'openapi-openshift.json')
                  openapiDemo.text = content
                    .replace('"paths":{', '"servers": [{ url: "talend-component-kit-demo-server-talend-component-kit.193b.starter-ca-central-1.openshiftapps.com" }],\n  "paths":{')
                  // and attach it to the release
                  session.container.lookup(MavenProjectHelper).attachArtifact(project, 'json', 'openapi-openshift', openapiDemo);

                  // copy icon (in svg) for the topbar logo
                  def icon = Thread.currentThread().getContextClassLoader().getResourceAsStream('icons/svg/component-kit-positive.svg')
                  def iconTarget = new File(project.build.outputDirectory, 'META-INF/resources/documentation/logo.svg')
                  // change color
                  iconTarget.text = icon.text.replace('#000', '#0675c1')

                  // create the favicon from the png
                  ICOEncoder.write(
                    ImageIO.read(new File(project.build.outputDirectory, 'icons/svg/component-kit-positive_icon32.png')),
                    new File(project.build.outputDirectory, 'META-INF/resources/documentation/favicon.ico'));
                  ]]>
                </script>
              </scripts>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.jclarion</groupId>
            <artifactId>image4j</artifactId>
            <version>0.7</version>
          </dependency>
          <dependency>
            <groupId>org.apache.tomee</groupId>
            <artifactId>ziplock</artifactId>
            <version>${ziplock.version}</version>
          </dependency>
          <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>batik-codec</artifactId>
            <version>${batik.version}</version>
            <exclusions>
              <exclusion>
                <groupId>xml-apis</groupId>
                <artifactId>xml-apis</artifactId>
              </exclusion>
              <exclusion>
                <groupId>xalan</groupId>
                <artifactId>xalan</artifactId>
              </exclusion>
              <exclusion>
                <groupId>xerces</groupId>
                <artifactId>xercesImpl</artifactId>
              </exclusion>
            </exclusions>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>${dependency-plugin.version}</version>
        <executions>
          <execution>
            <id>create-TALEND-INF/dependencies.txt</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>list</goal>
            </goals>
            <configuration>
              <outputFile>${project.build.outputDirectory}/TALEND-INF/dependencies.txt</outputFile>
            </configuration>
          </execution>
          <execution>
            <id>import-redoc</id>
            <phase>prepare-package</phase>
            <goals> <!-- otherwise .map are too fat for what we do of it -->
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.webjars.npm</groupId>
                  <artifactId>redoc</artifactId>
                  <version>2.0.0-alpha.38</version>
                  <type>jar</type>
                  <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                  <includes>**/redoc.standalone.js</includes>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
          <execution>
            <id>copy-beam-sample</id>
            <phase>generate-test-resources</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <stripVersion>true</stripVersion>
              <artifactItems>
                <artifact>
                  <groupId>org.talend.sdk.component</groupId>
                  <artifactId>sample-beam</artifactId>
                  <version>${project.version}</version>
                  <type>jar</type>
                  <outputDirectory>${sample.beam.location}</outputDirectory>
                </artifact>
                <artifact>
                  <groupId>org.talend.sdk.component</groupId>
                  <artifactId>component-runtime-beam</artifactId>
                  <version>${project.version}</version>
                  <type>jar</type>
                  <outputDirectory>${sample.beam.location}/deps</outputDirectory>
                </artifact>
                <artifact>
                  <groupId>org.apache.beam</groupId>
                  <artifactId>beam-sdks-java-core</artifactId>
                  <version>${beam.version}</version>
                  <type>jar</type>
                  <outputDirectory>${sample.beam.location}/deps</outputDirectory>
                </artifact>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin><!-- for dev for now -->
        <groupId>org.apache.meecrowave</groupId>
        <artifactId>meecrowave-maven-plugin</artifactId>
        <version>${meecrowave.version}</version>
        <executions>
          <execution>
            <id>bundle</id>
            <phase>package</phase>
            <goals>
              <goal>bundle</goal>
            </goals>
            <configuration>
              <attach>true</attach>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <cdiConversation>false</cdiConversation>
          <watcherBouncing>-1</watcherBouncing>
          <scanningExcludes>
            apiguardian,brave,kafka,lz4,talend-icon,zipkin,container-core,component-runtime,beam,paranamer,joda-time,avro,objenesis,xz,snappy,component-spi,component-api,tomcat-websocket
          </scanningExcludes>
          <!--<webapp>${project.basedir}/src/dev/webapp</webapp>-->
          <properties>
            <!--
            <talend.component.server.documentation.active>true</talend.component.server.documentation.active>
            -->
            <talend.component.server.component.coordinates>${talend.component.server.component.coordinates.samples}</talend.component.server.component.coordinates>
          </properties>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <excludes>
                <exclude>**/beam/*Test.java</exclude>
              </excludes>
              <systemPropertyVariables>
                <org.apache.geronimo.config.configsource.SystemPropertyConfigSource.copy>false</org.apache.geronimo.config.configsource.SystemPropertyConfigSource.copy>
              </systemPropertyVariables>
              <classpathDependencyExcludes>
                <classpathDependencyExclude>org.talend.sdk.component:sample-beam</classpathDependencyExclude>
                <classpathDependencyExclude>org.talend.sdk.component:component-runtime-beam</classpathDependencyExclude>
              </classpathDependencyExcludes>
            </configuration>
          </execution>
          <execution>
            <id>beam-sample-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <includes>
                <include>**/beam/*Test.java</include>
              </includes>
              <systemPropertyVariables>
                <org.apache.geronimo.config.configsource.SystemPropertyConfigSource.copy>false</org.apache.geronimo.config.configsource.SystemPropertyConfigSource.copy>
                <components.server.beam.active>true</components.server.beam.active>
                <components.sample.beam.groupId>${sample.beam.groupId}</components.sample.beam.groupId>
                <components.sample.beam.artifactId>${sample.beam.artifactId}</components.sample.beam.artifactId>
                <components.sample.beam.version>${project.version}</components.sample.beam.version>
                <components.sample.beam.location>${sample.beam.location}</components.sample.beam.location>
              </systemPropertyVariables>
              <classpathDependencyExcludes>
                <classpathDependencyExclude>org.talend.sdk.component:sample-beam</classpathDependencyExclude>
              </classpathDependencyExcludes>
              <additionalClasspathElements>
                <additionalClasspathElement>${sample.beam.location}${file.separator}deps${file.separator}beam-sdks-java-core.jar</additionalClasspathElement>
              </additionalClasspathElements>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>java11</id>
      <activation>
        <jdk>11</jdk>
      </activation>
      <dependencies>
        <dependency>
          <groupId>org.apache.geronimo.specs</groupId>
          <artifactId>geronimo-jaxws_2.2_spec</artifactId>
        </dependency>
        <dependency>
          <groupId>org.apache.geronimo.specs</groupId>
          <artifactId>geronimo-activation_1.1_spec</artifactId>
        </dependency>
        <dependency>
          <groupId>javax.xml.bind</groupId>
          <artifactId>jaxb-api</artifactId>
        </dependency>
        <dependency>
          <groupId>com.sun.xml.bind</groupId>
          <artifactId>jaxb-impl</artifactId>
        </dependency>
      </dependencies>
    </profile>
    <profile>
      <id>travis</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <systemPropertyVariables>
                <java.util.logging.manager>org.apache.logging.log4j.jul.LogManager</java.util.logging.manager>
                <component.server.test.logging.skip>true</component.server.test.logging.skip>
              </systemPropertyVariables>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
