Removed
Link Here
|
1 |
/* |
2 |
* (c) 2004 Red Hat, Inc. |
3 |
* |
4 |
* This program is open source software licensed under the |
5 |
* Eclipse Public License ver. 1 |
6 |
*/ |
7 |
|
8 |
package org.eclipse.cdt.rpm.core; |
9 |
|
10 |
import org.eclipse.core.runtime.CoreException; |
11 |
import org.eclipse.core.runtime.IStatus; |
12 |
import org.eclipse.core.runtime.Status; |
13 |
|
14 |
import java.io.*; |
15 |
import java.util.ArrayList; |
16 |
import java.text.SimpleDateFormat; |
17 |
import java.util.Date; |
18 |
|
19 |
/** |
20 |
*This class contains the core methods for manipulating rpm's. Most othe classes |
21 |
*extend this one to get to these classes. |
22 |
*/ |
23 |
public class RPMCore { |
24 |
// When debug is set to true, lots of debug statements are printed. |
25 |
private static final boolean debug = false; |
26 |
protected static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ |
27 |
protected static final String line_sep = System.getProperty("line.separator"); //$NON-NLS-1$ |
28 |
protected static final String Error = Messages.getString("RPMCore.Error_1"); //$NON-NLS-1$ |
29 |
|
30 |
protected String spec_file_prefix = RPMCorePlugin.getDefault().getPreferenceStore() |
31 |
.getString("IRpmConstants.SPEC_FILE_PREFIX"); //$NON-NLS-1$ |
32 |
protected String srpm_info_name = RPMCorePlugin.getDefault().getPreferenceStore() |
33 |
.getString("IRpmConstants.SRPM_INFO_FILE"); //$NON-NLS-1$ |
34 |
protected String wksp_path = RPMCorePlugin.getDefault().getPreferenceStore() |
35 |
.getString("IRpmConstants.RPM_WORK_AREA"); //$NON-NLS-1$ |
36 |
protected String rpmrc = RPMCorePlugin.getDefault().getPreferenceStore() |
37 |
.getString("IRpmConstants.RPM_RESOURCE_FILE"); //$NON-NLS-1$ |
38 |
protected String rpm_macros = RPMCorePlugin.getDefault().getPreferenceStore() |
39 |
.getString("IRpmConstants.RPM_MACROS_FILE"); //$NON-NLS-1$ |
40 |
protected String rpm_shell = RPMCorePlugin.getDefault().getPreferenceStore() |
41 |
.getString("IRpmConstants.RPM_SHELL_SCRIPT"); //$NON-NLS-1$ |
42 |
protected String rpmbuild_logname = RPMCorePlugin.getDefault().getPreferenceStore() |
43 |
.getString("IRpmConstants.RPM_LOG_NAME"); //$NON-NLS-1$ |
44 |
protected String usr_make_cmd = RPMCorePlugin.getDefault().getPreferenceStore() |
45 |
.getString("IRpmConstants.MAKE_CMD"); //$NON-NLS-1$ |
46 |
protected String usr_rpm_cmd = RPMCorePlugin.getDefault().getPreferenceStore() |
47 |
.getString("IRpmConstants.RPM_CMD"); //$NON-NLS-1$ |
48 |
protected String usr_rpmbuild_cmd = RPMCorePlugin.getDefault().getPreferenceStore() |
49 |
.getString("IRpmConstants.RPMBUILD_CMD"); //$NON-NLS-1$ |
50 |
protected String usr_cp_cmd = RPMCorePlugin.getDefault().getPreferenceStore() |
51 |
.getString("IRpmConstants.CP_CMD"); //$NON-NLS-1$ |
52 |
protected String usr_chmod_cmd = RPMCorePlugin.getDefault().getPreferenceStore() |
53 |
.getString("IRpmConstants.CHMOD_CMD"); //$NON-NLS-1$ |
54 |
protected String usr_diff_cmd = RPMCorePlugin.getDefault().getPreferenceStore() |
55 |
.getString("IRpmConstants.DIFF_CMD"); //$NON-NLS-1$ |
56 |
|
57 |
protected String proj_path; |
58 |
protected String path_to_rpm; |
59 |
protected String rpmdirs_path; |
60 |
protected String rpm_version = "1"; //$NON-NLS-1$ |
61 |
protected String rpm_release = "0"; //$NON-NLS-1$ |
62 |
protected String rpm_name; |
63 |
protected String path_to_specfile; |
64 |
protected String path_to_newspecfile; |
65 |
protected String spec_file_name; |
66 |
protected String proj_dir; |
67 |
protected String srpm_full_name; |
68 |
protected String ui_rel_no = ""; //$NON-NLS-1$ |
69 |
protected String ui_ver_no = ""; //$NON-NLS-1$ |
70 |
protected boolean chk_sum_diff = false; |
71 |
|
72 |
private boolean preserve = true; |
73 |
private boolean generate_patch; |
74 |
private String rpm_spec; |
75 |
private String checksum_string; |
76 |
private String diff_old_dir; |
77 |
private String diff_new_dir; |
78 |
private String copied_proj_path; |
79 |
private String orig_srpm_path; |
80 |
private String srpm_abbr_name; |
81 |
|
82 |
|
83 |
/** |
84 |
* Constructor #1 for RPMCore - used for the RPM import to Eclipse Project sequence |
85 |
* also used for exporting an Eclipse C/C++ project to Source RPM |
86 |
* This method is called when a source rpm is to be imported into an Eclipse C/C++ project |
87 |
* or exported from an Eclipse project. It extends LinuxShellCmds and is extended by |
88 |
* RPMExportCore and SRPMExport. |
89 |
* @param c_proj_path - is a string containing the full path to the workspace project of the form |
90 |
* /home/xxxx/workspace/cproject |
91 |
* @param c_path_to_rpm - is a string containing the path to the user-selected RPM |
92 |
* (only used if this is an import of a source RPM) |
93 |
* @return - throws a CoreException if it cannot get to the .sprminfo file if this was a |
94 |
* previously imported source RPM |
95 |
*/ |
96 |
public RPMCore(String c_proj_path, String c_path_to_rpm) |
97 |
throws CoreException { |
98 |
if (debug) { |
99 |
System.out.println( |
100 |
"RPMCore constructor**************************************************"); //$NON-NLS-1$ |
101 |
} |
102 |
|
103 |
proj_path = c_proj_path; |
104 |
path_to_rpm = c_path_to_rpm; |
105 |
|
106 |
String user_wksp = wksp_path + file_sep + System.getProperty("user.name"); //$NON-NLS-1$ //$NON-NLS-2$ |
107 |
rpmdirs_path = user_wksp + file_sep + "rpm_workarea"; //$NON-NLS-1$ |
108 |
String srpm_abbr_name = ""; //$NON-NLS-1$ |
109 |
|
110 |
int j = proj_path.lastIndexOf(file_sep); //$NON-NLS-1$ |
111 |
if ( j == -1) { |
112 |
proj_dir = proj_path; |
113 |
} else { |
114 |
proj_dir = proj_path.substring( j + 1); |
115 |
} |
116 |
if (!firstSRPM(proj_path)) { |
117 |
long cksum; |
118 |
ArrayList srpminfo = new ArrayList(); |
119 |
try { |
120 |
srpminfo = getSRPMexportinfo(proj_path); |
121 |
checkSrpmExists((String) srpminfo.get(0)); |
122 |
cksum = generateChecksum(proj_path, 0); |
123 |
} catch (CoreException e) { |
124 |
String throw_message = e.getMessage(); |
125 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null); |
126 |
throw new CoreException(error); |
127 |
} |
128 |
|
129 |
int i = spec_file_name.lastIndexOf(file_sep); |
130 |
if (i == -1) { |
131 |
path_to_specfile = proj_path + file_sep + spec_file_name; |
132 |
} else { |
133 |
path_to_specfile = spec_file_name; |
134 |
} |
135 |
if (Long.parseLong(checksum_string) != cksum) { |
136 |
chk_sum_diff = true; |
137 |
} |
138 |
|
139 |
if (!(path_to_rpm.equals(""))) { //$NON-NLS-1$ |
140 |
j = path_to_rpm.lastIndexOf(file_sep); |
141 |
if (j != -1) { |
142 |
srpm_full_name = path_to_rpm.substring(j+1); |
143 |
} |
144 |
j = srpm_full_name.lastIndexOf(".src.rpm"); //$NON-NLS-1$ |
145 |
|
146 |
// Strip off the ".src.rpm" part of the name to get the abbreviated name |
147 |
if (j!= -1) { |
148 |
srpm_abbr_name = srpm_full_name.substring(0, j); |
149 |
} |
150 |
// If this is the first time this project has been exported into RPM |
151 |
// format, use the Eclipse project directory name as the RPM name |
152 |
} |
153 |
} else { |
154 |
rpm_name = proj_dir; |
155 |
srpm_abbr_name = proj_dir; |
156 |
srpm_full_name = proj_dir; |
157 |
spec_file_name = proj_dir + ".spec"; //$NON-NLS-1$ |
158 |
} |
159 |
|
160 |
rpm_spec = rpmdirs_path + file_sep + "SPECS" + file_sep + srpm_abbr_name + ".spec"; //$NON-NLS-1$ //$NON-NLS-2$ |
161 |
rpm_shell = rpmdirs_path + file_sep + rpm_shell; |
162 |
rpm_macros = rpmdirs_path + file_sep + getRpm_macros(); |
163 |
rpmrc = rpmdirs_path + file_sep + getRpmrc(); |
164 |
} |
165 |
|
166 |
/** |
167 |
* Constructor #2 for RPMCore - used by the GUI to access information stored in the |
168 |
* project's .srpminfo file and the latest source RPM built from this project. The GUI |
169 |
* displays the RPM version/release info on the screen for the user to change if desired. |
170 |
* This method is called when a source rpm is to be imported into an Eclipse C/C++ |
171 |
* project. It is called to instantiate this class so the GUI can call getSRPMinfo |
172 |
*/ |
173 |
public RPMCore() throws CoreException { |
174 |
|
175 |
} |
176 |
|
177 |
/** |
178 |
* Method checkMakefileForClean. |
179 |
* This method is used to check the M/makefile in the C/C++ project for a |
180 |
* particular string. |
181 |
* @param path - contains a string to the Makefile to be searched |
182 |
* @param srch_string - contains a string to search the Makefile for |
183 |
* @return boolean - return true if successful, false if not |
184 |
* @exception - throw a CoreException if we have problems reading the |
185 |
* Makefile |
186 |
*/ |
187 |
/******************************************************************************/ |
188 |
public boolean checkMakefileForString(String path, String srch_string) |
189 |
throws CoreException { |
190 |
if (debug) { |
191 |
System.out.println("checkForMakefileClean: " + path); //$NON-NLS-1$ |
192 |
} |
193 |
boolean makefile_found = false; |
194 |
boolean found_string = false; |
195 |
String sh_command; |
196 |
String line; |
197 |
String[] makefile_path = { "", "" }; //$NON-NLS-1$ //$NON-NLS-2$ |
198 |
|
199 |
if (!path.equals("")) { //$NON-NLS-1$ |
200 |
makefile_path[0] = path + file_sep + "Makefile"; //$NON-NLS-1$ |
201 |
makefile_path[1] = path + file_sep + "makefile"; //$NON-NLS-1$ |
202 |
} |
203 |
|
204 |
for (int i = 0; i < makefile_path.length; i++) { |
205 |
File f = new File(makefile_path[i]); |
206 |
|
207 |
// Now check for whether or not there are 'install:'/'clean:' sections in the Makefile/makefile |
208 |
if (f.exists()) { |
209 |
makefile_found = true; |
210 |
|
211 |
try { |
212 |
FileReader makefile = new FileReader(makefile_path[i]); |
213 |
StreamTokenizer st = new StreamTokenizer(makefile); |
214 |
st.wordChars(':', ':'); |
215 |
st.wordChars('-', '-'); |
216 |
|
217 |
int token = st.nextToken(); |
218 |
|
219 |
while ((token != StreamTokenizer.TT_EOF) & |
220 |
(!found_string)) { |
221 |
token = st.nextToken(); |
222 |
|
223 |
switch (token) { |
224 |
case StreamTokenizer.TT_WORD: |
225 |
|
226 |
String word = st.sval; |
227 |
|
228 |
if (word.equals(srch_string) | word.equals(srch_string + ":")) { //$NON-NLS-1$ |
229 |
return true; |
230 |
} |
231 |
|
232 |
break; |
233 |
|
234 |
default: |
235 |
break; |
236 |
} |
237 |
} |
238 |
|
239 |
makefile.close(); |
240 |
} catch (IOException e) { |
241 |
String throw_message = Messages.getString( |
242 |
"RPMCore.I/O_error_processing/reading_the_M/makefile__183") + //$NON-NLS-1$ |
243 |
e; |
244 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
245 |
throw_message, null); |
246 |
throw new CoreException(error); |
247 |
} |
248 |
} |
249 |
} |
250 |
return false; |
251 |
} |
252 |
/** |
253 |
* Method checkForMakefile. |
254 |
* This method is used to check the C/C++ project to be made into an RPM has a |
255 |
* Makefile/makefile present in its top directory |
256 |
* @param path - contains a string with the path of where to check for the existence |
257 |
* of a Makefile or makefile (this last check for "makefile" may be removed at a later |
258 |
* date if deemed unnecessary) |
259 |
* @return boolean - return true if successful, throw CoreException if not |
260 |
*/ |
261 |
/******************************************************************************/ |
262 |
public boolean checkForMakefile(String path) throws CoreException { |
263 |
if (debug) { |
264 |
System.out.println("checkMakefile: " + path); //$NON-NLS-1$ |
265 |
} |
266 |
boolean makefile_found = false; |
267 |
String sh_command; |
268 |
String line; |
269 |
String[] makefile_path = { "", "" }; //$NON-NLS-1$ //$NON-NLS-2$ |
270 |
|
271 |
if (!path.equals("")) { //$NON-NLS-1$ |
272 |
makefile_path[0] = path + file_sep + "Makefile"; //$NON-NLS-1$ |
273 |
makefile_path[1] = path + file_sep + "makefile"; //$NON-NLS-1$ |
274 |
} |
275 |
|
276 |
for (int i = 0; i < makefile_path.length; i++) { |
277 |
File f = new File(makefile_path[i]); |
278 |
|
279 |
// Now check for whether or not there are 'install:'/'clean:' sections in the Makefile/makefile |
280 |
if (f.exists()) { |
281 |
return true; |
282 |
} |
283 |
} |
284 |
// If no M/makefile is found, throw an error. |
285 |
String throw_message = Messages.getString( |
286 |
"RPMCore.Failed_to_find_a_M/makefile_in_the_project.___THIS_IS_REQUIRED_!_!_!_185"); //$NON-NLS-1$ |
287 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
288 |
null); |
289 |
throw new CoreException(error); |
290 |
|
291 |
} |
292 |
|
293 |
/** |
294 |
* Method copyDirTree. |
295 |
* This method copies one directory tree to another. |
296 |
* @param dir - A file that points to the directory where the traversing |
297 |
* is to begin |
298 |
* @return - false if unsuccessful, true if successful |
299 |
* ***NOTE*** this method is not currectly used, we use the |
300 |
* Linux "cp" command right now since Java provides not way |
301 |
* to preserve file permissions, particularly the "execute" bit... |
302 |
* when this deficiency is corrected, we will replace those "cp" |
303 |
* commands with calls to this method |
304 |
*/ |
305 |
private boolean copyDirTree(String dirin, String dirout) { |
306 |
if (debug) { |
307 |
System.out.println("--copyDirTree" + //$NON-NLS-1$ |
308 |
line_sep + "----dirin = " + dirin + //$NON-NLS-1$ |
309 |
line_sep + "----dirout = " + dirout); //$NON-NLS-1$ |
310 |
} |
311 |
|
312 |
int file_ctr; |
313 |
String infile; |
314 |
String outfile; |
315 |
File newdirin = new File(dirin); |
316 |
File newdirout = new File(dirout); |
317 |
|
318 |
if (newdirin.isDirectory()) { |
319 |
// If the directory to output to already exists, |
320 |
// skip trying to create it |
321 |
if (!newdirout.exists()) { |
322 |
if (!newdirout.mkdir()) { |
323 |
return false; |
324 |
} |
325 |
} |
326 |
|
327 |
// Get a list of all of the files in this directory |
328 |
String[] children = newdirin.list(); |
329 |
|
330 |
// Walk the tree and copy files |
331 |
for (int i = 0; i < children.length; i++) { |
332 |
infile = dirin + file_sep + children[i]; |
333 |
outfile = dirout + file_sep + children[i]; |
334 |
|
335 |
File newfilein = new File(infile); |
336 |
File newfileout = new File(outfile); |
337 |
long modifiedTime = newfilein.lastModified(); |
338 |
|
339 |
if (newfilein.isDirectory()) { |
340 |
copyDirTree(infile, outfile); |
341 |
} else { |
342 |
try { |
343 |
copyFile(infile, outfile); |
344 |
} catch (Exception e) { |
345 |
return false; |
346 |
} |
347 |
|
348 |
if (!newfileout.setLastModified(modifiedTime)) { |
349 |
return false; |
350 |
} |
351 |
} |
352 |
} |
353 |
} |
354 |
|
355 |
return true; |
356 |
} |
357 |
|
358 |
/** |
359 |
* Method getConfigOpts. |
360 |
* This method takes a spec file path and parses it to see if there are any options |
361 |
* that need to be passed to the "configure" script when conmfiguring an RPM. |
362 |
* @param path_to_specfile - contains a string with a path to the spec file to be |
363 |
* searched to see if the "configure" command has any options to be applied |
364 |
* @return a string containing the options to pass to configure if any were found |
365 |
*/ |
366 |
public String getConfigOpts(String path_to_specfile) throws CoreException { |
367 |
if (debug) { |
368 |
System.out.println("--getConfigOpts: " + path_to_specfile); //$NON-NLS-1$ |
369 |
} |
370 |
|
371 |
|
372 |
boolean found_config = false; |
373 |
int lines = 0; |
374 |
int config_line = 0; |
375 |
String config_opts = ""; //$NON-NLS-1$ |
376 |
|
377 |
try { |
378 |
FileReader sp_file = new FileReader(path_to_specfile); |
379 |
StreamTokenizer st = new StreamTokenizer(sp_file); |
380 |
// st.resetSyntax(); |
381 |
|
382 |
// Make sure numbers, colons and percent signs are considered valid |
383 |
st.wordChars('a','z'); |
384 |
st.wordChars('A','Z'); |
385 |
st.wordChars(':', ':'); |
386 |
st.wordChars('0', '9'); |
387 |
st.wordChars('%', '%'); |
388 |
st.wordChars('{', '}'); |
389 |
st.wordChars('-', '-'); |
390 |
st.wordChars('/','/'); |
391 |
st.wordChars('=','='); |
392 |
st.wordChars('.','.'); |
393 |
st.wordChars('_','_'); |
394 |
st.eolIsSignificant(true); |
395 |
|
396 |
String new_word; |
397 |
int if_ctr = 0; |
398 |
int token = st.nextToken(); |
399 |
while (token != StreamTokenizer.TT_EOF) { |
400 |
token = st.nextToken(); |
401 |
|
402 |
switch (token) { |
403 |
case StreamTokenizer.TT_EOL: |
404 |
lines++; |
405 |
break; |
406 |
case StreamTokenizer.TT_WORD: |
407 |
new_word = st.sval; |
408 |
// System.out.println("---- " + new_word + line_sep + " line no = " + st.lineno()); |
409 |
|
410 |
// If '%configure' was found, gather the options if there were any |
411 |
if (found_config & config_line == lines) { |
412 |
config_opts = config_opts + " --" + new_word; //$NON-NLS-1$ |
413 |
break; |
414 |
} |
415 |
if (found_config & !(config_line == lines)) { |
416 |
found_config = false; |
417 |
break; |
418 |
} |
419 |
|
420 |
// See if there is a %configure section |
421 |
if (new_word.equals("%configure")) { //$NON-NLS-1$ |
422 |
found_config = true; |
423 |
config_line = lines; |
424 |
|
425 |
break; |
426 |
} |
427 |
} |
428 |
} |
429 |
|
430 |
sp_file.close(); |
431 |
} catch (IOException e) { |
432 |
String throw_message = Messages.getString( |
433 |
"RPMCore.Error_parsing_the_spec_file_in_the_project_--_157") + //$NON-NLS-1$ |
434 |
path_to_specfile; |
435 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
436 |
null); |
437 |
throw new CoreException(error); |
438 |
} |
439 |
|
440 |
return config_opts; |
441 |
} |
442 |
|
443 |
|
444 |
/** |
445 |
* Method executeProjConfigure. |
446 |
* See if there is a "configure" script to be run to set up the project with a properly |
447 |
* configured Makefile and if there is, run it. |
448 |
* @param orig_proj_path - contans a string with a path to the directory in which |
449 |
* to run the "configure" script |
450 |
* @return boolean - return true if successful, throw CoreException if not |
451 |
*/ |
452 |
/***************************************************************************/ |
453 |
public void executeProjConfigure(String orig_proj_path) throws CoreException { |
454 |
if (debug) { |
455 |
System.out.println("executeProjConfigure"); //$NON-NLS-1$ |
456 |
} |
457 |
String config_opts; |
458 |
|
459 |
// Check to see if there is indeed a "configure" script |
460 |
File config = new File(orig_proj_path + file_sep + "configure"); //$NON-NLS-1$ |
461 |
|
462 |
if (config.exists()) { |
463 |
|
464 |
// We need to parse the spec file to see if there are any "configure" options |
465 |
File spec_path = new File(rpmdirs_path + file_sep + "SPECS" + file_sep); //$NON-NLS-1$ |
466 |
String[] children = spec_path.list(); |
467 |
String path_to_specfile = rpmdirs_path + file_sep + "SPECS" + file_sep + children[0]; //$NON-NLS-1$ |
468 |
try { |
469 |
config_opts = getConfigOpts(path_to_specfile); |
470 |
} catch (Exception e) { |
471 |
String throw_message = Messages.getString("RPMCore.Error_parsing_spec_file_at__33") + path_to_specfile; //$NON-NLS-1$ |
472 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
473 |
throw_message, null); |
474 |
throw new CoreException(error); |
475 |
} |
476 |
String conf_cmd = "cd " + orig_proj_path + line_sep + "." + file_sep + "configure " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
477 |
config_opts + " >> " + rpmdirs_path + file_sep + "configure.log"; //$NON-NLS-1$ //$NON-NLS-2$ |
478 |
try { |
479 |
LinuxShellCmds.createLinuxShellScript(conf_cmd, rpmbuild_logname, rpm_shell); |
480 |
LinuxShellCmds.executeLinuxCommand(rpm_shell, 0); |
481 |
} catch (Exception e) { |
482 |
String throw_message = e.getMessage(); |
483 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
484 |
throw_message, null); |
485 |
throw new CoreException(error); |
486 |
} |
487 |
} |
488 |
} |
489 |
/** |
490 |
* Method getSRPMexportinfo. |
491 |
* This method is called to get the information from the .srpminfo |
492 |
* file in the Eclipse project where information about an imported |
493 |
* source RPM is kept. |
494 |
* @param String containing the path to the Eclipse project |
495 |
* @return ArrayList - contains the following if successful: |
496 |
* ArrayList[0] = previous source RPM used to create this Eclipse project |
497 |
* ArrayList[1] = version number |
498 |
* ArrayList[2] = release number |
499 |
* ArrayList[3] = rpm name |
500 |
* ArrayList[4] = date when SRPM was imported/exported |
501 |
* ArrayList[5] = spec file name |
502 |
* ArrayList[6] = String with the checksum |
503 |
* |
504 |
* or throws CoreException if unsuccessful |
505 |
*/ |
506 |
public ArrayList getSRPMexportinfo(String project_path) |
507 |
throws CoreException { |
508 |
if (debug) { |
509 |
System.out.println("getSRPMexportinfo -- " + project_path); //$NON-NLS-1$ |
510 |
} |
511 |
|
512 |
String path_to_srpm_info_file = project_path + srpm_info_name; //$NON-NLS-1$ |
513 |
String Error = Messages.getString("RPMCore.Error_1"); //$NON-NLS-1$ |
514 |
boolean found_chksum = false; |
515 |
|
516 |
// See if the srpminfo file exists |
517 |
ArrayList srpm_info = new ArrayList(); |
518 |
|
519 |
// Read the first line of the file in, it is a warning about not deleting the file |
520 |
try { |
521 |
BufferedReader in = new BufferedReader(new FileReader( |
522 |
path_to_srpm_info_file)); |
523 |
String str; |
524 |
|
525 |
while ((str = in.readLine()) != null) { |
526 |
if (str.lastIndexOf(".src.rpm") != -1) { //$NON-NLS-1$ |
527 |
|
528 |
path_to_rpm = project_path + file_sep + str; //$NON-NLS-1$ |
529 |
srpm_info.add(0, path_to_rpm); |
530 |
|
531 |
// save the source rpm path for the installRPMsource() method |
532 |
// path_to_rpm = path; |
533 |
// Now get the version/release number from the RPM |
534 |
rpm_version = LinuxShellCmds.getInfo( |
535 |
usr_rpm_cmd + " --qf %{VERSION} -qp " + //$NON-NLS-1$ |
536 |
path_to_rpm); |
537 |
rpm_release = LinuxShellCmds.getInfo( |
538 |
usr_rpm_cmd + " --qf %{RELEASE} -qp " + //$NON-NLS-1$ |
539 |
path_to_rpm); |
540 |
rpm_name = LinuxShellCmds.getInfo(usr_rpm_cmd + " --qf %{NAME} -qp " + //$NON-NLS-1$ |
541 |
path_to_rpm); |
542 |
srpm_info.add(1, rpm_version); |
543 |
srpm_info.add(2, rpm_release); |
544 |
srpm_info.add(3, rpm_name); |
545 |
} |
546 |
|
547 |
if (str.startsWith("Date:")) { //$NON-NLS-1$ |
548 |
|
549 |
String date_temp = str.substring(6, str.length()); |
550 |
srpm_info.add(4, date_temp); |
551 |
} |
552 |
|
553 |
if (str.startsWith("Specfile:")) { //$NON-NLS-1$ |
554 |
|
555 |
spec_file_name = str.substring(10, str.length()); |
556 |
srpm_info.add(5, spec_file_name); |
557 |
} |
558 |
|
559 |
if (str.startsWith("Checksum:")) { //$NON-NLS-1$ |
560 |
|
561 |
checksum_string = str.substring(10, str.length()); |
562 |
srpm_info.add(6, checksum_string); |
563 |
found_chksum = true; |
564 |
} |
565 |
} |
566 |
|
567 |
in.close(); |
568 |
} catch (IOException e) { |
569 |
String throw_message = Messages.getString( |
570 |
"RPMCore.Error_getting_info_from__93") + //$NON-NLS-1$ |
571 |
path_to_srpm_info_file; |
572 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
573 |
null); |
574 |
throw new CoreException(error); |
575 |
} |
576 |
|
577 |
if (!found_chksum) { |
578 |
srpm_info.add(6, "-1"); //$NON-NLS-1$ |
579 |
} |
580 |
|
581 |
return srpm_info; |
582 |
} |
583 |
|
584 |
/** |
585 |
* Method checkSrpmExists takes a path to the source rpm to be |
586 |
* checked and verifies that there is indeed still there. |
587 |
* If there is not, we cannot successfully export this project. |
588 |
* @param project - a string containing the path to the selected project |
589 |
* @throws CoreException if it does not exist |
590 |
*/ |
591 |
public void checkSrpmExists(String srpm_path) throws CoreException { |
592 |
|
593 |
File f = new File(srpm_path); |
594 |
// Make sure the source rpm is still where it was |
595 |
|
596 |
if (!f.exists()) { |
597 |
String throw_message = Messages.getString( |
598 |
"RPMCore.There_is_no_longer_a_source_RPM_at__86") + //$NON-NLS-1$ |
599 |
srpm_path + |
600 |
Messages.getString("RPMCore._nThis_RPM_*must*_be_restored_before_exporting_can_occur._1"); //$NON-NLS-1$ |
601 |
IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 2, //$NON-NLS-1$ |
602 |
throw_message, null); |
603 |
throw new CoreException(error); |
604 |
} |
605 |
return; |
606 |
} |
607 |
|
608 |
/** |
609 |
* Method copyFile with two file input strings |
610 |
* Takes two input strings containing pathnames, one input file path and |
611 |
* one output file path and does a copy |
612 |
* @param inName - a string containing a path to the input file |
613 |
* @param outName - a string containing a path to the output file |
614 |
* @return - throws any of three exceptions if an error occurs |
615 |
*/ |
616 |
public void copyFile(String inName, String outName) |
617 |
throws FileNotFoundException, IOException, CoreException { |
618 |
// if (debug) { |
619 |
// System.out.println("--copyFile - inName: " + inName + //$NON-NLS-1$ |
620 |
// line _sep + " outName: " + outName); //$NON-NLS-1$ |
621 |
// } |
622 |
BufferedInputStream is = new BufferedInputStream(new FileInputStream( |
623 |
inName)); |
624 |
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream( |
625 |
outName)); |
626 |
|
627 |
try { |
628 |
copyFile(is, os, true); |
629 |
} catch (Exception e) { |
630 |
String throw_message = e.getMessage(); |
631 |
IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 1, //$NON-NLS-1$ |
632 |
throw_message, null); |
633 |
throw new CoreException(error); |
634 |
} |
635 |
} |
636 |
|
637 |
/** |
638 |
* Method copyFile which copies a file from an input stream to an output stream |
639 |
* @param is - a file InputStream |
640 |
* @param os - a file OutputStream |
641 |
* @param close - a boolean to tell if the OutputStream should be closed upon exit |
642 |
* @return if successful, throw Exception if not |
643 |
*/ |
644 |
public void copyFile(InputStream is, OutputStream os, boolean close) |
645 |
throws IOException, CoreException { |
646 |
int b; |
647 |
|
648 |
try { |
649 |
while ((b = is.read()) != -1) { |
650 |
os.write(b); |
651 |
} |
652 |
|
653 |
is.close(); |
654 |
|
655 |
if (close) { |
656 |
os.close(); |
657 |
} |
658 |
} catch (Exception e) { |
659 |
String throw_message = Messages.getString( |
660 |
"RPMCore.Error_trying_to_write_to__8") + os; //$NON-NLS-1$ |
661 |
IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 1, //$NON-NLS-1$ |
662 |
throw_message, null); |
663 |
throw new CoreException(error); |
664 |
} |
665 |
} |
666 |
|
667 |
/** |
668 |
* Method getNameVerRel interrogates a spec file for the name, version and release |
669 |
* of the RPM |
670 |
* @param path_to_specfile contains a string pointing to the specfile to interrogate |
671 |
* @return if successful, throw Exception if not |
672 |
*/ |
673 |
|
674 |
public ArrayList getNameVerRel(String path_to_specfile) |
675 |
throws CoreException, FileNotFoundException { |
676 |
if (debug) { |
677 |
System.out.println("getNameVerRel"); //$NON-NLS-1$ |
678 |
} |
679 |
|
680 |
ArrayList rpm_info = new ArrayList(); |
681 |
ArrayList define_info = new ArrayList(); |
682 |
|
683 |
// initialize version/release numbers to 0 in case none are found in the spec file |
684 |
rpm_info.add(0, "0"); //$NON-NLS-1$ |
685 |
rpm_info.add(1, "0"); //$NON-NLS-1$ |
686 |
rpm_info.add(2, " "); //$NON-NLS-1$ |
687 |
|
688 |
boolean found_version = false; |
689 |
boolean found_release = false; |
690 |
boolean found_name = false; |
691 |
boolean found_ver_token = false; |
692 |
boolean found_rel_token = false; |
693 |
boolean found_name_token = false; |
694 |
boolean found_define = false; |
695 |
boolean found_define_name = false; |
696 |
int define_ctr = 0; |
697 |
|
698 |
File f = new File(path_to_specfile); |
699 |
|
700 |
if (!f.exists()) { |
701 |
String throw_message = "" + //$NON-NLS-1$ |
702 |
path_to_specfile; |
703 |
IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 1, //$NON-NLS-1$ |
704 |
throw_message, null); |
705 |
throw new CoreException(error); |
706 |
} |
707 |
|
708 |
try { |
709 |
FileReader sp_file = new FileReader(path_to_specfile); |
710 |
StreamTokenizer st = new StreamTokenizer(sp_file); |
711 |
|
712 |
// Make sure numbers, colons and periods are considered valid characters |
713 |
st.resetSyntax(); |
714 |
st.wordChars(':', ':'); |
715 |
st.wordChars('0', '9'); |
716 |
st.wordChars('.', '.'); |
717 |
st.wordChars('A', 'z'); |
718 |
st.wordChars('%','%'); |
719 |
st.wordChars('{','{'); |
720 |
st.wordChars('}','}'); |
721 |
|
722 |
int token = 0; |
723 |
String new_word; |
724 |
outer: |
725 |
while (token != StreamTokenizer.TT_EOF) { |
726 |
token = st.nextToken(); |
727 |
|
728 |
switch (token) { |
729 |
case StreamTokenizer.TT_WORD: |
730 |
new_word = st.sval; |
731 |
|
732 |
if (found_define) { |
733 |
found_define = false; |
734 |
define_info.add(define_ctr,new_word); |
735 |
define_ctr++; |
736 |
found_define_name = true; |
737 |
break; |
738 |
} |
739 |
|
740 |
if (found_define_name) { |
741 |
found_define_name = false; |
742 |
define_info.add(define_ctr,new_word); |
743 |
define_ctr++; |
744 |
break; |
745 |
} |
746 |
|
747 |
if (found_version & !found_ver_token) { |
748 |
found_ver_token = true; |
749 |
if (new_word.startsWith("%")) { //$NON-NLS-1$ |
750 |
try { |
751 |
rpm_info.set(0,parseDefine(new_word, define_info)); |
752 |
} catch (Exception e) { |
753 |
String throw_message = Messages.getString("RPMCore.Error_using_parseDefine_to_get_the_version_no._41") + //$NON-NLS-1$ |
754 |
Messages.getString("RPMCore._from_the_spec_file_at___42") + path_to_specfile; //$NON-NLS-1$ |
755 |
IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 1, //$NON-NLS-1$ |
756 |
throw_message, null); |
757 |
throw new CoreException(error); |
758 |
} |
759 |
} else { |
760 |
rpm_info.set(0, new_word); |
761 |
} |
762 |
|
763 |
// System.out.println("Found version = " + new_word); |
764 |
if (found_name_token & found_ver_token & |
765 |
found_rel_token) { |
766 |
break outer; |
767 |
} |
768 |
|
769 |
break; |
770 |
} |
771 |
|
772 |
if (found_release & !found_rel_token) { |
773 |
found_rel_token = true; |
774 |
if (new_word.startsWith("%")) { //$NON-NLS-1$ |
775 |
try { |
776 |
rpm_info.set(1,parseDefine(new_word, define_info)); |
777 |
} catch (Exception e) { |
778 |
String throw_message = Messages.getString("RPMCore.Error_using_parseDefine_to_get_the_release_no._44") + //$NON-NLS-1$ |
779 |
Messages.getString("RPMCore._from_the_spec_file_at___45") + path_to_specfile; //$NON-NLS-1$ |
780 |
IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 1, //$NON-NLS-1$ |
781 |
throw_message, null); |
782 |
throw new CoreException(error); |
783 |
} |
784 |
break; |
785 |
} else { |
786 |
rpm_info.set(1, new_word); |
787 |
} |
788 |
|
789 |
// System.out.println("Found release = " + new_word); |
790 |
if (found_name_token & found_ver_token & |
791 |
found_rel_token) { |
792 |
break outer; |
793 |
} |
794 |
|
795 |
break; |
796 |
} |
797 |
|
798 |
if (found_name & !found_name_token) { |
799 |
found_name_token = true; |
800 |
rpm_info.set(2, new_word); |
801 |
|
802 |
// System.out.println("Found name = " + new_word); |
803 |
if (found_name_token & found_ver_token & |
804 |
found_rel_token) { |
805 |
break outer; |
806 |
} |
807 |
|
808 |
break; |
809 |
} |
810 |
|
811 |
// See if this is a "Version:" tag |
812 |
if (new_word.equals("Version:")) { //$NON-NLS-1$ |
813 |
found_version = true; |
814 |
break; |
815 |
} |
816 |
|
817 |
// See if this is a "Release:" tag |
818 |
if (new_word.equals("Release:")) { //$NON-NLS-1$ |
819 |
found_release = true; |
820 |
break; |
821 |
} |
822 |
|
823 |
// See if this is a "Name:" tag |
824 |
if (new_word.equals("Name:")) { //$NON-NLS-1$ |
825 |
found_name = true; |
826 |
break; |
827 |
} |
828 |
|
829 |
// See if this a "%define" statement |
830 |
// the version and release can sometimes be in a define stmt |
831 |
if (new_word.equals("%define")) { //$NON-NLS-1$ |
832 |
found_define = true; |
833 |
break; |
834 |
} |
835 |
|
836 |
default: |
837 |
break; |
838 |
} |
839 |
} |
840 |
} catch (IOException e) { |
841 |
String throw_message = Messages.getString( |
842 |
"RPMCore.Error_parsing_the_spec_file_at") + //$NON-NLS-1$ |
843 |
path_to_specfile; |
844 |
IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 1, //$NON-NLS-1$ |
845 |
throw_message, null); |
846 |
throw new CoreException(error); |
847 |
} |
848 |
|
849 |
return rpm_info; |
850 |
} |
851 |
|
852 |
/** |
853 |
* Method parseDefine accepts a token from the parser and |
854 |
* searches the ArrayList passed to it for the value of the |
855 |
* token name. This is crude at this point since this does not |
856 |
* happen very often. |
857 |
* @param token is a string containing the name found after the |
858 |
* "Version:" or "Release:" fields of a spec file and the |
859 |
* begining character is a "%" |
860 |
* @param token_value ia an ArrayList containing the names and |
861 |
* values found in the "%define" statements usually found |
862 |
* at the top of the spec file |
863 |
* @return a string with the correct version or release number |
864 |
* else throw a CoreException |
865 |
*/ |
866 |
public String parseDefine(String token, ArrayList token_value) |
867 |
throws CoreException { |
868 |
if (debug) { |
869 |
System.out.println("parseDefine - token = " + token); //$NON-NLS-1$ |
870 |
} |
871 |
// See if there in anything in the ArrayList |
872 |
if (token_value.isEmpty()) { |
873 |
String throw_message = Messages.getString("RPMCore.No___%defines___were_found_in_the_spec_file_38"); //$NON-NLS-1$ |
874 |
IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 1, //$NON-NLS-1$ |
875 |
throw_message, null); |
876 |
throw new CoreException(error); |
877 |
} |
878 |
// A token usually looks this: %{name} |
879 |
String token_name = token.substring(2,token.length()-1); |
880 |
int i = token_value.indexOf(token_name); |
881 |
return (String) token_value.get(i+1); |
882 |
} |
883 |
|
884 |
|
885 |
/** |
886 |
* Method generateChecksum is used to calculate the size of the source |
887 |
* files in a project. This can then be used by the GUI to see if any files |
888 |
* have changed since the last time this project was exported. |
889 |
* @param project_path is a string containing the path to the project |
890 |
* @param a long containing the initial value to begin with (since this is |
891 |
* a recursive function, the value is always passed into the function) |
892 |
* @return long integer with total file size |
893 |
*/ |
894 |
public long generateChecksum(String project_path, long proj_checksum) |
895 |
throws CoreException { |
896 |
// if (debug) { |
897 |
// System.out.println("generateChecksum"); //$NON-NLS-1$ |
898 |
// } |
899 |
|
900 |
File dir = new File(project_path); |
901 |
|
902 |
if (dir.isDirectory()) { |
903 |
String[] children = dir.list(); |
904 |
|
905 |
for (int i = 0; i < children.length; i++) { |
906 |
|
907 |
File temp = new File(project_path + file_sep + children[i]); |
908 |
|
909 |
if (temp.isDirectory()) { |
910 |
proj_checksum = generateChecksum(project_path |
911 |
+ file_sep + children[i], proj_checksum); |
912 |
/** |
913 |
* Here is a list of files to include for the checksum and a |
914 |
* couple to exclude. We want to only include source files |
915 |
* that are not generated or modified in some way by the |
916 |
* "configure" script. |
917 |
*/ |
918 |
} else { |
919 |
if ((children[i].endsWith(".c") | //$NON-NLS-1$ |
920 |
children[i].endsWith(".cpp") | //$NON-NLS-1$ |
921 |
children[i].endsWith(".h") | //$NON-NLS-1$ |
922 |
children[i].endsWith(".in") | //$NON-NLS-1$ |
923 |
children[i].endsWith(".pl") | //$NON-NLS-1$ |
924 |
children[i].endsWith(".s") | //$NON-NLS-1$ |
925 |
children[i].endsWith(".log") | //$NON-NLS-1$ |
926 |
children[i].endsWith(".m4") | //$NON-NLS-1$ |
927 |
children[i].endsWith("-sh") | //$NON-NLS-1$ |
928 |
children[i].endsWith(".mo") | //$NON-NLS-1$ |
929 |
children[i].endsWith(".po") | //$NON-NLS-1$ |
930 |
children[i].endsWith(".pot") | //$NON-NLS-1$ |
931 |
children[i].endsWith(".sh")) & //$NON-NLS-1$ |
932 |
(!children[i].equals("config.log") & //$NON-NLS-1$ |
933 |
!children[i].equals("config.h"))) { //$NON-NLS-1$ |
934 |
try { |
935 |
proj_checksum += fileCheckSum(temp); |
936 |
} catch (Exception e) { |
937 |
String throw_message = Messages.getString("RPMCore.0") + //$NON-NLS-1$ |
938 |
temp.toString(); |
939 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
940 |
throw_message, null); |
941 |
throw new CoreException(error); |
942 |
} |
943 |
} |
944 |
if (children[i].equals("Makefile") & !LinuxShellCmds.checkForConfigure(project_path)) { //$NON-NLS-1$ |
945 |
try { |
946 |
proj_checksum += fileCheckSum(temp); |
947 |
} catch (Exception e) { |
948 |
// Auto-generated catch block |
949 |
e.printStackTrace(); |
950 |
} |
951 |
} |
952 |
} |
953 |
} |
954 |
} |
955 |
|
956 |
return proj_checksum; |
957 |
} |
958 |
|
959 |
/** |
960 |
* Method fileCheckSum. |
961 |
* Generate a checksum for the file passed to this method. |
962 |
* |
963 |
* @param File |
964 |
* to parse |
965 |
* @return long containing the checksum of the file |
966 |
* @throws CoreException |
967 |
*/ |
968 |
public long fileCheckSum(File input) throws Exception { |
969 |
if (debug) { |
970 |
System.out.println("fileCheckSum file = " + input); //$NON-NLS-1$ |
971 |
} |
972 |
String input_line; |
973 |
long chksum = 0; |
974 |
BufferedReader br = new BufferedReader(new FileReader(input.toString())); |
975 |
while ((input_line = br.readLine()) != null) { |
976 |
for (int i=0; i<input_line.length(); i++) |
977 |
chksum += input_line.charAt(i); |
978 |
} |
979 |
br.close(); |
980 |
return chksum; |
981 |
} |
982 |
/** |
983 |
* Method executeMakeClean. |
984 |
* Create a shell script to do a "make clean" in the project and run it. |
985 |
* @param String containing a path where "make xxxxclean" needs to be run |
986 |
* @return boolean - return true if successful, else return false |
987 |
*/ |
988 |
/***************************************************************************/ |
989 |
public boolean executeMakeClean(String mc_path) throws CoreException { |
990 |
if (debug) { |
991 |
System.out.println("executeMakeClean"); //$NON-NLS-1$ |
992 |
} |
993 |
|
994 |
String make_cmd = ""; //$NON-NLS-1$ |
995 |
String orig_srpm_path = ""; //$NON-NLS-1$ |
996 |
// Create the shell script for the "make clean" command and execute it |
997 |
if (mc_path.equals("")) { //$NON-NLS-1$ |
998 |
mc_path = orig_srpm_path; |
999 |
} |
1000 |
|
1001 |
File f = new File(mc_path + file_sep + "Makefile"); //$NON-NLS-1$ |
1002 |
// The different "cleans" are searched in a particular order. Depending on the |
1003 |
// how the RPM package maintainer designed their Makefile; some maintainers |
1004 |
// use maintainer-clean, some use realclean and some use distclean and some use |
1005 |
// all three, with maintainer clean being the best |
1006 |
if (f.exists()) { |
1007 |
if (checkMakefileForString(mc_path, "maintainer-clean:")) { //$NON-NLS-1$ |
1008 |
make_cmd = line_sep + usr_make_cmd + " maintainer-clean"; //$NON-NLS-1$ |
1009 |
} else if (checkMakefileForString(mc_path, "realclean:")) { //$NON-NLS-1$ |
1010 |
make_cmd = line_sep + usr_make_cmd + " realclean"; //$NON-NLS-1$ |
1011 |
} else if (checkMakefileForString(mc_path, "distclean:")) { //$NON-NLS-1$ |
1012 |
make_cmd = line_sep + usr_make_cmd + " distclean"; //$NON-NLS-1$ |
1013 |
} else { |
1014 |
make_cmd = line_sep + usr_make_cmd + " clean"; //$NON-NLS-1$ |
1015 |
} |
1016 |
|
1017 |
String mc_cmd = "( cd " + mc_path + make_cmd; //$NON-NLS-1$ |
1018 |
|
1019 |
try { |
1020 |
LinuxShellCmds.createLinuxShellScript(mc_cmd, rpmbuild_logname, rpm_shell); |
1021 |
LinuxShellCmds.executeLinuxCommand(rpm_shell, 0); |
1022 |
} catch (CoreException e) { |
1023 |
String throw_message = Messages.getString( |
1024 |
"RPMCore.Problem_running_the___make_install___shell_script_--__518") + //$NON-NLS-1$ |
1025 |
rpm_shell + |
1026 |
Messages.getString( |
1027 |
"RPMCore._nThere_may_be_a_problem_in_the_M/makefile._519"); //$NON-NLS-1$ |
1028 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
1029 |
throw_message, null); |
1030 |
throw new CoreException(error); |
1031 |
} |
1032 |
} |
1033 |
return true; |
1034 |
} |
1035 |
|
1036 |
/** |
1037 |
* Method deleteSRPMextrafiles. |
1038 |
* This method deletes files the "make distclean" sometimes misses. |
1039 |
* @param path_to_start - the starting directory |
1040 |
* @return true if successful, false if not |
1041 |
*/ |
1042 |
public boolean deleteSRPMextrafiles(File path_to_start) |
1043 |
throws CoreException { |
1044 |
// if (debug) { |
1045 |
// System.out.println("--deleteSRPMextrafiles"); //$NON-NLS-1$ |
1046 |
// } |
1047 |
|
1048 |
String[] files_to_del = { ".a", ".o", ".so", "~", ".rpm", ".spec.new" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ |
1049 |
|
1050 |
if (path_to_start.isDirectory()) { |
1051 |
String[] subfiles = path_to_start.list(); |
1052 |
|
1053 |
for (int i = 0; i < subfiles.length; i++) { |
1054 |
File f = new File(path_to_start, subfiles[i]); |
1055 |
|
1056 |
if (f.isDirectory()) { |
1057 |
try { |
1058 |
deleteSRPMextrafiles(f); |
1059 |
} catch (CoreException e) { |
1060 |
String throw_message = e.getMessage(); |
1061 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
1062 |
throw_message, null); |
1063 |
throw new CoreException(error); |
1064 |
} |
1065 |
} |
1066 |
|
1067 |
for (int j = 0; j < files_to_del.length; j++) { |
1068 |
int ext_length = files_to_del[j].length(); |
1069 |
int file_length = subfiles[i].length(); |
1070 |
|
1071 |
if (ext_length > file_length) { |
1072 |
continue; |
1073 |
} |
1074 |
|
1075 |
String file_ext = subfiles[i].substring(file_length - |
1076 |
ext_length); |
1077 |
|
1078 |
if (!file_ext.equals(files_to_del[j])) { |
1079 |
continue; |
1080 |
} |
1081 |
|
1082 |
boolean del_file = f.delete(); |
1083 |
|
1084 |
if (!del_file) { |
1085 |
String throw_message = Messages.getString( |
1086 |
"RPMCore.Error_deleting_files_in_deleteSRPMextrafiles_498"); //$NON-NLS-1$ |
1087 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
1088 |
throw_message, null); |
1089 |
throw new CoreException(error); |
1090 |
} |
1091 |
} |
1092 |
} |
1093 |
} |
1094 |
return true; |
1095 |
} |
1096 |
|
1097 |
/** |
1098 |
* Method deleteEclipseFiles will delete the files added to an SRPM that |
1099 |
* was imported by Eclipse and the import process. |
1100 |
* @param String containing the path where to start deleting |
1101 |
* @return true if successful, false if not |
1102 |
*/ |
1103 |
public boolean deleteEclipseFiles(String path_to_delete, String rpm_name) |
1104 |
throws CoreException { |
1105 |
if (debug) { |
1106 |
System.out.println("--deleteEclipseFiles"); //$NON-NLS-1$ |
1107 |
} |
1108 |
|
1109 |
// Remove the .srpminfo file used to store info about the SRPM |
1110 |
String[] eclipse_files = { |
1111 |
srpm_info_name, file_sep + ".project", file_sep + ".cdtproject", file_sep + ".cdtbuild", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
1112 |
file_sep + spec_file_prefix + rpm_name + ".spec", //$NON-NLS-1$ |
1113 |
file_sep + spec_file_prefix + rpm_name + |
1114 |
".spec.new" + file_sep + //$NON-NLS-1$ |
1115 |
"Binaries" //$NON-NLS-1$ |
1116 |
|
1117 |
}; |
1118 |
|
1119 |
for (int i = 0; i < eclipse_files.length; i++) { |
1120 |
File f = new File(path_to_delete + eclipse_files[i]); |
1121 |
|
1122 |
if (f.exists()) { |
1123 |
if (!f.delete()) { |
1124 |
String throw_message = ""; //$NON-NLS-1$ |
1125 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
1126 |
throw_message, null); |
1127 |
throw new CoreException(error); |
1128 |
} |
1129 |
} |
1130 |
} |
1131 |
|
1132 |
return true; |
1133 |
} |
1134 |
|
1135 |
/** |
1136 |
* Method createRPMdirectories creates the directories in the "path" passed to |
1137 |
* it necessary for the "rpm/rpmbuild" command to execute. |
1138 |
* @param path contains a string to the path of where to create the directories |
1139 |
* @return boolean - true is the operation was successful, |
1140 |
* throw CoreException if not |
1141 |
*/ |
1142 |
/******************************************************************************/ |
1143 |
|
1144 |
// Create RPM Directories used for the rpmbuild process |
1145 |
public boolean createRPMdirectories(String path) throws CoreException { |
1146 |
if (debug) { |
1147 |
System.out.println("createRPMdirectories: path = " + //$NON-NLS-1$ |
1148 |
path); |
1149 |
} |
1150 |
|
1151 |
boolean cmd_stat; |
1152 |
File f = new File(path); |
1153 |
|
1154 |
// If an old environment exists remove it |
1155 |
if (f.exists()) { |
1156 |
deleteRPMworkarea(f); |
1157 |
} |
1158 |
|
1159 |
// Create the rpm temporary work area |
1160 |
if (!f.mkdirs()) { |
1161 |
String throw_message = Messages.getString( |
1162 |
"RPMCore.Failed_to_create_RPM_directories,_check_file_permissions_in__195") + //$NON-NLS-1$ |
1163 |
wksp_path; |
1164 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1165 |
null); |
1166 |
throw new CoreException(error); |
1167 |
} |
1168 |
|
1169 |
// Create the directories required by rpm/rpmbuild to perform their work |
1170 |
String[] rpm_dirs = { "BUILD", "RPMS", "SOURCES", "SPECS", "SRPMS" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
1171 |
|
1172 |
for (int i = 0; i < rpm_dirs.length; i++) { |
1173 |
File f1 = new File(rpmdirs_path + file_sep + rpm_dirs[i]); |
1174 |
|
1175 |
if (!f1.mkdir()) { |
1176 |
String throw_message = Messages.getString( |
1177 |
"RPMCore.Failed_to_create_RPM_directories_in__203") + //$NON-NLS-1$ |
1178 |
f1 + |
1179 |
Messages.getString( |
1180 |
"RPMCore._--_check_file_permissions._204"); //$NON-NLS-1$ |
1181 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
1182 |
throw_message, null); |
1183 |
throw new CoreException(error); |
1184 |
} |
1185 |
} |
1186 |
|
1187 |
// Set the permissions of the work area so only the owner can access for |
1188 |
String chmodcommand = usr_chmod_cmd + " -R 744 " + rpmdirs_path + file_sep; //$NON-NLS-1$ |
1189 |
|
1190 |
try { |
1191 |
LinuxShellCmds.executeLinuxCommand(chmodcommand, 0); |
1192 |
} catch (CoreException e) { |
1193 |
String throw_message = e.getMessage(); |
1194 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1195 |
null); |
1196 |
throw new CoreException(error); |
1197 |
} |
1198 |
return true; |
1199 |
} |
1200 |
/** |
1201 |
* Method createRPMLogFile. |
1202 |
* Create the file where the name of the logfile resides for this run. |
1203 |
* @return throw CoreException if unsuccessful |
1204 |
*/ |
1205 |
public void createRPMLogFile() throws CoreException { |
1206 |
if (debug) { |
1207 |
System.out.println("createRPMLogFile: " + rpmbuild_logname); //$NON-NLS-1$ |
1208 |
} |
1209 |
|
1210 |
String logfilename = wksp_path + file_sep + |
1211 |
RPMCorePlugin.getDefault().getPreferenceStore(). |
1212 |
getString("IRpmConstants.RPM_DISPLAYED_LOG_NAME"); //$NON-NLS-1$ |
1213 |
byte[] buf = rpmbuild_logname.getBytes(); |
1214 |
try { |
1215 |
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream( |
1216 |
logfilename)); |
1217 |
|
1218 |
for (int i = 0; i <buf.length; i++) { |
1219 |
os.write(buf[i]); |
1220 |
} |
1221 |
|
1222 |
os.close(); |
1223 |
} catch (Exception e) { |
1224 |
String throw_message = Messages.getString("RPMCore.Error_creating__1") + //$NON-NLS-1$ |
1225 |
logfilename + Messages.getString("RPMCore._nCheck_permissions__2"); //$NON-NLS-1$ |
1226 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1227 |
null); |
1228 |
throw new CoreException(error); |
1229 |
} |
1230 |
} |
1231 |
/** |
1232 |
* Method createRPMrpmrc. |
1233 |
* Create the RPM .rpmrc resource file for use by rpmbuild |
1234 |
* @param rpmrc contains a string of where the .rpmrc file should be written |
1235 |
* @return boolean - return true if able to create .rpmrc, |
1236 |
* throw CoreException if not |
1237 |
*/ |
1238 |
/******************************************************************************/ |
1239 |
public boolean createRPMrpmrc(String rpmrc) throws CoreException { |
1240 |
if (debug) { |
1241 |
System.out.println("createRPMrpmrc " + rpmrc); //$NON-NLS-1$ |
1242 |
} |
1243 |
|
1244 |
String is = "include: /usr/lib/rpm/rpmrc" + line_sep + //$NON-NLS-1$ |
1245 |
"macrofiles: /usr/lib/rpm/macros:/usr/lib/rpm/%{_target}/macros:" + //$NON-NLS-1$ |
1246 |
"/etc/rpm/macros.specspo:/etc/rpm/macros.db1:/etc/rpm/macros:" + //$NON-NLS-1$ |
1247 |
"/etc/rpm/%{_target}/macros:~/.rpm_macros:" + rpmdirs_path + //$NON-NLS-1$ |
1248 |
"/.rpm_macros" + line_sep; //$NON-NLS-1$ |
1249 |
|
1250 |
byte[] buf = is.getBytes(); |
1251 |
|
1252 |
try { |
1253 |
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream( |
1254 |
rpmrc)); |
1255 |
|
1256 |
for (int i = 0; i < buf.length; i++) { |
1257 |
os.write(buf[i]); |
1258 |
} |
1259 |
|
1260 |
os.close(); |
1261 |
} catch (IOException e) { |
1262 |
String throw_message = Messages.getString( |
1263 |
"RPMCore.Problem_creating_the_.rpmrc_file.__Check_file_permissions_in__217") + //$NON-NLS-1$ |
1264 |
rpmdirs_path; |
1265 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1266 |
null); |
1267 |
throw new CoreException(error); |
1268 |
} |
1269 |
|
1270 |
return true; |
1271 |
} |
1272 |
|
1273 |
/** |
1274 |
* Method createRPMmacros. |
1275 |
* Create the .rpm_macros resource file for use by rpmbuild |
1276 |
* @param rpm_macros contains a string with a path to where the |
1277 |
* macros file should be written |
1278 |
* @return boolean - return true if able to create .rpmmacros, |
1279 |
* throw CoreException if not |
1280 |
*/ |
1281 |
/******************************************************************************/ |
1282 |
public boolean createRPMmacros(String rpm_macros) throws CoreException { |
1283 |
if (debug) { |
1284 |
System.out.println("createRPMmacros: rpm_macros = " + rpm_macros); //$NON-NLS-1$ |
1285 |
} |
1286 |
|
1287 |
String is = "%_topdir " + rpmdirs_path + line_sep + //$NON-NLS-1$ |
1288 |
"%_vendor redhat" + line_sep + "%_dbpath " + //$NON-NLS-1$ //$NON-NLS-2$ |
1289 |
rpmdirs_path + line_sep + "%_tmppath " + rpmdirs_path + //$NON-NLS-1$ |
1290 |
line_sep + "%_unpackaged_files_terminate_build 0" + line_sep; //$NON-NLS-1$ |
1291 |
|
1292 |
byte[] buf = is.getBytes(); |
1293 |
|
1294 |
// Read the input stream and try to create the .rpm_macros file |
1295 |
try { |
1296 |
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream( |
1297 |
rpm_macros)); |
1298 |
|
1299 |
for (int i = 0; i < buf.length; i++) { |
1300 |
os.write(buf[i]); |
1301 |
} |
1302 |
|
1303 |
os.close(); |
1304 |
} catch (FileNotFoundException e) { |
1305 |
String throw_message = Messages.getString( |
1306 |
"RPMCore.Problem_creating_the_.rpmmacros_file._nCheck_file_permissions_in__226") + //$NON-NLS-1$ |
1307 |
rpmdirs_path; |
1308 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1309 |
null); |
1310 |
throw new CoreException(error); |
1311 |
} catch (IOException e) { |
1312 |
String throw_message = Messages.getString( |
1313 |
"RPMCore.Problem_creating_the_.rpmmacros_file._nCheck_file_permissions_in__228") + //$NON-NLS-1$ |
1314 |
rpmdirs_path; |
1315 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1316 |
null); |
1317 |
throw new CoreException(error); |
1318 |
} |
1319 |
return true; |
1320 |
} |
1321 |
|
1322 |
/** |
1323 |
* Method deleteRPMworkarea. |
1324 |
* This method deletes all files and subdirectories under path_to_delete. |
1325 |
* @param path_to_delete - the starting directory |
1326 |
* @return true if successful, false if not |
1327 |
*/ |
1328 |
private boolean deleteRPMworkarea(File path_to_delete) { |
1329 |
if (path_to_delete.isDirectory()) { |
1330 |
String[] subfiles = path_to_delete.list(); |
1331 |
|
1332 |
for (int i = 0; i < subfiles.length; i++) { |
1333 |
boolean success = deleteRPMworkarea(new File(path_to_delete, |
1334 |
subfiles[i])); |
1335 |
|
1336 |
if (!success) { |
1337 |
return false; |
1338 |
} |
1339 |
} |
1340 |
} |
1341 |
|
1342 |
// If we made it to here, the directory must be empty so we can delete it |
1343 |
return path_to_delete.delete(); |
1344 |
} |
1345 |
/** |
1346 |
* Method deleteRPMresources. |
1347 |
* Delete the directories created for the purpose of building an RPM |
1348 |
* @param path - contains a string with a path to where the resources are |
1349 |
* @return boolean - true if successful, false if not |
1350 |
*/ |
1351 |
/***************************************************************************/ |
1352 |
public boolean deleteRPMresources(String path) throws CoreException { |
1353 |
if (debug) { |
1354 |
System.out.println("deleteRPMresources"); //$NON-NLS-1$ |
1355 |
} |
1356 |
|
1357 |
File path_to_delete = new File(path); |
1358 |
|
1359 |
// Call the recursive method to delete a directory tree |
1360 |
if (debug) { |
1361 |
System.out.println("--calling deleteRPMworkarea"); //$NON-NLS-1$ |
1362 |
} |
1363 |
|
1364 |
if (!deleteRPMworkarea(path_to_delete)) { |
1365 |
String throw_message = Messages.getString( |
1366 |
"RPMCore.Error_deleting_resources.__Check_file_permissions_in__483") + //$NON-NLS-1$ |
1367 |
rpmdirs_path; |
1368 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1369 |
null); |
1370 |
throw new CoreException(error); |
1371 |
} |
1372 |
|
1373 |
return true; |
1374 |
} |
1375 |
|
1376 |
|
1377 |
/** |
1378 |
* @param string |
1379 |
*/ |
1380 |
public void setRpm_shell(String string) { |
1381 |
rpm_shell = string; |
1382 |
} |
1383 |
|
1384 |
/** |
1385 |
* Method setRpmbuild_logname. |
1386 |
* Set the name of the RPM build log. This gets a little tricky since the name |
1387 |
* of the log iis based on the version/release of the rpm. If the developer has entered |
1388 |
* a version/release, then those values are used as part of the name. |
1389 |
*/ |
1390 |
/******************************************************************************/ |
1391 |
public void setRpmbuild_logname() { |
1392 |
SimpleDateFormat df2 = new SimpleDateFormat("MMdd_HHmm"); //$NON-NLS-1$ |
1393 |
Date today = new Date(); |
1394 |
String logname_version = rpm_version; |
1395 |
String logname_release = rpm_release; |
1396 |
if (!ui_ver_no.equals("")) { //$NON-NLS-1$ |
1397 |
logname_version = ui_ver_no; |
1398 |
} |
1399 |
if (!ui_rel_no.equals("")) { //$NON-NLS-1$ |
1400 |
logname_release = ui_rel_no; |
1401 |
} |
1402 |
rpmbuild_logname = wksp_path + file_sep + rpm_name + "-" + //$NON-NLS-1$ |
1403 |
logname_version + "-" + logname_release + "-" + //$NON-NLS-1$ //$NON-NLS-2$ |
1404 |
df2.format(today) + ".rpmbuild.log"; //$NON-NLS-1$ |
1405 |
} |
1406 |
/** |
1407 |
* Method executeRPMbuildprep. |
1408 |
* This method creates a shell script with the 'rpmbuild -bp' command that takes the sources |
1409 |
* peviously installed in the RPM work area, untars them into the BUILD directory and applies |
1410 |
* all of the patches specified in the spec file. |
1411 |
* @return String - path to the original srpm that was copied into the work area |
1412 |
*/ |
1413 |
/******************************************************************************/ |
1414 |
public String executeRPMbuildprep() throws CoreException { |
1415 |
if (debug) { |
1416 |
System.out.println("Export executeRPMbuildprep"); //$NON-NLS-1$ |
1417 |
} |
1418 |
|
1419 |
boolean cmd_stat; |
1420 |
String orig_proj_path = proj_path; |
1421 |
// Get the path to the spec file directory to use |
1422 |
String specdir = rpmdirs_path + file_sep + "SPECS" + file_sep; //$NON-NLS-1$ |
1423 |
File f = new File(specdir); |
1424 |
|
1425 |
if (!f.isDirectory()) { |
1426 |
String throw_message = Messages.getString( |
1427 |
"RPMCore.There_is_not_a__360") + specdir + //$NON-NLS-1$ |
1428 |
Messages.getString( |
1429 |
"RPMCore._directory._nCheck_permissions_in_the_path_directories._361"); //$NON-NLS-1$ |
1430 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1431 |
null); |
1432 |
throw new CoreException(error); |
1433 |
} |
1434 |
|
1435 |
FilenameFilter only = new OnlyExt("spec"); //$NON-NLS-1$ |
1436 |
String[] s = f.list(only); |
1437 |
|
1438 |
/* Get ready to execute the rpmbuild command to do a "build prep" which |
1439 |
* will untar the source into a directory under BUILD and apply all patches |
1440 |
* specified in the "spec" file. |
1441 |
*/ |
1442 |
String build_opt = "-bp"; //$NON-NLS-1$ |
1443 |
|
1444 |
String rpmbuild_cmd = usr_rpmbuild_cmd + " " + build_opt + //$NON-NLS-1$ |
1445 |
" -v --rcfile " + rpmrc + " --nodeps " + specdir + s[0]; //$NON-NLS-1$ //$NON-NLS-2$ |
1446 |
|
1447 |
try { |
1448 |
LinuxShellCmds.createLinuxShellScript(rpmbuild_cmd, rpmbuild_logname, rpm_shell); |
1449 |
LinuxShellCmds.executeLinuxCommand(rpm_shell, 0); |
1450 |
} catch (CoreException e) { |
1451 |
String throw_message = e.getMessage(); |
1452 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1453 |
null); |
1454 |
throw new CoreException(error); |
1455 |
} |
1456 |
|
1457 |
// Need to figure out what the name of the directory under the BUILD dir is |
1458 |
File build_dir = new File(rpmdirs_path + file_sep + "BUILD" + file_sep); //$NON-NLS-1$ |
1459 |
String[] build_dir_list = build_dir.list(); |
1460 |
diff_old_dir = build_dir_list[0]; |
1461 |
diff_new_dir = diff_old_dir + ".new"; //$NON-NLS-1$ |
1462 |
orig_srpm_path = build_dir + file_sep + build_dir_list[0]; |
1463 |
copied_proj_path = orig_srpm_path + ".new"; //$NON-NLS-1$ |
1464 |
|
1465 |
String chmod_command = usr_chmod_cmd + " -R u+rw " + orig_srpm_path + file_sep; //$NON-NLS-1$ |
1466 |
String cp_cmd1 = "(cd " + orig_srpm_path + line_sep + usr_cp_cmd + " -rp . " + //$NON-NLS-1$ //$NON-NLS-2$ |
1467 |
copied_proj_path; |
1468 |
String cp_cmd2 = "(cd " + proj_path + line_sep + usr_cp_cmd + " -rp . " + //$NON-NLS-1$ //$NON-NLS-2$ |
1469 |
copied_proj_path; |
1470 |
String make_cmd = "(cd " + orig_srpm_path + line_sep + usr_make_cmd + " "; //$NON-NLS-1$ //$NON-NLS-2$ |
1471 |
// Make a copy of the tree under BUILD for patch creation |
1472 |
try { |
1473 |
orig_proj_path = orig_srpm_path; |
1474 |
executeProjConfigure(orig_proj_path); |
1475 |
LinuxShellCmds.createLinuxShellScript(make_cmd,rpmbuild_logname, rpm_shell); |
1476 |
LinuxShellCmds.executeLinuxCommand(rpm_shell,0); |
1477 |
// copyDirTree(orig_srpm_path, copied_proj_path); |
1478 |
// copyDirTree(proj_path, copied_proj_path); |
1479 |
LinuxShellCmds.executeLinuxCommand(chmod_command, 0); |
1480 |
LinuxShellCmds.createLinuxShellScript(cp_cmd1, rpmbuild_logname, rpm_shell); |
1481 |
LinuxShellCmds.executeLinuxCommand(rpm_shell,0); |
1482 |
LinuxShellCmds.createLinuxShellScript(cp_cmd2,rpmbuild_logname, rpm_shell); |
1483 |
LinuxShellCmds.executeLinuxCommand(rpm_shell,0); |
1484 |
} catch (Exception e) { |
1485 |
String throw_message = e.getMessage(); |
1486 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
1487 |
throw_message, null); |
1488 |
throw new CoreException(error); |
1489 |
} |
1490 |
|
1491 |
return orig_srpm_path; |
1492 |
} |
1493 |
|
1494 |
/** |
1495 |
* Method executeRPMBuild. |
1496 |
* This method execs the rpmbuild shell script to build either a binary or source |
1497 |
* RPM |
1498 |
* @param rpm_type - type of RPM to handle - "-ba" for both source and binary |
1499 |
* "-bs" for just a source rpm |
1500 |
* "-bb" for just binary rpm(s) |
1501 |
* @param rpm_spec is a String with the path to the specfile |
1502 |
* @return boolean - returns if successful, throw CoreException if not |
1503 |
*/ |
1504 |
/******************************************************************************/ |
1505 |
public void executeRpmBuild(String rpm_opt, String rpm_spec) throws CoreException { |
1506 |
if (debug) { |
1507 |
System.out.println("executeRpmBuild -- type = " + rpm_opt); //$NON-NLS-1$ |
1508 |
} |
1509 |
|
1510 |
String rpmbuild_cmd = usr_rpmbuild_cmd + " " + rpm_opt + //$NON-NLS-1$ |
1511 |
" -v --nodeps --rcfile " + rpmrc + " " + rpm_spec; //$NON-NLS-1$ //$NON-NLS-2$ |
1512 |
|
1513 |
try { |
1514 |
LinuxShellCmds.createLinuxShellScript(rpmbuild_cmd, rpmbuild_logname, rpm_shell); |
1515 |
|
1516 |
// Execute the rpmbuild shell script to try and create an RPM |
1517 |
LinuxShellCmds.executeLinuxCommand(rpm_shell, 0); |
1518 |
} catch (CoreException e) { |
1519 |
String throw_message = e.getMessage(); |
1520 |
IStatus error = new Status(IStatus.ERROR, Error, 1,throw_message,null); |
1521 |
preserve = true;; |
1522 |
throw new CoreException(error); |
1523 |
} |
1524 |
return; |
1525 |
} |
1526 |
/** |
1527 |
* Method copyRpms. |
1528 |
* This method copies the binary and/or source rpm's created during the |
1529 |
* rpmbuild process back to the Eclipse project |
1530 |
* @param rpm_type - type of RPM to handle - "-ba", "-bs" or "-ba" |
1531 |
* @return - returns if successful, throw CoreException if not |
1532 |
*/ |
1533 |
/******************************************************************************/ |
1534 |
public String copyRpms(String rpm_opt) throws CoreException { |
1535 |
if (debug) { |
1536 |
System.out.println("copyRpms"); //$NON-NLS-1$ |
1537 |
} |
1538 |
String path_to_src_rpm = ""; //$NON-NLS-1$ |
1539 |
/* Copy the source rpm(s) back to the original project */ |
1540 |
if (rpm_opt.equals("-bs") | rpm_opt.equals("-ba")) { //$NON-NLS-1$ //$NON-NLS-2$ |
1541 |
|
1542 |
File dir = new File(rpmdirs_path + file_sep + "SRPMS"); //$NON-NLS-1$ |
1543 |
String[] dirlist = dir.list(); |
1544 |
String from_file = rpmdirs_path + file_sep + "SRPMS" + file_sep + dirlist[0]; //$NON-NLS-1$ |
1545 |
path_to_src_rpm = proj_path + file_sep + dirlist[0]; |
1546 |
rpm_name = dirlist[0]; |
1547 |
|
1548 |
// If the destination source rpm file already exists, delete it |
1549 |
File f1 = new File(path_to_src_rpm); |
1550 |
|
1551 |
if (f1.exists()) { |
1552 |
if (!f1.delete()) { |
1553 |
String throw_message = Messages.getString( |
1554 |
"RPMCore.Unable_to_delete_file__582") + f1 + //$NON-NLS-1$ |
1555 |
Messages.getString( |
1556 |
"RPMCore._nCheck_permissions_in_the_project._583"); //$NON-NLS-1$ |
1557 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
1558 |
throw_message, null); |
1559 |
preserve = true;; |
1560 |
throw new CoreException(error); |
1561 |
} |
1562 |
} |
1563 |
|
1564 |
try { |
1565 |
copyFile(from_file, path_to_src_rpm); |
1566 |
} catch (Exception e) { |
1567 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
1568 |
Messages.getString( |
1569 |
"RPMCore.Error_trying_to_copy__") + //$NON-NLS-1$ |
1570 |
from_file + |
1571 |
Messages.getString("RPMCore._to__") + //$NON-NLS-1$ |
1572 |
path_to_rpm, null); |
1573 |
throw new CoreException(error); |
1574 |
} |
1575 |
} |
1576 |
|
1577 |
/* Get the name of the RPM out of the directory to copy |
1578 |
* Need to figure out what the name of the directory under the RPMS dir is |
1579 |
*so we can get a path so we can copy the created RPM |
1580 |
*/ |
1581 |
if (rpm_opt.equals("-ba") | rpm_opt.equals("-bb")) { //$NON-NLS-1$ //$NON-NLS-2$ |
1582 |
File dir = new File(rpmdirs_path + file_sep + "RPMS" + file_sep); //$NON-NLS-1$ |
1583 |
String[] dirlist = dir.list(); |
1584 |
File dir2 = new File(rpmdirs_path + file_sep + "RPMS" + file_sep + dirlist[0]); //$NON-NLS-1$ |
1585 |
String[] dirlist2 = dir2.list(); |
1586 |
|
1587 |
// Copy all of the rpms back to the project |
1588 |
for (int i = 0; i < dirlist2.length; i++) { |
1589 |
String from_file = rpmdirs_path + file_sep + "RPMS" + file_sep + dirlist[0] + //$NON-NLS-1$ |
1590 |
file_sep + dirlist2[i]; |
1591 |
|
1592 |
try { |
1593 |
copyFile(from_file, proj_path + file_sep + dirlist2[i]); |
1594 |
} catch (Exception e) { |
1595 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
1596 |
Messages.getString( |
1597 |
"RPMCore.Error_trying_to_copy__") + //$NON-NLS-1$ |
1598 |
from_file + |
1599 |
Messages.getString("RPMCore._to__") + //$NON-NLS-1$ |
1600 |
proj_path + file_sep + dirlist2[i], null); |
1601 |
preserve = true;; |
1602 |
throw new CoreException(error); |
1603 |
} |
1604 |
} |
1605 |
} |
1606 |
|
1607 |
return path_to_src_rpm; |
1608 |
} |
1609 |
|
1610 |
/** |
1611 |
* Method to see if this is the first tme a project has been exported |
1612 |
* as a source RPM. |
1613 |
* @param projpath is a string containing the path to the project |
1614 |
* @return true if this is the first time (.srpminfo does not exist), false if not |
1615 |
*/ |
1616 |
public boolean firstSRPM(String projpath) { |
1617 |
/* Check to see if there a .srpminfo file, if not |
1618 |
* this project was not imported from a source rpm. So, copy |
1619 |
* the spec file from the work area to the project. |
1620 |
*/ |
1621 |
File f = new File(projpath + srpm_info_name); |
1622 |
|
1623 |
if (f.exists()) { |
1624 |
return false; |
1625 |
} |
1626 |
|
1627 |
return true; |
1628 |
} |
1629 |
|
1630 |
/** |
1631 |
* Method createSRPMinfo. |
1632 |
* This method creates the ".srpminfo" file in the project to store information |
1633 |
* so that if this project is ever to be re-exported as a binary and/or source |
1634 |
* we will know where the original source RPM is so we can generate patches. |
1635 |
* @param specfile - String containing spec file name |
1636 |
* @param path_to_srpm - String containing the path to the source rpm |
1637 |
* for this project |
1638 |
* @return if successful, throw CoreException if not |
1639 |
* @throws CoreException |
1640 |
*/ |
1641 |
public void createSRPMinfo(String specfile, String path_to_rpm) |
1642 |
throws CoreException { |
1643 |
if (debug) { |
1644 |
System.out.println("--createSRPMinfo"); //$NON-NLS-1$ |
1645 |
} |
1646 |
|
1647 |
SimpleDateFormat df = new SimpleDateFormat("E MMM dd yyyy HH:mm"); //$NON-NLS-1$ |
1648 |
Date today = new Date(); |
1649 |
String srpm_info_file = |
1650 |
"#### DO NOT DELETE THIS FILE IF YOU EVER WANT TO RE-EXPORT THIS " + //$NON-NLS-1$ |
1651 |
"PROJECT AS A BINARY OR SOURCE RPM ####" + line_sep + path_to_rpm + //$NON-NLS-1$ |
1652 |
line_sep + "Date: " + df.format(today); //$NON-NLS-1$ |
1653 |
long file_chksum; |
1654 |
try { |
1655 |
file_chksum = generateChecksum(proj_path, 0); |
1656 |
} catch (Exception e) { |
1657 |
String throw_message = e.getMessage(); |
1658 |
IStatus error = new Status(IStatus.ERROR, Error, 1, |
1659 |
throw_message, null); |
1660 |
throw new CoreException(error); |
1661 |
} |
1662 |
|
1663 |
String new_srpm_info_file = proj_path + srpm_info_name; |
1664 |
srpm_info_file = srpm_info_file + line_sep + "Specfile: " + specfile + //$NON-NLS-1$ |
1665 |
line_sep + Messages.getString("RPMCore.Checksum___32") + String.valueOf(file_chksum); //$NON-NLS-1$ |
1666 |
|
1667 |
byte[] buf = srpm_info_file.getBytes(); |
1668 |
|
1669 |
/* Read the input stream and try to create the spec file to be used by |
1670 |
* the rpmbuild process */ |
1671 |
try { |
1672 |
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream( |
1673 |
new_srpm_info_file)); |
1674 |
|
1675 |
for (int i = 0; i < buf.length; i++) { |
1676 |
os.write(buf[i]); |
1677 |
} |
1678 |
|
1679 |
os.close(); |
1680 |
} catch (Exception e) { |
1681 |
String throw_message = Messages.getString("RPMCore.Error_creating_srpminfo_file_in_the_project._9") + //$NON-NLS-1$ |
1682 |
Messages.getString("RPMCore._nCheck_permissions_in__10") + proj_path; //$NON-NLS-1$ |
1683 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1684 |
null); |
1685 |
throw new CoreException(error); |
1686 |
} |
1687 |
|
1688 |
return; |
1689 |
} |
1690 |
/** |
1691 |
* Method installRPMsource. |
1692 |
* This method installs the source RPM into the "buildroot" area so we can capture it |
1693 |
* for use in importing the project. |
1694 |
* @param path - contains a string to the source RPM to install |
1695 |
* @return boolean - returns true if successful, throws CoreException if not |
1696 |
*/ |
1697 |
/******************************************************************************/ |
1698 |
public boolean installRPMsource(String path) throws CoreException { |
1699 |
if (debug) { |
1700 |
System.out.println("installRPMsource"); //$NON-NLS-1$ |
1701 |
} |
1702 |
|
1703 |
String rpm_cmd = usr_rpm_cmd + " -i -v --rcfile " + rpmrc + " " + //$NON-NLS-1$ //$NON-NLS-2$ |
1704 |
path; |
1705 |
|
1706 |
try { |
1707 |
LinuxShellCmds.createLinuxShellScript(rpm_cmd, rpmbuild_logname, rpm_shell); |
1708 |
LinuxShellCmds.executeLinuxCommand(rpm_shell, 0); |
1709 |
} catch (CoreException e) { |
1710 |
String throw_message = Messages.getString( |
1711 |
"RPMCore.Error_trying_to_install_the_source_with_this_command__355") + //$NON-NLS-1$ |
1712 |
rpm_cmd + |
1713 |
Messages.getString("RPMCore._nCheck_the_log_at__356") + //$NON-NLS-1$ |
1714 |
rpmbuild_logname; |
1715 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1716 |
null); |
1717 |
throw new CoreException(error); |
1718 |
} |
1719 |
|
1720 |
return true; |
1721 |
} |
1722 |
|
1723 |
/** |
1724 |
* Method generateSRPMpatch will take a path to an Eclipse C/C++ |
1725 |
* project and copy it to a temp area, run "make clean" and install |
1726 |
* the SRPM this project was created from and generate a patch |
1727 |
* of the differences for inclusion for the new SRPM. |
1728 |
* @param ver_no String containing the version number of this SRPM |
1729 |
* @param patch_tag String containing a unique identifier for the patch |
1730 |
* @return a long integer indicating the size of the patch, |
1731 |
* throw CoreException if there are any errors |
1732 |
*/ |
1733 |
public long generateSRPMpatch(String ver_no, |
1734 |
String patch_tag) throws CoreException { |
1735 |
if (debug) { |
1736 |
System.out.println("generateSRPMpatch"); //$NON-NLS-1$ |
1737 |
System.out.println("---patch tag: " + patch_tag); //$NON-NLS-1$ |
1738 |
} |
1739 |
String patch_name = rpm_name + "-" + ver_no + "-" + //$NON-NLS-1$ //$NON-NLS-2$ |
1740 |
patch_tag + ".patch"; //$NON-NLS-1$ |
1741 |
|
1742 |
boolean cmd_stat; |
1743 |
|
1744 |
/* Now that the original source rpm has been installed in the rpm workarea, |
1745 |
* The source has already been copied from the Eclipse project and has a |
1746 |
* ".new" appended to the end. |
1747 |
*/ |
1748 |
String chmodcommand = usr_chmod_cmd + " -R u+r " + rpmdirs_path + //$NON-NLS-1$ |
1749 |
file_sep + "BUILD" + file_sep; //$NON-NLS-1$ |
1750 |
|
1751 |
try { |
1752 |
LinuxShellCmds.executeLinuxCommand(chmodcommand, 0); |
1753 |
} catch (CoreException e) { |
1754 |
String throw_message = e.getMessage(); |
1755 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1756 |
null); |
1757 |
throw new CoreException(error); |
1758 |
} |
1759 |
|
1760 |
try { |
1761 |
checkForMakefile(copied_proj_path); |
1762 |
} catch (CoreException e) { |
1763 |
String throw_message = e.getMessage(); |
1764 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1765 |
null); |
1766 |
throw new CoreException(error); |
1767 |
} |
1768 |
|
1769 |
/* Run a "make clean" and/or "make distclean" on the previously installed source |
1770 |
* A bit of explanation here. There probably is a question of why we are doing an |
1771 |
* "rpmbuild -bc" (which does a build/compile) when we install the previously- |
1772 |
* installed source RPM instead of an "rpmbuild -bp" which just installs the source. |
1773 |
* We have found that a *lot* of "Makefiles" in the source RPMs do not properly |
1774 |
* "clean-up" the directory tree when a "make distclean" is done. Sometimes files |
1775 |
* created by "autoconf" and "aclocal" get left behind. So, we perform the same |
1776 |
* procedure on the previous source RPM as we do the source RPM we imported, |
1777 |
* "rpmbuild -bc" and then "make distclean". This way the same files get created so |
1778 |
* when we run the "diff" command on the previous and the to-be-exported source |
1779 |
* RPM only the differences that were edited by the developer are picked up. |
1780 |
*/ |
1781 |
String make_cmd = "(cd " + copied_proj_path + line_sep + usr_make_cmd + " "; //$NON-NLS-1$ //$NON-NLS-2$ |
1782 |
try { |
1783 |
// need to make sure that "make" has been run on the Eclipse project at least |
1784 |
// once before doing the "diff" command so we "compare apples to apples" |
1785 |
LinuxShellCmds.createLinuxShellScript(make_cmd, rpmbuild_logname, rpm_shell); |
1786 |
LinuxShellCmds.executeLinuxCommand(rpm_shell,0); |
1787 |
executeMakeClean(copied_proj_path); |
1788 |
deleteEclipseFiles(copied_proj_path, rpm_name); |
1789 |
File f = new File(copied_proj_path); |
1790 |
deleteSRPMextrafiles(f); |
1791 |
executeMakeClean(orig_srpm_path); |
1792 |
deleteEclipseFiles(orig_srpm_path, rpm_name); |
1793 |
f = new File(orig_srpm_path); |
1794 |
deleteSRPMextrafiles(f); |
1795 |
} catch (Exception e) { |
1796 |
String throw_message = e.getMessage(); |
1797 |
IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, |
1798 |
null); |
1799 |
throw new CoreException(error); |
1800 |
} |
1801 |
|
1802 |
// Now, get the directory names under the "BUILD" directory and run the "diff" |
1803 |
// command to generate the patch |
1804 |
|
1805 |
/* It makes a difference when using the "diff" command which directory comes first and |
1806 |
* which directory comes second in the command. We want the original to come first |
1807 |
* and we have appended a ".new" to the Eclipse project that was copied over. |
1808 |
*/ |
1809 |
String diff_cmd = "(cd " + rpmdirs_path + file_sep + "BUILD" + line_sep + usr_diff_cmd +" -uNr " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
1810 |
"--ignore-matching-lines=POT-Creation-Date --exclude=autom4te.cache " + //$NON-NLS-1$ |
1811 |
// skip the fields that are dynamically filled in or created by autoconf |
1812 |
diff_old_dir + " " + diff_new_dir + " > " + rpmdirs_path + //$NON-NLS-1$ //$NON-NLS-2$ |
1813 |
file_sep + "SOURCES" + file_sep + patch_name + " )" + line_sep; //$NON-NLS-1$ //$NON-NLS-2$ |
1814 |
File f = new File(rpmdirs_path + file_sep + "SOURCES" + file_sep + patch_name); //$NON-NLS-1$ |
1815 |
// Execute the diff_cmd shell script to create a patch file |
1816 |
try { |
1817 |
LinuxShellCmds.createLinuxShellScript(diff_cmd, rpmbuild_logname, rpm_shell); |
1818 |
LinuxShellCmds.executeLinuxCommand(rpm_shell, 1); |
1819 |
} catch (CoreException e) { |
1820 |
|
1821 |
if (!f.exists() | f.length() == 0) { |
1822 |
return 0; |
1823 |
} else { |
1824 |
return -1;} |
1825 |
} |
1826 |
return f.length(); |
1827 |
} |
1828 |
|
1829 |
/** |
1830 |
* This small class implements the FilenameFilter method. It is |
1831 |
* used to return all files ending with ".spec" from the SPECS |
1832 |
* directory |
1833 |
*/ |
1834 |
public class OnlyExt implements FilenameFilter { |
1835 |
String ext; |
1836 |
|
1837 |
/** |
1838 |
* Method OnlyExt. |
1839 |
* This method accepts a string to be used as a filter. Only files with names ending |
1840 |
* in .'ext' will be returned. |
1841 |
* @param ext - string containing the file extension to use as a filter |
1842 |
*/ |
1843 |
public OnlyExt(String ext) { |
1844 |
this.ext = "." + ext; //$NON-NLS-1$ |
1845 |
} |
1846 |
|
1847 |
/** |
1848 |
* @see java.io.FilenameFilter#accept(File, String) |
1849 |
*/ |
1850 |
public boolean accept(File dir, String name) { |
1851 |
return (name.endsWith(ext)); |
1852 |
} |
1853 |
} |
1854 |
|
1855 |
/** |
1856 |
* @return |
1857 |
*/ |
1858 |
public static String getError() { |
1859 |
return Error; |
1860 |
} |
1861 |
|
1862 |
/** |
1863 |
* @return |
1864 |
*/ |
1865 |
public boolean isGenerate_patch() { |
1866 |
return generate_patch; |
1867 |
} |
1868 |
|
1869 |
/** |
1870 |
* @return |
1871 |
*/ |
1872 |
public String getPath_to_rpm() { |
1873 |
return path_to_rpm; |
1874 |
} |
1875 |
|
1876 |
/** |
1877 |
* @return |
1878 |
*/ |
1879 |
public String getPath_to_specfile() { |
1880 |
return path_to_specfile; |
1881 |
} |
1882 |
|
1883 |
/** |
1884 |
* @return |
1885 |
*/ |
1886 |
public String getProj_dir() { |
1887 |
return proj_dir; |
1888 |
} |
1889 |
|
1890 |
/** |
1891 |
* @return |
1892 |
*/ |
1893 |
public String getProj_path() { |
1894 |
return proj_path; |
1895 |
} |
1896 |
|
1897 |
/** |
1898 |
* @return |
1899 |
*/ |
1900 |
public String getRpm_macros() { |
1901 |
return rpm_macros; |
1902 |
} |
1903 |
|
1904 |
/** |
1905 |
* @return |
1906 |
*/ |
1907 |
public String getRpm_name() { |
1908 |
return rpm_name; |
1909 |
} |
1910 |
|
1911 |
/** |
1912 |
* @return |
1913 |
*/ |
1914 |
public String getRpm_release() { |
1915 |
return rpm_release; |
1916 |
} |
1917 |
|
1918 |
/** |
1919 |
* @return |
1920 |
*/ |
1921 |
public String getRpm_spec() { |
1922 |
return rpm_spec; |
1923 |
} |
1924 |
|
1925 |
/** |
1926 |
* @return |
1927 |
*/ |
1928 |
public String getRpm_version() { |
1929 |
return rpm_version; |
1930 |
} |
1931 |
|
1932 |
/** |
1933 |
* @return |
1934 |
*/ |
1935 |
public String getRpmbuild_logname() { |
1936 |
return rpmbuild_logname; |
1937 |
} |
1938 |
|
1939 |
/** |
1940 |
* @return |
1941 |
*/ |
1942 |
public String getRpmdirs_path() { |
1943 |
return rpmdirs_path; |
1944 |
} |
1945 |
|
1946 |
/** |
1947 |
* @return |
1948 |
*/ |
1949 |
public String getRpmrc() { |
1950 |
return rpmrc; |
1951 |
} |
1952 |
|
1953 |
/** |
1954 |
* @return |
1955 |
*/ |
1956 |
public String getSpec_file_name() { |
1957 |
return spec_file_name; |
1958 |
} |
1959 |
|
1960 |
/** |
1961 |
* @return |
1962 |
*/ |
1963 |
public String getSpec_file_prefix() { |
1964 |
return spec_file_prefix; |
1965 |
} |
1966 |
|
1967 |
/** |
1968 |
* @return |
1969 |
*/ |
1970 |
public String getSrpm_info_name() { |
1971 |
return srpm_info_name; |
1972 |
} |
1973 |
|
1974 |
/** |
1975 |
* @return |
1976 |
*/ |
1977 |
public String getWksp_path() { |
1978 |
return wksp_path; |
1979 |
} |
1980 |
|
1981 |
/** |
1982 |
* @param string |
1983 |
*/ |
1984 |
public void setRpm_release(String string) { |
1985 |
rpm_release = string; |
1986 |
} |
1987 |
|
1988 |
/** |
1989 |
* @param string |
1990 |
*/ |
1991 |
public void setRpm_version(String string) { |
1992 |
rpm_version = string; |
1993 |
} |
1994 |
|
1995 |
/** |
1996 |
* @param string |
1997 |
*/ |
1998 |
public void setSpec_file_name(String string) { |
1999 |
spec_file_name = string; |
2000 |
} |
2001 |
|
2002 |
/** |
2003 |
* @return |
2004 |
*/ |
2005 |
public boolean isChk_sum_diff() { |
2006 |
return chk_sum_diff; |
2007 |
} |
2008 |
|
2009 |
/** |
2010 |
* @return |
2011 |
*/ |
2012 |
public String getRpm_shell() { |
2013 |
return rpm_shell; |
2014 |
} |
2015 |
|
2016 |
/** |
2017 |
* @param string |
2018 |
*/ |
2019 |
public void setPath_to_specfile(String string) { |
2020 |
path_to_specfile = string; |
2021 |
} |
2022 |
|
2023 |
/** |
2024 |
* @param string |
2025 |
*/ |
2026 |
public void setUi_rel_no(String string) { |
2027 |
ui_rel_no = string; |
2028 |
} |
2029 |
|
2030 |
/** |
2031 |
* @param string |
2032 |
*/ |
2033 |
public void setUi_ver_no(String string) { |
2034 |
ui_ver_no = string; |
2035 |
} |
2036 |
|
2037 |
} |