Comments (6)
Ok, I see. Your approach to changing templates from {{}} to '$' makes sense to me. The only drawback I see now is that IntelliJ will try to resolve a local variable when it finds '$'. So in the code, it will be necessary to escape '$' with a backslash, or IntelliJ will complain about the non-existing variable. Have you tried it? How does it work? Should we escape '$' or not?
Regarding the implementation. There is already a code resolving username and password. It is in SectionResolver:
The resolution of the URL, username, and password should happen there. I think that the best algorithm would be (for all three parameters):
- Check if it starts with the dollar sign, and in such a case, try to replace it with the env variable value
- If the env variable is unresolved, and the name is one of the KSCRIPT_REPOSITORY_* names, then we should use those names as they are now (details can still be written in the configuration file)
- If variables are still not resolved, we should probably throw an exception
Please merge all 3 PRs into only one; it's much easier for me to test and review. Also, please write at least a simple Unit Test.
And thanks for your great work! 👍
from kscript.
Please explain what you mean by "variable substitution for repositories no longer works"? Is it a user code problem or in kscript itself?
from kscript.
Please explain what you mean by "variable substitution for repositories no longer works"? Is it a user code problem or in kscript itself?
@aartiPl Substitution of environment variables for the username and password components of a repository is a documented feature of kscript. See
Lines 419 to 422 in 1c97c21
I've submitted PR #403 to illustrate the two issues I have identified. You will note that both test 4 and test 5 currently fail.
Test 4 is at the moment a documentation problem -- the initial implementation of this in kscript used {{FOO}}
syntax. But when the backend was changed to kotlin script, the machinery inside kotlin script uses the $FOO
syntax. So simply documenting the change is sufficient I think.
Test 5 illustrates an issue with packaging scripts that use custom auth with env vars. I'm not sure this ever worked.
For test 4, the call to the relevant code is
For test 5, the relevant code is
kscript/src/main/kotlin/io/github/kscripting/kscript/code/GradleTemplates.kt
Lines 109 to 114 in 1c97c21
from kscript.
I submitted 3 PRs to resolve this. Please review.
from kscript.
The approach I took was to move kscript in a way compatible with Kotlin scripting. An alternate approach would be to keep the syntax as {{FOO}}
, resolve these inside kscript, and pass the Kotlin script backend (and Gradle) the resolved vars. This would actually simplify the code a bit, but personally I think kscript moving towards syntactic compatibility with Kotlin Script is a better option, as hopefully the kscript wrapper will get smaller and smaller over time. However, that does make it a breaking change for existing scripts.
from kscript.
Ok, I see. Your approach to changing templates from {{}} to '$' makes sense to me. The only drawback I see now is that IntelliJ will try to resolve a local variable when it finds '$'. So in the code, it will be necessary to escape '$' with a backslash, or IntelliJ will complain about the non-existing variable. Have you tried it? How does it work? Should we escape '$' or not?
Kotlin script appears to require it be unescaped i.e. it reads it as a literal value. Adding the escape bypasses Kotlin script's var resolution. While we will now do the parsing for this before it ever gets to Kotlin Script and could change this behavior, I suggest we stay compatible to the syntax used in Kotlin Script. IDEA will likely be updated at some point to correctly interpret the $
in scripts.
Regarding the implementation. There is already a code resolving username and password. It is in SectionResolver:
Ok.
2. If the env variable is unresolved, and the name is one of the KSCRIPT_REPOSITORY_* names, then we should use those names as they are now (details can still be written in the configuration file)
One tweak to this which will be more powerful as it allows environment variables to compose from properties, and also easier to implement:
2. After env variable resolution, if the name is one of the KSCRIPT_REPOSITORY_* names, then we should use those names as they are now
Also, please write at least a simple Unit Test.
Done.
PR submitted for all these changes #406.
from kscript.
Related Issues (20)
- Create kscript package for scoop HOT 7
- Don't work @file:Import("absolute/path/to/myutils.kt") HOT 2
- Basic hello world example does not work with interpreter HOT 1
- Allow setting an alternate kotlinc binary (or use kotlinc-jvm)
- Add an option to suppress final error output HOT 10
- [Windows] path to kotlinc not quoted HOT 4
- How to load text file via relative path? HOT 2
- kscript --interactive does not resolve the variables defined inside .kts file HOT 1
- Does not work with Kotlin 1.9.0 HOT 12
- Can kscript used in Android project written in kotlin HOT 1
- Can you change kscript's included java version? HOT 1
- [question] daemon concept HOT 4
- Does not support spaces in KOTLIN_HOME variable.
- --package is broken in 4.2.3 - doesn't include stuff in local dependencies
- Fresh checkout of repo causes failure on `gradle run` and other ways of invoking `kscript` fail for the same reason
- kscript downloading Kotlin Native jars during dependency resolution - why? HOT 1
- Example in README with @file:Import fails
- Use version 4.2.3 on Dockerfile
- Does not work with Kotlin 2.0.0 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kscript.