use of com.google.idea.blaze.android.libraries.UnpackedAars in project intellij by bazelbuild.
the class BlazeModuleSystemDependentLibrariesIntegrationTest method getAarLibrary.
private ExternalAndroidLibrary getAarLibrary(PathString rootPath, String aarPath, @Nullable String resourcePackage) {
String path = rootPath.resolve(aarPath).getNativePath();
String name = FileUtil.getNameWithoutExtension(PathUtil.getFileName(path));
String aarDirName = UnpackedAarUtils.generateAarDirectoryName(name, path.hashCode()) + SdkConstants.DOT_AAR;
UnpackedAars unpackedAars = UnpackedAars.getInstance(getProject());
File aarDir = new File(unpackedAars.getCacheDir(), aarDirName);
PathString aarFile = new PathString(aarDir);
PathString resFolder = new PathString(UnpackedAarUtils.getResDir(aarDir));
return new ExternalLibraryImpl(LibraryKey.libraryNameFromArtifactLocation(source(aarPath))).withLocation(aarFile).withManifestFile(resFolder == null ? null : resFolder.getParentOrRoot().resolve("AndroidManifest.xml")).withResFolder(resFolder == null ? null : new SelectiveResourceFolder(resFolder, null)).withSymbolFile(resFolder == null ? null : resFolder.getParentOrRoot().resolve("R.txt")).withPackageName(resourcePackage);
}
use of com.google.idea.blaze.android.libraries.UnpackedAars in project intellij by bazelbuild.
the class AarLibrary method modifyLibraryModel.
/**
* Create an IntelliJ library that matches Android Studio's expectation for an AAR. See {@link
* org.jetbrains.android.facet.ResourceFolderManager#addAarsFromModuleLibraries}.
*/
@Override
public void modifyLibraryModel(Project project, ArtifactLocationDecoder artifactLocationDecoder, ModifiableModel libraryModel) {
UnpackedAars unpackedAars = UnpackedAars.getInstance(project);
File resourceDirectory = unpackedAars.getResourceDirectory(artifactLocationDecoder, this);
if (resourceDirectory == null) {
logger.warn("No resource directory found for aar: " + aarArtifact);
return;
}
libraryModel.addRoot(pathToUrl(resourceDirectory), OrderRootType.CLASSES);
// have class jars or sources
if (libraryArtifact == null) {
return;
}
File jar = unpackedAars.getClassJar(artifactLocationDecoder, this);
if (jar != null) {
libraryModel.addRoot(pathToUrl(jar), OrderRootType.CLASSES);
}
// Longer term, we may want to make this behave just like the Java libraries.
for (ArtifactLocation srcJar : libraryArtifact.getSourceJars()) {
File sourceJar = JarCache.getInstance(project).getCachedSourceJar(artifactLocationDecoder, srcJar);
if (sourceJar != null) {
libraryModel.addRoot(pathToUrl(sourceJar), OrderRootType.SOURCES);
}
}
}
use of com.google.idea.blaze.android.libraries.UnpackedAars in project intellij by bazelbuild.
the class AarLibrary method getLintRuleJar.
@Nullable
public File getLintRuleJar(Project project, ArtifactLocationDecoder decoder) {
UnpackedAars unpackedAars = UnpackedAars.getInstance(project);
File lintRuleJar = unpackedAars.getLintRuleJar(decoder, this);
return (lintRuleJar == null || !lintRuleJar.exists()) ? null : lintRuleJar;
}
use of com.google.idea.blaze.android.libraries.UnpackedAars in project intellij by bazelbuild.
the class BlazeModuleSystem method toExternalLibrary.
@Nullable
static ExternalAndroidLibrary toExternalLibrary(Project project, @Nullable AarLibrary library, ArtifactLocationDecoder decoder) {
if (library == null) {
return null;
}
UnpackedAars unpackedAars = UnpackedAars.getInstance(project);
File aarFile = unpackedAars.getAarDir(decoder, library);
if (aarFile == null) {
logger.warn(String.format("Fail to locate AAR file %s. Re-sync the project may solve the problem", library.aarArtifact));
return null;
}
File resFolder = unpackedAars.getResourceDirectory(decoder, library);
PathString resFolderPathString = resFolder == null ? null : new PathString(resFolder);
return new ExternalLibraryImpl(library.key.toString()).withLocation(new PathString(aarFile)).withManifestFile(resFolderPathString == null ? null : resFolderPathString.getParentOrRoot().resolve("AndroidManifest.xml")).withResFolder(resFolderPathString == null ? null : new SelectiveResourceFolder(resFolderPathString, null)).withSymbolFile(resFolderPathString == null ? null : resFolderPathString.getParentOrRoot().resolve("R.txt")).withPackageName(library.resourcePackage);
}
use of com.google.idea.blaze.android.libraries.UnpackedAars in project intellij by bazelbuild.
the class AswbGotoDeclarationTest method getResourceFile.
private VirtualFile getResourceFile(File aarLibraryFile, String relativePathToResourceFile) {
String path = aarLibraryFile.getAbsolutePath();
String name = FileUtil.getNameWithoutExtension(PathUtil.getFileName(path));
String aarDirName = UnpackedAarUtils.generateAarDirectoryName(name, path.hashCode()) + SdkConstants.DOT_AAR;
UnpackedAars unpackedAars = UnpackedAars.getInstance(getProject());
File aarDir = new File(unpackedAars.getCacheDir(), aarDirName);
File resourceDir = UnpackedAarUtils.getResDir(aarDir);
return VirtualFileManager.getInstance().findFileByUrl(URLUtil.FILE_PROTOCOL + URLUtil.SCHEME_SEPARATOR + resourceDir.getPath() + File.separator + relativePathToResourceFile);
}
Aggregations