Skip to content

Commit 8d91b8d

Browse files
Added Zstd support
1 parent 7f2be9e commit 8d91b8d

File tree

19 files changed

+201
-26
lines changed

19 files changed

+201
-26
lines changed

ZipEditor-test/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Require-Bundle: org.eclipse.core.runtime,
99
org.eclipse.core.filesystem,
1010
org.eclipse.search,
1111
ZipEditor,
12-
org.junit
12+
org.junit,
13+
org.apache.commons.commons-compress
1314
Eclipse-LazyStart: false
1415
Bundle-Vendor: %Bundle-Vendor.0

ZipEditor-test/resources/zstd.zip

694 Bytes
Binary file not shown.

ZipEditor-test/src/zipeditor/model/AbstractModelTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
public abstract class AbstractModelTest {
1515

16-
private ZipModel model;
16+
protected ZipModel model;
1717

1818
public abstract String getArchiveName();
1919

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package zipeditor.model;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.io.File;
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
9+
import org.apache.commons.compress.archivers.zip.ZipMethod;
10+
import org.junit.Test;
11+
12+
import zipeditor.model.ZipContentDescriber.ContentTypeId;
13+
14+
public class ZipModelZstdTest extends AbstractModelTest {
15+
16+
@Override
17+
public String getArchiveName() {
18+
return "zstd.zip";
19+
}
20+
21+
@Override
22+
public ContentTypeId getArchiveType() {
23+
return ContentTypeId.ZIP_FILE;
24+
}
25+
26+
@Override
27+
public void shouldOpenNodes() throws Exception {
28+
assertEquals(getArchiveType(), model.getType());
29+
assertEquals("", model.getRoot().getPath());
30+
assertEquals(2, model.getRoot().getChildren().length);
31+
32+
ZipNode childByName = (ZipNode) model.getRoot().getChildByName(".classpath", false);
33+
assertEquals(".classpath", childByName.getName());
34+
assertEquals(childByName.getMethod(), ZipMethod.ZSTD.getCode());
35+
36+
childByName = (ZipNode) model.getRoot().getChildByName(".project", false);
37+
assertEquals(".project", childByName.getName());
38+
assertEquals(childByName.getMethod(), ZipMethod.ZSTD.getCode());
39+
}
40+
41+
@Test
42+
public void extractZstdNode() throws IOException {
43+
ZipNode childByName = (ZipNode) model.getRoot().getChildByName(".project", false);
44+
assertEquals(".project", childByName.getName());
45+
assertEquals(childByName.getMethod(), ZipMethod.ZSTD.getCode());
46+
47+
InputStream content = childByName.getContent();
48+
String string = new String(content.readAllBytes());
49+
50+
String[] split = string.split("\n");
51+
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", split[0]);
52+
assertEquals(23, split.length);
53+
}
54+
55+
}

ZipEditor/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
</attributes>
88
</classpathentry>
99
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
10+
<classpathentry kind="lib" path="lib/aircompressor-0.27.jar" sourcepath="lib/aircompressor-0.27-sources.jar"/>
1011
<classpathentry kind="output" path="bin"/>
1112
</classpath>

ZipEditor/META-INF/MANIFEST.MF

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Automatic-Module-Name: %Bundle-Name.0
44
Bundle-Name: %Bundle-Name.0
5+
Bundle-RequiredExecutionEnvironment: JavaSE-21
56
Bundle-SymbolicName: ZipEditor;singleton:=true
67
Bundle-Version: 1.1.9.qualifier
78
Bundle-Activator: zipeditor.ZipEditorPlugin
9+
Bundle-ClassPath: .,
10+
lib/aircompressor-0.27.jar
811
Bundle-Localization: plugin
912
Require-Bundle: org.eclipse.core.runtime,
1013
org.eclipse.core.resources,
@@ -18,8 +21,9 @@ Require-Bundle: org.eclipse.core.runtime,
1821
org.eclipse.search,
1922
org.apache.ant,
2023
org.apache.commons.commons-io,
21-
org.apache.commons.commons-compress;bundle-version="1.27.1",
22-
org.apache.commons.lang3;bundle-version="3.17.0"
24+
org.apache.commons.lang3;bundle-version="3.17.0",
25+
org.apache.commons.commons-compress;bundle-version="1.28.0",
26+
wrapped.io.airlift.aircompressor;bundle-version="2.0.2"
2327
Bundle-ActivationPolicy: lazy
2428
Bundle-Vendor: %Bundle-Vendor.0
2529
Export-Package: zipeditor,

ZipEditor/build.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ bin.includes = META-INF/,\
77
.options,\
88
about_files/,\
99
about.html,\
10-
plugin.properties
10+
plugin.properties,\
11+
lib/aircompressor-0.27.jar
202 KB
Binary file not shown.
249 KB
Binary file not shown.

ZipEditor/src/zipeditor/actions/AddAction.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import zipeditor.ZipEditorPlugin;
1212
import zipeditor.model.Node;
13+
import zipeditor.model.ZipContentDescriber.ContentTypeId;
1314
import zipeditor.operations.AddOperation;
1415

1516
public class AddAction extends DialogAction {
@@ -20,13 +21,13 @@ public AddAction(StructuredViewer viewer) {
2021
}
2122

2223
public void run() {
23-
File[] paths = openDialog(ActionMessages.getString("AddAction.2"), null, true, true); //$NON-NLS-1$);
24-
if (paths == null || paths.length == 0)
25-
return;
2624
Node[] selectedNodes = getSelectedNodes();
2725
Node targetNode = selectedNodes.length > 0 ? selectedNodes[0] : getViewerInputAsNode();
26+
File[] paths = openDialog(ActionMessages.getString("AddAction.2"), null, true, true, targetNode.getModel().getType() == ContentTypeId.ZIP_FILE); //$NON-NLS-1$);
27+
if (paths == null || paths.length == 0)
28+
return;
2829
AddOperation operation = new AddOperation();
29-
operation.execute(paths, targetNode, null, getViewer());
30+
operation.execute(paths, targetNode, null, getViewer(), isZstdCompression());
3031
}
3132

3233
}

0 commit comments

Comments
 (0)