Java 类com.intellij.util.lang.UrlClassLoader 实例源码

项目:intellij-ce-playground    文件:PostfixTemplateMetaData.java   
@NotNull
@Override
protected URL getDirURL() {
  if (urlDir != null) {
    return urlDir;
  }

  final URL pageURL = myLoader.getResource(DESCRIPTION_FOLDER + "/" + myDescriptionDirectoryName + "/" + DESCRIPTION_FILE_NAME);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Path:" + DESCRIPTION_FOLDER + "/" + myDescriptionDirectoryName);
    LOG.debug("URL:" + pageURL);
  }
  if (pageURL != null) {
    try {
      final String url = pageURL.toExternalForm();
      urlDir = UrlClassLoader.internProtocol(new URL(url.substring(0, url.lastIndexOf('/'))));
      return urlDir;
    }
    catch (MalformedURLException e) {
      LOG.error(e);
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:IntentionActionMetaData.java   
@Nullable
private static URL getIntentionDescriptionDirURL(ClassLoader aClassLoader, String intentionFolderName) {
  final URL pageURL = aClassLoader.getResource(INTENTION_DESCRIPTION_FOLDER + "/" + intentionFolderName + "/" + DESCRIPTION_FILE_NAME);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Path:" + "intentionDescriptions/" + intentionFolderName);
    LOG.debug("URL:" + pageURL);
  }
  if (pageURL != null) {
    try {
      final String url = pageURL.toExternalForm();
      return UrlClassLoader.internProtocol(new URL(url.substring(0, url.lastIndexOf('/'))));
    }
    catch (MalformedURLException e) {
      LOG.error(e);
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:InProcessGroovyc.java   
@NotNull
private JointCompilationClassLoader createCompilationClassLoader(Collection<String> compilationClassPath) throws MalformedURLException {
  ClassLoader parent = obtainParentLoader(compilationClassPath);
  return new JointCompilationClassLoader(UrlClassLoader.build().
    urls(toUrls(compilationClassPath)).parent(parent).allowLock().
    useCache(ourLoaderCachePool, new UrlClassLoader.CachingCondition() {
      @Override
      public boolean shouldCacheData(@NotNull URL url) {
        try {
          String file = FileUtil.toCanonicalPath(new File(url.toURI()).getPath());
          for (String output : myOutputs) {
            if (FileUtil.startsWith(output, file)) {
              return false;
            }
          }
          return true;
        }
        catch (URISyntaxException e) {
          LOG.info(e);
          return false;
        }
      }
    }));
}
项目:firstspiritlanguagesupport    文件:FirstSpiritClassPathHack.java   
public void addURL(UrlClassLoader classLoader, URL u) throws Exception {

        if (classLoader != null) {
            System.out.println("Classloader loaded successfully: " + classLoader);
        } else {
            System.err.println("Cannot load system classloader!");
        }
        Class sysclass = UrlClassLoader.class;

        try {
            Method method = sysclass.getDeclaredMethod("addURL", parameters);
            method.setAccessible(true);
            method.invoke(classLoader, new Object[]{u});
        } catch (Exception e) {
            System.err.println("Error, could not add URL " + u.getPath() + " to classloader!");
            e.printStackTrace();
            throw e;
        }

    }
项目:tools-idea    文件:IntentionActionMetaData.java   
@Nullable
private static URL getIntentionDescriptionDirURL(ClassLoader aClassLoader, String intentionFolderName) {
  final URL pageURL = aClassLoader.getResource(INTENTION_DESCRIPTION_FOLDER + "/" + intentionFolderName+"/"+ DESCRIPTION_FILE_NAME);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Path:"+"intentionDescriptions/" + intentionFolderName);
    LOG.debug("URL:"+pageURL);
  }
  if (pageURL != null) {
    try {
      final String url = pageURL.toExternalForm();
      return UrlClassLoader.internProtocol(new URL(url.substring(0, url.lastIndexOf('/'))));
    }
    catch (MalformedURLException e) {
      LOG.error(e);
    }
  }
  return null;
}
项目:tools-idea    文件:ClassloaderUtil.java   
public static UrlClassLoader initClassloader(final List<URL> classpathElements, boolean updatePlugins) throws Exception {
  PathManager.loadProperties();

  addParentClasspath(classpathElements);
  addIDEALibraries(classpathElements);
  addAdditionalClassPath(classpathElements);

  filterClassPath(classpathElements);
  UrlClassLoader newClassLoader = new UrlClassLoader(classpathElements, null, true, true);

  // prepare plugins
  if (updatePlugins && !isLoadingOfExternalPluginsDisabled()) {
    try {
      StartupActionScriptManager.executeActionScript();
    }
    catch (IOException e) {
      Main.showMessage("Plugin Installation Error", e);
    }
  }

  Thread.currentThread().setContextClassLoader(newClassLoader);
  return newClassLoader;
}
项目:tools-idea    文件:AppEngineSdkUtil.java   
public static Map<String, Set<String>> computeWhiteList(final File toolsApiJarFile) {
  try {
    final THashMap<String, Set<String>> map = new THashMap<String, Set<String>>();
    ClassLoader loader = new UrlClassLoader(Collections.singletonList(toolsApiJarFile.toURI().toURL()), AppEngineSdkUtil.class.getClassLoader());
    final Class<?> whiteListClass = Class.forName("com.google.apphosting.runtime.security.WhiteList", true, loader);
    final Set<String> classes = (Set<String>) whiteListClass.getMethod("getWhiteList").invoke(null);
    for (String qualifiedName : classes) {
      final String packageName = StringUtil.getPackageName(qualifiedName);
      Set<String> classNames = map.get(packageName);
      if (classNames == null) {
        classNames = new THashSet<String>();
        map.put(packageName, classNames);
      }
      classNames.add(StringUtil.getShortName(qualifiedName));
    }
    return map;
  }
  catch (Exception e) {
    LOG.error(e);
    return Collections.emptyMap();
  }
}
项目:consulo    文件:PostfixTemplateMetaData.java   
@Override
protected URL getDirURL() {
  if (urlDir != null) {
    return urlDir;
  }

  final URL pageURL = myLoader.getResource(DESCRIPTION_FOLDER + "/" + myDescriptionDirectoryName + "/" + DESCRIPTION_FILE_NAME);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Path:" + DESCRIPTION_FOLDER + "/" + myDescriptionDirectoryName);
    LOG.debug("URL:" + pageURL);
  }
  if (pageURL != null) {
    try {
      final String url = pageURL.toExternalForm();
      urlDir = UrlClassLoader.internProtocol(new URL(url.substring(0, url.lastIndexOf('/'))));
      return urlDir;
    }
    catch (MalformedURLException e) {
      LOG.error(e);
    }
  }
  return null;
}
项目:consulo    文件:IntentionActionMetaData.java   
@Nullable
private static URL getIntentionDescriptionDirURL(ClassLoader aClassLoader, String intentionFolderName) {
  final URL pageURL = aClassLoader.getResource(INTENTION_DESCRIPTION_FOLDER + "/" + intentionFolderName+"/"+ DESCRIPTION_FILE_NAME);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Path:"+"intentionDescriptions/" + intentionFolderName);
    LOG.debug("URL:"+pageURL);
  }
  if (pageURL != null) {
    try {
      final String url = pageURL.toExternalForm();
      return UrlClassLoader.internProtocol(new URL(url.substring(0, url.lastIndexOf('/'))));
    }
    catch (MalformedURLException e) {
      LOG.error(e);
    }
  }
  return null;
}
项目:consulo-java    文件:TestClassCollector.java   
public static ClassLoader createUsersClassLoader(JavaTestConfigurationBase configuration)
{
    Module module = configuration.getConfigurationModule().getModule();
    List<URL> urls = new ArrayList<>();

    PathsList pathsList = ReadAction.compute(() -> (module == null || configuration.getTestSearchScope() == TestSearchScope.WHOLE_PROJECT ? OrderEnumerator.orderEntries(configuration.getProject
            ()) : OrderEnumerator.orderEntries(module)).runtimeOnly().recursively().getPathsList()); //include jdk to avoid NoClassDefFoundError for classes inside tools.jar
    for(VirtualFile file : pathsList.getVirtualFiles())
    {
        try
        {
            urls.add(VfsUtilCore.virtualToIoFile(file).toURI().toURL());
        }
        catch(MalformedURLException ignored)
        {
            LOG.info(ignored);
        }
    }

    return UrlClassLoader.build().allowLock().useCache().urls(urls).get();
}
项目:intellij-ce-playground    文件:ExternalSystemApiUtil.java   
/**
 * There is a possible case that methods of particular object should be executed with classpath different from the one implied
 * by the current class' class loader. External system offers {@link ParametersEnhancer#enhanceLocalProcessing(List)} method
 * for defining that custom classpath.
 * <p/>
 * It's also possible that particular implementation of {@link ParametersEnhancer} is compiled using dependency to classes
 * which are provided by the {@link ParametersEnhancer#enhanceLocalProcessing(List) expanded classpath}. E.g. a class
 * <code>'A'</code> might use method of class <code>'B'</code> and 'A' is located at the current (system/plugin) classpath but
 * <code>'B'</code> is not. We need to reload <code>'A'</code> using its expanded classpath then, i.e. create new class loaded
 * with that expanded classpath and load <code>'A'</code> by it.
 * <p/>
 * This method allows to do that.
 *
 * @param clazz  custom classpath-aware class which instance should be created (is assumed to have a no-args constructor)
 * @param <T>    target type
 * @return       newly created instance of the given class loaded by custom classpath-aware loader
 * @throws IllegalAccessException     as defined by reflection processing
 * @throws InstantiationException     as defined by reflection processing
 * @throws NoSuchMethodException      as defined by reflection processing
 * @throws InvocationTargetException  as defined by reflection processing
 * @throws ClassNotFoundException     as defined by reflection processing
 */
@NotNull
public static <T extends ParametersEnhancer> T reloadIfNecessary(@NotNull final Class<T> clazz)
  throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException, ClassNotFoundException
{
  T instance = clazz.newInstance();
  List<URL> urls = ContainerUtilRt.newArrayList();
  instance.enhanceLocalProcessing(urls);
  if (urls.isEmpty()) {
    return instance;
  }

  final ClassLoader baseLoader = clazz.getClassLoader();
  Method method = baseLoader.getClass().getMethod("getUrls");
  if (method != null) {
    //noinspection unchecked
    urls.addAll((Collection<? extends URL>)method.invoke(baseLoader));
  }
  UrlClassLoader loader = new UrlClassLoader(UrlClassLoader.build().urls(urls).parent(baseLoader.getParent())) {
    @Override
    protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
      if (name.equals(clazz.getName())) {
        return super.loadClass(name, resolve);
      }
      else {
        try {
          return baseLoader.loadClass(name);
        }
        catch (ClassNotFoundException e) {
          return super.loadClass(name, resolve);
        }
      }
    }
  };
  //noinspection unchecked
  return (T)loader.loadClass(clazz.getName()).newInstance();
}
项目:intellij-ce-playground    文件:BootstrapClassLoaderUtil.java   
@NotNull
public static ClassLoader initClassLoader(boolean updatePlugins) throws MalformedURLException {
  PathManager.loadProperties();

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

  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();
  }

  UrlClassLoader newClassLoader = builder.get();

  // prepare plugins
  if (updatePlugins && !isLoadingOfExternalPluginsDisabled()) {
    try {
      StartupActionScriptManager.executeActionScript();
    }
    catch (IOException e) {
      Main.showMessage("Plugin Installation Error", e);
    }
  }

  Thread.currentThread().setContextClassLoader(newClassLoader);
  return newClassLoader;
}
项目:intellij-ce-playground    文件:IdeTestApplication.java   
@NotNull
private static ClassLoader createClassLoader() throws MalformedURLException, URISyntaxException {
  Collection<URL> classpath = Sets.newLinkedHashSet();
  addParentClassPath(classpath);
  addIdeaLibraries(classpath);
  addAdditionalClassPath(classpath);

  UrlClassLoader.Builder builder = UrlClassLoader.build()
                                                 .urls(filterClassPath(Lists.newArrayList(classpath)))
                                                 .allowLock(false)
                                                 .usePersistentClasspathIndexForLocalClassDirectories()
                                                 .useCache();
  if (SystemProperties.getBooleanProperty(PROPERTY_ALLOW_BOOTSTRAP_RESOURCES, true)) {
    builder.allowBootstrapResources();
  }

  UrlClassLoader newClassLoader = builder.get();

  // prepare plugins
  try {
    StartupActionScriptManager.executeActionScript();
  }
  catch (IOException e) {
    Main.showMessage("Plugin Installation Error", e);
  }

  Thread.currentThread().setContextClassLoader(newClassLoader);
  return newClassLoader;
}
项目:intellij-ce-playground    文件:IdeaClassFinder.java   
@Override
protected Collection getClassPathEntries() {
  final Collection entries = super.getClassPathEntries();
  final Module[] modules = ModuleManager.getInstance(myProject).getModules();
  for (Module module : modules) {
    final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
    if (extension != null) {
      final VirtualFile outputFile = extension.getCompilerOutputPath();
      try {
        if (outputFile != null) {
          final URL outputURL = VfsUtilCore.virtualToIoFile(outputFile).toURI().toURL();
          entries.add(new ClassPathEntry(outputFile.getPath(), UrlClassLoader.build().urls(outputURL).get()));
        }
        if (myCurrentSuite.isTrackTestFolders()) {
          final VirtualFile testOutput = extension.getCompilerOutputPathForTests();
          if (testOutput != null) {
            final URL testOutputURL = VfsUtilCore.virtualToIoFile(testOutput).toURI().toURL();
            entries.add(new ClassPathEntry(testOutput.getPath(), UrlClassLoader.build().urls(testOutputURL).get()));
          }
        }
      }
      catch (MalformedURLException e1) {
        LOG.error(e1);
      }
    }
  }
  return entries;
}
项目:tools-idea    文件:Bootstrap.java   
public static void main(String[] args, String mainClass, String methodName, List<URL> classpathElements) throws Exception {
  UrlClassLoader newClassLoader = ClassloaderUtil.initClassloader(classpathElements, args.length == 0);
  WindowsCommandLineProcessor.ourMirrorClass = Class.forName(WindowsCommandLineProcessor.class.getName(), true, newClassLoader);

  Class<?> klass = Class.forName(PLUGIN_MANAGER, true, newClassLoader);
  Method startMethod = klass.getDeclaredMethod("start", String.class, String.class, String[].class);
  startMethod.setAccessible(true);
  startMethod.invoke(null, mainClass, methodName, args);
}
项目:tools-idea    文件:JavaFxInjectPageLanguageIntention.java   
private static UrlClassLoader composeUserClassLoader(Project project) {
  final List<URL> urls = new ArrayList<URL>();
  final List<String> list = OrderEnumerator.orderEntries(project).recursively().runtimeOnly().getPathsList().getPathList();
  for (String path : list) {
    try {
      urls.add(new File(FileUtil.toSystemIndependentName(path)).toURI().toURL());
    }
    catch (MalformedURLException e1) {
      LOG.info(e1);
    }
  }

  return new UrlClassLoader(urls, null);
}
项目:consulo-javafx    文件:JavaFxInjectPageLanguageIntention.java   
private static UrlClassLoader composeUserClassLoader(Project project) {
  final List<URL> urls = new ArrayList<URL>();
  final List<String> list = OrderEnumerator.orderEntries(project).recursively().runtimeOnly().getPathsList().getPathList();
  for (String path : list) {
    try {
      urls.add(new File(FileUtil.toSystemIndependentName(path)).toURI().toURL());
    }
    catch (MalformedURLException e1) {
      LOG.info(e1);
    }
  }

  return UrlClassLoader.build().urls(urls).get();
}
项目:consulo    文件:ExternalSystemApiUtil.java   
/**
 * There is a possible case that methods of particular object should be executed with classpath different from the one implied
 * by the current class' class loader. External system offers {@link ParametersEnhancer#enhanceLocalProcessing(List)} method
 * for defining that custom classpath.
 * <p>
 * It's also possible that particular implementation of {@link ParametersEnhancer} is compiled using dependency to classes
 * which are provided by the {@link ParametersEnhancer#enhanceLocalProcessing(List) expanded classpath}. E.g. a class
 * <code>'A'</code> might use method of class <code>'B'</code> and 'A' is located at the current (system/plugin) classpath but
 * <code>'B'</code> is not. We need to reload <code>'A'</code> using its expanded classpath then, i.e. create new class loaded
 * with that expanded classpath and load <code>'A'</code> by it.
 * <p>
 * This method allows to do that.
 *
 * @param clazz custom classpath-aware class which instance should be created (is assumed to have a no-args constructor)
 * @param <T>   target type
 * @return newly created instance of the given class loaded by custom classpath-aware loader
 * @throws IllegalAccessException    as defined by reflection processing
 * @throws InstantiationException    as defined by reflection processing
 * @throws NoSuchMethodException     as defined by reflection processing
 * @throws InvocationTargetException as defined by reflection processing
 * @throws ClassNotFoundException    as defined by reflection processing
 */
@Nonnull
public static <T extends ParametersEnhancer> T reloadIfNecessary(@Nonnull final Class<T> clazz)
        throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException, ClassNotFoundException {
  T instance = clazz.newInstance();
  List<URL> urls = ContainerUtilRt.newArrayList();
  instance.enhanceLocalProcessing(urls);
  if (urls.isEmpty()) {
    return instance;
  }

  final ClassLoader baseLoader = clazz.getClassLoader();
  Method method = baseLoader.getClass().getMethod("getUrls");
  if (method != null) {
    //noinspection unchecked
    urls.addAll((Collection<? extends URL>)method.invoke(baseLoader));
  }
  UrlClassLoader loader = new UrlClassLoader(UrlClassLoader.build().urls(urls).parent(baseLoader.getParent())) {
    @Override
    protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
      if (name.equals(clazz.getName())) {
        return super.loadClass(name, resolve);
      }
      else {
        try {
          return baseLoader.loadClass(name);
        }
        catch (ClassNotFoundException e) {
          return super.loadClass(name, resolve);
        }
      }
    }
  };
  //noinspection unchecked
  return (T)loader.loadClass(clazz.getName()).newInstance();
}
项目:consulo    文件:ClassLoaderUtil.java   
public static void addPlatformLoaderParentIfOnJdk9(@Nonnull UrlClassLoader.Builder builder) {
  if (SystemInfo.IS_AT_LEAST_JAVA9) {
    // on Java 8, 'tools.jar' is on a classpath; on Java 9, its classes are available via the platform loader
    try {
      ClassLoader platformCl = (ClassLoader)ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null);
      builder.parent(platformCl);
    }
    catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
}
项目:consulo    文件:PluginManagerCore.java   
private static boolean hasLoadedClass(@Nonnull String className, ClassLoader loader) {
  if (loader instanceof UrlClassLoader) return ((UrlClassLoader)loader).hasLoadedClass(className);

  // it can be an UrlClassLoader loaded by another class loader, so instanceof doesn't work
  try {
    return (Boolean)loader.getClass().getMethod("hasLoadedClass", String.class).invoke(loader, className);
  }
  catch (Exception e) {
    return false;
  }
}
项目:intellij-ce-playground    文件:ResourceTextDescriptor.java   
public ResourceTextDescriptor(@NotNull URL url) {
  myUrl = UrlClassLoader.internProtocol(url);
}
项目:intellij-ce-playground    文件:RenderClassLoader.java   
protected UrlClassLoader createClassLoader(List<URL> externalJars) {
  return UrlClassLoader.build().parent(this).urls(externalJars).noPreload().get();
}
项目:intellij-ce-playground    文件:IdeTestApplication.java   
private static boolean isUrlClassLoader(@NotNull ClassLoader classLoader) {
  return classLoader.getClass().getName().equals(UrlClassLoader.class.getName());
}
项目:intellij-ce-playground    文件:JUnitDevKitPatcher.java   
public void patchJavaParameters(@Nullable final Module module, JavaParameters javaParameters) {
  if (module != null && PsiUtil.isIdeaProject(module.getProject()) &&
      !javaParameters.getVMParametersList().hasParameter(JAVA_SYSTEM_CLASS_LOADER_PROPERTY)) {
    final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(module.getProject());
    final String qualifiedName = UrlClassLoader.class.getName();
    final PsiClass urlLoaderClass = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
      @Override
      public PsiClass compute() {
        return psiFacade.findClass(qualifiedName, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
      }
    });
    if (urlLoaderClass != null) {
      javaParameters.getVMParametersList().add("-D" + JAVA_SYSTEM_CLASS_LOADER_PROPERTY + "=" + UrlClassLoader.class.getName());
    }
  }
  Sdk jdk = javaParameters.getJdk();
  jdk = IdeaJdk.findIdeaJdk(jdk);
  if (jdk == null) return;

  @NonNls String libPath = jdk.getHomePath() + File.separator + "lib";

  final ParametersList vm = javaParameters.getVMParametersList();
  vm.add("-Xbootclasspath/a:" + libPath + File.separator + "boot.jar");
  if (!vm.hasProperty("idea.load.plugins.id") && module != null && PluginModuleType.isOfType(module)) {
    final String id = DescriptorUtil.getPluginId(module);
    if (id != null) {
      vm.defineProperty("idea.load.plugins.id", id);
    }
  }

  final File sandboxHome = getSandboxPath(jdk);
  if (sandboxHome != null) {
    if (!vm.hasProperty("idea.home.path")) {
      File homeDir = new File(sandboxHome, "test");
      FileUtil.createDirectory(homeDir);
      vm.defineProperty("idea.home.path", homeDir.getAbsolutePath());
    }
    if (!vm.hasProperty("idea.plugins.path")) {
      vm.defineProperty("idea.plugins.path", new File(sandboxHome, "plugins").getAbsolutePath());
    }
  }

  javaParameters.getClassPath().addFirst(libPath + File.separator + "idea.jar");
  javaParameters.getClassPath().addFirst(libPath + File.separator + "resources.jar");
  javaParameters.getClassPath().addFirst(((JavaSdkType)jdk.getSdkType()).getToolsPath(jdk));
}
项目:intellij-ce-playground    文件:ForkedGroovyc.java   
@Override
public GroovycContinuation runGroovyc(Collection<String> compilationClassPath,
                                      boolean forStubs,
                                      JpsGroovySettings settings,
                                      File tempFile,
                                      final GroovycOutputParser parser)
  throws Exception {
  List<String> classpath = new ArrayList<String>();
  if (myOptimizeClassLoading) {
    classpath.addAll(GroovyBuilder.getGroovyRtRoots());
    classpath.add(ClasspathBootstrap.getResourcePath(Function.class));
    classpath.add(ClasspathBootstrap.getResourcePath(UrlClassLoader.class));
    classpath.add(ClasspathBootstrap.getResourceFile(THashMap.class).getPath());
  } else {
    classpath.addAll(compilationClassPath);
  }

  List<String> vmParams = ContainerUtilRt.newArrayList();
  vmParams.add("-Xmx" + System.getProperty("groovyc.heap.size", settings.heapSize) + "m");
  vmParams.add("-Dfile.encoding=" + System.getProperty("file.encoding"));
  //vmParams.add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5239");

  if ("false".equals(System.getProperty(GroovyRtConstants.GROOVYC_ASM_RESOLVING_ONLY))) {
    vmParams.add("-D" + GroovyRtConstants.GROOVYC_ASM_RESOLVING_ONLY + "=false");
  }
  String configScript = settings.configScript;
  if (StringUtil.isNotEmpty(configScript)) {
    vmParams.add("-D" + GroovyRtConstants.GROOVYC_CONFIG_SCRIPT + "=" + configScript);
  }

  String grapeRoot = System.getProperty(GroovycOutputParser.GRAPE_ROOT);
  if (grapeRoot != null) {
    vmParams.add("-D" + GroovycOutputParser.GRAPE_ROOT + "=" + grapeRoot);
  }

  final List<String> cmd = ExternalProcessUtil.buildJavaCommandLine(
    getJavaExecutable(myChunk),
    "org.jetbrains.groovy.compiler.rt.GroovycRunner",
    Collections.<String>emptyList(), classpath,
    vmParams,
    getProgramParams(tempFile, settings, forStubs)
  );
  final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmd));
  ProcessHandler handler = new BaseOSProcessHandler(process, null, null) {
    @Override
    protected Future<?> executeOnPooledThread(Runnable task) {
      return SharedThreadPool.getInstance().executeOnPooledThread(task);
    }

    @Override
    public void notifyTextAvailable(String text, Key outputType) {
      parser.notifyTextAvailable(text, outputType);
    }
  };

  handler.startNotify();
  handler.waitFor();
  parser.notifyFinished(process.exitValue());
  return null;
}
项目:firstspiritlanguagesupport    文件:FirstSpiritClassPathHack.java   
public void addFile(UrlClassLoader classLoader, File f) throws Exception {
    System.out.println("Trying to add file " + (f) + " to classpath.");
    addURL(classLoader, f.toURI().toURL());
}
项目:firstspiritlanguagesupport    文件:FirstSpiritClassPathHack.java   
public void addFirstSpiritClientJar(UrlClassLoader classLoader, HttpScheme schema, String serverName, int port, String firstSpiritUserName, String firstSpiritUserPassword) throws Exception {
    System.out.println("starting to download fs-client.jar");

    String resolvalbleAddress = null;

    // asking DNS for IP Address, if some error occur choose the given value from user
    try {
        InetAddress address = InetAddress.getByName(serverName);
        resolvalbleAddress = address.getHostAddress();
        System.out.println("Resolved address: " + resolvalbleAddress);
    } catch (Exception e) {
        System.err.println("DNS cannot resolve address, using your given value: " + serverName);
        resolvalbleAddress = serverName;
    }

    String uri = schema + "://" + resolvalbleAddress + ":" + port + "/clientjar/fs-client.jar";
    String versionUri = schema + "://" + resolvalbleAddress + ":" + port + "/version.txt";
    String tempDirectory = System.getProperty("java.io.tmpdir");


    System.out.println(uri);
    System.out.println(versionUri);

    HttpClient client = new HttpClient();
    HttpMethod getVersion = new GetMethod(versionUri);
    client.executeMethod(getVersion);
    String currentServerVersionString = getVersion.getResponseBodyAsString();
    System.out.println("FirstSpirit server you want to connect to is at version: " + currentServerVersionString);

    File fsClientJar = new File(tempDirectory, "fs-client-" + currentServerVersionString + ".jar");

    if (!fsClientJar.exists()) {
        // get an authentication cookie from FirstSpirit
        HttpMethod post = new PostMethod(uri);
        post.setQueryString("login.user=" + URLEncoder.encode(firstSpiritUserName, "UTF-8") + "&login.password=" + URLEncoder.encode(firstSpiritUserPassword, "UTF-8") + "&login=webnonsso");
        client.executeMethod(post);
        String setCookieJsession = post.getResponseHeader("Set-Cookie").getValue();

        // download the fs-client.jar by using the authentication cookie
        HttpMethod get = new GetMethod(uri);
        get.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
        get.setRequestHeader("Cookie", setCookieJsession);
        client.executeMethod(get);

        InputStream inputStream = get.getResponseBodyAsStream();
        FileOutputStream outputStream = new FileOutputStream(fsClientJar);
        outputStream.write(IOUtils.readFully(inputStream, -1, false));
        outputStream.close();
        System.out.println("tempfile of fs-client.jar created within path: " + fsClientJar);
    }

    addFile(classLoader, fsClientJar);
}
项目:tools-idea    文件:ResourceTextDescriptor.java   
public ResourceTextDescriptor(@NotNull URL url) {
  myUrl = UrlClassLoader.internProtocol(url);
}
项目:consulo    文件:ResourceTextDescriptor.java   
public ResourceTextDescriptor(@Nonnull URL url) {
  myUrl = UrlClassLoader.internProtocol(url);
}
项目: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;
}