Skip to content

Commit 4b46560

Browse files
committed
Make a runnable jar so the tool can be used independently to generate entities
1 parent bd438e2 commit 4b46560

File tree

2 files changed

+71
-39
lines changed

2 files changed

+71
-39
lines changed

pom.xml

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
<maven.compiler.target>17</maven.compiler.target>
1717
<maven.version>3.9.1</maven.version>
1818
<maven.plugin.tools.version>3.8.2</maven.plugin.tools.version>
19-
<logback.version>1.2.3</logback.version>
19+
<logback.version>1.2.9</logback.version>
20+
<maven.assembly.plugin.version>3.6.0</maven.assembly.plugin.version>
2021
</properties>
2122

2223
<dependencies>
24+
<!-- Maven plugin dependencies -->
2325
<dependency>
2426
<groupId>org.apache.maven</groupId>
2527
<artifactId>maven-plugin-api</artifactId>
@@ -81,7 +83,6 @@
8183
<version>${logback.version}</version>
8284
</dependency>
8385

84-
8586
<!-- lombok -->
8687
<dependency>
8788
<groupId>org.projectlombok</groupId>
@@ -112,43 +113,65 @@
112113
</dependencies>
113114

114115
<build>
115-
<pluginManagement>
116-
<plugins>
117-
<plugin>
118-
<groupId>org.apache.maven.plugins</groupId>
119-
<artifactId>maven-plugin-plugin</artifactId>
120-
<version>3.7.1</version>
121-
<executions>
122-
<execution>
123-
<id>help-mojo</id>
124-
<goals>
125-
<!-- good practice is to generate help mojo for plugin -->
126-
<goal>helpmojo</goal>
127-
</goals>
128-
</execution>
129-
</executions>
130-
</plugin>
131-
<plugin>
132-
<groupId>org.codehaus.mojo</groupId>
133-
<artifactId>build-helper-maven-plugin</artifactId>
134-
<version>3.2.0</version>
135-
<executions>
136-
<execution>
137-
<id>add-source</id>
138-
<phase>generate-sources</phase>
139-
<goals>
140-
<goal>add-source</goal>
141-
</goals>
142-
<configuration>
143-
<sources>
144-
<source>target/generated-sources/sqlscript2jpa/src/main/java/</source>
145-
</sources>
146-
</configuration>
147-
</execution>
148-
</executions>
149-
</plugin>
150-
</plugins>
151-
</pluginManagement>
116+
<plugins>
117+
<plugin>
118+
<groupId>org.apache.maven.plugins</groupId>
119+
<artifactId>maven-plugin-plugin</artifactId>
120+
<version>3.7.1</version>
121+
<executions>
122+
<execution>
123+
<id>help-mojo</id>
124+
<goals>
125+
<!-- good practice is to generate help mojo for plugin -->
126+
<goal>helpmojo</goal>
127+
</goals>
128+
</execution>
129+
</executions>
130+
</plugin>
131+
<plugin>
132+
<groupId>org.codehaus.mojo</groupId>
133+
<artifactId>build-helper-maven-plugin</artifactId>
134+
<version>3.2.0</version>
135+
<executions>
136+
<execution>
137+
<id>add-source</id>
138+
<phase>generate-sources</phase>
139+
<goals>
140+
<goal>add-source</goal>
141+
</goals>
142+
<configuration>
143+
<sources>
144+
<source>target/generated-sources/sqlscript2jpa/src/main/java/</source>
145+
</sources>
146+
</configuration>
147+
</execution>
148+
</executions>
149+
</plugin>
150+
<plugin>
151+
<groupId>org.apache.maven.plugins</groupId>
152+
<artifactId>maven-assembly-plugin</artifactId>
153+
<version>${maven.assembly.plugin.version}</version>
154+
<configuration>
155+
<descriptorRefs>
156+
<descriptorRef>jar-with-dependencies</descriptorRef>
157+
</descriptorRefs>
158+
<archive>
159+
<manifest>
160+
<mainClass>org.ngbsn.generator.JPACodeGenerator</mainClass>
161+
</manifest>
162+
</archive>
163+
</configuration>
164+
<executions>
165+
<execution>
166+
<id>make-assembly</id>
167+
<phase>package</phase>
168+
<goals>
169+
<goal>single</goal>
170+
</goals>
171+
</execution>
172+
</executions>
173+
</plugin>
174+
</plugins>
152175
</build>
153176

154177
</project>

src/main/java/org/ngbsn/generator/JPACodeGenerator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.slf4j.LoggerFactory;
1111

1212
import java.io.*;
13+
import java.nio.charset.StandardCharsets;
1314
import java.nio.file.Files;
1415
import java.nio.file.Paths;
1516
import java.util.*;
@@ -20,6 +21,14 @@
2021
public class JPACodeGenerator {
2122
private static final Logger logger = LoggerFactory.getLogger(JPACodeGenerator.class);
2223

24+
public static void main(String[] args) throws TemplateException, IOException {
25+
String sqlScript = new BufferedReader(
26+
new InputStreamReader(new FileInputStream(args[0]), StandardCharsets.UTF_8))
27+
.lines()
28+
.collect(Collectors.joining("\n"));
29+
generateCode(sqlScript, args[1]);
30+
}
31+
2332
public static void generateCode(final String sqlScript, final String packageName) throws IOException, TemplateException {
2433
logger.info("sql script {}", sqlScript);
2534
List<Table> tables = generateModels(sqlScript);

0 commit comments

Comments
 (0)