Révision 3808

TXM/trunk/bundles/org.txm.groovy.core/src/java/org/txm/groovy/core/InstallGroovyFiles.java (revision 3808)
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) {
TXM/trunk/bundles/org.txm.core/src/java/org/txm/utils/BundleUtils.java (revision 3808)
3 3
import java.io.File;
4 4
import java.io.IOException;
5 5
import java.net.URISyntaxException;
6
import java.text.DateFormat;
7
import java.text.SimpleDateFormat;
8
import java.util.Date;
6 9

  
7 10
import org.eclipse.core.runtime.FileLocator;
8 11
import org.eclipse.core.runtime.Platform;
......
150 153
		return copyFiles(bundle_id, source_relative_directory, file_path, file_name, outputDirectory, true);
151 154
	}
152 155
	
156
	public static final SimpleDateFormat qualifierDateFormatter = new SimpleDateFormat("YYYYMMDDHHmm");
157
	
153 158
	public static long getDate(String bundle_id) {
154 159
		
155
		File bundleDir = getBundleFile(bundle_id);
156
		long l1 = bundleDir.lastModified();
157
//		System.out.println("bundle dir "+bundleDir+" date="+l1);
160
//		File bundleDir = getBundleFile(bundle_id);
161
//		long l1 = bundleDir.lastModified();
162
////		System.out.println("bundle dir "+bundleDir+" date="+l1);
163
//		
164
//		Bundle bundle = Platform.getBundle(bundle_id);
165
//		long l2 = bundle.getLastModified();
166
////		System.out.println("bundle dir "+bundle+" date="+l2);
167
//		return Math.max(l1, l2);
158 168
		
159
		Bundle bundle = Platform.getBundle(bundle_id);
160
		long l2 = bundle.getLastModified();
161
//		System.out.println("bundle dir "+bundle+" date="+l2);
162
		return Math.max(l1, l2);
169
		Version v = getBundleVersion(bundle_id);
170
		String qualifier = v.getQualifier(); // 	Textometrie.org	Macro	1.0.0.202305171515	org.txm.groovy.core 
171
		// "(....)(..)(..)(..)(..)", "$1-$2-$3 $4h$5"
172
		
173
		try {
174
			Date d = qualifierDateFormatter.parse(qualifier);
175
			return d.getTime();
176
		} catch(Exception e) {
177
			return 0;
178
		}
179
		
163 180
	}
164 181
	
165 182
	/**

Formats disponibles : Unified diff