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