[560901] Provide improved support for conforming to the incubation
branding requirements

Provide generator support for predicting the site URIs for the upcoming
M, RC, or R build.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=560901
diff --git a/plugins/org.eclipse.oomph.setup.installer/ProductCatalogGenerator.launch b/plugins/org.eclipse.oomph.setup.installer/ProductCatalogGenerator.launch
index 00c09c7..2d9c288 100644
--- a/plugins/org.eclipse.oomph.setup.installer/ProductCatalogGenerator.launch
+++ b/plugins/org.eclipse.oomph.setup.installer/ProductCatalogGenerator.launch
@@ -18,7 +18,7 @@
 <stringAttribute key="location" value="${workspace_loc}/../ws-product-catalog-generator"/>
 <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
 <stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog &#13;&#10;-outputLocation ${file_uri:${resource_loc:/setups/org.eclipse.products.setup}}&#13;&#10;-xstaging 2020-03  http://download.eclipse.org/technology/epp/packages/2020-03/RC1 http://download.eclipse.org/releases/2020-03/202003061000&#13;&#10;-useComposite 2020-03&#13;&#10;-xlatestReleased&#13;&#10;-xbrandingNotification"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog &#13;&#10;-outputLocation ${file_uri:${resource_loc:/setups/org.eclipse.products.setup}}&#13;&#10;-xstaging 2020-03  http://download.eclipse.org/technology/epp/packages/2020-03/RC1 http://download.eclipse.org/releases/2020-03/202003061000&#13;&#10;-useComposite 2020-03&#13;&#10;-xlatestReleased&#13;&#10;-xbrandingNotification&#13;&#10;-xsiteURI https://www.eclipse.org/downloads/packages/release/2020-03/r"/>
 <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
 <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Declipse.p2.mirrors=false&#13;&#10;-Dxorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient45&#13;&#10;-Doomph.p2.repository.retry=2&#13;&#10;-Dxorg.eclipse.ecf.core.util.traceAll=true&#13;&#10;-Dxorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog&#13;&#10;-Dxorg.apache.commons.logging.simplelog.showdatetime=true&#13;&#10;-Dxorg.apache.commons.logging.simplelog.log.org.apache.http=DEBUG&#13;&#10;-Dxorg.apache.commons.logging.simplelog.log.org.apache.http.wire=ERROR"/>
 <stringAttribute key="pde.version" value="3.3"/>
diff --git a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/ProductCatalogGenerator.java b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/ProductCatalogGenerator.java
index 50d5c3a..c4d09f8 100644
--- a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/ProductCatalogGenerator.java
+++ b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/ProductCatalogGenerator.java
@@ -169,6 +169,8 @@
 
   private URI stagingEclipePlatformLocation;
 
+  private URI eppSiteURI;
+
   private final Map<String, Map<URI, Map<String, URI>>> sites = new LinkedHashMap<String, Map<URI, Map<String, URI>>>();
 
   private final IMetadataRepositoryManager manager = getMetadataRepositoryManager();
@@ -235,6 +237,10 @@
         {
           brandingNotification = true;
         }
+        else if ("-siteURI".equals(option))
+        {
+          eppSiteURI = URI.createURI(arguments[++i]);
+        }
       }
     }
 
@@ -1688,12 +1694,12 @@
       addImageURI(product, staticIconURL);
     }
 
-    String[] trains = getTrains();
+    final String[] trains = getTrains();
     for (int i = trains.length; i >= 0; --i)
     {
       InputStream in = null;
 
-      String branch = i == trains.length ? "master" : trains[i].toUpperCase();
+      final String branch = i == trains.length ? "master" : trains[i].toUpperCase();
       String url = "https://git.eclipse.org/c/epp/org.eclipse.epp.packages.git/plain/packages/org.eclipse.epp.package." + name + ".feature/epp.website.xml"
           + "?h=" + branch;
       try
@@ -1726,6 +1732,39 @@
               String packageName = element.getAttribute("packageName");
               if (packageName != null)
               {
+                // If we are generating for a site that does not yet exist and are on the master branch.
+                if (eppSiteURI != null && "master".equals(branch))
+                {
+                  // Compute the site URL from the package name.
+                  URI siteURI = URI
+                      .createURI(eppSiteURI + "/" + packageName.replaceAll("[\\W&&[^ ]]", "").replace(" for ", " ").replaceAll(" +", "-").toLowerCase());
+                  String key = getKey(packageName);
+                  String train = trains[trains.length - 1];
+                  synchronized (sites)
+                  {
+                    Map<URI, Map<String, URI>> releaseLocations = sites.get(train);
+                    if (releaseLocations == null)
+                    {
+                      // Nothing yet for this train, so create it.
+                      releaseLocations = new LinkedHashMap<URI, Map<String, URI>>();
+                      sites.put(train, releaseLocations);
+                    }
+
+                    Map<String, URI> map = releaseLocations.get(eppSiteURI);
+                    if (map == null)
+                    {
+                      // Clear any existing map and create a new one for this EPP site.
+                      releaseLocations.clear();
+                      map = new LinkedHashMap<String, URI>();
+                      releaseLocations.put(eppSiteURI, map);
+                      map.put(key, siteURI);
+                    }
+
+                    // Replace the site for this key.
+                    map.put(key, siteURI);
+                  }
+                }
+
                 setProductLabel(product, packageName);
               }
             }