89 |
89 |
String bundle_id = "org.txm.groovy.core"; //$NON-NLS-1$
|
90 |
90 |
|
91 |
91 |
// copy modified files in the backup directory
|
92 |
|
backupFiles(userDirectory, userDirectory.getParentFile(), bundle_id);
|
|
92 |
backupFiles(userDirectory, systemDirectory , userDirectory.getParentFile());
|
93 |
93 |
|
|
94 |
BundleUtils.copyFiles(bundle_id, "", "src/groovy", "", systemDirectory, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
94 |
95 |
BundleUtils.copyFiles(bundle_id, "", "src/groovy", "", userDirectory, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
95 |
|
BundleUtils.copyFiles(bundle_id, "", "src/groovy", "", systemDirectory, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
96 |
96 |
|
97 |
97 |
bundle_id = "org.txm.core"; //$NON-NLS-1$
|
98 |
98 |
|
|
99 |
// copy additional Groovy files from the src/java directory of
|
99 |
100 |
File scriptsPackageDirectory = new File(userDirectory, "org/txm/scripts/importer"); //$NON-NLS-1$
|
100 |
101 |
scriptsPackageDirectory.mkdirs();
|
101 |
102 |
BundleUtils.copyFiles(bundle_id, "src/java/", "org/txm/scripts/importer", "", scriptsPackageDirectory, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
102 |
103 |
|
|
104 |
scriptsPackageDirectory = new File(systemDirectory, "org/txm/scripts/importer"); //$NON-NLS-1$
|
|
105 |
scriptsPackageDirectory.mkdirs();
|
|
106 |
BundleUtils.copyFiles(bundle_id, "src/java/", "org/txm/scripts/importer", "", scriptsPackageDirectory, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
107 |
|
103 |
108 |
return scriptsDirectory.exists();
|
104 |
109 |
}
|
105 |
110 |
|
106 |
|
public static void backupFiles(File directorytoBackUp, File parentFiletoUse, String bundle_id) {
|
|
111 |
public static void backupFiles(File directorytoBackUp, File referenceDirectory, File parentFiletoUse) {
|
107 |
112 |
|
|
113 |
if (Platform.inDevelopmentMode()) return; // don't recopy the groovy files in dev mode
|
|
114 |
|
|
115 |
Log.fine("Backing up modified Groovy files of "+directorytoBackUp+" VS "+referenceDirectory+" to "+parentFiletoUse);
|
108 |
116 |
File backUserDirectory = new File(parentFiletoUse, directorytoBackUp.getName()+"-"+Toolbox.dateformat.format(new Date()));
|
109 |
117 |
int nBackupedFiles = 0;
|
110 |
118 |
|
111 |
|
long updateTime = BundleUtils.getDate(bundle_id);
|
112 |
|
if (Platform.inDevelopmentMode()) updateTime = Long.MAX_VALUE; // don't recopy the groovy files in dev mode
|
113 |
|
|
114 |
119 |
// System.out.println("update time: "+updateTime+" of "+bundle_id);
|
115 |
120 |
for (File f : DeleteDir.scanDirectory(directorytoBackUp, true, true)) {
|
116 |
|
long t = f.lastModified();
|
117 |
121 |
|
118 |
|
if (f.isFile() && f.getName().endsWith(".groovy") && t > updateTime) { // backup the file if it was modified by the user
|
|
122 |
if (f.isFile() && f.getName().endsWith(".groovy")) { // backup the file if it was modified by the user
|
119 |
123 |
|
120 |
124 |
String path = f.getAbsolutePath();
|
121 |
|
path = path.substring(directorytoBackUp.getAbsolutePath().length());
|
122 |
|
File backGroovy = new File(backUserDirectory, path);
|
|
125 |
String subpath = path.substring(directorytoBackUp.getAbsolutePath().length());
|
|
126 |
File backGroovy = new File(backUserDirectory, subpath);
|
|
127 |
File refGroovy = new File(referenceDirectory, subpath);
|
123 |
128 |
|
124 |
|
try {
|
|
129 |
if (!refGroovy.exists() || refGroovy.lastModified() < f.lastModified()) {
|
125 |
130 |
Log.fine(NLS.bind("Backing {0} -> {1}", f, backGroovy));
|
126 |
|
backGroovy.getParentFile().mkdirs();
|
127 |
|
FileCopy.copy(f, backGroovy);
|
128 |
|
nBackupedFiles++;
|
|
131 |
|
|
132 |
try {
|
|
133 |
backGroovy.getParentFile().mkdirs();
|
|
134 |
FileCopy.copy(f, backGroovy);
|
|
135 |
nBackupedFiles++;
|
|
136 |
}
|
|
137 |
catch (IOException e) {
|
|
138 |
// TODO Auto-generated catch block
|
|
139 |
e.printStackTrace();
|
|
140 |
}
|
|
141 |
|
|
142 |
|
129 |
143 |
}
|
130 |
|
catch (IOException e) {
|
131 |
|
// TODO Auto-generated catch block
|
132 |
|
e.printStackTrace();
|
133 |
|
}
|
134 |
144 |
}
|
135 |
145 |
}
|
136 |
146 |
if (nBackupedFiles > 0) {
|