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;
}
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;
}
Aggregations