<?xml version="1.0" encoding="UTF-8"?>
<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">
	<parent>
		<artifactId>org.cumulus4j.parent</artifactId>
		<groupId>org.cumulus4j</groupId>
		<version>1.2.1-SNAPSHOT</version>
		<relativePath>../org.cumulus4j.parent/pom.xml</relativePath>
	</parent>
	<modelVersion>4.0.0</modelVersion>
	<artifactId>org.cumulus4j.store</artifactId>
	<name>org.cumulus4j.store</name>
	<description>DataNucleus-store-plugin providing Cumulus4j encrypted data storage.</description>
	<packaging>bundle</packaging>

	<dependencies>
		<dependency>
			<groupId>javax.jdo</groupId>
			<artifactId>jdo-api</artifactId>
		</dependency>
		<dependency>
			<groupId>org.cumulus4j</groupId>
			<artifactId>org.cumulus4j.annotation</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.cumulus4j</groupId>
			<artifactId>org.cumulus4j.crypto</artifactId>
		</dependency>
		<dependency>
			<groupId>org.datanucleus</groupId>
			<artifactId>datanucleus-api-jdo</artifactId>
		</dependency>
		<dependency>
			<groupId>org.datanucleus</groupId>
			<artifactId>datanucleus-core</artifactId>
		</dependency>
		<dependency>
			<groupId>org.cumulus4j</groupId>
			<artifactId>org.cumulus4j.testutil</artifactId>
		</dependency>
	</dependencies>
	
	<profiles>
		<profile>
			<id>default</id>
			<activation>
				<property>
					<name>gae</name>
					<value>!true</value>
				</property>
			</activation>

			<build>
				<resources>
					<resource>
						<directory>src/main/resources</directory>
					</resource>
					<resource>
						<directory>src/main/default-resources</directory>
					</resource>
					<resource>
						<directory>src/main/java</directory>
						<excludes>
							<exclude>**/*.java</exclude>
						</excludes>
					</resource>
					<resource>
						<directory>.</directory>
						<includes>
							<include>plugin.xml</include>
						</includes>
					</resource>
				</resources>
			</build>
		</profile>

		<profile>
			<id>gae</id>
			<activation>
				<property>
					<name>gae</name>
					<value>true</value>
				</property>
			</activation>
			
			<properties>
				<finalName>${project.artifactId}-${project.version}-gae</finalName>

				<!-- SNAPSHOT -->
				<repositoryId>dev.nightlabs.org-libs-snapshots-local</repositoryId>
				<repositoryUrl>http://dev.nightlabs.org/maven-repository/libs-snapshots-local</repositoryUrl>

				<!-- RELEASE -->
				<!--
				<repositoryId>dev.nightlabs.org-libs-releases-local</repositoryId>
				<repositoryUrl>http://dev.nightlabs.org/maven-repository/libs-releases-local</repositoryUrl>
				-->
			</properties>
			
			<build>
				<resources>
					<resource>
						<directory>src/main/resources</directory>
					</resource>
					<resource>
						<directory>src/main/gae-resources</directory>
					</resource>
					<resource>
						<directory>src/main/java</directory>
						<excludes>
							<exclude>**/*.java</exclude>
						</excludes>
					</resource>
					<resource>
						<directory>.</directory>
						<includes>
							<include>plugin.xml</include>
						</includes>
					</resource>
				</resources>

				<finalName>${finalName}</finalName>

				<plugins>
					<!-- 
					<plugin>
						<artifactId>maven-dependency-plugin</artifactId>
						<executions>
							<execution>
								<id>copy-default-artifact</id>
								<phase>compile</phase>
								<goals>
									<goal>copy</goal>
								</goals>
								<inherited>false</inherited>
								<configuration>
									<artifactItems>
										<artifactItem>
											<groupId>${project.groupId}</groupId>
											<artifactId>${project.artifactId}</artifactId>
											<version>${project.version}</version>
											<type>jar</type>
											<overWrite>true</overWrite>
											<outputDirectory>${project.build.directory}</outputDirectory>
											<destFileName>${project.artifactId}-${project.version}.jar</destFileName>
										</artifactItem>
									</artifactItems>
								</configuration>
							</execution>
						</executions>
					</plugin>
					-->

<!-- doesn't work - only adds and doesn't replace :-( need detach-artifact, but doesn't exist
					<plugin>
						<groupId>org.codehaus.mojo</groupId>
						<artifactId>build-helper-maven-plugin</artifactId>
						<version>1.7</version>
						<executions>
							<execution>
								<id>attach-artifacts</id>
								<phase>package</phase>
								<goals>
									<goal>attach-artifact</goal>
								</goals>
								<configuration>
									<artifacts>
										<artifact> <!- overwrite wrong default ->
											<file>${settings.localRepository}/org/cumulus4j/${project.artifactId}/${project.version}/${project.artifactId}-${project.version}.jar</file>
											<type>jar</type>
										</artifact>
										<artifact> <!- overwrite wrong default ->
											<file>${settings.localRepository}/org/cumulus4j/${project.artifactId}/${project.version}/${project.artifactId}-${project.version}-sources.jar</file>
											<type>jar</type>
											<classifier>sources</classifier>
										</artifact>
										<artifact>
											<file>${project.build.directory}/${finalName}.jar</file>
											<type>jar</type>
											<classifier>gae</classifier>
										</artifact>
										<artifact>
											<file>${project.build.directory}/${finalName}-sources.jar</file>
											<type>jar</type>
											<classifier>gae-sources</classifier>
										</artifact>
									</artifacts>
								</configuration>
							</execution>
						</executions>
					</plugin>
-->

					<plugin>
						<artifactId>maven-install-plugin</artifactId>
						<executions>
							<execution>
								<id>gae-install-main</id>
								<phase>verify</phase> <!-- must be one phase earlier than normal - otherwise is not executed at all -->
								<goals>
									<goal>install-file</goal>
								</goals>
								<inherited>false</inherited>
								<configuration>
									<file>${project.build.directory}/${finalName}.jar</file>
									<groupId>${project.groupId}</groupId>
									<artifactId>${project.artifactId}</artifactId>
									<packaging>jar</packaging>
									<version>${cumulus4j.version}</version>
									<classifier>gae</classifier>
								</configuration>
							</execution>
							<!-- trouble with sources (gae-specific sources overwrite default artifacts - disabled!
							<execution>
								<id>gae-install-sources</id>
								<phase>verify</phase> <!- must be one phase earlier than normal - otherwise is not executed at all ->
								<goals>
									<goal>install-file</goal>
								</goals>
								<inherited>false</inherited>
								<configuration>
									<file>${project.build.directory}/${finalName}-sources.jar</file>
									<groupId>${project.groupId}</groupId>
									<artifactId>${project.artifactId}</artifactId>
									<packaging>jar</packaging>
									<version>${cumulus4j.version}</version>
									<classifier>gae-sources</classifier>
								</configuration>
							</execution>
							-->
							<execution>
								<id>default-install</id>
								<goals>
									<goal>install</goal>
								</goals>
								<inherited>false</inherited>
								<configuration>
									<skip>true</skip>
								</configuration>
							</execution>
						</executions>
					</plugin>
					
					<plugin>
						<artifactId>maven-source-plugin</artifactId>
						<configuration>
							<attach>false</attach>
						</configuration>
					</plugin>

					<plugin>
						<artifactId>maven-deploy-plugin</artifactId>
						<executions>
							<execution>
								<id>gae-deploy</id>
								<phase>deploy</phase> 
								<goals>
									<goal>deploy-file</goal>
								</goals>
								<inherited>false</inherited>
								<configuration>
									<file>${project.build.directory}/${finalName}.jar</file>
									<!-- <url>${repositoryUrl}/org/cumulus4j/org.cumulus4j.store/${cumulus4j.version}/${finalName}.jar</url> -->
									<url>${repositoryUrl}</url>
									<repositoryId>${repositoryId}</repositoryId>

									<groupId>${project.groupId}</groupId>
									<artifactId>${project.artifactId}</artifactId>
									<packaging>jar</packaging>
									<version>${cumulus4j.version}</version>
									<classifier>gae</classifier>

									<!-- MAYBE NO sources, because I didn't manage to prevent the GAE-sources from overwriting the default sources. -->
									<types>jar</types>
									<classifiers>gae-sources</classifiers>
									<files>${project.build.directory}/${finalName}-sources.jar</files>

									<generatePom>false</generatePom>
								</configuration>
							</execution>
							<execution>
								<id>default-deploy</id>
								<goals>
									<goal>deploy</goal>
								</goals>
								<inherited>false</inherited>
								<configuration>
									<skip>true</skip>
								</configuration>
							</execution>
						</executions>
					</plugin>

				</plugins>
			</build>
			
		</profile>
	</profiles>

	<build>
		<plugins>
			<!--
			<plugin>
				<artifactId>maven-clean-plugin</artifactId>
				<configuration>
					<filesets>
						<fileset>
							<directory>${project.build.directory}</directory>
							<includes>
								<include>**</include>
							</includes>
						</fileset>
						<fileset>
							<directory>${basedir}</directory>
							<includes>
								<include>*.log</include>
								<include>$jarplug.work/**</include>
							</includes>
						</fileset>
					</filesets>
				</configuration>
			</plugin>
			-->
			<plugin>
				<groupId>org.datanucleus</groupId>
				<artifactId>maven-datanucleus-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.apache.felix</groupId>
				<artifactId>maven-bundle-plugin</artifactId>
				<configuration>
					<instructions>
						<!-- We don't export anything. The API is in javax.jdo/javax.persistence, 
							as well as org.cumulus4j.annotation and org.cumulus4j.keymanager.*. -->
						<Export-Package>!${project.artifactId}</Export-Package>
						<Private-Package>${project.artifactId}.*</Private-Package>

						<!-- The required *optional* dependency onto org.cumulus4j.annotation is not added
						automatically, because there is no code reference (only referenced via plugin.xml).
						Hence, we add this dependency manually. -->
						<Import-Package>*,org.cumulus4j.annotation;resolution:=optional</Import-Package>

<!-- We currently don't have an activator.
						<Bundle-Activator>com.my.company.Activator</Bundle-Activator>
-->
					</instructions>
				</configuration>
			</plugin>

<!--
			<plugin>
				<artifactId>maven-antrun-plugin</artifactId>
				<executions>
					<execution>
						<id>gae-jar-prepare</id>
						<phase>package</phase>
						<configuration>
							<tasks>
								<echo message="Unpacking JAR" />
								<unzip src="${project.build.directory}/${project.artifactId}-${project.version}.jar" dest="${project.build.directory}/gae/" />
								<copy todir="${project.build.directory}/gae/" overwrite="true">
									<fileset dir="${basedir}/src/main/gae-resources/">
										<include name="**/*"/>
									</fileset>
								</copy>
							</tasks>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<artifactId>maven-jar-plugin</artifactId>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>jar</goal>
						</goals>
						<configuration>
							<classifier>gae</classifier>
							<classesDirectory>${project.build.directory}/gae/</classesDirectory>
							<useDefaultManifestFile>true</useDefaultManifestFile>
							<includes>
								<include>**/*</include>
							</includes>
						</configuration>
					</execution>
				</executions>
			</plugin>
-->
		</plugins>
	</build>
</project>