From 1912b2b0ec8ba76238353002157743cb47ca6c02 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Tue, 9 Sep 2014 19:03:08 +0400 Subject: [PATCH] add android jps builder test stub wtf --- .../kotlin/generators/tests/GenerateTests.kt | 5 + idea/testData/android/goto/simple/simple.kt | 8 +- .../jet/android/AbstractAndroidGotoTest.kt | 9 +- .../jet/android/KotlinAndroidTestCase.java | 97 ++++++++++--------- .../android/KotlinAndroidTestCaseBase.java | 12 ++- jps-plugin/jps-plugin.iml | 13 +++ .../kotlin/jps/build/KotlinBuilder.kt | 6 +- .../android/AbstractAndroidJpsTestCase.kt | 33 +++++++ .../android/AndroidJpsTestCaseGenerated.java | 44 +++++++++ .../android/simple/AndroidManifest.xml | 16 +++ .../android/simple/res/layout/main.xml | 13 +++ jps-plugin/testData/android/simple/simple.iml | 44 +++++++++ jps-plugin/testData/android/simple/simple.ipr | 18 ++++ .../simple/src/com/example/myapp/Foo.java | 10 ++ .../src/com/example/myapp/MyActivity.kt | 19 ++++ 15 files changed, 292 insertions(+), 55 deletions(-) create mode 100644 jps-plugin/test/org/jetbrains/jet/jps/build/android/AbstractAndroidJpsTestCase.kt create mode 100644 jps-plugin/test/org/jetbrains/jet/jps/build/android/AndroidJpsTestCaseGenerated.java create mode 100644 jps-plugin/testData/android/simple/AndroidManifest.xml create mode 100644 jps-plugin/testData/android/simple/res/layout/main.xml create mode 100644 jps-plugin/testData/android/simple/simple.iml create mode 100644 jps-plugin/testData/android/simple/simple.ipr create mode 100644 jps-plugin/testData/android/simple/src/com/example/myapp/Foo.java create mode 100644 jps-plugin/testData/android/simple/src/com/example/myapp/MyActivity.kt diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 54c7c04135c..62d2887adeb 100644 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -147,6 +147,7 @@ import org.jetbrains.jet.android.AbstractCrossParserTest import org.jetbrains.jet.lang.resolve.android.AbstractAndroidBoxTest import org.jetbrains.jet.android.AbstractAndroidCompletionTest import org.jetbrains.jet.android.AbstractAndroidGotoTest +import org.jetbrains.jet.jps.build.android.AbstractAndroidJpsTestCase fun main(args: Array) { System.setProperty("java.awt.headless", "true") @@ -750,6 +751,10 @@ fun main(args: Array) { model("incremental/pureKotlin", extension = null, excludeParentDirs = true) model("incremental/withJava", extension = null, excludeParentDirs = true) } + + testClass(javaClass()) { + model("android", recursive = false, extension = null) + } } generateTestDataForReservedWords() diff --git a/idea/testData/android/goto/simple/simple.kt b/idea/testData/android/goto/simple/simple.kt index 045b36dcbb8..c7905f97d7b 100644 --- a/idea/testData/android/goto/simple/simple.kt +++ b/idea/testData/android/goto/simple/simple.kt @@ -1,9 +1,13 @@ package com.myapp import android.app.Activity +import android.os.Bundle +import java.io.File -class MyActivity: Activity() { - val button = this.login +public class MyActivity : Activity() { + override fun onCreate(savedInstanceState: Bundle?) {} + //val button = login + val shit = File("") } diff --git a/idea/tests/org/jetbrains/jet/android/AbstractAndroidGotoTest.kt b/idea/tests/org/jetbrains/jet/android/AbstractAndroidGotoTest.kt index a3194aa41cb..a9ce631ad99 100644 --- a/idea/tests/org/jetbrains/jet/android/AbstractAndroidGotoTest.kt +++ b/idea/tests/org/jetbrains/jet/android/AbstractAndroidGotoTest.kt @@ -41,12 +41,11 @@ public abstract class AbstractAndroidGotoTest : KotlinAndroidTestCase() { override fun requireRecentSdk() = true public fun doTest(path: String) { - val f = myFixture!! - f.copyDirectoryToProject(getResDir()!!, "res") - f.configureByFile(path + getTestName(true) + ".kt"); + myFixture!!.copyDirectoryToProject(getResDir()!!, "res") + myFixture!!.configureByFile(path + getTestName(true) + ".kt"); - val asf = GotoDeclarationAction.findTargetElement(f.getProject(), f.getEditor(), f.getCaretOffset()) - f.getEditor().toString() + val asf = GotoDeclarationAction.findTargetElement(myFixture!!.getProject(), myFixture!!.getEditor(), myFixture!!.getCaretOffset()) + myFixture!!.getEditor().toString() fail("this test doesn't work yet") } } diff --git a/idea/tests/org/jetbrains/jet/android/KotlinAndroidTestCase.java b/idea/tests/org/jetbrains/jet/android/KotlinAndroidTestCase.java index 6e4b3101ef3..49756b4bdd1 100644 --- a/idea/tests/org/jetbrains/jet/android/KotlinAndroidTestCase.java +++ b/idea/tests/org/jetbrains/jet/android/KotlinAndroidTestCase.java @@ -1,17 +1,17 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2010-2014 JetBrains s.r.o. * - * 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 + * 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 + * 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. + * 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 org.jetbrains.jet.android; @@ -29,8 +29,15 @@ import com.intellij.facet.ModifiableFacetModel; import com.intellij.ide.startup.impl.StartupManagerImpl; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.roots.ContentEntry; +import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.ModuleRootModificationUtil; +import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; import com.intellij.openapi.startup.StartupManager; +import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess; import com.intellij.psi.FileViewProvider; @@ -39,18 +46,19 @@ import com.intellij.psi.impl.PsiManagerEx; import com.intellij.psi.impl.file.impl.FileManager; import com.intellij.testFramework.InspectionTestUtil; import com.intellij.testFramework.builders.JavaModuleFixtureBuilder; -import com.intellij.testFramework.fixtures.IdeaProjectTestFixture; -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory; -import com.intellij.testFramework.fixtures.JavaTestFixtureFactory; -import com.intellij.testFramework.fixtures.TestFixtureBuilder; +import com.intellij.testFramework.fixtures.*; import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; +import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl; import org.jetbrains.android.facet.AndroidFacet; import org.jetbrains.android.facet.AndroidRootUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetTestCaseBuilder; import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.jet.plugin.JetLightProjectDescriptor; +import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor; import org.jetbrains.jet.plugin.actions.internal.KotlinInternalMode; import org.jetbrains.jet.plugin.references.BuiltInsReferenceResolver; +import org.jetbrains.jet.testing.ConfigLibraryUtil; import java.io.File; import java.io.IOException; @@ -82,53 +90,54 @@ public abstract class KotlinAndroidTestCase extends KotlinAndroidTestCaseBase { return "res/"; } - @Override - public void setUp() throws Exception { - super.setUp(); + class LightAndroidProjectDescriptor extends JetLightProjectDescriptor { + @Override + public Sdk getSdk() { + androidSdk = createAndroidSdk(getTestSdkPath(), getPlatformDir()); + return androidSdk; + } - // this will throw an exception if we don't have a full Android SDK, so we need to do this first thing before any other setup + @Override + public void configureModule( + Module module, ModifiableRootModel model, ContentEntry contentEntry + ) { + NewLibraryEditor editor = new NewLibraryEditor(); + editor.setName("android.jar"); + editor.addRoot(androidSdk.getSdkModificator().getRoots(OrderRootType.CLASSES)[0], OrderRootType.CLASSES); + + ConfigLibraryUtil.addLibrary(editor, model); + } + } + + @Override + protected void setUp() throws Exception { + super.setUp(); String sdkPath = getTestSdkPath(); - final TestFixtureBuilder projectBuilder = - IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName()); - myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture()); - final JavaModuleFixtureBuilder moduleFixtureBuilder = projectBuilder.addModule(JavaModuleFixtureBuilder.class); + + IdeaTestFixtureFactory factory = IdeaTestFixtureFactory.getFixtureFactory(); + //TestFixtureBuilder fixtureBuilder = factory.createLightFixtureBuilder(JetLightProjectDescriptor.INSTANCE); + TestFixtureBuilder fixtureBuilder = factory.createLightFixtureBuilder(new LightAndroidProjectDescriptor()); + //final TestFixtureBuilder fixtureBuilder = factory.createLightFixtureBuilder(getName()); + final IdeaProjectTestFixture fixture = fixtureBuilder.getFixture(); + myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(fixture, new LightTempDirTestFixtureImpl(true)); + final String dirPath = myFixture.getTempDirPath() + getContentRootPath(); final File dir = new File(dirPath); if (!dir.exists()) { assertTrue(dir.mkdirs()); } - tuneModule(moduleFixtureBuilder, dirPath); - - final ArrayList modules = new ArrayList(); - configureAdditionalModules(projectBuilder, modules); myFixture.setUp(); myFixture.setTestDataPath(getTestDataPath()); - myModule = moduleFixtureBuilder.getFixture().getModule(); - // Must be done before addAndroidFacet, and must always be done, even if !myCreateManifest. - // We will delete it at the end of setUp; this is needed when unit tests want to rewrite - // the manifest on their own. + myModule = myFixture.getModule(); + createManifest(); myFacet = addAndroidFacet(myModule, sdkPath, getPlatformDir(), isToAddSdk()); - myAdditionalModules = new ArrayList(); - - for (MyAdditionalModuleData data : modules) { - final Module additionalModule = data.myModuleFixtureBuilder.getFixture().getModule(); - myAdditionalModules.add(additionalModule); - final AndroidFacet facet = addAndroidFacet(additionalModule, sdkPath, getPlatformDir()); - facet.setLibraryProject(data.myLibrary); - final String rootPath = getContentRootPath(data.myDirName); - myFixture.copyDirectoryToProject("res", rootPath + "/res"); - myFixture.copyFileToProject(SdkConstants.FN_ANDROID_MANIFEST_XML, - rootPath + '/' + SdkConstants.FN_ANDROID_MANIFEST_XML); - ModuleRootModificationUtil.addDependency(myModule, additionalModule); - } - if (!myCreateManifest) { deleteManifest(); } diff --git a/idea/tests/org/jetbrains/jet/android/KotlinAndroidTestCaseBase.java b/idea/tests/org/jetbrains/jet/android/KotlinAndroidTestCaseBase.java index 2b398de46f7..04fa6a9274b 100644 --- a/idea/tests/org/jetbrains/jet/android/KotlinAndroidTestCaseBase.java +++ b/idea/tests/org/jetbrains/jet/android/KotlinAndroidTestCaseBase.java @@ -36,6 +36,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.xml.XmlAttributeValue; import com.intellij.testFramework.IdeaTestCase; import com.intellij.testFramework.UsefulTestCase; +import com.intellij.testFramework.fixtures.CodeInsightTestFixture; import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture; import org.jetbrains.android.dom.wrappers.LazyValueResourceElementWrapper; import org.jetbrains.android.sdk.*; @@ -53,7 +54,9 @@ public abstract class KotlinAndroidTestCaseBase extends UsefulTestCase { /** Environment variable or system property pointing to the directory name of the platform inside $sdk/platforms, e.g. "android-17" */ public static final String PLATFORM_DIR_PROPERTY = "ADT_TEST_PLATFORM"; - protected JavaCodeInsightTestFixture myFixture; + protected CodeInsightTestFixture myFixture; + + protected Sdk androidSdk; protected KotlinAndroidTestCaseBase() { IdeaTestCase.initPlatformPrefix(); @@ -136,7 +139,7 @@ public abstract class KotlinAndroidTestCaseBase extends UsefulTestCase { } protected void addAndroidSdk(Module module, String sdkPath, String platformDir) { - Sdk androidSdk = createAndroidSdk(sdkPath, platformDir); + assert androidSdk != null : "android sdk must be initialized"; ModuleRootModificationUtil.setModuleSdk(module, androidSdk); } @@ -184,6 +187,11 @@ public abstract class KotlinAndroidTestCaseBase extends UsefulTestCase { } assertNotNull(target); data.setBuildTarget(target); + data.setJavaSdk(PluginTestCaseBase.fullJdk()); + // Srsly, WTF? Why do i have to manually add jdk classes to android sdk roots? Even with setJavaSdk(PluginTestCaseBase.fullJdk()) + for (VirtualFile f : PluginTestCaseBase.fullJdk().getRootProvider().getFiles(OrderRootType.CLASSES)) { + sdkModificator.addRoot(f, OrderRootType.CLASSES); + } sdkModificator.setSdkAdditionalData(data); sdkModificator.commitChanges(); return sdk; diff --git a/jps-plugin/jps-plugin.iml b/jps-plugin/jps-plugin.iml index 201c8d3bb04..69240513cb7 100644 --- a/jps-plugin/jps-plugin.iml +++ b/jps-plugin/jps-plugin.iml @@ -23,5 +23,18 @@ + + + + + + + + + + + + + diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index 2a13192a5c2..a50171c021a 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -434,13 +434,15 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR } private fun getAndroidResPath(module: JpsModule, context: CompileContext): String { - val extension = AndroidJpsUtil.getExtension(module)!! + val extension = AndroidJpsUtil.getExtension(module) + if (extension == null) return "" val path = AndroidJpsUtil.getResourceDirForCompilationPath(extension) return File(path!!.getAbsolutePath() + "/layout").getAbsolutePath() } private fun getAndroidManifest(module: JpsModule): String { - val extension = AndroidJpsUtil.getExtension(module)!! + val extension = AndroidJpsUtil.getExtension(module) + if (extension == null) return "" return AndroidJpsUtil.getManifestFileForCompilationPath(extension)!!.getAbsolutePath() } diff --git a/jps-plugin/test/org/jetbrains/jet/jps/build/android/AbstractAndroidJpsTestCase.kt b/jps-plugin/test/org/jetbrains/jet/jps/build/android/AbstractAndroidJpsTestCase.kt new file mode 100644 index 00000000000..05de8ff8005 --- /dev/null +++ b/jps-plugin/test/org/jetbrains/jet/jps/build/android/AbstractAndroidJpsTestCase.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * 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 org.jetbrains.jet.jps.build.android + +import org.jetbrains.jps.builders.JpsBuildTestCase + +public abstract class AbstractAndroidJpsTestCase : JpsBuildTestCase() { + private val SDK_NAME = "Android_SDK" + override fun setUp() { + super.setUp() + System.setProperty("kotlin.jps.tests", "true") + } + public fun doTest(path: String) { + addJdk(SDK_NAME, getHomePath() + "/androidSDK/platforms/android-17" + "/android.jar") + loadProject(path + getTestName(true) + ".ipr") + rebuildAll() + makeAll().assertSuccessful() + } +} diff --git a/jps-plugin/test/org/jetbrains/jet/jps/build/android/AndroidJpsTestCaseGenerated.java b/jps-plugin/test/org/jetbrains/jet/jps/build/android/AndroidJpsTestCaseGenerated.java new file mode 100644 index 00000000000..bc507501bfc --- /dev/null +++ b/jps-plugin/test/org/jetbrains/jet/jps/build/android/AndroidJpsTestCaseGenerated.java @@ -0,0 +1,44 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * 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 org.jetbrains.jet.jps.build.android; + +import com.intellij.testFramework.TestDataPath; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.InnerTestClasses; +import org.jetbrains.jet.test.TestMetadata; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("jps-plugin/testData/android") +@TestDataPath("$PROJECT_ROOT") +public class AndroidJpsTestCaseGenerated extends AbstractAndroidJpsTestCase { + public void testAllFilesPresentInAndroid() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("jps-plugin/testData/android"), Pattern.compile("^([^\\.]+)$"), false); + } + + @TestMetadata("simple") + public void testSimple() throws Exception { + String fileName = JetTestUtils.navigationMetadata("jps-plugin/testData/android/simple/"); + doTest(fileName); + } + +} diff --git a/jps-plugin/testData/android/simple/AndroidManifest.xml b/jps-plugin/testData/android/simple/AndroidManifest.xml new file mode 100644 index 00000000000..57d0d4c3e82 --- /dev/null +++ b/jps-plugin/testData/android/simple/AndroidManifest.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/jps-plugin/testData/android/simple/res/layout/main.xml b/jps-plugin/testData/android/simple/res/layout/main.xml new file mode 100644 index 00000000000..024accd07c7 --- /dev/null +++ b/jps-plugin/testData/android/simple/res/layout/main.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/jps-plugin/testData/android/simple/simple.iml b/jps-plugin/testData/android/simple/simple.iml new file mode 100644 index 00000000000..b92085bd371 --- /dev/null +++ b/jps-plugin/testData/android/simple/simple.iml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/jps-plugin/testData/android/simple/simple.ipr b/jps-plugin/testData/android/simple/simple.ipr new file mode 100644 index 00000000000..a80d5700fa2 --- /dev/null +++ b/jps-plugin/testData/android/simple/simple.ipr @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/jps-plugin/testData/android/simple/src/com/example/myapp/Foo.java b/jps-plugin/testData/android/simple/src/com/example/myapp/Foo.java new file mode 100644 index 00000000000..03041b80591 --- /dev/null +++ b/jps-plugin/testData/android/simple/src/com/example/myapp/Foo.java @@ -0,0 +1,10 @@ +package com.example.myapp; + +/** + * Created by miha on 8/6/14. + */ +public class Foo { + public static void main(String[] args) { + System.out.println(R.id.LOL); + } +} diff --git a/jps-plugin/testData/android/simple/src/com/example/myapp/MyActivity.kt b/jps-plugin/testData/android/simple/src/com/example/myapp/MyActivity.kt new file mode 100644 index 00000000000..38d44fe8136 --- /dev/null +++ b/jps-plugin/testData/android/simple/src/com/example/myapp/MyActivity.kt @@ -0,0 +1,19 @@ +package com.example.myapp + +import android.app.Activity +import android.os.Bundle + +public class MyActivity : Activity() { + /** + * Called when the activity is first created. + */ + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.main) + println(R.id.LOL) + fuck + this.LOL + LOL.setText("UIGFVIYUGFKGYUFOD") + LOL.setText("test") + } +}