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

<!--
  ~  Copyright 2017 Alexey Andreev.
  ~
  ~  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>
  <groupId>org.teavm</groupId>
  <artifactId>teavm-idea-dependencies</artifactId>
  <version>1.0.0-SNAPSHOT</version>

  <repositories>
    <repository>
      <id>idea-releases</id>
      <url>https://www.jetbrains.com/intellij-repository/releases</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>com.jetbrains.intellij.idea</groupId>
      <artifactId>ideaIC</artifactId>
      <version>${idea.version}</version>
      <type>zip</type>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.teavm</groupId>
      <artifactId>teavm-tooling</artifactId>
      <version>${teavm.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.teavm</groupId>
      <artifactId>teavm-chrome-rdp</artifactId>
      <version>${teavm.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>unpack-idea</id>
            <phase>compile</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <includeGroupIds>com.jetbrains.intellij.idea</includeGroupIds>
              <includeArtifactIds>ideaIC</includeArtifactIds>
              <outputDirectory>${basedir}/dependencies/idea</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <phase>process-resources</phase>
            <configuration>
              <target>
                <mkdir dir="${basedir}/dependencies/"/>
                <get src="https://plugins.jetbrains.com/plugin/download?updateId=42362"
                     dest="${basedir}/dependencies/scala.zip"/>
                <unzip src="${basedir}/dependencies/scala.zip" dest="${basedir}/dependencies"/>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.1.1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <atrifactSet>
                <excludes>
                  <exclude>com.jetbrains.intellij.idea:ideaIC:zip:*</exclude>
                </excludes>
              </atrifactSet>
              <createDependencyReducedPom>false</createDependencyReducedPom>
              <outputFile>dependencies/teavm.jar</outputFile>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.5.2</version>
        <executions>
          <execution>
            <id>teavm</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>install</phase>
            <configuration>
              <file>dependencies/teavm.jar</file>
              <artifactId>teavm</artifactId>
              <version>${teavm.version}</version>
            </configuration>
          </execution>
          <execution>
            <id>openapi</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/lib/openapi.jar</file>
              <artifactId>openapi</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>util</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/lib/util.jar</file>
              <artifactId>util</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>extensions</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/lib/extensions.jar</file>
              <artifactId>extensions</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>annotations</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/lib/annotations.jar</file>
              <artifactId>annotations</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>jdom</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/lib/jdom.jar</file>
              <artifactId>jdom</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>maven</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/plugins/maven/lib/maven.jar</file>
              <artifactId>maven</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>maven-server-api</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/plugins/maven/lib/maven-server-api.jar</file>
              <artifactId>maven-server-api</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>idea</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/lib/idea.jar</file>
              <artifactId>idea</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>jps-model</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/lib/jps-model.jar</file>
              <artifactId>jps-model</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>jps-builders</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/lib/jps-builders.jar</file>
              <artifactId>jps-builders</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>jps-builders-6</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/lib/jps-builders-6.jar</file>
              <artifactId>jps-builders-6</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>log4j</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/lib/commons-logging-1.2.jar</file>
              <artifactId>commons-logging</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>kotlin</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/idea/plugins/Kotlin/lib/kotlin-plugin.jar</file>
              <artifactId>kotlin-plugin</artifactId>
            </configuration>
          </execution>
          <execution>
            <id>scala</id>
            <goals>
              <goal>install-file</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <file>dependencies/Scala/lib/scala-plugin.jar</file>
              <artifactId>scala-plugin</artifactId>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <localRepositoryPath>dependencies/maven</localRepositoryPath>
          <groupId>org.teavm.idea</groupId>
          <version>${idea.version}</version>
          <packaging>jar</packaging>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>