Search in sources :

Example 1 with BumpVersionFileTask

use of org.shipkit.gradle.version.BumpVersionFileTask in project shipkit by mockito.

the class InitPlugin method apply.

@Override
public void apply(final Project project) {
    project.getPlugins().apply(VersioningPlugin.class);
    project.getPlugins().apply(ShipkitConfigurationPlugin.class);
    final GitOriginPlugin gitOriginPlugin = project.getRootProject().getPlugins().apply(GitOriginPlugin.class);
    TaskMaker.task(project, INIT_TRAVIS_TASK, InitTravisTask.class, new Action<InitTravisTask>() {

        public void execute(InitTravisTask t) {
            t.setDescription("Creates '.travis.yml' file if not already present.");
            t.setOutputFile(new File(project.getRootDir(), ".travis.yml"));
        }
    });
    final BumpVersionFileTask bump = (BumpVersionFileTask) project.getTasks().getByName(VersioningPlugin.BUMP_VERSION_FILE_TASK);
    TaskMaker.task(project, INIT_VERSIONING_TASK, InitVersioningTask.class, new Action<InitVersioningTask>() {

        @Override
        public void execute(InitVersioningTask t) {
            t.setDescription("Creates version.properties file if it doesn't exist");
            t.setVersionFile(bump.getVersionFile());
        }
    });
    TaskMaker.task(project, INIT_SHIPKIT_FILE_TASK, InitShipkitFileTask.class, new Action<InitShipkitFileTask>() {

        @Override
        public void execute(final InitShipkitFileTask t) {
            final File shipkitFile = ShipkitConfigurationPlugin.getShipkitFile(project);
            t.setDescription("Creates Shipkit configuration file unless it already exists");
            t.setShipkitFile(shipkitFile);
            gitOriginPlugin.provideOriginRepo(t, new Action<String>() {

                public void execute(String originRepo) {
                    t.setOriginRepoName(originRepo);
                }
            });
        }
    });
    TaskMaker.task(project, INIT_SHIPKIT_TASK, new Action<Task>() {

        public void execute(Task t) {
            t.setDescription("Initializes Shipkit");
            t.dependsOn(INIT_TRAVIS_TASK, INIT_VERSIONING_TASK, INIT_SHIPKIT_FILE_TASK);
            t.doLast(new Action<Task>() {

                @Override
                public void execute(Task task) {
                    LOG.lifecycle("  Initialization complete. Thank you for using Shipkit!\n" + "  Please review generated files before checking them in.\n" + "  Guide: https://github.com/mockito/shipkit/blob/master/docs/getting-started.md");
                }
            });
        }
    });
    // The user might configure the 'group' later, after the plugin is applied
    DeferredConfiguration.deferredConfiguration(project, new Runnable() {

        @Override
        public void run() {
            if (project.getGroup() == null) {
                LOG.info("  Gradle project does not have 'group' property configured yet." + "\n  Shipkit is setting the group to 'org.shipkit.bootstrap' so that it has a reasonable default." + "\n  It is recommended that you configure the 'group' to your choice.");
                project.setGroup("org.shipkit.bootstrap");
            }
        }
    });
}
Also used : Action(org.gradle.api.Action) InitTravisTask(org.shipkit.gradle.init.InitTravisTask) Task(org.gradle.api.Task) InitVersioningTask(org.shipkit.gradle.init.InitVersioningTask) InitShipkitFileTask(org.shipkit.gradle.init.InitShipkitFileTask) BumpVersionFileTask(org.shipkit.gradle.version.BumpVersionFileTask) InitTravisTask(org.shipkit.gradle.init.InitTravisTask) BumpVersionFileTask(org.shipkit.gradle.version.BumpVersionFileTask) GitOriginPlugin(org.shipkit.internal.gradle.git.GitOriginPlugin) InitShipkitFileTask(org.shipkit.gradle.init.InitShipkitFileTask) InitVersioningTask(org.shipkit.gradle.init.InitVersioningTask) File(java.io.File)

Example 2 with BumpVersionFileTask

use of org.shipkit.gradle.version.BumpVersionFileTask in project shipkit by mockito.

the class VersioningPlugin method apply.

public void apply(final Project project) {
    final File versionFile = project.file(VERSION_FILE_NAME);
    final VersionInfo versionInfo;
    if (versionFile.isFile()) {
        versionInfo = Version.versionInfo(versionFile);
        LOG.lifecycle("  Building version '{}' (value loaded from '{}' file).", versionInfo.getVersion(), versionFile.getName());
    } else {
        versionInfo = Version.defaultVersionInfo(versionFile, project.getVersion().toString());
        LOG.lifecycle("  Building version '{}'.", versionInfo.getVersion());
    }
    project.getExtensions().add(VersionInfo.class.getName(), versionInfo);
    final String version = versionInfo.getVersion();
    project.allprojects(new Action<Project>() {

        @Override
        public void execute(Project project) {
            project.setVersion(version);
        }
    });
    TaskMaker.task(project, BUMP_VERSION_FILE_TASK, BumpVersionFileTask.class, new Action<BumpVersionFileTask>() {

        public void execute(final BumpVersionFileTask t) {
            t.setDescription("Increments version number in " + versionFile.getName());
            t.setVersionFile(versionFile);
            String versionChangeMessage = formatVersionInformationInCommitMessage(version, versionInfo.getPreviousVersion());
            GitPlugin.registerChangesForCommitIfApplied(singletonList(versionFile), versionChangeMessage, t);
        }
    });
}
Also used : VersionInfo(org.shipkit.version.VersionInfo) Project(org.gradle.api.Project) BumpVersionFileTask(org.shipkit.gradle.version.BumpVersionFileTask) File(java.io.File)

Aggregations

File (java.io.File)2 BumpVersionFileTask (org.shipkit.gradle.version.BumpVersionFileTask)2 Action (org.gradle.api.Action)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1 InitShipkitFileTask (org.shipkit.gradle.init.InitShipkitFileTask)1 InitTravisTask (org.shipkit.gradle.init.InitTravisTask)1 InitVersioningTask (org.shipkit.gradle.init.InitVersioningTask)1 GitOriginPlugin (org.shipkit.internal.gradle.git.GitOriginPlugin)1 VersionInfo (org.shipkit.version.VersionInfo)1