1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package share;
24 
25 import java.io.BufferedReader;
26 import java.io.FileReader;
27 import java.util.ArrayList;
28 import java.util.StringTokenizer;
29 
30 import java.util.Vector;
31 
32 /**
33  *
34  * Base Interface to get a description for a given TestJob
35  *
36  */
37 public abstract class DescGetter
38 {
39 
getDescriptionFor(String entry, String DescPath, boolean debug)40     public abstract DescEntry[] getDescriptionFor(String entry,
41             String DescPath,
42             boolean debug);
43 
getDescriptionForSingleJob(String job, String descPath, boolean debug)44     protected abstract DescEntry getDescriptionForSingleJob(String job,
45             String descPath,
46             boolean debug);
47 
createScenario(String descPath, String job, boolean debug)48     protected abstract String[] createScenario(String descPath, String job,
49             boolean debug);
50 
getScenario(String url, String descPath, boolean debug)51     protected DescEntry[] getScenario(String url, String descPath,
52             boolean debug)
53     {
54         Vector entryList = new Vector();
55         String line = "";
56         BufferedReader scenario = null;
57         DescEntry[] entries = null;
58 
59         try
60         {
61             scenario = new BufferedReader(new FileReader(url));
62         }
63         catch (java.io.FileNotFoundException fnfe)
64         {
65             System.out.println("Couldn't find file " + url);
66 
67             return entries;
68         }
69 
70         while (line != null)
71         {
72             try
73             {
74                 if (line.startsWith("-o"))
75                 {
76                     String job = line.substring(3, line.length()).trim();
77                     DescEntry aEntry;
78                     // special in case several Interfaces are given comma separated
79                     if (job.indexOf(",") < 0)
80                     {
81                         aEntry = getDescriptionForSingleJob(job, descPath,
82                                 debug);
83                     }
84                     else
85                     {
86                         ArrayList subs = getSubInterfaces(job);
87                         String partjob = job.substring(0, job.indexOf(",")).trim();
88                         aEntry = getDescriptionForSingleJob(partjob, descPath,
89                                 debug);
90 
91                         if (aEntry != null)
92                         {
93                             for (int i = 0; i < aEntry.SubEntryCount; i++)
94                             {
95                                 String subEntry = aEntry.SubEntries[i].longName;
96                                 int cpLength = aEntry.longName.length();
97                                 subEntry = subEntry.substring(cpLength + 2,
98                                         subEntry.length());
99 
100                                 if (subs.contains(subEntry))
101                                 {
102                                     aEntry.SubEntries[i].isToTest = true;
103                                 }
104                             }
105                         }
106                     }
107 //                    DescEntry aEntry = getDescriptionForSingleJob(
108 //                                          line.substring(3).trim(), descPath,
109 //                                          debug);
110                     if (aEntry != null)
111                     {
112                         entryList.add(aEntry);
113                     }
114                 }
115                 else if (line.startsWith("-sce"))
116                 {
117                     DescEntry[] subs = getScenario(line.substring(5,
118                             line.length()).trim(), descPath,
119                             debug);
120 
121                     for (int i = 0; i < subs.length; i++)
122                     {
123                         entryList.add(subs[i]);
124                     }
125                 }
126                 else if (line.startsWith("-p"))
127                 {
128                     String[] perModule = createScenario(descPath,
129                             line.substring(3).trim(), debug);
130 
131                     for (int i = 0; i < perModule.length; i++)
132                     {
133                         DescEntry aEntry = getDescriptionForSingleJob(
134                                 perModule[i].substring(3).trim(),
135                                 descPath, debug);
136                         if (aEntry != null)
137                         {
138                             entryList.add(aEntry);
139                         }
140                     }
141                 }
142 
143                 line = scenario.readLine();
144             }
145             catch (java.io.IOException ioe)
146             {
147                 if (debug)
148                 {
149                     System.out.println("Exception while reading scenario");
150                 }
151             }
152         }
153 
154         try
155         {
156             scenario.close();
157         }
158         catch (java.io.IOException ioe)
159         {
160             if (debug)
161             {
162                 System.out.println("Exception while closeing scenario");
163             }
164         }
165 
166         if (entryList.size() == 0)
167         {
168             return null;
169         }
170         entries = new DescEntry[entryList.size()];
171         entries = (DescEntry[]) entryList.toArray(entries);
172 
173         return entries;
174     }
175 
getSubInterfaces(String job)176     protected ArrayList getSubInterfaces(String job)
177     {
178         ArrayList namesList = new ArrayList();
179         StringTokenizer st = new StringTokenizer(job, ",");
180 
181         for (int i = 0; st.hasMoreTokens(); i++)
182         {
183             String token = st.nextToken();
184 
185             if (token.indexOf(".") < 0)
186             {
187                 namesList.add(token);
188             }
189         }
190 
191         return namesList;
192     }
193 }