Skip to content

Commit

Permalink
main cli done; add todo's; fix getOutArtifact
Browse files Browse the repository at this point in the history
  • Loading branch information
clagomess committed Mar 7, 2024
1 parent 89df440 commit 159c583
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 115 deletions.
90 changes: 37 additions & 53 deletions cli/src/main/java/com/github/clagomess/pirilampo/cli/Main.java
Original file line number Diff line number Diff line change
@@ -1,72 +1,56 @@
package com.github.clagomess.pirilampo.cli;

import com.github.clagomess.pirilampo.core.compilers.FeatureToHTMLCompiler;
import com.github.clagomess.pirilampo.core.compilers.FeatureToPDFCompiler;
import com.github.clagomess.pirilampo.core.compilers.FolderToHTMLCompiler;
import com.github.clagomess.pirilampo.core.compilers.FolderToPDFCompiler;
import com.github.clagomess.pirilampo.core.dto.ParametersDto;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

import static com.github.clagomess.pirilampo.core.enums.CompilationArtifactEnum.HTML;
import static com.github.clagomess.pirilampo.core.enums.CompilationArtifactEnum.PDF;
import static com.github.clagomess.pirilampo.core.enums.CompilationTypeEnum.*;

@Slf4j
public class Main {
/*
public static void main(String[] args) throws Exception {
Main main = new Main();
log.info("Pirilampo - Ver.: {}", main.getVersion());
private static final MainOptions mainOptions = new MainOptions();

if(args.length > 0){
CommandLine cmd = consoleOptions(args);
Compilador compilador = new Compilador();
public static void main(String[] args) {
log.info("Pirilampo - Ver.: {}", Main.class.getPackage().getImplementationVersion());

if(cmd.getOptionValue("feature") == null && cmd.getOptionValue("feature_path") == null){
log.warn("É necessário informar {feature} ou {feature_path}");
System.exit(1);
}
try {
ParametersDto parameters = mainOptions.getArgs(args);

if(cmd.getOptionValue("feature") != null){
compilador.compilarFeature(new Parametro(cmd));
System.exit(0);
if (parameters.getCompilationType() == FEATURE &&
parameters.getCompilationArtifact() == HTML
) {
new FeatureToHTMLCompiler(parameters).build();
}

if(cmd.getOptionValue("feature_path") != null){
compilador.compilarPasta(new Parametro(cmd));
System.exit(0);
if (parameters.getCompilationType() == FEATURE &&
parameters.getCompilationArtifact() == PDF
) {
new FeatureToPDFCompiler(parameters).build();
}
}else{
MainUi.launch(MainUi.class);
}
}
private static CommandLine consoleOptions(String[] args){
Options options = new Options();
Option option;
options.addOption(new Option("feature", true, "Arquivo *.feature"));
options.addOption(new Option("feature_path", true, "Diretório contendo arquivos *.feature"));
options.addOption(new Option("feature_path_master", true, "Diretório contendo arquivos *.feature master"));
options.addOption(new Option("output", true, "Diretório de saída"));

option = new Option("name", true, "Nome do projeto");
option.setRequired(true);
options.addOption(option);
option = new Option("version", true, "Versão");
option.setRequired(true);
options.addOption(option);
CommandLineParser parser = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
CommandLine cmd = null;
if (Arrays.asList(FOLDER, FOLDER_DIFF).contains(parameters.getCompilationType()) &&
parameters.getCompilationArtifact() == HTML
) {
new FolderToHTMLCompiler(parameters).build();
}

try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
log.info(e.getMessage());
formatter.printHelp("Pirilampo", options);
if (parameters.getCompilationType() == FOLDER &&
parameters.getCompilationArtifact() == PDF
) {
new FolderToPDFCompiler(parameters).build();
}

System.exit(0);
} catch (Throwable e) {
log.error(log.getName(), e);
System.exit(1);
}
return cmd;
}
private synchronized String getVersion(){
return getClass().getPackage().getImplementationVersion();
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,11 @@ public ParametersDto getArgs(String[] argv){
parameters.validate();

return parameters;
} catch (ParseException | ParametersException e ) {
} catch (ParseException | ParametersException e) {
log.error(e.getMessage());
new HelpFormatter().printHelp("Pirilampo", options);
} catch (Throwable e) {
log.error(log.getName(), e);
} finally {
new HelpFormatter().printHelp("Pirilampo", options);
}

System.exit(1);
Expand Down
91 changes: 37 additions & 54 deletions cli/src/test/java/com/github/clagomess/pirilampo/cli/MainTest.java
Original file line number Diff line number Diff line change
@@ -1,69 +1,52 @@
package com.github.clagomess.pirilampo.cli;

import com.github.clagomess.pirilampo.cli.Main;
import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import java.io.File;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

@Slf4j
public class MainTest {
/*
@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();
private File criarPasta(){
String dir = System.getProperty("java.io.tmpdir");
dir += File.separator;
dir += "pirilampo_test";
File f = new File(dir);
if (f.isDirectory() || f.mkdir()) {
dir += File.separator;
dir += (new Long(Calendar.getInstance().getTime().getTime())).toString();
f = new File(dir);
if(f.mkdir()){
pastas.add(f);
}
@Test
@ExpectSystemExitWithStatus(1)
public void main_options_validate(){
Main.main(new String[]{"-projectSource", "aaa"});
}

log.info("Pasta de teste: {}", f.getAbsolutePath());
@ParameterizedTest
@CsvSource(value = {
"FEATURE,HTML,feature/xxx.Feature,",
"FEATURE,PDF,feature/xxx.Feature,",
"FOLDER,HTML,feature,",
"FOLDER_DIFF,HTML,feature,master",
"FOLDER,PDF,feature,",
})
@ExpectSystemExitWithStatus(0)
public void main_ok(
String compilationType,
String compilationArtifact,
String projectSource,
String projectMasterSource
){
List<String> argv = new LinkedList<>();
argv.add("-projectSource");
argv.add(getClass().getResource(projectSource).getFile());

if(projectMasterSource != null) {
argv.add("-projectMasterSource");
argv.add(getClass().getResource(projectMasterSource).getFile());
}

return f;
}
@Test
public void testMain() throws Exception {
exit.expectSystemExit();
argv.add("-compilationType");
argv.add(compilationType);

String outDir = criarPasta().getAbsolutePath();
Main.main(new String[]{
"-feature_path",
resourcePath + File.separator + "feature",
"-name",
"XXX",
"-version",
"1.2.3",
"-output",
outDir,
});
Assert.assertTrue((new File(outDir + File.separator + "index.html")).isFile());
argv.add("-compilationArtifact");
argv.add(compilationArtifact);

outDir = criarPasta().getAbsolutePath();
Main.main(new String[]{
"-feature",
resourcePath + File.separator + "feature/xxx.Feature",
"-name",
"XXX",
"-version",
"1.2.3",
"-output",
criarPasta().getAbsolutePath(),
});
Assert.assertTrue((new File(outDir + File.separator + "xxx.html")).isFile());
Main.main(argv.toArray(new String[0]));
}
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<strong>html_embed_txt</strong>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# language: pt
# encoding: utf-8
Funcionalidade: XX

XXX

Contexto: XXX

Dado XXX
E Teste
| Ibagem |
| ![Image](xxx.png) |
| <img src="xxx.png"> |
| <img src="xxx.png" width="50"> |
| ![Image](https://pt.wikipedia.org/static/images/project-logos/ptwiki.png) |
| Link Html Embeded: [Link Embeded](html_embed.html) |
| Link Google: [Google](https://www.google.com.br) |
| <strike>strike</strike> |
| <strike>strike<br>strike</strike> |


Esquema do Cenário: JJJ
Quando xxx
E YYY
Exemplos:
| a | b |
| c | d |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# language: pt
# encoding: utf-8
Funcionalidade: XX

XXX

Contexto: XXX
- YYY_MASTER_YYY

Dado XXX
E Teste
| Ibagem |
| ![Image](xxx.png) |
| <img src="xxx.png"> |
| <img src="xxx.png" width="50"> |
| ![Image](https://pt.wikipedia.org/static/images/project-logos/ptwiki.png) |
| Link Html Embeded: [Link Embeded](html_embed.html) |
| Link Google: [Google](https://www.google.com.br) |
| <strike>strike</strike> |
| <strike>strike<br>strike</strike> |


Esquema do Cenário: JJJ
Quando xxx
E YYY
Exemplos:
| a | b |
| c | d |
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.github.clagomess.pirilampo.core.dto.FeatureMetadataDto;
import com.github.clagomess.pirilampo.core.dto.ParametersDto;
import com.github.clagomess.pirilampo.core.enums.CompilationArtifactEnum;
import com.github.clagomess.pirilampo.core.enums.CompilationTypeEnum;
import org.apache.commons.io.input.BOMInputStream;

import java.io.*;
Expand All @@ -13,6 +11,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.github.clagomess.pirilampo.core.enums.CompilationArtifactEnum.HTML;
import static com.github.clagomess.pirilampo.core.enums.CompilationTypeEnum.FOLDER;
import static com.github.clagomess.pirilampo.core.enums.CompilationTypeEnum.FOLDER_DIFF;

public abstract class Compiler {
public String getFeatureExtension(File f){
Matcher matcher = Pattern.compile("\\.feature$", Pattern.CASE_INSENSITIVE)
Expand Down Expand Up @@ -64,7 +66,7 @@ protected FeatureMetadataDto getFeatureMetadata(ParametersDto parameters, File f
}

protected File getOutArtifact(ParametersDto parameters){
if(parameters.getCompilationType() == CompilationTypeEnum.FOLDER){
if(Arrays.asList(FOLDER, FOLDER_DIFF).contains(parameters.getCompilationType())){
File targetDir = parameters.getProjectTarget() != null ?
new File(parameters.getProjectTarget(), "html") :
new File(parameters.getProjectSource().getParent(), "html");
Expand All @@ -73,12 +75,12 @@ protected File getOutArtifact(ParametersDto parameters){
throw new RuntimeException(String.format("Failed to create dir: %s", targetDir.getAbsolutePath()));
}

return new File(targetDir, parameters.getCompilationArtifact() == CompilationArtifactEnum.HTML ? "index.html" : "index.pdf");
return new File(targetDir, parameters.getCompilationArtifact() == HTML ? "index.html" : "index.pdf");
}else{
String filename = String.format(
"%s.%s",
getFeatureMetadata(parameters, parameters.getProjectSource()).getName(),
parameters.getCompilationArtifact() == CompilationArtifactEnum.HTML ? "html" : "pdf"
parameters.getCompilationArtifact() == HTML ? "html" : "pdf"
);

File targetDir = parameters.getProjectTarget() != null ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ public void build() throws Exception {

out.print("</div></div></div></body></html>");
}

// @TODO: add done and took
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ public void build() throws Exception {
}

// @TODO: remove buffer file
// @TODO: add done and took
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,7 @@ public void build() throws Exception {
out.print("</script>\n");
out.print("</body></html>");
}

// @TODO: add done and took
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ public void build() throws Exception {

// @TODO: remove buffer file
// @TODO: impl. PDF Index
// @TODO: add done and took
}
}

0 comments on commit 159c583

Please sign in to comment.