Skip to content

Inital implementation of create_war_fromjar. #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions clamp/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ def copy_file(self, relpath, path):
self.jar.write(chunk, 0, read)
self.jar.closeEntry()

def copy_bytes(self, relpath, bytez):
self.jar.putNextEntry(JarEntry(relpath))
self.jar.write(bytez)
self.jar.closeEntry()

class JarBuilder(OutputJar):

Expand Down Expand Up @@ -453,3 +457,28 @@ def create_singlejar(output_path, classpath, runpy):

if runpy and os.path.exists(runpy):
singlejar.copy_file("__run__.py", runpy)

def create_war_fromjar(output_path, jar, application):
with JarCopy(output_path=output_path) as war:
print("Building war...")
war.copy_file("WEB-INF/lib/wsgi-app.jar", jar)
war.copy_bytes("WEB-INF/web.xml",
b"""
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>modjy</servlet-name>
<servlet-class>com.xhaus.modjy.ModjyJServlet</servlet-class>
<init-param>
<param-name>app_import_name</param-name>
<param-value>{}</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>modjy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
""".format(application))