<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>

	<parent>
		<artifactId>maven-parent</artifactId>
		<groupId>org.gcube.tools</groupId>
		<version>1.0.0</version>
		<relativePath />
	</parent>

	<artifactId>maven-service-parent</artifactId>
	<packaging>pom</packaging>

	<name>Service Parent POM</name>
	<description>A parent POM for gCube Services with a mono-module project structure</description>

	<developers>
		<developer>
			<name>Fabio Simeoni</name>
		</developer>
	</developers>

	<properties>
		<!-- default source folder for generated stubs -->
		<stubSourceDirectory>${basedir}/target/generated-sources/stubs</stubSourceDirectory>
	</properties>

	<build>

		<pluginManagement>

			<plugins>

				<!-- pre-configures stub compilation (exclude other sources) -->
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-compiler-plugin</artifactId>
					<executions>
						<execution>
							<id>default-compile</id>
							<goals>
								<goal>compile</goal>
							</goals>
							<configuration>
								<includes>
									<include>**/stubs/**</include>
								</includes>
							</configuration>
						</execution>
					</executions>
				</plugin>

				<!-- pre-configures stub packaging  -->
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-jar-plugin</artifactId>
					<executions>
						<execution>
							<id>default-jar</id>
							<goals>
								<goal>jar</goal>
							</goals>
							<configuration>
								<classifier>stubs</classifier>
							</configuration>
						</execution>
					</executions>
				</plugin>

			</plugins>

		</pluginManagement>


		<plugins>

			<!-- Adds source folder with generated stubs. -->
			
			<!-- NOTE: this operation will be carried out by the service-plugin too, 
				but the plugin does not have yet an m2e connector to notify m2e that 
				a new source folder has been added. the build-helper plugin does, so by doing 
				it redundantly here we keep Eclipse in line without manual intervention. -->

			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>build-helper-maven-plugin</artifactId>
				<version>1.7</version>
				<executions>
					<execution>
						<id>add-source</id>
						<phase>process-sources</phase>
						<goals>
							<goal>add-source</goal>
						</goals>
						<configuration>
							<sources>
								<source>${stubSourceDirectory}</source>
							</sources>
						</configuration>
					</execution>
				</executions>
			</plugin>


			<!-- adds @SuppressedWarnings to generated stub classes -->

			<plugin>
				<groupId>com.google.code.maven-replacer-plugin</groupId>
				<artifactId>maven-replacer-plugin</artifactId>
				<version>1.3.9</version>
				<executions>	
					<execution>
						<phase>process-sources</phase>
						<goals>
							<goal>replace</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<quiet>true</quiet>
					<includes>
						<include>**/stubs/**/**/*.java</include>
					</includes>

					<regex>true</regex>
					<regexFlags>
						<regexFlag>MULTILINE</regexFlag>
					</regexFlags>

					<replacements>
						<replacement>
							<token>^public class</token>
							<value>@SuppressWarnings("all") public class</value>
						</replacement>
					</replacements>
				</configuration>
			</plugin>

		</plugins>
	</build>



	<!-- adds service-specific build logic -->
	<profiles>
		<profile>
			<id>full</id>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
			<build>

				<pluginManagement>
					<plugins>

						<!-- pre-configures source packaging -->
						<plugin>
							<groupId>org.apache.maven.plugins</groupId>
							<artifactId>maven-source-plugin</artifactId>
							<configuration>
								<excludes>
									<excludes>**/stubs/**</excludes>
								</excludes>
							</configuration>
						</plugin>

						<!-- pre-configures javadoc generation and packaging -->
						<plugin>
							<groupId>org.apache.maven.plugins</groupId>
							<artifactId>maven-javadoc-plugin</artifactId>
							<configuration>
								<excludePackageNames>**.stubs.**</excludePackageNames>
							</configuration>
						</plugin>

					</plugins>
				</pluginManagement>

				<plugins>
					<!-- pre-configures source compilation -->
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-compiler-plugin</artifactId>
						<version>2.3.2</version>
						<executions>
							<execution>
								<id>compile-service</id>
								<goals>
									<goal>compile</goal>
								</goals>
							</execution>
						</executions>
					</plugin>

					<!-- pre-configures source packaging -->
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-jar-plugin</artifactId>
						<version>2.3.1</version>
						<executions>
							<execution>
								<id>service-jar</id>
								<goals>
									<goal>jar</goal>
								</goals>
								<configuration>
									<excludes>
										<excludes>**/stubs/**</excludes>
									</excludes>
								</configuration>
							</execution>
						</executions>
					</plugin>

				</plugins>

			</build>
		</profile>

		<profile>
			<id>stubs</id>
			<build>
				<pluginManagement>
					<plugins>

						<!-- disables-configures source compilation -->
						<plugin>
							<groupId>org.apache.maven.plugins</groupId>
							<artifactId>maven-compiler-plugin</artifactId>
							<executions>
								<execution>
									<id>default-testCompile</id>
									<phase>none</phase>
								</execution>
							</executions>
						</plugin>
					</plugins>

				</pluginManagement>
			</build>
		</profile>

	</profiles>

</project>