001: package tide.project;
002:
003: import tide.editor.TideUtils;
004: import snow.utils.CollectionUtils;
005: import tide.editor.MainEditorFrame;
006: import tide.editor.linemessages.LineMessagesManager;
007: import java.util.concurrent.Callable;
008: import tide.sources.*;
009: import tide.editor.bookmarks.SourceBookmark;
010: import java.io.*;
011: import java.util.*;
012: import java.util.prefs.*;
013: import snow.utils.storage.*;
014: import tide.utils.FileUtilities;
015: import snow.utils.SysUtils;
016:
017: /** Used to store projects settings (paths, jdk, ...) and preferences...
018: * also contains bookmarks, list of already ran classes, ...
019: *
020: * TODO: create some .projet_name in the .tide => detects if several projects are in the same src (and warn)
021: * and use it to sync (File lock) so we ensure not loading twice at same time
022: */
023: public final class ProjectSettings {
024: // important: empty all datas in terminate !
025:
026: // CAN't BE CLEARED until termination, because is used at project reload...
027: private final SourcesInfoStorageManager sourcesStorageManager = new SourcesInfoStorageManager();
028:
029: // this is where almost all settings are stored for this project
030: private final AppProperties props = new AppProperties();
031: private final List<SourceBookmark> bookmarks = new ArrayList<SourceBookmark>();
032:
033: // TODO: count... and offer a shortcut (??)
034: private final Set<String> alreadyRanJavaNames = new TreeSet<String>();
035: private final Map<String, Integer> ranCount = new HashMap<String, Integer>();
036:
037: // absolute names (=> ignore not conserved when changing jdk, even dates)
038: public final Set<String> ignoredLibrariesNames = new TreeSet<String>();
039:
040: // 0: latest search
041: private List<ArrayList<Object>> searchHistory = new ArrayList<ArrayList<Object>>();
042:
043: public void addSearchToHistory(ArrayList<Object> search) {
044: searchHistory.add(0, search);
045: if (searchHistory.size() > 20) {
046: searchHistory.remove(20);
047: }
048: }
049:
050: public List<ArrayList<Object>> getSearchHistory() {
051: return searchHistory;
052: }
053:
054: // public SourcesInfoStorageManager getSourcesStorageManager() { return sourcesStorageManager; }
055:
056: private boolean changed = false;
057:
058: private long workingTime = -1; // opened time
059: private long activeTime;
060: private long this Start = System.currentTimeMillis(); // overidden in "create from vec rep"
061: private long firstStart = -1;
062:
063: // used to know if the classes are really all consistent...
064: private boolean isCompleteBuild = false;
065:
066: public long getWorkingTime() {
067: return workingTime;
068: }
069:
070: public long getFirstStart() {
071: return firstStart;
072: }
073:
074: public long getActiveTime() {
075: return activeTime;
076: }
077:
078: public void resetWorkingTime(long wt, long at) {
079: workingTime = wt;
080: activeTime = at;
081: }
082:
083: /** True if the project has been completely build (F9) (no incremential builds (shift-F9)).
084: * use this along with looking for new uncompiled classes (occur when loading a project)
085: * to warn when creating a project archive.
086: */
087: public boolean getIsCompleteBuild() {
088: return isCompleteBuild;
089: }
090:
091: public void setIsCompleteBuild(boolean a) {
092: props
093: .setLong("last_complete_build", System
094: .currentTimeMillis()); // not used now.
095: this .isCompleteBuild = a;
096: }
097:
098: public void setChangedFalse() {
099: changed = false;
100: sourcesStorageManager.setChangedFalse();
101: }
102:
103: public boolean hasChanged() {
104: if (changed)
105: return true;
106: if (sourcesStorageManager.getHasChanged())
107: return true;
108: return false;
109: }
110:
111: public AppProperties getProps() {
112: return props;
113: }
114:
115: // and these are the keys to access them
116:
117: private final static String JAVA_HOME_key = "Java_Home";
118: private final static String SOURCE_HOME_key = "Source_Home";
119: private final static String EXTERNAL_JARS_key = "ExtJars";
120: private final static String EXTERNAL_JAVADOCS_key = "ExtJavaDocs";
121: private final static String CLASSES_HOME_key = "Classes_Home";
122: private final static String PROJECT_NAME = "Project_Name";
123: private final static String COMPILER_OPTIONS = "Compiler_Options";
124: private final static String RUNTIME_OPTIONS = "Runtime_Options";
125: private final static String APP_ARGUMENTS = "App_Options";
126: private final static String MAIN_Source_File = "Main_Source_File";
127: private final static String JAVA_VERSION_key = "Java_Version";
128: private final static String JDK_DOCS_HOME_key = "JDK docs home"; // where /api is
129:
130: // if empty or not present, takes ".tide" root sibling.
131: private final static String CUSTOM_PROJ_SETTINGS_FOLDER_key = "Custom project settings folder";
132:
133: public final SourcesTreeModel sourcesTreeModel = new SourcesTreeModel();
134: public final LibrariesTreeModel librariesTreeModel = new LibrariesTreeModel();
135:
136: private ClassFilesManager classFilesManager = null;
137: private final JavaDocManager javaDocManager = new JavaDocManager();
138:
139: public ProjectSettings() {
140: super ();
141: // overridden by create from vector representation... if already exists
142: firstStart = System.currentTimeMillis();
143: }
144:
145: /** loads on first request. Contains all libs and generated classes. Must be kept up to date, that is
146: * must be reloaded (below) at project reload and called after each compilation.
147: * Used mainly by the completion, is a lazy process, i.e. the ide will also work without it
148: */
149: public ClassFilesManager getClassFilesManager() {
150: if (classFilesManager == null) {
151: // NO:::
152: //classFilesManager = new ClassFilesManager(getExternalJarFiles(false, true), getClasses_Home(), getClassesCacheTempFolderForCompletion() );
153: // todo: join the loader thread !!!
154: }
155: return classFilesManager;
156: }
157:
158: /** call this to reload or load the classfilesmanager.
159: * lazy initialization in a thread...
160: * MUST be called with call() !!
161: */
162: public Callable<ClassFilesManager> reloadClassesManager() {
163: if (classFilesManager != null) {
164: classFilesManager.terminate();
165: // [May2007] was missing
166: classFilesManager = null;
167: }
168:
169: Callable<ClassFilesManager> reloader = new Callable<ClassFilesManager>() {
170: public ClassFilesManager call() {
171: if (classFilesManager != null)
172: return classFilesManager;
173:
174: // takes time...
175:
176: classFilesManager = new ClassFilesManager(
177: getClassPath(true, false), // TODO: remove ignored (no., ok, only for views... the compiler is treated elsewhere )
178: getClasses_Home(),
179: getClassesCacheTempFolderForCompletion());
180:
181: return classFilesManager;
182: }
183: };
184:
185: return reloader;
186: }
187:
188: /** todo: joint the loader thread if requested before created !!
189: */
190: public JavaDocManager getJavaDocManager() {
191: return javaDocManager;
192: }
193:
194: /** must be call when loading / reloading the project
195: */
196: public Callable<Object> reloadJavaDocManager() {
197: // Remark: takes NO time !
198: if (javaDocManager != null) {
199: javaDocManager.terminate();
200: }
201:
202: Callable<Object> reloader = new Callable<Object>() {
203: public ClassFilesManager call() {
204: List<File> roots = getExternalJavaDocsRoots();
205: roots.add(getProjectJavaDocRoot()); // add it ! it is helpful if present
206:
207: if (getJDKDoc_Home() != null
208: && getJDKDoc_Home().exists()) {
209: File jdkApiDoc = new File(getJDKDoc_Home(), "api/");
210: if (jdkApiDoc.exists()
211: && !roots.contains(jdkApiDoc)) {
212: roots.add(jdkApiDoc);
213: }
214: }
215:
216: MainEditorFrame.debugOut("Javadoc roots: " + roots);
217:
218: javaDocManager.setJavaDocRoots(roots);
219: return null;
220: }
221: };
222:
223: return reloader;
224: }
225:
226: /** helps the gc when terminated. Clears all stored data.
227: * must be called before loading a new project...
228: * but after last usage ! (after having be stored)
229: */
230: public void _terminate() {
231: if (classFilesManager != null) {
232: classFilesManager.terminate();
233: classFilesManager = null;
234: }
235:
236: if (javaDocManager != null) {
237: javaDocManager.terminate();
238: }
239:
240: // [Dec2006]: was missing
241: this .sourcesStorageManager.clearReps();
242: props.clear();
243: bookmarks.clear();
244: alreadyRanJavaNames.clear();
245: ranCount.clear();
246:
247: }
248:
249: public String getProperty(String name, String def) {
250: return props.getProperty(name, def);
251: }
252:
253: public void setProperty(String name, String val) {
254: props.setProperty(name, val);
255: changed = true;
256: }
257:
258: public boolean getBooleanProperty(String name, boolean def) {
259: return props.getBoolean(name, def);
260: }
261:
262: public void setBooleanProperty(String name, boolean val) {
263: props.setBoolean(name, val);
264: changed = true;
265: }
266:
267: public String getProjectName() {
268: return props.getProperty(PROJECT_NAME, "Project1");
269: }
270:
271: public void setProjectName(String name) {
272: props.setProperty(PROJECT_NAME, name);
273: changed = true;
274: }
275:
276: public String getCompilerOptions() {
277: // defaults are -g (all debug infos), -Xlint without serial warns and Xmx512m
278: return props.getProperty(COMPILER_OPTIONS,
279: "-J-Xmx512m -Xlint -Xlint:-serial -Xmaxerrs 20 -g");
280: }
281:
282: /** the editor look that no xlint is present for <1.5 jvms
283: */
284: public void setCompilerOptions(String opts) {
285:
286: props.setProperty(COMPILER_OPTIONS, opts);
287: changed = true;
288: }
289:
290: public String getAppArgs() {
291: return props.getProperty(APP_ARGUMENTS, "");
292: }
293:
294: public void setAppArgs(String opts) {
295: props.setProperty(APP_ARGUMENTS, opts);
296: changed = true;
297: }
298:
299: public void setRuntimeArgs(String opts) {
300: props.setProperty(RUNTIME_OPTIONS, opts);
301: changed = true;
302: }
303:
304: public String getRuntimeArgs() {
305: return props.getProperty(RUNTIME_OPTIONS, "-Xmx256m");
306: }
307:
308: public void setExternalJars(List<File> jars) {
309: props.setProperty(EXTERNAL_JARS_key, FileUtils
310: .filesToList(jars));
311: }
312:
313: /* public List<File> getClassPath(boolean includeJDKLibs)
314: {
315: return getClassPath(includeJDKLibs, false);
316: }*/
317:
318: /** without jdk libs, is also called "aux classpath" or user classpath. without source files.
319: * if includeJDKLibs, Contain all jdk jar files.
320: * @return a copy, no reference. So we can add/remove items without influence on the project !
321: */
322: public List<File> getClassPath(boolean includeJDKLibs,
323: boolean removeIgnored) // TODO !
324: {
325: List<File> cp = FileUtils.getFilesFromList(props.getProperty(
326: EXTERNAL_JARS_key, ""), false);
327:
328: // if both requested, add first the rt !
329: if (includeJDKLibs) {
330: cp.addAll(getAPIClasses());
331: }
332:
333: removeDoubleEntries(cp);
334:
335: // remove ignored
336: if (removeIgnored) {
337: List<File> toRemove = new ArrayList<File>();
338: for (File li : cp) {
339: if (this .ignoredLibrariesNames.contains(li
340: .getAbsolutePath())) {
341: toRemove.add(li);
342: }
343: }
344: //System.out.println("Removing "+toRemove.size()+" from classpath "+ignoredLibrariesNames);
345: cp.removeAll(toRemove);
346: }
347:
348: return cp;
349: }
350:
351: /** src.zip and user defined sources (zip files, jar files, directories...)
352: * Optional !
353: */
354: public List<File> getSourcesForClassPathLibraries() {
355: List<File> srcs = new ArrayList<File>();
356: File sf = getJavaAPISourceZIP();
357: if (sf != null && sf.exists())
358: srcs.add(sf);
359: return srcs;
360: }
361:
362: /** external javadocs. No need to put project javadoc neither standard api, automatically add.
363: */
364: public void setExternalJavaDocs(List<File> jds) {
365: props.setProperty(EXTERNAL_JAVADOCS_key, FileUtils
366: .filesToList(jds));
367: }
368:
369: /** a copy, not a reference !
370: */
371: public List<File> getExternalJavaDocsRoots() {
372: return FileUtils.getFilesFromList(props.getProperty(
373: EXTERNAL_JAVADOCS_key, ""), true);
374: }
375:
376: /** may exist or not !
377: */
378: public File getProjectJavaDocRoot() {
379: File dest = new File(getProperty("JavaDoc_DESTINATION",
380: getSources_Home() + "/../docs/JavaDoc"));
381: try // remove the ..
382: {
383: dest = dest.getCanonicalFile();
384: } catch (Exception e) {
385: e.printStackTrace();
386: }
387: return dest;
388: }
389:
390: /** may exist or not !
391: */
392: public File getClassesCacheTempFolderForCompletion() {
393: File dest = new File(getProjectSettingsFolder(), "classesTemp/");
394: return dest;
395: }
396:
397: /** may exist or not !
398: */
399: public File getBackupFolder() {
400: return getRootSiblingFolder("backup/");
401: }
402:
403: /** May exist or not !
404: */
405: public File getProfilerResultsFolder() {
406: return new File(getProjectSettingsFolder(), "profiler/");
407: }
408:
409: /** @return the folder named name in the same folder as the source folder.
410: * May exist or not ! if not, is created.
411: * Usage: for example: "dev", "classes", "backup", ...
412: * For ".tide", please use getProjectSettingsFolder().
413: */
414: public File getRootSiblingFolder(String name) {
415: File dest = new File(getSources_Home(), "../" + name + "/");
416: try // remove the ".."
417: {
418: dest = dest.getCanonicalFile();
419: if (!dest.exists())
420: dest.mkdirs();
421: } catch (Exception e) {
422: e.printStackTrace();
423: }
424: return dest;
425: }
426:
427: /** May exist or not !
428: * Per default, takes the root sources sibling folder named ".tide".
429: * [March2008]: to work nicely with RAMDrives, enabled customization.
430: */
431: public File getProjectSettingsFolder() {
432: if (props
433: .containsKey(ProjectSettings.CUSTOM_PROJ_SETTINGS_FOLDER_key)) {
434: String pa = props
435: .getProperty(ProjectSettings.CUSTOM_PROJ_SETTINGS_FOLDER_key);
436: if (pa != null && pa.trim().length() > 0) {
437: pa = pa.trim();
438: if (pa.endsWith(".tide"))
439: return new File(pa); // don't add twice !
440: return new File(pa, ".tide/");
441: }
442: }
443: // default
444: return getRootSiblingFolder(".tide/");
445: }
446:
447: public void setCustomTideSettingsFolder(File f) {
448: if (f != null) {
449: props.setProperty(
450: ProjectSettings.CUSTOM_PROJ_SETTINGS_FOLDER_key, f
451: .getAbsolutePath());
452: } else {
453: props
454: .remove(ProjectSettings.CUSTOM_PROJ_SETTINGS_FOLDER_key);
455: }
456: }
457:
458: public File getJava_Home() {
459: if (props.containsKey(ProjectSettings.JAVA_HOME_key)) {
460: return new File(props
461: .getProperty(ProjectSettings.JAVA_HOME_key));
462: }
463:
464: String def = System.getenv("JAVA_HOME");
465: if (def == null) {
466: String javaHome = System.getProperty("java.home").replace(
467: '\\', '/'); // this is often the jre of a jdk !
468: if (javaHome.endsWith("/jre")) {
469: def = javaHome.substring(0, javaHome.length() - 4);
470: } else {
471: def = "c:/jdk1.6.0_05"; // TODO: guess !, look for jdk* dirs in the program files/ or /opt/ ...
472: }
473: }
474:
475: return new File(props.getProperty(
476: ProjectSettings.JAVA_HOME_key, def));
477: }
478:
479: /** null if not set ("")
480: * TODO use: parent.globalProperties.setProperty("lastKnownJDKDocsDir"
481: */
482: public File getJDKDoc_Home() {
483: String folder = props.getProperty(
484: ProjectSettings.JDK_DOCS_HOME_key, "").trim();
485: if (folder.length() == 0)
486: return null;
487: return new File(folder);
488: }
489:
490: /** null if not set ("")
491: */
492: public void setJDKDoc_Home(File home) {
493: String folder = "";
494: if (home != null)
495: folder = home.getAbsolutePath();
496: props.setProperty(ProjectSettings.JDK_DOCS_HOME_key, folder);
497:
498: ProjectUtils.updateJDKDocsHelpMenu(home);
499: }
500:
501: /** try src.zip and if not found src.jar, found in java home.
502: */
503: public File getJavaAPISourceZIP() {
504: File jh = getJava_Home();
505: File zf = new File(jh, "src.zip");
506: if (zf.exists())
507: return zf;
508: zf = new File(jh, "src.jar");
509: return zf;
510: }
511:
512: public File getRTJar() {
513: File jh = getJava_Home();
514: // at first position, the rt.jar
515: return new File(jh, "jre/lib/rt.jar");
516: }
517:
518: /** rt.jar file and the other (jce.jar, ...) found in jre/lib/*.jar and jre/lib/ext/*.jar
519: */
520: private List<File> getAPIClasses() {
521: List<File> files = new ArrayList<File>();
522: File jh = getJava_Home();
523: // at first position, the rt.jar
524: File zf = new File(jh, "jre/lib/rt.jar");
525: files.add(zf);
526: files.addAll(FileUtilities
527: .getAllFilesInDirEndingWithIgnoreCases(new File(jh,
528: "jre/lib/"), ".jar"));
529: files.addAll(FileUtilities
530: .getAllFilesInDirEndingWithIgnoreCases(new File(jh,
531: "jre/lib/ext"), ".jar"));
532:
533: // remove doubles entries (rt.jar is twice)
534: removeDoubleEntries(files);
535:
536: return files;
537: }
538:
539: // keep the first
540: private void removeDoubleEntries(List<File> files) {
541: for (int i = files.size() - 1; i >= 0; i--) // reverse order !
542: {
543: // look in precedent
544: lj: for (int j = 0; j < i; j++) {
545: if (files.get(i).equals(files.get(j))) {
546: files.remove(i);
547: break lj;
548: }
549: }
550: }
551: }
552:
553: /** this is the JDK home (where bin/java is).
554: * this also read the actual jdk version, invoking java -version.
555: * when editing project settings this is called first.
556: */
557: public void setJava_Home(File file) {
558: props.setProperty(JAVA_HOME_key, file.getAbsolutePath());
559: changed = true;
560:
561: String javaVersion = TideUtils.readJavaVersion(getJava_TOOL());
562: props.setProperty(JAVA_VERSION_key, javaVersion);
563:
564: rememberJDKPath();
565: }
566:
567: /** useful later, UI offers them as alternative
568: */
569: private void rememberJDKPath() {
570: File jdkHome = getJava_Home();
571: List<File> allPaths = FileUtils.getFilesFromList(
572: MainEditorFrame.instance.globalProperties.getProperty(
573: "JDK_paths", ""), true);
574:
575: if (!allPaths.contains(jdkHome)) {
576: allPaths.add(jdkHome);
577: }
578:
579: MainEditorFrame.instance.globalProperties.setProperty(
580: "JDK_paths", FileUtils.filesToList(allPaths));
581: }
582:
583: /** @return the version that was read with java -version when the setJava_Home was called
584: **/
585: public String getJavaVersion() {
586: return props.getProperty(ProjectSettings.JAVA_VERSION_key,
587: "0 (not initialized)");
588: }
589:
590: /** important to detect if JVMTI is enable (hprof, jconsole, jstack...)
591: */
592: public boolean isJava5_OrMore() {
593: return getJavaVersion().compareTo("1.5") >= 0;
594: }
595:
596: /** @return null if not defined
597: */
598: public File getMainSourceFile() {
599: String ms = props.getProperty(ProjectSettings.MAIN_Source_File,
600: "").trim();
601: if (ms.length() == 0)
602: return null;
603: return new File(ms);
604: }
605:
606: /** null if not defined
607: */
608: public String getMainClassJavaName() {
609: return ProjectUtils.getJavaNameFor(getMainSourceFile(), this );
610: }
611:
612: /** @param file can be null, if the project has no main file (library)...
613: */
614: public void setMainSourceFile(File file) {
615: if (file == null) {
616: props.setProperty(MAIN_Source_File, "");
617: } else {
618: props.setProperty(MAIN_Source_File, file.getAbsolutePath());
619: }
620: changed = true;
621: }
622:
623: /** @return null if not set
624: */
625: public File getSources_Home() {
626: String name = props.getProperty(
627: ProjectSettings.SOURCE_HOME_key, null);
628: if (name == null)
629: return null;
630: return new File(name);
631: }
632:
633: public void setSources_Home(File file) {
634: props.setProperty(SOURCE_HOME_key, file.getAbsolutePath());
635: changed = true;
636: }
637:
638: /** with clever global defaults
639: */
640: public File getClasses_Home() {
641: String defClassesRoot = new File(System.getProperty(
642: "user.home", ""), "tide_generated_temp_classes/"
643: + this .getProjectName()).getAbsolutePath();
644: try {
645: defClassesRoot = Preferences.userRoot().get(
646: "tIDE_classes_gen_root", defClassesRoot);
647: } catch (Exception ignored) {
648: }
649:
650: return new File(props.getProperty(
651: ProjectSettings.CLASSES_HOME_key, defClassesRoot));
652: }
653:
654: public void setClasses_Home(File file) {
655: props.setProperty(CLASSES_HOME_key, file.getAbsolutePath());
656: changed = true;
657: }
658:
659: // Persistence
660: //
661:
662: public StorageVector _getVectorRepresentation() {
663:
664: StorageVector sv = new StorageVector();
665: sv.add(2); // version
666: sv.add(this .props.getVectorRepresentation()); // 1
667:
668: Vector<String> srepKeys = new Vector<String>();
669: sv.add(srepKeys); // 2
670:
671: Vector<Object> srepVals = new Vector<Object>();
672: sv.add(srepVals); // 3 (let it here...)
673: /* OLD
674: *for(String k : vectorRepOfSources.keySet())
675: {
676: srepKeys.add(k);
677: srepVals.add(vectorRepOfSources.get(k));
678: }*/
679:
680: Vector<Object> brep = new Vector<Object>();
681: sv.add(brep); // 4
682: for (SourceBookmark sb : bookmarks) {
683: brep.add(sb.getStorageRepresentation());
684: }
685:
686: Vector<String> rrep = new Vector<String>();
687: sv.add(rrep); // 5
688: rrep.addAll(alreadyRanJavaNames);
689:
690: // update:
691: long now = System.currentTimeMillis();
692: workingTime += (now - this Start);
693: this Start = now;
694:
695: activeTime += MainEditorFrame.instance.editorPanel
696: .getTotalActiveTime();
697: MainEditorFrame.instance.editorPanel.resetTotalActiveTime();
698:
699: sv.add(workingTime); // 6
700: sv.add(firstStart);
701: sv.add(activeTime);
702: sv.add(isCompleteBuild); // 9
703:
704: sv.add(searchHistory); // 10
705:
706: sv.add(new ArrayList<String>(ignoredLibrariesNames)); // 11
707:
708: List<String> ark = new ArrayList<String>();
709: List<Integer> arv = new ArrayList<Integer>();
710: for (String ki : ranCount.keySet()) {
711: ark.add(ki);
712: arv.add(ranCount.get(ki));
713: }
714: sv.add(ark);
715: sv.add(arv);
716:
717: return sv;
718:
719: }
720:
721: public void saveSourcesInfos() {
722: try {
723: File ps = this .getProjectSettingsFolder();
724: if (!ps.exists())
725: ps.mkdirs();
726: File srf = new File(ps, ".src_infos");
727: FileUtils.saveZippedVectorToFile(srf, sourcesStorageManager
728: .getVectorRepresentation());
729: } catch (Exception e) {
730: e.printStackTrace();
731: }
732:
733: }
734:
735: public StorageVector getStoredSourceInfo(String jn) {
736: return sourcesStorageManager.getSourceFileRep(jn);
737: }
738:
739: public void setStoredSourceInfo(SourceFile sf) {
740: sourcesStorageManager.setSourceFileRep(sf.getJavaName(), sf
741: .getVectorRep());
742: }
743:
744: /** @return a copy...
745: */
746: public Set<String> getSourcesForWhichRepExist() {
747: return sourcesStorageManager.getSourcesForWhichRepExist();
748: }
749:
750: /** Called when loading a project.
751: * This first resets the old one.
752: */
753: @SuppressWarnings("unchecked")
754: public void createFromVectorRepresentation(StorageVector rep,
755: boolean clearRep) {
756: this Start = System.currentTimeMillis();
757:
758: if (rep.size() == 0) {
759: throw new RuntimeException(
760: "ERROR: Project settings storage representation is empty.");
761: }
762:
763: int version = (Integer) rep.get(0);
764: props.createFromVectorRepresentation((List) rep.get(1), true);
765:
766: if (version == 1) {
767: this .sourcesStorageManager
768: .createFromVectorRepresentation_old(rep);
769: } else {
770: File srf = new File(this .getProjectSettingsFolder(),
771: ".src_infos");
772: if (srf.exists()) {
773: try {
774: StorageVector sv = FileUtils
775: .loadZippedVectorFromFile3(srf);
776: sourcesStorageManager
777: .createFromVectorRepresentation(sv,
778: clearRep);
779: if (clearRep) {
780: sv.clear();
781: }
782: } catch (Exception e) {
783: e.printStackTrace();
784: }
785: }
786: }
787:
788: /* OLD if(rep.size()>2)
789: {
790: ArrayList<String> srepKeys = (ArrayList<String>) rep.get(2);
791: ArrayList<ArrayList<Object>> srepVals = (ArrayList<ArrayList<Object>>) rep.get(3);
792:
793: for(int i=0; i<srepKeys.size(); i++)
794: {
795: StorageVector srep = new StorageVector();
796: srep.addAll( srepVals.get(i));
797: vectorRepOfSources.put( srepKeys.get(i), srep);
798: }
799: }*/
800:
801: if (rep.size() > 4) {
802: ArrayList<ArrayList<Object>> brep = (ArrayList<ArrayList<Object>>) rep
803: .get(4);
804: this .bookmarks.clear();
805: for (int i = 0; i < brep.size(); i++) {
806: StorageVector srep = new StorageVector();
807: srep.addAll(brep.get(i));
808: bookmarks.add(new SourceBookmark(srep));
809: }
810: }
811:
812: if (rep.size() > 5) {
813: ArrayList<String> brep = (ArrayList<String>) rep.get(5);
814: this .alreadyRanJavaNames.clear();
815: alreadyRanJavaNames.addAll(brep);
816: }
817:
818: if (rep.size() > 6) {
819: workingTime = (Long) rep.get(6);
820: }
821:
822: if (rep.size() > 7) {
823: firstStart = (Long) rep.get(7);
824: }
825:
826: if (rep.size() > 8) {
827: activeTime = (Long) rep.get(8);
828: }
829: MainEditorFrame.instance.editorPanel.resetTotalActiveTime();
830:
831: if (rep.size() > 9) {
832: isCompleteBuild = (Boolean) rep.get(9);
833: }
834:
835: if (rep.size() > 10) {
836: searchHistory = (ArrayList<ArrayList<Object>>) rep.get(10);
837: }
838:
839: if (rep.size() > 11) {
840: ignoredLibrariesNames.clear();
841: ignoredLibrariesNames.addAll((List<String>) rep.get(11));
842: }
843:
844: if (rep.size() > 13) {
845: List<String> ak = (List<String>) rep.get(12);
846: List<Integer> av = (List<Integer>) rep.get(13);
847: ranCount.clear();
848: for (int i = 0; i < ak.size(); i++) {
849: ranCount.put(ak.get(i), av.get(i));
850: }
851: }
852:
853: ProjectUtils.updateJDKDocsHelpMenu(this .getJDKDoc_Home());
854:
855: changed = true;
856:
857: // to provide nice completions for next projects...
858: rememberJDKPath();
859: }
860:
861: /** Call this when a source has been removed.
862: */
863: public void sourceFileRemoved(String javaName) {
864: sourcesStorageManager.remove(javaName);
865: alreadyRanJavaNames.remove(javaName);
866: LineMessagesManager.getInstance()
867: .removeAllMessagesFor(javaName);
868: getClassFilesManager().remove(javaName);
869: }
870:
871: /** Called for files that are no more existing at project load...
872: */
873: public void removeFileReps(Set<String> javaNames) {
874: for (String jn : javaNames) {
875: alreadyRanJavaNames.remove(jn);
876: ranCount.remove(jn);
877: }
878: this .sourcesStorageManager.removeFileReps(javaNames);
879: }
880:
881: /** Adds the new bookmark and refresh the view.
882: */
883: public void addBookmark(SourceBookmark b) {
884: bookmarks.add(b);
885: LineMessagesManager.getInstance().refreshView();
886: }
887:
888: /** CAUTION: This is not a copy, but the reference.
889: * The first is the oldest one. New ones are to be added at the end.
890: * Bookmarks are stored in these settings.
891: */
892: public List<SourceBookmark> getAllBookmarks_REF() {
893: return this .bookmarks;
894: }
895:
896: /** [relatively slow]... (no hashmap...)
897: */
898: public List<SourceBookmark> getBookmarksFor(String javaName) {
899: List<SourceBookmark> res = new ArrayList<SourceBookmark>();
900: for (SourceBookmark sb : bookmarks) {
901: if (sb.getJavaName().equals(javaName)) {
902: res.add(sb);
903: }
904: }
905: return res;
906: }
907:
908: public Set<String> getAllAlreadyRanJavaNames() {
909: return alreadyRanJavaNames;
910: }
911:
912: public Map<String, Integer> getRanCount() {
913: return ranCount;
914: }
915:
916: public void addRan(String javaName) {
917: alreadyRanJavaNames.add(javaName);
918: if (ranCount.containsKey(javaName)) {
919: ranCount.put(javaName, ranCount.get(javaName) + 1);
920: } else {
921: ranCount.put(javaName, 1);
922: }
923: }
924:
925: // Standard tools in JAVA_HOME, works on Windows and Linux
926: //
927:
928: public File getKeyTool_TOOL() {
929: return getJDK_Tool("keytool");
930: }
931:
932: public File getJavaDoc_TOOL() {
933: return getJDK_Tool("javadoc");
934: }
935:
936: public File getJar_TOOL() {
937: return getJDK_Tool("jar");
938: }
939:
940: public File getJarSigner_TOOL() {
941: return getJDK_Tool("jarsigner");
942: }
943:
944: public File getJavaC_TOOL() {
945: return getJDK_Tool("javac");
946: }
947:
948: /** javap -l javaName shows the bytecode along with the names tables (if compiled with -g) */
949: public File getJavap_TOOL() {
950: return getJDK_Tool("javap");
951: }
952:
953: public File getJava_TOOL() {
954: return getJDK_Tool("java");
955: }
956:
957: public File getJava_WebStart() {
958: return getJDK_Tool("javaws");
959: }
960:
961: public File getJPS_TOOL() {
962: return getJDK_Tool("jps");
963: }
964:
965: public File getJHAT_TOOL() {
966: return getJDK_Tool("jhat");
967: }
968:
969: public File getJConsole_TOOL() {
970: return getJDK_Tool("jconsole");
971: }
972:
973: /** Works on linux and windows,
974: @param nameWithoutExe is for example jps or javah
975: */
976: public File getJDK_Tool(String nameWithoutExe) {
977: if (!SysUtils.is_Windows_OS()) {
978: // try linux
979: File f = new File(getJava_Home(), "bin/" + nameWithoutExe);
980: if (f.exists())
981: return f;
982: }
983: return new File(getJava_Home(), "bin/" + nameWithoutExe
984: + ".exe");
985: }
986:
987: /** A central place to define the Xmx.
988: */
989: public String getExtJavaToolMemoryOption() {
990: return "-J-Xmx512m";
991: }
992:
993: }
|