Search in sources :

Example 1 with RepoData

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);
    }
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) TypeToken(com.google.gson.reflect.TypeToken) ListProperty(org.gradle.api.provider.ListProperty) NamedDomainObjectContainer(org.gradle.api.NamedDomainObjectContainer) ArrayList(java.util.ArrayList) TaskAction(org.gradle.api.tasks.TaskAction) Gson(com.google.gson.Gson) DirectoryProperty(org.gradle.api.file.DirectoryProperty) DefaultTask(org.gradle.api.DefaultTask) RepoData(org.zaproxy.zap.internal.RepoData) Path(java.nio.file.Path) Console(org.gradle.api.tasks.Console) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) Action(org.gradle.api.Action) Files(java.nio.file.Files) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Project(org.gradle.api.Project) IOException(java.io.IOException) Reader(java.io.Reader) File(java.io.File) List(java.util.List) RegularFileProperty(org.gradle.api.file.RegularFileProperty) Os(org.apache.tools.ant.taskdefs.condition.Os) ObjectFactory(org.gradle.api.model.ObjectFactory) Type(java.lang.reflect.Type) Property(org.gradle.api.provider.Property) InputFile(org.gradle.api.tasks.InputFile) Nested(org.gradle.api.tasks.Nested) Git(org.eclipse.jgit.api.Git) Input(org.gradle.api.tasks.Input) Collections(java.util.Collections) InvalidUserDataException(org.gradle.api.InvalidUserDataException) Repository(org.eclipse.jgit.lib.Repository) Named(org.gradle.api.Named) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) ArrayList(java.util.ArrayList) List(java.util.List) RepoData(org.zaproxy.zap.internal.RepoData) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 File (java.io.File)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 Type (java.lang.reflect.Type)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Os (org.apache.tools.ant.taskdefs.condition.Os)1 Git (org.eclipse.jgit.api.Git)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 Repository (org.eclipse.jgit.lib.Repository)1 FileRepositoryBuilder (org.eclipse.jgit.storage.file.FileRepositoryBuilder)1 Action (org.gradle.api.Action)1 DefaultTask (org.gradle.api.DefaultTask)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1