Exemplo n.º 1
0
 @Nullable
 public static Configuration load(final InputStream is) throws IOException, JDOMException {
   try {
     final Document document = JDOMUtil.loadDocument(is);
     final ArrayList<Element> elements = new ArrayList<Element>();
     final Element rootElement = document.getRootElement();
     final Element state;
     if (rootElement.getName().equals(COMPONENT_NAME)) {
       state = rootElement;
     } else {
       elements.add(rootElement);
       //noinspection unchecked
       elements.addAll(rootElement.getChildren("component"));
       state =
           ContainerUtil.find(
               elements,
               new Condition<Element>() {
                 public boolean value(final Element element) {
                   return "component".equals(element.getName())
                       && COMPONENT_NAME.equals(element.getAttributeValue("name"));
                 }
               });
     }
     if (state != null) {
       final Configuration cfg = new Configuration();
       cfg.loadState(state);
       return cfg;
     }
     return null;
   } finally {
     is.close();
   }
 }
Exemplo n.º 2
0
 private int importPlaces(final List<BaseInjection> injections) {
   final Map<String, Set<BaseInjection>> map =
       ContainerUtil.classify(
           injections.iterator(),
           new Convertor<BaseInjection, String>() {
             @Override
             public String convert(final BaseInjection o) {
               return o.getSupportId();
             }
           });
   final ArrayList<BaseInjection> originalInjections = new ArrayList<BaseInjection>();
   final ArrayList<BaseInjection> newInjections = new ArrayList<BaseInjection>();
   for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
     final Set<BaseInjection> importingInjections = map.get(supportId);
     if (importingInjections == null) continue;
     importInjections(
         getInjections(supportId), importingInjections, originalInjections, newInjections);
   }
   if (!newInjections.isEmpty()) configurationModified();
   replaceInjections(newInjections, originalInjections, true);
   return newInjections.size();
 }
Exemplo n.º 3
0
 public boolean setHostInjectionEnabled(
     final PsiLanguageInjectionHost host,
     final Collection<String> languages,
     final boolean enabled) {
   final ArrayList<BaseInjection> originalInjections = new ArrayList<BaseInjection>();
   final ArrayList<BaseInjection> newInjections = new ArrayList<BaseInjection>();
   for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
     for (BaseInjection injection : getInjections(support.getId())) {
       if (!languages.contains(injection.getInjectedLanguageId())) continue;
       boolean replace = false;
       final ArrayList<InjectionPlace> newPlaces = new ArrayList<InjectionPlace>();
       for (InjectionPlace place : injection.getInjectionPlaces()) {
         if (place.isEnabled() != enabled
             && place.getElementPattern() != null
             && (place.getElementPattern().accepts(host)
                 || place.getElementPattern().accepts(host.getParent()))) {
           newPlaces.add(place.enabled(enabled));
           replace = true;
         } else newPlaces.add(place);
       }
       if (replace) {
         originalInjections.add(injection);
         final BaseInjection newInjection = injection.copy();
         newInjection.setInjectionPlaces(newPlaces.toArray(new InjectionPlace[newPlaces.size()]));
         newInjections.add(newInjection);
       }
     }
   }
   if (!originalInjections.isEmpty()) {
     replaceInjectionsWithUndo(
         host.getProject(),
         newInjections,
         originalInjections,
         Collections.<PsiElement>emptyList());
     return true;
   }
   return false;
 }
 public static ArrayList<TaskRepository> loadRepositories(Element element) {
   ArrayList<TaskRepository> repositories = new ArrayList<TaskRepository>();
   for (TaskRepositoryType repositoryType : TaskRepositoryType.getRepositoryTypes()) {
     for (Object o : element.getChildren()) {
       if (((Element) o).getName().equals(repositoryType.getName())) {
         try {
           @SuppressWarnings({"unchecked"})
           TaskRepository repository =
               (TaskRepository)
                   XmlSerializer.deserialize((Element) o, repositoryType.getRepositoryClass());
           if (repository != null) {
             repository.setRepositoryType(repositoryType);
             repositories.add(repository);
           }
         } catch (XmlSerializationException e) {
           // ignore
           LOG.error(e.getMessage());
         }
       }
     }
   }
   return repositories;
 }
Exemplo n.º 5
0
  private static List<BaseInjection> loadDefaultInjections() {
    final ArrayList<Configuration> cfgList = new ArrayList<Configuration>();
    final THashSet<Object> visited = new THashSet<Object>();
    for (LanguageInjectionConfigBean configBean :
        Extensions.getExtensions(LanguageInjectionSupport.CONFIG_EP_NAME)) {
      PluginDescriptor descriptor = configBean.getPluginDescriptor();
      final ClassLoader loader = descriptor.getPluginClassLoader();
      try {
        final Enumeration<URL> enumeration = loader.getResources(configBean.getConfigUrl());
        if (enumeration == null || !enumeration.hasMoreElements()) {
          LOG.warn(descriptor.getPluginId() + ": " + configBean.getConfigUrl() + " was not found");
        } else {
          while (enumeration.hasMoreElements()) {
            URL url = enumeration.nextElement();
            if (!visited.add(url.getFile())) continue; // for DEBUG mode
            try {
              cfgList.add(load(url.openStream()));
            } catch (Exception e) {
              LOG.warn(e);
            }
          }
        }
      } catch (Exception e) {
        LOG.warn(e);
      }
    }

    final ArrayList<BaseInjection> defaultInjections = new ArrayList<BaseInjection>();
    for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
      for (Configuration cfg : cfgList) {
        final List<BaseInjection> imported = cfg.getInjections(supportId);
        defaultInjections.addAll(imported);
      }
    }
    return defaultInjections;
  }