|
Lines 20-29
Link Here
|
| 20 |
import java.util.HashSet; |
20 |
import java.util.HashSet; |
| 21 |
import java.util.zip.ZipFile; |
21 |
import java.util.zip.ZipFile; |
| 22 |
|
22 |
|
| 23 |
import junit.framework.TestSuite; |
|
|
| 24 |
|
| 25 |
import org.eclipse.core.resources.IFolder; |
23 |
import org.eclipse.core.resources.IFolder; |
| 26 |
import org.eclipse.core.resources.IProject; |
24 |
import org.eclipse.core.resources.IProject; |
|
|
25 |
import org.eclipse.core.resources.IResource; |
| 27 |
import org.eclipse.core.resources.IWorkspaceRoot; |
26 |
import org.eclipse.core.resources.IWorkspaceRoot; |
| 28 |
import org.eclipse.core.resources.ResourcesPlugin; |
27 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 29 |
import org.eclipse.core.runtime.CoreException; |
28 |
import org.eclipse.core.runtime.CoreException; |
|
Lines 50-68
Link Here
|
| 50 |
import org.eclipse.ui.tests.util.FileUtil; |
49 |
import org.eclipse.ui.tests.util.FileUtil; |
| 51 |
|
50 |
|
| 52 |
public class ImportExistingTest extends DataTransferTestCase { |
51 |
public class ImportExistingTest extends DataTransferTestCase { |
| 53 |
public static TestSuite suite() { |
|
|
| 54 |
return new TestSuite(ImportExistingTest.class); |
| 55 |
} |
| 56 |
|
| 57 |
private static final String PLUGIN_ID = "org.eclipse.ui.tests"; |
52 |
private static final String PLUGIN_ID = "org.eclipse.ui.tests"; |
| 58 |
private static final String DATA_PATH_PREFIX = "data/org.eclipse.datatransferArchives/"; |
53 |
private static final String DATA_PATH_PREFIX = "data/org.eclipse.datatransferArchives/"; |
| 59 |
private static final String WS_DATA_PREFIX = "data/workspaces"; |
54 |
private static final String WS_DATA_PREFIX = "data/workspaces"; |
| 60 |
private static final String WS_DATA_LOCATION = "importExistingFromDirTest"; |
55 |
private static final String WS_DATA_LOCATION = "importExistingFromDirTest"; |
|
|
56 |
private static final String ARCHIVE_HELLOWORLD = "helloworld"; |
| 57 |
private static final String ARCHIVE_FILE_WITH_EMPTY_FOLDER = "EmptyFolderInArchive"; |
| 61 |
|
58 |
|
| 62 |
private static final String[] ARCHIVE_FILE_LIST = new String[] { |
59 |
private static final String[] ARCHIVE_FILE_LIST = new String[] { |
| 63 |
"HelloWorld.java", "HelloWorld.class", ".project", ".classpath" }; |
60 |
"HelloWorld.java", "HelloWorld.class", ".project", ".classpath" }; |
|
|
61 |
|
| 62 |
private static final String[] ARCHIVE_FILE_EMPTY_FOLDER_LIST = new String[]{ |
| 63 |
"empty", "folder" }; |
| 64 |
|
| 64 |
private String dataLocation = null; |
65 |
private String dataLocation = null; |
| 65 |
|
66 |
|
|
|
67 |
private boolean originalRefreshSetting; |
| 68 |
|
| 66 |
public ImportExistingTest(String testName) { |
69 |
public ImportExistingTest(String testName) { |
| 67 |
super(testName); |
70 |
super(testName); |
| 68 |
} |
71 |
} |
|
Lines 71-76
Link Here
|
| 71 |
return DialogCheck.getShell(); |
74 |
return DialogCheck.getShell(); |
| 72 |
} |
75 |
} |
| 73 |
|
76 |
|
|
|
77 |
protected void doSetUp() throws Exception { |
| 78 |
super.doSetUp(); |
| 79 |
originalRefreshSetting = ResourcesPlugin.getPlugin() |
| 80 |
.getPluginPreferences().getBoolean(ResourcesPlugin.PREF_AUTO_REFRESH); |
| 81 |
ResourcesPlugin.getPlugin() |
| 82 |
.getPluginPreferences().setValue(ResourcesPlugin.PREF_AUTO_REFRESH, true); |
| 83 |
} |
| 84 |
|
| 74 |
protected void doTearDown() throws Exception { |
85 |
protected void doTearDown() throws Exception { |
| 75 |
super.doTearDown(); |
86 |
super.doTearDown(); |
| 76 |
IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); |
87 |
IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); |
|
Lines 86-103
Link Here
|
| 86 |
} |
97 |
} |
| 87 |
} |
98 |
} |
| 88 |
dataLocation = null; // reset for next test |
99 |
dataLocation = null; // reset for next test |
|
|
100 |
|
| 101 |
ResourcesPlugin.getPlugin() |
| 102 |
.getPluginPreferences().setValue(ResourcesPlugin.PREF_AUTO_REFRESH, |
| 103 |
originalRefreshSetting); |
| 89 |
} |
104 |
} |
| 90 |
|
105 |
|
| 91 |
public void testFindSingleZip() { |
106 |
public void testFindSingleZip() { |
| 92 |
try { |
107 |
try { |
| 93 |
URL helloworld = Platform.asLocalURL(Platform.find(TestPlugin.getDefault().getBundle(), |
108 |
URL archiveFile = Platform.asLocalURL(Platform.find(TestPlugin.getDefault().getBundle(), |
| 94 |
new Path(DATA_PATH_PREFIX+"helloworld.zip"))); |
109 |
new Path(DATA_PATH_PREFIX + ARCHIVE_HELLOWORLD + ".zip"))); |
| 95 |
WizardProjectsImportPage wpip = getNewWizard(); |
110 |
WizardProjectsImportPage wpip = getNewWizard(); |
| 96 |
HashSet projects = new HashSet(); |
111 |
HashSet projects = new HashSet(); |
| 97 |
projects.add("HelloWorld"); |
112 |
projects.add("HelloWorld"); |
| 98 |
|
113 |
|
| 99 |
wpip.getProjectFromDirectoryRadio().setSelection((false)); //We want the other one selected |
114 |
wpip.getProjectFromDirectoryRadio().setSelection((false)); //We want the other one selected |
| 100 |
wpip.updateProjectsList(helloworld.getPath()); |
115 |
wpip.updateProjectsList(archiveFile.getPath()); |
| 101 |
|
116 |
|
| 102 |
ProjectRecord[] selectedProjects= wpip.getValidProjects(); |
117 |
ProjectRecord[] selectedProjects= wpip.getValidProjects(); |
| 103 |
ArrayList projectNames = new ArrayList(); |
118 |
ArrayList projectNames = new ArrayList(); |
|
Lines 113-126
Link Here
|
| 113 |
|
128 |
|
| 114 |
public void testFindSingleTar() { |
129 |
public void testFindSingleTar() { |
| 115 |
try { |
130 |
try { |
| 116 |
URL helloworld = Platform.asLocalURL(Platform.find(TestPlugin.getDefault().getBundle(), |
131 |
URL archiveFile = Platform.asLocalURL(Platform.find(TestPlugin.getDefault().getBundle(), |
| 117 |
new Path(DATA_PATH_PREFIX+"helloworld.tar"))); |
132 |
new Path(DATA_PATH_PREFIX + ARCHIVE_HELLOWORLD + ".tar"))); |
| 118 |
WizardProjectsImportPage wpip = getNewWizard(); |
133 |
WizardProjectsImportPage wpip = getNewWizard(); |
| 119 |
HashSet projects = new HashSet(); |
134 |
HashSet projects = new HashSet(); |
| 120 |
projects.add("HelloWorld"); |
135 |
projects.add("HelloWorld"); |
| 121 |
|
136 |
|
| 122 |
wpip.getProjectFromDirectoryRadio().setSelection((false)); //We want the other one selected |
137 |
wpip.getProjectFromDirectoryRadio().setSelection((false)); //We want the other one selected |
| 123 |
wpip.updateProjectsList(helloworld.getPath()); |
138 |
wpip.updateProjectsList(archiveFile.getPath()); |
| 124 |
|
139 |
|
| 125 |
ProjectRecord[] selectedProjects= wpip.getValidProjects(); |
140 |
ProjectRecord[] selectedProjects= wpip.getValidProjects(); |
| 126 |
ArrayList projectNames = new ArrayList(); |
141 |
ArrayList projectNames = new ArrayList(); |
|
Lines 196-209
Link Here
|
| 196 |
IProject[] workspaceProjects = root.getProjects(); |
211 |
IProject[] workspaceProjects = root.getProjects(); |
| 197 |
for (int i = 0; i < workspaceProjects.length; i++) |
212 |
for (int i = 0; i < workspaceProjects.length; i++) |
| 198 |
FileUtil.deleteProject(workspaceProjects[i]); |
213 |
FileUtil.deleteProject(workspaceProjects[i]); |
| 199 |
URL helloworld = Platform.asLocalURL(Platform.find(TestPlugin.getDefault().getBundle(), |
214 |
URL archiveFile = Platform.asLocalURL(Platform.find(TestPlugin.getDefault().getBundle(), |
| 200 |
new Path(DATA_PATH_PREFIX+"helloworld.zip"))); |
215 |
new Path(DATA_PATH_PREFIX + ARCHIVE_HELLOWORLD + ".zip"))); |
| 201 |
WizardProjectsImportPage wpip = getNewWizard(); |
216 |
WizardProjectsImportPage wpip = getNewWizard(); |
| 202 |
HashSet projects = new HashSet(); |
217 |
HashSet projects = new HashSet(); |
| 203 |
projects.add("HelloWorld"); |
218 |
projects.add("HelloWorld"); |
| 204 |
|
219 |
|
| 205 |
wpip.getProjectFromDirectoryRadio().setSelection((false)); //We want the other one selected |
220 |
wpip.getProjectFromDirectoryRadio().setSelection((false)); //We want the other one selected |
| 206 |
wpip.updateProjectsList(helloworld.getPath()); |
221 |
wpip.updateProjectsList(archiveFile.getPath()); |
| 207 |
|
222 |
|
| 208 |
ProjectRecord[] selectedProjects= wpip.getValidProjects(); |
223 |
ProjectRecord[] selectedProjects= wpip.getValidProjects(); |
| 209 |
ArrayList projectNames = new ArrayList(); |
224 |
ArrayList projectNames = new ArrayList(); |
|
Lines 225-231
Link Here
|
| 225 |
if (helloFolder.exists()) |
240 |
if (helloFolder.exists()) |
| 226 |
fail("Project was imported as a folder into itself"); |
241 |
fail("Project was imported as a folder into itself"); |
| 227 |
|
242 |
|
| 228 |
verifyProjectInWorkspace(true, workspaceProjects[0], ARCHIVE_FILE_LIST); |
243 |
verifyProjectInWorkspace(true, workspaceProjects[0], ARCHIVE_FILE_LIST, true); |
| 229 |
|
244 |
|
| 230 |
} catch (IOException e) { |
245 |
} catch (IOException e) { |
| 231 |
fail(e.toString()); |
246 |
fail(e.toString()); |
|
Lines 235-240
Link Here
|
| 235 |
|
250 |
|
| 236 |
} |
251 |
} |
| 237 |
|
252 |
|
|
|
253 |
public void testImportZipWithEmptyFolder(){ |
| 254 |
try { |
| 255 |
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
| 256 |
|
| 257 |
IProject[] workspaceProjects = root.getProjects(); |
| 258 |
for (int i = 0; i < workspaceProjects.length; i++) |
| 259 |
FileUtil.deleteProject(workspaceProjects[i]); |
| 260 |
URL archiveFile = Platform.asLocalURL(Platform.find(TestPlugin.getDefault().getBundle(), |
| 261 |
new Path(DATA_PATH_PREFIX + ARCHIVE_FILE_WITH_EMPTY_FOLDER + ".zip"))); |
| 262 |
WizardProjectsImportPage wpip = getNewWizard(); |
| 263 |
HashSet projects = new HashSet(); |
| 264 |
projects.add("A"); |
| 265 |
|
| 266 |
wpip.getProjectFromDirectoryRadio().setSelection((false)); //We want the other one selected |
| 267 |
wpip.updateProjectsList(archiveFile.getPath()); |
| 268 |
|
| 269 |
ProjectRecord[] selectedProjects= wpip.getValidProjects(); |
| 270 |
ArrayList projectNames = new ArrayList(); |
| 271 |
for (int i = 0; i < selectedProjects.length; i++) { |
| 272 |
projectNames.add(selectedProjects[i].getProjectName()); |
| 273 |
} |
| 274 |
|
| 275 |
assertTrue("Not all projects were found correctly in zip", projectNames.containsAll(projects)); |
| 276 |
|
| 277 |
CheckboxTreeViewer projectsList= wpip.getProjectsList(); |
| 278 |
projectsList.setCheckedElements(selectedProjects); |
| 279 |
wpip.createProjects(); // Try importing all the projects we found |
| 280 |
|
| 281 |
// "HelloWorld" should be the only project in the workspace |
| 282 |
workspaceProjects = root.getProjects(); |
| 283 |
if (workspaceProjects.length != 1) |
| 284 |
fail("Incorrect Number of projects imported"); |
| 285 |
IFolder helloFolder = workspaceProjects[0].getFolder("HelloWorld"); |
| 286 |
if (helloFolder.exists()) |
| 287 |
fail("Project was imported as a folder into itself"); |
| 288 |
|
| 289 |
verifyProjectInWorkspace(true, workspaceProjects[0], ARCHIVE_FILE_EMPTY_FOLDER_LIST, false); |
| 290 |
|
| 291 |
} catch (IOException e) { |
| 292 |
fail(e.toString()); |
| 293 |
} catch (CoreException e) { |
| 294 |
fail(e.toString()); |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 238 |
public void testImportSingleTar() { |
298 |
public void testImportSingleTar() { |
| 239 |
try { |
299 |
try { |
| 240 |
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
300 |
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
|
Lines 242-255
Link Here
|
| 242 |
IProject[] workspaceProjects = root.getProjects(); |
302 |
IProject[] workspaceProjects = root.getProjects(); |
| 243 |
for (int i = 0; i < workspaceProjects.length; i++) |
303 |
for (int i = 0; i < workspaceProjects.length; i++) |
| 244 |
FileUtil.deleteProject(workspaceProjects[i]); |
304 |
FileUtil.deleteProject(workspaceProjects[i]); |
| 245 |
URL helloworld = Platform.asLocalURL(Platform.find(TestPlugin.getDefault().getBundle(), |
305 |
URL archiveFile = Platform.asLocalURL(Platform.find(TestPlugin.getDefault().getBundle(), |
| 246 |
new Path(DATA_PATH_PREFIX+"helloworld.tar"))); |
306 |
new Path(DATA_PATH_PREFIX + ARCHIVE_HELLOWORLD + ".tar"))); |
| 247 |
WizardProjectsImportPage wpip = getNewWizard(); |
307 |
WizardProjectsImportPage wpip = getNewWizard(); |
| 248 |
HashSet projects = new HashSet(); |
308 |
HashSet projects = new HashSet(); |
| 249 |
projects.add("HelloWorld"); |
309 |
projects.add("HelloWorld"); |
| 250 |
|
310 |
|
| 251 |
wpip.getProjectFromDirectoryRadio().setSelection((false)); //We want the other one selected |
311 |
wpip.getProjectFromDirectoryRadio().setSelection((false)); //We want the other one selected |
| 252 |
wpip.updateProjectsList(helloworld.getPath()); |
312 |
wpip.updateProjectsList(archiveFile.getPath()); |
| 253 |
|
313 |
|
| 254 |
ProjectRecord[] selectedProjects= wpip.getValidProjects(); |
314 |
ProjectRecord[] selectedProjects= wpip.getValidProjects(); |
| 255 |
ArrayList projectNames = new ArrayList(); |
315 |
ArrayList projectNames = new ArrayList(); |
|
Lines 271-277
Link Here
|
| 271 |
if (helloFolder.exists()) |
331 |
if (helloFolder.exists()) |
| 272 |
fail("Project was imported as a folder into itself"); |
332 |
fail("Project was imported as a folder into itself"); |
| 273 |
|
333 |
|
| 274 |
verifyProjectInWorkspace(true, workspaceProjects[0], ARCHIVE_FILE_LIST); |
334 |
verifyProjectInWorkspace(true, workspaceProjects[0], ARCHIVE_FILE_LIST, true); |
|
|
335 |
|
| 336 |
} catch (IOException e) { |
| 337 |
fail(e.toString()); |
| 338 |
} catch (CoreException e) { |
| 339 |
fail(e.toString()); |
| 340 |
} |
| 341 |
|
| 342 |
} |
| 343 |
|
| 344 |
public void testImportTarWithEmptyFolder(){ |
| 345 |
try { |
| 346 |
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
| 347 |
|
| 348 |
IProject[] workspaceProjects = root.getProjects(); |
| 349 |
for (int i = 0; i < workspaceProjects.length; i++) |
| 350 |
FileUtil.deleteProject(workspaceProjects[i]); |
| 351 |
URL archiveFile = Platform.asLocalURL(Platform.find(TestPlugin.getDefault().getBundle(), |
| 352 |
new Path(DATA_PATH_PREFIX + ARCHIVE_FILE_WITH_EMPTY_FOLDER + ".tar"))); |
| 353 |
WizardProjectsImportPage wpip = getNewWizard(); |
| 354 |
HashSet projects = new HashSet(); |
| 355 |
projects.add("A"); |
| 356 |
|
| 357 |
wpip.getProjectFromDirectoryRadio().setSelection((false)); //We want the other one selected |
| 358 |
wpip.updateProjectsList(archiveFile.getPath()); |
| 359 |
|
| 360 |
ProjectRecord[] selectedProjects= wpip.getValidProjects(); |
| 361 |
ArrayList projectNames = new ArrayList(); |
| 362 |
for (int i = 0; i < selectedProjects.length; i++) { |
| 363 |
projectNames.add(selectedProjects[i].getProjectName()); |
| 364 |
} |
| 365 |
|
| 366 |
assertTrue("Not all projects were found correctly in tar", projectNames.containsAll(projects)); |
| 367 |
|
| 368 |
CheckboxTreeViewer projectsList= wpip.getProjectsList(); |
| 369 |
projectsList.setCheckedElements(selectedProjects); |
| 370 |
wpip.createProjects(); // Try importing all the projects we found |
| 371 |
|
| 372 |
// "HelloWorld" should be the only project in the workspace |
| 373 |
workspaceProjects = root.getProjects(); |
| 374 |
if (workspaceProjects.length != 1) |
| 375 |
fail("Incorrect Number of projects imported"); |
| 376 |
IFolder helloFolder = workspaceProjects[0].getFolder("A"); |
| 377 |
if (helloFolder.exists()) |
| 378 |
fail("Project was imported as a folder into itself"); |
| 379 |
|
| 380 |
verifyProjectInWorkspace(true, workspaceProjects[0], ARCHIVE_FILE_EMPTY_FOLDER_LIST, false); |
| 275 |
|
381 |
|
| 276 |
} catch (IOException e) { |
382 |
} catch (IOException e) { |
| 277 |
fail(e.toString()); |
383 |
fail(e.toString()); |
|
Lines 319-325
Link Here
|
| 319 |
if (helloFolder.exists()) |
425 |
if (helloFolder.exists()) |
| 320 |
fail("Project was imported as a folder into itself"); |
426 |
fail("Project was imported as a folder into itself"); |
| 321 |
|
427 |
|
| 322 |
verifyProjectInWorkspace(false, workspaceProjects[0], fileList); |
428 |
verifyProjectInWorkspace(false, workspaceProjects[0], fileList, true); |
| 323 |
|
429 |
|
| 324 |
} catch (IOException e) { |
430 |
} catch (IOException e) { |
| 325 |
fail(e.toString()); |
431 |
fail(e.toString()); |
|
Lines 370-376
Link Here
|
| 370 |
if (helloFolder.exists()) |
476 |
if (helloFolder.exists()) |
| 371 |
fail("Project was imported as a folder into itself"); |
477 |
fail("Project was imported as a folder into itself"); |
| 372 |
|
478 |
|
| 373 |
verifyProjectInWorkspace(true, workspaceProjects[0], fileList); |
479 |
verifyProjectInWorkspace(true, workspaceProjects[0], fileList, true); |
| 374 |
|
480 |
|
| 375 |
} catch (IOException e) { |
481 |
} catch (IOException e) { |
| 376 |
fail(e.toString()); |
482 |
fail(e.toString()); |
|
Lines 421-427
Link Here
|
| 421 |
if (helloFolder.exists()) |
527 |
if (helloFolder.exists()) |
| 422 |
fail("Project was imported as a folder into itself"); |
528 |
fail("Project was imported as a folder into itself"); |
| 423 |
|
529 |
|
| 424 |
verifyProjectInWorkspace(true, workspaceProjects[0], fileList); |
530 |
verifyProjectInWorkspace(true, workspaceProjects[0], fileList, true); |
| 425 |
|
531 |
|
| 426 |
// delete project but not contents |
532 |
// delete project but not contents |
| 427 |
workspaceProjects[0].delete(false, true, null); |
533 |
workspaceProjects[0].delete(false, true, null); |
|
Lines 461-467
Link Here
|
| 461 |
if (helloFolder.exists()) |
567 |
if (helloFolder.exists()) |
| 462 |
fail("Project was imported as a folder into itself"); |
568 |
fail("Project was imported as a folder into itself"); |
| 463 |
|
569 |
|
| 464 |
verifyProjectInWorkspace(true, workspaceProjects[0], fileList); |
570 |
verifyProjectInWorkspace(true, workspaceProjects[0], fileList, true); |
| 465 |
|
571 |
|
| 466 |
} catch (IOException e) { |
572 |
} catch (IOException e) { |
| 467 |
fail(e.toString()); |
573 |
fail(e.toString()); |
|
Lines 496-504
Link Here
|
| 496 |
* @param inWorkspace |
602 |
* @param inWorkspace |
| 497 |
* @param project |
603 |
* @param project |
| 498 |
*/ |
604 |
*/ |
| 499 |
private void verifyProjectInWorkspace(final boolean inWorkspace, final IProject project, String[] fileList){ |
605 |
private void verifyProjectInWorkspace(final boolean inWorkspace, final IProject project, String[] fileList, boolean isListFiles){ |
| 500 |
try { |
606 |
try { |
| 501 |
Platform.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, new NullProgressMonitor()); |
607 |
Platform.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, new NullProgressMonitor()); |
| 502 |
} catch (OperationCanceledException e) { |
608 |
} catch (OperationCanceledException e) { |
| 503 |
fail(e.getLocalizedMessage()); |
609 |
fail(e.getLocalizedMessage()); |
| 504 |
} catch (InterruptedException e) { |
610 |
} catch (InterruptedException e) { |
|
Lines 518-525
Link Here
|
| 518 |
} |
624 |
} |
| 519 |
// make sure the files in the project were imported |
625 |
// make sure the files in the project were imported |
| 520 |
for (int i = 0; i < fileList.length; i++){ |
626 |
for (int i = 0; i < fileList.length; i++){ |
|
|
627 |
IResource res = isListFiles ? (IResource)project.getFile(fileList[i]) |
| 628 |
: (IResource)project.getFolder(fileList[i]); |
| 521 |
assertTrue("Files were not imported", |
629 |
assertTrue("Files were not imported", |
| 522 |
project.getFile(fileList[i]).exists()); |
630 |
res.exists()); |
| 523 |
} |
631 |
} |
| 524 |
|
632 |
|
| 525 |
} |
633 |
} |