Skip to content

Commit

Permalink
feat: jans-linux-setup set_class_path() (#2442)
Browse files Browse the repository at this point in the history
* feat: jans-linux-setup set_class_path()

* fix: jans-linux-setup code smells
  • Loading branch information
devrimyatar authored Sep 22, 2022
1 parent 77d8d88 commit 8128244
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions jans-linux-setup/jans_setup/setup_app/installers/jetty.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,49 +355,58 @@ def calculate_selected_aplications_memory(self):
return self.calculate_aplications_memory(Config.application_max_ram, self.jetty_app_configuration, installedComponents)

def add_extra_class(self, class_path, xml_fn=None):
current_plugins = self.get_plugins(xml_fn, paths=True)
for cp in class_path.split(','):
if os.path.basename(cp) not in ','.join(current_plugins):
current_plugins.append(cp.strip())

self.set_class_path(current_plugins, xml_fn)

def set_class_path(self, paths, xml_fn=None):

if not xml_fn:
xml_fn = self.web_app_xml_fn

tree = ET.parse(xml_fn)
root = tree.getroot()
path_list = []

for app_set in root.findall("Set"):
if app_set.get('name') == 'extraClasspath':
path_list = [cp.strip() for cp in app_set.text.split(',')]
break
else:
app_set = ET.Element("Set")
app_set.set('name', 'extraClasspath')

root.append(app_set)

for cp in class_path.split(','):
if os.path.basename(cp) not in ','.join(path_list):
path_list.append(cp.strip())

app_set.text = ','.join(path_list)
app_set.text = ','.join(paths)

with open(xml_fn, 'wb') as f:
f.write(b'<?xml version="1.0" encoding="ISO-8859-1"?>\n')
f.write(b'<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">\n')
f.write(ET.tostring(root, method='xml'))


def get_plugins(self):
def get_plugins(self, xml_fn=None, paths=False):
plugins = []
webapps_xml_fn = os.path.join(self.jetty_base, self.service_name, WEBAPPS, self.service_name+'.xml')
if not xml_fn:
xml_fn = self.web_app_xml_fn

if os.path.exists(webapps_xml_fn):
if os.path.exists(xml_fn):

tree = ET.parse(webapps_xml_fn)
tree = ET.parse(xml_fn)
root = tree.getroot()

for app_set in root.findall("Set"):
if app_set.get('name') == 'extraClasspath':
for plugin_path in app_set.text.split(','):
path_list = app_set.text.split(',')
if paths:
return path_list

for plugin_path in path_list:
base_name = os.path.basename(plugin_path)
n = base_name.rfind('plugin')
plugins.append(base_name[:n].rstrip('-'))
fname, fext = os.path.splitext(base_name)
plugins.append(fname.rstrip('plugin').rstrip('-'))

return plugins

Expand Down

0 comments on commit 8128244

Please sign in to comment.