use of org.zaproxy.zap.internal.RepoData in project zaproxy by zaproxy.
the class GradleBuildWithGitRepos method buildWeeklyAddOns.
@TaskAction
public void buildWeeklyAddOns() throws GitAPIException, IOException {
Path reposDir = repositoriesDirectory.get().getAsFile().toPath();
List<RepoData> reposData = readRepoData();
for (RepoData repoData : reposData) {
String cloneUrl = repoData.getCloneUrl();
String repoName = extractRepoName(cloneUrl);
Path repoDir = reposDir.resolve(repoName);
if (Files.notExists(repoDir)) {
if (!cloneRepositories.get()) {
getLogger().warn("The directory {} does not exist, the {} add-on(s) will not be built.", repoDir, repoName);
continue;
}
getProject().mkdir(reposDir);
// XXX Rely just on JGit once it supports depth arg:
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=475615
getProject().exec(spec -> {
spec.setWorkingDir(reposDir);
spec.setExecutable("git");
spec.setEnvironment(Collections.emptyMap());
List<String> execArgs = new ArrayList<>();
execArgs.add("clone");
if (quiet.get()) {
execArgs.add("-q");
}
String branch = repoData.getBranch();
if (branch != null && !branch.isEmpty()) {
execArgs.add("--branch");
execArgs.add(branch);
}
execArgs.add("--depth");
execArgs.add("1");
execArgs.add(cloneUrl);
execArgs.add(repoName);
spec.args(execArgs);
}).assertNormalExitValue();
getLogger().lifecycle("Cloned {} into {}", cloneUrl, repoDir);
} else if (updateRepositories.get()) {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(repoDir.resolve(".git").toFile()).build();
try (Git git = new Git(repository)) {
git.pull().call();
getLogger().lifecycle("Pulled from {} into {}", cloneUrl, repoDir);
}
}
List<String> projects = repoData.getProjects() == null || repoData.getProjects().isEmpty() ? Arrays.asList("") : repoData.getProjects();
if (clean.get()) {
// Execute clean separately to avoid Gradle issue:
// https://github.com/gradle/gradle/issues/2488
getLogger().lifecycle("Running clean task for {}", repoDir.getFileName());
runGradle(repoDir, Arrays.asList("clean"));
}
runTasks(repoDir, projects);
}
}
Aggregations