1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package share; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import java.io.BufferedReader; 30*cdf0e10cSrcweir import java.io.FileReader; 31*cdf0e10cSrcweir import java.util.ArrayList; 32*cdf0e10cSrcweir import java.util.StringTokenizer; 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir import java.util.Vector; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir /** 37*cdf0e10cSrcweir * 38*cdf0e10cSrcweir * Base Interface to get a description for a given TestJob 39*cdf0e10cSrcweir * 40*cdf0e10cSrcweir */ 41*cdf0e10cSrcweir public abstract class DescGetter 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir public abstract DescEntry[] getDescriptionFor(String entry, 45*cdf0e10cSrcweir String DescPath, 46*cdf0e10cSrcweir boolean debug); 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir protected abstract DescEntry getDescriptionForSingleJob(String job, 49*cdf0e10cSrcweir String descPath, 50*cdf0e10cSrcweir boolean debug); 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir protected abstract String[] createScenario(String descPath, String job, 53*cdf0e10cSrcweir boolean debug); 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir protected DescEntry[] getScenario(String url, String descPath, 56*cdf0e10cSrcweir boolean debug) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir Vector entryList = new Vector(); 59*cdf0e10cSrcweir String line = ""; 60*cdf0e10cSrcweir BufferedReader scenario = null; 61*cdf0e10cSrcweir DescEntry[] entries = null; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir try 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir scenario = new BufferedReader(new FileReader(url)); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir catch (java.io.FileNotFoundException fnfe) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir System.out.println("Couldn't find file " + url); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir return entries; 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir while (line != null) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir try 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir if (line.startsWith("-o")) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir String job = line.substring(3, line.length()).trim(); 81*cdf0e10cSrcweir DescEntry aEntry; 82*cdf0e10cSrcweir // special in case several Interfaces are given comma separated 83*cdf0e10cSrcweir if (job.indexOf(",") < 0) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir aEntry = getDescriptionForSingleJob(job, descPath, 86*cdf0e10cSrcweir debug); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir else 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir ArrayList subs = getSubInterfaces(job); 91*cdf0e10cSrcweir String partjob = job.substring(0, job.indexOf(",")).trim(); 92*cdf0e10cSrcweir aEntry = getDescriptionForSingleJob(partjob, descPath, 93*cdf0e10cSrcweir debug); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir if (aEntry != null) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir for (int i = 0; i < aEntry.SubEntryCount; i++) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir String subEntry = aEntry.SubEntries[i].longName; 100*cdf0e10cSrcweir int cpLength = aEntry.longName.length(); 101*cdf0e10cSrcweir subEntry = subEntry.substring(cpLength + 2, 102*cdf0e10cSrcweir subEntry.length()); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir if (subs.contains(subEntry)) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir aEntry.SubEntries[i].isToTest = true; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir // DescEntry aEntry = getDescriptionForSingleJob( 112*cdf0e10cSrcweir // line.substring(3).trim(), descPath, 113*cdf0e10cSrcweir // debug); 114*cdf0e10cSrcweir if (aEntry != null) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir entryList.add(aEntry); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir else if (line.startsWith("-sce")) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir DescEntry[] subs = getScenario(line.substring(5, 122*cdf0e10cSrcweir line.length()).trim(), descPath, 123*cdf0e10cSrcweir debug); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir for (int i = 0; i < subs.length; i++) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir entryList.add(subs[i]); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir else if (line.startsWith("-p")) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir String[] perModule = createScenario(descPath, 133*cdf0e10cSrcweir line.substring(3).trim(), debug); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir for (int i = 0; i < perModule.length; i++) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir DescEntry aEntry = getDescriptionForSingleJob( 138*cdf0e10cSrcweir perModule[i].substring(3).trim(), 139*cdf0e10cSrcweir descPath, debug); 140*cdf0e10cSrcweir if (aEntry != null) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir entryList.add(aEntry); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir line = scenario.readLine(); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir catch (java.io.IOException ioe) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir if (debug) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir System.out.println("Exception while reading scenario"); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir try 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir scenario.close(); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir catch (java.io.IOException ioe) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir if (debug) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir System.out.println("Exception while closeing scenario"); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir if (entryList.size() == 0) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir return null; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir entries = new DescEntry[entryList.size()]; 175*cdf0e10cSrcweir entries = (DescEntry[]) entryList.toArray(entries); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir return entries; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir protected ArrayList getSubInterfaces(String job) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir ArrayList namesList = new ArrayList(); 183*cdf0e10cSrcweir StringTokenizer st = new StringTokenizer(job, ","); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir for (int i = 0; st.hasMoreTokens(); i++) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir String token = st.nextToken(); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir if (token.indexOf(".") < 0) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir namesList.add(token); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir return namesList; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir }