convert ArtifactManager and CompilerConfiguration to services

GitOrigin-RevId: 355d9d66ae79cc582840bc469b024683d634b037
This commit is contained in:
Vladimir Krivosheev
2019-12-14 07:11:32 +00:00
committed by intellij-monorepo-bot
parent 046fabc0fc
commit a8ef074d02
9 changed files with 42 additions and 114 deletions
@@ -16,7 +16,6 @@ import com.intellij.openapi.compiler.options.ExcludedEntriesConfiguration;
import com.intellij.openapi.compiler.options.ExcludedEntriesListener;
import com.intellij.openapi.compiler.options.ExcludesConfiguration;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.diagnostic.Logger;
@@ -26,6 +25,7 @@ import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.ModuleListener;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.ui.InputValidator;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.*;
@@ -66,7 +66,7 @@ import static org.jetbrains.jps.model.java.impl.compiler.ResourcePatterns.normal
import static org.jetbrains.jps.model.serialization.java.compiler.JpsJavaCompilerConfigurationSerializer.DEFAULT_WILDCARD_PATTERNS;
@State(name = "CompilerConfiguration", storages = @Storage("compiler.xml"))
public class CompilerConfigurationImpl extends CompilerConfiguration implements PersistentStateComponent<Element>, ProjectComponent {
public class CompilerConfigurationImpl extends CompilerConfiguration implements PersistentStateComponent<Element> {
private static final Logger LOG = Logger.getInstance(CompilerConfiguration.class);
public static final String TESTS_EXTERNAL_COMPILER_HOME_PROPERTY_NAME = "tests.external.compiler.home";
@@ -104,7 +104,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
private String myBytecodeTargetLevel = null; // null means same as effective language level
private final Map<String, String> myModuleBytecodeTarget = new HashMap<>();
public CompilerConfigurationImpl(Project project) {
public CompilerConfigurationImpl(@NotNull Project project) {
myProject = project;
myExcludesConfiguration = createExcludedEntriesConfiguration(project);
MessageBusConnection connection = project.getMessageBus().connect();
@@ -126,6 +126,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
updateModuleNames(modules.stream().collect(Collectors.toMap(oldNameProvider::fun, Module::getName)));
}
});
StartupManager.getInstance(project).runAfterOpened(() -> createCompilers());
}
// Overridden in Upsource
@@ -423,11 +424,6 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
return JAVAC_EXTERNAL_BACKEND;
}
@Override
public void projectOpened() {
createCompilers();
}
private void createCompilers() {
if (JAVAC_EXTERNAL_BACKEND != null) {
return;
@@ -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.openapi.components.PersistentStateComponent
@@ -26,7 +26,7 @@ internal class ExternalCompilerConfigurationStorage(private val project: Project
return result
}
val map = (CompilerConfigurationImpl.getInstance(project) as CompilerConfigurationImpl).modulesBytecodeTargetMap
val map = if (project.isDefault) emptyMap() else (CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl).modulesBytecodeTargetMap
val moduleNames = getFilteredModuleNameList(project, map, true)
if (moduleNames.isNotEmpty()) {
val element = Element(JpsJavaCompilerConfigurationSerializer.BYTECODE_TARGET_LEVEL)
@@ -1,29 +1,17 @@
/*
* Copyright 2000-2017 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.impl;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.compiler.Compiler;
import com.intellij.openapi.compiler.*;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
@@ -35,25 +23,26 @@ import java.util.Map;
/**
* @author Eugene Zhuravlev
*/
public class CompilerCacheManager implements Disposable {
@Service
public final class CompilerCacheManager implements Disposable {
private static final Logger LOG = Logger.getInstance(CompilerCacheManager.class);
private final Map<Compiler, Object> myCompilerToCacheMap = new HashMap<>();
private final List<Disposable> myCacheDisposables = new ArrayList<>();
private final File myCachesRoot;
public CompilerCacheManager(Project project) {
public CompilerCacheManager(@NotNull Project project) {
myCachesRoot = CompilerPaths.getCacheStoreDirectory(project);
}
public static CompilerCacheManager getInstance(Project project) {
return project.getComponent(CompilerCacheManager.class);
return project.getService(CompilerCacheManager.class);
}
@Override
public void dispose() {
flushCaches();
}
private File getCompilerRootDir(final Compiler compiler) {
final File dir = new File(myCachesRoot, getCompilerIdString(compiler));
dir.mkdirs();
@@ -84,7 +73,7 @@ public class CompilerCacheManager implements Disposable {
@NonNls String description = compiler.getDescription();
return StringUtil.toLowerCase(description.replaceAll("\\s+", "_").replaceAll("[\\.\\?]", "_"));
}
synchronized void flushCaches() {
for (Disposable disposable : myCacheDisposables) {
try {
@@ -40,7 +40,7 @@ import java.util.*;
* @author nik
*/
@State(name = ArtifactManagerImpl.COMPONENT_NAME, storages = @Storage(value = "artifacts", stateSplitter = ArtifactManagerStateSplitter.class))
public class ArtifactManagerImpl extends ArtifactManager implements PersistentStateComponent<ArtifactManagerState>, Disposable {
public final class ArtifactManagerImpl extends ArtifactManager implements PersistentStateComponent<ArtifactManagerState>, Disposable {
private static final Logger LOG = Logger.getInstance(ArtifactManagerImpl.class);
@NonNls public static final String COMPONENT_NAME = "ArtifactManager";
@NonNls public static final String PACKAGING_ELEMENT_NAME = "element";
@@ -53,7 +53,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements PersistentSt
private final SimpleModificationTracker myModificationTracker = new SimpleModificationTracker();
private final Map<String, LocalFileSystem.WatchRequest> myWatchedOutputs = new HashMap<>();
public ArtifactManagerImpl(Project project) {
public ArtifactManagerImpl(@NotNull Project project) {
myProject = project;
myModel = new ArtifactManagerModel();
myResolvingContext = new DefaultPackagingElementResolvingContext(myProject);
@@ -1,16 +1,4 @@
// Copyright 2000-2017 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.options.ExcludesConfiguration;
@@ -25,7 +13,7 @@ import java.util.List;
public abstract class CompilerConfiguration {
public static CompilerConfiguration getInstance(Project project) {
return project.getComponent(CompilerConfiguration.class);
return project.getService(CompilerConfiguration.class);
}
public abstract int getBuildProcessHeapSize(int javacPreferredHeapSize);
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2009 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.packaging.artifacts;
import com.intellij.openapi.project.Project;
@@ -36,7 +22,7 @@ public abstract class ArtifactManager implements ArtifactModel {
public static final Comparator<Artifact> ARTIFACT_COMPARATOR = (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName());
public static ArtifactManager getInstance(@NotNull Project project) {
return project.getComponent(ArtifactManager.class);
return project.getService(ArtifactManager.class);
}
public abstract Artifact[] getSortedArtifacts();
+17 -1
View File
@@ -16,7 +16,6 @@
<idea-plugin xmlns:xi="http://www.w3.org/2001/XInclude">
<module value="com.intellij.modules.java"/>
<xi:include href="/componentSets/Compiler.xml" xpointer="xpointer(/idea-plugin/*)"/>
<xi:include href="/idea/JavaActions.xml" xpointer="xpointer(/idea-plugin/*)"/>
<xi:include href="/META-INF/JavaAnalysisPlugin.xml" xpointer="xpointer(/idea-plugin/*)"/>
@@ -46,6 +45,11 @@
</application-components>
<project-components>
<component>
<implementation-class>com.intellij.compiler.ExternalCompilerConfigurationStorage</implementation-class>
<loadForDefaultProject/>
</component>
<component>
<interface-class>com.intellij.psi.RefResolveService</interface-class>
<implementation-class>com.intellij.psi.refResolve.RefResolveServiceImpl</implementation-class>
@@ -271,6 +275,18 @@
</extensionPoints>
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceImplementation="com.intellij.compiler.server.BuildManager" preload="true"/>
<projectService serviceInterface="com.intellij.packaging.artifacts.ArtifactManager" serviceImplementation="com.intellij.packaging.impl.artifacts.ArtifactManagerImpl" preload="await"/>
<projectService serviceInterface="com.intellij.compiler.CompilerConfiguration" serviceImplementation="com.intellij.compiler.CompilerConfigurationImpl" preload="await"/>
<projectService serviceInterface="com.intellij.compiler.ProblemsView" serviceImplementation="com.intellij.compiler.impl.ProblemsViewImpl"/>
<javaCompilerConfigurationProxy implementation="com.intellij.compiler.JavaCompilerConfiguration"/>
<projectService serviceImplementation="com.intellij.compiler.server.impl.BuildProcessCustomPluginsConfiguration"/>
<buildProcess.parametersProvider implementation="com.intellij.compiler.server.impl.CustomBuildProcessPluginsClasspathProvider"/>
<vfs.asyncListener implementation="com.intellij.compiler.impl.TranslatingCompilerFilesMonitor"/>
<editorFactoryDocumentListener implementation="com.intellij.compiler.server.BuildManager$MyDocumentListener"/>
<highlightingPassFactory implementation="com.intellij.framework.detection.impl.FrameworkDetectionManager$FrameworkDetectionHighlightingPassFactory"/>
<virtualFileSystem implementationClass="com.intellij.openapi.vfs.impl.jrt.JrtFileSystemImpl" key="jrt" physical="true"/>
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 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 org.jetbrains.plugins.groovy.compiler;
import com.intellij.compiler.CompilerConfiguration;
@@ -28,17 +14,17 @@ import java.io.File;
import java.util.Collections;
import java.util.List;
public class GrBuildProcessParametersProvider extends BuildProcessParametersProvider {
final class GrBuildProcessParametersProvider extends BuildProcessParametersProvider {
private final Project myProject;
public GrBuildProcessParametersProvider(@NotNull Project project) {
GrBuildProcessParametersProvider(@NotNull Project project) {
myProject = project;
}
@NotNull
@Override
public List<String> getClassPath() {
CompilerConfiguration config = CompilerConfiguration.getInstance(myProject);
CompilerConfiguration config = myProject.isDefault() ? null : CompilerConfiguration.getInstance(myProject);
if (config instanceof CompilerConfigurationImpl) {
BackendCompiler backend = ((CompilerConfigurationImpl)config).getDefaultCompiler();
if (backend != null && backend.getId() == GreclipseBuilder.ID) {
-33
View File
@@ -1,33 +0,0 @@
<idea-plugin>
<project-components>
<component>
<interface-class>com.intellij.packaging.artifacts.ArtifactManager</interface-class>
<implementation-class>com.intellij.packaging.impl.artifacts.ArtifactManagerImpl</implementation-class>
</component>
<component>
<implementation-class>com.intellij.compiler.ExternalCompilerConfigurationStorage</implementation-class>
<loadForDefaultProject/>
</component>
<component>
<interface-class>com.intellij.compiler.CompilerConfiguration</interface-class>
<implementation-class>com.intellij.compiler.CompilerConfigurationImpl</implementation-class>
<loadForDefaultProject/>
</component>
<component>
<implementation-class>com.intellij.compiler.impl.CompilerCacheManager</implementation-class>
</component>
</project-components>
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceImplementation="com.intellij.compiler.server.BuildManager" preload="true"/>
<postStartupActivity implementation="com.intellij.compiler.server.BuildManager$BuildManagerStartupActivity"/>
<projectService serviceInterface="com.intellij.compiler.ProblemsView" serviceImplementation="com.intellij.compiler.impl.ProblemsViewImpl"/>
<javaCompilerConfigurationProxy implementation="com.intellij.compiler.JavaCompilerConfiguration"/>
<projectService serviceImplementation="com.intellij.compiler.server.impl.BuildProcessCustomPluginsConfiguration"/>
<buildProcess.parametersProvider implementation="com.intellij.compiler.server.impl.CustomBuildProcessPluginsClasspathProvider"/>
<vfs.asyncListener implementation="com.intellij.compiler.impl.TranslatingCompilerFilesMonitor"/>
<editorFactoryDocumentListener implementation="com.intellij.compiler.server.BuildManager$MyDocumentListener"/>
</extensions>
</idea-plugin>