Codebase list jd-gui / 12c9c35
Fixes #35, "Save All source dose not work" emmanue1 8 years ago
7 changed file(s) with 103 addition(s) and 57 deletion(s). Raw diff Collapse all Expand all
1919
2020 public int getFileCount(API api, Container.Entry entry);
2121
22 public void save(API api, Controller controller, Listener listener, Path path, Container.Entry entry);
22 /**
23 * Check parent path, build source file name, create NIO path and save the content.
24 */
25 public void save(API api, Controller controller, Listener listener, Path rootPath, Container.Entry entry);
26
27 /**
28 * Save content:
29 * <ul>
30 * <li>For file, save the source content.</li>
31 * <li>For directory, call 'save' for each children.</li>
32 * </ul>
33 */
34 public void saveContent(API api, Controller controller, Listener listener, Path rootPath, Path path, Container.Entry entry);
2335
2436 public interface Controller {
2537 public boolean isCancelled();
2121 import javax.swing.JComponent
2222 import javax.swing.tree.DefaultMutableTreeNode
2323 import javax.swing.tree.DefaultTreeModel
24 import java.nio.file.FileSystems
25 import java.nio.file.Files
2426 import java.nio.file.Path
2527
2628 class ContainerPanelFactoryProvider implements PanelFactory {
2729
28 String[] getTypes() { ['default'] }
30 @Override String[] getTypes() { ['default'] }
2931
32 @Override
3033 public <T extends JComponent & UriGettable> T make(API api, Container container) {
3134 return new ContainerPanel(api, container)
3235 }
5255 }
5356
5457 // --- ContentIndexable --- //
58 @Override
5559 @CompileStatic
5660 Indexes index(API api) {
5761 // Classic map
7074 }
7175 // Index populating value automatically
7276 def indexesWithDefault = new Indexes() {
73 void waitIndexers() {}
74 Map<String, Collection> getIndex(String name) {
75 mapWithDefault.get(name)
76 }
77 @Override void waitIndexers() {}
78 @Override Map<String, Collection> getIndex(String name) { mapWithDefault.get(name) }
7779 }
7880
7981 api.getIndexer(entry)?.index(api, entry, indexesWithDefault)
8082
8183 // To prevent memory leaks, return an index without the 'populate' behaviour
8284 return new Indexes() {
83 void waitIndexers() {}
84 Map<String, Collection> getIndex(String name) { map.get(name) }
85 @Override void waitIndexers() {}
86 @Override Map<String, Collection> getIndex(String name) { map.get(name) }
8587 }
8688 }
8789
8890 // --- SourcesSavable --- //
91 @Override
8992 String getSourceFileName() {
9093 def path = api.getSourceSaver(entry)?.getSourcePath(entry)
9194 int index = path.lastIndexOf('/')
9295 return path.substring(index+1)
9396 }
9497
95 int getFileCount() { api.getSourceSaver(entry)?.getFileCount(api, entry) }
98 @Override int getFileCount() { api.getSourceSaver(entry)?.getFileCount(api, entry) }
9699
100 @Override
97101 void save(API api, Controller controller, Listener listener, Path path) {
98 api.getSourceSaver(entry)?.save(
102 def parentPath = path.parent
103
104 if (parentPath && !Files.exists(parentPath)) {
105 Files.createDirectories(parentPath)
106 }
107
108 def uri = path.toUri()
109 def archiveUri = new URI('jar:' + uri.scheme, uri.host, uri.path + '!/', null)
110 def archiveFs = FileSystems.newFileSystem(archiveUri, [create: 'true'])
111 def archiveRootPath = archiveFs.getPath('/')
112
113 api.getSourceSaver(entry)?.saveContent(
99114 api,
100115 new SourceSaver.Controller() {
101116 boolean isCancelled() { controller.isCancelled() }
103118 new SourceSaver.Listener() {
104119 void pathSaved(Path p) { listener.pathSaved(p) }
105120 },
106 path, entry)
121 archiveRootPath, archiveRootPath, entry
122 )
123
124 archiveFs.close()
107125 }
108126 }
109127 }
1717 /**
1818 * @return local + optional external selectors
1919 */
20 String[] getSelectors() { ['*:dir:*'] + externalSelectors }
20 @Override String[] getSelectors() { ['*:dir:*'] + externalSelectors }
2121
22 String getSourcePath(Container.Entry entry) { entry.path }
22 @Override String getSourcePath(Container.Entry entry) { entry.path + '.src.zip' }
2323
24 int getFileCount(API api, Container.Entry entry) { getFileCount(api, entry.children) }
24 @Override int getFileCount(API api, Container.Entry entry) { getFileCount(api, entry.children) }
2525
2626 @CompileStatic
2727 protected int getFileCount(API api, Collection<Container.Entry> entries) {
3434 return count
3535 }
3636
37 void save(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path path, Container.Entry entry) {
38 save(api, controller, listener, path, entry.children)
37 @Override
38 @CompileStatic
39 public void save(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path rootPath, Container.Entry entry) {
40 Path path = rootPath.resolve(entry.getPath())
41
42 Files.createDirectories(path)
43
44 saveContent(api, controller, listener, rootPath, path, entry);
3945 }
4046
47 @Override
4148 @CompileStatic
42 protected void save(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path path, Collection<Container.Entry> entries) {
43 Files.createDirectories(path)
44
45 for (def e : entries) {
49 public void saveContent(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path rootPath, Path path, Container.Entry entry) {
50 for (def e : getChildren(entry)) {
4651 if (controller.isCancelled()) {
4752 break
4853 }
4954
50 def saver = api.getSourceSaver(e)
51
52 if (saver) {
53 def sp = saver.getSourcePath(e)
54 def p = path.fileSystem.getPath(sp)
55 saver.save(api, controller, listener, p, e)
56 }
55 api.getSourceSaver(e)?.save(api, controller, listener, rootPath, e)
5756 }
5857 }
58
59 protected Collection<Container.Entry> getChildren(Container.Entry entry) { entry.children }
5960 }
1818 /**
1919 * @return local + optional external selectors
2020 */
21 String[] getSelectors() { ['*:file:*'] + externalSelectors }
21 @Override String[] getSelectors() { ['*:file:*'] + externalSelectors }
2222
23 String getSourcePath(Container.Entry entry) { entry.path }
23 @Override String getSourcePath(Container.Entry entry) { entry.path }
2424
25 int getFileCount(API api, Container.Entry entry) { 1 }
25 @Override int getFileCount(API api, Container.Entry entry) { 1 }
2626
27 @Override
2728 @CompileStatic
28 void save(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path path, Container.Entry entry) {
29 public void save(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path rootPath, Container.Entry entry) {
30 saveContent(api, controller, listener, rootPath, rootPath.resolve(entry.getPath()), entry);
31 }
32
33 @Override
34 @CompileStatic
35 void saveContent(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path rootPath, Path path, Container.Entry entry) {
2936 listener.pathSaved(path)
3037
3138 entry.inputStream.withStream { InputStream is ->
44
55 package org.jd.gui.service.sourcesaver
66
7 import org.jd.gui.api.API
87 import org.jd.gui.api.model.Container
9 import org.jd.gui.spi.SourceSaver
108 import org.jd.gui.util.JarContainerEntryUtil
11
12 import java.nio.file.Path
139
1410 class PackageSourceSaverProvider extends DirectorySourceSaverProvider {
1511 /**
1612 * @return local + optional external selectors
1713 */
18 String[] getSelectors() { ['jar:dir:*', 'war:dir:*', 'ear:dir:*'] + externalSelectors }
14 @Override String[] getSelectors() { ['jar:dir:*', 'war:dir:*', 'ear:dir:*'] + externalSelectors }
1915
20 void save(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path path, Container.Entry entry) {
21 save(api, controller, listener, path, JarContainerEntryUtil.removeInnerTypeEntries(entry.children))
16 @Override
17 protected Collection<Container.Entry> getChildren(Container.Entry entry) {
18 JarContainerEntryUtil.removeInnerTypeEntries(entry.children)
2219 }
2320 }
1919 /**
2020 * @return local + optional external selectors
2121 */
22 String[] getSelectors() { ['*:file:*.zip', '*:file:*.jar', '*:file:*.war', '*:file:*.ear'] + externalSelectors }
22 @Override String[] getSelectors() { ['*:file:*.zip', '*:file:*.jar', '*:file:*.war', '*:file:*.ear'] + externalSelectors }
2323
24 String getSourcePath(Container.Entry entry) { entry.path + '.src.zip' }
24 @Override
25 @CompileStatic
26 public void save(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path rootPath, Container.Entry entry) {
27 def sourcePath = getSourcePath(entry)
28 def path = rootPath.resolve(sourcePath)
29 def parentPath = path.parent
2530
26 @CompileStatic
27 void save(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path path, Container.Entry entry) {
31 if (parentPath && !Files.exists(parentPath)) {
32 Files.createDirectories(parentPath)
33 }
34
2835 def tmpFile = File.createTempFile('jd-gui.', '.tmp.zip')
2936 tmpFile.delete()
3037
31 def env = new HashMap<String, String>()
32 env.put('create', 'true')
38 def tmpFileUri = tmpFile.toURI()
39 def tmpArchiveUri = new URI('jar:' + tmpFileUri.scheme, tmpFileUri.host, tmpFileUri.path + '!/', null)
40 def tmpArchiveFs = FileSystems.newFileSystem(tmpArchiveUri, [create: 'true']);
41 def tmpArchiveRootPath = tmpArchiveFs.getPath('/')
3342
34 def tmpFileUri = tmpFile.toURI()
35 def tmpURI = new URI('jar:' + tmpFileUri.scheme, tmpFileUri.host, tmpFileUri.path + '!/', null)
36 def tmpFs = FileSystems.newFileSystem(tmpURI, env);
43 saveContent(api, controller, listener, tmpArchiveRootPath, tmpArchiveRootPath, entry)
3744
38 super.save(api, controller, listener, tmpFs.getPath('/'), entry)
39 tmpFs.close()
45 tmpArchiveFs.close()
4046
4147 def tmpPath = Paths.get(tmpFile.absolutePath)
42 def srcZipParentPath = path.parent
43
44 if (srcZipParentPath && !Files.exists(srcZipParentPath)) {
45 Files.createDirectories(srcZipParentPath)
46 }
4748
4849 Files.move(tmpPath, path)
4950 }
44
55 package org.jd.gui.service.sourcesaver;
66
7 import groovy.transform.CompileStatic;
87 import jd.core.CoreConstants;
98 import jd.core.Decompiler;
109 import jd.core.process.DecompilerImpl;
4039 /**
4140 * @return local + optional external selectors
4241 */
42 @Override
4343 public String[] getSelectors() {
4444 List<String> externalSelectors = getExternalSelectors();
4545
5454 }
5555 }
5656
57 @Override
5758 public String getSourcePath(Container.Entry entry) {
5859 String path = entry.getPath();
5960 int index = path.lastIndexOf('.');
6162 return prefix + ".java";
6263 }
6364
65 @Override
6466 public int getFileCount(API api, Container.Entry entry) {
6567 if (entry.getPath().indexOf('$') == -1) {
6668 return 1;
6971 }
7072 }
7173
72 public void save(API api, Controller controller, Listener listener, Path path, Container.Entry entry) {
74 @Override
75 public void save(API api, Controller controller, Listener listener, Path rootPath, Container.Entry entry) {
76 String sourcePath = getSourcePath(entry);
77 Path path = rootPath.resolve(sourcePath);
78
79 saveContent(api, controller, listener, rootPath, path, entry);
80 }
81
82 @Override
83 public void saveContent(API api, Controller controller, Listener listener, Path rootPath, Path path, Container.Entry entry) {
7384 try {
7485 // Call listener
7586 if (path.toString().indexOf('$') == -1) {
136147 }
137148 }
138149
139 @CompileStatic
140150 protected static boolean getPreferenceValue(Map<String, String> preferences, String key, boolean defaultValue) {
141151 String v = preferences.get(key);
142152