public static CronTabList create(@Nonnull String format, Hash hash) throws ANTLRException { Vector<CronTab> r = new Vector<>(); int lineNumber = 0; String timezone = null; for (String line : format.split("\\r?\\n")) { lineNumber++; line = line.trim(); if(lineNumber == 1 && line.startsWith("TZ=")) { timezone = getValidTimezone(line.replace("TZ=","")); if(timezone != null) { LOGGER.log(Level.CONFIG, "CRON with timezone {0}", timezone); } else { throw new ANTLRException("Invalid or unsupported timezone '" + timezone + "'"); } continue; } if(line.length()==0 || line.startsWith("#")) continue; // ignorable line try { r.add(new CronTab(line,lineNumber,hash,timezone)); } catch (ANTLRException e) { throw new ANTLRException(Messages.CronTabList_InvalidInput(line,e.toString()),e); } } return new CronTabList(r); }
long calculateDelay(final long currentTime, final BackupType backupType, final String cron) { CronTab cronTab; try { if (StringUtils.isEmpty(cron)) { return -1; } cronTab = new CronTab(cron); final Calendar nextExecution = cronTab.ceil(currentTime); final long delay = nextExecution.getTimeInMillis() - currentTime; LOGGER.fine(MessageFormat.format("Current time: {0,date,medium} {0,time,long}. Next execution ({3}) in {2} seconds which is {1,date,medium} {1,time,long}", new Date(currentTime), nextExecution.getTime(), TimeUnit.MILLISECONDS.toSeconds(delay), backupType)); if (delay < 0) { final String msg = "Delay is a negative number, which means the next execution is in the past! This happens for Hudson/Jenkins installations with version 1.395 or below. Please upgrade to fix this."; LOGGER.severe(msg); throw new IllegalStateException(msg); } return delay; } catch (final ANTLRException e) { LOGGER.warning(MessageFormat.format( "Cannot parse the specified ''Backup schedule for {0} backups''. Check cron notation.", backupType.toString())); return -1; } }
public FormValidation doCheckBackupSchedule(final StaplerRequest res, final StaplerResponse rsp, @QueryParameter("value") final String schedule) { if ((schedule != null) && !schedule.isEmpty()) { String message; try { message = new CronTab(schedule).checkSanity(); } catch (final ANTLRException e) { return FormValidation.error("Invalid cron schedule. " + e.getMessage()); } if (message != null) { return FormValidation.warning("Cron schedule warning: " + message); } else { return FormValidation.ok(); } } else { return FormValidation.ok(); } }
public static CronTabList create(String format) throws ANTLRException { Vector<CronTab> r = new Vector<CronTab>(); int lineNumber = 0; for (String line : format.split("\\r?\\n")) { lineNumber++; line = line.trim(); if(line.length()==0 || line.startsWith("#")) continue; // ignorable line try { r.add(new CronTab(line,lineNumber)); } catch (ANTLRException e) { throw new ANTLRException(Messages.CronTabList_InvalidInput(line,e.toString()),e); } } return new CronTabList(r); } }
public static CronTabList create(String format) throws ANTLRException { Vector<CronTab> r = new Vector<CronTab>(); int lineNumber = 0; for (String line : format.split("\\r?\\n")) { lineNumber++; line = line.trim(); if(line.length()==0 || line.startsWith("#")) continue; // ignorable line try { r.add(new CronTab(line,lineNumber)); } catch (ANTLRException e) { throw new ANTLRException(Messages.CronTabList_InvalidInput(line,e.toString()),e); } } return new CronTabList(r); } }
public static CronTabList create(String format) throws ANTLRException { Vector<CronTab> r = new Vector<CronTab>(); int lineNumber = 0; for (String line : format.split("\\r?\\n")) { lineNumber++; line = line.trim(); if(line.length()==0 || line.startsWith("#")) continue; // ignorable line try { r.add(new CronTab(line,lineNumber)); } catch (ANTLRException e) { throw new ANTLRException(Messages.CronTabList_InvalidInput(line,e.toString()),e); } } return new CronTabList(r); } }
public static CronTabList create(String format) throws RecognitionException { List<CronTab> r = new ArrayList<CronTab>(); int lineNumber = 0; for (String line : format.split("\\r?\\n")) { lineNumber++; line = line.trim(); if (line.length() == 0 || line.startsWith("#")) { continue; // ignorable line } try { r.add(new CronTab(line, lineNumber)); } catch (RecognitionException e) { throw new BaseParser.SemanticException(Messages.CronTabList_InvalidInput(line, e.toString()), e); } } return new CronTabList(r); } }
public static CronTabList create(@Nonnull String format, Hash hash) throws ANTLRException { Vector<CronTab> r = new Vector<>(); int lineNumber = 0; String timezone = null; for (String line : format.split("\\r?\\n")) { lineNumber++; line = line.trim(); if(lineNumber == 1 && line.startsWith("TZ=")) { timezone = getValidTimezone(line.replace("TZ=","")); if(timezone != null) { LOGGER.log(Level.CONFIG, "CRON with timezone {0}", timezone); } else { throw new ANTLRException("Invalid or unsupported timezone '" + timezone + "'"); } continue; } if(line.length()==0 || line.startsWith("#")) continue; // ignorable line try { r.add(new CronTab(line,lineNumber,hash,timezone)); } catch (ANTLRException e) { throw new ANTLRException(Messages.CronTabList_InvalidInput(line,e.toString()),e); } } return new CronTabList(r); }
public CronTab getCronTab() throws ANTLRException{ String cron = Jenkins.getInstance().getPlugin(DiskUsagePlugin.class).getConfiguration().getCountIntervalForBuilds(); CronTab tab = new CronTab(cron); return tab; }
@Override public CronTab getCronTab() throws ANTLRException { String cron = Jenkins.getInstance().getPlugin(DiskUsagePlugin.class).getConfiguration().getCountIntervalForJobs(); CronTab tab = new CronTab(cron); return tab; }
@Override public CronTab getCronTab() throws ANTLRException { String cron = Jenkins.getInstance().getPlugin(DiskUsagePlugin.class).getConfiguration().getCountIntervalForWorkspaces(); CronTab tab = new CronTab(cron); return tab; }