-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathIssuePackager.java
More file actions
93 lines (85 loc) · 3.38 KB
/
IssuePackager.java
File metadata and controls
93 lines (85 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Tai-e: A Static Analysis Framework for Java
*
* Copyright (C) 2022 Tian Tan <tiantan@nju.edu.cn>
* Copyright (C) 2022 Yue Li <yueli@nju.edu.cn>
*
* This file is part of Tai-e.
*
* Tai-e is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Tai-e 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 Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Tai-e. If not, see <https://www.gnu.org/licenses/>.
*/
package pascal.taie.util;
import pascal.taie.config.Options;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class IssuePackager {
public static void createIssuePackage(Options options) {
try {
List<Source> filePaths = new ArrayList<>();
filePaths.add(new Source("output", new File(options.getOutputDir().getCanonicalPath())));
options.getClassPath().stream()
.map(path -> new Source("cp", new File(path)))
.forEach(filePaths::add);
options.getAppClassPath().stream()
.map(path -> new Source("acp", new File(path)))
.forEach(filePaths::add);
options.getInputClasses().stream()
.map(path -> new Source("input-classes", new File(path)))
.forEach(filePaths::add);
createZipFile("package.zip", filePaths);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static void createZipFile(String zipFileName, List<Source> filePaths) {
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFileName))) {
for (Source source : filePaths) {
File file = source.file;
String category = source.category;
addToZipFile(category, file, zos);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static void addToZipFile(String category, File file, ZipOutputStream zos) {
if (file.isDirectory()) {
for (File subFile : Objects.requireNonNull(file.listFiles())) {
addToZipFile(category + "/" + subFile.getName(), subFile, zos);
}
} else {
try (FileInputStream fis = new FileInputStream(file)) {
ZipEntry zipEntry = new ZipEntry(category + "/" + file.getName());
zos.putNextEntry(zipEntry);
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
private record Source(String category, File file) {
}
}