-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert-packages.sh
executable file
·58 lines (48 loc) · 2.47 KB
/
convert-packages.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# INTERNALS
OPENCYPHER_DIR="org/opencypher/v9_0"
OPENCYPHER_PACKAGE=`echo $OPENCYPHER_DIR | sed "s|/|.|g"`
NEO4J_DIR_PREFIX="org/neo4j/cypher/internal"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
OPENCYPHER_LICENSE="$DIR/opencypher-license.txt"
# Go through all relevant folders
for d in ast ast-factory cypher-macros expressions frontend javacc-parser neo4j-ast-factory rewriting util test-util; do
for use in main test; do
for lang in java scala; do
sourceDir="$d/src/$use/$lang"
if [ -d $sourceDir ]; then
neo4jDir="$NEO4J_DIR_PREFIX"
neo4jPackage=`echo $neo4jDir | sed "s|/|.|g"`
if [ -d $sourceDir/$neo4jDir ]; then
# Move the files to the right place
mkdir -p "$sourceDir/$OPENCYPHER_DIR"
rm -r "$sourceDir/$OPENCYPHER_DIR"
mv "$sourceDir/$neo4jDir" "$sourceDir/$OPENCYPHER_DIR"
# For all .java/.scala files:
for sourceFile in `find "$sourceDir/$OPENCYPHER_DIR" -type f -name "*.$lang"`; do
# change to open cypher packages
cat "$sourceFile" | sed "s/$neo4jPackage/$OPENCYPHER_PACKAGE/g" > "$sourceFile.temp"
# add open cypher license
cat $OPENCYPHER_LICENSE > "$sourceFile"
# copy in rest of code, but omitting any previous license
sed -n '/package /,$p' "$sourceFile.temp" >> "$sourceFile"
rm "$sourceFile.temp"
done
# Special handling for *.jj files
for jjFile in `find "$sourceDir/$OPENCYPHER_DIR" -type f -name "*.jj"`; do
# change to open cypher package
cat "$jjFile" | sed "s/$neo4jPackage/$OPENCYPHER_PACKAGE/g" > "$jjFile.temp"
# copy in all code up until the search string (i.e. before the Neo4j license)
searchString="PARSER_BEGIN"
sed -n "1,/${searchString}/p" "$jjFile.temp" > "$jjFile"
# insert the open cypher license
cat $OPENCYPHER_LICENSE >> "$jjFile"
# copy in the rest of the code
sed -n '/package /,$p' "$jjFile.temp" >> "$jjFile"
rm "$jjFile.temp"
done
fi
fi
done
done
done