AsciiDocImgForwarder.groovy revision f5e34776
1/*
2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package io.fd.honeycomb.common.scripts
18
19import java.nio.file.Files
20import java.nio.file.Paths
21
22class AsciiDocImgForwarder {
23
24    static final def ADOC_FOLDER = "asciidoc"
25    static final def SITE_FOLDER = "site"
26    static final def PNG_EXTENSION = "png";
27
28    /**
29     * Copies generated images to site folder
30     * */
31    public static void copyGeneratedImages(project, properties, log){
32
33        def sourcePath = Paths.get(project.basedir.toString(), ADOC_FOLDER)
34        def destinationPathString = Paths.get(project.build.directory.toString(), SITE_FOLDER).toString()
35
36        log.info "Copying generated asciidoc images from ${sourcePath} to ${destinationPathString}"
37        Files.walk(sourcePath)
38                .filter({ path -> path.toString().endsWith(PNG_EXTENSION) })
39                .forEach({ sourceFilePath ->
40                    def targetFilePath = Paths.get(destinationPathString, sourceFilePath.getFileName().toString())
41                    log.info "Copying ${sourceFilePath} to ${targetFilePath}"
42                    Files.copy(sourceFilePath, targetFilePath) })
43    }
44}
45