<!--
  ~ Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
  ~
  ~ WSO2 Inc. licenses this file to you 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/maven-v4_0_0.xsd">
    <parent>
        <groupId>org.ballerinalang</groupId>
        <artifactId>ballerina-parent</artifactId>
        <version>0.970.0-beta4</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>plugin-vscode</artifactId>
    <packaging>pom</packaging>

    <name>Ballerina - Plugin VSCode</name>

    <repositories>
        <repository>
            <id>wso2.releases</id>
            <name>WSO2 Releases Repository</name>
            <url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>daily</updatePolicy>
                <checksumPolicy>ignore</checksumPolicy>
            </releases>
        </repository>
        <repository>
            <id>wso2.snapshots</id>
            <name>WSO2 Snapshot Repository</name>
            <url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>daily</updatePolicy>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.ballerinalang</groupId>
                <artifactId>language-server-stdio-launcher</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>${maven.exec.plugin.version}</version>
                <executions>
                    <execution>
                        <id>backup-package-lock</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <executable>node</executable>
                            <arguments>
                                <argument>./scripts/npm-preinstall</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm-install</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>initialize</phase>
                        <configuration>
                            <executable>${npm.executable}</executable>
                            <arguments>
                                <argument>install</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>replace-package-lock</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <executable>node</executable>
                            <arguments>
                                <argument>./scripts/npm-postinstall</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>vsix-package</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <executable>${npm.executable}</executable>
                            <arguments>
                                <argument>run</argument>
                                <argument>package</argument>
                                <argument>--</argument>
                                <argument>--out</argument>
                                <argument>target/ballerina-vscode-plugin-${project.version}.vsix</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>${maven.antrun.plugin.version}</version>
                <executions>
                    <execution>
                        <id>clean-target-server-build-dirs</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <delete dir="${project.basedir}/server-build" includeemptydirs="true" />
                                <delete dir="${project.basedir}/target" includeemptydirs="true" />
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <id>make-target-dir</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <mkdir dir="${project.basedir}/target" />
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.ballerinalang</groupId>
                                    <artifactId>language-server-stdio-launcher</artifactId>
                                    <version>${ballerina.version}</version>
                                    <type>jar</type>
                                    <classifier>jar-with-dependencies</classifier>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${basedir}/server-build/</outputDirectory>
                                    <destFileName>langserver.jar</destFileName>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.ballerinalang</groupId>
                                    <artifactId>language-server-stdio-launcher</artifactId>
                                    <version>${ballerina.version}</version>
                                    <type>jar</type>
                                    <classifier>jar-with-non-ballerina-dependencies</classifier>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${basedir}/server-build/</outputDirectory>
                                    <destFileName>langserver-no-bal-deps.jar</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>${maven.replacer.plugin.version}</version>
                <executions>
                    <execution>
                        <id>replace-version</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includes>
                        <include>${basedir}/package.json</include>
                    </includes>
                    <replacements>
                        <replacement>
                            <token>"version": "(.*?)",</token>
                            <value>"version": "${project.version}",</value>
                        </replacement>
                    </replacements>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
