org.eclipse.pde.core_3.7.1.v20120103_r372

  public String getExportWizardId()
  {
    return fExportWizard;
  }
  
  public void setExportWizardId(String id)
  {
    fExportWizard = id;
  }
  
  public void setActivationPolicy(String policy)
  {
    if ("lazy".equals(policy)) {
      fActivationPolicy = policy;
    } else {
      fActivationPolicy = null;
    }
  }
  
  public String getActivationPolicy()
  {
    return fActivationPolicy;
  }
  
  public void setHeader(String header, String value)
  {
    fHeaders.put(header, value);
  }
  
  public String getHeader(String header)
  {
    if (fHeaders.containsKey(header)) {
      return (String)fHeaders.get(header);
    }
    if ((fReadHeaders != null) && 
      (fReadHeaders.containsKey(header)))
    {
      String value = (String)fReadHeaders.get(header);
      if (value == null) {
        return "";
      }
      return value;
    }
    return null;
  }
  
  Map getExtraHeaders()
  {
    return fHeaders;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.project.BundleProjectDescription
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.project;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.project.IBundleClasspathEntry;
import org.eclipse.pde.core.project.IBundleProjectDescription;
import org.eclipse.pde.core.project.IBundleProjectService;
import org.eclipse.pde.core.project.IHostDescription;
import org.eclipse.pde.core.project.IPackageExportDescription;
import org.eclipse.pde.core.project.IPackageImportDescription;
import org.eclipse.pde.core.project.IRequiredBundleDescription;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.target.Messages;
import org.eclipse.team.core.ScmUrlImportDescription;
import org.eclipse.team.core.Team;
import org.eclipse.team.core.importing.provisional.IBundleImporter;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;

public final class BundleProjectService
  implements IBundleProjectService
{
  public static final String BUNDLE_IMPORTER = "BUNDLE_IMPORTER";
  public static final String PLUGIN = "PLUGIN";
  private static IBundleProjectService fgDefault;
  
  public static synchronized IBundleProjectService getDefault()
  {
    if (fgDefault == null) {
      fgDefault = new BundleProjectService();
    }
    return fgDefault;
  }
  
  public IBundleProjectDescription getDescription(IProject project)
    throws CoreException
  {
    return new BundleProjectDescription(project);
  }
  
  public IHostDescription newHost(String name, VersionRange range)
  {
    return new HostDescriptoin(name, range);
  }
  
  public IPackageImportDescription newPackageImport(String name, VersionRange range, boolean optional)
  {
    return new PackageImportDescription(name, range, optional);
  }
  
  public IPackageExportDescription newPackageExport(String name, Version version, boolean api, String[] friends)
  {
    return new PackageExportDescription(name, version, friends, api);
  }
  
  public IRequiredBundleDescription newRequiredBundle(String name, VersionRange range, boolean optional, boolean export)
  {
    return new RequiredBundleDescription(name, range, export, optional);
  }
  
  public IBundleClasspathEntry newBundleClasspathEntry(IPath sourceFolder, IPath binaryFolder, IPath library)
  {
    return new BundleClasspathSpecification(sourceFolder, binaryFolder, library);
  }
  
  public void setBundleRoot(IProject project, IPath bundleRoot)
    throws CoreException
  {
    PDEProject.setBundleRoot(project, bundleRoot == null ? null : project.getFolder(bundleRoot));
  }
  
  public IBundleImporter getSourceReferenceHandler(String id)
  {
    return null;
  }
  
  public Map getImportDescriptions(IPluginModelBase[] models)
    throws CoreException
  {
    List manifests = new ArrayList();
    List plugins = new ArrayList();
    for (int i = 0; i < models.length; i++)
    {
      String location = models[i].getInstallLocation();
      if (location != null)
      {
        Map manifest = loadManifest(new File(location));
        if (manifest != null)
        {
          manifests.add(manifest);
          plugins.add(models[i]);
        }
      }
    }
    if (!manifests.isEmpty())
    {
      Map[] marray = (Map[])manifests.toArray(new Map[manifests.size()]);
      Map result = new HashMap();
      IBundleImporter[] importers = Team.getBundleImporters();
      for (int i = 0; i < importers.length; i++)
      {
        IBundleImporter importer = importers[i];
        ScmUrlImportDescription[] descriptions = importer.validateImport(marray);
        List descriptioonList = new ArrayList();
        for (int j = 0; j < descriptions.length; j++)
        {
          ScmUrlImportDescription description = descriptions[j];
          if (description != null)
          {
            descriptioonList.add(description);
            description.setProperty("BUNDLE_IMPORTER", importer);
            description.setProperty("PLUGIN", plugins.get(j));
          }
        }
        if (!descriptioonList.isEmpty()) {
          result.put(importer, descriptioonList.toArray(new ScmUrlImportDescription[descriptioonList.size()]));
        }
      }
      return result;
    }
    return new HashMap();
  }
  
  private Map loadManifest(File bundleLocation)
    throws CoreException
  {
    ZipFile jarFile = null;
    InputStream manifestStream = null;
    String extension = new Path(bundleLocation.getName()).getFileExtension();
    try
    {
      if ((extension != null) && (extension.equals("jar")) && (bundleLocation.isFile()))
      {
        jarFile = new ZipFile(bundleLocation, 1);
        ZipEntry manifestEntry = jarFile.getEntry("META-INF/MANIFEST.MF");
        if (manifestEntry != null) {
          manifestStream = jarFile.getInputStream(manifestEntry);
        }
      }
      else
      {
        File file = new File(bundleLocation, "META-INF/MANIFEST.MF");
        if (file.exists()) {
          manifestStream = new FileInputStream(file);
        }
      }
      if (manifestStream == null) {
        return null;
      }
      return ManifestElement.parseBundleManifest(manifestStream, new Hashtable(10));
    }
    catch (BundleException e)
    {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", 102, NLS.bind(Messages.DirectoryBundleContainer_3, bundleLocation.getAbsolutePath()), e));
    }
    catch (IOException e)
    {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", 102, NLS.bind(Messages.DirectoryBundleContainer_3, bundleLocation.getAbsolutePath()), e));
    }
    finally
    {
      closeZipFileAndStream(manifestStream, jarFile);
    }
  }
  
  private void closeZipFileAndStream(InputStream stream, ZipFile jarFile)
  {
    try
    {
      if (stream != null) {
        stream.close();
      }
    }
    catch (IOException e)
    {
      PDECore.log(e);
    }
    try
    {
      if (jarFile != null) {
        jarFile.close();
      }
    }
    catch (IOException e)
    {
      PDECore.log(e);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.project.BundleProjectService
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.project;

import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.pde.core.project.IHostDescription;

public class HostDescriptoin
  extends RequirementSpecification
  implements IHostDescription
{
  public HostDescriptoin(String name, VersionRange range)
  {
    super(name, range, false, false);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.project.HostDescriptoin
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.project;

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.pde.internal.core.project.Messages";
  public static String ProjectModifyOperation_0;
  public static String ProjectModifyOperation_1;
  public static String ProjectModifyOperation_2;
  
  static
  {
    NLS.initializeMessages("org.eclipse.pde.internal.core.project.Messages", Messages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.project.Messages
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.project;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.internal.core.ICoreConstants;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.PDEManager;
import org.eclipse.pde.internal.core.PluginModelManager;
import org.osgi.service.prefs.BackingStoreException;

public class PDEProject
{
  public static final String BUNDLE_ROOT_PATH = "BUNDLE_ROOT_PATH";
  
  public static IContainer getBundleRoot(IProject project)
  {
    ProjectScope scope = new ProjectScope(project);
    IEclipsePreferences node = scope.getNode("org.eclipse.pde.core");
    if (node != null)
    {
      String string = node.get("BUNDLE_ROOT_PATH", null);
      if (string != null)
      {
        IPath path = Path.fromPortableString(string);
        return project.getFolder(path);
      }
    }
    return project;
  }
  
  public static String[] getLaunchShortcuts(IProject project)
  {
    ProjectScope scope = new ProjectScope(project);
    IEclipsePreferences node = scope.getNode("org.eclipse.pde.core");
    if (node != null)
    {
      String list = node.get("manifest.launchShortcuts", null);
      if (list != null) {
        return list.split(",");
      }
    }
    return null;
  }
  
  public static String getExportWizard(IProject project)
  {
    ProjectScope scope = new ProjectScope(project);
    IEclipsePreferences node = scope.getNode("org.eclipse.pde.core");
    if (node != null) {
      return node.get("manifest.exportWizard", null);
    }
    return null;
  }
  
  public static void setBundleRoot(IProject project, IContainer root)
    throws CoreException
  {
    if ((root != null) && (!root.getProject().equals(project))) {
      throw new IllegalArgumentException("root must be contained in the given project");
    }
    ProjectScope scope = new ProjectScope(project);
    IEclipsePreferences node = scope.getNode("org.eclipse.pde.core");
    if (node != null)
    {
      IPath path = null;
      if (root != null) {
        path = root.getProjectRelativePath();
      }
      if ((path != null) && (path.isEmpty())) {
        path = null;
      }
      String value = null;
      if (path != null) {
        value = path.toPortableString();
      }
      if (value == null) {
        node.remove("BUNDLE_ROOT_PATH");
      } else {
        node.put("BUNDLE_ROOT_PATH", value);
      }
      try
      {
        node.flush();
        
        PDECore.getDefault().getModelManager().bundleRootChanged(project);
      }
      catch (BackingStoreException e)
      {
        throw new CoreException(new Status(4, "org.eclipse.pde.core", e.getMessage(), e));
      }
    }
    else
    {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", "Failed to retrieve project scope preference settings"));
    }
  }
  
  public static IFile getManifest(IProject project)
  {
    return getBundleRelativeFile(project, ICoreConstants.MANIFEST_PATH);
  }
  
  public static IFile getBuildProperties(IProject project)
  {
    return getBundleRelativeFile(project, ICoreConstants.BUILD_PROPERTIES_PATH);
  }
  
  public static IFile getPluginXml(IProject project)
  {
    return getBundleRelativeFile(project, ICoreConstants.PLUGIN_PATH);
  }
  
  public static IFile getFragmentXml(IProject project)
  {
    return getBundleRelativeFile(project, ICoreConstants.FRAGMENT_PATH);
  }
  
  public static IFile getFeatureXml(IProject project)
  {
    return getBundleRelativeFile(project, ICoreConstants.FEATURE_PATH);
  }
  
  public static IFile getOptionsFile(IProject project)
  {
    return getBundleRelativeFile(project, new Path(".options"));
  }
  
  public static IFolder getOSGiInf(IProject project)
  {
    return getBundleRelativeFolder(project, ICoreConstants.OSGI_INF_PATH);
  }
  
  public static IFolder getMetaInf(IProject project)
  {
    return getBundleRelativeFolder(project, new Path("META-INF/"));
  }
  
  public static IFile getBundleRelativeFile(IProject project, IPath path)
  {
    return getBundleRoot(project).getFile(path);
  }
  
  public static IFolder getBundleRelativeFolder(IProject project, IPath path)
  {
    return getBundleRoot(project).getFolder(path);
  }
  
  public static IFile getLocalizationFile(IProject project)
  {
    IPluginModelBase model = PluginRegistry.findModel(project);
    String localization = PDEManager.getBundleLocalization(model);
    return getBundleRelativeFile(project, new Path(localization + ".properties"));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.project.PDEProject
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.project;

import org.eclipse.pde.core.project.IPackageExportDescription;
import org.osgi.framework.Version;

public class PackageExportDescription
  implements IPackageExportDescription
{
  private String fName;
  private Version fVersion;
  private String[] fFriends;
  private boolean fApi;
  
  public PackageExportDescription(String name, Version version, String[] friends, boolean api)
  {
    fName = name;
    fVersion = version;
    fApi = api;
    if ((friends != null) && (friends.length > 0))
    {
      fFriends = friends;
      fApi = false;
    }
  }
  
  public Version getVersion()
  {
    return fVersion;
  }
  
  public String[] getFriends()
  {
    return fFriends;
  }
  
  public boolean isApi()
  {
    return fApi;
  }
  
  public String getName()
  {
    return fName;
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof PackageExportDescription))
    {
      PackageExportDescription spec = (PackageExportDescription)obj;
      return (getName().equals(spec.getName())) && (isApi() == spec.isApi()) && (equalOrNull(getVersion(), spec.getVersion())) && (equalOrNull(getFriends(), spec.getFriends()));
    }
    return false;
  }
  
  public int hashCode()
  {
    int code = getClass().hashCode() + fName.hashCode();
    if (fVersion != null) {
      code += fVersion.hashCode();
    }
    if (fApi) {
      code++;
    }
    if (fFriends != null) {
      for (int i = 0; i < fFriends.length; i++) {
        code += fFriends[i].hashCode();
      }
    }
    return code;
  }
  
  private boolean equalOrNull(Object o1, Object o2)
  {
    if (o1 == null) {
      return o2 == null;
    }
    if (o2 == null) {
      return o1 == null;
    }
    return o1.equals(o2);
  }
  
  private boolean equalOrNull(Object[] array1, Object[] array2)
  {
    if ((array1 == null) || (array1.length == 0)) {
      return (array2 == null) || (array2.length == 0);
    }
    if ((array2 == null) || (array2.length == 0)) {
      return false;
    }
    if (array1.length != array2.length) {
      return false;
    }
    for (int i = 0; i < array1.length; i++) {
      if (!array1[i].equals(array2[i])) {
        return false;
      }
    }
    return true;
  }
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer();
    buf.append(fName);
    if (fVersion != null)
    {
      buf.append(";version=");
      buf.append(fVersion.toString());
    }
    if (fFriends != null)
    {
      buf.append(";x-friends=");
      buf.append('"');
      for (int i = 0; i < fFriends.length; i++)
      {
        if (i > 0) {
          buf.append(',');
        }
        buf.append(fFriends[i]);
      }
      buf.append('"');
    }
    else if (!fApi)
    {
      buf.append(";x-internal=true");
    }
    return buf.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.project.PackageExportDescription
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.project;

import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.pde.core.project.IPackageImportDescription;

public class PackageImportDescription
  extends RequirementSpecification
  implements IPackageImportDescription
{
  public PackageImportDescription(String name, VersionRange range, boolean optional)
  {
    super(name, range, false, optional);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.project.PackageImportDescription
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.project;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.pde.core.build.IBuild;
import org.eclipse.pde.core.build.IBuildEntry;
import org.eclipse.pde.core.build.IBuildModelFactory;
import org.eclipse.pde.core.plugin.IFragment;
import org.eclipse.pde.core.plugin.IPlugin;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginImport;
import org.eclipse.pde.core.plugin.IPluginLibrary;
import org.eclipse.pde.core.plugin.IPluginModelFactory;
import org.eclipse.pde.core.project.IBundleClasspathEntry;
import org.eclipse.pde.core.project.IBundleProjectDescription;
import org.eclipse.pde.core.project.IBundleProjectService;
import org.eclipse.pde.core.project.IHostDescription;
import org.eclipse.pde.core.project.IPackageExportDescription;
import org.eclipse.pde.core.project.IPackageImportDescription;
import org.eclipse.pde.core.project.IRequiredBundleDescription;
import org.eclipse.pde.internal.core.ClasspathComputer;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.TargetPlatformHelper;
import org.eclipse.pde.internal.core.build.WorkspaceBuildModel;
import org.eclipse.pde.internal.core.bundle.BundlePluginBase;
import org.eclipse.pde.internal.core.bundle.WorkspaceBundleFragmentModel;
import org.eclipse.pde.internal.core.bundle.WorkspaceBundleModel;
import org.eclipse.pde.internal.core.bundle.WorkspaceBundlePluginModel;
import org.eclipse.pde.internal.core.ibundle.IBundle;
import org.eclipse.pde.internal.core.ibundle.IBundleModel;
import org.eclipse.pde.internal.core.ibundle.IBundlePluginBase;
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
import org.eclipse.pde.internal.core.plugin.WorkspacePluginModelBase;
import org.eclipse.pde.internal.core.text.bundle.BundleModelFactory;
import org.eclipse.pde.internal.core.text.bundle.BundleSymbolicNameHeader;
import org.eclipse.pde.internal.core.text.bundle.ExportPackageHeader;
import org.eclipse.pde.internal.core.text.bundle.ExportPackageObject;
import org.eclipse.pde.internal.core.text.bundle.ImportPackageHeader;
import org.eclipse.pde.internal.core.text.bundle.ImportPackageObject;
import org.eclipse.pde.internal.core.text.bundle.PackageFriend;
import org.eclipse.pde.internal.core.util.CoreUtility;
import org.osgi.framework.Version;
import org.osgi.service.prefs.BackingStoreException;

public class ProjectModifyOperation
{
  private WorkspacePluginModelBase fModel;
  private static final IPath[] EXCLUDE_NONE = new IPath[0];
  
  public void execute(IProgressMonitor monitor, IBundleProjectDescription description)
    throws CoreException
  {
    IProject project = description.getProject();
    IBundleProjectService service = (IBundleProjectService)PDECore.getDefault().acquireService(IBundleProjectService.class.getName());
    IBundleProjectDescription before = service.getDescription(project);
    boolean considerRoot = !project.exists();
    String taskName = null;
    boolean jpExisted = false;
    if (project.exists())
    {
      taskName = Messages.ProjectModifyOperation_0;
      jpExisted = before.hasNature("org.eclipse.jdt.core.javanature");
    }
    else
    {
      taskName = Messages.ProjectModifyOperation_1;
      if (description.getNatureIds().length == 0) {
        description.setNatureIds(new String[] { "org.eclipse.pde.PluginNature", "org.eclipse.jdt.core.javanature" });
      }
    }
    boolean becomeBundle = (!before.hasNature("org.eclipse.pde.PluginNature")) && (description.hasNature("org.eclipse.pde.PluginNature"));
    if ((jpExisted) && (becomeBundle) && 
      (description.getExecutionEnvironments() == null))
    {
      IJavaProject jp = JavaCore.create(project);
      if (jp.exists())
      {
        IClasspathEntry[] classpath = jp.getRawClasspath();
        for (int i = 0; i < classpath.length; i++)
        {
          IClasspathEntry entry = classpath[i];
          if (entry.getEntryKind() == 5)
          {
            String id = JavaRuntime.getExecutionEnvironmentId(entry.getPath());
            if (id != null)
            {
              description.setExecutionEnvironments(new String[] { id });
              break;
            }
          }
        }
      }
    }
    if (becomeBundle) {
      if (description.getBundleVersion() == null) {
        description.setBundleVersion(new Version(1, 0, 0, "qualifier"));
      }
    }
    SubMonitor sub = SubMonitor.convert(monitor, taskName, 6);
    
    createProject(description);
    if (considerRoot)
    {
      IFolder folder = null;
      IPath root = description.getBundleRoot();
      if ((root != null) && (!root.isEmpty()))
      {
        folder = project.getFolder(root);
        CoreUtility.createFolder(folder);
      }
      PDEProject.setBundleRoot(project, folder);
    }
    sub.worked(1);
    configureNatures(description);
    sub.worked(1);
    if (project.hasNature("org.eclipse.jdt.core.javanature")) {
      configureJavaProject(description, before, jpExisted);
    }
    sub.worked(1);
    configureManifest(description, before);
    sub.worked(1);
    configureBuildPropertiesFile(description, before);
    sub.worked(1);
    
    IEclipsePreferences pref = new ProjectScope(project).getNode("org.eclipse.pde.core");
    if (pref != null)
    {
      if ((description.isEquinox()) && (description.isExtensionRegistry())) {
        pref.remove("resolve.requirebundle");
      } else {
        pref.putBoolean("resolve.requirebundle", false);
      }
      if (description.isExtensionRegistry()) {
        pref.remove("pluginProject.extensions");
      } else {
        pref.putBoolean("pluginProject.extensions", false);
      }
      if (description.isEquinox()) {
        pref.remove("pluginProject.equinox");
      } else {
        pref.putBoolean("pluginProject.equinox", false);
      }
      String[] shorts = description.getLaunchShortcuts();
      if ((shorts == null) || (shorts.length == 0))
      {
        pref.remove("manifest.launchShortcuts");
      }
      else
      {
        StringBuffer value = new StringBuffer();
        for (int i = 0; i < shorts.length; i++)
        {
          if (i > 0) {
            value.append(',');
          }
          value.append(shorts[i]);
        }
        pref.put("manifest.launchShortcuts", value.toString());
      }
      if (description.getExportWizardId() == null) {
        pref.remove("manifest.exportWizard");
      } else {
        pref.put("manifest.exportWizard", description.getExportWizardId());
      }
      try
      {
        pref.flush();
      }
      catch (BackingStoreException e)
      {
        throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.ProjectModifyOperation_2, e));
      }
    }
    if (fModel.isDirty()) {
      fModel.save();
    }
    sub.worked(1);
    sub.done();
    if (monitor != null) {
      monitor.done();
    }
  }
  
  public WorkspacePluginModelBase getModel()
  {
    return fModel;
  }
  
  private void configureJavaProject(IBundleProjectDescription description, IBundleProjectDescription before, boolean existed)
    throws CoreException
  {
    IProject project = description.getProject();
    IJavaProject javaProject = JavaCore.create(project);
    
    IBundleClasspathEntry[] bces = description.getBundleClasspath();
    if ((bces != null) && (bces.length > 0)) {
      for (int i = 0; i < bces.length; i++)
      {
        IPath folder = bces[i].getSourcePath();
        if (folder != null) {
          CoreUtility.createFolder(project.getFolder(folder));
        }
      }
    }
    if (description.getDefaultOutputFolder() != null)
    {
      IPath path = project.getFullPath().append(description.getDefaultOutputFolder());
      javaProject.setOutputLocation(path, null);
    }
    IBundleClasspathEntry[] prev = before.getBundleClasspath();
    if (!isEqual(bces, prev)) {
      if (existed)
      {
        IClasspathEntry[] entries = getSourceFolderEntries(javaProject, description);
        IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
        List add = new ArrayList();
        for (int i = 0; i < entries.length; i++)
        {
          IClasspathEntry entry = entries[i];
          boolean present = false;
          for (int j = 0; j < rawClasspath.length; j++)
          {
            IClasspathEntry existingEntry = rawClasspath[j];
            if ((existingEntry.getEntryKind() == entry.getEntryKind()) && 
              (existingEntry.getPath().equals(entry.getPath())))
            {
              present = true;
              break;
            }
          }
          if (!present) {
            add.add(entry);
          }
        }
        boolean addRequired = false;
        if (description.hasNature("org.eclipse.pde.PluginNature"))
        {
          addRequired = true;
          for (int i = 0; i < rawClasspath.length; i++)
          {
            IClasspathEntry cpe = rawClasspath[i];
            if ((cpe.getEntryKind() == 5) && 
              (PDECore.REQUIRED_PLUGINS_CONTAINER_PATH.equals(cpe.getPath())))
            {
              addRequired = false;
              break;
            }
          }
        }
        if (addRequired) {
          add.add(ClasspathComputer.createContainerEntry());
        }
        if (!add.isEmpty())
        {
          List all = new ArrayList();
          for (int i = 0; i < rawClasspath.length; i++) {
            all.add(rawClasspath[i]);
          }
          all.addAll(add);
          javaProject.setRawClasspath((IClasspathEntry[])all.toArray(new IClasspathEntry[all.size()]), null);
        }
      }
      else
      {
        IClasspathEntry[] entries = getClassPathEntries(javaProject, description);
        javaProject.setRawClasspath(entries, null);
      }
    }
  }
  
  private boolean isEqual(Object[] array1, Object[] array2)
  {
    if ((array1 == null) || (array1.length == 0)) {
      return (array2 == null) || (array2.length == 0);
    }
    if ((array2 == null) || (array2.length == 0)) {
      return false;
    }
    if (array1.length != array2.length) {
      return false;
    }
    for (int i = 0; i < array1.length; i++) {
      if (!array1[i].equals(array2[i])) {
        return false;
      }
    }
    return true;
  }
  
  private boolean isEqual(Object st1, Object st2)
  {
    if (st1 == null) {
      return st2 == null;
    }
    if (st2 == null) {
      return false;
    }
    return st1.equals(st2);
  }
  
  private IClasspathEntry[] getClassPathEntries(IJavaProject project, IBundleProjectDescription description)
    throws CoreException
  {
    IClasspathEntry[] internalClassPathEntries = getSourceFolderEntries(project, description);
    IClasspathEntry[] entries = new IClasspathEntry[internalClassPathEntries.length + 2];
    System.arraycopy(internalClassPathEntries, 0, entries, 2, internalClassPathEntries.length);
    
    String[] ids = description.getExecutionEnvironments();
    String executionEnvironment = null;
    if ((ids != null) && (ids.length > 0)) {
      executionEnvironment = ids[0];
    }
    ClasspathComputer.setComplianceOptions(project, executionEnvironment);
    entries[0] = ClasspathComputer.createJREEntry(executionEnvironment);
    entries[1] = ClasspathComputer.createContainerEntry();
    return entries;
  }
  
  private IClasspathEntry[] getSourceFolderEntries(IJavaProject project, IBundleProjectDescription description)
    throws CoreException
  {
    IBundleClasspathEntry[] folders = description.getBundleClasspath();
    if ((folders == null) || (folders.length == 0)) {
      return new IClasspathEntry[0];
    }
    List entries = new ArrayList();
    for (int i = 0; i < folders.length; i++)
    {
      IBundleClasspathEntry folder = folders[i];
      if (folder.getSourcePath() == null)
      {
        IPath bin = folder.getBinaryPath();
        if (bin == null) {
          bin = folder.getLibrary();
        }
        if (bin != null)
        {
          IPath output = project.getProject().getFullPath().append(bin);
          entries.add(JavaCore.newLibraryEntry(output, null, null));
        }
      }
      else
      {
        IPath path = project.getProject().getFullPath().append(folder.getSourcePath());
        IPath output = folder.getBinaryPath();
        if (output != null) {
          output = project.getProject().getFullPath().append(output);
        }
        entries.add(JavaCore.newSourceEntry(path, EXCLUDE_NONE, output));
      }
    }
    return (IClasspathEntry[])entries.toArray(new IClasspathEntry[entries.size()]);
  }
  
  private void createProject(IBundleProjectDescription description)
    throws CoreException
  {
    IProject project = description.getProject();
    if (!project.exists())
    {
      IProjectDescription pd = project.getWorkspace().newProjectDescription(project.getName());
      pd.setLocationURI(description.getLocationURI());
      project.create(pd, null);
    }
    if (!project.isOpen()) {
      project.open(null);
    }
  }
  
  private void configureNatures(IBundleProjectDescription description)
    throws CoreException
  {
    IProject project = description.getProject();
    IProjectDescription projectDescription = project.getDescription();
    String[] curr = projectDescription.getNatureIds();
    Set before = new HashSet();
    for (int i = 0; i < curr.length; i++) {
      before.add(curr[i]);
    }
    String[] natureIds = description.getNatureIds();
    Set after = new HashSet();
    for (int i = 0; i < natureIds.length; i++) {
      after.add(natureIds[i]);
    }
    if (!before.equals(after))
    {
      projectDescription.setNatureIds(natureIds);
      project.setDescription(projectDescription, null);
    }
  }
  
  private void configureManifest(IBundleProjectDescription description, IBundleProjectDescription before)
    throws CoreException
  {
    IProject project = description.getProject();
    IFile manifest = PDEProject.getManifest(project);
    if (description.getHost() == null) {
      fModel = new WorkspaceBundlePluginModel(manifest, PDEProject.getPluginXml(project));
    } else {
      fModel = new WorkspaceBundleFragmentModel(manifest, PDEProject.getFragmentXml(project));
    }
    IPluginBase pluginBase = fModel.getPluginBase();
    
    String targetVersion = getTargetVersion(description.getTargetVersion());
    if (!isEqual(targetVersion, getTargetVersion(before.getTargetVersion())))
    {
      String schemaVersion = TargetPlatformHelper.getSchemaVersionForTargetVersion(targetVersion);
      pluginBase.setSchemaVersion(schemaVersion);
    }
    if (!isEqual(description.getSymbolicName(), before.getSymbolicName())) {
      pluginBase.setId(description.getSymbolicName());
    }
    if (!isEqual(description.getBundleVersion(), before.getBundleVersion())) {
      pluginBase.setVersion(description.getBundleVersion().toString());
    }
    String bundleName = description.getBundleName();
    if (bundleName == null) {
      bundleName = description.getSymbolicName();
    }
    if (!isEqual(bundleName, before.getBundleName())) {
      pluginBase.setName(bundleName);
    }
    if (!isEqual(description.getBundleVendor(), before.getBundleVendor())) {
      pluginBase.setProviderName(description.getBundleVendor());
    }
    if ((fModel instanceof IBundlePluginModelBase))
    {
      IBundlePluginModelBase bmodel = (IBundlePluginModelBase)fModel;
      
      ((IBundlePluginBase)bmodel.getPluginBase()).setTargetVersion(targetVersion);
      String ver = bmodel.getBundleModel().getBundle().getHeader("Bundle-ManifestVersion");
      if (!isEqual("2", ver)) {
        bmodel.getBundleModel().getBundle().setHeader("Bundle-ManifestVersion", "2");
      }
    }
    if ((pluginBase instanceof IFragment))
    {
      IFragment fragment = (IFragment)pluginBase;
      IHostDescription host = description.getHost();
      if (!isEqual(host, before.getHost()))
      {
        fragment.setPluginId(host.getName());
        if (host.getVersionRange() != null) {
          fragment.setPluginVersion(host.getVersionRange().toString());
        } else {
          fragment.setPluginVersion(null);
        }
      }
    }
    else
    {
      String activator = description.getActivator();
      if (!isEqual(activator, before.getActivator())) {
        ((IPlugin)pluginBase).setClassName(activator);
      }
    }
    configureBundleClasspath(description, before);
    
    IRequiredBundleDescription[] dependencies = description.getRequiredBundles();
    if (!isEqual(dependencies, before.getRequiredBundles()))
    {
      IPluginImport[] imports = pluginBase.getImports();
      if ((imports != null) && (imports.length > 0)) {
        for (int i = 0; i < imports.length; i++) {
          pluginBase.remove(imports[i]);
        }
      }
      if (dependencies != null) {
        for (int i = 0; i < dependencies.length; i++)
        {
          IRequiredBundleDescription req = dependencies[i];
          VersionRange range = req.getVersionRange();
          IPluginImport iimport = fModel.getPluginFactory().createImport();
          iimport.setId(req.getName());
          if (range != null)
          {
            iimport.setVersion(range.toString());
            iimport.setMatch(2);
          }
          iimport.setReexported(req.isExported());
          iimport.setOptional(req.isOptional());
          pluginBase.add(iimport);
        }
      }
    }
    if ((pluginBase instanceof BundlePluginBase))
    {
      IBundle bundle = ((BundlePluginBase)pluginBase).getBundle();
      BundleModelFactory factory = new BundleModelFactory(bundle.getModel());
      if ((before.getHost() != null) && (description.getHost() == null)) {
        bundle.setHeader("Fragment-Host", null);
      }
      if ((description.isSingleton() != before.isSingleton()) && 
        (description.isSingleton()))
      {
        IManifestHeader header = factory.createHeader("Bundle-SymbolicName", description.getSymbolicName());
        if ((header instanceof BundleSymbolicNameHeader))
        {
          ((BundleSymbolicNameHeader)header).setSingleton(description.isSingleton());
          bundle.setHeader("Bundle-SymbolicName", header.getValue());
        }
      }
      String[] ees = description.getExecutionEnvironments();
      if (!isEqual(ees, before.getExecutionEnvironments())) {
        if (ees == null)
        {
          bundle.setHeader("Bundle-RequiredExecutionEnvironment", null);
        }
        else
        {
          StringBuffer buffer = new StringBuffer();
          for (int i = 0; i < ees.length; i++)
          {
            String id = ees[i];
            if (buffer.length() > 0) {
              buffer.append(",\n ");
            }
            buffer.append(id);
          }
          bundle.setHeader("Bundle-RequiredExecutionEnvironment", buffer.toString());
        }
      }
      IPackageImportDescription[] packages = description.getPackageImports();
      if (!isEqual(packages, before.getPackageImports())) {
        if (packages == null)
        {
          bundle.setHeader("Import-Package", null);
        }
        else
        {
          ImportPackageHeader header = (ImportPackageHeader)factory.createHeader("Import-Package", "");
          for (int i = 0; i < packages.length; i++)
          {
            IPackageImportDescription pkg = packages[i];
            ImportPackageObject ip = header.addPackage(pkg.getName());
            VersionRange range = pkg.getVersionRange();
            if (range != null) {
              ip.setVersion(range.toString());
            }
            ip.setOptional(pkg.isOptional());
          }
          header.update();
          bundle.setHeader("Import-Package", header.getValue());
        }
      }
      IPackageExportDescription[] exports = description.getPackageExports();
      if (!isEqual(exports, before.getPackageExports())) {
        if (exports == null)
        {
          bundle.setHeader("Export-Package", null);
        }
        else
        {
          ExportPackageHeader header = (ExportPackageHeader)factory.createHeader("Export-Package", "");
          for (int i = 0; i < exports.length; i++)
          {
            IPackageExportDescription pkg = exports[i];
            ExportPackageObject epo = header.addPackage(pkg.getName());
            Version version = pkg.getVersion();
            if (version != null) {
              epo.setVersion(version.toString());
            }
            String[] friends = pkg.getFriends();
            if (friends != null) {
              for (int j = 0; j < friends.length; j++) {
                epo.addFriend(new PackageFriend(epo, friends[j]));
              }
            } else {
              epo.setInternal(!pkg.isApi());
            }
          }
          header.update();
          bundle.setHeader("Export-Package", header.getValue());
        }
      }
      boolean removeActivation = false;
      if (!isEqual(description.getActivationPolicy(), before.getActivationPolicy())) {
        if ("lazy".equals(description.getActivationPolicy()))
        {
          if (description.isEquinox())
          {
            if (targetVersion.equals("3.1"))
            {
              bundle.setHeader("Eclipse-AutoStart", "true");
            }
            else
            {
              do
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd