Skip to content

Commit

Permalink
TkRefresh
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Apr 7, 2017
1 parent 0d20da4 commit 26a76b5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 34 deletions.
38 changes: 4 additions & 34 deletions src/main/java/io/jare/tk/TkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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"
)
),
Expand Down Expand Up @@ -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())
);
}

}
68 changes: 68 additions & 0 deletions src/main/java/io/jare/tk/TkRefresh.java
Original file line number Diff line number Diff line change
@@ -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())
)
);
}

}

0 comments on commit 26a76b5

Please sign in to comment.