<?xml version="1.0"?>
<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>de.saumya.mojo</groupId>
  <artifactId>rubygems</artifactId>
  <version>0.2.3</version>
  <packaging>war</packaging>
  <name>Rubygems Servlets</name>
  <url>http://github.com/torquebox/rubygems-servlets</url>
  <description>a servlet which can run a hosted rubygems repo, or caching proxy to remote repo, or just a proxy. finally you can have a merged repo of three types.</description>
  <licenses>
    <license>
      <name>AGPL</name>
    </license>
  </licenses>
  <developers>
    <developer>
      <name>Christian Meier</name>
      <email>m.kristian@web.de</email>
    </developer>
  </developers>
  <scm>
    <connection>scm:git:git://github.com/torquebox/rubygems-servlets.git</connection>
    <developerConnection>scm:git:git@github.com:torquebox/rubygems-servlets.git</developerConnection>
    <url>https://github.com/torquebox/rubygems-servlets</url>
  </scm>
  <distributionManagement>
    <repository>
      <id>sonatype-nexus-staging</id>
      <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
    </repository>
    <snapshotRepository>
      <id>sonatype-nexus-snapshots</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
  </distributionManagement>

  <dependencies>
    <dependency>
      <groupId>org.sonatype.nexus.plugins</groupId>
      <artifactId>nexus-ruby-tools</artifactId>
      <version>2.12.0-01</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.jruby.mains</groupId>
      <artifactId>jruby-mains</artifactId>
      <version>0.4.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-server</artifactId>
      <version>${jetty.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-webapp</artifactId>
      <version>${jetty.version}</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <properties>
    <path>caching/maven/</path>
    <web.xml>web.xml</web.xml>
    <proxy.storage>${project.build.directory}/proxy</proxy.storage>
    <jetty.version>8.1.18.v20150929</jetty.version>
    <jetty.run>**/JettyRun.java</jetty.run>
    <deploy.skip>true</deploy.skip>
  </properties>
  <build>
    <finalName>rubygems</finalName>
    <plugins>

      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
          <excludes><exclude>${jetty.run}</exclude></excludes>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
          <webXml>${basedir}/src/main/webapp/WEB-INF/${web.xml}</webXml>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <!-- we need a different version since there is no 8.1.18.xyz of this
             plugin -->
        <version>9.3.5.v20151012</version>
        <configuration>
          <webXml>${basedir}/src/main/webapp/WEB-INF/${web.xml}</webXml>
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <systemProperties>
            <systemProperty>
              <name>gem.proxy.storage</name>
              <value>${proxy.storage}</value>
            </systemProperty>
            <systemProperty>
              <name>gem.caching.proxy.storage</name>
              <value>${project.build.directory}/caching</value>
            </systemProperty>
            <systemProperty>
              <name>gem.hosted.storage</name>
              <value>${project.build.directory}/hosted</value>
            </systemProperty>
            <systemProperty>
              <name>gem.merged</name>
              <value>true</value>
            </systemProperty>
            <systemProperty>
              <name>jetty.port</name>
              <value>8989</value>
            </systemProperty>
          </systemProperties>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.8.2</version>
        <configuration>
          <skip>${deploy.skip}</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>executable</id>
      <properties>
        <jetty.run>nothing</jetty.run>
        <deploy.skip>false</deploy.skip>
      </properties>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
              <webResources>
                <webResource>
                  <directory>${project.build.outputDirectory}</directory>
                  <includes><include>**/JettyRun.class</include></includes>
                </webResource>
                <webResource>
                  <directory>${project.build.directory}/${project.artifactId}</directory>
                  <includes><include>**</include></includes>
                </webResource>
              </webResources>
              <archive>
                <manifest>
                  <mainClass>de.saumya.mojo.rubygems.JettyRun</mainClass>
                </manifest>
              </archive>
            </configuration>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.5.1</version>
            <executions>
              <execution>
                <id>jetty-classpath</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>unpack-dependencies</goal>
                </goals>
                <configuration>
                  <includeScope>provided</includeScope>
                  <!-- remove some files in order to decrease size -->
                  <excludes>*, about_files/*, META-INF/*</excludes>
                  <outputDirectory>
                    ${project.build.directory}/${project.artifactId}
                  </outputDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>merged</id>
      <properties>
        <path>merged/maven/</path>
      </properties>
    </profile>
    <profile>
      <id>proxy</id>
      <properties>
        <path>proxy/maven/</path>
      </properties>
    </profile>
    <profile>
      <id>legacy</id>
      <properties>
        <path></path>
        <proxy.storage>${project.build.directory}/legacy</proxy.storage>
        <web.xml>web-legacy.xml</web.xml>
      </properties>
    </profile>
    <profile>
      <id>run-its</id>
      <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
          <plugin>
            <artifactId>maven-invoker-plugin</artifactId>
            <version>1.5</version>
            <configuration>
              <streamLogs>true</streamLogs>
              <projectsDirectory>src/it</projectsDirectory>
              <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
              <preBuildHookScript>setup.bsh</preBuildHookScript>
              <postBuildHookScript>verify.bsh</postBuildHookScript>
              <settingsFile>src/it/settings.xml</settingsFile>
              <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
            </configuration>
            <executions>
              <execution>
                <id>integration-test</id>
                <goals>
                  <goal>install</goal>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin> 
          <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <configuration>
              <stopPort>4711</stopPort>
              <stopKey>gem-proxy</stopKey>
            </configuration>
            <executions>
              <execution>
                <id>start-jetty</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
                <configuration>
                  <scanIntervalSeconds>0</scanIntervalSeconds>
                  <daemon>true</daemon>
                </configuration>
              </execution>
              <execution>
                <id>stop-jetty</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>release</id>
      <activation>
        <property>
          <name>performRelease</name>
          <value>true</value>
        </property>
      </activation>
      <build>
        <defaultGoal>deploy</defaultGoal>
        <plugins>
          <plugin>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.4</version>
            <executions>
              <execution>
                <id>attach-sources</id>
                <goals>
                  <goal>jar-no-fork</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.10.1</version>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>1.5</version>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
