<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>ru.entaxy.ion.distribution</groupId>
    <artifactId>external-features-customized</artifactId>
    <version>1.12.1</version>
  </parent>
  <artifactId>assembled-replacements</artifactId>
  <packaging>pom</packaging>
  
  <properties>
  	<artemis.version>2.19.0</artemis.version>
  </properties>
  
  <profiles>
  
  	<profile>
  		<id>attach-customized-features</id>
  		<activation>
  			<file>
  				<exists>generated/list</exists>
  			</file>
  		</activation>
  		<build>
  		
  			<plugins>
  			<!--
		  		<plugin>
		
			        <groupId>org.codehaus.mojo</groupId>
			        <artifactId>build-helper-maven-plugin</artifactId>
			        <version>${build-helper-maven-plugin.version}</version>
			        
					<executions>
						<execution>
							<id>attach-addembled-features-list</id>
					        <goals>
								<goal>attach-artifact</goal>
							</goals>
							<phase>prepare-package</phase>
				            <configuration>
				                <artifacts>
				                    <artifact>
				                        <file>
				                        	generated/list
				                        </file>
				                        <type>list</type>
				                        <classifier>assembled-features</classifier>
				                    </artifact>
				                </artifacts>
				            </configuration>
						</execution>
					</executions>
		
		  		</plugin>
		  		-->
<!--
	            <plugin>
	                <groupId>org.apache.maven.plugins</groupId>
	                <artifactId>maven-dependency-plugin</artifactId>
	                <executions>
	                    <execution>
	                        <id>download-artems-configuration</id>
	                        <phase>generate-sources</phase>
	                        <goals>
	                            <goal>copy</goal>
	                        </goals>
	                        <configuration>
	                            <artifactItems>
	                                <artifactItem>
	                                    <groupId>ru.entaxy.ion.distribution</groupId>
	                                    <artifactId>entaxy-ion-support</artifactId>
	                                    <version>${project.version}</version>
	                                    <type>xml</type>
	                                    <classifier>artemis-configuration_${artemis.version}</classifier>
	                                    <overWrite>true</overWrite>
	                                    <outputDirectory>${project.build.directory}/feature-replacements/org/apache/activemq/artemis-features/${artemis.version}</outputDirectory>
	                                    <destFileName>artemis-features-${artemis.version}-artemis.entaxy.xml</destFileName>
	                                </artifactItem>
	
	                            </artifactItems>
	                        </configuration>
	                    </execution>
	                </executions>
	            </plugin>
-->

	            <plugin>
	                <groupId>org.apache.maven.plugins</groupId>
	                <artifactId>maven-antrun-plugin</artifactId>
	                <executions>
	
						<!-- load features replacemts list to property -->
	                    <execution>
	                        <id>load-features-replacements-list</id>
	                        <phase>generate-resources</phase>
	                        <goals>
	                            <goal>run</goal>
	                        </goals>
	                        <configuration>
	                            <exportAntProperties>true</exportAntProperties>
	                            <target>
	                                <taskdef resource="net/sf/antcontrib/antcontrib.properties"
	                                         classpathref="maven.plugin.classpath"/>
									
									<loadfile property="features.replacemnts.list"
	                                      srcFile="generated/list">
	                                      <filterchain>
	                                      	<linecontains>
	                                      		<contains value="/"/>
	                                  		</linecontains>
	                                      	<trim/>
	                                      </filterchain>
									</loadfile>
									<echo>
~~~~~~~~~~~~~
~~~~~~
~~~~~~ ${features.replacemnts.list}
~~~~~~
~~~~~~~~~~~~~
									
									</echo>
	                            </target>
	
	                        </configuration>
	                    </execution>
					</executions>
				</plugin>		  		

	            <plugin>
	                <groupId>com.soebes.maven.plugins</groupId>
	                <artifactId>iterator-maven-plugin</artifactId>
	                <executions>
	                    <execution>
	                        <id>iterate-assembled-features-list</id>
	                        <phase>process-resources</phase>
	                        <goals>
	                            <goal>iterator</goal>
	                        </goals>
	                        <configuration>
	                            <content>${features.replacemnts.list}</content>
	                            <delimiter>,</delimiter>
	                            <pluginExecutors>
	                                <pluginExecutor>
	                                    <plugin>
	                                        <groupId>org.apache.maven.plugins</groupId>
	                                        <artifactId>maven-antrun-plugin</artifactId>
	                                    </plugin>
	                                    <goal>run</goal>
	                                    <configuration>
	                                        <target>
	                                            <taskdef resource="net/sf/antcontrib/antcontrib.properties"
	                                                     classpathref="maven.plugin.classpath"/>
	
												<echo>
==================
=======
======= [@item@]
=======
==================
												
												</echo>
	
					                            <script language="javascript" classpath="${maven.plugin.classpath}">
					                              currentRepo = '@item@';
					                              if (currentRepo != ''){
													  arr = currentRepo.split('/');
													  project.setProperty('replacement.feature.groupId', arr[0]);
													  project.setProperty('replacement.feature.artifactId', arr[1]);
													  project.setProperty('replacement.feature.version', arr[2]);
													  project.setProperty('replacement.feature.type', arr[3]);
													  project.setProperty('replacement.feature.classifier', arr[4]);
													  
													  originalVersion = arr[2].replace('-ENTAXY', '');
													  
													  project.setProperty('replacement.feature.targetPath', 
													  	arr[0].replaceAll('\\.', '/') + '/' + arr[1] + '/' + originalVersion);
													  project.setProperty('replacement.feature.targetName', arr[1] + '-' + originalVersion + '-' + arr[4] + '.' + arr[3]);
													  project.setProperty('replacement.feature.skip', 'false');													  
												  } else {
														project.setProperty('replacement.feature.skip', 'true');
												  }
											    </script>
	
	                                            <property name="item.current">@item@</property>
	                                            <basename property="filename.full" file="${item.current}"
	                                                      suffix=".xml"/>
	                                            <echo file="${project.build.directory}/temp/features.replacements.properties">
replacement.feature.groupId=${replacement.feature.groupId}
replacement.feature.artifactId=${replacement.feature.artifactId}
replacement.feature.version=${replacement.feature.version}
replacement.feature.type=${replacement.feature.type}
replacement.feature.classifier=${replacement.feature.classifier}
replacement.feature.targetPath=${replacement.feature.targetPath}
replacement.feature.targetName=${replacement.feature.targetName}
	                                            </echo>
	                                        </target>
	                                    </configuration>
	                                </pluginExecutor>
	                                <pluginExecutor>
	                                    <plugin>
	                                        <groupId>org.codehaus.mojo</groupId>
	                                        <artifactId>properties-maven-plugin</artifactId>
	                                    </plugin>
	                                    <goal>read-project-properties</goal>
	                                    <configuration>
	                                        <files>
	                                            <file>${project.build.directory}/temp/features.replacements.properties</file>
	                                        </files>
	                                    </configuration>
	                                </pluginExecutor>
	
	                                <pluginExecutor>
	                                    <plugin>
							                <groupId>org.apache.maven.plugins</groupId>
							                <artifactId>maven-dependency-plugin</artifactId>
	                                        <version>${maven-dependency-plugin.version}</version>
	                                    </plugin>
			                            <goal>copy</goal>
	                                    <configuration>
	                                    	<skip>${replacement.feature.skip}</skip>
				                            <artifactItems>
				                                <artifactItem>
				                                    <groupId>${replacement.feature.groupId}</groupId>
				                                    <artifactId>${replacement.feature.artifactId}</artifactId>
				                                    <version>${replacement.feature.version}</version>
				                                    <type>${replacement.feature.type}</type>
				                                    <classifier>${replacement.feature.classifier}</classifier>
				                                    <overWrite>true</overWrite>
				                                    <outputDirectory>${project.build.directory}/feature-replacements/${replacement.feature.targetPath}</outputDirectory>
				                                    <destFileName>${replacement.feature.targetName}</destFileName>
				                                </artifactItem>
				
				                            </artifactItems>
	                                    </configuration>
	                                </pluginExecutor>
	                            </pluginExecutors>
	                        </configuration>
	                    </execution>
	                </executions>
	            </plugin>

                <plugin>
                    <!-- NOTE: We don't need a groupId specification because the group is
                         org.apache.maven.plugins ...which is assumed by default.
                     -->
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.3.0</version>
                    <executions>
                        <execution>
                            <id>assebmly</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                            <configuration>
                                <descriptors>
                                    <descriptor>src/assembly/descriptor.xml
                                    </descriptor>
                                </descriptors>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
		  		
		  		
	  		</plugins>
	  	</build>
  	
  	</profile>
  	
  </profiles>
  
</project>
