{"id":21387206,"url":"https://github.com/sshtools/codeswitcher-maven-plugin","last_synced_at":"2025-03-16T12:20:56.055Z","repository":{"id":57727243,"uuid":"43007332","full_name":"sshtools/codeswitcher-maven-plugin","owner":"sshtools","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-26T10:45:36.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-23T00:13:33.563Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sshtools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-09-23T14:48:33.000Z","updated_at":"2022-02-19T15:58:13.000Z","dependencies_parsed_at":"2024-11-22T12:12:14.869Z","dependency_job_id":"e9d722bc-6bf2-4d8a-9585-9b368a910899","html_url":"https://github.com/sshtools/codeswitcher-maven-plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshtools%2Fcodeswitcher-maven-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshtools%2Fcodeswitcher-maven-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshtools%2Fcodeswitcher-maven-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshtools%2Fcodeswitcher-maven-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sshtools","download_url":"https://codeload.github.com/sshtools/codeswitcher-maven-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243865533,"owners_count":20360460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T12:12:10.301Z","updated_at":"2025-03-16T12:20:56.034Z","avatar_url":"https://github.com/sshtools.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# codeswitcher-maven-plugin\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.sshtoosl/codeswitcher-maven-plugin/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.sshtools/codeswitcher-maven-plugin/)\n\nA simple pre-processor plugin for Maven that can adjust Java source, removing or inserting blocks of code depending on simple boolean conditions, or replacing any strings (not just variable patterns). \n\nIt is based on HSQLDB's `CodeSwitcher` class, turned into a Maven plugin and a couple of extra features added.\n\nPS. Do not use this plugin, there are probably other ways to achieve your goal. \n\n## Requirements\n\n * Maven 3.6.3 or above\n * Java 1.8 or above\n \n## Installation\n \nAdd to the `\u003cplugins\u003e` section.\n\n```xml\n\t\u003cpluginManagement\u003e\n\t\t\u003cplugin\u003e\n\t        \u003cgroupId\u003ecom.sshtools\u003c/groupId\u003e\n\t        \u003cartifactId\u003ecodeswitcher-maven-plugin\u003c/artifactId\u003e\n\t        \u003c!-- Use the latest released version: https://repo1.maven.org/maven2/com/sshttols/codeswitcher-maven-plugin/ --\u003e\n\t        \u003cversion\u003eLATEST_VERSION\u003c/version\u003e\n\t    \u003c/plugin\u003e\n\t\u003c/pluginManagement\u003e\n```\n\n## Usage\n\nTo make use of this plugin you will :-\n\n * Edit your Java source to add the required directives and tokens.\n * Edit your POM, configuring the plugin with the used directives and tokens.\n\n### Source\n\n#### Conditional Blocks\n\nYou can include (enable) or exclude (disable) blocks using the `ifdef` directive, terminated by an `endif`. An optional `else` directive also may be used.\n\nDirectives are introduced as single line comments where the first character is a `#`. \n\n```java\n\t//#ifdef LICENSE_CHECKS\n\t/*\n\t\tFile f = new File(\"myapp.lic\");\n\t\tLicense l = new License(f);\n\t\tl.verify();\n\t\tSystem.out.println(\"Valid license.\");\n\t*/\n\t//#else\n\t\tSystem.out.println(\"This build does not require a license.\");\n\t//#endif\n```\n\nThe `ifdef` directive works by adding or removing comment characters in the final source. 3 different styles of commenting are recognised. In addition to the style above, you can also use :-\n\n```java\n\t//#ifdef LICENSE_CHECKS\n\t//\n\t// your code \n\t//\n\t//#else\n\t.. your other code\n\t//#endif\n```\n\n.. or ..\n\n```java\n\t//#ifdef LICENSE_CHECKS\n\t/*\n\t * your code \n\t */\n\t//#else\n\t.. your other code\n\t//#endif\n```\n\nThe above example requires that you add an `\u003cenable\u003e` with a value of `LICENSE_CHECKS` to the plugin `\u003cconfiguration\u003e` in your POM. \n\n*Single Line Directives* may be used. These are introduced using the following.\n\n```java\n\t//#[LICENSE_CHECKS] System.out.println(\"This app will require a license\");\n```\n\nA final special directive, `del` may be added to entirely remove blocks of code using the same format. \n\n#### Replacement\n\nSimple string replacement just replaces any text with another piece of text determined at build time. In the example below, the `\u003cconfiguration\u003e` tag in your POM will have a `\u003ctoken\u003e` that specifies a `\u003ckey\u003e` of `SOFTWARE_VERSION` with a value of `${project.version}` which will expand to the project version.\n\n```java\n\tString version = \"SOFTWARE_VERSION\"\n```\n\n#### Timestamp\n\nA special token may be specified that is set to the current timestamp. In the example below, the `\u003cconfiguration\u003e` tag in your POM will have `\u003ctimestampToken\u003e` set to `/* RELEASE_DATE */`.\n\n```java\n\tData r = new Date(/* RELEASE_DATE */);\n```\n\n### Running Automatically On Every Build\n\nAdd to `\u003cplugins\u003e` section, bind to the `pre-process` goal on the `generate-sources` phase and add required configuration. \n\n```xml\n\t\u003cplugin\u003e\n        \u003cgroupId\u003ecom.sshtools\u003c/groupId\u003e\n        \u003cartifactId\u003ecodeswitcher-maven-plugin\u003c/artifactId\u003e\n        \u003cexecutions\u003e\n\t\t\t\u003cexecution\u003e\n\t\t\t\t\u003cid\u003eenterprise-build\u003c/id\u003e\n\t\t\t\t\u003cphase\u003egenerate-sources\u003c/phase\u003e\n\t\t\t\t\u003cgoals\u003e\n\t\t\t\t\t\u003cgoal\u003epre-process\u003c/goal\u003e\n\t\t\t\t\u003c/goals\u003e\n\t\t\t\t\u003cconfiguration\u003e\n\t\t\t\t\t\u003c!-- When set, the new source code will be set as the main source directory for the built. workOnCopy must also be true --\u003e\n\t\t\t\t\t\u003cchangeBuildSourceDirectory\u003etrue\u003c/changeBuildSourceDirectory\u003e\n\t\t\t\t\t\n\t\t\t\t\t\u003c!--  The temporary directory to write the pre-processed files to when workOnCopy is set to true (the default). --\u003e\n\t\t\t\t\t\u003ctemporaryDirectory\u003etarget/preprocessed\u003c/temporaryDirectory\u003e\n\t\t\t\t\t\n\t\t\t\t\t\u003c!-- When set, code will be commented out rather than stripped out --\u003e\n\t\t\t\t\t\u003ccomment\u003efalse\u003c/comment\u003e\n\t\t\t\t\t\n\t\t\t\t\t\u003c!-- When set, the goal will run on a copy of the source. --\u003e\n\t\t\t\t\t\u003cworkOnCopy\u003etrue\u003c/workOnCopy\u003e\n\t\t\t\t\t\n\t\t\t\t\t\u003c!-- Special token that gets replaced with the current timestamp --\u003e\n\t\t\t\t\t\u003ctimestampToken\u003e/* RELEASE_DATE */\u003c/timestampToken\u003e\n\t\t\t\t\t\n\t\t\t\t\t\u003c!-- List of 'token's consisting of a 'key' and 'value'. Every\n\t\t\t\t\t     occurrence of 'key' is replaced with 'value'. key is a\n\t\t\t\t\t     simple string search. Patterns, regexp's or otherwise are\n\t\t\t\t\t     not supported --\u003e\n\t\t\t\t\t\u003ctokens\u003e\n\t\t\t\t\t\t\u003ctoken\u003e\n\t\t\t\t\t\t\t\u003ckey\u003eSOFTWARE_VERSION\u003c/key\u003e\n\t\t\t\t\t\t\t\u003cvalue\u003eMyApp_${project.version}\u003c/value\u003e\n\t\t\t\t\t\t\u003c/token\u003e\n\t\t\t\t\t\u003c/tokens\u003e\n\t\t\t\t\t\n\t\t\t\t\t\u003c!-- Enable symbols. Any code associated with this symbol\n\t\t\t\t\t     will be uncommented in the pre-processed result --\u003e\n\t\t\t\t\t\u003cenables\u003e\n\t\t\t\t\t\t\u003cenable\u003eLICENSE_CHECKS\u003c/enable\u003e\n\t\t\t\t\t\u003c/enables\u003e\n\t\t\t\t\t\n\t\t\t\t\t\u003c!-- Disable symbols. Any code associated with this symbol\n\t\t\t\t\t     will be commented in the pre-processed result --\u003e\n\t\t\t\t\t\u003cdisables\u003e\n\t\t\t\t\t\t\u003cdisable\u003ePRODUCTION\u003c/disable\u003e\n\t\t\t\t\t\u003c/disables\u003e\n\t\t\t\t\u003c/configuration\u003e\n\t\t\t\u003c/execution\u003e\n\t\t\u003c/executions\u003e\n    \u003c/plugin\u003e\n```\n\nThen any Maven compilation will pre-process any source in `src/main/java` into `target/preprocessed`, which will then be used to compile.\n\n```\nmvn clean compile\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshtools%2Fcodeswitcher-maven-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsshtools%2Fcodeswitcher-maven-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshtools%2Fcodeswitcher-maven-plugin/lists"}