use of hudson.AbortException in project hudson-2.x by hudson.
the class TestResult method parse.
/**
* Collect reports from the given {@link DirectoryScanner}, while
* filtering out all files that were created before the given time.
*/
public void parse(long buildTime, DirectoryScanner results) throws IOException {
String[] includedFiles = results.getIncludedFiles();
File baseDir = results.getBasedir();
boolean parsed = false;
for (String value : includedFiles) {
File reportFile = new File(baseDir, value);
// only count files that were actually updated during this build
if ((buildTime - 3000 <= /*error margin*/
reportFile.lastModified()) || !checkTimestamps) {
if (reportFile.length() == 0) {
// this is a typical problem when JVM quits abnormally, like OutOfMemoryError during a test.
SuiteResult sr = new SuiteResult(reportFile.getName(), "", "");
sr.addCase(new CaseResult(sr, "<init>", "Test report file " + reportFile.getAbsolutePath() + " was length 0"));
add(sr);
} else {
parse(reportFile);
}
parsed = true;
}
}
if (!parsed) {
long localTime = System.currentTimeMillis();
if (localTime < buildTime - 1000)
// build time is in the the future. clock on this slave must be running behind
throw new AbortException("Clock on this slave is out of sync with the master, and therefore \n" + "I can't figure out what test results are new and what are old.\n" + "Please keep the slave clock in sync with the master.");
File f = new File(baseDir, includedFiles[0]);
throw new AbortException(String.format("Test reports were found but none of them are new. Did tests run? \n" + "For example, %s is %s old\n", f, Util.getTimeSpanString(buildTime - f.lastModified())));
}
}
use of hudson.AbortException in project hudson-2.x by hudson.
the class JDKInstaller method install.
/**
* Performs the JDK installation to a system, provided that the bundle was already downloaded.
*
* @param launcher
* Used to launch processes on the system.
* @param p
* Platform of the system. This determines how the bundle is installed.
* @param fs
* Abstraction of the file system manipulation on this system.
* @param log
* Where the output from the installation will be written.
* @param expectedLocation
* Path to install JDK to. Must be absolute and in the native file system notation.
* @param jdkBundle
* Path to the installed JDK bundle. (The bundle to download can be determined by {@link #locate(TaskListener, Platform, CPU)} call.)
*/
public void install(Launcher launcher, Platform p, FileSystem fs, TaskListener log, String expectedLocation, String jdkBundle) throws IOException, InterruptedException {
PrintStream out = log.getLogger();
out.println("Installing " + jdkBundle);
switch(p) {
case LINUX:
case SOLARIS:
fs.chmod(jdkBundle, 0755);
int exit = launcher.launch().cmds(jdkBundle, "-noregister").stdin(new ByteArrayInputStream("yes".getBytes())).stdout(out).pwd(new FilePath(launcher.getChannel(), expectedLocation)).join();
if (exit != 0)
throw new AbortException(Messages.JDKInstaller_FailedToInstallJDK(exit));
// JDK creates its own sub-directory, so pull them up
List<String> paths = fs.listSubDirectories(expectedLocation);
for (Iterator<String> itr = paths.iterator(); itr.hasNext(); ) {
String s = itr.next();
if (!s.matches("j(2s)?dk.*"))
itr.remove();
}
if (paths.size() != 1)
throw new AbortException("Failed to find the extracted JDKs: " + paths);
// remove the intermediate directory
fs.pullUp(expectedLocation + '/' + paths.get(0), expectedLocation);
break;
case WINDOWS:
/*
Windows silent installation is full of bad know-how.
On Windows, command line argument to a process at the OS level is a single string,
not a string array like POSIX. When we pass arguments as string array, JRE eventually
turn it into a single string with adding quotes to "the right place". Unfortunately,
with the strange argument layout of InstallShield (like /v/qn" INSTALLDIR=foobar"),
it appears that the escaping done by JRE gets in the way, and prevents the installation.
Presumably because of this, my attempt to use /q/vn" INSTALLDIR=foo" didn't work with JDK5.
I tried to locate exactly how InstallShield parses the arguments (and why it uses
awkward option like /qn, but couldn't find any. Instead, experiments revealed that
"/q/vn ARG ARG ARG" works just as well. This is presumably due to the Visual C++ runtime library
(which does single string -> string array conversion to invoke the main method in most Win32 process),
and this consistently worked on JDK5 and JDK4.
Some of the official documentations are available at
- http://java.sun.com/j2se/1.5.0/sdksilent.html
- http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/silent.html
*/
String logFile = jdkBundle + ".install.log";
ArgumentListBuilder args = new ArgumentListBuilder();
args.add(jdkBundle);
args.add("/s");
// according to http://community.acresso.com/showthread.php?t=83301, \" is the trick to quote values with whitespaces.
// Oh Windows, oh windows, why do you have to be so difficult?
args.add("/v/qn REBOOT=Suppress INSTALLDIR=\\\"" + expectedLocation + "\\\" /L \\\"" + logFile + "\\\"");
int r = launcher.launch().cmds(args).stdout(out).pwd(new FilePath(launcher.getChannel(), expectedLocation)).join();
if (r != 0) {
out.println(Messages.JDKInstaller_FailedToInstallJDK(r));
// log file is in UTF-16
InputStreamReader in = new InputStreamReader(fs.read(logFile), "UTF-16");
try {
IOUtils.copy(in, new OutputStreamWriter(out));
} finally {
in.close();
}
throw new AbortException();
}
fs.delete(logFile);
break;
}
}
use of hudson.AbortException in project hudson-2.x by hudson.
the class AbstractProject method poll.
/**
* Checks if there's any update in SCM, and returns true if any is found.
*
* <p>
* The implementation is responsible for ensuring mutual exclusion between polling and builds
* if necessary.
*
* @since 1.345
*/
public PollingResult poll(TaskListener listener) {
SCM scm = getScm();
if (scm == null) {
listener.getLogger().println(Messages.AbstractProject_NoSCM());
return NO_CHANGES;
}
if (isDisabled()) {
listener.getLogger().println(Messages.AbstractProject_Disabled());
return NO_CHANGES;
}
R lb = getLastBuild();
if (lb == null) {
listener.getLogger().println(Messages.AbstractProject_NoBuilds());
return isInQueue() ? NO_CHANGES : BUILD_NOW;
}
if (pollingBaseline == null) {
// if we have a persisted baseline, we'll find it by this
R success = getLastSuccessfulBuild();
for (R r = lb; r != null; r = r.getPreviousBuild()) {
SCMRevisionState s = r.getAction(SCMRevisionState.class);
if (s != null) {
pollingBaseline = s;
break;
}
// searched far enough
if (r == success)
break;
}
// NOTE-NO-BASELINE:
// if we don't have baseline yet, it means the data is built by old Hudson that doesn't set the baseline
// as action, so we need to compute it. This happens later.
}
try {
if (scm.requiresWorkspaceForPolling()) {
// lock the workspace of the last build
FilePath ws = lb.getWorkspace();
if (ws == null || !ws.exists()) {
// workspace offline. build now, or nothing will ever be built
Label label = getAssignedLabel();
if (label != null && label.isSelfLabel()) {
// if the build is fixed on a node, then attempting a build will do us
// no good. We should just wait for the slave to come back.
listener.getLogger().println(Messages.AbstractProject_NoWorkspace());
return NO_CHANGES;
}
listener.getLogger().println(ws == null ? Messages.AbstractProject_WorkspaceOffline() : Messages.AbstractProject_NoWorkspace());
if (isInQueue()) {
listener.getLogger().println(Messages.AbstractProject_AwaitingBuildForWorkspace());
return NO_CHANGES;
} else {
listener.getLogger().println(Messages.AbstractProject_NewBuildForWorkspace());
return BUILD_NOW;
}
} else {
Node node = lb.getBuiltOn();
if (node == null || node.toComputer() == null) {
LOGGER.log(Level.FINE, "Node on which this job previously was built is not available now, build is started on an available node");
return isInQueue() ? NO_CHANGES : BUILD_NOW;
}
WorkspaceList l = node.toComputer().getWorkspaceList();
// if doing non-concurrent build, acquire a workspace in a way that causes builds to block for this workspace.
// this prevents multiple workspaces of the same job --- the behavior of Hudson < 1.319.
//
// OTOH, if a concurrent build is chosen, the user is willing to create a multiple workspace,
// so better throughput is achieved over time (modulo the initial cost of creating that many workspaces)
// by having multiple workspaces
WorkspaceList.Lease lease = l.acquire(ws, !concurrentBuild);
Launcher launcher = ws.createLauncher(listener);
try {
LOGGER.fine("Polling SCM changes of " + getName());
if (// see NOTE-NO-BASELINE above
pollingBaseline == null)
calcPollingBaseline(lb, launcher, listener);
PollingResult r = scm.poll(this, launcher, ws, listener, pollingBaseline);
pollingBaseline = r.remote;
return r;
} finally {
lease.release();
}
}
} else {
// polling without workspace
LOGGER.fine("Polling SCM changes of " + getName());
if (// see NOTE-NO-BASELINE above
pollingBaseline == null)
calcPollingBaseline(lb, null, listener);
PollingResult r = scm.poll(this, null, null, listener, pollingBaseline);
pollingBaseline = r.remote;
return r;
}
} catch (AbortException e) {
listener.getLogger().println(e.getMessage());
listener.fatalError(Messages.AbstractProject_Aborted());
LOGGER.log(Level.FINE, "Polling " + this + " aborted", e);
return NO_CHANGES;
} catch (IOException e) {
e.printStackTrace(listener.fatalError(e.getMessage()));
return NO_CHANGES;
} catch (InterruptedException e) {
e.printStackTrace(listener.fatalError(Messages.AbstractProject_PollingABorted()));
return NO_CHANGES;
}
}
use of hudson.AbortException in project memory-map-plugin by Praqma.
the class GccMemoryMapParser method getMemory.
/**
* Parses the MEMORY section of the GCC file. Throws an abort exception
* which will be shown in the Jenkins console log.
*
* @param seq The content of the map file
* @return a list of the defined MEMORY in the map file
* @throws hudson.AbortException when a illegal value of memory found
*/
public MemoryMapConfigMemory getMemory(CharSequence seq) throws AbortException {
Pattern allMemory = Pattern.compile("^\\s*(\\S+).*?(?:ORIGIN|org|o)\\s*=\\s*([^,]*).*?(?:LENGTH|len|l)\\s*\\=\\s*([^\\s]*)", Pattern.MULTILINE);
Matcher match = allMemory.matcher(seq);
MemoryMapConfigMemory memory = new MemoryMapConfigMemory();
while (match.find()) {
try {
String hexLength = new HexUtils.HexifiableString(match.group(3)).toValidHexString().rawString;
MemoryMapConfigMemoryItem item = new MemoryMapConfigMemoryItem(match.group(1), match.group(2), hexLength);
memory.add(item);
} catch (Throwable ex) {
logger.log(Level.SEVERE, "Unable to convert %s to a valid hex string.", ex);
throw new AbortException(String.format("Unable to convert %s to a valid hex string.", match.group(3)));
}
}
return memory;
}
use of hudson.AbortException in project sonar-scanner-jenkins by SonarSource.
the class AbstractMsBuildSQRunner method perform.
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
FilePath workspace = build.getWorkspace();
if (workspace == null) {
throw new AbortException("no workspace for " + build);
}
perform(build, workspace, launcher, listener);
return true;
}
Aggregations