From ea6bcda223210b42e8efdd03290b43ad50d859ba Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Tue, 27 Apr 2010 12:37:06 +0000 Subject: [PATCH] Bug 310514: Exporting resource snapshots in addition to cdt index. --- .../core/pdom/TeamPDOMExportOperation.java | 48 ++++++-- core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF | 2 +- .../ui/wizards/indexwizards/Messages.java | 2 + .../TeamProjectIndexExportWizardPage.java | 107 +++++++++++++++--- .../wizards/indexwizards/messages.properties | 2 + 5 files changed, 135 insertions(+), 26 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMExportOperation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMExportOperation.java index 0b96362267f..ea81c5e8f0b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMExportOperation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMExportOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,10 +17,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; +import java.net.URI; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.zip.Deflater; import java.util.zip.ZipEntry; @@ -35,11 +35,14 @@ import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.dom.PDOMProjectIndexLocationConverter; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.cdt.internal.core.resources.ResourceLookup; +import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; @@ -48,11 +51,23 @@ import org.eclipse.core.runtime.SubProgressMonitor; public class TeamPDOMExportOperation implements IWorkspaceRunnable { + /** + * Option constant (value:1) to indicate that a resource snapshot + * should be saved along with the exported PDOM. + * @since 5.2 + */ + public static int EXPORT_OPTION_RESOURCE_SNAPSHOT = 1; + + private static final String RESOURCE_PREFIX = "res-"; //$NON-NLS-1$ + private static final String CDT_PREFIX = "cdt-"; //$NON-NLS-1$ + private static final String RESOURCE_SNAP_EXTENSION = "snap.zip"; //$NON-NLS-1$ + private ICProject fProject; private String fTargetLocation; private File fTargetLocationFile; private MessageDigest fMessageDigest; - + private int fOptions; + public TeamPDOMExportOperation(ICProject project) { fProject= project; } @@ -62,6 +77,7 @@ public class TeamPDOMExportOperation implements IWorkspaceRunnable { } public void setOptions(int options) { + fOptions = options; } public void setAlgorithm(MessageDigest md) { @@ -114,6 +130,14 @@ public class TeamPDOMExportOperation implements IWorkspaceRunnable { // store preferences monitor.setTaskName(Messages.TeamPDOMExportOperation_taskExportIndex); IndexerPreferences.setIndexImportLocation(fProject.getProject(), fTargetLocation.toString()); + + // store resource snapshot + if ((fOptions & EXPORT_OPTION_RESOURCE_SNAPSHOT) != 0) { + IPath p = Path.fromOSString(fTargetLocationFile.getAbsolutePath()); + p = computeSnapshotPath(p); + URI snapURI = URIUtil.toURI(p); + fProject.getProject().saveSnapshot(IProject.SNAPSHOT_TREE | /*Project.SNAPSHOT_SET_AUTOLOAD*/2, snapURI, null); + } } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; @@ -128,6 +152,14 @@ public class TeamPDOMExportOperation implements IWorkspaceRunnable { } } + private IPath computeSnapshotPath(IPath p) { + final String fileName = p.lastSegment(); + if (fileName.startsWith(CDT_PREFIX)) { + return p.removeLastSegments(1).append(RESOURCE_PREFIX + fileName.substring(4)); + } + return p.removeFileExtension().addFileExtension(RESOURCE_SNAP_EXTENSION); + } + private void getTargetLocation() throws CoreException { fTargetLocationFile= TeamPDOMImportOperation.expandLocation(fProject.getProject(), fTargetLocation); } @@ -152,8 +184,8 @@ public class TeamPDOMExportOperation implements IWorkspaceRunnable { } try { IIndexFile[] ifiles= pdom.getAllFiles(); - for (int i = 0; i < ifiles.length; i++) { - String fullPath= ifiles[i].getLocation().getFullPath(); + for (IIndexFile ifile : ifiles) { + String fullPath= ifile.getLocation().getFullPath(); if (fullPath != null) { fullPaths.add(fullPath); } @@ -165,8 +197,7 @@ public class TeamPDOMExportOperation implements IWorkspaceRunnable { int i=0; IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); IFile[] files= new IFile[fullPaths.size()]; - for (Iterator iterator = fullPaths.iterator(); iterator.hasNext();) { - String fullPath= iterator.next(); + for (String fullPath : fullPaths) { files[i++]= root.getFile(new Path(fullPath)); } Map map= Checksums.createChecksumMap(files, fMessageDigest, monitor); @@ -223,8 +254,7 @@ public class TeamPDOMExportOperation implements IWorkspaceRunnable { close(out); } IFile[] wsResource= ResourceLookup.findFilesForLocation(new Path(fTargetLocationFile.getAbsolutePath())); - for (int i = 0; i < wsResource.length; i++) { - IFile file = wsResource[i]; + for (IFile file : wsResource) { file.refreshLocal(0, new NullProgressMonitor()); } } diff --git a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF index 1fa37857dad..de8dd443d5a 100644 --- a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF @@ -100,7 +100,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.3.0,4.0.0)", org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)", org.eclipse.search;bundle-version="[3.2.0,4.0.0)", org.eclipse.compare;bundle-version="[3.3.0,4.0.0)", - org.eclipse.cdt.core;bundle-version="[5.0.0,6.0.0)", + org.eclipse.cdt.core;bundle-version="[5.2.0,6.0.0)", org.eclipse.ui.console;bundle-version="[3.1.100,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", org.eclipse.help;bundle-version="[3.2.0,4.0.0)", diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/indexwizards/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/indexwizards/Messages.java index 6b52e768802..40d3b6897c6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/indexwizards/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/indexwizards/Messages.java @@ -26,8 +26,10 @@ public class Messages extends NLS { public static String TeamProjectIndexExportWizardPage_destinationMessage; public static String TeamProjectIndexExportWizardPage_errorDlgTitle; public static String TeamProjectIndexExportWizardPage_errorExporting; + public static String TeamProjectIndexExportWizardPage_errorInOperation; public static String TeamProjectIndexExportWizardPage_labelProjectTable; public static String TeamProjectIndexExportWizardPage_noProjectError; + public static String TeamProjectIndexExportWizardPage_resourceSnapshotButton; public static String TeamProjectIndexExportWizardPage_selectAll; public static String TeamProjectIndexExportWizardPage_title; public static String TeamProjectIndexExportWizardPage_variableButton; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/indexwizards/TeamProjectIndexExportWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/indexwizards/TeamProjectIndexExportWizardPage.java index ca8056d837d..d0b8b570b0e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/indexwizards/TeamProjectIndexExportWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/indexwizards/TeamProjectIndexExportWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -23,12 +23,15 @@ import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -39,10 +42,10 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.dialogs.WizardDataTransferPage; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; @@ -55,11 +58,13 @@ import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.cdt.internal.ui.viewsupport.ListContentProvider; -public class TeamProjectIndexExportWizardPage extends WizardDataTransferPage { +public class TeamProjectIndexExportWizardPage extends WizardPage implements Listener { + private static final int SIZING_TEXT_FIELD_WIDTH = 250; private IStructuredSelection fInitialSelection; private CheckboxTableViewer fProjectViewer; private Text fDestinationField; + private Button fResourceSnapshotButton; /** * Create an instance of this class @@ -106,7 +111,7 @@ public class TeamProjectIndexExportWizardPage extends WizardDataTransferPage { giveFocusToDestination(); } - /** + /** * Creates the checkbox tree and list for selecting resources. * * @param parent the parent control @@ -272,6 +277,18 @@ public class TeamProjectIndexExportWizardPage extends WizardDataTransferPage { }; button.addSelectionListener(listener); + // resource snapshot destination group + Composite resourceSnapshotDestinationGroup = new Composite(parent, SWT.NONE); + resourceSnapshotDestinationGroup.setLayout(new GridLayout(1, false)); + resourceSnapshotDestinationGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); + resourceSnapshotDestinationGroup.setFont(font); + + fResourceSnapshotButton = new Button(resourceSnapshotDestinationGroup, SWT.CHECK); + fResourceSnapshotButton.setText(Messages.TeamProjectIndexExportWizardPage_resourceSnapshotButton); + fResourceSnapshotButton.setFont(font); + fResourceSnapshotButton.setLayoutData(gd= new GridData()); + gd.grabExcessHorizontalSpace= true; + gd.horizontalAlignment= GridData.FILL; } protected void onInsertVariable() { @@ -287,10 +304,16 @@ public class TeamProjectIndexExportWizardPage extends WizardDataTransferPage { // about to invoke the operation so save our state saveWidgetValues(); - return executeExportOperation(projectsToExport); } + private void saveWidgetValues() { + } + + private void restoreWidgetValues() { + } + + private ICProject[] getCheckedElements() { Object[] obj= fProjectViewer.getCheckedElements(); ICProject[] prjs= new ICProject[obj.length]; @@ -302,13 +325,17 @@ public class TeamProjectIndexExportWizardPage extends WizardDataTransferPage { final String dest= getDestinationValue(); final MultiStatus status= new MultiStatus(CUIPlugin.PLUGIN_ID, 0, Messages.TeamProjectIndexExportWizardPage_errorExporting, null); - + final boolean exportResourceSnapshot = fResourceSnapshotButton.getSelection(); + IRunnableWithProgress op= new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("", projects.length); //$NON-NLS-1$ for (ICProject project : projects) { TeamPDOMExportOperation op= new TeamPDOMExportOperation(project); op.setTargetLocation(dest); + if (exportResourceSnapshot) { + op.setOptions(TeamPDOMExportOperation.EXPORT_OPTION_RESOURCE_SNAPSHOT); + } try { op.run(new SubProgressMonitor(monitor, 1)); } catch (CoreException e) { @@ -352,7 +379,6 @@ public class TeamProjectIndexExportWizardPage extends WizardDataTransferPage { * Answer a boolean indicating whether the receivers destination specification * widgets currently all contain valid values. */ - @Override protected boolean validateDestinationGroup() { String destinationValue = getDestinationValue(); if (destinationValue.length() == 0) { @@ -364,7 +390,6 @@ public class TeamProjectIndexExportWizardPage extends WizardDataTransferPage { return true; } - @Override protected boolean validateSourceGroup() { // there must be some resources selected for Export boolean isValid = true; @@ -375,17 +400,15 @@ public class TeamProjectIndexExportWizardPage extends WizardDataTransferPage { } else { setErrorMessage(null); } - return super.validateSourceGroup() && isValid; + return isValid; } - @Override protected void updateWidgetEnablements() { boolean pageComplete = determinePageCompletion(); setPageComplete(pageComplete); if (pageComplete) { setMessage(null); } - super.updateWidgetEnablements(); } @@ -393,13 +416,65 @@ public class TeamProjectIndexExportWizardPage extends WizardDataTransferPage { updateWidgetEnablements(); } - @Override protected String getErrorDialogTitle() { return Messages.TeamProjectIndexExportWizardPage_errorDlgTitle; } - @Override - protected boolean allowNewContainerName() { - return false; - } + /** + * Returns whether this page is complete. This determination is made based upon + * the current contents of this page's controls. Subclasses wishing to include + * their controls in this determination should override the hook methods + * validateSourceGroup and/or validateOptionsGroup. + * + * @return true if this page is complete, and false if + * incomplete + * @see #validateSourceGroup + * @see #validateDestinationGroup + */ + private boolean determinePageCompletion() { + boolean complete = validateSourceGroup() && validateDestinationGroup(); + + // Avoid draw flicker by not clearing the error + // message unless all is valid. + if (complete) { + setErrorMessage(null); + } + + return complete; + } + + /** + * Determine if the page is complete and update the page appropriately. + */ + protected void updatePageCompletion() { + boolean pageComplete = determinePageCompletion(); + setPageComplete(pageComplete); + if (pageComplete) { + setErrorMessage(null); + } + } + + /** + * Display an error dialog with the specified message. + * + * @param message the error message + */ + private void displayErrorDialog(String message) { + MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(), + getErrorDialogTitle(), message, SWT.SHEET); + } + + /** + * Display an error dislog with the information from the + * supplied exception. + * @param exception Throwable + */ + private void displayErrorDialog(Throwable exception) { + String message = exception.getMessage(); + //Some system exceptions have no message + if (message == null) { + message = NLS.bind(Messages.TeamProjectIndexExportWizardPage_errorInOperation, exception); + } + displayErrorDialog(message); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/indexwizards/messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/indexwizards/messages.properties index 35da0096b0b..011b46b9d91 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/indexwizards/messages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/indexwizards/messages.properties @@ -20,6 +20,8 @@ TeamProjectIndexExportWizardPage_errorExporting=Errors occurred while exporting TeamProjectIndexExportWizardPage_destinationMessage=Enter a destination archive file. TeamProjectIndexExportWizardPage_noProjectError=At least one project must be selected. TeamProjectIndexExportWizardPage_errorDlgTitle=Export C/C++ Index +TeamProjectIndexExportWizardPage_errorInOperation=Error occurred during operation: {0} +TeamProjectIndexExportWizardPage_resourceSnapshotButton=Export resource snapshot StringVariableSelectionDialog_title=Select Variable StringVariableSelectionDialog_message=&Choose a variable (? = any character, * = any string): StringVariableSelectionDialog_columnArgument=&Argument: