diff --git a/java/compiler/impl/src/com/intellij/compiler/CompileTaskBean.java b/java/compiler/impl/src/com/intellij/compiler/CompileTaskBean.java index 1b4a26551261..9384bee20b99 100644 --- a/java/compiler/impl/src/com/intellij/compiler/CompileTaskBean.java +++ b/java/compiler/impl/src/com/intellij/compiler/CompileTaskBean.java @@ -1,23 +1,9 @@ -/* - * Copyright 2000-2014 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. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.compiler; import com.intellij.openapi.compiler.CompileTask; import com.intellij.openapi.extensions.AbstractExtensionPointBean; -import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.extensions.ProjectExtensionPointName; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.AtomicNotNullLazyValue; import com.intellij.util.xmlb.annotations.Attribute; @@ -26,35 +12,30 @@ import org.jetbrains.annotations.NotNull; /** * @author nik */ -public class CompileTaskBean extends AbstractExtensionPointBean { - public static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.compiler.task"); +public final class CompileTaskBean extends AbstractExtensionPointBean { + public static final ProjectExtensionPointName EP_NAME = new ProjectExtensionPointName<>("com.intellij.compiler.task"); public enum CompileTaskExecutionPhase { BEFORE, AFTER } - - private final Project myProject; - - public CompileTaskBean(Project project) { - myProject = project; - } @Attribute("execute") public CompileTaskExecutionPhase myExecutionPhase = CompileTaskExecutionPhase.BEFORE; - + @Attribute("implementation") public String myImplementation; - - private final AtomicNotNullLazyValue myInstanceHolder = new AtomicNotNullLazyValue() { - @NotNull - @Override - protected CompileTask compute() { + + private final AtomicNotNullLazyValue myInstanceHolder; + + public CompileTaskBean(Project project) { + myInstanceHolder = AtomicNotNullLazyValue.createValue(() -> { try { - return instantiate(myImplementation, myProject.getPicoContainer()); + return instantiateWithPicoContainerOnlyIfNeeded(myImplementation, project.getPicoContainer()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } - } - }; + }); + } + @NotNull public CompileTask getTaskInstance() { return myInstanceHolder.getValue(); } diff --git a/java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java b/java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java index f7ab58b1ed86..0e2a4e3a0333 100644 --- a/java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.compiler; import com.intellij.codeInspection.InspectionManager; @@ -42,8 +42,7 @@ import org.jetbrains.jps.incremental.BinaryContent; import org.jetbrains.jps.javac.*; import org.jetbrains.jps.javac.ast.api.JavacFileData; -import javax.tools.Diagnostic; -import javax.tools.JavaFileObject; +import javax.tools.*; import java.io.File; import java.io.IOException; import java.lang.reflect.Array; @@ -198,23 +197,24 @@ public class CompilerManagerImpl extends CompilerManager { @Override @NotNull - public CompileTask[] getBeforeTasks() { + public List getBeforeTasks() { return getCompileTasks(myBeforeTasks, CompileTaskBean.CompileTaskExecutionPhase.BEFORE); } - private CompileTask[] getCompileTasks(List taskList, CompileTaskBean.CompileTaskExecutionPhase phase) { + @NotNull + private List getCompileTasks(List taskList, CompileTaskBean.CompileTaskExecutionPhase phase) { List beforeTasks = new ArrayList<>(taskList); for (CompileTaskBean extension : CompileTaskBean.EP_NAME.getExtensions(myProject)) { if (extension.myExecutionPhase == phase) { beforeTasks.add(extension.getTaskInstance()); } } - return beforeTasks.toArray(new CompileTask[0]); + return beforeTasks; } @Override @NotNull - public CompileTask[] getAfterTasks() { + public List getAfterTaskList() { return getCompileTasks(myAfterTasks, CompileTaskBean.CompileTaskExecutionPhase.AFTER); } diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index a56be2b9e76a..c139f1ee1a41 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -581,8 +581,8 @@ public class CompileDriver { final ProgressIndicator progressIndicator = context.getProgressIndicator(); progressIndicator.pushState(); try { - CompileTask[] tasks = beforeTasks ? manager.getBeforeTasks() : manager.getAfterTasks(); - if (tasks.length > 0) { + List tasks = beforeTasks ? manager.getBeforeTasks() : manager.getAfterTaskList(); + if (tasks.size() > 0) { progressIndicator.setText( CompilerBundle.message(beforeTasks ? "progress.executing.precompile.tasks" : "progress.executing.postcompile.tasks")); for (CompileTask task : tasks) { diff --git a/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerManager.java b/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerManager.java index f57f3e37a6f7..f2084af6cbeb 100644 --- a/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerManager.java +++ b/java/compiler/openapi/src/com/intellij/openapi/compiler/CompilerManager.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.compiler; import com.intellij.execution.configurations.RunConfiguration; @@ -123,7 +123,16 @@ public abstract class CompilerManager { * @return all tasks to be executed before compilation. */ @NotNull - public abstract CompileTask[] getBeforeTasks(); + public abstract List getBeforeTasks(); + + /** + * @deprecated Use {@link #getAfterTaskList} + */ + @Deprecated + @NotNull + public CompileTask[] getAfterTasks() { + return getAfterTaskList().toArray(new CompileTask[0]); + } /** * Returns the list of all tasks to be executed after compilation. @@ -131,7 +140,7 @@ public abstract class CompilerManager { * @return all tasks to be executed after compilation. */ @NotNull - public abstract CompileTask[] getAfterTasks(); + public abstract List getAfterTaskList(); /** * Compile a set of files. diff --git a/java/execution/impl/src/com/intellij/execution/scratch/JavaScratchCompilationSupport.java b/java/execution/impl/src/com/intellij/execution/scratch/JavaScratchCompilationSupport.java index cafb71465d2a..fe5874163900 100644 --- a/java/execution/impl/src/com/intellij/execution/scratch/JavaScratchCompilationSupport.java +++ b/java/execution/impl/src/com/intellij/execution/scratch/JavaScratchCompilationSupport.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.scratch; import com.intellij.compiler.options.CompileStepBeforeRun; @@ -22,6 +22,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.java.JpsJavaSdkType; @@ -33,8 +34,8 @@ import java.util.*; * @author Eugene Zhuravlev */ public class JavaScratchCompilationSupport implements CompileTask { - public JavaScratchCompilationSupport(CompilerManager compileManager) { - compileManager.addAfterTask(this); + public JavaScratchCompilationSupport(@NotNull Project project) { + CompilerManager.getInstance(project).addAfterTask(this); } @Nullable diff --git a/platform/extensions/src/com/intellij/openapi/extensions/AbstractExtensionPointBean.java b/platform/extensions/src/com/intellij/openapi/extensions/AbstractExtensionPointBean.java index 5691393321ec..5b29fb516860 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/AbstractExtensionPointBean.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/AbstractExtensionPointBean.java @@ -2,6 +2,7 @@ package com.intellij.openapi.extensions; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.util.ReflectionUtil; import com.intellij.util.pico.CachingConstructorInjectionComponentAdapter; import com.intellij.util.xmlb.annotations.Transient; import org.jetbrains.annotations.NotNull; @@ -65,4 +66,30 @@ public abstract class AbstractExtensionPointBean implements PluginAware { final boolean allowNonPublicClasses) { return (T)new CachingConstructorInjectionComponentAdapter(aClass.getName(), aClass, null, allowNonPublicClasses).getComponentInstance(container); } + + @NotNull + protected T instantiateWithPicoContainerOnlyIfNeeded(@Nullable String implementationClass, @NotNull PicoContainer picoContainer) + throws ClassNotFoundException { + if (implementationClass == null) { + throw new RuntimeException("implementation class is not specified, " + + "plugin id: " + + (myPluginDescriptor == null ? "" : myPluginDescriptor.getPluginId()) + ". " + + "Check if 'implementationClass' attribute is specified"); + } + + + Class clazz = findClass(implementationClass); + try { + return ReflectionUtil.newInstance(clazz); + } + catch (RuntimeException e) { + if (e.getCause() instanceof NoSuchMethodException) { + LOG.error("Bean extension class constructor must not have parameters: " + implementationClass); + return instantiate(clazz, picoContainer, true); + } + else { + throw e; + } + } + } } diff --git a/platform/extensions/src/com/intellij/openapi/extensions/CustomLoadingExtensionPointBean.java b/platform/extensions/src/com/intellij/openapi/extensions/CustomLoadingExtensionPointBean.java index 7622994f5bfc..3125a53cd0e2 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/CustomLoadingExtensionPointBean.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/CustomLoadingExtensionPointBean.java @@ -1,7 +1,6 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.extensions; -import com.intellij.util.ReflectionUtil; import com.intellij.util.xmlb.annotations.Attribute; import org.jetbrains.annotations.NotNull; import org.picocontainer.PicoContainer; @@ -15,30 +14,12 @@ public class CustomLoadingExtensionPointBean extends AbstractExtensionPointBean @NotNull protected Object instantiateExtension(String implementationClass, @NotNull PicoContainer picoContainer) throws ClassNotFoundException { - if (factoryClass != null) { + if (factoryClass == null) { + return instantiateWithPicoContainerOnlyIfNeeded(implementationClass, picoContainer); + } + else { ExtensionFactory factory = instantiate(factoryClass, picoContainer); return factory.createInstance(factoryArgument, implementationClass); } - else { - if (implementationClass == null) { - throw new RuntimeException("implementation class is not specified for unknown language extension point, " + - "plugin id: " + - (myPluginDescriptor == null ? "" : myPluginDescriptor.getPluginId()) + ". " + - "Check if 'implementationClass' attribute is specified"); - } - Class clazz = findClass(implementationClass); - try { - return ReflectionUtil.newInstance(clazz); - } - catch (RuntimeException e) { - if (e.getCause() instanceof NoSuchMethodException) { - LOG.error("Bean extension class constructor must not have parameters: " + implementationClass); - return instantiate(clazz, picoContainer, true); - } - else { - throw e; - } - } - } } }