File tree 6 files changed +64
-8
lines changed 6 files changed +64
-8
lines changed Original file line number Diff line number Diff line change 32
32
import cc .arduino .contributions .packages .ContributionsIndexer ;
33
33
import cc .arduino .contributions .DownloadableContributionVersionComparator ;
34
34
import cc .arduino .contributions .packages .ui .ContributionManagerUI ;
35
+ import cc .arduino .files .DeleteFilesOnShutdown ;
35
36
import cc .arduino .packages .DiscoveryManager ;
36
37
import cc .arduino .utils .Progress ;
37
38
import cc .arduino .view .SplashScreenHelper ;
@@ -127,6 +128,8 @@ static public void main(String args[]) throws Exception {
127
128
}
128
129
129
130
static public void guardedMain (String args []) throws Exception {
131
+ Runtime .getRuntime ().addShutdownHook (new Thread (DeleteFilesOnShutdown .INSTANCE ));
132
+
130
133
BaseNoGui .initLogger ();
131
134
132
135
BaseNoGui .notifier = new GUIUserNotifier ();
@@ -202,7 +205,7 @@ static public void guardedMain(String args[]) throws Exception {
202
205
203
206
// Create a location for untitled sketches
204
207
untitledFolder = createTempFolder ("untitled" );
205
- untitledFolder . deleteOnExit ( );
208
+ DeleteFilesOnShutdown . add ( untitledFolder );
206
209
207
210
new Base (args );
208
211
}
Original file line number Diff line number Diff line change 1
1
package processing .app ;
2
2
3
+ import cc .arduino .files .DeleteFilesOnShutdown ;
4
+
3
5
import static processing .app .I18n ._ ;
4
6
5
7
import java .io .File ;
@@ -33,19 +35,19 @@ public static void init() {
33
35
// The files and folders are not deleted on exit because they may be
34
36
// needed for debugging or bug reporting.
35
37
tempFolder = Base .createTempFolder ("console" );
36
- tempFolder . deleteOnExit ( );
38
+ DeleteFilesOnShutdown . add ( tempFolder );
37
39
try {
38
40
String outFileName = Preferences .get ("console.output.file" );
39
41
if (outFileName != null ) {
40
42
outFile = new File (tempFolder , outFileName );
41
- outFile . deleteOnExit ( );
43
+ DeleteFilesOnShutdown . add ( outFile );
42
44
stdoutFile = new FileOutputStream (outFile );
43
45
}
44
46
45
47
String errFileName = Preferences .get ("console.error.file" );
46
48
if (errFileName != null ) {
47
49
errFile = new File (tempFolder , errFileName );
48
- errFile . deleteOnExit ( );
50
+ DeleteFilesOnShutdown . add ( errFile );
49
51
stderrFile = new FileOutputStream (errFile );
50
52
}
51
53
} catch (IOException e ) {
Original file line number Diff line number Diff line change 6
6
import org .junit .After ;
7
7
import org .junit .Before ;
8
8
import processing .app .helpers .ArduinoFrameFixture ;
9
+ import processing .app .helpers .FileUtils ;
9
10
10
11
import javax .swing .*;
11
12
@@ -25,7 +26,6 @@ public void startUpTheIDE() throws Exception {
25
26
Theme .init ();
26
27
Base .getPlatform ().setLookAndFeel ();
27
28
Base .untitledFolder = Base .createTempFolder ("untitled" );
28
- Base .untitledFolder .deleteOnExit ();
29
29
30
30
window = GuiActionRunner .execute (new GuiQuery <ArduinoFrameFixture >() {
31
31
@ Override
@@ -38,6 +38,7 @@ protected ArduinoFrameFixture executeInEDT() throws Throwable {
38
38
@ After
39
39
public void stopTheIDE () {
40
40
window .cleanUp ();
41
+ FileUtils .recursiveDelete (Base .untitledFolder );
41
42
}
42
43
43
44
}
Original file line number Diff line number Diff line change 1
1
package processing .app ;
2
2
3
+ import org .junit .After ;
3
4
import org .junit .Before ;
5
+ import processing .app .helpers .FileUtils ;
4
6
5
7
public abstract class AbstractWithPreferencesTest {
6
8
@@ -11,7 +13,11 @@ public void init() throws Exception {
11
13
Theme .init ();
12
14
13
15
Base .untitledFolder = Base .createTempFolder ("untitled" );
14
- Base .untitledFolder .deleteOnExit ();
15
16
16
17
}
18
+
19
+ @ After
20
+ public void cleanup () {
21
+ FileUtils .recursiveDelete (Base .untitledFolder );
22
+ }
17
23
}
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 1
1
package processing .app ;
2
2
3
3
import cc .arduino .contributions .libraries .LibrariesIndexer ;
4
+ import cc .arduino .files .DeleteFilesOnShutdown ;
4
5
import cc .arduino .packages .DiscoveryManager ;
5
6
import cc .arduino .packages .Uploader ;
6
7
import cc .arduino .contributions .packages .ContributedTool ;
7
8
import cc .arduino .contributions .packages .ContributionsIndexer ;
8
- import cc .arduino .utils .ArchiveExtractor ;
9
9
import org .apache .commons .logging .impl .LogFactoryImpl ;
10
10
import org .apache .commons .logging .impl .NoOpLog ;
11
11
import processing .app .debug .Compiler ;
@@ -133,7 +133,7 @@ static public File getBuildFolder() {
133
133
//File folder = new File(getTempFolder(), "build");
134
134
//if (!folder.exists()) folder.mkdirs();
135
135
buildFolder = createTempFolder ("build" );
136
- buildFolder . deleteOnExit ( );
136
+ DeleteFilesOnShutdown . add ( buildFolder );
137
137
}
138
138
}
139
139
return buildFolder ;
@@ -703,6 +703,8 @@ static public void main(String args[]) throws Exception {
703
703
if (args .length == 0 )
704
704
showError (_ ("No parameters" ), _ ("No command line parameters found" ), null );
705
705
706
+ Runtime .getRuntime ().addShutdownHook (new Thread (DeleteFilesOnShutdown .INSTANCE ));
707
+
706
708
initPlatform ();
707
709
708
710
initPortableFolder ();
You can’t perform that action at this time.
0 commit comments