<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright (C) 2015 Google Inc.

  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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.google.cloud.datastore</groupId>
  <artifactId>datastore-v1-protos</artifactId>
  <name>${project.groupId}:${project.artifactId}</name>
  <url>https://cloud.google.com/datastore/</url>

  <version>1.3.0</version>

  <description>
    Protocol buffers for accessing the Google Cloud Datastore API.
  </description>
  <licenses>
    <license>
      <name>The Apache License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    </license>
  </licenses>
  <developers>
    <developer>
      <organization>Google</organization>
      <organizationUrl>http://www.google.com</organizationUrl>
    </developer>
  </developers>
  <scm>
    <connection>scm:git:git@github.com:googleapis/googleapis.git</connection>
    <developerConnection>scm:git:git@github.com:googleapis/googleapis.git</developerConnection>
    <url>git@github.com:googleapis/googleapis.git</url>
  </scm>

  <packaging>jar</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <project.protobuf-python.version>3.0.0</project.protobuf-python.version>
    <project.protobuf-java.version>3.0.0</project.protobuf-java.version>
    <!--
      Must depend on the same version of com.google.protobuf:protobuf-java
      that we do.
    -->
    <project.grpc-google-common-protos.version>0.1.0</project.grpc-google-common-protos.version>
    <!--
      The node protobuf library (protobufjs) is third-party so the versioning
      will likely be different.
    -->
    <project.protobuf-node.version>4.1.2</project.protobuf-node.version>
    <project.javadocExecutable></project.javadocExecutable>
    <project.exec-maven-plugin.version>1.1</project.exec-maven-plugin.version>
    <project.maven-deploy-plugin.version>2.8.2</project.maven-deploy-plugin.version>
    <project.build-helper-maven-plugin.version>1.8</project.build-helper-maven-plugin.version>
    <project.maven-protoc-plugin.version>0.4.2</project.maven-protoc-plugin.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
      <version>${project.protobuf-java.version}</version>
    </dependency>

    <dependency>
      <groupId>com.google.api.grpc</groupId>
      <artifactId>grpc-google-common-protos</artifactId>
      <version>${project.grpc-google-common-protos.version}</version>
    </dependency>
  </dependencies>

  <pluginRepositories>
    <pluginRepository>
      <!-- For maven-protoc-plugin. -->
      <id>protoc-plugin</id>
      <url>https://dl.bintray.com/sergei-ivanov/maven/</url>
    </pluginRepository>
  </pluginRepositories>

  <build>
    <directory>/tmp/google-datastore-dist/target</directory>
    <outputDirectory>/tmp/google-datastore-dist/classes</outputDirectory>
    <extensions>
      <extension>
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
        <version>1.2.3.Final</version>
      </extension>
    </extensions>

    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>${project.exec-maven-plugin.version}</version>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>download_protos.sh</executable>
              <workingDirectory>${project.build.directory}/protos</workingDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- By default, skip maven deployment. This is reenabled in java only. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>${project.maven-deploy-plugin.version}</version>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>java</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
            </configuration>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.5</version>
            <configuration>
              <excludes>
                <!-- These classes are provided by the protobuf-java artifact. -->
                <exclude>com/google/protobuf/*</exclude>
                <!-- These classes are provided by the grpc-google-common-protos artifact. -->
                <exclude>com/google/api/*</exclude>
                <exclude>com/google/rpc/*</exclude>
                <exclude>com/google/type/*</exclude>
              </excludes>
            </configuration>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.10.3</version>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.4</version>
            <executions>
              <execution>
                <id>attach-sources</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>com.google.protobuf.tools</groupId>
            <artifactId>maven-protoc-plugin</artifactId>
            <version>${project.maven-protoc-plugin.version}</version>
            <configuration>
              <protocArtifact>com.google.protobuf:protoc:${project.protobuf-java.version}:exe:${os.detected.classifier}</protocArtifact>
              <protoSourceRoot>${project.build.directory}/protos</protoSourceRoot>
              <!-- Exclude the actual protos from the package. -->
              <attachProtoSources>false</attachProtoSources>
            </configuration>
            <executions>
              <execution>
                <phase>generate-resources</phase>
                <goals>
                  <goal>compile</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>${project.maven-deploy-plugin.version}</version>
            <configuration>
              <skip>false</skip>
            </configuration>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>1.6</version>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>

      <distributionManagement>
        <repository>
          <id>sonatype-nexus-staging</id>
          <name>Sonatype Nexus Staging</name>
          <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
        </repository>
        <snapshotRepository>
          <id>sonatype-nexus-snapshots</id>
          <name>Sonatype Nexus Snapshots</name>
          <url>http://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
      </distributionManagement>
    </profile>

    <profile>
      <id>python</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>${project.exec-maven-plugin.version}</version>
            <executions>
              <execution>
                <id>python-gen-files</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>generate_python_init_files.sh</executable>
                  <workingDirectory>${project.build.directory}/python</workingDirectory>
                </configuration>
              </execution>
              <execution>
                <id>python-prepare-package</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>python</executable>
                  <workingDirectory>${project.build.directory}/python</workingDirectory>
                  <arguments>
                    <argument>setup.py</argument>
                    <argument>sdist</argument>
                  </arguments>
                </configuration>
              </execution>
              <execution>
                <id>python-deploy</id>
                <phase>deploy</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>python</executable>
                  <workingDirectory>${project.build.directory}/python</workingDirectory>
                  <arguments>
                    <argument>setup.py</argument>
                    <argument>sdist</argument>
                    <argument>upload</argument>
                    <argument>-r</argument>
                    <argument>pypi</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>com.google.protobuf.tools</groupId>
            <artifactId>maven-protoc-plugin</artifactId>
            <version>${project.maven-protoc-plugin.version}</version>
            <configuration>
              <protocArtifact>com.google.protobuf:protoc:${project.protobuf-java.version}:exe:${os.detected.classifier}</protocArtifact>
              <protoSourceRoot>${project.build.directory}/protos</protoSourceRoot>
              <!-- Exclude the actual protos from the package. -->
              <attachProtoSources>false</attachProtoSources>
            </configuration>
            <executions>
              <execution>
                <id>python-codegen</id>
                <configuration>
                  <outputDirectory>${project.build.directory}/python</outputDirectory>
                  <clearOutputDirectory>false</clearOutputDirectory>
                </configuration>
                <phase>generate-resources</phase>
                <goals>
                  <goal>compile-python</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>

        <resources>
          <resource>
            <directory></directory>
            <includes>
              <include>setup.py</include>
            </includes>
            <targetPath>${project.build.directory}/python</targetPath>
            <filtering>true</filtering>
          </resource>
        </resources>
      </build>
    </profile>

    <profile>
      <id>node</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>${project.exec-maven-plugin.version}</version>
            <executions>
              <execution>
                <id>node-deploy</id>
                <phase>deploy</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>npm</executable>
                  <workingDirectory>${project.build.directory}/node</workingDirectory>
                  <arguments>
                    <argument>publish</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>${project.exec-maven-plugin.version}</version>
            <executions>
              <execution>
                <id>node-install-modules</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>npm</executable>
                  <workingDirectory>${project.build.directory}</workingDirectory>
                  <arguments>
                    <argument>install</argument>
                    <argument>protobufjs@${project.protobuf-node.version}</argument>
                  </arguments>
                </configuration>
              </execution>
              <execution>
                <id>node-build</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <environmentVariables>
                    <NODE_PATH>${project.build.directory}/node_modules:</NODE_PATH>
                  </environmentVariables>
                  <executable>/usr/bin/node</executable>
                  <workingDirectory>${project.build.directory}</workingDirectory>
                  <arguments>
                    <argument>${project.basedir}/node-builder.js</argument>
                    <argument>${project.build.directory}/protos</argument>
                    <argument>${project.build.directory}/protos/google/datastore/v1/datastore.proto</argument>
                    <argument>${project.build.directory}/node</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>

        <resources>
          <resource>
            <directory>node</directory>
            <includes>
              <include>package.json</include>
            </includes>
            <targetPath>${project.build.directory}/node</targetPath>
            <filtering>true</filtering>
          </resource>
        </resources>
      </build>
    </profile>

  </profiles>
</project>
