Remove 181 bunch files
This commit is contained in:
-65
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.android.configure
|
||||
|
||||
import com.android.tools.idea.gradle.project.model.JavaModuleModel
|
||||
import com.android.tools.idea.gradle.project.sync.idea.data.service.AndroidProjectKeys
|
||||
import com.android.tools.idea.gradle.util.FilePaths
|
||||
import com.intellij.openapi.externalSystem.model.DataNode
|
||||
import com.intellij.openapi.externalSystem.model.project.ModuleData
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectData
|
||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
|
||||
import com.intellij.openapi.externalSystem.service.project.manage.AbstractProjectDataService
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.OrderRootType
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import com.intellij.openapi.roots.libraries.Library
|
||||
import org.jetbrains.kotlin.idea.configuration.detectPlatformKindByPlugin
|
||||
import org.jetbrains.kotlin.idea.framework.detectLibraryKind
|
||||
import org.jetbrains.kotlin.idea.platform.tooling
|
||||
import java.io.File
|
||||
|
||||
class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaModuleModel, Void>() {
|
||||
override fun getTargetDataKey() = AndroidProjectKeys.JAVA_MODULE_MODEL
|
||||
|
||||
override fun postProcess(
|
||||
toImport: MutableCollection<DataNode<JavaModuleModel>>,
|
||||
projectData: ProjectData?,
|
||||
project: Project,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
) {
|
||||
for (dataNode in toImport) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val targetLibraryKind = detectPlatformKindByPlugin(dataNode.parent as DataNode<ModuleData>)?.tooling?.libraryKind
|
||||
if (targetLibraryKind != null) {
|
||||
for (dep in dataNode.data.jarLibraryDependencies) {
|
||||
val library = modelsProvider.findLibraryByBinaryPath(dep.binaryPath) as LibraryEx? ?: continue
|
||||
if (library.kind == null) {
|
||||
val model = modelsProvider.getModifiableLibraryModel(library) as LibraryEx.ModifiableModelEx
|
||||
detectLibraryKind(model.getFiles(OrderRootType.CLASSES))?.let { model.kind = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun IdeModifiableModelsProvider.findLibraryByBinaryPath(path: File?): Library? {
|
||||
if (path == null) return null
|
||||
val url = FilePaths.pathToIdeaUrl(path)
|
||||
return allLibraries.firstOrNull { url in getModifiableLibraryModel(it).getUrls(OrderRootType.CLASSES) }
|
||||
}
|
||||
}
|
||||
-236
@@ -1,236 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-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/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.android.configure
|
||||
|
||||
import com.android.tools.idea.gradle.project.sync.idea.data.service.AndroidProjectKeys
|
||||
import com.android.tools.idea.gradle.util.ContentEntries.findParentContentEntry
|
||||
import com.android.tools.idea.gradle.util.FilePaths
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.externalSystem.ExternalSystemModulePropertyManager
|
||||
import com.intellij.openapi.externalSystem.model.DataNode
|
||||
import com.intellij.openapi.externalSystem.model.ProjectKeys
|
||||
import com.intellij.openapi.externalSystem.model.project.ModuleData
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectData
|
||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
|
||||
import com.intellij.openapi.externalSystem.service.project.manage.AbstractProjectDataService
|
||||
import com.intellij.openapi.externalSystem.service.project.manage.ContentRootDataService.CREATE_EMPTY_DIRECTORIES
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.DependencyScope
|
||||
import com.intellij.openapi.roots.ModifiableRootModel
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.util.SmartList
|
||||
import com.intellij.util.containers.stream
|
||||
import org.jetbrains.jps.model.java.JavaResourceRootType
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRootType
|
||||
import org.jetbrains.kotlin.gradle.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.KotlinPlatform
|
||||
import org.jetbrains.kotlin.gradle.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.idea.addModuleDependencyIfNeeded
|
||||
import org.jetbrains.kotlin.idea.configuration.*
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import org.jetbrains.kotlin.idea.configuration.kotlinSourceSet
|
||||
|
||||
class KotlinAndroidGradleMPPModuleDataService : AbstractProjectDataService<ModuleData, Void>() {
|
||||
override fun getTargetDataKey() = ProjectKeys.MODULE
|
||||
|
||||
private fun shouldCreateEmptySourceRoots(
|
||||
moduleDataNode: DataNode<ModuleData>,
|
||||
module: Module
|
||||
): Boolean {
|
||||
val projectDataNode = ExternalSystemApiUtil.findParent(moduleDataNode, ProjectKeys.PROJECT) ?: return false
|
||||
if (projectDataNode.getUserData<Boolean>(CREATE_EMPTY_DIRECTORIES) == true) return true
|
||||
|
||||
val projectSystemId = projectDataNode.data.owner
|
||||
val externalSystemSettings = ExternalSystemApiUtil.getSettings(module.project, projectSystemId)
|
||||
|
||||
val path = ExternalSystemModulePropertyManager.getInstance(module).getRootProjectPath() ?: return false
|
||||
return externalSystemSettings.getLinkedProjectSettings(path)?.isCreateEmptyContentRootDirectories ?: false
|
||||
}
|
||||
|
||||
override fun postProcess(
|
||||
toImport: MutableCollection<DataNode<ModuleData>>,
|
||||
projectData: ProjectData?,
|
||||
project: Project,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
) {
|
||||
for (nodeToImport in toImport) {
|
||||
val projectNode = ExternalSystemApiUtil.findParent(nodeToImport, ProjectKeys.PROJECT) ?: continue
|
||||
val moduleData = nodeToImport.data
|
||||
val module = modelsProvider.findIdeModule(moduleData) ?: continue
|
||||
val shouldCreateEmptySourceRoots = shouldCreateEmptySourceRoots(nodeToImport, module)
|
||||
val rootModel = modelsProvider.getModifiableRootModel(module)
|
||||
val kotlinAndroidSourceSets = nodeToImport.kotlinAndroidSourceSets ?: emptyList()
|
||||
for (sourceSetInfo in kotlinAndroidSourceSets) {
|
||||
val compilation = sourceSetInfo.kotlinModule as? KotlinCompilation ?: continue
|
||||
for (sourceSet in compilation.sourceSets) {
|
||||
if (sourceSet.platform == KotlinPlatform.ANDROID) {
|
||||
val sourceType = if (sourceSet.isTestModule) JavaSourceRootType.TEST_SOURCE else JavaSourceRootType.SOURCE
|
||||
val resourceType = if (sourceSet.isTestModule) JavaResourceRootType.TEST_RESOURCE else JavaResourceRootType.RESOURCE
|
||||
sourceSet.sourceDirs.forEach { addSourceRoot(it, sourceType, rootModel, shouldCreateEmptySourceRoots) }
|
||||
sourceSet.resourceDirs.forEach { addSourceRoot(it, resourceType, rootModel, shouldCreateEmptySourceRoots) }
|
||||
}
|
||||
}
|
||||
}
|
||||
addExtraDependeeModules(nodeToImport, projectNode, modelsProvider, rootModel, false)
|
||||
addExtraDependeeModules(nodeToImport, projectNode, modelsProvider, rootModel, true)
|
||||
|
||||
if (nodeToImport.kotlinAndroidSourceSets == null) {
|
||||
continue
|
||||
}
|
||||
|
||||
val androidModel = getAndroidModuleModel(nodeToImport) ?: continue
|
||||
val variantName = androidModel.selectedVariant.name
|
||||
val activeSourceSetInfos = nodeToImport.kotlinAndroidSourceSets?.filter { it.kotlinModule.name.startsWith(variantName) } ?: emptyList()
|
||||
for (activeSourceSetInfo in activeSourceSetInfos) {
|
||||
val activeCompilation = activeSourceSetInfo.kotlinModule as? KotlinCompilation ?: continue
|
||||
for (sourceSet in activeCompilation.sourceSets) {
|
||||
if (sourceSet.platform != KotlinPlatform.ANDROID) {
|
||||
val sourceSetId = activeSourceSetInfo.sourceSetIdsByName[sourceSet.name] ?: continue
|
||||
val sourceSetNode = ExternalSystemApiUtil.findFirstRecursively(projectNode) {
|
||||
(it.data as? ModuleData)?.id == sourceSetId
|
||||
} as? DataNode<out ModuleData>? ?: continue
|
||||
val sourceSetData = sourceSetNode.data as? ModuleData ?: continue
|
||||
val sourceSetModule = modelsProvider.findIdeModule(sourceSetData) ?: continue
|
||||
addModuleDependencyIfNeeded(
|
||||
rootModel,
|
||||
sourceSetModule,
|
||||
activeSourceSetInfo.isTestModule,
|
||||
sourceSetNode.kotlinSourceSet?.isTestModule ?: false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val mainSourceSetInfo = activeSourceSetInfos.firstOrNull { it.kotlinModule.name == variantName }
|
||||
if (mainSourceSetInfo != null) {
|
||||
KotlinSourceSetDataService.configureFacet(moduleData, mainSourceSetInfo, nodeToImport, module, modelsProvider)
|
||||
}
|
||||
|
||||
val kotlinFacet = KotlinFacet.get(module)
|
||||
if (kotlinFacet != null) {
|
||||
GradleProjectImportHandler.getInstances(project).forEach { it.importByModule(kotlinFacet, nodeToImport) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDependeeModuleNodes(
|
||||
moduleNode: DataNode<ModuleData>,
|
||||
projectNode: DataNode<ProjectData>,
|
||||
modelsProvider: IdeModifiableModelsProvider,
|
||||
testScope: Boolean
|
||||
): List<DataNode<out ModuleData>> {
|
||||
val androidModel = getAndroidModuleModel(moduleNode)
|
||||
if (androidModel != null) {
|
||||
val dependencies = if (testScope) {
|
||||
androidModel.selectedAndroidTestCompileDependencies
|
||||
} else {
|
||||
androidModel.selectedMainCompileLevel2Dependencies
|
||||
} ?: return emptyList()
|
||||
return dependencies
|
||||
.moduleDependencies
|
||||
.mapNotNull { projectNode.findChildModuleById(it.projectPath) }
|
||||
}
|
||||
|
||||
val javaModel = getJavaModuleModel(moduleNode)
|
||||
if (javaModel != null) {
|
||||
val scope = if (testScope) DependencyScope.TEST.name else DependencyScope.COMPILE.name
|
||||
val moduleNames = javaModel
|
||||
.javaModuleDependencies
|
||||
.filter { scope == it.scope ?: DependencyScope.COMPILE.name }
|
||||
.mapTo(HashSet()) { it.moduleName }
|
||||
return ExternalSystemApiUtil
|
||||
.getChildren(projectNode, ProjectKeys.MODULE)
|
||||
.filter { modelsProvider.findIdeModule(it.data)?.name in moduleNames }
|
||||
}
|
||||
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
private fun List<DataNode<GradleSourceSetData>>.firstByPlatformOrNull(platform: KotlinPlatform) = firstOrNull {
|
||||
it.kotlinSourceSet?.platform == platform
|
||||
}
|
||||
|
||||
private fun addExtraDependeeModules(
|
||||
moduleNode: DataNode<ModuleData>,
|
||||
projectNode: DataNode<ProjectData>,
|
||||
modelsProvider: IdeModifiableModelsProvider,
|
||||
rootModel: ModifiableRootModel,
|
||||
testScope: Boolean
|
||||
) {
|
||||
val dependeeModuleNodes = getDependeeModuleNodes(moduleNode, projectNode, modelsProvider, testScope)
|
||||
val relevantNodes = dependeeModuleNodes
|
||||
.flatMap { ExternalSystemApiUtil.getChildren(it, GradleSourceSetData.KEY) }
|
||||
.filter {
|
||||
val ktModule = it.kotlinSourceSet?.kotlinModule
|
||||
ktModule != null && ktModule.isTestModule == testScope
|
||||
}
|
||||
val commonSourceSetName = KotlinSourceSet.commonName(testScope)
|
||||
val isAndroidModule = getAndroidModuleModel(moduleNode) != null
|
||||
|
||||
val gradleSourceSetDataNodes = SmartList<DataNode<GradleSourceSetData>>()
|
||||
.apply {
|
||||
addIfNotNull(
|
||||
(if (isAndroidModule) relevantNodes.firstByPlatformOrNull(KotlinPlatform.ANDROID) else null)
|
||||
?: relevantNodes.firstByPlatformOrNull(KotlinPlatform.JVM)
|
||||
)
|
||||
addIfNotNull(
|
||||
relevantNodes.firstOrNull {
|
||||
it.kotlinSourceSet?.platform == KotlinPlatform.COMMON && it.kotlinSourceSet?.kotlinModule?.name == commonSourceSetName
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
val testKotlinModules =
|
||||
gradleSourceSetDataNodes.filter { it.kotlinSourceSet?.isTestModule ?: false }.mapNotNull { modelsProvider.findIdeModule(it.data) }
|
||||
.toSet()
|
||||
|
||||
gradleSourceSetDataNodes.forEach { node ->
|
||||
val module = modelsProvider.findIdeModule(node.data) ?: return
|
||||
addModuleDependencyIfNeeded(rootModel, module, testScope, node.kotlinSourceSet?.isTestModule ?: false)
|
||||
val dependeeRootModel = modelsProvider.getModifiableRootModel(module)
|
||||
dependeeRootModel.getModuleDependencies(testScope).forEach { transitiveDependee ->
|
||||
addModuleDependencyIfNeeded(rootModel, transitiveDependee, testScope, testKotlinModules.contains(transitiveDependee))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAndroidModuleModel(moduleNode: DataNode<ModuleData>) =
|
||||
ExternalSystemApiUtil.getChildren(moduleNode, AndroidProjectKeys.ANDROID_MODEL).firstOrNull()?.data
|
||||
|
||||
private fun getJavaModuleModel(moduleNode: DataNode<ModuleData>) =
|
||||
ExternalSystemApiUtil.getChildren(moduleNode, AndroidProjectKeys.JAVA_MODULE_MODEL).firstOrNull()?.data
|
||||
|
||||
private fun addSourceRoot(
|
||||
sourceRoot: File,
|
||||
type: JpsModuleSourceRootType<*>,
|
||||
rootModel: ModifiableRootModel,
|
||||
shouldCreateEmptySourceRoots: Boolean
|
||||
) {
|
||||
val parent = findParentContentEntry(sourceRoot, rootModel.contentEntries.stream()) ?: return
|
||||
val url = FilePaths.pathToIdeaUrl(sourceRoot)
|
||||
parent.addSourceFolder(url, type)
|
||||
if (shouldCreateEmptySourceRoots) {
|
||||
ExternalSystemApiUtil.doWriteAction {
|
||||
try {
|
||||
VfsUtil.createDirectoryIfMissing(sourceRoot.path)
|
||||
} catch (e: IOException) {
|
||||
LOG.warn(String.format("Unable to create directory for the path: %s", sourceRoot.path), e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val LOG = Logger.getInstance(KotlinAndroidGradleMPPModuleDataService::class.java)
|
||||
}
|
||||
}
|
||||
@@ -1,388 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.android;
|
||||
|
||||
import com.android.SdkConstants;
|
||||
import com.android.tools.idea.rendering.RenderSecurityManager;
|
||||
import com.android.tools.idea.startup.AndroidCodeStyleSettingsModifier;
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInspection.GlobalInspectionTool;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.InspectionManagerEx;
|
||||
import com.intellij.facet.FacetManager;
|
||||
import com.intellij.facet.ModifiableFacetModel;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSchemes;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.testFramework.InspectionTestUtil;
|
||||
import com.intellij.testFramework.ThreadTracker;
|
||||
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
|
||||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
|
||||
import com.intellij.testFramework.fixtures.JavaTestFixtureFactory;
|
||||
import com.intellij.testFramework.fixtures.TestFixtureBuilder;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.testFramework.fixtures.impl.GlobalInspectionContextForTests;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.android.facet.AndroidRootUtil;
|
||||
import org.jetbrains.android.formatter.AndroidXmlCodeStyleSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.picocontainer.MutablePicoContainer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Copied from AS 2.3 sources
|
||||
*/
|
||||
@SuppressWarnings({"JUnitTestCaseWithNonTrivialConstructors"})
|
||||
public abstract class AndroidTestCase extends AndroidTestBase {
|
||||
protected Module myModule;
|
||||
protected List<Module> myAdditionalModules;
|
||||
|
||||
protected AndroidFacet myFacet;
|
||||
protected CodeStyleSettings mySettings;
|
||||
|
||||
private List<String> myAllowedRoots = new ArrayList<>();
|
||||
private boolean myUseCustomSettings;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
VfsRootAccess.allowRootAccess(KotlinTestUtils.getHomeDirectory());
|
||||
|
||||
TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName());
|
||||
myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
|
||||
JavaModuleFixtureBuilder moduleFixtureBuilder = projectBuilder.addModule(JavaModuleFixtureBuilder.class);
|
||||
File moduleRoot = new File(myFixture.getTempDirPath());
|
||||
|
||||
if (!moduleRoot.exists()) {
|
||||
assertTrue(moduleRoot.mkdirs());
|
||||
}
|
||||
initializeModuleFixtureBuilderWithSrcAndGen(moduleFixtureBuilder, moduleRoot.toString());
|
||||
|
||||
ArrayList<MyAdditionalModuleData> modules = new ArrayList<>();
|
||||
configureAdditionalModules(projectBuilder, modules);
|
||||
|
||||
myFixture.setUp();
|
||||
myFixture.setTestDataPath(getTestDataPath());
|
||||
myModule = moduleFixtureBuilder.getFixture().getModule();
|
||||
|
||||
// Must be done before addAndroidFacet, and must always be done, even if a test provides
|
||||
// its own custom manifest file. However, in that case, we will delete it shortly below.
|
||||
createManifest();
|
||||
|
||||
myFacet = addAndroidFacet(myModule);
|
||||
|
||||
LanguageLevel languageLevel = getLanguageLevel();
|
||||
if (languageLevel != null) {
|
||||
LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(myModule.getProject());
|
||||
if (extension != null) {
|
||||
extension.setLanguageLevel(languageLevel);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: myFixture.copyDirectoryToProject(getResDir(), "res");
|
||||
|
||||
myAdditionalModules = new ArrayList<>();
|
||||
for (MyAdditionalModuleData data : modules) {
|
||||
Module additionalModule = data.myModuleFixtureBuilder.getFixture().getModule();
|
||||
myAdditionalModules.add(additionalModule);
|
||||
AndroidFacet facet = addAndroidFacet(additionalModule);
|
||||
facet.setProjectType(data.myProjectType);
|
||||
String rootPath = getAdditionalModulePath(data.myDirName);
|
||||
myFixture.copyDirectoryToProject(getResDir(), rootPath + "/res");
|
||||
myFixture.copyFileToProject(SdkConstants.FN_ANDROID_MANIFEST_XML, rootPath + '/' + SdkConstants.FN_ANDROID_MANIFEST_XML);
|
||||
if (data.myIsMainModuleDependency) {
|
||||
ModuleRootModificationUtil.addDependency(myModule, additionalModule);
|
||||
}
|
||||
}
|
||||
|
||||
if (providesCustomManifest()) {
|
||||
deleteManifest();
|
||||
}
|
||||
|
||||
if (RenderSecurityManager.RESTRICT_READS) {
|
||||
// Unit test class loader includes disk directories which security manager does not allow access to
|
||||
RenderSecurityManager.sEnabled = false;
|
||||
}
|
||||
|
||||
ArrayList<String> allowedRoots = new ArrayList<>();
|
||||
collectAllowedRoots(allowedRoots);
|
||||
// TODO: registerAllowedRoots(allowedRoots, myTestRootDisposable);
|
||||
mySettings = CodeStyleSettingsManager.getSettings(getProject()).clone();
|
||||
AndroidCodeStyleSettingsModifier.modify(mySettings);
|
||||
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(mySettings);
|
||||
myUseCustomSettings = getAndroidCodeStyleSettings().USE_CUSTOM_SETTINGS;
|
||||
getAndroidCodeStyleSettings().USE_CUSTOM_SETTINGS = true;
|
||||
|
||||
// Layoutlib rendering thread will be shutdown when the app is closed so do not report it as a leak
|
||||
ThreadTracker.longRunningThreadCreated(ApplicationManager.getApplication(), "Layoutlib");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
Sdk androidSdk = ProjectJdkTable.getInstance().findJdk(ANDROID_SDK_NAME);
|
||||
if (androidSdk != null) {
|
||||
ApplicationManager.getApplication().runWriteAction(() -> ProjectJdkTable.getInstance().removeJdk(androidSdk));
|
||||
}
|
||||
|
||||
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
|
||||
myModule = null;
|
||||
myAdditionalModules = null;
|
||||
myFixture.tearDown();
|
||||
myFixture = null;
|
||||
myFacet = null;
|
||||
getAndroidCodeStyleSettings().USE_CUSTOM_SETTINGS = myUseCustomSettings;
|
||||
if (RenderSecurityManager.RESTRICT_READS) {
|
||||
RenderSecurityManager.sEnabled = true;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
VfsRootAccess.disallowRootAccess(KotlinTestUtils.getHomeDirectory());
|
||||
}
|
||||
}
|
||||
|
||||
private static void initializeModuleFixtureBuilderWithSrcAndGen(JavaModuleFixtureBuilder moduleFixtureBuilder, String moduleRoot) {
|
||||
moduleFixtureBuilder.addContentRoot(moduleRoot);
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
new File(moduleRoot + "/src/").mkdir();
|
||||
moduleFixtureBuilder.addSourceRoot("src");
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
new File(moduleRoot + "/gen/").mkdir();
|
||||
moduleFixtureBuilder.addSourceRoot("gen");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path that any additional modules registered by
|
||||
* {@link #configureAdditionalModules(TestFixtureBuilder, List)} or
|
||||
* {@link #addModuleWithAndroidFacet(TestFixtureBuilder, List, String, int, boolean)} are
|
||||
* installed into.
|
||||
*/
|
||||
protected static String getAdditionalModulePath(@NotNull String moduleName) {
|
||||
return "/additionalModules/" + moduleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this class provides its own {@code AndroidManifest.xml} for its tests. If
|
||||
* {@code true}, then {@link #setUp()} calls {@link #deleteManifest()} before finishing.
|
||||
*/
|
||||
protected boolean providesCustomManifest() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "res" directory for this SDK. Children classes can override this if they need to
|
||||
* provide a custom "res" location for tests.
|
||||
*/
|
||||
protected String getResDir() {
|
||||
return "res";
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the project level to set for the test project, or null to get the default language
|
||||
* level associated with the test project.
|
||||
*/
|
||||
@Nullable
|
||||
protected LanguageLevel getLanguageLevel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static AndroidXmlCodeStyleSettings getAndroidCodeStyleSettings() {
|
||||
return AndroidXmlCodeStyleSettings.getInstance(CodeStyleSchemes.getInstance().getDefaultScheme().getCodeStyleSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook point for child test classes to register directories that can be safely accessed by all
|
||||
* of its tests.
|
||||
*
|
||||
* @see {@link VfsRootAccess}
|
||||
*/
|
||||
protected void collectAllowedRoots(List<String> roots) throws IOException {
|
||||
}
|
||||
|
||||
private void registerAllowedRoots(List<String> roots, @NotNull Disposable disposable) {
|
||||
List<String> newRoots = new ArrayList<>(roots);
|
||||
newRoots.removeAll(myAllowedRoots);
|
||||
|
||||
String[] newRootsArray = ArrayUtil.toStringArray(newRoots);
|
||||
VfsRootAccess.allowRootAccess(newRootsArray);
|
||||
myAllowedRoots.addAll(newRoots);
|
||||
|
||||
Disposer.register(disposable, () -> {
|
||||
VfsRootAccess.disallowRootAccess(newRootsArray);
|
||||
myAllowedRoots.removeAll(newRoots);
|
||||
});
|
||||
}
|
||||
|
||||
public static AndroidFacet addAndroidFacet(Module module) {
|
||||
return addAndroidFacet(module, true);
|
||||
}
|
||||
|
||||
private static AndroidFacet addAndroidFacet(Module module, boolean attachSdk) {
|
||||
FacetManager facetManager = FacetManager.getInstance(module);
|
||||
AndroidFacet facet = facetManager.createFacet(AndroidFacet.getFacetType(), "Android", null);
|
||||
|
||||
if (attachSdk) {
|
||||
addLatestAndroidSdk(module);
|
||||
}
|
||||
ModifiableFacetModel facetModel = facetManager.createModifiableModel();
|
||||
facetModel.addFacet(facet);
|
||||
ApplicationManager.getApplication().runWriteAction(facetModel::commit);
|
||||
return facet;
|
||||
}
|
||||
|
||||
protected void configureAdditionalModules(
|
||||
@NotNull TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder, @NotNull List<MyAdditionalModuleData> modules) {
|
||||
}
|
||||
|
||||
protected final void addModuleWithAndroidFacet(
|
||||
@NotNull TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder,
|
||||
@NotNull List<MyAdditionalModuleData> modules,
|
||||
@NotNull String dirName,
|
||||
int projectType) {
|
||||
// By default, created module is declared as a main module's dependency
|
||||
addModuleWithAndroidFacet(projectBuilder, modules, dirName, projectType, true);
|
||||
}
|
||||
|
||||
protected final void addModuleWithAndroidFacet(
|
||||
@NotNull TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder,
|
||||
@NotNull List<MyAdditionalModuleData> modules,
|
||||
@NotNull String dirName,
|
||||
int projectType,
|
||||
boolean isMainModuleDependency) {
|
||||
JavaModuleFixtureBuilder moduleFixtureBuilder = projectBuilder.addModule(JavaModuleFixtureBuilder.class);
|
||||
String moduleDirPath = myFixture.getTempDirPath() + getAdditionalModulePath(dirName);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
new File(moduleDirPath).mkdirs();
|
||||
initializeModuleFixtureBuilderWithSrcAndGen(moduleFixtureBuilder, moduleDirPath);
|
||||
modules.add(new MyAdditionalModuleData(moduleFixtureBuilder, dirName, projectType, isMainModuleDependency));
|
||||
}
|
||||
|
||||
protected void createManifest() throws IOException {
|
||||
myFixture.copyFileToProject(SdkConstants.FN_ANDROID_MANIFEST_XML, SdkConstants.FN_ANDROID_MANIFEST_XML);
|
||||
}
|
||||
|
||||
protected final void createProjectProperties() throws IOException {
|
||||
myFixture.copyFileToProject(SdkConstants.FN_PROJECT_PROPERTIES, SdkConstants.FN_PROJECT_PROPERTIES);
|
||||
}
|
||||
|
||||
protected final void deleteManifest() throws IOException {
|
||||
deleteManifest(myModule);
|
||||
}
|
||||
|
||||
protected final void deleteManifest(final Module module) throws IOException {
|
||||
AndroidFacet facet = AndroidFacet.getInstance(module);
|
||||
assertNotNull(facet);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String manifestRelativePath = facet.getProperties().MANIFEST_FILE_RELATIVE_PATH;
|
||||
VirtualFile manifest = AndroidRootUtil.getFileByRelativeModulePath(module, manifestRelativePath, true);
|
||||
if (manifest != null) {
|
||||
try {
|
||||
manifest.delete(this);
|
||||
}
|
||||
catch (IOException e) {
|
||||
fail("Could not delete default manifest");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected final void doGlobalInspectionTest(
|
||||
@NotNull GlobalInspectionTool inspection, @NotNull String globalTestDir, @NotNull AnalysisScope scope) {
|
||||
doGlobalInspectionTest(new GlobalInspectionToolWrapper(inspection), globalTestDir, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an inspection and a path to a directory that contains an "expected.xml" file, run the
|
||||
* inspection on the current test project and verify that its output matches that of the
|
||||
* expected file.
|
||||
*/
|
||||
protected final void doGlobalInspectionTest(
|
||||
@NotNull GlobalInspectionToolWrapper wrapper, @NotNull String globalTestDir, @NotNull AnalysisScope scope) {
|
||||
myFixture.enableInspections(wrapper.getTool());
|
||||
|
||||
scope.invalidate();
|
||||
|
||||
InspectionManagerEx inspectionManager = (InspectionManagerEx)InspectionManager.getInstance(getProject());
|
||||
GlobalInspectionContextForTests globalContext =
|
||||
CodeInsightTestFixtureImpl.createGlobalContextForTool(scope, getProject(), inspectionManager, wrapper);
|
||||
|
||||
InspectionTestUtil.runTool(wrapper, scope, globalContext);
|
||||
InspectionTestUtil.compareToolResults(globalContext, wrapper, false, getTestDataPath() + globalTestDir);
|
||||
}
|
||||
|
||||
protected static class MyAdditionalModuleData {
|
||||
final JavaModuleFixtureBuilder myModuleFixtureBuilder;
|
||||
final String myDirName;
|
||||
final int myProjectType;
|
||||
final boolean myIsMainModuleDependency;
|
||||
|
||||
private MyAdditionalModuleData(
|
||||
@NotNull JavaModuleFixtureBuilder moduleFixtureBuilder, @NotNull String dirName, int projectType, boolean isMainModuleDependency) {
|
||||
myModuleFixtureBuilder = moduleFixtureBuilder;
|
||||
myDirName = dirName;
|
||||
myProjectType = projectType;
|
||||
myIsMainModuleDependency = isMainModuleDependency;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected <T> T registerApplicationComponent(@NotNull Class<T> key, @NotNull T instance) throws Exception {
|
||||
MutablePicoContainer picoContainer = (MutablePicoContainer)ApplicationManager.getApplication().getPicoContainer();
|
||||
@SuppressWarnings("unchecked")
|
||||
T old = (T)picoContainer.getComponentInstance(key.getName());
|
||||
picoContainer.unregisterComponent(key.getName());
|
||||
picoContainer.registerComponentInstance(key.getName(), instance);
|
||||
return old;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected <T> T registerProjectComponent(@NotNull Class<T> key, @NotNull T instance) {
|
||||
MutablePicoContainer picoContainer = (MutablePicoContainer)getProject().getPicoContainer();
|
||||
@SuppressWarnings("unchecked")
|
||||
T old = (T)picoContainer.getComponentInstance(key.getName());
|
||||
picoContainer.unregisterComponent(key.getName());
|
||||
picoContainer.registerComponentInstance(key.getName(), instance);
|
||||
return old;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.android;
|
||||
|
||||
|
||||
import com.android.annotations.NonNull;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Stub for com.android.testutils.TestUtils
|
||||
* stabbed to minimize changes in AndroidTestBase
|
||||
*/
|
||||
public class TestUtils {
|
||||
@NonNull
|
||||
public static File getSdk() {
|
||||
return KotlinTestUtils.findAndroidSdk();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String getLatestAndroidPlatform() {
|
||||
return "android-26";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user