Skip to content

Commit

Permalink
Removes usage of deprecated ANTLRException
Browse files Browse the repository at this point in the history
This is no longer being thrown by Crontab constructor
jenkinsci/jenkins#7293
  • Loading branch information
froque committed Sep 6, 2023
1 parent 89687d9 commit 75d67ed
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package hudson.plugins.disk_usage;

import antlr.ANTLRException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.model.AbstractBuild;
Expand Down Expand Up @@ -86,7 +85,7 @@ public void execute(TaskListener listener) throws IOException, InterruptedExcept
}

@Override
public CronTab getCronTab() throws ANTLRException {
public CronTab getCronTab() {
DiskUsagePlugin plugin = Jenkins.get().getPlugin(DiskUsagePlugin.class);
if (plugin == null) {
return null;
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/hudson/plugins/disk_usage/DiskUsageCalculation.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package hudson.plugins.disk_usage;

import antlr.ANTLRException;
import hudson.model.AsyncAperiodicWork;
import hudson.scheduler.CronTab;
import java.util.Calendar;
Expand All @@ -13,7 +12,6 @@
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.util.Timer;

/**
Expand Down Expand Up @@ -56,20 +54,14 @@ public String getThreadName() {
public abstract DiskUsageCalculation getLastTask();

public long scheduledLastInstanceExecutionTime() {
try {
if(getLastTask() == null || getLastTask().isCancelled()) { // not scheduled
return 0L;
}
long time = getCronTab().ceil(new GregorianCalendar().getTimeInMillis()).getTimeInMillis();
if(time < new GregorianCalendar().getTimeInMillis()) {
return 0;
}
return time;

} catch (ANTLRException ex) {
Logger.getLogger(DiskUsageCalculation.class.getName()).log(Level.SEVERE, null, ex);
return -1;
if(getLastTask() == null || getLastTask().isCancelled()) { // not scheduled
return 0L;
}
long time = getCronTab().ceil(new GregorianCalendar().getTimeInMillis()).getTimeInMillis();
if(time < new GregorianCalendar().getTimeInMillis()) {
return 0;
}
return time;
}

@Override
Expand Down Expand Up @@ -102,7 +94,7 @@ public void reschedule() {
Timer.get().schedule(getNewInstance(), getRecurrencePeriod(), TimeUnit.MILLISECONDS);
}

public abstract CronTab getCronTab() throws ANTLRException;
public abstract CronTab getCronTab();

@Override
public long getRecurrencePeriod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package hudson.plugins.disk_usage;

import antlr.ANTLRException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.model.AbstractProject;
Expand Down Expand Up @@ -91,7 +90,7 @@ public AperiodicWork getNewInstance() {
}

@Override
public CronTab getCronTab() throws ANTLRException {
public CronTab getCronTab() {
DiskUsagePlugin plugin = Jenkins.get().getPlugin(DiskUsagePlugin.class);
if (plugin == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package hudson.plugins.disk_usage;

import antlr.ANTLRException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.model.AbstractProject;
Expand Down Expand Up @@ -84,7 +83,7 @@ public AperiodicWork getNewInstance() {
}

@Override
public CronTab getCronTab() throws ANTLRException {
public CronTab getCronTab() {
DiskUsagePlugin plugin = Jenkins.get().getPlugin(DiskUsagePlugin.class);
if (plugin == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package hudson.plugins.disk_usage;

import antlr.ANTLRException;
import hudson.model.AperiodicWork;
import hudson.model.TaskListener;
import hudson.scheduler.CronTab;
Expand Down Expand Up @@ -36,7 +35,7 @@ public void setCron(String cron) {
}

@Override
public CronTab getCronTab() throws ANTLRException {
public CronTab getCronTab() {
return new CronTab(cron);
}

Expand Down

0 comments on commit 75d67ed

Please sign in to comment.