Skip to content

Commit

Permalink
half done Java DSL and plural macro
Browse files Browse the repository at this point in the history
  • Loading branch information
verhas committed Jan 26, 2024
1 parent f34c067 commit aadc9ed
Show file tree
Hide file tree
Showing 40 changed files with 1,895 additions and 134 deletions.
2 changes: 1 addition & 1 deletion README.jrf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is a Jamal reference file containing serialized base64 encoded macros
# Created: 2023-12-27 19:49:51 +0100
# Created: 2024-01-26 12:29:48 +0100
# id|openStr|closeStr|verbatim|tailParameter|pure|content|parameters
# TOC
VE9D|eyU=|JX0=|0|0|0|Ci4gPDxJbnN0YWxsYXRpb24+PgouIDw8R1M+PgouIDw8Q29uZmlndXJhdGlvbj4+Ci4gPDxGZWF0dXJlcz4+Ci4gPDxDb250cmlidXRpbmc+PgouIDw8RG9jdW1lbnRhdGlvbj4+Ci4gPDxMaWNlbnNlPj4KLiA8PENoYW5nZWxvZz4+Ci4gPDxSb2FkbWFwPj4KLiA8PFN1cHBvcnQ+PgouIDw8RkFRPj4KLiA8PE1haW50ZW5hbmNlPj4=|
1 change: 1 addition & 0 deletions RELEASES.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* `import` has a new parop `global` that makes the import global and mot imported again even if the file was imported from a local scope
* `import` does not import a file again if it has the same content as an already imported file.
Until now, different files with the same content could be imported parallel.
* Snippet library has a new macro `plural` that can be used to pluralize a word.
* Bugfix invoking macro close for AutoCloseable macros that need processor and output.
* Module plantUML was removed from the development.
This module is not supported anymore.
Expand Down
1 change: 1 addition & 0 deletions RELEASES.adoc.jam
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* `import` has a new parop `global` that makes the import global and mot imported again even if the file was imported from a local scope
* `import` does not import a file again if it has the same content as an already imported file.
Until now, different files with the same content could be imported parallel.
* Snippet library has a new macro `plural` that can be used to pluralize a word.
* Bugfix invoking macro close for AutoCloseable macros that need processor and output.
* Module plantUML was removed from the development.
This module is not supported anymore.
Expand Down
673 changes: 673 additions & 0 deletions jamal-java/src/main/resources/maven-4.0.0.xsd

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions jamal-java/src/main/resources/pom.jim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static javax0.jamal.java.TextTags.*
〔#define [pure] precode=
try {
final var project = new MyPom();
return project.build();
return project.doit();
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -27,7 +27,7 @@ static javax0.jamal.java.TextTags.*
super("〔@pos (top format=%f)〕");
}

private String build() throws Exception {
private String doit() throws Exception {
〔@define [pure] postcode=
return format();
Expand Down
63 changes: 63 additions & 0 deletions jamal-java/src/test/jamal/Pom.java.jam
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{%@comment nosave%}
{%#java:insert to="../java/javax0/jamal/java/Pom.java" segment="text_tags"
{%!@for $TAG in (modelVersion,groupId,artifactId,version,packaging,name,description,url,inceptionYear)=
public void $TAG(String $TAG) {
project.add("$TAG", $TAG);
}
%}\
%}\
{%#java:insert to="../java/javax0/jamal/java/Pom.java" segment="typed_tags"
{%!@for $TAG in (parent,organization,prerequisites,issueManagement,ciManagement,distributionManagement,dependencyManagement,build,reporting)=
{%#define $CLASS={%#case:upper {%@string:substring (begin=0 end=1) $TAG%}%}{%@string:substring (begin=1) $TAG%}%}\
public {%$CLASS%} $TAG() {
var $TAG = project.get({%$CLASS%}.class, "$TAG");
if ($TAG != null) {
return $TAG;
}
$TAG = new {%$CLASS%}();
project.add("$TAG", $TAG);
return $TAG;
}
%}
%}

{%#java:insert to="../java/javax0/jamal/java/DependencyManagement.java" wholeFile
package javax0.jamal.java;
import static javax0.jamal.java.Xml.path;
public class DependencyManagement extends Xml {


public DependencyManagement dependency(CharSequence... dependencies) {
for (var dependency : dependencies) {
if (!(dependency instanceof Dependency)) {
dependency = Dependency.dependency(dependency);
}
add("dependencies", dependency);
}
return this;
}
}

%}
{%#java:insert to="../java/javax0/jamal/java/Build.java" wholeFile
package javax0.jamal.java;
public class Build extends Xml {

{%!@for $TAG in (sourceDirectory,scriptSourceDirectory,testSourceDirectory,outputDirectory,testOutputDirectory,extensions )=
public void $TAG(String $TAG) {
add("$TAG", $TAG);
}
%}\

public Build extensions(CharSequence... extensions) {
for (var extension : extensions) {
if (!(extension instanceof Extension)) {
extension = Extension.extension(extension);
}
add("extensions", extension);
}
return this;
}
}

%}
35 changes: 31 additions & 4 deletions jamal-java/src/test/java/javax0/jamal/java/Build.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
package javax0.jamal.java;
public class Build extends Xml {

public class Build {

private final Xml project;
public void sourceDirectory(String sourceDirectory) {
add("sourceDirectory", sourceDirectory);
}

public void scriptSourceDirectory(String scriptSourceDirectory) {
add("scriptSourceDirectory", scriptSourceDirectory);
}

public void testSourceDirectory(String testSourceDirectory) {
add("testSourceDirectory", testSourceDirectory);
}

public Build(Xml project) {
this.project = project;
public void outputDirectory(String outputDirectory) {
add("outputDirectory", outputDirectory);
}

public void testOutputDirectory(String testOutputDirectory) {
add("testOutputDirectory", testOutputDirectory);
}

public void extensions (String extensions ) {
add("extensions ", extensions );
}

public Build extensions(CharSequence... extensions) {
for (var extension : extensions) {
if (!(extension instanceof Extension)) {
extension = Extension.extension(extension);
}
add("extensions", extension);
}
return this;
}
}

4 changes: 4 additions & 0 deletions jamal-java/src/test/java/javax0/jamal/java/CiManagement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package javax0.jamal.java;

public class CiManagement extends Xml {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package javax0.jamal.java;
import static javax0.jamal.java.Xml.path;
public class DependencyManagement extends Xml {


public DependencyManagement dependency(CharSequence... dependencies) {
for (var dependency : dependencies) {
if (!(dependency instanceof Dependency)) {
dependency = Dependency.dependency(dependency);
}
add("dependencies", dependency);
}
return this;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package javax0.jamal.java;

public class DistributionManagement extends Xml {
}
45 changes: 45 additions & 0 deletions jamal-java/src/test/java/javax0/jamal/java/Extension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package javax0.jamal.java;

public class Extension extends Xml {

public Extension() {
super("dependency");
}

private Extension(CharSequence coordinate) {
this();
final var coords = ((String) coordinate).split(":");
if (coords.length > 0 && !coords[0].isEmpty()) {
groupId(coords[0]);
}
if (coords.length > 1 && !coords[1].isEmpty()) {
artifactId(coords[1]);
}
if (coords.length > 2 && !coords[2].isEmpty()) {
version(coords[2]);
}
}

public static Extension extension(CharSequence coordinates) {
return new Extension(coordinates);
}

public static Extension extension() {
return new Extension();
}

public Extension groupId(CharSequence groupId) {
add(path("extension", "groupId"), groupId);
return this;
}

public Extension artifactId(CharSequence artifactId) {
add(path("extension", "artifactId"), artifactId);
return this;
}

public Extension version(CharSequence version) {
add(path("extension", "version"), version);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package javax0.jamal.java;

public class IssueManagement extends Xml {
}
Loading

0 comments on commit aadc9ed

Please sign in to comment.