0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: /*
0043: * ManagedGroup.java
0044: *
0045: * Created on May 27, 2002, 9:49 PM
0046: */
0047:
0048: package org.netbeans.xtest.pes.xmlbeans;
0049:
0050: import org.netbeans.xtest.pe.xmlbeans.*;
0051: import org.netbeans.xtest.util.*;
0052: import org.netbeans.xtest.pes.*;
0053: import java.io.*;
0054: import java.util.*;
0055: import javax.xml.transform.*;
0056: import org.w3c.dom.*;
0057:
0058: // logging stuff
0059: import org.netbeans.xtest.pes.PESLogger;
0060: import java.util.logging.Level;
0061:
0062: /**
0063: *
0064: * @author breh
0065: */
0066: public class ManagedGroup extends PESProjectGroup {
0067:
0068: /** Creates a new instance of ManagedGroup */
0069: public ManagedGroup() {
0070: }
0071:
0072: // elements
0073: public ManagedReport[] xmlel_ManagedReport;
0074:
0075: // private stuff
0076: private File groupFile;
0077:
0078: private IncomingReport[] incomings;
0079: private PESWeb pesWeb;
0080: private PESProjectGroup pesProjectGroup;
0081:
0082: // bussiness methods
0083: /*
0084: public String getGroupFilename() {
0085: String name = GROUP_PREFIX+xmlat_name+XMLBEAN_FILE_SUFFIX;
0086: return FileUtils.normalizeName(name);
0087: }
0088: */
0089:
0090: public static ManagedGroup getDefault(PESWeb pesWeb,
0091: PESProjectGroup pesGroup) {
0092: ManagedGroup group = new ManagedGroup();
0093: group.xmlel_ManagedReport = new ManagedReport[0];
0094: group.readPESProjectGroup(pesGroup);
0095: group.pesWeb = pesWeb;
0096: group.pesProjectGroup = pesGroup;
0097: return group;
0098: }
0099:
0100: public static ManagedGroup loadManagedGroup(PESWeb web,
0101: PESProjectGroup group) throws IOException {
0102: //String filename =
0103: File groupData = new File(web.getDataDir(),
0104: getDataFilename(group));
0105: if (groupData.isFile()) {
0106: PESLogger.logger.finest("loading ManagedGroup from "
0107: + groupData);
0108: XMLBean aBean = null;
0109: try {
0110: aBean = XMLBean.loadXMLBean(groupData);
0111: } catch (ClassNotFoundException cnfe) {
0112: System.out.println("CNFE:" + cnfe);
0113: }
0114: if ((aBean == null) | !(aBean instanceof ManagedGroup)) {
0115: // this should not happen very often
0116: PESLogger.logger
0117: .finest("ManagedGroup could not be loaded from "
0118: + groupData);
0119: PESLogger.logger.finest("Installing new group");
0120: ManagedGroup mg = ManagedGroup.getDefault(web, group);
0121: mg.groupFile = groupData;
0122: return mg;
0123: } else {
0124: ManagedGroup mg = (ManagedGroup) aBean;
0125: mg.readPESProjectGroup(group);
0126: mg.pesWeb = web;
0127: mg.pesProjectGroup = group;
0128: mg.groupFile = groupData;
0129: return mg;
0130: }
0131: } else {
0132: ManagedGroup mg = ManagedGroup.getDefault(web, group);
0133: mg.groupFile = groupData;
0134: return mg;
0135: }
0136: }
0137:
0138: public void readPESProjectGroup(PESProjectGroup ppg) {
0139: this .xmlat_name = ppg.xmlat_name;
0140: this .xmlat_description = ppg.xmlat_description;
0141: this .xmlat_historyMatrices = ppg.xmlat_historyMatrices;
0142: this .xmlat_main = ppg.xmlat_main;
0143: this .xmlat_detailedData = ppg.xmlat_detailedData;
0144: this .xmlat_deleteAge = ppg.xmlat_deleteAge;
0145: this .xmlat_currentBuilds = ppg.xmlat_currentBuilds;
0146: this .xmlel_PESProject = null;
0147: }
0148:
0149: public void addIncomingReports(IncomingReport[] incomings) {
0150: PESLogger.logger.fine("adding incoming reports");
0151: this .incomings = incomings;
0152: if (incomings == null) {
0153: return;
0154: }
0155: ManagedReport[] newReports = new ManagedReport[incomings.length];
0156: for (int i = 0; i < incomings.length; i++) {
0157: ManagedReport mr = new ManagedReport();
0158: mr.readManagedReport(incomings[i]);
0159: // are hostnames mapped ?
0160: if (pesWeb.areHostnamesMapped()) {
0161: String mappedHostname = pesWeb.getMappedHostname(mr);
0162: mr.setMappedHostname(mappedHostname);
0163: PESLogger.logger.finer("Mapping hostname "
0164: + mr.getHost() + " to "
0165: + mr.getMappedHostname());
0166: }
0167:
0168: if (incomings[i].isReplace()) {
0169: if (xmlel_ManagedReport != null) {
0170: int index = mr.indexOf(xmlel_ManagedReport);
0171: if (index > -1) {
0172: xmlel_ManagedReport[index] = mr;
0173: continue;
0174: }
0175: }
0176: int index = mr.indexOf(newReports);
0177: if (index > -1) {
0178: newReports[index] = mr;
0179: continue;
0180: }
0181: }
0182: // well, add it
0183: newReports[i] = mr;
0184: }
0185: //
0186: newReports = (ManagedReport[]) XMLBean.shrinkArray(newReports);
0187: // now add the array to the existing one
0188: if (xmlel_ManagedReport == null) {
0189: xmlel_ManagedReport = newReports;
0190: } else {
0191: xmlel_ManagedReport = (ManagedReport[]) XMLBean.addToArray(
0192: xmlel_ManagedReport, newReports);
0193: }
0194: }
0195:
0196: // process web
0197: public void processWebPages() {
0198: PESLogger.logger.fine("processing web pages");
0199:
0200: // are there any incomings ?
0201: if ((incomings != null) & (incomings.length > 0))
0202: // convert main group file
0203:
0204: try {
0205: File groupHTMLFile = getGroupHTMLFile();
0206: PESLogger.logger.finer("Converting summary to:"
0207: + groupFile);
0208:
0209: //get webdata file
0210: File webDataFile = new File(groupFile.getParentFile(),
0211: ManagedWeb.getDataFilename());
0212: // prepare transformer
0213: Transformer transformer = XSLTransformers
0214: .getProjectsSummaryTransformer();
0215: transformer.setParameter("pesWebDataFile", webDataFile
0216: .getAbsolutePath());
0217: XSLUtils.transform(transformer, this .toDocument(),
0218: groupHTMLFile);
0219: } catch (Exception e) {
0220: PESLogger.logger.log(Level.WARNING,
0221: "Transforming unsucessfull", e);
0222: }
0223:
0224: // convert all projects
0225: Iterator projects = ManagedGroup.getUniqueProjects(incomings)
0226: .iterator();
0227: while (projects.hasNext()) {
0228: String project = (String) projects.next();
0229:
0230: // overall build summaries/history matrices/navigator frames
0231:
0232: Iterator departments = ManagedGroup.getUniqueTestingGroups(
0233: incomings, project).iterator();
0234: while (departments.hasNext()) {
0235: String department = (String) departments.next();
0236: Iterator types = ManagedGroup.getUniqueTestedTypes(
0237: incomings, project, department).iterator();
0238: while (types.hasNext()) {
0239: String type = (String) types.next();
0240: PESLogger.logger.fine("Processing project:"
0241: + project + " department:" + department
0242: + " type:" + type);
0243: try {
0244: ManagedGroup filteredGroup = ManagedGroup
0245: .getDefault(this .pesWeb,
0246: this .pesProjectGroup);
0247: filteredGroup
0248: .readPESProjectGroup(pesProjectGroup);
0249: filteredGroup.xmlel_ManagedReport = this
0250: .filterBy(project, null, department,
0251: type, null);
0252: Document filteredDOM = filteredGroup
0253: .toDocument();
0254:
0255: File projectFile = getProjectHTMLFile(project,
0256: department, type, true);
0257: PESLogger.logger.finer("Converting to:"
0258: + projectFile);
0259:
0260: Transformer transformer = XSLTransformers
0261: .getBuildsSummaryTransformer();
0262:
0263: XSLUtils.transform(transformer, filteredDOM,
0264: projectFile);
0265:
0266: if (xmlat_currentBuilds > 0) {
0267: projectFile = getProjectHTMLFile(project,
0268: department, type, false);
0269: PESLogger.logger.finest("As well as to:"
0270: + projectFile);
0271: transformer.setParameter("oldBuilds",
0272: "true");
0273: XSLUtils.transform(transformer,
0274: filteredDOM, projectFile);
0275: }
0276: // here goes the matrix ...
0277: if (getHistoryMatricesAge() > 0) {
0278: // do history matrices
0279: PESLogger.logger
0280: .finer("Creating HistoryMatrices, age="
0281: + getHistoryMatricesAge());
0282: Transformer historyTransformer = XSLTransformers
0283: .getBuildsHistoryMatrixTransformer();
0284: historyTransformer.setParameter(
0285: "includeExceptions",
0286: "" + pesWeb.includeExceptions());
0287: CreateHistoryMatrices matrices = new CreateHistoryMatrices(
0288: filteredGroup, historyTransformer);
0289: matrices
0290: .setBuildHistoryAge(getHistoryMatricesAge());
0291: matrices.createMatrices(project);
0292:
0293: }
0294: // clean up if applicable
0295: if (getDetailedDataAge() >= 0) {
0296: // clean up detailed data of some age()
0297: PESLogger.logger
0298: .finer("Setting trasinet flag with age "
0299: + getDetailedDataAge());
0300: setManagedReportsFlag(getDetailedDataAge(),
0301: project, department, type,
0302: ManagedReport.OLD);
0303: }
0304: // delete old builds if applicable
0305: if (getDeleteAge() > 0) {
0306: // delete all builds
0307: PESLogger.logger
0308: .finer("Setting delete flag with age "
0309: + getDeleteAge());
0310: setManagedReportsFlag(getDeleteAge(),
0311: project, department, type,
0312: ManagedReport.TO_BE_DELETED);
0313: }
0314: // create (recreate) build summary pages for all incoming builds
0315:
0316: Iterator builds = ManagedGroup.getUniqueBuilds(
0317: incomings, project, department, type,
0318: null).iterator();
0319: ManagedGroup buildFilteredGroup = ManagedGroup
0320: .getDefault(this .pesWeb,
0321: this .pesProjectGroup);
0322: buildFilteredGroup
0323: .readPESProjectGroup(pesProjectGroup);
0324: // for each found build create summary page
0325: while (builds.hasNext()) {
0326: String build = (String) builds.next();
0327: buildFilteredGroup.xmlel_ManagedReport = filteredGroup
0328: .filterBy(project, build,
0329: department, type, null);
0330: Document buildFilteredDOM = buildFilteredGroup
0331: .toDocument();
0332:
0333: File buildFile = getBuildHTMLFile(project,
0334: department, type, build);
0335: PESLogger.logger
0336: .finer("Converting build summary to:"
0337: + buildFile);
0338: Transformer buildTransformer = XSLTransformers
0339: .getBuildSummaryTransformer();
0340:
0341: try {
0342: XSLUtils.transform(buildTransformer,
0343: buildFilteredDOM, buildFile);
0344: } catch (TransformerException te) {
0345: PESLogger.logger
0346: .log(
0347: Level.WARNING,
0348: "Build summary transforming unsucessfull",
0349: te);
0350: } catch (IOException ioe) {
0351: PESLogger.logger
0352: .log(
0353: Level.WARNING,
0354: "Build summary transforming unsucessfull",
0355: ioe);
0356: }
0357: }
0358:
0359: } catch (Exception e) {
0360: PESLogger.logger.log(Level.WARNING,
0361: "Transforming unsucessfull", e);
0362: }
0363:
0364: }
0365: }
0366: }
0367: // clean up detailed data in all 'transient' files
0368: cleanUpAndRetransformTransients();
0369: // delete all files to be deleted (also remove them from metadata)
0370: cleanUpAndRemoveToBeDeleted();
0371: }
0372:
0373: // save the group to groupFile
0374: public void saveManagedGroup() throws IOException {
0375: if (groupFile != null) {
0376: this .saveXMLBean(groupFile);
0377: } else {
0378: throw new IOException(
0379: "group file is not specified - cannot save");
0380: }
0381: }
0382:
0383: // get main HTML file
0384: public File getGroupHTMLFile() throws IOException {
0385: String groupFilename;
0386: if (pesProjectGroup.isMain()) {
0387: groupFilename = "index.html";
0388: } else {
0389: if (pesProjectGroup.getName() == null) {
0390: throw new IOException(
0391: "Cannot create group HTML file, because name of the group is not set");
0392: }
0393: groupFilename = FileUtils.normalizeName("group-"
0394: + pesProjectGroup.getName() + ".html");
0395: }
0396: File result = new File(pesWeb.getWebRoot(), groupFilename);
0397: return result;
0398: }
0399:
0400: // get file for given project in this group
0401: public File getProjectHTMLFile(String projectName,
0402: String department, String testType, boolean current)
0403: throws IOException {
0404: if (projectName == null | department == null | testType == null) {
0405: throw new IllegalArgumentException(
0406: "arguments cannot be null");
0407: }
0408: File projectDir = new File(pesWeb.getWebRoot(), FileUtils
0409: .normalizeName(projectName));
0410: String prefix = "";
0411: if (!current) {
0412: prefix = "old-";
0413: }
0414: if (pesProjectGroup.getName() == null) {
0415: throw new IOException(
0416: "Cannot create Project HTML file, because name of the group is not set");
0417: } else {
0418: prefix = prefix + pesProjectGroup.getName() + "-";
0419: }
0420:
0421: File projectFile = new File(projectDir, FileUtils
0422: .normalizeName(prefix + department + "-" + testType
0423: + ".html"));
0424: return projectFile;
0425: }
0426:
0427: // get file for build summary file
0428: public File getBuildHTMLFile(String projectName, String department,
0429: String testType, String buildNumber) throws IOException {
0430: if (projectName == null | department == null | testType == null
0431: | buildNumber == null) {
0432: throw new IllegalArgumentException(
0433: "arguments cannot be null");
0434: }
0435: File buildDir = new File(pesWeb.getWebRoot(), FileUtils
0436: .normalizeName(projectName + "/" + buildNumber + "/"
0437: + department + "-" + testType));
0438: File buildFile = new File(buildDir, "index.html");
0439: return buildFile;
0440: }
0441:
0442: // get filename of xml file with ManagedReports for this group
0443: public static String getDataFilename(PESProjectGroup group) {
0444: String name = "groupdata-" + group.getName() + ".xml";
0445: return FileUtils.normalizeName(name);
0446: }
0447:
0448: // get webroot of this web
0449: public PESWeb getPESWeb() {
0450: return pesWeb;
0451: }
0452:
0453: // cleanup/ transient stuff
0454:
0455: public void setManagedReportsFlag(int age, String project,
0456: String department, String type, short flag) {
0457: // find 'age' number of builds in given project/department/type and if anything older than 'age'
0458: // is still new - set it's status to transient
0459: // get all builds for this project/department,type
0460: ManagedReport[] reports = this .filterBy(project, null,
0461: department, type, null);
0462: String[] uniqueBuilds = (String[]) ManagedGroup
0463: .getUniqueBuilds(reports).toArray(new String[0]);
0464: PESLogger.logger.finest("uniqueBuilds.length="
0465: + uniqueBuilds.length + " reports.length="
0466: + reports.length);
0467: if (uniqueBuilds.length > age) {
0468: Arrays.sort(uniqueBuilds);
0469: String lastBuild = null;
0470: if (age > 0) {
0471: lastBuild = uniqueBuilds[uniqueBuilds.length - age];
0472: }
0473: PESLogger.logger.finest("last build =" + lastBuild);
0474: for (int i = 0; i < reports.length; i++) {
0475: // find all builds older than lastBuilds
0476: if ((lastBuild == null)
0477: || (lastBuild.compareToIgnoreCase(reports[i]
0478: .getBuild()) > 0)) {
0479: switch (flag) {
0480: case ManagedReport.OLD:
0481: // process only new reports
0482: if (reports[i].isNew()) {
0483: reports[i]
0484: .setReportStatus(ManagedReport.IN_TRANSITION);
0485: }
0486: break;
0487: case ManagedReport.TO_BE_DELETED:
0488: // process only reports which are not already DELETED
0489: if (!reports[i].isToBeDeleted()) {
0490: reports[i]
0491: .setReportStatus(ManagedReport.TO_BE_DELETED);
0492: }
0493: break;
0494: }
0495: }
0496: }
0497: }
0498: }
0499:
0500: public void cleanUpAndRetransformTransients() {
0501: if (xmlel_ManagedReport == null) {
0502: // there is nothing to do - return
0503: return;
0504: }
0505: PESLogger.logger
0506: .fine("cleaning up detailed data for transients");
0507: for (int i = 0; i < xmlel_ManagedReport.length; i++) {
0508: ManagedReport report = xmlel_ManagedReport[i];
0509: if (report != null) {
0510: if (report.isInTransition()) {
0511: try {
0512: File reportRoot = new File(pesWeb.getWebRoot(),
0513: report.getPathToResultsRoot());
0514: if (reportRoot.isDirectory()) {
0515: try {
0516: PESLogger.logger
0517: .finest("deleting detailed data for "
0518: + reportRoot);
0519: report.deleteDetailedData(reportRoot,
0520: true, false);
0521: PESLogger.logger
0522: .finest("retransforming report to not include links to detailed data");
0523: // retransform report
0524: XSLTransformers
0525: .transformResultsForServer(
0526: reportRoot, true, true,
0527: true, null,
0528: pesProjectGroup, true);
0529: report
0530: .setReportStatus(ManagedReport.OLD);
0531: } catch (IOException ioe) {
0532: PESLogger.logger.log(Level.WARNING,
0533: "IOExcepting caught when deleting detailed Data at "
0534: + reportRoot, ioe);
0535: } catch (Exception e) {
0536: PESLogger.logger.log(Level.WARNING,
0537: "Excepting cautgh when retransforming transient report at "
0538: + reportRoot, e);
0539: }
0540: } else {
0541: PESLogger.logger.warning("Report root "
0542: + reportRoot
0543: + " is not a valid directory");
0544: }
0545: } catch (IOException ioe) {
0546: PESLogger.logger
0547: .log(
0548: Level.WARNING,
0549: "IOExcepting caught when determining report root "
0550: + report
0551: .getPathToResultsRoot(),
0552: ioe);
0553: }
0554: }
0555: }
0556: }
0557: }
0558:
0559: public void cleanUpAndRemoveToBeDeleted() {
0560: if (xmlel_ManagedReport == null) {
0561: // there is nothing to do - return
0562: return;
0563: }
0564: PESLogger.logger.fine("cleaning up to be deleted reports");
0565: for (int i = 0; i < xmlel_ManagedReport.length; i++) {
0566: ManagedReport report = xmlel_ManagedReport[i];
0567: if (report != null) {
0568: if (report.isToBeDeleted()) {
0569: try {
0570: // e.g. netbeans_dev/200609131100
0571: File buildRoot = new File(pesWeb.getWebRoot(),
0572: FileUtils.normalizeName(report
0573: .getProject())
0574: + "/"
0575: + FileUtils
0576: .normalizeName(report
0577: .getBuild()));
0578: // e.g. netbeans_dev/200609131100/qa-functional_validation
0579: File typeRoot = new File(
0580: buildRoot,
0581: FileUtils.normalizeName(report
0582: .getTestingGroup())
0583: + "-"
0584: + FileUtils
0585: .normalizeName(report
0586: .getTestedType()));
0587: PESLogger.logger
0588: .finest("deleting old reports at "
0589: + typeRoot);
0590: if (FileUtils.delete(typeRoot)) {
0591: // remove report from the collection
0592: xmlel_ManagedReport[i] = null;
0593: } else {
0594: PESLogger.logger
0595: .warning("Cannot delete directory "
0596: + typeRoot);
0597: }
0598: if (buildRoot.exists()
0599: && buildRoot.list().length == 0) {
0600: PESLogger.logger
0601: .finest("deleting empty build directory "
0602: + buildRoot);
0603: if (!buildRoot.delete()) {
0604: PESLogger.logger
0605: .warning("Cannot delete directory "
0606: + buildRoot);
0607: }
0608: }
0609: } catch (IOException ioe) {
0610: PESLogger.logger
0611: .log(
0612: Level.WARNING,
0613: "IOExcepting caught when determining web root.",
0614: ioe);
0615: }
0616: }
0617: }
0618: }
0619: // now shrink array, so it does not contain any nulls;
0620: xmlel_ManagedReport = (ManagedReport[]) XMLBean
0621: .shrinkArray(xmlel_ManagedReport);
0622: }
0623:
0624: //
0625: //
0626: // unique stuff
0627: //
0628:
0629: public static Collection getUniqueProjects(ManagedReport[] reports) {
0630: HashSet uniqueProjectsSet = new HashSet();
0631: if (reports != null) {
0632: for (int i = 0; i < reports.length; i++) {
0633: String currentProject = reports[i].xmlat_project;
0634: if (!uniqueProjectsSet.contains(currentProject)) {
0635: uniqueProjectsSet.add(currentProject);
0636: }
0637: }
0638: }
0639: return uniqueProjectsSet;
0640: }
0641:
0642: public Collection getUniqueProjects() {
0643: return getUniqueProjects(xmlel_ManagedReport);
0644: }
0645:
0646: public Collection getUniqueHosts() {
0647: HashSet uniqueHostsSet = new HashSet();
0648: if (xmlel_ManagedReport != null) {
0649: for (int i = 0; i < xmlel_ManagedReport.length; i++) {
0650: String currentHost = xmlel_ManagedReport[i].xmlat_host;
0651: if (!uniqueHostsSet.contains(currentHost)) {
0652: uniqueHostsSet.add(currentHost);
0653: }
0654: }
0655: }
0656: return uniqueHostsSet;
0657: }
0658:
0659: public Collection getUniqueHosts(String inProject) {
0660: HashSet uniqueHostsSet = new HashSet();
0661: if (xmlel_ManagedReport != null) {
0662: for (int i = 0; i < xmlel_ManagedReport.length; i++) {
0663: if (inProject != null) {
0664: if (!inProject
0665: .equals(xmlel_ManagedReport[i].xmlat_project)) {
0666: // this is not our project !!!
0667: continue;
0668: }
0669: }
0670: String currentHost = xmlel_ManagedReport[i].xmlat_host;
0671: if (!uniqueHostsSet.contains(currentHost)) {
0672: uniqueHostsSet.add(currentHost);
0673: }
0674: }
0675: }
0676: return uniqueHostsSet;
0677: }
0678:
0679: public static Collection getUniqueTestingGroups(
0680: ManagedReport[] reports, String inProject) {
0681: HashSet uniqueGroupsSet = new HashSet();
0682: if (reports != null) {
0683: for (int i = 0; i < reports.length; i++) {
0684: if (inProject != null) {
0685: if (!inProject.equals(reports[i].xmlat_project)) {
0686: // this is not our project !!!
0687: continue;
0688: }
0689: }
0690: String currentGroup = reports[i].xmlat_testingGroup;
0691: if (!uniqueGroupsSet.contains(currentGroup)) {
0692: uniqueGroupsSet.add(currentGroup);
0693: }
0694: }
0695: }
0696: return uniqueGroupsSet;
0697:
0698: }
0699:
0700: public Collection getUniqueTestingGroups(String inProject) {
0701: return getUniqueTestingGroups(this .xmlel_ManagedReport,
0702: inProject);
0703: }
0704:
0705: public static Collection getUniqueTestedTypes(
0706: ManagedReport[] reports, String inProject, String inGroup) {
0707: HashSet uniqueTypesSet = new HashSet();
0708: if (reports != null) {
0709: for (int i = 0; i < reports.length; i++) {
0710: if (inProject != null) {
0711: if (!inProject.equals(reports[i].xmlat_project)) {
0712: // this is not our project !!!
0713: continue;
0714: }
0715: }
0716: if (inGroup != null) {
0717: if (!inGroup
0718: .equals((reports[i].xmlat_testingGroup))) {
0719: continue;
0720: }
0721: }
0722: String currentType = reports[i].xmlat_testedType;
0723: if (!uniqueTypesSet.contains(currentType)) {
0724: uniqueTypesSet.add(currentType);
0725: }
0726: }
0727: }
0728: return uniqueTypesSet;
0729: }
0730:
0731: public Collection getUniqueTestedTypes(String inProject,
0732: String inGroup) {
0733: return getUniqueTestedTypes(this .xmlel_ManagedReport,
0734: inProject, inGroup);
0735: }
0736:
0737: public Collection getUniqueHosts(String inProject, String inGroup,
0738: String inType) {
0739: HashSet uniqueHostsSet = new HashSet();
0740: if (xmlel_ManagedReport != null) {
0741: for (int i = 0; i < xmlel_ManagedReport.length; i++) {
0742: if (inProject != null) {
0743: if (!inProject
0744: .equals(xmlel_ManagedReport[i].xmlat_project)) {
0745: // this is not our project !!!
0746: continue;
0747: }
0748: }
0749: if (inGroup != null) {
0750: if (!inGroup
0751: .equals((xmlel_ManagedReport[i].xmlat_testingGroup))) {
0752: continue;
0753: }
0754: }
0755: if (inType != null) {
0756: if (!inGroup
0757: .equals((xmlel_ManagedReport[i].xmlat_testingGroup))) {
0758: continue;
0759: }
0760: }
0761: String currentHost = null;
0762: if (xmlel_ManagedReport[i].getMappedHostname() != null) {
0763: currentHost = xmlel_ManagedReport[i]
0764: .getMappedHostname();
0765: } else {
0766: currentHost = xmlel_ManagedReport[i].getHost();
0767: }
0768: if (!uniqueHostsSet.contains(currentHost)) {
0769: uniqueHostsSet.add(currentHost);
0770: }
0771: }
0772: }
0773: return uniqueHostsSet;
0774: }
0775:
0776: private Collection getUniqueBuilds() {
0777: return getUniqueBuilds(null, null, null, null);
0778: }
0779:
0780: public Collection getUniqueBuilds(String inProject) {
0781: HashSet uniqueBuildsSet = new HashSet();
0782: if (xmlel_ManagedReport != null) {
0783: for (int i = 0; i < xmlel_ManagedReport.length; i++) {
0784: if (inProject != null) {
0785: if (!inProject
0786: .equals(xmlel_ManagedReport[i].xmlat_project)) {
0787: // this is not our project !!!
0788: continue;
0789: }
0790: }
0791: String currentBuild = xmlel_ManagedReport[i].xmlat_build;
0792: if (!uniqueBuildsSet.contains(currentBuild)) {
0793: uniqueBuildsSet.add(currentBuild);
0794: }
0795: }
0796: }
0797: return uniqueBuildsSet;
0798: }
0799:
0800: public Collection getUniqueBuildsWithStatus(String inProject,
0801: short status) {
0802: HashSet uniqueBuildsSet = new HashSet();
0803: if (xmlel_ManagedReport != null) {
0804: for (int i = 0; i < xmlel_ManagedReport.length; i++) {
0805: if (inProject != null) {
0806: if (!inProject
0807: .equals(xmlel_ManagedReport[i].xmlat_project)) {
0808: // this is not our project !!!
0809: continue;
0810: }
0811: }
0812: if (xmlel_ManagedReport[i].xmlat_reportStatus == status) {
0813: String currentBuild = xmlel_ManagedReport[i].xmlat_build;
0814: if (!uniqueBuildsSet.contains(currentBuild)) {
0815: uniqueBuildsSet.add(currentBuild);
0816: }
0817: }
0818: }
0819: }
0820: return uniqueBuildsSet;
0821: }
0822:
0823: public Collection getUniqueBuilds(String inProject, String fromHost) {
0824: HashSet uniqueBuildsSet = new HashSet();
0825: if (xmlel_ManagedReport != null) {
0826: for (int i = 0; i < xmlel_ManagedReport.length; i++) {
0827: if (inProject != null) {
0828: if (!inProject
0829: .equals(xmlel_ManagedReport[i].xmlat_project)) {
0830: // this is not our project !!!
0831: continue;
0832: }
0833: }
0834: if (fromHost != null) {
0835: if (!fromHost
0836: .equals(xmlel_ManagedReport[i].xmlat_host)) {
0837: // this is not our host !!!
0838: continue;
0839: }
0840: }
0841: String currentBuild = xmlel_ManagedReport[i].xmlat_build;
0842: if (!uniqueBuildsSet.contains(currentBuild)) {
0843: uniqueBuildsSet.add(currentBuild);
0844: }
0845: }
0846: }
0847: return uniqueBuildsSet;
0848: }
0849:
0850: public Collection getUniqueBuilds(String inProject, String inGroup,
0851: String inType) {
0852: return getUniqueBuilds(inProject, inGroup, inType, null);
0853: }
0854:
0855: public Collection getUniqueBuilds(String inProject, String inGroup,
0856: String inType, String fromHost) {
0857: return getUniqueBuilds(this .xmlel_ManagedReport, inProject,
0858: inGroup, inType, fromHost);
0859: }
0860:
0861: public static Collection getUniqueBuilds(ManagedReport[] reports) {
0862: return ManagedGroup.getUniqueBuilds(reports, null, null, null,
0863: null);
0864: }
0865:
0866: public static Collection getUniqueBuilds(ManagedReport[] reports,
0867: String inProject, String inGroup, String inType,
0868: String fromHost) {
0869: HashSet uniqueBuildsSet = new HashSet();
0870: if (reports != null) {
0871: for (int i = 0; i < reports.length; i++) {
0872: if (inProject != null) {
0873: if (!inProject.equals(reports[i].xmlat_project)) {
0874: // this is not our project !!!
0875: continue;
0876: }
0877: }
0878: if (inGroup != null) {
0879: if (!inGroup
0880: .equals((reports[i].xmlat_testingGroup))) {
0881: continue;
0882: }
0883: }
0884: if (inType != null) {
0885: if (!inType.equals((reports[i].xmlat_testedType))) {
0886: continue;
0887: }
0888: }
0889: if (fromHost != null) {
0890: if (!fromHost.equals(reports[i].xmlat_host)) {
0891: // this is not our host !!!
0892: continue;
0893: }
0894: }
0895: String currentBuild = reports[i].xmlat_build;
0896: if (!uniqueBuildsSet.contains(currentBuild)) {
0897: uniqueBuildsSet.add(currentBuild);
0898: }
0899: }
0900: }
0901: return uniqueBuildsSet;
0902: }
0903:
0904: // new stuff - get unique teams
0905: public static Collection getUniqueTeams(ManagedReport[] reports,
0906: String inProject) {
0907: HashSet uniqueTeamSet = new HashSet();
0908: if (reports != null) {
0909: for (int i = 0; i < reports.length; i++) {
0910: if (inProject != null) {
0911: if (!inProject.equals(reports[i].xmlat_project)) {
0912: // this is not our project !!!
0913: continue;
0914: }
0915: }
0916: String currentTeam = reports[i].getTeam();
0917: if (currentTeam != null) {
0918: if (!uniqueTeamSet.contains(currentTeam)) {
0919: uniqueTeamSet.add(currentTeam);
0920: }
0921: }
0922: }
0923: }
0924: return uniqueTeamSet;
0925: }
0926:
0927: public Collection getUniqueTeams(String inProject) {
0928: return ManagedGroup.getUniqueTeams(this .xmlel_ManagedReport,
0929: inProject);
0930: }
0931:
0932: // filters !!!
0933:
0934: public ManagedReport[] filterBy(String project, String build,
0935: String testingGroup, String testedType, String host) {
0936: if (this .xmlel_ManagedReport == null) {
0937: return null;
0938: }
0939: ManagedReport[] filteredReport = new ManagedReport[this .xmlel_ManagedReport.length];
0940: int newSize = 0;
0941: for (int i = 0; i < xmlel_ManagedReport.length; i++) {
0942: if (xmlel_ManagedReport[i].isEqualTo(project, build,
0943: testingGroup, testedType, host)) {
0944: filteredReport[newSize] = xmlel_ManagedReport[i];
0945: newSize++;
0946: }
0947: }
0948: ManagedReport[] resultingReport = new ManagedReport[newSize];
0949: for (int i = 0; i < newSize; i++) {
0950: resultingReport[i] = filteredReport[i];
0951: }
0952:
0953: return resultingReport;
0954: }
0955:
0956: // select only projects listed in projects array
0957: public ManagedReport[] filterByProjects(String projects[]) {
0958: if (this .xmlel_ManagedReport == null) {
0959: return null;
0960: }
0961: if (projects == null) {
0962: throw new IllegalArgumentException(
0963: "argument cannot be null");
0964: }
0965:
0966: ManagedReport[] filteredReport = new ManagedReport[this .xmlel_ManagedReport.length];
0967: int newSize = 0;
0968: for (int i = 0; i < xmlel_ManagedReport.length; i++) {
0969: for (int j = 0; j < projects.length; j++) {
0970: if (projects[j]
0971: .equals(xmlel_ManagedReport[i].xmlat_project)) {
0972: filteredReport[newSize] = xmlel_ManagedReport[i];
0973: newSize++;
0974: break;
0975: }
0976: }
0977: }
0978: ManagedReport[] resultingReport = new ManagedReport[newSize];
0979: for (int i = 0; i < newSize; i++) {
0980: resultingReport[i] = filteredReport[i];
0981: }
0982:
0983: return resultingReport;
0984: }
0985:
0986: // select only projects not listed in the array
0987: public ManagedReport[] filterProjects(String projects[]) {
0988: if (this .xmlel_ManagedReport == null) {
0989: return null;
0990: }
0991: if (projects == null) {
0992: throw new IllegalArgumentException(
0993: "argument cannot be null");
0994: }
0995:
0996: ManagedReport[] filteredReport = new ManagedReport[this .xmlel_ManagedReport.length];
0997: int newSize = 0;
0998: for (int i = 0; i < xmlel_ManagedReport.length; i++) {
0999: int j = 0;
1000: for (j = 0; j < projects.length; j++) {
1001: if (projects[j]
1002: .equals(xmlel_ManagedReport[i].xmlat_project)) {
1003: break;
1004: }
1005: }
1006: if (j == projects.length) {
1007: // this report is not of any given project - add it to result
1008: filteredReport[newSize] = xmlel_ManagedReport[i];
1009: newSize++;
1010: }
1011: }
1012: ManagedReport[] resultingReport = new ManagedReport[newSize];
1013: for (int i = 0; i < newSize; i++) {
1014: resultingReport[i] = filteredReport[i];
1015: }
1016:
1017: return resultingReport;
1018: }
1019:
1020: }
|