Skip to content

Commit 1243d5f

Browse files
CarolynRountreeddsharpe
authored andcommitted
WDT#479 sort discovery created variable file properties (#497)
1 parent 909e31a commit 1243d5f

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

core/src/main/python/wlsdeploy/tool/util/variable_injector.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,7 @@ def sort_dictionary_by_keys(dictionary):
894894
sorted_props = dictionary.keys()
895895
sorted_props.sort()
896896
for prop in sorted_props:
897-
print '******* what is the order ? ', prop
898897
sorted_dict[prop] = dictionary[prop]
899-
for key, value in sorted_dict.iteritems():
900-
print key, '=', value
901898
return sorted_dict
902899

903900

core/src/main/python/wlsdeploy/util/variables.py

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from java.io import FileInputStream
1212
from java.io import FileOutputStream
1313
from java.io import FileReader
14+
from java.io import PrintWriter
1415
from java.io import IOException
1516
from java.util import Properties
1617

@@ -70,23 +71,56 @@ def write_variables(program_name, variable_map, file_path, append=False):
7071
"""
7172
_method_name = 'write_variables'
7273
_logger.entering(program_name, file_path, append, class_name=_class_name, method_name=_method_name)
73-
props = Properties()
74-
for key, value in variable_map.items():
75-
props.setProperty(key, value)
74+
if isinstance(variable_map, OrderedDict):
75+
write_ordered_variables(program_name, variable_map, file_path, append)
76+
else:
77+
props = Properties()
78+
for key, value in variable_map.items():
79+
props.setProperty(key, value)
80+
81+
comment = exception_helper.get_message('WLSDPLY-01731', program_name)
82+
output_stream = None
83+
try:
84+
output_stream = FileOutputStream(File(file_path), Boolean(append))
85+
props.store(output_stream, comment)
86+
output_stream.close()
87+
except IOException, ioe:
88+
_logger.fine('WLSDPLY-20007', file_path, ioe.getLocalizedMessage())
89+
ex = exception_helper.create_variable_exception('WLSDPLY-20007', file_path,
90+
ioe.getLocalizedMessage(), error=ioe)
91+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
92+
if output_stream is not None:
93+
output_stream.close()
94+
raise ex
95+
_logger.exiting(class_name=_class_name, method_name=_method_name)
96+
return
97+
7698

77-
comment = exception_helper.get_message('WLSDPLY-01731', program_name)
78-
output_stream = None
99+
def write_ordered_variables(program_name, variable_map, file_path, append=False):
100+
"""
101+
Write variables to file while preserving order of the variables.
102+
:param program_name: name of the calling program
103+
:param variable_map: map or variable properties to write to file
104+
:param file_path: the file to which to write the properties
105+
:param append: defaults to False. Append properties to the end of file
106+
:raises VariableException if an error occurs while storing the variables in the file
107+
"""
108+
_method_name = 'write_ordered_variables'
109+
_logger.entering(program_name, file_path, append, class_name=_class_name, method_name=_method_name)
110+
pw = None
79111
try:
80-
output_stream = FileOutputStream(File(file_path), Boolean(append))
81-
props.store(output_stream, comment)
82-
output_stream.close()
112+
pw = PrintWriter(FileOutputStream(File(file_path), Boolean(append)), Boolean('true'))
113+
for key, value in variable_map.iteritems():
114+
formatted = '%s=%s' % (key, value)
115+
pw.println(formatted)
116+
pw.close()
83117
except IOException, ioe:
84118
_logger.fine('WLSDPLY-20007', file_path, ioe.getLocalizedMessage())
85119
ex = exception_helper.create_variable_exception('WLSDPLY-20007', file_path,
86120
ioe.getLocalizedMessage(), error=ioe)
87121
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
88-
if output_stream is not None:
89-
output_stream.close()
122+
if pw is not None:
123+
pw.close()
90124
raise ex
91125
_logger.exiting(class_name=_class_name, method_name=_method_name)
92126
return

0 commit comments

Comments
 (0)