Search in sources :

Example 16 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class SdkComponentSourceTest method testCurrentVersions.

public void testCurrentVersions() throws Exception {
    Set<UpdatableExternalComponent> components = Sets.newTreeSet(COMPONENT_COMPARATOR);
    components.addAll(myTestComponentSource.getCurrentVersions());
    Iterator<UpdatableExternalComponent> componentIter = components.iterator();
    UpdatableExternalComponent c = componentIter.next();
    assertEquals("package hasPreview", c.getName());
    assertEquals(new Revision(1, 0, 0), ((RepoPackage) c.getKey()).getVersion());
    c = componentIter.next();
    assertEquals("package newerPreview", c.getName());
    assertEquals(new Revision(1, 0, 0, 1), ((RepoPackage) c.getKey()).getVersion());
    c = componentIter.next();
    assertEquals("package newerRemote", c.getName());
    assertEquals(new Revision(1, 0, 0), ((RepoPackage) c.getKey()).getVersion());
    c = componentIter.next();
    assertEquals("package noRemote", c.getName());
    assertEquals(new Revision(1, 0, 0), ((RepoPackage) c.getKey()).getVersion());
    c = componentIter.next();
    assertEquals("package olderPreview", c.getName());
    assertEquals(new Revision(2, 0, 0), ((RepoPackage) c.getKey()).getVersion());
    c = componentIter.next();
    assertEquals("package olderRemote", c.getName());
    assertEquals(new Revision(1, 2, 0), ((RepoPackage) c.getKey()).getVersion());
    c = componentIter.next();
    assertEquals("package samePreview", c.getName());
    assertEquals(new Revision(1, 0, 0, 1), ((RepoPackage) c.getKey()).getVersion());
    c = componentIter.next();
    assertEquals("package sameRemote", c.getName());
    assertEquals(new Revision(1, 0, 0), ((RepoPackage) c.getKey()).getVersion());
    c = componentIter.next();
    assertEquals("package zNewerInBeta", c.getName());
    assertEquals(new Revision(1, 0, 0), ((RepoPackage) c.getKey()).getVersion());
    assertFalse(componentIter.hasNext());
}
Also used : Revision(com.android.repository.Revision) UpdatableExternalComponent(com.intellij.ide.externalComponents.UpdatableExternalComponent)

Example 17 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class NlPreviewTest method testRenderingDynamicResources.

@Test
public void testRenderingDynamicResources() throws Exception {
    // Opens a layout which contains dynamic resources (defined only in build.gradle)
    // and checks that the values have been resolved correctly (both that there are no
    // unresolved reference errors in the XML file, and that the rendered layout strings
    // matches the expected overlay semantics); also edits these in the Gradle file and
    // checks that the layout rendering is updated after a Gradle sync.
    guiTest.importProjectAndWaitForProjectSyncToFinish("LayoutTest");
    AndroidModuleModel androidModel = guiTest.ideFrame().getAndroidModel("app");
    String modelVersion = androidModel.getAndroidProject().getModelVersion();
    Revision version = Revision.parseRevision(modelVersion);
    assumeTrue("This test tests behavior that starts working in 0.14.+", version.getMajor() != 0 || version.getMinor() >= 14);
    EditorFixture editor = guiTest.ideFrame().getEditor();
    String layoutFilePath = "app/src/main/res/layout/dynamic_layout.xml";
    editor.open(layoutFilePath, EditorFixture.Tab.EDITOR);
    NlPreviewFixture preview = editor.getLayoutPreview(true);
    preview.waitForRenderToFinish();
    assertFalse(preview.hasRenderErrors());
    NlComponentFixture string1 = preview.findView("TextView", 0);
    string1.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string1");
    string1.requireViewClass("android.support.v7.widget.AppCompatTextView");
    string1.requireActualText("String 1 defined only by defaultConfig");
    NlComponentFixture string2 = preview.findView("TextView", 1);
    string2.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string2");
    string2.requireActualText("String 1 defined only by defaultConfig");
    NlComponentFixture string3 = preview.findView("TextView", 2);
    string3.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string3");
    string3.requireActualText("String 3 defined by build type debug");
    NlComponentFixture string4 = preview.findView("TextView", 3);
    string4.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string4");
    string4.requireActualText("String 4 defined by flavor free");
    NlComponentFixture string5 = preview.findView("TextView", 4);
    string5.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string5");
    string5.requireActualText("String 5 defined by build type debug");
    // Ensure that all the references are properly resolved
    FileFixture file = guiTest.ideFrame().findExistingFileByRelativePath(layoutFilePath);
    file.waitForCodeAnalysisHighlightCount(ERROR, 0);
    editor.open("app/build.gradle", EditorFixture.Tab.EDITOR).moveBetween("String 1 defined only by ", "defaultConfig").enterText("edited ").awaitNotification("Gradle files have changed since last project sync. A project sync may be necessary for the IDE to work properly.").performAction("Sync Now").waitForGradleProjectSyncToFinish();
    editor.open(layoutFilePath, EditorFixture.Tab.EDITOR);
    preview.waitForRenderToFinish();
    string1 = preview.findView("TextView", 0);
    string1.requireActualText("String 1 defined only by edited defaultConfig");
    file.waitForCodeAnalysisHighlightCount(ERROR, 0);
}
Also used : EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) Revision(com.android.repository.Revision) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) FileFixture(com.android.tools.idea.tests.gui.framework.fixture.FileFixture) Test(org.junit.Test)

Example 18 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class ConfigureAndroidProjectPath method putSdkDependentParams.

/**
   * Populate the given state with a set of variables that depend on the user's installed SDK. This method should
   * be called early in the initialization of a wizard or path.
   * Variables:
   * Build Tools Version: Used to populate the project level build.gradle with the correct Gradle plugin version number
   * If the required build tools version is not installed, a request is added for installation
   * SDK Home: The location of the installed SDK
   *
   * @param state the state store to populate with the values stored in the SDK
   */
public static void putSdkDependentParams(@NotNull ScopedStateStore state) {
    final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(ConfigureAndroidProjectPath.class);
    BuildToolInfo buildTool = sdkHandler.getLatestBuildTool(progress, false);
    Revision minimumRequiredBuildToolVersion = Revision.parseRevision(SdkConstants.MIN_BUILD_TOOLS_VERSION);
    if (buildTool != null && buildTool.getRevision().compareTo(minimumRequiredBuildToolVersion) >= 0) {
        state.put(WizardConstants.BUILD_TOOLS_VERSION_KEY, buildTool.getRevision().toString());
    } else {
        // We need to install a new build tools version
        state.listPush(WizardConstants.INSTALL_REQUESTS_KEY, DetailsTypes.getBuildToolsPath(minimumRequiredBuildToolVersion));
        state.put(WizardConstants.BUILD_TOOLS_VERSION_KEY, minimumRequiredBuildToolVersion.toString());
    }
    File location = sdkHandler.getLocation();
    if (location != null) {
        // Gradle expects a platform-neutral path
        state.put(WizardConstants.SDK_DIR_KEY, FileUtil.toSystemIndependentName(location.getPath()));
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Revision(com.android.repository.Revision) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) File(java.io.File)

Example 19 with Revision

use of com.android.repository.Revision in project bazel by bazelbuild.

the class AndroidSdkRepositoryFunction method getNewestBuildToolsDirectory.

/**
   * Gets the newest build tools directory according to {@link Revision}.
   *
   * @throws RepositoryFunctionException if none of the buildToolsDirectories are directories and
   *     have names that are parsable as build tools version.
   */
private static String getNewestBuildToolsDirectory(Rule rule, Dirents buildToolsDirectories) throws RepositoryFunctionException {
    String newestBuildToolsDirectory = null;
    Revision newestBuildToolsRevision = null;
    for (Dirent buildToolsDirectory : buildToolsDirectories) {
        if (buildToolsDirectory.getType() != Dirent.Type.DIRECTORY) {
            continue;
        }
        try {
            Revision buildToolsRevision = Revision.parseRevision(buildToolsDirectory.getName());
            if (newestBuildToolsRevision == null || buildToolsRevision.compareTo(newestBuildToolsRevision) > 0) {
                newestBuildToolsDirectory = buildToolsDirectory.getName();
                newestBuildToolsRevision = buildToolsRevision;
            }
        } catch (NumberFormatException e) {
        // Ignore unparsable build tools directories.
        }
    }
    if (newestBuildToolsDirectory == null) {
        throw new RepositoryFunctionException(new EvalException(rule.getLocation(), String.format("Bazel requires Android build tools version %s or newer but none are installed. " + "Please install a recent version through the Android SDK manager.", MIN_BUILD_TOOLS_REVISION)), Transience.PERSISTENT);
    }
    return newestBuildToolsDirectory;
}
Also used : Revision(com.android.repository.Revision) Dirent(com.google.devtools.build.lib.vfs.Dirent) EvalException(com.google.devtools.build.lib.syntax.EvalException)

Example 20 with Revision

use of com.android.repository.Revision in project bazel by bazelbuild.

the class AndroidSdk method create.

@Override
public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
    // If the user didn't specify --proguard_top, go with the proguard attribute in the android_sdk
    // rule. Otherwise, use what she told us to.
    FilesToRunProvider proguard = ruleContext.getFragment(JavaConfiguration.class).getProguardBinary() == null ? ruleContext.getExecutablePrerequisite("proguard", Mode.HOST) : ruleContext.getExecutablePrerequisite(":proguard", Mode.HOST);
    String buildToolsVersion = AggregatingAttributeMapper.of(ruleContext.getRule()).get("build_tools_version", Type.STRING);
    Revision parsedBuildToolsVersion = null;
    try {
        parsedBuildToolsVersion = Strings.isNullOrEmpty(buildToolsVersion) ? null : Revision.parseRevision(buildToolsVersion);
    } catch (NumberFormatException nfe) {
        ruleContext.attributeError("build_tools_version", "Invalid version: " + buildToolsVersion);
    }
    boolean aaptSupportsMainDexGeneration = parsedBuildToolsVersion == null || parsedBuildToolsVersion.compareTo(new Revision(24)) >= 0;
    FilesToRunProvider aidl = ruleContext.getExecutablePrerequisite("aidl", Mode.HOST);
    FilesToRunProvider aapt = ruleContext.getExecutablePrerequisite("aapt", Mode.HOST);
    FilesToRunProvider apkBuilder = ruleContext.getExecutablePrerequisite("apkbuilder", Mode.HOST);
    FilesToRunProvider apkSigner = ruleContext.getExecutablePrerequisite("apksigner", Mode.HOST);
    FilesToRunProvider adb = ruleContext.getExecutablePrerequisite("adb", Mode.HOST);
    FilesToRunProvider dx = ruleContext.getExecutablePrerequisite("dx", Mode.HOST);
    FilesToRunProvider mainDexListCreator = ruleContext.getExecutablePrerequisite("main_dex_list_creator", Mode.HOST);
    FilesToRunProvider zipalign = ruleContext.getExecutablePrerequisite("zipalign", Mode.HOST);
    FilesToRunProvider jack = ruleContext.getExecutablePrerequisite("jack", Mode.HOST);
    FilesToRunProvider jill = ruleContext.getExecutablePrerequisite("jill", Mode.HOST);
    FilesToRunProvider resourceExtractor = ruleContext.getExecutablePrerequisite("resource_extractor", Mode.HOST);
    Artifact frameworkAidl = ruleContext.getPrerequisiteArtifact("framework_aidl", Mode.HOST);
    TransitiveInfoCollection aidlLib = ruleContext.getPrerequisite("aidl_lib", Mode.TARGET);
    Artifact androidJar = ruleContext.getPrerequisiteArtifact("android_jar", Mode.HOST);
    Artifact shrinkedAndroidJar = ruleContext.getPrerequisiteArtifact("shrinked_android_jar", Mode.HOST);
    // Because all Jack actions using this android_sdk will need Jack versions of the Android and
    // Java classpaths, pre-translate the jars for Android and Java targets here. (They will only
    // be run if needed, as usual for Bazel.)
    NestedSet<Artifact> androidBaseClasspathForJack = convertClasspathJarsToJack(ruleContext, jack, jill, resourceExtractor, ImmutableList.of(androidJar));
    NestedSet<Artifact> javaBaseClasspathForJack = convertClasspathJarsToJack(ruleContext, jack, jill, resourceExtractor, JavaCompilationHelper.getBootClasspath(JavaToolchainProvider.fromRuleContext(ruleContext)));
    Artifact annotationsJar = ruleContext.getPrerequisiteArtifact("annotations_jar", Mode.HOST);
    Artifact mainDexClasses = ruleContext.getPrerequisiteArtifact("main_dex_classes", Mode.HOST);
    if (ruleContext.hasErrors()) {
        return null;
    }
    return new RuleConfiguredTargetBuilder(ruleContext).add(AndroidSdkProvider.class, AndroidSdkProvider.create(buildToolsVersion, aaptSupportsMainDexGeneration, frameworkAidl, aidlLib, androidJar, shrinkedAndroidJar, androidBaseClasspathForJack, javaBaseClasspathForJack, annotationsJar, mainDexClasses, adb, dx, mainDexListCreator, aidl, aapt, apkBuilder, apkSigner, proguard, zipalign, jack, jill, resourceExtractor)).add(RunfilesProvider.class, RunfilesProvider.EMPTY).setFilesToBuild(NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER)).build();
}
Also used : FilesToRunProvider(com.google.devtools.build.lib.analysis.FilesToRunProvider) Revision(com.android.repository.Revision) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) JavaConfiguration(com.google.devtools.build.lib.rules.java.JavaConfiguration) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

Revision (com.android.repository.Revision)37 Test (org.junit.Test)11 FakeRemotePackage (com.android.repository.testframework.FakePackage.FakeRemotePackage)10 FakeLocalPackage (com.android.repository.testframework.FakePackage.FakeLocalPackage)9 File (java.io.File)8 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)6 UpdatableExternalComponent (com.intellij.ide.externalComponents.UpdatableExternalComponent)6 Nullable (org.jetbrains.annotations.Nullable)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 LocalPackage (com.android.repository.api.LocalPackage)4 BuildToolInfo (com.android.sdklib.BuildToolInfo)4 StudioProgressIndicatorAdapter (com.android.tools.idea.sdk.progress.StudioProgressIndicatorAdapter)4 NotNull (org.jetbrains.annotations.NotNull)4 Installer (com.android.repository.api.Installer)3 FakeDownloader (com.android.repository.testframework.FakeDownloader)3 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)3 ExternalUpdate (com.intellij.openapi.updateSettings.impl.ExternalUpdate)3 UpdateSettings (com.intellij.openapi.updateSettings.impl.UpdateSettings)3 VisibleForTesting (com.android.annotations.VisibleForTesting)2 GradleVersion (com.android.ide.common.repository.GradleVersion)2