### Eclipse Workspace Patch 1.0 #P org.eclipse.team.cvs.ui Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.ui/plugin.xml,v retrieving revision 1.3 diff -u -r1.3 plugin.xml --- plugin.xml 15 Mar 2007 01:25:41 -0000 1.3 +++ plugin.xml 21 Mar 2007 20:26:32 -0000 @@ -192,6 +192,15 @@ + + + + + + + Index: src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryPrompter.java =================================================================== RCS file: src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryPrompter.java diff -N src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryPrompter.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryPrompter.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.ui; + +import java.util.Map; + +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.swt.widgets.Display; +import org.eclipse.team.internal.ccvs.core.IAlternativeRepositoryPrompter; + +public class AlternativeRepositoryPrompter implements IAlternativeRepositoryPrompter { + + public AlternativeRepositoryPrompter() { + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see org.eclipse.team.internal.ccvs.core.IAlternativeRepositoryPrompter#promptForAlternativeRepository(java.util.Map) + */ + public void promptForAlternativeRepository(final Map alternativeMap) { + + final Object[] result = new Object[1]; + Display display = Display.getCurrent(); + if (display != null) { + result[0] = openAlternativeRepositoryDialog(alternativeMap); + } else { + // sync exec in default thread + Display.getDefault().syncExec(new Runnable() { + public void run() { + result[0] = openAlternativeRepositoryDialog(alternativeMap); + } + }); + } + + if (result[0] == null) { + //TODO + throw new OperationCanceledException(CVSUIMessages.WorkbenchUserAuthenticator_The_operation_was_canceled_by_the_user_1); + } + + } + + + private Object openAlternativeRepositoryDialog(Map alternativeMap) { + //TODO: + AlternativeRepositoryDialog dialog = new AlternativeRepositoryDialog(null, alternativeMap); + dialog.open(); + dialog.getSelected(); + return null; + } +} Index: src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryTable.java =================================================================== RCS file: src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryTable.java diff -N src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryTable.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryTable.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,248 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.team.internal.ccvs.ui; + +import java.util.*; +import java.util.List; + +import org.eclipse.jface.viewers.*; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.TableEditor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.*; +import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; +import org.eclipse.team.internal.ui.*; + + +public class AlternativeRepositoryTable implements ICellModifier, IStructuredContentProvider, ITableLabelProvider { + + private static final class AlternativeRepositoryComparator extends ViewerComparator { + + public AlternativeRepositoryComparator() { + } + + private int getCategory(Object element) { + if (element instanceof RepositoryLocationItem) { + return 0; + } + return 2; + } + + public int compare(Viewer viewer,Object e1,Object e2) { + final int compare= getCategory(e1) - getCategory(e2); + if (compare != 0) + return compare; + return super.compare(viewer, ((Item)e1).location, ((Item)e2).location); + } + } + + public abstract static class Item implements Comparable { + public final String location; + public List alternativeList; + public int selected; + + public Item(String name, List alternative/*, boolean contributed*/) { this.location= name; this.alternativeList=alternative; this.selected=0; /*this.contributed = contributed; save= true; mode= Team.BINARY; */} + + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Object o) { + return location.compareTo(((Item)o).location); + } + } + + public static class RepositoryLocationItem extends Item { + public RepositoryLocationItem(CVSRepositoryLocation repo,List repositoryLocation) { super(repo.getLocation(),repositoryLocation/*, contributed*/); } + } + + private final static int COLUMN_PADDING = 5; + + protected static final String ITEM = "item"; //$NON-NLS-1$ + protected static final String PROPERTY_ALTERNATIVE_LIST = "alternativeList"; //$NON-NLS-1$ + + private final TableViewer fTableViewer; + private final List fItems; + + private CellEditor[] cellEditors; + + private TextCellEditor dummyAlternativeRepositoryEditor; + + private final Table table; + + public AlternativeRepositoryTable(Composite composite, List items) { + + fItems = items; + + /** + * Create a table. + */ + table = new Table(composite, SWT.V_SCROLL | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); + table.setLayoutData(SWTUtils.createHVFillGridData()); + table.setLinesVisible(true); + table.setHeaderVisible(true); + + final PixelConverter converter= SWTUtils.createDialogPixelConverter(composite); + + //TODO: colums width (@see Snippet77) + + /** + * The 'Extension' column + */ + final TableColumn projectSetRepositoryColumn = new TableColumn(table, SWT.NONE, 0); + projectSetRepositoryColumn.setWidth(converter.convertWidthInCharsToPixels(/*TeamUIMessages.FileTypeTable_4*/"Repository Location from the project set".length() + COLUMN_PADDING)); + //TODO: externalize + projectSetRepositoryColumn.setText(/*TeamUIMessages.FileTypeTable_4*/"Repository Location from the project set"); + + /** + * The 'Mode' column + */ + final TableColumn alternativeRepositoryColums = new TableColumn(table, SWT.NONE, 1); + int length; + try { + //TODO: externalize + length = "Alternative repository ".length(); + } catch (RuntimeException e) { + // There may be an unbound message so just pick a reasonable length + length = 15; + } + alternativeRepositoryColums.setWidth(converter.convertWidthInCharsToPixels(length + COLUMN_PADDING)); + alternativeRepositoryColums.setText(/*TeamUIMessages.FileTypeTable_5*/"Alternative repository"); + + /** + * Create a viewer for the table. + */ + fTableViewer = new TableViewer(table); + fTableViewer.setContentProvider(this); + fTableViewer.setLabelProvider(this); + fTableViewer.setComparator(new AlternativeRepositoryComparator()); + + /** + * Add a cell editor in the Keyword Substitution Mode column + */ + new TableEditor(table); + + cellEditors = new CellEditor[2]; + cellEditors[0] = null; + // to enable cell editing, create a dummy cell editor + cellEditors[1] = dummyAlternativeRepositoryEditor = new TextCellEditor(table, SWT.READ_ONLY); + + fTableViewer.setCellEditors(cellEditors); + fTableViewer.setColumnProperties(new String [] { ITEM, PROPERTY_ALTERNATIVE_LIST }); + fTableViewer.setCellModifier(this); + fTableViewer.setInput(fItems); + } + + + public Object getValue(Object element, String property) { + + final Item item = (Item)element; + + if (PROPERTY_ALTERNATIVE_LIST.equals(property)) { + return new Integer(item.selected); + } + return null; + } + + public boolean canModify(Object element, String property) { + // set the correct cell editor for this element + cellEditors[1] = getCellEditor(element); + // only allow modification for editable elements + return PROPERTY_ALTERNATIVE_LIST.equals(property) /*|| (fShowSaveColumn && PROPERTY_SAVE.equals(property))*/; + } + + private CellEditor getCellEditor(Object element) { + + if (element instanceof RepositoryLocationItem) { + + // create combobox list of alt. repos + List alternativeList = ((RepositoryLocationItem) element).alternativeList; + String[] alternativeNames = new String[alternativeList.size() + 1]; + // TODO: externalize, move to CVSProjectSetCapabilty when looking + // for alt. repos + alternativeNames[0] = "Configure new repo location"; + int i = 1; + for (Iterator iterator = alternativeList.iterator(); iterator.hasNext();) { + CVSRepositoryLocation repo = (CVSRepositoryLocation) iterator.next(); + alternativeNames[i++] = repo.getLocation(); + } + return new ComboBoxCellEditor(table, alternativeNames, + SWT.READ_ONLY); + } + return dummyAlternativeRepositoryEditor; + } + + + public void modify(Object element, String property, Object value) { + + final IStructuredSelection selection = (IStructuredSelection)fTableViewer.getSelection(); + final Item item= (Item)selection.getFirstElement(); + if (item == null) + return; + + final int comboIndex = ((Integer)value).intValue(); + + if (PROPERTY_ALTERNATIVE_LIST.equals(property)) { + item.selected = comboIndex; + } + fTableViewer.refresh(item); + } + + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + public String getColumnText(Object element, int columnIndex) { + + final Item item = (Item) element; + + if (columnIndex == 0) { + return item.location; + } + + if (columnIndex == 1) { + //TODO: externalize + // 0 is added by the cell editor + return item.selected>0?((CVSRepositoryLocation)item.alternativeList.get(item.selected-1)).getLocation():"Configure new repo location"; + } + return null; + } + + public void addListener(ILabelProviderListener listener) {} + + public void dispose() {} + + public boolean isLabelProperty(Object element, String property) { + return false; + } + + public void removeListener(ILabelProviderListener listener) {} + + public Object[] getElements(Object inputElement) { + return ((Collection)inputElement).toArray(); + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + + public IStructuredSelection getSelection() { + return (IStructuredSelection)fTableViewer.getSelection(); + } + + public void setInput(List items) { + fItems.clear(); + fItems.addAll(items); + fTableViewer.refresh(); + } + + public TableViewer getViewer() { + return fTableViewer; + } +} Index: src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryDialog.java =================================================================== RCS file: src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryDialog.java diff -N src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryDialog.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryDialog.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.ui; + +import java.util.*; +import java.util.List; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.TrayDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.*; +import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; +import org.eclipse.team.internal.ui.SWTUtils; + +public class AlternativeRepositoryDialog extends TrayDialog { + + private List fAlternatives; + //TODO externalize + private final static String title = "Select alternative repository"; + private final static String message = "Select alternative repository"; + + /** + * Creates a new AlternativeRepositoryDialog. + * + * @param parentShell the parent shell + * @param alternativesMap the default user name + * @param message a mesage to display to the user + */ + public AlternativeRepositoryDialog(Shell parentShell, Map alternativesMap/*, String message*/) { + super(parentShell); + setShellStyle(getShellStyle() | SWT.RESIZE); + fAlternatives = new ArrayList(); + for (Iterator iterator = alternativesMap.entrySet().iterator(); iterator.hasNext();) { + Map.Entry entry = (Map.Entry) iterator.next(); + fAlternatives + .add(new AlternativeRepositoryTable.RepositoryLocationItem( + (CVSRepositoryLocation) entry.getKey(), + (List) entry.getValue())); + + } + alternativeToString(fAlternatives); + } + + /* + * (non-Javadoc) Method declared in Window. + */ + protected void configureShell(Shell shell) { + super.configureShell(shell); + if (title != null) { + shell.setText(title); + } + } + + /** + * @see Dialog#createDialogArea + */ + protected Control createDialogArea(Composite parent) { + initializeDialogUnits(parent); + + final Composite composite= new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(1, false)); + // set F1 help +// PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.COMMIT_FILE_TYPES_PAGE); + + GridData childData = new GridData(GridData.FILL_BOTH); + composite.setLayoutData(childData); + + final Label label= new Label(composite, SWT.WRAP); + label.setText(/*CVSUIMessages.CommitWizardFileTypePage_3*/message); + label.setLayoutData(SWTUtils.createHFillGridData()); + Dialog.applyDialogFont(composite); + + new AlternativeRepositoryTable(composite, fAlternatives); + + return composite; + } + + protected Point getInitialSize() { + //TODO: read/write using memento + return new Point(500,500); + } + + public Map getSelected() { + alternativeToString(fAlternatives); + Map map = new HashMap(); + for (Iterator iterator = fAlternatives.iterator(); iterator.hasNext();) { + AlternativeRepositoryTable.RepositoryLocationItem rli = (AlternativeRepositoryTable.RepositoryLocationItem) iterator.next(); + // rli.selected==0 means there was no alt repo selected + map.put(rli.location, rli.selected > 0 ? rli.alternativeList + .get(rli.selected - 1) : null); + } + return map; + } + + //XXX: dev only + + private void alternativeToString(List alts) { + for (Iterator iterator = alts.iterator(); iterator.hasNext();) { + AlternativeRepositoryTable.RepositoryLocationItem rli = (AlternativeRepositoryTable.RepositoryLocationItem) iterator.next(); + // rli.selected==0 means there was no alt repo selected + StringBuffer sb = new StringBuffer("AlternativeRepositoryTable.RepositoryLocationItem:\n"); + sb.append("location->").append(rli.location).append(";\n"); + sb.append("selected->").append(rli.selected).append(";\n"); + sb.append("alternativeList->"); + for (Iterator iterator2 = rli.alternativeList.iterator(); iterator2.hasNext();) { + CVSRepositoryLocation rl = (CVSRepositoryLocation) iterator2.next(); + sb.append(rl).append(","); + } + sb.append(";\n-----------------------\n"); + System.out.println(sb); + } + + } +} #P org.eclipse.team.tests.cvs.core Index: src/org/eclipse/team/tests/ccvs/core/CVSProjectSetCapabilityTest.java =================================================================== RCS file: src/org/eclipse/team/tests/ccvs/core/CVSProjectSetCapabilityTest.java diff -N src/org/eclipse/team/tests/ccvs/core/CVSProjectSetCapabilityTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/team/tests/ccvs/core/CVSProjectSetCapabilityTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,195 @@ +package org.eclipse.team.tests.ccvs.core; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +import org.eclipse.core.resources.IProject; +import org.eclipse.team.internal.ccvs.core.CVSProjectSetCapability; +import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; +import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; +import org.eclipse.team.internal.ccvs.core.util.KnownRepositories; + +public class CVSProjectSetCapabilityTest extends /* EclipseTest */TestCase { + private ICVSRepositoryLocation[] savedRepositories; + + protected void setUp() throws Exception { + // save already cached repositories + savedRepositories = KnownRepositories.getInstance().getRepositories(); + for (int i = 0; i < KnownRepositories.getInstance().getRepositories().length; i++) { + KnownRepositories.getInstance().disposeRepository( + KnownRepositories.getInstance().getRepositories()[i]); + } + assertEquals(0, + KnownRepositories.getInstance().getRepositories().length); + } + + protected void tearDown() throws Exception { + // clear testing repositories + for (int i = 0; i < KnownRepositories.getInstance().getRepositories().length; i++) { + KnownRepositories.getInstance().disposeRepository( + KnownRepositories.getInstance().getRepositories()[i]); + } + + // load saved repositories + for (int i = 0; i < savedRepositories.length; i++) { + KnownRepositories.getInstance().addRepository(savedRepositories[i], + true); + } + } + + public void testIsAlternativeRepositoryNeeded_infoMapIsNull() + throws Exception { + Map infoMap = null; + Map alternativeMap = new HashMap(); + boolean isAlternativeRepositoryNeeded = invokeIsAlternativeRepositoryNeeded( + infoMap, alternativeMap); + assertEquals(false, isAlternativeRepositoryNeeded); + } + + public void testIsAlternativeRepositoryNeeded_infoMapIsEmpty() + throws Exception { + Map infoMap = new HashMap(); + Map alternativeMap = new HashMap(); + boolean isAlternativeRepositoryNeeded = invokeIsAlternativeRepositoryNeeded( + infoMap, alternativeMap); + assertEquals(false, isAlternativeRepositoryNeeded); + } + + public void testIsAlternativeRepositoryNeeded_knownRepository() throws Exception { + Map infoMap = new HashMap(); + Map alternativeMap = new HashMap(); + + String repo = ":pserver:user:password@hostname:1/path/to/repository"; + KnownRepositories.getInstance().addRepository( + CVSRepositoryLocation.fromString(repo), true); + assertEquals(1, + KnownRepositories.getInstance().getRepositories().length); + + invokeAsProjects( + new String[] { "1.0,:pserver:user:password@hostname:1/path/to/repository,module.name,project.name" }, + infoMap); + + boolean isAlternativeRepositoryNeeded = invokeIsAlternativeRepositoryNeeded( + infoMap, alternativeMap); + assertEquals(false, isAlternativeRepositoryNeeded); + } + + public void testIsAlternativeRepositoryNeeded_unknownHost() throws Exception { + Map infoMap = new HashMap(); + Map alternativeMap = new HashMap(); + + String repo = ":pserver:user:password@hostname:80/path/to/repository"; + KnownRepositories.getInstance().addRepository( + CVSRepositoryLocation.fromString(repo), true); + assertEquals(1, + KnownRepositories.getInstance().getRepositories().length); + + invokeAsProjects( + new String[] { "1.0,:pserver:user:password@UNKNOWN:80/path/to/repository,module.name,project.name" }, + infoMap); + + boolean isAlternativeRepositoryNeeded = invokeIsAlternativeRepositoryNeeded( + infoMap, alternativeMap); + assertEquals(false, isAlternativeRepositoryNeeded); + } + + public void testIsAlternativeRepositoryNeeded_differentMethod() throws Exception { + Map infoMap = new HashMap(); + Map alternativeMap = new HashMap(); + + String repo = ":pserver:user:password@hostname/path/to/repository"; + KnownRepositories.getInstance().addRepository( + CVSRepositoryLocation.fromString(repo), true); + assertEquals(1, + KnownRepositories.getInstance().getRepositories().length); + + invokeAsProjects( + new String[] { "1.0,:extssh:user:password@hostname/path/to/repository,module.name,project.name" }, + infoMap); + + boolean isAlternativeRepositoryNeeded = invokeIsAlternativeRepositoryNeeded( + infoMap, alternativeMap); + assertEquals(true, isAlternativeRepositoryNeeded); + } + + public void testIsAlternativeRepositoryNeeded_differentPort() throws Exception { + Map infoMap = new HashMap(); + Map alternativeMap = new HashMap(); + + String repo = ":pserver:user:password@hostname:80/path/to/repository"; + KnownRepositories.getInstance().addRepository( + CVSRepositoryLocation.fromString(repo), true); + assertEquals(1, + KnownRepositories.getInstance().getRepositories().length); + + invokeAsProjects( + new String[] { "1.0,:pserver:user:password@hostname:81/path/to/repository,module.name,project.name" }, + infoMap); + + boolean isAlternativeRepositoryNeeded = invokeIsAlternativeRepositoryNeeded( + infoMap, alternativeMap); + assertEquals(true, isAlternativeRepositoryNeeded); + } + + //TODO: add tests for alternatives repos order + + //TODO: add tests for prompter (in different class) + + // private utility methods + + private static boolean invokeIsAlternativeRepositoryNeeded(Map infoMap, + Map alternativeMap) throws InvocationTargetException { + + Class[] argClasses = { Map.class, Map.class }; + Object[] argObjects = { infoMap, alternativeMap }; + + Object isAlternativeRepositoryNeeded = invokeStaticMethod( + CVSProjectSetCapability.class, "isAlternativeRepositoryNeeded", + argClasses, argObjects); + return ((Boolean) isAlternativeRepositoryNeeded).booleanValue(); + } + + private static IProject[] invokeAsProjects(String[] referenceStrings, + Map infoMap) throws InvocationTargetException { + Class[] argClasses = { String[].class, Map.class }; + Object[] argObjects = { referenceStrings, infoMap }; + + Object projects = invokeMethod(new CVSProjectSetCapability(), + CVSProjectSetCapability.class, "asProjects", argClasses, + argObjects); + return (IProject[]) projects; + } + + private static Object invokeStaticMethod(Class targetClass, + String methodName, Class[] argClasses, Object[] argObjects) + throws InvocationTargetException { + return invokeMethod(null, targetClass, methodName, argClasses, + argObjects); + } + + private static Object invokeMethod(Object instance, Class targetClass, + String methodName, Class[] argClasses, Object[] argObjects) + throws InvocationTargetException { + + try { + Method method = targetClass.getDeclaredMethod(methodName, + argClasses); + method.setAccessible(true); + return method.invoke(instance, argObjects); + } catch (NoSuchMethodException e) { + fail(e.getMessage()); + } catch (SecurityException e) { + fail(e.getMessage()); + } catch (IllegalAccessException e) { + fail(e.getMessage()); + } catch (IllegalArgumentException e) { + fail(e.getMessage()); + } + return null; + } + +} #P org.eclipse.team.cvs.core Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.core/plugin.xml,v retrieving revision 1.1 diff -u -r1.1 plugin.xml --- plugin.xml 15 Mar 2007 01:29:41 -0000 1.1 +++ plugin.xml 21 Mar 2007 20:26:32 -0000 @@ -5,9 +5,9 @@ + - Ensures that all repositories from imported project set are known. If + * yes, return true. If not, checks whether there is an + * alternative known repository for one from project set.

+ *

Cached repository is matched as an alternative when it's:

+ * + *
    + *
  • host equals to the one from the project set
  • + *
  • port equals to the one from the project set
  • + *
  • root directory equals to the one from the project set
  • + *
+ * + * @param infoMap + * @return + */ + private static boolean isAlternativeRepositoryNeeded(final Map infoMap, Map alternativeMap) { + + if (infoMap == null) + return false; + + Set projectSetRepositories = new HashSet(); + for (Iterator iterator = infoMap.keySet().iterator(); iterator.hasNext();) { + IProject project = (IProject) iterator.next(); + LoadInfo loadInfo = (LoadInfo) infoMap.get(project); + projectSetRepositories.add(loadInfo.repositoryLocation); + } + + //TODO: use match criteria from plugin.xml (method,port,*,none)? + List knownRepositories = Arrays.asList(KnownRepositories.getInstance().getRepositories()); + + // not all repositories from the project set being imported are known + if (!knownRepositories.containsAll(projectSetRepositories)) { + + for (Iterator iterator = projectSetRepositories.iterator(); iterator + .hasNext();) { + ICVSRepositoryLocation projectSetRepositoryLocation = (ICVSRepositoryLocation) iterator.next(); + + ICVSRepositoryLocation[] alternativeArray = new ICVSRepositoryLocation[4]; + int alternativesCounter = 0; + for (Iterator iterator2 = knownRepositories.iterator(); iterator2 + .hasNext();) { + ICVSRepositoryLocation knownRepositoryLocation = (ICVSRepositoryLocation) iterator2.next(); + + // the closest match here + if (projectSetRepositoryLocation.getHost().equals(knownRepositoryLocation.getHost()) + && projectSetRepositoryLocation.getPort() == knownRepositoryLocation.getPort() + && projectSetRepositoryLocation.getRootDirectory().equals(knownRepositoryLocation.getRootDirectory())) { + // only connection method doesn't match + alternativeArray[0] = knownRepositoryLocation; + alternativesCounter++; + } else if (projectSetRepositoryLocation.getHost().equals(knownRepositoryLocation.getHost()) + && projectSetRepositoryLocation.getPort() == knownRepositoryLocation.getPort() ) { + // root directory doesn't match + alternativeArray[1]= knownRepositoryLocation; + alternativesCounter++; + } else if (projectSetRepositoryLocation.getHost().equals(knownRepositoryLocation.getHost()) + && projectSetRepositoryLocation.getRootDirectory().equals(knownRepositoryLocation.getRootDirectory())){ + // port doesn't match + alternativeArray[2]= knownRepositoryLocation; + alternativesCounter++; + } else if (projectSetRepositoryLocation.getHost().equals(knownRepositoryLocation.getHost())) { + // only host matches + alternativeArray[3]= knownRepositoryLocation; + alternativesCounter++; + } + // the furthest match here + } + + // convert alternative array into ordered list, closer match first + if (alternativesCounter > 0) { + ArrayList alternativeList = new ArrayList( + alternativesCounter); + + for (int i = alternativeArray.length-1; i >= 0; i--) { + if (alternativeArray[i] != null) + alternativeList.add(alternativeArray[i]); + } + alternativeMap.put(projectSetRepositoryLocation, + alternativeList); + } + } + } + + return alternativeMap.size() > 0; + } + + private void promptForAlternativeRespository(Map alternativeMap) { + IAlternativeRepositoryPrompter prompter = getAlternativeRepositoryPrompter(); + prompter.promptForAlternativeRepository(alternativeMap); + //TODO tzarna: remember choices made on the dialog + } + private IAlternativeRepositoryPrompter getAlternativeRepositoryPrompter() { + if (alternativeRepositoryPrompter == null) { + alternativeRepositoryPrompter = getPluggedInAlternativeRepositoryPrompter(); + } + return alternativeRepositoryPrompter; + } + + private static IAlternativeRepositoryPrompter getPluggedInAlternativeRepositoryPrompter() { + IExtension[] extensions = Platform.getExtensionRegistry().getExtensionPoint(CVSProviderPlugin.ID, CVSProviderPlugin.PT_ALTERNATIVE_REPOSITORY_PROMPTER).getExtensions(); + if (extensions.length == 0) + return null; + IExtension extension = extensions[0]; + IConfigurationElement[] configs = extension.getConfigurationElements(); + if (configs.length == 0) { + CVSProviderPlugin.log(IStatus.ERROR, NLS.bind("Alternative Repository Prompter {0} is missing required fields", (new Object[] {extension.getUniqueIdentifier()})), null);//$NON-NLS-1$ + return null; + } + try { + IConfigurationElement config = configs[0]; + return (IAlternativeRepositoryPrompter) config.createExecutableExtension("run");//$NON-NLS-1$ + } catch (CoreException ex) { + CVSProviderPlugin.log(IStatus.ERROR, NLS.bind("Unable to instantiate Alternative Repository Prompter {0}", (new Object[] {extension.getUniqueIdentifier()})), ex);//$NON-NLS-1$ + return null; + } + } } Index: schema/alternativerepositoryprompter.exsd =================================================================== RCS file: schema/alternativerepositoryprompter.exsd diff -N schema/alternativerepositoryprompter.exsd --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ schema/alternativerepositoryprompter.exsd 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,97 @@ + + + + + + + + + This extension point is internal use only + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.0 + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + This extension point is for internal use only + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + + + + + Copyright (c) 2004 IBM Corporation 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 <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> + + + + Index: src/org/eclipse/team/internal/ccvs/core/IAlternativeRepositoryPrompter.java =================================================================== RCS file: src/org/eclipse/team/internal/ccvs/core/IAlternativeRepositoryPrompter.java diff -N src/org/eclipse/team/internal/ccvs/core/IAlternativeRepositoryPrompter.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/team/internal/ccvs/core/IAlternativeRepositoryPrompter.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.core; + +import java.util.Map; + +public interface IAlternativeRepositoryPrompter { + + public abstract void promptForAlternativeRepository(Map alternativeMap); +}