2 * Copyright 2000-2012 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.jps.incremental.groovy;
18 import com.intellij.openapi.application.PathManager;
19 import com.intellij.util.ObjectUtils;
20 import org.jetbrains.annotations.NotNull;
21 import org.jetbrains.annotations.Nullable;
22 import org.jetbrains.jps.incremental.BuilderService;
23 import org.jetbrains.jps.incremental.ModuleLevelBuilder;
27 import java.net.URLClassLoader;
28 import java.util.Arrays;
29 import java.util.List;
34 public class GroovyBuilderService extends BuilderService {
36 * All Groovy-Eclipse stuff is contained in a separate classLoader to avoid clashes with ecj.jar being in the classpath of the builder process
39 private static final ClassLoader ourGreclipseLoader = createGreclipseLoader();
42 private static ClassLoader createGreclipseLoader() {
43 String jar = System.getProperty("groovy.eclipse.batch.jar");
44 if (jar == null) return null;
48 new File(jar).toURI().toURL(),
49 new File(ObjectUtils.assertNotNull(PathManager.getJarPathForClass(GreclipseMain.class))).toURI().toURL()
51 ClassLoader loader = new URLClassLoader(urls, null);
52 Class.forName("org.eclipse.jdt.internal.compiler.batch.Main", false, loader);
56 throw new RuntimeException(e);
62 public List<? extends ModuleLevelBuilder> createModuleLevelBuilders() {
63 if (ourGreclipseLoader != null) {
64 return Arrays.asList(new GreclipseBuilder(ourGreclipseLoader));
66 return Arrays.asList(new GroovyBuilder(true), new GroovyBuilder(false));