Bug 386377 - Native launcher not built during first build

Change where the build.xml is invoked for building the native parts
during a maven build.

Previously, because the build.xml was invoked from the feature, and
the reactor orders the build of the native fragments *before* the
feature, it means the fragments do not include the freshly built
native parts.

Invoke it instead from the fragments themselves by moving the
profile to the launcher-binary-parent pom. This way the native
parts are guaranteed to be built in time to be included in the
fragments.

Change-Id: I0f9004cb10427cdd6a84bdf94cbbf10263f5267f
Signed-off-by: Mat Booth <mat.booth@redhat.com>
diff --git a/features/org.eclipse.equinox.executable.feature/library/cocoa/build.xml b/features/org.eclipse.equinox.executable.feature/library/cocoa/build.xml
index 9561ac5..f574230 100644
--- a/features/org.eclipse.equinox.executable.feature/library/cocoa/build.xml
+++ b/features/org.eclipse.equinox.executable.feature/library/cocoa/build.xml
@@ -1,58 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
-
 <project default="build_eclipse" basedir=".">
 
-<target name="build_eclipse">
+<condition property="build-natives">
+	<matches pattern="^${ws}.${os}.${arch}$" string="${native}"/>
+</condition>
 
-	<loadresource property="WS">
-    <string value="${native}"/>
-    <filterchain>
-      <tokenfilter>
-				<replaceregex pattern="([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)" replace="\1"/>
-      </tokenfilter>
-    </filterchain>
-  </loadresource>
-
-	<condition property="WS_ARG" value="-ws ${WS}" else="">
-	    <isset property="native" />
-	</condition>
-
-  <loadresource property="OS">
-    <string value="${native}"/>
-    <filterchain>
-      <tokenfilter>
-				<replaceregex pattern="([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)" replace="\2"/>
-      </tokenfilter>
-    </filterchain>
-  </loadresource>
-
-	<condition property="OS_ARG" value="-os ${OS}" else="">
-	    <isset property="native" />
-	</condition>
-
- <loadresource property="ARCH">
-    <string value="${native}"/>
-    <filterchain>
-      <tokenfilter>
-        <replaceregex pattern="([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)" replace="\3"/>
-      </tokenfilter>
-    </filterchain>
-  </loadresource>
-
-	<condition property="ARCH_ARG" value="-arch ${ARCH}" else="">
-	    <isset property="native" />
-	</condition>
-
+<target name="build_eclipse" if="build-natives">
 	<exec dir="." executable="sh">
 		<arg line="${basedir}/build.sh"/>
 		<arg line="install"/>
-		<arg line="${WS_ARG}"/>
-		<arg line="${OS_ARG}"/>
-		<arg line="${ARCH_ARG}"/>
+		<arg line="-ws ${ws}"/>
+		<arg line="-os ${os}"/>
+		<arg line="-arch ${arch}"/>
 	</exec>
 </target>
 
-<target name="clean">
+<target name="clean" if="build-natives">
 	<tstamp/>
 	<exec dir="." executable="sh">
 		<arg line="${basedir}/build.sh"/>
diff --git a/features/org.eclipse.equinox.executable.feature/library/gtk/build.xml b/features/org.eclipse.equinox.executable.feature/library/gtk/build.xml
index f485479..f574230 100644
--- a/features/org.eclipse.equinox.executable.feature/library/gtk/build.xml
+++ b/features/org.eclipse.equinox.executable.feature/library/gtk/build.xml
@@ -1,23 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
-
 <project default="build_eclipse" basedir=".">
 
-<target name="build_eclipse">
+<condition property="build-natives">
+	<matches pattern="^${ws}.${os}.${arch}$" string="${native}"/>
+</condition>
+
+<target name="build_eclipse" if="build-natives">
 	<exec dir="." executable="sh">
 		<arg line="${basedir}/build.sh"/>
 		<arg line="install"/>
+		<arg line="-ws ${ws}"/>
+		<arg line="-os ${os}"/>
+		<arg line="-arch ${arch}"/>
 	</exec>
 </target>
 
-<target name="build_eclipse_ppc">
-	<exec dir="." executable="sh">
-		<env key="MODEL" value="ppc"/>
-		<arg line="${basedir}/build.sh"/>
-		<arg line="install"/>
-	</exec>
-</target>
-	
-<target name="clean">
+<target name="clean" if="build-natives">
 	<tstamp/>
 	<exec dir="." executable="sh">
 		<arg line="${basedir}/build.sh"/>
@@ -25,4 +23,4 @@
 	</exec>
 </target>
 
-</project>
\ No newline at end of file
+</project>
diff --git a/features/org.eclipse.equinox.executable.feature/library/win32/build.xml b/features/org.eclipse.equinox.executable.feature/library/win32/build.xml
index 056b859..f9af591 100644
--- a/features/org.eclipse.equinox.executable.feature/library/win32/build.xml
+++ b/features/org.eclipse.equinox.executable.feature/library/win32/build.xml
@@ -1,18 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
-
 <project default="build_eclipse" basedir=".">
 
-<target name="build_eclipse">
+<condition property="build-natives">
+	<matches pattern="^${ws}.${os}.${arch}$" string="${native}"/>
+</condition>
+
+<target name="build_eclipse" if="build-natives">
 	<exec dir="." executable="${basedir}\build.bat">
 		<arg line="install"/>
 	</exec>
 </target>
 
-<target name="clean">
+<target name="clean" if="build-natives">
 	<tstamp/>
 	<exec dir="." executable="${basedir}\build.bat">
 		<arg line="clean"/>
 	</exec>
 </target>
 
-</project>
\ No newline at end of file
+</project>
diff --git a/features/org.eclipse.equinox.executable.feature/pom.xml b/features/org.eclipse.equinox.executable.feature/pom.xml
index 66c4744..e56be01 100644
--- a/features/org.eclipse.equinox.executable.feature/pom.xml
+++ b/features/org.eclipse.equinox.executable.feature/pom.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-  Copyright (c) 2012, 2014 Eclipse Foundation.
+  Copyright (c) 2012, 2018 Eclipse Foundation and others.
   All rights reserved. This program and the accompanying materials
   are made available under the terms of the Eclipse Distribution License v1.0
   which accompanies this distribution, and is available at
@@ -98,384 +98,6 @@
 
   <profiles>
     <profile>
-      <id>build-native-launchers-gtk.linux.x86_64</id>
-      <activation>
-        <property>
-          <name>native</name>
-          <value>gtk.linux.x86_64</value>
-        </property>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-antrun-plugin</artifactId>
-            <executions>
-              <execution>
-                <id>compile-executable-natives</id>
-                <phase>generate-resources</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/gtk/" target="build_eclipse"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-              <execution>
-                <id>clean-executable-natives</id>
-                <phase>clean</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/gtk/" target="clean"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
-      <id>build-native-launchers-gtk.linux.x86</id>
-      <activation>
-        <property>
-          <name>native</name>
-          <value>gtk.linux.x86</value>
-        </property>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-antrun-plugin</artifactId>
-            <executions>
-              <execution>
-                <id>compile-executable-natives</id>
-                <phase>generate-resources</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/gtk/" target="build_eclipse"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-              <execution>
-                <id>clean-executable-natives</id>
-                <phase>clean</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/gtk/" target="clean"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
-      <id>build-native-launchers-gtk.linux.ppc64le</id>
-      <activation>
-        <property>
-          <name>native</name>
-          <value>gtk.linux.ppc64le</value>
-        </property>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-antrun-plugin</artifactId>
-            <executions>
-              <execution>
-                <id>compile-executable-natives</id>
-                <phase>generate-resources</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/gtk/" target="build_eclipse"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-              <execution>
-                <id>clean-executable-natives</id>
-                <phase>clean</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/gtk/" target="clean"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
-      <id>build-native-launchers-gtk.solaris.x86_64</id>
-      <activation>
-        <property>
-          <name>native</name>
-          <value>gtk.solaris.x86_64</value>
-        </property>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-antrun-plugin</artifactId>
-            <executions>
-              <execution>
-                <id>compile-executable-natives</id>
-                <phase>generate-resources</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/gtk/" target="build_eclipse"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-              <execution>
-                <id>clean-executable-natives</id>
-                <phase>clean</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/gtk/" target="clean"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
-      <id>build-native-launchers-gtk.linux.arm</id>
-      <activation>
-        <property>
-          <name>native</name>
-          <value>gtk.linux.arm</value>
-        </property>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-antrun-plugin</artifactId>
-            <executions>
-              <execution>
-                <id>compile-executable-natives</id>
-                <phase>generate-resources</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/gtk/" target="build_eclipse"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-              <execution>
-                <id>clean-executable-natives</id>
-                <phase>clean</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/gtk/" target="clean"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
-      <id>build-native-launchers-gtk.linux.aarch64</id>
-      <activation>
-        <property>
-          <name>native</name>
-          <value>gtk.linux.aarch64</value>
-        </property>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-antrun-plugin</artifactId>
-            <executions>
-              <execution>
-                <id>compile-executable-natives</id>
-                <phase>generate-resources</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/gtk/" target="build_eclipse"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-              <execution>
-                <id>clean-executable-natives</id>
-                <phase>clean</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/gtk/" target="clean"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
-      <id>build-native-launchers-win32.win32.x86_64</id>
-      <activation>
-        <property>
-          <name>native</name>
-          <value>win32.win32.x86_64</value>
-        </property>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-antrun-plugin</artifactId>
-            <executions>
-              <execution>
-                <id>compile-executable-natives</id>
-                <phase>generate-resources</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/win32/" target="build_eclipse"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-              <execution>
-                <id>clean-executable-natives</id>
-                <phase>clean</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/win32/" target="clean"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
-      <id>build-native-launchers-win32.win32.x86</id>
-      <activation>
-        <property>
-          <name>native</name>
-          <value>win32.win32.x86</value>
-        </property>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-antrun-plugin</artifactId>
-            <executions>
-              <execution>
-                <id>compile-executable-natives</id>
-                <phase>generate-resources</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/win32/" target="build_eclipse"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-              <execution>
-                <id>clean-executable-natives</id>
-                <phase>clean</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/win32/" target="clean"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
-      <id>build-native-launchers-cocoa.macosx.x86_64</id>
-      <activation>
-        <property>
-          <name>native</name>
-          <value>cocoa.macosx.x86_64</value>
-        </property>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-antrun-plugin</artifactId>
-            <executions>
-              <execution>
-                <id>compile-executable-natives</id>
-                <phase>generate-resources</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/cocoa/" target="build_eclipse"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-              <execution>
-                <id>clean-executable-natives</id>
-                <phase>clean</phase>
-                <configuration>
-                  <target>
-                    <ant antfile="build.xml" dir="library/cocoa/" target="clean"/>
-                  </target>
-                </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
       <id>assemble-launchers</id>
       <activation>
         <property>
diff --git a/launcher-binary-parent/pom.xml b/launcher-binary-parent/pom.xml
index f5edf73..4b5e759 100644
--- a/launcher-binary-parent/pom.xml
+++ b/launcher-binary-parent/pom.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-  Copyright (c) 2012 Eclipse Foundation.
+  Copyright (c) 2012, 2018 Eclipse Foundation and others.
   All rights reserved. This program and the accompanying materials
   are made available under the terms of the Eclipse Distribution License v1.0
   which accompanies this distribution, and is available at
@@ -79,4 +79,54 @@
       </plugin>
     </plugins>
   </build>
+
+  <profiles>
+    <profile>
+      <!--
+        This profile is enabled when the "native" system property is defined.
+        If the "ws.os.arch" triplet given in the "native" system property matches
+        the "ws", "os" and "arch" properties set by the current fragment, then the
+        ant script will trigger the build of the native parts for that fragment.
+      -->
+      <id>build-natives</id>
+      <activation>
+        <property>
+          <name>native</name>
+        </property>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <artifactId>maven-antrun-plugin</artifactId>
+            <executions>
+              <execution>
+                <id>compile-launcher-natives</id>
+                <phase>generate-resources</phase>
+                <configuration>
+                  <target>
+                    <ant dir="../../features/org.eclipse.equinox.executable.feature/library/${ws}/" target="build_eclipse"/>
+                  </target>
+                </configuration>
+                <goals>
+                  <goal>run</goal>
+                </goals>
+              </execution>
+              <execution>
+                <id>clean-launcher-natives</id>
+                <phase>clean</phase>
+                <configuration>
+                  <target>
+                    <ant dir="../../features/org.eclipse.equinox.executable.feature/library/${ws}/" target="clean"/>
+                  </target>
+                </configuration>
+                <goals>
+                  <goal>run</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
 </project>