/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jetbrains.jps.incremental.groovy;

import com.intellij.util.SystemProperties;
import com.intellij.util.lang.ClassPath;
import com.intellij.util.lang.UrlClassLoader;
import org.jetbrains.annotations.NotNull;

/**
 * @author peter
 */
class JointCompilationClassLoader extends UrlClassLoader {
  private static final boolean ourExplicitlyAvoidLoadingJava = SystemProperties.getBooleanProperty("groovy.classloader.skip.java.package", true);
  @NotNull private final Builder myBuilder;
  @NotNull private ClassPath myClassPath;

  public JointCompilationClassLoader(@NotNull Builder builder) {
    super(builder);
    myBuilder = builder;
    myClassPath = super.getClassPath();
  }

  @Override
  protected Class findClass(String name) throws ClassNotFoundException {
    if (ourExplicitlyAvoidLoadingJava && name.startsWith("java.")) return null;

    return super.findClass(name);
  }

  @Override
  protected Class _defineClass(String name, byte[] b) {
    try {
      return super._defineClass(name, b);
    }
    catch (NoClassDefFoundError e) {
      NoClassDefFoundError wrap = new NoClassDefFoundError(e.getMessage() + " needed for " + name);
      wrap.initCause(e);
      throw wrap;
    }
  }

  @NotNull
  @Override
  protected ClassPath getClassPath() {
    return myClassPath;
  }

  void resetCache() {
    myClassPath = createClassPath(myBuilder);
  }
}

@@ -645,51 +645,8 @@
 y;%0A%0A
-import com.intellij.util.SystemProperties;%0A
 impo
@@ -682,16 +682,16 @@
 ssPath;%0A
+
 import c
@@ -859,154 +859,8 @@
 r %7B%0A
-  private static final boolean ourExplicitlyAvoidLoadingJava = SystemProperties.getBooleanProperty(%22groovy.classloader.skip.java.package%22, true);%0A
   @N
@@ -1052,16 +1052,16 @@
 uilder;%0A
+
     myCl
@@ -1101,213 +1101,8 @@
  %7D%0A%0A
-  @Override%0A  protected Class findClass(String name) throws ClassNotFoundException %7B%0A    if (ourExplicitlyAvoidLoadingJava && name.startsWith(%22java.%22)) return null;%0A%0A    return super.findClass(name);%0A  %7D%0A%0A
   @O

revert groovyc JointCompilationClassLoader changes as they don't fix IDEA-166169