Search in sources :

Example 1 with UnpackedAars

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);
}
Also used : SelectiveResourceFolder(com.android.projectmodel.SelectiveResourceFolder) PathString(com.android.ide.common.util.PathString) ExternalLibraryImpl(com.android.projectmodel.ExternalLibraryImpl) PathString(com.android.ide.common.util.PathString) UnpackedAars(com.google.idea.blaze.android.libraries.UnpackedAars) File(java.io.File)

Example 2 with UnpackedAars

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);
        }
    }
}
Also used : ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) UnpackedAars(com.google.idea.blaze.android.libraries.UnpackedAars) File(java.io.File)

Example 3 with UnpackedAars

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;
}
Also used : UnpackedAars(com.google.idea.blaze.android.libraries.UnpackedAars) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with UnpackedAars

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);
}
Also used : SelectiveResourceFolder(com.android.projectmodel.SelectiveResourceFolder) PathString(com.android.ide.common.util.PathString) ExternalLibraryImpl(com.android.projectmodel.ExternalLibraryImpl) UnpackedAars(com.google.idea.blaze.android.libraries.UnpackedAars) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with UnpackedAars

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);
}
Also used : UnpackedAars(com.google.idea.blaze.android.libraries.UnpackedAars) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

UnpackedAars (com.google.idea.blaze.android.libraries.UnpackedAars)5 File (java.io.File)5 PathString (com.android.ide.common.util.PathString)2 ExternalLibraryImpl (com.android.projectmodel.ExternalLibraryImpl)2 SelectiveResourceFolder (com.android.projectmodel.SelectiveResourceFolder)2 Nullable (org.jetbrains.annotations.Nullable)2 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1