Skip to content

Commit 531d41e

Browse files
committed
yajsw + izpack + db init etc.
1 parent f93716e commit 531d41e

File tree

32 files changed

+577
-519
lines changed

32 files changed

+577
-519
lines changed

ToDo.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
JavaDoc
22
JUnit
33
Database Initialisierung mit IzPack?
4-
YAJSW - Yet another Java Service Wrapper
4+
YAJSW - Yet another Java Service Wrapper
5+

modctrl-api/pom.xml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0"?>
2-
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
34
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
45
<modelVersion>4.0.0</modelVersion>
56

@@ -45,6 +46,11 @@
4546
<version>${gwtVersion}</version>
4647
<scope>provided</scope>
4748
</dependency>
49+
<dependency>
50+
<groupId>com.h2database</groupId>
51+
<artifactId>h2</artifactId>
52+
<version>1.3.163</version>
53+
</dependency>
4854
</dependencies>
4955

5056
<build>
@@ -82,6 +88,11 @@
8288
<artifactId>groovy-all</artifactId>
8389
<version>1.8.5</version>
8490
</dependency>
91+
<dependency>
92+
<groupId>com.h2database</groupId>
93+
<artifactId>h2</artifactId>
94+
<version>1.3.163</version>
95+
</dependency>
8596
</dependencies>
8697
<executions>
8798
<execution>
@@ -92,6 +103,24 @@
92103
<goal>testCompile</goal>
93104
</goals>
94105
</execution>
106+
<execution>
107+
<id>create inital database file</id>
108+
<phase>process-resources</phase>
109+
<goals>
110+
<goal>execute</goal>
111+
</goals>
112+
<configuration>
113+
<!-- issue with classpath and JDBC Driver / temp usage of plugin dependency section
114+
<classpath>
115+
<element>
116+
<groupId>com.h2database</groupId>
117+
<artifactId>h2</artifactId>
118+
</element>
119+
</classpath>
120+
-->
121+
<source>${pom.basedir}/src/main/groovy/modbus/control/api/db/InitDBScript.groovy</source>
122+
</configuration>
123+
</execution>
95124
</executions>
96125
</plugin>
97126
</plugins>

modctrl-api/src/main/groovy/modbus/control/api/db/GroovySqlQuery.groovy

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import groovy.sql.Sql
1313
* @author ares
1414
*/
1515
class GroovySqlQuery {
16-
private static def db = [url:'jdbc:h2:~/wagocontrol', user:'sa', password:'12qwertz.-', driver:'org.h2.Driver']
1716
private static def categoryQueryAll = "SELECT * FROM CATEGORYS"
1817
private static def varQueryByCategory = "SELECT * FROM MODBUS_DIGITAL WHERE CATEGORY = ?"
1918
private static def plcQueryById = "SELECT * FROM MODBUS_PLCS WHERE ID = ?"
@@ -58,15 +57,4 @@ class GroovySqlQuery {
5857
}
5958
vars
6059
}
61-
62-
static void main(String[] args) {
63-
def sql = Sql.newInstance(db.url, db.user, db.password, db.driver)
64-
65-
sql.eachRow(categoryQueryAll) { row -> println row.name }
66-
67-
def c = new Category()
68-
c.setId(1)
69-
70-
println getVars(sql, c)
71-
}
7260
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
6+
package modbus.control.api.db
7+
8+
import groovy.sql.Sql
9+
10+
def database = System.getProperty("user.dir") + "\\src\\main\\resources\\db"
11+
if(!new File(database).exists()) {
12+
database = System.getProperty("user.dir") + "\\modctrl-api\\src\\main\\resources\\db\\wagocontrol"
13+
} else {
14+
database += "\\wagocontrol"
15+
}
16+
17+
if(!(new File(database + ".h2.db")).exists()) {
18+
def db = [url:"jdbc:h2:$database", user:'sa', password:'12qwertz.-', driver:'org.h2.Driver']
19+
def sql = Sql.newInstance(db.url, db.user, db.password, db.driver)
20+
21+
def scriptfile = System.getProperty("user.dir") + "\\src\\main\\resources\\db_init.sql"
22+
23+
sql.execute("RUNSCRIPT FROM '$scriptfile'")
24+
}

modctrl-api/src/main/java/modbus/control/api/db/JDBCQuery.java

Lines changed: 0 additions & 84 deletions
This file was deleted.
Binary file not shown.

modctrl-api/src/main/java/modbus/control/api/db/db_init.sql renamed to modctrl-api/src/main/resources/db_init.sql

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
DROP TABLE CATEGORYS;
2-
DROP TABLE MODBUS_PLCS;
3-
DROP TABLE MODBUS_DIGITAL;
1+
--DROP TABLE CATEGORYS;
2+
--DROP TABLE MODBUS_PLCS;
3+
--DROP TABLE MODBUS_DIGITAL;
44

55
--Initial
6-
76
CREATE TABLE CATEGORYS (ID INT PRIMARY KEY, NAME VARCHAR(100) UNIQUE);
87

98
CREATE TABLE MODBUS_PLCS (ID INT PRIMARY KEY, NAME VARCHAR(100) UNIQUE, IP VARCHAR(100) UNIQUE, PORT INT);
@@ -15,7 +14,6 @@ ALTER TABLE MODBUS_DIGITAL ADD CONSTRAINT MODBUS_ID_PLCS FOREIGN KEY (PLC) REFER
1514
-- Wago Starterkit! INSERT INTO MODBUS_PLCS (ID , NAME, IP, PORT) VALUES (1, 'Wago Starterkit', '192.168.1.55', 502);
1615

1716
--Initialisierung HPC
18-
1917
INSERT INTO MODBUS_PLCS (ID , NAME, IP, PORT) VALUES (1, 'HV2', '10.1.220.2', 502);
2018

2119
--UV1
@@ -100,7 +98,6 @@ INSERT INTO MODBUS_DIGITAL (ID, NAME, DESCRIPTION, CATEGORY, PLC, MODBUSADDR) VA
10098
INSERT INTO MODBUS_DIGITAL (ID, NAME, DESCRIPTION, CATEGORY, PLC, MODBUSADDR) VALUES (41, '%MX3.4', '(Raum 1.13)', 24, 4, 12340);
10199
INSERT INTO MODBUS_DIGITAL (ID, NAME, DESCRIPTION, CATEGORY, PLC, MODBUSADDR) VALUES (42, '%MX3.5', 'Aussenwerbung', 25, 4, 12341);
102100

103-
104101
--UV4
105102
INSERT INTO MODBUS_PLCS (ID , NAME, IP, PORT) VALUES (5, 'UV4', '10.1.220.6', 502);
106103

modctrl-api/src/main/resources/log4j.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
</layout>
88
</appender>
99
<appender name="util" class="org.apache.log4j.FileAppender">
10-
<param name="File" value="D:\\dev\\Test.log" />
10+
<param name="File" value="C:\\ModbusControl\\logs\\modctrl.log" />
1111
<param name="Append" value="true" />
1212
<layout class="org.apache.log4j.PatternLayout">
1313
<param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/>
1414
</layout>
1515
</appender>
1616
<root>
1717
<priority value="debug"></priority>
18-
<appender-ref ref="stdout"/>
18+
<appender-ref ref="util"/>
1919
</root>
2020
</log4j:configuration>

modctrl-app/pom.xml

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<properties>
2121
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2222
<staging.dir>${project.build.directory}/staging</staging.dir>
23+
<installer.dir>${project.build.directory}/installer</installer.dir>
2324
<izpack-standalone.version>4.3.5</izpack-standalone.version>
2425
<jna.version>3.3.0</jna.version>
2526
</properties>
@@ -152,9 +153,25 @@
152153
</dependency>
153154
</dependencies>
154155

155-
156156
<build>
157-
<plugins>
157+
<plugins>
158+
<!-- Example for executing a Java Class between the build <plugin>
159+
<groupId>org.codehaus.mojo</groupId>
160+
<artifactId>exec-maven-plugin</artifactId>
161+
<version>1.1.1</version>
162+
<executions>
163+
<execution>
164+
<id>init</id>
165+
<phase>package</phase>
166+
<goals>
167+
<goal>java</goal>
168+
</goals>
169+
<configuration>
170+
<mainClass>modbus.control.api.db.InitDB</mainClass>
171+
</configuration>
172+
</execution>
173+
</executions>
174+
</plugin> -->
158175
<!-- IzPack -->
159176
<!-- copy other checked resource into staging area, expected by install.xml -->
160177
<plugin>
@@ -180,7 +197,11 @@
180197
<copy todir="${staging.dir}/ModbusControl/lib"> <!-- " ${project.build.directory}/dependency" -->
181198
<fileset dir="${basedir}/lib" />
182199
</copy>
183-
200+
<!-- copy Database File to Staging -->
201+
<copy todir="${staging.dir}/ModbusControl/db"> <!-- " ${project.build.directory}/dependency" -->
202+
<fileset dir="${basedir}/../modctrl-api/src/main/resources/db" />
203+
</copy>
204+
<mkdir dir="${staging.dir}/ModbusControl/logs"/>
184205
<copy todir="C:/ModbusControl"> <!-- " ${project.build.directory}/dependency" -->
185206
<fileset dir="${staging.dir}/ModbusControl" />
186207
</copy>
@@ -203,12 +224,12 @@
203224
<configuration>
204225
<stripVersion>true</stripVersion>
205226
<excludeGroupIds>org.codehaus.izpack</excludeGroupIds>
206-
<outputDirectory>${staging.dir}/ModbusControl/lib<!-- ${project.build.directory}/dependency --></outputDirectory>
227+
<outputDirectory>${staging.dir}/ModbusControl/lib<!-- ${project.build.directory}/dependency -->
228+
</outputDirectory>
207229
</configuration>
208230
</execution>
209231
</executions>
210232
</plugin>
211-
212233
<!-- see install.xml to see how MyHelloPanel is used -->
213234
<plugin>
214235
<groupId>org.codehaus.izpack</groupId>
@@ -228,13 +249,44 @@
228249
<executions>
229250
<execution>
230251
<id>standard-installer</id>
231-
<phase>install</phase>
252+
<phase>verify</phase>
232253
<goals>
233254
<goal>izpack</goal>
234255
</goals>
235256
</execution>
236257
</executions>
237258
</plugin>
238-
</plugins>
259+
<!-- make an .exe from izpack installer -->
260+
<plugin>
261+
<groupId>org.bluestemsoftware.open.maven.plugin</groupId>
262+
<artifactId>launch4j-plugin</artifactId>
263+
<version>1.5.0.0</version>
264+
<executions>
265+
<execution>
266+
<id>launch4j</id>
267+
<phase>install</phase>
268+
<goals>
269+
<goal>launch4j</goal>
270+
</goals>
271+
<configuration>
272+
<dontWrapJar>false</dontWrapJar>
273+
<headerType>gui</headerType>
274+
<outfile>${project.build.directory}/modctrl-install.exe</outfile>
275+
<jar>${project.build.directory}/modctrl-app-0.0.1-SNAPSHOT-standard.jar</jar>
276+
<errTitle>ModCtrl</errTitle>
277+
<jre>
278+
<minVersion>1.6.0</minVersion>
279+
</jre>
280+
<splash>
281+
<file>${pom.basedir}/src/main/resources/splash.bmp</file>
282+
<waitForWindow>true</waitForWindow>
283+
<timeout>60</timeout>
284+
<timeoutErr>false</timeoutErr>
285+
</splash>
286+
</configuration>
287+
</execution>
288+
</executions>
289+
</plugin>
290+
</plugins>
239291
</build>
240292
</project>

0 commit comments

Comments
 (0)