Java Code Examples for org.openide.util.lookup.Lookups#metaInfServices()
The following examples show how to use
org.openide.util.lookup.Lookups#metaInfServices() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainImpl.java From netbeans with Apache License 2.0 | 6 votes |
public BootClassLoader(List<File> cp, ClassLoader[] parents) { super(cp, parents); metaInf = Lookups.metaInfServices(this); String value = null; try { if (cp.isEmpty ()) { value = searchBuildNumber(this.getResources("META-INF/MANIFEST.MF")); } else { value = searchBuildNumber(this.findResources("META-INF/MANIFEST.MF")); } } catch (IOException ex) { ex.printStackTrace(); } if (value == null) { System.err.println("Cannot set netbeans.buildnumber property no OpenIDE-Module-Build-Version found"); // NOI18N } else { System.setProperty ("netbeans.buildnumber", value); // NOI18N } }
Example 2
Source File: LookupUsesRequestProcessorTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testMetaInfLookupDeliversEventsInRPThread() throws InterruptedException { ClassLoader l = new MyCL(); Lookup lkp = Lookups.metaInfServices(l); Lookup.Result<Runnable> result = lkp.lookupResult(Runnable.class); result.addLookupListener(this); assertNull("No runnables found", lkp.lookup(Runnable.class)); assertNotNull("Thread found", lkp.lookup(Thread.class)); assertNotNull("Now runnable found", lkp.lookup(Runnable.class)); synchronized (this) { int retry = 5; while (cnt == 0 && retry-- > 0) { wait(1000); } } assertEquals("Count is now 1", 1, cnt); }
Example 3
Source File: NamedServiceProcessorTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testNamedDefinition() throws Exception { System.setProperty("executed", "false"); String content = "import " + RunTestReg.class.getCanonicalName() + ";\n" + "@RunTestReg(position=10,when=\"now\")\n" + "public class Test implements Runnable {\n" + " public void run() { System.setProperty(\"executed\", \"true\"); }\n" + "}\n"; AnnotationProcessorTestUtils.makeSource(getWorkDir(), "x.Test", content); assertTrue("Compiles OK", AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, System.err) ); URLClassLoader l = new URLClassLoader(new URL[] { getWorkDir().toURI().toURL() }, NamedServiceProcessorTest.class.getClassLoader()); Lookup lkp = Lookups.metaInfServices(l, "META-INF/namedservices/runtest/now/below/"); for (Runnable r : lkp.lookupAll(Runnable.class)) { r.run(); } assertEquals("Our runnable was executed", "true", System.getProperty("executed")); }
Example 4
Source File: EditorTestLookup.java From netbeans with Apache License 2.0 | 5 votes |
public static void setLookup(Object[] instances, ClassLoader cl, FileObject servicesFolder, Class [] exclude) { Lookup metaInfServices = Lookups.metaInfServices(cl); if (exclude != null && exclude.length > 0) { metaInfServices = Lookups.exclude(metaInfServices, exclude); } DEFAULT_LOOKUP.setLookups(new Lookup[] { Lookups.fixed(instances), metaInfServices, Lookups.singleton(cl), }); if (servicesFolder != null) { // DataSystems need default repository, which is read from the default lookup. // That's why the lookup is set first without the services lookup and then again // here with the FolderLookup over the Services folder. Lookup services = new FolderLookup(DataFolder.findFolder(servicesFolder)).getLookup(); if (exclude != null && exclude.length > 0) { services = Lookups.exclude(services, exclude); } DEFAULT_LOOKUP.setLookups(new Lookup[] { Lookups.fixed(instances), metaInfServices, Lookups.singleton(cl), services }); } }
Example 5
Source File: MainLookup.java From netbeans with Apache License 2.0 | 5 votes |
public MainLookup () { super (new Lookup[] { // #14722: pay attention also to META-INF/services/class.Name resources: Lookups.metaInfServices(classLoader), Lookups.singleton(classLoader), Lookup.EMPTY, // will be moduleLookup instanceLookup }); }
Example 6
Source File: TestBase.java From netbeans with Apache License 2.0 | 5 votes |
private void setProxyLookups(Lookup[] lookups) { Lookup[] allLookups = new Lookup[lookups.length + 2]; ClassLoader l = TestBase.class.getClassLoader(); allLookups[allLookups.length - 1] = Lookups.metaInfServices(l); allLookups[allLookups.length - 2] = Lookups.singleton(l); System.arraycopy(lookups, 0, allLookups, 0, lookups.length); setLookups(allLookups); }
Example 7
Source File: TestBase.java From netbeans with Apache License 2.0 | 5 votes |
public void setProxyLookups(Lookup... lookups) { Lookup[] allLookups = new Lookup[lookups.length+3]; ClassLoader classLoader = TestBase.class.getClassLoader(); allLookups[0] = Lookups.singleton(classLoader); allLookups[1] = Lookups.singleton(defaultCPP); System.arraycopy(lookups, 0, allLookups, 2, lookups.length); allLookups[allLookups.length - 1] = Lookups.metaInfServices(classLoader); setLookups(allLookups); }
Example 8
Source File: EditorTestLookup.java From netbeans with Apache License 2.0 | 5 votes |
public static void setLookup(Object[] instances, ClassLoader cl, FileObject servicesFolder, Class [] exclude) { Lookup metaInfServices = Lookups.metaInfServices(cl); if (exclude != null && exclude.length > 0) { metaInfServices = Lookups.exclude(metaInfServices, exclude); } DEFAULT_LOOKUP.setLookups(new Lookup[] { Lookups.fixed(instances), metaInfServices, Lookups.singleton(cl), }); if (servicesFolder != null) { // DataSystems need default repository, which is read from the default lookup. // That's why the lookup is set first without the services lookup and then again // here with the FolderLookup over the Services folder. Lookup services = new FolderLookup(DataFolder.findFolder(servicesFolder)).getLookup(); if (exclude != null && exclude.length > 0) { services = Lookups.exclude(services, exclude); } DEFAULT_LOOKUP.setLookups(new Lookup[] { Lookups.fixed(instances), metaInfServices, Lookups.singleton(cl), services }); } }
Example 9
Source File: MainImpl.java From netbeans with Apache License 2.0 | 5 votes |
/** Checks for new JARs in netbeans.user */ @Override public void run () { // do not call this method twice if (onlyRunRunOnce) return; onlyRunRunOnce = true; ArrayList<File> toAdd = new ArrayList<File> (); String user = System.getProperty ("netbeans.user"); // NOI18N try { if (user != null) { JarClassLoader.initializeCache(); build_cp (new File (user), toAdd, new HashSet<File> (), new HashSet<String> ()); } if (!toAdd.isEmpty ()) { // source were already added in MainImpl.execute() method while processing userdir metaInf = Lookups.metaInfServices(this); if (handlers != null) { handlers.clear(); handlers.addAll(metaInf.lookupAll(CLIHandler.class)); } } } catch (IOException ex) { ex.printStackTrace(); } }
Example 10
Source File: NamedServicesProvider.java From netbeans with Apache License 2.0 | 5 votes |
public static Lookup forPath(String path) { Reference<Lookup> ref = namedServicesProviders.get(path); Lookup lkp = ref == null ? null : ref.get(); if (lkp != null) { return lkp; } NamedServicesProvider prov = Lookup.getDefault().lookup(NamedServicesProvider.class); if (prov != null && IN.get() == null) { IN.set(true); try { lkp = prov.create(path); } finally { IN.set(null); } } else { ClassLoader l = Lookup.getDefault().lookup(ClassLoader.class); if (l == null) { l = Thread.currentThread().getContextClassLoader(); if (l == null) { l = NamedServicesProvider.class.getClassLoader(); } } lkp = Lookups.metaInfServices(l, "META-INF/namedservices/" + path); } namedServicesProviders.put(path, new WeakReference<Lookup>(lkp)); return lkp; }
Example 11
Source File: Lookup.java From netbeans with Apache License 2.0 | 5 votes |
/** Called from MockServices to reset default lookup in case services change */ private static synchronized void resetDefaultLookup() { if (defaultLookup == null || defaultLookup instanceof DefLookup) { DefLookup def = (DefLookup)defaultLookup; ClassLoader l = Thread.currentThread().getContextClassLoader(); Lookup misl = Lookups.metaInfServices(l); if (def == null) { def = new DefLookup(); def.init(l, misl, false); defaultLookup = def; } def.init(l, misl, true); } }
Example 12
Source File: RecognizeInstanceObjects.java From netbeans with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") private static Lookup[] delegates(Lookup prevFolderLkp, String path) { ClassLoader loader = Lookup.getDefault().lookup(ClassLoader.class); LOG.log(Level.FINEST, "lkp loader: {0}", loader); if (loader == null) { loader = Thread.currentThread().getContextClassLoader(); LOG.log(Level.FINEST, "ccl: {0}", loader); } if (loader == null) { loader = RecognizeInstanceObjects.class.getClassLoader(); } LOG.log(Level.FINER, "metaInfServices for {0}", loader); Lookup base = Lookups.metaInfServices(loader, "META-INF/namedservices/" + path); // NOI18N FileObject fo = FileUtil.getConfigFile(path); if (fo == null) { return new Lookup[] {base}; } String s; if (path.endsWith("/")) { // NOI18N s = path.substring(0, path.length() - 1); } else { s = path; } if (prevFolderLkp == null) { prevFolderLkp = new org.openide.loaders.FolderLookup(DataFolder.findFolder(fo), s).getLookup(); } return new Lookup[] {prevFolderLkp, base}; }
Example 13
Source File: OSGiMainLookup.java From netbeans with Apache License 2.0 | 5 votes |
private void setDelegates() { Lookup[] delegates = new Lookup[nonClassLoaderDelegates.size() + 2]; nonClassLoaderDelegates.toArray(delegates); delegates[delegates.length - 2] = Lookups.metaInfServices(classLoader); delegates[delegates.length - 1] = Lookups.singleton(classLoader); setLookups(delegates); }
Example 14
Source File: ModulesHintTest.java From netbeans with Apache License 2.0 | 4 votes |
public TestLookup() { super(Lookups.metaInfServices(TestLookup.class.getClassLoader())); }
Example 15
Source File: FolderLookupTest.java From netbeans with Apache License 2.0 | 4 votes |
public GLkp() { super(new Lookup[] { new ALkp(), Lookups.metaInfServices(GLkp.class.getClassLoader()), }); }
Example 16
Source File: DataShadowBrokenAreNotTestedTest.java From netbeans with Apache License 2.0 | 4 votes |
public Lkp() { super(new Lookup[] { Lookups.singleton(new UM()), Lookups.metaInfServices(Lkp.class.getClassLoader()), }); }
Example 17
Source File: DataShadowBrokenAreNotQueriedTest.java From netbeans with Apache License 2.0 | 4 votes |
public Lkp() { super(new Lookup[] { Lookups.singleton(new UM()), Lookups.metaInfServices(Lkp.class.getClassLoader()), }); }
Example 18
Source File: NbLoaderPoolResolverChangeTest.java From netbeans with Apache License 2.0 | 4 votes |
private MyLkp(ClassLoader l) { super(Lookups.fixed(new Repository(FileUtil.createMemoryFileSystem())), Lookups.metaInfServices(l), Lookups.singleton(l)); }
Example 19
Source File: URLMapperTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testURLMapperCallingFromMetaInfLookup() { Lookup lkp = Lookups.metaInfServices(Thread.currentThread().getContextClassLoader()); Object obj = lkp.lookup(Object.class); assertNotNull(obj); assertEquals(MyInstance2.class, obj.getClass()); }
Example 20
Source File: Deadlock73332Test.java From netbeans with Apache License 2.0 | 4 votes |
private Lookup getMetaInfLookup() { return Lookups.metaInfServices(Thread.currentThread().getContextClassLoader()); }