diff --git a/src/main/java/io/jare/tk/TkApp.java b/src/main/java/io/jare/tk/TkApp.java index d959758..91b3a6e 100644 --- a/src/main/java/io/jare/tk/TkApp.java +++ b/src/main/java/io/jare/tk/TkApp.java @@ -22,10 +22,8 @@ */ package io.jare.tk; -import com.jcabi.log.VerboseProcess; import com.jcabi.manifests.Manifests; import io.jare.model.Base; -import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -34,8 +32,6 @@ import org.takes.facets.fallback.TkFallback; import org.takes.facets.flash.TkFlash; import org.takes.facets.fork.FkAuthenticated; -import org.takes.facets.fork.FkFixed; -import org.takes.facets.fork.FkHitRefresh; import org.takes.facets.fork.FkHost; import org.takes.facets.fork.FkRegex; import org.takes.facets.fork.TkFork; @@ -45,8 +41,6 @@ import org.takes.rs.RsWithBody; import org.takes.rs.RsWithStatus; import org.takes.rs.RsWithType; -import org.takes.tk.TkClasspath; -import org.takes.tk.TkFiles; import org.takes.tk.TkGzip; import org.takes.tk.TkMeasured; import org.takes.tk.TkVersioned; @@ -129,28 +123,28 @@ private static Take make(final Base base) throws IOException { new FkRegex( "/xsl/[a-z\\-]+\\.xsl", new TkWithType( - TkApp.refresh("./src/main/xsl"), + new TkRefresh("./src/main/xsl"), "text/xsl" ) ), new FkRegex( "/css/[a-z]+\\.css", new TkWithType( - TkApp.refresh("./src/main/scss"), + new TkRefresh("./src/main/scss"), "text/css" ) ), new FkRegex( "/images/[a-z]+\\.svg", new TkWithType( - TkApp.refresh("./src/main/resources"), + new TkRefresh("./src/main/resources"), "image/svg+xml" ) ), new FkRegex( "/images/[a-z]+\\.png", new TkWithType( - TkApp.refresh("./src/main/resources"), + new TkRefresh("./src/main/resources"), "image/png" ) ), @@ -187,28 +181,4 @@ private static Take make(final Base base) throws IOException { ); } - /** - * Hit refresh fork. - * @param path Path of files - * @return Fork - * @throws IOException If fails - */ - private static Take refresh(final String path) throws IOException { - return new TkFork( - new FkHitRefresh( - new File(path), - () -> { - new VerboseProcess( - new ProcessBuilder( - "mvn", - "generate-resources" - ) - ).stdout(); - }, - new TkFiles("./target/classes") - ), - new FkFixed(new TkClasspath()) - ); - } - } diff --git a/src/main/java/io/jare/tk/TkRefresh.java b/src/main/java/io/jare/tk/TkRefresh.java new file mode 100644 index 0000000..51d3d43 --- /dev/null +++ b/src/main/java/io/jare/tk/TkRefresh.java @@ -0,0 +1,68 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2016 jare.io + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: the above copyright notice and this + * permission notice shall be included in all copies or substantial + * portions of the Software. The software is provided "as is", without + * warranty of any kind, express or implied, including but not limited to + * the warranties of merchantability, fitness for a particular purpose + * and non-infringement. In no event shall the authors or copyright + * holders be liable for any claim, damages or other liability, whether + * in an action of contract, tort or otherwise, arising from, out of or + * in connection with the software or the use or other dealings in the + * software. + */ +package io.jare.tk; + +import com.jcabi.log.VerboseProcess; +import java.io.File; +import java.io.IOException; +import org.takes.facets.fork.FkFixed; +import org.takes.facets.fork.FkHitRefresh; +import org.takes.facets.fork.TkFork; +import org.takes.tk.TkClasspath; +import org.takes.tk.TkFiles; +import org.takes.tk.TkWrap; + +/** + * Refresh on hit. + * + * @author Yegor Bugayenko (yegor@teamed.io) + * @version $Id$ + * @since 1.0 + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) + */ +final class TkRefresh extends TkWrap { + + /** + * Ctor. + * @param path Path of files + * @throws IOException If fails + */ + TkRefresh(final String path) throws IOException { + super( + new TkFork( + new FkHitRefresh( + new File(path), + () -> new VerboseProcess( + new ProcessBuilder( + "mvn", + "generate-resources" + ) + ).stdout(), + new TkFiles("./target/classes") + ), + new FkFixed(new TkClasspath()) + ) + ); + } + +}