package org.jenkinsci.plugins.p4.client; import com.perforce.p4java.core.file.FileSpecOpStatus; import com.perforce.p4java.core.file.IFileSpec; import hudson.AbortException; import hudson.model.TaskListener; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.logging.Logger; public class Validate { private static Logger logger = Logger.getLogger(Validate.class.getName()); private final TaskListener listener; public Validate(TaskListener listener) { this.listener = listener; } /** * Look for a message in the returned FileSpec from operation. * * @param fileSpecs List of Perforce file specs * @param ignore Parameter list of messages to ignore * @return true if no errors. * @throws Exception push up stack */ public boolean check(List<IFileSpec> fileSpecs, String... ignore) throws Exception { return check(fileSpecs, true, ignore); } /** * Only return boolean; false is returned for an exception. * * @param fileSpecs List of Perforce file specs * @param ignore Parameter list of messages to ignore * @return true if no errors or exceptions */ public boolean checkCatch(List<IFileSpec> fileSpecs, String... ignore) { try { return check(fileSpecs, true, ignore); } catch (Exception e) { return false; } } public boolean check(List<IFileSpec> fileSpecs, boolean quiet, String... ignore) throws Exception { boolean success = true; boolean abort = false; StringBuffer errorLog = new StringBuffer(); ArrayList<String> ignoreList = new ArrayList<String>(); ignoreList.addAll(Arrays.asList(ignore)); for (IFileSpec fileSpec : fileSpecs) { FileSpecOpStatus status = fileSpec.getOpStatus(); if (status != FileSpecOpStatus.VALID) { String msg = fileSpec.getStatusMessage(); // superfluous p4java message boolean unknownMsg = true; for (String istring : ignoreList) { if (!istring.isEmpty() && msg.contains(istring)) { // its a known message unknownMsg = false; break; } } // check and report unknown message if (unknownMsg) { if (!quiet) { msg = "P4JAVA: " + msg; log(msg); logger.warning(msg); } if (status == FileSpecOpStatus.ERROR || status == FileSpecOpStatus.CLIENT_ERROR) { errorLog.append(msg); errorLog.append("\n"); abort = true; } success = false; } } } if (abort) { String msg = "P4JAVA: Error(s):\n" + errorLog.toString(); throw new AbortException(msg); } return success; } public void log(String msg) { if (listener == null) { return; } listener.getLogger().println(msg); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 23685 | Paul Allen | Copy main -> dev | ||
#1 | 20641 | Paul Allen | Copy main -> dev (jenkinsci/p4-plugin) | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/client/Validate.java | |||||
#3 | 20179 | Paul Allen | Javadoc fixes for java 8 builds. | ||
#2 | 19593 | Paul Allen | More minor fixes to satisfy FindBugs Analysis. | ||
#1 | 18889 | Paul Allen |
Asynchronous sync operation. To avoid memory issues with very large sync operations. #review-18773 |