Search in sources :

Example 1 with AndroidApplicationArtifactProperties

use of org.jetbrains.android.compiler.artifact.AndroidApplicationArtifactProperties in project android by JetBrains.

the class AndroidPrecompileTask method checkArtifacts.

private static boolean checkArtifacts(@NotNull CompileContext context) {
    final Project project = context.getProject();
    final CompileScope scope = context.getCompileScope();
    final Set<Artifact> artifacts = ApplicationManager.getApplication().runReadAction(new Computable<Set<Artifact>>() {

        @Override
        public Set<Artifact> compute() {
            return ArtifactCompileScope.getArtifactsToBuild(project, scope, false);
        }
    });
    if (artifacts == null) {
        return true;
    }
    final Set<Artifact> debugArtifacts = new HashSet<>();
    final Set<Artifact> releaseArtifacts = new HashSet<>();
    final Map<AndroidFacet, List<Artifact>> facet2artifacts = new HashMap<>();
    for (final Artifact artifact : artifacts) {
        final ArtifactProperties<?> properties = artifact.getProperties(AndroidArtifactPropertiesProvider.getInstance());
        if (properties instanceof AndroidApplicationArtifactProperties) {
            final AndroidArtifactSigningMode mode = ((AndroidApplicationArtifactProperties) properties).getSigningMode();
            if (mode == AndroidArtifactSigningMode.DEBUG || mode == AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
                debugArtifacts.add(artifact);
            } else {
                releaseArtifacts.add(artifact);
            }
        }
        final AndroidFacet facet = ApplicationManager.getApplication().runReadAction(new Computable<AndroidFacet>() {

            @Nullable
            @Override
            public AndroidFacet compute() {
                return AndroidArtifactUtil.getPackagedFacet(project, artifact);
            }
        });
        if (facet != null) {
            List<Artifact> list = facet2artifacts.get(facet);
            if (list == null) {
                list = new ArrayList<>();
                facet2artifacts.put(facet, list);
            }
            list.add(artifact);
        }
    }
    boolean success = true;
    if (debugArtifacts.size() > 0 && releaseArtifacts.size() > 0) {
        final String message = "Cannot build debug and release Android artifacts in the same session\n" + "Debug artifacts: " + toString(debugArtifacts) + "\n" + "Release artifacts: " + toString(releaseArtifacts);
        context.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
        success = false;
    }
    if (releaseArtifacts.size() > 0 && CompileStepBeforeRun.getRunConfiguration(context) != null) {
        final String message = "Cannot build release Android artifacts in the 'make before run' session\n" + "Release artifacts: " + toString(releaseArtifacts);
        context.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
        success = false;
    }
    for (Map.Entry<AndroidFacet, List<Artifact>> entry : facet2artifacts.entrySet()) {
        final List<Artifact> list = entry.getValue();
        final String moduleName = entry.getKey().getModule().getName();
        if (list.size() > 1) {
            final Artifact firstArtifact = list.get(0);
            final Object[] firstArtifactProGuardOptions = getProGuardOptions(firstArtifact);
            for (int i = 1; i < list.size(); i++) {
                final Artifact artifact = list.get(i);
                if (!Arrays.equals(getProGuardOptions(artifact), firstArtifactProGuardOptions)) {
                    context.addMessage(CompilerMessageCategory.ERROR, "Artifacts related to the same module '" + moduleName + "' have different ProGuard options: " + firstArtifact.getName() + ", " + artifact.getName(), null, -1, -1);
                    success = false;
                    break;
                }
            }
        }
    }
    return success;
}
Also used : HashSet(com.intellij.util.containers.hash.HashSet) HashMap(com.intellij.util.containers.HashMap) AndroidApplicationArtifactProperties(org.jetbrains.android.compiler.artifact.AndroidApplicationArtifactProperties) HashSet(com.intellij.util.containers.hash.HashSet) Artifact(com.intellij.packaging.artifacts.Artifact) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) ArtifactCompileScope(com.intellij.packaging.impl.compiler.ArtifactCompileScope) AndroidArtifactSigningMode(org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode) HashMap(com.intellij.util.containers.HashMap) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AndroidApplicationArtifactProperties

use of org.jetbrains.android.compiler.artifact.AndroidApplicationArtifactProperties in project android by JetBrains.

the class AndroidBuildTargetScopeProvider method isProGuardUsed.

private static boolean isProGuardUsed(@NotNull Project project, @NotNull CompileScope scope) {
    for (Module module : scope.getAffectedModules()) {
        final AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet != null && facet.getProperties().RUN_PROGUARD) {
            return true;
        }
    }
    final String proguardCfgPathsStr = scope.getUserData(AndroidCompileUtil.PROGUARD_CFG_PATHS_KEY);
    if (proguardCfgPathsStr != null && proguardCfgPathsStr.length() > 0) {
        return true;
    }
    final Set<Artifact> artifacts = ArtifactCompileScope.getArtifactsToBuild(project, scope, false);
    for (Artifact artifact : artifacts) {
        if (artifact.getArtifactType() instanceof AndroidApplicationArtifactType) {
            final ArtifactProperties<?> properties = artifact.getProperties(AndroidArtifactPropertiesProvider.getInstance());
            if (properties instanceof AndroidApplicationArtifactProperties) {
                final AndroidApplicationArtifactProperties p = (AndroidApplicationArtifactProperties) properties;
                if (p.isRunProGuard()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : AndroidApplicationArtifactProperties(org.jetbrains.android.compiler.artifact.AndroidApplicationArtifactProperties) Module(com.intellij.openapi.module.Module) AndroidApplicationArtifactType(org.jetbrains.android.compiler.artifact.AndroidApplicationArtifactType) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Artifact(com.intellij.packaging.artifacts.Artifact)

Aggregations

Artifact (com.intellij.packaging.artifacts.Artifact)2 AndroidApplicationArtifactProperties (org.jetbrains.android.compiler.artifact.AndroidApplicationArtifactProperties)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 ArtifactCompileScope (com.intellij.packaging.impl.compiler.ArtifactCompileScope)1 HashMap (com.intellij.util.containers.HashMap)1 HashSet (com.intellij.util.containers.hash.HashSet)1 AndroidApplicationArtifactType (org.jetbrains.android.compiler.artifact.AndroidApplicationArtifactType)1 AndroidArtifactSigningMode (org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode)1 Nullable (org.jetbrains.annotations.Nullable)1