Java 类com.intellij.openapi.util.ClassLoaderUtil 实例源码

项目:vso-intellij    文件:TfsRequestManager.java   
private static <T> T executeRequestImpl(final URI serverUri,
                                        final Ref<Credentials> credentialsRef,
                                        final Request<T> request,
                                        final ProgressIndicator pi)
  throws Exception {
  return ClassLoaderUtil.runWithClassLoader(TfsRequestManager.class.getClassLoader(), new ThrowableComputable<T, Exception>() {
    @Override
    public T compute() throws Exception {
      Credentials credentials = credentialsRef.get();
      boolean needsAuthentication =
        credentials == null ||
        request.retrieveAuthorizedCredentials() && (credentials.getUserName().length() == 0 || credentials.getDomain().length() == 0);
      if (needsAuthentication) {
        TfsServerConnectionHelper.ServerDescriptor descriptor =
          TfsServerConnectionHelper.connect(serverUri, credentialsRef.get(), true, pi);
        credentialsRef.set(descriptor.authorizedCredentials);
      }
      return request.execute(credentialsRef.get(), serverUri, pi);
    }
  });
}
项目:vso-intellij    文件:MementoTest.java   
private static <T> T runWithPatchedClassloader(ThrowableComputable<T, Exception> computable) throws Exception {
  return ClassLoaderUtil.runWithClassLoader(new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader()) {
    @Override
    public InputStream getResourceAsStream(String name) {
      if (XML_ENTITIES_URL.equals(name)) {
        String resource = XML_ENTITIES_CONTENT;
        try {
          return new ByteArrayInputStream(resource.getBytes("UTF-8"));
        }
        catch (UnsupportedEncodingException e) {
          // should not happen, fallback
        }
      }
      return super.getResourceAsStream(name);
    }
  }, computable);
}
项目:vso-intellij    文件:WebServiceHelper.java   
public static ConfigurationContext getStubConfigurationContext() {
  return ClassLoaderUtil.runWithClassLoader(TFSVcs.class.getClassLoader(), new Computable<ConfigurationContext>() {
    public ConfigurationContext compute() {
      try {
        ConfigurationContext configContext = ConfigurationContextFactory.createDefaultConfigurationContext();
        configContext.getAxisConfiguration().addMessageBuilder(SOAP_BUILDER_KEY, new CustomSOAPBuilder());
        return configContext;
      }
      catch (Exception e) {
        LOG.error("Axis2 configuration error", e);
        return null;
      }
    }
  });
}
项目:consulo    文件:Jsr223IdeScriptEngineManagerImpl.java   
@Nullable
@Override
public IdeScriptEngine getEngineForLanguage(@Nonnull final String language, @Nullable ClassLoader loader) {
  ClassLoader l = ObjectUtils.notNull(loader, AllPluginsLoader.INSTANCE);
  return ClassLoaderUtil.runWithClassLoader(l, new Computable<IdeScriptEngine>() {
    @Override
    public IdeScriptEngine compute() {
      return createIdeScriptEngine(getScriptEngineManager().getEngineByName(language));
    }
  });
}
项目:consulo    文件:Jsr223IdeScriptEngineManagerImpl.java   
@Nullable
@Override
public IdeScriptEngine getEngineForFileExtension(@Nonnull final String extension, @Nullable ClassLoader loader) {
  ClassLoader l = ObjectUtils.notNull(loader, AllPluginsLoader.INSTANCE);
  return ClassLoaderUtil.runWithClassLoader(l, new Computable<IdeScriptEngine>() {
    @Override
    public IdeScriptEngine compute() {
      return createIdeScriptEngine(getScriptEngineManager().getEngineByExtension(extension));
    }
  });
}
项目:consulo    文件:Jsr223IdeScriptEngineManagerImpl.java   
@Override
public Object eval(@Nonnull final String script) throws IdeScriptException {
  return ClassLoaderUtil.runWithClassLoader(myLoader, new ThrowableComputable<Object, IdeScriptException>() {
    @Override
    public Object compute() throws IdeScriptException {
      try {
        return myEngine.eval(script);
      }
      catch (Throwable e) {
        throw new IdeScriptException(e);
      }
    }
  });
}
项目:vso-intellij    文件:TfsUtil.java   
public static <T, E extends Throwable> T forcePluginClassLoader(@NotNull ThrowableComputable<T, E> computable) throws E {
  return ClassLoaderUtil.runWithClassLoader(null, computable);
}
项目:vso-intellij    文件:TfsUtil.java   
public static <E extends Throwable> void forcePluginClassLoader(@NotNull ThrowableRunnable<E> runnable) throws E {
  ClassLoaderUtil.runWithClassLoader(null, runnable);
}
项目:consulo    文件:FileTemplateUtil.java   
public static PsiElement createFromTemplate(@Nonnull final FileTemplate template,
                                            @NonNls @Nullable String fileName,
                                            @Nullable Map<String, Object> additionalProperties,
                                            @Nonnull final PsiDirectory directory,
                                            @Nullable ClassLoader classLoader) throws Exception {
  final Project project = directory.getProject();

  Map<String, Object> properties = new THashMap<>();
  FileTemplateManager.getInstance(project).fillDefaultVariables(properties);

  if(additionalProperties != null) {
    properties.putAll(additionalProperties);
  }

  FileTemplateManager.getInstance(project).addRecentName(template.getName());
  fillDefaultProperties(properties, directory);

  final CreateFromTemplateHandler handler = findHandler(template);
  if (fileName != null && properties.get(FileTemplate.ATTRIBUTE_NAME) == null) {
    properties.put(FileTemplate.ATTRIBUTE_NAME, fileName);
  }
  else if (fileName == null && handler.isNameRequired()) {
    fileName = (String)properties.get(FileTemplate.ATTRIBUTE_NAME);
    if (fileName == null) {
      throw new Exception("File name must be specified");
    }
  }

  //Set escaped references to dummy values to remove leading "\" (if not already explicitely set)
  String[] dummyRefs = calculateAttributes(template.getText(), properties, true, project);
  for (String dummyRef : dummyRefs) {
    properties.put(dummyRef, "");
  }

  handler.prepareProperties(properties);

  final String fileName_ = fileName;
  String mergedText =
          ClassLoaderUtil.runWithClassLoader(classLoader != null ? classLoader : FileTemplateUtil.class.getClassLoader(), (ThrowableComputable<String, IOException>)() -> template.getText(properties));
  final String templateText = StringUtil.convertLineSeparators(mergedText);
  final Exception[] commandException = new Exception[1];
  final PsiElement[] result = new PsiElement[1];
  CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> {
    try {
      result[0] = handler.createFromTemplate(project, directory, fileName_, template, templateText, properties);
    }
    catch (Exception ex) {
      commandException[0] = ex;
    }
  }), handler.commandName(template), null);
  if (commandException[0] != null) {
    throw commandException[0];
  }
  return result[0];
}
项目:consulo    文件:BootstrapClassLoaderUtil.java   
@Nonnull
public static ClassLoader initClassLoader(boolean updatePlugins) throws MalformedURLException {
  PathManager.loadProperties();

  Collection<URL> classpath = new LinkedHashSet<URL>();
  addParentClasspath(classpath, false);
  addIDEALibraries(classpath);
  addAdditionalClassPath(classpath);
  addParentClasspath(classpath, true);

  UrlClassLoader.Builder builder =
          UrlClassLoader.build().urls(filterClassPath(new ArrayList<URL>(classpath))).allowLock().usePersistentClasspathIndexForLocalClassDirectories()
                  .useCache();
  if (Boolean.valueOf(System.getProperty(PROPERTY_ALLOW_BOOTSTRAP_RESOURCES, "true"))) {
    builder.allowBootstrapResources();
  }

  ClassLoaderUtil.addPlatformLoaderParentIfOnJdk9(builder);

  UrlClassLoader newClassLoader = builder.get();

  StartupActionLogger logger = null;
  try {
    logger = new StartupActionLogger();

    logger.info("start: update=" + updatePlugins);
    // prepare plugins
    if (updatePlugins) {
      try {
        StartupActionScriptManager.executeActionScript(logger);
      }
      catch (IOException e) {
        logger.error(e);

        Main.showMessage("Plugin Installation Error", e);
      }
    }
  }
  finally {
    if (logger != null) {
      try {
        logger.close();
      }
      catch (IOException ignored) {
      }
    }
  }

  Thread.currentThread().setContextClassLoader(newClassLoader);
  return newClassLoader;
}