Search in sources :

Example 1 with PathString

use of com.android.ide.common.util.PathString in project intellij by bazelbuild.

the class BlazeSampleDataDirectoryProvider method getOrCreateSampleDataDirectory.

@Override
@Nullable
public PathString getOrCreateSampleDataDirectory() throws IOException {
    PathString sampleDataDirectory = getSampleDataDirectory();
    if (sampleDataDirectory == null) {
        return null;
    }
    PathString rootPath = sampleDataDirectory.getRoot();
    VirtualFile root = rootPath != null ? toVirtualFile(rootPath) : null;
    if (root == null) {
        return sampleDataDirectory;
    }
    createDirectoryIfMissing(root, sampleDataDirectory.getPortablePath());
    // We want to make sure that the sample data directory is associated with this resource module
    // instead of just being lumped into the workspace module because it sits outside the res
    // folder.
    ModuleRootModificationUtil.addContentRoot(module, sampleDataDirectory.getPortablePath());
    return sampleDataDirectory;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileExtensions.toVirtualFile(com.android.tools.idea.util.FileExtensions.toVirtualFile) FileExtensions.toPathString(com.android.tools.idea.util.FileExtensions.toPathString) PathString(com.android.ide.common.util.PathString) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PathString

use of com.android.ide.common.util.PathString 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 3 with PathString

use of com.android.ide.common.util.PathString in project intellij by bazelbuild.

the class BlazeSampleDataDirectoryProviderTest method getOrCreateSampleDataDirectory_doesNothingIfNotResourceModule.

@Test
public void getOrCreateSampleDataDirectory_doesNothingIfNotResourceModule() throws IOException {
    BlazeSampleDataDirectoryProvider provider = new BlazeSampleDataDirectoryProvider(workspaceModule);
    PathString sampleDataDirPath = WriteAction.computeAndWait(() -> provider.getOrCreateSampleDataDirectory());
    assertThat(sampleDataDirPath).isNull();
    assertThat(workspaceDir.getParent().findChild(FD_SAMPLE_DATA)).isNull();
}
Also used : FileExtensions.toPathString(com.android.tools.idea.util.FileExtensions.toPathString) PathString(com.android.ide.common.util.PathString) Test(org.junit.Test)

Example 4 with PathString

use of com.android.ide.common.util.PathString in project intellij by bazelbuild.

the class BlazeSampleDataDirectoryProviderTest method getOrCreateSampleDataDirectory_createsDirectoryParallelToResFolderIfMissing.

@Test
public void getOrCreateSampleDataDirectory_createsDirectoryParallelToResFolderIfMissing() throws IOException {
    BlazeSampleDataDirectoryProvider provider = new BlazeSampleDataDirectoryProvider(resModule);
    PathString sampleDataDirPath = WriteAction.computeAndWait(() -> provider.getOrCreateSampleDataDirectory());
    VirtualFile sampleDataDir = sampleDataDirPath != null ? toVirtualFile(sampleDataDirPath) : null;
    assertThat(sampleDataDir).isNotNull();
    assertThat(sampleDataDir.getParent()).isEqualTo(resDir.getParent());
    assertThat(sampleDataDir.exists()).isTrue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileExtensions.toVirtualFile(com.android.tools.idea.util.FileExtensions.toVirtualFile) FileExtensions.toPathString(com.android.tools.idea.util.FileExtensions.toPathString) PathString(com.android.ide.common.util.PathString) Test(org.junit.Test)

Example 5 with PathString

use of com.android.ide.common.util.PathString in project intellij by bazelbuild.

the class BlazeSampleDataDirectoryProviderTest method getSampleDataDirectory_parallelToResFolder.

@Test
public void getSampleDataDirectory_parallelToResFolder() {
    BlazeSampleDataDirectoryProvider provider = new BlazeSampleDataDirectoryProvider(resModule);
    PathString expectedPath = toPathString(resDir).getParentOrRoot().resolve(FD_SAMPLE_DATA);
    assertThat(provider.getSampleDataDirectory()).isEqualTo(expectedPath);
}
Also used : FileExtensions.toPathString(com.android.tools.idea.util.FileExtensions.toPathString) PathString(com.android.ide.common.util.PathString) Test(org.junit.Test)

Aggregations

PathString (com.android.ide.common.util.PathString)8 Test (org.junit.Test)5 FileExtensions.toPathString (com.android.tools.idea.util.FileExtensions.toPathString)4 ExternalAndroidLibrary (com.android.projectmodel.ExternalAndroidLibrary)2 ExternalLibraryImpl (com.android.projectmodel.ExternalLibraryImpl)2 SelectiveResourceFolder (com.android.projectmodel.SelectiveResourceFolder)2 FileExtensions.toVirtualFile (com.android.tools.idea.util.FileExtensions.toVirtualFile)2 UnpackedAars (com.google.idea.blaze.android.libraries.UnpackedAars)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2