{"id":31527157,"url":"https://github.com/mkopylec/source-gen-x","last_synced_at":"2025-10-03T21:58:35.204Z","repository":{"id":30518533,"uuid":"34073019","full_name":"mkopylec/source-gen-x","owner":"mkopylec","description":"A source code and files generator with an intuitive API","archived":false,"fork":false,"pushed_at":"2015-04-20T21:37:02.000Z","size":348,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-01T09:47:15.336Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkopylec.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-16T18:25:38.000Z","updated_at":"2015-04-20T21:37:02.000Z","dependencies_parsed_at":"2022-07-24T16:47:20.137Z","dependency_job_id":null,"html_url":"https://github.com/mkopylec/source-gen-x","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/mkopylec/source-gen-x","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkopylec%2Fsource-gen-x","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkopylec%2Fsource-gen-x/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkopylec%2Fsource-gen-x/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkopylec%2Fsource-gen-x/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkopylec","download_url":"https://codeload.github.com/mkopylec/source-gen-x/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkopylec%2Fsource-gen-x/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278234034,"owners_count":25953075,"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","status":"online","status_checked_at":"2025-10-03T02:00:06.070Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-10-03T21:58:29.979Z","updated_at":"2025-10-03T21:58:35.194Z","avatar_url":"https://github.com/mkopylec.png","language":"Groovy","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Source Gen-X\n[![Build Status](https://travis-ci.org/mkopylec/source-gen-x.svg?branch=master)](https://travis-ci.org/mkopylec/source-gen-x)\n[![Coverage Status](https://coveralls.io/repos/mkopylec/source-gen-x/badge.svg?branch=master)](https://coveralls.io/r/mkopylec/source-gen-x?branch=master)\n\nSource code and files generator with an intuitive API written in Java.\nWith this tool you can create your sources with a minimal learning curve. \n\nThe goal of the project is to create natural, easy to use and self-documented Java API.\n\n## Usage\nEvery class that represents a model of source file is a subclass of `SourceFile`.\nTo create a physical file use `createSourceFile()` method.\nTo create a string representation of file content invoke `toString()`.\nThe generated source code often needs some kind of reformatting.\n\nThe following examples are **not a complete overview** of available methods.\nThey are just a simple demonstration of how to use the Source Gen-X tool.\n\n### Generating a Java class\nCreating a sample main class:\n    \n```java\nConstant constant = new Constant(\"String\", \"GREETING\", \"\\\"Hello World!\\\"\");\n\nMethod main = new Method(AccessModifier.PUBLIC, Modifier.STATIC, \"void\", \"main\")\n        .addParameter(new Parameter(\"String[]\", \"args\"))\n        .setBody(\"\\tSystem.out.println(GREETING);\");\n\nJavaClass mainClass = new JavaClass(\"sourcegenx.demo\", \"Application\")\n        .addField(constant)\n        .addMethod(main);\n\nmainClass.createSourceFile(\"/demo/src/main/java/sourcegenx/demo\");\n```\n    \nOutput Application.java:\n\n    package sourcegenx.demo;\n\n\n    public class Application   {\n\n        public static final String GREETING = \"Hello World!\";\n\n        public static void main(String[] args) {\n    \t    System.out.println(GREETING);\n        }\n    }\n\n### Generating a Java interface\nCreating a sample DAO interface:\n\n```java\nImport imp = new Import(\"sourcegenx.demo.entities.User\");\n       \nInterfaceMethod findMethod = new InterfaceMethod(\"User\", \"findById\")\n        .addParameter(new Parameter(\"long\", \"id\"));\n       \nJavaInterface dao = new JavaInterface(\"sourcegenx.demo\", \"UserDao\u003cUser\u003e\")\n        .addImport(imp)\n        .addMethod(findMethod);\n        \ndao.createSourceFile(\"/demo/src/main/java/sourcegenx/demo\", \"UserDao\");\n```\n        \nOutput UserDao.java:\n\n    package sourcegenx.demo;\n\n    import sourcegenx.demo.entities.User;\n\n    public interface UserDao\u003cUser\u003e  {\n\n\n         User findById(long id);\n    }\n\n### Generating a Java enum\nCreating a sample cardinal directions enum:\n\n```java\nJavaEnum directions = new JavaEnum(\"sourcegenx.demo\", \"CardinalDirection\")\n        .addValue(new EnumValue(\"NORTH\"))\n        .addValue(new EnumValue(\"WEST\"))\n        .addValue(new EnumValue(\"SOUTH\"))\n        .addValue(new EnumValue(\"EAST\"));\n        \ndirections.createSourceFile(\"/demo/src/main/java/sourcegenx/demo\");\n```\n    \nOutput CardinalDirection.java:\n\n    package sourcegenx.demo;\n\n\n    public enum CardinalDirection  {\n\n        NORTH,\n        WEST,\n        SOUTH,\n        EAST;\n\n\n    }\n    \n### Generating a Java annotation\nCreating a sample secured annotation:\n\n```java\nAnnotation target = new Annotation(\"Target\")\n        .addAttribute(\"value\", \"METHOD\");\n\nAnnotation retention = new Annotation(\"Retention\")\n        .addAttribute(\"value\", \"RUNTIME\");\n\nAnnotationElement allowedRoles = new AnnotationElement(\"String[]\", \"allowedRoles\")\n        .setDefaultValue(\"{\\\"ADMIN\\\", \\\"CUSTOMER\\\"}\");\n\nJavaAnnotation secured = new JavaAnnotation(\"sourcegenx.demo\", \"Secured\")\n        .addImport(new Import(\"java.lang.annotation.Retention\"))\n        .addImport(new Import(\"java.lang.annotation.Target\"))\n        .addImport(new Import(Modifier.STATIC, \"java.lang.annotation.ElementType.METHOD\"))\n        .addImport(new Import(Modifier.STATIC, \"java.lang.annotation.RetentionPolicy.RUNTIME\"))\n        .addAnnotation(target)\n        .addAnnotation(retention)\n        .addElement(allowedRoles);\n\nsecured.createSourceFile(\"/demo/src/main/java/sourcegenx/demo\");\n```\n    \nOutput Secured.java:\n\n    package sourcegenx.demo;\n\n    import java.lang.annotation.Retention;\n    import java.lang.annotation.Target;\n    import static java.lang.annotation.ElementType.METHOD;\n    import static java.lang.annotation.RetentionPolicy.RUNTIME;\n\n    @Target(METHOD)\n    @Retention(RUNTIME)\n    public @interface Secured {\n\n        String[] allowedRoles() default {\"ADMIN\", \"CUSTOMER\"};\n    }\n\n### Generating a configuration properties file\nCreating a sample properties file:\n\n```java\nConfigProperties properties = new ConfigProperties()\n        .addProperty(new Property(\"database.name\", \"test\"))\n        .addProperty(new Property(\"database.host\", \"localhost\"));\n\nproperties.createSourceFile(\"/demo/src/main/resources\", \"application\");\n```\n\nOutput application.properties:\n\n    database.name=test\n    database.host=localhost\n\n### Generating a configuration YAML file\nCreating a sample YAML file:\n\n```java\nYamlNode root = new YamlNode(\"root\")\n        .addChild(new YamlNode(\"message.default\").addValue(\"Some message\"))\n        .addChild(new YamlNode(\"message.special\")\n                        .addChild(new YamlNode(\"server\").addValue(\"1\"))\n                        .addChild(new YamlNode(\"client\").addValue(\"2\"))\n        );\n\nConfigYaml yaml = new ConfigYaml().addNode(root);\n\nyaml.createSourceFile(\"/demo/src/main/resources\", \"application\");\n```\n\nOutput application.yaml:\n\n    root:\n      message.default: Some message\n      message.special:\n        server: 1\n        client: 2\n\n## More examples\nSee test specifications for more samples:\n\n- [Java class spec](https://github.com/mkopylec/source-gen-x/blob/master/src/test/groovy/pl/allegro/tech/sourcegenx/core/java/JavaClassSpec.groovy)\n- [Java interface spec](https://github.com/mkopylec/source-gen-x/blob/master/src/test/groovy/pl/allegro/tech/sourcegenx/core/java/JavaInterfaceSpec.groovy)\n- [Java enum spec](https://github.com/mkopylec/source-gen-x/blob/master/src/test/groovy/pl/allegro/tech/sourcegenx/core/java/JavaEnumSpec.groovy)\n- [Java annotation spec](https://github.com/mkopylec/source-gen-x/blob/master/src/test/groovy/pl/allegro/tech/sourcegenx/core/java/JavaAnnotationSpec.groovy)\n- [Config properties spec](https://github.com/mkopylec/source-gen-x/blob/master/src/test/groovy/pl/allegro/tech/sourcegenx/core/config/ConfigPropertiesSpec.groovy)\n- [Config YAML spec](https://github.com/mkopylec/source-gen-x/blob/master/src/test/groovy/pl/allegro/tech/sourcegenx/core/config/ConfigYamlSpec.groovy)\n\n## License\nSource Gen-X is published under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkopylec%2Fsource-gen-x","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkopylec%2Fsource-gen-x","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkopylec%2Fsource-gen-x/lists"}