Skip to content

Commit

Permalink
Target Spigot 1.16, Sponge 7.2.0, Disable Pack Provider on JDK 14+
Browse files Browse the repository at this point in the history
* 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+.
  • Loading branch information
dscalzi committed Jun 27, 2020
1 parent 7b95caf commit b62590b
Show file tree
Hide file tree
Showing 11 changed files with 346 additions and 85 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![# Header](https://i.imgur.com/NNwBkWb.png)

[<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)
[<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)

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.

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

* Extraction of **ZIP**, **RAR**, **JAR**, **PACK**, **TAR**, **GZ**, and **XZ** archives.
* Note: Pack operations are only supported on JDK 13 and below.
* Compression of any file or directory into the **ZIP** or **TAR** formats.
* Compression of any **JAR** file to the **PACK** format, and any non-directory file to the **GZ** or **XZ** formats.
* Queueable operations if you have many extractions/compressions to perform.
Expand Down
2 changes: 1 addition & 1 deletion ZipExtractor-Bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
}

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

implementation project(':ZipExtractor-Core')
implementation 'org.bstats:bstats-bukkit:1.7'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/*
* This file is part of ZipExtractor.
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.dscalzi.zipextractor.core;
/*
* This file is part of ZipExtractor.
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.dscalzi.zipextractor.core;

import java.io.File;
import java.nio.file.Path;
Expand Down Expand Up @@ -65,6 +65,10 @@ public static void asyncCompress(ICommandSender sender, File src, File dest, boo
if(provider == null) {
return;
}
if(!provider.isSupported()) {
mm.providerUnsupported(sender, provider.getUnsupportedMessage());
return;
}
pDeque.push(new OpTuple(src, dest, provider));
} else {
File dTemp = dest;
Expand All @@ -81,6 +85,10 @@ public static void asyncCompress(ICommandSender sender, File src, File dest, boo
if(provider == null) {
return;
}
if(!provider.isSupported()) {
mm.providerUnsupported(sender, provider.getUnsupportedMessage());
return;
}

pDeque.push(new OpTuple(i == 0 ? src : sTemp, dTemp, provider));
dTemp = sTemp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/*
* This file is part of ZipExtractor.
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.dscalzi.zipextractor.core;
/*
* This file is part of ZipExtractor.
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.dscalzi.zipextractor.core;

import java.io.File;
import java.nio.file.Path;
Expand Down Expand Up @@ -80,6 +80,10 @@ public static void asyncExtract(ICommandSender sender, File src, File dest, bool
mm.invalidExtractionExtension(sender);
return;
}
if(!p.isSupported()) {
mm.providerUnsupported(sender, p.getUnsupportedMessage());
return;
}
pDeque.add(new OpTuple(src, dest, p));
} else {

Expand All @@ -103,6 +107,10 @@ public static void asyncExtract(ICommandSender sender, File src, File dest, bool
break;
}
}
if(!p.isSupported()) {
mm.providerUnsupported(sender, p.getUnsupportedMessage());
return;
}
pDeque.add(new OpTuple(tSrc, dest, p));
queue = queue.substring(0, queue.lastIndexOf('.'));
tSrc = new File(dest + File.separator + new File(queue).getName());
Expand All @@ -117,6 +125,10 @@ public static void asyncExtract(ICommandSender sender, File src, File dest, bool
mm.invalidExtractionExtension(sender);
return;
}
if(!p.isSupported()) {
mm.providerUnsupported(sender, p.getUnsupportedMessage());
return;
}
pDeque.add(new OpTuple(src, dest, p));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ public void invalidSourceForDest(ICommandSender sender, List<String> sources, Li
"Only " + listToString(sources) + " files can be compressed to " + listToString(dests) + " files.");
}

public void providerUnsupported(ICommandSender sender, String providerMessage) {
sendError(sender, providerMessage);
}

public void invalidPath(ICommandSender sender, String path, String type) {
if (path == null || path.isEmpty()) {
sendError(sender, "A " + type + " path must be specified.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
/*
* This file is part of ZipExtractor.
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.dscalzi.zipextractor.core.provider;
/*
* This file is part of ZipExtractor.
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.dscalzi.zipextractor.core.provider;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.jar.Pack200;
import java.util.regex.Pattern;

import com.dscalzi.zipextractor.core.ZTask;
import com.dscalzi.zipextractor.core.managers.MessageManager;
import com.dscalzi.zipextractor.core.util.ICommandSender;
import com.dscalzi.zipextractor.core.util.JavaUtil;
import com.dscalzi.zipextractor.core.util.ReflectionUtil;

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

public static final Pattern PATH_END_EXTRACT = Pattern.compile("\\.pack$");
Expand Down Expand Up @@ -69,7 +74,13 @@ public boolean extract(ICommandSender sender, File src, File dest, boolean log,
try (JarOutputStream jarStream = new JarOutputStream(new FileOutputStream(realDest))) {
if (log)
mm.info("Extracting : " + src.getAbsoluteFile());
Pack200.newUnpacker().unpack(src, jarStream);
try {
this.unpack(src, jarStream);
} catch(Throwable t) {
t.printStackTrace();
mm.genericOperationError(sender, src, ZTask.EXTRACT);
return false;
}
if(!pipe)
mm.extractionComplete(sender, realDest);
return true;
Expand All @@ -87,7 +98,13 @@ public boolean compress(ICommandSender sender, File src, File dest, boolean log,
try (JarFile in = new JarFile(src); OutputStream out = Files.newOutputStream(dest.toPath())) {
if (log)
mm.info("Compressing : " + src.getAbsolutePath());
Pack200.newPacker().pack(in, out);
try {
this.pack(in, out);
} catch(Throwable t) {
t.printStackTrace();
mm.genericOperationError(sender, src, ZTask.COMPRESS);
return false;
}
if(!pipe)
mm.compressionComplete(sender, dest);
return true;
Expand Down Expand Up @@ -128,4 +145,60 @@ public List<String> canCompressFrom() {
return SUPPORTED_COMPRESS;
}

@Override
public boolean isSupported() {
return JavaUtil.getJavaVersion() < 14;
}

@Override
public String getUnsupportedMessage() {
return "Pack200 support is only enabled on JDK 13 and below.";
}

/* Access Pack200 Reflectively */

protected Class<?> getPack200Class() {
return ReflectionUtil.getClass("java.util.jar.Pack200");
}

protected Object getUnpacker() throws InvocationTargetException, IllegalAccessException {
Class<?> Pack200Class = this.getPack200Class();
Method newUnpacker = Objects.requireNonNull(ReflectionUtil.getMethod(Pack200Class, "newUnpacker"));
return newUnpacker.invoke(null);
}

protected Object getPacker() throws InvocationTargetException, IllegalAccessException {
Class<?> Pack200Class = this.getPack200Class();
Method newPacker = Objects.requireNonNull(ReflectionUtil.getMethod(Pack200Class, "newPacker"));
return newPacker.invoke(null);
}

protected Method getUnpackMethod() {
Class<?> Pack200Class = this.getPack200Class();
Class<?> UnpackerClass = ReflectionUtil.getDeclaredClass(Pack200Class, "Unpacker");
// void unpack(File in, JarOutputStream out) throws IOException;
return ReflectionUtil.getMethod(UnpackerClass, "unpack", File.class, JarOutputStream.class);
}

protected Method getPackMethod() {
Class<?> Pack200Class = this.getPack200Class();
Class<?> PackerClass = ReflectionUtil.getDeclaredClass(Pack200Class, "Packer");
// void pack(JarFile in, OutputStream out) throws IOException;
return ReflectionUtil.getMethod(PackerClass, "pack", JarFile.class, OutputStream.class);
}

protected void unpack(File in, JarOutputStream out) throws InvocationTargetException, IllegalAccessException {
// Pack200.newUnpacker().unpack(src, jarStream);
Object unpacker = this.getUnpacker();
Method unpackMethod = this.getUnpackMethod();
unpackMethod.invoke(unpacker, in, out);
}

protected void pack(JarFile in, OutputStream out) throws InvocationTargetException, IllegalAccessException {
// Pack200.newPacker().pack(in, out);
Object packer = this.getPacker();
Method packMethod = this.getPackMethod();
packMethod.invoke(packer, in, out);
}

}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/*
* This file is part of ZipExtractor.
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.dscalzi.zipextractor.core.provider;
/*
* This file is part of ZipExtractor.
* Copyright (C) 2016-2020 Daniel D. Scalzi <https://github.com/dscalzi/ZipExtractor>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.dscalzi.zipextractor.core.provider;

import java.io.File;
import java.util.List;
Expand Down Expand Up @@ -179,4 +179,19 @@ default List<String> canCompressFrom() {
*/
boolean canDetectPipedConflicts();

/**
* Returns whether or not this provider is supported on the current runtime environment.
*
* @return True if the provider can be run, false otherwise.
*/
default boolean isSupported() { return true; }

/**
* Returns an message to the user explaining why the provider is not supported. Must be
* defined if {@link TypeProvider#isSupported()} can return false.
*
* @return A message to the user explaining why the provider is not supported.
*/
default String getUnsupportedMessage() { return ""; }

}
Loading

0 comments on commit b62590b

Please sign in to comment.