public Map<String, List<LibraryInfo>> getRoutineAndJars() {
    if (routineAndJars == null) {
      routineAndJars = new HashMap<String, List<LibraryInfo>>();
      for (IConfigurationElement current : configurationElements) {
        String routine = current.getAttribute(NAME_ATTR);
        List<LibraryInfo> jarList = routineAndJars.get(routine);
        if (jarList == null) {
          jarList = new ArrayList<LibraryInfo>();
          routineAndJars.put(routine, jarList);
        }
        IConfigurationElement[] children = current.getChildren(LIBRARY_ELE);
        for (IConfigurationElement child : children) {
          LibraryInfo libraryInfo = new LibraryInfo();
          String library = child.getAttribute(NAME_ATTR);
          libraryInfo.setLibName(library);
          IConfigurationElement[] bundleIdChildren = child.getChildren(BUNDLE_ID);
          if (bundleIdChildren == null || bundleIdChildren.length == 0) {
            libraryInfo.setBundleId(null);
          } else {
            for (IConfigurationElement bundleIdChild : bundleIdChildren) {
              String bundleId = bundleIdChild.getAttribute(BUNDLE_ID);
              libraryInfo.setBundleId(StringUtils.trimToEmpty(bundleId));
            }
          }
          if (!jarList.contains(libraryInfo)) {
            jarList.add(libraryInfo);
          }
        }
      }
    }

    return routineAndJars;
  }
Beispiel #2
0
  /**
   * DOC smallet Comment method "createRoutine".
   *
   * @param url
   * @throws PersistenceException
   */
  private void createRoutine(URL url, IPath path, String label, List<LibraryInfo> neededJars)
      throws PersistenceException {
    if (url == null) {
      throw new IllegalArgumentException();
    }
    InputStream stream = null;
    try {
      Property property = PropertiesFactory.eINSTANCE.createProperty();
      property.setId(getNextId());
      property.setLabel(label);

      ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
      stream = url.openStream();
      byte[] innerContent = new byte[stream.available()];
      stream.read(innerContent);
      stream.close();
      byteArray.setInnerContent(innerContent);

      // String basePath = System.getProperty("user.dir") + File.separator + "plugins";

      RoutineItem routineItem = PropertiesFactory.eINSTANCE.createRoutineItem();
      routineItem.setProperty(property);
      routineItem.setContent(byteArray);
      routineItem.setBuiltIn(true);
      if (neededJars != null) {
        for (LibraryInfo jar : neededJars) {
          IMPORTType type = ComponentFactory.eINSTANCE.createIMPORTType();
          type.setMESSAGE("");
          type.setNAME(label);
          type.setREQUIRED(true);
          type.setMODULE(jar.getLibName());
          type.setBundleID(jar.getBundleId());
          routineItem.getImports().add(type);
        }
      }

      if (!routineItem.getProperty().getLabel().equals(coreSerivce.getTemplateString())) {
        create(getRepositoryContext().getProject(), routineItem, path, true);
      }
    } catch (IOException ioe) {
      if (stream != null) {
        try {
          stream.close();
        } catch (IOException e) {
          throw new PersistenceException(ioe);
        }
      }
      throw new PersistenceException(ioe);
    }
  }