2017-02-08 13:35:32 +00:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by st on 06.02.17.
|
|
|
|
*/
|
|
|
|
public class CopyDependencies {
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
String version = args[2];
|
|
|
|
Path targetRoot = new File(args[1]).toPath().resolve(version);
|
2023-02-28 11:16:43 +00:00
|
|
|
Path projectDir = targetRoot.getParent().getParent().getParent().getParent();
|
|
|
|
Path mavenRepository = new File(args[0]).toPath().resolve("org").resolve("keycloak");
|
|
|
|
|
|
|
|
CopyDependencies dependencies = new CopyDependencies(version, projectDir, targetRoot, mavenRepository);
|
|
|
|
dependencies.copyFiles();
|
|
|
|
}
|
2017-02-08 13:35:32 +00:00
|
|
|
|
2023-02-28 11:16:43 +00:00
|
|
|
private final String version;
|
|
|
|
private final Path targetDir;
|
|
|
|
private final Path projectDir;
|
|
|
|
private final Path mavenRepository;
|
|
|
|
|
|
|
|
public CopyDependencies(String version, Path projectDir, Path targetDir, Path mavenRepository) {
|
|
|
|
this.version = version;
|
|
|
|
this.targetDir = targetDir;
|
|
|
|
this.projectDir = projectDir;
|
|
|
|
this.mavenRepository = mavenRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void copyFiles() throws IOException {
|
2017-02-08 13:35:32 +00:00
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(CopyDependencies.class.getResourceAsStream("files")));
|
2023-02-28 11:16:43 +00:00
|
|
|
targetDir.toFile().mkdirs();
|
2017-02-08 13:35:32 +00:00
|
|
|
|
|
|
|
for (String l = br.readLine(); l != null; l = br.readLine()) {
|
2023-02-28 11:16:43 +00:00
|
|
|
if (l.trim().length() > 0) {
|
|
|
|
l = replaceVariables(l);
|
2017-02-08 13:35:32 +00:00
|
|
|
|
|
|
|
String[] t = l.trim().split(":");
|
|
|
|
|
2023-02-28 11:16:43 +00:00
|
|
|
String type = t[0];
|
|
|
|
String artifactName = t[1];
|
|
|
|
String destinationName = t.length == 2 ? artifactName : t[2];
|
2017-02-08 13:35:32 +00:00
|
|
|
|
2023-02-28 11:16:43 +00:00
|
|
|
switch (type) {
|
|
|
|
case "mvn":
|
|
|
|
copyMaven(artifactName, destinationName);
|
|
|
|
break;
|
|
|
|
case "npm":
|
|
|
|
copyNpm(artifactName, destinationName);
|
|
|
|
break;
|
2017-02-08 13:35:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
br.close();
|
|
|
|
}
|
|
|
|
|
2023-02-28 11:16:43 +00:00
|
|
|
private void copyMaven(String artifactName, String destinationName) throws IOException {
|
|
|
|
File artifactDir = mavenRepository.resolve(artifactName).resolve(version).toFile();
|
2023-03-01 07:57:20 +00:00
|
|
|
if (!artifactDir.isDirectory()) {
|
|
|
|
throw new RuntimeException(artifactName + " (" + artifactDir + ") not found");
|
|
|
|
}
|
2023-02-28 11:16:43 +00:00
|
|
|
|
|
|
|
File[] files = artifactDir.listFiles((file, name) -> name.contains(".tar.gz") || name.contains(".tgz") || name.contains(".zip"));
|
|
|
|
|
|
|
|
for (File f : files) {
|
|
|
|
Files.copy(f.toPath(), targetDir.resolve(f.getName().replace(artifactName, destinationName)), StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void copyNpm(String artifactName, String destinationName) throws IOException {
|
2023-03-01 07:57:20 +00:00
|
|
|
Path artifactPath = projectDir.resolve(artifactName);
|
|
|
|
if (!artifactPath.toFile().isFile()) {
|
|
|
|
throw new RuntimeException(artifactName + " (" + artifactPath + ") not found");
|
|
|
|
}
|
|
|
|
|
2023-02-28 11:16:43 +00:00
|
|
|
Files.copy(projectDir.resolve(artifactName), targetDir.resolve(destinationName));
|
|
|
|
}
|
|
|
|
|
|
|
|
private String replaceVariables(String input) {
|
2023-03-03 10:11:44 +00:00
|
|
|
return input.replaceAll("\\$\\$VERSION\\$\\$", version);
|
2023-02-28 11:16:43 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 13:35:32 +00:00
|
|
|
}
|