Skip to content

Commit 6237413

Browse files
authored
feat: add auto-generated enums for HIPO schema (#1205)
* add script to generate enums from bank schema * add resulting enums * cleanup * update package name * update bank package path * remove auto-generated bank schema enums * rename * remove auto-generated bank enums (again?) * gitignore auto-generated bank enums * add schema-enum-cleaning to mvn clean * add bank schema enum generation to maven validation phase * switch to single underscore * move enum build to clas-io
1 parent dfd1905 commit 6237413

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ target
66
/docs/javadoc/*
77
/clara-home
88
tmp
9+
/common-tools/clas-io/src/main/java/org/jlab/io/banks
910

1011
# deployment
1112
/myLocalMvnRepo
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
import os,glob,json
3+
top = os.path.normpath(os.path.dirname(os.path.abspath(__file__))+'/../..')
4+
idir = 'etc/bankdefs/hipo4'
5+
odir = 'common-tools/clas-io/src/main/java/org/jlab/io/banks'
6+
print(f'INFO: Creating schema enums at {odir}')
7+
os.makedirs(f'{top}/{odir}', exist_ok=True)
8+
for x in glob.glob(f'{top}/{idir}/*.json'):
9+
for bank in json.load(open(x,'r')):
10+
class_name = bank['name'].replace('::','_').replace(':','_')
11+
with open(f'{top}/{odir}/{class_name}.java','w') as f:
12+
f.write('package org.jlab.io.banks;\n')
13+
f.write(f'public class {class_name} {{\n')
14+
for i,entry in enumerate(bank['entries']):
15+
var_name = entry['name']
16+
f.write(f' public static final short {var_name} = {i};\n')
17+
f.write('}\n')
18+
f.close()

‎common-tools/clas-io/pom.xml‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,45 @@
5555

5656
</dependencies>
5757

58+
<build>
59+
<plugins>
60+
<plugin>
61+
<groupId>org.apache.maven.plugins</groupId>
62+
<artifactId>maven-antrun-plugin</artifactId>
63+
<version>3.1.0</version>
64+
<executions>
65+
<execution>
66+
<id>bank-schema-enums</id>
67+
<phase>validate</phase>
68+
<goals>
69+
<goal>run</goal>
70+
</goals>
71+
<inherited>false</inherited>
72+
<configuration>
73+
<target>
74+
<exec executable="python3">
75+
<arg value="./bank-schema-enums"/>
76+
</exec>
77+
</target>
78+
</configuration>
79+
</execution>
80+
</executions>
81+
</plugin>
82+
<plugin>
83+
<artifactId>maven-clean-plugin</artifactId>
84+
<version>3.4.0</version>
85+
<configuration>
86+
<filesets>
87+
<fileset>
88+
<directory>src/main/java/org/jlab/io/banks</directory>
89+
<includes>
90+
<include>**/*.java</include>
91+
</includes>
92+
</fileset>
93+
</filesets>
94+
</configuration>
95+
</plugin>
96+
</plugins>
97+
</build>
98+
5899
</project>

0 commit comments

Comments
 (0)