Search in sources :

Example 16 with AndroidPlatform

use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.

the class RenderErrorContributor method reportTagResourceFormat.

private void reportTagResourceFormat(@NotNull RenderResult result, @NotNull RenderProblem message) {
    Object clientData = message.getClientData();
    if (!(clientData instanceof String[])) {
        return;
    }
    String[] strings = (String[]) clientData;
    if (strings.length != 2) {
        return;
    }
    RenderTask renderTask = result.getRenderTask();
    if (renderTask == null) {
        return;
    }
    IAndroidTarget target = renderTask.getConfiguration().getRealTarget();
    if (target == null) {
        return;
    }
    AndroidPlatform platform = renderTask.getPlatform();
    if (platform == null) {
        return;
    }
    AndroidTargetData targetData = platform.getSdkData().getTargetData(target);
    AttributeDefinitions definitionLookup = targetData.getPublicAttrDefs(result.getFile().getProject());
    final String attributeName = strings[0];
    final String currentValue = strings[1];
    if (definitionLookup == null) {
        return;
    }
    AttributeDefinition definition = definitionLookup.getAttrDefByName(attributeName);
    if (definition == null) {
        return;
    }
    Set<AttributeFormat> formats = definition.getFormats();
    if (formats.contains(AttributeFormat.Flag) || formats.contains(AttributeFormat.Enum)) {
        String[] values = definition.getValues();
        if (values.length > 0) {
            HtmlBuilder builder = new HtmlBuilder();
            builder.add("Change ").add(currentValue).add(" to: ");
            boolean first = true;
            for (String value : values) {
                if (first) {
                    first = false;
                } else {
                    builder.add(", ");
                }
                builder.addLink(value, myLinkManager.createReplaceAttributeValueUrl(attributeName, currentValue, value));
            }
            addRefreshAction(builder);
            addIssue().setSummary("Incorrect resource value format").setHtmlContent(builder).build();
        }
    }
}
Also used : HtmlBuilder(com.android.utils.HtmlBuilder) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) AttributeFormat(org.jetbrains.android.dom.attrs.AttributeFormat) AttributeDefinitions(org.jetbrains.android.dom.attrs.AttributeDefinitions) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData)

Example 17 with AndroidPlatform

use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.

the class AndroidPrecompileTask method prepareForCompilation.

private static boolean prepareForCompilation(CompileContext context) {
    final Project project = context.getProject();
    if (!checkArtifacts(context)) {
        return false;
    }
    checkAndroidDependencies(context);
    ExcludesConfiguration configuration = CompilerConfiguration.getInstance(project).getExcludedEntriesConfiguration();
    Set<ExcludeEntryDescription> addedEntries = new HashSet<>();
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        final AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet == null) {
            continue;
        }
        if (context.isRebuild()) {
            clearResCache(facet, context);
        }
        final AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
        final int platformToolsRevision = platform != null ? platform.getSdkData().getPlatformToolsRevision() : -1;
        LOG.debug("Platform-tools revision for module " + module.getName() + " is " + platformToolsRevision);
        if (!facet.isAppProject()) {
            if (platformToolsRevision >= 0 && platformToolsRevision <= 7) {
                LOG.debug("Excluded sources of module " + module.getName());
                excludeAllSourceRoots(module, configuration, addedEntries);
            } else {
                // todo: support this by project converter to use on compile-server
                unexcludeAllSourceRoots(facet, configuration);
            }
        }
    }
    if (addedEntries.size() > 0) {
        LOG.debug("Files excluded by Android: " + addedEntries.size());
        project.getMessageBus().connect().subscribe(CompilerTopics.COMPILATION_STATUS, new MyCompilationStatusListener(project, addedEntries));
    }
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) ExcludesConfiguration(com.intellij.openapi.compiler.options.ExcludesConfiguration) ExcludeEntryDescription(com.intellij.openapi.compiler.options.ExcludeEntryDescription) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HashSet(com.intellij.util.containers.hash.HashSet)

Example 18 with AndroidPlatform

use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.

the class AndroidCompileUtil method isExcludedFromCompilation.

public static boolean isExcludedFromCompilation(VirtualFile child, @Nullable Project project) {
    final CompilerManager compilerManager = project != null ? CompilerManager.getInstance(project) : null;
    if (compilerManager == null) {
        return false;
    }
    if (!compilerManager.isExcludedFromCompilation(child)) {
        return false;
    }
    final Module module = ModuleUtil.findModuleForFile(child, project);
    if (module == null) {
        return true;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null || facet.isAppProject()) {
        return true;
    }
    final AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
    if (platform == null) {
        return true;
    }
    // we exclude sources of library modules automatically for tools r7 or previous
    return platform.getSdkData().getPlatformToolsRevision() > 7;
}
Also used : CompilerManager(com.intellij.openapi.compiler.CompilerManager) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 19 with AndroidPlatform

use of org.jetbrains.android.sdk.AndroidPlatform 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 20 with AndroidPlatform

use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.

the class AndroidJunitPatcher method patchJavaParameters.

@Override
public void patchJavaParameters(@Nullable Module module, JavaParameters javaParameters) {
    if (module == null) {
        return;
    }
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    if (androidModel == null) {
        return;
    }
    // Modify the class path only if we're dealing with the unit test artifact.
    PathsList classPath = javaParameters.getClassPath();
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (sdk == null || !(sdk.getSdkType() instanceof AndroidSdkType)) {
        return;
    }
    SdkAdditionalData data = sdk.getSdkAdditionalData();
    if (!(data instanceof AndroidSdkAdditionalData)) {
        return;
    }
    AndroidPlatform platform = ((AndroidSdkAdditionalData) data).getAndroidPlatform();
    if (platform == null) {
        return;
    }
    classPath.remove(platform.getTarget().getPath(IAndroidTarget.ANDROID_JAR));
    // Move the mockable android jar to the end.
    String mockableJarPath = null;
    for (String path : classPath.getPathList()) {
        if (new File(FileUtil.toSystemDependentName(path)).getName().startsWith("mockable-android")) {
            // PathsList stores strings - use the one that's actually stored there.
            mockableJarPath = path;
            break;
        }
    }
    if (mockableJarPath != null) {
        classPath.remove(mockableJarPath);
        classPath.addTail(mockableJarPath);
    }
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) PathsList(com.intellij.util.PathsList) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidSdkType(org.jetbrains.android.sdk.AndroidSdkType) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData)

Aggregations

AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)46 Module (com.intellij.openapi.module.Module)16 IAndroidTarget (com.android.sdklib.IAndroidTarget)13 Nullable (org.jetbrains.annotations.Nullable)11 Project (com.intellij.openapi.project.Project)10 Sdk (com.intellij.openapi.projectRoots.Sdk)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 File (java.io.File)9 IOException (java.io.IOException)9 AndroidVersion (com.android.sdklib.AndroidVersion)8 NotNull (org.jetbrains.annotations.NotNull)6 AndroidTargetData (org.jetbrains.android.sdk.AndroidTargetData)5 LayoutLibrary (com.android.ide.common.rendering.LayoutLibrary)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)3 RenderingException (com.android.tools.idea.layoutlib.RenderingException)3 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)3 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)3 SourceProvider (com.android.builder.model.SourceProvider)2 IDevice (com.android.ddmlib.IDevice)2