Search in sources :

Example 6 with BuildUtil

use of com.thomasjensen.checkstyle.addons.build.BuildUtil in project checkstyle-addons by checkstyle-addons.

the class SiteTask method collect.

@SuppressWarnings("ResultOfMethodCallIgnored")
private void collect() throws IOException {
    final Project project = getProject();
    final BuildUtil buildUtil = new BuildUtil(project);
    final FileTree mdFiles = getMarkdownFiles().get();
    final File siteDir = getSiteDir().get();
    File includesVersionDir = new File(siteDir, "_includes/v" + project.getVersion());
    includesVersionDir.mkdirs();
    File versionChecksDir = new File(siteDir, "v" + project.getVersion() + "/checks");
    versionChecksDir.mkdirs();
    File latestChecksDir = new File(siteDir, "latest/checks");
    latestChecksDir.mkdirs();
    SortedMap<String, List<File>> rawDocs = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    for (final File f : mdFiles.getFiles()) {
        String cat = f.getAbsoluteFile().getParentFile().getName();
        List<File> catDocs = rawDocs.computeIfAbsent(cat, k -> new ArrayList<>());
        catDocs.add(f.getAbsoluteFile());
    }
    final DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZ");
    for (Map.Entry<String, List<File>> cat : rawDocs.entrySet()) {
        File mdDir = new File(includesVersionDir, cat.getKey());
        mdDir.mkdir();
        SortedSet<String> frontMatterFileSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        for (final File f : cat.getValue()) {
            Files.copy(f.toPath(), new File(mdDir, f.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
            frontMatterFileSet.add("v" + project.getVersion() + "/" + cat.getKey() + "/" + f.getName());
        }
        StringBuilder sb = new StringBuilder();
        sb.append("---\n");
        sb.append("layout: checks\n");
        // current version
        sb.append("check_version: v");
        sb.append(project.getVersion());
        sb.append("\n");
        // current check category
        sb.append("check_category: ");
        sb.append(cat.getKey());
        sb.append("\n");
        // list of all check categories, so Jekyll can construct navigation
        sb.append("check_categories:\n");
        for (String s : rawDocs.keySet()) {
            sb.append("  - ");
            sb.append(s);
            sb.append("\n");
        }
        // list of checks in this category
        sb.append("check_list:\n");
        for (String s : frontMatterFileSet) {
            sb.append("  - ");
            sb.append(s);
            sb.append("\n");
        }
        // timestamp of this file's generation, for sitemap.xml
        sb.append("last_modified_at: ");
        sb.append(sdf.format(buildUtil.getBuildConfig().getBuildTimestamp().get()));
        sb.append("\n");
        sb.append("---\n\n");
        final File catPage = new File(versionChecksDir, cat.getKey() + ".html");
        Files.write(catPage.toPath(), sb.toString().getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE);
        Files.copy(catPage.toPath(), new File(latestChecksDir, catPage.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
    }
}
Also used : BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil) TreeMap(java.util.TreeMap) Project(org.gradle.api.Project) TreeSet(java.util.TreeSet) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) FileTree(org.gradle.api.file.FileTree) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 7 with BuildUtil

use of com.thomasjensen.checkstyle.addons.build.BuildUtil in project checkstyle-addons by checkstyle-addons.

the class SiteTask method configureTask.

public void configureTask() {
    final Project project = getProject();
    final BuildUtil buildUtil = new BuildUtil(project);
    setDescription("Package documentation for publication on the website");
    setGroup(SITE_GROUP);
    final TaskContainer tasks = project.getTasks();
    for (final String predecTaskName : new String[] { "processResources", "siteCopyAllChecks", "siteCopyJavadoc", // 
    "siteCopyDownloadGuide" }) {
        dependsOn(tasks.named(predecTaskName));
    }
    markdownFiles = project.provider(() -> {
        SourceSet mainSourceSet = buildUtil.getSourceSet(SourceSet.MAIN_SOURCE_SET_NAME);
        return project.fileTree(mainSourceSet.getResources().getSrcDirs().iterator().next(), ft -> ft.include("**/*.md"));
    });
    siteDir = project.provider(() -> new File(project.getBuildDir(), "site"));
}
Also used : SortedSet(java.util.SortedSet) SimpleDateFormat(java.text.SimpleDateFormat) InputFiles(org.gradle.api.tasks.InputFiles) TreeSet(java.util.TreeSet) OutputDirectory(org.gradle.api.tasks.OutputDirectory) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) SourceSet(org.gradle.api.tasks.SourceSet) TaskAction(org.gradle.api.tasks.TaskAction) Provider(org.gradle.api.provider.Provider) FileTree(org.gradle.api.file.FileTree) Map(java.util.Map) DefaultTask(org.gradle.api.DefaultTask) DateFormat(java.text.DateFormat) Files(java.nio.file.Files) Project(org.gradle.api.Project) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) TreeMap(java.util.TreeMap) TaskContainer(org.gradle.api.tasks.TaskContainer) GradleException(org.gradle.api.GradleException) BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil) SortedMap(java.util.SortedMap) Project(org.gradle.api.Project) BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil) SourceSet(org.gradle.api.tasks.SourceSet) TaskContainer(org.gradle.api.tasks.TaskContainer) File(java.io.File)

Aggregations

BuildUtil (com.thomasjensen.checkstyle.addons.build.BuildUtil)7 SimpleDateFormat (java.text.SimpleDateFormat)3 ArrayList (java.util.ArrayList)3 Project (org.gradle.api.Project)3 BuildConfigExtension (com.thomasjensen.checkstyle.addons.build.BuildConfigExtension)2 File (java.io.File)2 IOException (java.io.IOException)2 DateFormat (java.text.DateFormat)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 GradleException (org.gradle.api.GradleException)2 FileTree (org.gradle.api.file.FileTree)2 TaskAction (org.gradle.api.tasks.TaskAction)2 ClasspathBuilder (com.thomasjensen.checkstyle.addons.build.ClasspathBuilder)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1