summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpschonbac2008-03-12 11:30:10 (EDT)
committer pschonbac2008-03-12 11:30:10 (EDT)
commit376dafa599eb7aea10afc327d2989a8c19dd87e8 (patch)
tree7e17136086417611da95ca44b7e61015c715df0a
parent3f740fe2ecaa5a2335d5f0e42b0a27669ed6ca86 (diff)
downloadorg.eclipse.xpand-376dafa599eb7aea10afc327d2989a8c19dd87e8.zip
org.eclipse.xpand-376dafa599eb7aea10afc327d2989a8c19dd87e8.tar.gz
org.eclipse.xpand-376dafa599eb7aea10afc327d2989a8c19dd87e8.tar.bz2
NEW - bug 222366: XtendComponent locks resource unnecessarily
https://bugs.eclipse.org/bugs/show_bug.cgi?id=222366
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java201
1 files changed, 109 insertions, 92 deletions
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java
index 70d7e05..aeba251 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java
@@ -33,86 +33,103 @@ import org.eclipse.xtend.expression.Variable;
public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
- private final Log log = LogFactory.getLog(getClass());
-
String extensionFile = null;
-
- private List<String> extensionAdvices = new ArrayList<String>();
- @Override
- public void addExtensionAdvice(String extensionAdvices) {
- if ( !this.extensionAdvices.contains(extensionAdvices) )
- this.extensionAdvices.add( extensionAdvices );
- }
+ private final Log log = LogFactory.getLog(getClass());
+
+ private final List<String> extensionAdvices = new ArrayList<String>();
- /** Stores the value of the 'invoke' property. Needed for error analysis. */
+ /** Stores the value of the 'invoke' property. Needed for error analysis. */
private String invokeExpression;
+
private String expression = null;
private String collectProfileSummary = null;
+
private String verboseProfileFilename = null;
-
- public void setCollectProfileSummary (String c) {
- collectProfileSummary = c;
- }
-
- public void setVerboseProfileFilename (String f) {
- verboseProfileFilename = f;
- }
-
+ private String outputSlot = WorkflowContext.DEFAULT_SLOT;
+
@Override
- public String getLogMessage() {
- return "executing '"+extensionFile+"'";
+ public void addExtensionAdvice(final String extensionAdvices) {
+ if (!this.extensionAdvices.contains(extensionAdvices))
+ this.extensionAdvices.add(extensionAdvices);
}
-
- public void setInvoke(final String invoke) {
- invokeExpression = invoke;
- final int i = invoke.lastIndexOf("::");
- if (i != -1) {
- extensionFile = invoke.substring(0, i);
- expression = invoke.substring(i + 2);
- } else {
- expression = invoke;
+
+ @Override
+ public void checkConfiguration(final Issues issues) {
+ super.checkConfiguration(issues);
+
+ // Try to create detailed error message (see Bug#172567)
+ final String compPrefix = getId() != null ? getId() + ": " : "";
+
+ if (invokeExpression == null || invokeExpression.trim().length() == 0) {
+ issues.addError(compPrefix + "Property 'invoke' not specified.");
+ return;
+ }
+ if (extensionFile == null) {
+ issues
+ .addError(compPrefix
+ + "Error parsing property 'invoke': Could not extract name of the extension file.");
+ return;
+ }
+ if (expression == null) {
+ issues
+ .addError(compPrefix
+ + "Property 'invoke' not specified properly. AbstractExtension file '"
+ + extensionFile + "' not found.");
+ return;
+ }
+ if (expression == null) {
+ issues
+ .addError(compPrefix
+ + "Error parsing property 'invoke': Could not extract the expression to invoke in extension file '"
+ + extensionFile + "'.");
+ return;
}
- }
- private String outputSlot = WorkflowContext.DEFAULT_SLOT;
+ }
- public void setOutputSlot(final String outputSlot) {
- this.outputSlot = outputSlot;
+ @Override
+ public String getLogMessage() {
+ return "executing '" + extensionFile + "'";
}
-
-
@Override
- public void invokeInternal2(final WorkflowContext ctx, final ProgressMonitor monitor, final Issues issues) {
-
+ public void invokeInternal2(final WorkflowContext ctx,
+ final ProgressMonitor monitor, final Issues issues) {
+
final InputStream in = getExtFileIS();
if (in == null) {
- issues.addError("Cannot find extension file: "+extensionFile);
+ issues.addError("Cannot find extension file: " + extensionFile);
return;
}
-
+
+ try {
+ in.close();
+ } catch (final IOException e) {
+ log.error("could not close extension file", e);
+ }
+
OutputStream verboseProfileOutputStream = null;
if (verboseProfileFilename != null) {
try {
- verboseProfileOutputStream = new BufferedOutputStream (new FileOutputStream (verboseProfileFilename));
- ProfileCollector.getInstance().setDetailedLoggingWriter(verboseProfileOutputStream);
- }
- catch (IOException exc) {
+ verboseProfileOutputStream =
+ new BufferedOutputStream(new FileOutputStream(
+ verboseProfileFilename));
+ ProfileCollector.getInstance().setDetailedLoggingWriter(
+ verboseProfileOutputStream);
+ } catch (final IOException exc) {
log.warn("could not open profiling log file", exc);
}
}
-
ExecutionContextImpl ec = getExecutionContext(ctx);
-
- for (String advice : extensionAdvices) {
+
+ for (final String advice : extensionAdvices) {
final String[] allAdvices = advice.split(",");
- for (int i = 0; i < allAdvices.length; i++) {
- final String string = allAdvices[i];
+ for (final String string : allAdvices) {
ec.registerExtensionAdvices(string.trim());
}
}
@@ -124,76 +141,76 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
return name;
}
- public void setFullyQualifiedName(final String fqn) {
- name = fqn;
+ public String[] getImportedExtensions() {
+ return new String[] { extensionFile };
}
public String[] getImportedNamespaces() {
return new String[0];
}
- public String[] getImportedExtensions() {
- return new String[] { extensionFile };
+ public void setFullyQualifiedName(final String fqn) {
+ name = fqn;
}
});
final String[] slots = ctx.getSlotNames();
- for (int i = 0; i < slots.length; i++) {
- ec = (ExecutionContextImpl) ec.cloneWithVariable(new Variable(slots[i], ctx.get(slots[i])));
+ for (final String element : slots) {
+ ec =
+ (ExecutionContextImpl) ec.cloneWithVariable(new Variable(
+ element, ctx.get(element)));
}
- if (monitor!=null) {
- ec.setMonitor(monitor);
+ if (monitor != null) {
+ ec.setMonitor(monitor);
}
-
+
final Object result = new ExpressionFacade(ec).evaluate(expression);
ctx.set(outputSlot, result);
ProfileCollector.getInstance().finish();
- if ("true".equalsIgnoreCase(this.collectProfileSummary)) {
- log.info ("profiling info: \n" + ProfileCollector.getInstance().toString());
+ if ("true".equalsIgnoreCase(collectProfileSummary)) {
+ log.info("profiling info: \n"
+ + ProfileCollector.getInstance().toString());
}
-
+
if (verboseProfileOutputStream != null) {
try {
- verboseProfileOutputStream.close ();
- }
- catch (IOException exc) {
+ verboseProfileOutputStream.close();
+ } catch (final IOException exc) {
log.warn("problem closing profile log file", exc);
}
}
}
- private InputStream getExtFileIS() {
- final InputStream in = ResourceLoaderFactory.createResourceLoader().getResourceAsStream(
- extensionFile.replace("::", "/")+".ext");
- return in;
+ public void setCollectProfileSummary(final String c) {
+ collectProfileSummary = c;
}
- @Override
- public void checkConfiguration(final Issues issues) {
- super.checkConfiguration(issues);
-
- // Try to create detailed error message (see Bug#172567)
- String compPrefix = getId()!=null ? getId()+": " : "";
-
- if (invokeExpression==null || invokeExpression.trim().length()==0) {
- issues.addError(compPrefix+"Property 'invoke' not specified.");
- return;
- }
- if (extensionFile==null) {
- issues.addError(compPrefix+"Error parsing property 'invoke': Could not extract name of the extension file.");
- return;
- }
- if (getExtFileIS()==null || expression == null) {
- issues.addError(compPrefix+"Property 'invoke' not specified properly. AbstractExtension file '"+extensionFile+"' not found.");
- return;
- }
- if (expression==null) {
- issues.addError(compPrefix+"Error parsing property 'invoke': Could not extract the expression to invoke in extension file '"+extensionFile+"'.");
- return;
+ public void setInvoke(final String invoke) {
+ invokeExpression = invoke;
+ final int i = invoke.lastIndexOf("::");
+ if (i != -1) {
+ extensionFile = invoke.substring(0, i);
+ expression = invoke.substring(i + 2);
+ } else {
+ expression = invoke;
}
-
}
-
+ public void setOutputSlot(final String outputSlot) {
+ this.outputSlot = outputSlot;
+ }
+
+ public void setVerboseProfileFilename(final String f) {
+ verboseProfileFilename = f;
+ }
+
+ private InputStream getExtFileIS() {
+ final InputStream in =
+ ResourceLoaderFactory.createResourceLoader()
+ .getResourceAsStream(
+ extensionFile.replace("::", "/") + ".ext");
+ return in;
+ }
+
}