-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
218 lines (171 loc) · 6.53 KB
/
Makefile
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Mirror for downloading Apache Solr.
SOLR_MIRROR := https://archive.apache.org/dist/lucene/solr
# Use 'schema.xml' if solr will be used to create the core
# Use 'managed-schema' if pre-configuring core
SCHEMA_FILE := managed-schema
#location of default settings files in solr dist
DEFAULT_SETS := server/solr/configsets/_default
PYTHON := python2
# Use latest available version of Solr 4.
SOLR_VERSION := $(shell curl -s $(SOLR_MIRROR)/ | $(PYTHON) get_latest_solr_vers.py)
SOLR_DIST := solr-$(SOLR_VERSION)
INPUTS := $(wildcard specify_exports/*.zip)
COLLECTIONS := $(patsubst specify_exports/%.zip, %, $(INPUTS))
PORTALFILES := $(foreach c, $(COLLECTIONS), build/col/$c/PortalFiles)
WEBAPPS := $(addprefix build/html/, $(COLLECTIONS))
SETTING_TEMPLATES := $(addprefix build/setting_templates/, $(COLLECTIONS))
SOLR_CORES := $(addprefix build/server/solr/, $(COLLECTIONS))
###### Usage Information #####
.PHONY: usage
usage:
@echo Usage:
@echo
@echo make build-all -- Same as build-html build-cores.
@echo make build-html -- Builds the web app part of the web portal.
@echo make build-cores -- Builds the solr cores for all collections.
@echo make load-data -- Loads the collection data into solr.
@echo make load-data-COLLECTION -- Loads the data for COLLECTION into solr.
@echo make force-load-data -- Loads the collection data into solr even if up-to-date.
@echo make force-load-data-COLLECTION -- Loads the data for COLLECTION into solr even if up-to-date.
@echo
@echo The build-all and build-cores targets should only be used when solr is
@echo not running. The build-html and load-data* targets maybe used freely.
@echo All build and load targets will only have effect if there are changes in
@echo the specify_exports or custom_settings directories.
##### Main targets #####
.PHONY: build-all build-cores build-html build-setting-templates load-data
build-all: build-cores build-html build-setting-templates
build-cores: $(SOLR_CORES)
build-html: $(WEBAPPS) build/html/index.html
build-setting-templates: $(SETTING_TEMPLATES)
load-data: $(addprefix load-data-, $(COLLECTIONS))
force-load-data: $(addprefix force-load-data-, $(COLLECTIONS))
##### Cleaning targets #####
.PHONY: clean-all clean-build clean-solr clean-cores clean-html clean-*-html clean-*-core clean-setting-templates
clean-all: clean-build clean-solr
clean-build:
rm -rf build
clean-solr:
rm -rf solr-*
clean-cores:
rm -rf $(SOLR_CORES)
clean-html:
rm -rf build/html
clean-%-html:
rm -rf build/html/$*
clean-%-core:
rm -rf build/server/solr/$*
clean-setting-templates:
rm -rf build/setting-templates
##### Common building steps #####
$(SOLR_DIST).tgz:
@printf "\n\n### Fetching Solr distribution tar ball.\n\n"
wget $(SOLR_MIRROR)/$(SOLR_VERSION)/$@
$(SOLR_DIST): $(SOLR_DIST).tgz
@printf "\n\n### Unpacking Solr distribution.\n\n"
rm -rf $@
tar -zxf $<
touch $@
build: $(SOLR_DIST)
@printf "\n\n### Copying solr to build directory.\n\n"
cp -r $(SOLR_DIST)/ build
$(PYTHON) patch_web_xml.py \
$(SOLR_DIST)/server/solr-webapp/webapp/WEB-INF/web.xml\
> $@/server/solr-webapp/webapp/WEB-INF/web.xml
build/col: | build
@printf "\n\n"
mkdir build/col
.PRECIOUS: build/col/%/PortalFiles
build/col/%/PortalFiles: specify_exports/%.zip | build/col
@printf "\n\n### Extracting $@.\n\n"
unzip -DD -qq -o -d build/col/$* $^
##### Solr core building #####
build/server/solr/%: build/col/%/SolrFldSchema.xml | build
@printf "\n\n### Generating $@.\n\n"
mkdir -p $@/conf $@/data
$(PYTHON) patch_solrconfig_xml.py \
$(SOLR_DIST)/$(DEFAULT_SETS)/conf/solrconfig.xml \
> $@/conf/solrconfig.xml
$(PYTHON) patch_schema_xml.py \
$(SOLR_DIST)/$(DEFAULT_SETS)/conf/$(SCHEMA_FILE) \
build/col/$*/SolrFldSchema.xml \
> $@/conf/$(SCHEMA_FILE)
cp $(SOLR_DIST)/$(DEFAULT_SETS)/conf/protwords.txt $@/conf/
cp $(SOLR_DIST)/$(DEFAULT_SETS)/conf/synonyms.txt $@/conf/
cp $(SOLR_DIST)/$(DEFAULT_SETS)/conf/stopwords.txt $@/conf/
cp -r $(SOLR_DIST)/$(DEFAULT_SETS)/conf/lang/ $@/conf/
echo 'dataDir=data' > $@/core.properties
echo 'name=$*' >> $@/core.properties
echo 'config=conf/solrconfig.xml' >> $@/core.properties
touch $@
build/col/%/SolrFldSchema.xml: build/col/%/PortalFiles
@printf "\n\n### Generating $@.\n\n"
echo '<?xml version="1.0" encoding="UTF-8" ?>' > $@
echo "<fields>" >> $@
cat $</SolrFldSchema.xml >> $@
echo "</fields>" >> $@
##### Website building #####
build/html: | build
@printf "\n\n"
mkdir build/html
build/html/index.html: $(WEBAPPS) | build/html
@printf "\n\n### Generating $@.\n\n"
$(PYTHON) make_toplevel_index.py index_skel.html \
$(addsuffix /resources/config/settings.json, $(WEBAPPS)) \
> $@
build/html/%: build/col/%/PortalFiles custom_settings/%/fldmodel.json custom_settings/%/settings.json | build/html
@printf "\n\n### Generating $@.\n\n"
mkdir -p $@
cp -r PortalApp/* $@
$(PYTHON) make_fldmodel_json.py \
build/col/$*/PortalFiles/*flds.json \
custom_settings/$*/fldmodel.json \
> $@/resources/config/fldmodel.json
$(PYTHON) patch_settings_json.py \
PortalApp/resources/config/settings.json \
custom_settings/$*/settings.json \
$* \
build/col/$*/PortalFiles/*Setting.json \
> $@/resources/config/settings.json
touch $@
custom_settings/%/fldmodel.json:
@printf "\n\n### Generating empty $@.\n\n"
mkdir -p custom_settings/$*
touch $@
custom_settings/%/settings.json:
@printf "\n\n### Generating empty $@.\n\n"
mkdir -p custom_settings/$*
touch $@
##### Loading data #####
.PHONY: load-data-%
load-data-%: build/html/%/load-timestamp.txt ;
.PRECIOUS: build/html/%/load-timestamp.txt
build/html/%/load-timestamp.txt: build/col/%/PortalFiles | build/html/%
@printf "\n\n### Loading data into $*.\n\n"
curl -X POST "http://localhost:8983/solr/$*/update" \
-d '{ "delete": {"query":"*:*"} }' \
-H 'Content-Type: application/json' \
| grep '"status":0'
curl "http://localhost:8983/solr/$*/update/csv?commit=true&encapsulator=\"&escape=\&header=true" \
--data-binary @build/col/$*/PortalFiles/PortalData.csv \
-H 'Content-type:application/csv' \
| grep '"status":0'
date > $@
.PHONY: force-load-data-%
force-load-data-%:
rm -f build/html/$*/load-timestamp.txt
$(MAKE) build/html/$*/load-timestamp.txt
##### Settings templates #####
build/setting_templates: | build
@printf "\n\n"
mkdir $@
build/setting_templates/%: build/html/% | build/setting_templates
@printf "\n\n### Generating $@.\n\n"
mkdir -p $@
$(PYTHON) make_settings_template.py \
PortalApp/resources/config/settings.json \
> $@/settings.json
$(PYTHON) make_fields_template.py \
build/html/$*/resources/config/fldmodel.json \
> $@/fldmodel.json
touch $@