Skip to content

Commit b62590b

Browse files
committed
Target Spigot 1.16, Sponge 7.2.0, Disable Pack Provider on JDK 14+
* Updated Spigot to 1.16.x (compatible with 1.8-1.16). * Updated Sponge-API to 7.2.0 * Pack200 was removed from the JDK starting with 14 (see https://openjdk.java.net/jeps/367). It has been disabled when using JDK 14+.
1 parent 7b95caf commit b62590b

File tree

11 files changed

+346
-85
lines changed

11 files changed

+346
-85
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![# Header](https://i.imgur.com/NNwBkWb.png)
22

3-
[<img src="https://ci.appveyor.com/api/projects/status/e9h6l9fu137jr5ek?retina=true" height="20.74px"></img>](https://ci.appveyor.com/project/dscalzi/zipextractor) [![](https://pluginbadges.glitch.me/api/v1/dl/Downloads-limegreen.svg?bukkit=zipextractor&spigot=zipextractor.43482&ore=ZipExtractor&github=dscalzi%2FZipExtractor&style=flat)](https://github.com/dscalzi/PluginBadges) [![](https://img.shields.io/github/license/dscalzi/ZipExtractor.svg)](https://github.com/dscalzi/ZipExtractor/blob/master/LICENSE.txt) ![](https://img.shields.io/badge/Spigot-1.8.x--1.15.x-orange.svg) [![](https://discordapp.com/api/guilds/211524927831015424/widget.png)](https://discordapp.com/invite/Fcrh6PT)
3+
[<img src="https://ci.appveyor.com/api/projects/status/e9h6l9fu137jr5ek?retina=true" height="20.74px"></img>](https://ci.appveyor.com/project/dscalzi/zipextractor) [![](https://pluginbadges.glitch.me/api/v1/dl/Downloads-limegreen.svg?bukkit=zipextractor&spigot=zipextractor.43482&ore=ZipExtractor&github=dscalzi%2FZipExtractor&style=flat)](https://github.com/dscalzi/PluginBadges) [![](https://img.shields.io/github/license/dscalzi/ZipExtractor.svg)](https://github.com/dscalzi/ZipExtractor/blob/master/LICENSE.txt) ![](https://img.shields.io/badge/Spigot-1.8.x--1.16.x-orange.svg) [![](https://discordapp.com/api/guilds/211524927831015424/widget.png)](https://discordapp.com/invite/Fcrh6PT)
44

55
ZipExtractor is an administrative utility plugin allowing the compression/extraction of archived files through minecraft command. This plugin is extremely useful for dealing with archives over FTP, which does not provide support for neither compression nor extraction. While many safeguards are in place, please note that **there is no undo button**. Overridden files **cannot** be recovered.
66

@@ -11,6 +11,7 @@ The source and destination file paths are saved inside of the config.yml. This m
1111
# Feature List
1212

1313
* Extraction of **ZIP**, **RAR**, **JAR**, **PACK**, **TAR**, **GZ**, and **XZ** archives.
14+
* Note: Pack operations are only supported on JDK 13 and below.
1415
* Compression of any file or directory into the **ZIP** or **TAR** formats.
1516
* Compression of any **JAR** file to the **PACK** format, and any non-directory file to the **GZ** or **XZ** formats.
1617
* Queueable operations if you have many extractions/compressions to perform.

ZipExtractor-Bukkit/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repositories {
1010
}
1111

1212
dependencies {
13-
compileOnly 'org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT'
13+
compileOnly 'org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT'
1414

1515
implementation project(':ZipExtractor-Core')
1616
implementation 'org.bstats:bstats-bukkit:1.7'

ZipExtractor-Core/src/main/java/com/dscalzi/zipextractor/core/ZCompressor.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
/*
2-
* This file is part of ZipExtractor.
3-
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
4-
*
5-
* This program is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU Affero General Public License as
7-
* published by the Free Software Foundation, either version 3 of the
8-
* License, or (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU Affero General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Affero General Public License
16-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17-
*/
18-
19-
package com.dscalzi.zipextractor.core;
1+
/*
2+
* This file is part of ZipExtractor.
3+
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.dscalzi.zipextractor.core;
2020

2121
import java.io.File;
2222
import java.nio.file.Path;
@@ -65,6 +65,10 @@ public static void asyncCompress(ICommandSender sender, File src, File dest, boo
6565
if(provider == null) {
6666
return;
6767
}
68+
if(!provider.isSupported()) {
69+
mm.providerUnsupported(sender, provider.getUnsupportedMessage());
70+
return;
71+
}
6872
pDeque.push(new OpTuple(src, dest, provider));
6973
} else {
7074
File dTemp = dest;
@@ -81,6 +85,10 @@ public static void asyncCompress(ICommandSender sender, File src, File dest, boo
8185
if(provider == null) {
8286
return;
8387
}
88+
if(!provider.isSupported()) {
89+
mm.providerUnsupported(sender, provider.getUnsupportedMessage());
90+
return;
91+
}
8492

8593
pDeque.push(new OpTuple(i == 0 ? src : sTemp, dTemp, provider));
8694
dTemp = sTemp;

ZipExtractor-Core/src/main/java/com/dscalzi/zipextractor/core/ZExtractor.java

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
/*
2-
* This file is part of ZipExtractor.
3-
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
4-
*
5-
* This program is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU Affero General Public License as
7-
* published by the Free Software Foundation, either version 3 of the
8-
* License, or (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU Affero General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Affero General Public License
16-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17-
*/
18-
19-
package com.dscalzi.zipextractor.core;
1+
/*
2+
* This file is part of ZipExtractor.
3+
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.dscalzi.zipextractor.core;
2020

2121
import java.io.File;
2222
import java.nio.file.Path;
@@ -80,6 +80,10 @@ public static void asyncExtract(ICommandSender sender, File src, File dest, bool
8080
mm.invalidExtractionExtension(sender);
8181
return;
8282
}
83+
if(!p.isSupported()) {
84+
mm.providerUnsupported(sender, p.getUnsupportedMessage());
85+
return;
86+
}
8387
pDeque.add(new OpTuple(src, dest, p));
8488
} else {
8589

@@ -103,6 +107,10 @@ public static void asyncExtract(ICommandSender sender, File src, File dest, bool
103107
break;
104108
}
105109
}
110+
if(!p.isSupported()) {
111+
mm.providerUnsupported(sender, p.getUnsupportedMessage());
112+
return;
113+
}
106114
pDeque.add(new OpTuple(tSrc, dest, p));
107115
queue = queue.substring(0, queue.lastIndexOf('.'));
108116
tSrc = new File(dest + File.separator + new File(queue).getName());
@@ -117,6 +125,10 @@ public static void asyncExtract(ICommandSender sender, File src, File dest, bool
117125
mm.invalidExtractionExtension(sender);
118126
return;
119127
}
128+
if(!p.isSupported()) {
129+
mm.providerUnsupported(sender, p.getUnsupportedMessage());
130+
return;
131+
}
120132
pDeque.add(new OpTuple(src, dest, p));
121133
}
122134

ZipExtractor-Core/src/main/java/com/dscalzi/zipextractor/core/managers/MessageManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ public void invalidSourceForDest(ICommandSender sender, List<String> sources, Li
215215
"Only " + listToString(sources) + " files can be compressed to " + listToString(dests) + " files.");
216216
}
217217

218+
public void providerUnsupported(ICommandSender sender, String providerMessage) {
219+
sendError(sender, providerMessage);
220+
}
221+
218222
public void invalidPath(ICommandSender sender, String path, String type) {
219223
if (path == null || path.isEmpty()) {
220224
sendError(sender, "A " + type + " path must be specified.");

ZipExtractor-Core/src/main/java/com/dscalzi/zipextractor/core/provider/PackProvider.java

Lines changed: 96 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
1-
/*
2-
* This file is part of ZipExtractor.
3-
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
4-
*
5-
* This program is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU Affero General Public License as
7-
* published by the Free Software Foundation, either version 3 of the
8-
* License, or (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU Affero General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Affero General Public License
16-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17-
*/
18-
19-
package com.dscalzi.zipextractor.core.provider;
1+
/*
2+
* This file is part of ZipExtractor.
3+
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.dscalzi.zipextractor.core.provider;
2020

2121
import java.io.File;
2222
import java.io.FileOutputStream;
2323
import java.io.IOException;
2424
import java.io.OutputStream;
25+
import java.lang.reflect.InvocationTargetException;
26+
import java.lang.reflect.Method;
2527
import java.nio.file.Files;
2628
import java.util.ArrayList;
27-
import java.util.Arrays;
2829
import java.util.Collections;
2930
import java.util.List;
31+
import java.util.Objects;
3032
import java.util.jar.JarFile;
3133
import java.util.jar.JarOutputStream;
32-
import java.util.jar.Pack200;
3334
import java.util.regex.Pattern;
3435

3536
import com.dscalzi.zipextractor.core.ZTask;
3637
import com.dscalzi.zipextractor.core.managers.MessageManager;
3738
import com.dscalzi.zipextractor.core.util.ICommandSender;
39+
import com.dscalzi.zipextractor.core.util.JavaUtil;
40+
import com.dscalzi.zipextractor.core.util.ReflectionUtil;
3841

42+
// Pack200 deprecated in JDK 13, removed in JDK 14.
43+
// https://openjdk.java.net/jeps/367
3944
public class PackProvider implements TypeProvider {
4045

4146
public static final Pattern PATH_END_EXTRACT = Pattern.compile("\\.pack$");
@@ -69,7 +74,13 @@ public boolean extract(ICommandSender sender, File src, File dest, boolean log,
6974
try (JarOutputStream jarStream = new JarOutputStream(new FileOutputStream(realDest))) {
7075
if (log)
7176
mm.info("Extracting : " + src.getAbsoluteFile());
72-
Pack200.newUnpacker().unpack(src, jarStream);
77+
try {
78+
this.unpack(src, jarStream);
79+
} catch(Throwable t) {
80+
t.printStackTrace();
81+
mm.genericOperationError(sender, src, ZTask.EXTRACT);
82+
return false;
83+
}
7384
if(!pipe)
7485
mm.extractionComplete(sender, realDest);
7586
return true;
@@ -87,7 +98,13 @@ public boolean compress(ICommandSender sender, File src, File dest, boolean log,
8798
try (JarFile in = new JarFile(src); OutputStream out = Files.newOutputStream(dest.toPath())) {
8899
if (log)
89100
mm.info("Compressing : " + src.getAbsolutePath());
90-
Pack200.newPacker().pack(in, out);
101+
try {
102+
this.pack(in, out);
103+
} catch(Throwable t) {
104+
t.printStackTrace();
105+
mm.genericOperationError(sender, src, ZTask.COMPRESS);
106+
return false;
107+
}
91108
if(!pipe)
92109
mm.compressionComplete(sender, dest);
93110
return true;
@@ -128,4 +145,60 @@ public List<String> canCompressFrom() {
128145
return SUPPORTED_COMPRESS;
129146
}
130147

148+
@Override
149+
public boolean isSupported() {
150+
return JavaUtil.getJavaVersion() < 14;
151+
}
152+
153+
@Override
154+
public String getUnsupportedMessage() {
155+
return "Pack200 support is only enabled on JDK 13 and below.";
156+
}
157+
158+
/* Access Pack200 Reflectively */
159+
160+
protected Class<?> getPack200Class() {
161+
return ReflectionUtil.getClass("java.util.jar.Pack200");
162+
}
163+
164+
protected Object getUnpacker() throws InvocationTargetException, IllegalAccessException {
165+
Class<?> Pack200Class = this.getPack200Class();
166+
Method newUnpacker = Objects.requireNonNull(ReflectionUtil.getMethod(Pack200Class, "newUnpacker"));
167+
return newUnpacker.invoke(null);
168+
}
169+
170+
protected Object getPacker() throws InvocationTargetException, IllegalAccessException {
171+
Class<?> Pack200Class = this.getPack200Class();
172+
Method newPacker = Objects.requireNonNull(ReflectionUtil.getMethod(Pack200Class, "newPacker"));
173+
return newPacker.invoke(null);
174+
}
175+
176+
protected Method getUnpackMethod() {
177+
Class<?> Pack200Class = this.getPack200Class();
178+
Class<?> UnpackerClass = ReflectionUtil.getDeclaredClass(Pack200Class, "Unpacker");
179+
// void unpack(File in, JarOutputStream out) throws IOException;
180+
return ReflectionUtil.getMethod(UnpackerClass, "unpack", File.class, JarOutputStream.class);
181+
}
182+
183+
protected Method getPackMethod() {
184+
Class<?> Pack200Class = this.getPack200Class();
185+
Class<?> PackerClass = ReflectionUtil.getDeclaredClass(Pack200Class, "Packer");
186+
// void pack(JarFile in, OutputStream out) throws IOException;
187+
return ReflectionUtil.getMethod(PackerClass, "pack", JarFile.class, OutputStream.class);
188+
}
189+
190+
protected void unpack(File in, JarOutputStream out) throws InvocationTargetException, IllegalAccessException {
191+
// Pack200.newUnpacker().unpack(src, jarStream);
192+
Object unpacker = this.getUnpacker();
193+
Method unpackMethod = this.getUnpackMethod();
194+
unpackMethod.invoke(unpacker, in, out);
195+
}
196+
197+
protected void pack(JarFile in, OutputStream out) throws InvocationTargetException, IllegalAccessException {
198+
// Pack200.newPacker().pack(in, out);
199+
Object packer = this.getPacker();
200+
Method packMethod = this.getPackMethod();
201+
packMethod.invoke(packer, in, out);
202+
}
203+
131204
}

ZipExtractor-Core/src/main/java/com/dscalzi/zipextractor/core/provider/TypeProvider.java

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
/*
2-
* This file is part of ZipExtractor.
3-
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
4-
*
5-
* This program is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU Affero General Public License as
7-
* published by the Free Software Foundation, either version 3 of the
8-
* License, or (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU Affero General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Affero General Public License
16-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17-
*/
18-
19-
package com.dscalzi.zipextractor.core.provider;
1+
/*
2+
* This file is part of ZipExtractor.
3+
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.dscalzi.zipextractor.core.provider;
2020

2121
import java.io.File;
2222
import java.util.List;
@@ -179,4 +179,19 @@ default List<String> canCompressFrom() {
179179
*/
180180
boolean canDetectPipedConflicts();
181181

182+
/**
183+
* Returns whether or not this provider is supported on the current runtime environment.
184+
*
185+
* @return True if the provider can be run, false otherwise.
186+
*/
187+
default boolean isSupported() { return true; }
188+
189+
/**
190+
* Returns an message to the user explaining why the provider is not supported. Must be
191+
* defined if {@link TypeProvider#isSupported()} can return false.
192+
*
193+
* @return A message to the user explaining why the provider is not supported.
194+
*/
195+
default String getUnsupportedMessage() { return ""; }
196+
182197
}

0 commit comments

Comments
 (0)