use of com.android.sdklib.IAndroidTarget.OptionalLibrary in project android by JetBrains.
the class AndroidPlatform method parse.
/** @deprecated Use only for converting. */
@Deprecated
@Nullable
public static AndroidPlatform parse(@NotNull Library library, @Nullable Library.ModifiableModel model, @Nullable Map<String, AndroidSdkData> parsedSdks) {
VirtualFile[] files = model != null ? model.getFiles(CLASSES) : library.getFiles(CLASSES);
Set<String> jarPaths = Sets.newHashSet();
VirtualFile frameworkLibrary = null;
for (VirtualFile file : files) {
VirtualFile vFile = JarFileSystem.getInstance().getVirtualFileForJar(file);
if (vFile != null) {
if (vFile.getName().equals(FN_FRAMEWORK_LIBRARY)) {
frameworkLibrary = vFile;
}
jarPaths.add(vFile.getPath());
}
}
if (frameworkLibrary != null) {
VirtualFile sdkDir = frameworkLibrary.getParent();
if (sdkDir != null) {
VirtualFile platformsDir = sdkDir.getParent();
if (platformsDir != null && platformsDir.getName().equals(FD_PLATFORMS)) {
sdkDir = platformsDir.getParent();
if (sdkDir == null)
return null;
}
String sdkPath = sdkDir.getPath();
AndroidSdkData sdkData = parsedSdks != null ? parsedSdks.get(sdkPath) : null;
if (sdkData == null) {
sdkData = AndroidSdkData.getSdkData(sdkPath);
if (sdkData == null)
return null;
if (parsedSdks != null) {
parsedSdks.put(sdkPath, sdkData);
}
}
IAndroidTarget resultTarget = null;
for (IAndroidTarget target : sdkData.getTargets()) {
String targetsFrameworkLibPath = getCanonicalPath(target.getPath(ANDROID_JAR));
if (frameworkLibrary.getPath().equals(targetsFrameworkLibPath)) {
if (target.isPlatform()) {
if (resultTarget == null)
resultTarget = target;
} else {
boolean ok = true;
List<OptionalLibrary> libraries = target.getAdditionalLibraries();
if (libraries.isEmpty()) {
// we cannot identify add-on target without optional libraries by classpath
ok = false;
} else {
for (OptionalLibrary optionalLibrary : libraries) {
if (!jarPaths.contains(getCanonicalPath(optionalLibrary.getJar().getAbsolutePath()))) {
ok = false;
}
}
}
if (ok) {
resultTarget = target;
}
}
}
}
if (resultTarget != null) {
return new AndroidPlatform(sdkData, resultTarget);
}
}
}
return null;
}
Aggregations