All Projects → ZacSweers → Redacted Compiler Plugin

ZacSweers / Redacted Compiler Plugin

Licence: apache-2.0
A Kotlin compiler plugin that generates redacted toString() implementations.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Redacted Compiler Plugin

Codec Beam
Generate Erlang VM byte code from Haskell
Stars: ✭ 152 (-9.52%)
Mutual labels:  compiler, codegen
Cranelift
Cranelift code generator
Stars: ✭ 2,485 (+1379.17%)
Mutual labels:  compiler, codegen
Lightbeam
Lightbeam has moved and now lives in the Wasmtime repository!
Stars: ✭ 253 (+50.6%)
Mutual labels:  compiler, codegen
Ebooks
A repository for ebooks, including C, C plus plus, Linux Kernel, Compiler, OS, Algorithm, Security, Database, Network, ML and DL
Stars: ✭ 151 (-10.12%)
Mutual labels:  compiler
Forge
A lightweight, elegant scripting language with built-in Rust-FFI.
Stars: ✭ 153 (-8.93%)
Mutual labels:  compiler
Rhine
🔬 a C++ compiler middle-end, using an LLVM backend
Stars: ✭ 157 (-6.55%)
Mutual labels:  compiler
Ddc
The Disco Discus Compiler
Stars: ✭ 164 (-2.38%)
Mutual labels:  compiler
Xcassetpacker
A command line tool for converting a folder of images into an .xcasset package for Xcode
Stars: ✭ 150 (-10.71%)
Mutual labels:  codegen
Elena Lang
ELENA is a general-purpose language with late binding. It is multi-paradigm, combining features of functional and object-oriented programming. Rich set of tools are provided to deal with message dispatching : multi-methods, message qualifying, generic message handlers, run-time interfaces
Stars: ✭ 161 (-4.17%)
Mutual labels:  compiler
C
Compile and execute C "scripts" in one go!
Stars: ✭ 1,920 (+1042.86%)
Mutual labels:  compiler
Lbac Swift
Let's Build a Compiler by Jack Crenshaw translated to Swift Playgrounds
Stars: ✭ 156 (-7.14%)
Mutual labels:  compiler
Quickjs
QuickJS是一个小型并且可嵌入的Javascript引擎,它支持ES2020规范,包括模块,异步生成器和代理器。
Stars: ✭ 2,199 (+1208.93%)
Mutual labels:  compiler
Bytecode Viewer
A Java 8+ Jar & Android APK Reverse Engineering Suite (Decompiler, Editor, Debugger & More)
Stars: ✭ 12,606 (+7403.57%)
Mutual labels:  compiler
Xstate Codegen
A codegen tool for 100% TS type-safety in XState
Stars: ✭ 158 (-5.95%)
Mutual labels:  codegen
Cs2cpp
C# to C++ transpiler (Cs2Cpp) (Powered by Roslyn)
Stars: ✭ 155 (-7.74%)
Mutual labels:  compiler
One
On-device Neural Engine
Stars: ✭ 162 (-3.57%)
Mutual labels:  compiler
Zydis
Fast and lightweight x86/x86-64 disassembler and code generation library
Stars: ✭ 2,168 (+1190.48%)
Mutual labels:  codegen
Lioness
The Lioness Programming Language
Stars: ✭ 155 (-7.74%)
Mutual labels:  compiler
Eval
Eval is a lightweight interpreter framework written in Swift, evaluating expressions at runtime
Stars: ✭ 157 (-6.55%)
Mutual labels:  compiler
Awesome Machine Learning In Compilers
Must read research papers and links to tools and datasets that are related to using machine learning for compilers and systems optimisation
Stars: ✭ 168 (+0%)
Mutual labels:  compiler

redacted-compiler-plugin

A Kotlin compiler plugin that generates redacted toString() implementations.

Inspired by the auto-value-redacted extension for AutoValue.

Usage

Include the gradle plugin in your project, define a @Redacted annotation, and apply it to any properties that you wish to redact.

@Retention(SOURCE)
@Target(PROPERTY)
annotation class Redacted

data class User(val name: String, @Redacted val phoneNumber: String)

When you call toString() any @Redacted properties are hidden:

User(name=Bob, phoneNumber=██)

If your annotation is applied to the class, then toString() will emit a single replacement string:

@Retention(SOURCE)
@Target(CLASS)
annotation class Redacted

@Redacted
data class SensitiveData(val ssn: String, val birthday: String)
SensitiveData(██)

Installation

Apply the gradle plugin.

plugins {
  id("dev.zacsweers.redacted") version <version>
}

And that's it! The default configuration will add the -annotations artifact (which has a @Redacted annotation you can use) and wire it all automatically. Just annotate what you want to redact.

You can configure custom behavior with properties on the redacted extension.

redacted {
  // Define a custom annotation. The -annotations artifact won't be automatically added to
  // dependencies if you define your own!
  redactedAnnotation = "dev.zacsweers.redacted.annotations.Redacted" // Default

  // Define whether or not this is enabled. Useful if you want to gate this behind a dynamic
  // build configuration.
  enabled = true // Default

  // Define a custom replacement string for redactions.
  replacementString = "██" // Default
}

Android Per-Variant Configuration

If using Android, you can optionally configure the plugin to be applied on a per-variant basis via androidVariantFilter. This is similar to the Android Gradle Plugin's native variantFilter API, except with an overrideEnabled function to override the enabled status and there is no defaultConfig property. If not overridden, the default is to match the redacted extension's value. Other VariantFilter APIs should behave as expected (buildType, flavors, name, etc).

Note: Variants with different enabled values will have to be compiled separately. This is common in most multi-variant projects anyway, but something to be aware of.

redacted {
  enabled = true // Default
  androidVariantFilter {
    // Don't enable on debug
    if (buildType.name == "debug") {
      overrideEnabled(false)
    }
  }
}

Snapshots of the development version are available in Sonatype's snapshots repository.

Caveats

  • Kotlin compiler plugins are not a stable API! Compiled outputs from this plugin should be stable, but usage in newer versions of kotlinc are not guaranteed to be stable.
  • IDE support is not currently possible. See #8.

License

Copyright (C) 2018 Zac Sweers

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].