You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2017/10/09 18:23:51 UTC
svn commit: r1811591 - in /uima/uv3/uimaj-v3/trunk:
uimaj-core/src/main/java/org/apache/uima/resource/
uimaj-core/src/main/java/org/apache/uima/resource/impl/
uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/
Author: schor
Date: Mon Oct 9 18:23:51 2017
New Revision: 1811591
URL: http://svn.apache.org/viewvc?rev=1811591&view=rev
Log:
[UIMA-5609] slight change to definition - allow any kind of classloader, and avoid creating wrapping UIMAClassloader if the argument is an instance of that already.
Modified:
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceManager.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManager_impl.java
uima/uv3/uimaj-v3/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceManager.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceManager.java?rev=1811591&r1=1811590&r2=1811591&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceManager.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceManager.java Mon Oct 9 18:23:51 2017
@@ -25,7 +25,6 @@ import java.net.URL;
import java.util.List;
import java.util.Map;
-import org.apache.uima.internal.util.UIMAClassLoader;
import org.apache.uima.resource.impl.ResourceManager_impl;
import org.apache.uima.resource.metadata.ResourceManagerConfiguration;
import org.apache.uima.util.XMLizable;
@@ -334,11 +333,13 @@ public interface ResourceManager {
/**
* Set an extension class loader into the Resource Manager
- * @param uimaExtensionClassLoader the loader to use
+ * @param classLoader the loader to use. If this is an instance of UIMAClassLoader, it is
+ * used directly; otherwise, a new UIMAClassLoader with no classpath, having
+ * the classLoader as a parent is created and used.
* @param resolveResources true to also use this to resolve resources
*/
- default void setExtensionClassLoader(UIMAClassLoader uimaExtensionClassLoader, boolean resolveResources) {
- ((ResourceManager_impl)this).setExtensionClassLoaderImpl(uimaExtensionClassLoader, resolveResources);
+ default void setExtensionClassLoader(ClassLoader classLoader, boolean resolveResources) {
+ ((ResourceManager_impl)this).setExtensionClassLoaderImpl(classLoader, resolveResources);
}
/**
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManager_impl.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManager_impl.java?rev=1811591&r1=1811590&r2=1811591&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManager_impl.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ResourceManager_impl.java Mon Oct 9 18:23:51 2017
@@ -99,7 +99,9 @@ public class ResourceManager_impl implem
*/
protected static final String LOG_RESOURCE_BUNDLE = "org.apache.uima.impl.log_messages";
- protected static final Class<Resource> EMPTY_RESOURCE_CLASS = Resource.class;
+ protected static final Class<Resource> EMPTY_RESOURCE_CLASS = Resource.class;
+
+ private static final URL[] emptyURLarray = null;
private AtomicBoolean isDestroyed = new AtomicBoolean(false);
/**
@@ -330,8 +332,10 @@ public class ResourceManager_impl implem
// https://issues.apache.org/jira/browse/UIMA-5553
// https://issues.apache.org/jira/browse/UIMA-5609
// synchronized because the other methods that set the extension class loader are.
- public synchronized void setExtensionClassLoaderImpl(UIMAClassLoader uimaExtensionClassLoader, boolean resolveResource) {
- uimaCL = uimaExtensionClassLoader;
+ public synchronized void setExtensionClassLoaderImpl(ClassLoader classLoader, boolean resolveResource) {
+ uimaCL = (classLoader instanceof UIMAClassLoader)
+ ? ((UIMAClassLoader) classLoader)
+ : new UIMAClassLoader(emptyURLarray, classLoader);
if (resolveResource) {
// set UIMA extension ClassLoader also to resolve resources
getRelativePathResolver().setPathResolverClassLoader(uimaCL);
Modified: uima/uv3/uimaj-v3/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java?rev=1811591&r1=1811590&r2=1811591&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java Mon Oct 9 18:23:51 2017
@@ -61,7 +61,6 @@ import org.apache.uima.cas.impl.CASImpl;
import org.apache.uima.cas.impl.TypeImpl;
import org.apache.uima.cas.impl.TypeImpl_string;
import org.apache.uima.cas.impl.TypeSystemImpl;
-import org.apache.uima.internal.util.UIMAClassLoader;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.ResourceManager;
import org.apache.uima.resource.metadata.FeatureDescription;
@@ -103,7 +102,7 @@ public class Jg {
static final FeatureDescription[] featureDescriptionArray0 = new FeatureDescription[0];
/** The Constant reservedFeatureNames. */
- static final Collection reservedFeatureNames = new ArrayList();
+ static final Collection<String> reservedFeatureNames = new ArrayList<>();
{
reservedFeatureNames.add("Address");
@@ -126,7 +125,7 @@ public class Jg {
* Set of types not generated from the CAS type set because they're already in existence as
* builtins in the JCas impl. and if they're generated, the generated forms are wrong.
*/
- static final Set noGenTypes = new HashSet();
+ static final Set<String> noGenTypes = new HashSet<>();
/** The Constant casCreateProperties. */
public static final Properties casCreateProperties = new Properties();
@@ -135,7 +134,7 @@ public class Jg {
}
/** The Constant extendableBuiltInTypes. */
- static final Map extendableBuiltInTypes = new HashMap();
+ static final Map<String, FeatureDescription[]> extendableBuiltInTypes = new HashMap<>();
// create a hash map of built-in types, where the
// key is the fully-qualified name "uima.tcas.Annotation"
@@ -146,8 +145,6 @@ public class Jg {
/** The Constant emptyFds. */
static final FeatureDescription[] emptyFds = new FeatureDescription[0];
- private static final URL[] emptyURLarray = new URL[0];
-
/** The built in type system. */
static TypeSystem builtInTypeSystem;
@@ -169,8 +166,8 @@ public class Jg {
noGenTypes.add("org.apache.uima.jcas.cas.IntegerArrayList");
noGenTypes.add("org.apache.uima.jcas.cas.FSHashSet");
- for (Iterator it = builtInTypeSystem.getTypeIterator(); it.hasNext();) {
- Type type = (Type) it.next();
+ for (Iterator<Type> it = builtInTypeSystem.getTypeIterator(); it.hasNext();) {
+ Type type = it.next();
if (type.isFeatureFinal()) {
noGenTypes.add(type.getName());
continue; // skip if feature final
@@ -291,10 +288,10 @@ public class Jg {
/** The imports. */
// Instance fields
- final Map imports = new HashMap(); // can't be final - one per instance running
+ final Map<String, String> imports = new HashMap<>(); // can't be final - one per instance running
/** The imports. */
- final Map _imports = new HashMap();
+ final Map<String, String> _imports = new HashMap<>();
/** The class path. */
String classPath = "";
@@ -464,21 +461,21 @@ public class Jg {
* @param outputDirectory the output directory
* @param tds the tds
* @param aCas the a cas
- * @param projectPathDir the project path dir
- * @param limitJCasGenToProjectScope the limit J cas gen to project scope
- * @param mergedTypesAddingFeatures the merged types adding features
+ * @param pProjectPathDir the project path dir
+ * @param limitToProjectScope the limit J cas gen to project scope
+ * @param pMergedTypesAddingFeatures the merged types adding features
* @throws IOException Signals that an I/O exception has occurred.
*/
public void mainForCde(IMerge aMerger, IProgressMonitor aProgressMonitor, IError aError,
String inputFile, String outputDirectory, TypeDescription[] tds, CASImpl aCas,
- String projectPathDir, boolean limitJCasGenToProjectScope,
- Map<String, Set<String>> mergedTypesAddingFeatures)
+ String pProjectPathDir, boolean limitToProjectScope,
+ Map<String, Set<String>> pMergedTypesAddingFeatures)
throws IOException {
try {
// Generate type classes by using DEFAULT templates
mainGenerateAllTypesFromTemplates(aMerger, aProgressMonitor, aError, inputFile,
outputDirectory, tds, aCas, JCasTypeTemplate.class,
- projectPathDir, limitJCasGenToProjectScope, mergedTypesAddingFeatures);
+ pProjectPathDir, limitToProjectScope, pMergedTypesAddingFeatures);
// convert thrown things to IOExceptions to avoid changing API for this
// FIXME later
} catch (InstantiationException e) {
@@ -507,8 +504,8 @@ public class Jg {
// use template classes to generate code
public void mainGenerateAllTypesFromTemplates(IMerge aMerger, IProgressMonitor aProgressMonitor,
IError aError, String inputFile, String outputDirectory, TypeDescription[] tds,
- CASImpl aCas, Class jcasTypeClass, // Template class
- Class jcas_TypeClass) // Template class
+ CASImpl aCas, Class<JCasTypeTemplate> jcasTypeClass, // Template class
+ Class<JCasTypeTemplate> jcas_TypeClass) // Template class
throws IOException, InstantiationException, IllegalAccessException {
mainGenerateAllTypesFromTemplates(aMerger, aProgressMonitor,
aError, inputFile, outputDirectory, tds, aCas,
@@ -526,26 +523,26 @@ public class Jg {
* @param tds the tds
* @param aCas the a cas
* @param jcasTypeClass the jcas type class
- * @param projectPathDir the project path dir
- * @param limitJCasGenToProjectScope the limit J cas gen to project scope
- * @param mergedTypesAddingFeatures the merged types adding features
+ * @param pProjectPathDir the project path dir
+ * @param limitToProjectScope the limit J cas gen to project scope
+ * @param pMergedTypesAddingFeatures the merged types adding features
* @throws IOException Signals that an I/O exception has occurred.
* @throws InstantiationException the instantiation exception
* @throws IllegalAccessException the illegal access exception
*/
public void mainGenerateAllTypesFromTemplates(IMerge aMerger, IProgressMonitor aProgressMonitor,
IError aError, String inputFile, String outputDirectory, TypeDescription[] tds,
- CASImpl aCas, Class jcasTypeClass, // Template class
- String projectPathDir, boolean limitJCasGenToProjectScope,
- Map<String, Set<String>> mergedTypesAddingFeatures) // Template class
+ CASImpl aCas, Class<JCasTypeTemplate> jcasTypeClass, // Template class
+ String pProjectPathDir, boolean limitToProjectScope,
+ Map<String, Set<String>> pMergedTypesAddingFeatures) // Template class
throws IOException, InstantiationException, IllegalAccessException {
this.merger = aMerger;
this.error = aError;
this.progressMonitor = aProgressMonitor;
xmlSourceFileName = inputFile.replaceAll("\\\\", "/");
- this.projectPathDir = projectPathDir;
- this.limitJCasGenToProjectScope = limitJCasGenToProjectScope;
- this.mergedTypesAddingFeatures = mergedTypesAddingFeatures;
+ this.projectPathDir = pProjectPathDir;
+ this.limitJCasGenToProjectScope = limitToProjectScope;
+ this.mergedTypesAddingFeatures = pMergedTypesAddingFeatures;
// Generate type classes by using SPECIFIED templates
generateAllTypesFromTemplates(outputDirectory, tds, aCas, jcasTypeClass);
@@ -750,23 +747,19 @@ public class Jg {
* @return the string
*/
// message: TypeName = ".....", URLs defining this type = "xxxx", "xxxx", ....
- private String makeMergeMessage(Map m) {
+ private String makeMergeMessage(Map<String, Set<String>> m) {
StringBuffer sb = new StringBuffer();
- for (Iterator it = m.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- String typeName = (String) entry.getKey();
+ for (Map.Entry<String, Set<String>> entry : m.entrySet()) {
+ String typeName = entry.getKey();
sb.append("\n ");
sb.append("TypeName having merged features = ").append(typeName).append(
"\n URLs defining this type =");
- Set urls = (Set) entry.getValue();
+ Set<String> urls = entry.getValue();
boolean afterFirst = false;
- for (Iterator itUrls = urls.iterator(); itUrls.hasNext();) {
- if (afterFirst)
- sb.append(",\n ");
- else
- sb.append("\n ");
+ for (String url : urls) {
+ sb.append(afterFirst ? ',' : "")
+ .append("\n \"");
afterFirst = true;
- String url = (String) itUrls.next();
sb.append('"').append(url).append('"');
}
}
@@ -786,13 +779,13 @@ public class Jg {
*/
// This is also the interface for CDE
private void generateAllTypesFromTemplates(String outputDirectory, TypeDescription[] tds,
- CASImpl aCas, Class jcasTypeClass) throws IOException,
+ CASImpl aCas, Class<JCasTypeTemplate> jcasTypeClass) throws IOException,
InstantiationException, IllegalAccessException {
// Create instances of Template classes
IJCasTypeTemplate jcasTypeInstance = (IJCasTypeTemplate) jcasTypeClass.newInstance();
- Set generatedBuiltInTypes = new TreeSet();
+ Set<String> generatedBuiltInTypes = new TreeSet<>();
this.cas = aCas;
this.typeSystem = cas.getTypeSystem();
@@ -825,7 +818,7 @@ public class Jg {
.getName());
if (null != builtInFeatures) {
generatedBuiltInTypes.add(td.getName());
- List newFeatures = setDifference(td.getFeatures(), builtInFeatures);
+ List<FeatureDescription> newFeatures = setDifference(td.getFeatures(), builtInFeatures);
int newFeaturesSize = newFeatures.size();
if (newFeaturesSize > 0) {
int newSize = builtInFeatures.length + newFeaturesSize;
@@ -1164,7 +1157,7 @@ public class Jg {
}
/** The non importable java names. */
- private static ArrayList nonImportableJavaNames = new ArrayList(8);
+ private static ArrayList<String> nonImportableJavaNames = new ArrayList<>(8);
static {
nonImportableJavaNames.add("String");
nonImportableJavaNames.add("float");
@@ -1211,7 +1204,7 @@ public class Jg {
* @param _Type the type
* @return the collection
*/
- Collection collectImports(TypeDescription td, boolean _Type) {
+ Collection<String> collectImports(TypeDescription td, boolean _Type) {
if (_Type)
_imports.clear();
else
@@ -1405,7 +1398,7 @@ public class Jg {
String v = ", v";
// if (get_set.equals("set") && range.equals("Feature"))
// v = ", jcasType.ll_cas.ll_getFSRef(v)";
- boolean isInInt = ! (range.equals("String") || range.equals("Feature") || range.equals("JavaObject"));
+// boolean isInInt = ! (range.equals("String") || range.equals("Feature") || range.equals("JavaObject"));
String chksfx = getCheckSuffix(get_set, range);
//wrapGetIntCatchException(_FH_begin)
String featOrOffset = "wrapGetIntCatchException(_FH_" + fname + ")";
@@ -1573,7 +1566,7 @@ public class Jg {
}
}
else {
- resourceManager.setExtensionClassLoader(new UIMAClassLoader(emptyURLarray, this.getClass().getClassLoader()), true);
+ resourceManager.setExtensionClassLoader(this.getClass().getClassLoader(), true);
}
return resourceManager;
}
@@ -1587,8 +1580,8 @@ public class Jg {
*/
private TypeSystemDescription mergeTypeSystemImports(TypeSystemDescription tsd)
throws ResourceInitializationException {
- Collection tsdc = new ArrayList(1);
- tsdc.add(tsd.clone());
+ Collection<TypeSystemDescription> tsdc = new ArrayList<>(1);
+ tsdc.add((TypeSystemDescription) tsd.clone());
mergedTypesAddingFeatures.clear();
TypeSystemDescription mergedTsd = CasCreationUtils.mergeTypeSystems(tsdc,
createResourceManager(), mergedTypesAddingFeatures);
@@ -1602,8 +1595,8 @@ public class Jg {
* @param alreadyDefinedFeatures the already defined features
* @return the list
*/
- List setDifference(FeatureDescription[] newFeatures, FeatureDescription[] alreadyDefinedFeatures) {
- List result = new ArrayList();
+ List<FeatureDescription> setDifference(FeatureDescription[] newFeatures, FeatureDescription[] alreadyDefinedFeatures) {
+ List<FeatureDescription> result = new ArrayList<>();
outerLoop: for (int i = 0; i < newFeatures.length; i++) {
for (int j = 0; j < alreadyDefinedFeatures.length; j++) {
if (isSameFeatureDescription(newFeatures[i], alreadyDefinedFeatures[j]))