View | Details | Raw Unified | Return to bug 82195 | Differences between
and this patch

Collapse All | Expand All

(-)build.properties (-1 / +10 lines)
Lines 9-12 Link Here
9
source.RPMCore.jar = src/
9
source.RPMCore.jar = src/
10
bin.includes = plugin.xml,\
10
bin.includes = plugin.xml,\
11
               *.jar,\
11
               *.jar,\
12
               RPMCore.jar
12
               RPMCore.jar,\
13
               about.html
14
src.includes = .classpath,\
15
               .project,\
16
               .template,\
17
               ChangeLog,\
18
               about.html,\
19
               build.properties,\
20
               plugin.xml,\
21
               src/
(-)plugin.xml (-3 / +8 lines)
Lines 12-20 Link Here
12
        <library name="RPMCore.jar">
12
        <library name="RPMCore.jar">
13
	      <export name="*"/>    
13
	      <export name="*"/>    
14
      </library>
14
      </library>
15
      <library name="RPMPluginPreferencesPage.jar">
16
	      <export name="*"/> 
17
	  </library>
18
   </runtime>
15
   </runtime>
19
    
16
    
20
 
17
 
Lines 25-29 Link Here
25
      <import plugin="org.eclipse.ui" />
22
      <import plugin="org.eclipse.ui" />
26
 
23
 
27
   </requires>
24
   </requires>
25
   <extension
26
         id="rpmnature"
27
         name="RPM Project Nature"
28
         point="org.eclipse.core.resources.natures">
29
         <runtime>
30
         	<run class="org.eclipse.cdt.rpm.core.RPMProjectNature"></run>
31
         </runtime>
32
   </extension>
28
33
29
</plugin>
34
</plugin>
(-)src/org/eclipse/cdt/rpm/core/LinuxShellCmds.java (-387 lines)
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
16
/**
17
  *This class is used to interface to Linux commands
18
  */
19
public class LinuxShellCmds {
20
	private static final boolean debug = false;
21
	private static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$
22
	private static final String line_sep = System.getProperty("line.separator"); //$NON-NLS-1$
23
	private static final String Error = Messages.getString("RPMCore.Error_1"); //$NON-NLS-1$
24
	/**
25
		 * Method createLinuxShellScript.
26
		 * This method is necessary because of problems trying to execute the
27
		 *  "rpmbuild -bb....." command directly from the executeRPMbuild method.
28
		 *  The command did not work the same as it did from the command line.
29
		 *  It appears that the java command line parser does not work very well
30
		 *  on very sophisticated or lengthy command lines. Hence, we build a shell
31
		 *  script to eliminate the java command line parser and all works fine.
32
		 * @param shellString - string containing the command to be executed as a shell script
33
		 * @param rpmbuild_logname - boolean variable which determines whether or 
34
		 * not the output of the shell script to be created should be placed in the 
35
		 * rpmbuild logfile; true means do not output to the logfile, false means output to the logfile
36
		 * @param rpm_shell is the name of the shell to create
37
		 * @return boolean - return true if successful, else throw CoreException
38
		 */
39
		/******************************************************************************/
40
		public static boolean createLinuxShellScript(String shellString,
41
			 String rpmbuild_logname, String rpm_shell)
42
			throws CoreException {
43
			if (debug) {
44
				System.out.println("--createLinuxShellScript: " + shellString); //$NON-NLS-1$
45
			}
46
47
			// if there was a parenthesis at the beginning of the script, put one at the end
48
			String tail;
49
			String first = shellString.substring(0, 1);
50
51
			if (first.equals("(")) { //$NON-NLS-1$
52
				tail = " 2>&1 )" + line_sep; //$NON-NLS-1$
53
			} else {
54
				tail = " 2>&1" + line_sep; //$NON-NLS-1$
55
			}
56
57
			String is = "#!/bin/sh" + line_sep + shellString + " >> " + rpmbuild_logname + //$NON-NLS-1$ //$NON-NLS-2$
58
					tail;
59
60
			byte[] buf = is.getBytes();
61
62
			/* Read the input stream and try to create the shell script to be used by
63
			 * the rpmbuild process   */
64
			try {
65
				BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(
66
					rpm_shell));
67
68
				for (int i = 0; i < buf.length; i++) {
69
					os.write(buf[i]);
70
				}
71
72
				os.close();
73
			} catch (Exception e) {
74
				String throw_message = Messages.getString(
75
						"RPMCore.Problem_creating_a_shell_script_--__342") + //$NON-NLS-1$
76
					rpm_shell +
77
					Messages.getString(
78
						"RPMCore._nThere_may_be_a_problem_in_the_M/makefile._343"); //$NON-NLS-1$
79
				IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
80
						null);
81
				throw new CoreException(error);
82
			}
83
84
			/* Change the file attributes so it is exectable, there is no method that I can
85
			   *  find in java that performs this function   */
86
			String usr_chmod_cmd = RPMCorePlugin.getDefault().getPreferenceStore().getString("IRpmConstants.CHMOD_CMD"); //$NON_NLS-1$
87
			String chmodcommand = usr_chmod_cmd + " 744 " + rpm_shell; //$NON-NLS-1$
88
89
			try {
90
				executeLinuxCommand(chmodcommand, 0);
91
			} catch (CoreException e) {
92
				String throw_message = Messages.getString(
93
						"RPMCore.Problem_running_this_command___346") + //$NON-NLS-1$
94
					chmodcommand +
95
					Messages.getString("RPMCore._nCheck_permissions._347"); //$NON-NLS-1$
96
				IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
97
						null);
98
				throw new CoreException(error);
99
			}
100
101
			return true;
102
		}
103
		
104
	/**
105
	 * Method executeLinuxCommand.
106
	 * This method executes a Linux command passed to it from other methods.  It executes
107
	 * the command, reads the output from the command and passes back a status.  This method
108
	 * is used when several output lines is expected from a command.  If one line or less is
109
	 * expected and the developer wants the output of the command, use the getInfo method.
110
	 * @param linux_command - a string containing a Linux command
111
	 * @param status - what the successful status value from the command should be (normally 0)
112
	 * @return - throws a CoreException if an error is encountered
113
	 */
114
	/****************************************************************************/
115
	public static void executeLinuxCommand(String linux_command, int status)
116
			throws CoreException {
117
		if (debug) {
118
			System.out.println("--executeLinuxCommand: " + //$NON-NLS-1$
119
					linux_command);
120
		}
121
122
		Runtime r = Runtime.getRuntime();
123
		Process p = null;
124
		int result;
125
		String line = ""; //$NON-NLS-1$
126
		String line2 = ""; //$NON-NLS-1$
127
		// prepare buffers for process output and error streams
128
		StringBuffer err = new StringBuffer();
129
		StringBuffer out = new StringBuffer();
130
131
		try {
132
			p = r.exec(linux_command);
133
			// create thread for reading inputStream (process' stdout)
134
			StreamReaderThread outThread = new StreamReaderThread(p
135
					.getInputStream(), out);
136
			// create thread for reading errorStream (process' stderr)
137
			StreamReaderThread errThread = new StreamReaderThread(p
138
					.getErrorStream(), err);
139
			// start both threads
140
			outThread.start();
141
			errThread.start();
142
143
			//wait for process to end
144
			result = p.waitFor();
145
			//finish reading whatever's left in the buffers
146
			outThread.join();
147
			errThread.join();
148
149
			if (result != 0) {
150
				if (debug) {
151
					System.out.println(Messages.getString("LinuxShellCmds.1") //$NON-NLS-1$
152
							+ result);
153
					System.out.println(Messages.getString("LinuxShellCmds.2") + out.toString()); //$NON-NLS-1$
154
					System.out.println(Messages.getString("LinuxShellCmds.3") + err.toString()); //$NON-NLS-1$
155
				}
156
			} else {
157
				if (debug) {
158
					System.out.println(Messages.getString("LinuxShellCmds.4")); //$NON-NLS-1$
159
					System.out.println(Messages.getString("LinuxShellCmds.5") + out.toString()); //$NON-NLS-1$
160
					System.out.println(Messages.getString("LinuxShellCmds.6") + err.toString()); //$NON-NLS-1$
161
				}
162
			}
163
		} catch (Exception e) {
164
			String throw_message = Messages
165
					.getString("RPMCore.Error_executing__97") + linux_command + //$NON-NLS-1$
166
					Messages.getString("LinuxShellCmds.7") + err.toString(); //$NON-NLS-1$
167
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
168
					null);
169
			throw new CoreException(error);
170
		}
171
	}
172
	
173
	/**
174
	 * Method checkCompression. This method takes a spec file path and parses it
175
	 * to see what compression will be required to untar the source file. We
176
	 * assume that the compression will either be gzip or bzip2 since those are
177
	 * the only 2 currently used for RPM's that we have run into.
178
	 * 
179
	 * @param path
180
	 *            to the spec file to be searched
181
	 * @return return the tar file suffix of either ".gz" or ".bz2" if
182
	 *         successful, return "" if not.
183
	 */
184
	public static String checkCompression(String path_to_specfile) throws CoreException {
185
		if (debug) {
186
			System.out.println("--parseSpecfile: " + path_to_specfile); //$NON-NLS-1$
187
		}
188
189
		boolean found_source_line = false;
190
		
191
		try {
192
			FileReader sp_file = new FileReader(path_to_specfile);
193
			StreamTokenizer st = new StreamTokenizer(sp_file);
194
195
			// Make sure numbers, colons and percent signs are considered valid
196
			st.wordChars('a','z');
197
			st.wordChars('A','Z');
198
			st.wordChars(':', ':');
199
			st.wordChars('0', '9');
200
			st.wordChars('%', '%');
201
			st.wordChars('{', '}');
202
			st.wordChars('-', '-');
203
			st.wordChars('/', '/');
204
			st.wordChars('=','=');
205
			st.wordChars('.','.');
206
			st.wordChars('_','_');
207
			st.eolIsSignificant(true);
208
            
209
			String new_word;
210
			boolean check_ifs = false;
211
			int if_ctr = 0;
212
			int token = st.nextToken();
213
			while (token != StreamTokenizer.TT_EOF) {
214
				token = st.nextToken();
215
216
				switch (token) {
217
				case StreamTokenizer.TT_EOL:
218
				  break;
219
				case StreamTokenizer.TT_WORD:
220
					new_word = st.sval;
221
					// System.out.println("---- " + new_word + "\n   line no = " + st.lineno());
222
223
					if (found_source_line) {
224
						if (new_word.endsWith(".gz")) { //$NON-NLS-1$
225
							return ".gz"; //$NON-NLS-1$
226
						} else {
227
							return ".bz2"; //$NON-NLS-1$
228
						}
229
					}
230
					
231
						// Record where the last line of the form "Sourcex:" is
232
						if (new_word.startsWith("Source") &  //$NON-NLS-1$
233
							 new_word.endsWith(":")) { //$NON-NLS-1$
234
							found_source_line = true;
235
							break;
236
						}
237
						
238
				default:
239
					break;
240
				}
241
			}
242
243
			sp_file.close();
244
		} catch (IOException e) {
245
			String throw_message = Messages.getString(
246
					"RPMCore.Error_parsing_the_spec_file_in_the_project_--_157") + //$NON-NLS-1$
247
					path_to_specfile;
248
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
249
					null);
250
			throw new CoreException(error);
251
		}
252
	// If we got here, we could not determine the compression for the tar file
253
		return "";  //$NON-NLS-1$
254
	}
255
	/**
256
	 * Method linuxCopy
257
	 * This method takes two strings containing paths and uses the Linux cp
258
	 * command to copy from the first string path to the second string path.  The
259
	 * reason we sue this instead of native Java techniques is that Java copies
260
	 * do not preserve all of the file attributes, particularly the executable bit and
261
	 * also does not preserve the modification date/time without special handling.
262
	 * In the future when this is taken care of, we will replace this method.
263
	 * @author Red Hat, Inc.
264
	 *@param from_path is a string containing the from path
265
	 *@param to_path is a string containing the to path
266
	 *@return if successful, throw CoreException if not
267
	 */
268
	public static void linuxCopy(String from_path, String to_path, String rpmbuild_logname,
269
			String rpm_shell) throws CoreException {
270
		// If we are doing a directory to directory copy, make sure the to_path
271
		// exists and is a directory
272
		File f = new File(to_path);
273
		File f1 = new File(from_path);
274
		if (f1.isDirectory()) {
275
			if (!f.exists()) {
276
				if (!f.mkdir()) {
277
					String throw_message = Messages.getString("LinuxShellCmds.Error_attempting_to_create___1") + to_path; //$NON-NLS-1$
278
					IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
279
					throw new CoreException(error); 
280
				}
281
			}
282
			if (f.exists() & !f.isDirectory()) {
283
				String throw_message = Messages.getString("LinuxShellCmds.Cannot_copy_a_directory___2") + from_path + //$NON-NLS-1$
284
				  Messages.getString("LinuxShellCmds._to_a_file___3") + to_path; //$NON-NLS-1$
285
				IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
286
				throw new CoreException(error);  
287
			}
288
		}
289
		String usr_cp_cmd = RPMCorePlugin.getDefault().getPreferenceStore().getString("IRpmConstants.CP_CMD"); //$NON_NLS-1$
290
		String cp_cmd = "(cd " + from_path + line_sep + usr_cp_cmd + " -rp . " + to_path; //$NON-NLS-1$ //$NON-NLS-2$
291
				try {
292
					createLinuxShellScript(cp_cmd, rpmbuild_logname, rpm_shell);
293
					executeLinuxCommand(rpm_shell,0);
294
				} catch (CoreException e) {
295
					String throw_message = Messages.getString("LinuxShellCmds.Error_attempting_to_copy_source_from___4") + from_path + //$NON-NLS-1$
296
					Messages.getString("LinuxShellCmds._to__5") + to_path; //$NON-NLS-1$
297
					IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
298
					throw new CoreException(error); 
299
				}
300
	}
301
	
302
		/**
303
		 * Method getInfo.
304
		 * This method takes a Linux/shell command, executes it and passes the output line back
305
		 * as the information string.
306
		 * @param sh_command - a string containing the command to execute
307
		 * @return String - the output of the executed command, maybe null if there is an error
308
		 */
309
		/******************************************************************************/
310
		public static String getInfo(String sh_command) {
311
			if (debug) {
312
				System.out.println("getInfo: " + sh_command); //$NON-NLS-1$
313
			}
314
315
			Runtime r = Runtime.getRuntime();
316
			Process p = null;
317
			int result;
318
			String line = ""; //$NON-NLS-1$
319
			String line2 = ""; //$NON-NLS-1$
320
			int line_ctr = 0;
321
			// prepare buffers for process output and error streams
322
			StringBuffer err=new StringBuffer();
323
			StringBuffer out=new StringBuffer();    
324
325
			try {
326
				p = r.exec(sh_command);
327
				//create thread for reading inputStream (process' stdout)
328
			    StreamReaderThread outThread=new StreamReaderThread(p.getInputStream(),out);
329
			    //create thread for reading errorStream (process' stderr)
330
			    StreamReaderThread errThread=new StreamReaderThread(p.getErrorStream(),err);
331
			    //start both threads
332
			    outThread.start();
333
			    errThread.start();
334
335
				// Set up and capture the stdout messages from the Linux/shell command
336
				
337
			    //wait for process to end
338
			    result=p.waitFor();
339
			    //finish reading whatever's left in the buffers
340
			    outThread.join();
341
			    errThread.join();
342
343
			    if (result!=0) 
344
			        {
345
			    	if (debug) 
346
			    		{
347
			    		System.out.println(Messages.getString("LinuxShellCmds.9")+result); //$NON-NLS-1$
348
			    		System.out.println(Messages.getString("LinuxShellCmds.10")+out.toString()); //$NON-NLS-1$
349
			    		System.out.println(Messages.getString("LinuxShellCmds.11")+err.toString()); //$NON-NLS-1$
350
			    		}
351
			    	return err.toString();
352
			        }
353
			    else
354
			        {
355
			    	if (debug)
356
			    		{
357
			    		System.out.println(Messages.getString("LinuxShellCmds.12")); //$NON-NLS-1$
358
			    		System.out.println(Messages.getString("LinuxShellCmds.13")+out.toString()); //$NON-NLS-1$
359
			    		System.out.println(Messages.getString("LinuxShellCmds.14")+err.toString()); //$NON-NLS-1$
360
			    		}
361
			        return out.toString();
362
			        }
363
			    }
364
			catch (Exception e)
365
			    {
366
			    System.out.println(Messages.getString("LinuxShellCmds.15")); //$NON-NLS-1$
367
			    e.printStackTrace();
368
			    }
369
370
			return line2;
371
		}
372
		
373
	/**
374
	 * Method checkForConfigure checks a project for the presence of a 
375
	 * "configure" script that creates various parts of a project including
376
	 * "Makefile".
377
	 * @return true if "configure" was found, false if not
378
	 */
379
380
	public static boolean checkForConfigure(String proj_path) {
381
//		Check to see if there is a "configure" script for use when creating a spec file
382
			 File f = new File(proj_path + file_sep + "configure"); //$NON-NLS-1$
383
384
			 return f.exists();
385
	}
386
387
}
(-)src/org/eclipse/cdt/rpm/core/Messages.java (-30 lines)
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 java.util.MissingResourceException;
11
import java.util.ResourceBundle;
12
13
public class Messages {
14
15
	private static final String BUNDLE_NAME = "org.eclipse.cdt.rpm.core.rpm_strings"; 
16
17
18
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
19
20
	private Messages() {
21
	}
22
23
	public static String getString(String key) {
24
		try {
25
			return RESOURCE_BUNDLE.getString(key);
26
		} catch (MissingResourceException e) {
27
			return '!' + key + '!';
28
		}
29
	}
30
}
(-)src/org/eclipse/cdt/rpm/core/RPMCore.java (-2037 lines)
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
}
(-)src/org/eclipse/cdt/rpm/core/RPMCorePlugin.java (-26 / +61 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * (c) 2004 Red Hat, Inc.
2
 * (c) 2004, 2005 Red Hat, Inc.
3
 *
3
 *
4
 * This program is open source software licensed under the 
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
5
 * Eclipse Public License ver. 1
Lines 7-19 Link Here
7
7
8
package org.eclipse.cdt.rpm.core;
8
package org.eclipse.cdt.rpm.core;
9
9
10
import org.eclipse.ui.plugin.AbstractUIPlugin;
10
import java.io.File;
11
import org.eclipse.core.resources.IWorkspace;
11
import java.io.IOException;
12
import org.eclipse.jface.preference.IPreferenceStore;
13
14
import java.net.UnknownHostException;
12
import java.net.UnknownHostException;
15
import java.util.ResourceBundle;
16
import java.util.MissingResourceException;
13
import java.util.MissingResourceException;
14
import java.util.ResourceBundle;
15
16
import org.eclipse.cdt.rpm.core.internal.Messages;
17
import org.eclipse.core.resources.IWorkspace;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.jface.preference.IPreferenceStore;
22
import org.eclipse.ui.plugin.AbstractUIPlugin;
17
import org.osgi.framework.BundleContext;
23
import org.osgi.framework.BundleContext;
18
24
19
/**
25
/**
Lines 24-31 Link Here
24
	private static RPMCorePlugin plugin;
30
	private static RPMCorePlugin plugin;
25
	//Resource bundle.
31
	//Resource bundle.
26
	private ResourceBundle resourceBundle;
32
	private ResourceBundle resourceBundle;
33
	//Shell script shared by all external operations
34
	private File shellScriptFile;
35
	//Log file shared by all external operations
36
	private File externalLogFile;
37
	
38
	public static final String ID = "org.eclipse.cdt.rpm.core";
27
	
39
	
28
	static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$
29
	
40
	
30
	/**
41
	/**
31
	 * The constructor.
42
	 * The constructor.
Lines 88-114 Link Here
88
	protected void initializeDefaultPreferences(IPreferenceStore store)
99
	protected void initializeDefaultPreferences(IPreferenceStore store)
89
		 {
100
		 {
90
		  String user_name = System.getProperty("user.name");
101
		  String user_name = System.getProperty("user.name");
91
		  store.setDefault("IRpmConstants.RPM_WORK_AREA","/var/tmp");
102
		  store.setDefault(IRPMConstants.RPM_DISPLAYED_LOG_NAME, ".logfilename_" //$NON-NLS-1$
92
		  store.setDefault("IRpmConstants.USER_WORK_AREA",file_sep + "rpm_workarea");
93
		  store.setDefault("IRpmConstants.RPM_DISPLAYED_LOG_NAME",".logfilename_"
94
		  		+ user_name);
103
		  		+ user_name);
95
		  store.setDefault("IRpmConstants.SPEC_FILE_PREFIX","eclipse_");
104
		  store.setDefault(IRPMConstants.RPM_LOG_NAME, "rpmbuild.log"); //$NON-NLS-1$
96
		  store.setDefault("IRpmConstants.SRPM_INFO_FILE",file_sep+".srpminfo");
105
		  store.setDefault(IRPMConstants.AUTHOR_NAME, user_name);
97
		  store.setDefault("IRpmConstants.RPM_SHELL_SCRIPT","rpmshell.sh");
106
		  store.setDefault(IRPMConstants.AUTHOR_EMAIL, user_name + "@" + getHostName()); //$NON-NLS-1$
98
		  store.setDefault("IRpmConstants.RPM_LOG_NAME","rpmbuild.log");
107
	
99
		  store.setDefault("IRpmConstants.RPM_RESOURCE_FILE",".rpmrc");
108
		  store.setDefault(IRPMConstants.RPM_CMD, "/bin/rpm"); //$NON-NLS-1$
100
		  store.setDefault("IRpmConstants.RPM_MACROS_FILE",".rpm_macros");
109
		  store.setDefault(IRPMConstants.RPMBUILD_CMD, "/usr/bin/rpmbuild"); //$NON-NLS-1$
101
		  store.setDefault("IRpmConstants.AUTHOR_NAME",user_name); //$NON-NLS-1$ //$NON-NLS-2$
110
		  store.setDefault(IRPMConstants.DIFF_CMD, "/usr/bin/diff"); //$NON-NLS-1$
102
		  store.setDefault("IRpmConstants.AUTHOR_EMAIL",user_name +"@" + getHostName()); //$NON-NLS-1$ //$NON-NLS-2$
103
	
104
		  store.setDefault("IRpmConstants.MAKE_CMD", "/usr/bin/make"); //$NON-NLS-1$ //$NON-NLS-2$
105
		  store.setDefault("IRpmConstants.RPM_CMD", "/bin/rpm"); //$NON-NLS-1$ //$NON-NLS-2$
106
		  store.setDefault("IRpmConstants.RPMBUILD_CMD", "/usr/bin/rpmbuild"); //$NON-NLS-1$ //$NON-NLS-2$
107
		  store.setDefault("IRpmConstants.CHMOD_CMD", "/bin/chmod"); //$NON-NLS-1$ //$NON-NLS-2$
108
		  store.setDefault("IRpmConstants.CP_CMD", "/bin/cp"); //$NON-NLS-1$ //$NON-NLS-2$
109
		  store.setDefault("IRpmConstants.DIFF_CMD", "/usr/bin/diff"); //$NON-NLS-1$ //$NON-NLS-2$
110
		  store.setDefault("IRpmConstants.TAR_CMD", "/bin/tar"); //$NON-NLS-1$ //$NON-NLS-2$
111
		 }
111
		 }
112
113
	
114
	//Note this method is not thread-safe
115
	public File getShellScriptFile() throws CoreException {
116
		if(shellScriptFile == null) {
117
			try {
118
				shellScriptFile = File.createTempFile(RPMCorePlugin.ID, ".sh"); //$NON-NLS-1$
119
			} catch(IOException e) {
120
				String throw_message = Messages.getString("RPMCore.Error_creating__1") + //$NON-NLS-1$
121
				  shellScriptFile.getAbsolutePath();
122
				IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1,
123
						throw_message, null);
124
				throw new CoreException(error);
125
			}
126
		}
127
		return shellScriptFile;
128
	}
129
	
130
	//Note this method is not thread-safe
131
	public File getExternalLogFile() throws CoreException {
132
		if(externalLogFile == null) {
133
			try {
134
				externalLogFile = File.createTempFile(RPMCorePlugin.ID, ".log"); //$NON-NLS-1$
135
			} catch(IOException e) {
136
				String throw_message = Messages.getString("RPMCore.Error_creating__1") + //$NON-NLS-1$
137
				  externalLogFile.getAbsolutePath();
138
				IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1,
139
						throw_message, null);
140
				throw new CoreException(error);
141
			}
142
		}
143
		return externalLogFile;
144
	}
145
112
	/** 
146
	/** 
113
	* Method getHostName gets the name of the host to use as part of the
147
	* Method getHostName gets the name of the host to use as part of the
114
	* e-mail address for the changelog entry in the spec file.
148
	* e-mail address for the changelog entry in the spec file.
Lines 138-141 Link Here
138
		 }
172
		 }
139
		 return hosttemp.substring(1);
173
		 return hosttemp.substring(1);
140
	}
174
	}
175
   
141
}
176
}
(-)src/org/eclipse/cdt/rpm/core/RPMExport.java (-35 lines)
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
/**
15
  *This class is used to manipulate RPM files for Linux systems
16
  */
17
public class RPMExport extends RPMExportCore {
18
19
	private static final boolean debug = false;
20
	
21
	public RPMExport(String c_proj_path) 
22
		throws CoreException {
23
	  	super(c_proj_path, "-bb"); //$NON-NLS-1$
24
	}
25
	
26
	public void run() throws CoreException {
27
		try {
28
			super.run();
29
		} catch (Exception e) {
30
			String throw_message = e.getMessage();
31
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
32
			throw new CoreException(error); 	
33
		}
34
	}
35
}
(-)src/org/eclipse/cdt/rpm/core/RPMExportCore.java (-472 lines)
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
import java.io.File;
14
import java.io.FileNotFoundException;
15
import java.io.IOException;
16
17
/**
18
  *This class is the core class that is extended by RPMExport and SRPMExport.
19
  * It conatins the main methods for exporting either a binary or source RPM.
20
  */
21
public class RPMExportCore extends RPMCore {
22
23
	protected String ui_spec_file = ""; //$NON-NLS-1$
24
	protected String patch_name;
25
	protected String patch_tag;
26
	protected String changelog_entry;
27
	
28
	private String which_rpm;
29
	private SpecFileOps specfileops;
30
	
31
	private static final String src_exp = "-bs"; //$NON-NLS-1$
32
	private static final String bin_exp = "-bb"; //$NON-NLS-1$
33
	private static final boolean debug = false;
34
	
35
	/**
36
	 * This is the constructor called to instantiate this class.
37
	 * @param c_proj_path is the path to the Eclipse project to be exported.
38
	 * @param c_which_rpm is which rpm to export; "-bs" = source, "-bb" = binary
39
	 * @throws CoreException
40
	 */
41
	
42
	public RPMExportCore (String c_proj_path, String c_which_rpm) 
43
   	    throws CoreException {
44
		super(c_proj_path, ""); //$NON-NLS-1$
45
46
		which_rpm = c_which_rpm;
47
48
		int j = proj_path.lastIndexOf(file_sep);
49
		proj_dir = proj_path.substring(j + 1);
50
 	}
51
 	
52
	/**
53
		 * Method run will call the proper methods in the proper sequence
54
		 * to create the appropriate RPM.  This is called from the GUI to
55
		 * segregate the implementation from the user interface.
56
		 * @return if successful, throws CoreException if not
57
		 */
58
	public void run() throws CoreException {
59
		if (debug) {
60
					System.out.println("*************** RPMExportCore run **********************"); //$NON-NLS-1$
61
		}
62
		// Create the work area for rpm to do its thing
63
		try {
64
			setRpmbuild_logname();
65
			createRPMdirectories(rpmdirs_path);
66
			createRPMmacros(rpm_macros);
67
			createRPMrpmrc(rpmrc);
68
			createRPMLogFile();
69
		} catch (Exception e) {
70
			String throw_message = e.getMessage();
71
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
72
			throw new CoreException(error); 
73
		}
74
		// If we are exporting a binary RPM and the source RPM is already built and contains
75
		// the same version/release numbers and the checksums are the same
76
		//  just build the RPM from the source
77
		if (ui_ver_no.equals(getRpm_version()) & ui_rel_no.equals(getRpm_release()) &
78
			patch_tag == null & which_rpm.equals("-bb") & !isChk_sum_diff()) { //$NON-NLS-1$
79
				try {
80
					buildBinaryFromSourceRpm();
81
				} catch (Exception e) {
82
					String throw_message = e.getMessage();
83
					IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
84
					throw new CoreException(error); 
85
				}
86
				return;
87
			}
88
		// Was this project previously exported (does a .srpminfo file exist)
89
		if (firstSRPM(proj_path)) {
90
			// if this is the first time this project has been exported, branch off to another method
91
			try {
92
				createSRPM();
93
			} catch (CoreException e) {
94
				String throw_message = e.getMessage();
95
				IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
96
				throw new CoreException(error);
97
			}
98
			return;
99
		}
100
		String path_to_newspecfile;
101
		/** During an export we install the source rpm this project was imported from
102
		 * and then copy the Eclipse project itself over to the to allow us to create patches
103
		 * by executing the "diff" command.  In the future we should change this behaviour
104
		 * to only occur when a source RPM is being exported, but for now we do it the same
105
		 * for both exports.
106
		 */
107
		// Install the source into the rpm workarea 
108
		try {
109
			installRPMsource(getPath_to_rpm());  // "rpm -i ...." command
110
			executeRPMbuildprep();               // "rpmbuild -bp ...." command
111
			// If the user specfied a spec file, use it instead of modifying the one in the project
112
			if (ui_spec_file.startsWith(spec_file_prefix)) { 
113
				specfileops = new SpecFileOps(proj_path, rpmdirs_path, wksp_path, proj_dir);
114
				path_to_newspecfile =
115
			   		specfileops.changeRPMspecfile(ui_ver_no, ui_rel_no, rpm_version, 
116
					rpm_release,patch_tag,changelog_entry,rpm_name,getPath_to_specfile());
117
				// Now generate patches by doing a diff between the old source RPM and
118
				// the current project directory
119
				generateSRPMpatch(ui_ver_no, patch_tag);
120
			} else {
121
				path_to_newspecfile = ui_spec_file;
122
			}
123
			/* If the version number changed, we must change the tarball name if we are exporting
124
			 * a source rpm export, the source tarball name format is:
125
			 * rpmname-version.tar.zz where zz is usually either bz2 or gz
126
			 */
127
			 if (which_rpm.equals(src_exp) & !ui_ver_no.equals(getRpm_version())) {
128
			 	TarOps tarops = new TarOps(proj_path, rpmdirs_path);
129
			 	try {
130
			 		tarops.renameRPMtarfile(getRpm_name(), getRpmbuild_logname(),
131
			 	   		getRpm_shell(), ui_ver_no, getRpm_version());
132
			 	} catch (Exception e) {
133
					String throw_message = e.getMessage();
134
					IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
135
					throw new CoreException(error);
136
			 	}
137
			 }
138
			// Replace the spec file in the work area with the new one we just created
139
			String spec_path = replaceSpecFile(path_to_newspecfile);
140
			// Now build us an RPM....which_rpm governs which one
141
			executeRpmBuild(which_rpm, spec_path);
142
			// Now copy the newly created RPM(s) back to the Eclipse project
143
			String new_src_rpm = copyRpms(which_rpm);
144
			// Only create a new spec file/.srpminfo file if a source RPM was exported
145
			if (which_rpm.equals("-bs")) { //$NON-NLS-1$
146
				String newspecpath = renameSpecFile(path_to_newspecfile, spec_path);
147
				int j = new_src_rpm.lastIndexOf(file_sep);
148
				String srpm_full_name = new_src_rpm.substring(j + 1);
149
				createSRPMinfo(newspecpath, srpm_full_name);
150
				// Delete the newly created spec file if we exported a binary RPM
151
				} else {
152
					try {
153
						File f = new File(path_to_newspecfile);
154
						f.delete();
155
					} catch (Exception e) {
156
						String throw_message = "Error trying to delete newly created spec file at: " //$NON-NLS-1$
157
							+ path_to_newspecfile;
158
						IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
159
						throw new CoreException(error);
160
					}
161
				}
162
163
			deleteRPMresources(rpmdirs_path);
164
		} catch (Exception e) {
165
			String throw_message = e.getMessage();
166
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
167
			throw new CoreException(error);
168
		}
169
	  return;
170
	}
171
	
172
	/**
173
			 * Method renameSpecFile will delete the previous "eclipse_...spec"
174
			 * and the new "eclipse_...spec.new" files from the project and copy the
175
			 * spec file that was used to perform the building of the source rpm from
176
			 * the work area to the project renaming it to "eclipse_...spec"
177
			 * @param path is a String containing the path to the spec file either created 
178
			 * by changeRPMspec which was created from the original spec file but has
179
			 * the version and/or release numbers changed along with the addition of
180
			 * Patch:/%patch/Changelog statements or is a user-specified spec file
181
			 * @param path2 is a String containing the path to the spec file in the rpm 
182
			 * workarea so we can copy it back to the project for future use
183
			 * @return the path to the new spec file so this information can be included
184
			 * in the .srpminfo file so the next time we export we'll know which spec file
185
			 * to use; throws CoreException if there is an error
186
			 */
187
	public String renameSpecFile(String path, String path2) throws CoreException {
188
		if (debug) {
189
					System.out.println("renameSpecFile" + line_sep + " path = " + path + //$NON-NLS-1$ //$NON-NLS-2$
190
						line_sep + "  path2 = " + path2); //$NON-NLS-1$
191
		}
192
		int j = path2.lastIndexOf(file_sep);
193
		String spec_name;
194
		if (j != -1) {
195
			spec_name = path2.substring(j+1);
196
		} else {
197
			spec_name = path2;
198
		}
199
		// Only delete the spec file is the user did not specify their own spec file
200
		if (ui_spec_file.startsWith(spec_file_prefix)) {
201
		  File f = new File(path);
202
		  File f1 = new File(getPath_to_specfile());
203
		  if (!f.delete() | !f1.delete()) {
204
			String throw_message = "Error trying to delete " + f + " or " + f1; //$NON-NLS-1$ //$NON-NLS-2$
205
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
206
			throw new CoreException(error);
207
		  }
208
		}
209
210
			try {
211
				copyFile(path2, proj_path + file_sep + getSpec_file_prefix() + spec_name);
212
			} catch (FileNotFoundException e) {
213
				
214
				e.printStackTrace();
215
			} catch (IOException e) {
216
				
217
				e.printStackTrace();
218
			} catch (CoreException e) {
219
				
220
				e.printStackTrace();
221
			}
222
		return proj_path + file_sep + spec_name;
223
	}
224
	
225
	/**
226
			 * Method replaceSpecFile takes the new spec file created by changeRPMspec
227
			 * with the new information and copies it to the rpm workarea replacing the spec
228
			 * file that was a part of original source RPM.
229
			 * @param contains a String with is the path to the newly created spec file
230
			 * which resides in the project for now.
231
			 * @return if successful, throws CoreException if not
232
			 */
233
	
234
	public String replaceSpecFile(String path) throws CoreException {
235
		if (debug) {
236
					System.out.println("replaceSpecFile"); //$NON-NLS-1$
237
		}
238
		String temp = rpmdirs_path + file_sep + "SPECS" + file_sep; //$NON-NLS-1$
239
		File f = new File(temp);
240
		String[] subdir = f.list();
241
		if (subdir.length != 1) {
242
			String throw_message = Messages.getString("RPMExportCore.Too_many_spec_files_in__4") + temp;  //$NON-NLS-1$
243
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
244
			throw new CoreException(error);
245
		}
246
		File f1 = new File(temp + subdir[0]);
247
		if (!f1.delete()) {
248
			String throw_message = Messages.getString("RPMExportCore.Error_trying_to_delete__5") + f1;  //$NON-NLS-1$
249
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
250
			throw new CoreException(error);
251
		}
252
		 try {
253
			copyFile(path, temp + subdir[0]);
254
		} catch (FileNotFoundException e) {
255
			e.printStackTrace();
256
		} catch (IOException e) {
257
			e.printStackTrace();
258
		} catch (CoreException e) {
259
			e.printStackTrace();
260
		}
261
		return temp + subdir[0];
262
	}
263
	
264
	/**
265
			 * Method createSRPM is called when a project has never been
266
			 * exported as a project before.
267
			 * @return if successful, throws CoreException if not
268
			 */
269
	public void createSRPM() throws CoreException {
270
		if (debug) {
271
			System.out.println("createSRPM"); //$NON-NLS-1$
272
		}
273
		String spec_dir = file_sep + "SPECS" + file_sep;
274
		// Since this is the first time this project has been exported as an RPM,
275
		// use the version/release number entered by the user
276
		rpm_version = ui_ver_no;
277
		rpm_release = ui_rel_no;
278
		// Copy the project to the work area to preserve the Eclipse project
279
		String proj_work_dir = rpmdirs_path + file_sep + "BUILD" + file_sep + proj_dir; //$NON-NLS-1$
280
		// Copy the project to the rpm workarea so we can work on it
281
		try {
282
			LinuxShellCmds.linuxCopy(proj_path, proj_work_dir, getRpmbuild_logname(), 
283
			   getRpm_shell());
284
		} catch (Exception e) {
285
			String throw_message = e.getMessage();
286
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
287
			throw new CoreException(error);
288
		}
289
		String spec_file_name = ui_spec_file;
290
		String spec_file_path = ui_spec_file;
291
		// Invoke the specfile ops class to create a new spec file if the user has not specified one
292
		// If the user chose a spec file inside the Eclipse project, there will not be any
293
		// '/'s in the name, if there are '/'s, figure out the name
294
		if (!ui_spec_file.equals("")) { //$NON-NLS-1$
295
			int i = ui_spec_file.lastIndexOf(file_sep);
296
			if (i != -1) {
297
				spec_file_name = ui_spec_file.substring(i+1);
298
				spec_file_path = ui_spec_file;
299
			}
300
		} else {
301
			spec_file_name = proj_dir + ".spec"; //$NON-NLS-1$
302
			spec_file_path = rpmdirs_path + spec_dir + spec_file_name;
303
			SpecFileOps specfileops = new SpecFileOps(proj_path, rpmdirs_path, wksp_path, 
304
		   		proj_dir);
305
			specfileops.createRPMspec(getRpm_shell(), getRpmbuild_logname(),
306
		     	proj_work_dir, rpm_version, rpm_release, rpmdirs_path + spec_dir + 
307
		     		spec_file_name,
308
		     	rpm_name);
309
		}
310
		
311
		// Now create a tarball for the source if the user has indicated that a source RPM be built
312
		if (which_rpm.equals("-bs")) { //$NON-NLS-1$
313
		// Clean up after the spec file creation is done in preparation for creating a tarball
314
			try {
315
				executeMakeClean(proj_work_dir);
316
			} catch (Exception e) {
317
				String throw_message = e.getMessage();
318
				IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
319
				throw new CoreException(error);
320
			}
321
		}		
322
			try {
323
				TarOps tarops = new TarOps(proj_path, rpmdirs_path);
324
				tarops.createRPMtarfile(rpm_name, rpm_version, spec_file_path);
325
			} catch (Exception e) {
326
				String throw_message = e.getMessage();
327
				IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
328
				throw new CoreException(error);
329
			}
330
		// Copy the spec file to be used by rpmbuild to the work area if it isn't already there
331
		if (!spec_file_path.equals(rpmdirs_path + spec_dir + spec_file_name)) { 
332
			try {
333
				 copyFile(spec_file_path, rpmdirs_path + spec_dir + spec_file_name);
334
			  	  } catch (Exception e) {
335
				  	String throw_message = e.getMessage();
336
				  	IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
337
				  	throw new CoreException(error); 
338
			  	  }
339
		}
340
		// Now, build the RPM's and copy them to the project
341
		try {
342
			executeRpmBuild(which_rpm, spec_file_path);
343
			String path_to_src_rpm = copyRpms(which_rpm);
344
			copyFile(rpmdirs_path + spec_dir + spec_file_name, proj_path + file_sep + 
345
			getSpec_file_prefix() + spec_file_name);
346
			if (which_rpm.equals("-bs")){ //$NON-NLS-1$
347
				int j = path_to_src_rpm.lastIndexOf(file_sep);
348
				String src_name = path_to_src_rpm.substring(j+1);
349
				createSRPMinfo(getSpec_file_prefix() + spec_file_name, src_name);
350
			}
351
		} catch (Exception e) {
352
			String throw_message = e.getMessage();
353
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
354
			throw new CoreException(error);
355
		}
356
		// Now clean up the work area
357
		try {
358
			deleteRPMresources(rpmdirs_path);
359
		} catch (Exception e) {
360
			String throw_message = e.getMessage();
361
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
362
			throw new CoreException(error);
363
		}
364
	}
365
	
366
	/**
367
			 * Method createSRPMinfo is used as an interface to the same method
368
			 * inthe RPMCore class.  We just put try/catch around it
369
			 * @param file1 is a string containing the Eclipce spec file name in the Eclipse project
370
			 * @param file2 is a string containing the name of the new source rpm that resides
371
			 * in the project
372
			 * @return if successful, throws CoreException if not
373
			 */
374
	public void createSRPMinfo(String specfile, String src_name)
375
		throws CoreException {
376
			int j = specfile.lastIndexOf(file_sep);
377
			if (j != -1) {
378
				specfile = getSpec_file_prefix() + specfile.substring(j+1);
379
			}
380
			// Now, recreate the .srpminfo file in the project to point to the new source RPM
381
			try {
382
				super.createSRPMinfo(specfile, src_name);
383
			} catch (Exception e) {
384
				String throw_message = e.getMessage();
385
				IStatus error = new Status(IStatus.ERROR, Error, 1,
386
						throw_message, null);
387
				throw new CoreException(error);
388
			}
389
	}
390
	
391
	/**
392
			 * Method buildBinaryFromSource builds a binary RPM from a source RPM
393
			 * that has previously been created in the project.
394
			 * @return if successful, throws CoreException if not
395
			 */
396
	public void buildBinaryFromSourceRpm() throws CoreException {
397
		if (debug) {
398
			System.out.println("buildBinaryFromSourceRpm"); //$NON-NLS-1$
399
		}
400
		try {
401
			installRPMsource(getPath_to_rpm());  // "rpm -i ...." command
402
			//	Now build us an RPM....which_rpm governs which one
403
			String spec_path = findSpecFileName();
404
			executeRpmBuild(which_rpm, spec_path);
405
			copyRpms(which_rpm);
406
			deleteRPMresources(rpmdirs_path);
407
		} catch (Exception e) {
408
			String throw_message = e.getMessage();
409
			IStatus error = new Status(IStatus.ERROR, Error, 1,
410
							throw_message, null);
411
			throw new CoreException(error);
412
		}
413
		return;
414
		}
415
	
416
	/**
417
	 * Method findSpecFileName will return the name of the spec file in the 
418
	 * SPECS directory of the RPM work area.
419
	 * @return if successful, throws CoreException if not
420
	 */
421
	public String findSpecFileName() throws CoreException {
422
		if (debug) {
423
			System.out.println("findSpecFileName"); //$NON-NLS-1$
424
		}
425
		File f = new File(rpmdirs_path + file_sep + "SPECS" + file_sep); //$NON-NLS-1$
426
		String[] subdir = f.list();
427
		if (subdir.length != 1) {
428
			String throw_message = "Error in spec file directory:" + f; //$NON-NLS-1$
429
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
430
			throw new CoreException(error);
431
		}
432
		return rpmdirs_path + file_sep + "SPECS" + file_sep + subdir[0]; //$NON-NLS-1$
433
	}
434
435
	/**
436
	 * @param string
437
	 */
438
	public void setPatch_name(String string) {
439
		patch_name = string;
440
	}
441
442
	/**
443
	 * @param string
444
	 */
445
	public void setPatch_tag(String string) {
446
		patch_tag = string;
447
	}
448
449
	/**
450
	 * @param string containing the changelog entry the user entered
451
	 * 	from the GUI
452
	 */
453
	public void setChangelog_entry(String string) {
454
		changelog_entry = string;
455
	}
456
457
	/**
458
	 * @param string
459
	 */
460
	public void setUi_spec_file(String string) {
461
		ui_spec_file = string;
462
		if (!string.equals("") & string != null) { //$NON-NLS-1$
463
			int i = spec_file_name.lastIndexOf(file_sep);
464
			if (i == -1) {
465
				setPath_to_specfile(proj_path + file_sep + ui_spec_file);
466
			} else {
467
				setPath_to_specfile(ui_spec_file);
468
			}
469
		}
470
	}
471
472
}
(-)src/org/eclipse/cdt/rpm/core/SRPMExport.java (-46 lines)
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
package org.eclipse.cdt.rpm.core;
8
9
import org.eclipse.core.runtime.CoreException;
10
import org.eclipse.core.runtime.IStatus;
11
import org.eclipse.core.runtime.Status;
12
13
14
/**
15
  *This class is called from the GUI when a source RPM is to be created.
16
  */
17
public class SRPMExport extends RPMExportCore {
18
	
19
	private static final boolean debug = false;
20
	
21
	/**
22
	 * This is the constructor called by the GUI to instantiate this class.
23
	 * @param c_proj_path is the path to the Eclipse project to be exported
24
	 * @param c_wksp_path is the path to the temporary work area to be used by rpm
25
	 * @throws CoreException
26
	 */
27
	
28
	public SRPMExport(String c_proj_path) throws CoreException {
29
		super(c_proj_path, "-bs"); //$NON-NLS-1$
30
	}
31
	
32
	/**
33
	 * This run method is called by the GUI to run the methods to create a source RPM.
34
	 * @return if successful, throw CoreException if not
35
	 * @throws CoreException
36
	 */
37
	public void run() throws CoreException {
38
		try {
39
			super.run();
40
		} catch (Exception e) {
41
			String throw_message = e.getMessage();
42
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
43
			throw new CoreException(error); 	
44
		}
45
	}
46
}
(-)src/org/eclipse/cdt/rpm/core/SRPMImport.java (-297 lines)
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
package org.eclipse.cdt.rpm.core;
8
9
import org.eclipse.core.runtime.CoreException;
10
import org.eclipse.core.runtime.IStatus;
11
import org.eclipse.core.runtime.Status;
12
13
import java.io.*;
14
15
/**
16
  *This class is used to import source RPMs into Eclipse projects.
17
  *It is called by the GUI to invoke the run method which does the import.
18
  */
19
public class SRPMImport extends RPMCore {
20
21
	private boolean doAutoconf = true;
22
	private boolean doPatches = true; 
23
	
24
	//	When debug is set to true, lots of debug statements are printed.
25
	private static final boolean debug = false;
26
	/*
27
	 * Constructor to create data for the RPMCore class.
28
	 */
29
  public SRPMImport(String c_proj_path, String c_path_to_rpm) 
30
  	throws CoreException {
31
		super(c_proj_path, c_path_to_rpm);
32
		
33
		int j = path_to_rpm.lastIndexOf(file_sep);
34
		if (j == -1) {
35
			srpm_full_name = path_to_rpm;
36
		} else {
37
			srpm_full_name = path_to_rpm.substring(j+1);
38
		}
39
  }
40
		  
41
	/**
42
		 * Method setupSRPMworkarea.
43
		 * This method is called by the GUI to setup the RPM workarea specified
44
		 * in the "rpmdirs_bld" path.  The directories that rpm will use to install and 
45
		 * setup the source rpm before importing it into the Eclipse project.
46
		 * @return return if successful, throw CoreException if failed
47
		 */
48
	public void run() throws CoreException {
49
		if (debug) {
50
			System.out.println("******************Import run*****************"); //$NON-NLS-1$
51
		}
52
		setRpmbuild_logname();
53
		rpmbuild_logname = getRpmbuild_logname();
54
		try {
55
			createRPMdirectories(rpmdirs_path);
56
			createRPMmacros(rpm_macros);
57
			createRPMrpmrc(rpmrc);
58
			createRPMLogFile();
59
		} catch (Exception e) {
60
			String throw_message = e.getMessage();
61
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
62
			throw new CoreException(error); 
63
		}
64
		String orig_proj_path;
65
		try {
66
			orig_proj_path = getSourceCode();
67
		} catch (Exception e) {
68
			String throw_message = e.getMessage();
69
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
70
			throw new CoreException(error); 
71
		}
72
				
73
		// Now see if 'configure' should be run, but only if we applied patches
74
		if (doAutoconf & doPatches) {
75
			executeProjConfigure(orig_proj_path);
76
		}
77
		// We are now ready to copy the files from the work area to the Eclipse project
78
		
79
		try {
80
			LinuxShellCmds.linuxCopy(orig_proj_path, proj_path, rpmbuild_logname, rpm_shell);
81
		} catch (CoreException e) {
82
			String throw_message = e.getMessage();
83
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
84
			throw new CoreException(error); 
85
		}
86
		String spec_dir = file_sep + "SPECS" + file_sep; //$NON-NLS-1$
87
		// Copy the spec file and source RPM to the project for safekeeping
88
		File f = new File(rpmdirs_path + spec_dir); 
89
		String[] subdir = f.list();
90
		if (subdir == null | subdir.length > 1) {
91
			String throw_message = "There should only be one file in: " + rpmdirs_path + spec_dir; //$NON-NLS-1$
92
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
93
			throw new CoreException(error); 
94
		}
95
		String from_file = rpmdirs_path + spec_dir + subdir[0];
96
		try {
97
			super.copyFile(from_file, proj_path + file_sep + spec_file_prefix + subdir[0]);
98
			super.copyFile(path_to_rpm, proj_path + file_sep + srpm_full_name);
99
		} catch (Exception e) {
100
			String throw_message = e.getMessage();
101
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
102
			throw new CoreException(error); 
103
		}
104
		// Now, create a file that resides in the project that contains information 
105
		int j = path_to_rpm.lastIndexOf(file_sep);
106
		String srpm_full_name = path_to_rpm.substring(j + 1); 
107
		createSRPMinfo(spec_file_prefix + subdir[0], srpm_full_name);
108
		// Now clean up the RPM work area
109
		deleteRPMresources(rpmdirs_path);
110
	}
111
	
112
	/**
113
		 * Method getSourceCode.
114
		 * This method is called to install the source code and then depending
115
		 * on whether or not patches are to be applied either run the rpmbuild
116
		 * command or untar the source tarball.
117
		 * @return return path to the source if successful, return "" or 
118
		 *    throw CoreException if failed
119
		 */
120
	public String getSourceCode() throws CoreException {
121
		if (debug) {
122
			System.out.println("getSourceCode"); //$NON-NLS-1$
123
		}
124
		try {
125
					installRPMsource(path_to_rpm);
126
				} catch (CoreException e) {
127
					String throw_message = e.getMessage();
128
					IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
129
					throw new CoreException(error); 
130
				}
131
				// If the doPatches switch is set run the "rpmbuild -bp" command to install the 
132
				//  source with patches
133
				if (doPatches) {
134
					try {
135
						executeRPMbuildprep();
136
					}  catch (CoreException e) {
137
						String throw_message = e.getMessage();
138
						IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
139
						throw new CoreException(error); 
140
					}
141
					// Figure out what the path to the installed sources is
142
					File f = new File(rpmdirs_path + file_sep + "BUILD"); //$NON-NLS-1$
143
					String subdir[] = f.list();
144
					if (subdir == null | subdir.length != 1) {
145
						String throw_message = Messages.getString("SRPMImport.Error_occurred_during_the_source_install._n_1") + //$NON-NLS-1$
146
						   Messages.getString("SRPMImport.There_are_either_too_many_or_0_directories_under__2") + f; //$NON-NLS-1$
147
						IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
148
						throw new CoreException(error); 
149
					}
150
					return rpmdirs_path + file_sep + "BUILD" + file_sep + subdir[0]; //$NON-NLS-1$
151
				// If doPatches is not set, untar the source myself
152
				} else {
153
					String tarball_path = findTarBallPath(rpmdirs_path + file_sep + "SOURCES"); //$NON-NLS-1$
154
					if (tarball_path != "") { //$NON-NLS-1$
155
					  TarOps tarOps = new TarOps(proj_path, rpmdirs_path);
156
					  try {
157
						tarOps.untarSource(tarball_path, rpmbuild_logname, rpm_shell);
158
					  } catch (CoreException e) {
159
						  String throw_message =e.getMessage();
160
						  IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
161
						  throw new CoreException(error); 
162
					  }
163
					} else {
164
						String throw_message = Messages.getString("SRPMImport.Cannot_find_a_tarball_to_untar_in___3") + tarball_path; //$NON-NLS-1$
165
						IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message, null);
166
						throw new CoreException(error); 
167
					}
168
				}
169
						// Figure out where the source code is, there *should* be only one directory
170
						 // in the 'rpmdirs_path/SOURCES/' directory
171
						 String src_path = rpmdirs_path + file_sep + "SOURCES" + file_sep; //$NON-NLS-1$
172
						 File f = new File(src_path);
173
						 String[] subdir = f.list();
174
						 for (int i =0; i<subdir.length; i++) {
175
							 File f1 = new File(src_path + subdir[i]);
176
							 if (f1.isDirectory()) {
177
								 return src_path + subdir[i];
178
							 }
179
						 }
180
		return ""; //$NON-NLS-1$
181
	}
182
	/**
183
	 * Method findTarBallPath.
184
	 * This method is called to find a tarball in the directory passed to it.
185
	 * @param String containing the path to the directory to search for the tarball
186
	 * @return String containing a path to the tarball if there is one, else return ""
187
	 */
188
	public String findTarBallPath(String path) {
189
		File f = new File(path);
190
		String[] subdir = f.list();
191
		for (int i = 0; i<subdir.length;i++) {
192
			if (subdir[i].endsWith(".bz2") | subdir[i].endsWith(".gz") | //$NON-NLS-1$ //$NON-NLS-2$
193
			  subdir[i].endsWith(".tar")) { //$NON-NLS-1$
194
			  	return path + file_sep + subdir[i];
195
			  }
196
		}
197
	  return "";	//$NON-NLS-1$
198
	}
199
	
200
	/**
201
		 * Method executeRPMbuildprep.
202
		 * This method creates a shell script with the 'rpmbuild -bp' command that takes the sources
203
		 * peviously installed in the RPM work area, untars them into the BUILD directory and applies
204
		 * all of the patches specified in the spec file.
205
		 * @return String - path to the original srpm that was copied into the work area
206
		 */
207
		/******************************************************************************/
208
		public String executeRPMbuildprep() throws CoreException {
209
			if (debug) {
210
				System.out.println(" Import executeRPMbuildprep"); //$NON-NLS-1$
211
			}
212
			String rpm_shell = getRpm_shell(); 
213
			boolean cmd_stat;
214
			String orig_proj_path = proj_path;
215
			// Get the path to the spec file directory to use
216
			String specdir = rpmdirs_path + file_sep + "SPECS" + file_sep; //$NON-NLS-1$
217
			File f = new File(specdir);
218
219
			if (!f.isDirectory()) {
220
				String throw_message = Messages.getString(
221
						"RPMCore.There_is_not_a__360") + specdir + //$NON-NLS-1$
222
					Messages.getString(
223
						"RPMCore._directory._nCheck_permissions_in_the_path_directories._361"); //$NON-NLS-1$
224
				IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
225
						null);
226
				throw new CoreException(error);
227
			}
228
229
			FilenameFilter only = new OnlyExt("spec"); //$NON-NLS-1$
230
			String[] s = f.list(only);
231
232
			/* Get ready to execute the rpmbuild command to do a "build prep" which
233
			 *  will untar the source into a directory under BUILD and apply all patches
234
			 *  specified in the "spec" file.
235
			 */
236
			String build_opt = "-bp"; //$NON-NLS-1$
237
238
			String rpmbuild_cmd = usr_rpmbuild_cmd + " " + build_opt + //$NON-NLS-1$
239
				" -v --rcfile " + rpmrc + " --nodeps" + " " + specdir + s[0]; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
240
241
			try {
242
				LinuxShellCmds.createLinuxShellScript(rpmbuild_cmd, rpmbuild_logname, rpm_shell);
243
				LinuxShellCmds.executeLinuxCommand(rpm_shell, 0);
244
			} catch (CoreException e) {
245
				String throw_message = e.getMessage();
246
				IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
247
						null);
248
				throw new CoreException(error);
249
			}
250
251
			// Need to figure out what the name of the directory under the BUILD dir is
252
			File build_dir = new File(rpmdirs_path + file_sep + "BUILD" + file_sep); //$NON-NLS-1$
253
			String[] build_dir_list = build_dir.list();
254
			String orig_srpm_path = build_dir + file_sep + build_dir_list[0];
255
256
				if (build_dir_list.length != 1) {
257
					String throw_message = Messages.getString(
258
							"RPMCore.There_should_be_only_one_directory_under__391") + //$NON-NLS-1$
259
						build_dir +
260
						Messages.getString("RPMCore._at_this_point_392"); //$NON-NLS-1$
261
					IStatus error = new Status(IStatus.ERROR, Error, 1,
262
							throw_message, null);
263
					throw new CoreException(error);
264
				}
265
266
				String eclipse_specfile_path = orig_srpm_path + file_sep + spec_file_prefix + 
267
					s[0];
268
269
				File f1 = new File(eclipse_specfile_path);
270
271
				if (f1.exists()) {
272
					String throw_message = Messages.getString(
273
							"RPMCore.This_file_already_exists___396") + //$NON-NLS-1$
274
						eclipse_specfile_path;
275
					IStatus error = new Status(IStatus.ERROR, Error, 1,
276
							throw_message, null);
277
					throw new CoreException(error);
278
				} 
279
280
			return orig_srpm_path;
281
		}
282
	
283
	/**
284
	 * @param b
285
	 */
286
	public void setDoAutoconf(boolean b) {
287
		doAutoconf = b;
288
	}
289
290
	/**
291
	 * @param b
292
	 */
293
	public void setDoPatches(boolean b) {
294
		doPatches = b;
295
	}
296
297
  }
(-)src/org/eclipse/cdt/rpm/core/SpecFileOps.java (-763 lines)
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
package org.eclipse.cdt.rpm.core;
8
9
import org.eclipse.cdt.rpm.core.RPMCorePlugin;
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.text.SimpleDateFormat;
16
import java.util.ArrayList;
17
import java.util.Date;
18
import java.net.UnknownHostException;
19
20
/**
21
  *This class is used to manipulate RPM spec files for Linux systems
22
  */
23
public class SpecFileOps {
24
25
//	When debug is set to true, lots of debug statements are printed.
26
	private static final boolean debug = false;
27
	private static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$
28
	private static final String line_sep = System.getProperty("line.separator"); //$NON-NLS-1$
29
	private static final String Error = Messages.getString("RPMCore.Error_1"); //$NON-NLS-1$
30
	
31
	private String usr_make_cmd = RPMCorePlugin.getDefault().getPreferenceStore()
32
		.getString("IRpmConstants.MAKE_CMD"); //$NON_NLS-1$
33
	private static int[] line_ptr = { 0, 0, 0, 0 };
34
	private int pat_ctr = 1;
35
	private String prev_ver_no = ""; //$NON-NLS-1$
36
	private String new_rpm_version = ""; //$NON-NLS-1$
37
	private String proj_path;
38
	private String rpmdirs_path;
39
	private String wksp_path;
40
	private String proj_dir;
41
	 
42
	public SpecFileOps(String c_proj_path, String c_rpmdirs_path, 
43
		String c_wksp_path, String c_proj_dir) 
44
				throws CoreException {
45
		proj_path = c_proj_path;
46
		rpmdirs_path = c_rpmdirs_path;
47
		wksp_path = c_wksp_path;
48
		proj_dir = c_wksp_path;
49
	}
50
51
	/**
52
	 * This method modifies a previous spec file from a source RPM install
53
	 * adding the appropriate statements to it so the changes made to the
54
	 * C/C++ project via a patch file that will be generated.
55
	 * @param String ver_no is the version number from the GUI to place into the spec file
56
	 * @param rel_no is the release number from the GUI to place into the spec file
57
	 * @param rpm_version is the current version of the rpm
58
	 * @param rpm_release is the current release of the rpm
59
	 * @param patch_tag is the name associated with the patch, it is used to
60
	 *      create a unique name for the patch of the form:
61
	 *       packagename-ver_no-patch_tag.patch
62
	 * @param changelog_entry - string from the GUI to place in the %changelog section
63
	 * @param rpm_name is the name of the rpm we are working with
64
	 * @param path_to_specfile is the path to the specfile to change with the new info
65
	 * @ return returns true if successful, throws CoreException if not
66
	 */
67
	public String changeRPMspecfile(String ver_no, String rel_no, String rpm_version,
68
		String rpm_release, String patch_tag, String changelog_entry, String rpm_name,
69
		String path_to_specfile)
70
		throws CoreException, FileNotFoundException {
71
		if (debug) {
72
			System.out.println("changeRPMspecfile" + line_sep + "---ver_no = " + ver_no + //$NON-NLS-1$ //$NON-NLS-2$
73
				line_sep + "---rel_no = " + rel_no +  //$NON-NLS-1$ 
74
				line_sep + "---patch_tag = " + patch_tag  + //$NON-NLS-1$
75
				line_sep + "---path_to_specfile = " + path_to_specfile); //$NON-NLS-1$
76
		}
77
		String patch_name;
78
		// If the versions have changed, we must later recreate the source 
79
		// tarball with the new version
80
		if (!ver_no.equals(rpm_version)) {
81
			prev_ver_no = rpm_version;
82
			new_rpm_version = ver_no;
83
		}
84
		if (!patch_tag.equals("")) { //$NON-NLS-1$
85
		   patch_name = rpm_name + "-" + ver_no + "-" +  //$NON-NLS-1$ //$NON-NLS-2
86
			 patch_tag + ".patch";  //$NON-NLS-1$
87
		} else {
88
			patch_name = ""; //$NON-NLS-1$
89
		}
90
91
		// Check to make sure the patch name is unique
92
		if (!checkPatch(patch_name) & !patch_name.equals("")) { //$NON-NLS-1$
93
			String throw_message = Messages.getString(
94
					"RPMCore.The_patch_name__109") + patch_name + //$NON-NLS-1$
95
				Messages.getString("RPMCore._is_not_unique._110") + //$NON-NLS-1$
96
				Messages.getString(
97
					"RPMCore._nPlease_modify_the___Patch_tag___field_and_try_again._111"); //$NON-NLS-1$
98
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
99
					null);
100
			throw new CoreException(error);
101
		}
102
103
		try {
104
			parseSpecfile(path_to_specfile);
105
		} catch (CoreException e) {
106
			String throw_message = e.getMessage();
107
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
108
					null);
109
			throw new CoreException(error);
110
		}
111
112
		// Figure out the format of the lines to add
113
		String[] add_line = {
114
			"Patch" + pat_ctr + ": " + patch_name + line_sep, //$NON-NLS-1$ //$NON-NLS-2$
115
			"%patch" + pat_ctr + " -p1 -b ." + patch_tag + line_sep //$NON-NLS-1$ //$NON-NLS-2$ 
116
		};
117
        
118
		// If there were %defines for Version and/or Release, setup replacement statements
119
120
		/* The logic here is if we did not find a "Patchx:" statement(line_ptr[1]=0) then
121
		 * this is the first patch for this source RPM and the "Patch1:" statement will be
122
		 * added after the last "Sourcex:" statement(line_ptr[0] and the "%patch1"
123
		 * statement will be added after the "%setup" statement where line_ptr[2] is
124
		 * pointing.  If a "Patchx" statement  was found, (line_ptr[1] != 0), add the new
125
		 * "Patchx:"line after the last "Patchx:" statement pointed to by line_ptr[1] and
126
		 * add the "%patchx" statement after the last "%patchx" statement indicated by
127
		 * line_ptr[3].
128
		 */
129
		if (line_ptr[1] == 0) {
130
			line_ptr[1] = line_ptr[2];
131
		} else {
132
			line_ptr[0] = line_ptr[1];
133
			line_ptr[1] = line_ptr[3];
134
		}
135
136
		// Now read the spec file line by line and write it to the final 
137
		// spec file adding in the lines to perform the patching.
138
		String path_to_newspecfile = path_to_specfile + ".new"; //$NON-NLS-1$
139
140
		FileReader fr = new FileReader(path_to_specfile);
141
		BufferedReader br = new BufferedReader(fr);
142
		FileWriter fw;
143
144
		try {
145
			fw = new FileWriter(path_to_newspecfile);
146
		} catch (IOException e) {
147
			String throw_message = Messages.getString(
148
					"RPMCore.Failed_to_open_the_output_spec_file_at__123") + //$NON-NLS-1$
149
					path_to_newspecfile;
150
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
151
					null);
152
			throw new CoreException(error);
153
		}
154
155
		int line_ctr = 0;
156
		int line_indx = 0;
157
		String input_line;
158
		boolean found_changelog = false;
159
160
		// Setup the lines that set the version and release numbers
161
		String new_version_line = "Version: " + ver_no; //$NON-NLS-1$
162
		String new_release_line = "Release: " + rel_no; //$NON-NLS-1$
163
164
		try {
165
			while ((input_line = br.readLine()) != null) {
166
				if (input_line.length() > 8) {
167
					if (input_line.startsWith("Version")) { //$NON-NLS-1$
168
						input_line = new_version_line;
169
					} else if (input_line.startsWith("Release")) { //$NON-NLS-1$
170
						input_line = new_release_line;
171
					}
172
				}
173
174
				fw.write(input_line + line_sep);
175
176
				// See if this was the "%changelog" line just written, if it was, write out the new entry
177
				if (input_line.length() == 10 && !patch_name.equals("")) { //$NON-NLS-1$
178
					if (input_line.startsWith("%changelog")) { //$NON-NLS-1$
179
						fw.write(changelog_entry);
180
						found_changelog = true;
181
					}
182
				}
183
184
				line_ctr++;
185
186
				// Check to see if this is one of the lines I should add something after
187
				if (!patch_name.equals("")) { //$NON-NLS-1$
188
				   if (line_ctr == line_ptr[line_indx]) {
189
					   fw.write(add_line[line_indx]);
190
					   line_indx++;
191
				   }
192
				}
193
			}
194
195
			// if there was not a "%changelog" section, make one
196
			if (!found_changelog && !patch_name.equals("")) { //$NON-NLS-1$
197
				fw.write("%changelog" + line_sep + changelog_entry); //$NON-NLS-1$
198
			}
199
200
			fw.close();
201
		} catch (IOException e) {
202
			String throw_message = Messages.getString(
203
					"RPMCore.Error_trying_to_modify__132") + //$NON-NLS-1$
204
				path_to_specfile;
205
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
206
					null);
207
			throw new CoreException(error);
208
		}
209
210
		return path_to_newspecfile;
211
	}
212
213
	/**
214
	 * Method parseSpecfile.
215
	 * This method takes a spec file path and parses it for various information.
216
	 * @param String containing the path to the spec file to be parsed
217
	 * @return simply return if successful, throw CoreEception if not
218
	 */
219
	public void parseSpecfile(String path_to_specfile) throws CoreException {
220
		if (debug) {
221
			System.out.println("--parseSpecfile: " + path_to_specfile); //$NON-NLS-1$
222
		}
223
		for (int i = 0; i < line_ptr.length; i++) {
224
			line_ptr[i] = 0;
225
		}
226
		/* The following logic determines where in the spec file the "Patchx:" and
227
		 * %patchx -p1" lines will need to be added to accomodate the patch we
228
		 * are fixing to generate.  If this is the first patch to ever be added to this
229
		 * source RPM then the "Patchx: statement will have to be added after the
230
		 * last "Sourcex:" statement and the "%patch -p1" statement will need to be
231
		 * added after the "%setup" statement.  If this is not the first patch for this
232
		 * source rpm, the "Patchx:" statement will be added after the last "Patchx:"
233
		 * statement and the "%patchx -p1" will be added after the last "%patch -p1"
234
		 * statement.  So, we keep track of where the line numbers for all of these
235
		 * eventualities are so when we mod the file we will know where to insert
236
		 * the necessary new lines.
237
		 */
238
		ArrayList patchlist = new ArrayList();
239
		boolean found_source_line = false;
240
		boolean found_patch = false;
241
		boolean found_define = false;
242
		boolean found_define_name = false;
243
		boolean found_version = false;
244
		boolean found_release = false;
245
		int define_ctr = 0;
246
		int define_line_ctr = 0;
247
		int lines = 1;
248
249
		try {
250
			FileReader sp_file = new FileReader(path_to_specfile);
251
			StreamTokenizer st = new StreamTokenizer(sp_file);
252
253
			// Make sure numbers, colons and percent signs are considered valid
254
			st.wordChars('a','z');
255
			st.wordChars('A','Z');
256
			st.wordChars(':', ':');
257
			st.wordChars('0', '9');
258
			st.wordChars('%', '%');
259
			st.wordChars('{', '}');
260
			st.wordChars('-', '-');
261
			st.wordChars('/', '/');
262
			st.wordChars('=','=');
263
			st.wordChars('.','.');
264
			st.wordChars('_','_');
265
			st.eolIsSignificant(true);
266
            
267
			String new_word;
268
			boolean check_ifs = false;
269
			int if_ctr = 0;
270
			int token = st.nextToken();
271
			while (token != StreamTokenizer.TT_EOF) {
272
				token = st.nextToken();
273
274
				switch (token) {
275
				case StreamTokenizer.TT_EOL:
276
				  lines++;
277
				  break;
278
				case StreamTokenizer.TT_WORD:
279
					new_word = st.sval;
280
					
281
/* The following commented out logic addresses bugzilla 110452 where the version and
282
 * release numbers for spec files are stored in "%define" variables at the top of the file.  It
283
 * has been decided to put this change on hold until it can be determined how pervasive
284
 * the use of this practice is.  The code is incomplete for the time being and may be deleted
285
 * entirely in future releases.
286
 */                   
287
/*					if (found_version) {
288
						found_version = false;
289
						if (new_word.startsWith("%{")) {  //$NON-NLS-1$
290
							version_param = true;
291
							define_info.add(0,new_word.substring(2,new_word.length()-1));
292
						}
293
						break;
294
					}
295
                    
296
					if (found_release) {
297
						found_release = false;
298
						if (new_word.startsWith("%{")) {  //$NON-NLS-1$
299
//							release_param = true;
300
							define_info.add(1,new_word.substring(2,new_word.length()-1));
301
						}
302
						break;
303
					}  */
304
                    
305
					// See if we have found the Version: line
306
					if (new_word.equals("Version:")) {  //$NON-NLS-1$
307
						found_version = true;
308
						break;
309
					}
310
                    
311
					// See if we have found the Release: line
312
					if (new_word.equals("Release:")) {  //$NON-NLS-1$
313
						found_release = true;
314
						break;
315
					}
316
317
						// Record where the last line of the form "Sourcex:" is
318
						if (new_word.startsWith("Source") &  //$NON-NLS-1$
319
							 new_word.endsWith(":")) { //$NON-NLS-1$
320
							line_ptr[0] = lines;
321
							found_source_line = true;
322
							break;
323
						}
324
325
						/* Record where the last line of the form "Patchx:" is and count how many there were.
326
						 * Also, record the statement so when we generate our new "Patchx:" statement
327
						 * we don't duplicate a "Patch" statement.  This has to be done because a lot of
328
						 * spec files have "Patchx:" statements that are non-sequential
329
						 */
330
						if (new_word.startsWith("Patch") &  //$NON-NLS-1$
331
							   new_word.endsWith(":")) { //$NON-NLS-1$
332
							line_ptr[1] = lines;
333
							pat_ctr++;
334
							patchlist.add(new_word);
335
336
							break;
337
						}
338
339
						// Record where the "%setup line is
340
						if (new_word.equals("%setup")) { //$NON-NLS-1$
341
342
							// set the "check for if" constructs switch
343
							check_ifs = true;
344
							line_ptr[2] = lines;
345
346
							break;
347
						}
348
349
						if (new_word.equals("%build")) { //$NON-NLS-1$
350
							check_ifs = false;
351
                            
352
							break;
353
						}
354
355
						// Record where the last (if any) "%patchx" line is
356
						if (new_word.startsWith("%patch")) { //$NON-NLS-1$
357
							line_ptr[3] = lines;
358
							found_patch = true;
359
360
							break;
361
						}
362
                        
363
						// See if we have found a %define statement, if so save it as some
364
						// source RPMs use %define statements to "define" version/release #'s
365
/* See the comment several lines above regarding bugzilla 110452 as it also pertains to this code */
366
/*						if (new_word.equals("%define")) {  //$NON-NLS-1$
367
							found_define = true;
368
							define_line_ptr[define_line_ctr] = lines;
369
							define_line_ctr++;
370
                        	
371
							break;
372
						}  */
373
                        
374
					if (found_define) {
375
						found_define = false;
376
//						define_info.add(define_ctr,new_word);
377
						define_ctr++;
378
						found_define_name = true;
379
						break;
380
					}
381
                    
382
					if (found_define_name) {
383
						found_define_name = false;
384
//						define_info.add(define_ctr,new_word);
385
						define_ctr++;
386
						break;
387
					}
388
389
						// Set the found %if/%ifarch/%ifnarch/%ifos/%ifnos switch
390
						if (check_ifs) {
391
							if (new_word.startsWith("%if")) { //$NON-NLS-1$
392
								if_ctr++;
393
394
								break;
395
							}
396
397
							// Reset the found %if/%ifarch switch
398
							if (new_word.equals("%endif")) { //$NON-NLS-1$
399
400
								if ((if_ctr > 0) & found_patch) {
401
									if_ctr--;
402
									line_ptr[3] = lines;
403
									found_patch = false;
404
405
									break;
406
								}
407
							}
408
409
							break;
410
						}
411
                        
412
						break;
413
414
				default:
415
					break;
416
				}
417
			}
418
419
			sp_file.close();
420
		} catch (IOException e) {
421
			String throw_message = Messages.getString(
422
					"RPMCore.Error_parsing_the_spec_file_in_the_project_--_157") + //$NON-NLS-1$
423
					path_to_specfile;
424
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
425
					null);
426
			throw new CoreException(error);
427
		}
428
429
		if (pat_ctr > 1) {
430
			int patch_num = parsePatchArray(patchlist, pat_ctr);
431
			pat_ctr = patch_num;
432
		}
433
434
		return;
435
	}
436
	
437
	/**
438
		* Method checkPatch is used to check for the existence of a previous
439
		* patch name in the "SOURCES" directory.
440
		* @param patch name formed from the patch tag from the GUI
441
		* @return true if the name unique, false if name already exists
442
		*/
443
	   private boolean checkPatch(String patch_name) {
444
		   if (debug) {
445
			   System.out.println("--checkPatch"); //$NON-NLS-1$
446
		   }
447
                                                                                                
448
		   File f = new File(rpmdirs_path + file_sep + "SOURCES" + file_sep + patch_name); //$NON-NLS-1$
449
                                                                                                
450
		   if (f.exists()) {
451
			   return false;
452
		   }
453
                                                                                                
454
		   return true;
455
	   }
456
457
	/**
458
	 * Method parseArrayList is used to peruse a list of the "Patchx:"
459
	 * statements gleaned from a spec file and determine what would
460
	 * be unique "Patchx:"/"%patchx" statements to add to the spec file.
461
	 * @param patchlist is an ArrayList containing the "Patchx:" statements
462
	 *     in the spec file
463
	 * @param patch_ctr is the number of "Patchx:" statements found in the spec file
464
	 * @return a number to replace "x" in "Patchx:" and "%patchx" which
465
	 *     is unique for this spec file
466
	 *
467
	 */
468
	private static int parsePatchArray(ArrayList patchlist, int patch_ctr) {
469
		if (debug) {
470
			System.out.println("--parsePatchArrayList"); //$NON-NLS-1$
471
		}
472
473
		int patch_array_size = patchlist.size();
474
		String num_string;
475
		int patch_num;
476
		String last_patch = (String) patchlist.get(patch_array_size - 1);
477
		int indx = 5;
478
479
		while (last_patch.charAt(indx) != ':') {
480
			indx++;
481
		}
482
483
		// Allow for the fact that there could only be one patch statement of the
484
		// form "Patch:", that is, there is no number
485
		if (indx == 5) {
486
			return 0;
487
		}
488
489
		String num = last_patch.substring(5, indx);
490
491
		try {
492
			patch_num = Integer.parseInt(num, 10);
493
		} catch (NumberFormatException e) {
494
			return -1;
495
		}
496
497
		return patch_num + 1;
498
	}
499
	
500
	/**
501
			 * Method createRPMspec.
502
			 * Create a *very* generic spec file since no spec file was specfified and
503
			 * this is the first time this project has been exported.
504
			 * @param rpm_shell is the name to use when creating a shell script
505
			 * @param rpmbuild_logname is the name of the file to send log errors to
506
			 * @param tar_path is the path to the tarball to be used in this specfile
507
			 * @param rpm_version is the verison number to be placed in the spec file
508
			 * @param rpm_release is the release number to be placed in the spec file
509
			 * @param path_to_specfile is the path to write the new spec file to
510
			 * @param proj_dir is the name of the Eclipse project directory, it will be used
511
			 *        to create the name of the tarball along with the version number
512
			 * @return - true if successful, throw CoreException if not
513
			 */
514
			/******************************************************************************/
515
			public boolean createRPMspec(String rpm_shell, String rpmbuild_logname, 
516
			  String tar_path, String rpm_version, String rpm_release, String path_to_specfile,
517
			  String proj_dir)
518
			  throws CoreException {
519
				if (debug) {
520
					System.out.println("createRPMspec "); //$NON-NLS-1$
521
					System.out.println(rpm_shell + "  " + rpmbuild_logname + "  " + tar_path + line_sep + //$NON-NLS-1$
522
					rpm_version + "  " + rpm_release + "  " + path_to_specfile + line_sep + //$NON-NLS-1$ //$NON-NLS-2$
523
					proj_dir);
524
				}
525
				String author_name = RPMCorePlugin.getDefault().getPreferenceStore()
526
						.getString("IRpmConstants.AUTHOR_NAME"); //$NON-NLS-1$
527
				String author_email = RPMCorePlugin.getDefault().getPreferenceStore()
528
						.getString("IRpmConstants.AUTHOR_EMAIL"); //$NON-NLS-1$
529
				String user_name = System.getProperty("user.name"); //$NON-NLS-1$
530
				String user_wksp = wksp_path + file_sep + user_name; 
531
				ArrayList file_list = new ArrayList();
532
				String mkdir_cmds = "make install" + line_sep; //$NON-NLS-1$
533
534
				String make_cmd = "(cd " + tar_path + line_sep + usr_make_cmd + line_sep; //$NON-NLS-1$
535
				
536
				// Build the project to generate the binaries
537
				try {
538
					LinuxShellCmds.createLinuxShellScript(make_cmd, rpmbuild_logname, rpm_shell);
539
					LinuxShellCmds.executeLinuxCommand(rpm_shell, 0);
540
				} catch (CoreException e) {
541
					String throw_message = Messages.getString(
542
							"RPMCore.Problem_running_the___make___file_to_create_the_executables._nView_the_log_file_at__249") + //$NON-NLS-1$
543
							rpmbuild_logname;
544
					IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
545
							null);
546
					throw new CoreException(error);
547
				}
548
				String user_work_area = RPMCorePlugin.getDefault().getPreferenceStore()
549
					.getString("IRpmConstants.USER_WORK_AREA"); //$NON_NLS-1$
550
				String build_root_path = user_wksp + user_work_area + file_sep + 
551
					proj_dir + "-root"; //$NON-NLS-1$
552
553
				/* Now run the 'make install' to install the files into the directory structure
554
				 * so we can get a list of them and the directories they go into.
555
				 */
556
557
				String make_inst_cmd = "export RPM_BUILD_ROOT=" + //$NON-NLS-1$
558
					build_root_path + line_sep + mkdir_cmds;
559
560
				try {
561
					LinuxShellCmds.createLinuxShellScript("cd " + tar_path + line_sep + make_inst_cmd, rpmbuild_logname, //$NON-NLS-1$
562
						rpm_shell);
563
					LinuxShellCmds.executeLinuxCommand(rpm_shell, 0);
564
				} catch (CoreException e) {
565
					String throw_message = Messages.getString(
566
							"RPMCore.Problem_running_the___make_install___shell_script_--__273") + //$NON-NLS-1$
567
						rpm_shell +
568
						Messages.getString(
569
							"RPMCore._nThere_may_be_a_problem_in_the_M/makefile._274"); //$NON-NLS-1$
570
					IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
571
							null);
572
					throw new CoreException(error);
573
				}
574
575
				/* Now traverse the "build root" directory to find all of the files installed by
576
				 * the "make install" above.  This file list will be used to populate the "%files"
577
				 * section of the spec file.
578
				 */
579
				traverse(new File(build_root_path), build_root_path, file_list);
580
581
				/* See if there are any files in file_lst, if not, we probably have an error in the install: section
582
				 * of the Makefile/makefile.
583
				 */
584
				if (file_list.size() == 0) {
585
					String throw_message = Messages.getString(
586
							"RPMCore.No_files_were_found_under_build_root_--__276") + //$NON-NLS-1$
587
						build_root_path +
588
						Messages.getString(
589
							"RPMCore._n_--_Problem_with_the___install____section_of_the_spec_file__277"); //$NON-NLS-1$
590
					IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
591
							null);
592
					throw new CoreException(error);
593
				}
594
595
				// If there is a configure script, put in a %configure
596
				String configure = ""; //$NON-NLS-1$
597
598
				if (LinuxShellCmds.checkForConfigure(proj_path)) {
599
					configure = "%configure" + line_sep; //$NON-NLS-1$
600
				}
601
602
				// Set up date for "%changelog" entry
603
				SimpleDateFormat df = new SimpleDateFormat("E MMM dd yyyy"); //$NON-NLS-1$
604
605
				//	PatchChangeLogStamp.setText("* " + df.format(today)+ " -- YourName" +" <your@mail.com>");
606
				// Now set up to build the RPM spec file
607
				String is = 
608
					"%define _unpackaged_files_terminate_build 0" + line_sep +  //$NON-NLS-1$
609
					"Summary: None - Eclipse-generated spec file" + line_sep +  "Name: " + //$NON-NLS-1$ //$NON-NLS-2$
610
					proj_dir + "" + line_sep +  "Version: " + rpm_version + "" + line_sep +  "Release: " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
611
					rpm_release + "" + line_sep +  "License: GPL" + line_sep +  //$NON-NLS-1$ //$NON-NLS-2$
612
					"Group: Applications/Internet" + line_sep +  "Source: " + proj_dir + "-" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
613
					"%{version}.tar.bz2" + line_sep +  "Requires: tar" + line_sep +  "BuildRoot: " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
614
					"%{_tmppath}/%{name}-root" + line_sep +  //$NON-NLS-1$
615
					"%description" + line_sep + line_sep + //$NON-NLS-1$
616
					"Basic spec file for rpm build in Eclipse for " + proj_dir + //$NON-NLS-1$
617
					line_sep + line_sep +  "%prep" + line_sep +  "%setup -q" + line_sep +  "%build" + line_sep + line_sep +  configure + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
618
					"make" + line_sep + line_sep +  "%install rm -rf $RPM_BUILD_ROOT" + line_sep + 
619
					"%makeinstall RPM_BUILD_ROOT=$RPM_BUILD_ROOT" + line_sep +  "%clean" + line_sep +  //$NON-NLS-1$ //$NON-NLS-2$
620
					"rm -rf $RPM_BUILD_ROOT" + line_sep +  "%files" + line_sep +  //$NON-NLS-1$ //$NON-NLS-2$
621
					"%defattr(-,root,root)" + line_sep; //$NON-NLS-1$
622
623
				// Convert the ArrayList file_list to an array of strings and append to the spec file 
624
				String[] lines = new String[file_list.size()];
625
				file_list.toArray(lines);
626
627
				for (int i = 0; i < lines.length; i++) {
628
					/* The following marked code is a hack to get around a problem of the ".gz" being
629
					 * dropped from some document file names that belong in /usr/share/man.  I'm not sure
630
					 * why docs whose names are of the form "xxxx.8.gz" are returned from the "traverse
631
					 * method as "xxxx.8".  Is there a problem with having two periods in the name with java
632
					 * for some reason?  Using the find command from a shell returns the correct names.
633
					 * When the exact same find command is embedded in java code and fired off as a shell
634
					 * script, again the ".gz" gets lost.  I was hoping to solve the problem with the "traverse"
635
					 * method, but it has the same problem which leads me to believe it is a java-related
636
					 * problem.  I must move on now, but this hack can be removed if this mystery is solved.
637
					 *
638
					 * ************* Beginning of hack ************************************/
639
					int k = lines[i].length() - 2;
640
					char last_char = lines[i].charAt(k);
641
642
					if (Character.isDigit(last_char) &
643
							(lines[i].lastIndexOf(file_sep + "man" + file_sep) != -1)) { //$NON-NLS-1$
644
						lines[i] = lines[i].substring(0, k + 1) + ".gz" + line_sep; //$NON-NLS-1$
645
					}
646
647
					/* ************ End of hack  *****************************************/
648
					is = is + lines[i];
649
				}
650
				Date today = new Date();
651
				is = is + "%changelog" + line_sep + "* " + returnDate() +
652
					 " " + author_name + " <" + //$NON-NLS-1$ //$NON-NLS-2$
653
				  	author_email + ">" + line_sep + "- Original" + line_sep; //$NON-NLS-1$ //$NON-NLS-2$
654
655
				byte[] buf = is.getBytes();
656
657
				/* Read the input stream and try to create the spec file to be used by
658
				 *  the rpmbuild process                 */
659
				try {
660
					BufferedOutputStream os = 
661
						new BufferedOutputStream(new FileOutputStream(path_to_specfile));
662
663
					for (int i = 0; i < buf.length; i++) {
664
						os.write(buf[i]);
665
					}
666
667
					os.close();
668
				} catch (Exception e) {
669
					String throw_message = Messages.getString(
670
						"RPMCore.Problem_creating_spec_file.__Check_permissions_in__324") + //$NON-NLS-1$
671
						rpmdirs_path;
672
					IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
673
							null);
674
					throw new CoreException(error);
675
				}
676
677
				return true;
678
			}
679
680
			/**
681
			 * Method traverse.
682
			 * This method traverses a directory tree beginning at the path passed
683
			 * to it and builds an array of file names contained in that tree.  This list
684
			 * of files is used to populate the "%files" section of the spec file.
685
			 * @param dir - A file that points to the directory where the traversing
686
			 * is to begin
687
			 * @param build_root_path is the path to the rpm build root directory
688
			 * @param file_list is an ArrayList of strings containing paths to what files were
689
			 *  installed by the "make install" command
690
			 * @return - If the file_lst[[] array is empty upon return there is a problem
691
			 * probably in the "install" section of the M/makefile
692
			 */
693
			private void traverse(File dir, String build_root_path, ArrayList file_list) {
694
				if (debug) {
695
					System.out.println("--traverse"); //$NON-NLS-1$
696
				}
697
698
				int file_ctr;
699
700
				if (dir.isDirectory()) {
701
					String[] children = dir.list();
702
703
					for (int i = 0; i < children.length; i++) {
704
						File temp = new File(dir, children[i]);
705
706
						if (temp.isDirectory()) {
707
							traverse(temp, build_root_path, file_list);
708
						} else {
709
							String tmp_name = temp.getAbsolutePath();
710
							file_list.add(tmp_name.substring(build_root_path.length()) + line_sep);
711
712
							if (debug) {
713
								file_ctr = file_list.size() - 1;
714
								System.out.println(" file_lst[" + file_ctr + "] = " + //$NON-NLS-1$ //$NON-NLS-2$
715
									file_list.get(file_ctr));
716
							}
717
						}
718
					}
719
				}
720
			}
721
	
722
	/** 
723
	 * Method getHostName gets the name of the host to use as part of the
724
	 * e-mail address for the chnagelog.
725
	 * @return String containing the name of the host, "" if error
726
	 */
727
	private String getHostName()
728
	 {
729
		String hostname;
730
		  try {
731
			  hostname = java.net.InetAddress.getLocalHost().getHostName();
732
		  } catch (UnknownHostException e) {
733
			  return "";
734
		  }
735
		  // Trim off superflous stuff from the hostname
736
		  int firstdot = hostname.indexOf(".");
737
		  int lastdot = hostname.lastIndexOf(".");
738
		  // If the two are equal, no need to trim name
739
		  if (firstdot == lastdot) {
740
			return hostname;
741
		  }
742
		  String hosttemp = "";
743
		  String hosttemp2 = hostname;
744
		  while (firstdot != lastdot) {
745
			hosttemp = hosttemp2.substring(lastdot) + hosttemp;
746
			hosttemp2 = hostname.substring(0,lastdot);
747
			lastdot = hosttemp2.lastIndexOf(".");
748
		  }
749
		  return hosttemp.substring(1);
750
	 }
751
	 
752
	/** 
753
	 * Method returnDate returns the type of date requested by the user.
754
	 * @return String containing the date in the requested format
755
	 */
756
	private String returnDate() {
757
		 SimpleDateFormat date_Format;
758
		 date_Format = new SimpleDateFormat("E MMM dd yyyy"); //$NON-NLS-1$
759
		 return date_Format.format(new Date());
760
	 }
761
762
   
763
}
(-)src/org/eclipse/cdt/rpm/core/StreamReaderThread.java (-29 lines)
Removed Link Here
1
package org.eclipse.cdt.rpm.core;
2
3
import java.io.InputStreamReader;
4
import java.io.InputStream;
5
6
public class StreamReaderThread extends Thread
7
{
8
    StringBuffer mOut;
9
    InputStreamReader mIn;
10
    
11
    public StreamReaderThread(InputStream in, StringBuffer out)
12
    {
13
    mOut=out;
14
    mIn=new InputStreamReader(in);
15
    }
16
    
17
    public void run()
18
    {
19
    int ch;
20
    try {
21
        while(-1 != (ch=mIn.read()))
22
            mOut.append((char)ch);
23
        }
24
    catch (Exception e)
25
        {
26
        mOut.append("\nRead error:"+e.getMessage());
27
        }
28
    }
29
}
(-)src/org/eclipse/cdt/rpm/core/TarOps.java (-292 lines)
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
package org.eclipse.cdt.rpm.core;
8
9
import org.eclipse.core.runtime.CoreException;
10
import org.eclipse.core.runtime.IStatus;
11
import org.eclipse.core.runtime.Status;
12
13
import java.io.*;
14
/**
15
  *This class is used to interface with the Linux "tar" command when
16
  *manipulating rpm's
17
  */
18
public class TarOps {
19
	
20
//	When debug is set to true, lots of debug statements are printed.
21
	 private static final boolean debug = false;
22
	 private static final String Error = Messages.getString("RPMCore.Error_1"); //$NON-NLS-1$
23
	 private static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$
24
	 private static final String line_sep = System.getProperty("line.separator"); //$NON-NLS-1$
25
	 
26
	 private String usr_tar_cmd = RPMCorePlugin.getDefault().getPreferenceStore().getString("IRpmConstants.TAR_CMD"); //$NON_NLS-1$
27
	 private String rpmdirs_path;
28
	 private String proj_path;
29
	 
30
	 public TarOps (String c_proj_path, String c_rpmdirs_path) 
31
		throws CoreException {
32
		
33
	 	proj_path = c_proj_path;
34
	 	rpmdirs_path = c_rpmdirs_path;
35
	 	
36
	 }
37
38
	/**
39
		 * Method untarSource.
40
		 * This method is called when the source RPM being imported and the developer does
41
		 * not want patches applied to the source code.
42
		 * @return void if OK, throws CoreException if error occurs
43
		 * @throws CoreException
44
		 */
45
		public boolean untarSource(String tarball_path, String rpmbuild_logname,
46
		   String rpm_shell) throws CoreException {
47
			if (debug) {
48
				System.out.println("untarSource"); //$NON-NLS-1$
49
			}
50
51
			String tarball_type = null;
52
			String from_path;
53
54
			// Get a list of files in the SOURCES directory
55
			File tarball = new File(tarball_path);
56
57
			// See what the tarball ends with to see which compression we need
58
			if (tarball_path.endsWith(".gz")) { //$NON-NLS-1$
59
					tarball_type = "z"; //$NON-NLS-1$
60
				} else if (tarball_path.endsWith(".bz2")) { //$NON-NLS-1$
61
					tarball_type = "j"; //$NON-NLS-1$
62
				} else if (tarball_path.endsWith(".tar")) { //$NON-NLS-1$
63
					tarball_type = ""; //$NON-NLS-1$
64
				} else {
65
					return false;
66
				}
67
68
			// change to the directory and untar it, first get the path to the tarball
69
			int j = tarball_path.lastIndexOf(file_sep);
70
			String tar_path = tarball_path.substring(0,j);
71
			// now get the name of the tarball
72
			String tarball_name = tarball_path.substring(j+1);
73
			String tar_cmd = "cd " + tar_path + line_sep + usr_tar_cmd + " x" + //$NON-NLS-1$ //$NON-NLS-2$
74
						tarball_type + "f " + tarball_name; //$NON-NLS-1$
75
76
			try {
77
				LinuxShellCmds.createLinuxShellScript(tar_cmd, rpmbuild_logname, rpm_shell);
78
				LinuxShellCmds.executeLinuxCommand(rpm_shell, 0);
79
			} catch (CoreException e) {
80
				String throw_message = e.getMessage();
81
				IStatus error = new Status(IStatus.ERROR, Error, 1,
82
								throw_message, null);
83
				throw new CoreException(error);
84
			}
85
86
		return true;
87
		}
88
89
	/**
90
	 * The method takes care of renaming the source tarball in the SOURCES
91
	 * directory of the temporary RPM work area.  Usually the source tarball
92
	 * is named of the form: packagename-version#.tar.gz/bz2.  When the
93
	 * version number changes both the name of the tarball needs to change
94
	 * and the directory it creates (which is also usually of the format
95
	 * packagename-version).  The problem is that sometimes the
96
	 * "make clean/make dist-clean/make maintainer-clean does not totally
97
	 * remove files created by the auto* tools.  To get around this we use the
98
	 * original tarball from the source RPM.  We untar it, rename the directory
99
	 * it creates and then re-tar it with the new name.
100
	 * @param rpm_name - contains a string with the rpm name
101
	 * @param rpmbuild_logname - string pointing to the file where errors are being logged
102
	 * @param rpm_shell - string to use for creating a Linux shell script
103
	 * @param rpm_version - string containing the version of the rpm
104
	 * @param prev_ver_no - string with the previous version number of the rpm
105
	 * @return true if successful, throw CoreException if not
106
	 * @throws CoreException
107
	 */
108
	public boolean renameRPMtarfile(String rpm_name, String rpmbuild_logname,
109
	   String rpm_shell, String rpm_version, String prev_ver_no) throws CoreException {
110
		if (debug) {
111
			System.out.println("renameRPMtarfile"); //$NON-NLS-1$
112
		}
113
114
		String source_dir = rpmdirs_path + file_sep +"SOURCES" + file_sep; //$NON-NLS-1$
115
		String tarball_name = ""; //$NON-NLS-1$
116
		String tar_cmd_opt = ""; //$NON-NLS-1$
117
		String tar_extension = ""; //$NON-NLS-1$
118
		File f = new File(source_dir);
119
		String[] dirlist = f.list();
120
121
122
// Get the name of the current tarball
123
loop: 
124
		for (int i = 0; i < dirlist.length; i++) {
125
			if (dirlist[i].length() > rpm_name.length()) {
126
				String temp = dirlist[i].substring(0, rpm_name.length());
127
128
				if (temp.equals(rpm_name)) {
129
					if (dirlist[i].endsWith(".tar.bz2")) { //$NON-NLS-1$
130
						tarball_name = dirlist[i];
131
						tar_cmd_opt = "j"; //$NON-NLS-1$
132
						tar_extension = ".tar.bz2"; //$NON-NLS-1$
133
134
						break loop;
135
					} else if (dirlist[i].endsWith(".tar.gz")) { //$NON-NLS-1$
136
						tarball_name = dirlist[i];
137
						tar_cmd_opt = "z"; //$NON-NLS-1$
138
						tar_extension = ".tar.gz"; //$NON-NLS-1$
139
140
						break loop;
141
					}
142
				}
143
			}
144
		}
145
146
		// If tar_cmd_opt did not get set, we did not find a tarball
147
		if (tar_cmd_opt.equals("")) { //$NON-NLS-1$
148
149
			String throw_message = Messages.getString(
150
					"RPMCore.Cannot_find_source_tarball_in__644") + //$NON-NLS-1$
151
				source_dir;
152
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
153
					null);
154
			throw new CoreException(error);
155
		}
156
157
		// Set up to untar the source tarball
158
		String tar_cmd = "cd " + source_dir + line_sep + usr_tar_cmd + " -x" + tar_cmd_opt + //$NON-NLS-1$ //$NON-NLS-2$
159
			"f " + tarball_name; //$NON-NLS-1$
160
161
		try {
162
			LinuxShellCmds.createLinuxShellScript(tar_cmd, rpmbuild_logname, rpm_shell);
163
			LinuxShellCmds.executeLinuxCommand(rpm_shell, 0);
164
		} catch (CoreException e) {
165
			String throw_message = Messages.getString(
166
					"RPMCore.Error_trying_to_extract_the_source_tarball_using_this_command_--__652") + //$NON-NLS-1$
167
				tar_cmd;
168
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
169
					null);
170
			throw new CoreException(error);
171
		}
172
173
		File f1 = new File(source_dir + rpm_name + "-" + prev_ver_no); //$NON-NLS-1$
174
175
		if (f1.exists() & f1.isDirectory()) {
176
			File f2 = new File(source_dir + rpm_name + "-" + rpm_version); //$NON-NLS-1$
177
178
			if (!f2.exists()) {
179
				if (!f1.renameTo(f2)) {
180
					String throw_message = Messages.getString(
181
							"RPMCore.Error_trying_to_rename_directory__656") + //$NON-NLS-1$
182
						f1 + Messages.getString("RPMCore._to__") + f2; //$NON-NLS-1$
183
					IStatus error = new Status(IStatus.ERROR, Error, 1,
184
							throw_message, null);
185
					throw new CoreException(error);
186
				} else {
187
					tar_cmd = usr_tar_cmd + " -C " + source_dir + " -c" + //$NON-NLS-1$ //$NON-NLS-2$
188
						tar_cmd_opt + "f " + source_dir + rpm_name + "-" + //$NON-NLS-1$ //$NON-NLS-2$
189
						rpm_version + tar_extension + " ." + file_sep + rpm_name + //$NON-NLS-1$
190
						"-" + rpm_version; //$NON-NLS-1$
191
192
					try {
193
						LinuxShellCmds.executeLinuxCommand(tar_cmd, 0);
194
					} catch (CoreException e) {
195
						String throw_message = Messages.getString(
196
								"RPMCore.Error_trying_to_create_a_new_source_tarball_using_this_command_--__665") + //$NON-NLS-1$
197
							tar_cmd;
198
						IStatus error = new Status(IStatus.ERROR, Error, 1,
199
								throw_message, null);
200
						throw new CoreException(error);
201
					}
202
				}
203
			}
204
		}
205
206
		return true;
207
	}
208
	
209
	/**
210
	 * Method createRPMtarfile
211
	 * This method creates a tar file from a source directory in the RPM work area
212
	 * under the "/BUILD" directory and puts it in the "/SOURCES" directory for use
213
	 * by the "rpmbuild" command when it creates either a source or binary RPM.
214
	 * @param rpm_name - string with the name of the rpm
215
	 * @param rpm_version - string with the rpm verison number
216
	 * @param path_to_specfile - string with a path to the specfile
217
	 * @return returns true if successful, else it throws a CoreException
218
	 * @throws CoreException
219
	 */
220
	public boolean createRPMtarfile(String rpm_name, String rpm_version,
221
	   String path_to_specfile) 
222
	   throws CoreException {
223
		if (debug) {
224
			System.out.println("createRPMtarfile"); //$NON-NLS-1$
225
		}
226
		
227
		String tar_compression;
228
		String tar_suffix;
229
		String rpm_new_name = rpm_name + "-" + rpm_version; //$NON-NLS-1$
230
		// Figure out what the directory name is under "/BUILD" in the workarea is
231
		File f = new File(rpmdirs_path + file_sep + "BUILD"); //$NON-NLS-1$
232
		String[] dirlist = f.list();
233
		if (dirlist.length != 1) {
234
				  String throw_message = Messages.getString(
235
						  "RPMCore.There_are_too_many_directories_in__432") + //$NON-NLS-1$
236
						rpmdirs_path + file_sep + "BUILD"; //$NON-NLS-1$
237
				  IStatus error = new Status(IStatus.ERROR,
238
						  Error, 1, throw_message, null);
239
				  throw new CoreException(error);
240
			  }
241
242
		if (!dirlist[0].equals(rpm_new_name)) {
243
			File f1 = new File(rpmdirs_path + file_sep + "BUILD" + file_sep + dirlist[0]); //$NON-NLS-1$
244
245
			if (!f1.renameTo(new File(rpmdirs_path + file_sep + "BUILD" + file_sep + rpm_new_name))) { //$NON-NLS-1$
246
247
				String throw_message = Messages.getString(
248
						"RPMCore.Error_trying_to_rename_directory_in__438") + //$NON-NLS-1$
249
					rpmdirs_path + file_sep + "BUILD" + line_sep + //$NON-NLS-1$
250
					Messages.getString(
251
						"RPMCore.Permissions_problem__440"); //$NON-NLS-1$
252
				IStatus error = new Status(IStatus.ERROR, Error, 1,
253
						throw_message, null);
254
				throw new CoreException(error);
255
			}
256
		}
257
258
		// compression we need for the tar file, gzip or bzip2
259
			try {
260
				tar_suffix = LinuxShellCmds.checkCompression(path_to_specfile);
261
			} catch (CoreException e) {
262
				String throw_message = e.getMessage();
263
				IStatus error = new Status(IStatus.ERROR, Error, 1,
264
						throw_message, null);
265
				throw new CoreException(error);
266
			}
267
		
268
		if (tar_suffix.equals(".bz2")) { //$NON-NLS-1$
269
			tar_compression = "j"; //$NON-NLS-1$
270
		} else {
271
			tar_compression = "z"; //$NON-NLS-1$
272
		}
273
274
		String tar_cmd = usr_tar_cmd + " -C " + rpmdirs_path + file_sep + "BUILD" + " -c" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
275
			tar_compression + "f " + rpmdirs_path + file_sep + "SOURCES" + file_sep + rpm_new_name + //$NON-NLS-1$ //$NON-NLS-2$
276
			".tar" + tar_suffix + " ." + file_sep + rpm_new_name; //$NON-NLS-1$ //$NON-NLS-2$
277
278
		try {
279
			LinuxShellCmds.executeLinuxCommand(tar_cmd, 0);
280
		} catch (CoreException e) {
281
			String throw_message = Messages.getString(
282
					"RPMCore.Error_trying_to_create_a_tarball_of_the_source_using_this_command_--__454") + //$NON-NLS-1$
283
				tar_cmd;
284
			IStatus error = new Status(IStatus.ERROR, Error, 1, throw_message,
285
					null);
286
			throw new CoreException(error);
287
		}
288
289
		return true;
290
	}
291
	
292
}
(-)src/org/eclipse/cdt/rpm/core/rpm_strings.properties (-216 lines)
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
9
RPMCore.Error=Error
10
RPMCore.Error_trying_to_copy__=Error trying to copy 
11
RPMCore._to__=\ to 
12
RPMCore.--executeRPMlinux_command__95=--executeRPMlinux_command:
13
RPMCore.Error_executing__97=Error executing 
14
RPMCore.Error_waiting_for__99=Error waiting for 
15
RPMCore._to_complete._100=\ to complete.
16
RPMCore.Command__102=Command 
17
RPMCore._was_interrupted._103=\ was interrupted.
18
RPMCore.The_patch_name__109=The patch name 
19
RPMCore._is_not_unique._110=\ is not unique.
20
RPMCore._nPlease_modify_the___Patch_tag___field_and_try_again._111=\nPlease modify the \'Patch tag\' field and try again.
21
RPMCore.Error_trying_to_parse_spec_file_113=Error trying to parse spec file\nMaybe a character encoding error?
22
RPMCore._nIs_there_a_spec_file_at___114=\nIs there a spec file at: 
23
RPMCore.Failed_to_open_the_output_spec_file_at__123=Failed to open the output spec file at 
24
RPMCore.Error_trying_to_modify__132=Error trying to modify 
25
RPMCore.Error_parsing_the_spec_file_in_the_project_--_157=Error parsing the spec file in the project --
26
RPMCore.Failed_to_find_a___install__or___clean____section_in_the__180=Failed to find a \'install: or \'clean:\' section in the 
27
RPMCore.project__s_M/makefile.__THIS_IS_REQUIRED_!_!_!_181=project\'s M/makefile.  THIS IS REQUIRED\!\!\!
28
RPMCore.I/O_error_processing/reading_the_M/makefile__183=I/O error processing/reading the M/makefile 
29
RPMCore.Failed_to_find_a_M/makefile_in_the_project.___THIS_IS_REQUIRED_!_!_!_185=Failed to find a M/makefile in the project.   THIS IS REQUIRED\!\!\!
30
RPMCore.Failed_to_create_RPM_directories,_check_file_permissions_in__195=Failed to create RPM directories, check file permissions in 
31
RPMCore.Failed_to_create_RPM_directories_in__203=Failed to create RPM directories in 
32
RPMCore._--_check_file_permissions._204=\ -- check file permissions.
33
RPMCore.Error_executing__208=Error executing 
34
RPMCore.command._nSomething_is_wrong_with_file_permissions._209=command.\nSomething is wrong with file permissions.
35
RPMCore.Problem_creating_the_.rpmrc_file.__Check_file_permissions_in__217=Problem creating the .rpmrc file.  Check file permissions in 
36
RPMCore.Problem_creating_the_.rpmmacros_file._nCheck_file_permissions_in__226=Problem creating the .rpmmacros file.\nCheck file permissions in 
37
RPMCore.Problem_creating_the_.rpmmacros_file._nCheck_file_permissions_in__228=Problem creating the .rpmmacros file.\nCheck file permissions in 
38
RPMCore.Problem_creating_the_rpm_spec_file._nCheck_file_permissions_in__247=Problem creating the rpm spec file.\nCheck file permissions in 
39
RPMCore.Problem_running_the___make___file_to_create_the_executables._nView_the_log_file_at__249=Problem running the \'make\' file to create the executables.\nView the log file at 
40
RPMCore.Problem_creating_the___make_install___shell_script_--___rpmbuild.sh__.___270=Problem creating the \'make install\' shell script -- \'rpmbuild.sh\'.  
41
RPMCore._nCheck_file_permissions_in__271=\nCheck file permissions in 
42
RPMCore.Problem_running_the___make_install___shell_script_--__273=Problem running the \'make install\' shell script -- 
43
RPMCore._nThere_may_be_a_problem_in_the_M/makefile._274=\nThere may be a problem in the M/makefile.
44
RPMCore.No_files_were_found_under_build_root_--__276=No files were found under build root -- 
45
RPMCore._n_--_Problem_with_the___install____section_of_the_spec_file__277=\n -- Problem with the \'install:\' section of the spec file?
46
RPMCore.Problem_creating_spec_file.__Check_permissions_in__324=Problem creating spec file.  Check permissions in 
47
RPMCore.Problem_creating_spec_file.__Check_permissions_in__326=Problem creating spec file.  Check permissions in 
48
RPMCore.source_328=source
49
RPMCore.Error_executing___make_clean___in__329=Error executing \'make clean\' in 
50
RPMCore.Problem_creating_a_shell_script_--__342=Problem creating a shell script -- 
51
RPMCore._nThere_may_be_a_problem_in_the_M/makefile._343=\nThere may be a problem in the M/makefile.
52
RPMCore.Problem_running_this_command___346=Problem running this command: 
53
RPMCore._nCheck_permissions._347=\nCheck permissions.
54
RPMCore.Error_trying_to_create_shell_script_to_install__352=Error trying to create shell script to install 
55
RPMCore.the_source_rpm._nCheck_the_file_permissions_in__353=the source rpm.\nCheck the file permissions in 
56
RPMCore.Error_trying_to_install_the_source_with_this_command__355=Error trying to install the source with this command 
57
RPMCore._nCheck_the_log_at__356=\nCheck the log at 
58
RPMCore./SPECS/_359=/SPECS/
59
RPMCore.There_is_not_a__360=There is not a 
60
RPMCore._directory._nCheck_permissions_in_the_path_directories._361=\ directory.\nCheck permissions in the path directories.
61
RPMCore.An_error_in_the__364=An error in the 
62
RPMCore.directory._nEither_there_is_either_no_spec_file_or_more_than_one._365=directory.\nEither there is either no spec file or more than one.
63
RPMCore.There_are_either_no_directories_or_too_many_directories_under__369=There are either no directories or too many directories under 
64
RPMCore.An_error_occurred_trying_to_rename__373=An error occurred trying to rename  
65
RPMCore.Error_creating_shell_script_for_the__381=Error creating shell script for the 
66
RPMCore._nCheck_file_permissions._382=\nCheck file permissions.
67
RPMCore.Error_executing_the_command_to_build_prep_the_rpm_-__384=Error executing the command to build prep the rpm - 
68
RPMCore._nCheck_the_log_at__385=\nCheck the log at 
69
RPMCore.There_should_be_only_one_directory_under__391=There should be only one directory under 
70
RPMCore._at_this_point_392=\ at this point
71
RPMCore.This_file_already_exists___396=This file already exists: 
72
RPMCore.Error_trying_to_create_.srpminfo_file._401=Error trying to create .srpminfo file.
73
RPMCore.Problem_copying_source_rpm_info_file._nCheck_permissions_in__409=Problem copying source rpm info file.\nCheck permissions in 
74
RPMCore.Problem_copying_source_rpm_info_file._nCheck_permissions_in__411=Problem copying source rpm info file.\nCheck permissions in 
75
RPMCore.Error_trying_to_copy_the_target_project_directory_tree_with_this_command_--__417=Error trying to copy the target project directory tree with this command -- 
76
RPMCore._nFile_permissions_problem__418=\nFile permissions problem?
77
RPMCore.Error_trying_to_check_for_Makefile_in__421=Error trying to check for Makefile in 
78
RPMCore.Error_--_the_M/makefile_does_not_have_either_an___install____or___clean_____423=Error -- the M/makefile does not have either an \'install:\' or \'clean:\' 
79
RPMCore.section._nLook_in_this_directory_____424=section.\nLook in this directory:   
80
RPMCore.Error_running___make_clean___in__426=Error running \'make clean\' in 
81
RPMCore.Error_either_creating_or_executing_the___make_clean___command_in__428=Error either creating or executing the \'make clean\' command in 
82
RPMCore.There_are_too_many_directories_in__432=There are too many directories in 
83
RPMCore.Error_trying_to_rename_directory_in__438=Error trying to rename directory in 
84
RPMCore.Permissions_problem__440=Permissions problem?
85
RPMCore.Error_trying_to_parse_spec_file_442=Error trying to parse spec file
86
RPMCore._nIs_there_a_spec_file_at___443=\nIs there a spec file at: 
87
RPMCore.Error_trying_to_create_a_tarball_of_the_source_using_this_command_--__454=Error trying to create a tarball of the source using this command -- 
88
RPMCore.A_problem_occurred_creating_the_rpmbuild_shell_script.___461=A problem occurred creating the rpmbuild shell script.  
89
RPMCore._nPlease_check_the_file_permissions_in_/var/tmp__462=\nPlease check the file permissions in /var/tmp 
90
RPMCore.A_problem_occurred_running_this_command.___464=A problem occurred running this command.  
91
RPMCore.__nPlease_review_the_log_at__465=\ \nPlease review the log at\nWindows->Show View->Other...->RPM Plugin Log File->RPM Plugin Log Viewer
92
RPMCore.There_should_be_only_one_directory_under__467=There should be only one directory under 
93
RPMCore.__nCheck_the_directories_there.__The_RPM_work_area_in_/var/tmp_will_be_preserved._468=\ \nCheck the directories there.  The RPM work area in /var/tmp will be preserved. 
94
RPMCore.Error_trying_to_delete__477=Error trying to delete 
95
RPMCore._nCheck_permissions._478=\nCheck permissions.
96
RPMCore.Error_deleting_resources.__Check_file_permissions_in__483=Error deleting resources.  Check file permissions in 
97
RPMCore.Problem_deleting_the_log_file_at__486=Problem deleting the log file at 
98
RPMCore.__Check_the_permissions._487=\ \ Check the permissions.
99
RPMCore.Error_deleting_files_in_deleteSRPMextrafiles_496=Error deleting files in deleteSRPMextrafiles
100
RPMCore.Error_deleting_files_in_deleteSRPMextrafiles_498=Error deleting files in deleteSRPMextrafiles
101
RPMCore.executeProjConfigure_500=executeProjConfigure
102
RPMCore./bin/chmod_-R_u+r__501=/bin/chmod -R u+r 
103
RPMCore./_502=/
104
RPMCore.Error_executing_the_command__503=Error executing the command 
105
RPMCore.__Check_permissions_of__504=\ \ Check permissions of 
106
RPMCore.Problem_creating_the___make_clean/distclean/maintainer-clean___shell_script_--__515=Problem creating the \'make clean/distclean/maintainer-clean\' shell script -- 
107
RPMCore._nThere_may_be_a_problem_in_the_M/makefile._516=\nThere may be a problem in the M/makefile.
108
RPMCore.Problem_running_the___make_install___shell_script_--__518=Problem running the \'make install\' shell script -- 
109
RPMCore._nThere_may_be_a_problem_in_the_M/makefile._519=\nThere may be a problem in the M/makefile.
110
RPMCore.Problem_deleting_extra_files_from_project_in_deleteSRPMextrafiles_521=Problem deleting extra files from project in deleteSRPMextrafiles
111
RPMCore.Problem_deleting_extra_files_in_the_project_in_deleteEclipseiles._523=Problem deleting extra files in the project in deleteEclipseiles.
112
RPMCore.There_should_only_be_two_directories_in__531=There should only be two directories in 
113
RPMCore.Error_executing_the_command__538=Error executing the command 
114
RPMCore.__Check_permissions_of__539=\ \ Check permissions of 
115
RPMCore.Error_in_the_Makefile_in__541=Error in the Makefile in 
116
RPMCore._nMake_sure_there_is_a_clean_/distclean_/realclean_section__542=\nMake sure there is a clean:/distclean:/realclean section:
117
RPMCore.Error_running_the___make_distclean/realclean/mainainer-clean____544=Error running the \'make distclean/realclean/maintainer-clean\' 
118
RPMCore.command_on_the_previous_source_RPM_545=command on the previous source RPM
119
RPMCore.Error_creating_shell_script_for_the__553=Error creating shell script for the 
120
RPMCore._nCheck_file_permissions._554=\nCheck file permissions.
121
RPMCore.Error_executing_the_command_to_create_the_patch_file_-__558=Error executing the command to create the patch file - 
122
RPMCore._nAre_you_sure_there_were_changes_made_to_the_project__559=\nAre you sure there were changes made to the project? 
123
RPMCore.rpm_spec_should_not_be_null_here_in__567=rpm_spec should not be null here in 
124
RPMCore.A_problem_occurred_creating_the_rpmbuild_shell_script.___571=A problem occurred creating the rpmbuild shell script.  
125
RPMCore._nPlease_check_the_file_permissions_in_/var/tmp__572=\nPlease check the file permissions in /var/tmp 
126
RPMCore.A_problem_occurred_running_this_command.___574=A problem occurred running this command.  
127
RPMCore._nPlease_review_the_log_at__575=\nPlease review the log at\nWindows->Show View->Other...->RPM Plugin Log File->RPM Plugin Log Viewer
128
RPMCore.There_are_too_many_directories_in__577=There are too many directories in 
129
RPMCore.Unable_to_delete_file__582=Unable to delete file 
130
RPMCore._nCheck_permissions_in_the_project._583=\nCheck permissions in the project.
131
RPMCore.Error_returned_from_firstSRPM_trying__588=Error returned from firstSRPM() trying 
132
RPMCore.to_copy_the_spec_file_from_the_work_area_to_the_project_589=to copy the spec file from the work area to the project
133
RPMCore.Error_trying_to_rename__591=Error trying to rename 
134
RPMCore.Error_trying_to_create_.srpminfo_file._594=Error trying to create .srpminfo file.
135
RPMCore.Error_trying_to_copy_spec_file_from_work__598=Error trying to copy spec file from work 
136
RPMCore.area_to_Eclipse_project_directory_599=area to Eclipse project directory
137
RPMCore.Error_copying_directories_in__1=Error copying directories in 
138
RPMCore.Error_trying_to_copy_project_directory(_3=Error trying to copy project directory(
139
RPMCore.)_to_the_work_area(_4=) to the work area(
140
RPMCore.Error_trying_to_write_to__8=Error trying to write to 
141
RPMCore.Error_1=Error
142
RPMCore.Error_6=Error
143
RPMCore.Error_8=Error
144
RPMCore.Error_creating_directory___18=Error creating directory: 
145
RPMCore._nCheck_permissions__19=\nCheck permissions?
146
RPMCore.Error_copying_project_source_from__20=Error copying project source from 
147
RPMCore._to__21=\ to 
148
RPMCore.Error_creating_the_shell_script_to_untar_or__22=Error creating the shell script to untar or 
149
RPMCore.executing_the_shell_script_to_untar_the_source._Command____23=executing the shell script to untar the source. Command = 
150
RPMCore.Error_copying_source_from__24=Error copying source from 
151
RPMCore._to__25=\ to 
152
RPMCore.__26=\ 
153
RPMCore.0=generateChecksum: Error trying to access file: 
154
RPMCore.Error_trying_to_copy_file__27=Error trying to copy file 
155
RPMCore._to__28=\ to 
156
RPMCore.Error_trying_to_set_up_rpm__29=Error trying to set up rpm 
157
RPMCore.in__30=in 
158
RPMCore._to_create_patches_31=\ to create patches
159
RPMCore.Checksum___32=Checksum: 
160
RPMCore.Error_parsing_spec_file_at__33=Error parsing spec file at 
161
RPMCore.Error_either_creating_or_running_configure_script_34=Error either creating or running configure script
162
RPMCore.RPMCore._to__7_35=RPMCore._to__7
163
RPMCore.Error_36=Error
164
RPMCore.Error_37=Error
165
RPMCore.Error_39=Error
166
RPMCore.Error_40=Error
167
RPMCore.Error_47=Error
168
RPMCore.An_error_occurred_either_creating_the_shell_script_containing_2=An error occurred either creating the shell script containing 
169
RPMCore.this_command____3=this command:\n  
170
RPMCore._nor_trying_to_execute_it._nView_the_log_at___4=\nor trying to execute it.\nView the log at: 
171
RPMCore._for_more_details_5=\ for more details
172
RPMCore.Error_1=Error
173
RPMCore.There_is_not_a_.srpminfo_file_in__7=There is not a .srpminfo file in 
174
RPMCore.There_is_no_longer_a_source_RPM_at__86=There is no longer a source RPM at 
175
RPMCore.Error_getting_info_from__93=Error getting info from 
176
RPMCore.Error_during__191=Error during 
177
RPMCore._execution..error____192=\ execution..error = 
178
RPMCore.Error_trying_to_copy__6=Error trying to copy 
179
RPMCore._to__7=\ to 
180
RPMCore.Error_trying_to_write_to__8=Error trying to write to 
181
RPMCore.No___%defines___were_found_in_the_spec_file_38=No \'%defines\' were found in the spec file
182
RPMCore.Failed_to_find_a_spec_file_at=Failed to find a spec file at 
183
RPMCore.Error_using_parseDefine_to_get_the_version_no._41=Error using parseDefine to get the version no.
184
RPMCore._from_the_spec_file_at___42=\ from the spec file at: 
185
RPMCore.Error_using_parseDefine_to_get_the_release_no._44=Error using parseDefine to get the release no.
186
RPMCore._from_the_spec_file_at___45=\ from the spec file at: 
187
RPMCore.Error_parsing_the_spec_file_at=Error parsing the spec file at 
188
RPMCore.Error_creating_srpminfo_file_in_the_project._9=Error creating srpminfo file in the project.
189
RPMCore._nCheck_permissions_in__10=\nCheck permissions in 
190
RPMExportCore.Too_many_spec_files_in__4=Too many spec files in 
191
RPMExportCore.Error_trying_to_delete__5=Error trying to delete 
192
ImportSRPM.Error_occurred_during_the_source_install._n_1=Error occurred during the source install.\n
193
ImportSRPM.There_are_either_too_many_or_0_directories_under__2=There are either too many or 0 directories under 
194
ImportSRPM.Cannot_find_a_tarball_to_untar_in___3=Cannot find a tarball to untar in: 
195
LinuxShellCmds.Error_attempting_to_create___1=Error attempting to create: 
196
LinuxShellCmds.Cannot_copy_a_directory___2=Cannot copy a directory: 
197
LinuxShellCmds._to_a_file___3=\ to a file: 
198
LinuxShellCmds.Error_attempting_to_copy_source_from___4=Error attempting to copy source from: 
199
LinuxShellCmds._to__5=\ to 
200
LinuxShellCmds.1=Process  returned non-zero value:
201
LinuxShellCmds.2=Process output:\n
202
LinuxShellCmds.3=Process error:\n
203
LinuxShellCmds.4=Process  executed successfully
204
LinuxShellCmds.5=Process output:\n
205
LinuxShellCmds.6=Process error:\n
206
LinuxShellCmds.7=\n Error output from command:\n
207
LinuxShellCmds.9=Process  returned non-zero value:
208
LinuxShellCmds.10=Process output:\n
209
LinuxShellCmds.11=Process error:\n
210
LinuxShellCmds.12=Process  executed successfully
211
LinuxShellCmds.13=Process output:\n
212
LinuxShellCmds.14=Process error:\n
213
LinuxShellCmds.15=Error executing 
214
RPMCore._nThis_RPM_*must*_be_restored_before_exporting_can_occur._1=\nThis RPM *must* be restored before exporting can occur.
215
RPMCore.Error_creating__1=Error creating 
216
RPMCore._nCheck_permissions__2=\nCheck permissions?
(-)src/org/eclipse/cdt/rpm/core/IPatch.java (+57 lines)
Added Link Here
1
/*
2
 * (c) 2005 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.resources.IFile;
11
12
/** 
13
 * Represents a patch to a source RPM.
14
 */
15
public interface IPatch {
16
17
	/**
18
	 * Returns the spec file ChangeLog entry associated with this patch.
19
	 * @return the ChangeLog entry, or <code>null</code> if not set
20
	 */
21
	public String getChangelogEntry();
22
	
23
	/**
24
	 * Sets the spec file ChangeLog entry associated with this patch.
25
	 * @param changelogEntry the ChangeLog entry
26
	 */
27
	public void setChangelogEntry(String changelogEntry);
28
	
29
	/**
30
	 * Returns the workspace patch file that contains the source code diffs
31
	 * associated with this patch.
32
	 * @return the patch file, or <code>null</code> if not set
33
	 */
34
	public IFile getFile();
35
	
36
	/**
37
	 * Sets the workspace patch file that contains the source code diffs 
38
	 * associated with this patch.
39
	 * @param file the patch file
40
	 */
41
	public void setFile(IFile file);
42
	
43
	/**
44
	 * Returns the name of the patch file.
45
	 * @return the patch file name, or <code>null</code> if not set.
46
	 */
47
	public String getPatchName();
48
	
49
	/**
50
	 * Sets the name of the patch file.  Note that if the workspace patch file has 
51
	 * already been set using <code>setFile</code>, this method will not modify the 
52
	 * name of the patch file on disk.
53
	 * @param patchName the name of the patch file
54
	 */
55
	public void setPatchName(String patchName);
56
	
57
}
(-)src/org/eclipse/cdt/rpm/core/IRPMConfiguration.java (+50 lines)
Added Link Here
1
/*
2
 * (c) 2005 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.resources.IFolder;
11
12
/**
13
 * Represents an RPM configuration associated with an RPM project.
14
 * An RPM configuration contains information about RPM folder locations 
15
 * and other RPM macro definitions.
16
 *
17
 */
18
public interface IRPMConfiguration {
19
20
	/**
21
	 * Returns the workspace folder containing RPM build artifacts.
22
	 * @return the build folder
23
	 */
24
	public IFolder getBuildFolder();
25
26
	/**
27
	 * Returns the workspace folder containing binary RPMs.
28
	 * @return the RPMs folder
29
	 */
30
	public IFolder getRpmsFolder();
31
32
	/**
33
	 * Returns the workspace folder containing RPM sources artifacts.
34
	 * @return the sources folder
35
	 */
36
	public IFolder getSourcesFolder();
37
38
	/**
39
	 * Returns the workspace folder containing RPM spec files.
40
	 * @return the spec files folder
41
	 */
42
	public IFolder getSpecsFolder();
43
44
	/**
45
	 * Returns the workspace folder containing source RPMs.
46
	 * @return the source RPMs folder
47
	 */
48
	public IFolder getSrpmsFolder();
49
50
}
(-)src/org/eclipse/cdt/rpm/core/IRPMConstants.java (+114 lines)
Added Link Here
1
/*
2
 * (c) 2005 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.cdt.rpm.core.internal.Messages;
11
12
public interface IRPMConstants {
13
14
	/**
15
	 * Contains the name of the preference store key for storing and retrieving
16
	 * the path to the system's <code>rpm</code> binary.
17
	 */
18
	public static final String RPM_CMD = "RPM_CMD"; //$NON-NLS-1$
19
	
20
	/**
21
	 * Contains the name of the preference store key for storing and retrieving
22
	 * the path to the system's <code>rpmbuild</code> binary.
23
	 */
24
	public static final String RPMBUILD_CMD = "RPMBUILD_CMD"; //$NON-NLS-1$
25
	
26
	/**
27
	 * Contains the name of the preference store key for storing and retrieving
28
	 * the path to the system's <code>diff</code> binary.
29
	 */
30
	public static final String DIFF_CMD = "DIFF_CMD"; //$NON-NLS-1$
31
	
32
	/**
33
	 * Contains the name of the preference store key for storing and retrieving
34
	 * the author's name.
35
	 */
36
	public static final String AUTHOR_NAME = "AUTHOR_NAME"; //$NON-NLS-1$
37
	
38
	/**
39
	 * Contains the name of the preference store key for storing and retrieving
40
	 * the author's email address.
41
	 */
42
	public static final String AUTHOR_EMAIL = "AUTHOR_EMAIL"; //$NON-NLS-1$
43
	
44
	/**
45
	 * Contains the name of the preference store key for storing and retrieving
46
	 * the name of the RPM log viewer.
47
	 */
48
	public static final String RPM_DISPLAYED_LOG_NAME = "RPM_DISPLAYED_LOG_NAME"; //$NON-NLS-1$
49
	
50
	/**
51
	 * Contains the name of the preference store key for storing and retrieving
52
	 * the name of the RPM log.
53
	 */
54
	public static final String RPM_LOG_NAME = "RPM_LOG_NAME"; //$NON-NLS-1$
55
	
56
	/**
57
	 * Contains the name of the default RPMS folder in an RPM project.
58
	 */
59
	public static final String RPMS_FOLDER = "RPMS"; //$NON-NLS-1$
60
	
61
	/**
62
	 * Contains the name of the default SRPMS folder in an RPM project.
63
	 */
64
	public static final String SRPMS_FOLDER = "SRPMS"; //$NON-NLS-1$
65
	
66
	/**
67
	 * Contains the name of the default SPECS folder in an RPM project.
68
	 */
69
	public static final String SPECS_FOLDER = "SPECS"; //$NON-NLS-1$
70
	
71
	/**
72
	 * Contains the name of the default SOURCES folder in an RPM project.
73
	 */
74
	public static final String SOURCES_FOLDER = "SOURCES"; //$NON-NLS-1$
75
	
76
	/**
77
	 * Contains the name of the default BUILD folder in an RPM project.
78
	 */
79
	public static final String BUILD_FOLDER = "BUILD"; //$NON-NLS-1$
80
	
81
	/**
82
	 * Contains the name of the project property used to store the project-relative
83
	 * path of an RPM project's source RPM.
84
	 */
85
	public static final String SRPM_PROPERTY = "SRPM_PROPERTY"; //$NON-NLS-1$
86
	
87
	/**
88
	 * Contains the name of the project property used to store the project-relative
89
	 * path of an RPM project's spec file.
90
	 */
91
	public static final String SPEC_FILE_PROPERTY = "SPEC_FILE_PROPERTY"; //$NON-NLS-1$
92
	
93
	/**
94
	 * Contains the name of the project property used to store an RPM project's
95
	 * checksum value.
96
	 */
97
	public static final String CHECKSUM_PROPERTY = "CHECKSUM_PROPERTY"; //$NON-NLS-1$
98
	
99
	/**
100
	 * Contains the system's file separator.
101
	 */
102
	public static final String FILE_SEP = System.getProperty("file.separator"); //$NON-NLS-1$
103
104
	/**
105
	 * Contains the system's line separator.
106
	 */
107
	public static final String LINE_SEP = System.getProperty("line.separator"); //$NON-NLS-1$
108
	
109
	/**
110
	 * Contains the plug-ins default error message.
111
	 */
112
	public static final String ERROR = Messages.getString("RPMCore.Error_1"); //$NON-NLS-1$
113
	
114
}
(-)src/org/eclipse/cdt/rpm/core/IRPMProject.java (+157 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core;
8
9
import java.io.File;
10
11
import org.eclipse.core.resources.IProject;
12
import org.eclipse.core.runtime.CoreException;
13
14
/**
15
 * Represents an RPM project.
16
 *
17
 */
18
public interface IRPMProject {
19
20
	/**
21
	 * Prepares the sources for the RPM project according to the directives
22
	 * in the project's spec file.  This method deposits prepared sources 
23
	 * in the project's BUILD directory.  This method is the equivalent of
24
	 * executing <code>rpmbuild -bp /path/to/specfile.spec</code> on the 
25
	 * command line.
26
	 * @throws CoreException if:
27
	 * <ul>
28
	 * <li>The project's BUILD directory cannot be refreshed</li>
29
	 * <li><code>rpmbuild</code> execution fails</li>
30
	 * <li>The project is not an RPM project (a source RPM has not been imported)</li>
31
	 * </ul>
32
	 */
33
	public void buildPrep() throws CoreException;
34
	
35
	/**
36
	 * Builds both a source RPM and a binary RPM according to the directives
37
	 * in the project's spec file.  This method deposits the binary and source
38
	 * RPMs into the project's RPMS and SRPMS directories, respectively.
39
	 * This method will modify the project model and project spec file according
40
	 * to the given export deltas.  This method will also refresh the project
41
	 * sources with the new project model when the export operation is complete.
42
	 * @param export the deltas associated with the export operation
43
	 * @throws CoreException if:
44
	 * <ul>
45
	 * <li>Updating the RPM project model fails</li>
46
	 * <li><code>rpmbuild</code> execution fails</li>
47
	 * <li>Refreshing project sources fails</li>
48
	 * <li>The project is not an RPM project (a source RPM has not been imported)</li>
49
	 * </ul>
50
	 */
51
	public void buildAll(RPMExportDelta export) throws CoreException;
52
	
53
	/**
54
	 * Builds a binary RPM according to the directives in the project's spec file.
55
	 * This method deposits the binary RPM(s) into the project's RPMS directory.
56
	 * This method will modify the project model and project spec file according 
57
	 * to the given export deltas.  This method will also refresh the project 
58
	 * sources with the new project model when the export operation is complete.
59
	 * @param export the deltas associated with the export operation
60
	 * @throws CoreException if:
61
	 * <ul>
62
	 * <li>Updating the RPM project model fails</li>
63
	 * <li><code>rpmbuild</code> execution failse</li>
64
	 * <li>Refreshing project sources fails</li>
65
	 * <li>The project is not an RPM project (a source RPM has not been imported)</li>
66
	 * </ul>
67
	 */
68
	public void buildBinaryRPM(RPMExportDelta export) throws CoreException;
69
	
70
	/**
71
	 * Builds a source RPM according to the directives in the project's spec file.
72
	 * This method deposits the source RPM into the project's RPMS directory.
73
	 * This method will modify the project model and project spec file according 
74
	 * to the given export deltas.  This method will also refresh the project 
75
	 * sources with the new project model when the export operation is complete.
76
	 * @param export the deltas associated with the export operation
77
	 * @throws CoreException if:
78
	 * <ul>
79
	 * <li>Updating the RPM project model fails</li>
80
	 * <li><code>rpmbuild</code> execution failse</li>
81
	 * <li>Refreshing project sources fails</li>
82
	 * <li>The project is not an RPM project (a source RPM has not been imported)</li>
83
	 * </ul>
84
	 */
85
	public void buildSourceRPM(RPMExportDelta export) throws CoreException;
86
	
87
	/**
88
	 * Imports an external source RPM into the project and installs project 
89
	 * sources.  This method also adds an RPM nature to the project.
90
	 * @param externalFile the external source RPM
91
	 * @throws CoreException if:
92
	 * <ul>
93
	 * <li>The external source RPM cannot be accessed</li>
94
	 * <li>Source installation fails</li>
95
	 * <li>Spec file parsing error occurs</li>
96
	 * <li>Calculating project checksum fails</li>
97
	 * </ul>
98
	 */
99
	public void importSourceRPM(File externalFile) throws CoreException;
100
	
101
	/**
102
	 * Returns whether the project has been modified since it has been imported.
103
	 * @return true if the project has been modified, false if it has not
104
	 * @throws CoreException if:
105
	 * <ul>
106
	 * <li>Calculating project checksum fails</li>
107
	 * </ul>
108
	 */
109
	public boolean isChanged() throws CoreException;
110
	
111
	/**
112
	 * Returns the project handle associated with the RPM project.
113
	 * @return the project handle
114
	 */
115
	public IProject getProject();
116
	
117
	/**
118
	 * Returns the RPM configuration associated with the RPM project.
119
	 * @return the RPM configuration
120
	 */
121
	public IRPMConfiguration getConfiguration();
122
	
123
	/**
124
	 * Returns the source RPM associated with the RPM project.
125
	 * @return the source RPM, or <code>null</code> if no source RPM
126
	 * has been imported
127
	 */
128
    public ISourceRPM getSourceRPM();
129
	
130
	/**
131
	 * Sets the source RPM associated with the RPM project.
132
	 * @param sourceRPM the source RPM
133
	 * @throws CoreException if:
134
	 * <ul>
135
	 * <li>Setting the project property associated with the source RPM fails</li>
136
	 * </ul>
137
	 */
138
	public void setSourceRPM(ISourceRPM sourceRPM) throws CoreException;
139
	
140
	/**
141
	 * Returns the spec file associated with the RPM project.
142
	 * @return the spec file, or <code>null</code> if no source RPM 
143
	 * has been imported
144
	 */
145
	public ISpecFile getSpecFile();
146
	
147
	/**
148
	 * Sets the spec file associated with the RPM project.
149
	 * @param specFile the spec file
150
	 * @throws CoreException if:
151
	 * <ul>
152
	 * <li>Setting the project property associated with the spec file fails</li>
153
	 * </ul>
154
	 */
155
	public void setSpecFile(ISpecFile specFile) throws CoreException;
156
	
157
}
(-)src/org/eclipse/cdt/rpm/core/ISourceRPM.java (+43 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core;
8
9
import org.eclipse.core.resources.IFile;
10
import org.eclipse.core.resources.IFolder;
11
12
/**
13
 * Represents a source RPM in an RPM project.
14
 *
15
 */
16
public interface ISourceRPM {
17
	
18
	/**
19
	 * Returns the workspace file associated with the source RPM.
20
	 * @return the source RPM file
21
	 */
22
	public IFile getFile();
23
	
24
	/**
25
	 * Returns the folder contained within the RPM BUILD directory 
26
	 * that contains the project sources.  Typically, this is the 
27
	 * directory that is installed in the BUILD directory after unpacking
28
	 * the project sources during source preparation.
29
	 * @return the source RPM sources folder, or <code>null</code> if 
30
	 * none exists
31
	 */
32
	public IFolder getSourcesFolder();
33
	
34
	/**
35
	 * Sets the folder contained within the RPM BUILD directory that
36
	 * contains the project sources.  Typically, this is the directory
37
	 * that is installed in the BUILD directory after unpacking the 
38
	 * project sources during source preparation.
39
	 * @param folder the source RPM sources folder
40
	 */
41
	public void setSourcesFolder(IFolder folder);
42
	
43
}
(-)src/org/eclipse/cdt/rpm/core/ISpecFile.java (+92 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core;
8
9
import org.eclipse.core.resources.IFile;
10
import org.eclipse.core.runtime.CoreException;
11
12
/**
13
 * Represents a spec file in an RPM project.
14
 *
15
 */
16
public interface ISpecFile {
17
    
18
	/**
19
	 * Adds a patch to the spec file.  Changes to the spec file are not
20
	 * reflected on-disk until the write method is called.
21
	 * @param patch the patch to add
22
	 */
23
    public void addPatch(IPatch patch);
24
    
25
	/**
26
	 * Returns the workspace file handle for the spec file.
27
	 * @return the spec file handle
28
	 */
29
    public IFile getFile();
30
31
	/**
32
	 * Returns the spec file's configure arguments.  For projects that 
33
	 * contain a <code>configure</code> script, the spec file typically 
34
	 * contains a <code>%configure</code> directive followed by a list
35
	 * of arguments.  Not all spec files contain this directive.
36
	 * @return the configure arguments, or <code>null</code> if none present
37
	 */
38
    public String getConfigureArgs();
39
    
40
	/**
41
	 * Returns the name of the RPM project according to the spec file's
42
	 * directives.
43
	 * @return the RPM project name
44
	 */
45
    public String getName();
46
    
47
	/**
48
	 * Sets the name of the RPM project.  Changes to the spec file are
49
	 * not reflected on-disk until the write method is called.
50
	 * @param name the RPM project name
51
	 */
52
    public void setName(String name);
53
    
54
	/**
55
	 * Returns the version of the RPM project according to the spec file's
56
	 * directives.
57
	 * @return the RPM project version
58
	 */
59
    public String getVersion();
60
    
61
	/**
62
	 * Sets the version of the RPM project.  Changes to the spec file
63
	 * are not reflected on-disk until the write method is called.
64
	 * @param version the RPM project version
65
	 */
66
    public void setVersion(String version);
67
    
68
	/**
69
	 * Returns the release of the RPM project according to the spec 
70
	 * file's directives.
71
	 * @return the RPM project release
72
	 */
73
    public String getRelease();
74
    
75
	/**
76
	 * Sets the release of the RPM proejct.  Changes to the spec file
77
	 * are not reflected on-disk until the write method is called.
78
	 * @param release the RPM project release
79
	 */
80
    public void setRelease(String release);
81
	
82
	/**
83
	 * Writes the current spec file model to disk.
84
	 * @throws CoreException if:
85
	 * <ul>
86
	 * <li>Parsing the spec file fails</li>
87
	 * <li>Writing to the spec file fails</li>
88
	 * </ul>
89
	 */
90
	public void write() throws CoreException;
91
	
92
}
(-)src/org/eclipse/cdt/rpm/core/RPMExportDelta.java (+107 lines)
Added Link Here
1
/*
2
 * (c) 2005 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.resources.IFile;
11
12
/**
13
 * Represents a set of changes (delta) to be made to the RPM project
14
 * model during export.
15
 *
16
 */
17
public class RPMExportDelta {
18
19
	private IFile specFile;
20
	private String version;
21
	private String release;
22
	private String patchName;
23
	private String changelogEntry;
24
	
25
	/**
26
	 * Returns the ChangeLog entry associated with the export delta.
27
	 * @return the ChangeLog entry, or <code>null</code> if none set
28
	 */
29
	public String getChangelogEntry() {
30
		return changelogEntry;
31
	}
32
	
33
	/**
34
	 * Sets the ChangeLog entry associated with the export delta.
35
	 * @param changelogEntry the ChangeLog entry
36
	 */
37
	public void setChangelogEntry(String changelogEntry) {
38
		this.changelogEntry = changelogEntry;
39
	}
40
	
41
	/**
42
	 * Returns the name of the patch file associated with the export delta.
43
	 * @return the patch file name, or <code>null</code> if none set
44
	 */
45
	public String getPatchName() {
46
		return patchName;
47
	}
48
	
49
	/**
50
	 * Sets the name of the patch file associated with the export delta.
51
	 * @param patchName the patch file name
52
	 */
53
	public void setPatchName(String patchName) {
54
		this.patchName = patchName;
55
	}
56
	
57
	/**
58
	 * Returns the release associated with the export delta.
59
	 * @return the release
60
	 */
61
	public String getRelease() {
62
		return release;
63
	}
64
	
65
	/**
66
	 * Sets the release associated with the export delta.
67
	 * @param release the release
68
	 */
69
	public void setRelease(String release) {
70
		this.release = release;
71
	}
72
	
73
	/**
74
	 * Returns the workspace file handle for the spec file associated 
75
	 * with this export delta.
76
	 * @return the spec file handle
77
	 */
78
	public IFile getSpecFile() {
79
		return specFile;
80
	}
81
	
82
	/**
83
	 * Sets the workspace file handle for the spec file associated
84
	 * with this export delta.
85
	 * @param specFile the spec file handle
86
	 */
87
	public void setSpecFile(IFile specFile) {
88
		this.specFile = specFile;
89
	}
90
	
91
	/**
92
	 * Returns the the version associated with the export delta.
93
	 * @return the version
94
	 */
95
	public String getVersion() {
96
		return version;
97
	}
98
	
99
	/**
100
	 * Sets the version associated with the export delta.
101
	 * @param version the version
102
	 */
103
	public void setVersion(String version) {
104
		this.version = version;
105
	}
106
	
107
}
(-)src/org/eclipse/cdt/rpm/core/RPMProjectFactory.java (+83 lines)
Added Link Here
1
/*
2
 * (c) 2005 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.cdt.rpm.core.internal.Messages;
11
import org.eclipse.cdt.rpm.core.internal.RPMProject;
12
import org.eclipse.cdt.rpm.core.internal.SourceRPM;
13
import org.eclipse.cdt.rpm.core.internal.SpecFile;
14
import org.eclipse.core.resources.IFolder;
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.QualifiedName;
19
import org.eclipse.core.runtime.Status;
20
21
/**
22
 * Factory class for obtaining an instance of an RPM project.
23
 *
24
 */
25
public class RPMProjectFactory {
26
	
27
	private RPMProjectFactory() {
28
	}
29
	
30
	/**
31
	 * Returns an instance of an RPM project given a workspace project.
32
	 * If the given project has an RPM nature (a source RPM was previously 
33
	 * imported), the RPM project model will be reconstructed.  Otherwise, 
34
	 * the given project will be initialized with the default properties of a
35
	 * new RPM project.  Note that an RPM project is not given an RPM nature 
36
	 * until an import operation has been completed.
37
	 * @param project the workspace project to use in constructing an RPM project
38
	 * @return an RPM project
39
	 * @throws CoreException if:
40
	 * <ul>
41
	 * <li>Initializing the RPM project configuration fails</li>
42
	 * <li>Reconstructing the existing RPM project model fails</li>
43
	 * </ul>
44
	 */
45
	public static IRPMProject getRPMProject(IProject project) throws CoreException {
46
		IRPMProject rpmProject = new RPMProject(project);
47
		
48
		if(project.hasNature(RPMProjectNature.RPM_NATURE_ID)) {
49
			// Construct the project's source RPM object
50
			String sourceRPMName = 
51
				project.getPersistentProperty(new QualifiedName(RPMCorePlugin.ID, IRPMConstants.SRPM_PROPERTY));
52
			if(sourceRPMName != null) {
53
				IFolder srpmsFolder = rpmProject.getConfiguration().getSrpmsFolder();
54
				ISourceRPM sourceRPM = new SourceRPM(srpmsFolder.getFile(sourceRPMName));
55
				rpmProject.setSourceRPM(sourceRPM);
56
			}
57
			else {
58
				String throw_message = Messages.getString("RPMCore.RPMProjectFactory.0"); //$NON-NLS-1$
59
				IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1,
60
						throw_message, null);
61
				throw new CoreException(error);
62
			}
63
		
64
			// Construct the project's spec file object
65
			String specFileName = 
66
				project.getPersistentProperty(new QualifiedName(RPMCorePlugin.ID, IRPMConstants.SPEC_FILE_PROPERTY));
67
			if(specFileName != null) {
68
				ISpecFile specFile = 
69
					new SpecFile(rpmProject.getConfiguration().getSpecsFolder().getFile(specFileName));
70
				rpmProject.setSpecFile(specFile);
71
			}
72
			else {
73
				String throw_message = Messages.getString("RPMCore.RPMProjectFactory.1"); //$NON-NLS-1$
74
				IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1,
75
						throw_message, null);
76
				throw new CoreException(error);
77
			}
78
		}
79
		
80
		return rpmProject;
81
	}
82
83
}
(-)src/org/eclipse/cdt/rpm/core/RPMProjectNature.java (+121 lines)
Added Link Here
1
/*
2
 * (c) 2005 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 java.util.ArrayList;
11
import java.util.Arrays;
12
import java.util.List;
13
14
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.resources.IProjectDescription;
16
import org.eclipse.core.resources.IProjectNature;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
20
/**
21
 * The RPM project nature.
22
 *
23
 */
24
public class RPMProjectNature implements IProjectNature {
25
26
	/**
27
	 * The unique nature ID associated with the RPM project nature.
28
	 */
29
	public static final String RPM_NATURE_ID = RPMCorePlugin.ID + ".rpmnature"; //$NON-NLS-1$
30
	
31
	IProject project;
32
	
33
	public RPMProjectNature() {
34
	}
35
	
36
	public RPMProjectNature(IProject project) {
37
		this.project = project;
38
	}
39
	
40
	/**
41
	 * Adds the RPM project nature to a given workspace project.
42
	 * @param project the project
43
	 * @param mon a progress monitor, or <code>null</code> if progress monitoring
44
	 * is not desired
45
	 * @throws CoreException if adding the RPM project nature fails
46
	 */
47
	public static void addRPMNature(IProject project, IProgressMonitor mon) throws CoreException {
48
		addNature(project, RPM_NATURE_ID, mon);
49
	}
50
51
	/**
52
	 * Removes the RPM project nature from a given workspace project.
53
	 * @param project the project
54
	 * @param mon a progress monitor, or <code>null</code> if progress monitoring
55
	 * is not desired
56
	 * @throws CoreException if removing the RPM project nature fails
57
	 */
58
	public static void removeRPMNature(IProject project, IProgressMonitor mon) throws CoreException {
59
		removeNature(project, RPM_NATURE_ID, mon);
60
	}
61
	
62
	/**
63
	 * Utility method for adding a nature to a project.
64
	 * 
65
	 * @param proj
66
	 *            the project to add the nature
67
	 * @param natureId
68
	 *            the id of the nature to assign to the project
69
	 * @param monitor
70
	 *            a progress monitor to indicate the duration of the operation,
71
	 *            or <code>null</code> if progress reporting is not required.
72
	 *  
73
	 */
74
	private static void addNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException {
75
		if(project.hasNature(natureId)) {
76
			return;
77
		}
78
		IProjectDescription description = project.getDescription();
79
		String[] prevNatures = description.getNatureIds();
80
		String[] newNatures = new String[prevNatures.length + 1];
81
		System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
82
		newNatures[prevNatures.length] = natureId;
83
		description.setNatureIds(newNatures);
84
		project.setDescription(description, monitor);
85
	}
86
87
	/**
88
	 * Utility method for removing a project nature from a project.
89
	 * 
90
	 * @param proj
91
	 *            the project to remove the nature from
92
	 * @param natureId
93
	 *            the nature id to remove
94
	 * @param monitor
95
	 *            a progress monitor to indicate the duration of the operation,
96
	 *            or <code>null</code> if progress reporting is not required.
97
	 */
98
	private static void removeNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException {
99
		IProjectDescription description = project.getDescription();
100
		String[] prevNatures = description.getNatureIds();
101
		List newNatures = new ArrayList(Arrays.asList(prevNatures));
102
		newNatures.remove(natureId);
103
		description.setNatureIds((String[]) newNatures.toArray(new String[newNatures.size()]));
104
		project.setDescription(description, monitor);
105
	}
106
	
107
	public void configure() throws CoreException {
108
	}
109
110
	public void deconfigure() throws CoreException {
111
	}
112
113
	public IProject getProject() {
114
		return project;
115
	}
116
117
	public void setProject(IProject project) {
118
		this.project = project;
119
	}
120
121
}
(-)src/org/eclipse/cdt/rpm/core/internal/Messages.java (+28 lines)
Added Link Here
1
/*
2
 * (c) 2004, 2005 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.internal;
9
10
import java.util.MissingResourceException;
11
import java.util.ResourceBundle;
12
13
public class Messages {
14
	private static final String BUNDLE_NAME = "org.eclipse.cdt.rpm.core.internal.rpm_strings"; //$NON-NLS-1$
15
16
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
17
18
	private Messages() {
19
	}
20
21
	public static String getString(String key) {
22
		try {
23
			return RESOURCE_BUNDLE.getString(key);
24
		} catch (MissingResourceException e) {
25
			return '!' + key + '!';
26
		}
27
	}
28
}
(-)src/org/eclipse/cdt/rpm/core/internal/Patch.java (+38 lines)
Added Link Here
1
/*
2
 * (c) 2005 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.internal;
9
10
import org.eclipse.cdt.rpm.core.IPatch;
11
import org.eclipse.core.resources.IFile;
12
13
public class Patch implements IPatch {
14
15
	private String changelogEntry;
16
	private String patchName;
17
	private IFile file;
18
	
19
	public String getChangelogEntry() {
20
		return changelogEntry;
21
	}
22
	public void setChangelogEntry(String changelogEntry) {
23
		this.changelogEntry = changelogEntry;
24
	}
25
	public IFile getFile() {
26
		return file;
27
	}
28
	public void setFile(IFile file) {
29
		this.file = file;
30
	}
31
	public String getPatchName() {
32
		return patchName;
33
	}
34
	public void setPatchName(String patchName) {
35
		this.patchName = patchName;
36
	}
37
38
}
(-)src/org/eclipse/cdt/rpm/core/internal/RPMConfiguration.java (+143 lines)
Added Link Here
1
/*
2
 * (c) 2005 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.internal;
9
10
import org.eclipse.cdt.rpm.core.IRPMConfiguration;
11
import org.eclipse.cdt.rpm.core.IRPMConstants;
12
import org.eclipse.cdt.rpm.core.RPMCorePlugin;
13
import org.eclipse.core.resources.IFolder;
14
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.QualifiedName;
17
18
public class RPMConfiguration implements IRPMConfiguration {
19
	
20
	private IProject project;
21
	
22
	private IFolder rpmsFolder;
23
    private IFolder srpmsFolder;
24
    private IFolder specsFolder;
25
    private IFolder sourcesFolder;
26
    private IFolder buildFolder;
27
	
28
	public RPMConfiguration(IProject project) throws CoreException {
29
		this.project = project;
30
		initialize();
31
	}
32
	
33
	/**
34
	 * Sets the internal folder fields according to stored properties
35
	 * in the workspace project, or according to the default properties
36
	 * if no stored properties are found.  If the folders do not exist,
37
	 * they are created.
38
	 * @throws CoreException if:
39
	 * <ul>
40
	 * <li>Getting or setting project properties fails</ul>
41
	 * <li>Creating project folders fails</li>
42
	 * </ul>
43
	 */
44
    private void initialize() throws CoreException {
45
		String pluginID = RPMCorePlugin.ID;
46
        
47
		String sourcesPath = 
48
			project.getPersistentProperty(new QualifiedName(pluginID, IRPMConstants.SOURCES_FOLDER));
49
		if(sourcesPath == null) {
50
			sourcesFolder = project.getFolder(IRPMConstants.SOURCES_FOLDER);
51
			sourcesFolder.create(false, true, null);
52
			sourcesFolder.setDerived(true);
53
			project.setPersistentProperty(new QualifiedName(pluginID, IRPMConstants.SOURCES_FOLDER), 
54
	                sourcesFolder.getName());
55
        } else {
56
			sourcesFolder = project.getFolder(sourcesPath);
57
			if(!sourcesFolder.exists()) {
58
				sourcesFolder.create(false, true, null);
59
			}
60
        }
61
		
62
		String srcRpmPath = 
63
			project.getPersistentProperty(new QualifiedName(pluginID, IRPMConstants.SRPMS_FOLDER));
64
        if(srcRpmPath == null) {
65
			srpmsFolder = project.getFolder(IRPMConstants.SRPMS_FOLDER);
66
			srpmsFolder.create(false, true, null);
67
			srpmsFolder.setDerived(true);
68
			project.setPersistentProperty(new QualifiedName(pluginID, IRPMConstants.SRPMS_FOLDER),
69
					srpmsFolder.getName());
70
        } else {
71
			srpmsFolder = project.getFolder(srcRpmPath);
72
			if(!srpmsFolder.exists()) {
73
				srpmsFolder.create(false, true, null);
74
			}
75
        }
76
		
77
		String buildPath = 
78
			project.getPersistentProperty(new QualifiedName(pluginID, IRPMConstants.BUILD_FOLDER));
79
        if(buildPath == null) {
80
            buildFolder = project.getFolder(IRPMConstants.BUILD_FOLDER);
81
			buildFolder.create(false, true, null);
82
			buildFolder.setDerived(true);
83
			project.setPersistentProperty(new QualifiedName(pluginID, IRPMConstants.BUILD_FOLDER), 
84
					buildFolder.getName());
85
        } else {
86
			buildFolder = project.getFolder(buildPath);
87
			if(!buildFolder.exists()) {
88
				buildFolder.create(false, true, null);
89
			}
90
        }
91
		
92
		String rpmPath = 
93
			project.getPersistentProperty(new QualifiedName(pluginID, IRPMConstants.RPMS_FOLDER));
94
        if(rpmPath == null) {
95
			rpmsFolder = project.getFolder(IRPMConstants.RPMS_FOLDER);
96
			rpmsFolder.create(false, true, null);
97
			rpmsFolder.setDerived(true);
98
			project.setPersistentProperty(new QualifiedName(pluginID, IRPMConstants.RPMS_FOLDER), 
99
	                rpmsFolder.getName());
100
        } else {
101
			rpmsFolder = project.getFolder(rpmPath);
102
			if(!rpmsFolder.exists()) {
103
				rpmsFolder.create(false, true, null);
104
			}
105
        }
106
		
107
		String specPath = 
108
			project.getPersistentProperty(new QualifiedName(pluginID, IRPMConstants.SPECS_FOLDER));
109
        if(specPath == null) {
110
            specsFolder = project.getFolder(IRPMConstants.SPECS_FOLDER);
111
			specsFolder.create(false, true, null);
112
			specsFolder.setDerived(true);
113
			project.setPersistentProperty(new QualifiedName(pluginID, IRPMConstants.SPECS_FOLDER),
114
					specsFolder.getName());
115
        } else {
116
			specsFolder = project.getFolder(specPath);
117
			if(!specsFolder.exists()) {
118
				specsFolder.create(false, true, null);
119
			}
120
        }
121
    }
122
	
123
	public IFolder getBuildFolder() {
124
		return buildFolder;
125
	}
126
127
	public IFolder getRpmsFolder() {
128
		return rpmsFolder;
129
	}
130
131
	public IFolder getSourcesFolder() {
132
		return sourcesFolder;
133
	}
134
135
	public IFolder getSpecsFolder() {
136
		return specsFolder;
137
	}
138
139
	public IFolder getSrpmsFolder() {
140
		return srpmsFolder;
141
	}
142
143
}
(-)src/org/eclipse/cdt/rpm/core/internal/RPMProject.java (+419 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.internal;
8
9
import java.io.BufferedReader;
10
import java.io.File;
11
import java.io.FileInputStream;
12
import java.io.FileNotFoundException;
13
import java.io.FileReader;
14
import java.io.IOException;
15
import java.util.Vector;
16
17
import org.eclipse.cdt.rpm.core.IPatch;
18
import org.eclipse.cdt.rpm.core.IRPMConfiguration;
19
import org.eclipse.cdt.rpm.core.IRPMConstants;
20
import org.eclipse.cdt.rpm.core.IRPMProject;
21
import org.eclipse.cdt.rpm.core.ISourceRPM;
22
import org.eclipse.cdt.rpm.core.ISpecFile;
23
import org.eclipse.cdt.rpm.core.RPMCorePlugin;
24
import org.eclipse.cdt.rpm.core.RPMExportDelta;
25
import org.eclipse.cdt.rpm.core.RPMProjectNature;
26
import org.eclipse.cdt.rpm.core.utils.Diff;
27
import org.eclipse.cdt.rpm.core.utils.RPM;
28
import org.eclipse.cdt.rpm.core.utils.RPMBuild;
29
import org.eclipse.core.resources.IFile;
30
import org.eclipse.core.resources.IFolder;
31
import org.eclipse.core.resources.IProject;
32
import org.eclipse.core.resources.IResource;
33
import org.eclipse.core.runtime.CoreException;
34
import org.eclipse.core.runtime.IPath;
35
import org.eclipse.core.runtime.IStatus;
36
import org.eclipse.core.runtime.Path;
37
import org.eclipse.core.runtime.QualifiedName;
38
import org.eclipse.core.runtime.Status;
39
40
public class RPMProject implements IRPMProject {
41
	
42
    private IProject project;
43
    private ISourceRPM sourceRPM;
44
	private ISpecFile specFile;
45
	private IRPMConfiguration rpmConfig;
46
    
47
    public RPMProject(IProject project) throws CoreException {
48
        this.project = project;
49
		rpmConfig = new RPMConfiguration(this.project);
50
    }
51
	
52
	public IProject getProject() {
53
		return project;
54
	}
55
	
56
    public ISourceRPM getSourceRPM() {
57
        return sourceRPM;
58
    }
59
	
60
	public void setSourceRPM(ISourceRPM sourceRPM) throws CoreException {
61
		this.sourceRPM = sourceRPM;
62
		getProject().setPersistentProperty(new QualifiedName(RPMCorePlugin.ID, 
63
				IRPMConstants.SRPM_PROPERTY), sourceRPM.getFile().getName());
64
	}
65
	
66
	public IRPMConfiguration getConfiguration() {
67
		return rpmConfig;
68
	}
69
	
70
	public ISpecFile getSpecFile() {
71
		return specFile;
72
	}
73
	
74
	public void setSpecFile(ISpecFile specFile) throws CoreException {
75
		this.specFile = specFile;
76
		getProject().setPersistentProperty(new QualifiedName(RPMCorePlugin.ID, 
77
				IRPMConstants.SPEC_FILE_PROPERTY), specFile.getFile().getName());
78
	}
79
	
80
	public void importSourceRPM(File externalFile) throws CoreException {
81
		// Copy original SRPM to workspace
82
		IFile srpmFile = getConfiguration().getSrpmsFolder().getFile(externalFile.getName());
83
		try {
84
			srpmFile.create(new FileInputStream(externalFile), false, null);
85
		} catch(FileNotFoundException e) {
86
			String throw_message = Messages.getString("RPMCore.Error_trying_to_copy__") + //$NON-NLS-1$
87
				rpmConfig.getSpecsFolder().getLocation().toOSString();
88
			IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1, throw_message, null);
89
			throw new CoreException(error); 
90
		}
91
		setSourceRPM(new SourceRPM(srpmFile));
92
        
93
        // Install the SRPM
94
        RPM rpm = new RPM(getConfiguration());
95
        rpm.install(getSourceRPM().getFile());
96
		getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
97
		
98
        // Set the spec file
99
        IResource[] installedSpecs = {};
100
        installedSpecs = getConfiguration().getSpecsFolder().members();
101
        if (installedSpecs.length != 1) {
102
            String throw_message = Messages.getString("RPMCore.spec_file_ambiguous") + //$NON-NLS-1$
103
            	rpmConfig.getSpecsFolder().getLocation().toOSString();
104
            IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1, throw_message, null);
105
            throw new CoreException(error); 
106
        }
107
        setSpecFile(new SpecFile(getConfiguration().getSpecsFolder().getFile(installedSpecs[0].getName())));
108
		
109
		// Prepare the sources
110
		buildPrep();
111
		getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
112
		
113
		// Copy sources from build root
114
		copySources();
115
		
116
		// Set the project nature
117
		RPMProjectNature.addRPMNature(getProject(), null);
118
		
119
		// Generate and store project checksum
120
		long checksum = generateProjectChecksum(getProject().getLocation().toOSString(), 0);
121
		getProject().setPersistentProperty(new QualifiedName(RPMCorePlugin.ID, 
122
				IRPMConstants.CHECKSUM_PROPERTY), new Long(checksum).toString());
123
	}
124
	
125
	public void buildAll(RPMExportDelta exportOp) throws CoreException {
126
		prepareExport(exportOp);
127
		RPMBuild rpmbuild = new RPMBuild(getConfiguration());
128
		rpmbuild.buildAll(getSpecFile().getFile());
129
		
130
		getConfiguration().getBuildFolder().refreshLocal(IResource.DEPTH_INFINITE, null);
131
		getConfiguration().getRpmsFolder().refreshLocal(IResource.DEPTH_INFINITE, null);
132
		getConfiguration().getSrpmsFolder().refreshLocal(IResource.DEPTH_INFINITE, null);
133
		buildPrep();
134
		copySources();
135
	}
136
	
137
	public void buildBinaryRPM(RPMExportDelta exportOp) throws CoreException {
138
		prepareExport(exportOp);
139
		RPMBuild rpmbuild = new RPMBuild(getConfiguration());
140
		rpmbuild.buildBinary(getSpecFile().getFile());
141
		
142
		getConfiguration().getBuildFolder().refreshLocal(IResource.DEPTH_INFINITE, null);
143
		getConfiguration().getRpmsFolder().refreshLocal(IResource.DEPTH_INFINITE, null);
144
	}
145
	
146
	public void buildSourceRPM(RPMExportDelta exportOp) throws CoreException {
147
		prepareExport(exportOp);
148
		RPMBuild rpmbuild = new RPMBuild(getConfiguration());
149
		rpmbuild.buildSource(getSpecFile().getFile());
150
		
151
		getConfiguration().getBuildFolder().refreshLocal(IResource.DEPTH_INFINITE, null);
152
		getConfiguration().getSrpmsFolder().refreshLocal(IResource.DEPTH_INFINITE, null);
153
		buildPrep();
154
		copySources();
155
	}
156
	
157
	public void buildPrep() throws CoreException {	
158
        RPMBuild rpmbuild = new RPMBuild(getConfiguration());
159
        rpmbuild.buildPrep(getSpecFile().getFile());
160
        getConfiguration().getBuildFolder().refreshLocal(IResource.DEPTH_INFINITE, null);
161
		IResource[] sources = getConfiguration().getBuildFolder().members();
162
		// If there is one folder, assume it contains all the sources
163
		if(sources.length == 1 && sources[0].getType() == IResource.FOLDER) {
164
			IFolder foo = getProject().getFolder(sources[0].getProjectRelativePath());
165
			getSourceRPM().setSourcesFolder(foo);
166
		}
167
    }
168
	
169
	public boolean isChanged() throws CoreException {
170
		getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
171
		String originalSumStr = getProject().getPersistentProperty(new QualifiedName(RPMCorePlugin.ID,
172
				IRPMConstants.CHECKSUM_PROPERTY));
173
		long currSum = generateProjectChecksum(getProject().getLocation().toOSString(), 0);
174
		return (new Long(originalSumStr).longValue()) != currSum;
175
	}
176
	
177
	/**
178
	 * Copies sources from the project's BUILD directory to the project root.
179
	 * @throws CoreException if copying fails
180
	 */
181
	private void copySources() throws CoreException {
182
		//Copy all sources to the project root
183
		IResource[] sources = null;
184
		if(getSourceRPM().getSourcesFolder() != null) {
185
			sources = getSourceRPM().getSourcesFolder().members();
186
		} else {
187
			getConfiguration().getBuildFolder().members();
188
		}
189
		for(int i=0; i < sources.length; i++) {
190
			IPath path = getProject().getFullPath().addTrailingSeparator();
191
			path = path.append(sources[i].getName());
192
			if(sources[i].getType() == IResource.FILE) {
193
				IFile oldFile = getProject().getParent().getFile(path);
194
				IFile newFile = 
195
					getProject().getFile(sources[i].getProjectRelativePath());
196
				if(oldFile.exists()) {
197
					oldFile.setContents(newFile.getContents(), false, true, null);
198
				} else {
199
					sources[i].copy(path, false, null);
200
				}
201
			} else if(sources[i].getType() == IResource.FOLDER) {
202
				IFolder oldDir = getProject().getParent().getFolder(path);
203
				if(oldDir.exists()) {
204
					oldDir.delete(false, true, null);
205
				}
206
				sources[i].copy(path, false, null);
207
			}
208
		}
209
		getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
210
	}
211
	
212
	/**
213
	 * Prepares for project export.  This method updates the project model with 
214
	 * the given RPM project export delta by:
215
	 * <ul>
216
	 * <li>Parsing the given spec file and updating the model accordingly</li>
217
	 * <li>Updating the spec file model and writing it to disk</li>
218
	 * <li>Determining if a patch is needed and generating a patch</li>
219
	 * </ul>
220
	 * @param exportOp the export delta
221
	 * @throws CoreException if:
222
	 * <ul>
223
	 * <li>The project does not have an RPM nature</li>
224
	 * <li>Parsing the spec file fails</li>
225
	 * <li>Patch generation fails</li>
226
	 * <li>Writing the spec file fails</li>
227
	 * </ul>
228
	 */
229
	private void prepareExport(RPMExportDelta exportOp) throws CoreException {
230
		/* Don't support exporting projects that have not been imported as SRPMs */
231
		if (!getProject().hasNature(RPMProjectNature.RPM_NATURE_ID)) {
232
			String throw_message = Messages.getString("RPMCore.RPMProject.prepareExport") + //$NON-NLS-1$
233
				getProject().getName();
234
			IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1, throw_message, null);
235
			throw new CoreException(error);
236
		}
237
		
238
		// We need to reset the spec file (which may be user-defined)
239
		if(exportOp.getSpecFile() != null && 
240
				!getSpecFile().getFile().getProjectRelativePath().equals(exportOp.getSpecFile().getProjectRelativePath())) {
241
			setSpecFile(new SpecFile(exportOp.getSpecFile()));
242
		}
243
		else {
244
			setSpecFile(new SpecFile(getSpecFile().getFile()));
245
		}
246
		
247
		boolean patchNeeded = isChanged();
248
		if (exportOp.getVersion().equals(getSpecFile().getVersion()) && 
249
				exportOp.getRelease().equals(getSpecFile().getRelease()) && !patchNeeded) {
250
			return;
251
		}
252
		
253
		getSpecFile().setVersion(exportOp.getVersion());
254
		getSpecFile().setRelease(exportOp.getRelease());
255
		if(patchNeeded) {
256
			//Do a buildPrep again to make sure the BUILD folder is pristine
257
			buildPrep();
258
			getSpecFile().addPatch(generatePatch(exportOp));
259
			//Generate and store new project checksum
260
			long checksum = generateProjectChecksum(getProject().getLocation().toOSString(), 0);
261
			getProject().setPersistentProperty(new QualifiedName(RPMCorePlugin.ID, 
262
					IRPMConstants.CHECKSUM_PROPERTY), new Long(checksum).toString());
263
		}
264
		// write changes to spec file on disk
265
		getSpecFile().write();
266
		
267
		getConfiguration().getSourcesFolder().refreshLocal(IResource.DEPTH_INFINITE, null);
268
		getConfiguration().getSpecsFolder().refreshLocal(IResource.DEPTH_INFINITE, null);
269
	}
270
	
271
	/**
272
	 * Generates a patch given a project's export delta.
273
	 * @param exportOp the export delta
274
	 * @return the patch
275
	 * @throws CoreException if:
276
	 * <ul>
277
	 * <li>The supplied patch name already exists</li>
278
	 * <li>Patch generation fails</li>
279
	 * </ul>
280
	 */
281
	private IPatch generatePatch(RPMExportDelta exportOp) throws CoreException {
282
		// Make sure patch name is unique
283
		String patch_name = exportOp.getPatchName();
284
		IFile patchFile = getConfiguration().getSourcesFolder().getFile(patch_name);
285
		if(patchFile.exists()) {
286
			String throw_message = Messages.getString(
287
			"RPMCore.The_patch_name__109") + patch_name + //$NON-NLS-1$
288
			Messages.getString("RPMCore._is_not_unique._110") + //$NON-NLS-1$
289
			Messages.getString(
290
			"RPMCore._nPlease_modify_the___Patch_tag___field_and_try_again._111"); //$NON-NLS-1$
291
			IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1, throw_message,
292
					null);
293
			throw new CoreException(error);
294
		}
295
		
296
		String diff_old_dir = null;
297
		if(getSourceRPM().getSourcesFolder() != null) {
298
			diff_old_dir = getSourceRPM().getSourcesFolder().getLocation().toOSString();
299
		}
300
		else {
301
			diff_old_dir = getConfiguration().getBuildFolder().getLocation().toOSString();
302
		}
303
		String diff_new_dir = getProject().getName();
304
305
		// Figure out what resources to exclude from the diff
306
		String[] excludes = findExcludedFiles();
307
		
308
		// Do the diff
309
		Diff diff = new Diff(getProject().getParent().getLocation().toOSString(),
310
				diff_old_dir, diff_new_dir, excludes, patchFile.getLocation().toOSString());
311
		diff.exec();
312
		
313
		// Construct a new patch
314
		IPatch patch = new Patch();
315
		patch.setChangelogEntry(exportOp.getChangelogEntry());
316
		patch.setFile(patchFile);
317
		patch.setPatchName(patch_name);
318
		return patch;
319
	}
320
	
321
	/**
322
	 * Finds a list of files to exclude from patch generation.  By default,
323
	 * all resources that are marked as derived are excluded from patch 
324
	 * generation.
325
	 * @return an array of project-relative paths of excluded files
326
	 * @throws CoreException if the operation fails
327
	 */
328
	private String[] findExcludedFiles() throws CoreException {
329
		Vector excludes = new Vector();
330
		IResource[] resources = getProject().members();
331
		for(int i=0; i < resources.length; i++) {
332
			find(resources[i], excludes);
333
		}
334
335
		String[] excludesArr = new String[excludes.size()];
336
		for(int i=0; i < excludes.size(); i++) {
337
			excludesArr[i] = (String) excludes.get(i);
338
		}
339
		return excludesArr;
340
	}
341
	
342
	private void find(IResource resource, Vector excludes) throws CoreException {
343
		if(resource.isDerived()) {
344
			excludes.add(resource.getName());
345
		}
346
		else if(resource.getType() == IResource.FOLDER) {
347
			IFolder folder = getProject().getFolder(resource.getProjectRelativePath());
348
			IResource[] members = folder.members();
349
			for(int i=0; i < members.length; i++) {
350
				find(members[i], excludes);
351
			}
352
		}
353
	}
354
	
355
	/**
356
	 * Generates the checksum for a given project path.
357
	 * @param project_path the absolute path of the project
358
	 * @param proj_checksum input 0
359
	 * @return
360
	 * @throws CoreException if the operation fails
361
	 */
362
	private long generateProjectChecksum(String project_path, long proj_checksum) 
363
	   throws CoreException {
364
		File dir = new File(project_path);
365
366
		if (dir.isDirectory()) {
367
			String[] children = dir.list();
368
369
			for (int i = 0; i < children.length; i++) {
370
371
				File temp = new File(project_path + IRPMConstants.FILE_SEP + children[i]);
372
				
373
				if (temp.isDirectory()) {
374
					  	IFolder folder = getProject().getFolder(new Path(children[i]));
375
						if(!folder.isDerived()) {
376
							proj_checksum = generateProjectChecksum(project_path
377
								+ IRPMConstants.FILE_SEP + children[i], proj_checksum);
378
						}
379
				} else {
380
					IFile file = getProject().getFile(new Path(children[i]));
381
					if(!file.isDerived() || file.getProjectRelativePath().equals(getSpecFile().getFile().getProjectRelativePath())) {
382
						proj_checksum += generateFileCheckSum(temp);
383
					}
384
					if (children[i].equals("Makefile") & !getProject().getFile("configure").exists()) { //$NON-NLS-1$ //$NON-//$NON-NLS-2$
385
						proj_checksum += generateFileCheckSum(temp);
386
					}
387
				}
388
			}
389
		}
390
391
		return proj_checksum;
392
	}
393
	
394
	private long generateFileCheckSum(File input) throws CoreException {
395
		String input_line;
396
		long chksum = 0;
397
		try {
398
		BufferedReader br = new BufferedReader(new FileReader(input.toString()));
399
		while ((input_line = br.readLine()) != null) {
400
			for (int i=0; i<input_line.length(); i++)
401
			  chksum += input_line.charAt(i);
402
		}
403
		br.close();
404
		} catch(FileNotFoundException e) {
405
			String throw_message = Messages.getString("RPMCore.0") + //$NON-NLS-1$
406
			  input.getName();
407
			IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1,
408
					throw_message, null);
409
			throw new CoreException(error);
410
		} catch(IOException e) {
411
			String throw_message = Messages.getString("RPMCore.0") + //$NON-NLS-1$
412
			  input.getName();
413
			IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1,
414
					throw_message, null);
415
			throw new CoreException(error);
416
		}
417
		return chksum;
418
	}
419
}
(-)src/org/eclipse/cdt/rpm/core/internal/SourceRPM.java (+33 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.internal;
8
9
import org.eclipse.cdt.rpm.core.ISourceRPM;
10
import org.eclipse.core.resources.IFile;
11
import org.eclipse.core.resources.IFolder;
12
13
public class SourceRPM implements ISourceRPM {
14
    
15
	private IFile sourceRPM;
16
	private IFolder sourcesFolder;
17
	
18
	public SourceRPM(IFile sourceRPM) {
19
		this.sourceRPM = sourceRPM;
20
	}
21
	
22
	public IFile getFile() {
23
		return sourceRPM;
24
	}
25
	
26
	public IFolder getSourcesFolder() {
27
		return sourcesFolder;
28
	}
29
	
30
	public void setSourcesFolder(IFolder sourcesFolder) {
31
		this.sourcesFolder = sourcesFolder;
32
	}
33
}
(-)src/org/eclipse/cdt/rpm/core/internal/SpecFile.java (+207 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.internal;
8
9
import java.io.BufferedReader;
10
import java.io.FileNotFoundException;
11
import java.io.FileReader;
12
import java.io.FileWriter;
13
import java.io.IOException;
14
15
import org.eclipse.cdt.rpm.core.IPatch;
16
import org.eclipse.cdt.rpm.core.IRPMConstants;
17
import org.eclipse.cdt.rpm.core.ISpecFile;
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.core.runtime.Status;
24
25
public class SpecFile implements ISpecFile {
26
	
27
    private String name;
28
    private String version;
29
    private String release;
30
    private IPatch patch;
31
    private IFile specFile;
32
	
33
	private int lastSourceLine;
34
	private int lastPatchLine;
35
	private int setupLine;
36
	private int lastPatchMacroLine;
37
	private int numPatches;
38
    
39
    private String configureArgs;
40
    
41
    public SpecFile(IFile specFile) throws CoreException {
42
        this.specFile = specFile;
43
        SpecFileParser parser = new SpecFileParser(this.specFile);
44
        parser.parse();
45
        name = parser.getName();
46
        version = parser.getVersion();
47
        release = parser.getRelease();
48
        configureArgs = parser.getConfigureArgs();
49
		lastSourceLine = parser.getLastSourceLine();
50
		lastPatchLine = parser.getLastPatchLine();
51
		setupLine = parser.getSetupLine();
52
		lastPatchMacroLine = parser.getLastPatchMacroLine();
53
		numPatches = parser.getNumPatches();
54
    }
55
    
56
    public void addPatch(IPatch patch) {
57
        this.patch = patch;
58
    }
59
60
    public void write() throws CoreException {
61
		String patch_name = null;
62
		String patchLine = null;
63
		String patchMacroLine = null;
64
		if(patch != null) {
65
		   patch_name = patch.getPatchName();
66
67
		   // Figure out the format of the lines to add
68
		   patchLine = "Patch" + numPatches + ": " + patch_name + IRPMConstants.LINE_SEP; //$NON-NLS-1$ //$NON-NLS-2$
69
		   patchMacroLine = "%patch" + numPatches + " -p1" + IRPMConstants.LINE_SEP; //$NON-NLS-1$ //$NON-NLS-2$
70
		}
71
        
72
		if(lastPatchLine == 0) {
73
			if(lastSourceLine == 0) {
74
				lastPatchLine = setupLine;
75
			} 
76
			else {
77
				lastPatchLine = lastSourceLine;
78
			}
79
		}
80
		if(lastPatchMacroLine == 0) {
81
			lastPatchMacroLine = setupLine;
82
		}
83
84
		// Now read the spec file line by line and write it to the final 
85
		// spec file adding in the lines to perform the patching.
86
		IFile newSpecFile = 
87
			getFile().getParent().getFile(new Path(getFile().getName() + ".new")); //$NON-NLS-1$
88
		String path_to_newspecfile = newSpecFile.getLocation().toOSString();
89
		
90
		FileReader fr = null;
91
		try {
92
			fr = new FileReader(getFile().getLocation().toOSString());
93
		} catch(FileNotFoundException e) {
94
			String throw_message = Messages.getString("RPMCore.Failed_to_find_a_spec_file_at") + //$NON-NLS-1$
95
			  getFile().getLocation().toOSString();
96
			IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1,
97
					throw_message, null);
98
			throw new CoreException(error);
99
		}
100
		BufferedReader br = new BufferedReader(fr);
101
		FileWriter fw;
102
103
		try {
104
			fw = new FileWriter(path_to_newspecfile);
105
		} catch (IOException e) {
106
			String throw_message = Messages.getString(
107
					"RPMCore.Failed_to_open_the_output_spec_file_at__123") + //$NON-NLS-1$
108
					path_to_newspecfile;
109
			IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1, throw_message,
110
					null);
111
			throw new CoreException(error);
112
		}
113
114
		int line_ctr = 0;
115
		String input_line;
116
		boolean found_changelog = false;
117
118
		// Setup the lines that set the version and release numbers
119
		String new_version_line = "Version: " + getVersion(); //$NON-NLS-1$
120
		String new_release_line = "Release: " + getRelease(); //$NON-NLS-1$
121
122
		try {
123
			while ((input_line = br.readLine()) != null) {
124
				if (input_line.length() > 8) {
125
					if (input_line.startsWith("Version")) { //$NON-NLS-1$
126
						input_line = new_version_line;
127
					} else if (input_line.startsWith("Release")) { //$NON-NLS-1$
128
						input_line = new_release_line;
129
					}
130
				}
131
132
				fw.write(input_line + IRPMConstants.LINE_SEP);
133
134
				// See if this was the "%changelog" line just written, if it was, write out the new entry
135
				if (input_line.length() == 10 && patch != null) { //$NON-NLS-1$
136
					if (input_line.startsWith("%changelog")) { //$NON-NLS-1$
137
						fw.write(patch.getChangelogEntry());
138
						found_changelog = true;
139
					}
140
				}
141
142
				line_ctr++;
143
144
				// Check to see if this is one of the lines I should add something after
145
				if(patch != null) { //$NON-NLS-1$
146
				   if(line_ctr == lastPatchLine) {
147
					   fw.write(patchLine);
148
				   }
149
				   else if(line_ctr == lastPatchMacroLine) {
150
					   fw.write(patchMacroLine);
151
				   }
152
				}
153
			}
154
155
			// if there was not a "%changelog" section, make one
156
			if (!found_changelog && patch != null) { //$NON-NLS-1$
157
				fw.write("%changelog" + IRPMConstants.LINE_SEP + patch.getChangelogEntry()); //$NON-NLS-1$
158
			}
159
160
			fw.close();
161
		} catch (IOException e) {
162
			String throw_message = Messages.getString(
163
					"RPMCore.Error_trying_to_modify__132") + //$NON-NLS-1$
164
				getFile().getLocation().toOSString();
165
			IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1, throw_message,
166
					null);
167
			throw new CoreException(error);
168
		}
169
		
170
		newSpecFile.refreshLocal(IResource.DEPTH_INFINITE, null);
171
		getFile().delete(false, true, null);
172
		newSpecFile.move(getFile().getFullPath(), false, false, null);
173
		getFile().refreshLocal(IResource.DEPTH_INFINITE, null);
174
    }
175
    
176
    public IFile getFile() {
177
        return specFile;
178
    }
179
180
    public String getConfigureArgs() {
181
        return configureArgs;
182
    }
183
184
    public String getName() {
185
        return name;
186
    }
187
188
    public void setName(String name) {
189
        this.name = name;
190
    }
191
192
    public String getVersion() {
193
        return version;
194
    }
195
196
    public void setVersion(String version) {
197
        this.version = version;
198
    }
199
200
    public String getRelease() {
201
        return release;
202
    }
203
204
    public void setRelease(String release) {
205
        this.release = release;
206
    }
207
}
(-)src/org/eclipse/cdt/rpm/core/internal/SpecFileParser.java (+657 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.internal;
8
9
import java.io.File;
10
import java.io.FileReader;
11
import java.io.IOException;
12
import java.io.StreamTokenizer;
13
import java.util.ArrayList;
14
15
import org.eclipse.cdt.rpm.core.IRPMConstants;
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Status;
20
21
/**
22
 * A spec file parser.
23
 *
24
 */
25
public class SpecFileParser {
26
27
	private int lastSourceLine = 0;
28
	private int lastPatchLine = 0;
29
	private int setupLine = 0;
30
	private int lastPatchMacroLine = 0;
31
    private int numPatches = 0;
32
    
33
    private IFile specFile;
34
    private String configureArgs;
35
    private String name;
36
    private String version;
37
    private String release;
38
    
39
	/**
40
	 * Constructs a new parser.
41
	 * @param specFile a handle to the workspace spec file
42
	 */
43
    public SpecFileParser(IFile specFile) {
44
        this.specFile = specFile;
45
    }
46
    
47
	/**
48
	 * Parses the spec file.
49
	 * @throws CoreException if parsing fails
50
	 */
51
    public void parse() throws CoreException {
52
        /* The following logic determines where in the spec file the "Patchx:" and
53
         * %patchx -p1" lines will need to be added to accomodate the patch we
54
         * are fixing to generate.  If this is the first patch to ever be added to this
55
         * source RPM then the "Patchx: statement will have to be added after the
56
         * last "Sourcex:" statement and the "%patch -p1" statement will need to be
57
         * added after the "%setup" statement.  If this is not the first patch for this
58
         * source rpm, the "Patchx:" statement will be added after the last "Patchx:"
59
         * statement and the "%patchx -p1" will be added after the last "%patch -p1"
60
         * statement.  So, we keep track of where the line numbers for all of these
61
         * eventualities are so when we mod the file we will know where to insert
62
         * the necessary new lines.
63
         */
64
        ArrayList patchlist = new ArrayList();
65
        boolean found_source_line = false;
66
        boolean found_patch = false;
67
        boolean found_define = false;
68
        boolean found_define_name = false;
69
        boolean found_version = false;
70
        boolean found_release = false;
71
        int define_ctr = 0;
72
        int define_line_ctr = 0;
73
        int lines = 1;
74
75
        try {
76
            FileReader sp_file = new FileReader(specFile.getLocation().toOSString());
77
            StreamTokenizer st = new StreamTokenizer(sp_file);
78
79
            // Make sure numbers, colons and percent signs are considered valid
80
            st.wordChars('a','z');
81
            st.wordChars('A','Z');
82
            st.wordChars(':', ':');
83
            st.wordChars('0', '9');
84
            st.wordChars('%', '%');
85
            st.wordChars('{', '}');
86
            st.wordChars('-', '-');
87
            st.wordChars('/', '/');
88
            st.wordChars('=','=');
89
            st.wordChars('.','.');
90
            st.wordChars('_','_');
91
            st.eolIsSignificant(true);
92
            
93
            String new_word;
94
            boolean check_ifs = false;
95
            int if_ctr = 0;
96
            int token = st.nextToken();
97
            while (token != StreamTokenizer.TT_EOF) {
98
                token = st.nextToken();
99
100
                switch (token) {
101
                case StreamTokenizer.TT_EOL:
102
                  lines++;
103
                  break;
104
                case StreamTokenizer.TT_WORD:
105
                    new_word = st.sval;
106
                    
107
/* The following commented out logic addresses bugzilla 110452 where the version and
108
 * release numbers for spec files are stored in "%define" variables at the top of the file.  It
109
 * has been decided to put this change on hold until it can be determined how pervasive
110
 * the use of this practice is.  The code is incomplete for the time being and may be deleted
111
 * entirely in future releases.
112
 */                   
113
/*                  if (found_version) {
114
                        found_version = false;
115
                        if (new_word.startsWith("%{")) {  //$NON-NLS-1$
116
                            version_param = true;
117
                            define_info.add(0,new_word.substring(2,new_word.length()-1));
118
                        }
119
                        break;
120
                    }
121
                    
122
                    if (found_release) {
123
                        found_release = false;
124
                        if (new_word.startsWith("%{")) {  //$NON-NLS-1$
125
//                          release_param = true;
126
                            define_info.add(1,new_word.substring(2,new_word.length()-1));
127
                        }
128
                        break;
129
                    }  */
130
                    
131
                    // See if we have found the Version: line
132
                    if (new_word.equals("Version:")) {  //$NON-NLS-1$
133
                        found_version = true;
134
                        break;
135
                    }
136
                    
137
                    // See if we have found the Release: line
138
                    if (new_word.equals("Release:")) {  //$NON-NLS-1$
139
                        found_release = true;
140
                        break;
141
                    }
142
143
                        // Record where the last line of the form "Sourcex:" is
144
                        if (new_word.startsWith("Source") &  //$NON-NLS-1$
145
                             new_word.endsWith(":")) { //$NON-NLS-1$
146
                            lastSourceLine = lines;
147
                            found_source_line = true;
148
                            break;
149
                        }
150
151
                        /* Record where the last line of the form "Patchx:" is and count how many there were.
152
                         * Also, record the statement so when we generate our new "Patchx:" statement
153
                         * we don't duplicate a "Patch" statement.  This has to be done because a lot of
154
                         * spec files have "Patchx:" statements that are non-sequential
155
                         */
156
                        if (new_word.startsWith("Patch") &  //$NON-NLS-1$
157
                               new_word.endsWith(":")) { //$NON-NLS-1$
158
                            lastPatchLine = lines;
159
                            numPatches++;
160
                            patchlist.add(new_word);
161
162
                            break;
163
                        }
164
165
                        // Record where the "%setup line is
166
                        if (new_word.equals("%setup")) { //$NON-NLS-1$
167
168
                            // set the "check for if" constructs switch
169
                            check_ifs = true;
170
                            setupLine = lines;
171
172
                            break;
173
                        }
174
175
                        if (new_word.equals("%build")) { //$NON-NLS-1$
176
                            check_ifs = false;
177
                            
178
                            break;
179
                        }
180
181
                        // Record where the last (if any) "%patchx" line is
182
                        if (new_word.startsWith("%patch")) { //$NON-NLS-1$
183
                            lastPatchMacroLine = lines;
184
                            found_patch = true;
185
186
                            break;
187
                        }
188
                        
189
                        // See if we have found a %define statement, if so save it as some
190
                        // source RPMs use %define statements to "define" version/release #'s
191
/* See the comment several lines above regarding bugzilla 110452 as it also pertains to this code */
192
/*                      if (new_word.equals("%define")) {  //$NON-NLS-1$
193
                            found_define = true;
194
                            define_line_ptr[define_line_ctr] = lines;
195
                            define_line_ctr++;
196
                            
197
                            break;
198
                        }  */
199
                        
200
                    if (found_define) {
201
                        found_define = false;
202
//                      define_info.add(define_ctr,new_word);
203
                        define_ctr++;
204
                        found_define_name = true;
205
                        break;
206
                    }
207
                    
208
                    if (found_define_name) {
209
                        found_define_name = false;
210
//                      define_info.add(define_ctr,new_word);
211
                        define_ctr++;
212
                        break;
213
                    }
214
215
                        // Set the found %if/%ifarch/%ifnarch/%ifos/%ifnos switch
216
                        if (check_ifs) {
217
                            if (new_word.startsWith("%if")) { //$NON-NLS-1$
218
                                if_ctr++;
219
220
                                break;
221
                            }
222
223
                            // Reset the found %if/%ifarch switch
224
                            if (new_word.equals("%endif")) { //$NON-NLS-1$
225
226
                                if ((if_ctr > 0) & found_patch) {
227
                                    if_ctr--;
228
                                    lastPatchMacroLine = lines;
229
                                    found_patch = false;
230
231
                                    break;
232
                                }
233
                            }
234
235
                            break;
236
                        }
237
                        
238
                        break;
239
240
                default:
241
                    break;
242
                }
243
            }
244
245
            sp_file.close();
246
        } catch (IOException e) {
247
            e.printStackTrace();
248
            String throw_message = Messages.getString(
249
                    "RPMCore.Error_parsing_the_spec_file_in_the_project_--_157") + //$NON-NLS-1$
250
                    specFile.getLocation().toOSString();
251
            IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1, throw_message,
252
                    null);
253
            throw new CoreException(error);
254
        }
255
256
        if (numPatches > 1) {
257
            int patch_num = getUniquePatchId(patchlist, numPatches);
258
            numPatches = patch_num;
259
        }
260
        setConfigureArgs(parseConfigureArgs());
261
        parseNameVerRel();
262
    }
263
    
264
    /**
265
     * Method parseConfigureArgs.
266
     * This method takes a spec file path and parses it to see if there are any options
267
     * that need to be passed to the "configure" script when conmfiguring an RPM.
268
     * @param path_to_specfile - contains a string with a path to the spec file to be
269
     * searched to see if the "configure" command has any options to be applied
270
     * @return a string containing the options to pass to configure if any were found
271
     */
272
    private String parseConfigureArgs() throws CoreException {
273
        String path_to_specfile = specFile.getLocation().toOSString();
274
    
275
        boolean found_config = false;
276
        int lines = 0;
277
        int config_line = 0;
278
        String config_opts = ""; //$NON-NLS-1$
279
        
280
        try {
281
            FileReader sp_file = new FileReader(path_to_specfile);
282
            StreamTokenizer st = new StreamTokenizer(sp_file);
283
//            st.resetSyntax();
284
285
            // Make sure numbers, colons and percent signs are considered valid
286
            st.wordChars('a','z');
287
            st.wordChars('A','Z');
288
            st.wordChars(':', ':');
289
            st.wordChars('0', '9');
290
            st.wordChars('%', '%');
291
            st.wordChars('{', '}');
292
            st.wordChars('-', '-');
293
            st.wordChars('/','/');
294
            st.wordChars('=','=');
295
            st.wordChars('.','.');
296
            st.wordChars('_','_');
297
            st.eolIsSignificant(true);
298
            
299
            String new_word;
300
            int if_ctr = 0;
301
            int token = st.nextToken();
302
            while (token != StreamTokenizer.TT_EOF) {
303
                token = st.nextToken();
304
305
                switch (token) {
306
                case StreamTokenizer.TT_EOL:
307
                  lines++;  
308
                  break;
309
                case StreamTokenizer.TT_WORD:
310
                    new_word = st.sval;
311
                    // System.out.println("---- " + new_word + line_sep + "   line no = " + st.lineno());
312
                    
313
                    // If '%configure' was found, gather the options if there were any
314
                    if (found_config & config_line == lines) {
315
                        config_opts = config_opts + " --" + new_word; //$NON-NLS-1$
316
                        break;
317
                    }
318
                    if (found_config & !(config_line == lines)) {
319
                        found_config = false;
320
                        break;
321
                    }
322
323
                        // See if there is a %configure section
324
                        if (new_word.equals("%configure")) { //$NON-NLS-1$
325
                            found_config = true;
326
                            config_line = lines;
327
                            
328
                            break;
329
                        }
330
                }
331
            }
332
333
            sp_file.close();
334
        } catch (IOException e) {
335
            String throw_message = Messages.getString(
336
                    "RPMCore.Error_parsing_the_spec_file_in_the_project_--_157") + //$NON-NLS-1$
337
                    path_to_specfile;
338
            IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1, throw_message,
339
                    null);
340
            throw new CoreException(error);
341
        }
342
343
        if(!found_config) {
344
            return null;
345
        }
346
        return config_opts;
347
    }
348
    
349
    /**
350
     * Method parseNameVerRel interrogates a spec file for the name, version and release
351
     * of the RPM
352
     * @param path_to_specfile contains a string pointing to the specfile to interrogate
353
     * @return if successful, throw Exception if not
354
     */
355
356
    private void parseNameVerRel() throws CoreException {
357
        String path_to_specfile = specFile.getLocation().toOSString();
358
        ArrayList rpm_info = new ArrayList();
359
        ArrayList define_info = new ArrayList();
360
361
        // initialize version/release numbers to 0 in case none are found in the spec file
362
        rpm_info.add(0, "0"); //$NON-NLS-1$
363
        rpm_info.add(1, "0"); //$NON-NLS-1$
364
        rpm_info.add(2, " "); //$NON-NLS-1$
365
366
        boolean found_version = false;
367
        boolean found_release = false;
368
        boolean found_name = false;
369
        boolean found_ver_token = false;
370
        boolean found_rel_token = false;
371
        boolean found_name_token = false;
372
        boolean found_define = false;
373
        boolean found_define_name = false;
374
        int define_ctr = 0;
375
        
376
        File f = new File(path_to_specfile);
377
378
        if (!f.exists()) {
379
            String throw_message = "" + //$NON-NLS-1$
380
                path_to_specfile;
381
            IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 1, //$NON-NLS-1$
382
                    throw_message, null);
383
            throw new CoreException(error);
384
        }
385
386
        try {
387
            FileReader sp_file = new FileReader(path_to_specfile);
388
            StreamTokenizer st = new StreamTokenizer(sp_file);
389
390
            // Make sure numbers, colons and periods are considered valid characters
391
            st.resetSyntax();
392
            st.wordChars(':', ':');
393
            st.wordChars('0', '9');
394
            st.wordChars('.', '.');
395
            st.wordChars('A', 'z');
396
            st.wordChars('%','%');
397
            st.wordChars('{','{');
398
            st.wordChars('}','}');
399
400
            int token = 0;
401
            String new_word;
402
outer: 
403
            while (token != StreamTokenizer.TT_EOF) {
404
                token = st.nextToken();
405
406
                switch (token) {
407
                case StreamTokenizer.TT_WORD:
408
                    new_word = st.sval;
409
                    
410
                    if (found_define) {
411
                        found_define = false;
412
                        define_info.add(define_ctr,new_word);
413
                        define_ctr++;
414
                        found_define_name = true;
415
                        break;
416
                    }
417
                    
418
                    if (found_define_name) {
419
                        found_define_name = false;
420
                        define_info.add(define_ctr,new_word);
421
                        define_ctr++;
422
                        break;
423
                    }
424
                    
425
                    if (found_version & !found_ver_token) {
426
                        found_ver_token = true;
427
                        if (new_word.startsWith("%")) { //$NON-NLS-1$
428
                            try {
429
                                rpm_info.set(0,parseDefine(new_word, define_info));
430
                            } catch (Exception e) {
431
                                String throw_message = Messages.getString("RPMCore.Error_using_parseDefine_to_get_the_version_no._41") + //$NON-NLS-1$
432
                                  Messages.getString("RPMCore._from_the_spec_file_at___42") + path_to_specfile; //$NON-NLS-1$
433
                                IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 1, //$NON-NLS-1$
434
                                                    throw_message, null);
435
                                throw new CoreException(error);
436
                            }
437
                        } else {
438
                             rpm_info.set(0, new_word);
439
                        }
440
441
                        // System.out.println("Found version = " + new_word);
442
                        if (found_name_token & found_ver_token &
443
                                found_rel_token) {
444
                            break outer;
445
                        }
446
447
                        break;
448
                    }
449
450
                    if (found_release & !found_rel_token) {
451
                        found_rel_token = true;
452
                        if (new_word.startsWith("%")) {  //$NON-NLS-1$
453
                            try {
454
                                rpm_info.set(1,parseDefine(new_word, define_info));
455
                            } catch (Exception e) {
456
                            String throw_message = Messages.getString("RPMCore.Error_using_parseDefine_to_get_the_release_no._44") + //$NON-NLS-1$
457
                              Messages.getString("RPMCore._from_the_spec_file_at___45") + path_to_specfile; //$NON-NLS-1$
458
                            IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 1, //$NON-NLS-1$
459
                                                throw_message, null);
460
                            throw new CoreException(error);
461
                        }
462
                            break;
463
                        } else {
464
                             rpm_info.set(1, new_word);
465
                          }
466
467
                        // System.out.println("Found release = " + new_word);
468
                        if (found_name_token & found_ver_token &
469
                                found_rel_token) {
470
                            break outer;
471
                        }
472
473
                        break;
474
                    }
475
476
                    if (found_name & !found_name_token) {
477
                        found_name_token = true;
478
                        rpm_info.set(2, new_word);
479
480
                        // System.out.println("Found name = " + new_word);
481
                        if (found_name_token & found_ver_token &
482
                                found_rel_token) {
483
                            break outer;
484
                        }
485
486
                        break;
487
                    }
488
489
                    // See if this is a "Version:" tag
490
                    if (new_word.equals("Version:")) { //$NON-NLS-1$
491
                        found_version = true;
492
                        break;
493
                    }
494
495
                    // See if this is a "Release:" tag
496
                    if (new_word.equals("Release:")) { //$NON-NLS-1$
497
                        found_release = true;
498
                        break;
499
                    }
500
501
                    // See if this is a "Name:" tag
502
                    if (new_word.equals("Name:")) { //$NON-NLS-1$
503
                        found_name = true;
504
                        break;
505
                    }
506
                    
507
                    // See if this a "%define" statement
508
                    // the version and release can sometimes be in a define stmt
509
                    if (new_word.equals("%define")) {  //$NON-NLS-1$
510
                        found_define = true;
511
                        break;
512
                    }
513
514
                default:
515
                    break;
516
                }
517
            }
518
        } catch (IOException e) {
519
            String throw_message = Messages.getString(
520
                    "RPMCore.Error_parsing_the_spec_file_at") + //$NON-NLS-1$
521
                path_to_specfile;
522
            IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 1, //$NON-NLS-1$
523
                    throw_message, null);
524
            throw new CoreException(error);
525
        }
526
527
        /* Ugly: In rpm_info ArrayList:
528
         * [0] = Version
529
         * [1] = Release
530
         * [2] = Name
531
         */
532
        setVersion((String) rpm_info.get(0));
533
        setRelease((String) rpm_info.get(1));
534
        setName((String) rpm_info.get(2));
535
    }
536
    
537
    /**
538
      * Method parseDefine accepts a token from the parser and
539
      * searches the ArrayList passed to it for the value of the
540
      * token name.  This is crude at this point since this does not
541
      * happen very often.
542
      * @param token is a string containing the name found after the
543
      *               "Version:" or "Release:" fields of a spec file and the
544
      *               begining character is a "%"
545
      * @param token_value ia an ArrayList containing the names and
546
      *               values found in the "%define" statements usually found
547
      *              at the top of the spec file
548
      * @return a string with the correct version or release number
549
      *               else throw a CoreException
550
      */
551
    private String parseDefine(String token, ArrayList token_value) 
552
        throws CoreException {
553
          // See if there in anything in the ArrayList
554
          if (token_value.isEmpty()) {
555
              String throw_message = Messages.getString("RPMCore.No___%defines___were_found_in_the_spec_file_38"); //$NON-NLS-1$
556
              IStatus error = new Status(IStatus.ERROR, Messages.getString("RPMCore.Error_1"), 1, //$NON-NLS-1$
557
                                  throw_message, null);
558
              throw new CoreException(error);
559
          }
560
          // A token usually looks this: %{name}
561
          String token_name = token.substring(2,token.length()-1);
562
          int i = token_value.indexOf(token_name);
563
          return (String) token_value.get(i+1);
564
    }
565
    
566
    private int getUniquePatchId(ArrayList patchlist, int patch_ctr) {
567
        int patch_array_size = patchlist.size();
568
        String num_string;
569
        int patch_num;
570
        String last_patch = (String) patchlist.get(patch_array_size - 1);
571
        int indx = 5;
572
573
        while (last_patch.charAt(indx) != ':') {
574
            indx++;
575
        }
576
577
        // Allow for the fact that there could only be one patch statement of the
578
        // form "Patch:", that is, there is no number
579
        if (indx == 5) {
580
            return 0;
581
        }
582
583
        String num = last_patch.substring(5, indx);
584
585
        try {
586
            patch_num = Integer.parseInt(num, 10);
587
        } catch (NumberFormatException e) {
588
            return -1;
589
        }
590
591
        return patch_num + 1;
592
    }
593
    public String getConfigureArgs() {
594
        return configureArgs;
595
    }
596
    public String getName() {
597
        return name;
598
    }
599
    public String getRelease() {
600
        return release;
601
    }
602
    public String getVersion() {
603
        return version;
604
    }
605
    private void setConfigureArgs(String configureArgs) {
606
        this.configureArgs = configureArgs;
607
    }
608
    private void setName(String name) {
609
        this.name = name;
610
    }
611
    private void setRelease(String release) {
612
        this.release = release;
613
    }
614
    private void setVersion(String version) {
615
        this.version = version;
616
    }
617
618
	public int getLastPatchLine() {
619
		return lastPatchLine;
620
	}
621
622
	private void setLastPatchLine(int lastPatchLine) {
623
		this.lastPatchLine = lastPatchLine;
624
	}
625
626
	public int getLastPatchMacroLine() {
627
		return lastPatchMacroLine;
628
	}
629
630
	private void setLastPatchMacroLine(int lastPatchMacroLine) {
631
		this.lastPatchMacroLine = lastPatchMacroLine;
632
	}
633
634
	public int getLastSourceLine() {
635
		return lastSourceLine;
636
	}
637
638
	private void setLastSourceLine(int lastSourceLine) {
639
		this.lastSourceLine = lastSourceLine;
640
	}
641
642
	public int getNumPatches() {
643
		return numPatches;
644
	}
645
646
	private void setNumPatches(int numPatches) {
647
		this.numPatches = numPatches;
648
	}
649
650
	public int getSetupLine() {
651
		return setupLine;
652
	}
653
654
	private void setSetupLine(int setupLine) {
655
		this.setupLine = setupLine;
656
	}
657
}
(-)src/org/eclipse/cdt/rpm/core/internal/rpm_strings.properties (+220 lines)
Added 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
9
RPMCore.Error=Error
10
RPMCore.Error_trying_to_copy__=Error trying to copy 
11
RPMCore._to__=\ to 
12
RPMCore.--executeRPMlinux_command__95=--executeRPMlinux_command:
13
RPMCore.Error_executing__97=Error executing 
14
RPMCore.Error_waiting_for__99=Error waiting for 
15
RPMCore._to_complete._100=\ to complete.
16
RPMCore.Command__102=Command 
17
RPMCore._was_interrupted._103=\ was interrupted.
18
RPMCore.The_patch_name__109=The patch name 
19
RPMCore._is_not_unique._110=\ is not unique.
20
RPMCore._nPlease_modify_the___Patch_tag___field_and_try_again._111=\nPlease modify the \'Patch tag\' field and try again.
21
RPMCore.Error_trying_to_parse_spec_file_113=Error trying to parse spec file\nMaybe a character encoding error?
22
RPMCore._nIs_there_a_spec_file_at___114=\nIs there a spec file at: 
23
RPMCore.Failed_to_open_the_output_spec_file_at__123=Failed to open the output spec file at 
24
RPMCore.Error_trying_to_modify__132=Error trying to modify 
25
RPMCore.Error_parsing_the_spec_file_in_the_project_--_157=Error parsing the spec file in the project --
26
RPMCore.Failed_to_find_a___install__or___clean____section_in_the__180=Failed to find a \'install: or \'clean:\' section in the 
27
RPMCore.project__s_M/makefile.__THIS_IS_REQUIRED_!_!_!_181=project\'s M/makefile.  THIS IS REQUIRED\!\!\!
28
RPMCore.I/O_error_processing/reading_the_M/makefile__183=I/O error processing/reading the M/makefile 
29
RPMCore.Failed_to_find_a_M/makefile_in_the_project.___THIS_IS_REQUIRED_!_!_!_185=Failed to find a M/makefile in the project.   THIS IS REQUIRED\!\!\!
30
RPMCore.Failed_to_create_RPM_directories,_check_file_permissions_in__195=Failed to create RPM directories, check file permissions in 
31
RPMCore.Failed_to_create_RPM_directories_in__203=Failed to create RPM directories in 
32
RPMCore._--_check_file_permissions._204=\ -- check file permissions.
33
RPMCore.Error_executing__208=Error executing 
34
RPMCore.command._nSomething_is_wrong_with_file_permissions._209=command.\nSomething is wrong with file permissions.
35
RPMCore.Problem_creating_the_.rpmrc_file.__Check_file_permissions_in__217=Problem creating the .rpmrc file.  Check file permissions in 
36
RPMCore.Problem_creating_the_.rpmmacros_file._nCheck_file_permissions_in__226=Problem creating the .rpmmacros file.\nCheck file permissions in 
37
RPMCore.Problem_creating_the_.rpmmacros_file._nCheck_file_permissions_in__228=Problem creating the .rpmmacros file.\nCheck file permissions in 
38
RPMCore.Problem_creating_the_rpm_spec_file._nCheck_file_permissions_in__247=Problem creating the rpm spec file.\nCheck file permissions in 
39
RPMCore.Problem_running_the___make___file_to_create_the_executables._nView_the_log_file_at__249=Problem running the \'make\' file to create the executables.\nView the log file at 
40
RPMCore.Problem_creating_the___make_install___shell_script_--___rpmbuild.sh__.___270=Problem creating the \'make install\' shell script -- \'rpmbuild.sh\'.  
41
RPMCore._nCheck_file_permissions_in__271=\nCheck file permissions in 
42
RPMCore.Problem_running_the___make_install___shell_script_--__273=Problem running the \'make install\' shell script -- 
43
RPMCore._nThere_may_be_a_problem_in_the_M/makefile._274=\nThere may be a problem in the M/makefile.
44
RPMCore.No_files_were_found_under_build_root_--__276=No files were found under build root -- 
45
RPMCore._n_--_Problem_with_the___install____section_of_the_spec_file__277=\n -- Problem with the \'install:\' section of the spec file?
46
RPMCore.Problem_creating_spec_file.__Check_permissions_in__324=Problem creating spec file.  Check permissions in 
47
RPMCore.Problem_creating_spec_file.__Check_permissions_in__326=Problem creating spec file.  Check permissions in 
48
RPMCore.source_328=source
49
RPMCore.Error_executing___make_clean___in__329=Error executing \'make clean\' in 
50
RPMCore.Problem_creating_a_shell_script_--__342=Problem creating a shell script -- 
51
RPMCore._nThere_may_be_a_problem_in_the_M/makefile._343=\nThere may be a problem in the M/makefile.
52
RPMCore.Problem_running_this_command___346=Problem running this command: 
53
RPMCore._nCheck_permissions._347=\nCheck permissions.
54
RPMCore.Error_trying_to_create_shell_script_to_install__352=Error trying to create shell script to install 
55
RPMCore.the_source_rpm._nCheck_the_file_permissions_in__353=the source rpm.\nCheck the file permissions in 
56
RPMCore.Error_trying_to_install_the_source_with_this_command__355=Error trying to install the source with this command 
57
RPMCore._nCheck_the_log_at__356=\nCheck the log at 
58
RPMCore./SPECS/_359=/SPECS/
59
RPMCore.There_is_not_a__360=There is not a 
60
RPMCore._directory._nCheck_permissions_in_the_path_directories._361=\ directory.\nCheck permissions in the path directories.
61
RPMCore.An_error_in_the__364=An error in the 
62
RPMCore.directory._nEither_there_is_either_no_spec_file_or_more_than_one._365=directory.\nEither there is either no spec file or more than one.
63
RPMCore.There_are_either_no_directories_or_too_many_directories_under__369=There are either no directories or too many directories under 
64
RPMCore.An_error_occurred_trying_to_rename__373=An error occurred trying to rename  
65
RPMCore.Error_creating_shell_script_for_the__381=Error creating shell script for the 
66
RPMCore._nCheck_file_permissions._382=\nCheck file permissions.
67
RPMCore.Error_executing_the_command_to_build_prep_the_rpm_-__384=Error executing the command to build prep the rpm - 
68
RPMCore._nCheck_the_log_at__385=\nCheck the log at 
69
RPMCore.There_should_be_only_one_directory_under__391=There should be only one directory under 
70
RPMCore._at_this_point_392=\ at this point
71
RPMCore.This_file_already_exists___396=This file already exists: 
72
RPMCore.Error_trying_to_create_.srpminfo_file._401=Error trying to create .srpminfo file.
73
RPMCore.Problem_copying_source_rpm_info_file._nCheck_permissions_in__409=Problem copying source rpm info file.\nCheck permissions in 
74
RPMCore.Problem_copying_source_rpm_info_file._nCheck_permissions_in__411=Problem copying source rpm info file.\nCheck permissions in 
75
RPMCore.Error_trying_to_copy_the_target_project_directory_tree_with_this_command_--__417=Error trying to copy the target project directory tree with this command -- 
76
RPMCore._nFile_permissions_problem__418=\nFile permissions problem?
77
RPMCore.Error_trying_to_check_for_Makefile_in__421=Error trying to check for Makefile in 
78
RPMCore.Error_--_the_M/makefile_does_not_have_either_an___install____or___clean_____423=Error -- the M/makefile does not have either an \'install:\' or \'clean:\' 
79
RPMCore.section._nLook_in_this_directory_____424=section.\nLook in this directory:   
80
RPMCore.Error_running___make_clean___in__426=Error running \'make clean\' in 
81
RPMCore.Error_either_creating_or_executing_the___make_clean___command_in__428=Error either creating or executing the \'make clean\' command in 
82
RPMCore.There_are_too_many_directories_in__432=There are too many directories in 
83
RPMCore.Error_trying_to_rename_directory_in__438=Error trying to rename directory in 
84
RPMCore.Permissions_problem__440=Permissions problem?
85
RPMCore.Error_trying_to_parse_spec_file_442=Error trying to parse spec file
86
RPMCore._nIs_there_a_spec_file_at___443=\nIs there a spec file at: 
87
RPMCore.Error_trying_to_create_a_tarball_of_the_source_using_this_command_--__454=Error trying to create a tarball of the source using this command -- 
88
RPMCore.A_problem_occurred_creating_the_rpmbuild_shell_script.___461=A problem occurred creating the rpmbuild shell script.  
89
RPMCore._nPlease_check_the_file_permissions_in_/var/tmp__462=\nPlease check the file permissions in /var/tmp 
90
RPMCore.A_problem_occurred_running_this_command.___464=A problem occurred running this command.  
91
RPMCore.__nPlease_review_the_log_at__465=\ \nPlease review the log at\nWindows->Show View->Other...->RPM Plugin Log File->RPM Plugin Log Viewer
92
RPMCore.There_should_be_only_one_directory_under__467=There should be only one directory under 
93
RPMCore.__nCheck_the_directories_there.__The_RPM_work_area_in_/var/tmp_will_be_preserved._468=\ \nCheck the directories there.  The RPM work area in /var/tmp will be preserved. 
94
RPMCore.Error_trying_to_delete__477=Error trying to delete 
95
RPMCore._nCheck_permissions._478=\nCheck permissions.
96
RPMCore.Error_deleting_resources.__Check_file_permissions_in__483=Error deleting resources.  Check file permissions in 
97
RPMCore.Problem_deleting_the_log_file_at__486=Problem deleting the log file at 
98
RPMCore.__Check_the_permissions._487=\ \ Check the permissions.
99
RPMCore.Error_deleting_files_in_deleteSRPMextrafiles_496=Error deleting files in deleteSRPMextrafiles
100
RPMCore.Error_deleting_files_in_deleteSRPMextrafiles_498=Error deleting files in deleteSRPMextrafiles
101
RPMCore.executeProjConfigure_500=executeProjConfigure
102
RPMCore./bin/chmod_-R_u+r__501=/bin/chmod -R u+r 
103
RPMCore./_502=/
104
RPMCore.Error_executing_the_command__503=Error executing the command 
105
RPMCore.__Check_permissions_of__504=\ \ Check permissions of 
106
RPMCore.Problem_creating_the___make_clean/distclean/maintainer-clean___shell_script_--__515=Problem creating the \'make clean/distclean/maintainer-clean\' shell script -- 
107
RPMCore._nThere_may_be_a_problem_in_the_M/makefile._516=\nThere may be a problem in the M/makefile.
108
RPMCore.Problem_running_the___make_install___shell_script_--__518=Problem running the \'make install\' shell script -- 
109
RPMCore._nThere_may_be_a_problem_in_the_M/makefile._519=\nThere may be a problem in the M/makefile.
110
RPMCore.Problem_deleting_extra_files_from_project_in_deleteSRPMextrafiles_521=Problem deleting extra files from project in deleteSRPMextrafiles
111
RPMCore.Problem_deleting_extra_files_in_the_project_in_deleteEclipseiles._523=Problem deleting extra files in the project in deleteEclipseiles.
112
RPMCore.There_should_only_be_two_directories_in__531=There should only be two directories in 
113
RPMCore.Error_executing_the_command__538=Error executing the command 
114
RPMCore.__Check_permissions_of__539=\ \ Check permissions of 
115
RPMCore.Error_in_the_Makefile_in__541=Error in the Makefile in 
116
RPMCore._nMake_sure_there_is_a_clean_/distclean_/realclean_section__542=\nMake sure there is a clean:/distclean:/realclean section:
117
RPMCore.Error_running_the___make_distclean/realclean/mainainer-clean____544=Error running the \'make distclean/realclean/maintainer-clean\' 
118
RPMCore.command_on_the_previous_source_RPM_545=command on the previous source RPM
119
RPMCore.Error_creating_shell_script_for_the__553=Error creating shell script for the 
120
RPMCore._nCheck_file_permissions._554=\nCheck file permissions.
121
RPMCore.Error_executing_the_command_to_create_the_patch_file_-__558=Error executing the command to create the patch file - 
122
RPMCore._nAre_you_sure_there_were_changes_made_to_the_project__559=\nAre you sure there were changes made to the project? 
123
RPMCore.rpm_spec_should_not_be_null_here_in__567=rpm_spec should not be null here in 
124
RPMCore.A_problem_occurred_creating_the_rpmbuild_shell_script.___571=A problem occurred creating the rpmbuild shell script.  
125
RPMCore._nPlease_check_the_file_permissions_in_/var/tmp__572=\nPlease check the file permissions in /var/tmp 
126
RPMCore.A_problem_occurred_running_this_command.___574=A problem occurred running this command.  
127
RPMCore._nPlease_review_the_log_at__575=\nPlease review the log at\nWindows->Show View->Other...->RPM Plugin Log File->RPM Plugin Log Viewer
128
RPMCore.There_are_too_many_directories_in__577=There are too many directories in 
129
RPMCore.Unable_to_delete_file__582=Unable to delete file 
130
RPMCore._nCheck_permissions_in_the_project._583=\nCheck permissions in the project.
131
RPMCore.Error_returned_from_firstSRPM_trying__588=Error returned from firstSRPM() trying 
132
RPMCore.to_copy_the_spec_file_from_the_work_area_to_the_project_589=to copy the spec file from the work area to the project
133
RPMCore.Error_trying_to_rename__591=Error trying to rename 
134
RPMCore.Error_trying_to_create_.srpminfo_file._594=Error trying to create .srpminfo file.
135
RPMCore.Error_trying_to_copy_spec_file_from_work__598=Error trying to copy spec file from work 
136
RPMCore.area_to_Eclipse_project_directory_599=area to Eclipse project directory
137
RPMCore.Error_copying_directories_in__1=Error copying directories in 
138
RPMCore.Error_trying_to_copy_project_directory(_3=Error trying to copy project directory(
139
RPMCore.)_to_the_work_area(_4=) to the work area(
140
RPMCore.Error_trying_to_write_to__8=Error trying to write to 
141
RPMCore.Error_1=Error
142
RPMCore.Error_6=Error
143
RPMCore.Error_8=Error
144
RPMCore.Error_creating_directory___18=Error creating directory: 
145
RPMCore._nCheck_permissions__19=\nCheck permissions?
146
RPMCore.Error_copying_project_source_from__20=Error copying project source from 
147
RPMCore._to__21=\ to 
148
RPMCore.Error_creating_the_shell_script_to_untar_or__22=Error creating the shell script to untar or 
149
RPMCore.executing_the_shell_script_to_untar_the_source._Command____23=executing the shell script to untar the source. Command = 
150
RPMCore.Error_copying_source_from__24=Error copying source from 
151
RPMCore._to__25=\ to 
152
RPMCore.__26=\ 
153
RPMCore.0=Error generating checksum: 
154
RPMCore.Error_trying_to_copy_file__27=Error trying to copy file 
155
RPMCore._to__28=\ to 
156
RPMCore.Error_trying_to_set_up_rpm__29=Error trying to set up rpm 
157
RPMCore.in__30=in 
158
RPMCore._to_create_patches_31=\ to create patches
159
RPMCore.Checksum___32=Checksum: 
160
RPMCore.Error_parsing_spec_file_at__33=Error parsing spec file at 
161
RPMCore.Error_either_creating_or_running_configure_script_34=Error either creating or running configure script
162
RPMCore.RPMCore._to__7_35=RPMCore._to__7
163
RPMCore.Error_36=Error
164
RPMCore.Error_37=Error
165
RPMCore.Error_39=Error
166
RPMCore.Error_40=Error
167
RPMCore.Error_47=Error
168
RPMCore.An_error_occurred_either_creating_the_shell_script_containing_2=An error occurred either creating the shell script containing 
169
RPMCore.this_command____3=this command:\n  
170
RPMCore._nor_trying_to_execute_it._nView_the_log_at___4=\nor trying to execute it.\nView the log at: 
171
RPMCore._for_more_details_5=\ for more details
172
RPMCore.Error_1=Error
173
RPMCore.There_is_not_a_.srpminfo_file_in__7=There is not a .srpminfo file in 
174
RPMCore.There_is_no_longer_a_source_RPM_at__86=There is no longer a source RPM at 
175
RPMCore.Error_getting_info_from__93=Error getting info from 
176
RPMCore.Error_during__191=Error during 
177
RPMCore._execution..error____192=\ execution..error = 
178
RPMCore.Error_trying_to_copy__6=Error trying to copy 
179
RPMCore._to__7=\ to 
180
RPMCore.Error_trying_to_write_to__8=Error trying to write to 
181
RPMCore.No___%defines___were_found_in_the_spec_file_38=No \'%defines\' were found in the spec file
182
RPMCore.Failed_to_find_a_spec_file_at=Failed to find a spec file at 
183
RPMCore.Error_using_parseDefine_to_get_the_version_no._41=Error using parseDefine to get the version no.
184
RPMCore._from_the_spec_file_at___42=\ from the spec file at: 
185
RPMCore.Error_using_parseDefine_to_get_the_release_no._44=Error using parseDefine to get the release no.
186
RPMCore._from_the_spec_file_at___45=\ from the spec file at: 
187
RPMCore.Error_parsing_the_spec_file_at=Error parsing the spec file at 
188
RPMCore.Error_creating_srpminfo_file_in_the_project._9=Error creating srpminfo file in the project.
189
RPMCore._nCheck_permissions_in__10=\nCheck permissions in 
190
RPMExportCore.Too_many_spec_files_in__4=Too many spec files in 
191
RPMExportCore.Error_trying_to_delete__5=Error trying to delete 
192
ImportSRPM.Error_occurred_during_the_source_install._n_1=Error occurred during the source install.\n
193
ImportSRPM.There_are_either_too_many_or_0_directories_under__2=There are either too many or 0 directories under 
194
ImportSRPM.Cannot_find_a_tarball_to_untar_in___3=Cannot find a tarball to untar in: 
195
LinuxShellCmds.Error_attempting_to_create___1=Error attempting to create: 
196
LinuxShellCmds.Cannot_copy_a_directory___2=Cannot copy a directory: 
197
LinuxShellCmds._to_a_file___3=\ to a file: 
198
LinuxShellCmds.Error_attempting_to_copy_source_from___4=Error attempting to copy source from: 
199
LinuxShellCmds._to__5=\ to 
200
LinuxShellCmds.1=Process  returned non-zero value:
201
LinuxShellCmds.2=Process output:\n
202
LinuxShellCmds.3=Process error:\n
203
LinuxShellCmds.4=Process  executed successfully
204
LinuxShellCmds.5=Process output:\n
205
LinuxShellCmds.6=Process error:\n
206
LinuxShellCmds.7=\n Error output from command:\n
207
LinuxShellCmds.9=Process  returned non-zero value:
208
LinuxShellCmds.10=Process output:\n
209
LinuxShellCmds.11=Process error:\n
210
LinuxShellCmds.12=Process  executed successfully
211
LinuxShellCmds.13=Process output:\n
212
LinuxShellCmds.14=Process error:\n
213
LinuxShellCmds.15=Error executing 
214
RPMCore._nThis_RPM_*must*_be_restored_before_exporting_can_occur._1=\nThis RPM *must* be restored before exporting can occur.
215
RPMCore.Error_creating__1=Error creating 
216
RPMCore._nCheck_permissions__2=\nCheck permissions?
217
RPMCore.spec_file_ambiguous=More than one file found in 
218
RPMCore.RPMProjectFactory.0=Error constructing spec file model
219
RPMCore.RPMProjectFactory.1=Error constructing source RPM model
220
RPMCore.RPMProject.prepareExport=The project is not an RPM project 
(-)src/org/eclipse/cdt/rpm/core/utils/Diff.java (+56 lines)
Added Link Here
1
/*
2
 * (c) 2005 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.utils;
9
10
import org.eclipse.cdt.rpm.core.IRPMConstants;
11
import org.eclipse.cdt.rpm.core.RPMCorePlugin;
12
import org.eclipse.cdt.rpm.core.utils.internal.ShellScript;
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.Preferences;
15
16
/**
17
 * A utility class for executing a diff.
18
 *
19
 */
20
public class Diff {
21
	
22
	private String diffCmd;
23
	
24
	/**
25
	 * Constructs a new object to run diff.
26
	 * @param baseDir the absolute path of the directory to run the diff in
27
	 * @param oldPath the path containing old resources to use in the diff
28
	 * @param newPath the path containing new resources to use in the diff
29
	 * @param excludes an array of paths to resources to exclude from the diff
30
	 * @param outputFile the path of the file to redirect the diff output to
31
	 */
32
	public Diff(String baseDir, String oldPath, String newPath, String[] excludes, 
33
			String outputFile) {
34
		Preferences prefs = RPMCorePlugin.getDefault().getPluginPreferences();
35
		String pathToDiff = prefs.getString(IRPMConstants.DIFF_CMD);
36
		
37
		diffCmd = "cd " + baseDir + " && "; //$NON-NLS-1$ //$NON-NLS-2$
38
		diffCmd += pathToDiff + " -uNr "; //$NON-NLS-1$
39
		diffCmd += "--ignore-matching-lines=POT-Creation-Date --exclude=autom4te.cache "; //$NON-NLS-1$
40
		for(int i=0; i < excludes.length; i++) {
41
			diffCmd += "--exclude=" + excludes[i] + " "; //$NON-NLS-1$ //$NON-NLS-2$
42
		}
43
		diffCmd += oldPath + " " + newPath + " "; //$NON-NLS-1$ //$NON-NLS-2$
44
		diffCmd += "> " + outputFile;
45
	}
46
	
47
	/**
48
	 * Executes the diff operation.
49
	 * @throws CoreException if the operation fails
50
	 */
51
	public void exec() throws CoreException {
52
		ShellScript script = new ShellScript(diffCmd, 1);
53
		script.execNoLog();
54
	}
55
56
}
(-)src/org/eclipse/cdt/rpm/core/utils/RPM.java (+58 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.utils;
8
9
import org.eclipse.cdt.rpm.core.IRPMConfiguration;
10
import org.eclipse.cdt.rpm.core.IRPMConstants;
11
import org.eclipse.cdt.rpm.core.RPMCorePlugin;
12
import org.eclipse.cdt.rpm.core.utils.internal.ShellScript;
13
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.runtime.CoreException;
15
16
/**
17
 * A utility class for executing RPM commands.
18
 *
19
 */
20
public class RPM {
21
    
22
	private String macroDefines;
23
	private String rpmCmd;
24
	private IRPMConfiguration config;
25
	
26
	/**
27
	 * Constructs a new RPM object.
28
	 * @param config the RPM configuration to use
29
	 */
30
    public RPM(IRPMConfiguration config) {
31
		this.config = config;
32
		rpmCmd = RPMCorePlugin.getDefault().getPluginPreferences().getString(IRPMConstants.RPM_CMD) + 
33
			" -v "; //$NON-NLS-1$
34
		macroDefines = " --define '_sourcedir " + //$NON-NLS-1$
35
			config.getSourcesFolder().getLocation().toOSString() + "' "; //$NON-NLS-1$
36
		macroDefines += "--define '_srcrpmdir " + //$NON-NLS-1$
37
			config.getSrpmsFolder().getLocation().toOSString() + "' "; //$NON-NLS-1$
38
		macroDefines += "--define '_builddir " + //$NON-NLS-1$
39
			config.getBuildFolder().getLocation().toOSString() + "' "; //$NON-NLS-1$
40
		macroDefines += "--define '_rpmdir " + //$NON-NLS-1$
41
			config.getRpmsFolder().getLocation().toOSString() + "' "; //$NON-NLS-1$
42
		macroDefines += "--define '_specdir " + //$NON-NLS-1$
43
			config.getSpecsFolder().getLocation().toOSString() + "' "; //$NON-NLS-1$
44
    }
45
    
46
	/**
47
	 * Installs a given source RPM 
48
	 * @param sourceRPM
49
	 * @throws CoreException
50
	 */
51
    public void install(IFile sourceRPM) throws CoreException {
52
        String command = rpmCmd;
53
		command += macroDefines;
54
        command += " -i " + sourceRPM.getLocation().toOSString(); //$NON-NLS-1$
55
        ShellScript script = new ShellScript(command, 0);
56
		script.exec();
57
    }
58
}
(-)src/org/eclipse/cdt/rpm/core/utils/RPMBuild.java (+113 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.utils;
8
9
import org.eclipse.cdt.rpm.core.IRPMConfiguration;
10
import org.eclipse.cdt.rpm.core.IRPMConstants;
11
import org.eclipse.cdt.rpm.core.RPMCorePlugin;
12
import org.eclipse.cdt.rpm.core.utils.internal.ShellScript;
13
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.runtime.CoreException;
15
16
/**
17
 * A utility class for executing rpmbuild commands.
18
 *
19
 */
20
public class RPMBuild {
21
    
22
    private IRPMConfiguration config;
23
	
24
	private String macroDefines;
25
	
26
	private String rpmBuildCmd;
27
    
28
	/**
29
	 * Constructs a new object.
30
	 * @param config the RPM configuration to use
31
	 */
32
    public RPMBuild(IRPMConfiguration config) {
33
        this.config = config;
34
		rpmBuildCmd = 
35
			RPMCorePlugin.getDefault().getPluginPreferences().getString(IRPMConstants.RPMBUILD_CMD) + 
36
			" -v "; //$NON-NLS-1$
37
		macroDefines = " --define '_sourcedir " + 
38
    			config.getSourcesFolder().getLocation().toOSString() + "' "; //$NON-NLS-1$
39
		macroDefines += "--define '_srcrpmdir " + //$NON-NLS-1$
40
			config.getSrpmsFolder().getLocation().toOSString() + "' "; //$NON-NLS-1$
41
		macroDefines += "--define '_builddir " + //$NON-NLS-1$
42
			config.getBuildFolder().getLocation().toOSString() + "' "; //$NON-NLS-1$
43
		macroDefines += "--define '_rpmdir " + //$NON-NLS-1$
44
			config.getRpmsFolder().getLocation().toOSString() + "' "; //$NON-NLS-1$
45
		macroDefines += "--define '_specdir " + //$NON-NLS-1$
46
			config.getSpecsFolder().getLocation().toOSString() + "' "; //$NON-NLS-1$
47
    }
48
    
49
	/**
50
	 * Prepares the sources for a given spec file.
51
	 * @param specFile the spec file
52
	 * @throws CoreException if the operation fails
53
	 */
54
    public void buildPrep(IFile specFile) throws CoreException {
55
        String command = rpmBuildCmd;
56
        command += macroDefines;
57
        command += " -bp " + specFile.getLocation().toOSString(); //$NON-NLS-1$
58
        ShellScript script = new ShellScript(command, 0);
59
		script.exec();
60
    }
61
	
62
	/**
63
	 * Builds a binary RPM for a given spec file.
64
	 * @param specFile the spec file
65
	 * @throws CoreException if the operation fails
66
	 */
67
	public void buildBinary(IFile specFile) throws CoreException {
68
		String command = rpmBuildCmd;
69
        command += macroDefines;
70
        command += " -bb " + specFile.getLocation().toOSString(); //$NON-NLS-1$
71
        ShellScript script = new ShellScript(command, 0);
72
		script.exec();
73
	}
74
	
75
	/**
76
	 * Rebuilds a binary RPM from a given source RPM.
77
	 * @param sourceRPM the source RPM
78
	 * @throws CoreException if the operation fails
79
	 */
80
    public void rebuild(IFile sourceRPM) throws CoreException {
81
        String command = rpmBuildCmd;
82
        command += macroDefines;
83
        command += " --rebuild " + sourceRPM.getLocation().toOSString(); //$NON-NLS-1$
84
        ShellScript script = new ShellScript(command, 0);
85
		script.exec();
86
    }
87
	
88
	/**
89
	 * Builds both a binary and source RPM for a given spec file.
90
	 * @param specFile the spec file
91
	 * @throws CoreException if the operation fails
92
	 */
93
    public void buildAll(IFile specFile) throws CoreException {
94
        String command = rpmBuildCmd;
95
        command += macroDefines;
96
        command += " -ba " + specFile.getLocation().toOSString(); //$NON-NLS-1$
97
        ShellScript script = new ShellScript(command, 0);
98
		script.exec();
99
    }
100
	
101
	/**
102
	 * Builds a source RPM for a given spec file.
103
	 * @param specFile the spec file
104
	 * @throws CoreException if the operation fails
105
	 */
106
    public void buildSource(IFile specFile) throws CoreException {
107
        String command = rpmBuildCmd;
108
        command += macroDefines;
109
        command += " -bs " + specFile.getLocation().toOSString(); //$NON-NLS-1$
110
        ShellScript script = new ShellScript(command, 0);
111
		script.exec();
112
    }
113
}
(-)src/org/eclipse/cdt/rpm/core/utils/internal/Command.java (+72 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.utils.internal;
8
9
import org.eclipse.cdt.rpm.core.IRPMConstants;
10
import org.eclipse.cdt.rpm.core.internal.Messages;
11
import org.eclipse.core.runtime.CoreException;
12
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.core.runtime.Status;
14
15
/**
16
 * A utility class for executing commands using @link java.lang.Runtime.exec.
17
 *
18
 */
19
public class Command {
20
	
21
    /**
22
     * Method exec.
23
     * This method executes a Linux command passed to it from other methods.  It executes
24
     * the command, reads the output from the command and passes back a status.  This method
25
     * is used when several output lines is expected from a command.  If one line or less is
26
     * expected and the developer wants the output of the command, use the getInfo method.
27
     * @param command - a string containing a Linux command
28
     * @param successCode - what the successful status value from the command should be (normally 0)
29
     * @return - throws a CoreException if an error is encountered
30
     */
31
    /****************************************************************************/
32
    public static void exec(String command, int successCode) throws CoreException {
33
        Runtime r = Runtime.getRuntime();
34
        Process p = null;
35
        int returnCode;
36
        String line = ""; //$NON-NLS-1$
37
        String line2 = ""; //$NON-NLS-1$
38
        // prepare buffers for process output and error streams
39
        StringBuffer err = new StringBuffer();
40
        StringBuffer out = new StringBuffer();
41
42
        try {
43
			p = r.exec((String) command);
44
            // create thread for reading inputStream (process' stdout)
45
            StreamReaderThread outThread = new StreamReaderThread(p
46
                    .getInputStream(), out);
47
            // create thread for reading errorStream (process' stderr)
48
            StreamReaderThread errThread = new StreamReaderThread(p
49
                    .getErrorStream(), err);
50
            // start both threads
51
            outThread.start();
52
            errThread.start();
53
54
            //wait for process to end
55
			returnCode = p.waitFor();
56
            //finish reading whatever's left in the buffers
57
            outThread.join();
58
            errThread.join();
59
			
60
			if(returnCode != successCode) {
61
				throw new Exception();
62
			}
63
        } catch (Exception e) {
64
            String throw_message = Messages
65
                    .getString("RPMCore.Error_executing__97") + command + //$NON-NLS-1$
66
                    Messages.getString("LinuxShellCmds.7") + err.toString(); //$NON-NLS-1$
67
            IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1, throw_message,
68
                    null);
69
            throw new CoreException(error);
70
        }
71
    }
72
}
(-)src/org/eclipse/cdt/rpm/core/utils/internal/ShellScript.java (+79 lines)
Added Link Here
1
/*
2
 * (c) 2005 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.utils.internal;
9
10
import java.io.BufferedOutputStream;
11
import java.io.File;
12
import java.io.FileOutputStream;
13
import java.io.IOException;
14
15
import org.eclipse.cdt.rpm.core.IRPMConstants;
16
import org.eclipse.cdt.rpm.core.RPMCorePlugin;
17
import org.eclipse.cdt.rpm.core.internal.Messages;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.Status;
21
22
/**
23
 * A utility class for constructing and executing shell scripts on the system.
24
 *
25
 */
26
public class ShellScript {
27
	
28
	private File script;
29
	private String scriptContents;
30
	private int successCode;
31
	
32
	/**
33
	 * Constructs a new shell script object.
34
	 * @param command the command to execute
35
	 * @param successCode the return code that indicated command execution was successful
36
	 */
37
	public ShellScript(String command, int successCode)  {
38
		scriptContents = "#!/bin/sh" + IRPMConstants.LINE_SEP + command; //$NON-NLS-1$
39
		this.successCode = successCode;
40
	}
41
42
	/**
43
	 * Executes the shell script without logging standard output.
44
	 * @throws CoreException if the operation fails
45
	 */
46
	public void execNoLog() throws CoreException {
47
		byte[] buf = scriptContents.getBytes();
48
		File file = null;
49
		try {
50
			file = RPMCorePlugin.getDefault().getShellScriptFile();
51
			BufferedOutputStream os = 
52
				new BufferedOutputStream(new FileOutputStream(file));
53
			for(int i = 0; i < buf.length; i++) {
54
				os.write(buf[i]);
55
		}
56
		os.close();
57
		} catch(IOException e) {
58
			String throw_message = Messages.getString("RPMCore.Error_trying_to_write_to__8") + //$NON-NLS-1$
59
			  file.getAbsolutePath();
60
			IStatus error = new Status(IStatus.ERROR, IRPMConstants.ERROR, 1,
61
					throw_message, null);
62
			throw new CoreException(error);
63
		}
64
        	script = file;
65
		Command.exec("chmod +x " + script.getAbsolutePath(), 0); //$NON-NLS-1$
66
        	Command.exec("sh " + script.getAbsolutePath(), successCode); //$NON-NLS-1$
67
	}
68
	
69
	/**
70
	 * Executes the shell script and logs standard output to the log file.
71
	 * @throws CoreException if the operation fails
72
	 */
73
	public void exec() throws CoreException {
74
		scriptContents += " >> " + 
75
			RPMCorePlugin.getDefault().getExternalLogFile().getAbsolutePath(); //$NON-NLS-1$
76
		execNoLog();
77
	}
78
	
79
}
(-)src/org/eclipse/cdt/rpm/core/utils/internal/StreamReaderThread.java (+38 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.utils.internal;
8
9
import java.io.InputStreamReader;
10
import java.io.InputStream;
11
12
/**
13
 * Thread for reading input and output streams
14
 */
15
public class StreamReaderThread extends Thread
16
{
17
    StringBuffer mOut;
18
    InputStreamReader mIn;
19
    
20
    public StreamReaderThread(InputStream in, StringBuffer out)
21
    {
22
    mOut=out;
23
    mIn=new InputStreamReader(in);
24
    }
25
    
26
    public void run()
27
    {
28
    int ch;
29
    try {
30
        while(-1 != (ch=mIn.read()))
31
            mOut.append((char)ch);
32
        }
33
    catch (Exception e)
34
        {
35
        mOut.append("\nRead error:"+e.getMessage());
36
        }
37
    }
38
}

Return to bug 82195