Skip to content

Commit 731e337

Browse files
CarolynRountreeddsharpe
authored andcommitted
Issue#503 add java home global token (#511)
1 parent 94ac256 commit 731e337

File tree

5 files changed

+62
-13
lines changed

5 files changed

+62
-13
lines changed

core/src/main/python/discover.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
The entry point for the discoverDomain tool.
@@ -69,6 +69,7 @@
6969
# Used by shell script to locate WLST
7070
CommandLineArgUtil.MODEL_FILE_SWITCH,
7171
CommandLineArgUtil.DOMAIN_TYPE_SWITCH,
72+
CommandLineArgUtil.JAVA_HOME_SWITCH,
7273
CommandLineArgUtil.VARIABLE_FILE_SWITCH,
7374
CommandLineArgUtil.ADMIN_URL_SWITCH,
7475
CommandLineArgUtil.ADMIN_USER_SWITCH,
@@ -92,6 +93,7 @@ def __process_args(args):
9293
__wlst_mode = __process_online_args(optional_arg_map)
9394
__process_archive_filename_arg(required_arg_map)
9495
__process_variable_filename_arg(optional_arg_map)
96+
__process_java_home(optional_arg_map)
9597

9698
combined_arg_map = optional_arg_map.copy()
9799
combined_arg_map.update(required_arg_map)
@@ -198,6 +200,22 @@ def __process_variable_filename_arg(optional_arg_map):
198200
return
199201

200202

203+
def __process_java_home(optional_arg_map):
204+
_method_name = '__process_java_home'
205+
if CommandLineArgUtil.JAVA_HOME_SWITCH in optional_arg_map:
206+
java_home_name = optional_arg_map[CommandLineArgUtil.JAVA_HOME_SWITCH]
207+
else:
208+
java_home_name = os.environ.get('JAVA_HOME')
209+
210+
try:
211+
FileUtils.validateExistingDirectory(java_home_name)
212+
except IllegalArgumentException, iae:
213+
# this value is used for java home global token in attributes.
214+
# If this was passed as command line, it might no longer exist.
215+
# The JAVA_HOME environment variable was validated by script.
216+
__logger.info('WLSDPLY-06027', java_home_name, iae.getLocalizedMessage(),
217+
class_name=_class_name, method_name=_method_name)
218+
201219
def __discover(model_context, aliases, injector):
202220
"""
203221
Populate the model from the domain.

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import os
@@ -23,6 +23,7 @@ class ModelContext(object):
2323
__ORACLE_HOME_TOKEN = '@@ORACLE_HOME@@'
2424
__WL_HOME_TOKEN = '@@WL_HOME@@'
2525
__DOMAIN_HOME_TOKEN = '@@DOMAIN_HOME@@'
26+
__JAVA_HOME_TOKEN = '@@JAVA_HOME@@'
2627
__CURRENT_DIRECTORY_TOKEN = '@@PWD@@'
2728
__TEMP_DIRECTORY_TOKEN = '@@TMP@@'
2829

@@ -501,10 +502,11 @@ def has_token_prefix(self, path):
501502
:return: true if the path begins with a known prefix, false otherwise
502503
"""
503504
return path.startswith(self.__ORACLE_HOME_TOKEN) or \
504-
path.startswith(self.__WL_HOME_TOKEN) or \
505-
path.startswith(self.__DOMAIN_HOME_TOKEN) or \
506-
path.startswith(self.__CURRENT_DIRECTORY_TOKEN) or \
507-
path.startswith(self.__TEMP_DIRECTORY_TOKEN)
505+
path.startswith(self.__WL_HOME_TOKEN) or \
506+
path.startswith(self.__DOMAIN_HOME_TOKEN) or \
507+
path.startswith(self.__JAVA_HOME_TOKEN) or \
508+
path.startswith(self.__CURRENT_DIRECTORY_TOKEN) or \
509+
path.startswith(self.__TEMP_DIRECTORY_TOKEN)
508510

509511
def replace_tokens(self, resource_type, resource_name, attribute_name, resource_dict):
510512
"""
@@ -532,6 +534,12 @@ def replace_tokens(self, resource_type, resource_name, attribute_name, resource_
532534
self.get_domain_home(), class_name=self._class_name, method_name='_replace_tokens')
533535
resource_dict[attribute_name] = attribute_value.replace(self.__DOMAIN_HOME_TOKEN,
534536
self.get_domain_home())
537+
elif attribute_value.startswith(self.__JAVA_HOME_TOKEN):
538+
message = "Replacing {0} in {1} {2} {3} with {4}"
539+
self._logger.fine(message, self.__JAVA_HOME_TOKEN, resource_type, resource_name, attribute_name,
540+
self.get_domain_home(), class_name=self._class_name, method_name='_replace_tokens')
541+
resource_dict[attribute_name] = attribute_value.replace(self.__JAVA_HOME_TOKEN,
542+
self.get_java_home())
535543
elif attribute_value.startswith(self.__CURRENT_DIRECTORY_TOKEN):
536544
cwd = path_utils.fixup_path(os.getcwd())
537545
message = "Replacing {0} in {1} {2} {3} with {4}"
@@ -561,6 +569,8 @@ def replace_token_string(self, string_value):
561569
result = _replace(string_value, self.__WL_HOME_TOKEN, self.get_wl_home())
562570
elif string_value.startswith(self.__DOMAIN_HOME_TOKEN):
563571
result = _replace(string_value, self.__DOMAIN_HOME_TOKEN, self.get_domain_home())
572+
elif string_value.startswith(self.__JAVA_HOME_TOKEN):
573+
result = _replace(string_value, self.__JAVA_HOME_TOKEN, self.get_java_home())
564574
elif string_value.startswith(self.__CURRENT_DIRECTORY_TOKEN):
565575
result = _replace(string_value, self.__CURRENT_DIRECTORY_TOKEN, path_utils.fixup_path(os.getcwd()))
566576
elif string_value.startswith(self.__TEMP_DIRECTORY_TOKEN):
@@ -582,6 +592,7 @@ def tokenize_path(self, path):
582592
wl_home = path_utils.fixup_path(self.get_wl_home())
583593
domain_home = path_utils.fixup_path(self.get_domain_home())
584594
oracle_home = path_utils.fixup_path(self.get_oracle_home())
595+
java_home = path_utils.fixup_path(self.get_java_home())
585596
tmp_dir = path_utils.fixup_path(tempfile.gettempdir())
586597
cwd = path_utils.fixup_path(os.path.dirname(os.path.abspath(__file__)))
587598

@@ -594,6 +605,8 @@ def tokenize_path(self, path):
594605
result = my_path.replace(domain_home, self.__DOMAIN_HOME_TOKEN)
595606
elif oracle_home is not None and my_path.startswith(oracle_home):
596607
result = my_path.replace(oracle_home, self.__ORACLE_HOME_TOKEN)
608+
elif java_home is not None and my_path.startswith(java_home):
609+
result = my_path.replace(java_home, self.__JAVA_HOME_TOKEN)
597610
elif my_path.startswith(cwd):
598611
result = my_path.replace(cwd, self.__CURRENT_DIRECTORY_TOKEN)
599612
elif my_path.startswith(tmp_dir):

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
22
# The Universal Permissive License (UPL), Version 1.0
33
#
44
#
@@ -476,6 +476,7 @@ WLSDPLY-06024=No variable file provided. Model passwords will contain the token
476476
WLSDPLY-06025=Variable file was provided. Model password attributes will be replaced with tokens and corresponding \
477477
values put into the variable file.
478478
WLSDPLY-06026=Target directory for archive file argument {0} does not exist
479+
WLSDPLY-06027=JAVA_HOME {0} is not a valid location: {1}
479480

480481
# discoverer.py
481482
WLSDPLY-06100=Find attributes at location {0}

installer/src/main/bin/discoverDomain.cmd

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@rem **************************************************************************
33
@rem discoverDomain.cmd
44
@rem
5-
@rem Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
5+
@rem Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
66
@rem Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
77
@rem
88
@rem NAME
@@ -63,6 +63,11 @@
6363
@rem For example, for SOA 12.1.3, -wlst_path should be
6464
@rem specified as %ORACLE_HOME%\soa
6565
@rem
66+
@rem - -java_home The path to the Java Home directory used for the
67+
@rem Oracle Home. This overrides the JAVA_HOME environment variable
68+
@rem when discovering attributes with a java home. Any attribute with this
69+
@rem value will be replaced with a java home global token in the model.
70+
@rem
6671
@rem This script uses the following variables:
6772
@rem
6873
@rem JAVA_HOME - The location of the JDK to use. The caller must set
@@ -169,7 +174,6 @@ IF "%~1" == "" (
169174
SET ORACLE_HOME=
170175
SET DOMAIN_TYPE=
171176
SET WLST_PATH_DIR=
172-
173177
:arg_loop
174178
IF "%1" == "-help" (
175179
SET RETURN_CODE=0
@@ -190,7 +194,7 @@ IF "%1" == "-wlst_path" (
190194
SHIFT
191195
GOTO arg_continue
192196
)
193-
@REM If none of the above, unknown argument so skip it
197+
@REM If none of the above, a general argument so skip collecting it
194198
:arg_continue
195199
SHIFT
196200
IF NOT "%~1" == "" (
@@ -341,6 +345,7 @@ ECHO [-model_file ^<model_file^>]
341345
ECHO [-variable_file ^<variable_file^>]
342346
ECHO [-domain_type ^<domain_type^>]
343347
ECHO [-wlst_path ^<wlst_path^>]
348+
ECHO [-java_home ^<java_home^>]
344349
ECHO [-admin_url ^<admin_url^>
345350
ECHO -admin_user ^<admin_user^>
346351
ECHO ]
@@ -366,6 +371,9 @@ ECHO.
366371
ECHO wlst_path - the Oracle Home subdirectory of the wlst.cmd
367372
ECHO script to use (e.g., ^<ORACLE_HOME^>\soa)
368373
ECHO.
374+
ECHO java_home - overrides the JAVA_HOME value when discovering
375+
ECHO domain values to be replaced with the java home global token
376+
ECHO.
369377
ECHO admin_url - the admin server URL (used for online discovery)
370378
ECHO.
371379
ECHO admin_user - the admin username (used for online discovery)

installer/src/main/bin/discoverDomain.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# *****************************************************************************
33
# discoverDomain.sh
44
#
5-
# Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
5+
# Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
66
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
77
#
88
# NAME
@@ -63,10 +63,15 @@
6363
# For example, for SOA 12.1.3, -wlst_path should be
6464
# specified as $ORACLE_HOME/soa
6565
#
66+
# -wlst_path The path to the Oracle Home product directory under
67+
# which to find the wlst script. This is only
68+
# needed for pre-12.2.1 upper stack products like SOA.
69+
#
6670
# This script uses the following variables:
6771
#
68-
# JAVA_HOME - The location of the JDK to use. The caller must set
69-
# this variable to a valid Java 7 (or later) JDK.
72+
# JAVA_HOME - The path to the Java Home directory used by the ORACLE HOME.
73+
# This overrides the JAVA_HOME value when locating attributes
74+
# which will be replaced with the java home global token in the model
7075
#
7176
# WLSDEPLOY_HOME - The location of the WLS Deploy installation.
7277
# If the caller sets this, the callers location will be
@@ -89,6 +94,7 @@ usage() {
8994
echo " [-variable_file <variable_file>]"
9095
echo " [-domain_type <domain_type>]"
9196
echo " [-wlst_path <wlst_path>]"
97+
echo " [-java_home <java_home>]"
9298
echo " [-admin_url <admin_url>"
9399
echo " -admin_user <admin_user>"
94100
echo " ]"
@@ -115,6 +121,9 @@ usage() {
115121
echo " wlst_path - the Oracle Home subdirectory of the wlst.cmd"
116122
echo " script to use (e.g., <ORACLE_HOME>/soa)"
117123
echo ""
124+
echo " java_home - overrides the JAVA_HOME value when discovering"
125+
echo " domain values to be replaced with the java home global token"
126+
echo ""
118127
echo " admin_url - the admin server URL (used for online deploy)"
119128
echo ""
120129
echo " admin_user - the admin username (used for online deploy)"

0 commit comments

Comments
 (0)