63 Commits

Author SHA1 Message Date
Jen Basch
6c036bf82a Implement Pkl binary renderer and parser (#1203)
Implements a binary renderer for Pkl values, which is a lossless capturing of Pkl data.

This follows the pkl binary format that is already used with `pkl server` calls, and is
made available as a Java API and also an in-language API.

Also, introduces a binary parser into the corresponding `PObject` types in Java.
2025-10-20 09:10:22 -07:00
Daniel Chao
42dcad25c6 Fix error message when reading a resource/module past root dir (#1234) 2025-10-09 10:16:33 -07:00
Daniel Chao
98ab741c54 Bump Kotlin to 2.2.20, minimum Kotlin to 2.1 (#1232)
The current version of the kotlin-gradle plugin is not compatible with
Gradle 9.1, causing error `java.lang.NoSuchMethodError:
 'org.gradle.api.Project org.gradle.api.artifacts.ProjectDependency.getDependencyProject()'`

Also, the Kotlin 2.0 language target is deprecated as of Kotlin 2.2.
2025-10-08 21:40:35 -07:00
Daniel Chao
cf9d87373d Bump Gradle to 9.1.0 (#1228)
* Bump Gradle to 9.1.0
* Bump foojay resolver to 1.0.0
* Fix build logic on windows

Also, remove support for kotlin gradle plugin less than 1.8.x, because:

* Class `org.gradle.api.plugins.Convention` is no longer available in the classpath in Gradle
* Continued support for legacy plugin would require heavy reflection, which is brittle and hard to verify
* Kotlin 1.7 is 3 years old and no longer updated
2025-10-08 08:54:43 -07:00
Steve Salevan
cecaf39aff Adds traceMode evaluator setting to support trace() pretty printing (#1100) 2025-10-07 12:31:16 -07:00
Daniel Chao
d03a074f63 Bump dependencies (#1225)
* byte-buddy to 1.17.7
* commonmark to 0.26

And also test dependencies (junit, assertj)
2025-10-04 13:59:54 -07:00
Daniel Chao
5d90cf8f4e Introduce pkl-doc model version 2 (#1169)
Currently, in order to update a pkl-doc documentation site,
almost the entire existing site is read in order to update metadata
like known versions, known subtypes, and more.

For example, adding a new version of a package requires that the
existing runtime data of all existing versions be updated.
Eventually, this causes the required storage size to balloon
exponentially to the number of versions.

This addresses these limitations by:

1. Updating the runtime data structure to move "known versions" metadata
   to the package level (the same JSON file is used for all versions).
2. Eliminating known subtype and known usage information at a
   cross-package level.
3. Generating the search index by consuming the previously generated
   search index.
4. Generating the main page by consuming the search index.

Because this changes how runtime data is stored, an existing docsite
needs to be migrated.

This also introduces a new migration command, `pkl-doc --migrate`,
which transforms an older version of the website into a newer version.
2025-09-29 16:10:44 -07:00
Daniel Chao
a779316cc2 Update dependencies (#1184)
Bump test dependencies, and also commonmark
2025-08-21 21:32:56 -07:00
Daniel Chao
6cd73227a1 Update dependencies (#1128) 2025-07-18 09:29:44 -07:00
Daniel Chao
99020bb79d Add support for HTTP rewrites (#1062)
This adds a new configuration option for the HTTP client to replace URI prefixes when making outbound calls.

Follows the design of https://github.com/apple/pkl-evolution/pull/17
2025-07-16 15:53:31 -07:00
Daniel Chao
48ad4386c8 Add Kotlin support for "addGeneratedAnnotation" flag (#1115)
This adds logic so that the Kotlin code generator also supports the
"addGeneratedAnnotation" flag.

Also:
* Add Antora documentation
* Adjust names (generated-annotation -> add-generated-annotation)
* Adjust doc comments
2025-07-08 14:05:15 -07:00
André Rouél
0973774a5d Add @Generated annotation to generated Java types (#1075)
JaCoCo automatically excludes methods and classes annotated with @Generated from the coverage reports. This is very important to us as generated code should not normally be included in the coverage report. We want to measure the coverage of the code that we actually wrote and maintain, not the code that was automatically generated by tools.

By introducing a property generatedAnnotation (default value false) one could enable writing @Generated on Java types to be generated.

Co-authored-by: Nullpointer <mike.schulze@tealium.com>
2025-07-07 15:31:49 -07:00
Artem Yarmoliuk
f1388ffb2f Don't show 100% when number of failures is rounded up (#1110)
Co-Authored-By: Mike Drob <mdrob@apple.com>
2025-06-27 15:29:26 +02:00
Daniel Chao
e9320557b7 Introduces Bytes class (#1019)
This introduces a new `Bytes` standard library class, for working with
binary data.

* Add Bytes class to the standard library
* Change CLI to eval `output.bytes`
* Change code generators to map Bytes to respective underlying type
* Add subscript and concat operator support
* Add binary encoding for Bytes
* Add PCF and Plist rendering for Bytes

Co-authored-by: Kushal Pisavadia <kushi.p@gmail.com>
2025-06-11 16:23:55 -07:00
Artem Yarmoliuk
3bd8a88506 Aggregate junit report into one file (#1056)
Some systems require junit report to be in a single file. For example `bazel` https://bazel.build/reference/test-encyclopedia needs single file to be available in `XML_OUTPUT_FILE` path.

To avoid implementing junit aggregation in pkl wrappers in different places this PR instead adds a `--junit-aggregate-reports` flag to return all junit reports as a single file.

Additional flag `--junit-aggregate-suite-name` is added to allow overriding global test suite name from default `pkl-tests`
2025-06-06 17:33:13 -07:00
Daniel Chao
568c6ccbc2 Update dependencies, and clean up multi-JDK testing (#1088)
* Update dependencies
  1. Remove */gradle.lockfile files
  2. Run `gradle updateDependencyLocks` and commit
* Update multi-JDK testing to use simple Test task, add junit-platform-launcher to dependencies
  - Don't use JvmTestSuite (we don't use another test runner, we use the same classpath)
* Add junit-platform-launcher to libs (prevent an issue where junit-engine and junit-launcher can fall out of sync)
2025-06-04 08:30:02 -07:00
Daniel Chao
9f22c56ff5 Make Truffle use fallback runtime in Gradle plugin (#995)
Using native libraries in Gradle plugins is problematic; this adds some flags that causes Truffle to use a fallback runtime that avoids loading native libraries.
2025-02-27 12:54:49 -08:00
Artem Yarmoliuk
50cfb1c962 Bump clikt to 5.0.3 (#947)
This bumps Clikt from version 3 to version 5, which, among other things, improves
the help text formatting with colors.

Also: 
* Add `--version` flag to pkldoc, pkl-codegen-java, pkl-codegen-kotlin
* Add help text to pkldoc, pkl-codegen-java, pkl-codegen-kotlin
2025-02-19 15:18:02 -08:00
Vladimir Matveev
baa34a6dd1 Added support for an alternative current dir mode in pkldoc (#824)
Some systems have trouble with handling symlinks, which breaks the current directory links created by Pkldoc. In this PR, we add an alternative mode which creates a full copy of the latest published version contents in the current directory instead.

Co-authored-by: Dan Chao <dan.chao@apple.com>
2025-02-19 08:52:32 -08:00
Daniel Chao
28b128f86f Run spotless formatting (#958)
When we updated spotless's Java and Kotlin formatter, we changed the underlying
formatting rules.
However, due to spotless ratcheting, these formatting changes don't get applied unless a file
gets touched in a commit.

To avoid future PRs introducing lines of change that aren't related to the intention of the PR,
this is a one-time format of all files.
2025-02-17 07:36:43 -08:00
Daniel Chao
d00d0ba79f Update dependencies (#938) 2025-02-13 10:19:24 -08:00
Daniel Chao
5dc672731d Bump minimum Gradle version to 8.2 (#901)
The Kotlin 2.0 version upgrade made us incompatible with Gradle 8.1.

Given that it is now over 1.5 years old, this drops support for it, and
raises the minimum version to 8.2.
2025-01-27 10:04:31 -08:00
odenix
258eda8630 Update Kotlin to 2.0 (#900)
- update Kotlin from 1.7.10 to 2.0.21
  - Kotlin 1.6 dependencies in Gradle lock files are expected because kotlinc,
    which is also used by some tests, internally uses some 1.6 dependencies
    for backwards compatibility reasons.
- update kotlinx-html and kotlinx-serialization
- adapt Kotlin code where necessary
- use Kotlin stdlib Path APIs where possible
- fix IntelliJ Kotlin inspection warnings
- reformat code with `./gradlew spotlessApply`
  - ktfmt adds lots of trailing commas
- Add workaround to fix IntelliJ "unresolved reference" errors
2025-01-23 14:41:59 -08:00
Daniel Chao
2a9b10097d Revert "Upgrade Kotlin to 1.7.21 (#887)" (#896)
This reverts commit 273d1219a6.
2025-01-22 08:33:06 -08:00
Kushal Pisavadia
273d1219a6 Upgrade Kotlin to 1.7.21 (#887)
What's new: https://kotlinlang.org/docs/whatsnew1720.html

Releases
--------

- https://github.com/JetBrains/kotlin/releases/tag/v1.7.20
- https://github.com/JetBrains/kotlin/releases/tag/v1.7.21
2025-01-17 14:12:31 +00:00
Daniel Chao
ec7d7267dc Update dependencies (#883)
Most of these dependencies are test dependencies.
2025-01-15 05:39:14 -08:00
odenix
01bf844a96 codegen-java: Support not annotating constructor parameters (#792)
Motivation:
Spring Boot configuration classes neither require nor benefit from annotating constructor parameters with their name.
The same is true for pkl-config-java configuration classes compiled with `-parameter`.

Changes:
- Change CLI parameter `--params-annotation` to accept a `none` value.
  This is recommended in https://clig.dev/#arguments-and-flags and is how the `-F` parameter of the `ssh` command works.
- Change `paramsAnnotation` property in Gradle plugin, CliJavaCodeGeneratorOptions, and JavaCodegenOptions as follows:
  - Change meaning of `null` from "generate org.pkl.java.config.mapper.Named annotations" to "do not generate annotations".
    This is a breaking change (only) affecting users who explicitly set the property to `null` instead of omitting it.
  - Change property default from `null` to:
    `null` if `generateSpringBootConfig` is `true` and `org.pkl.java.config.mapper.Named` otherwise
- add tests
- update docs of this and other codegen options

Result:
Generated code does not contain unnecessary annotations.
2024-12-13 14:29:18 -08:00
Daniel Chao
b93cb9b322 Exclude non file-based modules from synthesized *GatherImports task (#821)
This fixes an issue where certain modules tasks fail due to the plugin
attempting to analyze their imports, but the arguments may not actually be
Pkl modules.

For example, the pkldoc task accepts entire packages in its "sourceMoules" property.

This changes the gather imports logic to only analyze file-based modules.
This is also a performance improvement; non file-based modules are unlikely to import
files due to insufficient trust levels.

Also: fix a bug when generating pkldoc on Windows
2024-11-18 11:14:17 -08:00
Daniel Chao
40a08affa6 Use ANSI colors for test results; more polish (#771)
Any thrown Pkl Errors are colored in the simple test report!

Also:
* Refactor `TextFormatter` to be more generic; rename to `TextFormattingStringBuilder`
* Adjust test report slightly (no emojis, add more spacing).
* Introduce `ColorTheme` class.
* Make stack frame descriptors colored as "faint"

Also: this changes the summary so it summarizes _all_ modules, rather than a summary per module.

---------

Co-authored-by: Islon Scherer <islonscherer@gmail.com>
Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
2024-11-04 14:14:19 -08:00
translatenix
3f38173ed5 Update commonmark and test dependencies (#767) 2024-11-01 12:48:01 -07:00
Philip K.F. Hölzenspies
03462fefae Add color to error formatting (#746)
* Add color to error formatting

* Apply suggestions from code review

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

* Address reviewer comments

* Apply suggestions from code review

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

* Define style choices as operations on formatter (abandon semantic API)

* Adjust margin styling

* Review feedback

* Documentation nits

---------

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
2024-11-01 10:02:19 +00:00
Daniel Chao
acd2222534 Polish test result running and reporting (#738)
Changes:
* Move class `TestResults` to package `org.pkl.core`, because it is a public class (it's the result of `Evaluator#evaluateTest`)
* Change examples to treat individual examples as assertions in the same test. Previously, they were considered different tests with an incrementing number. This better aligns with how facts are treated.
* Change `TestResults` to be a record, and introduce builders.
* Remove "module" test result section (it is not really a section).
* Add javadoc to `TestResults`
* Formatting fix: prefix ✍️ emoji just like we do the  and  emojis 
* Consider writing examples as failures, not successes. `pkl test` will exit with code 10 if the only failing tests are due to writing examples.
2024-10-28 21:05:13 -07:00
Josh B
666f8c3939 Implement SPICE-0009 External Readers (#660)
This adds a new feature, which allows Pkl to read resources and modules from external processes.

Follows the design laid out in SPICE-0009.

Also, this moves most of the messaging API into pkl-core
2024-10-28 18:22:14 -07:00
Josh B
069a5d1adc Fix test failures on main (#735) 2024-10-24 11:53:39 +01:00
Javier Maestro
86d870ba09 Improve testing with stats and errors per test section (#498)
* Emojis are moves to the left to be aligned
* A summary line is added with test counts
* Facts and Examples are grouped under their own section
2024-10-23 23:00:35 -07:00
Daniel Chao
5a654e453c Fix formatting issues (#733) 2024-10-23 20:49:16 -07:00
Daniel Chao
ce25cb8ef0 Add analyze imports libs (SPICE-0001) (#695)
This adds a new feature to build a dependency graph of Pkl programs, following the SPICE outlined in https://github.com/apple/pkl-evolution/pull/2.

It adds:
* CLI command `pkl analyze imports`
* Java API `org.pkl.core.Analyzer`
* Pkl stdlib module `pkl:analyze`
* pkl-gradle extension `analyze`

In addition, it also changes the Gradle plugin such that `transitiveModules` is by default computed from the import graph.
2024-10-23 14:36:57 -07:00
Philip K.F. Hölzenspies
eb3891b21f Change license header from doc- to block-comment (#730)
* Change license header from doc to block comment

* Apply fixed license header throughout
2024-10-23 16:02:42 +01:00
translatenix
d271b62543 Update dependencies (#689)
- Update dependencies by deleting lock files and regenerating them with `gw updateDependencyLocks`.
  Deleting lock files avoids strange `some.library:some.older.version=default` entries.
  Most updated dependencies are test dependencies.
- Handle breaking changes in library commonmark.
- Fix test to close PackageServer exactly once.
  This problem surfaced because JUnit 5.11 changed override rules for lifecycle methods,
  resulting in too many instead of too few close() calls.
- Bump msgpack version
- Bump clikt version
- Bump Gradle plugin versions
2024-10-17 09:12:07 -07:00
translatenix
4854027a1a Update Gradle to 8.10.2 (#684)
Verify wrapper JAR according to:
https://docs.gradle.org/current/userguide/gradle_wrapper.html#wrapper_checksum_verification
2024-10-14 22:53:26 -07:00
Daniel Chao
7868d9d9c8 Typecheck Mapping/Listing members lazily (#628)
This changes how the language performs typechecks for mappings and
listings.

Currently, Pkl will shallow-force any Mapping and Listing to check it
the type parameter (e.g. Listing<Person> means each element is checked
to be an instance of Person).

This changes the language to check each member's type when the member
is accessed.

This also adjust test runner to handle thrown errors from within tests.

With the change to make mapping/listing typechecks lazy, we can now
correctly handle thrown errors from within a single test case.

This adjusts the test runner to consider any thrown errors as a failure
for that specific test case.
2024-09-06 15:05:23 -07:00
Daniel Chao
7c4904429f Fix: make Gradle tests compatible with Gradle 8.1 (#610)
The tests were using assignment expressions, a Kotlin compiler feature
only available in Gradle 8.2 and onwards.
2024-08-06 07:55:13 -07:00
Daniel Chao
604b042d1b Make EvalTask track resolved output paths and fix file() notation on Gradle on Windows (#403)
* Add `getEffectiveOutputFiles` and `getEffectiveOutputDirs` to `EvalTask`, and mark them as output files/dirs so they are tracked by Gradle. This enables implicit dependency tracking between two tasks.
* Fix usage of `file()` notation in Gradle scripts when on Windows.
2024-07-25 17:41:03 -07:00
Philip K.F. Hölzenspies
5cc2ea2d00 Revert error coloring (for development on dedicated branch) (#565) 2024-07-03 17:25:06 +01:00
Dan Chao
8c1c10528f Run spotless apply 2024-07-01 09:24:04 -07:00
Thomas Purchas
0d7b95d3ff Add colours to Pkl errors in Cli output
To make error messages from Pkl eval easier to read, this change uses
the Jansi library to colour the output, making it quicker and easier to
scan error messages and understand what's happened.

The Jansi library also detects if the CLI output is a terminal capable
of handling colours, and will automatically strip out escape codes if
the output won't support them (e.g. piping the output somewhere else).
2024-07-01 10:13:16 +01:00
Daniel Chao
f15ad6ec06 Change CLI flag and Gradle name for proxy options (#526)
Rationale: "proxy" can mean very different things (e.g. java.lang.reflect.Proxy in Java).
This makes the flag name more specific.

CLI:
* `--proxy` -> `--http-proxy`
* `--no-proxy` -> `--http-no-proxy`

Gradle:
* `proxyAddress` -> `httpProxy`
* `noProxy` -> `httpNoProxy`
2024-06-14 08:08:21 -07:00
Daniel Chao
380095c8a7 Change Gradle property to "rename" (#528)
This changes the property to match the name of the CLI flag.
2024-06-14 07:36:28 -07:00
Vladimir Matveev
d7a1778199 Allow renaming Java/Kotlin classes/packages during code generation (#499)
Adds a `rename` field to the Java/Kotlin code generators that allows renaming packages and classes during codegen.

* Add `--rename` flag to CLIs
* Add `rename` property to Gradle API
2024-06-12 15:43:43 -07:00
Philip K.F. Hölzenspies
b03530ed1f Add support for HTTP proxying (#506)
* Add `--proxy` and `--no-proxy` CLI flags
* Add property `http` to `pkl:settings`
* Move `EvaluatorSettings` from `pkl:Project` to its own module and add property `http`
* Add support for proxying in server mode, and through Gradle
* Add `setProxy()` to `HttpClient`
* Add documentation
2024-06-12 11:54:22 -07:00