Search in sources :

Example 1 with ShipkitConfiguration

use of org.shipkit.gradle.configuration.ShipkitConfiguration in project shipkit by mockito.

the class ShipkitBintrayPlugin method apply.

public void apply(final Project project) {
    final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration();
    // TODO (maybe) since this plugin depends on bintray,
    // we need to either shade bintray plugin or ship this Gradle plugin in a separate jar
    // this way we avoid version conflicts and any bintray dependencies for users who don't use bintray
    project.getPlugins().apply("com.jfrog.bintray");
    // Configure some properties right away
    final BintrayExtension bintray = project.getExtensions().getByType(BintrayExtension.class);
    LOG.info("Configuring bintray plugin to publish automatically ({}.bintray.publish = true)", project.getPath());
    bintray.setPublish(true);
    final BintrayUploadTask bintrayUpload = (BintrayUploadTask) project.getTasks().getByName(BINTRAY_UPLOAD_TASK);
    bintrayUpload.doFirst(task -> {
        String welcomeMessage = uploadWelcomeMessage((BintrayUploadTask) task);
        LOG.lifecycle(welcomeMessage);
    });
    final BintrayExtension.PackageConfig pkg = bintray.getPkg();
    pkg.setPublicDownloadNumbers(true);
    pkg.getVersion().getGpg().setSign(true);
    // Defer configuration of other properties
    deferredConfiguration(project, () -> {
        // Below overwrites prior value in case the user configured dry run directly on the bintray extension.
        // It should be ok.
        bintray.setDryRun(conf.isDryRun());
        if (pkg.getDesc() == null) {
            pkg.setDesc(project.getDescription());
        }
        if (pkg.getName() == null) {
            pkg.setName(project.getGroup().toString());
        }
        if (pkg.getVersion().getVcsTag() == null) {
            pkg.getVersion().setVcsTag(conf.getGit().getTagPrefix() + project.getVersion());
        }
    });
    if (pkg.getWebsiteUrl() == null) {
        pkg.setWebsiteUrl(conf.getGitHub().getUrl() + "/" + conf.getGitHub().getRepository());
    }
    if (pkg.getIssueTrackerUrl() == null) {
        pkg.setIssueTrackerUrl(conf.getGitHub().getUrl() + "/" + conf.getGitHub().getRepository() + "/issues");
    }
    if (pkg.getVcsUrl() == null) {
        pkg.setVcsUrl(conf.getGitHub().getUrl() + "/" + conf.getGitHub().getRepository() + ".git");
    }
    LazyConfiguration.lazyConfiguration(bintrayUpload, () -> {
        String key = notNull(bintray.getKey(), "BINTRAY_API_KEY", "Missing 'bintray.key' value.\n" + "  Please configure Bintray extension or export 'BINTRAY_API_KEY' env variable.");
        bintray.setKey(key);
        // api key is set by Bintray plugin, based on 'bintray.key' value, before lazy configuration.
        // Hence we need to set it again here:
        bintrayUpload.setApiKey(key);
        // workaround for https://github.com/bintray/gradle-bintray-plugin/issues/170
        notNull(bintray.getUser(), "Missing 'bintray.user' value.\n" + "  Please configure Bintray extension.");
    });
}
Also used : ShipkitConfiguration(org.shipkit.gradle.configuration.ShipkitConfiguration) ShipkitConfigurationPlugin(org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin) BintrayUploadTask(com.jfrog.bintray.gradle.BintrayUploadTask) BintrayExtension(com.jfrog.bintray.gradle.BintrayExtension)

Example 2 with ShipkitConfiguration

use of org.shipkit.gradle.configuration.ShipkitConfiguration in project shipkit by mockito.

the class GitHubContributorsPlugin method apply.

public void apply(final Project project) {
    final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration();
    final FetchGitHubContributorsTask task = TaskMaker.task(project, FETCH_CONTRIBUTORS, FetchGitHubContributorsTask.class, new Action<FetchGitHubContributorsTask>() {

        @Override
        public void execute(final FetchGitHubContributorsTask task) {
            task.setDescription("Fetch info about all project contributors and store it in file");
            task.setOutputFile(contributorsFile(project));
            task.setEnabled(conf.getTeam().getContributors().isEmpty());
            task.setIgnoredContributors(conf.getTeam().getIgnoredContributors());
        }
    });
    task.setDescription("Fetch info about all project contributors from GitHub and store it in file");
    task.setApiUrl(conf.getGitHub().getApiUrl());
    task.setReadOnlyAuthToken(conf.getGitHub().getReadOnlyAuthToken());
    task.setRepository(conf.getGitHub().getRepository());
}
Also used : ShipkitConfiguration(org.shipkit.gradle.configuration.ShipkitConfiguration) ShipkitConfigurationPlugin(org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin) FetchGitHubContributorsTask(org.shipkit.gradle.notes.FetchGitHubContributorsTask)

Example 3 with ShipkitConfiguration

use of org.shipkit.gradle.configuration.ShipkitConfiguration in project shipkit by mockito.

the class ReleaseNeededPlugin method apply.

@Override
public void apply(Project project) {
    final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration();
    // Task that throws an exception when release is not needed is very useful for CI workflows
    // Travis CI job will stop executing further commands if assertReleaseNeeded fails.
    // See the example projects how we have set up the 'assertReleaseNeeded' task in CI pipeline.
    releaseNeededTask(project, ASSERT_RELEASE_NEEDED_TASK, conf).setExplosive(true).setDescription("Asserts that criteria for the release are met and throws exception if release is not needed.");
    // Below task is useful for testing. It will not throw an exception but will run the code that check is release is needed
    // and it will print the information to the console.
    releaseNeededTask(project, RELEASE_NEEDED, conf).setExplosive(false).setDescription("Checks and prints to the console if criteria for the release are met.");
}
Also used : ShipkitConfiguration(org.shipkit.gradle.configuration.ShipkitConfiguration) ShipkitConfigurationPlugin(org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin)

Example 4 with ShipkitConfiguration

use of org.shipkit.gradle.configuration.ShipkitConfiguration in project shipkit by mockito.

the class BintrayReleasePlugin method apply.

public void apply(final Project project) {
    project.getPlugins().apply(ReleasePlugin.class);
    final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration();
    final Task gitPush = project.getTasks().getByName(GitPlugin.GIT_PUSH_TASK);
    final Task performRelease = project.getTasks().getByName(ReleasePlugin.PERFORM_RELEASE_TASK);
    project.allprojects(subproject -> {
        subproject.getPlugins().withType(ShipkitBintrayPlugin.class, plugin -> {
            Task bintrayUpload = subproject.getTasks().getByName(ShipkitBintrayPlugin.BINTRAY_UPLOAD_TASK);
            performRelease.dependsOn(bintrayUpload);
            // bintray upload after git push so that when git push fails we don't publish jars to bintray
            // git push is easier to undo than deleting published jars (not possible with Central)
            bintrayUpload.mustRunAfter(gitPush);
            final BintrayExtension bintray = subproject.getExtensions().getByType(BintrayExtension.class);
            deferredConfiguration(subproject, () -> {
                UpdateReleaseNotesTask updateNotes = (UpdateReleaseNotesTask) project.getTasks().getByName(ReleaseNotesPlugin.UPDATE_NOTES_TASK);
                String userSpecifiedRepo = conf.getLenient().getReleaseNotes().getPublicationRepository();
                if (userSpecifiedRepo != null) {
                    updateNotes.setPublicationRepository(userSpecifiedRepo);
                } else {
                    updateNotes.setPublicationRepository(BintrayUtil.getRepoLink(bintray));
                }
            });
        });
        subproject.getPlugins().withType(JavaBintrayPlugin.class, plugin -> {
            // Making git push run as late as possible because it is an operation that is hard to reverse.
            // Git push will be executed after all tasks needed by bintrayUpload
            // but before bintrayUpload.
            // Using task path as String because the task comes from maven-publish new configuration model
            // and we cannot refer to it in a normal way, by task instance.
            String mavenLocalTask = subproject.getPath() + ":" + MAVEN_LOCAL_TASK;
            gitPush.mustRunAfter(mavenLocalTask);
        });
    });
}
Also used : Task(org.gradle.api.Task) UpdateReleaseNotesTask(org.shipkit.gradle.notes.UpdateReleaseNotesTask) ShipkitConfiguration(org.shipkit.gradle.configuration.ShipkitConfiguration) ShipkitConfigurationPlugin(org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin) UpdateReleaseNotesTask(org.shipkit.gradle.notes.UpdateReleaseNotesTask) BintrayExtension(com.jfrog.bintray.gradle.BintrayExtension)

Example 5 with ShipkitConfiguration

use of org.shipkit.gradle.configuration.ShipkitConfiguration in project shipkit by mockito.

the class UpgradeDependencyPlugin method apply.

@Override
public void apply(final Project project) {
    IncubatingWarning.warn("upgrade-dependency plugin");
    final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration();
    final GitOriginPlugin gitOriginPlugin = project.getRootProject().getPlugins().apply(GitOriginPlugin.class);
    project.getPlugins().apply(GitConfigPlugin.class);
    upgradeDependencyExtension = project.getExtensions().create("upgradeDependency", UpgradeDependencyExtension.class);
    // set defaults
    upgradeDependencyExtension.setBuildFile(project.file("build.gradle"));
    upgradeDependencyExtension.setBaseBranch("master");
    String dependency = (String) project.findProperty(DEPENDENCY_PROJECT_PROPERTY);
    new DependencyNewVersionParser(dependency).fillVersionUpgradeExtension(upgradeDependencyExtension);
    TaskMaker.task(project, CHECKOUT_BASE_BRANCH, GitCheckOutTask.class, new Action<GitCheckOutTask>() {

        @Override
        public void execute(final GitCheckOutTask task) {
            task.setDescription("Checks out the base branch.");
            deferredConfiguration(project, new Runnable() {

                @Override
                public void run() {
                    task.setRev(upgradeDependencyExtension.getBaseBranch());
                }
            });
        }
    });
    TaskMaker.task(project, PULL_UPSTREAM, GitPullTask.class, new Action<GitPullTask>() {

        @Override
        public void execute(final GitPullTask task) {
            task.setDescription("Performs git pull from upstream repository.");
            task.mustRunAfter(CHECKOUT_BASE_BRANCH);
            task.setDryRun(conf.isDryRun());
            deferredConfiguration(project, new Runnable() {

                @Override
                public void run() {
                    task.setRev(upgradeDependencyExtension.getBaseBranch());
                }
            });
            gitOriginPlugin.provideOriginRepo(task, new Action<String>() {

                public void execute(String originRepo) {
                    GitUrlInfo info = new GitUrlInfo(conf);
                    task.setUrl(info.getGitUrl());
                    task.setSecretValue(info.getWriteToken());
                }
            });
        }
    });
    final FindOpenPullRequestTask findOpenPullRequestTask = TaskMaker.task(project, FIND_OPEN_PULL_REQUEST, FindOpenPullRequestTask.class, new Action<FindOpenPullRequestTask>() {

        @Override
        public void execute(final FindOpenPullRequestTask task) {
            task.setDescription("Find an open pull request with version upgrade, if such exists.");
            task.mustRunAfter(PULL_UPSTREAM);
            task.setGitHubApiUrl(conf.getGitHub().getApiUrl());
            task.setAuthToken(conf.getLenient().getGitHub().getReadOnlyAuthToken());
            task.setUpstreamRepositoryName(conf.getGitHub().getRepository());
            task.setVersionBranchRegex(getVersionBranchName(upgradeDependencyExtension.getDependencyName(), ReplaceVersionTask.VERSION_REGEX));
        }
    });
    TaskMaker.task(project, CHECKOUT_VERSION_BRANCH, GitCheckOutTask.class, new Action<GitCheckOutTask>() {

        public void execute(final GitCheckOutTask task) {
            task.setDescription("Creates a new version branch and checks it out.");
            task.mustRunAfter(FIND_OPEN_PULL_REQUEST);
            findOpenPullRequestTask.provideOpenPullRequest(task, new Action<Optional<PullRequest>>() {

                @Override
                public void execute(Optional<PullRequest> pullRequest) {
                    if (pullRequest.isPresent()) {
                        // don't create a new branch if there is already a branch with open pull request with version upgrade
                        task.setNewBranch(false);
                    } else {
                        task.setNewBranch(true);
                    }
                    task.setRev(getCurrentVersionBranchName(upgradeDependencyExtension.getDependencyName(), upgradeDependencyExtension.getNewVersion(), pullRequest));
                }
            });
        }
    });
    final ReplaceVersionTask replaceVersionTask = TaskMaker.task(project, REPLACE_VERSION, ReplaceVersionTask.class, new Action<ReplaceVersionTask>() {

        @Override
        public void execute(final ReplaceVersionTask task) {
            task.setDescription("Replaces dependency version in build file.");
            task.mustRunAfter(CHECKOUT_VERSION_BRANCH);
            deferredConfiguration(project, new Runnable() {

                @Override
                public void run() {
                    task.setDependencyGroup(upgradeDependencyExtension.getDependencyGroup());
                    task.setNewVersion(upgradeDependencyExtension.getNewVersion());
                    task.setDependencyName(upgradeDependencyExtension.getDependencyName());
                    task.setBuildFile(upgradeDependencyExtension.getBuildFile());
                }
            });
        }
    });
    final ShipkitExecTask shipkitExecTask = TaskMaker.task(project, COMMIT_VERSION_UPGRADE, ShipkitExecTask.class, new Action<ShipkitExecTask>() {

        @Override
        public void execute(final ShipkitExecTask exec) {
            exec.setDescription("Commits updated build file.");
            exec.mustRunAfter(REPLACE_VERSION);
            exec.dependsOn(GitConfigPlugin.SET_EMAIL_TASK, GitConfigPlugin.SET_USER_TASK);
            deferredConfiguration(project, new Runnable() {

                @Override
                public void run() {
                    String message = String.format("%s version upgraded to %s", upgradeDependencyExtension.getDependencyName(), upgradeDependencyExtension.getNewVersion());
                    exec.execCommand(execCommand("Committing build file", "git", "commit", "--author", GitUtil.getGitGenericUserNotation(conf.getGit().getUser(), conf.getGit().getEmail()), "-m", message, upgradeDependencyExtension.getBuildFile().getAbsolutePath()));
                }
            });
            exec.onlyIf(wasBuildFileUpdatedSpec(replaceVersionTask));
        }
    });
    final GitPushTask gitPushTask = TaskMaker.task(project, PUSH_VERSION_UPGRADE, GitPushTask.class, new Action<GitPushTask>() {

        @Override
        public void execute(final GitPushTask task) {
            task.setDescription("Pushes updated config file to an update branch.");
            task.mustRunAfter(COMMIT_VERSION_UPGRADE);
            task.setDryRun(conf.isDryRun());
            gitOriginPlugin.provideOriginRepo(task, new Action<String>() {

                public void execute(String originRepo) {
                    GitUrlInfo info = new GitUrlInfo(conf);
                    task.setUrl(info.getGitUrl());
                    task.setSecretValue(info.getWriteToken());
                }
            });
            findOpenPullRequestTask.provideOpenPullRequest(task, new Action<Optional<PullRequest>>() {

                @Override
                public void execute(Optional<PullRequest> pullRequest) {
                    task.getTargets().add(getCurrentVersionBranchName(upgradeDependencyExtension.getDependencyName(), upgradeDependencyExtension.getNewVersion(), pullRequest));
                }
            });
            task.onlyIf(wasBuildFileUpdatedSpec(replaceVersionTask));
        }
    });
    final CreatePullRequestTask createPullRequestTask = TaskMaker.task(project, CREATE_PULL_REQUEST, CreatePullRequestTask.class, new Action<CreatePullRequestTask>() {

        @Override
        public void execute(final CreatePullRequestTask task) {
            task.setDescription("Creates a pull request from branch with version upgraded to master");
            task.mustRunAfter(PUSH_VERSION_UPGRADE);
            task.setGitHubApiUrl(conf.getGitHub().getApiUrl());
            task.setDryRun(conf.isDryRun());
            task.setAuthToken(conf.getLenient().getGitHub().getWriteAuthToken());
            task.setPullRequestTitle(getPullRequestTitle(upgradeDependencyExtension));
            task.setPullRequestDescription(getPullRequestDescription(upgradeDependencyExtension));
            task.setUpstreamRepositoryName(conf.getGitHub().getRepository());
            gitOriginPlugin.provideOriginRepo(task, new Action<String>() {

                @Override
                public void execute(String originRepoName) {
                    task.setForkRepositoryName(originRepoName);
                }
            });
            findOpenPullRequestTask.provideOpenPullRequest(task, new Action<Optional<PullRequest>>() {

                @Override
                public void execute(Optional<PullRequest> pullRequest) {
                    task.setVersionBranch(getCurrentVersionBranchName(upgradeDependencyExtension.getDependencyName(), upgradeDependencyExtension.getNewVersion(), pullRequest));
                }
            });
            deferredConfiguration(project, new Runnable() {

                @Override
                public void run() {
                    task.setBaseBranch(upgradeDependencyExtension.getBaseBranch());
                }
            });
            task.onlyIf(wasOpenPullRequestNotFound(findOpenPullRequestTask));
            task.onlyIf(wasBuildFileUpdatedSpec(replaceVersionTask));
        }
    });
    TaskMaker.task(project, MERGE_PULL_REQUEST, MergePullRequestTask.class, new Action<MergePullRequestTask>() {

        @Override
        public void execute(final MergePullRequestTask task) {
            task.setDescription("Merge pull request when all checks will be passed");
            task.mustRunAfter(CREATE_PULL_REQUEST);
            task.setGitHubApiUrl(conf.getGitHub().getApiUrl());
            task.setDryRun(conf.isDryRun());
            task.setAuthToken(conf.getLenient().getGitHub().getWriteAuthToken());
            task.setBaseBranch(upgradeDependencyExtension.getBaseBranch());
            task.setUpstreamRepositoryName(conf.getGitHub().getRepository());
            gitOriginPlugin.provideOriginRepo(task, new Action<String>() {

                @Override
                public void execute(String originRepoName) {
                    task.setForkRepositoryName(originRepoName);
                }
            });
            createPullRequestTask.provideCreatedPullRequest(task, new Action<PullRequest>() {

                @Override
                public void execute(PullRequest pullRequest) {
                    setPullRequestDataToTask(Optional.ofNullable(pullRequest), task);
                }
            });
            deferredConfiguration(project, new Runnable() {

                @Override
                public void run() {
                    task.setBaseBranch(upgradeDependencyExtension.getBaseBranch());
                }
            });
            task.onlyIf(wasOpenPullRequestNotFound(findOpenPullRequestTask));
            task.onlyIf(wasBuildFileUpdatedSpec(replaceVersionTask));
        }
    });
    TaskMaker.task(project, PERFORM_VERSION_UPGRADE, new Action<Task>() {

        @Override
        public void execute(Task task) {
            task.setDescription("Checkouts new version branch, updates Shipkit dependency in config file, commits and pushes.");
            task.dependsOn(CHECKOUT_BASE_BRANCH);
            task.dependsOn(FIND_OPEN_PULL_REQUEST);
            task.dependsOn(PULL_UPSTREAM);
            task.dependsOn(CHECKOUT_VERSION_BRANCH);
            task.dependsOn(REPLACE_VERSION);
            task.dependsOn(COMMIT_VERSION_UPGRADE);
            task.dependsOn(PUSH_VERSION_UPGRADE);
            task.dependsOn(CREATE_PULL_REQUEST);
            task.dependsOn(MERGE_PULL_REQUEST);
        }
    });
    addLazyDependencyValidation(dependency, createPullRequestTask, gitPushTask, findOpenPullRequestTask, replaceVersionTask, shipkitExecTask);
}
Also used : Action(org.gradle.api.Action) Task(org.gradle.api.Task) GitCheckOutTask(org.shipkit.internal.gradle.git.tasks.GitCheckOutTask) GitPushTask(org.shipkit.gradle.git.GitPushTask) ShipkitExecTask(org.shipkit.gradle.exec.ShipkitExecTask) GitPullTask(org.shipkit.internal.gradle.git.tasks.GitPullTask) ShipkitConfiguration(org.shipkit.gradle.configuration.ShipkitConfiguration) PullRequest(org.shipkit.internal.gradle.git.domain.PullRequest) GitPushTask(org.shipkit.gradle.git.GitPushTask) ShipkitConfigurationPlugin(org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin) Optional(java.util.Optional) GitUrlInfo(org.shipkit.internal.gradle.git.GitUrlInfo) ShipkitExecTask(org.shipkit.gradle.exec.ShipkitExecTask) GitOriginPlugin(org.shipkit.internal.gradle.git.GitOriginPlugin) GitPullTask(org.shipkit.internal.gradle.git.tasks.GitPullTask) GitCheckOutTask(org.shipkit.internal.gradle.git.tasks.GitCheckOutTask)

Aggregations

ShipkitConfiguration (org.shipkit.gradle.configuration.ShipkitConfiguration)15 ShipkitConfigurationPlugin (org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin)15 Task (org.gradle.api.Task)6 Action (org.gradle.api.Action)4 ShipkitExecTask (org.shipkit.gradle.exec.ShipkitExecTask)4 BintrayExtension (com.jfrog.bintray.gradle.BintrayExtension)2 File (java.io.File)2 Jar (org.gradle.api.tasks.bundling.Jar)2 GitPushTask (org.shipkit.gradle.git.GitPushTask)2 UpdateReleaseNotesTask (org.shipkit.gradle.notes.UpdateReleaseNotesTask)2 UploadGistsTask (org.shipkit.internal.gradle.release.tasks.UploadGistsTask)2 BintrayUploadTask (com.jfrog.bintray.gradle.BintrayUploadTask)1 Optional (java.util.Optional)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 PublicationContainer (org.gradle.api.publish.PublicationContainer)1 MavenPublication (org.gradle.api.publish.maven.MavenPublication)1 GitCommitTask (org.shipkit.gradle.git.GitCommitTask)1 IdentifyGitBranchTask (org.shipkit.gradle.git.IdentifyGitBranchTask)1 ComparePublicationsTask (org.shipkit.gradle.java.ComparePublicationsTask)1