Skip to content

Commit 5d4c9c3

Browse files
moacirrfmoacirrf
authored andcommitted
Remove the decompiled directory when netbeans is about to be closed.
1 parent 8b02b20 commit 5d4c9c3

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
25+
public class Installer extends org.openide.modules.ModuleInstall {
26+
27+
@Override
28+
public boolean closing() {
29+
this.clearTempFolder(Path.of(Constants.TEMP_DIR_PLUGIN));
30+
return super.closing();
31+
}
32+
/**
33+
* Will remove recursivelly all decompiled classes, when close Netbeans.
34+
*
35+
* @param path
36+
*/
37+
private void clearTempFolder(Path path) {
38+
Exceptions.wrap(ex -> ExceptionHandler.handleException(ex)).run(() -> {
39+
if (Files.isDirectory(path) && Files.list(path).count() > 0) {
40+
Files.list(path).forEach(it -> this.clearTempFolder(it));
41+
}
42+
Files.deleteIfExists(path);
43+
});
44+
}
45+
46+
}

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)