-
Notifications
You must be signed in to change notification settings - Fork 12
/
TargetPlatformPluginTagger.java
executable file
·65 lines (51 loc) · 2.58 KB
/
TargetPlatformPluginTagger.java
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
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.List;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
import static java.util.stream.Collectors.toList;
public class TargetPlatformPluginTagger {
private static final Path PLUGINS_TARGET_PATH = Paths.get("target").toAbsolutePath();
private static final Path PLUGIN_FILE_LIST = Paths.get("plugins.txt").toAbsolutePath();
public static void main(String[] args) throws IOException {
createBundlesTarget();
copyJars(getPluginsPath(args));
}
private static void copyJars(List<Path> paths) throws IOException {
for (Path path : paths) {
Path targetPath = path.resolve("target").toAbsolutePath().normalize();
File targetFolder = targetPath.toFile();
for (File file : targetFolder.listFiles()) {
if (file.isFile() && file.getName().endsWith("SNAPSHOT.jar")) {
JarInputStream jarStream = new JarInputStream(new FileInputStream(file));
Manifest manifest = jarStream.getManifest();
String symbolicName = manifest.getMainAttributes().getValue("Bundle-SymbolicName");
String version = manifest.getMainAttributes().getValue("Bundle-Version");
String jarName = String.format("%s-%s.jar", symbolicName, version);
Path newJar = file.toPath().getParent().resolve(jarName).toAbsolutePath();
Path newJarInTarget = PLUGINS_TARGET_PATH.resolve(jarName).toAbsolutePath();
Files.copy(file.toPath(), newJar, StandardCopyOption.REPLACE_EXISTING);
Files.copy(file.toPath(), newJarInTarget, StandardCopyOption.REPLACE_EXISTING);
System.out.printf("Output plugin: %s\n", newJarInTarget);
}
}
}
}
private static void createBundlesTarget() {
PLUGINS_TARGET_PATH.toFile().mkdirs();
}
private static List<Path> getPluginsPath(String[] args) throws IOException {
List<String> stringPaths = Arrays.asList(args);
if (stringPaths.isEmpty() && PLUGIN_FILE_LIST.toFile().exists()) {
stringPaths = Files.readAllLines(PLUGIN_FILE_LIST, StandardCharsets.UTF_8);
}
return stringPaths.stream().map(s -> Paths.get(s).toAbsolutePath()).collect(toList());
}
}