Index: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/generator/ApplicationGenerator.java |
=================================================================== |
--- editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/generator/ApplicationGenerator.java (revision 3100) |
+++ editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/generator/ApplicationGenerator.java (working copy) |
@@ -47,6 +47,8 @@ |
private String applicationLocation; |
+ private boolean isWebApplication; |
+ |
private IFile iApplicationFile = null; |
/** |
@@ -71,31 +73,13 @@ |
} |
String applicationFileName = appendIfNoExtension(applicationName, Extensions.DOT_DART); |
+ File applicationFile; |
+ if (isWebApplication) { |
+ applicationFile = generateWebApplication(monitor, applicationFileName); |
+ } else { |
+ applicationFile = generateCommandLineApp(monitor, applicationFileName); |
+ } |
- SubMonitor subMonitor = SubMonitor.convert(monitor, |
- GeneratorMessages.ApplicationGenerator_message, 100); |
- String className = applicationFileName.substring(0, applicationFileName.indexOf('.')); |
- final HashMap<String, String> substitutions = new HashMap<String, String>(); |
- substitutions.put("className", className); //$NON-NLS-1$ |
- substitutions.put("extends", ""); //$NON-NLS-1$ //$NON-NLS-2$ |
- substitutions.put("implements", ""); //$NON-NLS-1$ //$NON-NLS-2$ |
- |
- File applicationFile = getSystemFile(applicationFileName); |
- execute("generated-dart-class-main.txt", applicationFile, substitutions, monitor); //$NON-NLS-1$ |
- subMonitor.newChild(100); |
- subMonitor.done(); |
- |
- // html file |
- subMonitor = SubMonitor.convert(monitor, |
- GeneratorMessages.ApplicationGenerator_htmlFileMessage, 100); |
- String htmlFileName = appendIfNoExtension(applicationName, HTML_FILENAME_EXTENSION); |
- File iHtmlFile = getSystemFile(htmlFileName); |
- substitutions.put("title", className); |
- substitutions.put("dartPath", applicationFileName + "." + JavascriptBackend.EXTENSION_APP_JS); |
- execute("generated-html.txt", iHtmlFile, substitutions, monitor); //$NON-NLS-1$ |
- subMonitor.newChild(100); |
- subMonitor.done(); |
- |
DartLibrary library = DartCore.openLibrary(applicationFile, monitor); |
if (library != null) { |
library.setTopLevel(true); |
@@ -126,6 +110,10 @@ |
return new File(applicationLocation + File.separator + fileName); |
} |
+ public boolean isWebApplication() { |
+ return isWebApplication; |
+ } |
+ |
public void setApplicationLocation(String applicationLocation) { |
this.applicationLocation = applicationLocation; |
} |
@@ -134,6 +122,10 @@ |
this.applicationName = applicationName; |
} |
+ public void setWebApplication(boolean isWebApplication) { |
+ this.isWebApplication = isWebApplication; |
+ } |
+ |
/** |
* Checks that the library location and file name are both valid. |
* |
@@ -148,6 +140,51 @@ |
return status; |
} |
+ private File generateCommandLineApp(IProgressMonitor monitor, String applicationFileName) |
+ throws CoreException { |
+ SubMonitor subMonitor = SubMonitor.convert(monitor, |
+ GeneratorMessages.ApplicationGenerator_message, 100); |
+ |
+ final HashMap<String, String> substitutions = new HashMap<String, String>(); |
+ |
+ File applicationFile = getSystemFile(applicationFileName); |
+ execute("generated-dart-server.txt", applicationFile, substitutions, monitor); //$NON-NLS-1$ |
+ subMonitor.newChild(100); |
+ subMonitor.done(); |
+ |
+ return applicationFile; |
+ } |
+ |
+ private File generateWebApplication(IProgressMonitor monitor, String applicationFileName) |
+ throws CoreException { |
+ SubMonitor subMonitor = SubMonitor.convert(monitor, |
+ GeneratorMessages.ApplicationGenerator_message, 100); |
+ |
+ String className = applicationFileName.substring(0, applicationFileName.indexOf('.')); |
+ |
+ final HashMap<String, String> substitutions = new HashMap<String, String>(); |
+ substitutions.put("className", className); //$NON-NLS-1$ |
+ substitutions.put("extends", ""); //$NON-NLS-1$ //$NON-NLS-2$ |
+ substitutions.put("implements", ""); //$NON-NLS-1$ //$NON-NLS-2$ |
+ |
+ File applicationFile = getSystemFile(applicationFileName); |
+ execute("generated-dart-class-main.txt", applicationFile, substitutions, monitor); //$NON-NLS-1$ |
+ subMonitor.newChild(100); |
+ subMonitor.done(); |
+ |
+ // html file |
+ subMonitor = SubMonitor.convert(monitor, |
+ GeneratorMessages.ApplicationGenerator_htmlFileMessage, 100); |
+ String htmlFileName = appendIfNoExtension(applicationName, HTML_FILENAME_EXTENSION); |
+ File iHtmlFile = getSystemFile(htmlFileName); |
+ substitutions.put("title", className); |
+ substitutions.put("dartPath", applicationFileName + "." + JavascriptBackend.EXTENSION_APP_JS); |
+ execute("generated-html.txt", iHtmlFile, substitutions, monitor); //$NON-NLS-1$ |
+ subMonitor.newChild(100); |
+ subMonitor.done(); |
+ return applicationFile; |
+ } |
+ |
/** |
* Validate the application location. |
* |