Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/generator/ApplicationGenerator.java

Issue 9120017: modified New Application Wizard to allow for generation of web/command line application (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011, the Dart project authors. 2 * Copyright (c) 2011, the Dart project authors.
3 * 3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at 5 * in compliance with the License. You may obtain a copy of the License at
6 * 6 *
7 * http://www.eclipse.org/legal/epl-v10.html 7 * http://www.eclipse.org/legal/epl-v10.html
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
(...skipping 29 matching lines...) Expand all
40 public class ApplicationGenerator extends AbstractGenerator { 40 public class ApplicationGenerator extends AbstractGenerator {
41 41
42 public static final String HTML_FILENAME_EXTENSION = ".html"; //$NON-NLS-1$ 42 public static final String HTML_FILENAME_EXTENSION = ".html"; //$NON-NLS-1$
43 43
44 public static final String DESCRIPTION = GeneratorMessages.ApplicationGenerato r_description; 44 public static final String DESCRIPTION = GeneratorMessages.ApplicationGenerato r_description;
45 45
46 private String applicationName; 46 private String applicationName;
47 47
48 private String applicationLocation; 48 private String applicationLocation;
49 49
50 private boolean isWebApplication;
51
50 private IFile iApplicationFile = null; 52 private IFile iApplicationFile = null;
51 53
52 /** 54 /**
53 * Construct a new instance. 55 * Construct a new instance.
54 */ 56 */
55 public ApplicationGenerator() { 57 public ApplicationGenerator() {
56 } 58 }
57 59
58 /** 60 /**
59 * Create the folder to contain the library and the library declaration file 61 * Create the folder to contain the library and the library declaration file
60 * 62 *
61 * @param monitor the monitor to which activity is reported 63 * @param monitor the monitor to which activity is reported
62 */ 64 */
63 @Override 65 @Override
64 public void execute(IProgressMonitor monitor) throws CoreException { 66 public void execute(IProgressMonitor monitor) throws CoreException {
65 // Sanity Check 67 // Sanity Check
66 Assert.isNotNull(applicationName); 68 Assert.isNotNull(applicationName);
67 Assert.isNotNull(applicationLocation); 69 Assert.isNotNull(applicationLocation);
68 IStatus status = validate(); 70 IStatus status = validate();
69 if (status.getSeverity() == IStatus.ERROR) { 71 if (status.getSeverity() == IStatus.ERROR) {
70 throw new IllegalStateException(status.getMessage()); 72 throw new IllegalStateException(status.getMessage());
71 } 73 }
72 74
73 String applicationFileName = appendIfNoExtension(applicationName, Extensions .DOT_DART); 75 String applicationFileName = appendIfNoExtension(applicationName, Extensions .DOT_DART);
74 76 File applicationFile;
75 SubMonitor subMonitor = SubMonitor.convert(monitor, 77 if (isWebApplication) {
76 GeneratorMessages.ApplicationGenerator_message, 100); 78 applicationFile = generateWebApplication(monitor, applicationFileName);
77 String className = applicationFileName.substring(0, applicationFileName.inde xOf('.')); 79 } else {
78 final HashMap<String, String> substitutions = new HashMap<String, String>(); 80 applicationFile = generateCommandLineApp(monitor, applicationFileName);
79 substitutions.put("className", className); //$NON-NLS-1$ 81 }
80 substitutions.put("extends", ""); //$NON-NLS-1$ //$NON-NLS-2$
81 substitutions.put("implements", ""); //$NON-NLS-1$ //$NON-NLS-2$
82
83 File applicationFile = getSystemFile(applicationFileName);
84 execute("generated-dart-class-main.txt", applicationFile, substitutions, mon itor); //$NON-NLS-1$
85 subMonitor.newChild(100);
86 subMonitor.done();
87
88 // html file
89 subMonitor = SubMonitor.convert(monitor,
90 GeneratorMessages.ApplicationGenerator_htmlFileMessage, 100);
91 String htmlFileName = appendIfNoExtension(applicationName, HTML_FILENAME_EXT ENSION);
92 File iHtmlFile = getSystemFile(htmlFileName);
93 substitutions.put("title", className);
94 substitutions.put("dartPath", applicationFileName + "." + JavascriptBackend. EXTENSION_APP_JS);
95 execute("generated-html.txt", iHtmlFile, substitutions, monitor); //$NON-NLS -1$
96 subMonitor.newChild(100);
97 subMonitor.done();
98 82
99 DartLibrary library = DartCore.openLibrary(applicationFile, monitor); 83 DartLibrary library = DartCore.openLibrary(applicationFile, monitor);
100 if (library != null) { 84 if (library != null) {
101 library.setTopLevel(true); 85 library.setTopLevel(true);
102 } 86 }
103 IFile[] files = ResourceUtil.getResources(applicationFile); 87 IFile[] files = ResourceUtil.getResources(applicationFile);
104 iApplicationFile = files[0]; 88 iApplicationFile = files[0];
105 89
106 } 90 }
107 91
(...skipping 11 matching lines...) Expand all
119 * 103 *
120 * @return the file or <code>null</code> if a file cannot be created 104 * @return the file or <code>null</code> if a file cannot be created
121 */ 105 */
122 106
123 public File getSystemFile(String fileName) { 107 public File getSystemFile(String fileName) {
124 // Fail fast for null elements 108 // Fail fast for null elements
125 Assert.isNotNull(fileName); 109 Assert.isNotNull(fileName);
126 return new File(applicationLocation + File.separator + fileName); 110 return new File(applicationLocation + File.separator + fileName);
127 } 111 }
128 112
113 public boolean isWebApplication() {
114 return isWebApplication;
115 }
116
129 public void setApplicationLocation(String applicationLocation) { 117 public void setApplicationLocation(String applicationLocation) {
130 this.applicationLocation = applicationLocation; 118 this.applicationLocation = applicationLocation;
131 } 119 }
132 120
133 public void setApplicationName(String applicationName) { 121 public void setApplicationName(String applicationName) {
134 this.applicationName = applicationName; 122 this.applicationName = applicationName;
135 } 123 }
136 124
125 public void setWebApplication(boolean isWebApplication) {
126 this.isWebApplication = isWebApplication;
127 }
128
137 /** 129 /**
138 * Checks that the library location and file name are both valid. 130 * Checks that the library location and file name are both valid.
139 * 131 *
140 * @see #validateLocation() 132 * @see #validateLocation()
141 * @see #validateName() 133 * @see #validateName()
142 * @return IStatus corresponding to any errors/warnings that would make the li b/app invalid 134 * @return IStatus corresponding to any errors/warnings that would make the li b/app invalid
143 */ 135 */
144 @Override 136 @Override
145 public IStatus validate() { 137 public IStatus validate() {
146 IStatus status = StatusUtil.getMoreSevere(Status.OK_STATUS, validateLocation ()); 138 IStatus status = StatusUtil.getMoreSevere(Status.OK_STATUS, validateLocation ());
147 status = StatusUtil.getMoreSevere(status, validateName()); 139 status = StatusUtil.getMoreSevere(status, validateName());
148 return status; 140 return status;
149 } 141 }
150 142
143 private File generateCommandLineApp(IProgressMonitor monitor, String applicati onFileName)
144 throws CoreException {
145 SubMonitor subMonitor = SubMonitor.convert(monitor,
146 GeneratorMessages.ApplicationGenerator_message, 100);
147
148 final HashMap<String, String> substitutions = new HashMap<String, String>();
149
150 File applicationFile = getSystemFile(applicationFileName);
151 execute("generated-dart-server.txt", applicationFile, substitutions, monitor ); //$NON-NLS-1$
152 subMonitor.newChild(100);
153 subMonitor.done();
154
155 return applicationFile;
156 }
157
158 private File generateWebApplication(IProgressMonitor monitor, String applicati onFileName)
159 throws CoreException {
160 SubMonitor subMonitor = SubMonitor.convert(monitor,
161 GeneratorMessages.ApplicationGenerator_message, 100);
162
163 String className = applicationFileName.substring(0, applicationFileName.inde xOf('.'));
164
165 final HashMap<String, String> substitutions = new HashMap<String, String>();
166 substitutions.put("className", className); //$NON-NLS-1$
167 substitutions.put("extends", ""); //$NON-NLS-1$ //$NON-NLS-2$
168 substitutions.put("implements", ""); //$NON-NLS-1$ //$NON-NLS-2$
169
170 File applicationFile = getSystemFile(applicationFileName);
171 execute("generated-dart-class-main.txt", applicationFile, substitutions, mon itor); //$NON-NLS-1$
172 subMonitor.newChild(100);
173 subMonitor.done();
174
175 // html file
176 subMonitor = SubMonitor.convert(monitor,
177 GeneratorMessages.ApplicationGenerator_htmlFileMessage, 100);
178 String htmlFileName = appendIfNoExtension(applicationName, HTML_FILENAME_EXT ENSION);
179 File iHtmlFile = getSystemFile(htmlFileName);
180 substitutions.put("title", className);
181 substitutions.put("dartPath", applicationFileName + "." + JavascriptBackend. EXTENSION_APP_JS);
182 execute("generated-html.txt", iHtmlFile, substitutions, monitor); //$NON-NLS -1$
183 subMonitor.newChild(100);
184 subMonitor.done();
185 return applicationFile;
186 }
187
151 /** 188 /**
152 * Validate the application location. 189 * Validate the application location.
153 * 190 *
154 * @return {@link Status#OK_STATUS} if the name is valid, or a status indicati ng an error or 191 * @return {@link Status#OK_STATUS} if the name is valid, or a status indicati ng an error or
155 * warning. 192 * warning.
156 */ 193 */
157 private IStatus validateLocation() { 194 private IStatus validateLocation() {
158 // Validate that: 195 // Validate that:
159 // 1) The file is non-empty 196 // 1) The file is non-empty
160 // 2) The directory is a valid path 197 // 2) The directory is a valid path
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 + HTML_FILENAME_EXTENSION})); 235 + HTML_FILENAME_EXTENSION}));
199 } 236 }
200 IStatus status = DartIdentifierUtil.validateIdentifier(applicationName); 237 IStatus status = DartIdentifierUtil.validateIdentifier(applicationName);
201 if (status != Status.OK_STATUS) { 238 if (status != Status.OK_STATUS) {
202 return status; 239 return status;
203 } 240 }
204 return Status.OK_STATUS; 241 return Status.OK_STATUS;
205 } 242 }
206 243
207 } 244 }
OLDNEW
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/generator/generated-dart-server.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698