Skip to content

Commit f8299fa

Browse files
authored
Merge pull request #13 from moacirrf/ft-clear-files-when-close-nb
Remove the decompiled directory when netbeans is about to be closed.
2 parents 8b02b20 + 8bd6b12 commit f8299fa

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
<artifactId>org-netbeans-modules-java-source</artifactId>
106106
<version>RELEASE130</version>
107107
</dependency>
108+
109+
<dependency>
110+
<groupId>org.netbeans.api</groupId>
111+
<artifactId>org-openide-modules</artifactId>
112+
<version>RELEASE130</version>
113+
</dependency>
108114
</dependencies>
109115

110116
<repositories>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (C) 2022 moacirrf
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
package com.mrf.javadecompiler.openapi;
18+
19+
import com.machinezoo.noexception.Exceptions;
20+
import com.mrf.javadecompiler.constants.Constants;
21+
import com.mrf.javadecompiler.exception.ExceptionHandler;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
24+
import org.openide.modules.ModuleInstall;
25+
26+
public class Installer extends ModuleInstall {
27+
28+
@Override
29+
public boolean closing() {
30+
this.clearTempFolder(Path.of(Constants.TEMP_DIR_PLUGIN));
31+
return super.closing();
32+
}
33+
/**
34+
* Will remove recursivelly all decompiled classes, when close Netbeans.
35+
*
36+
* @param path
37+
*/
38+
private void clearTempFolder(Path path) {
39+
Exceptions.wrap(ex -> ExceptionHandler.handleException(ex)).run(() -> {
40+
if (Files.isDirectory(path) && Files.list(path).count() > 0) {
41+
Files.list(path).forEach(it -> this.clearTempFolder(it));
42+
}
43+
Files.deleteIfExists(path);
44+
});
45+
}
46+
47+
}

src/main/nbm/manifest.mf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Manifest-Version: 1.0
22
OpenIDE-Module-Localizing-Bundle: com/mrf/javadecompiler/Bundle.properties
33
OpenIDE-Module-Requires: org.openide.windows.WindowManager
4+
OpenIDE-Module-Install: com/mrf/javadecompiler/openapi/Installer.class
45

0 commit comments

Comments
 (0)