File tree Expand file tree Collapse file tree 6 files changed +64
-8
lines changed Expand file tree Collapse file tree 6 files changed +64
-8
lines changed Original file line number Diff line number Diff line change 3232import cc .arduino .contributions .packages .ContributionsIndexer ;
3333import cc .arduino .contributions .DownloadableContributionVersionComparator ;
3434import cc .arduino .contributions .packages .ui .ContributionManagerUI ;
35+ import cc .arduino .files .DeleteFilesOnShutdown ;
3536import cc .arduino .packages .DiscoveryManager ;
3637import cc .arduino .utils .Progress ;
3738import cc .arduino .view .SplashScreenHelper ;
@@ -127,6 +128,8 @@ static public void main(String args[]) throws Exception {
127128 }
128129
129130 static public void guardedMain (String args []) throws Exception {
131+ Runtime .getRuntime ().addShutdownHook (new Thread (DeleteFilesOnShutdown .INSTANCE ));
132+
130133 BaseNoGui .initLogger ();
131134
132135 BaseNoGui .notifier = new GUIUserNotifier ();
@@ -202,7 +205,7 @@ static public void guardedMain(String args[]) throws Exception {
202205
203206 // Create a location for untitled sketches
204207 untitledFolder = createTempFolder ("untitled" );
205- untitledFolder . deleteOnExit ( );
208+ DeleteFilesOnShutdown . add ( untitledFolder );
206209
207210 new Base (args );
208211 }
Original file line number Diff line number Diff line change 11package processing .app ;
22
3+ import cc .arduino .files .DeleteFilesOnShutdown ;
4+
35import static processing .app .I18n ._ ;
46
57import java .io .File ;
@@ -33,19 +35,19 @@ public static void init() {
3335 // The files and folders are not deleted on exit because they may be
3436 // needed for debugging or bug reporting.
3537 tempFolder = Base .createTempFolder ("console" );
36- tempFolder . deleteOnExit ( );
38+ DeleteFilesOnShutdown . add ( tempFolder );
3739 try {
3840 String outFileName = Preferences .get ("console.output.file" );
3941 if (outFileName != null ) {
4042 outFile = new File (tempFolder , outFileName );
41- outFile . deleteOnExit ( );
43+ DeleteFilesOnShutdown . add ( outFile );
4244 stdoutFile = new FileOutputStream (outFile );
4345 }
4446
4547 String errFileName = Preferences .get ("console.error.file" );
4648 if (errFileName != null ) {
4749 errFile = new File (tempFolder , errFileName );
48- errFile . deleteOnExit ( );
50+ DeleteFilesOnShutdown . add ( errFile );
4951 stderrFile = new FileOutputStream (errFile );
5052 }
5153 } catch (IOException e ) {
Original file line number Diff line number Diff line change 66import org .junit .After ;
77import org .junit .Before ;
88import processing .app .helpers .ArduinoFrameFixture ;
9+ import processing .app .helpers .FileUtils ;
910
1011import javax .swing .*;
1112
@@ -25,7 +26,6 @@ public void startUpTheIDE() throws Exception {
2526 Theme .init ();
2627 Base .getPlatform ().setLookAndFeel ();
2728 Base .untitledFolder = Base .createTempFolder ("untitled" );
28- Base .untitledFolder .deleteOnExit ();
2929
3030 window = GuiActionRunner .execute (new GuiQuery <ArduinoFrameFixture >() {
3131 @ Override
@@ -38,6 +38,7 @@ protected ArduinoFrameFixture executeInEDT() throws Throwable {
3838 @ After
3939 public void stopTheIDE () {
4040 window .cleanUp ();
41+ FileUtils .recursiveDelete (Base .untitledFolder );
4142 }
4243
4344}
Original file line number Diff line number Diff line change 11package processing .app ;
22
3+ import org .junit .After ;
34import org .junit .Before ;
5+ import processing .app .helpers .FileUtils ;
46
57public abstract class AbstractWithPreferencesTest {
68
@@ -11,7 +13,11 @@ public void init() throws Exception {
1113 Theme .init ();
1214
1315 Base .untitledFolder = Base .createTempFolder ("untitled" );
14- Base .untitledFolder .deleteOnExit ();
1516
1617 }
18+
19+ @ After
20+ public void cleanup () {
21+ FileUtils .recursiveDelete (Base .untitledFolder );
22+ }
1723}
Original file line number Diff line number Diff line change 1+ package cc .arduino .files ;
2+
3+ import processing .app .helpers .FileUtils ;
4+
5+ import java .io .File ;
6+ import java .util .Collections ;
7+ import java .util .LinkedList ;
8+ import java .util .List ;
9+
10+ public class DeleteFilesOnShutdown implements Runnable {
11+
12+ public static final DeleteFilesOnShutdown INSTANCE = new DeleteFilesOnShutdown ();
13+
14+ public static void add (File file ) {
15+ INSTANCE .addFile (file );
16+ }
17+
18+ private final List <File > files ;
19+
20+ public DeleteFilesOnShutdown () {
21+ this .files = new LinkedList <File >();
22+ }
23+
24+ public synchronized void addFile (File file ) {
25+ this .files .add (file );
26+ }
27+
28+ @ Override
29+ public void run () {
30+ List <File > copyOfFiles ;
31+ synchronized (this ) {
32+ copyOfFiles = new LinkedList <File >(files );
33+ }
34+ Collections .reverse (copyOfFiles );
35+ for (File file : copyOfFiles ) {
36+ if (file .exists () && file .canWrite ()) {
37+ FileUtils .recursiveDelete (file );
38+ }
39+ }
40+ }
41+
42+ }
Original file line number Diff line number Diff line change 11package processing .app ;
22
33import cc .arduino .contributions .libraries .LibrariesIndexer ;
4+ import cc .arduino .files .DeleteFilesOnShutdown ;
45import cc .arduino .packages .DiscoveryManager ;
56import cc .arduino .packages .Uploader ;
67import cc .arduino .contributions .packages .ContributedTool ;
78import cc .arduino .contributions .packages .ContributionsIndexer ;
8- import cc .arduino .utils .ArchiveExtractor ;
99import org .apache .commons .logging .impl .LogFactoryImpl ;
1010import org .apache .commons .logging .impl .NoOpLog ;
1111import processing .app .debug .Compiler ;
@@ -133,7 +133,7 @@ static public File getBuildFolder() {
133133 //File folder = new File(getTempFolder(), "build");
134134 //if (!folder.exists()) folder.mkdirs();
135135 buildFolder = createTempFolder ("build" );
136- buildFolder . deleteOnExit ( );
136+ DeleteFilesOnShutdown . add ( buildFolder );
137137 }
138138 }
139139 return buildFolder ;
@@ -703,6 +703,8 @@ static public void main(String args[]) throws Exception {
703703 if (args .length == 0 )
704704 showError (_ ("No parameters" ), _ ("No command line parameters found" ), null );
705705
706+ Runtime .getRuntime ().addShutdownHook (new Thread (DeleteFilesOnShutdown .INSTANCE ));
707+
706708 initPlatform ();
707709
708710 initPortableFolder ();
You can’t perform that action at this time.
0 commit comments