Bug 562908 - Populate the JustJ Git clones with initial content

Don't declare the osgi.ee capabilities in the MANIFEST.MF but instead in
the p2.inf.  Also declare the java.package capabilities in the p2.inf.
diff --git a/plugins/org.eclipse.justj.codegen/src/org/eclipse/justj/codegen/model/util/Generator.java b/plugins/org.eclipse.justj.codegen/src/org/eclipse/justj/codegen/model/util/Generator.java
index ddff2ff..dfb4da1 100644
--- a/plugins/org.eclipse.justj.codegen/src/org/eclipse/justj/codegen/model/util/Generator.java
+++ b/plugins/org.eclipse.justj.codegen/src/org/eclipse/justj/codegen/model/util/Generator.java
@@ -28,6 +28,7 @@
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.TreeSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -55,6 +56,7 @@
 import org.eclipse.justj.codegen.model.Touchpoint;
 import org.eclipse.justj.codegen.model.Variant;
 import org.eclipse.justj.codegen.model.util.Generator.Description.Descriptor;
+import org.osgi.framework.Constants;
 
 
 public class Generator
@@ -608,6 +610,28 @@
     return result;
   }
 
+  public static Set<String> getSystemPackages(Variant variant)
+  {
+    String systemPackages = ModelUtil.getAnnotation(variant, ModelUtil.MODEL_PROPERTIES_ANNOTATION_URI, Constants.FRAMEWORK_SYSTEMPACKAGES);
+    if (systemPackages == null)
+    {
+      systemPackages = ModelUtil.getAnnotation(variant.getJVM(), ModelUtil.MODEL_PROPERTIES_ANNOTATION_URI, Constants.FRAMEWORK_SYSTEMPACKAGES);
+    }
+
+    Set<String> result = new TreeSet<>();
+    if (systemPackages != null)
+    {
+      for (String systemPackage : systemPackages.split("\\s*,\\s*"))
+      {
+        if (!systemPackage.isEmpty())
+        {
+          result.add(systemPackage);
+        }
+      }
+    }
+    return result;
+  }
+
   public static String getModelXMLAsPropertyValue(EObject eObject, String nl)
   {
     try (StringWriter stringWriter = new StringWriter(); WriteableOutputStream writeableOutputStream = new URIConverter.WriteableOutputStream(stringWriter, "UTF-8"))
diff --git a/plugins/org.eclipse.justj.codegen/src/org/eclipse/justj/codegen/templates/fragment/Manifest.java b/plugins/org.eclipse.justj.codegen/src/org/eclipse/justj/codegen/templates/fragment/Manifest.java
index 49a0e89..99afef8 100644
--- a/plugins/org.eclipse.justj.codegen/src/org/eclipse/justj/codegen/templates/fragment/Manifest.java
+++ b/plugins/org.eclipse.justj.codegen/src/org/eclipse/justj/codegen/templates/fragment/Manifest.java
@@ -1,8 +1,5 @@
 package org.eclipse.justj.codegen.templates.fragment;
 
-import java.util.Iterator;
-import java.util.Map.Entry;
-import java.util.Set;
 import org.eclipse.justj.codegen.model.*;
 import org.eclipse.justj.codegen.model.util.Generator;
 
@@ -20,33 +17,26 @@
   public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
   protected static final String _1 = ") (osgi.arch=";
   protected static final String _2 = "))";
-  protected static final String _3 = ",";
-  protected static final String _4 = ".qualifier";
-  protected static final String _5 = ";bundle-version=\"";
-  protected static final String _6 = ";singleton:=true";
-  protected static final String _7 = "Automatic-Module-Name: ";
-  protected static final String _8 = "Bundle-Localization: fragment";
-  protected static final String _9 = "Bundle-ManifestVersion: 2";
-  protected static final String _10 = "Bundle-Name: %pluginName";
-  protected static final String _11 = "Bundle-SymbolicName: ";
-  protected static final String _12 = "Bundle-Vendor: %providerName";
-  protected static final String _13 = "Bundle-Version: ";
-  protected static final String _14 = "Eclipse-BundleShape: dir";
-  protected static final String _15 = "Eclipse-PlatformFilter: (& (osgi.os=";
-  protected static final String _16 = "Fragment-Host: ";
-  protected static final String _17 = "Manifest-Version: 1.0";
-  protected static final String _18 = "Provide-Capability: ";
-  protected static final String _19 = "\"";
-  protected static final String _20 = "\";version:Version=\"";
-  protected static final String _21 = "osgi.ee;osgi.ee=\"";
-  protected final String NL_1 = NL + " ";
-  protected final String _22 = _17 + NL + _9 + NL + _11;
-  protected final String _23 = _6 + NL + _13;
-  protected final String _24 = _4 + NL + _8 + NL + _10 + NL + _12 + NL + _16;
-  protected final String _25 = _19 + NL + _14 + NL + _15;
-  protected final String _26 = _2 + NL + _7;
-  protected final String _27 = NL + _18;
-  protected final String _28 = NL_1 + _21;
+  protected static final String _3 = ".qualifier";
+  protected static final String _4 = ";bundle-version=\"";
+  protected static final String _5 = ";singleton:=true";
+  protected static final String _6 = "Automatic-Module-Name: ";
+  protected static final String _7 = "Bundle-Localization: fragment";
+  protected static final String _8 = "Bundle-ManifestVersion: 2";
+  protected static final String _9 = "Bundle-Name: %pluginName";
+  protected static final String _10 = "Bundle-SymbolicName: ";
+  protected static final String _11 = "Bundle-Vendor: %providerName";
+  protected static final String _12 = "Bundle-Version: ";
+  protected static final String _13 = "Eclipse-BundleShape: dir";
+  protected static final String _14 = "Eclipse-PlatformFilter: (& (osgi.os=";
+  protected static final String _15 = "Fragment-Host: ";
+  protected static final String _16 = "Manifest-Version: 1.0";
+  protected static final String _17 = "\"";
+  protected final String _18 = _16 + NL + _8 + NL + _10;
+  protected final String _19 = _5 + NL + _12;
+  protected final String _20 = _3 + NL + _7 + NL + _9 + NL + _11 + NL + _15;
+  protected final String _21 = _17 + NL + _13 + NL + _14;
+  protected final String _22 = _2 + NL + _6;
 
   public String generate(Object argument)
   {
@@ -61,36 +51,20 @@
   String hostName = modelName + '.' + jvmName;
   String fullName = hostName + '.' + os + '.' + arch;
   String version = jvm.getVersion();
-    builder.append(_22);
+    builder.append(_18);
     builder.append(fullName);
-    builder.append(_23);
+    builder.append(_19);
     builder.append(version);
-    builder.append(_24);
+    builder.append(_20);
     builder.append(hostName);
-    builder.append(_5);
+    builder.append(_4);
     builder.append(Generator.getVersionRange(version));
-    builder.append(_25);
+    builder.append(_21);
     builder.append(os);
     builder.append(_1);
     builder.append(arch);
-    builder.append(_26);
+    builder.append(_22);
     builder.append(fullName);
-    builder.append(_27);
-    
-    for (Iterator<Entry<String, Set<String>>> it = Generator.getEECapabilities(version).entrySet().iterator(); it.hasNext();) {
-    Entry<String, Set<String>> entry = it.next();
-    for (Iterator<String> it2 = entry.getValue().iterator(); it2.hasNext();) {
-      String eeVersion = it2.next();
-    builder.append(_28);
-    builder.append(entry.getKey());
-    builder.append(_20);
-    builder.append(eeVersion);
-    builder.append(_19);
-    if (it.hasNext() || it2.hasNext()) {
-    builder.append(_3);
-    }
-    }
-    }
     builder.append(NL);
     return builder.toString();
   }
diff --git a/plugins/org.eclipse.justj.codegen/src/org/eclipse/justj/codegen/templates/fragment/P2Inf.java b/plugins/org.eclipse.justj.codegen/src/org/eclipse/justj/codegen/templates/fragment/P2Inf.java
index 136f923..7fd77ac 100644
--- a/plugins/org.eclipse.justj.codegen/src/org/eclipse/justj/codegen/templates/fragment/P2Inf.java
+++ b/plugins/org.eclipse.justj.codegen/src/org/eclipse/justj/codegen/templates/fragment/P2Inf.java
@@ -29,42 +29,86 @@
   public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
   protected static final String _1 = " = \\";
   protected static final String _2 = "#";
-  protected static final String _3 = ";";
-  protected static final String _4 = "\\";
-  protected static final String _5 = "instructions.";
-  protected static final String _6 = "properties.0.name = org.eclipse.justj.model";
-  protected static final String _7 = "properties.0.value = ";
+  protected static final String _3 = ".name = ";
+  protected static final String _4 = ".namespace = java.package";
+  protected static final String _5 = ".namespace = osgi.ee";
+  protected static final String _6 = ".version = ";
+  protected static final String _7 = ".version = 0.0.0";
+  protected static final String _8 = ";";
+  protected static final String _9 = "\\";
+  protected static final String _10 = "instructions.";
+  protected static final String _11 = "properties.0.name = org.eclipse.justj.model";
+  protected static final String _12 = "properties.0.value = ";
+  protected static final String _13 = "provides.";
   protected final String NL_1 = NL + "  ";
-  protected final String _8 = "";
-  protected final String _9 = NL + _2 + NL;
-  protected final String _10 = NL + _5;
-  protected final String _11 = NL + _6 + NL + _7;
+  protected final String _14 = "";
+  protected final String _15 = NL + _2 + NL;
+  protected final String _16 = NL + _10;
+  protected final String _17 = NL + _13;
+  protected final String _18 = _5 + NL + _13;
+  protected final String _19 = _4 + NL + _13;
+  protected final String _20 = _7 + NL;
+  protected final String _21 = NL + _11 + NL + _12;
 
   public String generate(Object argument)
   {
     final StringBuilder builder = new StringBuilder();
     Variant variant = (Variant)argument;
-    builder.append(_8);
+  JVM jvm = variant.getJVM();
+  String version = jvm.getVersion();
+    builder.append(_14);
     builder.append(org.eclipse.justj.codegen.model.util.Generator.getCopyright(argument, "# ", NL));
-    builder.append(_9);
+    builder.append(_15);
     Map<String, Set<String>> touchpoints = Generator.getTouchpoints(variant);
   for (Map.Entry<String, Set<String>> entry : touchpoints.entrySet()) {
     String phase = entry.getKey();
-    builder.append(_10);
+    builder.append(_16);
     builder.append(phase);
     builder.append(_1);
     for (Iterator<String> it = entry.getValue().iterator(); it.hasNext();) {
       String instruction = it.next();
     builder.append(NL_1);
     builder.append(instruction);
-    builder.append(_3);
+    builder.append(_8);
     if (it.hasNext()) {
-    builder.append(_4);
+    builder.append(_9);
     }
     }
     builder.append(NL);
     }
-    builder.append(_11);
+    int propertyCount = 0;
+  for (Map.Entry<String, Set<String>> entry : Generator.getEECapabilities(version).entrySet()) {
+    String eeName = entry.getKey();
+    Set<String> versions = entry.getValue();
+    for (String eeVersion : versions) {
+      int capabilityNumber = propertyCount++;
+    builder.append(_17);
+    builder.append(capabilityNumber);
+    builder.append(_18);
+    builder.append(capabilityNumber);
+    builder.append(_3);
+    builder.append(eeName);
+    builder.append(_17);
+    builder.append(capabilityNumber);
+    builder.append(_6);
+    builder.append(eeVersion);
+    builder.append(NL);
+    }
+    }
+    Set<String> systemPackages = Generator.getSystemPackages(variant);
+  for (String systemPackage : systemPackages) {
+    int capabilityNumber = propertyCount++;
+    builder.append(_17);
+    builder.append(capabilityNumber);
+    builder.append(_19);
+    builder.append(capabilityNumber);
+    builder.append(_3);
+    builder.append(systemPackage);
+    builder.append(_17);
+    builder.append(capabilityNumber);
+    builder.append(_20);
+    }
+    builder.append(_21);
     builder.append(Generator.getModelXMLAsPropertyValue(variant, NL));
     return builder.toString();
   }
diff --git a/plugins/org.eclipse.justj.codegen/templates/fragment/MANIFEST.MF.jet b/plugins/org.eclipse.justj.codegen/templates/fragment/MANIFEST.MF.jet
index 1052edc..253c72b 100644
--- a/plugins/org.eclipse.justj.codegen/templates/fragment/MANIFEST.MF.jet
+++ b/plugins/org.eclipse.justj.codegen/templates/fragment/MANIFEST.MF.jet
@@ -1,4 +1,9 @@
-<%@jet package="org.eclipse.justj.codegen.templates.fragment" class="Manifest" imports="java.util.Iterator java.util.Map.Entry java.util.Set org.eclipse.justj.codegen.model.* org.eclipse.justj.codegen.model.util.Generator" builder="StringBuilder builder = new StringBuilder()" minimize="true"%>
+<%@jet
+  package="org.eclipse.justj.codegen.templates.fragment"
+  class="Manifest"
+  imports="org.eclipse.justj.codegen.model.* org.eclipse.justj.codegen.model.util.Generator"
+  builder="StringBuilder builder = new StringBuilder()"
+  minimize="true"%>
 <%Variant variant = (Variant)argument;
   String os = variant.getOs();
   String arch = variant.getArch();
@@ -20,11 +25,3 @@
 Eclipse-BundleShape: dir
 Eclipse-PlatformFilter: (& (osgi.os=<%=os%>) (osgi.arch=<%=arch%>))
 Automatic-Module-Name: <%=fullName%>
-Provide-Capability: <%%>
-<%for (Iterator<Entry<String, Set<String>>> it = Generator.getEECapabilities(version).entrySet().iterator(); it.hasNext();) {
-    Entry<String, Set<String>> entry = it.next();%>
-  <%for (Iterator<String> it2 = entry.getValue().iterator(); it2.hasNext();) {
-      String eeVersion = it2.next();%>
- osgi.ee;osgi.ee="<%=entry.getKey()%>";version:Version="<%=eeVersion%>"<%if (it.hasNext() || it2.hasNext()) {%>,<%}%>
-  <%}%>
-<%}%>
diff --git a/plugins/org.eclipse.justj.codegen/templates/fragment/p2.inf.jet b/plugins/org.eclipse.justj.codegen/templates/fragment/p2.inf.jet
index 61c4bb2..d79b26a 100644
--- a/plugins/org.eclipse.justj.codegen/templates/fragment/p2.inf.jet
+++ b/plugins/org.eclipse.justj.codegen/templates/fragment/p2.inf.jet
@@ -14,7 +14,9 @@
   imports="java.util.* java.util.Iterator org.eclipse.justj.codegen.model.* org.eclipse.justj.codegen.model.util.Generator"
   builder="StringBuilder builder = new StringBuilder()"
   minimize="true"%>
-<%Variant variant = (Variant)argument;%>
+<%Variant variant = (Variant)argument;
+  JVM jvm = variant.getJVM();
+  String version = jvm.getVersion();%>
 <%@include file="../copyright.properties.jetinc"%>
 
 <%Map<String, Set<String>> touchpoints = Generator.getTouchpoints(variant);
@@ -27,5 +29,25 @@
   <%}%>
 
 <%}%>
+<%int propertyCount = 0;
+  for (Map.Entry<String, Set<String>> entry : Generator.getEECapabilities(version).entrySet()) {
+    String eeName = entry.getKey();
+    Set<String> versions = entry.getValue();
+    for (String eeVersion : versions) {
+      int capabilityNumber = propertyCount++;%>
+provides.<%=capabilityNumber%>.namespace = osgi.ee
+provides.<%=capabilityNumber%>.name = <%=eeName%>
+provides.<%=capabilityNumber%>.version = <%=eeVersion%>
+
+  <%}%>
+<%}%>
+<%Set<String> systemPackages = Generator.getSystemPackages(variant);
+  for (String systemPackage : systemPackages) {
+    int capabilityNumber = propertyCount++;%>
+provides.<%=capabilityNumber%>.namespace = java.package
+provides.<%=capabilityNumber%>.name = <%=systemPackage%>
+provides.<%=capabilityNumber%>.version = 0.0.0
+
+<%}%>
 properties.0.name = org.eclipse.justj.model
 properties.0.value = <%=Generator.getModelXMLAsPropertyValue(variant, NL)%>
\ No newline at end of file