Play! 2.0.2 and Mailer module - module

I'm trying to use mailer module for Play! 2.0.3/Scala.
1) updating Build.scala didn't help to make the classes availble - do I need to play clean? I ended up brutally dropping a jar into lib.
2) more puzzling, what is the use[] method in the tutorial? (use[MailerPlugin].email)? I never saw it in the imports, neither it is in tutorial's imports.
Build.scala:
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "some-some"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
"org.mindrot" % "jbcrypt" % "0.3m",
"com.typesafe" %% "play-plugins-mailer" % "2.0.4"
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
// Add your own project settings here
)
}

1) That was an issue in IDE (IntelliJ IDEA) only.
In order for it to pick up Build.scala dependencies, run play dependencies and play idea. The new project will include the Maven dependencies.
2) I should have been more attentive.
The compiler error itself says "add import play.api.Play.current", which does solve the problem.

Related

Specific gradle options for target build platform

I have a Kotlin project (not Android) that uses the LWJGL library. Under macOS, I need to add the following options to build.gradle:
project.ext.lwjglNatives = "natives-macos"
applicationDefaultJvmArgs = ["-XstartOnFirstThread"]
dependencies {
implementation platform('org.jetbrains.kotlin:kotlin-bom')
implementation platform("org.lwjgl:lwjgl-bom:3.2.3")
implementation "org.lwjgl:lwjgl"
implementation "org.lwjgl:lwjgl-openal"
runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-openal::$lwjglNatives"
}
On Windows, however, I need to drop applicationDefaultJvmArgs, and set lwjglNatives to:
project.ext.lwjglNatives = "natives-windows"
How can I tell gradle to do this? Basically I need some kind of target platform check.
Moreover, I need to know the target platform in Kotlin was well. How can I tell the build platform from Kotlin code?
I figured it out. The operating system can be tested like this:
import org.apache.tools.ant.taskdefs.condition.Os
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
project.ext.lwjglNatives = "natives-windows"
} else {
project.ext.lwjglNatives = "natives-macos"
applicationDefaultJvmArgs = ["-XstartOnFirstThread"]
}
To access this from Kotlin, a BuildConfig.java needs to be generated ad hoc:
tasks.register('generateSources') {
ext.outputDir = "$buildDir/generated/java"
outputs.dir outputDir
doFirst {
mkdir "$outputDir/ch/digorydoo/ksoundrender"
file("$outputDir/ch/digorydoo/ksoundrender/BuildConfig.java").text =
"""|package ch.digorydoo.ksoundrender;
|public class BuildConfig {
| public static Boolean isWindows() {
| return ${if (Os.isFamily(Os.FAMILY_WINDOWS)) "true" else "false"};
|}
|}""".stripMargin()
}
}
compileKotlin.dependsOn generateSources
sourceSets.main.java.srcDir generateSources.outputDir
Now I can just import BuildConfig from Kotlin.

Why is the kotlin-gradle-plugin failing to create a PSIFile from CodeInsightTestFixture.configureByText?

I created an IntelliJ plugin using the template https://github.com/JetBrains/intellij-platform-plugin-template. The template comes with a test that runs on an XML file. I want to create a similar test for a Kotlin file. Here's the template test file plus my added test (test2):
package org.jetbrains.plugins.template
import com.intellij.ide.highlighter.XmlFileType
import com.intellij.psi.xml.XmlFile
import com.intellij.testFramework.TestDataPath
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import com.intellij.util.PsiErrorElementUtil
#TestDataPath("\$CONTENT_ROOT/src/test/testData")
class MyPluginTest : BasePlatformTestCase() {
fun testXMLFile() {
val psiFile = myFixture.configureByText(XmlFileType.INSTANCE, "<foo>bar</foo>")
val xmlFile = assertInstanceOf(psiFile, XmlFile::class.java)
assertFalse(PsiErrorElementUtil.hasErrors(project, xmlFile.virtualFile))
assertNotNull(xmlFile.rootTag)
xmlFile.rootTag?.let {
assertEquals("foo", it.name)
assertEquals("bar", it.value.text)
}
}
override fun getTestDataPath() = "src/test/testData/rename"
fun testRename() {
myFixture.testRename("foo.xml", "foo_after.xml", "a2")
}
// Here's my test
fun test2() {
val fileText: String = """
package com.loganmay.test
data class MyClass(val myString: String)
""".trimIndent()
val psiFile = myFixture.configureByText("a.kt", fileText)
val xmlFile = assertInstanceOf(psiFile, XmlFile::class.java)
}
}
Without changing the build.gradle file, that test fails with:
Expected instance of: com.intellij.psi.xml.XmlFile actual: com.intellij.psi.impl.source.PsiPlainTextFileImpl
I want it to parse the text as a PsiFile that's also a KtFile. From various sources, I've been led to believe that the fixture is parsing it as a plain text file because the test project doesn't have access to the Kotlin compiler. So, I added:
dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10")
}
to the build.gradle. Then, when I run the test, configureByText throws an exception with a big trace, the root exception of which is:
Caused by: java.lang.Throwable: 'filetype.archive.display.name' is not found in java.util.PropertyResourceBundle#4ecbb519(messages.CoreBundle)
... 53 more
org.jetbrains.plugins.template.MyPluginTest > test2 FAILED
com.intellij.diagnostic.PluginException at ComponentManagerImpl.kt:511
Caused by: java.util.MissingResourceException at Registry.java:164
Does anyone have any insight into what the issue is or know how to resolve it?
Notes:
I also tried importing the kotlin compiler and casting psiFile as KtFile, which produced the same error, an idea I got from here
This project has a test like this that may be working
This post and this post recommend adding the kotlin gradle plugin, which I did
This question seems similar
Yann Cebron replied on the jetbrains help forum with an answer for Java, which also worked for Kotlin.
The solution is to add a dependency to the IntelliJ gradle plugin. The template comes with these lines in the build.gradle:
intellij {
pluginName.set(properties("pluginName"))
version.set(properties("platformVersion"))
type.set(properties("platformType"))
// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
}
So, didn't need to do anything there. In my gradle.properties, I added
platformPlugins = com.intellij.java, org.jetbrains.kotlin
To my plugin.xml, I added:
<depends>com.intellij.modules.java</depends>
<depends>org.jetbrains.kotlin</depends>
I was able to remove
dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10")
}
from the build.gradle which I mentioned above.
Now, the test works for Java and Kotlin files.

KMM how can I add custom value to Bundle.main.infoDictionary

I have kotlin multiplatform project.
I know that I can read from infoDictionary (infoplist) data in runtime with:
val value = NSBundle.mainBundle.infoDictionary?.get("customValue")
My question, how can I add customValue to infoDictionary as part of build process, in build.gradle.kts of shared.
it.binaries.framework {
baseName = "shared"
embedBitcode("disable")
// here I want to infoDictionary.add("customValue", myValue)
}

import kotlinx is impossible in IntelliJ IDEA

I`m testing coroutine example code on IntelliJ IDEA. But I cannot import library which needs for coroutine.
I created project as Kotlin - "JVM | IDEA". I tried simple print hello world code and succeesfully done. But coroutine example don`t even execute.
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
fun main()
{
runBlocking {
var counter = 0
val lock = Mutex()
val coroutines = List(3) {
launch {
repeat(1_000) {
lock.withLock {
counter++
}
}
}
}
coroutines.forEach { it.join() }
println("Final counter: $counter")
}
}
This Code runs on https://play.kotlinlang.org. But in IDEA, they cannot understand it, showing 'Unresolved reference'.
I`ve searched but no answer found. How can I run this on IDEA project?
it would be a good idea to switch to a Gradle-based build, which will automatically be imported by IntelliJ IDEA.
you can set IntelliJ to automatically stay in sync with your Gradle files, or you can opt to "sync" IntelliJ to Gradle's structure on demand.
you have two syntax options with Gradle: Groovy and Kotlin. make sure if you are new to Gradle that you use a consistent syntax, otherwise it can be hard to follow the guides. obviously if you are working in Kotlin, it's a great idea to use Kotlin in your build files, too.

Kotlin/Native Tensorflow

I created a tensorflow library and trying get tensorflow version in my kotlin script like that
import tensorflow.TF_Version
fun main(args: Array<String>) {
TF_Version()
}
idea can link TF_Version() method to library with Ctrl+click
and there(in library) i have method
fun TF_Version(): CPointer<ByteVar>? {
return interpretCPointer<ByteVar>(kniBridge0())
}
#SymbolName("tensorflow_kniBridge0")
private external fun kniBridge0(): NativePtr
but when i try to build and start i see this error
/tmp/konan_temp8584442034275821874/combined.o:ld-temp.o:function Konan_start: error: undefined reference to 'tensorflow_kniBridge0'
error: /home/fnasibov/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold invocation reported errors
Please help me fix that
Found solution:
my .def file was
headers = /home/user/.konan/third--arty/tensorflow/include/tensorflow/c/c_api.h
And after i add Opts to def file:
headers = /home/fnasibov/.konan/third-party/tensorflow/include/tensorflow/c/c_api.h
compilerOpts.linux = -I/usr/include -I/usr/include/x86_64-linux-gnu
linkerOpts.linux = -L/home/user/.konan/third-party/tensorflow/lib -ltensorflow
and regenerate klib - thats worked!