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 15-36
Link Here
|
15 |
*/ |
15 |
*/ |
16 |
package org.eclipse.cdt.rpm.ui; |
16 |
package org.eclipse.cdt.rpm.ui; |
17 |
|
17 |
|
18 |
import org.eclipse.cdt.rpm.core.*; |
18 |
import java.util.Iterator; |
19 |
|
19 |
|
20 |
import org.eclipse.cdt.core.CProjectNature; |
20 |
import org.eclipse.cdt.rpm.core.IRPMProject; |
|
|
21 |
import org.eclipse.cdt.rpm.core.RPMProjectFactory; |
22 |
import org.eclipse.cdt.rpm.core.RPMProjectNature; |
23 |
import org.eclipse.cdt.rpm.ui.util.ExceptionHandler; |
24 |
import org.eclipse.core.resources.IFile; |
21 |
import org.eclipse.core.resources.IProject; |
25 |
import org.eclipse.core.resources.IProject; |
22 |
import org.eclipse.core.resources.IProjectNature; |
|
|
23 |
import org.eclipse.core.resources.IResource; |
26 |
import org.eclipse.core.resources.IResource; |
24 |
import org.eclipse.core.resources.IWorkspaceRoot; |
27 |
import org.eclipse.core.resources.IWorkspaceRoot; |
25 |
import org.eclipse.core.resources.ResourcesPlugin; |
28 |
import org.eclipse.core.resources.ResourcesPlugin; |
26 |
import org.eclipse.core.runtime.CoreException; |
29 |
import org.eclipse.core.runtime.CoreException; |
27 |
import org.eclipse.core.runtime.IPath; |
30 |
import org.eclipse.core.runtime.IPath; |
28 |
import org.eclipse.core.runtime.MultiStatus; |
31 |
import org.eclipse.core.runtime.Path; |
29 |
|
|
|
30 |
import org.eclipse.jface.dialogs.ErrorDialog; |
31 |
import org.eclipse.jface.viewers.IStructuredSelection; |
32 |
import org.eclipse.jface.viewers.IStructuredSelection; |
32 |
import org.eclipse.jface.wizard.WizardPage; |
33 |
import org.eclipse.jface.wizard.WizardPage; |
33 |
|
|
|
34 |
import org.eclipse.swt.SWT; |
34 |
import org.eclipse.swt.SWT; |
35 |
import org.eclipse.swt.events.KeyEvent; |
35 |
import org.eclipse.swt.events.KeyEvent; |
36 |
import org.eclipse.swt.events.KeyListener; |
36 |
import org.eclipse.swt.events.KeyListener; |
Lines 56-96
Link Here
|
56 |
import org.eclipse.swt.widgets.Listener; |
56 |
import org.eclipse.swt.widgets.Listener; |
57 |
import org.eclipse.swt.widgets.Text; |
57 |
import org.eclipse.swt.widgets.Text; |
58 |
|
58 |
|
59 |
import java.io.FileNotFoundException; |
|
|
60 |
import java.lang.reflect.InvocationTargetException; |
61 |
|
62 |
import java.util.ArrayList; |
63 |
import java.util.Iterator; |
64 |
|
65 |
|
59 |
|
66 |
/** |
60 |
/** |
67 |
* @author pmuldoon |
|
|
68 |
* |
61 |
* |
69 |
* RPMExportPage. Called by RPMExportWizard. Class can not be subclassed |
62 |
* RPMExportPage. Called by RPMExportWizard. Class can not be subclassed |
70 |
*extends WizardPage for the RPM export wizard, implements Listener |
63 |
*extends WizardPage for the RPM export wizard, implements Listener |
71 |
* |
64 |
* |
72 |
*/ |
65 |
*/ |
73 |
public class RPMExportPage extends WizardPage implements Listener { |
66 |
public class RPMExportPage extends WizardPage implements Listener { |
74 |
private RPMExportOperation rpmExport; |
|
|
75 |
private RPMCore rpmExportCore; |
76 |
|
77 |
// Checkbox Buttons |
67 |
// Checkbox Buttons |
78 |
|
|
|
79 |
private Button generatePatch; |
68 |
private Button generatePatch; |
80 |
private Button exportBinary; |
69 |
private Button exportBinary; |
81 |
private Button exportSource; |
70 |
private Button exportSource; |
|
|
71 |
|
72 |
// Version and release fields |
82 |
private Text rpmVersion; |
73 |
private Text rpmVersion; |
83 |
private Text rpmRelease; |
74 |
private Text rpmRelease; |
|
|
75 |
|
76 |
// The current selection |
84 |
private IStructuredSelection selection; |
77 |
private IStructuredSelection selection; |
85 |
|
78 |
|
86 |
//Composite Project Listbox control |
79 |
//Composite Project Listbox control |
87 |
private List projectList; |
80 |
private List projectList; |
|
|
81 |
|
82 |
//Spec file combo box |
88 |
private Combo specFileCombo; |
83 |
private Combo specFileCombo; |
89 |
private boolean patchNeeded = false; |
84 |
|
|
|
85 |
//Patch grid |
90 |
private Group patchNeedHintGrid; |
86 |
private Group patchNeedHintGrid; |
91 |
private static String path_to_specfile; |
87 |
|
92 |
static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ |
88 |
//The currently selected RPM project |
93 |
static final String line_sep = System.getProperty("line.separator"); //$NON-NLS-1$ |
89 |
private IRPMProject rpmProject; |
|
|
90 |
|
91 |
//Is a patch needed? |
92 |
private boolean patchNeeded = false; |
94 |
|
93 |
|
95 |
public RPMExportPage(IStructuredSelection currentSelection) { |
94 |
public RPMExportPage(IStructuredSelection currentSelection) { |
96 |
super(Messages.getString("RPMExportPage.Export_SRPM"), //$NON-NLS-1$ |
95 |
super(Messages.getString("RPMExportPage.Export_SRPM"), //$NON-NLS-1$ |
Lines 99-252
Link Here
|
99 |
setPageComplete(true); |
98 |
setPageComplete(true); |
100 |
selection = currentSelection; |
99 |
selection = currentSelection; |
101 |
} |
100 |
} |
|
|
101 |
|
102 |
public IRPMProject getSelectedRPMProject() { |
103 |
return rpmProject; |
104 |
} |
105 |
|
106 |
public IFile getSelectedSpecFile() { |
107 |
Path newSpecFilePath = |
108 |
new Path(specFileCombo.getItem(specFileCombo.getSelectionIndex())); |
109 |
return rpmProject.getProject().getFile(newSpecFilePath); |
110 |
} |
111 |
|
112 |
public String getSelectedVersion() { |
113 |
return rpmVersion.getText(); |
114 |
} |
115 |
|
116 |
public String getSelectedRelease() { |
117 |
return rpmRelease.getText(); |
118 |
} |
102 |
|
119 |
|
103 |
/** |
120 |
public int getExportType() { |
104 |
* Method returnProject. |
121 |
int exportType = 0; |
105 |
* @return String - returned selected project |
122 |
if(exportBinary.getSelection() && exportSource.getSelection()) { |
106 |
* |
123 |
exportType = IRPMUIConstants.BUILD_ALL; |
107 |
* Returns a string from the selected project |
124 |
} else if(exportBinary.getSelection()) { |
108 |
* in the control list box. |
125 |
exportType = IRPMUIConstants.BUILD_BINARY; |
109 |
*/ |
126 |
} else if(exportSource.getSelection()) { |
110 |
public String returnProject() { |
127 |
exportType = IRPMUIConstants.BUILD_SOURCE; |
111 |
String projSelect; |
128 |
} |
|
|
129 |
return exportType; |
130 |
} |
131 |
|
132 |
private String getSelectedProjectName() { |
133 |
String projSelect = null; |
112 |
String[] projDetails = projectList.getSelection(); |
134 |
String[] projDetails = projectList.getSelection(); |
113 |
|
135 |
|
114 |
if (projDetails.length > 0) { |
136 |
if (projDetails.length > 0) { |
115 |
projSelect = projDetails[0]; |
137 |
projSelect = projDetails[0]; |
116 |
} else { |
|
|
117 |
projSelect = ""; //$NON-NLS-1$ |
118 |
} |
138 |
} |
119 |
|
|
|
120 |
return projSelect; |
139 |
return projSelect; |
121 |
} |
140 |
} |
122 |
|
141 |
|
123 |
/** |
142 |
private void setPatchNeeded(boolean patchDelta) { |
124 |
* Method returnProjectPath |
|
|
125 |
* @return returns the path of the currently selected project in |
126 |
* projectList |
127 |
*/ |
128 |
public String returnProjectPath() { |
129 |
String[] projectSelection = projectList.getSelection(); |
130 |
IProject projectDetail; |
131 |
|
132 |
// As we only allow a single selection in the listbox, and the listbox |
133 |
// always comes with the first element selected, we can assume |
134 |
// the first element in the returned array is valid. |
135 |
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); |
136 |
try { |
137 |
projectDetail = workspaceRoot.getProject(projectSelection[0]); |
138 |
} catch (Exception e) { |
139 |
return null; |
140 |
} |
141 |
|
142 |
return projectDetail.getLocation().toOSString(); |
143 |
} |
144 |
|
145 |
/** |
146 |
* Method setPatchModifier |
147 |
* @param patchDelta - sets whether patch is required in a project |
148 |
*/ |
149 |
private void setPatchModifier(boolean patchDelta) { |
150 |
patchNeeded = patchDelta; |
143 |
patchNeeded = patchDelta; |
151 |
} |
144 |
} |
152 |
|
145 |
|
153 |
/** |
146 |
private boolean isPatchNeeded() { |
154 |
* Method patchNeeded |
|
|
155 |
* @return boolean - is a patch needed? |
156 |
*/ |
157 |
public boolean patchNeeded() { |
158 |
return patchNeeded; |
147 |
return patchNeeded; |
159 |
} |
148 |
} |
160 |
|
149 |
|
161 |
/** |
150 |
/** |
162 |
* Method returnSpecFiles |
|
|
163 |
* |
164 |
* @param projname - Name of the project to mine for spec files |
165 |
* @return ArrayList - ArrayList of found spec files |
166 |
* |
167 |
* Method that mines a selected project for spec files |
168 |
* Will return an ArrayList of returned spec files |
169 |
* |
170 |
*/ |
171 |
public ArrayList returnSpecFiles(String givenProjectName) { |
172 |
IProject[] internalProjects; |
173 |
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); |
174 |
internalProjects = workspaceRoot.getProjects(); |
175 |
|
176 |
String projectName; |
177 |
ArrayList specFileList = new ArrayList(); |
178 |
|
179 |
for (int numberOfProjects = 0; numberOfProjects < internalProjects.length; numberOfProjects++) { |
180 |
projectName = internalProjects[numberOfProjects].getName(); |
181 |
|
182 |
if (projectName.equals(givenProjectName)) { |
183 |
try { |
184 |
final IResource[] projectResourceList = internalProjects[numberOfProjects].members(); |
185 |
|
186 |
for (int numberOfResources = 0; numberOfResources < projectResourceList.length; numberOfResources++) { |
187 |
String filenameExtension = projectResourceList[numberOfResources].getFileExtension(); |
188 |
|
189 |
if (filenameExtension != null) { |
190 |
if (filenameExtension.equals("spec")) { //$NON-NLS-1$ |
191 |
specFileList.add(projectResourceList[numberOfResources].getName().toString()); |
192 |
} |
193 |
} |
194 |
} |
195 |
} catch (CoreException e) { |
196 |
} |
197 |
} |
198 |
} |
199 |
|
200 |
return specFileList; |
201 |
} |
202 |
|
203 |
/** |
204 |
* Method hasMakefile. |
205 |
* @param givenProjectName - project name to check |
206 |
* @return boolean - true if project has makefile, false if not |
207 |
* |
208 |
* Returns boolean on whether the currently selected project |
209 |
* has a Makefile that is visible and can be sourced |
210 |
*/ |
211 |
public boolean hasMakefile(String givenProjectName) { |
212 |
IProject[] internalProjectList; |
213 |
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); |
214 |
internalProjectList = workspaceRoot.getProjects(); |
215 |
|
216 |
String projectName; |
217 |
IResource resourceList; |
218 |
|
219 |
for (int a = 0; a < internalProjectList.length; a++) { |
220 |
projectName = internalProjectList[a].getName(); |
221 |
|
222 |
if (projectName.equals(givenProjectName)) { |
223 |
resourceList = internalProjectList[a].findMember(Messages.getString( |
224 |
"RPMExportPage.Makefile_pc")); //$NON-NLS-1$ |
225 |
|
226 |
if (resourceList != null) { |
227 |
return true; |
228 |
} |
229 |
|
230 |
resourceList = internalProjectList[a].findMember(Messages.getString( |
231 |
"RPMExportPage.makefile_lc")); //$NON-NLS-1$ |
232 |
|
233 |
if (resourceList != null) { |
234 |
return true; |
235 |
} |
236 |
} |
237 |
} |
238 |
|
239 |
return false; |
240 |
} |
241 |
|
242 |
/** |
243 |
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite) |
151 |
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite) |
244 |
* |
152 |
* |
245 |
* Parent control. Creates the listbox, Destination box, and options box |
153 |
* Parent control. Creates the listbox, Destination box, and options box |
246 |
* |
154 |
* |
247 |
*/ |
155 |
*/ |
248 |
public void createControl(Composite parent) { |
156 |
public void createControl(Composite parent) { |
249 |
|
|
|
250 |
Composite composite = new Composite(parent, SWT.NULL); |
157 |
Composite composite = new Composite(parent, SWT.NULL); |
251 |
|
158 |
|
252 |
// Create a layout for the wizard page |
159 |
// Create a layout for the wizard page |
Lines 256-442
Link Here
|
256 |
|
163 |
|
257 |
// Create contols on the page |
164 |
// Create contols on the page |
258 |
createProjectBox(composite); |
165 |
createProjectBox(composite); |
259 |
createSpecFileField(composite); |
166 |
createSpecFileFields(composite); |
260 |
setSpecFileComboData(); |
|
|
261 |
createSpacer(composite); |
167 |
createSpacer(composite); |
262 |
createExportType(composite); |
168 |
createExportTypeControls(composite); |
263 |
setPatchHint(composite); |
169 |
createPatchHint(composite); |
|
|
170 |
|
171 |
// Fill in the fields |
172 |
setSpecFileComboData(); |
173 |
setVersionReleaseFields(); |
264 |
|
174 |
|
265 |
// Check if the project checksums are different |
175 |
// Check if the project has changed |
266 |
// and therefore the project needs a path |
176 |
// and therefore the project needs a patch |
267 |
if (compareCheckSum(returnProjectPath()).equals("patch")) //$NON-NLS-1$ |
177 |
boolean projectChanged = false; |
268 |
{ |
178 |
try { |
|
|
179 |
if(rpmProject != null) { |
180 |
projectChanged = rpmProject.isChanged(); |
181 |
} |
182 |
} catch(CoreException e) { |
183 |
ExceptionHandler.handle(e, getShell(), Messages.getString("ErrorDialog.title"), |
184 |
e.getMessage()); |
185 |
} |
186 |
if(projectChanged) { |
269 |
patchNeedHintGrid.setVisible(true); |
187 |
patchNeedHintGrid.setVisible(true); |
270 |
setPatchModifier(true); |
188 |
setPatchNeeded(true); |
271 |
setPageComplete(true); |
189 |
setPageComplete(true); |
272 |
} else { |
190 |
} else { |
273 |
setPatchModifier(false); |
191 |
setPatchNeeded(false); |
274 |
setPageComplete(false); |
192 |
setPageComplete(false); |
275 |
} |
193 |
} |
276 |
} |
194 |
} |
277 |
|
195 |
|
278 |
/** |
196 |
private void createExportTypeControls(Composite parent) { |
279 |
* Method compareCheckSum |
197 |
//Create a group for the control and set up the layout. |
280 |
* |
|
|
281 |
* @param givenProject - project to check |
282 |
* @return = match |
283 |
* @return = legacy |
284 |
* @return = patch |
285 |
* @return = error |
286 |
* |
287 |
* Returns one of the above status depending on project status |
288 |
* |
289 |
*/ |
290 |
public String compareCheckSum(String givenProject) { |
291 |
try { |
292 |
// Create an instance of the RPMExport class |
293 |
rpmExportCore = new RPMCore(); |
294 |
|
295 |
// Mine the .srpmInfo file if there is one |
296 |
if (rpmExportCore.firstSRPM(givenProject)) { |
297 |
return "legacy"; |
298 |
} |
299 |
ArrayList srpmProjectInfo = rpmExportCore.getSRPMexportinfo(givenProject); |
300 |
|
301 |
// If the generated checksum, and the one in the srpmInfo file are the same |
302 |
// then the project has not changed since last import and does not need a patch |
303 |
if (rpmExportCore.generateChecksum(givenProject, 0) == Long.parseLong( |
304 |
(String) srpmProjectInfo.get(6))) { |
305 |
setPatchModifier(false); |
306 |
|
307 |
return "match"; //$NON-NLS-1$ |
308 |
|
309 |
|
310 |
// If we cannot find an srpmInfo file, this is a legacy project |
311 |
} else if (Long.parseLong((String) srpmProjectInfo.get(6)) == -1) { |
312 |
setPatchModifier(false); |
313 |
|
314 |
return "legacy"; //$NON-NLS-1$ |
315 |
// Otherwise they don't match and we need to patch |
316 |
} else { |
317 |
setPatchModifier(true); |
318 |
|
319 |
return "patch"; //$NON-NLS-1$ |
320 |
} |
321 |
} catch (CoreException e) { |
322 |
return "error"; //$NON-NLS-1$ |
323 |
} |
324 |
} |
325 |
|
326 |
/** |
327 |
* Method checkPageComplete. |
328 |
* @return boolean |
329 |
* |
330 |
* Check if export rpm name is valid |
331 |
* Check if project has makefile |
332 |
* Check a valid project has been selected |
333 |
*/ |
334 |
public boolean checkPageComplete() { |
335 |
// Method invoked to check we have all the required data from the user |
336 |
// before we allow the wizard to execute. However they can cancel at |
337 |
// anytime. |
338 |
// Check the contents of the RPM destination filename |
339 |
// Needs work, least of all the variable name ;) |
340 |
// Check to ensure that the selected project has a makefile |
341 |
if (hasMakefile(returnProject()) == false) { |
342 |
setErrorMessage(Messages.getString( |
343 |
"RPMExportPage.project_does_not_have_Makefile")); //$NON-NLS-1$ |
344 |
|
345 |
return false; |
346 |
} |
347 |
|
348 |
// Check to ensure the select project is actually a project |
349 |
String projDetails = returnProject(); |
350 |
|
351 |
if (projDetails.equals(Messages.getString( |
352 |
"RPMExportPage.No_c/c++_projects_found")) == true) { //$NON-NLS-1$ |
353 |
setErrorMessage(Messages.getString( |
354 |
"RPMExportPage.Invald_project_specified")); //$NON-NLS-1$ |
355 |
|
356 |
return false; |
357 |
} |
358 |
|
359 |
// If all tests pass, then we are okay to go. |
360 |
return true; |
361 |
} |
362 |
|
363 |
/** |
364 |
* Method finish. Performs the actual work. |
365 |
* @return boolean |
366 |
* @throws CoreException |
367 |
* @throws CoreException |
368 |
*/ |
369 |
public boolean finish(String[] givenPatchData) throws CoreException { |
370 |
// Selected project location |
371 |
String projectLocation = null; |
372 |
|
373 |
// Check that we can finish the export operation |
374 |
if (checkPageComplete() == false) { |
375 |
return false; |
376 |
} |
377 |
|
378 |
// As we only allow a single selection in the listbox, and the listbox always |
379 |
// comes with the first element selected, we can assume the first element |
380 |
// in the returned array is valid. Need to add a try/catch group to check for |
381 |
// null though |
382 |
projectLocation = returnProjectPath(); |
383 |
|
384 |
String exportType = null; |
385 |
|
386 |
// Calculate the export source type |
387 |
// -ba = build all |
388 |
// -bs = build source |
389 |
// -bb = build binary |
390 |
if ((exportSource.getSelection() == true) && |
391 |
(exportBinary.getSelection() == true)) { |
392 |
exportType = "-ba"; //$NON-NLS-1$ |
393 |
} else if (exportSource.getSelection() == true) { |
394 |
exportType = "-bs"; //$NON-NLS-1$ |
395 |
} else if (exportBinary.getSelection() == true) { |
396 |
exportType = "-bb"; //$NON-NLS-1$ |
397 |
} |
398 |
|
399 |
// Create a new instance of rpmExportOperation build class |
400 |
try { |
401 |
rpmExport = new RPMExportOperation(returnProject(), |
402 |
projectLocation, specFileCombo.getText(), "", givenPatchData[0], //$NON-NLS-1$ |
403 |
givenPatchData[1] + line_sep + |
404 |
givenPatchData[2] + line_sep + line_sep, rpmVersion.getText(), |
405 |
rpmRelease.getText(), exportType, patchNeeded); |
406 |
} catch (Exception e) { |
407 |
setErrorMessage(e.toString()); |
408 |
return false; |
409 |
} |
410 |
|
411 |
// Run the export |
412 |
try { |
413 |
getContainer().run(true, true, rpmExport); |
414 |
} catch (InvocationTargetException e1) { |
415 |
setErrorMessage(e1.toString()); |
416 |
return false; |
417 |
} catch (InterruptedException e1) { |
418 |
setErrorMessage(e1.toString()); |
419 |
} |
420 |
|
421 |
MultiStatus status = rpmExport.getStatus(); |
422 |
|
423 |
if (!status.isOK()) { |
424 |
ErrorDialog.openError(getContainer().getShell(), |
425 |
Messages.getString( |
426 |
"RPMExportPage.Errors_encountered_importing_SRPM"), //$NON-NLS-1$ |
427 |
null, // no special message |
428 |
status); |
429 |
|
430 |
return false; |
431 |
} |
432 |
|
433 |
// Need to return some meaninful status. Should only return true if the wizard completed |
434 |
// successfully. |
435 |
return true; |
436 |
} |
437 |
|
438 |
private void createExportType(Composite parent) { //Create a group for the control and set up the layout. |
439 |
|
440 |
Group group = new Group(parent, SWT.NONE); |
198 |
Group group = new Group(parent, SWT.NONE); |
441 |
group.setLayout(new GridLayout()); |
199 |
group.setLayout(new GridLayout()); |
442 |
group.setText(Messages.getString("RPMExportPage.Composite_Export_Type")); //$NON-NLS-1$ |
200 |
group.setText(Messages.getString("RPMExportPage.Composite_Export_Type")); //$NON-NLS-1$ |
Lines 479-491
Link Here
|
479 |
* Create a list box and populate it with |
237 |
* Create a list box and populate it with |
480 |
* the list of current projects in the workspace |
238 |
* the list of current projects in the workspace |
481 |
*/ |
239 |
*/ |
482 |
protected void createProjectBox(Composite parent) { |
240 |
private void createProjectBox(Composite parent) { |
483 |
// Creates a control that enumerates all the projects in the current |
241 |
// Creates a control that enumerates all the projects in the current |
484 |
// Workspace and places them in a listbox. |
242 |
// Workspace and places them in a listbox. |
485 |
// Need to check what to do if the user chooses to export an RPM |
|
|
486 |
// when there are no current projects in the workspace. Right now |
487 |
// the other export wizard just open, with empty treeviews (?) |
488 |
// Declare an array of IProject; |
489 |
IProject[] internalProjectList; |
243 |
IProject[] internalProjectList; |
490 |
String Proj_Enum; |
244 |
String Proj_Enum; |
491 |
|
245 |
|
Lines 521-590
Link Here
|
521 |
|
275 |
|
522 |
if (internalProjectList.length < 1) { |
276 |
if (internalProjectList.length < 1) { |
523 |
projectList.add(Messages.getString( |
277 |
projectList.add(Messages.getString( |
524 |
"RPMPage.No_c/c++_projects_found_2")); //$NON-NLS-1$ |
278 |
"RPMPage.No_RPM_projects_found")); //$NON-NLS-1$ |
525 |
return; |
279 |
return; |
526 |
} |
280 |
} |
527 |
|
281 |
|
528 |
// Stuff the listbox with the text name of the projects |
|
|
529 |
// using the getName() method |
530 |
// Find the first selected project in the workspace |
282 |
// Find the first selected project in the workspace |
531 |
|
|
|
532 |
Iterator iter = selection.iterator(); |
283 |
Iterator iter = selection.iterator(); |
533 |
Object selectedObject= null; |
284 |
Object selectedObject= null; |
534 |
IProject selectedProject = null; |
285 |
IProject selectedProject = null; |
535 |
boolean isSelection = false; |
286 |
boolean isSelection = false; |
536 |
if (iter.hasNext()) |
287 |
if (iter.hasNext()) { |
537 |
{ |
|
|
538 |
selectedObject = iter.next(); |
288 |
selectedObject = iter.next(); |
539 |
if (selectedObject instanceof IResource) |
289 |
if (selectedObject instanceof IResource) { |
540 |
{ |
|
|
541 |
selectedProject = ((IResource) selectedObject).getProject(); |
290 |
selectedProject = ((IResource) selectedObject).getProject(); |
542 |
isSelection = true; |
291 |
isSelection = true; |
543 |
} |
292 |
} |
544 |
} |
293 |
} |
545 |
|
294 |
|
546 |
// Stuff the listbox with the text names of the projects |
295 |
// Stuff the listbox with the text names of the projects |
547 |
// using the getName() method and select the selected |
296 |
// Highlight the currently selected project in the workspace |
548 |
// project if available |
297 |
int selectedProjectIndex = 0; |
549 |
|
298 |
for (int a = 0; a < internalProjectList.length; a++) { |
550 |
|
|
|
551 |
for (int a = 0; a < internalProjectList.length; a++) |
552 |
{ |
553 |
|
554 |
try { |
299 |
try { |
555 |
IProjectNature cNature = internalProjectList[a].getNature(CProjectNature.C_NATURE_ID); |
300 |
if(internalProjectList[a].hasNature(RPMProjectNature.RPM_NATURE_ID)) { |
556 |
if (cNature!=null) |
|
|
557 |
projectList.add(internalProjectList[a].getName()); |
301 |
projectList.add(internalProjectList[a].getName()); |
558 |
if (isSelection && internalProjectList[a].equals(selectedProject)) |
302 |
if (isSelection && internalProjectList[a].equals(selectedProject)) { |
559 |
projectList.setSelection(a); |
303 |
selectedProjectIndex = a; |
560 |
} catch (CoreException e) { |
304 |
} |
561 |
|
305 |
} |
|
|
306 |
} catch(CoreException e) { |
307 |
ExceptionHandler.handle(e, getShell(), |
308 |
Messages.getString("ErrorDialog.title"), e.getMessage()); |
562 |
} |
309 |
} |
563 |
} |
310 |
} |
|
|
311 |
projectList.setSelection(selectedProjectIndex); |
312 |
try { |
313 |
rpmProject = RPMProjectFactory.getRPMProject(internalProjectList[selectedProjectIndex]); |
314 |
} catch(CoreException e) { |
315 |
ExceptionHandler.handle(e, getShell(), |
316 |
Messages.getString("ErrorDialog.title"), e.getMessage()); |
317 |
} |
564 |
|
318 |
|
565 |
if (!isSelection) |
319 |
// Add a listener to the project box |
566 |
projectList.setSelection(0);//if none is selected select first project |
|
|
567 |
|
568 |
// Add a listener to set the name in the location box as |
569 |
// it is selected in project box |
570 |
projectList.addListener(SWT.Selection, |
320 |
projectList.addListener(SWT.Selection, |
571 |
new Listener() { |
321 |
new Listener() { |
572 |
public void handleEvent(Event event) { |
322 |
public void handleEvent(Event event) { |
573 |
rpmVersion.setText(""); |
323 |
// Reset the RPM project |
574 |
rpmRelease.setText(""); |
324 |
int i = projectList.getSelectionIndex(); |
|
|
325 |
if(i != -1) { |
326 |
IProject project = workspaceRoot.getProject(projectList.getSelection()[0]); |
327 |
try { |
328 |
rpmProject = RPMProjectFactory.getRPMProject(project); |
329 |
if(rpmProject.isChanged()) { |
330 |
setPatchNeeded(true); |
331 |
patchNeedHintGrid.setVisible(true); |
332 |
setPageComplete(true); |
333 |
} else { |
334 |
setPatchNeeded(false); |
335 |
patchNeedHintGrid.setVisible(false); |
336 |
setPageComplete(false); |
337 |
} |
338 |
} catch(CoreException e) { |
339 |
ExceptionHandler.handle(e, getShell(), |
340 |
Messages.getString("ErrorDialog.title"), e.getMessage()); |
341 |
} |
342 |
} else { |
343 |
rpmProject = null; |
344 |
setPatchNeeded(false); |
345 |
patchNeedHintGrid.setVisible(false); |
346 |
setPageComplete(false); |
347 |
} |
575 |
setSpecFileComboData(); |
348 |
setSpecFileComboData(); |
576 |
if (compareCheckSum(returnProjectPath()).equals("patch")) //$NON-NLS-1$ |
349 |
setVersionReleaseFields(); |
577 |
{ |
350 |
} |
578 |
setPatchModifier(true); |
351 |
}); |
579 |
patchNeedHintGrid.setVisible(true); |
|
|
580 |
setPageComplete(true); |
581 |
} else { |
582 |
patchNeedHintGrid.setVisible(false); |
583 |
setPatchModifier(false); |
584 |
setPageComplete(false); |
585 |
} |
586 |
} |
587 |
}); |
588 |
} |
352 |
} |
589 |
|
353 |
|
590 |
/** |
354 |
/** |
Lines 596-611
Link Here
|
596 |
private void setSpecFileComboData() { |
360 |
private void setSpecFileComboData() { |
597 |
specFileCombo.clearSelection(); |
361 |
specFileCombo.clearSelection(); |
598 |
specFileCombo.removeAll(); |
362 |
specFileCombo.removeAll(); |
599 |
|
363 |
if(rpmProject != null) { |
600 |
final ArrayList specFileList = returnSpecFiles(returnProject()); |
364 |
String specFile = |
601 |
Iterator i = specFileList.iterator(); |
365 |
rpmProject.getSpecFile().getFile().getProjectRelativePath().toOSString(); |
602 |
|
366 |
specFileCombo.add(specFile); |
603 |
while (i.hasNext()) |
367 |
specFileCombo.setText(specFile); |
604 |
specFileCombo.add(i.next().toString()); |
|
|
605 |
|
606 |
if (specFileList.size() > 0) { |
607 |
specFileCombo.setText(specFileList.get(0).toString()); |
608 |
setVersionReleaseFields(); |
609 |
} |
368 |
} |
610 |
} |
369 |
} |
611 |
|
370 |
|
Lines 615-623
Link Here
|
615 |
* |
374 |
* |
616 |
* Creates the Spec file combo box |
375 |
* Creates the Spec file combo box |
617 |
*/ |
376 |
*/ |
618 |
protected void createSpecFileField(Composite parent) { |
377 |
private void createSpecFileFields(Composite parent) { |
619 |
|
|
|
620 |
|
621 |
Group specGrid = new Group(parent, SWT.NONE); |
378 |
Group specGrid = new Group(parent, SWT.NONE); |
622 |
specGrid.setLayout(new GridLayout()); |
379 |
specGrid.setLayout(new GridLayout()); |
623 |
specGrid.setText(Messages.getString("RPMExportPage.SPEC_file")); //$NON-NLS-1$ |
380 |
specGrid.setText(Messages.getString("RPMExportPage.SPEC_file")); //$NON-NLS-1$ |
Lines 646-652
Link Here
|
646 |
new Listener() { |
403 |
new Listener() { |
647 |
public void handleEvent(Event event) { |
404 |
public void handleEvent(Event event) { |
648 |
if (!specFileCombo.getText().equals("")) { //$NON-NLS-1$ |
405 |
if (!specFileCombo.getText().equals("")) { //$NON-NLS-1$ |
649 |
setVersionReleaseFields(); |
406 |
Path newSpecFilePath = new Path(specFileCombo.getText()); |
|
|
407 |
IFile newSpecFile = rpmProject.getProject().getFile(newSpecFilePath); |
408 |
if(!newSpecFile.exists()) { |
409 |
setErrorMessage(Messages.getString("RPMExportPage.Cannont_find_file")); |
410 |
} |
650 |
} |
411 |
} |
651 |
} |
412 |
} |
652 |
}); |
413 |
}); |
Lines 662-668
Link Here
|
662 |
.getShell(), SWT.OPEN); |
423 |
.getShell(), SWT.OPEN); |
663 |
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace() |
424 |
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace() |
664 |
.getRoot(); |
425 |
.getRoot(); |
665 |
IProject detailProject = workspaceRoot.getProject(returnProject()); |
426 |
IProject detailProject = workspaceRoot.getProject(getSelectedProjectName()); |
666 |
IPath detailProjectLocation = detailProject.getLocation(); |
427 |
IPath detailProjectLocation = detailProject.getLocation(); |
667 |
rpmFileDialog.setFilterPath(detailProjectLocation.toString()); |
428 |
rpmFileDialog.setFilterPath(detailProjectLocation.toString()); |
668 |
|
429 |
|
Lines 670-676
Link Here
|
670 |
|
431 |
|
671 |
if (selectedSpecName != null) { |
432 |
if (selectedSpecName != null) { |
672 |
specFileCombo.setText(selectedSpecName); |
433 |
specFileCombo.setText(selectedSpecName); |
673 |
setVersionReleaseFields(); |
|
|
674 |
} |
434 |
} |
675 |
} |
435 |
} |
676 |
}); |
436 |
}); |
Lines 686-692
Link Here
|
686 |
} |
446 |
} |
687 |
}; |
447 |
}; |
688 |
|
448 |
|
689 |
ModifyListener trapChange = new ModifyListener(){ |
449 |
ModifyListener trapChange = new ModifyListener(){ |
690 |
public void modifyText(ModifyEvent e) { |
450 |
public void modifyText(ModifyEvent e) { |
691 |
handleEvent(null); |
451 |
handleEvent(null); |
692 |
} |
452 |
} |
Lines 731-744
Link Here
|
731 |
rpmRelease.addModifyListener(trapChange); |
491 |
rpmRelease.addModifyListener(trapChange); |
732 |
} |
492 |
} |
733 |
|
493 |
|
734 |
/** |
494 |
private void createPatchHint(Composite parent) { |
735 |
* Method setPatchHint |
|
|
736 |
* |
737 |
* Draws a patch hint for the user |
738 |
* @param parent - composite to draw on |
739 |
* |
740 |
*/ |
741 |
private void setPatchHint(Composite parent) { |
742 |
Display display = null; |
495 |
Display display = null; |
743 |
patchNeedHintGrid = new Group(parent, SWT.NONE); |
496 |
patchNeedHintGrid = new Group(parent, SWT.NONE); |
744 |
patchNeedHintGrid.setVisible(false); |
497 |
patchNeedHintGrid.setVisible(false); |
Lines 767-841
Link Here
|
767 |
Messages.getString("RPMExportPage.needPatch_desc")); //$NON-NLS-1$ |
520 |
Messages.getString("RPMExportPage.needPatch_desc")); //$NON-NLS-1$ |
768 |
} |
521 |
} |
769 |
|
522 |
|
770 |
/** |
|
|
771 |
* Method setVersionReleaseFields |
772 |
* |
773 |
* Sets the Version and Release fields to the |
774 |
* values mined from the selected spec file |
775 |
*/ |
776 |
private void setVersionReleaseFields() { |
777 |
String specFileLocation = ""; //$NON-NLS-1$ |
778 |
|
779 |
String selectSpecFile = specFileCombo.getText(); |
780 |
specFileLocation = returnSpecFilePath(selectSpecFile); |
781 |
path_to_specfile = specFileLocation; |
782 |
//Calculate spec file's physical location |
783 |
|
784 |
ArrayList specVersionReleaseTag = returnSpecVersionRelease(specFileLocation); |
785 |
|
786 |
// Mine the spec file's version and release information from |
787 |
// the provided spec file |
788 |
|
789 |
if (specVersionReleaseTag.size() == 3) { |
790 |
rpmVersion.setText(specVersionReleaseTag.get(0).toString()); |
791 |
rpmRelease.setText(specVersionReleaseTag.get(1).toString()); |
792 |
} |
793 |
} |
794 |
|
795 |
private String returnSpecFilePath(String giveSpecPath) |
796 |
{ |
797 |
if (!giveSpecPath.startsWith(file_sep)) { |
798 |
|
799 |
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace() |
800 |
.getRoot(); |
801 |
IProject projectDetail = workspaceRoot.getProject(returnProject()); |
802 |
String projectLocation = projectDetail.getLocation().toOSString(); |
803 |
return projectLocation + file_sep + specFileCombo.getText(); |
804 |
} else { |
805 |
return specFileCombo.getText(); |
806 |
} |
807 |
|
808 |
} |
809 |
|
523 |
|
810 |
/** |
524 |
private void setVersionReleaseFields() { |
811 |
* Method returnSpecVersionRelease |
525 |
if(rpmProject != null) { |
812 |
* |
526 |
String version = rpmProject.getSpecFile().getVersion(); |
813 |
* Method to return the Spec File version |
527 |
String release = rpmProject.getSpecFile().getRelease(); |
814 |
* and release |
528 |
rpmVersion.setText(version); |
815 |
* @param giveSpecFileLocation |
529 |
rpmRelease.setText(release); |
816 |
* @return |
|
|
817 |
*/ |
818 |
private ArrayList returnSpecVersionRelease(String giveSpecFileLocation) |
819 |
{ |
820 |
|
821 |
ArrayList specFileVersionTag; |
822 |
|
823 |
try { |
824 |
rpmExportCore = new RPMCore(); |
825 |
specFileVersionTag = rpmExportCore.getNameVerRel(giveSpecFileLocation); |
826 |
} catch (FileNotFoundException e) { |
827 |
setErrorMessage(Messages.getString( |
828 |
"RPMExportPage.Cannont_find_file") + giveSpecFileLocation); //$NON-NLS-1$ |
829 |
|
830 |
return null; |
831 |
} catch (CoreException e) { |
832 |
setErrorMessage(Messages.getString("RPMExportPage.Core_Exception") + |
833 |
e.getMessage()); //$NON-NLS-1$ |
834 |
|
835 |
return null; |
836 |
} |
530 |
} |
837 |
|
|
|
838 |
return specFileVersionTag; |
839 |
} |
531 |
} |
840 |
|
532 |
|
841 |
/** |
533 |
/** |
Lines 845-851
Link Here
|
845 |
* Create a generic filler control so that we can dump |
537 |
* Create a generic filler control so that we can dump |
846 |
* controls in a better layout |
538 |
* controls in a better layout |
847 |
*/ |
539 |
*/ |
848 |
protected void createSpacer(Composite parent) { |
540 |
private void createSpacer(Composite parent) { |
849 |
Label spacer = new Label(parent, SWT.NONE); |
541 |
Label spacer = new Label(parent, SWT.NONE); |
850 |
GridData data = new GridData(); |
542 |
GridData data = new GridData(); |
851 |
data.horizontalAlignment = GridData.FILL; |
543 |
data.horizontalAlignment = GridData.FILL; |
Lines 860-880
Link Here
|
860 |
* button can be set to true |
552 |
* button can be set to true |
861 |
* @return boolean. true if finish can be activated |
553 |
* @return boolean. true if finish can be activated |
862 |
*/ |
554 |
*/ |
863 |
|
|
|
864 |
public boolean canFinish() { |
555 |
public boolean canFinish() { |
865 |
|
|
|
866 |
// Make sure project has been selected |
556 |
// Make sure project has been selected |
867 |
if (returnProject().equals("")) { //$NON-NLS-1$ |
557 |
if (getSelectedProjectName() == null && rpmProject == null) { |
868 |
return false; |
558 |
return false; |
869 |
} |
559 |
} |
870 |
|
560 |
// Make sure version/release fields are filled in |
871 |
|
561 |
if (!checkVersionReleaseFields()) { |
872 |
if (checkVersionReleaseFields() == false) { |
|
|
873 |
return false; |
562 |
return false; |
874 |
} |
563 |
} |
875 |
|
|
|
876 |
// Make sure either export binary/source is checked |
564 |
// Make sure either export binary/source is checked |
877 |
if (exportBinary.getSelection() == false && exportSource.getSelection() == false) |
565 |
if (!exportBinary.getSelection() && !exportSource.getSelection()) |
878 |
return false; |
566 |
return false; |
879 |
|
567 |
|
880 |
return true; |
568 |
return true; |
Lines 889-901
Link Here
|
889 |
*/ |
577 |
*/ |
890 |
private boolean checkVersionReleaseFields() { |
578 |
private boolean checkVersionReleaseFields() { |
891 |
if (!rpmVersion.getText().equals("")) { //$NON-NLS-1$ |
579 |
if (!rpmVersion.getText().equals("")) { //$NON-NLS-1$ |
892 |
|
|
|
893 |
if (!rpmRelease.getText().equals("")) { //$NON-NLS-1$ |
580 |
if (!rpmRelease.getText().equals("")) { //$NON-NLS-1$ |
894 |
|
|
|
895 |
return true; |
581 |
return true; |
896 |
} |
582 |
} |
897 |
} |
583 |
} |
898 |
|
|
|
899 |
return false; |
584 |
return false; |
900 |
} |
585 |
} |
901 |
|
586 |
|
Lines 908-914
Link Here
|
908 |
public boolean canGoNext() { |
593 |
public boolean canGoNext() { |
909 |
// if a patch is needed, the next button should |
594 |
// if a patch is needed, the next button should |
910 |
// be enabled |
595 |
// be enabled |
911 |
if (patchNeeded()) { |
596 |
if (isPatchNeeded()) { |
912 |
return true; |
597 |
return true; |
913 |
} else { |
598 |
} else { |
914 |
return false; |
599 |
return false; |
Lines 918-924
Link Here
|
918 |
public void handleEvent(Event e) { |
603 |
public void handleEvent(Event e) { |
919 |
setPageComplete(canGoNext()); |
604 |
setPageComplete(canGoNext()); |
920 |
} |
605 |
} |
921 |
public static String getSpecFilePath() { |
|
|
922 |
return path_to_specfile; |
923 |
} |
924 |
} |
606 |
} |