78 |
78 |
private ArrayList<String> pEditionNames = new ArrayList<String>();
|
79 |
79 |
private IProject rcpProject;
|
80 |
80 |
|
|
81 |
private ProjectScope preferenceScope;
|
|
82 |
|
|
83 |
/**
|
|
84 |
* If true, the computing will build the main corpus, editions, texts, etc.
|
|
85 |
*/
|
|
86 |
protected boolean needToBuild;
|
|
87 |
|
|
88 |
|
81 |
89 |
@Parameter(key=TBXPreferences.CLEAN)
|
82 |
90 |
private boolean pCleanAfterBuild;
|
83 |
91 |
|
84 |
|
private ProjectScope preferenceScope;
|
85 |
92 |
|
86 |
|
|
|
93 |
|
87 |
94 |
/**
|
88 |
95 |
* Name.
|
89 |
96 |
*/
|
... | ... | |
170 |
177 |
private Date pCreationDate;
|
171 |
178 |
|
172 |
179 |
/**
|
173 |
|
* Instantiates a new project.
|
|
180 |
* Instantiates a new project and define if it needs to build its main corpus, texts, editions, etc..
|
174 |
181 |
*
|
175 |
182 |
* @param workspace
|
176 |
183 |
* @param name
|
177 |
184 |
* @throws Exception
|
178 |
185 |
*/
|
179 |
|
public Project(Workspace workspace, String name) throws Exception {
|
|
186 |
public Project(Workspace workspace, String name, boolean needToBuild) throws Exception {
|
180 |
187 |
super("project/" + name + "/" + createUUID() + "_Project", workspace);
|
181 |
|
|
|
188 |
|
|
189 |
this.needToBuild = needToBuild;
|
182 |
190 |
this.internalPersistable = true;
|
183 |
191 |
this.pName = name;
|
184 |
192 |
this.dirty = false;
|
... | ... | |
186 |
194 |
this.setVisible(false);
|
187 |
195 |
|
188 |
196 |
initRCPStuffs();
|
|
197 |
|
|
198 |
// FIXME: SJ: this code doesn't flush the other nodes (EditionsPreferences, Tokenizer, etc. see if it's a problem at this stage or not)
|
|
199 |
this.autoSaveParametersFromAnnotations();
|
|
200 |
this.saveParameters();
|
|
201 |
TXMPreferences.flush(this);
|
|
202 |
|
189 |
203 |
}
|
190 |
204 |
|
191 |
205 |
/**
|
192 |
|
*
|
|
206 |
* Instantiates a new project that needs to build its main corpus, texts, editions, etc..
|
|
207 |
* @param workspace
|
|
208 |
* @param name
|
|
209 |
* @throws Exception
|
|
210 |
*/
|
|
211 |
public Project(Workspace workspace, String name) throws Exception {
|
|
212 |
this(workspace, name, true);
|
|
213 |
}
|
|
214 |
|
|
215 |
/**
|
|
216 |
* Instantiates a new existing project from persistence.
|
|
217 |
* This project will not be builded, main corpus, texts, editions, etc. will be restored from persistence.
|
|
218 |
*
|
193 |
219 |
* @param nodePath
|
194 |
220 |
* @throws CoreException
|
195 |
221 |
*/
|
196 |
222 |
public Project(String parametersNodePath) throws CoreException {
|
197 |
223 |
super(parametersNodePath);
|
198 |
|
initRCPStuffs();
|
199 |
224 |
|
|
225 |
this.needToBuild = false;
|
200 |
226 |
this.internalPersistable = true;
|
201 |
227 |
this.dirty = false;
|
202 |
228 |
this.hasBeenComputedOnce = true;
|
203 |
229 |
this.setVisible(false);
|
|
230 |
|
|
231 |
initRCPStuffs();
|
|
232 |
|
204 |
233 |
//
|
205 |
234 |
// this.setPath(project.getPath() + getName());
|
206 |
235 |
// params = parameters;
|
... | ... | |
219 |
248 |
}
|
220 |
249 |
|
221 |
250 |
|
|
251 |
@Override
|
|
252 |
public boolean canCompute() throws Exception {
|
|
253 |
if(pName == null) {
|
|
254 |
Log.severe("Project.canCompute(): can not compute with missing name.");
|
|
255 |
return false;
|
|
256 |
}
|
|
257 |
|
|
258 |
if(this.needToBuild == true && (pSrcDirectory == null || pImportModuleName == null)) {
|
|
259 |
Log.severe("Project.canCompute(): the project needs to build but source directory or import module name is missing.");
|
|
260 |
return false;
|
|
261 |
}
|
|
262 |
return true;
|
|
263 |
}
|
|
264 |
|
|
265 |
|
|
266 |
@Override
|
|
267 |
protected boolean _compute() throws Exception {
|
|
268 |
|
|
269 |
// build the main corpus, texts, editions, etc.
|
|
270 |
if(this.needToBuild) {
|
|
271 |
|
|
272 |
// if (pImportXMLParameters != null) {
|
|
273 |
// pImportXMLParameters.load();
|
|
274 |
// this._load(pImportXMLParameters.name);
|
|
275 |
// // convert to new preferences persistence
|
|
276 |
// }
|
|
277 |
|
|
278 |
if (!rcpProject.getName().equals(pName)) { // project directory and project name must stay in sync
|
|
279 |
IPath destination = new Path(this.getName());
|
|
280 |
if (destination.toFile().exists()) {
|
|
281 |
System.out.println("Error: could not rename project since one already existing with the same new name="+this.getName());
|
|
282 |
return false;
|
|
283 |
}
|
|
284 |
rcpProject.move(destination, true, null);
|
|
285 |
}
|
|
286 |
|
|
287 |
ImportEngines engines = Toolbox.getImportEngines();
|
|
288 |
|
|
289 |
//File scriptfile = new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/org/txm/scripts/importer/"+importName+"/"+importName+"Loader.groovy"); //$NON-NLS-1$
|
|
290 |
ImportEngine engine = engines.getEngine(getImportModuleName());
|
|
291 |
if (engine == null) {
|
|
292 |
//
|
|
293 |
// engine = new ScriptedImportEngine(scriptfile) {
|
|
294 |
// @Override
|
|
295 |
// public boolean build(Project project, IProgressMonitor monitor) {
|
|
296 |
// // TODO Auto-generated method stub
|
|
297 |
// return false;
|
|
298 |
// }
|
|
299 |
// };
|
|
300 |
//Log.severe("Project._compute(): Import engine not found.");
|
|
301 |
|
|
302 |
// no import set
|
|
303 |
return true;
|
|
304 |
}
|
|
305 |
|
|
306 |
if (monitor == null) {
|
|
307 |
monitor = new LogMonitor("computing "+this);
|
|
308 |
}
|
|
309 |
|
|
310 |
Log.finest("RUNNING IMPORT MODULE WITH NAME = " + getImportModuleName());
|
|
311 |
|
|
312 |
boolean state = engine.build(this, monitor).isOK();
|
|
313 |
if(state == true) {
|
|
314 |
this.needToBuild = false;
|
|
315 |
}
|
|
316 |
return state;
|
|
317 |
|
|
318 |
}
|
|
319 |
// Nothing to do if the project does not need to build
|
|
320 |
else {
|
|
321 |
return true;
|
|
322 |
}
|
|
323 |
|
|
324 |
|
|
325 |
}
|
|
326 |
|
|
327 |
/**
|
|
328 |
* Initializes the RCP project and project scope.
|
|
329 |
*
|
|
330 |
* @throws CoreException
|
|
331 |
*/
|
222 |
332 |
private void initRCPStuffs() throws CoreException {
|
223 |
333 |
IWorkspace rcpWorkspace = ResourcesPlugin.getWorkspace();
|
224 |
334 |
if (this.rcpProject == null) {
|
... | ... | |
355 |
465 |
// }
|
356 |
466 |
|
357 |
467 |
/**
|
358 |
|
* retro compatibility method for import.xml files
|
|
468 |
* Retro compatibility method for import.xml files.
|
359 |
469 |
*
|
360 |
470 |
* @return
|
361 |
471 |
* @throws IOException
|
... | ... | |
783 |
893 |
//DeleteDir.deleteDirectory(getProjectDirectory());
|
784 |
894 |
}
|
785 |
895 |
|
786 |
|
@Override
|
787 |
|
public boolean canCompute() throws Exception {
|
788 |
|
return pSrcDirectory != null && pName != null && pImportModuleName != null;
|
789 |
|
}
|
790 |
|
|
791 |
896 |
public void setName(String name) {
|
792 |
897 |
this.pName = name;
|
793 |
898 |
}
|
794 |
899 |
|
795 |
|
@Override
|
796 |
|
protected boolean _compute() throws Exception {
|
797 |
900 |
|
798 |
|
// if (pImportXMLParameters != null) {
|
799 |
|
// pImportXMLParameters.load();
|
800 |
|
// this._load(pImportXMLParameters.name);
|
801 |
|
// // convert to new preferences persistence
|
802 |
|
// }
|
803 |
901 |
|
804 |
|
if (!rcpProject.getName().equals(pName)) { // project directory and project name must stay in sync
|
805 |
|
IPath path = rcpProject.getProjectRelativePath();
|
806 |
|
String name = rcpProject.getName();
|
807 |
|
IPath destination = new Path(this.getName());
|
808 |
|
|
809 |
|
IWorkspace rcpWorkspace = ResourcesPlugin.getWorkspace();
|
810 |
|
IProject p2 = rcpWorkspace.getRoot().getProject(this.getName());
|
811 |
|
if (p2.exists()) {
|
812 |
|
//System.out.println("Error: could not rename project since one already existing with the same new name="+this.getName());
|
813 |
|
//return false;
|
814 |
|
rcpProject = p2;
|
815 |
|
} else {
|
816 |
|
rcpProject.move(destination, true, null);
|
817 |
|
}
|
818 |
|
}
|
819 |
|
|
820 |
|
ImportEngines engines = Toolbox.getImportEngines();
|
821 |
|
|
822 |
|
//File scriptfile = new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/org/txm/scripts/importer/"+importName+"/"+importName+"Loader.groovy"); //$NON-NLS-1$
|
823 |
|
ImportEngine engine = engines.getEngine(getImportModuleName());
|
824 |
|
if (engine == null) {
|
825 |
|
//
|
826 |
|
// engine = new ScriptedImportEngine(scriptfile) {
|
827 |
|
// @Override
|
828 |
|
// public boolean build(Project project, IProgressMonitor monitor) {
|
829 |
|
// // TODO Auto-generated method stub
|
830 |
|
// return false;
|
831 |
|
// }
|
832 |
|
// };
|
833 |
|
//Log.severe("Project._compute(): Import engine not found.");
|
834 |
|
|
835 |
|
// no import set
|
836 |
|
return true;
|
837 |
|
}
|
838 |
|
|
839 |
|
if (monitor == null) {
|
840 |
|
monitor = new LogMonitor("computing "+this);
|
841 |
|
}
|
842 |
|
|
843 |
|
System.out.println("RUNNING IMPORT MODULE WITH NAME="+getImportModuleName());
|
844 |
|
return engine.build(this, monitor).isOK();
|
845 |
|
}
|
846 |
|
|
847 |
902 |
@Override
|
848 |
903 |
public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception {
|
849 |
904 |
return false;
|
... | ... | |
1100 |
1155 |
this.getPreferencesScope().getNode("import").putBoolean(ImportKeys.MULTITHREAD, multithreaded);
|
1101 |
1156 |
}
|
1102 |
1157 |
|
|
1158 |
/**
|
|
1159 |
*
|
|
1160 |
* @param rcpProject
|
|
1161 |
*/
|
1103 |
1162 |
public static void loadProjectsFromProjectScope(IProject rcpProject) {
|
1104 |
1163 |
//IScopeContext projectScope = new ProjectScope(projects[i]);
|
1105 |
1164 |
ArrayList<String> resultNodePaths = TXMPreferences.getAllResultsNodePaths("project/" + rcpProject.getName() + "/");
|
... | ... | |
1160 |
1219 |
*
|
1161 |
1220 |
* @return
|
1162 |
1221 |
*/
|
|
1222 |
// FIXME: SJ: need to see if we need this, it doesn't seem.
|
1163 |
1223 |
public boolean save() {
|
1164 |
1224 |
try {
|
1165 |
1225 |
autoSaveParametersFromAnnotations();
|