Search in sources :

Example 1 with AndroidFacetConfiguration

use of org.jetbrains.android.facet.AndroidFacetConfiguration in project android by JetBrains.

the class AndroidTestRunConfiguration method checkConfiguration.

@NotNull
@Override
public List<ValidationError> checkConfiguration(@NotNull AndroidFacet facet) {
    List<ValidationError> errors = Lists.newArrayList();
    Module module = facet.getModule();
    JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
    switch(TESTING_TYPE) {
        case TEST_ALL_IN_PACKAGE:
            final PsiPackage testPackage = facade.findPackage(PACKAGE_NAME);
            if (testPackage == null) {
                errors.add(ValidationError.warning(ExecutionBundle.message("package.does.not.exist.error.message", PACKAGE_NAME)));
            }
            break;
        case TEST_CLASS:
            PsiClass testClass = null;
            try {
                testClass = getConfigurationModule().checkModuleAndClassName(CLASS_NAME, ExecutionBundle.message("no.test.class.specified.error.text"));
            } catch (RuntimeConfigurationException e) {
                errors.add(ValidationError.fromException(e));
            }
            if (testClass != null && !JUnitUtil.isTestClass(testClass)) {
                errors.add(ValidationError.warning(ExecutionBundle.message("class.isnt.test.class.error.message", CLASS_NAME)));
            }
            break;
        case TEST_METHOD:
            errors.addAll(checkTestMethod());
            break;
    }
    if (INSTRUMENTATION_RUNNER_CLASS.length() > 0) {
        if (facade.findClass(INSTRUMENTATION_RUNNER_CLASS, module.getModuleWithDependenciesAndLibrariesScope(true)) == null) {
            errors.add(ValidationError.fatal(AndroidBundle.message("instrumentation.runner.class.not.specified.error")));
        }
    }
    final AndroidFacetConfiguration configuration = facet.getConfiguration();
    if (!facet.requiresAndroidModel() && !configuration.getState().PACK_TEST_CODE) {
        final int count = getTestSourceRootCount(module);
        if (count > 0) {
            final String shortMessage = "Test code not included into APK";
            final String fixMessage = "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)";
            Runnable quickFix = new Runnable() {

                @Override
                public void run() {
                    final int result = Messages.showYesNoCancelDialog(getProject(), fixMessage, shortMessage, Messages.getQuestionIcon());
                    if (result == Messages.YES) {
                        configuration.getState().PACK_TEST_CODE = true;
                    }
                }
            };
            errors.add(ValidationError.fatal(shortMessage, quickFix));
        }
    }
    return errors;
}
Also used : AndroidFacetConfiguration(org.jetbrains.android.facet.AndroidFacetConfiguration) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with AndroidFacetConfiguration

use of org.jetbrains.android.facet.AndroidFacetConfiguration in project android by JetBrains.

the class AndroidUtils method addAndroidFacet.

@NotNull
public static AndroidFacet addAndroidFacet(final Module module, @NotNull VirtualFile contentRoot, boolean library) {
    final FacetManager facetManager = FacetManager.getInstance(module);
    ModifiableFacetModel model = facetManager.createModifiableModel();
    AndroidFacet facet = model.getFacetByType(AndroidFacet.ID);
    if (facet == null) {
        facet = facetManager.createFacet(AndroidFacet.getFacetType(), "Android", null);
        AndroidFacetConfiguration configuration = facet.getConfiguration();
        configuration.init(module, contentRoot);
        if (library) {
            facet.setProjectType(PROJECT_TYPE_LIBRARY);
        }
        model.addFacet(facet);
    }
    model.commit();
    return facet;
}
Also used : AndroidFacetConfiguration(org.jetbrains.android.facet.AndroidFacetConfiguration) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) ProjectFacetManager(com.intellij.facet.ProjectFacetManager) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with AndroidFacetConfiguration

use of org.jetbrains.android.facet.AndroidFacetConfiguration in project android by JetBrains.

the class AndroidCompileUtil method getProguardConfigFilePathIfShouldRun.

@Nullable
public static ProguardRunningOptions getProguardConfigFilePathIfShouldRun(@NotNull AndroidFacet facet, CompileContext context) {
    // wizard
    String pathsStr = context.getCompileScope().getUserData(PROGUARD_CFG_PATHS_KEY);
    if (pathsStr != null) {
        final String[] paths = pathsStr.split(File.pathSeparator);
        if (paths.length > 0) {
            return new ProguardRunningOptions(Arrays.asList(paths));
        }
    }
    final AndroidPlatform platform = AndroidPlatform.getInstance(facet.getModule());
    final String sdkHomePath = platform != null ? FileUtil.toCanonicalPath(platform.getSdkData().getPath()) : null;
    // artifact
    final Project project = context.getProject();
    final Set<Artifact> artifacts = ArtifactCompileScope.getArtifactsToBuild(project, context.getCompileScope(), false);
    for (Artifact artifact : artifacts) {
        if (artifact.getArtifactType() instanceof AndroidApplicationArtifactType && facet.equals(AndroidArtifactUtil.getPackagedFacet(project, artifact))) {
            final ArtifactProperties<?> properties = artifact.getProperties(AndroidArtifactPropertiesProvider.getInstance());
            if (properties instanceof AndroidApplicationArtifactProperties) {
                final AndroidApplicationArtifactProperties p = (AndroidApplicationArtifactProperties) properties;
                if (p.isRunProGuard()) {
                    final List<String> paths = AndroidUtils.urlsToOsPaths(p.getProGuardCfgFiles(), sdkHomePath);
                    return new ProguardRunningOptions(paths);
                }
            }
        }
    }
    // facet
    final AndroidFacetConfiguration configuration = facet.getConfiguration();
    final JpsAndroidModuleProperties properties = configuration.getState();
    if (properties != null && properties.RUN_PROGUARD) {
        final List<String> urls = properties.myProGuardCfgFiles;
        final List<String> paths = AndroidUtils.urlsToOsPaths(urls, sdkHomePath);
        return new ProguardRunningOptions(paths);
    }
    return null;
}
Also used : AndroidFacetConfiguration(org.jetbrains.android.facet.AndroidFacetConfiguration) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) Artifact(com.intellij.packaging.artifacts.Artifact) Project(com.intellij.openapi.project.Project) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with AndroidFacetConfiguration

use of org.jetbrains.android.facet.AndroidFacetConfiguration in project android by JetBrains.

the class AndroidFacetImporterBase method reimportFacet.

@Override
protected void reimportFacet(IdeModifiableModelsProvider modelsProvider, Module module, MavenRootModelAdapter rootModel, AndroidFacet facet, MavenProjectsTree mavenTree, MavenProject mavenProject, MavenProjectChanges changes, Map<MavenProject, String> mavenProjectToModuleName, List<MavenProjectsProcessorTask> postTasks) {
    configurePaths(facet, mavenProject);
    facet.getProperties().ENABLE_MANIFEST_MERGING = Boolean.parseBoolean(findConfigValue(mavenProject, "mergeManifests"));
    facet.getProperties().COMPILE_CUSTOM_GENERATED_SOURCES = false;
    configureAndroidPlatform(facet, mavenProject, modelsProvider);
    final Project project = module.getProject();
    importExternalAndroidLibDependencies(project, rootModel, modelsProvider, mavenTree, mavenProject, mavenProjectToModuleName, postTasks);
    if (hasAndroidLibDependencies(mavenProject) && MavenProjectsManager.getInstance(project).getImportingSettings().isUseMavenOutput()) {
        // IDEA's apklibs building model is different from Maven's one, so we cannot use the same
        rootModel.useModuleOutput(mavenProject.getBuildDirectory() + "/idea-classes", mavenProject.getBuildDirectory() + "/idea-test-classes");
    }
    project.putUserData(DELETE_OBSOLETE_MODULE_TASK_KEY, Boolean.TRUE);
    postTasks.add(new MyDeleteObsoleteApklibModulesTask(project));
    // exclude folders where Maven generates sources if gen source roots were changed by user manually
    final AndroidFacetConfiguration defaultConfig = new AndroidFacetConfiguration();
    AndroidMavenProviderImpl.setPathsToDefault(mavenProject, module, defaultConfig);
    if (!defaultConfig.getState().GEN_FOLDER_RELATIVE_PATH_APT.equals(facet.getProperties().GEN_FOLDER_RELATIVE_PATH_APT)) {
        final String rPath = mavenProject.getGeneratedSourcesDirectory(false) + "/r";
        rootModel.unregisterAll(rPath, false, true);
        rootModel.addExcludedFolder(rPath);
    }
    if (!defaultConfig.getState().GEN_FOLDER_RELATIVE_PATH_AIDL.equals(facet.getProperties().GEN_FOLDER_RELATIVE_PATH_AIDL)) {
        final String aidlPath = mavenProject.getGeneratedSourcesDirectory(false) + "/aidl";
        rootModel.unregisterAll(aidlPath, false, true);
        rootModel.addExcludedFolder(aidlPath);
    }
    if (facet.isLibraryProject()) {
        removeAttachedJarDependency(modelsProvider, mavenTree, mavenProject);
    }
}
Also used : Project(com.intellij.openapi.project.Project) AndroidFacetConfiguration(org.jetbrains.android.facet.AndroidFacetConfiguration)

Example 5 with AndroidFacetConfiguration

use of org.jetbrains.android.facet.AndroidFacetConfiguration in project android by JetBrains.

the class AndroidFacetImporterBase method importExternalApklibArtifact.

@Nullable
private static Module importExternalApklibArtifact(Project project, Module apklibModule, IdeModifiableModelsProvider modelsProvider, MavenProject mavenProject, MavenProjectsTree mavenTree, MavenId artifactMavenId, String artifactFilePath, ModifiableModuleModel moduleModel, Map<MavenProject, String> mavenProject2ModuleName) {
    final String genModuleName = AndroidMavenUtil.getModuleNameForExtApklibArtifact(artifactMavenId);
    String genExternalApklibsDirPath = null;
    String targetDirPath = null;
    if (apklibModule == null) {
        genExternalApklibsDirPath = AndroidMavenUtil.computePathForGenExternalApklibsDir(artifactMavenId, mavenProject, mavenTree.getProjects());
        targetDirPath = genExternalApklibsDirPath != null ? genExternalApklibsDirPath + '/' + AndroidMavenUtil.getMavenIdStringForFileName(artifactMavenId) : null;
    } else {
        final VirtualFile[] contentRoots = ModuleRootManager.getInstance(apklibModule).getContentRoots();
        if (contentRoots.length == 1) {
            targetDirPath = contentRoots[0].getPath();
        } else {
            final String moduleDir = new File(apklibModule.getModuleFilePath()).getParent();
            if (moduleDir != null) {
                targetDirPath = moduleDir + '/' + AndroidMavenUtil.getMavenIdStringForFileName(artifactMavenId);
            }
        }
    }
    if (targetDirPath == null) {
        return null;
    }
    if (!extractArtifact(artifactFilePath, targetDirPath, project, genModuleName)) {
        return null;
    }
    final AndroidExternalApklibDependenciesManager adm = AndroidExternalApklibDependenciesManager.getInstance(project);
    adm.setArtifactFilePath(artifactMavenId, FileUtil.toSystemIndependentName(artifactFilePath));
    final VirtualFile vApklibDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(targetDirPath);
    if (vApklibDir == null) {
        LOG.error("Cannot find file " + targetDirPath + " in VFS");
        return null;
    }
    if (apklibModule == null) {
        final String genModuleFilePath = genExternalApklibsDirPath + '/' + genModuleName + ModuleFileType.DOT_DEFAULT_EXTENSION;
        apklibModule = moduleModel.newModule(genModuleFilePath, StdModuleTypes.JAVA.getId());
    }
    final ModifiableRootModel apklibModuleModel = modelsProvider.getModifiableRootModel(apklibModule);
    final ContentEntry contentEntry = apklibModuleModel.addContentEntry(vApklibDir);
    final VirtualFile sourceRoot = vApklibDir.findChild(AndroidMavenUtil.APK_LIB_ARTIFACT_SOURCE_ROOT);
    if (sourceRoot != null) {
        contentEntry.addSourceFolder(sourceRoot, false);
    }
    final AndroidFacet facet = AndroidUtils.addAndroidFacet(apklibModuleModel.getModule(), vApklibDir, true);
    final AndroidFacetConfiguration configuration = facet.getConfiguration();
    String s = AndroidRootUtil.getPathRelativeToModuleDir(apklibModule, vApklibDir.getPath());
    if (s != null) {
        s = s.length() > 0 ? '/' + s + '/' : "/";
        configuration.getState().RES_FOLDER_RELATIVE_PATH = s + AndroidMavenUtil.APK_LIB_ARTIFACT_RES_DIR;
        configuration.getState().LIBS_FOLDER_RELATIVE_PATH = s + AndroidMavenUtil.APK_LIB_ARTIFACT_NATIVE_LIBS_DIR;
        configuration.getState().MANIFEST_FILE_RELATIVE_PATH = s + AndroidMavenUtil.APK_LIB_ARTIFACT_MANIFEST_FILE;
    }
    importSdkAndDependenciesForApklibArtifact(project, apklibModuleModel, modelsProvider, mavenTree, artifactMavenId, mavenProject2ModuleName);
    return apklibModule;
}
Also used : AndroidFacetConfiguration(org.jetbrains.android.facet.AndroidFacetConfiguration) File(java.io.File) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AndroidFacetConfiguration (org.jetbrains.android.facet.AndroidFacetConfiguration)7 Module (com.intellij.openapi.module.Module)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 Project (com.intellij.openapi.project.Project)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 FacetManager (com.intellij.facet.FacetManager)1 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)1 ProjectFacetManager (com.intellij.facet.ProjectFacetManager)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Artifact (com.intellij.packaging.artifacts.Artifact)1 File (java.io.File)1 Element (org.jdom.Element)1 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)1 JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)1