add common lib
[ccsdk/features.git] / sdnr / wt / common / src / main / java / org / onap / ccsdk / features / sdnr / wt / common / file / PomPropertiesFile.java
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.common.file;
19
20 import java.io.ByteArrayOutputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.text.DateFormat;
24 import java.text.ParseException;
25 import java.text.SimpleDateFormat;
26 import java.util.Date;
27 import java.util.Locale;
28
29 /**
30  * Example Content:
31  *   #Generated by org.apache.felix.bundleplugin
32  *   #Tue Nov 19 10:17:57 CET 2019
33  *   version=0.7.0-SNAPSHOT
34  *   groupId=org.onap.ccsdk.features.sdnr.wt
35 *    artifactId=sdnr-wt-data-provider-provider
36  * @author jack
37  *
38  */
39 public class PomPropertiesFile {
40
41         private Date buildDate;
42         private String version;
43         private String groupId;
44         private String artifactId;
45         
46         public Date getBuildDate() {
47                 return this.buildDate;
48         }
49         public String getVersion() {
50                 return this.version;
51         }
52         public String getGroupId() {
53                 return this.groupId;
54         }
55         public String getArtifactId() {
56                 return this.artifactId;
57         }
58         private final DateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
59         public PomPropertiesFile(InputStream is) throws IOException {
60                 ByteArrayOutputStream bos = new ByteArrayOutputStream();
61                 int intRead;
62                 while ((intRead = is.read()) != -1) {
63                         bos.write(intRead);
64                 }
65                 this.parse(new String(bos.toByteArray()));
66         }
67
68         private void parse(String s) {
69                 String[] lines = s.split("\n");
70                 for(String line:lines) {
71                         
72                         if(line.startsWith("#Generated")) {
73                                 
74                         } else if( line.startsWith("groupId")) {
75                                 this.groupId = line.substring("groupId=".length());
76                         }
77                         else if(line.startsWith("artifactId")) {
78                                 this.artifactId = line.substring("artifactId=".length());
79                         }
80                         else if(line.startsWith("#")){
81                                 try {
82                                         this.buildDate = sdf.parse(line.substring(1));
83                                 } catch (ParseException e) {
84                                         
85                                 }
86                         }
87                         if(version!=null && this.buildDate!=null && this.groupId!=null && this.artifactId!=null) {
88                                 break;
89                         }
90                 }
91         }
92 }