Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the decompiled directory when netbeans is about to be closed. #13

Merged
merged 2 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
<artifactId>org-netbeans-modules-java-source</artifactId>
<version>RELEASE130</version>
</dependency>

<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-modules</artifactId>
<version>RELEASE130</version>
</dependency>
</dependencies>

<repositories>
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/com/mrf/javadecompiler/openapi/Installer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2022 moacirrf
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.mrf.javadecompiler.openapi;

import com.machinezoo.noexception.Exceptions;
import com.mrf.javadecompiler.constants.Constants;
import com.mrf.javadecompiler.exception.ExceptionHandler;
import java.nio.file.Files;
import java.nio.file.Path;
import org.openide.modules.ModuleInstall;

public class Installer extends ModuleInstall {

@Override
public boolean closing() {
this.clearTempFolder(Path.of(Constants.TEMP_DIR_PLUGIN));
return super.closing();
}
/**
* Will remove recursivelly all decompiled classes, when close Netbeans.
*
* @param path
*/
private void clearTempFolder(Path path) {
Exceptions.wrap(ex -> ExceptionHandler.handleException(ex)).run(() -> {
if (Files.isDirectory(path) && Files.list(path).count() > 0) {
Files.list(path).forEach(it -> this.clearTempFolder(it));
}
Files.deleteIfExists(path);
});
}

}
1 change: 1 addition & 0 deletions src/main/nbm/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Manifest-Version: 1.0
OpenIDE-Module-Localizing-Bundle: com/mrf/javadecompiler/Bundle.properties
OpenIDE-Module-Requires: org.openide.windows.WindowManager
OpenIDE-Module-Install: com/mrf/javadecompiler/openapi/Installer.class