25
25
import java .util .List ;
26
26
import java .util .Map ;
27
27
import java .util .stream .Collectors ;
28
- import java .util .zip .ZipEntry ;
29
- import java .util .zip .ZipFile ;
28
+ // import java.util.zip.ZipEntry;
29
+ // import java.util.zip.ZipFile;
30
30
31
31
import org .apache .commons .compress .archivers .examples .Archiver ;
32
32
import org .apache .commons .compress .archivers .tar .TarArchiveEntry ;
33
33
import org .apache .commons .compress .archivers .tar .TarArchiveInputStream ;
34
34
import org .apache .commons .compress .archivers .tar .TarUtils ;
35
35
import org .apache .commons .compress .archivers .zip .ZipArchiveEntry ;
36
+ import org .apache .commons .compress .archivers .zip .ZipFile ;
36
37
import org .apache .commons .compress .compressors .gzip .GzipCompressorInputStream ;
37
38
import org .apache .commons .compress .utils .IOUtils ;
38
39
import org .apache .commons .io .FilenameUtils ;
@@ -110,14 +111,20 @@ public static String getCommandString(String project, String repo, String versio
110
111
return cmd + " -jar " ;
111
112
}
112
113
114
+ public static boolean isExecutable (ZipArchiveEntry entry ) {
115
+ int unixMode = entry .getUnixMode ();
116
+ // Check if any of the executable bits are set for user, group, or others.
117
+ // User executable: 0100 (0x40), Group executable: 0010 (0x10), Others executable: 0001 (0x01)
118
+ return (unixMode & 0x49 ) != 0 ;
119
+ }
113
120
private static void unzip (File path , String dir ) throws Exception {
114
121
String fileBaseName = FilenameUtils .getBaseName (path .getName ().toString ());
115
122
Path destFolderPath = new File (dir ).toPath ();
116
123
117
- try (ZipFile zipFile = new ZipFile ( path , ZipFile . OPEN_READ , Charset . defaultCharset () )) {
118
- Enumeration <? extends ZipEntry > entries = zipFile .entries ();
124
+ try (ZipFile zipFile = ZipFile . builder (). setFile ( path ). get ( )) {
125
+ Enumeration <ZipArchiveEntry > entries = zipFile .getEntries ();
119
126
while (entries .hasMoreElements ()) {
120
- ZipEntry entry = entries .nextElement ();
127
+ ZipArchiveEntry entry = entries .nextElement ();
121
128
Path entryPath = destFolderPath .resolve (entry .getName ());
122
129
if (entryPath .normalize ().startsWith (destFolderPath .normalize ())) {
123
130
if (entry .isDirectory ()) {
@@ -126,20 +133,25 @@ private static void unzip(File path, String dir) throws Exception {
126
133
Files .createDirectories (entryPath .getParent ());
127
134
try (InputStream in = zipFile .getInputStream (entry )) {
128
135
try {
129
- ZipArchiveEntry ar = new ZipArchiveEntry ( entry );
130
136
//ar.setExternalAttributes(entry.extraAttributes);
131
- if (ar .isUnixSymlink ()) {
137
+ if (entry .isUnixSymlink ()) {
132
138
String text = new BufferedReader (new InputStreamReader (in , StandardCharsets .UTF_8 ))
133
139
.lines ().collect (Collectors .joining ("\n " ));
134
- Files .createSymbolicLink (entryPath , Paths .get ("." , text ), null );
140
+ Path target = Paths .get ("." , text );
141
+ System .out .println ("Creating symlink " +entryPath +" with " +target );
142
+
143
+ Files .createSymbolicLink (entryPath , target );
135
144
continue ;
136
145
}
137
- } catch (java . lang . ClassCastException ex ) {
146
+ } catch (Exception ex ) {
138
147
ex .printStackTrace ();
139
148
}
140
149
try (OutputStream out = new FileOutputStream (entryPath .toFile ())) {
141
150
IOUtils .copy (in , out );
142
151
}
152
+ if (isExecutable (entry )) {
153
+ entryPath .toFile ().setExecutable (true );
154
+ }
143
155
}
144
156
}
145
157
}
0 commit comments