<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright (C) 2006-2018 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">
  <parent>
    <artifactId>component-server-parent</artifactId>
    <groupId>org.talend.sdk.component</groupId>
    <version>1.0.4</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>

  <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-model</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>io.zipkin.brave</groupId>
      <artifactId>brave-instrumentation-jaxrs2</artifactId>
      <version>4.13.3</version>
    </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.webjars</groupId>
      <artifactId>swagger-ui</artifactId>
      <version>3.17.4</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>

    <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>get-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.ActionResource</endpointClass>
                <endpointClass>org.talend.sdk.component.server.front.ComponentResource</endpointClass>
                <endpointClass>org.talend.sdk.component.server.front.ConfigurationTypeResource</endpointClass>
                <endpointClass>org.talend.sdk.component.server.front.DocumentationResource</endpointClass>
                <endpointClass>org.talend.sdk.component.server.front.EnvironmentResource</endpointClass>
              </endpointClasses>
            </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>com.sebastian-daschner</groupId>
        <artifactId>jaxrs-analyzer-maven-plugin</artifactId>
        <version>${jaxrs-analyzer.version}</version>
        <executions>
          <execution>
            <id>analyzer-adoc</id>
            <goals>
              <goal>analyze-jaxrs</goal>
            </goals>
            <configuration>
              <inlinePrettify>true</inlinePrettify>
              <backend>asciidoc</backend>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>com.github.rmannibucau</groupId>
            <artifactId>jaxrs-analyzer-extension</artifactId>
            <version>${jaxrs-analyzer-extension.version}</version>
          </dependency>
        </dependencies>
      </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 swagger.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>
          <execution>
            <id>copy-jaxrs-doc</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <allowSystemExits>true</allowSystemExits>
              <scripts>
                <script><![CDATA[
                  def doc = new File(project.build.directory, 'jaxrs-analyzer/rest-resources.adoc')
                  if (!doc.exists()) {
                    log.warn("${doc.absolutePath} doesn't exist")
                    return
                  }

                  def content = doc.text
                  def docCopy = new File(project.basedir, '../../documentation/src/main/antora/modules/ROOT/pages/_partials/generated_rest-resources.adoc')
                  if (!docCopy.exists() || !docCopy.text.trim() != content.trim()) {
                    docCopy.text = content
                  }
                ]]></script>
              </scripts>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.jclarion</groupId>
            <artifactId>image4j</artifactId>
            <version>0.7</version>
          </dependency>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>${groovy.version}</version>
            <type>pom</type>
          </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-shade-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>bundle</id>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <shadedClassifierName>fat</shadedClassifierName>
              <shadedArtifactAttached>true</shadedArtifactAttached>
              <dependencyReducedPomLocation>${project.build.directory}/reduced-pom-bundle.xml
              </dependencyReducedPomLocation>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>org.apache.meecrowave.runner.Cli</mainClass>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>META-INF/cxf/bus-extensions.txt</resource>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>log4j2.component.properties</resource>
                </transformer>
                <transformer implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer" />
                <transformer implementation="org.apache.openwebbeans.maven.shade.OpenWebBeansPropertiesTransformer" />
                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
              </transformers>
              <filters>
                <filter>
                  <artifact>*:*</artifact>
                  <excludes>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                    <exclude>META-INF/LICENSE.txt</exclude>
                    <exclude>META-INF/LICENSE</exclude>
                    <exclude>META-INF/NOTICE.txt</exclude>
                    <exclude>META-INF/NOTICE</exclude>
                  </excludes>
                </filter>
              </filters>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-maven</artifactId>
            <version>1.7.0</version>
          </dependency>
          <dependency>
            <groupId>com.github.edwgiz</groupId>
            <artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
            <version>2.1</version>
          </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>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,swagger-ui,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>
              <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>
                <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>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>
