<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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.imcode.imcms.addon</groupId>
    <artifactId>imsurvey</artifactId>
    <packaging>war</packaging>
    <version>1.3</version>
    <name>imsurvey</name>

    <properties>
        <build.webapp.dir>${project.build.directory}/${project.artifactId}</build.webapp.dir>
    </properties>

    <parent>
        <groupId>com.imcode.imcms</groupId>
        <artifactId>babs-root-library</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <profiles>
        <profile>
            <id>development</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>com.imcode.imcms</groupId>
                    <artifactId>imcms</artifactId>
                    <type>war</type>
                </dependency>
                <dependency>
                    <groupId>com.imcode.imcms</groupId>
                    <artifactId>imcms</artifactId>
                    <classifier>classes</classifier>
                    <scope>provided</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <configuration>
                                    <tasks>
                                        <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
                                        <if>
                                            <not>
                                                <available file="${basedir}/local.server.properties"/>
                                            </not>
                                            <then>
                                                <copy file="${basedir}/local.server.properties.template"
                                                      tofile="${basedir}/local.server.properties"/>
                                                <fail>Edit "local.server.properties".</fail>
                                            </then>
                                        </if>

                                        <taskdef name="mergeproperties"
                                                 classname="com.imcode.ant.tasks.PropertiesMerge"/>
                                        <mergeproperties
                                                srcFile="target/${project.build.finalName}/WEB-INF/conf/server.properties"
                                                mergeFile="${basedir}/local.server.properties"
                                                destFile="target/${project.build.finalName}/WEB-INF/conf/server.properties"/>

                                        <if>
                                            <available file="${basedir}/src/main/webapp/WEB-INF/web.xml"/>
                                            <then>
                                                <copy file="${basedir}/src/main/webapp/WEB-INF/web.xml"
                                                      tofile="${project.build.directory}/${project.build.finalName}/WEB-INF/web.xml"
                                                      overwrite="true"/>
                                            </then>
                                        </if>

                                        <property file="local.server.properties"/>

                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>com.imcode.ant.tasks</groupId>
                                <artifactId>imcode-ant-tasks</artifactId>
                                <version>1.3</version>
                            </dependency>
                            <dependency>
                                <groupId>ant-contrib</groupId>
                                <artifactId>ant-contrib</artifactId>
                                <version>20020829</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>deployment</id>
            <dependencies>
                <dependency>
                    <groupId>com.imcode.imcms</groupId>
                    <artifactId>imcms</artifactId>
                    <classifier>classes</classifier>
                    <type>jar</type>
                    <scope>provided</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>com.imcode.db</groupId>
            <artifactId>imcode-db</artifactId>
            <version>0.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.imcode.util</groupId>
            <artifactId>imcode-util</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>com.imcode.imcms.addon</groupId>
            <artifactId>db-utils</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>com.imcode.imcms.addon</groupId>
            <artifactId>sms</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>com.imcode.imcms.addon</groupId>
            <artifactId>gui</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.imcode.imcms.addon</groupId>
            <artifactId>tree-menu</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>imsurvey</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-idea-plugin</artifactId>
                <configuration>
                    <jdkName>1.6</jdkName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <attachClasses>true</attachClasses>
                    <archiveClasses>true</archiveClasses>
                    <!-- TODO: Exclude web.xml from deployment war. While it doesn't override client's web.xml, it's not needed there. -->
                    <!-- Attention! The following excludes are still present in development build. -->
                    <packagingExcludes>**/create_user.jsp</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.wagon</groupId>
                        <artifactId>wagon-ssh</artifactId>
                        <version>1.0-beta-6</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>imcode</id>
            <url>http://repo.imcode.com/maven2</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>imcode</id>
            <url>http://repo.imcode.com/maven2</url>
        </pluginRepository>
    </pluginRepositories>

    <distributionManagement>
        <repository>
            <id>imcode</id>
            <name>imcode</name>
            <url>sftp://repo.imcode.com:2022/srv/www/repo.imcode.com/maven2</url>
        </repository>
    </distributionManagement>
</project>
