55import os
66import tempfile
77
8+ import java .net .URI as URI
9+
810from wlsdeploy .aliases .wlst_modes import WlstModes
911from wlsdeploy .logging import platform_logger
1012from wlsdeploy .util .cla_utils import CommandLineArgUtil
@@ -20,12 +22,12 @@ class ModelContext(object):
2022 """
2123 _class_name = "ModelContext"
2224
23- __ORACLE_HOME_TOKEN = '@@ORACLE_HOME@@'
24- __WL_HOME_TOKEN = '@@WL_HOME@@'
25- __DOMAIN_HOME_TOKEN = '@@DOMAIN_HOME@@'
26- __JAVA_HOME_TOKEN = '@@JAVA_HOME@@'
27- __CURRENT_DIRECTORY_TOKEN = '@@PWD@@'
28- __TEMP_DIRECTORY_TOKEN = '@@TMP@@'
25+ ORACLE_HOME_TOKEN = '@@ORACLE_HOME@@'
26+ WL_HOME_TOKEN = '@@WL_HOME@@'
27+ DOMAIN_HOME_TOKEN = '@@DOMAIN_HOME@@'
28+ JAVA_HOME_TOKEN = '@@JAVA_HOME@@'
29+ CURRENT_DIRECTORY_TOKEN = '@@PWD@@'
30+ TEMP_DIRECTORY_TOKEN = '@@TMP@@'
2931
3032 def __init__ (self , program_name , arg_map ):
3133 """
@@ -610,7 +612,8 @@ def replace_tokens_in_path(self, attribute_name, resource_dict):
610612 :param resource_dict: the dictionary to use to lookup and replace the attribute value
611613 """
612614 separator = ':'
613- path_elements = resource_dict [attribute_name ].split (':' )
615+ attribute_value = resource_dict [attribute_name ]
616+ path_elements = attribute_value .split (':' )
614617 semicolon_path_elements = resource_dict [attribute_name ].split (';' )
615618 if len (semicolon_path_elements ) > len (path_elements ):
616619 separator = ';'
@@ -634,12 +637,12 @@ def has_token_prefix(self, path):
634637 :param path: the path to check for token prefix
635638 :return: true if the path begins with a known prefix, false otherwise
636639 """
637- return path .startswith (self .__ORACLE_HOME_TOKEN ) or \
638- path .startswith (self .__WL_HOME_TOKEN ) or \
639- path .startswith (self .__DOMAIN_HOME_TOKEN ) or \
640- path .startswith (self .__JAVA_HOME_TOKEN ) or \
641- path .startswith (self .__CURRENT_DIRECTORY_TOKEN ) or \
642- path .startswith (self .__TEMP_DIRECTORY_TOKEN )
640+ return path .startswith (self .ORACLE_HOME_TOKEN ) or \
641+ path .startswith (self .WL_HOME_TOKEN ) or \
642+ path .startswith (self .DOMAIN_HOME_TOKEN ) or \
643+ path .startswith (self .JAVA_HOME_TOKEN ) or \
644+ path .startswith (self .CURRENT_DIRECTORY_TOKEN ) or \
645+ path .startswith (self .TEMP_DIRECTORY_TOKEN )
643646
644647 def replace_tokens (self , resource_type , resource_name , attribute_name , resource_dict ):
645648 """
@@ -650,41 +653,44 @@ def replace_tokens(self, resource_type, resource_name, attribute_name, resource_
650653 :param resource_dict: the dictionary to use to lookup and replace the attribute value
651654 """
652655 attribute_value = resource_dict [attribute_name ]
653- if attribute_value .startswith (self .__ORACLE_HOME_TOKEN ):
656+ uri = URI (attribute_value )
657+ if uri .getScheme ().startsWith ('file' ):
658+ attribute_value = uri .getPath ()
659+ if attribute_value .startswith (self .ORACLE_HOME_TOKEN ):
654660 message = "Replacing {0} in {1} {2} {3} with {4}"
655- self ._logger .fine (message , self .__ORACLE_HOME_TOKEN , resource_type , resource_name , attribute_name ,
661+ self ._logger .fine (message , self .ORACLE_HOME_TOKEN , resource_type , resource_name , attribute_name ,
656662 self .get_oracle_home (), class_name = self ._class_name , method_name = '_replace_tokens' )
657- resource_dict [attribute_name ] = attribute_value .replace (self .__ORACLE_HOME_TOKEN ,
663+ resource_dict [attribute_name ] = attribute_value .replace (self .ORACLE_HOME_TOKEN ,
658664 self .get_oracle_home ())
659- elif attribute_value .startswith (self .__WL_HOME_TOKEN ):
665+ elif attribute_value .startswith (self .WL_HOME_TOKEN ):
660666 message = "Replacing {0} in {1} {2} {3} with {4}"
661- self ._logger .fine (message , self .__WL_HOME_TOKEN , resource_type , resource_name , attribute_name ,
667+ self ._logger .fine (message , self .WL_HOME_TOKEN , resource_type , resource_name , attribute_name ,
662668 self .get_wl_home (), class_name = self ._class_name , method_name = '_replace_tokens' )
663- resource_dict [attribute_name ] = attribute_value .replace (self .__WL_HOME_TOKEN , self .get_wl_home ())
664- elif attribute_value .startswith (self .__DOMAIN_HOME_TOKEN ):
669+ resource_dict [attribute_name ] = attribute_value .replace (self .WL_HOME_TOKEN , self .get_wl_home ())
670+ elif attribute_value .startswith (self .DOMAIN_HOME_TOKEN ):
665671 message = "Replacing {0} in {1} {2} {3} with {4}"
666- self ._logger .fine (message , self .__DOMAIN_HOME_TOKEN , resource_type , resource_name , attribute_name ,
672+ self ._logger .fine (message , self .DOMAIN_HOME_TOKEN , resource_type , resource_name , attribute_name ,
667673 self .get_domain_home (), class_name = self ._class_name , method_name = '_replace_tokens' )
668- resource_dict [attribute_name ] = attribute_value .replace (self .__DOMAIN_HOME_TOKEN ,
674+ resource_dict [attribute_name ] = attribute_value .replace (self .DOMAIN_HOME_TOKEN ,
669675 self .get_domain_home ())
670- elif attribute_value .startswith (self .__JAVA_HOME_TOKEN ):
676+ elif attribute_value .startswith (self .JAVA_HOME_TOKEN ):
671677 message = "Replacing {0} in {1} {2} {3} with {4}"
672- self ._logger .fine (message , self .__JAVA_HOME_TOKEN , resource_type , resource_name , attribute_name ,
678+ self ._logger .fine (message , self .JAVA_HOME_TOKEN , resource_type , resource_name , attribute_name ,
673679 self .get_domain_home (), class_name = self ._class_name , method_name = '_replace_tokens' )
674- resource_dict [attribute_name ] = attribute_value .replace (self .__JAVA_HOME_TOKEN ,
680+ resource_dict [attribute_name ] = attribute_value .replace (self .JAVA_HOME_TOKEN ,
675681 self .get_java_home ())
676- elif attribute_value .startswith (self .__CURRENT_DIRECTORY_TOKEN ):
682+ elif attribute_value .startswith (self .CURRENT_DIRECTORY_TOKEN ):
677683 cwd = path_utils .fixup_path (os .getcwd ())
678684 message = "Replacing {0} in {1} {2} {3} with {4}"
679- self ._logger .fine (message , self .__CURRENT_DIRECTORY_TOKEN , resource_type , resource_name ,
685+ self ._logger .fine (message , self .CURRENT_DIRECTORY_TOKEN , resource_type , resource_name ,
680686 attribute_name , cwd , class_name = self ._class_name , method_name = '_replace_tokens' )
681- resource_dict [attribute_name ] = attribute_value .replace (self .__CURRENT_DIRECTORY_TOKEN , cwd )
682- elif attribute_value .startswith (self .__TEMP_DIRECTORY_TOKEN ):
687+ resource_dict [attribute_name ] = attribute_value .replace (self .CURRENT_DIRECTORY_TOKEN , cwd )
688+ elif attribute_value .startswith (self .TEMP_DIRECTORY_TOKEN ):
683689 temp_dir = path_utils .fixup_path (tempfile .gettempdir ())
684690 message = "Replacing {0} in {1} {2} {3} with {4}"
685- self ._logger .fine (message , self .__TEMP_DIRECTORY_TOKEN , resource_type , resource_name , attribute_name ,
691+ self ._logger .fine (message , self .TEMP_DIRECTORY_TOKEN , resource_type , resource_name , attribute_name ,
686692 temp_dir , class_name = self ._class_name , method_name = '_replace_tokens' )
687- resource_dict [attribute_name ] = attribute_value .replace (self .__TEMP_DIRECTORY_TOKEN , temp_dir )
693+ resource_dict [attribute_name ] = attribute_value .replace (self .TEMP_DIRECTORY_TOKEN , temp_dir )
688694
689695 return
690696
@@ -696,18 +702,18 @@ def replace_token_string(self, string_value):
696702 """
697703 if string_value is None :
698704 result = None
699- elif string_value .startswith (self .__ORACLE_HOME_TOKEN ):
700- result = _replace (string_value , self .__ORACLE_HOME_TOKEN , self .get_oracle_home ())
701- elif string_value .startswith (self .__WL_HOME_TOKEN ):
702- result = _replace (string_value , self .__WL_HOME_TOKEN , self .get_wl_home ())
703- elif string_value .startswith (self .__DOMAIN_HOME_TOKEN ):
704- result = _replace (string_value , self .__DOMAIN_HOME_TOKEN , self .get_domain_home ())
705- elif string_value .startswith (self .__JAVA_HOME_TOKEN ):
706- result = _replace (string_value , self .__JAVA_HOME_TOKEN , self .get_java_home ())
707- elif string_value .startswith (self .__CURRENT_DIRECTORY_TOKEN ):
708- result = _replace (string_value , self .__CURRENT_DIRECTORY_TOKEN , path_utils .fixup_path (os .getcwd ()))
709- elif string_value .startswith (self .__TEMP_DIRECTORY_TOKEN ):
710- result = _replace (string_value , self .__TEMP_DIRECTORY_TOKEN , path_utils .fixup_path (tempfile .gettempdir ()))
705+ elif string_value .startswith (self .ORACLE_HOME_TOKEN ):
706+ result = _replace (string_value , self .ORACLE_HOME_TOKEN , self .get_oracle_home ())
707+ elif string_value .startswith (self .WL_HOME_TOKEN ):
708+ result = _replace (string_value , self .WL_HOME_TOKEN , self .get_wl_home ())
709+ elif string_value .startswith (self .DOMAIN_HOME_TOKEN ):
710+ result = _replace (string_value , self .DOMAIN_HOME_TOKEN , self .get_domain_home ())
711+ elif string_value .startswith (self .JAVA_HOME_TOKEN ):
712+ result = _replace (string_value , self .JAVA_HOME_TOKEN , self .get_java_home ())
713+ elif string_value .startswith (self .CURRENT_DIRECTORY_TOKEN ):
714+ result = _replace (string_value , self .CURRENT_DIRECTORY_TOKEN , path_utils .fixup_path (os .getcwd ()))
715+ elif string_value .startswith (self .TEMP_DIRECTORY_TOKEN ):
716+ result = _replace (string_value , self .TEMP_DIRECTORY_TOKEN , path_utils .fixup_path (tempfile .gettempdir ()))
711717 else :
712718 result = string_value
713719
@@ -733,17 +739,17 @@ def tokenize_path(self, path):
733739 result = my_path
734740 if not string_utils .is_empty (my_path ):
735741 if wl_home is not None and my_path .startswith (wl_home ):
736- result = my_path .replace (wl_home , self .__WL_HOME_TOKEN )
742+ result = my_path .replace (wl_home , self .WL_HOME_TOKEN )
737743 elif domain_home is not None and my_path .startswith (domain_home ):
738- result = my_path .replace (domain_home , self .__DOMAIN_HOME_TOKEN )
744+ result = my_path .replace (domain_home , self .DOMAIN_HOME_TOKEN )
739745 elif oracle_home is not None and my_path .startswith (oracle_home ):
740- result = my_path .replace (oracle_home , self .__ORACLE_HOME_TOKEN )
746+ result = my_path .replace (oracle_home , self .ORACLE_HOME_TOKEN )
741747 elif java_home is not None and my_path .startswith (java_home ):
742- result = my_path .replace (java_home , self .__JAVA_HOME_TOKEN )
748+ result = my_path .replace (java_home , self .JAVA_HOME_TOKEN )
743749 elif my_path .startswith (cwd ):
744- result = my_path .replace (cwd , self .__CURRENT_DIRECTORY_TOKEN )
750+ result = my_path .replace (cwd , self .CURRENT_DIRECTORY_TOKEN )
745751 elif my_path .startswith (tmp_dir ):
746- result = my_path .replace (tmp_dir , self .__TEMP_DIRECTORY_TOKEN )
752+ result = my_path .replace (tmp_dir , self .TEMP_DIRECTORY_TOKEN )
747753
748754 return result
749755
0 commit comments