|
| 1 | +package net.itarray.automotion.internal; |
| 2 | + |
| 3 | +import com.webfirmframework.wffweb.tag.html.Body; |
| 4 | +import com.webfirmframework.wffweb.tag.html.Html; |
| 5 | +import com.webfirmframework.wffweb.tag.html.TitleTag; |
| 6 | +import com.webfirmframework.wffweb.tag.html.attribute.Href; |
| 7 | +import com.webfirmframework.wffweb.tag.html.attribute.global.Style; |
| 8 | +import com.webfirmframework.wffweb.tag.html.links.A; |
| 9 | +import com.webfirmframework.wffweb.tag.html.lists.Li; |
| 10 | +import com.webfirmframework.wffweb.tag.html.lists.Ol; |
| 11 | +import com.webfirmframework.wffweb.tag.html.metainfo.Head; |
| 12 | +import com.webfirmframework.wffweb.tag.htmlwff.NoTag; |
| 13 | +import org.apache.maven.plugin.AbstractMojo; |
| 14 | +import org.apache.maven.plugin.MojoExecutionException; |
| 15 | +import org.apache.maven.plugins.annotations.Mojo; |
| 16 | + |
| 17 | +import java.io.BufferedOutputStream; |
| 18 | +import java.io.File; |
| 19 | +import java.io.FileOutputStream; |
| 20 | +import java.io.IOException; |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.List; |
| 23 | + |
| 24 | +import static net.itarray.automotion.validation.Constants.TARGET_AUTOMOTION; |
| 25 | +import static net.itarray.automotion.validation.Constants.TARGET_AUTOMOTION_HTML; |
| 26 | + |
| 27 | +@Mojo(name = "automotion") |
| 28 | +public class FinalReportBuilder extends AbstractMojo { |
| 29 | + |
| 30 | + @Override |
| 31 | + public void execute() throws MojoExecutionException { |
| 32 | + File folder = new File(TARGET_AUTOMOTION_HTML); |
| 33 | + File[] listOfFiles = folder.listFiles(); |
| 34 | + List<String> files = new ArrayList<>(); |
| 35 | + if (listOfFiles != null) { |
| 36 | + for (File file : listOfFiles) { |
| 37 | + files.add(file.getName()); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + Html html = buildHtml(files); |
| 42 | + |
| 43 | + File report = new File(TARGET_AUTOMOTION + "index.html"); |
| 44 | + report.getParentFile().mkdirs(); |
| 45 | + try (FileOutputStream fos = new FileOutputStream(report); |
| 46 | + BufferedOutputStream bos = new BufferedOutputStream(fos);) { |
| 47 | + |
| 48 | + html.toOutputStream(bos); |
| 49 | + bos.flush(); |
| 50 | + } catch (IOException e) { |
| 51 | + e.printStackTrace(); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + private Html buildHtml(List<String> files) { |
| 56 | + return new Html(null, |
| 57 | + new Style("background-color: #fff")) {{ |
| 58 | + super.setPrependDocType(true); |
| 59 | + new Head(this) {{ |
| 60 | + new TitleTag(this) {{ |
| 61 | + new NoTag(this, "Automotion report"); |
| 62 | + }}; |
| 63 | + new NoTag(this, "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"); |
| 64 | + new NoTag(this, "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">"); |
| 65 | + |
| 66 | + new NoTag(this, "<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js\"></script>"); |
| 67 | + new NoTag(this, "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" integrity=\"sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u\" crossorigin=\"anonymous\">"); |
| 68 | + new NoTag(this, "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css\" integrity=\"sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp\" crossorigin=\"anonymous\">"); |
| 69 | + new NoTag(this, "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\" integrity=\"sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa\" crossorigin=\"anonymous\"></script>"); |
| 70 | + }}; |
| 71 | + |
| 72 | + new Body(this) {{ |
| 73 | + new Ol(this) {{ |
| 74 | + for (String s: files) { |
| 75 | + |
| 76 | + new Li(this) {{ |
| 77 | + |
| 78 | + new A(this, |
| 79 | + new Href("html/" + s)) {{ |
| 80 | + new NoTag(this, s); |
| 81 | + }}; |
| 82 | + }}; |
| 83 | + } |
| 84 | + }}; |
| 85 | + }}; |
| 86 | + }}; |
| 87 | + } |
| 88 | +} |
0 commit comments