Search in sources :

Example 1 with JpsAndroidApplicationArtifactProperties

use of org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties in project android by JetBrains.

the class AndroidArtifactBuildTaskProvider method createArtifactBuildTasks.

@NotNull
@Override
public List<? extends BuildTask> createArtifactBuildTasks(@NotNull JpsArtifact artifact, @NotNull ArtifactBuildPhase buildPhase) {
    if (buildPhase != ArtifactBuildPhase.FINISHING_BUILD) {
        return Collections.emptyList();
    }
    if (!(artifact.getArtifactType() instanceof AndroidApplicationArtifactType)) {
        return Collections.emptyList();
    }
    final JpsElement props = artifact.getProperties();
    if (!(props instanceof JpsAndroidApplicationArtifactProperties)) {
        return Collections.emptyList();
    }
    final JpsAndroidApplicationArtifactProperties androidProps = (JpsAndroidApplicationArtifactProperties) props;
    if (!(artifact.getArtifactType() instanceof AndroidApplicationArtifactType)) {
        return Collections.emptyList();
    }
    final AndroidArtifactSigningMode signingMode = androidProps.getSigningMode();
    if (signingMode != AndroidArtifactSigningMode.RELEASE_SIGNED && signingMode != AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
        return Collections.emptyList();
    }
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getPackagedFacet(artifact);
    return extension != null ? Collections.singletonList(new MyTask(artifact, extension, androidProps)) : Collections.<BuildTask>emptyList();
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) JpsAndroidApplicationArtifactProperties(org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties) AndroidApplicationArtifactType(org.jetbrains.jps.android.model.AndroidApplicationArtifactType) AndroidArtifactSigningMode(org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JpsAndroidApplicationArtifactProperties

use of org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties in project android by JetBrains.

the class AndroidSourceGeneratingBuilder method getProGuardOptions.

@NotNull
private static Object[] getProGuardOptions(@NotNull JpsArtifact artifact) {
    final JpsElement properties = artifact.getProperties();
    if (properties instanceof JpsAndroidApplicationArtifactProperties) {
        final JpsAndroidApplicationArtifactProperties p = (JpsAndroidApplicationArtifactProperties) properties;
        final boolean runProGuard = p.isRunProGuard();
        return runProGuard ? new Object[] { runProGuard, p.getProGuardCfgFiles() } : new Object[] { runProGuard };
    }
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsAndroidApplicationArtifactProperties(org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with JpsAndroidApplicationArtifactProperties

use of org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties in project android by JetBrains.

the class AndroidSourceGeneratingBuilder method checkArtifacts.

private static boolean checkArtifacts(@NotNull CompileContext context) {
    final List<JpsArtifact> artifacts = AndroidJpsUtil.getAndroidArtifactsToBuild(context);
    if (!checkUnambiguousAndRecursiveArtifacts(context, artifacts)) {
        return false;
    }
    final Set<JpsArtifact> debugArtifacts = new HashSet<JpsArtifact>();
    final Set<JpsArtifact> releaseArtifacts = new HashSet<JpsArtifact>();
    final Map<String, List<JpsArtifact>> moduleName2Artifact = new HashMap<String, List<JpsArtifact>>();
    for (JpsArtifact artifact : artifacts) {
        final JpsElement properties = artifact.getProperties();
        if (!(properties instanceof JpsAndroidApplicationArtifactProperties)) {
            continue;
        }
        final AndroidArtifactSigningMode mode = ((JpsAndroidApplicationArtifactProperties) properties).getSigningMode();
        if (mode == AndroidArtifactSigningMode.DEBUG || mode == AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
            debugArtifacts.add(artifact);
        } else {
            releaseArtifacts.add(artifact);
        }
        final JpsAndroidModuleExtension facet = AndroidJpsUtil.getPackagedFacet(artifact);
        if (facet != null) {
            final String moduleName = facet.getModule().getName();
            List<JpsArtifact> list = moduleName2Artifact.get(moduleName);
            if (list == null) {
                list = new ArrayList<JpsArtifact>();
                moduleName2Artifact.put(moduleName, 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: " + artifactsToString(debugArtifacts) + "\n" + "Release artifacts: " + artifactsToString(releaseArtifacts);
        context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, message));
        success = false;
    }
    if (releaseArtifacts.size() > 0 && AndroidJpsUtil.getRunConfigurationTypeId(context) != null) {
        final String message = "Cannot build release Android artifacts in the 'build before run' session\n" + "Release artifacts: " + artifactsToString(releaseArtifacts);
        context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, message));
        success = false;
    }
    for (Map.Entry<String, List<JpsArtifact>> entry : moduleName2Artifact.entrySet()) {
        final List<JpsArtifact> list = entry.getValue();
        final String moduleName = entry.getKey();
        if (list.size() > 1) {
            final JpsArtifact firstArtifact = list.get(0);
            final Object[] firstArtifactProGuardOptions = getProGuardOptions(firstArtifact);
            for (int i = 1; i < list.size(); i++) {
                final JpsArtifact artifact = list.get(i);
                if (!Arrays.equals(getProGuardOptions(artifact), firstArtifactProGuardOptions)) {
                    context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, "Artifacts related to the same module '" + moduleName + "' have different ProGuard options: " + firstArtifact.getName() + ", " + artifact.getName()));
                    success = false;
                    break;
                }
            }
        }
    }
    return success;
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) JpsAndroidApplicationArtifactProperties(org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) AndroidArtifactSigningMode(org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet)

Aggregations

JpsAndroidApplicationArtifactProperties (org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties)3 JpsElement (org.jetbrains.jps.model.JpsElement)3 AndroidArtifactSigningMode (org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode)2 NotNull (org.jetbrains.annotations.NotNull)2 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)2 HashMap (com.intellij.util.containers.HashMap)1 HashSet (com.intellij.util.containers.HashSet)1 THashSet (gnu.trove.THashSet)1 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)1 AndroidApplicationArtifactType (org.jetbrains.jps.android.model.AndroidApplicationArtifactType)1 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)1 JpsArtifact (org.jetbrains.jps.model.artifact.JpsArtifact)1