org.fuin.srcgen4j:srcgen4j-core

Source code generation for Java (Core)

License

License

GroupId

GroupId

org.fuin.srcgen4j
ArtifactId

ArtifactId

srcgen4j-core
Last Version

Last Version

0.4.2
Release Date

Release Date

Type

Type

jar
Description

Description

Source code generation for Java (Core)
Project Organization

Project Organization

fuin.org (Germany)
Source Code Management

Source Code Management

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

Download srcgen4j-core

How to add to project

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

Dependencies

compile (11)

Group / Artifact Type Version
com.google.code.findbugs : jsr305 jar 3.0.2
javax.validation : validation-api jar 2.0.1.Final
org.fuin.srcgen4j : srcgen4j-commons jar 0.4.2
org.fuin : objects4j jar 0.6.8
commons-io : commons-io jar 2.6
org.slf4j : slf4j-api jar 1.7.25
org.apache.velocity : velocity Optional jar 1.7
org.eclipse.emf : org.eclipse.emf.ecore Optional jar 2.11.2
org.eclipse.emf : org.eclipse.emf.ecore.change Optional jar 2.11.0
org.eclipse.xtend : org.eclipse.xtend.lib jar 2.12.0
org.eclipse.xtend : org.eclipse.xtend.core jar 2.12.0

test (7)

Group / Artifact Type Version
junit : junit jar 4.12
org.assertj : assertj-core jar 3.10.0
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
org.fuin.xsample : org.fuin.xsample.dsl jar 0.0.1

Project Modules

There are no modules declared in this project.

srcgen4j-core

Source code generation for Java (Core)

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

What is this?

The project provides some parsers and generators based on the (srcgen4j-common) project.

XtextParser

The parser is configured with the path where the model files with a dedicated extension can be found. The setup class attribute is used to instantiate the Xtext) parser itself.

<parser name="ptp" class="org.fuin.srcgen4j.core.xtext.XtextParser">
    <config>
        <xtext:xtext-parser-config modelPath="${testRes}" modelExt="xsdsl"
               setupClass="org.fuin.xsample.XSampleDslStandaloneSetup" />
    </config>
</parser>

A full blown example for the Xtext based DDD DSL can be found here.

EMFGenerator

The EMF generator requires setting up the different artifact factories that generate code for different EMF model elements.

<generator name="gen1" class="org.fuin.srcgen4j.core.emf.EMFGenerator" parser="ptp" project="current">
    <config>
        <emf:emf-generator-config>
            <emf:artifact-factory artifact="abstractHello" class="org.fuin.srcgen4j.core.emf.AbstractHelloTstGen">
                <variable name="package" value="a.b.c" />
            </emf:artifact-factory>
        </emf:emf-generator-config>
    </config>
    <artifact name="abstractHello" folder="testGenMainJava" />
</generator>

You can also define local variables that will be provided to the artifact factory.

ParameterizedTemplateParser

The parser is configured with the path where the model files can be found.

<parser name="ptp" class="org.fuin.srcgen4j.core.velocity.ParameterizedTemplateParser">
    <config>
        <velo:parameterized-template-parser modelPath="${testRes}" 
                                            modelFilter=".*\.ptg\.xml"
                                            templatePath="${testRes}" 
                                            templateFilter=".*\.ptg\.java" />
    </config>
</parser>

A model element always consists of two parts: An XML definition and a velocity template for code generation.

An example template definition (parameterized-template-1.ptg.xml):

<parameterized-template template="parameterized-template-1.ptg.java" xmlns="http://www.fuin.org/srcgen4j/core/velocity">
    
    <!-- Variables that can be used in the velocity template -->
    
    <arguments>
        <argument key="name" value="-" />
        <argument key="pkg" value="-" />
    </arguments>

    <!-- Files to be generated with constant values for the above defined variables -->
        
    <target-file path="a" name="A.java">
        <argument key="name" value="A" />
        <argument key="pkg" value="a" />
    </target-file>
    
    <target-file path="b" name="B.java">
        <argument key="name" value="B" />
        <argument key="pkg" value="b" />
    </target-file>
    
</parameterized-template>

An example velocity template (parameterized-template-1.ptg.java):

package ${pkg};

public class ${name} {
    // Whatever
}

It's also possible to create the variable values programmatically (See TestTFLProducer):

<parameterized-template template="parameterized-template-2.ptg.java" xmlns="http://www.fuin.org/srcgen4j/core/velocity">
    
    <arguments>
        <argument key="name" value="-" />
        <argument key="pkg" value="-" />
    </arguments>

    <target-file-list-producer class="org.fuin.srcgen4j.core.velocity.TestTFLProducer" />
    
</parameterized-template>

ParameterizedTemplateGenerator

The generator is simply configured with the path to the to the velocity templates (See topic Resource Management / file.resource.loader.path). xxx

<generator name="gen1" class="org.fuin.srcgen4j.core.velocity.ParameterizedTemplateGenerator" 
           parser="ptp" project="current" folder="testJava">
    <config>
        <velo:parameterized-template-generator templatePath="${testRes}" />
    </config>
    <artifact name="file" />
</generator>

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