如何从Gradle中调用7zip来取消标记Jar [英] How Do I Call 7zip From Gradle To Unsign A Jar
问题描述
我想批量使用gradle取消签名一些罐子,但我不想使用蚂蚁因为它太慢了。
使用7zip命令行要快得多:
7z.exe d activemq-pool-5.7.0.jar META-INF / SIGFILE。*
其中SIGFILE是之前签名的名称。
我试图在gradle中这样做
printlnUnsigning jars
file(unsignedFolder +/jars\").listFiles().each {File file - >
exec {
workingDir'../tools'
commandLine'7z.exe','d',file.absolutePath,'META-INF / SIGFILE。*'
}
}
但是,我收到错误消息:
启动进程'命令'7z.exe''。工作目录:D:\ code\project\tools命令:7z.exe d D:\ code\project\build\unsigned\jars\activemq-pool-5.7.0.jar META- INF / SIGFILE。*
:signWebstart FAILED
:signWebWebstart(Thread [Daemon,5,main])已完成。花了0.109秒。
失败:构建失败,出现异常。
*出错:
任务':unsignJars'的执行失败。
> 7z.exe''
感谢这篇文章,我意识到它应该是什么。
我正在使用7zip的命令行版本 - 7za。在 http://p7zip.sourceforge.net/ 上也有一个unix版本,所以我将它们都包装在一起使用我的脚本并使用以下内容:
import org.apache.tools.ant.taskdefs.condition。 Os
任务unSignJars(){
if(Os.isFamily(Os.FAMILY_WINDOWS)){
println*** WINDOWS
exec {
可执行文件7za.exe
argsd,temp.jar,META-INF / SIGN.RSA
}
} else if(Os.isFamily(Os。 FAMILY_UNIX)){
println*** UNIX
exec {
可执行文件7za
argsd,temp.jar,META-INF / SIGN .RSA
}其他{
println***不支持
}
}
这种方法比使用Java nio快两倍 http:// t hinktibits.blogspot.ca/2013/02/Delete-Files-From-ZIP-Archive-Java-Example.html ,它本身的速度是OP中提及的ant方法的两倍。
import java.util。*;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file。*;
import java.nio.file.StandardCopyOption;
public class ZPFSDelete {
public static void main(String [] args)throws Exception {
/ *在HashMap中定义ZIP文件系统实例* /
Map<字符串,字符串> zip_properties = new HashMap<>();
/ *我们想读取一个现有的ZIP文件,所以我们将其设置为False * /
zip_properties.put(create,false);
指定要作为文件系统读取的ZIP文件的路径* /
URI zip_disk = URI.create(jar:file:/my_zip_file.zip) ;
$ b $ *创建ZIP文件系统* /
尝试(FileSystem zipfs = FileSystems.newFileSystem(zip_disk,zip_properties)){
/ *获取ZIP文件中的路径以删除ZIP条目* /
路径pathInZipfile = zipfs.getPath(source.sql);
System.out.println(关于从ZIP文件中删除条目+ pathInZipfile.toUri());
/ *执行删除* /
Files.delete(pathInZipfile);
System.out.println(File successfully deleted);
}
}
}
但是,unix zip -d再次快两倍,但不便携。
I want to batch Unsign some jars with in gradle but I don't want to use the ant jar method as it is too slow.
Using the 7zip command line is much faster:
7z.exe d activemq-pool-5.7.0.jar META-INF/SIGFILE.*
Where SIGFILE is the name of the previous signature.
I am trying to do it in gradle like this
println "Unsigning jars"
file(unsignedFolder + "/jars").listFiles().each { File file ->
exec {
workingDir '../tools'
commandLine '7z.exe', 'd', file.absolutePath, 'META-INF/SIGFILE.*'
}
}
However, I get the error:
Starting process 'command '7z.exe''. Working directory: D:\code\project\tools Command: 7z.exe d D:\code\project\build\unsigned\jars\activemq-pool-5.7.0.jar META-INF/SIGFILE.*
:signWebstart FAILED
:signWebstart (Thread[Daemon,5,main]) completed. Took 0.109 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':unsignJars'.
> A problem occurred starting process 'command '7z.exe''
Thanks to this post I realised what it should be.
I am using the command line version of 7zip now - 7za. There is also a unix version at http://p7zip.sourceforge.net/ so I am packaging them both with my script and using something along the lines of the following:
import org.apache.tools.ant.taskdefs.condition.Os
task unSignJars() {
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
println "*** WINDOWS "
exec {
executable "7za.exe"
args "d", "temp.jar", "META-INF/SIGN.RSA"
}
} else if(Os.isFamily(Os.FAMILY_UNIX)) {
println "*** UNIX "
exec {
executable "7za"
args "d", "temp.jar", "META-INF/SIGN.RSA"
}
} else {
println "*** NOT SUPPORTED "
}
}
This method is twice as fast as using Java nio http://thinktibits.blogspot.ca/2013/02/Delete-Files-From-ZIP-Archive-Java-Example.html which in itself is twice as fast as the ant method mention in the OP.
import java.util.*;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.*;
import java.nio.file.StandardCopyOption;
public class ZPFSDelete {
public static void main(String [] args) throws Exception {
/* Define ZIP File System Properies in HashMap */
Map<String, String> zip_properties = new HashMap<>();
/* We want to read an existing ZIP File, so we set this to False */
zip_properties.put("create", "false");
/* Specify the path to the ZIP File that you want to read as a File System */
URI zip_disk = URI.create("jar:file:/my_zip_file.zip");
/* Create ZIP file System */
try (FileSystem zipfs = FileSystems.newFileSystem(zip_disk, zip_properties)) {
/* Get the Path inside ZIP File to delete the ZIP Entry */
Path pathInZipfile = zipfs.getPath("source.sql");
System.out.println("About to delete an entry from ZIP File" + pathInZipfile.toUri() );
/* Execute Delete */
Files.delete(pathInZipfile);
System.out.println("File successfully deleted");
}
}
}
However, unix zip -d is twice as fast again but it isn't portable.
这篇关于如何从Gradle中调用7zip来取消标记Jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!