Skip to content

Commit

Permalink
move resources
Browse files Browse the repository at this point in the history
  • Loading branch information
clagomess committed Mar 12, 2024
1 parent b54b13b commit 6c1020d
Show file tree
Hide file tree
Showing 37 changed files with 49 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected File getOutArtifact(ParametersDto parameters){
}

protected void writeResourceToOut(String resource, PrintWriter out) throws IOException {
URL url = Thread.currentThread().getContextClassLoader().getResource(resource);
URL url = getClass().getResource(resource);
if(url == null){
throw new FileNotFoundException(String.format(
"Resource %s not loaded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void build() throws Exception {
out.print("<meta name=\"viewport\" content=\"width=device-width, shrink-to-fit=no, initial-scale=1\">");
out.print(String.format("<title>%s</title>", parameters.getProjectName()));
out.print("<style>");
writeResourceToOut("htmlTemplate/dist/feature.min.css", out);
writeResourceToOut("../dist/feature.min.css", out);
out.print("</style>");
out.print("</head><body>");
out.print("<div class=\"container\"><div class=\"row\"><div class=\"col-sm-12\">");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public void build() throws Exception {

try (
FileOutputStream fosPDF = new FileOutputStream(outArtifact);
InputStream css = Objects.requireNonNull(Thread.currentThread().getContextClassLoader()
.getResource("htmlTemplate/dist/feature-pdf.min.css"))
InputStream css = Objects.requireNonNull(getClass()
.getResource("../dist/feature-pdf.min.css"))
.openStream();
){
parameters.setEmbedImages(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void build() throws Exception {
out.print("<meta name=\"viewport\" content=\"width=device-width, shrink-to-fit=no, initial-scale=1\">");
out.print(String.format("<title>%s</title>", parameters.getProjectName()));
out.print("<style>");
writeResourceToOut("htmlTemplate/dist/feature-pasta.min.css", out);
writeResourceToOut("../dist/feature-pasta.min.css", out);
out.print("\n\n");
out.print(String.format(
"#sidebar-wrapper {background: %s;}",
Expand All @@ -188,7 +188,7 @@ public void build() throws Exception {
out.print("</head><body>\n");
out.print("<div id=\"wrapper\">");
buildSidebar(out);
writeResourceToOut("htmlTemplate/html/template-feature-pasta-content-wrapper.html", out);
writeResourceToOut("../html/template-feature-pasta-content-wrapper.html", out);
out.print("</div>");

for(File f : arquivos){
Expand Down Expand Up @@ -225,13 +225,13 @@ public void build() throws Exception {
}

buildTemplateIndex(out);
writeResourceToOut("htmlTemplate/html/template-feature-pasta-footer.html", out);
writeResourceToOut("../html/template-feature-pasta-footer.html", out);

out.print("<script type=\"text/javascript\">\n");
indexParser.buildIndex(out);
buildMenu(out);
writeResourceToOut("htmlTemplate/dist/feature-pasta.min.js", out);
writeResourceToOut("htmlTemplate/dist/feature-pasta-angular.min.js", out);
writeResourceToOut("../dist/feature-pasta.min.js", out);
writeResourceToOut("../dist/feature-pasta-angular.min.js", out);
out.print("</script>\n");
out.print("</body></html>");
} catch (Throwable e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public void build() throws Exception {

try (
FileOutputStream fosPDF = new FileOutputStream(outArtifact);
InputStream css = Objects.requireNonNull(Thread.currentThread().getContextClassLoader()
.getResource("htmlTemplate/dist/feature-pdf.min.css"))
InputStream css = Objects.requireNonNull(getClass()
.getResource("../dist/feature-pdf.min.css"))
.openStream();
){
parameters.setEmbedImages(false);
Expand Down
25 changes: 10 additions & 15 deletions core/src/test/java/com/github/clagomess/pirilampo/core/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@
import java.util.Objects;

public abstract class Common {
protected final File featureFolder = new File(Objects.requireNonNull(Thread.currentThread()
.getContextClassLoader()
.getResource("feature")).getFile());
protected final File featureFolder = new File(Objects.requireNonNull(getClass()
.getResource("../feature")).getFile());

protected final File featureMasterFolder = new File(Objects.requireNonNull(Thread.currentThread()
.getContextClassLoader()
.getResource("master")).getFile());
protected final File featureMasterFolder = new File(Objects.requireNonNull(getClass()
.getResource("../master")).getFile());

protected final File featureFile = new File(Objects.requireNonNull(Thread.currentThread()
.getContextClassLoader()
.getResource("feature/xxx.Feature")).getFile());
protected final File featureFile = new File(Objects.requireNonNull(getClass()
.getResource("../feature/xxx.Feature")).getFile());

protected final File featureErrorFolder = new File(Objects.requireNonNull(Thread.currentThread()
.getContextClassLoader()
.getResource("feature_error")).getFile());
protected final File featureErrorFolder = new File(Objects.requireNonNull(getClass()
.getResource("../feature_error")).getFile());

protected final File featureErrorFile = new File(Objects.requireNonNull(Thread.currentThread()
.getContextClassLoader()
.getResource("feature_error/yyy.feature")).getFile());
protected final File featureErrorFile = new File(Objects.requireNonNull(getClass()
.getResource("../feature_error/yyy.feature")).getFile());
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.jupiter.params.provider.CsvSource;

import java.io.*;
import java.util.Objects;

import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -36,8 +37,8 @@ public void listFolder_NotDir() {

@ParameterizedTest
@CsvSource({
"feature,,feature/xxx.Feature,_xxx,_xxx.html,_xxx.feature,xxx",
"feature,master,master/xxx.Feature,_xxx,_xxx.html,_xxx.feature,xxx",
"../feature,,../feature/xxx.Feature,_xxx,_xxx.html,_xxx.feature,xxx",
"../feature,../master,../master/xxx.Feature,_xxx,_xxx.html,_xxx.feature,xxx",
})
public void getFeatureMetadata(
String source,
Expand All @@ -48,18 +49,15 @@ public void getFeatureMetadata(
String expectedIdFeature,
String expectedIdName
){
File sourceFile = new File(Thread.currentThread()
.getContextClassLoader()
.getResource(source).getFile());
File sourceFile = new File(Objects.requireNonNull(getClass()
.getResource(source)).getFile());

File sourceMasterFile = StringUtils.isNotBlank(sourceMaster) ?
new File(Thread.currentThread()
.getContextClassLoader()
.getResource(sourceMaster).getFile()) : null;
new File(Objects.requireNonNull(getClass()
.getResource(sourceMaster)).getFile()) : null;

File featureFile = new File(Thread.currentThread()
.getContextClassLoader()
.getResource(feature).getFile());
File featureFile = new File(Objects.requireNonNull(getClass()
.getResource(feature)).getFile());

ParametersDto parameters = new ParametersDto();
parameters.setProjectSource(sourceFile);
Expand All @@ -75,15 +73,14 @@ public void getFeatureMetadata(

@ParameterizedTest
@CsvSource({
"feature/html_embed.html,.html",
"feature/xxx.png,.png",
"../feature/html_embed.html,.html",
"../feature/xxx.png,.png",
})
public void writeResourceToOut(String resource, String suffix) throws IOException {
File tmpFile = File.createTempFile("writeResourceToOut-", suffix);

File resourceFile = new File(Thread.currentThread()
.getContextClassLoader()
.getResource(resource).getFile());
File resourceFile = new File(Objects.requireNonNull(getClass()
.getResource(resource)).getFile());

try (
FileOutputStream fos = new FileOutputStream(tmpFile);
Expand All @@ -98,9 +95,8 @@ public void writeResourceToOut(String resource, String suffix) throws IOExceptio

@Test
public void writeFileToOut() throws IOException {
File resourceFile = new File(Thread.currentThread()
.getContextClassLoader()
.getResource("feature/html_embed.html").getFile());
File resourceFile = new File(Objects.requireNonNull(getClass()
.getResource("../feature/html_embed.html")).getFile());

try(
StringWriter sw = new StringWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.Objects;

import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -33,9 +34,8 @@ public void setup(){

@Test
public void build() throws Exception {
File logoFile = new File(Thread.currentThread()
.getContextClassLoader()
.getResource("logo_xxx.png").getFile());
File logoFile = new File(Objects.requireNonNull(getClass()
.getResource("../logo_xxx.png")).getFile());

ParametersDto parameters = new ParametersDto();
parameters.setMenuColor("#666");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,12 @@ public void validate_compilationArtifact(){
@ParameterizedTest
@CsvSource(value = {
"FOLDER,",
"FOLDER,feature/xxx.Feature",
"FOLDER_DIFF,feature/xxx.Feature",
"FEATURE,feature",
"FOLDER,../feature/xxx.Feature",
"FOLDER_DIFF,../feature/xxx.Feature",
"FEATURE,../feature",
})
public void validate_projectSource(CompilationTypeEnum compilationTypeEnum, String source){
val projectSource = source != null ? new File(Objects.requireNonNull(Thread.currentThread()
.getContextClassLoader()
val projectSource = source != null ? new File(Objects.requireNonNull(getClass()
.getResource(source)).getFile()) : null;

val dto = new ParametersDto();
Expand All @@ -124,13 +123,12 @@ public void validate_projectSource(CompilationTypeEnum compilationTypeEnum, Stri

@ParameterizedTest
@CsvSource(value = {
"FOLDER,feature",
"FOLDER_DIFF,feature/xxx.Feature",
"FOLDER,../feature",
"FOLDER_DIFF,../feature/xxx.Feature",
"FOLDER_DIFF,",
})
public void validate_projectMasterSource(CompilationTypeEnum compilationTypeEnum, String sourceMaster){
val projectMasterSource = sourceMaster != null ? new File(Objects.requireNonNull(Thread.currentThread()
.getContextClassLoader()
val projectMasterSource = sourceMaster != null ? new File(Objects.requireNonNull(getClass()
.getResource(sourceMaster)).getFile()) : null;

val dto = new ParametersDto();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Objects;

import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -24,8 +25,8 @@ public void build() throws Exception {
try (
FileOutputStream fos = new FileOutputStream(targetFile);
InputStream html = Files.newInputStream(sourceFile.toPath());
InputStream css = Thread.currentThread().getContextClassLoader()
.getResource("htmlTemplate/dist/feature-pdf.min.css")
InputStream css = Objects.requireNonNull(getClass()
.getResource("../dist/feature-pdf.min.css"))
.openStream();
){
PdfParser pdfParser = new PdfParser(new ParametersDto(), css);
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.

0 comments on commit 6c1020d

Please sign in to comment.