use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class TemplateManager method getExtraTemplateRootFolders.
/**
* @return A list of root folders containing extra templates
*/
@NotNull
public static List<File> getExtraTemplateRootFolders() {
List<File> folders = new ArrayList<>();
// Check in various locations in the SDK
AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (sdkData != null) {
File location = sdkData.getLocation();
if (USE_SDK_TEMPLATES) {
// Look in SDK/tools/templates
File toolsTemplatesFolder = new File(location, FileUtil.join(FD_TOOLS, FD_TEMPLATES));
if (toolsTemplatesFolder.isDirectory()) {
File[] templateRoots = toolsTemplatesFolder.listFiles(FileUtilRt.ALL_DIRECTORIES);
if (templateRoots != null) {
Collections.addAll(folders, templateRoots);
}
}
}
// Look in SDK/extras/*
File extras = new File(location, FD_EXTRAS);
if (extras.isDirectory()) {
for (File vendor : listFiles(extras)) {
if (!vendor.isDirectory()) {
continue;
}
for (File pkg : listFiles(vendor)) {
if (pkg.isDirectory()) {
File folder = new File(pkg, FD_TEMPLATES);
if (folder.isDirectory()) {
folders.add(folder);
}
}
}
}
// Legacy
File folder = new File(extras, FD_TEMPLATES);
if (folder.isDirectory()) {
folders.add(folder);
}
}
// Look in SDK/add-ons
File addOns = new File(location, FD_ADDONS);
if (addOns.isDirectory()) {
for (File addOn : listFiles(addOns)) {
if (!addOn.isDirectory()) {
continue;
}
File folder = new File(addOn, FD_TEMPLATES);
if (folder.isDirectory()) {
folders.add(folder);
}
}
}
}
// Look for source tree files
String homePath = toSystemIndependentName(PathManager.getHomePath());
// Release build?
VirtualFile root = LocalFileSystem.getInstance().findFileByPath(toSystemIndependentName(homePath + BUNDLED_TEMPLATE_PATH));
if (root == null) {
// Development build?
for (String path : DEVELOPMENT_TEMPLATE_PATHS) {
root = LocalFileSystem.getInstance().findFileByPath(toSystemIndependentName(homePath + path));
if (root != null) {
break;
}
}
}
if (root == null) {
// error message tailored for release build file layout
LOG.error("Templates not found in: " + homePath + BUNDLED_TEMPLATE_PATH + " or " + homePath + Arrays.toString(DEVELOPMENT_TEMPLATE_PATHS));
} else {
File templateDir = new File(root.getCanonicalPath()).getAbsoluteFile();
if (templateDir.isDirectory()) {
folders.add(templateDir);
}
}
return folders;
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class AndroidRunSdkToolAction method doAction.
public void doAction(@NotNull Project project) {
if (IdeInfo.getInstance().isAndroidStudio()) {
File androidHome = IdeSdks.getInstance().getAndroidSdkPath();
if (androidHome != null) {
doRunTool(project, androidHome.getPath());
return;
}
}
// Gradle project.
try {
LocalProperties localProperties = new LocalProperties(project);
File androidSdkPath = localProperties.getAndroidSdkPath();
if (androidSdkPath != null) {
doRunTool(project, androidSdkPath.getPath());
return;
}
} catch (IOException ignored) {
LOG.info(String.format("Unable to read local.properties file from project '%1$s'", project.getName()), ignored);
}
List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
assert facets.size() > 0;
Set<String> sdkSet = new HashSet<>();
for (AndroidFacet facet : facets) {
AndroidSdkData sdkData = facet.getConfiguration().getAndroidSdk();
if (sdkData != null) {
sdkSet.add(sdkData.getLocation().getPath());
}
}
if (sdkSet.size() == 0) {
Messages.showErrorDialog(project, AndroidBundle.message("specify.platform.error"), CommonBundle.getErrorTitle());
return;
}
String sdkPath = sdkSet.iterator().next();
if (sdkSet.size() > 1) {
String[] sdks = ArrayUtil.toStringArray(sdkSet);
int index = Messages.showChooseDialog(project, AndroidBundle.message("android.choose.sdk.label"), AndroidBundle.message("android.choose.sdk.title"), Messages.getQuestionIcon(), sdks, sdkPath);
if (index < 0) {
return;
}
sdkPath = sdks[index];
}
doRunTool(project, sdkPath);
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class SdkBuildToolsTooLowErrorHandler method getQuickFixHyperlinks.
@NotNull
public List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull String minimumVersion, @NotNull Project project, @Nullable Module module) {
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
boolean buildToolInstalled = false;
AndroidSdkHandler sdkHandler = null;
AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (androidSdkData != null) {
sdkHandler = androidSdkData.getSdkHandler();
}
if (sdkHandler != null) {
ProgressIndicator progress = new StudioLoggerProgressIndicator(SdkBuildToolsTooLowErrorHandler.class);
RepositoryPackages packages = sdkHandler.getSdkManager(progress).getPackages();
LocalPackage buildTool = packages.getLocalPackages().get(getBuildToolsPath(parseRevision(minimumVersion)));
buildToolInstalled = buildTool != null;
}
if (module != null) {
VirtualFile buildFile = getGradleBuildFile(module);
AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.find(project);
if (!buildToolInstalled) {
if (androidPluginInfo != null && androidPluginInfo.isExperimental()) {
hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, null));
} else {
hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, buildFile));
}
} else if (buildFile != null && androidPluginInfo != null && !androidPluginInfo.isExperimental()) {
hyperlinks.add(new FixBuildToolsVersionHyperlink(buildFile, minimumVersion));
}
if (buildFile != null) {
hyperlinks.add(new OpenFileHyperlink(buildFile.getPath()));
}
}
return hyperlinks;
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class MissingPlatformErrorHandler method findAndAddQuickFixes.
private void findAndAddQuickFixes(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
String missingPlatform = getMissingPlatform(text);
if (missingPlatform == null) {
return;
}
String loadError = null;
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
AndroidSdkHandler sdkHandler = null;
AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (androidSdkData != null) {
sdkHandler = androidSdkData.getSdkHandler();
}
if (sdkHandler != null) {
AndroidVersion version = AndroidTargetHash.getPlatformVersion(missingPlatform);
if (version != null) {
// Is the platform installed?
ProgressIndicator logger = new StudioLoggerProgressIndicator(getClass());
loadError = sdkHandler.getAndroidTargetManager(logger).getErrorForPackage(DetailsTypes.getPlatformPath(version));
hyperlinks.add(new InstallPlatformHyperlink(version));
}
}
if (hyperlinks.isEmpty()) {
// We are unable to install platform automatically.
List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
if (!facets.isEmpty()) {
// We can only open SDK manager if the project has an Android facet. Android facet has a reference to the Android SDK manager.
hyperlinks.add(new OpenAndroidSdkManagerHyperlink());
}
}
if (isNotEmpty(loadError)) {
text += "\nPossible cause: " + loadError;
}
SyncMessages.getInstance(project).updateNotification(notification, text, hyperlinks);
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class TemplateTest method checkTemplate.
private void checkTemplate(File templateFile, boolean createWithProject, @Nullable Map<String, Object> overrides, @Nullable Map<String, Object> projectOverrides) throws Exception {
if (KNOWN_BROKEN.contains(templateFile.getName())) {
return;
}
AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
assertNotNull(sdkData);
NewProjectWizardState values = createNewProjectState(createWithProject, sdkData);
String projectNameBase = "TestProject" + templateFile.getName();
TemplateWizardState state = values.getActivityTemplateState();
state.setTemplateLocation(templateFile);
// Iterate over all (valid) combinations of build target, minSdk and targetSdk
// TODO: Assert that the SDK manager has a minimum set of SDKs installed needed to be certain
// the test is comprehensive
// For now make sure there's at least one
boolean ranTest = false;
IAndroidTarget[] targets = sdkData.getTargets();
for (int i = targets.length - 1; i >= 0; i--) {
IAndroidTarget target = targets[i];
if (!target.isPlatform()) {
continue;
}
if (!isInterestingApiLevel(target.getVersion().getApiLevel(), MANUAL_BUILD_API)) {
continue;
}
TemplateMetadata activityMetadata = state.getTemplateMetadata();
TemplateMetadata projectMetadata = values.getTemplateMetadata();
assertNotNull(activityMetadata);
assertNotNull(projectMetadata);
int lowestSupportedApi = Math.max(projectMetadata.getMinSdk(), activityMetadata.getMinSdk());
for (int minSdk = lowestSupportedApi; minSdk <= SdkVersionInfo.HIGHEST_KNOWN_API; minSdk++) {
// Don't bother checking *every* single minSdk, just pick some interesting ones
if (!isInterestingApiLevel(minSdk, MANUAL_MIN_API)) {
continue;
}
for (int targetSdk = minSdk; targetSdk <= SdkVersionInfo.HIGHEST_KNOWN_API; targetSdk++) {
if (!isInterestingApiLevel(targetSdk, MANUAL_TARGET_API)) {
continue;
}
String status = validateTemplate(projectMetadata, minSdk, target.getVersion().getApiLevel());
if (status != null) {
continue;
}
// Also make sure activity is enabled for these versions
status = validateTemplate(activityMetadata, minSdk, target.getVersion().getApiLevel());
if (status != null) {
continue;
}
// Iterate over all new new project templates
// should I try all options of theme with all platforms?
// or just try all platforms, with one setting for each?
// doesn't seem like I need to multiply
// just pick the best setting that applies instead for each platform
Collection<Parameter> parameters = projectMetadata.getParameters();
projectParameters: for (Parameter parameter : parameters) {
if (overrides != null) {
String base = projectNameBase + "_min_" + minSdk + "_target_" + targetSdk + "_build_" + target.getVersion().getApiLevel() + "_overrides";
checkApiTarget(minSdk, targetSdk, target, values, base, state, overrides, projectOverrides);
ranTest = true;
break projectParameters;
}
List<Element> options = parameter.getOptions();
if (parameter.type == Parameter.Type.ENUM) {
assertNotNull(parameter.id);
for (Element element : options) {
Option option = Option.get(element);
String optionId = option.id;
int optionMinSdk = option.minSdk;
int optionMinBuildApi = option.minBuild;
if (optionMinSdk <= minSdk && optionMinBuildApi <= target.getVersion().getApiLevel()) {
values.put(parameter.id, optionId);
if (parameter.id.equals("baseTheme")) {
String base = projectNameBase + "_min_" + minSdk + "_target_" + targetSdk + "_build_" + target.getVersion().getApiLevel() + "_theme_" + optionId;
checkApiTarget(minSdk, targetSdk, target, values, base, state, null, null);
ranTest = true;
if (!TEST_VARIABLE_COMBINATIONS) {
break projectParameters;
}
}
}
}
}
}
if (TEST_JUST_ONE_TARGET_SDK_VERSION) {
break;
}
}
if (TEST_JUST_ONE_MIN_SDK) {
break;
}
}
if (TEST_JUST_ONE_BUILD_TARGET) {
break;
}
}
assertTrue("Didn't run any tests! Make sure you have the right platforms installed.", ranTest);
}
Aggregations