5757import org .eclipse .emf .ecore .resource .URIConverter ;
5858import org .osgi .framework .BundleActivator ;
5959import org .osgi .framework .BundleContext ;
60+ import org .osgi .framework .BundleException ;
6061
6162
6263/**
@@ -586,6 +587,7 @@ public static Map<String, URI> getEPackageNsURIToDynamicModelLocationMap(boolean
586587 */
587588 static public class Implementation extends EclipsePlugin
588589 {
590+ private ManifestEPackageTracker ePackageTracker ;
589591 /**
590592 * Creates the singleton instance.
591593 */
@@ -658,6 +660,18 @@ public void start(BundleContext context) throws Exception
658660 super .start (context );
659661 ExtensionProcessor .internalProcessExtensions ();
660662
663+ ePackageTracker = new ManifestEPackageTracker (context );
664+ ePackageTracker .open ();
665+ }
666+
667+ @ Override
668+ public void stop (BundleContext context ) throws Exception
669+ {
670+ super .stop (context );
671+ if (ePackageTracker != null )
672+ {
673+ ePackageTracker .close ();
674+ }
661675 }
662676
663677 /**
@@ -840,6 +854,8 @@ public IExtensionRegistry getRegistry()
840854 // Process the extension for the registry.
841855 //
842856 ExtensionProcessor .internalProcessExtensions ();
857+
858+ ExtensionProcessor .internalProcessManifests (classLoader );
843859 }
844860 }
845861
@@ -910,12 +926,47 @@ protected boolean readElement(IConfigurationElement element)
910926 new ConversionDelegateFactoryRegistryReader ().readRegistry ();
911927 new AnnotationValidatorRegistryReader ().readRegistry ();
912928 }
929+
930+ private static void internalProcessManifests (ClassLoader classLoader )
931+ {
932+ if (!IS_OSGI_RUNNING )
933+ { // not in a OSGi runtime, process raw MANIFEST.MF
934+ try
935+ {
936+ List <URI > manifests = getManifests (classLoader );
937+ for (URI manifest : manifests )
938+ {
939+ ManifestEPackageTracker .registerManifestPackagesIfAbsent (manifest , classLoader );
940+ }
941+ }
942+ catch (IOException | BundleException e )
943+ {
944+ e .printStackTrace (); //TODO: handle
945+ }
946+ }
947+ }
913948 }
914949
915950 /**
916951 * Determine all the available plugin.xml resources.
917952 */
918953 private static List <URI > getPluginXMLs (ClassLoader classLoader )
954+ {
955+ return getClasspathResource (classLoader , "plugin.xml" );
956+ }
957+
958+ /**
959+ * Determine all the available {@code META-INF/MANIFEST.MF} resources.
960+ */
961+ private static List <URI > getManifests (ClassLoader classLoader )
962+ {
963+ return getClasspathResource (classLoader , "META-INF/MANIFEST.MF" );
964+ }
965+
966+ /**
967+ * Determine all the available plugin.xml resources.
968+ */
969+ private static List <URI > getClasspathResource (ClassLoader classLoader , String resourcePath )
919970 {
920971 List <URI > result = new ArrayList <URI >();
921972
@@ -958,13 +1009,13 @@ private static List<URI> getPluginXMLs(ClassLoader classLoader)
9581009 {
9591010 // Determine if there is a plugin.xml at the root of the folder.
9601011 //
961- File pluginXML = new File (file , "plugin.xml" );
1012+ File pluginXML = new File (file , resourcePath );
9621013 if (!pluginXML .exists ())
9631014 {
9641015 // If not, check if there is one in the parent folder.
9651016 //
9661017 File parentFile = file .getParentFile ();
967- pluginXML = new File (parentFile , "plugin.xml" );
1018+ pluginXML = new File (parentFile , resourcePath );
9681019 if (pluginXML .isFile ())
9691020 {
9701021 // If there is, then we have plugin.xml files that aren't on the classpath.
@@ -975,7 +1026,7 @@ else if (parentFile != null)
9751026 {
9761027 // The parent has a parent, check if there is one in the parent's parent folder.
9771028 //
978- pluginXML = new File (parentFile .getParentFile (), "plugin.xml" );
1029+ pluginXML = new File (parentFile .getParentFile (), resourcePath );
9791030 if (pluginXML .isFile ())
9801031 {
9811032 // If there is, then we have plugin.xml files that aren't on the classpath.
@@ -1014,7 +1065,7 @@ else if (file.isFile())
10141065 // Look for a plugin.xml entry...
10151066 //
10161067 jarFile = new JarFile (classpathEntry );
1017- ZipEntry entry = jarFile .getEntry ("plugin.xml" );
1068+ ZipEntry entry = jarFile .getEntry (resourcePath );
10181069 if (entry != null )
10191070 {
10201071 // If we find one, create a URI for it.
@@ -1052,7 +1103,7 @@ else if (file.isFile())
10521103 result .clear ();
10531104 try
10541105 {
1055- for (Enumeration <URL > resources = classLoader .getResources ("plugin.xml" ); resources .hasMoreElements (); )
1106+ for (Enumeration <URL > resources = classLoader .getResources (resourcePath ); resources .hasMoreElements (); )
10561107 {
10571108 // Create a URI for each plugin.xml found by the class loader.
10581109 //
0 commit comments