KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > search > dependencies > AddNewBinaryDependenciesOperation


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.search.dependencies;
12
13 import java.util.Map JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.SubProgressMonitor;
19 import org.eclipse.jdt.core.IClassFile;
20 import org.eclipse.osgi.service.resolver.ExportPackageDescription;
21 import org.eclipse.pde.core.plugin.IPluginModelBase;
22 import org.eclipse.pde.internal.core.PDECore;
23 import org.eclipse.pde.internal.core.PluginModelManager;
24 import org.eclipse.pde.internal.core.ibundle.IBundle;
25 import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
26 import org.eclipse.pde.internal.ui.PDEUIMessages;
27
28 public class AddNewBinaryDependenciesOperation extends AddNewDependenciesOperation {
29     protected IClassFile [] fClassFiles;
30
31     public AddNewBinaryDependenciesOperation(IProject project, IBundlePluginModelBase base) {
32         this(project, base, PackageFinder.getClassFiles(project, base));
33     }
34     
35     public AddNewBinaryDependenciesOperation(IProject project, IBundlePluginModelBase base, IClassFile[] classFiles) {
36         super(project, base);
37         fClassFiles = classFiles;
38     }
39     
40     protected void findSecondaryDependencies(String JavaDoc[] secDeps, Set JavaDoc ignorePkgs, Map JavaDoc additionalDeps, IBundle bundle, boolean useRequireBundle,
41             IProgressMonitor monitor) {
42         monitor.beginTask(PDEUIMessages.AddNewDependenciesOperation_searchProject, 100);
43         Set JavaDoc projectPkgs = PackageFinder.findPackagesInClassFiles(fClassFiles, new SubProgressMonitor(monitor, 75));
44         PluginModelManager manager = PDECore.getDefault().getModelManager();
45         IProgressMonitor searchMonitor = new SubProgressMonitor(monitor, 25);
46         searchMonitor.beginTask("", secDeps.length); //$NON-NLS-1$
47
for (int i = 0; i < secDeps.length; i++) {
48             IPluginModelBase base = manager.findModel(secDeps[i]);
49             if (base != null) {
50                 ExportPackageDescription pkgs[] = findExportedPackages(base.getBundleDescription());
51                 for (int j = 0; j < pkgs.length; j++) {
52                     String JavaDoc pkgName = pkgs[j].getName();
53                     if (!ignorePkgs.contains(pkgName) && projectPkgs.contains(pkgName)) {
54                         additionalDeps.put(pkgs[j], secDeps[i]);
55                         ignorePkgs.add(pkgName);
56                         if (useRequireBundle) {
57                             while (j < pkgs.length) {
58                                 ignorePkgs.add(pkgs[j].getName());
59                                 j++;
60                             }
61                         }
62                     }
63                 }
64             }
65             searchMonitor.worked(1);
66         }
67     }
68
69 }
70
Popular Tags