001package apps.util.issuereporter; 002 003import java.io.File; 004import java.io.IOException; 005import java.nio.file.*; 006 007import jmri.util.FileUtil; 008import jmri.util.startup.StartupRunnable; 009 010import org.apiguardian.api.API; 011import org.openide.util.lookup.ServiceProvider; 012 013/** 014 * Remove remnants of prior issue reports. 015 * 016 * @author Randall Wood Copyright 2020 017 */ 018@API(status = API.Status.INTERNAL) 019@ServiceProvider(service = StartupRunnable.class) 020public final class IssueReporterStartupRunnable implements StartupRunnable { 021 022 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(IssueReporterStartupRunnable.class); 023 024 @Override 025 public void run() { 026 Path tempDir = new File(System.getProperty("java.io.tmpdir")).toPath(); 027 try (DirectoryStream<Path> stream = Files.newDirectoryStream(tempDir, entry -> entry.toFile().getName().startsWith("jmri-issue-report-"))) { 028 stream.forEach(entry -> FileUtil.delete(entry.toFile())); 029 } catch (IOException ex) { 030 log.error("Exception cleaning up from issue reporter", ex); 031 } 032 } 033}