Index: build.properties =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.ui/build.properties,v retrieving revision 1.1 diff -u -r1.1 build.properties --- build.properties 13 Oct 2004 02:31:16 -0000 1.1 +++ build.properties 18 May 2005 20:43:58 -0000 @@ -10,4 +10,14 @@ bin.includes = plugin.xml,\ *.jar,\ RpmUi.jar,\ - icons/ + icons/,\ + about.html +src.includes = .classpath,\ + .project,\ + .template,\ + ChangeLog,\ + about.html,\ + build.properties,\ + icons/,\ + plugin.xml,\ + src/ Index: plugin.xml =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.ui/plugin.xml,v retrieving revision 1.4 diff -u -r1.4 plugin.xml --- plugin.xml 11 Nov 2004 15:29:09 -0000 1.4 +++ plugin.xml 18 May 2005 20:43:58 -0000 @@ -5,18 +5,12 @@ name="RPM UI Plug-in" version="1.2" provider-name="Eclipse.org" - > + class="org.eclipse.cdt.rpm.ui.RPMUIPlugin"> - - - - - - @@ -28,7 +22,6 @@ - @@ -41,7 +34,7 @@ class="org.eclipse.cdt.rpm.ui.RPMExportWizard" id="org.eclipse.cdt.rpm.ui.RPMExportWizard"> - Export C/C++ projects to RPM format + Export an RPM @@ -53,8 +46,8 @@ + class="org.eclipse.cdt.rpm.ui.SRPMImportWizard" + id="org.eclipse.cdt.rpm.ui.SRPMImportWizard"> Imports a Source RPM to a project @@ -66,11 +59,11 @@ + name="RPM"> Index: src/org/eclipse/cdt/rpm/ui/RPMExportOperation.java =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.ui/src/org/eclipse/cdt/rpm/ui/RPMExportOperation.java,v retrieving revision 1.1 diff -u -r1.1 RPMExportOperation.java --- src/org/eclipse/cdt/rpm/ui/RPMExportOperation.java 13 Oct 2004 02:31:16 -0000 1.1 +++ src/org/eclipse/cdt/rpm/ui/RPMExportOperation.java 18 May 2005 20:43:58 -0000 @@ -1,5 +1,5 @@ /* - * (c) 2004 Red Hat, Inc. + * (c) 2004, 2005 Red Hat, Inc. * * This program is open source software licensed under the * Eclipse Public License ver. 1 @@ -7,12 +7,8 @@ package org.eclipse.cdt.rpm.ui; -import org.eclipse.cdt.rpm.core.*; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; +import org.eclipse.cdt.rpm.core.IRPMProject; +import org.eclipse.cdt.rpm.core.RPMExportDelta; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; @@ -27,91 +23,27 @@ import java.util.ArrayList; import java.util.Iterator; -/** - * @author pmuldoon - * - * Export Class for RPM plug-in. This allows us to abstract the operations to - * a utility class which also inherits IRunnableWithProgress that allows use of - * progress bar - */ public class RPMExportOperation implements IRunnableWithProgress { - // Class variables that are use for storage - // as they are passed into the constrcutor - private String project_name; - private String actual_proj_name; - private boolean preserve_env; - private boolean keep_log; - private String spec_file; - private String patch_name = ""; //$NON-NLS-1$ - private String patch_tag = ""; //$NON-NLS-1$ - private String patch_changelog = ""; //$NON-NLS-1$ - private String patch_version = ""; //$NON-NLS-1$ - private String patch_release = ""; //$NON-NLS-1$ - private boolean gen_patch; - private String exportType; - - // Progressmonitor private IProgressMonitor monitor; - - public ArrayList rpm_errorTable; - - /** - * Method RPMExportOperation. - * @param a_proj_name - actual project name - * @param work_path - path to workspace of project - * @param pSpec_File - path to spec file - * @param pPatchName - patch file name to use - * @param pPatchComment - Comment for patch entry - * @param pPatchChangeLog - ChangeLog header entry - * @param pPatchVersion - Version Number to use - * @param pPatchRelease- Release Number to use - * @param pexportType - -ba, -bs or -bp (all, source, binary) - * @param pGenPatch - Patch Generation toggle - * - */ - public RPMExportOperation( - String a_proj_name, - String work_path, - String pSpec_File, - String pPatchName, - String pPatchComment, - String pPatchChangeLog, - String pPatchVersion, - String pPatchRelease, - String pexportType, - boolean pGenPatch) { - - // Copy passed variables to constructor, to class variables - project_name = work_path; - actual_proj_name = a_proj_name; - spec_file = pSpec_File; - patch_name = pPatchName; - patch_tag = pPatchComment; - patch_changelog = pPatchChangeLog; - patch_version = pPatchVersion; - patch_release = pPatchRelease; - exportType = pexportType; - gen_patch = pGenPatch; + private ArrayList rpm_errorTable; + private IRPMProject rpmProject; + private RPMExportDelta exportDelta; + private int exportType; + + public RPMExportOperation(IRPMProject rpmProject, int exportType, + RPMExportDelta exportDelta) { + this.rpmProject = rpmProject; + this.exportDelta = exportDelta; + this.exportType = exportType; } /** * @see org.eclipse.jface.operation.IRunnableWithProgress#run(IProgressMonitor) * - * Perform the incremental build of the S/RPM export. */ public void run(IProgressMonitor progressMonitor) throws InvocationTargetException { - - int totalWork = 0; - ArrayList PatchInfo = null; - RPMExport rpmexport; - SRPMExport srpmexport; - - // Total number of work steps needed - if (exportType.equals("-ba")) //$NON-NLS-1$ - totalWork = 4; - else - totalWork = 2; + int totalWork = 2; monitor = progressMonitor; @@ -120,98 +52,38 @@ // Start progress monitor.beginTask(Messages.getString("RPMExportOperation.Starting"), //$NON-NLS-1$ - totalWork); //$NON-NLS-1$ - - // If the export type is all (-ba) or export type is source (-bs) - if (exportType.equals("-bs") || exportType.equals("-ba")) { //$NON-NLS-1$ //$NON-NLS-2$ - - monitor.setTaskName(Messages.getString("RPMExportOperation.Starting_SRPM_Export")); //$NON-NLS-1$ - - // Try to create an instance of the srpm export class + totalWork); + monitor.worked(1); + + switch(exportType) { + case IRPMUIConstants.BUILD_ALL: try { - srpmexport = new SRPMExport(project_name); - } catch (Exception e) { + monitor.setTaskName(Messages.getString("RPMExportOperation.Executing_RPM_Export")); + rpmProject.buildAll(exportDelta); + } catch(Exception e) { rpm_errorTable.add(e); - refreshWorkspace(); - return; } - // set the various properties of a SRPM export - srpmexport.setChangelog_entry(patch_changelog); - srpmexport.setUi_ver_no(patch_version); - srpmexport.setUi_rel_no(patch_release); - srpmexport.setUi_spec_file(spec_file); - srpmexport.setPatch_tag(patch_tag); - - monitor.worked(1); - monitor.setTaskName(Messages.getString("RPMExportOperation.Executing_SRPM_Export")); //$NON-NLS-1$ - - // execue the srpm export - try { - srpmexport.run(); - } catch (CoreException e) { - rpm_errorTable.add(e.getStatus()); - refreshWorkspace(); - return; - } - monitor.worked(1); - - } - // If the export type is all (-ba) or export type is binary (-bb) - if (exportType.equals("-bb") || exportType.equals("-ba")) { //$NON-NLS-1$ //$NON-NLS-2$ - - monitor.setTaskName(Messages.getString("RPMExportOperation.Starting_RPM_Export")); //$NON-NLS-1$ - - // Try to create an instance of the rpm export class + break; + + case IRPMUIConstants.BUILD_BINARY: + monitor.setTaskName(Messages.getString("RPMExportOperation.Executing_RPM_Export")); //$NON-NLS-1$ try { - rpmexport = new RPMExport(project_name); - } catch (Exception e) { + rpmProject.buildBinaryRPM(exportDelta); + } catch(Exception e) { rpm_errorTable.add(e); - refreshWorkspace(); - return; } - - // set the various properties of an RPM export - rpmexport.setUi_ver_no(patch_version); - rpmexport.setUi_rel_no(patch_release); - rpmexport.setUi_spec_file(spec_file); - if (exportType.equals("-bb")) { //$NON-NLS-1$ - rpmexport.setPatch_tag(patch_tag); - rpmexport.setChangelog_entry(patch_changelog); - } - - monitor.worked(1); - monitor.setTaskName(Messages.getString("RPMExportOperation.Executing_RPM_Export")); //$NON-NLS-1$ - - // execue the rpm export + break; + + case IRPMUIConstants.BUILD_SOURCE: + monitor.setTaskName(Messages.getString("RPMExportOperation.Executing_SRPM_Export")); //$NON-NLS-1$ try { - rpmexport.run(); - } catch (CoreException e) { - rpm_errorTable.add(e.getStatus()); - refreshWorkspace(); - return; + rpmProject.buildSourceRPM(exportDelta); + } catch(Exception e) { + rpm_errorTable.add(e); } - - monitor.worked(1); - } - - refreshWorkspace(); - - } - - - public void refreshWorkspace() - { - // Refresh the workspace - IWorkspaceRoot myWorkspaceRoot = - ResourcesPlugin.getWorkspace().getRoot(); - IProject myProject = myWorkspaceRoot.getProject(actual_proj_name); - - try { - myWorkspaceRoot.refreshLocal(2, null); - myProject.refreshLocal(2, null); - } catch (CoreException e1) { - rpm_errorTable.add(e1.getStatus()); + break; } + monitor.worked(1); } public MultiStatus getStatus() { Index: src/org/eclipse/cdt/rpm/ui/RPMExportPage.java =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.ui/src/org/eclipse/cdt/rpm/ui/RPMExportPage.java,v retrieving revision 1.4 diff -u -r1.4 RPMExportPage.java --- src/org/eclipse/cdt/rpm/ui/RPMExportPage.java 18 Jan 2005 16:53:14 -0000 1.4 +++ src/org/eclipse/cdt/rpm/ui/RPMExportPage.java 18 May 2005 20:43:58 -0000 @@ -1,5 +1,5 @@ /* - ** (c) 2004 Red Hat, Inc. + ** (c) 2004, 2005 Red Hat, Inc. * * This program is open source software licensed under the * Eclipse Public License ver. 1 @@ -15,22 +15,22 @@ */ package org.eclipse.cdt.rpm.ui; -import org.eclipse.cdt.rpm.core.*; +import java.util.Iterator; -import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.rpm.core.IRPMProject; +import org.eclipse.cdt.rpm.core.RPMProjectFactory; +import org.eclipse.cdt.rpm.core.RPMProjectNature; +import org.eclipse.cdt.rpm.ui.util.ExceptionHandler; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectNature; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.MultiStatus; - -import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.core.runtime.Path; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.WizardPage; - import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; @@ -56,41 +56,40 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Text; -import java.io.FileNotFoundException; -import java.lang.reflect.InvocationTargetException; - -import java.util.ArrayList; -import java.util.Iterator; - /** - * @author pmuldoon * * RPMExportPage. Called by RPMExportWizard. Class can not be subclassed *extends WizardPage for the RPM export wizard, implements Listener * */ public class RPMExportPage extends WizardPage implements Listener { - private RPMExportOperation rpmExport; - private RPMCore rpmExportCore; - // Checkbox Buttons - private Button generatePatch; private Button exportBinary; private Button exportSource; + + // Version and release fields private Text rpmVersion; private Text rpmRelease; + + // The current selection private IStructuredSelection selection; //Composite Project Listbox control private List projectList; + + //Spec file combo box private Combo specFileCombo; - private boolean patchNeeded = false; + + //Patch grid private Group patchNeedHintGrid; - private static String path_to_specfile; - static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ - static final String line_sep = System.getProperty("line.separator"); //$NON-NLS-1$ + + //The currently selected RPM project + private IRPMProject rpmProject; + + //Is a patch needed? + private boolean patchNeeded = false; public RPMExportPage(IStructuredSelection currentSelection) { super(Messages.getString("RPMExportPage.Export_SRPM"), //$NON-NLS-1$ @@ -99,154 +98,62 @@ setPageComplete(true); selection = currentSelection; } + + public IRPMProject getSelectedRPMProject() { + return rpmProject; + } + + public IFile getSelectedSpecFile() { + Path newSpecFilePath = + new Path(specFileCombo.getItem(specFileCombo.getSelectionIndex())); + return rpmProject.getProject().getFile(newSpecFilePath); + } + + public String getSelectedVersion() { + return rpmVersion.getText(); + } + + public String getSelectedRelease() { + return rpmRelease.getText(); + } - /** - * Method returnProject. - * @return String - returned selected project - * - * Returns a string from the selected project - * in the control list box. - */ - public String returnProject() { - String projSelect; + public int getExportType() { + int exportType = 0; + if(exportBinary.getSelection() && exportSource.getSelection()) { + exportType = IRPMUIConstants.BUILD_ALL; + } else if(exportBinary.getSelection()) { + exportType = IRPMUIConstants.BUILD_BINARY; + } else if(exportSource.getSelection()) { + exportType = IRPMUIConstants.BUILD_SOURCE; + } + return exportType; + } + + private String getSelectedProjectName() { + String projSelect = null; String[] projDetails = projectList.getSelection(); if (projDetails.length > 0) { projSelect = projDetails[0]; - } else { - projSelect = ""; //$NON-NLS-1$ } - return projSelect; } - - /** - * Method returnProjectPath - * @return returns the path of the currently selected project in - * projectList - */ - public String returnProjectPath() { - String[] projectSelection = projectList.getSelection(); - IProject projectDetail; - - // As we only allow a single selection in the listbox, and the listbox - // always comes with the first element selected, we can assume - // the first element in the returned array is valid. - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - try { - projectDetail = workspaceRoot.getProject(projectSelection[0]); - } catch (Exception e) { - return null; - } - - return projectDetail.getLocation().toOSString(); - } - - /** - * Method setPatchModifier - * @param patchDelta - sets whether patch is required in a project - */ - private void setPatchModifier(boolean patchDelta) { + + private void setPatchNeeded(boolean patchDelta) { patchNeeded = patchDelta; } - - /** - * Method patchNeeded - * @return boolean - is a patch needed? - */ - public boolean patchNeeded() { + + private boolean isPatchNeeded() { return patchNeeded; } /** - * Method returnSpecFiles - * - * @param projname - Name of the project to mine for spec files - * @return ArrayList - ArrayList of found spec files - * - * Method that mines a selected project for spec files - * Will return an ArrayList of returned spec files - * - */ - public ArrayList returnSpecFiles(String givenProjectName) { - IProject[] internalProjects; - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - internalProjects = workspaceRoot.getProjects(); - - String projectName; - ArrayList specFileList = new ArrayList(); - - for (int numberOfProjects = 0; numberOfProjects < internalProjects.length; numberOfProjects++) { - projectName = internalProjects[numberOfProjects].getName(); - - if (projectName.equals(givenProjectName)) { - try { - final IResource[] projectResourceList = internalProjects[numberOfProjects].members(); - - for (int numberOfResources = 0; numberOfResources < projectResourceList.length; numberOfResources++) { - String filenameExtension = projectResourceList[numberOfResources].getFileExtension(); - - if (filenameExtension != null) { - if (filenameExtension.equals("spec")) { //$NON-NLS-1$ - specFileList.add(projectResourceList[numberOfResources].getName().toString()); - } - } - } - } catch (CoreException e) { - } - } - } - - return specFileList; - } - - /** - * Method hasMakefile. - * @param givenProjectName - project name to check - * @return boolean - true if project has makefile, false if not - * - * Returns boolean on whether the currently selected project - * has a Makefile that is visible and can be sourced - */ - public boolean hasMakefile(String givenProjectName) { - IProject[] internalProjectList; - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); - internalProjectList = workspaceRoot.getProjects(); - - String projectName; - IResource resourceList; - - for (int a = 0; a < internalProjectList.length; a++) { - projectName = internalProjectList[a].getName(); - - if (projectName.equals(givenProjectName)) { - resourceList = internalProjectList[a].findMember(Messages.getString( - "RPMExportPage.Makefile_pc")); //$NON-NLS-1$ - - if (resourceList != null) { - return true; - } - - resourceList = internalProjectList[a].findMember(Messages.getString( - "RPMExportPage.makefile_lc")); //$NON-NLS-1$ - - if (resourceList != null) { - return true; - } - } - } - - return false; - } - - /** * @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite) * * Parent control. Creates the listbox, Destination box, and options box * */ public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); // Create a layout for the wizard page @@ -256,187 +163,38 @@ // Create contols on the page createProjectBox(composite); - createSpecFileField(composite); - setSpecFileComboData(); + createSpecFileFields(composite); createSpacer(composite); - createExportType(composite); - setPatchHint(composite); + createExportTypeControls(composite); + createPatchHint(composite); + + // Fill in the fields + setSpecFileComboData(); + setVersionReleaseFields(); - // Check if the project checksums are different - // and therefore the project needs a path - if (compareCheckSum(returnProjectPath()).equals("patch")) //$NON-NLS-1$ - { + // Check if the project has changed + // and therefore the project needs a patch + boolean projectChanged = false; + try { + if(rpmProject != null) { + projectChanged = rpmProject.isChanged(); + } + } catch(CoreException e) { + ExceptionHandler.handle(e, getShell(), Messages.getString("ErrorDialog.title"), + e.getMessage()); + } + if(projectChanged) { patchNeedHintGrid.setVisible(true); - setPatchModifier(true); + setPatchNeeded(true); setPageComplete(true); } else { - setPatchModifier(false); + setPatchNeeded(false); setPageComplete(false); } } - /** - * Method compareCheckSum - * - * @param givenProject - project to check - * @return = match - * @return = legacy - * @return = patch - * @return = error - * - * Returns one of the above status depending on project status - * - */ - public String compareCheckSum(String givenProject) { - try { - // Create an instance of the RPMExport class - rpmExportCore = new RPMCore(); - - // Mine the .srpmInfo file if there is one - if (rpmExportCore.firstSRPM(givenProject)) { - return "legacy"; - } - ArrayList srpmProjectInfo = rpmExportCore.getSRPMexportinfo(givenProject); - - // If the generated checksum, and the one in the srpmInfo file are the same - // then the project has not changed since last import and does not need a patch - if (rpmExportCore.generateChecksum(givenProject, 0) == Long.parseLong( - (String) srpmProjectInfo.get(6))) { - setPatchModifier(false); - - return "match"; //$NON-NLS-1$ - - - // If we cannot find an srpmInfo file, this is a legacy project - } else if (Long.parseLong((String) srpmProjectInfo.get(6)) == -1) { - setPatchModifier(false); - - return "legacy"; //$NON-NLS-1$ - // Otherwise they don't match and we need to patch - } else { - setPatchModifier(true); - - return "patch"; //$NON-NLS-1$ - } - } catch (CoreException e) { - return "error"; //$NON-NLS-1$ - } - } - - /** - * Method checkPageComplete. - * @return boolean - * - * Check if export rpm name is valid - * Check if project has makefile - * Check a valid project has been selected - */ - public boolean checkPageComplete() { - // Method invoked to check we have all the required data from the user - // before we allow the wizard to execute. However they can cancel at - // anytime. - // Check the contents of the RPM destination filename - // Needs work, least of all the variable name ;) - // Check to ensure that the selected project has a makefile - if (hasMakefile(returnProject()) == false) { - setErrorMessage(Messages.getString( - "RPMExportPage.project_does_not_have_Makefile")); //$NON-NLS-1$ - - return false; - } - - // Check to ensure the select project is actually a project - String projDetails = returnProject(); - - if (projDetails.equals(Messages.getString( - "RPMExportPage.No_c/c++_projects_found")) == true) { //$NON-NLS-1$ - setErrorMessage(Messages.getString( - "RPMExportPage.Invald_project_specified")); //$NON-NLS-1$ - - return false; - } - - // If all tests pass, then we are okay to go. - return true; - } - - /** - * Method finish. Performs the actual work. - * @return boolean - * @throws CoreException - * @throws CoreException - */ - public boolean finish(String[] givenPatchData) throws CoreException { - // Selected project location - String projectLocation = null; - - // Check that we can finish the export operation - if (checkPageComplete() == false) { - return false; - } - - // As we only allow a single selection in the listbox, and the listbox always - // comes with the first element selected, we can assume the first element - // in the returned array is valid. Need to add a try/catch group to check for - // null though - projectLocation = returnProjectPath(); - - String exportType = null; - - // Calculate the export source type - // -ba = build all - // -bs = build source - // -bb = build binary - if ((exportSource.getSelection() == true) && - (exportBinary.getSelection() == true)) { - exportType = "-ba"; //$NON-NLS-1$ - } else if (exportSource.getSelection() == true) { - exportType = "-bs"; //$NON-NLS-1$ - } else if (exportBinary.getSelection() == true) { - exportType = "-bb"; //$NON-NLS-1$ - } - - // Create a new instance of rpmExportOperation build class - try { - rpmExport = new RPMExportOperation(returnProject(), - projectLocation, specFileCombo.getText(), "", givenPatchData[0], //$NON-NLS-1$ - givenPatchData[1] + line_sep + - givenPatchData[2] + line_sep + line_sep, rpmVersion.getText(), - rpmRelease.getText(), exportType, patchNeeded); - } catch (Exception e) { - setErrorMessage(e.toString()); - return false; - } - - // Run the export - try { - getContainer().run(true, true, rpmExport); - } catch (InvocationTargetException e1) { - setErrorMessage(e1.toString()); - return false; - } catch (InterruptedException e1) { - setErrorMessage(e1.toString()); - } - - MultiStatus status = rpmExport.getStatus(); - - if (!status.isOK()) { - ErrorDialog.openError(getContainer().getShell(), - Messages.getString( - "RPMExportPage.Errors_encountered_importing_SRPM"), //$NON-NLS-1$ - null, // no special message - status); - - return false; - } - - // Need to return some meaninful status. Should only return true if the wizard completed - // successfully. - return true; - } - - private void createExportType(Composite parent) { //Create a group for the control and set up the layout. - + private void createExportTypeControls(Composite parent) { + //Create a group for the control and set up the layout. Group group = new Group(parent, SWT.NONE); group.setLayout(new GridLayout()); group.setText(Messages.getString("RPMExportPage.Composite_Export_Type")); //$NON-NLS-1$ @@ -479,13 +237,9 @@ * Create a list box and populate it with * the list of current projects in the workspace */ - protected void createProjectBox(Composite parent) { + private void createProjectBox(Composite parent) { // Creates a control that enumerates all the projects in the current // Workspace and places them in a listbox. - // Need to check what to do if the user chooses to export an RPM - // when there are no current projects in the workspace. Right now - // the other export wizard just open, with empty treeviews (?) - // Declare an array of IProject; IProject[] internalProjectList; String Proj_Enum; @@ -521,70 +275,80 @@ if (internalProjectList.length < 1) { projectList.add(Messages.getString( - "RPMPage.No_c/c++_projects_found_2")); //$NON-NLS-1$ + "RPMPage.No_RPM_projects_found")); //$NON-NLS-1$ return; } - // Stuff the listbox with the text name of the projects - // using the getName() method // Find the first selected project in the workspace - Iterator iter = selection.iterator(); Object selectedObject= null; IProject selectedProject = null; boolean isSelection = false; - if (iter.hasNext()) - { + if (iter.hasNext()) { selectedObject = iter.next(); - if (selectedObject instanceof IResource) - { + if (selectedObject instanceof IResource) { selectedProject = ((IResource) selectedObject).getProject(); isSelection = true; } } - // Stuff the listbox with the text names of the projects - // using the getName() method and select the selected - // project if available - - - for (int a = 0; a < internalProjectList.length; a++) - { - + // Stuff the listbox with the text names of the projects + // Highlight the currently selected project in the workspace + int selectedProjectIndex = 0; + for (int a = 0; a < internalProjectList.length; a++) { try { - IProjectNature cNature = internalProjectList[a].getNature(CProjectNature.C_NATURE_ID); - if (cNature!=null) + if(internalProjectList[a].hasNature(RPMProjectNature.RPM_NATURE_ID)) { projectList.add(internalProjectList[a].getName()); - if (isSelection && internalProjectList[a].equals(selectedProject)) - projectList.setSelection(a); - } catch (CoreException e) { - + if (isSelection && internalProjectList[a].equals(selectedProject)) { + selectedProjectIndex = a; + } + } + } catch(CoreException e) { + ExceptionHandler.handle(e, getShell(), + Messages.getString("ErrorDialog.title"), e.getMessage()); } } + projectList.setSelection(selectedProjectIndex); + try { + rpmProject = RPMProjectFactory.getRPMProject(internalProjectList[selectedProjectIndex]); + } catch(CoreException e) { + ExceptionHandler.handle(e, getShell(), + Messages.getString("ErrorDialog.title"), e.getMessage()); + } - if (!isSelection) - projectList.setSelection(0);//if none is selected select first project - - // Add a listener to set the name in the location box as - // it is selected in project box + // Add a listener to the project box projectList.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { - rpmVersion.setText(""); - rpmRelease.setText(""); + // Reset the RPM project + int i = projectList.getSelectionIndex(); + if(i != -1) { + IProject project = workspaceRoot.getProject(projectList.getSelection()[0]); + try { + rpmProject = RPMProjectFactory.getRPMProject(project); + if(rpmProject.isChanged()) { + setPatchNeeded(true); + patchNeedHintGrid.setVisible(true); + setPageComplete(true); + } else { + setPatchNeeded(false); + patchNeedHintGrid.setVisible(false); + setPageComplete(false); + } + } catch(CoreException e) { + ExceptionHandler.handle(e, getShell(), + Messages.getString("ErrorDialog.title"), e.getMessage()); + } + } else { + rpmProject = null; + setPatchNeeded(false); + patchNeedHintGrid.setVisible(false); + setPageComplete(false); + } setSpecFileComboData(); - if (compareCheckSum(returnProjectPath()).equals("patch")) //$NON-NLS-1$ - { - setPatchModifier(true); - patchNeedHintGrid.setVisible(true); - setPageComplete(true); - } else { - patchNeedHintGrid.setVisible(false); - setPatchModifier(false); - setPageComplete(false); - } - } - }); + setVersionReleaseFields(); + } + }); } /** @@ -596,16 +360,11 @@ private void setSpecFileComboData() { specFileCombo.clearSelection(); specFileCombo.removeAll(); - - final ArrayList specFileList = returnSpecFiles(returnProject()); - Iterator i = specFileList.iterator(); - - while (i.hasNext()) - specFileCombo.add(i.next().toString()); - - if (specFileList.size() > 0) { - specFileCombo.setText(specFileList.get(0).toString()); - setVersionReleaseFields(); + if(rpmProject != null) { + String specFile = + rpmProject.getSpecFile().getFile().getProjectRelativePath().toOSString(); + specFileCombo.add(specFile); + specFileCombo.setText(specFile); } } @@ -615,9 +374,7 @@ * * Creates the Spec file combo box */ - protected void createSpecFileField(Composite parent) { - - + private void createSpecFileFields(Composite parent) { Group specGrid = new Group(parent, SWT.NONE); specGrid.setLayout(new GridLayout()); specGrid.setText(Messages.getString("RPMExportPage.SPEC_file")); //$NON-NLS-1$ @@ -646,7 +403,11 @@ new Listener() { public void handleEvent(Event event) { if (!specFileCombo.getText().equals("")) { //$NON-NLS-1$ - setVersionReleaseFields(); + Path newSpecFilePath = new Path(specFileCombo.getText()); + IFile newSpecFile = rpmProject.getProject().getFile(newSpecFilePath); + if(!newSpecFile.exists()) { + setErrorMessage(Messages.getString("RPMExportPage.Cannont_find_file")); + } } } }); @@ -662,7 +423,7 @@ .getShell(), SWT.OPEN); IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace() .getRoot(); - IProject detailProject = workspaceRoot.getProject(returnProject()); + IProject detailProject = workspaceRoot.getProject(getSelectedProjectName()); IPath detailProjectLocation = detailProject.getLocation(); rpmFileDialog.setFilterPath(detailProjectLocation.toString()); @@ -670,7 +431,6 @@ if (selectedSpecName != null) { specFileCombo.setText(selectedSpecName); - setVersionReleaseFields(); } } }); @@ -686,7 +446,7 @@ } }; - ModifyListener trapChange = new ModifyListener(){ + ModifyListener trapChange = new ModifyListener(){ public void modifyText(ModifyEvent e) { handleEvent(null); } @@ -731,14 +491,7 @@ rpmRelease.addModifyListener(trapChange); } - /** - * Method setPatchHint - * - * Draws a patch hint for the user - * @param parent - composite to draw on - * - */ - private void setPatchHint(Composite parent) { + private void createPatchHint(Composite parent) { Display display = null; patchNeedHintGrid = new Group(parent, SWT.NONE); patchNeedHintGrid.setVisible(false); @@ -767,75 +520,14 @@ Messages.getString("RPMExportPage.needPatch_desc")); //$NON-NLS-1$ } - /** - * Method setVersionReleaseFields - * - * Sets the Version and Release fields to the - * values mined from the selected spec file - */ - private void setVersionReleaseFields() { - String specFileLocation = ""; //$NON-NLS-1$ - - String selectSpecFile = specFileCombo.getText(); - specFileLocation = returnSpecFilePath(selectSpecFile); - path_to_specfile = specFileLocation; - //Calculate spec file's physical location - - ArrayList specVersionReleaseTag = returnSpecVersionRelease(specFileLocation); - - // Mine the spec file's version and release information from - // the provided spec file - - if (specVersionReleaseTag.size() == 3) { - rpmVersion.setText(specVersionReleaseTag.get(0).toString()); - rpmRelease.setText(specVersionReleaseTag.get(1).toString()); - } - } - - private String returnSpecFilePath(String giveSpecPath) - { - if (!giveSpecPath.startsWith(file_sep)) { - - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace() - .getRoot(); - IProject projectDetail = workspaceRoot.getProject(returnProject()); - String projectLocation = projectDetail.getLocation().toOSString(); - return projectLocation + file_sep + specFileCombo.getText(); - } else { - return specFileCombo.getText(); - } - - } - /** - * Method returnSpecVersionRelease - * - * Method to return the Spec File version - * and release - * @param giveSpecFileLocation - * @return - */ - private ArrayList returnSpecVersionRelease(String giveSpecFileLocation) - { - - ArrayList specFileVersionTag; - - try { - rpmExportCore = new RPMCore(); - specFileVersionTag = rpmExportCore.getNameVerRel(giveSpecFileLocation); - } catch (FileNotFoundException e) { - setErrorMessage(Messages.getString( - "RPMExportPage.Cannont_find_file") + giveSpecFileLocation); //$NON-NLS-1$ - - return null; - } catch (CoreException e) { - setErrorMessage(Messages.getString("RPMExportPage.Core_Exception") + - e.getMessage()); //$NON-NLS-1$ - - return null; + private void setVersionReleaseFields() { + if(rpmProject != null) { + String version = rpmProject.getSpecFile().getVersion(); + String release = rpmProject.getSpecFile().getRelease(); + rpmVersion.setText(version); + rpmRelease.setText(release); } - - return specFileVersionTag; } /** @@ -845,7 +537,7 @@ * Create a generic filler control so that we can dump * controls in a better layout */ - protected void createSpacer(Composite parent) { + private void createSpacer(Composite parent) { Label spacer = new Label(parent, SWT.NONE); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; @@ -860,21 +552,17 @@ * button can be set to true * @return boolean. true if finish can be activated */ - public boolean canFinish() { - // Make sure project has been selected - if (returnProject().equals("")) { //$NON-NLS-1$ + if (getSelectedProjectName() == null && rpmProject == null) { return false; } - - - if (checkVersionReleaseFields() == false) { + // Make sure version/release fields are filled in + if (!checkVersionReleaseFields()) { return false; } - // Make sure either export binary/source is checked - if (exportBinary.getSelection() == false && exportSource.getSelection() == false) + if (!exportBinary.getSelection() && !exportSource.getSelection()) return false; return true; @@ -889,13 +577,10 @@ */ private boolean checkVersionReleaseFields() { if (!rpmVersion.getText().equals("")) { //$NON-NLS-1$ - if (!rpmRelease.getText().equals("")) { //$NON-NLS-1$ - return true; } } - return false; } @@ -908,7 +593,7 @@ public boolean canGoNext() { // if a patch is needed, the next button should // be enabled - if (patchNeeded()) { + if (isPatchNeeded()) { return true; } else { return false; @@ -918,7 +603,4 @@ public void handleEvent(Event e) { setPageComplete(canGoNext()); } - public static String getSpecFilePath() { - return path_to_specfile; - } } Index: src/org/eclipse/cdt/rpm/ui/RPMExportPage_2.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/ui/RPMExportPage_2.java diff -N src/org/eclipse/cdt/rpm/ui/RPMExportPage_2.java --- src/org/eclipse/cdt/rpm/ui/RPMExportPage_2.java 10 Dec 2004 21:04:53 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,403 +0,0 @@ -/* - * (c) 2004 Red Hat, Inc. - * - * This program is open source software licensed under the - * Eclipse Public License ver. 1 - */ - -/** - * @author pmuldoon - * @version 1.0 - * - * S/RPM export page 2. Defines the patch page that is shown to the user when they choose - * to export to an SRPM and patch. Defines the UI elements shown, and the basic validation (need to add to - * this) - */ -package org.eclipse.cdt.rpm.ui; - -import org.eclipse.cdt.rpm.core.RPMCorePlugin; - -import org.eclipse.jface.wizard.WizardPage; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; - -import java.text.SimpleDateFormat; -import java.net.UnknownHostException; -import java.util.Date; -import java.util.ArrayList; -import java.io.*; - -public class RPMExportPage_2 extends WizardPage implements Listener { - // Composite file/browse control - // Core RPM build class - private RPMExportOperation rpmExport; - - // Checkbox Buttons - private Button generatePatch; - - // Patch Fields - private Text patchTag; - - private Text patchChangeLog; - - private Text patchChangeLogstamp; - - private boolean first_spec = true; - - private String path_to_specfile_save = null; - - private String last_gettext = ""; //$NON-NLS-1$ - - private ArrayList patch_names; - - private boolean firstTag = true; - - private boolean patchTagError; - - private final String valid_char_list = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"; //$NON-NLS-1$ - - static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ - - /** - * @see java.lang.Object#Object() - * - * Constructor for RPMExportPage class - */ - public RPMExportPage_2() { - super( - Messages.getString("RPMExportPage.Export_SRPM"), //$NON-NLS-1$ - Messages.getString("RPMExportPage.Export_SRPM_from_project"), null); //$NON-NLS-1$ //$NON-NLS-2$ - setDescription(Messages.getString("RPMExportPage_2.0")); //$NON-NLS-1$ - patch_names = new ArrayList(); - } - - /** - * @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite) - * - * Parent control. Creates the listbox, Destination box, and options box - * - */ - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - // Create a layout for the wizard page - composite.setLayout(new GridLayout()); - composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); - setControl(composite); - - // Create contols on the page - createPatchFields(composite); - populatePatchInfo(); - } - - /** - * Method populatePatchInfo - * - * Populate the patch widgets with data - */ - protected void populatePatchInfo() { - - String userName = RPMCorePlugin.getDefault().getPreferenceStore() - .getString("IRpmConstants.AUTHOR_NAME"); //$NON-NLS-1$ - String userEmail = RPMCorePlugin.getDefault().getPreferenceStore() - .getString("IRpmConstants.AUTHOR_EMAIL"); //$NON-NLS-1$ - - // Populate the changeLog - Date today = new Date(); - SimpleDateFormat df = new SimpleDateFormat("E MMM dd yyyy"); //$NON-NLS-1$ - - patchChangeLogstamp.setText("* " + df.format(today) + //$NON-NLS-1$ - " -- " + userName + " <" + userEmail + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - patchChangeLog.setText("- "); //$NON-NLS-1$ - } - - /** - * Method createGenPatchFields - * - * Create the patch generation widgets - */ - protected void createPatchFields(Composite parent) { - Group group = new Group(parent, SWT.NONE); - group.setLayout(new GridLayout()); - group.setText(Messages.getString("RPMExportPage.Patch_Options")); //$NON-NLS-1$ - group.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL - | GridData.HORIZONTAL_ALIGN_FILL)); - - Composite composite = new Composite(group, SWT.NONE); - - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.GRAB_HORIZONTAL)); - - // Listen for changes to the patch tag field so we can make sure - // this tag has not been used before - ModifyListener trapTag = new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (firstTag) { - patch_names = getPatchNames(RPMExportPage.getSpecFilePath()); - firstTag = false; - } - - patchTagError = false; - // Does it have any spaces or special characters - if (patchTag.getText().length() != 0) { - for (int i = patchTag.getText().length(); i > 0; i--) { - if (valid_char_list.lastIndexOf(patchTag.getText() - .substring(i - 1,i)) == -1) { - setErrorMessage(Messages - .getString("RPMExportPage_2.1")); //$NON-NLS-1$ - patchTagError = true; - handleEvent(null); - return; - } - } - // Is the patch tag unique? (That is, if there are any patch - // tags.) - if (!patch_names.isEmpty()) { - for (int i = 0; i < patch_names.size(); i++) { - if (patchTag.getText().equals( - (String) patch_names.get(i))) { - patchTagError = true; - setErrorMessage(Messages - .getString("RPMExportPage_2.3")); //$NON-NLS-1$ - handleEvent(null); - return; - } - } - } - } - setErrorMessage(null); - setDescription(Messages.getString("RPMExportPage_2.0")); //$NON-NLS-1$ - handleEvent(null); - } - }; - - ModifyListener trapPatch = new ModifyListener() { - - public void modifyText(ModifyEvent e) { - handleEvent(null); - } - }; - - GridData patchTagGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.GRAB_HORIZONTAL); - new Label(composite, SWT.NONE).setText(Messages - .getString("RPMExportPage.Patch_Tag")); //$NON-NLS-1$ - patchTag = new Text(composite, SWT.BORDER); - patchTag.setToolTipText(Messages - .getString("RPMExportPage.toolTip_Patch_Tag")); //$NON-NLS-1$ - - patchTag.setLayoutData(patchTagGridData); - - GridData pChangelogStampGridData = new GridData( - GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); - new Label(composite, SWT.NONE).setText(Messages - .getString("RPMExportPage.Patch_Changelog_Stamp")); //$NON-NLS-1$ - - patchChangeLogstamp = new Text(composite, SWT.BORDER); - patchChangeLogstamp.setLayoutData(pChangelogStampGridData); - patchTag.addModifyListener(trapTag); - patchChangeLogstamp.addModifyListener(trapPatch); - patchChangeLogstamp.setToolTipText(Messages - .getString("RPMExportPage.toolTip_Changelog_Stamp")); //$NON-NLS-1$ - - new Label(composite, SWT.NONE).setText(Messages - .getString("RPMExportPage.Patch_Changelog")); //$NON-NLS-1$ - - KeyListener patchChangelogListener = new KeyListener() { - public void keyPressed(KeyEvent e) { - handleEvent(null); - } - - public void keyReleased(KeyEvent e) { - handleEvent(null); - if (e.keyCode == 13) { - if (patchChangeLog.getCaretPosition() == patchChangeLog - .getCharCount()) - patchChangeLog.append("- "); //$NON-NLS-1$ - else if (patchChangeLog.getText( - patchChangeLog.getCaretPosition() - 1, - patchChangeLog.getCaretPosition() - 1).equals("\n")) //$NON-NLS-1$ - patchChangeLog.insert("- "); //$NON-NLS-1$ - } - } - }; - - GridData pChangelogGridData = new GridData( - GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); - - patchChangeLog = new Text(composite, SWT.BORDER | SWT.MULTI); - pChangelogGridData.heightHint = 7 * patchChangeLog.getLineHeight(); - patchChangeLog.setLayoutData(pChangelogGridData); - patchChangeLog.addKeyListener(patchChangelogListener); - patchChangeLog.setToolTipText(Messages - .getString("RPMExportPage.toolTip_Changelog")); //$NON-NLS-1$ - - } - - /** - * canFinish() - * - * Hot validation. Called to determine whether Finish - * button can be set to true - * @return boolean. true if finish can be activated - */ - public boolean canFinish() { - - // Is the patch tag empty - if (patchTag.getText().equals("")) { //$NON-NLS-1$ - setErrorMessage(null); - setDescription(Messages.getString("RPMExportPage_2.5")); //$NON-NLS-1$ - return false; - } - - // Is tag a duplicate or have spaces? - if (patchTagError) { - return false; - } - - else { - setErrorMessage(null); - setDescription(Messages.getString("RPMExportPage_2.4")); //$NON-NLS-1$ - } - - // Is the Changelog fields empty? - if (patchChangeLog.getText().equals("- ") | patchChangeLog.getText().equals("") | //$NON-NLS-1$ //$NON-NLS-2$ - patchChangeLog.getText().equals("-")) { - setDescription(Messages.getString("RPMExportPage_2.4")); //$NON-NLS-1$ - - return false; - } else if (patchTag.getText().equals("")) { - setErrorMessage(null); - setDescription(Messages.getString("RPMExportPage_2.5")); //$NON-NLS-1$ - return false; - } - - // Is the time stamp empty? - if (patchChangeLogstamp.getText().equals("")) { //$NON-NLS-1$ - - return false; - } - - setErrorMessage(null); - setDescription(Messages.getString("RPMExportPage_2.2")); //$NON-NLS-1$ - - return true; - } - - public String[] patchData() { - String[] patchDataList = new String[3]; - - patchDataList[0] = patchTag.getText(); - patchDataList[1] = patchChangeLogstamp.getText(); - patchDataList[2] = patchChangeLog.getText(); - - return patchDataList; - } - - public void handleEvent(Event e) { - setPageComplete(canFinish()); - } - - private String getHostName() { - String hostname; - try { - hostname = java.net.InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - return ""; //$NON-NLS-1$ - } - // Trim off superflous stuff from the hostname - int firstdot = hostname.indexOf("."); //$NON-NLS-1$ - int lastdot = hostname.lastIndexOf("."); //$NON-NLS-1$ - // If the two are equal, no need to trim name - if (firstdot == lastdot) { - return hostname; - } - String hosttemp = ""; //$NON-NLS-1$ - String hosttemp2 = hostname; - while (firstdot != lastdot) { - hosttemp = hosttemp2.substring(lastdot) + hosttemp; - hosttemp2 = hostname.substring(0, lastdot); - lastdot = hosttemp2.lastIndexOf("."); //$NON-NLS-1$ - } - return hosttemp.substring(1); - } - - /* - * This method gets the path to the spec file that will be used to create - * the rpm and gleans the patch names from it. - * @returns populated ArrayList if spec file found, null ArrayList if not - */ - - private ArrayList getPatchNames(String path_to_specfile) { - - File f = new File(path_to_specfile); - if (!f.exists()) { - return null; - } - ArrayList patch_names = new ArrayList(); - try { - FileReader sp_file = new FileReader(path_to_specfile); - StreamTokenizer st = new StreamTokenizer(sp_file); - - // Make sure numbers, colons and percent signs are considered valid - st.wordChars('a', 'z'); - st.wordChars('A', 'Z'); - st.wordChars(':', ':'); - st.wordChars('0', '9'); - st.wordChars('%', '%'); - st.wordChars('{', '}'); - st.wordChars('-', '-'); - st.wordChars('/', '/'); - st.wordChars('=', '='); - st.wordChars('.', '.'); - st.wordChars('_', '_'); - st.eolIsSignificant(true); - boolean found_patch = false; - - String new_word; - int token = st.nextToken(); - while (token != StreamTokenizer.TT_EOF) { - token = st.nextToken(); - - switch (token) { - - case StreamTokenizer.TT_WORD: - new_word = st.sval; - if (new_word.startsWith("Patch")) { //$NON-NLS-1$ - found_patch = true; - break; - } - if (new_word.endsWith(".patch") && found_patch) { //$NON-NLS-1$ - int i = new_word.lastIndexOf("-"); //$NON-NLS-1$ - int j = new_word.lastIndexOf(".patch"); //$NON-NLS-1$ - patch_names.add(new_word.substring(i + 1, j)); - found_patch = false; - break; - } - default: - found_patch = false; - break; - } - } - sp_file.close(); - } catch (IOException e) { - return null; - } - return patch_names; - } -} \ No newline at end of file Index: src/org/eclipse/cdt/rpm/ui/RPMExportWizard.java =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.ui/src/org/eclipse/cdt/rpm/ui/RPMExportWizard.java,v retrieving revision 1.2 diff -u -r1.2 RPMExportWizard.java --- src/org/eclipse/cdt/rpm/ui/RPMExportWizard.java 8 Nov 2004 21:42:28 -0000 1.2 +++ src/org/eclipse/cdt/rpm/ui/RPMExportWizard.java 18 May 2005 20:43:58 -0000 @@ -1,36 +1,28 @@ /* - * (c) 2004 Red Hat, Inc. + * (c) 2004, 2005 Red Hat, Inc. * * This program is open source software licensed under the * Eclipse Public License ver. 1 */ package org.eclipse.cdt.rpm.ui; -import org.eclipse.core.runtime.CoreException; +import java.lang.reflect.InvocationTargetException; +import org.eclipse.cdt.rpm.core.IRPMProject; +import org.eclipse.cdt.rpm.core.RPMExportDelta; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; - import org.eclipse.ui.IExportWizard; import org.eclipse.ui.IWorkbench; - -/** - * @author pmuldoon - * @version 1.0 - * - * - * Plug-in entry point. When the user chooses to export an SRPM ,the plug-in manager in Eclipse - * will invoke this class. This class extends Wizard and implements IExportWizard. - * - * The main plugin class to be used in the desktop. This is the "entrypoint" - * for the export rpm plug-in. - */ public class RPMExportWizard extends Wizard implements IExportWizard { - // Create a local reference to RPMExportPage - RPMExportPage mainPage; - RPMExportPage_2 patchPage; + private RPMExportPage mainPage; + private RPMExportPatchPage patchPage; private IStructuredSelection selection; + private IRPMProject rpmProject; + /** * @see org.eclipse.ui.IWorkbenchWizard#init(IWorkbench, IStructuredSelection) * @@ -43,14 +35,44 @@ selection = currentSelection; } - // We have elected to do the Finish button clickin in the RPMExportPage. So override - //the default and point to RPMExport finish() public boolean performFinish() { - try { - return mainPage.finish(patchPage.patchData()); - } catch (CoreException e) { + RPMExportDelta exportDelta = new RPMExportDelta(); + exportDelta.setVersion(mainPage.getSelectedVersion()); + exportDelta.setRelease(mainPage.getSelectedRelease()); + exportDelta.setSpecFile(mainPage.getSelectedSpecFile()); + if(mainPage.canGoNext()) { + exportDelta.setPatchName(patchPage.getSelectedPatchName()); + exportDelta.setChangelogEntry(patchPage.getSelectedChangelog()); + } + + // Create a new instance of the RPMExportOperation runnable + RPMExportOperation rpmExport = new RPMExportOperation(mainPage.getSelectedRPMProject(), + mainPage.getExportType(), exportDelta); + + // Run the export + try { + getContainer().run(true, true, rpmExport); + } catch (InvocationTargetException e1) { + // use ExceptionHandler? + return false; + } catch (InterruptedException e1) { + } + + MultiStatus status = rpmExport.getStatus(); + + if (!status.isOK()) { + ErrorDialog.openError(getContainer().getShell(), + Messages.getString( + "RPMExportPage.Errors_encountered_importing_SRPM"), //$NON-NLS-1$ + null, // no special message + status); + return false; } + + // Need to return some meaninful status. Should only return true if the wizard completed + // successfully. + return true; } public boolean canFinish() { @@ -59,7 +81,6 @@ } else if (mainPage.canFinish() && patchPage.canFinish()) { return true; } - return false; } @@ -67,7 +88,7 @@ public void addPages() { mainPage = new RPMExportPage(selection); addPage(mainPage); - patchPage = new RPMExportPage_2(); + patchPage = new RPMExportPatchPage(); addPage(patchPage); } } Index: src/org/eclipse/cdt/rpm/ui/SRPMImportOperation.java =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.ui/src/org/eclipse/cdt/rpm/ui/SRPMImportOperation.java,v retrieving revision 1.3 diff -u -r1.3 SRPMImportOperation.java --- src/org/eclipse/cdt/rpm/ui/SRPMImportOperation.java 18 Jan 2005 16:53:14 -0000 1.3 +++ src/org/eclipse/cdt/rpm/ui/SRPMImportOperation.java 18 May 2005 20:43:58 -0000 @@ -1,49 +1,36 @@ /* - * (c) 2004 Red Hat, Inc. + * (c) 2004, 2005 Red Hat, Inc. * * This program is open source software licensed under the * Eclipse Public License ver. 1 */ package org.eclipse.cdt.rpm.ui; -import org.eclipse.cdt.rpm.core.*; +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.eclipse.cdt.rpm.core.IRPMProject; +import org.eclipse.cdt.rpm.core.RPMProjectFactory; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Status; - import org.eclipse.jface.operation.IRunnableWithProgress; - import org.eclipse.ui.PlatformUI; -import java.lang.reflect.InvocationTargetException; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - /** - * @author pmuldoon - * * Import Operation Class for RPM plug-in. This allows us to abstract the operations * to a utility class which also inherits IRunnableWithProgress that allows use of * progress bar */ public class SRPMImportOperation implements IRunnableWithProgress { - // Class variable that are use for storage - // as they are passed into the constrcutor - private String srpmname; - private IProject project_name; - private boolean preserve_env; - private boolean keep_log; - private boolean applyPatches; - private boolean runAutoConf; + private IProject project; + private File sourceRPM; // Progressmonitor private IProgressMonitor monitor; @@ -57,16 +44,9 @@ * @param applyPatchesFlag - Apply patches on import * @param runAutoConfFlag - Run autoconf on import */ - public SRPMImportOperation( - IProject name, - String srpm_name, - boolean applyPatchesFlag, - boolean runAutoConfFlag) { - // Copy passed variables to constructor, to class variables - project_name = name; - srpmname = srpm_name; - applyPatches = applyPatchesFlag; - runAutoConf = runAutoConfFlag; + public SRPMImportOperation(IProject project, File sourceRPM) { + this.project = project; + this.sourceRPM = sourceRPM; } /** @@ -82,59 +62,20 @@ monitor = progressMonitor; rpm_errorTable = new ArrayList(); - SRPMImport srpmimport; - monitor.beginTask(Messages.getString("SRPMImportOperation.Starting"), //$NON-NLS-1$ totalWork); //$NON-NLS-1$ // Try to create an instance of the build class. try { - srpmimport = new SRPMImport(project_name.getLocation().toOSString(), srpmname); //$NON-NLS-1$ + IRPMProject rpmProject = RPMProjectFactory.getRPMProject(project); + monitor.worked(1); + monitor.setTaskName(Messages.getString("SRPMImportOperation.Importing_SRPM")); //$NON-NLS-1$ + rpmProject.importSourceRPM(sourceRPM); } catch (Exception e) { rpm_errorTable.add(e); return; } monitor.worked(1); - String rpm_release; - String rpm_version; - String usr_rpm_cmd = RPMCorePlugin.getDefault().getPreferenceStore().getString("IRpmConstants.RPM_CMD"); //$NON_NLS-1$ - - rpm_version = LinuxShellCmds.getInfo(usr_rpm_cmd + " --qf %{VERSION} -qp " + //$NON-NLS-1$ - srpmname); - rpm_release = LinuxShellCmds.getInfo(usr_rpm_cmd + " --qf %{RELEASE} -qp " + //$NON-NLS-1$; - srpmname); - // If the generated checksum, and the one in the srpmInfo file are the same - // then the project has not changed since last import and does not need a patch - - - // set state and options - srpmimport.setDoAutoconf(runAutoConf); - srpmimport.setDoPatches(applyPatches); - srpmimport.setRpm_release(rpm_release); - srpmimport.setRpm_version(rpm_version); - - monitor.setTaskName(Messages.getString("SRPMImportOperation.Importing_SRPM")); //$NON-NLS-1$ - - // execute import - try { - srpmimport.run(); - } catch (CoreException e) { - rpm_errorTable.add(e.getStatus()); - return; - } - - monitor.worked(1); - - // Refresh the workspace - IWorkspaceRoot myWorkspaceRoot = - ResourcesPlugin.getWorkspace().getRoot(); - - try { - myWorkspaceRoot.refreshLocal(2, null); - project_name.refreshLocal(2, null); - } catch (CoreException e1) { - rpm_errorTable.add(e1.getStatus()); - } } Index: src/org/eclipse/cdt/rpm/ui/SRPMImportPage.java =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.ui/src/org/eclipse/cdt/rpm/ui/SRPMImportPage.java,v retrieving revision 1.6 diff -u -r1.6 SRPMImportPage.java --- src/org/eclipse/cdt/rpm/ui/SRPMImportPage.java 18 Jan 2005 22:09:44 -0000 1.6 +++ src/org/eclipse/cdt/rpm/ui/SRPMImportPage.java 18 May 2005 20:43:58 -0000 @@ -1,5 +1,5 @@ /* - * (c) 2004 Red Hat, Inc. + * (c) 2004, 2005 Red Hat, Inc. * * This program is open source software licensed under the * Eclipse Public License ver. 1 @@ -19,9 +19,7 @@ import java.util.Iterator; import java.util.Vector; -import org.eclipse.cdt.core.CProjectNature; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectNature; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeListener; @@ -31,11 +29,9 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; - import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.WizardPage; - import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; @@ -51,14 +47,11 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Listener; - import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.NewProjectAction; /** - * @author pmuldoon - * * SRPMImportPage. Called by SRPMImportwizard. Class can not be subclassed * extends WizardPage and implements Listener (for events) * @@ -97,14 +90,8 @@ private IWorkbench workbench; - // Convienience SRPM import operation class - private SRPMImportOperation srpmImport; - // GUI Control variables private Combo sourceSRPM; - private Button applyPatch; - private Button runAutoConf; - private Button buildSource; private Button intoConfigured; private Button intoExisting; private List projectList; @@ -131,17 +118,20 @@ } - public String returnProject() { - String projSelect; - String[] projDetails = projectList.getSelection(); - - if (projDetails.length > 0) { - projSelect = projDetails[0]; - } else { - projSelect = ""; //$NON-NLS-1$ + private String getSelectedProjectName() { + String[] selections = projectList.getSelection(); + if (selections.length > 0) { + return selections[0]; } - - return projSelect; + return null; + } + + private File getSelectedSRPM() { + String srpmName = sourceSRPM.getText(); + if(srpmName.equals("") || srpmName == null) { //$NON-NLS-1$ + return null; + } + return new File(sourceSRPM.getText()); } public void createControl(Composite parent) { @@ -158,12 +148,11 @@ setControl(composite); // Create contols on the page - sourceRPMcombo(composite); + createSourceRPMCombo(composite); createProjectBox(composite); - createOptions(composite); } - protected void sourceRPMcombo(Composite parent) { + private void createSourceRPMCombo(Composite parent) { Group specGrid = new Group(parent, SWT.NONE); specGrid.setLayout(new GridLayout()); specGrid.setText(Messages.getString("SRPMImportPage.SRPM_Name")); //$NON-NLS-1$ @@ -216,29 +205,6 @@ srpmBrowse.addListener(SWT.FocusOut, this); } - protected void createOptions(Composite parent) { - //Create a group for the control and set up the layout. - Group group = new Group(parent, SWT.NONE); - group.setLayout(new GridLayout()); - group.setText(Messages.getString("SRPMImportPage.Build_Options")); //$NON-NLS-1$ - group.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | - GridData.HORIZONTAL_ALIGN_FILL)); - - // Create the build environment checkbox - applyPatch = new Button(group, SWT.CHECK); - applyPatch.setText(Messages.getString("SRPMImportPage.ApplyPatches")); //$NON-NLS-1$ - applyPatch.setSelection(true); - applyPatch.setToolTipText(Messages.getString( - "SRPMImportPage.toolTip_ApplyPatches")); //$NON-NLS-1$ - - runAutoConf = new Button(group, SWT.CHECK); - runAutoConf.setText(Messages.getString("SRPMImportPage.runAutoConf")); //$NON-NLS-1$ - runAutoConf.setSelection(true); - runAutoConf.setToolTipText(Messages.getString( - "SRPMImportPage.toolTip_runAutoConf")); //$NON-NLS-1$ - - } - /** * Method createProjectBox. * @param parent - parent widget @@ -247,7 +213,7 @@ * the list of current projects in the workspace * along with adding the option for a configured project */ - protected void createProjectBox(Composite parent) { + private void createProjectBox(Composite parent) { // Creates a control that enumerates all the projects in the current // Workspace and places them in a listbox. // Give the option of importing into an existing project or creating a new one @@ -315,33 +281,29 @@ for (int a = 0; a < internalProjectList.length; a++) { - - try { - IProjectNature cNature = internalProjectList[a].getNature(CProjectNature.C_NATURE_ID); - if (cNature!=null) - projectList.add(internalProjectList[a].getName()); - if (isSelection && internalProjectList[a].equals(selectedProject)) - projectList.setSelection(a); - } catch (CoreException e) { - + projectList.add(internalProjectList[a].getName()); + if (isSelection && internalProjectList[a].equals(selectedProject)) { + projectList.setSelection(a); } } - if (projectList.getItemCount() == 0) //there were no C/C++ projects + if (projectList.getItemCount() == 0) //there were no projects { projectList.add(Messages.getString( - "RPMPage.No_c/c++_projects_found_2")); //$NON-NLS-1$ + "SRPMImportPage.No_projects_found")); //$NON-NLS-1$ intoExisting.setEnabled(false); // Can't very well import into an existing projectList.setEnabled(false); // project now can we? intoConfigured.setSelection(true); isSelection = true; // we don't want select the "RPMPage.No_c/c++_projects_found_2" } - else - intoExisting.setSelection(true); - - if (!isSelection) //if none is selected select first project + else { + intoExisting.setSelection(true); + } + + if (!isSelection) { //if none is selected select first project projectList.setSelection(0); - else + } + else { projectList.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { handleEvent(null); @@ -350,6 +312,7 @@ public void widgetDefaultSelected(SelectionEvent e) { } }); + } intoExisting.addListener(SWT.Selection, this); intoConfigured.addListener(SWT.Selection, this); @@ -385,31 +348,16 @@ public boolean canFinish() { // Make sure project has been selected or the user // has decided to configure a new one instead - if (intoConfigured.getSelection()) - { - return true; - } - else if (returnProject().equals("")) { //$NON-NLS-1$ + if (getSelectedProjectName() == null && !intoConfigured.getSelection()) { return false; } - // Make sure an rpm name has been provided + // Make sure an srpm name has been provided if (sourceSRPM.getText().equals("")) { //$NON-NLS-1$ return false; } - - return true; - } - - /** - * validateFinish() - * Second validation step. Validates minimum conditions - * for starting import - * @return boolean - true for go; false for problems - */ - public boolean validateFinish(){ - File srpmExists = new File(sourceSRPM.getText()); - if (!srpmExists.isFile()){ + File srpm = new File(sourceSRPM.getText()); + if (!srpm.isFile()){ setErrorMessage(Messages.getString("SRPMImportPage.Source_not_Valid")); return false; } @@ -418,13 +366,10 @@ setErrorMessage(Messages.getString("SRPMImportPage.No_src_rpm_ext")); return false; } - + return true; - - } - /** * finish() * @@ -435,9 +380,6 @@ public boolean finish() throws CoreException { IPath detailedProjectLocation = null; IProject detailedProject; - // Check second step validation - if (!validateFinish()) - return false; // Get the handle to the current activate Workspace IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); @@ -452,8 +394,12 @@ // in the returned array is valid. detailedProject = workspaceRoot.getProject(selectedProject[0]); } - else + else { detailedProject = getNewProject(); + if(detailedProject == null) { + return false; + } + } // Add this SRPM to srpmList for (int i = 0; i < srpmVector.size(); i++) { // There can only be one occurance @@ -465,19 +411,18 @@ } srpmVector.add((String)(sourceSRPM.getText())); - // Create a new instance of SRPMImportOperation build class + SRPMImportOperation srpmImportOp = null; try { - srpmImport = new SRPMImportOperation(detailedProject, - sourceSRPM.getText(), applyPatch.getSelection(), - runAutoConf.getSelection()); - getContainer().run(true, true, srpmImport); + srpmImportOp = new SRPMImportOperation(detailedProject, + getSelectedSRPM()); + getContainer().run(true, true, srpmImportOp); } catch (Exception e) { setErrorMessage(e.toString()); return false; } // Get the status of the operation - IStatus srpmImportStatus = srpmImport.getStatus(); + IStatus srpmImportStatus = srpmImportOp.getStatus(); // If the status does not come back clean, open error dialog if (!srpmImportStatus.isOK()) { Index: src/org/eclipse/cdt/rpm/ui/SRPMImportwizard.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/ui/SRPMImportwizard.java diff -N src/org/eclipse/cdt/rpm/ui/SRPMImportwizard.java --- src/org/eclipse/cdt/rpm/ui/SRPMImportwizard.java 18 Jan 2005 16:53:14 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,86 +0,0 @@ -/* - * (c) 2004 Red Hat, Inc. - * - * This program is open source software licensed under the - * Eclipse Public License ver. 1 -*/ - -/** - * @author pmuldoon - * @version 1.0 - * - * - * Plug-in entry point. When the user chooses to import an RPM the plug-in manager in Eclipse - * will invoke this class. This class extends Wizard and implements IImportWizard. - */ -package org.eclipse.cdt.rpm.ui; - -import org.eclipse.core.runtime.CoreException; - -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; - -import org.eclipse.ui.IImportWizard; -import org.eclipse.ui.IWorkbench; - - -/** - * @author pmuldoon - * - * The main plugin class to be used in the desktop. This is the "entrypoint" - * for the import rpm plug-in. - */ -public class SRPMImportwizard extends Wizard implements IImportWizard { - private IWorkbench workbench; - private IStructuredSelection selection; - - // Create a local reference to SRPMImportPage - private SRPMImportPage mainPage; - - /** - * @see org.eclipse.ui.IWorkbenchWizard#init(IWorkbench, IStructuredSelection) - */ - - //Basic constructor. Don't do much, just print out debug, and set progress - //monitor status to true - public void init(IWorkbench workbench, IStructuredSelection currentSelection) { - this.workbench = workbench; - selection = currentSelection; - setWindowTitle(Messages.getString("SRPMImportwizard.Import_an_SRPM")); //$NON-NLS-1$ - setNeedsProgressMonitor(true); - } - - /** - * @see org.eclipse.jface.wizard.IWizard#performFinish() - */ - - // We have elected to do the Finish button clickin in the SRPMImportPage. So override - //the default and point to SRPMImport finish() - public boolean performFinish() { - try { - return mainPage.finish(); - } catch (CoreException e) { - return false; - } - } - - /** - * @see org.eclipse.jface.wizard.IWizard#canFinish() - * - * Select to finish validation in the SRPMImportPage - */ - public boolean canFinish() { - return mainPage.canFinish(); - } - - /** - * @see org.eclipse.jface.wizard.IWizard#addPages() - */ - - // Add the SRPMImportPage as the only page in this wizard. - public void addPages() { - mainPage = new SRPMImportPage(workbench, selection); - addPage(mainPage); - super.addPages(); - } -} Index: src/org/eclipse/cdt/rpm/ui/rpm_strings.properties =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.ui/src/org/eclipse/cdt/rpm/ui/rpm_strings.properties,v retrieving revision 1.4 diff -u -r1.4 rpm_strings.properties --- src/org/eclipse/cdt/rpm/ui/rpm_strings.properties 18 Jan 2005 22:09:44 -0000 1.4 +++ src/org/eclipse/cdt/rpm/ui/rpm_strings.properties 18 May 2005 20:43:59 -0000 @@ -30,7 +30,7 @@ RPMExportPage.Makefile_lc=makefile RPMExportPage.specify_version_and_release_if_SPEC_file_not_provided=You must specify a version and release if a SPEC file is not provided RPMExportPage.selected_project_does_not_have_Makefile=The selected project does not have a Makefile -RPMExportPage.Cannont_find_file=Cannont find the file: +RPMExportPage.Cannont_find_file=Cannot find the file: RPMExportPage.Core_Exception=Core Exception: RPMExportPage.SPEC_file=SPEC file RPMExportPage.Version=Version: @@ -50,10 +50,10 @@ RPMexportwiz.Export_an_RPM_title=Export an RPM -SRPMImportPage.Configured_New_Project=Check out as a project &configured using the New Project Wizard +SRPMImportPage.Configured_New_Project=Import into project &configured using the New Project Wizard SRPMImportPage.Project_does_not_exist=Project does not exist. Please select a project SRPMImportPage.Problems_identifying_import_source_directory=Problems identifying import source directory -SRPMImportPage.SRPM_Name=SRPM Name +SRPMImportPage.SRPM_Name=SRPM SRPMImportPage.Import_SRPM=Import SRPM SRPMImportPage.Select_project_to_import=Select a project to import an SRPM into SRPMImportPage.No_objects_selected_to_be_imported=No objects have been selected to be imported @@ -71,6 +71,7 @@ SRPMImportPage.Build_Options=Build Options SRPMImportPage.import_srpm_into=Import SRPM into... SRPMImportwizard.Import_an_SRPM=Import an SRPM +SRPMImportPage.No_projects_found=No projects found SRPMImportPage.toolTip_ApplyPatches=Typically, an SRPM is comprised of a source tarball\nand a set of patches that are applied to that tarball.\nTherefore changes are made to the SRPM in the form of\npatches, while leaving the original source 'pristine'\n\nThis option allows you to import the unpatched\n'pristine' source code, and not apply patches @@ -109,7 +110,7 @@ RPMExportPage_2.0=Enter patch/changelog information for spec file RPMExportPage_2.1=Patch Tag cannot have a special character\! RPMExportPage_2.2=Enter patch/changelog information for spec file -RPMExportPage_2.3=Patch tag is not unique\! +RPMExportPage_2.3=Patch name is not unique RPMExportPage_2.4=Enter changelog entry info RPMExportPage_2.5=Enter a patch tag name RPMExportPage.Generate_patch=Generate patch (against previously imported SRPM) @@ -135,13 +136,13 @@ RPMExportPage.toolTip_file_navigator=Click to open a file navigator to select an external SPEC file RPMExportPage.toolTip_Version=The Version associated with this RPM.\nChange the version here to change the\nversion of the RPM. RPMExportPage.toolTip_Release=The Release associated with this RPM.\nChange the release here to change the release number of the RPM. -RPMExportPage.toolTip_Patch_Tag=Patch Tag - unique identifier for patch. Combined with the\npackage name and the version number to form the patch name. \n\nExample:\npump-1.1-exampletag.patch. \n\nThe 'exampletag' would be your tag. +RPMExportPage.toolTip_Patch_Name=Patch Name - unique identifier for patch. RPMExportPage.toolTip_Changelog_Stamp=Changelog Date - Date stamp for the changelog entry. \n\nExample: * Wed Oct 12 2003 -- John Doe RPMExportPage.toolTip_Changelog=Changelog Comment - short descriptive summary of change made in patch\n\nExample: - Fixed bugzilla entry #125642 RPMPage.Browse=Browse... RPMPage.Select_a_project=Select a project ... -RPMPage.No_c/c++_projects_found_2=---> No c/c++ projects found <--- +RPMPage.No_RPM_projects_found=No RPM projects found RPMExportWizard.Export_an_SRPM=Export an SRPM @@ -153,4 +154,7 @@ SRPMImportOperation.2=Undefined Error\! SRPMImportOperation.3=Source RPM Import Error SRPMImportOperation.Open_SRPM_Errors=Import SRPM Errors= -SRPMImportOperation.Importing_SRPM=Importing SRPM \ No newline at end of file +SRPMImportOperation.Importing_SRPM=Importing SRPM + +ExceptionDialog.seeErrorLogMessage=An exception occurred. See error log for details. +ErrorDialog.title=Error \ No newline at end of file Index: src/org/eclipse/cdt/rpm/ui/logviewer/LogReader.java =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.ui/src/org/eclipse/cdt/rpm/ui/logviewer/LogReader.java,v retrieving revision 1.1 diff -u -r1.1 LogReader.java --- src/org/eclipse/cdt/rpm/ui/logviewer/LogReader.java 13 Oct 2004 02:31:16 -0000 1.1 +++ src/org/eclipse/cdt/rpm/ui/logviewer/LogReader.java 18 May 2005 20:43:59 -0000 @@ -1,5 +1,5 @@ /* - * (c) 2004 Red Hat, Inc. + * (c) 2004, 2005 Red Hat, Inc. * * This program is open source software licensed under the * Eclipse Public License ver. 1 @@ -8,6 +8,7 @@ package org.eclipse.cdt.rpm.ui.logviewer; import org.eclipse.cdt.rpm.core.RPMCorePlugin; +import org.eclipse.core.runtime.CoreException; import java.io.BufferedReader; import java.io.File; @@ -94,12 +95,12 @@ } public String getLogFile() { - String wksp_path = RPMCorePlugin.getDefault().getPreferenceStore() - .getString("IRpmConstants.RPM_WORK_AREA"); //$NON-NLS-1$ - String log_name = RPMCorePlugin.getDefault().getPreferenceStore() - .getString("IRpmConstants.RPM_DISPLAYED_LOG_NAME"); //$NON-NLS-1$ - String log_file_name = wksp_path + file_sep + log_name + file_sep; - File f = new File(log_file_name); + File f = null; + try { + f = RPMCorePlugin.getDefault().getExternalLogFile(); + } catch(CoreException e) { + // Too bad. + } if (!f.exists()) { return null; } Index: src/org/eclipse/cdt/rpm/ui/preferences/RPMPluginPreferencesPage.java =================================================================== RCS file: /home/tools/org.eclipse.cdt-contrib/org.eclipse.cdt.rpm/org.eclipse.cdt.rpm.ui/src/org/eclipse/cdt/rpm/ui/preferences/RPMPluginPreferencesPage.java,v retrieving revision 1.3 diff -u -r1.3 RPMPluginPreferencesPage.java --- src/org/eclipse/cdt/rpm/ui/preferences/RPMPluginPreferencesPage.java 26 Jan 2005 20:08:58 -0000 1.3 +++ src/org/eclipse/cdt/rpm/ui/preferences/RPMPluginPreferencesPage.java 18 May 2005 20:43:59 -0000 @@ -1,5 +1,5 @@ /* - * (c) 2004 Red Hat, Inc. + * (c) 2004, 2005 Red Hat, Inc. * * This program is open source software licensed under the * Eclipse Public License ver. 1 @@ -27,6 +27,7 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.cdt.rpm.core.IRPMConstants; import org.eclipse.cdt.rpm.core.RPMCorePlugin; @@ -38,28 +39,12 @@ implements IWorkbenchPreferencePage, SelectionListener, ModifyListener { private Button dateFormat; - private Text rpmMacrosFileNameField; - private Text rpmResourceFileNameField; - private Text rpmWorkAreaField; - private Text rpmLogNameField; - private Text displayedRpmLogNameField; - private Text specFilePrefixField; - private Text srpmInfoFileNameField; - private Text rpmShellScriptFileNameField; private Text emailField; private Text nameField; - private Text WorkAreaField; - private Text makeField; private Text rpmField; private Text rpmbuildField; - private Text chmodField; - private Text cpField; private Text diffField; - private Text tarField; - - - static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ private Button createCheckBox(Composite group, String label) { Button button = new Button(group, SWT.CHECK | SWT.LEFT); @@ -156,12 +141,8 @@ gridData.grabExcessVerticalSpace = false; vfiller.setLayoutData(gridData); } - protected IPreferenceStore doGetPreferenceStore() { - return RPMCorePlugin.getDefault().getPreferenceStore(); - } public void init(IWorkbench workbench){ - initializeDefaultPreferences(getPreferenceStore()); } private String getUserName() @@ -169,79 +150,37 @@ return System.getProperty ( "user.name" ); //$NON-NLS-1$ } - - protected void initializeDefaultPreferences(IPreferenceStore store) - { - store.setDefault("IRpmConstants.RPM_WORK_AREA","/var/tmp"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.USER_WORK_AREA",file_sep+"rpm_workarea"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.RPM_DISPLAYED_LOG_NAME",".logfilename_" + //$NON-NLS-1$ //$NON-NLS-2$ - getUserName()); - store.setDefault("IRpmConstants.SPEC_FILE_PREFIX","eclipse_"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.SRPM_INFO_FILE",file_sep+".srpminfo"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.RPM_SHELL SCRIPT","rpmshell.sh"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.RPM_LOG_NAME","rpmbuild.log"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.RPM_RESOURCE_FILE",".rpmrc"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.RPM_MACROS_FILE",".rpm_macros"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.AUTHOR_NAME",getUserName()); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.AUTHOR_EMAIL",getUserName()+"@" + RPMCorePlugin.getHostName()); //$NON-NLS-1$ //$NON-NLS-2$ - - store.setDefault("IRpmConstants.MAKE_CMD", "/usr/bin/make"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.RPM_CMD", "/bin/rpm"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.RPMBUILD_CMD", "/usr/bin/rpmbuild"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.CHMOD_CMD", "/bin/chmod"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.CP_CMD", "/bin/cp"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.DIFF_CMD", "/usr/bin/diff"); //$NON-NLS-1$ //$NON-NLS-2$ - store.setDefault("IRpmConstants.TAR_CMD", "/bin/tar"); //$NON-NLS-1$ //$NON-NLS-2$ - } private void initializeDefaults() { - IPreferenceStore store = getPreferenceStore(); + IPreferenceStore store = RPMCorePlugin.getDefault().getPreferenceStore(); - emailField.setText(store.getDefaultString("IRpmConstants.AUTHOR_EMAIL")); //$NON-NLS-1$ - nameField.setText(store.getDefaultString("IRpmConstants.AUTHOR_NAME")); //$NON-NLS-1$ - rpmWorkAreaField.setText(store.getDefaultString("IRpmConstants.RPM_WORK_AREA")); //$NON-NLS-1$ - makeField.setText(store.getDefaultString("IRpmConstants.MAKE_CMD")); //$NON-NLS-1$ - rpmField.setText(store.getDefaultString("IRpmConstants.RPM_CMD")); //$NON-NLS-1$ - rpmbuildField.setText(store.getDefaultString("IRpmConstants.RPMBUILD_CMD")); //$NON-NLS-1$ - chmodField.setText(store.getDefaultString("IRpmConstants.CHMOD_CMD")); //$NON-NLS-1$ - cpField.setText(store.getDefaultString("IRpmConstants.CP_CMD")); //$NON-NLS-1$ - diffField.setText(store.getDefaultString("IRpmConstants.DIFF_CMD")); //$NON-NLS-1$ - tarField.setText(store.getDefaultString("IRpmConstants.TAR_CMD")); //$NON-NLS-1$ + emailField.setText(store.getDefaultString(IRPMConstants.AUTHOR_EMAIL)); + nameField.setText(store.getDefaultString(IRPMConstants.AUTHOR_NAME)); + rpmField.setText(store.getDefaultString(IRPMConstants.RPM_CMD)); + rpmbuildField.setText(store.getDefaultString(IRPMConstants.RPMBUILD_CMD)); + diffField.setText(store.getDefaultString(IRPMConstants.DIFF_CMD)); - storeValues(); } - private void initializeValues() - { - IPreferenceStore store = getPreferenceStore(); - - rpmWorkAreaField.setText(store.getString("IRpmConstants.RPM_WORK_AREA")); //$NON-NLS-1$ - emailField.setText(store.getString("IRpmConstants.AUTHOR_EMAIL")); //$NON-NLS-1$ - nameField.setText(store.getString("IRpmConstants.AUTHOR_NAME")); //$NON-NLS-1$ - makeField.setText(store.getString("IRpmConstants.MAKE_CMD")); //$NON-NLS-1$ - rpmField.setText(store.getString("IRpmConstants.RPM_CMD")); //$NON-NLS-1$ - rpmbuildField.setText(store.getString("IRpmConstants.RPMBUILD_CMD")); //$NON-NLS-1$ - chmodField.setText(store.getString("IRpmConstants.CHMOD_CMD")); //$NON-NLS-1$ - cpField.setText(store.getString("IRpmConstants.CP_CMD")); //$NON-NLS-1$ - diffField.setText(store.getString("IRpmConstants.DIFF_CMD")); //$NON-NLS-1$ - tarField.setText(store.getString("IRpmConstants.TAR_CMD")); //$NON-NLS-1$ - } - + private void initializeValues() { + IPreferenceStore store = RPMCorePlugin.getDefault().getPreferenceStore(); + + emailField.setText(store.getString(IRPMConstants.AUTHOR_EMAIL)); + nameField.setText(store.getString(IRPMConstants.AUTHOR_NAME)); + rpmField.setText(store.getString(IRPMConstants.RPM_CMD)); + rpmbuildField.setText(store.getString(IRPMConstants.RPMBUILD_CMD)); + diffField.setText(store.getString(IRPMConstants.DIFF_CMD)); + } private void storeValues() { - IPreferenceStore store = getPreferenceStore(); + IPreferenceStore store = RPMCorePlugin.getDefault().getPreferenceStore(); - store.setValue("IRpmConstants.RPM_WORK_AREA",rpmWorkAreaField.getText()); //$NON-NLS-1$ - store.setValue("IRpmConstants.AUTHOR_NAME",nameField.getText()); //$NON-NLS-1$ - store.setValue("IRpmConstants.AUTHOR_EMAIL",emailField.getText()); //$NON-NLS-1$ - store.setValue("IRpmConstants.RPM_CMD", rpmField.getText()); //$NON-NLS-1$ - store.setValue("IRpmConstants.RPMBUILD_CMD", rpmbuildField.getText()); //$NON-NLS-1$ - store.setValue("IRpmConstants.TAR_CMD", tarField.getText()); //$NON-NLS-1$ - store.setValue("IRpmConstants.MAKE_CMD", makeField.getText()); //$NON-NLS-1$ - store.setValue("IRpmConstants.CHMOD_CMD", chmodField.getText()); //$NON-NLS-1$ - store.setValue("IRpmConstants.CP_CMD", cpField.getText()); //$NON-NLS-1$ - store.setValue("IRpmConstants.DIFF_CMD", diffField.getText()); //$NON-NLS-1$ + store.setValue(IRPMConstants.AUTHOR_NAME, nameField.getText()); + store.setValue(IRPMConstants.AUTHOR_EMAIL, emailField.getText()); + store.setValue(IRPMConstants.RPM_CMD, rpmField.getText()); + store.setValue(IRPMConstants.RPMBUILD_CMD, rpmbuildField.getText()); + store.setValue(IRPMConstants.DIFF_CMD, diffField.getText()); } public void modifyText(ModifyEvent event) { @@ -285,9 +224,6 @@ createLabel(userPrefs, "Author Email: "); //$NON-NLS-1$ emailField = createTextField(userPrefs); - createLabel(userPrefs, "RPM Work Area: "); //$NON-NLS-1$ - rpmWorkAreaField = createTextField(userPrefs); - createSpacer(mainComposite, 2); Group shellPrefs = new Group(mainComposite, SWT.NONE); @@ -309,31 +245,11 @@ createLabel(shellPrefs, title + spacer); rpmbuildField = createTextField(shellPrefs); createBrowseButton(shellPrefs, rpmbuildField, title); - - title = "make"; //$NON-NLS-1$ - createLabel(shellPrefs, title + spacer); - makeField = createTextField(shellPrefs); - createBrowseButton(shellPrefs, makeField, title); title = "diff"; //$NON-NLS-1$ createLabel(shellPrefs, title + spacer); diffField = createTextField(shellPrefs); createBrowseButton(shellPrefs, diffField, title); - - title = "tar"; //$NON-NLS-1$ - createLabel(shellPrefs, title + spacer); - tarField = createTextField(shellPrefs); - createBrowseButton(shellPrefs, tarField, title); - - title = "chmod"; //$NON-NLS-1$ - createLabel(shellPrefs, title + spacer); - chmodField = createTextField(shellPrefs); - createBrowseButton(shellPrefs, chmodField, title); - - title = "cp"; //$NON-NLS-1$ - createLabel(shellPrefs, title + spacer); - cpField = createTextField(shellPrefs); - createBrowseButton(shellPrefs, cpField, title); initializeValues(); Index: src/org/eclipse/cdt/rpm/ui/IRPMUIConstants.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/ui/IRPMUIConstants.java diff -N src/org/eclipse/cdt/rpm/ui/IRPMUIConstants.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/rpm/ui/IRPMUIConstants.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,22 @@ +/* + * (c) 2005 Red Hat, Inc. + * + * This program is open source software licensed under the + * Eclipse Public License ver. 1 + */ + +package org.eclipse.cdt.rpm.ui; + +public interface IRPMUIConstants { + + public static final String FILE_SEP = System.getProperty("file.separator"); //$NON-NLS-1$ + + public static final String LINE_SEP = System.getProperty("line.separator"); //$NON-NLS-1$ + + public static final int BUILD_ALL = 1; + + public static final int BUILD_BINARY = 2; + + public static final int BUILD_SOURCE = 3; + +} Index: src/org/eclipse/cdt/rpm/ui/RPMExportPatchPage.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/ui/RPMExportPatchPage.java diff -N src/org/eclipse/cdt/rpm/ui/RPMExportPatchPage.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/rpm/ui/RPMExportPatchPage.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,290 @@ +/* + * (c) 2004, 2005 Red Hat, Inc. + * + * This program is open source software licensed under the + * Eclipse Public License ver. 1 + */ + +/** + * @author pmuldoon + * @version 1.0 + * + * S/RPM export page 2. Defines the patch page that is shown to the user when they choose + * to export to an SRPM and patch. Defines the UI elements shown, and the basic validation (need to add to + * this) + */ +package org.eclipse.cdt.rpm.ui; + +import java.net.UnknownHostException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; + +import org.eclipse.cdt.rpm.core.IRPMConstants; +import org.eclipse.cdt.rpm.core.RPMCorePlugin; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; + +public class RPMExportPatchPage extends WizardPage implements Listener { + // Checkbox Buttons + private Button generatePatch; + + // Patch Fields + private Text patchTag; + + private Text patchChangeLog; + + private Text patchChangeLogstamp; + + private boolean first_spec = true; + + private String path_to_specfile_save = null; + + private String last_gettext = ""; //$NON-NLS-1$ + + private ArrayList patch_names; + + private boolean firstTag = true; + + private boolean patchTagError; + + private final String valid_char_list = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"; //$NON-NLS-1$ + + static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ + + /** + * @see java.lang.Object#Object() + * + * Constructor for RPMExportPage class + */ + public RPMExportPatchPage() { + super( + Messages.getString("RPMExportPage.Export_SRPM"), //$NON-NLS-1$ + Messages.getString("RPMExportPage.Export_SRPM_from_project"), null); //$NON-NLS-1$ //$NON-NLS-2$ + setDescription(Messages.getString("RPMExportPage_2.0")); //$NON-NLS-1$ + patch_names = new ArrayList(); + } + + /** + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite) + * + * Parent control. Creates the listbox, Destination box, and options box + * + */ + public void createControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NULL); + // Create a layout for the wizard page + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); + setControl(composite); + + // Create contols on the page + createPatchFields(composite); + populatePatchInfo(); + } + + /** + * Method populatePatchInfo + * + * Populate the patch widgets with data + */ + private void populatePatchInfo() { + + String userName = RPMCorePlugin.getDefault().getPreferenceStore() + .getString(IRPMConstants.AUTHOR_NAME); //$NON-NLS-1$ + String userEmail = RPMCorePlugin.getDefault().getPreferenceStore() + .getString(IRPMConstants.AUTHOR_EMAIL); //$NON-NLS-1$ + + // Populate the changeLog + Date today = new Date(); + SimpleDateFormat df = new SimpleDateFormat("E MMM dd yyyy"); //$NON-NLS-1$ + + patchChangeLogstamp.setText("* " + df.format(today) + //$NON-NLS-1$ + " -- " + userName + " <" + userEmail + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + patchChangeLog.setText("- "); //$NON-NLS-1$ + } + + /** + * Method createGenPatchFields + * + * Create the patch generation widgets + */ + private void createPatchFields(Composite parent) { + Group group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout()); + group.setText(Messages.getString("RPMExportPage.Patch_Options")); //$NON-NLS-1$ + group.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL + | GridData.HORIZONTAL_ALIGN_FILL)); + + Composite composite = new Composite(group, SWT.NONE); + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.GRAB_HORIZONTAL)); + + ModifyListener trapPatch = new ModifyListener() { + + public void modifyText(ModifyEvent e) { + handleEvent(null); + } + }; + + GridData patchTagGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.GRAB_HORIZONTAL); + new Label(composite, SWT.NONE).setText(Messages + .getString("RPMExportPage.Patch_Name")); //$NON-NLS-1$ + patchTag = new Text(composite, SWT.BORDER); + patchTag.setToolTipText(Messages + .getString("RPMExportPage.toolTip_Patch_Tag")); //$NON-NLS-1$ + + patchTag.setLayoutData(patchTagGridData); + + GridData pChangelogStampGridData = new GridData( + GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); + new Label(composite, SWT.NONE).setText(Messages + .getString("RPMExportPage.Patch_Changelog_Stamp")); //$NON-NLS-1$ + + patchChangeLogstamp = new Text(composite, SWT.BORDER); + patchChangeLogstamp.setLayoutData(pChangelogStampGridData); + //patchTag.addModifyListener(trapTag); + patchChangeLogstamp.addModifyListener(trapPatch); + patchChangeLogstamp.setToolTipText(Messages + .getString("RPMExportPage.toolTip_Changelog_Stamp")); //$NON-NLS-1$ + + new Label(composite, SWT.NONE).setText(Messages + .getString("RPMExportPage.Patch_Changelog")); //$NON-NLS-1$ + + KeyListener patchChangelogListener = new KeyListener() { + public void keyPressed(KeyEvent e) { + handleEvent(null); + } + + public void keyReleased(KeyEvent e) { + handleEvent(null); + if (e.keyCode == 13) { + if (patchChangeLog.getCaretPosition() == patchChangeLog + .getCharCount()) + patchChangeLog.append("- "); //$NON-NLS-1$ + else if (patchChangeLog.getText( + patchChangeLog.getCaretPosition() - 1, + patchChangeLog.getCaretPosition() - 1).equals("\n")) //$NON-NLS-1$ + patchChangeLog.insert("- "); //$NON-NLS-1$ + } + } + }; + + GridData pChangelogGridData = new GridData( + GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); + + patchChangeLog = new Text(composite, SWT.BORDER | SWT.MULTI); + pChangelogGridData.heightHint = 7 * patchChangeLog.getLineHeight(); + patchChangeLog.setLayoutData(pChangelogGridData); + patchChangeLog.addKeyListener(patchChangelogListener); + patchChangeLog.setToolTipText(Messages + .getString("RPMExportPage.toolTip_Changelog")); //$NON-NLS-1$ + + } + + /** + * canFinish() + * + * Hot validation. Called to determine whether Finish + * button can be set to true + * @return boolean. true if finish can be activated + */ + public boolean canFinish() { + + // Is the patch tag empty + if (patchTag.getText().equals("")) { //$NON-NLS-1$ + setErrorMessage(null); + setDescription(Messages.getString("RPMExportPage_2.5")); //$NON-NLS-1$ + return false; + } + + // Is tag a duplicate or have spaces? + if (patchTagError) { + return false; + } + + else { + setErrorMessage(null); + setDescription(Messages.getString("RPMExportPage_2.4")); //$NON-NLS-1$ + } + + // Is the Changelog fields empty? + if (patchChangeLog.getText().equals("- ") | patchChangeLog.getText().equals("") | //$NON-NLS-1$ //$NON-NLS-2$ + patchChangeLog.getText().equals("-")) { + setDescription(Messages.getString("RPMExportPage_2.4")); //$NON-NLS-1$ + + return false; + } else if (patchTag.getText().equals("")) { + setErrorMessage(null); + setDescription(Messages.getString("RPMExportPage_2.5")); //$NON-NLS-1$ + return false; + } + + // Is the time stamp empty? + if (patchChangeLogstamp.getText().equals("")) { //$NON-NLS-1$ + + return false; + } + + setErrorMessage(null); + setDescription(Messages.getString("RPMExportPage_2.2")); //$NON-NLS-1$ + + return true; + } + + public String getSelectedPatchName() { + return patchTag.getText(); + } + + public String getSelectedChangelog() { + return patchChangeLogstamp.getText() + IRPMUIConstants.LINE_SEP + + patchChangeLog.getText() + IRPMUIConstants.LINE_SEP + + IRPMUIConstants.LINE_SEP; + } + + public void handleEvent(Event e) { + setPageComplete(canFinish()); + } + + private String getHostName() { + String hostname; + try { + hostname = java.net.InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + return ""; //$NON-NLS-1$ + } + // Trim off superflous stuff from the hostname + int firstdot = hostname.indexOf("."); //$NON-NLS-1$ + int lastdot = hostname.lastIndexOf("."); //$NON-NLS-1$ + // If the two are equal, no need to trim name + if (firstdot == lastdot) { + return hostname; + } + String hosttemp = ""; //$NON-NLS-1$ + String hosttemp2 = hostname; + while (firstdot != lastdot) { + hosttemp = hosttemp2.substring(lastdot) + hosttemp; + hosttemp2 = hostname.substring(0, lastdot); + lastdot = hosttemp2.lastIndexOf("."); //$NON-NLS-1$ + } + return hosttemp.substring(1); + } +} Index: src/org/eclipse/cdt/rpm/ui/RPMUIPlugin.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/ui/RPMUIPlugin.java diff -N src/org/eclipse/cdt/rpm/ui/RPMUIPlugin.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/rpm/ui/RPMUIPlugin.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,122 @@ +/* + * (c) 2005 Red Hat, Inc. + * + * This program is open source software licensed under the + * Eclipse Public License ver. 1 +*/ +package org.eclipse.cdt.rpm.ui; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class RPMUIPlugin extends AbstractUIPlugin { + //The shared instance. + private static RPMUIPlugin plugin; + //Resource bundle. + private ResourceBundle resourceBundle; + + public static final String ID = "org.eclipse.cdt.rpm.ui"; //$NON-NLS-1$ + + /** + * The constructor. + */ + public RPMUIPlugin() { + super(); + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + resourceBundle = null; + } + + /** + * Returns the shared instance. + */ + public static RPMUIPlugin getDefault() { + return plugin; + } + + /** + * Returns the string from the plugin's resource bundle, + * or 'key' if not found. + */ + public static String getResourceString(String key) { + ResourceBundle bundle = RPMUIPlugin.getDefault().getResourceBundle(); + try { + return (bundle != null) ? bundle.getString(key) : key; + } catch (MissingResourceException e) { + return key; + } + } + + /** + * Returns the plugin's resource bundle, + */ + public ResourceBundle getResourceBundle() { + try { + if (resourceBundle == null) + resourceBundle = ResourceBundle.getBundle("rpmui.RpmuiPluginResources"); + } catch (MissingResourceException x) { + resourceBundle = null; + } + return resourceBundle; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path. + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return AbstractUIPlugin.imageDescriptorFromPlugin("rpmui", path); + } + + public void log(Throwable e) { + log(new Status(IStatus.ERROR, ID, IStatus.ERROR, "Error", e)); //$NON-NLS-1$ + } + + public void log(IStatus status) { + getLog().log(status); + } + + public void logErrorMessage(String message) { + log(new Status(IStatus.ERROR, ID, 1, message, null)); + } + + public static Shell getActiveWorkbenchShell() { + IWorkbenchWindow window= getActiveWorkbenchWindow(); + if (window != null) { + return window.getShell(); + } + return null; + } + + public static IWorkbenchWindow getActiveWorkbenchWindow() { + return getDefault().getWorkbench().getActiveWorkbenchWindow(); + } +} Index: src/org/eclipse/cdt/rpm/ui/SRPMImportWizard.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/ui/SRPMImportWizard.java diff -N src/org/eclipse/cdt/rpm/ui/SRPMImportWizard.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/rpm/ui/SRPMImportWizard.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,79 @@ +/* + * (c) 2004, 2005 Red Hat, Inc. + * + * This program is open source software licensed under the + * Eclipse Public License ver. 1 +*/ + +/** + * @author pmuldoon + * @version 1.0 + * + * + * Plug-in entry point. When the user chooses to import an RPM the plug-in manager in Eclipse + * will invoke this class. This class extends Wizard and implements IImportWizard. + */ +package org.eclipse.cdt.rpm.ui; + +import org.eclipse.core.runtime.CoreException; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; + +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; + + +/** + * The main plugin class to be used in the desktop. This is the "entrypoint" + * for the import rpm plug-in. + */ +public class SRPMImportWizard extends Wizard implements IImportWizard { + private IWorkbench workbench; + private IStructuredSelection selection; + private SRPMImportPage mainPage; + + /** + * @see org.eclipse.ui.IWorkbenchWizard#init(IWorkbench, IStructuredSelection) + */ + public void init(IWorkbench workbench, IStructuredSelection currentSelection) { + this.workbench = workbench; + selection = currentSelection; + setWindowTitle(Messages.getString("SRPMImportwizard.Import_an_SRPM")); //$NON-NLS-1$ + setNeedsProgressMonitor(true); + } + + /** + * @see org.eclipse.jface.wizard.IWizard#performFinish() + */ + + // We have elected to do the Finish button clickin in the SRPMImportPage. So override + //the default and point to SRPMImport finish() + public boolean performFinish() { + try { + return mainPage.finish(); + } catch (CoreException e) { + return false; + } + } + + /** + * @see org.eclipse.jface.wizard.IWizard#canFinish() + * + * Select to finish validation in the SRPMImportPage + */ + public boolean canFinish() { + return mainPage.canFinish(); + } + + /** + * @see org.eclipse.jface.wizard.IWizard#addPages() + */ + + // Add the SRPMImportPage as the only page in this wizard. + public void addPages() { + mainPage = new SRPMImportPage(workbench, selection); + addPage(mainPage); + super.addPages(); + } +} Index: src/org/eclipse/cdt/rpm/ui/util/ExceptionHandler.java =================================================================== RCS file: src/org/eclipse/cdt/rpm/ui/util/ExceptionHandler.java diff -N src/org/eclipse/cdt/rpm/ui/util/ExceptionHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/rpm/ui/util/ExceptionHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2001 Rational Software Corp. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * Rational Software - initial implementation + * Red Hat, Inc. - modified for reuse + ******************************************************************************/ +package org.eclipse.cdt.rpm.ui.util; + + +import java.io.StringWriter; +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +import org.eclipse.cdt.rpm.ui.Messages; +import org.eclipse.cdt.rpm.ui.RPMUIPlugin; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.MessageDialog; + +/** + * The default exception handler shows an error dialog when one of its handle methods + * is called. If the passed exception is a CoreException an error dialog + * pops up showing the exception's status information. For a InvocationTargetException + * a normal message dialog pops up showing the exception's message. Additionally the exception + * is written to the platform log. + */ +public class ExceptionHandler { + + private static ExceptionHandler fgInstance= new ExceptionHandler(); + + /** + * Logs the given exception using the platform's logging mechanism. The exception is + * logged as an error with the error code JavaStatusConstants.INTERNAL_ERROR. + */ + public static void log(Throwable t, String message) { + RPMUIPlugin.getDefault().log(new Status(IStatus.ERROR, RPMUIPlugin.ID, + 1, message, t)); + } + + /** + * Handles the given CoreException. The workbench shell is used as a parent + * for the dialog window. + * + * @param e the CoreException to be handled + * @param title the dialog window's window title + * @param message message to be displayed by the dialog window + */ + public static void handle(CoreException e, String title, String message) { + handle(e, RPMUIPlugin.getActiveWorkbenchShell(), title, message); + } + + /** + * Handles the given CoreException. + * + * @param e the CoreException to be handled + * @param parent the dialog window's parent shell + * @param title the dialog window's window title + * @param message message to be displayed by the dialog window + */ + public static void handle(CoreException e, Shell parent, String title, String message) { + fgInstance.perform(e, parent, title, message); + } + + /** + * Handles the given InvocationTargetException. The workbench shell is used + * as a parent for the dialog window. + * + * @param e the InvocationTargetException to be handled + * @param title the dialog window's window title + * @param message message to be displayed by the dialog window + */ + public static void handle(InvocationTargetException e, String title, String message) { + handle(e, RPMUIPlugin.getActiveWorkbenchShell(), title, message); + } + + /** + * Handles the given InvocationTargetException. + * + * @param e the InvocationTargetException to be handled + * @param parent the dialog window's parent shell + * @param title the dialog window's window title + * @param message message to be displayed by the dialog window + */ + public static void handle(InvocationTargetException e, Shell parent, String title, String message) { + fgInstance.perform(e, parent, title, message); + } + + //---- Hooks for subclasses to control exception handling ------------------------------------ + + protected void perform(CoreException e, Shell shell, String title, String message) { + RPMUIPlugin.getDefault().log(e); + IStatus status= e.getStatus(); + if (status != null) { + ErrorDialog.openError(shell, title, message, status); + } else { + displayMessageDialog(e, e.getMessage(), shell, title, message); + } + } + + protected void perform(InvocationTargetException e, Shell shell, String title, String message) { + Throwable target= e.getTargetException(); + if (target instanceof CoreException) { + perform((CoreException)target, shell, title, message); + } else { + RPMUIPlugin.getDefault().log(e); + if (e.getMessage() != null && e.getMessage().length() > 0) { + displayMessageDialog(e, e.getMessage(), shell, title, message); + } else { + displayMessageDialog(e, target.getMessage(), shell, title, message); + } + } + } + + //---- Helper methods ----------------------------------------------------------------------- + + private void displayMessageDialog(Throwable t, String exceptionMessage, Shell shell, String title, String message) { + StringWriter msg= new StringWriter(); + if (message != null) { + msg.write(message); + msg.write("\n\n"); //$NON-NLS-1$ + } + if (exceptionMessage == null || exceptionMessage.length() == 0) + msg.write(Messages.getString("ExceptionDialog.seeErrorLogMessage")); //$NON-NLS-1$ + else + msg.write(exceptionMessage); + MessageDialog.openError(shell, title, msg.toString()); + } +}