Java Code Examples for org.apache.uima.resource.ResourceManager#setExtensionClassPath()
The following examples show how to use
org.apache.uima.resource.ResourceManager#setExtensionClassPath() .
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: Jg.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Creates the resource manager. * * @return the resource manager */ public ResourceManager createResourceManager() { ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager(); if (classPath != null && classPath.trim().length() > 0) { try { resourceManager.setExtensionClassPath(this.getClass().getClassLoader(), classPath, true); } catch (MalformedURLException e1) { error.newError(IError.ERROR, getString("Internal Error", null), e1); } } else { resourceManager.setExtensionClassLoader(this.getClass().getClassLoader(), true); } return resourceManager; }
Example 2
Source File: UIMAClassLoaderTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testSimpleRsrcMgrCLassLoaderCreation() throws Exception { ResourceManager rsrcMgr = UIMAFramework.newDefaultResourceManager(); assertNull(rsrcMgr.getExtensionClassLoader()); rsrcMgr.setExtensionClassPath("../this/is/a/simple/test.jar", false); ClassLoader cl = rsrcMgr.getExtensionClassLoader(); assertNotNull(cl); //assertTrue(cl != cl.getClassLoadingLock("Aclass")); Class classOfLoader = cl.getClass().getSuperclass(); while (!(classOfLoader.getName().equals("java.lang.ClassLoader"))) { classOfLoader = classOfLoader.getSuperclass(); } if (!Misc.isJava9ea) { // skip for java 9 Method m = classOfLoader.getDeclaredMethod("getClassLoadingLock", String.class); m.setAccessible(true); Object o = m.invoke(cl, "someString"); Object o2 = m.invoke(cl, "s2"); assertTrue(o != o2); assertTrue(cl != o); } }
Example 3
Source File: InstallationTester.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * returns a valid ResourceManager with the information from the PackageBrowser object. * * @param pkgBrowser * packageBrowser object of an installed PEAR package * * @return a ResourceManager object with the information from the PackageBrowser object. * * @throws IOException passthru */ private static ResourceManager getResourceManager(PackageBrowser pkgBrowser) throws IOException { ResourceManager resourceMgr = UIMAFramework.newDefaultResourceManager(); // set component data path if (pkgBrowser.getComponentDataPath() != null) { resourceMgr.setDataPath(pkgBrowser.getComponentDataPath()); } // set component classpath if (pkgBrowser.buildComponentClassPath() != null) { resourceMgr.setExtensionClassPath(pkgBrowser.buildComponentClassPath(), true); } return resourceMgr; }
Example 4
Source File: ResourceManagerFactory.java From uima-uimafit with Apache License 2.0 | 4 votes |
@Override public ResourceManager newResourceManager() throws ResourceInitializationException { UimaContext activeContext = UimaContextHolder.getContext(); if (activeContext != null) { // If we are already in a UIMA context, then we re-use it. Mind that the JCas cannot // handle switching across more than one classloader. // This can be done since UIMA 2.9.0 and starts being handled in uimaFIT 2.3.0 // See https://issues.apache.org/jira/browse/UIMA-5056 return ((UimaContextAdmin) activeContext).getResourceManager(); } else { // If there is no UIMA context, then we create a new resource manager // UIMA core still does not fall back to the context classloader in all cases. // This was the default behavior until uimaFIT 2.2.0. ResourceManager resMgr; if (Thread.currentThread().getContextClassLoader() != null) { // If the context classloader is set, then we want the resource manager to fallb // back to it. However, it may not reliably do that that unless we explictly pass // null here. See. UIMA-6239. resMgr = new ResourceManager_impl(null); } else { resMgr = UIMAFramework.newDefaultResourceManager(); } // Since UIMA Core version 2.10.3 and 3.0.1 the thread context classloader is taken // into account by the core framework. Thus, we no longer have to explicitly set a // classloader these or more recent versions. (cf. UIMA-5802) short maj = UimaVersion.getMajorVersion(); short min = UimaVersion.getMinorVersion(); short rev = UimaVersion.getBuildRevision(); boolean uimaCoreIgnoresContextClassloader = (maj == 2 && (min < 10 || (min == 10 && rev < 3))) || // version < 2.10.3 (maj == 3 && ((min == 0 && rev < 1))); // version < 3.0.1 if (uimaCoreIgnoresContextClassloader) { try { resMgr.setExtensionClassPath(ClassUtils.getDefaultClassLoader(), "", true); } catch (MalformedURLException e) { throw new ResourceInitializationException(e); } } return resMgr; } }
Example 5
Source File: PearMergerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * Runs test for org.apache.uima.pear.merger.PMController class by merging 2 sample input PEARs * into the output aggregate PEAR. Then, the output PEAR is installed by using * org.apache.uima.pear.tools.InstallationController, and the installed component is verified by * instantiating the aggregate TAE and creating CAS object. * * @throws Exception - */ public void testPearMerger() throws Exception { // check temporary working directory if (_tempWorkingDir == null) throw new FileNotFoundException("temp directory not found"); // check sample PEAR files File[] inpPearFiles = new File[2]; inpPearFiles[0] = JUnitExtension.getFile(TEST_FOLDER + File.separator + INP_PEAR_1_FILE); if (!inpPearFiles[0].isFile()) throw new FileNotFoundException("sample PEAR 1 not found"); inpPearFiles[1] = JUnitExtension.getFile(TEST_FOLDER + File.separator + INP_PEAR_2_FILE); if (!inpPearFiles[1].isFile()) throw new FileNotFoundException("sample PEAR 2 not found"); // specify output aggregate PEAR file File outPearFile = new File(_tempWorkingDir, OUT_PEAR_ID + ".pear"); // create PMController instance and perform merging operation PMController.setLogFileEnabled(false); PMController pmController = new PMController(inpPearFiles, OUT_PEAR_ID, outPearFile); boolean done = pmController.mergePears(); // check merging results Assert.assertTrue(done); Assert.assertTrue(outPearFile.isFile()); // install the output PEAR file and check the results InstallationController insController = new InstallationController(OUT_PEAR_ID, outPearFile, _tempWorkingDir); InstallationDescriptor insDesc = insController.installComponent(); Assert.assertTrue(insDesc != null); Assert.assertTrue(OUT_PEAR_ID.equals(insDesc.getMainComponentId())); // verify the installed component // customize ResourceManager by adding component CLASSPATH ResourceManager resMngr = UIMAFramework.newDefaultResourceManager(); String compClassPath = InstallationController.buildComponentClassPath(insDesc .getMainComponentRoot(), insDesc, false); // instantiate the aggregate AE resMngr.setExtensionClassPath(compClassPath, true); String compDescFilePath = insDesc.getMainComponentDesc(); XMLParser xmlPaser = UIMAFramework.getXMLParser(); XMLInputSource xmlInput = new XMLInputSource(compDescFilePath); AnalysisEngineDescription aeSpec = xmlPaser.parseAnalysisEngineDescription(xmlInput); AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(aeSpec, resMngr, null); Assert.assertTrue(ae != null); // create CAS object CAS cas = ae.newCAS(); Assert.assertTrue(cas != null); //process CAS cas.setDocumentText("Sample text for testing"); ae.process(cas); // clean-up the results pmController.cleanUp(); }
Example 6
Source File: PearAnalysisEngineWrapper.java From uima-uimaj with Apache License 2.0 | 4 votes |
private synchronized ResourceManager createRM(StringPair sp, PackageBrowser pkgBrowser, ResourceManager parentResourceManager) throws MalformedURLException { // create UIMA resource manager and apply pear settings // ResourceManager rsrcMgr = UIMAFramework.newDefaultResourceManager(); ResourceManager rsrcMgr; if (null == parentResourceManager) { // could be null for top level Pear not in an aggregate rsrcMgr = UIMAFramework.newDefaultResourceManager(); } else { rsrcMgr = ((ResourceManager_impl) parentResourceManager).copy(); // newPearsParent.set((ResourceManager_impl) parentResourceManager); // rsrcMgr = UIMAFramework.newDefaultResourceManagerPearWrapper(); // newPearsParent.remove(); // ((ResourceManagerPearWrapper)rsrcMgr).initializeFromParentResourceManager(parentResourceManager); } rsrcMgr.setExtensionClassPath(sp.classPath, true); if (parentResourceManager != null) { rsrcMgr.setCasManager(parentResourceManager.getCasManager()); // shares the same merged type system } UIMAFramework.getLogger(this.getClass()).logrb( Level.CONFIG, this.getClass().getName(), "createRM", LOG_RESOURCE_BUNDLE, "UIMA_pear_runtime_set_classpath__CONFIG", new Object[] { sp.classPath, pkgBrowser.getRootDirectory().getName() }); // get and set uima.datapath if specified if (sp.dataPath != null) { rsrcMgr.setDataPath(sp.dataPath); UIMAFramework.getLogger(this.getClass()).logrb( Level.CONFIG, this.getClass().getName(), "createRM", LOG_RESOURCE_BUNDLE, "UIMA_pear_runtime_set_datapath__CONFIG", new Object[] { sp.dataPath, pkgBrowser.getRootDirectory().getName() }); } return rsrcMgr; }
Example 7
Source File: UimaContext_implTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
protected void setUp() throws Exception { try { // configure ResourceManager to allow test components to locate their resources ResourceManager rm = UIMAFramework.newDefaultResourceManager(); rm.setDataPath(TEST_DATAPATH); rm.setExtensionClassPath(TEST_EXTENSION_CLASSPATH, true); // create a UimaContext with Config Params and Resources UIMAFramework.getXMLParser().enableSchemaValidation(true); CasConsumerDescription ccDesc = UIMAFramework.getXMLParser().parseCasConsumerDescription( new XMLInputSource(JUnitExtension .getFile("UimaContextTest/CasConsumerForUimaContextTest.xml"))); CasConsumer cc = UIMAFramework.produceCasConsumer(ccDesc, rm, null); mContext = cc.getUimaContext(); // create a UimaContext with Config Params in Groups but no resources XMLInputSource in = new XMLInputSource(JUnitExtension .getFile("AnnotatorContextTest/AnnotatorWithConfigurationGroups.xml")); AnalysisEngineDescription taeDesc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in); AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(taeDesc, rm, null); mContext2 = ae.getUimaContext(); // create a UimaContext with Groups and Groupless Parameters XMLInputSource in2 = new XMLInputSource(JUnitExtension .getFile("AnnotatorContextTest/AnnotatorWithGroupsAndNonGroupParams.xml")); AnalysisEngineDescription taeDesc2 = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in2); AnalysisEngine ae2 = UIMAFramework.produceAnalysisEngine(taeDesc2, rm, null); mContext3 = ae2.getUimaContext(); // create a UimaContext with duplicate configuration groups XMLInputSource in3 = new XMLInputSource(JUnitExtension .getFile("TextAnalysisEngineImplTest/AnnotatorWithDuplicateConfigurationGroups.xml")); AnalysisEngineDescription taeDesc3 = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in3); AnalysisEngine ae3 = UIMAFramework.produceAnalysisEngine(taeDesc3, rm, null); mContext4 = ae3.getUimaContext(); super.setUp(); // create a UimaContext for a CAS Multiplier XMLInputSource in4 = new XMLInputSource(JUnitExtension .getFile("TextAnalysisEngineImplTest/NewlineSegmenter.xml")); AnalysisEngineDescription taeDesc4 = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in4); AnalysisEngine ae4 = UIMAFramework.produceAnalysisEngine(taeDesc4); mContext5 = ae4.getUimaContext(); super.setUp(); } catch (Exception e) { JUnitExtension.handleException(e); } }
Example 8
Source File: AnnotatorContext_implTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
protected void setUp() throws Exception { try { super.setUp(); // create primitive analysis engine with configuration groups XMLInputSource in = new XMLInputSource(JUnitExtension .getFile("AnnotatorContextTest/AnnotatorWithConfigurationGroups.xml")); AnalysisEngineDescription desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in); PrimitiveAnalysisEngine_impl tae = new PrimitiveAnalysisEngine_impl(); // set data path just to test that we can get it later Map<String, Object> map = new HashMap<>(); ResourceManager rm = UIMAFramework.newDefaultResourceManager(); rm.setDataPath(TEST_DATAPATH); rm.setExtensionClassPath(TEST_EXTENSION_CLASSPATH, true); map.put(AnalysisEngine.PARAM_RESOURCE_MANAGER, rm); tae.initialize(desc, map); // this should include an annotator context mAC1 = new AnnotatorContext_impl(tae.getUimaContextAdmin()); // create aggregate analysis engine with configuration parameter overrides XMLInputSource in2 = new XMLInputSource(JUnitExtension .getFile("AnnotatorContextTest/AggregateTaeWithConfigParamOverrides.xml")); AnalysisEngineDescription aggDesc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in2); AggregateAnalysisEngine_impl aggTae = new AggregateAnalysisEngine_impl(); aggTae.initialize(aggDesc, map); // get the primitive TAE PrimitiveAnalysisEngine_impl primTae = (PrimitiveAnalysisEngine_impl) aggTae._getASB() .getComponentAnalysisEngines().values().toArray()[0]; // this should include an annotator context mAC2 = new AnnotatorContext_impl(primTae.getUimaContextAdmin()); // create primitive analysis engine for resource testing XMLInputSource in3 = new XMLInputSource(JUnitExtension .getFile("AnnotatorContextTest/ResourceTestAnnotator.xml")); AnalysisEngineDescription resTestDesc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in3); PrimitiveAnalysisEngine_impl resTestTae = new PrimitiveAnalysisEngine_impl(); resTestTae.initialize(resTestDesc, map); // this should include an annotator context mAC3 = new AnnotatorContext_impl(resTestTae.getUimaContextAdmin()); // create primitive TAE with configuration groups and default fallback XMLInputSource in4 = new XMLInputSource(JUnitExtension .getFile("AnnotatorContextTest/AnnotatorWithDefaultFallbackConfiguration.xml")); AnalysisEngineDescription desc4 = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in4); PrimitiveAnalysisEngine_impl tae4 = new PrimitiveAnalysisEngine_impl(); // set data path just to test that we can get it later tae4.initialize(desc4, null); // this should include an annotator context mAC4 = new AnnotatorContext_impl(tae4.getUimaContextAdmin()); // create primitive TAE with configuration parameters (no groups) XMLInputSource in5 = new XMLInputSource(JUnitExtension .getFile("AnnotatorContextTest/AnnotatorWithConfigurationParameters.xml")); AnalysisEngineDescription desc5 = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in5); PrimitiveAnalysisEngine_impl tae5 = new PrimitiveAnalysisEngine_impl(); // set data path just to test that we can get it later tae5.initialize(desc5, null); // this should include an annotator context mAC5 = new AnnotatorContext_impl(tae5.getUimaContextAdmin()); } catch (Exception e) { JUnitExtension.handleException(e); } }
Example 9
Source File: UIMAClassLoaderTest.java From uima-uimaj with Apache License 2.0 | 3 votes |
public void testAdvancedRsrcMgrCLassLoaderCreation() throws Exception { ResourceManager rsrcMgr = UIMAFramework.newDefaultResourceManager(); assertNull(rsrcMgr.getExtensionClassLoader()); rsrcMgr.setExtensionClassPath("../this/is/a/simple/test.jar", true); assertNotNull(rsrcMgr.getExtensionClassLoader()); }