Skip to content

Commit ea7df4d

Browse files
author
Daniel Henrique Alves Lima
committed
A better way of changing Config.groovy.
1 parent c3e2705 commit ea7df4d

12 files changed

+108
-74
lines changed

hibernate-spatial-hdb/HibernateSpatialHdbGrailsPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @author Daniel Henrique Alves Lima
1919
*/
2020
class HibernateSpatialHdbGrailsPlugin {
21-
def version = "0.0.3"
21+
def version = "0.0.4"
2222
// the version or versions of Grails the plugin is designed for
2323
def grailsVersion = "1.2.0 > *"
2424
// the other plugins this plugin depends on
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#Grails Metadata file
2-
#Mon Sep 26 14:35:27 BRT 2011
3-
app.grails.version=1.3.7
4-
app.name=hibernate-spatial-hdb
5-
plugins.hibernate=1.3.7
6-
plugins.hibernate-spatial=0.0.3
7-
plugins.plugin-config=0.1.5
8-
plugins.tomcat=1.3.7
1+
#Grails Metadata file
2+
#Tue Sep 27 19:46:22 BRT 2011
3+
app.grails.version=1.3.7
4+
app.name=hibernate-spatial-hdb
5+
plugins.hibernate=1.3.7
6+
plugins.hibernate-spatial=0.0.4
7+
plugins.plugin-config=0.1.5
8+
plugins.tomcat=1.3.7

hibernate-spatial-mysql/HibernateSpatialMysqlGrailsPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class HibernateSpatialMysqlGrailsPlugin {
2121
// the plugin version
22-
def version = "0.0.3"
22+
def version = "0.0.4"
2323
// the version or versions of Grails the plugin is designed for
2424
def grailsVersion = "1.2.0 > *"
2525
// the other plugins this plugin depends on
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#Grails Metadata file
2-
#Mon Sep 26 14:37:32 BRT 2011
3-
app.grails.version=1.3.7
4-
app.name=hibernate-spatial-mysql
5-
plugins.hibernate=1.3.7
6-
plugins.hibernate-spatial=0.0.3
7-
plugins.plugin-config=0.1.5
8-
plugins.tomcat=1.3.7
1+
#Grails Metadata file
2+
#Tue Sep 27 20:18:55 BRT 2011
3+
app.grails.version=1.3.7
4+
app.name=hibernate-spatial-mysql
5+
plugins.hibernate=1.3.7
6+
plugins.hibernate-spatial=0.0.4
7+
plugins.plugin-config=0.1.5
8+
plugins.tomcat=1.3.7

hibernate-spatial-oracle/HibernateSpatialOracleGrailsPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class HibernateSpatialOracleGrailsPlugin {
2121
// the plugin version
22-
def version = "0.0.3"
22+
def version = "0.0.4"
2323
// the version or versions of Grails the plugin is designed for
2424
def grailsVersion = "1.2.0 > *"
2525
// the other plugins this plugin depends on
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#Grails Metadata file
2-
#Mon Sep 26 14:38:40 BRT 2011
3-
app.grails.version=1.3.7
4-
app.name=hibernate-spatial-oracle
5-
plugins.hibernate=1.3.7
6-
plugins.hibernate-spatial=0.0.3
7-
plugins.plugin-config=0.1.5
8-
plugins.tomcat=1.3.7
1+
#Grails Metadata file
2+
#Tue Sep 27 20:19:05 BRT 2011
3+
app.grails.version=1.3.7
4+
app.name=hibernate-spatial-oracle
5+
plugins.hibernate=1.3.7
6+
plugins.hibernate-spatial=0.0.4
7+
plugins.plugin-config=0.1.5
8+
plugins.tomcat=1.3.7

hibernate-spatial-postgresql/HibernateSpatialPostgresqlGrailsPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class HibernateSpatialPostgresqlGrailsPlugin {
2121
// the plugin version
22-
def version = "0.0.3"
22+
def version = "0.0.4"
2323
// the version or versions of Grails the plugin is designed for
2424
def grailsVersion = "1.2.0 > *"
2525
// the other plugins this plugin depends on
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#Grails Metadata file
2-
#Mon Sep 26 14:03:47 BRT 2011
3-
app.grails.version=1.3.7
4-
app.name=hibernate-spatial-postgresql
5-
plugins.hibernate=1.3.7
6-
plugins.hibernate-spatial=0.0.3
7-
plugins.plugin-config=0.1.5
8-
plugins.tomcat=1.3.7
1+
#Grails Metadata file
2+
#Tue Sep 27 20:19:24 BRT 2011
3+
app.grails.version=1.3.7
4+
app.name=hibernate-spatial-postgresql
5+
plugins.hibernate=1.3.7
6+
plugins.hibernate-spatial=0.0.4
7+
plugins.plugin-config=0.1.5
8+
plugins.tomcat=1.3.7

hibernate-spatial-sqlserver/HibernateSpatialSqlserverGrailsPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class HibernateSpatialSqlserverGrailsPlugin {
2121
// the plugin version
22-
def version = "0.0.3"
22+
def version = "0.0.4"
2323
// the version or versions of Grails the plugin is designed for
2424
def grailsVersion = "1.2.0 > *"
2525
// the other plugins this plugin depends on
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#Grails Metadata file
2-
#Mon Sep 26 14:41:20 BRT 2011
3-
app.grails.version=1.3.7
4-
app.name=hibernate-spatial-sqlserver
5-
plugins.hibernate=1.3.7
6-
plugins.hibernate-spatial=0.0.3
7-
plugins.plugin-config=0.1.5
8-
plugins.tomcat=1.3.7
1+
#Grails Metadata file
2+
#Tue Sep 27 20:20:15 BRT 2011
3+
app.grails.version=1.3.7
4+
app.name=hibernate-spatial-sqlserver
5+
plugins.hibernate=1.3.7
6+
plugins.hibernate-spatial=0.0.4
7+
plugins.plugin-config=0.1.5
8+
plugins.tomcat=1.3.7

hibernate-spatial/HibernateSpatialGrailsPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class HibernateSpatialGrailsPlugin {
2121
// the plugin version
22-
def version = "0.0.3"
22+
def version = "0.0.4"
2323
// the version or versions of Grails the plugin is designed for
2424
def grailsVersion = "1.2.0 > *"
2525
// the other plugins this plugin depends on

hibernate-spatial/scripts/_HibernateSpatialInstall.groovy

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ _hibernateSpatialUpdateConfig = {Map dataSourceOptions = [:] ->
3535
File configDir = new File(grailsSettings.baseDir, '/grails-app/conf/')
3636
File configFile = new File(configDir, 'Config.groovy')
3737

38+
Set geometryClasses = new LinkedHashSet()
39+
for (geometry in ['Geometry',
40+
'GeometryCollection', 'LineString', 'Point', 'Polygon',
41+
'MultiLineString', 'MultiPoint', 'MultiPolygon',
42+
'LinearRing', 'Puntal', 'Lineal', 'Polygonal']) {
43+
geometryClasses << "com.vividsolutions.jts.geom.${geometry}".toString()
44+
}
45+
46+
3847
if (configFile.exists()) {
3948
try {
4049
Closure printUserTypes = {writer, String indentation = '' ->
41-
for (geometry in ['Geometry',
42-
'GeometryCollection', 'LineString', 'Point', 'Polygon',
43-
'MultiLineString', 'MultiPoint', 'MultiPolygon',
44-
'LinearRing', 'Puntal', 'Lineal', 'Polygonal']) {
45-
writer.println("${indentation}\'user-type\'(type:org.hibernatespatial.GeometryUserType, class:com.vividsolutions.jts.geom.${geometry})")
50+
for (geometryClass in geometryClasses) {
51+
writer.println("${indentation}\'user-type\'(type:org.hibernatespatial.GeometryUserType, class:${geometryClass})")
4652
}
4753
}
4854

@@ -53,30 +59,58 @@ _hibernateSpatialUpdateConfig = {Map dataSourceOptions = [:] ->
5359
boolean fileChanged = false
5460

5561
Pattern userTypePattern = Pattern.compile('.*["\']user-type["\'].*')
56-
Pattern geometryTypePattern = Pattern.compile('.*\\W*GeometryUserType\\W*.*')
57-
newConfigFile.withPrintWriter {writer ->
58-
configFile.eachLine {line ->
59-
if (userTypePattern.matcher(line).matches()) {
60-
foundDefaultMapping = foundDefaultMapping || true
61-
if (!foundGeometryType) {
62-
if (!geometryTypePattern.matcher(line).matches()) {
63-
writer.println(' /* Added by the Hibernate Spatial Plugin. */')
64-
printUserTypes(writer, ' ')
65-
fileChanged = true
62+
Pattern geometryTypePattern = Pattern.compile('.*class\\s*:\\s*([A-Za-z\\.]+).*')
63+
List userTypeLines = []
64+
65+
newConfigFile.withPrintWriter {writer ->
66+
configFile.withReader {reader ->
67+
String line = null
68+
69+
while ((line = reader.readLine()) != null) {
70+
if (!foundDefaultMapping) {
71+
while (line != null && userTypePattern.matcher(line).matches()) {
72+
userTypeLines << line
73+
line = reader.readLine()
6674
}
67-
foundGeometryType = true
68-
}
69-
}
70-
writer.println(line)
71-
}
72-
73-
if (!foundDefaultMapping) {
74-
writer.println('/* Added by the Hibernate Spatial Plugin. */')
75-
writer.println('grails.gorm.default.mapping = {')
76-
printUserTypes(writer, ' ')
77-
writer.println('}')
78-
fileChanged = true
79-
}
75+
76+
if (userTypeLines.size() > 0) {
77+
for (userTypeLine in userTypeLines) {
78+
Matcher matcher = geometryTypePattern.matcher(userTypeLine)
79+
if (matcher.matches()) {
80+
String geometryClass = matcher.replaceAll('$1')
81+
//println "geometryClass ${geometryClass}"
82+
geometryClasses.remove(geometryClass)
83+
84+
}
85+
}
86+
87+
println "geometryClasses ${geometryClasses}"
88+
if (geometryClasses.size() > 0) {
89+
writer.println(' /* Added by the Hibernate Spatial Plugin. */')
90+
printUserTypes(writer, ' ')
91+
92+
for (userTypeLine in userTypeLines) {
93+
writer.println(userTypeLine)
94+
}
95+
userTypeLines.clear()
96+
fileChanged = true
97+
}
98+
99+
foundDefaultMapping = true
100+
}
101+
}
102+
103+
writer.println(line)
104+
}
105+
106+
if (!foundDefaultMapping) {
107+
writer.println('/* Added by the Hibernate Spatial Plugin. */')
108+
writer.println('grails.gorm.default.mapping = {')
109+
printUserTypes(writer, ' ')
110+
writer.println('}')
111+
fileChanged = true
112+
}
113+
}
80114
}
81115

82116
if (!fileChanged) {

0 commit comments

Comments
 (0)