Skip to content

Commit

Permalink
2023.11.378
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Nov 7, 2023
1 parent 2e4db3d commit 0ed2c03
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 5 deletions.
9 changes: 7 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#!/usr/bin/env bash
bDATE=$(date '+%Y%m%d%H%M%S')
bDIR=$(dirname $0)
bDIR=$(cd $bDIR && pwd)
yDATE=$(date '+%Y')
mDATE=$(date '+%-m')
bDIR=$(cd $(dirname $0) && pwd)

#OPTS="-DskipTests=true -DproxySet=true -DproxyHost=127.0.0.1 -DproxyPort=3128 -Dhttps.nonProxyHosts=127.0.0.1"
OPTS="-DskipTests=true"

while test ! -z "$1" ; do
case "$1" in
-drel*)
(cd $bDIR && mvn -X build-helper:parse-version versions:set \
-DnewVersion="${yDATE}.${mDATE}.\${parsedVersion.nextIncrementalVersion}" ) || exit 1
;;
-setversion*)
VALUE="${2}"
(cd $bDIR && mvn build-helper:parse-version versions:set \
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

<groupId>com.github.terefang.template</groupId>
<artifactId>template</artifactId>
<version>2022.8.377</version>
<version>2023.11.378</version>
<modules>
<module>template-cli</module>
<module>template-maven-plugin</module>
<module>preproc-maven-plugin</module>
</modules>

<packaging>pom</packaging>
Expand Down
94 changes: 94 additions & 0 deletions preproc-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>template</artifactId>
<groupId>com.github.terefang.template</groupId>
<version>2023.11.378</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>preproc-maven-plugin</artifactId>

<packaging>maven-plugin</packaging>

<dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.5.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${maven.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<!-- <goalPrefix>maven-archetype-plugin</goalPrefix> -->
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<phase>prepare-package</phase>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
<execution>
<id>help-goal</id>
<phase>prepare-package</phase>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
package com.github.terefang.preproc_maven_plugin;

import lombok.Data;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;

import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;

@Mojo(name = "pre-processor", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
@Data
public class PreProcessorMojo extends AbstractMojo
{
@Parameter(defaultValue = "${project.build.scriptSourceDirectory}")
protected File resourcesDirectory;

@Parameter(defaultValue = "${project.build.directory}/generated-resources")
protected File resourcesOutput;

@Parameter(defaultValue = "false")
private boolean singleFileOutput;

@Parameter(defaultValue = "false")
private boolean flattenOutput;

@Parameter(defaultValue = ".txt")
private String destinationExtension;

@Parameter(defaultValue = "false")
private boolean processSingleLineMarker;

@Parameter(defaultValue = "false")
private boolean processIncludes;

@Parameter(defaultValue = "MARK")
private String marker;

@Parameter
private String includes;

@Parameter
private String excludes;

@Override
public void execute() throws MojoExecutionException, MojoFailureException
{
DirectoryScanner scanner = new DirectoryScanner();

if( resourcesDirectory.isDirectory())
{
scanner.setBasedir(resourcesDirectory);
if (StringUtils.isNotEmpty(includes)) {
scanner.setIncludes(StringUtils.split(includes));
} else {
scanner.setIncludes(new String[]{"**/*"});
}

if (StringUtils.isNotEmpty(excludes)) {
scanner.setExcludes(StringUtils.split(excludes));
}

scanner.addDefaultExcludes();
scanner.scan();

process(scanner.getIncludedFiles());
}
else
if( resourcesDirectory.isFile())
{
process(new String[]{ resourcesDirectory.getPath() });
}
}

public void process(String[] includedFiles)
{
includedFiles = Arrays.stream(includedFiles)
.sorted((x,y) -> { return x.compareToIgnoreCase(y); })
.toArray((x) -> { return new String[x]; });
File file = null;
PrintWriter out = null;
String _current = null;
try
{
if(singleFileOutput)
{
file = resourcesOutput;
file.getParentFile().mkdirs();
out = new PrintWriter(file);
}

for (String key : includedFiles)
{
this.getLog().info("processing: "+key);
_current = key;
String keybase = key.substring(0, key.lastIndexOf("."));
if(!singleFileOutput)
{
file = new File(resourcesOutput, keybase.concat(destinationExtension));
if(flattenOutput)
{
file = new File(resourcesOutput, file.getName());
}
file.getParentFile().mkdirs();
out = new PrintWriter(file);
}

File localFile = new File(resourcesDirectory, key);

resolveAndWrite(localFile.getParentFile(), localFile, out);

if(!singleFileOutput)
{
out.close();
}
}

if(singleFileOutput)
{
out.close();
}
}
catch (Exception _xe)
{
this.getLog().error((_current!=null ? _current+": " : "")+_xe.getMessage(), _xe);
}
}

public void resolveAndWrite(File _parent, File _file, PrintWriter _out) throws IOException
{
ArrayDeque<BufferedReader> _queue = new ArrayDeque<>();
_queue.add(new BufferedReader(new FileReader(_file)));
ArrayDeque<File> _dirs = new ArrayDeque<>();
_dirs.add(_parent);

while(_queue.size()>0)
{
BufferedReader _lr = _queue.poll();
File _bd = _dirs.poll();

String _line = "";
boolean _in=false;
while((_line = _lr.readLine()) != null)
{
if(_line.startsWith("%!end "))
{
if(this.marker.equalsIgnoreCase(_line.substring(6).trim()))
{
_in=false;
}
}
else
if(_in)
{
_out.println(_line);
}
else
if(_line.startsWith("%!begin "))
{
if(this.marker.equalsIgnoreCase(_line.substring(8).trim()))
{
_in=true;
}
}
else
if(_line.startsWith("%!include ") && processIncludes)
{
_queue.push(_lr);
_dirs.push(_bd);
File _next = new File(_bd, _line.substring(10).trim());
this.getLog().info("including: "+_next.getName());
_bd = _next.getParentFile();
_lr = new BufferedReader(new FileReader(_next));
}
else
if(_line.startsWith("%% ") && processSingleLineMarker)
{
_out.println(_line.substring(3));
}
else
if(_line.equalsIgnoreCase("%%") && processSingleLineMarker)
{
_out.println();
}

}
_out.flush();
IOUtil.close(_lr);
}
}
}
2 changes: 1 addition & 1 deletion template-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>template</artifactId>
<groupId>com.github.terefang.template</groupId>
<version>2022.8.377</version>
<version>2023.11.378</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion template-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>template</artifactId>
<groupId>com.github.terefang.template</groupId>
<version>2022.8.377</version>
<version>2023.11.378</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down

0 comments on commit 0ed2c03

Please sign in to comment.