Skip to content

Commit

Permalink
replace bash script with jbang
Browse files Browse the repository at this point in the history
  • Loading branch information
liweinan committed Mar 18, 2021
1 parent cc1effa commit 2d8084b
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 10 deletions.
38 changes: 35 additions & 3 deletions docbook/pom.xml
Expand Up @@ -10,6 +10,11 @@
<packaging>jdocbook</packaging>
<name>RESTEasy Reference Guide (${translation})</name>
<description/>
<properties>
<jbang.ver>0.45.0</jbang.ver>
<translation>en-US</translation>
</properties>

<repositories>
<repository>
<id>jboss</id>
Expand Down Expand Up @@ -124,10 +129,37 @@
</environmentVariables>
</configuration>
</plugin>
<plugin>
<groupId>dev.jbang</groupId>
<artifactId>jbang-maven-plugin</artifactId>
<version>0.0.4</version>
<executions>
<execution>
<id>run</id>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<jbangVersion>${jbang.ver}</jbangVersion>
<script>scripts/before.java</script>
</configuration>
</execution>
<execution>
<id>cleanup</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<jbangVersion>${jbang.ver}</jbangVersion>
<script>scripts/after.java</script>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<properties>
<translation>en-US</translation>
</properties>

</project>
33 changes: 33 additions & 0 deletions docbook/scripts/after.java
@@ -0,0 +1,33 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class after {
public static void main(String[] args) throws Exception {
Path path = Paths.get("reference/en/en-US/modules/RESTEasy_Spring_Integration.xml");
Charset charset = StandardCharsets.UTF_8;
String content = new String(Files.readAllBytes(path), charset);
String token = "_SPRING_VER_";
String ver = getVer();

// restore
content = content.replaceAll(ver, token);
Files.write(path, content.getBytes(charset));
}

public static String getVer() throws Exception {
Path path = Paths.get("../resteasy-dependencies-bom/pom.xml");
Charset charset = StandardCharsets.UTF_8;

String content = new String(Files.readAllBytes(path), charset);

Pattern pattern = Pattern.compile("<version\\.org\\.springframework>(.*)</version\\.org\\.springframework>");
Matcher matcher = pattern.matcher(content);
matcher.find();
return matcher.group(1);
}
}
36 changes: 36 additions & 0 deletions docbook/scripts/before.java
@@ -0,0 +1,36 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class before {

public static void main(String... args) throws Exception {
String ver = getVer();

Path path = Paths.get("reference/en/en-US/modules/RESTEasy_Spring_Integration.xml");
Charset charset = StandardCharsets.UTF_8;

String content = new String(Files.readAllBytes(path), charset);

String token = "_SPRING_VER_";

content = content.replaceAll(token, ver);
Files.write(path, content.getBytes(charset));
}

public static String getVer() throws Exception {
Path path = Paths.get("../resteasy-dependencies-bom/pom.xml");
Charset charset = StandardCharsets.UTF_8;

String content = new String(Files.readAllBytes(path), charset);

Pattern pattern = Pattern.compile("<version\\.org\\.springframework>(.*)</version\\.org\\.springframework>");
Matcher matcher = pattern.matcher(content);
matcher.find();
return matcher.group(1);
}
}
7 changes: 0 additions & 7 deletions docbook/scripts/set_spring_dep_ver.sh

This file was deleted.

0 comments on commit 2d8084b

Please sign in to comment.