Skip to content

Commit 6a80cad

Browse files
committed
print server version on startup; add manifest to JAR
1 parent 696efac commit 6a80cad

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

build.py

+36-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
]
2828

2929
LUCENE_VERSION = '6.2.0-SNAPSHOT'
30-
LUCENE_SERVER_VERSION = '0.1.0-SNAPSHOT'
30+
LUCENE_SERVER_BASE_VERSION = '0.1.0'
31+
LUCENE_SERVER_VERSION = '%s-SNAPSHOT' % LUCENE_SERVER_BASE_VERSION
3132

3233
luceneDeps = ('core',
3334
'analyzers-common',
@@ -353,7 +354,7 @@ def getFlag(option):
353354
else:
354355
return False
355356

356-
def compileSourcesAndDeps():
357+
def compileSourcesAndDeps(jarVersion):
357358
if not os.path.exists('lib'):
358359
print('init: create ./lib directory...')
359360
os.makedirs('lib')
@@ -374,15 +375,38 @@ def compileSourcesAndDeps():
374375
compileLuceneModules(luceneDeps)
375376

376377
# compile luceneserver sources
377-
jarFileName = 'build/luceneserver-%s.jar' % LUCENE_SERVER_VERSION
378+
jarFileName = 'build/luceneserver-%s.jar' % jarVersion
378379

379380
l = getCompileClassPath()
380381
l.append('build/classes/java')
381382
compileChangedSources('src/java', 'build/classes/java', l)
382383

383384
if anyChanges('build/classes/java', jarFileName):
384385
print('build %s' % jarFileName)
385-
run('jar cf %s -C build/classes/java .' % jarFileName)
386+
gitHash = os.popen('git rev-parse --short HEAD').readline().strip()
387+
modifiedFileCount = 0
388+
with os.popen('git ls-files -m') as p:
389+
while True:
390+
line = p.readline()
391+
if line == '':
392+
break
393+
modifiedFileCount += 1
394+
395+
with open('build/manifest.mf', 'w') as f:
396+
f.write('Extension-Name: org.apache.lucene.server\n')
397+
f.write('Specification-Title: Thin HTTP/REST server wrapper for Apache Lucene\n')
398+
f.write('Specification-Vendor: Mike McCandless\n')
399+
f.write('Specification-Version: %s\n' % LUCENE_SERVER_BASE_VERSION)
400+
f.write('Implementation-Title: org.apache.lucene.server\n')
401+
f.write('Implementation-Vendor: Mike McCandless\n')
402+
if modifiedFileCount > 0:
403+
if '-SNAPSHOT' not in jarVersion:
404+
raise RuntimeError('there are modified sources; cannot build releasable JAR')
405+
f.write('Implementation-Version: %s %s; %d source files modified\n' % (jarVersion, gitHash, modifiedFileCount))
406+
else:
407+
f.write('Implementation-Version: %s %s\n' % (jarVersion, gitHash))
408+
409+
run('jar cefm org.apache.lucene.server.Server %s build/manifest.mf -C build/classes/java .' % jarFileName)
386410

387411
return jarFileName
388412

@@ -403,14 +427,18 @@ def main():
403427
run('ant clean')
404428
os.chdir(ROOT_DIR)
405429
elif what == 'package':
430+
431+
jarVersion = getArg('-version')
432+
if jarVersion is None:
433+
jarVersion = LUCENE_SERVER_VERSION
406434

407-
jarFileName = compileSourcesAndDeps()
435+
jarFileName = compileSourcesAndDeps(jarVersion)
408436

409-
destFileName = 'build/luceneserver-%s.zip' % LUCENE_SERVER_VERSION
410-
rootDirName = 'luceneserver-%s' % LUCENE_SERVER_VERSION
437+
destFileName = 'build/luceneserver-%s.zip' % jarVersion
438+
rootDirName = 'luceneserver-%s' % jarVersion
411439

412440
with zipfile.ZipFile(destFileName, 'w') as z:
413-
z.write(jarFileName, '%s/lib/luceneserver-%s.jar' % (rootDirName, LUCENE_SERVER_VERSION))
441+
z.write(jarFileName, '%s/lib/luceneserver-%s.jar' % (rootDirName, jarVersion))
414442
for org, name, version in deps:
415443
z.write('lib/%s-%s.jar' % (name, version), '%s/lib/%s-%s.jar' % (rootDirName, name, version))
416444
for dep in luceneDeps:

src/java/org/apache/lucene/server/Server.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ public class Server {
8686

8787
public static final int DEFAULT_PORT = 4000;
8888

89+
public static final String SERVER_VERSION = computeVersion();
90+
91+
92+
private static String computeVersion() {
93+
Package p = Server.class.getPackage();
94+
String s;
95+
if (p != null) {
96+
s = p.getImplementationVersion();
97+
} else {
98+
s = null;
99+
}
100+
101+
if (s == null) {
102+
s = "0.1.0-SNAPSHOT";
103+
}
104+
105+
return s;
106+
}
107+
89108
final GlobalState globalState;
90109
final ExecutorService httpThreadPool;
91110
final List<HttpServer> httpServers;
@@ -700,7 +719,7 @@ public void run(CountDownLatch ready) throws Exception {
700719

701720
globalState.loadPlugins();
702721

703-
System.out.println("Server " + globalState.nodeName + ": listening on:");
722+
System.out.println("Server version \"" + SERVER_VERSION + "\", node " + globalState.nodeName + ": listening on:");
704723
for(int i=0;i<httpServers.size();i++) {
705724
System.out.println(" " + bindIPs.get(i) + ":" + actualPorts.get(i) + "/" + actualBinaryPorts.get(i));
706725
}
@@ -794,7 +813,7 @@ public void run() {
794813
}
795814

796815
private void _run() throws Exception {
797-
System.out.println("SVR " + globalState.nodeName + ": handle binary client; receive buffer=" + socket.getReceiveBufferSize());
816+
//System.out.println("SVR " + globalState.nodeName + ": handle binary client; receive buffer=" + socket.getReceiveBufferSize());
798817
try (InputStream in = new BufferedInputStream(socket.getInputStream(), 128 * 1024); OutputStream out = socket.getOutputStream()) {
799818
DataInput dataIn = new InputStreamDataInput(in);
800819
int x = dataIn.readInt();

0 commit comments

Comments
 (0)