Skip to content

Commit

Permalink
print server version on startup; add manifest to JAR
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemccand committed Aug 1, 2016
1 parent 696efac commit 6a80cad
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
44 changes: 36 additions & 8 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
]

LUCENE_VERSION = '6.2.0-SNAPSHOT'
LUCENE_SERVER_VERSION = '0.1.0-SNAPSHOT'
LUCENE_SERVER_BASE_VERSION = '0.1.0'
LUCENE_SERVER_VERSION = '%s-SNAPSHOT' % LUCENE_SERVER_BASE_VERSION

luceneDeps = ('core',
'analyzers-common',
Expand Down Expand Up @@ -353,7 +354,7 @@ def getFlag(option):
else:
return False

def compileSourcesAndDeps():
def compileSourcesAndDeps(jarVersion):
if not os.path.exists('lib'):
print('init: create ./lib directory...')
os.makedirs('lib')
Expand All @@ -374,15 +375,38 @@ def compileSourcesAndDeps():
compileLuceneModules(luceneDeps)

# compile luceneserver sources
jarFileName = 'build/luceneserver-%s.jar' % LUCENE_SERVER_VERSION
jarFileName = 'build/luceneserver-%s.jar' % jarVersion

l = getCompileClassPath()
l.append('build/classes/java')
compileChangedSources('src/java', 'build/classes/java', l)

if anyChanges('build/classes/java', jarFileName):
print('build %s' % jarFileName)
run('jar cf %s -C build/classes/java .' % jarFileName)
gitHash = os.popen('git rev-parse --short HEAD').readline().strip()
modifiedFileCount = 0
with os.popen('git ls-files -m') as p:
while True:
line = p.readline()
if line == '':
break
modifiedFileCount += 1

with open('build/manifest.mf', 'w') as f:
f.write('Extension-Name: org.apache.lucene.server\n')
f.write('Specification-Title: Thin HTTP/REST server wrapper for Apache Lucene\n')
f.write('Specification-Vendor: Mike McCandless\n')
f.write('Specification-Version: %s\n' % LUCENE_SERVER_BASE_VERSION)
f.write('Implementation-Title: org.apache.lucene.server\n')
f.write('Implementation-Vendor: Mike McCandless\n')
if modifiedFileCount > 0:
if '-SNAPSHOT' not in jarVersion:
raise RuntimeError('there are modified sources; cannot build releasable JAR')
f.write('Implementation-Version: %s %s; %d source files modified\n' % (jarVersion, gitHash, modifiedFileCount))
else:
f.write('Implementation-Version: %s %s\n' % (jarVersion, gitHash))

run('jar cefm org.apache.lucene.server.Server %s build/manifest.mf -C build/classes/java .' % jarFileName)

return jarFileName

Expand All @@ -403,14 +427,18 @@ def main():
run('ant clean')
os.chdir(ROOT_DIR)
elif what == 'package':

jarVersion = getArg('-version')
if jarVersion is None:
jarVersion = LUCENE_SERVER_VERSION

jarFileName = compileSourcesAndDeps()
jarFileName = compileSourcesAndDeps(jarVersion)

destFileName = 'build/luceneserver-%s.zip' % LUCENE_SERVER_VERSION
rootDirName = 'luceneserver-%s' % LUCENE_SERVER_VERSION
destFileName = 'build/luceneserver-%s.zip' % jarVersion
rootDirName = 'luceneserver-%s' % jarVersion

with zipfile.ZipFile(destFileName, 'w') as z:
z.write(jarFileName, '%s/lib/luceneserver-%s.jar' % (rootDirName, LUCENE_SERVER_VERSION))
z.write(jarFileName, '%s/lib/luceneserver-%s.jar' % (rootDirName, jarVersion))
for org, name, version in deps:
z.write('lib/%s-%s.jar' % (name, version), '%s/lib/%s-%s.jar' % (rootDirName, name, version))
for dep in luceneDeps:
Expand Down
23 changes: 21 additions & 2 deletions src/java/org/apache/lucene/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ public class Server {

public static final int DEFAULT_PORT = 4000;

public static final String SERVER_VERSION = computeVersion();


private static String computeVersion() {
Package p = Server.class.getPackage();
String s;
if (p != null) {
s = p.getImplementationVersion();
} else {
s = null;
}

if (s == null) {
s = "0.1.0-SNAPSHOT";
}

return s;
}

final GlobalState globalState;
final ExecutorService httpThreadPool;
final List<HttpServer> httpServers;
Expand Down Expand Up @@ -700,7 +719,7 @@ public void run(CountDownLatch ready) throws Exception {

globalState.loadPlugins();

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

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

0 comments on commit 6a80cad

Please sign in to comment.