Eclipseplugins
ReadDemasFile.java
1 package com.proalpha.pds.projconf.importwizards;
2 
3 
4 import java.io.File;
5 import java.io.FileInputStream;
6 import java.io.IOException;
7 import java.util.HashMap;
8 import java.util.Map;
9 import java.util.Properties;
10 
11 public class ReadDemasFile {
12 
13  private static final String[] iniprops = { "appserverslist", "assembliesDir", "buildFileDir",
14  "clientFolderProAlphaMaster", "clientfolderdb", "clientfolderproalpha", "dbConnectionProperties", "dlc",
15  "environment", "gitProjectRepository", "isInstallCry", "isPatchLevelInstallation", "jiraProject", "jiraURL",
16  "linkedFolderList", "masterVersionList", "objDir", "propathTemplate", "project", "startParameter",
17  "subversionlist", "tempDir", "version", "consistencychecks.location" };
18 
19  private String ininame = "";
20  private boolean validIni = false;
21  private String missingField = "";
22 
23  private Map<String, String> iniParams = new HashMap<>();
24 
30  public ReadDemasFile(String ininame) {
31  super();
32  this.ininame = ininame;
33  this.checkIni();
34  }
35 
42  public boolean isValidIni() {
43  return this.validIni;
44 
45  }
46 
47  public String getmissingField() {
48  return missingField;
49  }
50 
51  public String getIniname() {
52  return ininame;
53  }
54 
55  public String getProject() {
56  return iniParams.get("project");
57  }
58 
59  public String getVersion() {
60  return iniParams.get("version");
61  }
62 
63  public String getEnvironment() {
64  return iniParams.get("environment");
65  }
66 
67  public String getDbConnectionProperties() {
68  return iniParams.get("dbConnectionProperties");
69  }
70 
71  public String getClientfolderproalpha() {
72  return iniParams.get("clientfolderproalpha");
73  }
74 
75  public String getClientfolderdb() {
76  return iniParams.get("clientfolderdb");
77  }
78 
79  public String getSubversionlist() {
80  return iniParams.get("subversionlist");
81  }
82 
83  public String getAssembliesDir() {
84  return iniParams.get("assembliesDir");
85  }
86 
87  public String getAppserverslist() {
88  return iniParams.get("appserverslist");
89  }
90 
91  public String getStartParameter() {
92  return iniParams.get("startParameter");
93  }
94 
95  public String getIsInstallCry() {
96  return iniParams.get("isInstallCry");
97  }
98 
99  public String getClientFolderProAlphaMaster() {
100  return iniParams.get("clientFolderProAlphaMaster");
101  }
102 
103  public String getMasterVersionList() {
104  return iniParams.get("masterVersionList");
105  }
106 
107  public String getLinkedFolderList() {
108  return iniParams.get("linkedFolderList");
109  }
110 
111  public String getBuildFileDir() {
112  return iniParams.get("buildFileDir");
113  }
114 
115  public String getPropathTemplate() {
116  return iniParams.get("propathTemplate");
117  }
118 
119  public String getIsPatchLevelInstallation() {
120  return iniParams.get("isPatchLevelInstallation");
121  }
122 
123  public String getTempDir() {
124  return iniParams.get("tempDir");
125  }
126 
127  public String getObjDir() {
128  return iniParams.get("objDir");
129  }
130 
131  public String getDlc() {
132  return iniParams.get("dlc");
133  }
134 
135  public String getRepositoryUrl() {
136  return iniParams.get("gitProjectRepository");
137  }
138 
139  public String getJiraUrl() {
140  return iniParams.get("jiraURL");
141  }
142 
143  public String getJiraProject() {
144  return iniParams.get("jiraProject");
145  }
146 
147  public String getConsistencyChecksLocationLocal()
148  {
149  return iniParams.get("tempDir");
150  }
151 
152  public String getConsistencyChecksLocationServer() {
153  return iniParams.get("consistencychecks.location");
154  }
155 
156  public String[] getIniProperties() {
157  return iniprops;
158  }
159 
160  public String getFullProjectName() {
161  return getProject() + "-" + getVersion() + "-" + getEnvironment();
162  }
163 
169  private void checkIni() {
170 
171  File file = new File(this.ininame);
172 
173  if (!file.exists()) {
174  validIni = false;
175  return;
176  }
177 
178  validIni = this.readAndCheckIni();
179 
180  }
181 
188  private boolean readAndCheckIni() {
189  String keyname = "";
190 
191  try (FileInputStream fileInput = new FileInputStream(this.ininame)) {
192  Properties properties = new Properties();
193  properties.load(fileInput);
194 
195  for (int i = 0; i < iniprops.length; i++) {
196 
197  keyname = iniprops[i];
198  if (!properties.containsKey(keyname)) {
199  missingField = keyname;
200  return false;
201  } else {
202  iniParams.put(keyname, properties.getProperty(keyname));
203  }
204 
205  }
206 
207  }
208 
209  catch (IOException e) {
210  return false;
211  }
212 
213  return true;
214 
215  }
216 }