<?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.12</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.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>
    <talend.component.server.tomcat.valve.error.debug>false</talend.component.server.tomcat.valve.error.debug>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.talend.sdk.component</groupId>
      <artifactId>component-runtime-manager</artifactId>
      <version>${project.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.apache.geronimo.specs</groupId>
          <artifactId>geronimo-annotation_1.3_spec</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.apache.geronimo.specs</groupId>
          <artifactId>geronimo-json_1.1_spec</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.apache.geronimo.specs</groupId>
          <artifactId>geronimo-jsonb_1.0_spec</artifactId>
        </exclusion>
      </exclusions>
    </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>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.talend.sdk.component</groupId>
      <artifactId>component-server-extension-api</artifactId>
      <version>${project.version}</version>
      <exclusions>
        <exclusion><!-- all the stack must be provided -->
          <groupId>*</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </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.apache.cxf</groupId>
      <artifactId>cxf-rt-features-logging</artifactId>
      <version>${cxf.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.BulkReadResourceImpl</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>openapi-customizations</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <allowSystemExits>true</allowSystemExits>
              <scripts>
                <script><![CDATA[
                    import javax.imageio.ImageIO
                    import net.sf.image4j.codec.ico.ICOEncoder
                    import org.apache.batik.transcoder.TranscoderException
                    import org.apache.batik.transcoder.TranscoderInput
                    import org.apache.batik.transcoder.TranscoderOutput
                    import org.apache.batik.transcoder.image.ImageTranscoder
                    import org.apache.batik.transcoder.image.PNGTranscoder
                    import java.awt.Color
                    import java.awt.image.BufferedImage

                    def toPng(byte[] svg) throws IOException {
                      def pngTranscoder = new PNGTranscoder() {
                          @Override
                          void writeImage(BufferedImage img, TranscoderOutput output) throws TranscoderException {
                              // otherwise all web icon are just plain black and studio ignores the alpha in its
                              // md5 cache key so we just get only one icon
                              for (def x = 1; x < img.getWidth() - 1; x++) { for (def y = 1; y < img.getHeight() - 1; y++) {
                                  Color color = new Color(img.getRGB(x, y), true);
                                  if (color.getAlpha() == 0) {
                                    // enforce some differences for all black images
                                    img.setRGB(x, y, new Color(255, 255, 255, color.getAlpha()).getRGB());
                                  }
                                }
                              }

                              super.writeImage(img, output);
                          }
                      }
                      pngTranscoder.addTranscodingHint(ImageTranscoder.KEY_HEIGHT, 32f);
                      pngTranscoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, 32f);
                      def ostream = new ByteArrayOutputStream();
                      try {
                          pngTranscoder.transcode(new TranscoderInput(new ByteArrayInputStream(svg)), new TranscoderOutput(ostream));
                      } catch (e) {
                          throw new IllegalStateException(e);
                      }
                      ostream.close();

                      ostream.toByteArray();
                  }

                  def icon = {
                    Thread.currentThread().getContextClassLoader().getResourceAsStream('icons/svg/component-kit-positive.svg')
                  }

                  // copy icon (in svg) for the topbar logo - and change color to adapt it
                  def iconTarget = new File(project.build.outputDirectory, 'META-INF/resources/documentation/logo.svg')
                  iconTarget.text = icon().text.replace('#000', '#0675c1')

                  // create the favicon from the png
                  ICOEncoder.write(
                    ImageIO.read(new ByteArrayInputStream(toPng(icon().bytes))),
                    new File(project.build.outputDirectory, 'META-INF/resources/documentation/favicon.ico'));
                  ]]>
                </script>
              </scripts>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.talend.ui</groupId>
            <artifactId>talend-icon</artifactId>
            <version>${talend-ui.version}</version>
          </dependency>
          <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/server/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>
                <artifact>
                  <groupId>org.apache.avro</groupId>
                  <artifactId>avro</artifactId>
                  <version>${avro.version}</version>
                  <type>jar</type>
                  <outputDirectory>${sample.beam.location}/deps</outputDirectory>
                </artifact>
                <artifact>
                  <groupId>org.codehaus.jackson</groupId>
                  <artifactId>jackson-core-asl</artifactId>
                  <version>${avro-jackson.version}</version>
                  <type>jar</type>
                  <outputDirectory>${sample.beam.location}/deps</outputDirectory>
                </artifact>
                <artifact>
                  <groupId>org.codehaus.jackson</groupId>
                  <artifactId>jackson-mapper-asl</artifactId>
                  <version>${avro-jackson.version}</version>
                  <type>jar</type>
                  <outputDirectory>${sample.beam.location}/deps</outputDirectory>
                </artifact>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <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>-->
          <!--
          <systemProperties>
            <talend.component.server.documentation.active>true</talend.component.server.documentation.active>
            <talend.component.server.tomcat.valve.error.debug>${talend.component.server.tomcat.valve.error.debug}</talend.component.server.tomcat.valve.error.debug>
            <talend.component.server.component.coordinates>${talend.component.server.component.coordinates.samples}</talend.component.server.component.coordinates>
          </systemProperties>
          -->
        </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,
                  ${sample.beam.location}${file.separator}deps${file.separator}component-runtime-beam.jar,
                  ${sample.beam.location}${file.separator}deps${file.separator}jackson-core-asl.jar,
                  ${sample.beam.location}${file.separator}deps${file.separator}jackson-mapper-asl.jar,
                  ${sample.beam.location}${file.separator}deps${file.separator}avro.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>
