org.fuin.srcgen4j:srcgen4j-commons

Source code generation for Java (Commons)

License

License

GroupId

GroupId

org.fuin.srcgen4j
ArtifactId

ArtifactId

srcgen4j-commons
Last Version

Last Version

0.4.2
Release Date

Release Date

Type

Type

jar
Description

Description

Source code generation for Java (Commons)
Project Organization

Project Organization

fuin.org (Germany)
Source Code Management

Source Code Management

https://github.com/fuinorg/srcgen4j-commons/

Download srcgen4j-commons

How to add to project

<!-- https://jarcasting.com/artifacts/org.fuin.srcgen4j/srcgen4j-commons/ -->
<dependency>
    <groupId>org.fuin.srcgen4j</groupId>
    <artifactId>srcgen4j-commons</artifactId>
    <version>0.4.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.fuin.srcgen4j/srcgen4j-commons/
implementation 'org.fuin.srcgen4j:srcgen4j-commons:0.4.2'
// https://jarcasting.com/artifacts/org.fuin.srcgen4j/srcgen4j-commons/
implementation ("org.fuin.srcgen4j:srcgen4j-commons:0.4.2")
'org.fuin.srcgen4j:srcgen4j-commons:jar:0.4.2'
<dependency org="org.fuin.srcgen4j" name="srcgen4j-commons" rev="0.4.2">
  <artifact name="srcgen4j-commons" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.fuin.srcgen4j', module='srcgen4j-commons', version='0.4.2')
)
libraryDependencies += "org.fuin.srcgen4j" % "srcgen4j-commons" % "0.4.2"
[org.fuin.srcgen4j/srcgen4j-commons "0.4.2"]

Dependencies

compile (11)

Group / Artifact Type Version
org.fuin : xmlcfg4j jar 0.2.0
org.fuin : utils4j jar 0.10.0
com.google.code.findbugs : jsr305 jar 3.0.2
javax.validation : validation-api jar 2.0.1.Final
org.slf4j : slf4j-api jar 1.7.25
commons-io : commons-io jar 2.6
org.apache.commons : commons-lang3 jar 3.7
org.fuin : objects4j jar 0.6.8
org.hibernate.validator : hibernate-validator jar 6.0.10.Final
javax.el : javax.el-api jar 3.0.0
org.glassfish : javax.el jar 3.0.0

test (7)

Group / Artifact Type Version
junit : junit jar 4.12
org.assertj : assertj-core jar 3.10.0
xmlunit : xmlunit jar 1.6
org.fuin : units4j jar 0.8.3
com.openpojo : openpojo jar 0.8.10
org.slf4j : slf4j-log4j12 jar 1.7.25
log4j : log4j jar 1.2.17

Project Modules

There are no modules declared in this project.

srcgen4j-commons

Source code generation for Java (Commons)

Build Status Coverage Status Maven Central LGPLv3 License Java Development Kit 1.8

Background

A model driven approach requires almost always generating some code (model to text) or other output. This framework provides an easy way to setup multiple parsers and generators in a single configuration. It allows building a pipeline built on those parsers and generators.

Pipeline

The pipeline is configured using a single XML configuration file:

<srcgen4j-config
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://www.fuin.org/srcgen4j/commons">
    
    <variables />
    <classpath/>
    <projects />
    <parsers />
    <generators />
    
</srcgen4j-config>

There is currently a Maven plugin (srcgen4j-maven) that executes the pipeline during a build or on manually. An Eclipse plugin is planned, but not yet available. There are some predefined parsers and generators abailable in the (srcgen4j-core) project.

Variables

The variables section allows defining globally visible variables.

<variables>
    <variable name="path" value="/var/tmp" />
    <variable name="sub" value="${path}/mypath" />
    <variable name="esacpes" value="\r\n\t" />
    <variable name="res" url="classpath:header.txt" encoding="utf-8" />
</variables>

A variable definition is either a simple name/value combination or an URL that points to the content. Any content type that Java is capable to handle can be used. Additionally the content type "classpath" allows reading files from your classpath. There is a special variable called rootDir that is always available and points to the root directory. In case of a Maven build this is the directory where you executed the 'mvn' command.

Variables can be overwritten in the sub-sections:

<variables>
    <variable name="a" value="/var/tmp" />
</variables>
<parsers>
    <variable name="a" value="${a}/parsers1" />
</parsers>

The result is only visible inside the defining section.

Classpath

The classpath section allows adding additional binary classpaths.

<classpath>
    <bin path="${project_path}/target/classes" />
</classpath>

Projects

A project is used to define the folders where the generated output can be placed.

<projects>
  <project name="myprj" path="." maven="false">
        <folder name="doc" path="doc" create="true" override="true" clean="true" />
  </project>
</projects>

A Maven directory structure is assumed by default. This can be disabled with maven="false".

<project name="myprj" path=".">
    <!-- It's NOT necessary to add the following! It's just to show the default folder structure. -->
    <folder name="mainJava" path="src/main/java" create="false" override="false" clean="false" />
    <folder name="mainRes" path="src/main/resources" create="false" override="false" clean="false" />
    <folder name="genMainJava" path="src-gen/main/java" clean="true" cleanExclude="\..*" />
    <folder name="genMainRes" path="src-gen/main/resources" create="true" clean="true" />
    <folder name="testJava" path="src/test/java" create="false" override="false" clean="false" />
    <folder name="testRes" path="src/test/resources" create="false" override="false" clean="false" />
    <folder name="genTestJava" path="src-gen/test/java" create="true" clean="true" />
    <folder name="genTestRes" path="src-gen/test/resources" create="true" clean="true" />
</project>

A folder is defined by a name that is unique within the project and a path inside the project's directory.

<folder name="mainJava" 
        path="src/main/java" 
        create="false"
        override="false" 
        overrideExclude="[A\.java|B\.java]"
        clean="false"
        cleanExclude="\..*" />

Other attributes that indluence the generation process are:

  • create Create the directory if it does not exist
  • override Override existing files in that directory
  • overrideExclude Regular expression to exclude some files from being overridden.
  • clean All files in the directory will be deleted bevore new ones are created.
  • cleanExclude Regular expression to exclude some files from being deleted.

Parsers

The parsers section defines one or more parsers that are used to create the input models.

<parsers>
    <parser name="dddParser" class="org.fuin.srcgen4j.core.xtext.XtextParser">
        <config>
            <xtext:xtext-parser-config modelPath="src/main/domain" modelExt="ddd"
              setupClass="org.fuin.dsl.ddd.DomainDrivenDesignDslStandaloneSetup" />
        </config>
    </parser>
</parsers>

Every parser has a unique name and a full qualified class name that is used to instantiate the parser (using the default constructor). Some parsers might require a special configuration that can be added in the config section.

Generators

The generator section defines one or more generators that use the input of a parser and write their output to one of the projects.

<generators>
    <generator name="dddGenerator" class="org.fuin.srcgen4j.core.emf.EMFGenerator" parser="dddParser" project="current">
        <config>
            <!-- Generator specific configuration -->
            <emf:artifact-factory artifact="AbstractAggregate" class="org.fuin.dsl.ddd.gen.aggregate.AbstractAggregateArtifactFactory" />
        </config>
        <artifact name="AbstractAggregate" folder="genMainJava" />
        <!-- More artifact definition -->
    </generator>
</generators>

Every generator has a unique name and a full qualified class name that is used to instantiate the generator (using the default constructor). Some generators might require a special configuration that can be added in the config section. A generator creates one or more artifacts that are written to the configured folder of the project.


Snapshots

Snapshots can be found on the OSS Sonatype Snapshots Repository.

Add the following to your .m2/settings.xml to enable snapshots in your Maven build:

<repository>
    <id>sonatype.oss.snapshots</id>
    <name>Sonatype OSS Snapshot Repository</name>
    <url>http://oss.sonatype.org/content/repositories/snapshots</url>
    <releases>
        <enabled>false</enabled>
    </releases>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>
org.fuin.srcgen4j

fuin.org

Versions

Version
0.4.2
0.4.1
0.4.0
0.3.0