Search in sources :

Example 6 with LocalProperties

use of com.android.tools.idea.gradle.util.LocalProperties in project android by JetBrains.

the class SdkSyncTest method assertProjectSdkSet.

private void assertProjectSdkSet() throws Exception {
    myLocalProperties = new LocalProperties(myProject);
    File actual = myLocalProperties.getAndroidSdkPath();
    assertNotNull(actual);
    assertEquals(myAndroidSdkPath.getPath(), actual.getPath());
}
Also used : LocalProperties(com.android.tools.idea.gradle.util.LocalProperties) File(java.io.File)

Example 7 with LocalProperties

use of com.android.tools.idea.gradle.util.LocalProperties in project android by JetBrains.

the class GuiTestRule method updateLocalProperties.

protected void updateLocalProperties(File projectPath) throws IOException {
    LocalProperties localProperties = new LocalProperties(projectPath);
    localProperties.setAndroidSdkPath(IdeSdks.getInstance().getAndroidSdkPath());
    localProperties.save();
}
Also used : LocalProperties(com.android.tools.idea.gradle.util.LocalProperties)

Example 8 with LocalProperties

use of com.android.tools.idea.gradle.util.LocalProperties in project android by JetBrains.

the class SdkUpdaterConfigPanel method getSdkLocations.

@NotNull
private static Collection<File> getSdkLocations() {
    File androidHome = IdeSdks.getInstance().getAndroidSdkPath();
    if (androidHome != null) {
        return ImmutableList.of(androidHome);
    }
    Set<File> locations = new HashSet<>();
    // Gradle project.
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        try {
            LocalProperties localProperties = new LocalProperties(project);
            File androidSdkPath = localProperties.getAndroidSdkPath();
            if (androidSdkPath != null) {
                locations.add(androidSdkPath);
                continue;
            }
        } catch (IOException ignored) {
            Logger.getInstance(SdkUpdaterConfigPanel.class).info("Unable to read local.properties file from project: " + project.getName(), ignored);
        }
        List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
        for (AndroidFacet facet : facets) {
            AndroidSdkData sdkData = facet.getConfiguration().getAndroidSdk();
            if (sdkData != null) {
                locations.add(sdkData.getLocation());
            }
        }
    }
    return locations;
}
Also used : Project(com.intellij.openapi.project.Project) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) IOException(java.io.IOException) File(java.io.File) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with LocalProperties

use of com.android.tools.idea.gradle.util.LocalProperties in project android by JetBrains.

the class IdeSdksTest method testSetAndroidSdkPathUpdatingLocalPropertiesFile.

public void testSetAndroidSdkPathUpdatingLocalPropertiesFile() throws IOException {
    LocalProperties localProperties = new LocalProperties(myProject);
    localProperties.setAndroidSdkPath("");
    localProperties.save();
    List<Sdk> sdks = ApplicationManager.getApplication().runWriteAction((Computable<List<Sdk>>) () -> myIdeSdks.setAndroidSdkPath(myAndroidSdkPath, null));
    assertOneSdkPerAvailableTarget(sdks);
    localProperties = new LocalProperties(myProject);
    File androidSdkPath = localProperties.getAndroidSdkPath();
    assertNotNull(androidSdkPath);
    assertEquals(myAndroidSdkPath.getPath(), androidSdkPath.getPath());
}
Also used : List(java.util.List) Sdk(com.intellij.openapi.projectRoots.Sdk) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties) File(java.io.File)

Example 10 with LocalProperties

use of com.android.tools.idea.gradle.util.LocalProperties in project android by JetBrains.

the class GradleProjectSyncData method needsAndroidSdkSync.

private static boolean needsAndroidSdkSync(@NotNull final Project project) {
    if (IdeInfo.getInstance().isAndroidStudio()) {
        final File ideSdkPath = IdeSdks.getInstance().getAndroidSdkPath();
        if (ideSdkPath != null) {
            try {
                LocalProperties localProperties = new LocalProperties(project);
                File projectSdkPath = localProperties.getAndroidSdkPath();
                return projectSdkPath == null || !filesEqual(ideSdkPath, projectSdkPath);
            } catch (IOException ignored) {
            }
        }
        return true;
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties)

Aggregations

LocalProperties (com.android.tools.idea.gradle.util.LocalProperties)17 File (java.io.File)8 IOException (java.io.IOException)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)2 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)2 HashSet (com.intellij.util.containers.HashSet)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)2 TestUtils.getWorkspaceFile (com.android.testutils.TestUtils.getWorkspaceFile)1 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1 IdeSdks (com.android.tools.idea.sdk.IdeSdks)1 ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 PsiFile (com.intellij.psi.PsiFile)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.junit.Test)1