5
5
import os
6
6
import tempfile
7
7
8
+ import java .net .URI as URI
9
+
8
10
from wlsdeploy .aliases .wlst_modes import WlstModes
9
11
from wlsdeploy .logging import platform_logger
10
12
from wlsdeploy .util .cla_utils import CommandLineArgUtil
@@ -20,12 +22,12 @@ class ModelContext(object):
20
22
"""
21
23
_class_name = "ModelContext"
22
24
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@@'
29
31
30
32
def __init__ (self , program_name , arg_map ):
31
33
"""
@@ -610,7 +612,8 @@ def replace_tokens_in_path(self, attribute_name, resource_dict):
610
612
:param resource_dict: the dictionary to use to lookup and replace the attribute value
611
613
"""
612
614
separator = ':'
613
- path_elements = resource_dict [attribute_name ].split (':' )
615
+ attribute_value = resource_dict [attribute_name ]
616
+ path_elements = attribute_value .split (':' )
614
617
semicolon_path_elements = resource_dict [attribute_name ].split (';' )
615
618
if len (semicolon_path_elements ) > len (path_elements ):
616
619
separator = ';'
@@ -634,12 +637,12 @@ def has_token_prefix(self, path):
634
637
:param path: the path to check for token prefix
635
638
:return: true if the path begins with a known prefix, false otherwise
636
639
"""
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 )
643
646
644
647
def replace_tokens (self , resource_type , resource_name , attribute_name , resource_dict ):
645
648
"""
@@ -650,41 +653,44 @@ def replace_tokens(self, resource_type, resource_name, attribute_name, resource_
650
653
:param resource_dict: the dictionary to use to lookup and replace the attribute value
651
654
"""
652
655
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 ):
654
660
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 ,
656
662
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 ,
658
664
self .get_oracle_home ())
659
- elif attribute_value .startswith (self .__WL_HOME_TOKEN ):
665
+ elif attribute_value .startswith (self .WL_HOME_TOKEN ):
660
666
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 ,
662
668
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 ):
665
671
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 ,
667
673
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 ,
669
675
self .get_domain_home ())
670
- elif attribute_value .startswith (self .__JAVA_HOME_TOKEN ):
676
+ elif attribute_value .startswith (self .JAVA_HOME_TOKEN ):
671
677
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 ,
673
679
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 ,
675
681
self .get_java_home ())
676
- elif attribute_value .startswith (self .__CURRENT_DIRECTORY_TOKEN ):
682
+ elif attribute_value .startswith (self .CURRENT_DIRECTORY_TOKEN ):
677
683
cwd = path_utils .fixup_path (os .getcwd ())
678
684
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 ,
680
686
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 ):
683
689
temp_dir = path_utils .fixup_path (tempfile .gettempdir ())
684
690
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 ,
686
692
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 )
688
694
689
695
return
690
696
@@ -696,18 +702,18 @@ def replace_token_string(self, string_value):
696
702
"""
697
703
if string_value is None :
698
704
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 ()))
711
717
else :
712
718
result = string_value
713
719
@@ -733,17 +739,17 @@ def tokenize_path(self, path):
733
739
result = my_path
734
740
if not string_utils .is_empty (my_path ):
735
741
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 )
737
743
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 )
739
745
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 )
741
747
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 )
743
749
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 )
745
751
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 )
747
753
748
754
return result
749
755
0 commit comments