Author: schor
Date: Mon May 14 13:53:33 2012
New Revision: 1338200
URL: http://svn.apache.org/viewvc?rev=1338200&view=rev
Log:
[UIMA-1176] Add flag (in preferences, and locally in editor instance) to limit
JCasGen generation to just those types defined in the "project" (rypically an
Eclipse project).
Modified:
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/PreferencePage.java
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditorContributor.java
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/TypeSection.java
uima/uimaj/trunk/uimaj-ep-configurator/src/main/resources/org/apache/uima/taeconfigurator/messages.properties
uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java
uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/jcasgen/jcasgenpPluginResources.properties
Modified:
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/PreferencePage.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/PreferencePage.java?rev=1338200&r1=1338199&r2=1338200&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/PreferencePage.java
(original)
+++
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/PreferencePage.java
Mon May 14 13:53:33 2012
@@ -29,6 +29,8 @@ import org.eclipse.ui.IWorkbenchPreferen
public class PreferencePage extends FieldEditorPreferencePage implements
IWorkbenchPreferencePage {
public static final String P_JCAS = "org.apache.uima.cde.autojcasgen";
+
+ public static final String P_JCAS_LIMIT_TO_PROJECT_SCOPE =
"org.apache.uima.cde.jcasgen.limittoprojectscope";
public static final String P_SHOW_FULLY_QUALIFIED_NAMES =
"org.apache.uima.cde.qualifiedtypes";
@@ -62,6 +64,9 @@ public class PreferencePage extends Fiel
addField(new BooleanFieldEditor(P_JCAS, "&Automatically run JCasGen when
Types change",
getFieldEditorParent()));
+ addField(new BooleanFieldEditor(P_JCAS_LIMIT_TO_PROJECT_SCOPE, "&Limit
JCasGen to types defined in this project",
+ getFieldEditorParent()));
+
addField(new BooleanFieldEditor(P_SHOW_FULLY_QUALIFIED_NAMES, "&Show fully
qualified names",
getFieldEditorParent()));
Modified:
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java?rev=1338200&r1=1338199&r2=1338200&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java
(original)
+++
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java
Mon May 14 13:53:33 2012
@@ -221,7 +221,7 @@ public class MultiPageEditor extends For
private TypeSystemDescription mergedTypeSystemDescription = null;
- private Map mergedTypesAddingFeatures = new TreeMap();
+ private Map<String, Set<String>> mergedTypesAddingFeatures = new
TreeMap<String, Set<String>>();
private TypeSystemDescription importedTypeSystemDescription = null;
@@ -360,6 +360,16 @@ public class MultiPageEditor extends For
return isContextLoaded;
}
+ private boolean limitJCasGenToProjectScope =
MultiPageEditorContributor.getLimitJCasGenToProjectScope();
+
+ public boolean getLimitJCasGenToProjectScope() {
+ return limitJCasGenToProjectScope;
+ }
+
+ public void setLimitJCasGenToProjectScope(boolean v) {
+ limitJCasGenToProjectScope = v;
+ }
+
/**
* Descriptor Types
*/
@@ -2103,7 +2113,10 @@ public class MultiPageEditor extends For
public void run(IProgressMonitor progressMonitor) {
try {
jg.mainForCde(new MergerImpl(), new
JCasGenProgressMonitor(progressMonitor),
- jCasGenThrower, inputFile, outputDirectory, types,
(CASImpl) getCurrentView());
+ jCasGenThrower, inputFile, outputDirectory, types,
(CASImpl) getCurrentView(),
+ getProject().getLocationURI().getPath(),
+ limitJCasGenToProjectScope,
+ mergedTypesAddingFeatures);
} catch (IOException e) {
Utility.popMessage(Messages.getString("MultiPageEditor.25"),
//$NON-NLS-1$
Messages.getString("MultiPageEditor.26") //$NON-NLS-1$
@@ -3004,4 +3017,5 @@ public class MultiPageEditor extends For
"would have come from the remote components, had they been
available.\n\n" +
sb, MessageDialog.WARNING);
}
+
}
Modified:
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditorContributor.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditorContributor.java?rev=1338200&r1=1338199&r2=1338200&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditorContributor.java
(original)
+++
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditorContributor.java
Mon May 14 13:53:33 2012
@@ -55,6 +55,8 @@ public class MultiPageEditorContributor
private IEditorPart activeEditorPart;
Action autoJCasAction;
+
+ Action limitJCasGenToProject;
Action qualifiedTypesAction;
@@ -168,6 +170,18 @@ public class MultiPageEditorContributor
prefs.setValue(PreferencePage.P_JCAS, bAutoJCasGen); //$NON-NLS-1$
}
};
+
+ limitJCasGenToProject = new Action () {
+ // The run action is simply to toggle the setting in the prefs page, and
+ // to update the checked status to correspond to that
+ public void run() {
+ TAEConfiguratorPlugin plugin = TAEConfiguratorPlugin.getDefault();
+ Preferences prefs = plugin.getPluginPreferences();
+ boolean bJCasLimit =
!prefs.getBoolean(PreferencePage.P_JCAS_LIMIT_TO_PROJECT_SCOPE); //$NON-NLS-1$
+ limitJCasGenToProject.setChecked(bJCasLimit);
+ prefs.setValue(PreferencePage.P_JCAS_LIMIT_TO_PROJECT_SCOPE,
bJCasLimit); //$NON-NLS-1$
+ }
+ };
runJCasGenAction = new Action() {
public void run() {
@@ -201,6 +215,9 @@ public class MultiPageEditorContributor
autoJCasAction.setText(Messages.getString("MultiPageEditorContributor.autoGenJCas"));
//$NON-NLS-1$
autoJCasAction.setChecked(getAutoJCasGen()); //$NON-NLS-1$
+
+
limitJCasGenToProject.setText(Messages.getString("MultiPageEditorContributor.limitJCasGenToProjectScope"));
+ limitJCasGenToProject.setChecked(getLimitJCasGenToProjectScope());
qualifiedTypesAction.setText(Messages.getString("MultiPageEditorContributor.showFullNames"));
//$NON-NLS-1$
qualifiedTypesAction.setChecked(getUseQualifiedTypes()); //$NON-NLS-1$
@@ -217,6 +234,7 @@ public class MultiPageEditorContributor
menu.add(settingsMenu);
settingsMenu.add(autoJCasAction);
settingsMenu.add(qualifiedTypesAction);
+ settingsMenu.add(limitJCasGenToProject);
}
public static boolean getAutoJCasGen() {
@@ -226,6 +244,10 @@ public class MultiPageEditorContributor
public static boolean getUseQualifiedTypes() {
return getUimaPrefBoolean(PreferencePage.P_SHOW_FULLY_QUALIFIED_NAMES,
true);
}
+
+ public static boolean getLimitJCasGenToProjectScope() {
+ return getUimaPrefBoolean(PreferencePage.P_JCAS_LIMIT_TO_PROJECT_SCOPE,
false);
+ }
public static int getXMLindent() {
return getUimaPrefInt(PreferencePage.P_XML_TAB_SPACES, 2);
Modified:
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/TypeSection.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/TypeSection.java?rev=1338200&r1=1338199&r2=1338200&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/TypeSection.java
(original)
+++
uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/TypeSection.java
Mon May 14 13:53:33 2012
@@ -63,6 +63,7 @@ import org.apache.uima.resource.metadata
import org.apache.uima.taeconfigurator.InternalErrorCDE;
import org.apache.uima.taeconfigurator.TAEConfiguratorPlugin;
import org.apache.uima.taeconfigurator.editors.MultiPageEditor;
+import org.apache.uima.taeconfigurator.editors.MultiPageEditorContributor;
import
org.apache.uima.taeconfigurator.editors.ui.dialogs.AddAllowedValueDialog;
import org.apache.uima.taeconfigurator.editors.ui.dialogs.AddFeatureDialog;
import org.apache.uima.taeconfigurator.editors.ui.dialogs.AddTypeDialog;
@@ -114,6 +115,8 @@ public class TypeSection extends Abstrac
private Button exportButton;
+ private Button limitJCasGenToProjectScope;
+
// private TypeSystemDescription tsdLocal; // for this descriptor, no imports
private static final boolean ALLOWED = true;
@@ -160,6 +163,11 @@ public class TypeSection extends Abstrac
spacer(buttonContainer);
jcasGenButton = newPushButton(buttonContainer, "JCasGen",
"Click here to run JCasGen on this type system.");
+ limitJCasGenToProjectScope = newCheckBox(buttonContainer, "limited",
+ "JCasGen only those types defined within this project" +
+ "\n You can change the default in UIMA prefs or in the UIMA menu");
+ boolean defaultValue = editor.getLimitJCasGenToProjectScope();
+ limitJCasGenToProjectScope.setSelection(defaultValue);
}
/*
@@ -305,6 +313,8 @@ public class TypeSection extends Abstrac
refresh();
} else if (event.widget == jcasGenButton) {
editor.doJCasGenChkSrc(null);
+ } else if (event.widget == limitJCasGenToProjectScope) {
+
editor.setLimitJCasGenToProjectScope(limitJCasGenToProjectScope.getSelection());
} else if (event.type == SWT.MouseHover) {
handleHover(event);
}
Modified:
uima/uimaj/trunk/uimaj-ep-configurator/src/main/resources/org/apache/uima/taeconfigurator/messages.properties
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-configurator/src/main/resources/org/apache/uima/taeconfigurator/messages.properties?rev=1338200&r1=1338199&r2=1338200&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-ep-configurator/src/main/resources/org/apache/uima/taeconfigurator/messages.properties
(original)
+++
uima/uimaj/trunk/uimaj-ep-configurator/src/main/resources/org/apache/uima/taeconfigurator/messages.properties
Mon May 14 13:53:33 2012
@@ -103,6 +103,7 @@ MultiPageEditor.unrecognizedDescType=Unr
MultiPageEditor.XMLerrorInDescriptor=The descriptor has one or more XML
errors, and can''t be parsed. Please fix in the source editor.
MultiPageEditor.XMLerrorInDescriptorTitle=XML Error in Descriptor
MultiPageEditorContributor.autoGenJCas=Auto generate JCAS source java files
when changing types
+MultiPageEditorContributor.limitJCasGenToProjectScope=Generate JCasGen classes
only for types defined within the local project scope
MultiPageEditorContributor.showFullNames=Display fully qualified type names
MultiResourceSelectionDialog.BrowseFileSys=Browse the file system...
MultiResourceSelectionDialog.Or=OR
Modified:
uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java?rev=1338200&r1=1338199&r2=1338200&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java
(original)
+++
uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/jcasgen/Jg.java
Mon May 14 13:53:33 2012
@@ -29,6 +29,8 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -275,7 +277,11 @@ public class Jg {
private Type tcasAnnotationType;
- private Map mergedTypesAddingFeatures = new TreeMap(); // a Map of types and
the xml files that were merged to create them
+ private Map<String, Set<String>> mergedTypesAddingFeatures = new
TreeMap<String, Set<String>>(); // a Map of types and the xml files that were
merged to create them
+
+ private String projectPathDir;
+
+ private boolean limitJCasGenToProjectScope;
public Jg() { // default constructor
}
@@ -342,29 +348,54 @@ public class Jg {
public void mainForCde(IMerge aMerger, IProgressMonitor aProgressMonitor,
IError aError,
String inputFile, String outputDirectory, TypeDescription[] tds,
CASImpl aCas)
throws IOException {
+ mainForCde(aMerger, aProgressMonitor, aError,
+ inputFile, outputDirectory, tds, aCas, "", false, null);
+ }
+
+ 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)
+ throws IOException {
try {
// Generate type classes by using DEFAULT templates
mainGenerateAllTypesFromTemplates(aMerger, aProgressMonitor, aError,
inputFile,
- outputDirectory, tds, aCas, JCasTypeTemplate.class,
JCas_TypeTemplate.class);
+ outputDirectory, tds, aCas, JCasTypeTemplate.class,
JCas_TypeTemplate.class,
+ projectPathDir, limitJCasGenToProjectScope,
mergedTypesAddingFeatures);
// convert thrown things to IOExceptions to avoid changing API for this
// FIXME later
} catch (InstantiationException e) {
throw new IOException(e.toString());
} catch (IllegalAccessException e) {
throw new IOException(e.toString());
- }
+ }
}
// 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
+ throws IOException, InstantiationException, IllegalAccessException {
+ mainGenerateAllTypesFromTemplates(aMerger, aProgressMonitor,
+ aError, inputFile, outputDirectory, tds, aCas,
+ jcasTypeClass, jcas_TypeClass, "", false, null);
+ }
+
+ 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
+ Class jcas_TypeClass,
+ String projectPathDir, boolean limitJCasGenToProjectScope,
+ Map<String, Set<String>> mergedTypesAddingFeatures) // 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;
// Generate type classes by using SPECIFIED templates
generateAllTypesFromTemplates(outputDirectory, tds, aCas, jcasTypeClass,
jcas_TypeClass);
@@ -394,6 +425,15 @@ public class Jg {
}
}
+ /**
+ * Arguments are:
+ * -jcasgeninput xxxx
+ * -jcasgenoutput xxxx
+ * -jcasgenclasspath xxxx
+ *
+ * @param arguments
+ * @return
+ */
public int main1(String[] arguments) {
boolean hadError = false;
try {
@@ -409,6 +449,9 @@ public class Jg {
TypeSystemDescription typeSystemDescription = null;
TypeDescription[] tds = null;
+
+ projectPathDir = ""; // init to default value
+ limitJCasGenToProjectScope = false;
for (int i = 0; i < arguments.length - 1; i++) {
if (arguments[i].equalsIgnoreCase("-jcasgeninput")) {
@@ -419,10 +462,16 @@ public class Jg {
outputDirectory = arguments[++i];
continue;
}
+ // This next is not apparently used 5/2012 schor
if (arguments[i].equalsIgnoreCase("=jcasgenclasspath")) {
classPath = arguments[++i];
continue;
}
+ if (arguments[i].equalsIgnoreCase("-limitToDirectory")) {
+ projectPathDir = arguments[++i];
+ limitJCasGenToProjectScope = (projectPathDir.length() > 0);
+ continue;
+ }
}
xmlSourceFileName = inputFile.replaceAll("\\\\", "/");
@@ -580,6 +629,19 @@ public class Jg {
continue;
if (td.getSupertypeName().equals("uima.cas.String"))
continue;
+ if (limitJCasGenToProjectScope &&
+ isOutOfScope(td, projectPathDir)) {
+ Set<String> mt = mergedTypesAddingFeatures.get(td.getName());
+ if (null == mt) {
+ continue;
+ }
+ StringBuilder sb = new StringBuilder("\n");
+ for (String p : mt) {
+ sb.append(" ").append(p).append('\n');
+ }
+ error.newError(IError.ERROR, getString("limitingButTypeWasExtended",
new Object[] { td.getName(), sb.toString()}), null);
+ continue;
+ }
// if the type is built-in - augment it with the built-in's features
FeatureDescription[] builtInFeatures = (FeatureDescription[])
extendableBuiltInTypes.get(td
@@ -648,6 +710,41 @@ public class Jg {
*/
/**
+ * return true if td is not defined in this project, of
+ * it is defined, but is also in merged and any of the other
+ * merged urls are not defined in this project
+ */
+ private boolean isOutOfScope(TypeDescription td, String projectDirPath) {
+ URI typeDefinitionUri;
+ try {
+ typeDefinitionUri = new URI (td.getSourceUrlString());
+ } catch (URISyntaxException e) {
+ return true; // may be overkill - but if td's source cant be parsed, ...
likely out of project
+ }
+ String tdPath = typeDefinitionUri.getPath();
+ boolean r = !tdPath.startsWith(projectDirPath);
+ if (r) {
+ return true;
+ }
+ Set<String> mergedPaths = mergedTypesAddingFeatures.get(td.getName());
+ if (null != mergedPaths) {
+ for (String p : mergedPaths) {
+ URI tempURI;
+ try {
+ tempURI = new URI(p);
+ } catch (URISyntaxException e) {
+ return true; //because a merged path is out of the project
+ }
+ String tempPath = tempURI.getPath();
+ if (!tempPath.startsWith(projectDirPath)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
* Generate type classes from the specified templates
* @param td TypeDescription object
* @param outputDirectory output directory
Modified:
uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/jcasgen/jcasgenpPluginResources.properties
URL:
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/jcasgen/jcasgenpPluginResources.properties?rev=1338200&r1=1338199&r2=1338200&view=diff
==============================================================================
---
uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/jcasgen/jcasgenpPluginResources.properties
(original)
+++
uima/uimaj/trunk/uimaj-tools/src/main/resources/org/apache/uima/tools/jcasgen/jcasgenpPluginResources.properties
Mon May 14 13:53:33 2012
@@ -37,3 +37,4 @@ pkgMissing = The CAS Type ''{0}'' is mis
nullPtr = Null Pointer exception: Insure the CAS type name is qualified by
having a required namespace, for type ''{0}''.
InstantiationException = Unexpected InstantiationException
IllegalAccessException = Unexpected IllegalAccessException
+limitingButTypeWasExtended = JCasGen being run in mode to limit generation to
locally defined types, but type ''{0}'' from sources {1} was merged. The
generation operation is stopped.