01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.ui.tests.imports;
11:
12: import org.eclipse.core.resources.IProject;
13: import org.eclipse.core.resources.IWorkspaceRoot;
14: import org.eclipse.core.resources.ResourcesPlugin;
15: import org.eclipse.core.runtime.CoreException;
16: import org.eclipse.core.runtime.NullProgressMonitor;
17: import org.eclipse.core.runtime.OperationCanceledException;
18: import org.eclipse.jdt.core.IClasspathEntry;
19: import org.eclipse.jdt.core.IJavaProject;
20: import org.eclipse.jdt.core.IPackageFragmentRoot;
21: import org.eclipse.pde.core.plugin.IPluginModelBase;
22: import org.eclipse.pde.core.plugin.PluginRegistry;
23: import org.eclipse.pde.internal.core.PDECore;
24: import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation;
25: import org.eclipse.pde.internal.ui.wizards.imports.PluginImportWizard.ImportQuery;
26: import org.eclipse.pde.ui.tests.PDETestCase;
27:
28: public abstract class BaseImportTestCase extends PDETestCase {
29:
30: protected void runOperation(String[] symbolicNames, int type) {
31: PluginImportOperation.IImportQuery query = new ImportQuery(
32: getShell());
33: PluginImportOperation.IImportQuery executionQuery = new ImportQuery(
34: getShell());
35: final PluginImportOperation op = new PluginImportOperation(
36: getModels(symbolicNames), type, query, executionQuery,
37: false);
38:
39: try {
40: op.run(new NullProgressMonitor());
41: } catch (OperationCanceledException e) {
42: fail("Import Operation failed: " + e);
43: } catch (CoreException e) {
44: fail("Import Operation failed: " + e);
45: }
46: }
47:
48: protected IPluginModelBase[] getModels(String[] symbolicNames) {
49: IPluginModelBase[] models = new IPluginModelBase[symbolicNames.length];
50: for (int i = 0; i < symbolicNames.length; i++) {
51: IPluginModelBase model = PluginRegistry
52: .findModel(symbolicNames[i]);
53: assertNull(model.getUnderlyingResource());
54: models[i] = model;
55: }
56: return models;
57: }
58:
59: protected IProject verifyProject(String projectName) {
60: IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
61: IProject project = root.getProject(projectName);
62: assertTrue("Project " + projectName + " does not exist",
63: project.exists());
64: return project;
65: }
66:
67: protected boolean checkSourceAttached(IJavaProject jProject)
68: throws CoreException {
69: IPackageFragmentRoot[] roots = jProject
70: .getPackageFragmentRoots();
71: for (int i = 0; i < roots.length; i++) {
72: IClasspathEntry entry = roots[i].getRawClasspathEntry();
73: if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY
74: || entry.getEntryKind() != IClasspathEntry.CPE_CONTAINER
75: || !entry.getPath().equals(
76: PDECore.REQUIRED_PLUGINS_CONTAINER_PATH))
77: continue;
78: if (roots[i].getSourceAttachmentPath() == null)
79: return false;
80: }
81: return true;
82: }
83:
84: }
|