|
1 | 1 | package com.genexus; |
2 | 2 |
|
3 | | -import java.io.BufferedInputStream; |
4 | | -import java.io.FileInputStream; |
5 | | -import java.io.FileNotFoundException; |
6 | | -import java.io.IOException; |
7 | | -import java.io.InputStream; |
8 | | - |
| 3 | +import com.genexus.diagnostics.core.ILogger; |
| 4 | +import com.genexus.diagnostics.core.LogManager; |
9 | 5 | import com.genexus.util.IniFile; |
10 | 6 | import com.genexus.util.IniFileMultiple; |
11 | 7 |
|
12 | | -public class ConfigFileFinder |
13 | | -{ |
| 8 | +import java.io.*; |
| 9 | + |
| 10 | +public class ConfigFileFinder { |
| 11 | + public static final ILogger logger = LogManager.getLogger(ConfigFileFinder.class); |
14 | 12 | private static final String CRYPTO_CFG = "crypto.cfg"; |
15 | 13 | private static final String PROD_ENV_SUFFIX = ".prod"; |
| 14 | + private static final String DEV_ENV_SUFFIX = ".dev"; |
16 | 15 |
|
17 | | - public static IniFile getConfigFile(Class resourceClassParm, String fileName, Class defaultResourceClass) |
18 | | - { |
| 16 | + public static IniFile getConfigFile(Class resourceClassParm, String fileName, Class defaultResourceClass) { |
19 | 17 | IniFileStream iniFileStream = new IniFileStream(resourceClassParm, fileName, defaultResourceClass).invoke(); |
20 | 18 | InputStream is = iniFileStream.getIs(); |
21 | 19 | InputStream crypto = iniFileStream.getCrypto(); |
22 | 20 |
|
23 | | - IniFileStream iniFileStreamProdEnv = new IniFileStream(resourceClassParm, fileName + PROD_ENV_SUFFIX, defaultResourceClass).invoke(); |
24 | | - InputStream isProdEnv = iniFileStreamProdEnv.getIs(); |
25 | | - |
| 21 | + //If client.cfg.dev is present, any other client.cfg.* will not be read |
| 22 | + IniFileStream configurationOverride = new IniFileStream(resourceClassParm, fileName + DEV_ENV_SUFFIX, defaultResourceClass); |
| 23 | + if (configurationOverride == null || configurationOverride.invoke().getIs() == null) { |
| 24 | + configurationOverride = new IniFileStream(resourceClassParm, fileName + PROD_ENV_SUFFIX, defaultResourceClass); |
| 25 | + } |
| 26 | + |
26 | 27 | IniFile iniFile = null; |
27 | 28 |
|
28 | | - try |
29 | | - { |
30 | | - iniFile = new IniFileMultiple(is, isProdEnv); |
31 | | - } |
32 | | - catch (IOException e) |
33 | | - { |
34 | | - if (ApplicationContext.getInstance().isGXUtility()) |
35 | | - { |
| 29 | + try { |
| 30 | + iniFile = new IniFileMultiple(is); |
| 31 | + ((IniFileMultiple) iniFile).addConfigurationSource(configurationOverride.fileName, configurationOverride.invoke().getIs()); |
| 32 | + } catch (IOException e) { |
| 33 | + if (ApplicationContext.getInstance().isGXUtility()) { |
36 | 34 | iniFile = new IniFile(fileName); |
37 | | - } |
38 | | - else |
39 | | - { |
| 35 | + } else { |
40 | 36 | String userDir; |
41 | | - try |
42 | | - { |
| 37 | + try { |
43 | 38 | userDir = System.getProperty("user.dir") + "\\"; |
44 | | - } |
45 | | - catch (SecurityException ex) |
46 | | - { |
| 39 | + } catch (SecurityException ex) { |
47 | 40 | userDir = ""; |
48 | 41 | } |
49 | 42 |
|
50 | | - throw new InternalError("Can't open " + userDir + fileName + " / " + e.getMessage()); |
| 43 | + String errMessage = "Can't open " + userDir + fileName; |
| 44 | + logger.fatal(errMessage, e); |
| 45 | + throw new InternalError(errMessage + " / " + e.getMessage()); |
51 | 46 | } |
52 | 47 | } |
53 | 48 |
|
@@ -85,63 +80,47 @@ public IniFileStream invoke() { |
85 | 80 | if (ClientContext.getModelContext() != null) |
86 | 81 | resourceClass = ClientContext.getModelContext().getPackageClass(); |
87 | 82 |
|
88 | | - if (is == null && resourceClass != null) |
89 | | - { |
| 83 | + if (is == null && resourceClass != null) { |
90 | 84 | is = ResourceReader.getResourceAsStream(resourceClass, fileName); |
91 | | - if (is != null) |
92 | | - { |
| 85 | + if (is != null) { |
93 | 86 | crypto = ResourceReader.getResourceAsStream(resourceClass, CRYPTO_CFG); |
94 | 87 | } |
95 | 88 | } |
96 | 89 |
|
97 | 90 | // This is for GeneXus programs set where is the .cfg file |
98 | | - if (is == null && defaultResourceClass != null) |
99 | | - { |
| 91 | + if (is == null && defaultResourceClass != null) { |
100 | 92 | is = ResourceReader.getResourceAsStream(defaultResourceClass, fileName); |
101 | | - if (is != null) |
102 | | - { |
| 93 | + if (is != null) { |
103 | 94 | crypto = ResourceReader.getResourceAsStream(resourceClass, CRYPTO_CFG); |
104 | 95 | } |
105 | 96 | } |
106 | 97 |
|
107 | | - if (is == null) |
108 | | - { |
109 | | - try |
110 | | - { |
| 98 | + if (is == null) { |
| 99 | + try { |
| 100 | + is = new BufferedInputStream(new FileInputStream(fileName)); |
| 101 | + if (is != null) { |
| 102 | + crypto = new BufferedInputStream(new FileInputStream(CRYPTO_CFG)); |
| 103 | + } |
| 104 | + } catch (FileNotFoundException e) { |
| 105 | + try { |
111 | 106 | is = new BufferedInputStream(new FileInputStream(fileName)); |
112 | | - if (is != null) |
113 | | - { |
| 107 | + if (is != null) { |
114 | 108 | crypto = new BufferedInputStream(new FileInputStream(CRYPTO_CFG)); |
115 | 109 | } |
| 110 | + } catch (FileNotFoundException e2) { |
| 111 | + ; |
116 | 112 | } |
117 | | - catch (FileNotFoundException e) |
118 | | - { |
119 | | - try |
120 | | - { |
121 | | - is = new BufferedInputStream(new FileInputStream(fileName)); |
122 | | - if (is != null) |
123 | | - { |
124 | | - crypto = new BufferedInputStream(new FileInputStream(CRYPTO_CFG)); |
125 | | - } |
126 | | - } |
127 | | - catch (FileNotFoundException e2) { ; } |
128 | | - } |
| 113 | + } |
129 | 114 | } |
130 | 115 |
|
131 | | - if (is == null) |
132 | | - { |
133 | | - if (ApplicationContext.getInstance().isGXUtility()) |
134 | | - { |
135 | | - try |
136 | | - { |
| 116 | + if (is == null) { |
| 117 | + if (ApplicationContext.getInstance().isGXUtility()) { |
| 118 | + try { |
137 | 119 | is = new FileInputStream(fileName); |
138 | | - if (is != null) |
139 | | - { |
| 120 | + if (is != null) { |
140 | 121 | crypto = new FileInputStream(fileName); |
141 | 122 | } |
142 | | - } |
143 | | - catch (IOException e) |
144 | | - { |
| 123 | + } catch (IOException e) { |
145 | 124 | } |
146 | 125 | } |
147 | 126 | } |
|
0 commit comments