예제 #1
1
 public void computeImports() throws CoreException {
   // some existing imports may valid and can be preserved
   Vector preservedImports = new Vector(fImports.size());
   // new imports
   ArrayList newImports = new ArrayList();
   IPluginModelBase model = null;
   for (int i = 0; i < fPlugins.size(); i++) {
     IFeaturePlugin fp = (IFeaturePlugin) fPlugins.get(i);
     ModelEntry entry = PluginRegistry.findEntry(fp.getId());
     if (entry == null) continue;
     IPluginModelBase[] models = entry.getActiveModels();
     for (int j = 0; j < models.length; j++) {
       IPluginModelBase m = models[j];
       if (fp.getVersion().equals(m.getPluginBase().getVersion())
           || fp.getVersion().equals("0.0.0")) // $NON-NLS-1$
       model = m;
     }
     if (model != null) {
       addPluginImports(preservedImports, newImports, model.getPluginBase());
       if (model.isFragmentModel()) {
         BundleDescription desc = model.getBundleDescription();
         if (desc == null) continue;
         HostSpecification hostSpec = desc.getHost();
         String id = hostSpec.getName();
         String version = null;
         int match = IMatchRules.NONE;
         VersionRange versionRange = hostSpec.getVersionRange();
         if (!(versionRange == null || VersionRange.emptyRange.equals(versionRange))) {
           version =
               versionRange.getMinimum() != null ? versionRange.getMinimum().toString() : null;
           match = PluginBase.getMatchRule(versionRange);
         }
         addNewDependency(id, version, match, preservedImports, newImports);
       }
     }
   }
   // preserve imports of features
   for (int i = 0; i < fImports.size(); i++) {
     IFeatureImport iimport = (IFeatureImport) fImports.get(i);
     if (iimport.getType() == IFeatureImport.FEATURE) preservedImports.add(iimport);
   }
   // removed = old - preserved
   Vector removedImports = ((Vector) fImports.clone());
   removedImports.removeAll(preservedImports);
   // perform remove
   fImports = preservedImports;
   if (removedImports.size() > 0) {
     fireStructureChanged(
         (IFeatureImport[]) removedImports.toArray(new IFeatureImport[removedImports.size()]),
         IModelChangedEvent.REMOVE);
   }
   // perform add
   if (newImports.size() > 0) {
     fImports.addAll(newImports);
     fireStructureChanged(
         (IFeatureImport[]) newImports.toArray(new IFeatureImport[newImports.size()]),
         IModelChangedEvent.INSERT);
   }
 }
 private IPluginModelBase findModel(IAdaptable object) {
   if (object instanceof IJavaProject) object = ((IJavaProject) object).getProject();
   if (object instanceof IProject) return PluginRegistry.findModel((IProject) object);
   if (object instanceof PersistablePluginObject) {
     return PluginRegistry.findModel(((PersistablePluginObject) object).getPluginID());
   }
   return null;
 }
 /**
  * Validates that the version of the given plug-in is available in the registry. Adds a warning if
  * the plug-in could not be found.
  *
  * @param plugin xml element describing the plug-in to look for in the registry
  * @param attr set of element attributes
  */
 private void validateVersion(Element plugin, Attr attr) {
   String id = plugin.getAttribute("id"); // $NON-NLS-1$
   String version = plugin.getAttribute("version"); // $NON-NLS-1$
   if (id.trim().length() == 0
       || version.trim().length() == 0
       || version.equals("0.0.0")) // $NON-NLS-1$
   return;
   ModelEntry entry = PluginRegistry.findEntry(id);
   if (entry != null) {
     IPluginModelBase[] allModels = entry.getActiveModels();
     for (int i = 0; i < allModels.length; i++) {
       IPluginModelBase availablePlugin = allModels[i];
       if (id.equals(availablePlugin.getPluginBase().getId())) {
         if (version.equals(availablePlugin.getPluginBase().getVersion())) {
           return;
         }
       }
     }
   }
   report(
       NLS.bind(
           PDECoreMessages.Builders_Feature_mismatchPluginVersion, new String[] {version, id}),
       getLine(plugin, attr.getName()),
       CompilerFlags.WARNING,
       PDEMarkerFactory.CAT_OTHER);
 }
  public void search(
      ISearchRequestor requestor, QuerySpecification querySpecification, IProgressMonitor monitor)
      throws CoreException {

    if (querySpecification.getLimitTo() != S_LIMIT_REF
        && querySpecification.getLimitTo() != S_LIMIT_ALL) return;

    String search;
    if (querySpecification instanceof ElementQuerySpecification) {
      IJavaElement element = ((ElementQuerySpecification) querySpecification).getElement();
      if (element instanceof IType) search = ((IType) element).getFullyQualifiedName('.');
      else search = element.getElementName();
      int type = element.getElementType();
      if (type == IJavaElement.TYPE) fSearchFor = S_FOR_TYPES;
      else if (type == IJavaElement.PACKAGE_FRAGMENT || type == IJavaElement.PACKAGE_FRAGMENT_ROOT)
        fSearchFor = S_FOR_PACKAGES;
    } else {
      fSearchFor = ((PatternQuerySpecification) querySpecification).getSearchFor();
      search = ((PatternQuerySpecification) querySpecification).getPattern();
    }
    if (fSearchFor != S_FOR_TYPES && fSearchFor != S_FOR_PACKAGES) return;
    fSearchPattern = PatternConstructor.createPattern(search, true);
    fSearchRequestor = requestor;

    IPath[] enclosingPaths = querySpecification.getScope().enclosingProjectsAndJars();
    IPluginModelBase[] pluginModels = PluginRegistry.getWorkspaceModels();
    monitor.beginTask(PDEUIMessages.ClassSearchParticipant_taskMessage, pluginModels.length);
    for (int i = 0; i < pluginModels.length; i++) {
      IProject project = pluginModels[i].getUnderlyingResource().getProject();
      if (!monitor.isCanceled() && encloses(enclosingPaths, project.getFullPath()))
        searchProject(project, monitor);
    }
  }
 protected void collectSuites(IPluginModelBase model, Set<String> visited) {
   if (!model.isEnabled()) return;
   BundleDescription description = model.getBundleDescription();
   if (!visited.add(description.getSymbolicName())) return;
   model.addModelChangedListener(this);
   listentingTo.add(model);
   for (IPluginExtension ext : model.getExtensions(true).getExtensions())
     if ("org.xpect.testSuite".equals(ext.getPoint())) {
       for (IPluginObject child : ext.getChildren()) {
         if (child instanceof IPluginElement) {
           IPluginElement pluginElement = (IPluginElement) child;
           IPluginAttribute clazz = pluginElement.getAttribute("class");
           IPluginAttribute fileExtension = pluginElement.getAttribute("fileExtension");
           if (clazz != null && fileExtension != null) {
             LazyClass<Object> lazyClass =
                 LazyClass.create(
                     Object.class, clazz.getValue(), (Function<String, Class<?>>) null);
             TestSuiteInfo info =
                 new TestSuiteInfo(lazyClass, Collections.singleton(fileExtension.getValue()));
             this.extToInfo.put(fileExtension.getValue(), info);
           }
         }
       }
     }
   for (BundleDescription desc : description.getDependents()) {
     collectSuites(PluginRegistry.findModel(desc), visited);
   }
 }
 private void loadManifestAndIntroIds(boolean onlyLoadManifest) {
   TreeSet<String> result = new TreeSet<String>();
   String introId;
   IExtension[] extensions =
       PDECore.getDefault()
           .getExtensionsRegistry()
           .findExtensions("org.eclipse.ui.intro", true); // $NON-NLS-1$
   for (int i = 0; i < extensions.length; i++) {
     IConfigurationElement[] children = extensions[i].getConfigurationElements();
     for (int j = 0; j < children.length; j++) {
       if ("introProductBinding".equals(children[j].getName())) { // $NON-NLS-1$
         String attribute = children[j].getAttribute("productId"); // $NON-NLS-1$
         if (attribute != null && attribute.equals(getProduct().getProductId())) {
           if (fManifest == null) {
             IPluginModelBase base =
                 PluginRegistry.findModel(extensions[i].getContributor().getName());
             if (base == null) continue;
             fManifest = (IFile) base.getUnderlyingResource();
           }
           if (onlyLoadManifest) return;
           introId = children[j].getAttribute("introId"); // $NON-NLS-1$
           if (introId != null) result.add(introId);
         }
       }
     }
   }
   fAvailableIntroIds = result.toArray(new String[result.size()]);
 }
예제 #7
0
 /**
  * This will search through the workspace for a plugin defined with the given symbolic name and
  * return it if any.
  *
  * @param bundleName Symbolic name of the plugin we're searching a workspace project for.
  * @return The workspace project of the given symbolic name, <code>null</code> if none could be
  *     found.
  */
 public static IProject getProject(String bundleName) {
   for (IPluginModelBase model : PluginRegistry.getWorkspaceModels()) {
     if (model.getBundleDescription().getSymbolicName().equals(bundleName)) {
       return model.getUnderlyingResource().getProject();
     }
   }
   return null;
 }
 private void initializePluginModel() {
   IPluginModelBase base = PluginRegistry.findModel(getPluginProject());
   // should never happen
   if (base == null) return;
   if (base instanceof IBundlePluginModelBase)
     fExtensionsModel = ((IBundlePluginModelBase) base).getExtensionsModel();
   else fExtensionsModel = base;
 }
 protected void collectSuites() {
   if (this.extToInfo == null) {
     for (IModelChangeProvider provider : listentingTo) provider.removeModelChangedListener(this);
     listentingTo.clear();
     this.extToInfo = Maps.newHashMap();
     IPluginModelBase xpect = PluginRegistry.findModel("org.xpect");
     collectSuites(xpect, Sets.<String>newHashSet());
   }
 }
예제 #10
0
 private void initializeModel(IStructuredSelection selection) {
   Object selected = selection.getFirstElement();
   if (selected instanceof IAdaptable) {
     IResource resource = (IResource) ((IAdaptable) selected).getAdapter(IResource.class);
     if (resource != null) {
       IProject project = resource.getProject();
       fModel = PluginRegistry.findModel(project);
     }
   }
 }
예제 #11
0
 /**
  * This will install or refresh the given workspace contribution if needed, then search through it
  * for a class corresponding to <code>qualifiedName</code>.
  *
  * @param project The project that is to be dynamically installed when Acceleo searches for
  *     workspace contributions.
  * @param qualifiedName The qualified name of the class we seek to load.
  * @return An instance of the class <code>qualifiedName</code> if it could be found in the
  *     workspace bundles, <code>null</code> otherwise.
  */
 public synchronized Class<?> getClass(IProject project, String qualifiedName) {
   Class<?> instance = null;
   addWorkspaceContribution(project);
   refreshContributions();
   final IPluginModelBase model = PluginRegistry.findModel(project);
   final Bundle installedBundle = workspaceInstalledBundles.get(model);
   if (installedBundle != null) {
     instance = internalLoadClass(installedBundle, qualifiedName);
   }
   return instance;
 }
 // Copied from PDEClasspathContainer#resolveLibraryInFragments
 protected static IPluginModelBase resolveLibraryInFragments(
     IPluginModelBase model, String libraryName) {
   BundleDescription desc = model.getBundleDescription();
   if (desc != null) {
     BundleDescription[] fragments = desc.getFragments();
     for (int i = 0; i < fragments.length; i++) {
       if (new File(fragments[i].getLocation(), libraryName).exists())
         return PluginRegistry.findModel(fragments[i]);
     }
   }
   return null;
 }
 private void computeUnmigrated() {
   IPluginModelBase[] models = PluginRegistry.getWorkspaceModels();
   ArrayList<IPluginModelBase> modelArray = new ArrayList<IPluginModelBase>();
   try {
     for (int i = 0; i < models.length; i++) {
       if (models[i].getUnderlyingResource().getProject().hasNature(JavaCore.NATURE_ID))
         modelArray.add(models[i]);
     }
   } catch (CoreException e) {
     PDEPlugin.logException(e);
   }
   fUnmigrated = modelArray.toArray(new IPluginModelBase[modelArray.size()]);
 }
예제 #14
0
 /**
  * This will check through the dependencies of <code>model</code> and install the necessary
  * workspace plugins if they are required.
  *
  * @param model The model of which we wish the dependencies checked.
  */
 private void checkRequireBundleDependencies(IPluginModelBase model) {
   final BundleDescription desc = model.getBundleDescription();
   if (desc == null) {
     return;
   }
   for (BundleSpecification requiredBundle : desc.getRequiredBundles()) {
     for (IPluginModelBase workspaceModel : PluginRegistry.getWorkspaceModels()) {
       if (requiredBundle.isSatisfiedBy(workspaceModel.getBundleDescription())) {
         installBundle(workspaceModel);
         break;
       }
     }
   }
 }
  // Adapted from RequiredPluginsClassPathContainer#addPlugin and
  // PDEClasspathContainer#addExternalPlugin
  private void createEntry(BundleDescription desc, LinkedList<IClasspathEntry> entries) {
    IPluginModelBase model = PluginRegistry.findModel(desc);
    IResource resource = model.getUnderlyingResource();
    // Rule[] rules = useInclusions ? getInclusions(map, model) : null;
    if (resource != null) {
      entries.add(JavaCore.newProjectEntry(resource.getProject().getFullPath()));
      // addProjectEntry(resource.getProject(), rules, entries);
    } else {
      if (new File(model.getInstallLocation()).isFile()) {
        String installLocation = model.getInstallLocation();
        // This is to make it work in windows...
        if (!installLocation.startsWith("/")) {
          installLocation = "/" + installLocation;
        }
        IPath libraryLocation_ = Path.fromOSString(installLocation);
        entries.add(JavaCore.newLibraryEntry(libraryLocation_, null, null));

        // IPath libraryLocation_ = Path.fromPortableString(model.getInstallLocation());
        // entries.add( JavaCore.newLibraryEntry(libraryLocation_, null, null) );
      } else {
        IPluginLibrary[] libraries = model.getPluginBase().getLibraries();
        for (int i = 0; i < libraries.length; i++) {
          if (IPluginLibrary.RESOURCE.equals(libraries[i].getType())) continue;
          model = (IPluginModelBase) libraries[i].getModel();

          String name = libraries[i].getName();
          String expandedName = ClasspathUtilCore.expandLibraryName(name);
          IPath path = getPath(model, expandedName);
          if (path == null
              && !model.isFragmentModel()
              && ClasspathUtilCore.containsVariables(name)) {
            model = resolveLibraryInFragments(model, expandedName);
            if (model != null && model.isEnabled()) path = getPath(model, expandedName);
          }
          if (path != null && !path.toFile().isDirectory()) {
            entries.add(
                JavaCore.newLibraryEntry(
                    path, ClasspathUtilCore.getSourceAnnotation(model, expandedName), null));
            // addLibraryEntry(path, ClasspathUtilCore.getSourceAnnotation(model, expandedName),
            // rules, getClasspathAttributes(model), entries);
          } else if (path != null) {
            // is a directory
            entries.add(
                JavaCore.newLibraryEntry(
                    path, ClasspathUtilCore.getSourceAnnotation(model, expandedName), null));
          }
        }
      }
    }
  }
  private void validateUnpack(Element parent) {
    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.F_UNRESOLVED_PLUGINS);
    if (severity == CompilerFlags.IGNORE) {
      return;
    }
    if (severity == CompilerFlags.ERROR) {
      // this might not be an error, so max the flag at WARNING level.
      severity = CompilerFlags.WARNING;
    }
    String unpack = parent.getAttribute("unpack"); // $NON-NLS-1$
    IPluginModelBase pModel = PluginRegistry.findModel(parent.getAttribute("id")); // $NON-NLS-1$
    if (pModel == null) {
      return;
    }

    if (pModel instanceof IBundlePluginModel) {
      IBundlePluginModel bModel = (IBundlePluginModel) pModel;
      IManifestHeader header =
          bModel
              .getBundleModel()
              .getBundle()
              .getManifestHeader(ICoreConstants.ECLIPSE_BUNDLE_SHAPE);
      if (header != null) {
        String value = header.getValue();
        String unpackValue =
            "true".equals(unpack) ? "jar" : "dir"; // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        if (value != null && !value.equalsIgnoreCase(unpackValue)) {
          String message =
              NLS.bind(
                  PDECoreMessages.Builders_Feature_mismatchUnpackBundleShape,
                  (new String[] {
                    "unpack=" + unpack, parent.getAttribute("id"), "Eclipse-BundleShape: " + value
                  })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          report(message, getLine(parent), severity, PDEMarkerFactory.CAT_OTHER);
        }
      }
    }

    if ("true".equals(unpack)
        && !CoreUtility.guessUnpack(pModel.getBundleDescription())) { // $NON-NLS-1$
      String message =
          NLS.bind(
              PDECoreMessages.Builders_Feature_missingUnpackFalse,
              (new String[] {
                parent.getAttribute("id"), "unpack=\"false\""
              })); //$NON-NLS-1$ //$NON-NLS-2$
      report(message, getLine(parent), severity, PDEMarkerFactory.CAT_OTHER);
    }
  }
 private void computeSelected(Collection<?> initialSelection) {
   if (initialSelection == null || initialSelection.size() == 0) return;
   Set<IPluginModelBase> selected = new HashSet<IPluginModelBase>();
   Iterator<?> iter = initialSelection.iterator();
   while (iter.hasNext()) {
     Object obj = iter.next();
     if (obj instanceof IProject) {
       IPluginModelBase model = PluginRegistry.findModel((IProject) obj);
       if (model != null) {
         selected.add(model);
       }
     }
   }
   fSelected = selected.toArray(new IPluginModelBase[selected.size()]);
 }
예제 #18
0
  public static IPluginModelBase resolveTargetBundleEntry(BundleEntry e) {
    final String[] bundleId = splitBundleId(e);

    final String id = bundleId[0];
    final String version = bundleId[1];

    final ModelEntry entry = PluginRegistry.findEntry(id);
    if (entry == null) {
      return null;
    }

    final IPluginModelBase[] models = entry.getExternalModels();

    return findClosestPluginMatch(version, models);
  }
예제 #19
0
 private static String getServletBridgeAbsolutePath() {
   String result = null;
   ModelEntry entry = PluginRegistry.findEntry(Validator.SERVLET_BRIDGE_ID);
   if (entry != null) {
     IPluginModelBase[] targetModels = entry.getExternalModels();
     for (int i = 0; i < targetModels.length && result == null; i++) {
       IPluginModelBase bridgeModel = targetModels[i];
       String libLocation = bridgeModel.getInstallLocation();
       if (libLocation != null && libLocation.toLowerCase().indexOf(".jar") != -1) // $NON-NLS-1$
       {
         result = libLocation;
       }
     }
   }
   return result;
 }
예제 #20
0
 protected void validatePluginIDRef(Element element, Attr attr) {
   if (!validatePluginID(element, attr)) {
     return;
   }
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNRESOLVED_IMPORTS);
   if ("true".equals(element.getAttribute("optional"))
       && severity == CompilerFlags.ERROR) // $NON-NLS-1$ //$NON-NLS-2$
   severity = CompilerFlags.WARNING;
   if (severity != CompilerFlags.IGNORE) {
     IPluginModelBase model = PluginRegistry.findModel(attr.getValue());
     if (model == null || !model.isEnabled()) {
       report(
           NLS.bind(PDECoreMessages.Builders_Manifest_dependency, attr.getValue()),
           getLine(element, attr.getName()),
           severity,
           PDEMarkerFactory.CAT_FATAL);
     }
   }
 }
예제 #21
0
 /**
  * This will check the indirect dependencies of <code>model</code> and install the necessary
  * workspace plugins if we need to import some of their packages.
  *
  * @param model The model of which we wish the dependencies checked.
  */
 private void checkImportPackagesDependencies(IPluginModelBase model) {
   final BundleDescription desc = model.getBundleDescription();
   if (desc == null) {
     return;
   }
   for (ImportPackageSpecification importPackage : desc.getImportPackages()) {
     for (IPluginModelBase workspaceModel : PluginRegistry.getWorkspaceModels()) {
       if (workspaceModel != null && workspaceModel.getBundleDescription() != null) {
         for (ExportPackageDescription export :
             workspaceModel.getBundleDescription().getExportPackages()) {
           if (importPackage.isSatisfiedBy(export)) {
             installBundle(workspaceModel);
             break;
           }
         }
       }
     }
   }
 }
 private void validatePluginID(Element element, Attr attr, boolean isFragment) {
   String id = attr.getValue();
   if (!validatePluginID(element, attr)) {
     return;
   }
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.F_UNRESOLVED_PLUGINS);
   if (severity != CompilerFlags.IGNORE) {
     IPluginModelBase model = PluginRegistry.findModel(id);
     if (model == null
         || !model.isEnabled()
         || (isFragment && !model.isFragmentModel())
         || (!isFragment && model.isFragmentModel())) {
       report(
           NLS.bind(PDECoreMessages.Builders_Feature_reference, id),
           getLine(element, attr.getName()),
           severity,
           PDEMarkerFactory.CAT_OTHER);
     }
   }
 }
예제 #23
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
  */
 public void resourceChanged(IResourceChangeEvent event) {
   switch (event.getType()) {
       /*
        * Closing and deleting projects trigger the same actions : we must remove the model listener and
        * uninstall the bundle.
        */
     case IResourceChangeEvent.PRE_CLOSE:
     case IResourceChangeEvent.PRE_DELETE:
       if (event.getResource() instanceof IProject) {
         final IProject project = (IProject) event.getResource();
         final IPluginModelBase model = PluginRegistry.findModel(project);
         if (model != null) {
           final Bundle bundle = workspaceInstalledBundles.remove(model);
           changedContributions.remove(model);
           if (bundle != null) {
             try {
               uninstallBundle(bundle);
             } catch (BundleException e) {
               AcceleoCommonPlugin.log(
                   new Status(
                       IStatus.ERROR,
                       AcceleoCommonPlugin.PLUGIN_ID,
                       AcceleoCommonMessages.getString(
                           UNINSTALLATION_FAILURE_KEY, bundle.getSymbolicName()),
                       e));
             }
           }
         }
       }
       break;
     case IResourceChangeEvent.POST_BUILD:
       processBuildEvent(event);
       break;
     case IResourceChangeEvent.POST_CHANGE:
     default:
       // no default action
   }
 }
  private void initialize() {
    if (fWorkingSet != null) {
      HashSet<String> set = new HashSet<String>();
      IAdaptable[] elements = fWorkingSet.getElements();
      for (int i = 0; i < elements.length; i++) {
        if (elements[i] instanceof PersistablePluginObject)
          set.add(((PersistablePluginObject) elements[i]).getPluginID());
      }

      IPluginModelBase[] bases = PluginRegistry.getAllModels();
      for (int i = 0; i < bases.length; i++) {

        String id = bases[i].getPluginBase().getId();
        if (id == null) continue;
        if (set.contains(id)) {
          fTree.getCheckboxTreeViewer().setChecked(bases[i], true);
          set.remove(id);
        }
        if (set.isEmpty()) break;
      }
      fWorkingSetName.setText(fWorkingSet.getName());
    }
  }
  protected void doIncludeVersions(NameVersionDescriptor[] descriptions) throws Exception {
    String bsn = MULTI_VERSION_LOW_DESCRIPTION.getId();

    IPath extras = extractMultiVersionPlugins();
    ITargetDefinition target = getNewTarget();
    ITargetLocation container = getTargetService().newDirectoryLocation(extras.toOSString());
    target.setTargetLocations(new ITargetLocation[] {container});
    target.setIncluded(descriptions);
    try {
      getTargetService().saveTargetDefinition(target);
      setTargetPlatform(target);
      IPluginModelBase[] models = PluginRegistry.getExternalModels();
      Set enabled = new HashSet();
      for (int i = 0; i < models.length; i++) {
        IPluginModelBase pm = models[i];
        if (pm.getBundleDescription().getSymbolicName().equals(bsn)) {
          NameVersionDescriptor desc =
              new NameVersionDescriptor(
                  pm.getPluginBase().getId(), pm.getPluginBase().getVersion());
          if (pm.isEnabled()) {
            enabled.add(desc);
          }
        }
      }
      if (descriptions == null) {

      } else {
        assertEquals("Wrong number of enabled bundles", descriptions.length, enabled.size());
        for (int i = 0; i < descriptions.length; i++) {
          assertTrue("Missing bundle", enabled.contains(descriptions[i]));
        }
      }
    } finally {
      getTargetService().deleteTarget(target.getHandle());
      resetTargetPlatform();
    }
  }
 public Object[] getElements(Object inputElement) {
   return PluginRegistry.getAllModels();
 }
  // see
  // http://www.devdaily.com/java/jwarehouse/eclipse/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerInitializer.java.shtml
  // see
  // http://grepcode.com/file/repository.grepcode.com/java/eclipse.org/3.6.1/org.eclipse.jdt.junit/core/3.6.1/org/eclipse/jdt/internal/junit/buildpath/BuildPathSupport.java#BuildPathSupport.JUnitPluginDescription.getLibraryEntry
  private EclecticContainerInternal getNewContainer(IPath containerPath) {
    // IPath bundleLocation  = new Path(org.eclectic.idc.Activator.getBundle().getLocation());
    // IClasspathEntry entry = JavaCore.newLibraryEntry(
    //		bundleLocation.append("eclectic-runtime.jar"), null, null);

    // I may need to touch raw classpath according to the clojure example, but i don't know why

    // Eclectic-runtime
    /*
    File libFile = getJarInsidePlugin(org.eclectic.idc.Activator.getBundle().getSymbolicName(), "eclectic-runtime");
    IPath libraryLocation = Path.fromOSString(libFile.getAbsolutePath());

    IPluginModelBase srcPlugin = PluginRegistry.findModel(org.eclectic.idc.Activator.getBundle().getSymbolicName());
    IClasspathEntry entryEclecticRuntime = JavaCore.newLibraryEntry(libraryLocation,
    		Path.fromPortableString(srcPlugin.getInstallLocation()), null);

    // Eclectic-modelhandling
    File libFile2 = getJarInsidePlugin(org.eclectic.idc.Activator.getBundle().getSymbolicName(), "eclectic-modeling");
    IPath libraryLocation2 = Path.fromOSString(libFile2.getAbsolutePath());
    IClasspathEntry entryEclecticModeling = JavaCore.newLibraryEntry(libraryLocation2, null, null);
    */

    // Bundle bundle = Platform.getBundle("org.eclipse.emf.ecore");
    // Path path = new Path("icons/sample.gif");
    //   URL fileURL = FileLocator.find(bundle, path, null);
    //   InputStream in = fileURL.openStream();

    LinkedList<BundleDescription> bundleDescriptions = new LinkedList<BundleDescription>();
    bundleDescriptions.add(
        PluginRegistry.findModel("org.eclipse.emf.ecore").getBundleDescription());
    bundleDescriptions.add(
        PluginRegistry.findModel("org.eclipse.emf.ecore.xmi").getBundleDescription());
    bundleDescriptions.add(PluginRegistry.findModel("org.eclectic.idc").getBundleDescription());
    bundleDescriptions.add(
        PluginRegistry.findModel("org.eclectic.modeling").getBundleDescription());
    bundleDescriptions.add(
        PluginRegistry.findModel("org.eclectic.javaflow").getBundleDescription());
    // To allow loading a description to create an ApiModel -> maybe it could be removed in the
    // future
    bundleDescriptions.add(
        PluginRegistry.findModel("org.eclectic.apidesc.language").getBundleDescription());
    bundleDescriptions.add(
        PluginRegistry.findModel("org.eclectic.streamdesc.language").getBundleDescription());
    bundleDescriptions.add(PluginRegistry.findModel("com.google.inject").getBundleDescription());
    bundleDescriptions.add(PluginRegistry.findModel("javax.inject").getBundleDescription());
    bundleDescriptions.add(PluginRegistry.findModel("com.google.guava").getBundleDescription());

    fillWithDependent(bundleDescriptions);

    LinkedList<IClasspathEntry> entries = new LinkedList<IClasspathEntry>();
    for (int i = 0; i < bundleDescriptions.size(); i++) {
      BundleDescription bundleDescription = bundleDescriptions.get(i);

      // IPluginModelBase plugin = PluginRegistry.findModel(bundleDescription);
      // IPath libraryLocation_ = Path.fromPortableString(plugin.getInstallLocation());
      // IClasspathEntry entry_ = JavaCore.newLibraryEntry(libraryLocation_, null, null);

      createEntry(bundleDescription, entries);
    }

    // entries.add( entryEclecticRuntime );
    // entries.add( entryEclecticModeling );

    File libFile2 =
        getJarInsidePlugin(
            org.eclectic.idc.Activator.getBundle().getSymbolicName(),
            "lib-instrumented/idc-instrumented");
    IPath libraryLocation2 = Path.fromOSString(libFile2.getAbsolutePath());
    IClasspathEntry entryIdcInstrumentedClasses =
        JavaCore.newLibraryEntry(libraryLocation2, null, null);
    entries.add(entryIdcInstrumentedClasses);

    String javaflow =
        PluginRegistry.findModel("org.eclectic.javaflow").getBundleDescription().getSymbolicName();
    File libFile3 = getJarInsidePlugin(javaflow, "lib/commons-logging-api-1.1.1");
    IPath libraryLocation3 = Path.fromOSString(libFile3.getAbsolutePath());
    IClasspathEntry javaflow3 = JavaCore.newLibraryEntry(libraryLocation3, null, null);
    entries.add(javaflow3);

    File libFile4 = getJarInsidePlugin(javaflow, "lib/commons-logging-1.1.1");
    IPath libraryLocation4 = Path.fromOSString(libFile4.getAbsolutePath());
    IClasspathEntry javaflow4 = JavaCore.newLibraryEntry(libraryLocation4, null, null);
    entries.add(javaflow4);

    IClasspathEntry[] entriesAsArray = new IClasspathEntry[entries.size()];
    entries.toArray(entriesAsArray);
    return new EclecticContainerInternal(containerPath, entriesAsArray);
  }
예제 #28
0
    /**
     * This will process IResourceChangeEvent.POST_BUILD events so that we can react to builds of
     * our workspace loaded services.
     *
     * @param event The event that is to be processed. Assumes that <code>
     *     event.getType() == IResourceChangeEvent.POST_BUILD</code>.
     */
    private void processBuildEvent(IResourceChangeEvent event) {
      final IResourceDelta delta = event.getDelta();
      switch (event.getBuildKind()) {
        case IncrementalProjectBuilder.AUTO_BUILD:
          // Nothing built in such cases
          if (!ResourcesPlugin.getWorkspace().isAutoBuilding()) {
            break;
          }
          // Fall through to the incremental build handling otherwise
          // $FALL-THROUGH$
        case IncrementalProjectBuilder.INCREMENTAL_BUILD:
          final AcceleoDeltaVisitor visitor = new AcceleoDeltaVisitor();
          try {
            delta.accept(visitor);
          } catch (CoreException e) {
            AcceleoCommonPlugin.log(e, false);
          }
          for (IProject changed : visitor.getChangedProjects()) {
            IPluginModelBase model = PluginRegistry.findModel(changed);
            if (model != null) {
              changedContributions.add(model);
            }
          }
          for (String changedClass : visitor.getChangedClasses()) {
            final WorkspaceClassInstance workspaceInstance =
                workspaceLoadedClasses.get(changedClass);
            if (workspaceInstance != null) {
              workspaceInstance.setStale(true);
            }
          }
          break;
        case IncrementalProjectBuilder.FULL_BUILD:
          for (Map.Entry<IPluginModelBase, Bundle> entry : workspaceInstalledBundles.entrySet()) {
            IPluginModelBase model = entry.getKey();
            if (model != null) {
              changedContributions.add(model);
            }
          }
          for (WorkspaceClassInstance workspaceInstance : workspaceLoadedClasses.values()) {
            workspaceInstance.setStale(true);
          }
          break;
        case IncrementalProjectBuilder.CLEAN_BUILD:
          // workspace has been cleaned. Unload every service until next they're built
          final Iterator<Map.Entry<IPluginModelBase, Bundle>> workspaceBundleIterator =
              workspaceInstalledBundles.entrySet().iterator();
          while (workspaceBundleIterator.hasNext()) {
            Map.Entry<IPluginModelBase, Bundle> entry = workspaceBundleIterator.next();
            final Bundle bundle = entry.getValue();

            try {
              uninstallBundle(bundle);
            } catch (BundleException e) {
              AcceleoCommonPlugin.log(
                  new Status(
                      IStatus.ERROR,
                      AcceleoCommonPlugin.PLUGIN_ID,
                      AcceleoCommonMessages.getString(
                          UNINSTALLATION_FAILURE_KEY, bundle.getSymbolicName()),
                      e));
            }

            workspaceBundleIterator.remove();
          }
          for (WorkspaceClassInstance workspaceInstance : workspaceLoadedClasses.values()) {
            workspaceInstance.setStale(true);
          }
          break;
        default:
          // no default action
      }
    }
  /**
   * Creates a URL describing the location of a included schema. First looks up the plug-in in the
   * schema registry, then tries additional source locations, then looks for a co-located plug-in,
   * then looks in the additional search path locations.
   *
   * @param pluginID ID of the plug-in owning the schema
   * @param path the path to the schema inside the plug-in
   * @param parentURL url of the parent schema file
   * @param additionalSearchPath list of additional locations to search; only used with the <code>
   *     pde.convertSchemaToHTML</code> Ant task
   * @return a url location of the included schema or <code>null</code>
   */
  private static URL getPluginRelativePath(
      String pluginID, IPath path, URL parentURL, List<IPath> additionalSearchPath) {
    // Start by looking in the schema registry
    URL url = SchemaRegistry.getSchemaURL(pluginID, path.toString());

    // Next search source locations
    if (url == null) {
      IPluginModelBase model = PluginRegistry.findModel(pluginID);
      if (model != null)
        url = SchemaRegistry.getSchemaFromSourceExtension(model.getPluginBase(), path);
    }

    File parentFile = null;
    if (url == null && parentURL != null) {
      try {
        parentFile = URIUtil.toFile(URIUtil.toURI(parentURL));
      } catch (URISyntaxException e) {
      }
    }

    // If we are running the ant task, see if another project co-located with the parent contains
    // the schema file
    // The project folder must have the plug-in ID as its file name
    if (url == null && parentFile != null) {
      try {
        // assuming schemas are located in: pluginId/schema/schemaFile.exsd (need to go up to parent
        // of plug-in directory)
        File pluginFile = new File(parentFile + "/../../../" + pluginID); // $NON-NLS-1$
        if (pluginFile.isDirectory()) {
          File schemaFile = new File(pluginFile, path.toOSString());
          if (schemaFile.exists()) {
            url = schemaFile.toURL();
          }
          // This is how we would extract the schema from a jar, but in practice this will never be
          // the case
          // because when a bundle is built, the schema files are moved to the source bundle, not
          // the bundle we are checking
          //					} else if (CoreUtility.jarContainsResource(pluginFile, path.toPortableString(),
          // false)) {
          //						url = new URL("jar:file:" + pluginFile.getAbsolutePath() + "!/" + path);
          // //$NON-NLS-1$ //$NON-NLS-2$
        }
      } catch (MalformedURLException e) {
      }
    }

    // If we are running the ant task, additional search locations may be provided
    // The project folder must have the plug-in ID as its file name
    if (url == null && additionalSearchPath != null) {
      for (IPath searchPath : additionalSearchPath) {
        File pluginFile = null;
        if (searchPath.isAbsolute()) {
          // Append plug-in id directly to absolute paths
          pluginFile = new File(searchPath.toFile(), pluginID);
        } else if (parentFile != null) {
          // Append relative path to parent file location
          File file = new File(parentFile, searchPath.toOSString());
          pluginFile = new File(file, pluginID);
        }

        if (pluginFile != null && pluginFile.isDirectory()) {
          try {
            File schemaFile = new File(pluginFile, path.toOSString());
            if (schemaFile.exists()) {
              url = schemaFile.toURL();
              break;
            }
          } catch (MalformedURLException e) {
          }
        }
      }
    }
    return url;
  }
예제 #30
0
 /**
  * Adds a given project to the set of projects that are to be dynamically installed.
  *
  * @param project The project that is to be dynamically installed when Acceleo searches for
  *     workspace contributions.
  */
 public synchronized void addWorkspaceContribution(IProject project) {
   final IPluginModelBase model = PluginRegistry.findModel(project);
   if (model != null && !workspaceInstalledBundles.containsKey(model)) {
     changedContributions.add(model);
   }
 }