MCPcopy Index your code
hub / github.com/KyoriPowered/blossom

github.com/KyoriPowered/blossom @v2.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.2.0 ↗ · + Follow
174 symbols 343 edges 34 files 51 documented · 29%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

blossom Build Status License Gradle Plugin

blossom is a Gradle plugin for processing source templates to resources and sources across several languages. It is licensed under the LGPL v2.1 license.

Usage

Apply the plugin to your project. Blossom requires a minimum of Java 11. It is tested with the latest revision of the current major release of Gradle, and the latest revision of the previous major release of Gradle, but we focus our development time on newer Gradle versions.

plugins {
  id("net.kyori.blossom") version "2.1.0"
}

Blossom adds the blossom extension on every source set, allowing the configuration of templating for that source set. No template sets are enabled by default.

Both file names and source files can be templated as desired, using the Pebble templating language.

Resource templating

Call the resources() method on the blossom extension to start applying resource templates:

version = "1.4.0-SNAPSHOT"

sourceSets {
  main {
    blossom {
      resources {
        property("version", project.version.toString())
      }
    }
  }
}

[!IMPORTANT] When processing templates, Pebble will trim newlines immediately after a template tag. This might not be desired when using formats like YAML or Java properties files, so Blossom offers a way to disable this behaviour:

Add a trimNewlines = false line to the template set block and stripping will be disabled for any templates in the set.

Then place a file in the src/main/resource-templates folder:

build-vars.properties:

version={{ version }}

When the project is built, the build-vars.properties file will be processed into the final resource:

version=1.4.0-SNAPSHOT

Source templating

Source templating works similarly, though there is a bit of added complexity due to supporting multiple JVM languages:

build.gradle.kts:

sourceSets {
  main {
    blossom {
      javaSources {
        property("version", project.version.toString())
        property("gitCommit", indraGit.commit.map { it.name() }.orNull())
        property("decompilerVersion", libs.versions.vineflower.get())
      }
    }
  }
}

src/main/java-templates/net/kyori/blossomtest/BuildParameters.java.peb:

package net.kyori.blossomtest;

class BuildParameters {
    public static final String VERSION = "{{ version }}";
    public static final String GIT_COMMIT = "{{ gitCommit | default("unknown") }}";
    public static final String DECOMPILER_VERSION = "{{ decompilerVersion }}";
}

The BuildParameters class will be processed and available to other files being compiled.

Variants and parameter files, oh my!

While templates on their own allow generating quite a bit, Blossom adds an extra layer of power with variants. Each template set can have either the default variant, or several named variants, which produce output from the same template but different variables as input. When combined with templated file names, this allows generating a whole lot of different source files from one input (for example, when working with java primitives).

Properties themselves and property files can be set both for each template set individually, and per-variant.

As an example:

build.gradle.kts:

sourceSets {
  main {
    blossom {
      javaSources {
        propertyFile("template-vars.yaml")
        variants("float", "int", "double")
      }
    }
  }
}

template-vars.yaml:

type: potato # shared across variants

# variants key has a special meaning if multiple variants exist - each subkey should match the name of one variant.
# the values under each variant are 
variants:
  float:
    suffix: "f"
    wrapper: "Float"
  int:
    suffix: ""
    wrapper: "Integer"
  double:
    suffix: "d"
    wrapper: "Double"

This will process all templates three times, once for each variant -- so a src/main/java-templates/{{ wrapper }}Box.java.peb would produce three class files:

  • FloatBox.java
  • IntegerBox.java
  • DoubleBox.java

Template parameters set from different sources (via the DSL) will override each other, inheriting in the following order (where the last element in the list takes priority):

  • Default properties provided by Blossom
  • variant: provides the variant name as a parameter (only present in named variant mode)
  • Template set, defined in a set property file
  • Template set, defined in-buildscript
  • Variant, defined in global files
  • Variant, defined in the variant-specific property files
  • Variant, defined in-buildscript

IDE Integration

On first import into an IDE, you may have to run the generateTemplates task to ensure templates have been generated. For some common IDEs, we hook into the IDE's refresh system in order to

Eclipse

In Eclipse, this task is registered as a "synchronization" task, which will update templates every time the project is synced with Gradle.

IntelliJ

For IntelliJ integration, also add the org.jetbrains.gradle.plugin.idea-ext plugin, and Blossom will automatically configure the appropriate post-import hooks. Eclipse integration requires no other plugins.

There is some IDE support for the Pebble syntax. An IntelliJ plugin exists, though it does little more than syntax highlighting.

IntelliJ also has a setting that attempts to highlight template files as Java source files (available under Preferences > Languages & Frameworks > Template Data Languages). This option is of varying effectiveness depending on the source file.

Others

On other IDEs, there is no current support, but we are open to adding such support if there's a way -- open an issue if you use an IDE with such facilities that is not yet supported.

Extension points exported contracts — how you extend this code

TemplateSetInternal (Interface)
Internal hooks for template sets. [3 implementers]
src/main/java/net/kyori/blossom/internal/TemplateSetInternal.java
GenerateWorkerInvoker (Interface)
(no doc) [3 implementers]
src/workerShared/java/net/kyori/blossom/internal/worker/GenerateWorkerInvoker.java
Variant (Interface)
Template variant. Composed of: Name: used to map values from properties file Source fi [1 implementers]
src/main/java/net/kyori/blossom/Variant.java
BlossomExtension (Interface)
Templating that applies to a specific source set. Each template set registered will by default read templates from { [1 …
src/main/java/net/kyori/blossom/BlossomExtension.java
SourceTemplateSet (Interface)
A template set for sources. @since 2.0.0 [1 implementers]
src/main/java/net/kyori/blossom/SourceTemplateSet.java
ResourceTemplateSet (Interface)
A template set type targeting resources. @since 2.0.0 [1 implementers]
src/main/java/net/kyori/blossom/ResourceTemplateSet.java

Core symbols most depended-on inside this repo

getBaseSet
called by 10
src/main/java/net/kyori/blossom/GenerateTemplates.java
getName
called by 8
src/main/java/net/kyori/blossom/Variant.java
name
called by 7
src/workerShared/java/net/kyori/blossom/internal/worker/TemplateParams.java
data
called by 5
src/workerShared/java/net/kyori/blossom/internal/worker/TemplateParams.java
getTemplates
called by 4
src/main/java/net/kyori/blossom/TemplateSet.java
getSourceDirectories
called by 4
src/main/java/net/kyori/blossom/internal/worker/GenerateWorker.java
getDestinationDirectory
called by 4
src/main/java/net/kyori/blossom/internal/worker/GenerateWorker.java
toPaths
called by 4
src/main/java/net/kyori/blossom/internal/worker/GenerateWorker.java

Shape

Method 141
Class 23
Interface 9
Function 1

Languages

Java99%
Kotlin1%

Modules by API surface

src/main/java/net/kyori/blossom/internal/worker/GenerateWorker.java16 symbols
src/main/java/net/kyori/blossom/TemplateSet.java14 symbols
src/workerClasspath/java/net/kyori/blossom/internal/worker/MultiDirectoryLoader.java11 symbols
src/main/java/net/kyori/blossom/BlossomExtension.java11 symbols
src/main/java/net/kyori/blossom/internal/TemplateSetImpl.java10 symbols
src/workerClasspath/java/net/kyori/blossom/internal/worker/GenerateWorkerInvokerImpl.java9 symbols
src/main/java/net/kyori/blossom/internal/IdeConfigurer.java9 symbols
src/main/java/net/kyori/blossom/GenerateTemplates.java9 symbols
src/main/java/net/kyori/blossom/internal/SourceTemplateSetImpl.java8 symbols
src/main/java/net/kyori/blossom/internal/FileUtils.java8 symbols
src/main/java/net/kyori/blossom/Blossom.java7 symbols
src/workerClasspath/java/net/kyori/blossom/internal/worker/PropertyFileIO.java6 symbols

For agents

$ claude mcp add blossom \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact