mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
IDEA-252775 [merge-android-41] fix gradle-dsl content roots and compilation (after gradle-dsl move android>intellij)
GitOrigin-RevId: 8599e0bfd9fe61bb5b2e118d2b00281a5c8f21b0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
25b5236381
commit
3fee79a367
@@ -2,12 +2,12 @@
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/test">
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
</content>
|
||||
<content url="file://$MODULE_DIR$/testData">
|
||||
<sourceFolder url="file://$MODULE_DIR$/testData" type="java-test-resource" />
|
||||
</content>
|
||||
<content url="file://$MODULE_DIR$/testSrc">
|
||||
<sourceFolder url="file://$MODULE_DIR$/testSrc" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.gradle" scope="TEST" />
|
||||
|
||||
@@ -42,16 +42,7 @@ public final class GradleModelSource extends GradleModelProvider {
|
||||
private static final BuildModelContext.ResolvedConfigurationFileLocationProvider myResolvedConfigurationFileLocationProvider;
|
||||
|
||||
static {
|
||||
// FIXME-ank4: get rid of reflection (i.e. merge `api` and `impl` modules?)
|
||||
BuildModelContext.ResolvedConfigurationFileLocationProvider inst = null;
|
||||
try {
|
||||
inst = (BuildModelContext.ResolvedConfigurationFileLocationProvider)Class
|
||||
.forName("com.android.tools.idea.projectsystem.gradle.ResolvedConfigurationFileLocationProviderImpl").newInstance();
|
||||
}
|
||||
catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
|
||||
Logger.getInstance(GradleModelSource.class).error(e);
|
||||
}
|
||||
myResolvedConfigurationFileLocationProvider = inst;
|
||||
myResolvedConfigurationFileLocationProvider = new ResolvedConfigurationFileLocationProviderImpl();
|
||||
}
|
||||
|
||||
public static class GradleModelProviderFactoryImpl implements GradleModelProviderFactory {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.android.tools.idea.gradle.dsl;
|
||||
|
||||
import com.android.tools.idea.gradle.dsl.model.BuildModelContext;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.SystemIndependent;
|
||||
|
||||
class ResolvedConfigurationFileLocationProviderImpl
|
||||
implements BuildModelContext.ResolvedConfigurationFileLocationProvider {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public VirtualFile getGradleBuildFile(@NotNull Module module) {
|
||||
return GradleUtil.getGradleBuildFile(module);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public @SystemIndependent String getGradleProjectRootPath(@NotNull Module module) {
|
||||
return GradleUtil.getModuleDirPath(module);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public @SystemIndependent String getGradleProjectRootPath(@NotNull Project project) {
|
||||
VirtualFile projectDir = ProjectUtil.guessProjectDir(project);
|
||||
if (projectDir == null) return null;
|
||||
return projectDir.getPath();
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,12 @@
|
||||
*/
|
||||
package com.android.tools.idea.gradle.dsl;
|
||||
|
||||
import com.android.testutils.JarTestSuiteRunner;
|
||||
import com.android.tools.tests.IdeaTestSuiteBase;
|
||||
//import com.android.testutils.JarTestSuiteRunner;
|
||||
//import com.android.tools.tests.IdeaTestSuiteBase;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(JarTestSuiteRunner.class)
|
||||
@JarTestSuiteRunner.ExcludeClasses(GradleDslTestSuite.class) // a suite mustn't contain itself
|
||||
public class GradleDslTestSuite extends IdeaTestSuiteBase {
|
||||
//@RunWith(JarTestSuiteRunner.class)
|
||||
//@JarTestSuiteRunner.ExcludeClasses(GradleDslTestSuite.class) // a suite mustn't contain itself
|
||||
// FIXME-ank4: commented out, because these classes (JarTestSuiteRunner,JarTestSuiteRunner) are from android plugin
|
||||
public class GradleDslTestSuite /* extends IdeaTestSuiteBase */ {
|
||||
}
|
||||
|
||||
@@ -15,12 +15,7 @@
|
||||
*/
|
||||
package com.android.tools.idea.gradle.dsl.model;
|
||||
|
||||
import static com.android.SdkConstants.FN_BUILD_GRADLE;
|
||||
import static com.android.SdkConstants.FN_BUILD_GRADLE_KTS;
|
||||
import static com.android.SdkConstants.FN_GRADLE_PROPERTIES;
|
||||
import static com.android.SdkConstants.FN_SETTINGS_GRADLE;
|
||||
import static com.android.SdkConstants.FN_SETTINGS_GRADLE_KTS;
|
||||
import static com.android.tools.idea.Projects.getBaseDirPath;
|
||||
import static com.android.tools.idea.gradle.dsl.GradleUtil.getBaseDirPath;
|
||||
import static com.android.tools.idea.gradle.dsl.api.ext.GradlePropertyModel.BOOLEAN_TYPE;
|
||||
import static com.android.tools.idea.gradle.dsl.api.ext.GradlePropertyModel.INTEGER_TYPE;
|
||||
import static com.android.tools.idea.gradle.dsl.api.ext.GradlePropertyModel.LIST_TYPE;
|
||||
@@ -36,6 +31,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.runners.Parameterized.Parameter;
|
||||
import static org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import com.android.tools.idea.gradle.dsl.TestFileName;
|
||||
import com.android.tools.idea.gradle.dsl.api.GradleBuildModel;
|
||||
import com.android.tools.idea.gradle.dsl.api.GradleSettingsModel;
|
||||
@@ -46,6 +42,7 @@ import com.android.tools.idea.gradle.dsl.api.ext.GradlePropertyModel;
|
||||
import com.android.tools.idea.gradle.dsl.api.ext.PasswordPropertyModel;
|
||||
import com.android.tools.idea.gradle.dsl.api.ext.PropertyType;
|
||||
import com.android.tools.idea.gradle.dsl.api.util.TypeReference;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.intellij.ide.highlighter.ModuleFileType;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -60,6 +57,8 @@ import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.StdModuleTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectUtil;
|
||||
import com.intellij.openapi.util.ThrowableComputable;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
@@ -83,7 +82,6 @@ import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.SystemIndependent;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package com.android.tools.idea.gradle.dsl.model;
|
||||
|
||||
import static com.android.tools.idea.Projects.getBaseDirPath;
|
||||
import static com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction;
|
||||
|
||||
import com.android.tools.idea.gradle.dsl.GradleUtil;
|
||||
import com.android.tools.idea.gradle.dsl.TestFileName;
|
||||
import com.android.tools.idea.gradle.dsl.api.GradleBuildModel;
|
||||
import com.android.tools.idea.gradle.dsl.api.GradleSettingsModel;
|
||||
@@ -25,7 +25,6 @@ import com.android.tools.idea.gradle.dsl.api.ProjectBuildModel;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import java.io.File;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.SystemDependent;
|
||||
import org.junit.Test;
|
||||
@@ -312,9 +311,6 @@ public class GradleSettingsModelTest extends GradleFileModelTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExistingVariable() throws Exception {
|
||||
writeToSettingsFile(TestFile.EXISTING_VARIABLE);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.android.tools.idea.gradle.dsl.model.build;
|
||||
|
||||
import static com.android.tools.idea.Projects.getBaseDirPath;
|
||||
import static com.android.tools.idea.gradle.dsl.TestFileNameImpl.REFERENCE_RESOLUTION_RESOLVE_OTHER_PROJECT_PATH;
|
||||
import static com.android.tools.idea.gradle.dsl.TestFileNameImpl.REFERENCE_RESOLUTION_RESOLVE_OTHER_PROJECT_PATH_SUB;
|
||||
import static com.android.tools.idea.gradle.dsl.TestFileNameImpl.REFERENCE_RESOLUTION_RESOLVE_PARENT;
|
||||
|
||||
@@ -31,6 +31,8 @@ import com.android.tools.idea.gradle.dsl.model.GradleFileModelTestCase;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import org.junit.Test;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.tools.idea.gradle.dsl.model.dependencies;
|
||||
|
||||
public class ExpectedModuleDependency {
|
||||
public String configurationName;
|
||||
public String path;
|
||||
public String configuration;
|
||||
|
||||
public void reset() {
|
||||
configurationName = path = configuration = null;
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,6 @@ import static com.android.tools.idea.gradle.dsl.model.repositories.MavenCentralR
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import com.android.ide.common.repository.GradleVersion;
|
||||
import com.android.tools.idea.gradle.dsl.TestFileName;
|
||||
import com.android.tools.idea.gradle.dsl.api.GradleBuildModel;
|
||||
import com.android.tools.idea.gradle.dsl.api.ext.GradlePropertyModel;
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.tools.idea.gradle.dsl.model.util;
|
||||
|
||||
import static com.android.tools.idea.gradle.dsl.TestFileNameImpl.GOOGLE_MAVEN_REPOSITORY_ADD_GOOGLE_REPOSITORY_EMPTY3DOT5;
|
||||
import static com.android.tools.idea.gradle.dsl.TestFileNameImpl.GOOGLE_MAVEN_REPOSITORY_ADD_GOOGLE_REPOSITORY_EMPTY4DOT0;
|
||||
import static com.android.tools.idea.gradle.dsl.TestFileNameImpl.GOOGLE_MAVEN_REPOSITORY_ADD_GOOGLE_REPOSITORY_WITH_GOOGLE_ALREADY3DOT5;
|
||||
import static com.android.tools.idea.gradle.dsl.TestFileNameImpl.GOOGLE_MAVEN_REPOSITORY_ADD_GOOGLE_REPOSITORY_WITH_GOOGLE_ALREADY4DOT0;
|
||||
import static com.android.tools.idea.gradle.dsl.TestFileNameImpl.GOOGLE_MAVEN_REPOSITORY_HAS_GOOGLE_MAVEN_REPOSITORY_EMPTY;
|
||||
import static com.android.tools.idea.gradle.dsl.TestFileNameImpl.GOOGLE_MAVEN_REPOSITORY_HAS_GOOGLE_MAVEN_REPOSITORY_NAME3DOT5;
|
||||
import static com.android.tools.idea.gradle.dsl.TestFileNameImpl.GOOGLE_MAVEN_REPOSITORY_HAS_GOOGLE_MAVEN_REPOSITORY_NAME4DOT0;
|
||||
import static com.android.tools.idea.gradle.dsl.TestFileNameImpl.GOOGLE_MAVEN_REPOSITORY_HAS_GOOGLE_MAVEN_REPOSITORY_URL3DOT5;
|
||||
import static com.android.tools.idea.gradle.dsl.TestFileNameImpl.GOOGLE_MAVEN_REPOSITORY_HAS_GOOGLE_MAVEN_REPOSITORY_URL4DOT0;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction;
|
||||
|
||||
import com.android.ide.common.repository.GradleVersion;
|
||||
import com.android.tools.idea.gradle.dsl.api.GradleBuildModel;
|
||||
import com.android.tools.idea.gradle.dsl.api.repositories.RepositoriesModel;
|
||||
import com.android.tools.idea.gradle.dsl.api.repositories.RepositoriesModelExtensionKt;
|
||||
import com.android.tools.idea.gradle.dsl.api.repositories.RepositoryModel;
|
||||
import com.android.tools.idea.gradle.dsl.model.GradleFileModelTestCase;
|
||||
import com.android.tools.idea.gradle.dsl.model.repositories.GoogleDefaultRepositoryModelImpl;
|
||||
import com.android.tools.idea.gradle.dsl.model.repositories.MavenRepositoryModelImpl;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for {@link GoogleMavenRepository}.
|
||||
*/
|
||||
public class GoogleMavenRepositoryTest extends GradleFileModelTestCase {
|
||||
|
||||
@Test
|
||||
public void testHasGoogleMavenRepositoryEmpty() throws IOException {
|
||||
writeToBuildFile(GOOGLE_MAVEN_REPOSITORY_HAS_GOOGLE_MAVEN_REPOSITORY_EMPTY);
|
||||
assertFalse(getGradleBuildModel().repositories().hasGoogleMavenRepository());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasGoogleMavenRepositoryName3dot5() throws IOException {
|
||||
writeToBuildFile(GOOGLE_MAVEN_REPOSITORY_HAS_GOOGLE_MAVEN_REPOSITORY_NAME3DOT5);
|
||||
assertTrue(getGradleBuildModel().repositories().hasGoogleMavenRepository());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasGoogleMavenRepositoryName4dot0() throws IOException {
|
||||
writeToBuildFile(GOOGLE_MAVEN_REPOSITORY_HAS_GOOGLE_MAVEN_REPOSITORY_NAME4DOT0);
|
||||
assertTrue(getGradleBuildModel().repositories().hasGoogleMavenRepository());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasGoogleMavenRepositoryUrl3dot5() throws IOException {
|
||||
writeToBuildFile(GOOGLE_MAVEN_REPOSITORY_HAS_GOOGLE_MAVEN_REPOSITORY_URL3DOT5);
|
||||
assertTrue(getGradleBuildModel().repositories().hasGoogleMavenRepository());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasGoogleMavenRepositoryUrl4dot0() throws IOException {
|
||||
writeToBuildFile(GOOGLE_MAVEN_REPOSITORY_HAS_GOOGLE_MAVEN_REPOSITORY_URL4DOT0);
|
||||
assertTrue(getGradleBuildModel().repositories().hasGoogleMavenRepository());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddGoogleRepositoryEmpty3dot5() throws IOException {
|
||||
// Prepare repositories
|
||||
writeToBuildFile(GOOGLE_MAVEN_REPOSITORY_ADD_GOOGLE_REPOSITORY_EMPTY3DOT5);
|
||||
GradleBuildModel buildModel = getGradleBuildModel();
|
||||
RepositoriesModel repositoriesModel = buildModel.repositories();
|
||||
assertThat(repositoriesModel.repositories()).isEmpty();
|
||||
|
||||
// add repository
|
||||
RepositoriesModelExtensionKt.addGoogleMavenRepository(GradleVersion.parse("3.5"));
|
||||
assertTrue(buildModel.isModified());
|
||||
runWriteCommandAction(getProject(), buildModel::applyChanges);
|
||||
|
||||
// Verify
|
||||
buildModel = getGradleBuildModel();
|
||||
repositoriesModel = buildModel.repositories();
|
||||
List<RepositoryModel> repositories = repositoriesModel.repositories();
|
||||
assertThat(repositories).hasSize(1);
|
||||
assertThat(repositories.get(0)).isInstanceOf(MavenRepositoryModelImpl.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddGoogleRepositoryEmpty4dot0() throws IOException {
|
||||
// Prepare repositories
|
||||
writeToBuildFile(GOOGLE_MAVEN_REPOSITORY_ADD_GOOGLE_REPOSITORY_EMPTY4DOT0);
|
||||
GradleBuildModel buildModel = getGradleBuildModel();
|
||||
RepositoriesModel repositoriesModel = buildModel.repositories();
|
||||
assertThat(repositoriesModel.repositories()).isEmpty();
|
||||
|
||||
// add repository
|
||||
RepositoriesModelExtensionKt.addGoogleMavenRepository(GradleVersion.parse("4.0"));
|
||||
assertTrue(buildModel.isModified());
|
||||
runWriteCommandAction(getProject(), buildModel::applyChanges);
|
||||
|
||||
// Verify
|
||||
buildModel = getGradleBuildModel();
|
||||
repositoriesModel = buildModel.repositories();
|
||||
List<RepositoryModel> repositories = repositoriesModel.repositories();
|
||||
assertThat(repositories).hasSize(1);
|
||||
assertThat(repositories.get(0)).isInstanceOf(GoogleDefaultRepositoryModelImpl.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddGoogleRepositoryWithGoogleAlready3dot5() throws IOException {
|
||||
// Prepare repositories
|
||||
writeToBuildFile(GOOGLE_MAVEN_REPOSITORY_ADD_GOOGLE_REPOSITORY_WITH_GOOGLE_ALREADY3DOT5);
|
||||
GradleBuildModel buildModel = getGradleBuildModel();
|
||||
RepositoriesModel repositoriesModel = buildModel.repositories();
|
||||
assertThat(repositoriesModel.repositories()).hasSize(1);
|
||||
|
||||
// add repository
|
||||
RepositoriesModelExtensionKt.addGoogleMavenRepository(GradleVersion.parse("3.5"));
|
||||
assertTrue(buildModel.isModified());
|
||||
runWriteCommandAction(getProject(), buildModel::applyChanges);
|
||||
|
||||
// Verify
|
||||
buildModel = getGradleBuildModel();
|
||||
repositoriesModel = buildModel.repositories();
|
||||
List<RepositoryModel> repositories = repositoriesModel.repositories();
|
||||
assertThat(repositories).hasSize(2);
|
||||
assertThat(repositories.get(0)).isInstanceOf(GoogleDefaultRepositoryModelImpl.class);
|
||||
assertThat(repositories.get(1)).isInstanceOf(MavenRepositoryModelImpl.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddGoogleRepositoryWithGoogleAlready4dot0() throws IOException {
|
||||
// Prepare repositories
|
||||
writeToBuildFile(GOOGLE_MAVEN_REPOSITORY_ADD_GOOGLE_REPOSITORY_WITH_GOOGLE_ALREADY4DOT0);
|
||||
GradleBuildModel buildModel = getGradleBuildModel();
|
||||
RepositoriesModel repositoriesModel = buildModel.repositories();
|
||||
assertThat(repositoriesModel.repositories()).hasSize(1);
|
||||
|
||||
// add repository
|
||||
RepositoriesModelExtensionKt.addGoogleMavenRepository(GradleVersion.parse("4.0"));
|
||||
|
||||
// Verify
|
||||
assertFalse(buildModel.isModified());
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.tools.idea.gradle.dsl.parser
|
||||
|
||||
import com.android.tools.idea.gradle.dsl.parser.elements.GradleNameElement
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
|
||||
class GradleNameElementTest : UsefulTestCase() {
|
||||
// These tests check that we have correctly implemented the isomorphism between a list of unescaped strings and a single string with
|
||||
// a delimiter to separate suitably-escaped parts.
|
||||
fun testSplitNoDots() {
|
||||
assertThat(GradleNameElement.split("abcde")).isEqualTo(listOf("abcde"))
|
||||
}
|
||||
|
||||
fun testSplitDot() {
|
||||
assertThat(GradleNameElement.split("ab.de")).isEqualTo(listOf("ab", "de"))
|
||||
}
|
||||
|
||||
fun testSplitMultipleDots() {
|
||||
assertThat(GradleNameElement.split("ab.de.gh")).isEqualTo(listOf("ab", "de", "gh"))
|
||||
}
|
||||
|
||||
fun testSplitMultipleConsecutiveDots() {
|
||||
assertThat(GradleNameElement.split("ab..ef")).isEqualTo(listOf("ab", "", "ef"))
|
||||
}
|
||||
|
||||
fun testSplitDotAtBeginning() {
|
||||
assertThat(GradleNameElement.split(".bcdef")).isEqualTo(listOf("", "bcdef"))
|
||||
}
|
||||
|
||||
fun testSplitDotAtEnd() {
|
||||
assertThat(GradleNameElement.split("abcde.")).isEqualTo(listOf("abcde", ""))
|
||||
}
|
||||
|
||||
fun testSplitEscapedDot() {
|
||||
assertThat(GradleNameElement.split("""ab\.de""")).isEqualTo(listOf("ab.de"))
|
||||
}
|
||||
|
||||
fun testSplitEscapedBackslash() {
|
||||
assertThat(GradleNameElement.split("""ab\\de""")).isEqualTo(listOf("""ab\de"""))
|
||||
}
|
||||
|
||||
fun testSplitExoticCharacters() {
|
||||
assertThat(GradleNameElement.split("ab \t \n é Å £ € \u1234")).isEqualTo(listOf("ab \t \n é Å £ € \u1234"))
|
||||
}
|
||||
|
||||
fun testJoinNoDots() {
|
||||
assertThat(GradleNameElement.join(listOf("abcde"))).isEqualTo("abcde")
|
||||
}
|
||||
|
||||
fun testJoinDot() {
|
||||
assertThat(GradleNameElement.join(listOf("ab", "de"))).isEqualTo("ab.de")
|
||||
}
|
||||
|
||||
fun testJoinMultipleDots() {
|
||||
assertThat(GradleNameElement.join(listOf("ab", "de", "gh"))).isEqualTo("ab.de.gh")
|
||||
}
|
||||
|
||||
fun testJoinMultipleConsecutiveDots() {
|
||||
assertThat(GradleNameElement.join(listOf("ab", "", "ef"))).isEqualTo("ab..ef")
|
||||
}
|
||||
|
||||
fun testJoinDotAtBeginning() {
|
||||
assertThat(GradleNameElement.join(listOf("", "bcdef"))).isEqualTo(".bcdef")
|
||||
}
|
||||
|
||||
fun testJoinDotAtEnd() {
|
||||
assertThat(GradleNameElement.join(listOf("abcde", ""))).isEqualTo("abcde.")
|
||||
}
|
||||
|
||||
fun testJoinEscapedDot() {
|
||||
assertThat(GradleNameElement.join(listOf("ab.de"))).isEqualTo("""ab\.de""")
|
||||
}
|
||||
|
||||
fun testJoinEscapedBackslash() {
|
||||
assertThat(GradleNameElement.join(listOf("""ab\de"""))).isEqualTo("""ab\\de""")
|
||||
}
|
||||
|
||||
fun testJoinExoticCharacters() {
|
||||
assertThat(GradleNameElement.join(listOf("ab \t \n é Å £ € \u1234"))).isEqualTo("ab \t \n é Å £ € \u1234")
|
||||
}
|
||||
|
||||
// These tests check that we have implemented the lower-level escaping and unescaping operations correctly, which are occasionally
|
||||
// needed by backends.
|
||||
fun testEscapeNoDot() {
|
||||
assertThat(GradleNameElement.escape("abcde")).isEqualTo("abcde")
|
||||
}
|
||||
|
||||
fun testEscapeDot() {
|
||||
assertThat(GradleNameElement.escape("ab.de")).isEqualTo("""ab\.de""")
|
||||
}
|
||||
|
||||
fun testEscapeMultipleDots() {
|
||||
assertThat(GradleNameElement.escape("ab.de.gh")).isEqualTo("""ab\.de\.gh""")
|
||||
}
|
||||
|
||||
fun testEscapeMultipleConsecutiveDots() {
|
||||
assertThat(GradleNameElement.escape("ab..ef")).isEqualTo("""ab\.\.ef""")
|
||||
}
|
||||
|
||||
fun testEscapeDotAtBeginning() {
|
||||
assertThat(GradleNameElement.escape(".bcdef")).isEqualTo("""\.bcdef""")
|
||||
}
|
||||
|
||||
fun testEscapeDotAtEnd() {
|
||||
assertThat(GradleNameElement.escape("abcde.")).isEqualTo("""abcde\.""")
|
||||
}
|
||||
|
||||
fun testEscapeEscapedDot() {
|
||||
assertThat(GradleNameElement.escape("""ab\.de""")).isEqualTo("""ab\\\.de""")
|
||||
}
|
||||
|
||||
fun testEscapeEscapedBackslash() {
|
||||
assertThat(GradleNameElement.escape("""ab\\de""")).isEqualTo("""ab\\\\de""")
|
||||
}
|
||||
|
||||
fun testUnescapeNoDot() {
|
||||
assertThat(GradleNameElement.unescape("abcde")).isEqualTo("abcde")
|
||||
}
|
||||
|
||||
fun testUnescapeDot() {
|
||||
assertThat(GradleNameElement.unescape("""ab\.de""")).isEqualTo("ab.de")
|
||||
}
|
||||
|
||||
fun testUnescapeMultipleDots() {
|
||||
assertThat(GradleNameElement.unescape("""ab\.de\.gh""")).isEqualTo("ab.de.gh")
|
||||
}
|
||||
|
||||
fun testUnescapeMultipleConsecutiveDots() {
|
||||
assertThat(GradleNameElement.unescape("""ab\.\.ef""")).isEqualTo("ab..ef")
|
||||
}
|
||||
|
||||
fun testUnescapeDotAtBeginning() {
|
||||
assertThat(GradleNameElement.unescape("""\.bcdef""")).isEqualTo(".bcdef")
|
||||
}
|
||||
|
||||
fun testUnescapeDotAtEnd() {
|
||||
assertThat(GradleNameElement.unescape("""abcde\.""")).isEqualTo("abcde.")
|
||||
}
|
||||
|
||||
fun testUnescapeEscapedEscapedDot() {
|
||||
assertThat(GradleNameElement.unescape("""ab\\\.de""")).isEqualTo("""ab\.de""")
|
||||
}
|
||||
|
||||
fun testUnescapeEscapedEscapedBackslash() {
|
||||
assertThat(GradleNameElement.unescape("""ab\\\\de""")).isEqualTo("""ab\\de""")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.tools.idea.gradle.dsl.parser
|
||||
|
||||
import com.android.tools.idea.gradle.dsl.api.util.GradleNameElementUtil
|
||||
import com.android.tools.idea.gradle.dsl.parser.elements.GradleNameElement
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
|
||||
class GradleNameElementUtilTest : UsefulTestCase() {
|
||||
// These tests check that we have correctly implemented the isomorphism between a list of unescaped strings and a single string with
|
||||
// a delimiter to separate suitably-escaped parts.
|
||||
fun testSplitNoDots() {
|
||||
assertThat(GradleNameElementUtil.split("abcde")).isEqualTo(listOf("abcde"))
|
||||
}
|
||||
|
||||
fun testSplitDot() {
|
||||
assertThat(GradleNameElementUtil.split("ab.de")).isEqualTo(listOf("ab", "de"))
|
||||
}
|
||||
|
||||
fun testSplitMultipleDots() {
|
||||
assertThat(GradleNameElementUtil.split("ab.de.gh")).isEqualTo(listOf("ab", "de", "gh"))
|
||||
}
|
||||
|
||||
fun testSplitMultipleConsecutiveDots() {
|
||||
assertThat(GradleNameElementUtil.split("ab..ef")).isEqualTo(listOf("ab", "", "ef"))
|
||||
}
|
||||
|
||||
fun testSplitDotAtBeginning() {
|
||||
assertThat(GradleNameElementUtil.split(".bcdef")).isEqualTo(listOf("", "bcdef"))
|
||||
}
|
||||
|
||||
fun testSplitDotAtEnd() {
|
||||
assertThat(GradleNameElementUtil.split("abcde.")).isEqualTo(listOf("abcde", ""))
|
||||
}
|
||||
|
||||
fun testSplitEscapedDot() {
|
||||
assertThat(GradleNameElementUtil.split("""ab\.de""")).isEqualTo(listOf("ab.de"))
|
||||
}
|
||||
|
||||
fun testSplitEscapedBackslash() {
|
||||
assertThat(GradleNameElementUtil.split("""ab\\de""")).isEqualTo(listOf("""ab\de"""))
|
||||
}
|
||||
|
||||
fun testSplitExoticCharacters() {
|
||||
assertThat(GradleNameElementUtil.split("ab \t \n é Å £ € \u1234")).isEqualTo(listOf("ab \t \n é Å £ € \u1234"))
|
||||
}
|
||||
|
||||
fun testJoinNoDots() {
|
||||
assertThat(GradleNameElementUtil.join(listOf("abcde"))).isEqualTo("abcde")
|
||||
}
|
||||
|
||||
fun testJoinDot() {
|
||||
assertThat(GradleNameElementUtil.join(listOf("ab", "de"))).isEqualTo("ab.de")
|
||||
}
|
||||
|
||||
fun testJoinMultipleDots() {
|
||||
assertThat(GradleNameElementUtil.join(listOf("ab", "de", "gh"))).isEqualTo("ab.de.gh")
|
||||
}
|
||||
|
||||
fun testJoinMultipleConsecutiveDots() {
|
||||
assertThat(GradleNameElementUtil.join(listOf("ab", "", "ef"))).isEqualTo("ab..ef")
|
||||
}
|
||||
|
||||
fun testJoinDotAtBeginning() {
|
||||
assertThat(GradleNameElementUtil.join(listOf("", "bcdef"))).isEqualTo(".bcdef")
|
||||
}
|
||||
|
||||
fun testJoinDotAtEnd() {
|
||||
assertThat(GradleNameElementUtil.join(listOf("abcde", ""))).isEqualTo("abcde.")
|
||||
}
|
||||
|
||||
fun testJoinEscapedDot() {
|
||||
assertThat(GradleNameElementUtil.join(listOf("ab.de"))).isEqualTo("""ab\.de""")
|
||||
}
|
||||
|
||||
fun testJoinEscapedBackslash() {
|
||||
assertThat(GradleNameElementUtil.join(listOf("""ab\de"""))).isEqualTo("""ab\\de""")
|
||||
}
|
||||
|
||||
fun testJoinExoticCharacters() {
|
||||
assertThat(GradleNameElementUtil.join(listOf("ab \t \n é Å £ € \u1234"))).isEqualTo("ab \t \n é Å £ € \u1234")
|
||||
}
|
||||
|
||||
// These tests check that we have implemented the lower-level escaping and unescaping operations correctly, which are occasionally
|
||||
// needed by backends.
|
||||
fun testEscapeNoDot() {
|
||||
assertThat(GradleNameElementUtil.escape("abcde")).isEqualTo("abcde")
|
||||
}
|
||||
|
||||
fun testEscapeDot() {
|
||||
assertThat(GradleNameElementUtil.escape("ab.de")).isEqualTo("""ab\.de""")
|
||||
}
|
||||
|
||||
fun testEscapeMultipleDots() {
|
||||
assertThat(GradleNameElementUtil.escape("ab.de.gh")).isEqualTo("""ab\.de\.gh""")
|
||||
}
|
||||
|
||||
fun testEscapeMultipleConsecutiveDots() {
|
||||
assertThat(GradleNameElementUtil.escape("ab..ef")).isEqualTo("""ab\.\.ef""")
|
||||
}
|
||||
|
||||
fun testEscapeDotAtBeginning() {
|
||||
assertThat(GradleNameElementUtil.escape(".bcdef")).isEqualTo("""\.bcdef""")
|
||||
}
|
||||
|
||||
fun testEscapeDotAtEnd() {
|
||||
assertThat(GradleNameElementUtil.escape("abcde.")).isEqualTo("""abcde\.""")
|
||||
}
|
||||
|
||||
fun testEscapeEscapedDot() {
|
||||
assertThat(GradleNameElementUtil.escape("""ab\.de""")).isEqualTo("""ab\\\.de""")
|
||||
}
|
||||
|
||||
fun testEscapeEscapedBackslash() {
|
||||
assertThat(GradleNameElementUtil.escape("""ab\\de""")).isEqualTo("""ab\\\\de""")
|
||||
}
|
||||
|
||||
fun testUnescapeNoDot() {
|
||||
assertThat(GradleNameElementUtil.unescape("abcde")).isEqualTo("abcde")
|
||||
}
|
||||
|
||||
fun testUnescapeDot() {
|
||||
assertThat(GradleNameElementUtil.unescape("""ab\.de""")).isEqualTo("ab.de")
|
||||
}
|
||||
|
||||
fun testUnescapeMultipleDots() {
|
||||
assertThat(GradleNameElementUtil.unescape("""ab\.de\.gh""")).isEqualTo("ab.de.gh")
|
||||
}
|
||||
|
||||
fun testUnescapeMultipleConsecutiveDots() {
|
||||
assertThat(GradleNameElementUtil.unescape("""ab\.\.ef""")).isEqualTo("ab..ef")
|
||||
}
|
||||
|
||||
fun testUnescapeDotAtBeginning() {
|
||||
assertThat(GradleNameElementUtil.unescape("""\.bcdef""")).isEqualTo(".bcdef")
|
||||
}
|
||||
|
||||
fun testUnescapeDotAtEnd() {
|
||||
assertThat(GradleNameElementUtil.unescape("""abcde\.""")).isEqualTo("abcde.")
|
||||
}
|
||||
|
||||
fun testUnescapeEscapedEscapedDot() {
|
||||
assertThat(GradleNameElementUtil.unescape("""ab\\\.de""")).isEqualTo("""ab\.de""")
|
||||
}
|
||||
|
||||
fun testUnescapeEscapedEscapedBackslash() {
|
||||
assertThat(GradleNameElementUtil.unescape("""ab\\\\de""")).isEqualTo("""ab\\de""")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user