mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-80640 setting if include test code and resources into apk
This commit is contained in:
@@ -322,4 +322,5 @@ android.lint.inspections.set.to.wrap.content=Replace size attribute with 'wrap_c
|
||||
android.lint.inspections.add.permission.attribute=Add 'permission' attribute
|
||||
android.lint.inspections.add.input.type.attribute=Add 'inputType' attribute
|
||||
android.lint.inspections.remove.unnecessary.view=Remove unnecessary view
|
||||
android.lint.inspections.replace.with.suggested.characters=Replace with suggested characters
|
||||
android.lint.inspections.replace.with.suggested.characters=Replace with suggested characters
|
||||
android.facet.settings.pack.test.sources=Include test code and resources into APK
|
||||
@@ -164,10 +164,12 @@ public class AndroidDexCompiler implements ClassPostProcessingCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
if (facet.getConfiguration().PACK_TEST_CODE) {
|
||||
VirtualFile outputDirForTests = extension.getCompilerOutputPathForTests();
|
||||
|
||||
if (outputDirForTests != null) {
|
||||
addModuleOutputDir(files, outputDirForTests);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ public class AndroidIdlCompiler implements SourceGeneratingCompiler {
|
||||
}
|
||||
|
||||
try {
|
||||
VirtualFile[] sourceRoots = AndroidPackagingCompiler.getSourceRootsForModuleAndDependencies(idlItem.myModule);
|
||||
VirtualFile[] sourceRoots = AndroidPackagingCompiler.getSourceRootsForModuleAndDependencies(idlItem.myModule, false);
|
||||
final String[] sourceRootPaths = AndroidCompileUtil.toOsPaths(sourceRoots);
|
||||
|
||||
final Map<CompilerMessageCategory, List<String>> messages = AndroidIdl
|
||||
|
||||
@@ -65,11 +65,14 @@ public class AndroidPackagingCompiler implements PackagingCompiler {
|
||||
return VirtualFile.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
private static void fillSourceRoots(@NotNull Module module, @NotNull Set<Module> visited, @NotNull Set<VirtualFile> result) {
|
||||
private static void fillSourceRoots(@NotNull Module module,
|
||||
@NotNull Set<Module> visited,
|
||||
@NotNull Set<VirtualFile> result,
|
||||
boolean includingTests) {
|
||||
visited.add(module);
|
||||
VirtualFile resDir = AndroidRootUtil.getResourceDir(module);
|
||||
ModuleRootManager manager = ModuleRootManager.getInstance(module);
|
||||
for (VirtualFile sourceRoot : manager.getSourceRoots()) {
|
||||
for (VirtualFile sourceRoot : manager.getSourceRoots(includingTests)) {
|
||||
if (resDir != sourceRoot) {
|
||||
result.add(sourceRoot);
|
||||
}
|
||||
@@ -78,10 +81,10 @@ public class AndroidPackagingCompiler implements PackagingCompiler {
|
||||
if (entry instanceof ModuleOrderEntry) {
|
||||
ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry)entry;
|
||||
DependencyScope scope = moduleOrderEntry.getScope();
|
||||
if (scope == DependencyScope.COMPILE || scope == DependencyScope.TEST) {
|
||||
if (scope == DependencyScope.COMPILE) {
|
||||
Module depModule = moduleOrderEntry.getModule();
|
||||
if (depModule != null && !visited.contains(depModule)) {
|
||||
fillSourceRoots(depModule, visited, result);
|
||||
fillSourceRoots(depModule, visited, result, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,9 +92,9 @@ public class AndroidPackagingCompiler implements PackagingCompiler {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static VirtualFile[] getSourceRootsForModuleAndDependencies(@NotNull Module module) {
|
||||
public static VirtualFile[] getSourceRootsForModuleAndDependencies(@NotNull Module module, boolean includingTests) {
|
||||
Set<VirtualFile> result = new HashSet<VirtualFile>();
|
||||
fillSourceRoots(module, new HashSet<Module>(), result);
|
||||
fillSourceRoots(module, new HashSet<Module>(), result, includingTests);
|
||||
return VfsUtil.toVirtualFileArray(result);
|
||||
}
|
||||
|
||||
@@ -102,7 +105,7 @@ public class AndroidPackagingCompiler implements PackagingCompiler {
|
||||
AndroidFacet facet = AndroidFacet.getInstance(module);
|
||||
if (facet != null && !facet.getConfiguration().LIBRARY_PROJECT) {
|
||||
VirtualFile manifestFile = AndroidRootUtil.getManifestFileForCompiler(facet);
|
||||
VirtualFile[] sourceRoots = getSourceRootsForModuleAndDependencies(module);
|
||||
VirtualFile[] sourceRoots = getSourceRootsForModuleAndDependencies(module, facet.getConfiguration().PACK_TEST_CODE);
|
||||
if (manifestFile != null) {
|
||||
AndroidFacetConfiguration configuration = facet.getConfiguration();
|
||||
VirtualFile outputDir = AndroidDexCompiler.getOutputDirectoryForDex(module);
|
||||
|
||||
@@ -81,6 +81,8 @@ public class AndroidFacetConfiguration implements FacetConfiguration {
|
||||
|
||||
public String CUSTOM_DEBUG_KEYSTORE_PATH = "";
|
||||
|
||||
public boolean PACK_TEST_CODE = false;
|
||||
|
||||
private AndroidFacet myFacet = null;
|
||||
|
||||
public void init(@NotNull Module module, @NotNull VirtualFile contentRoot) {
|
||||
|
||||
@@ -115,8 +115,8 @@
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="84519" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<grid id="84519" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="4" right="0"/>
|
||||
<constraints>
|
||||
<tabbedpane title="Compiler"/>
|
||||
</constraints>
|
||||
@@ -124,7 +124,7 @@
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="3e085" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="4" bottom="0" right="0"/>
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@@ -198,11 +198,11 @@
|
||||
</grid>
|
||||
<vspacer id="e716a">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="4c810" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="4" bottom="0" right="0"/>
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@@ -237,7 +237,7 @@
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="c2a96" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="4" bottom="0" right="0"/>
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@@ -297,6 +297,14 @@
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="39707" class="javax.swing.JCheckBox" binding="myIncludeTestCodeAndCheckBox" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/AndroidBundle" key="android.facet.settings.pack.test.sources"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
|
||||
@@ -93,6 +93,7 @@ public class AndroidFacetEditorTab extends FacetEditorTab {
|
||||
private JLabel myRGenPathLabel;
|
||||
private TextFieldWithBrowseButton myCustomDebugKeystoreField;
|
||||
private JBLabel myCustomKeystoreLabel;
|
||||
private JCheckBox myIncludeTestCodeAndCheckBox;
|
||||
|
||||
public AndroidFacetEditorTab(FacetEditorContext context, AndroidFacetConfiguration androidFacetConfiguration) {
|
||||
final Project project = context.getProject();
|
||||
@@ -282,6 +283,9 @@ public class AndroidFacetEditorTab extends FacetEditorTab {
|
||||
if (!myConfiguration.CUSTOM_DEBUG_KEYSTORE_PATH.equals(getSelectedCustomKeystorePath())) {
|
||||
return true;
|
||||
}
|
||||
if (myConfiguration.PACK_TEST_CODE != myIncludeTestCodeAndCheckBox.isSelected()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -390,6 +394,8 @@ public class AndroidFacetEditorTab extends FacetEditorTab {
|
||||
myConfiguration.RUN_PROCESS_RESOURCES_MAVEN_TASK = myRunProcessResourcesRadio.isSelected();
|
||||
|
||||
myConfiguration.GENERATE_UNSIGNED_APK = myGenerateUnsignedApk.isSelected();
|
||||
|
||||
myConfiguration.PACK_TEST_CODE = myIncludeTestCodeAndCheckBox.isSelected();
|
||||
|
||||
boolean useCustomAptSrc = myUseCustomSourceDirectoryRadio.isSelected();
|
||||
|
||||
@@ -513,6 +519,7 @@ public class AndroidFacetEditorTab extends FacetEditorTab {
|
||||
myCompileResourcesByIdeRadio.setSelected(!myConfiguration.RUN_PROCESS_RESOURCES_MAVEN_TASK);
|
||||
|
||||
myGenerateUnsignedApk.setSelected(myConfiguration.GENERATE_UNSIGNED_APK);
|
||||
myIncludeTestCodeAndCheckBox.setSelected(myConfiguration.PACK_TEST_CODE);
|
||||
|
||||
updateAptPanel();
|
||||
|
||||
|
||||
@@ -257,14 +257,8 @@ public class AndroidRootUtil {
|
||||
}
|
||||
}
|
||||
// do not support android-app->android-app compile dependencies
|
||||
else if (facet == null) {
|
||||
if (!outputDirs.contains(classDir) && classDir != null && classDir.exists()) {
|
||||
outputDirs.add(classDir);
|
||||
}
|
||||
VirtualFile classDirForTests = extension.getCompilerOutputPathForTests();
|
||||
if (!outputDirs.contains(classDirForTests) && classDirForTests != null && classDirForTests.exists()) {
|
||||
outputDirs.add(classDirForTests);
|
||||
}
|
||||
else if (facet == null && !outputDirs.contains(classDir) && classDir != null && classDir.exists()) {
|
||||
outputDirs.add(classDir);
|
||||
}
|
||||
}
|
||||
fillExternalLibrariesAndModules(depModule, outputDirs, libraries, visited, !libraryProject || exportedLibrariesOnly);
|
||||
|
||||
@@ -128,6 +128,7 @@ public class AndroidModuleBuilder extends JavaModuleBuilder {
|
||||
|
||||
if (myProjectType == ProjectType.TEST) {
|
||||
assert myTestedModule != null;
|
||||
facet.getConfiguration().PACK_TEST_CODE = true;
|
||||
ModuleOrderEntry entry = rootModel.addModuleOrderEntry(myTestedModule);
|
||||
entry.setScope(DependencyScope.PROVIDED);
|
||||
}
|
||||
|
||||
@@ -92,11 +92,10 @@ public class AndroidRunConfiguration extends AndroidRunConfigurationBase impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
|
||||
RunProfileState state = super.getState(executor, env);
|
||||
public AndroidRunningState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
|
||||
AndroidRunningState state = super.getState(executor, env);
|
||||
if (state != null) {
|
||||
assert state instanceof AndroidRunningState;
|
||||
((AndroidRunningState)state).setDeploy(DEPLOY);
|
||||
state.setDeploy(DEPLOY);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public abstract class AndroidRunConfigurationBase extends ModuleBasedConfigurati
|
||||
return true;
|
||||
}
|
||||
|
||||
public RunProfileState getState(@NotNull final Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
|
||||
public AndroidRunningState getState(@NotNull final Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
|
||||
final Module module = getConfigurationModule().getModule();
|
||||
if (module == null) {
|
||||
throw new ExecutionException("Module is not found");
|
||||
|
||||
@@ -218,10 +218,6 @@ public abstract class AndroidRunningState implements RunProfileState, AndroidDeb
|
||||
return myLock;
|
||||
}
|
||||
|
||||
public AndroidFacet getAndroidFacet() {
|
||||
return myFacet;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return myPackageName;
|
||||
}
|
||||
@@ -230,6 +226,7 @@ public abstract class AndroidRunningState implements RunProfileState, AndroidDeb
|
||||
return myFacet.getModule();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AndroidFacet getFacet() {
|
||||
return myFacet;
|
||||
}
|
||||
|
||||
+43
-1
@@ -28,6 +28,7 @@ import com.intellij.execution.Executor;
|
||||
import com.intellij.execution.configurations.*;
|
||||
import com.intellij.execution.junit.JUnitUtil;
|
||||
import com.intellij.execution.process.ProcessOutputTypes;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil;
|
||||
import com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView;
|
||||
import com.intellij.execution.ui.ConsoleView;
|
||||
@@ -35,6 +36,8 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
@@ -43,6 +46,7 @@ import com.intellij.psi.PsiPackage;
|
||||
import org.jetbrains.android.dom.manifest.Instrumentation;
|
||||
import org.jetbrains.android.dom.manifest.Manifest;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.android.facet.AndroidFacetConfiguration;
|
||||
import org.jetbrains.android.run.AndroidApplicationLauncher;
|
||||
import org.jetbrains.android.run.AndroidRunConfigurationBase;
|
||||
import org.jetbrains.android.run.AndroidRunConfigurationEditor;
|
||||
@@ -108,6 +112,44 @@ public class AndroidTestRunConfiguration extends AndroidRunConfigurationBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AndroidRunningState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
|
||||
final AndroidRunningState state = super.getState(executor, env);
|
||||
|
||||
if (state == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final AndroidFacet facet = state.getFacet();
|
||||
final AndroidFacetConfiguration configuration = facet.getConfiguration();
|
||||
|
||||
if (!configuration.PACK_TEST_CODE) {
|
||||
final Module module = facet.getModule();
|
||||
final int count = getTestSourceRootCount(module);
|
||||
|
||||
if (count > 0) {
|
||||
final String message = "Code and resources under test source " + (count > 1 ? "roots" : "root") +
|
||||
" aren't included into debug APK.\nWould you like to include them and recompile " +
|
||||
module.getName() + " module?" + "\n(You may change this option in Android facet settings later)";
|
||||
final int result =
|
||||
Messages.showYesNoCancelDialog(getProject(), message, "Test code not included into APK", Messages.getQuestionIcon());
|
||||
|
||||
if (result == Messages.YES) {
|
||||
configuration.PACK_TEST_CODE = true;
|
||||
}
|
||||
else if (result == Messages.CANCEL) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private static int getTestSourceRootCount(@NotNull Module module) {
|
||||
final ModuleRootManager manager = ModuleRootManager.getInstance(module);
|
||||
return manager.getSourceRoots(true).length - manager.getSourceRoots(false).length;
|
||||
}
|
||||
|
||||
private void checkTestMethod() throws RuntimeConfigurationException {
|
||||
JavaRunConfigurationModule configurationModule = getConfigurationModule();
|
||||
final PsiClass testClass =
|
||||
@@ -166,7 +208,7 @@ public class AndroidTestRunConfiguration extends AndroidRunConfigurationBase {
|
||||
BaseTestsOutputConsoleView consoleView = SMTestRunnerConnectionUtil
|
||||
.createAndAttachConsole("Android", state.getProcessHandler(), properties, state.getRunnerSettings(), state.getConfigurationSettings()
|
||||
);
|
||||
Disposer.register(state.getAndroidFacet().getModule().getProject(), consoleView);
|
||||
Disposer.register(state.getFacet().getModule().getProject(), consoleView);
|
||||
return consoleView;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user