Skip to content

Commit

Permalink
Merge pull request #6467 from mkouba/issue-6164
Browse files Browse the repository at this point in the history
Qute parser - improve error messages
  • Loading branch information
mkouba authored Jan 9, 2020
2 parents 6d5912b + 4024571 commit a16aba0
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -71,7 +73,10 @@
import io.quarkus.qute.SectionHelper;
import io.quarkus.qute.SectionHelperFactory;
import io.quarkus.qute.Template;
import io.quarkus.qute.TemplateException;
import io.quarkus.qute.TemplateInstance;
import io.quarkus.qute.TemplateLocator;
import io.quarkus.qute.Variant;
import io.quarkus.qute.api.ResourcePath;
import io.quarkus.qute.api.VariantTemplate;
import io.quarkus.qute.deployment.TemplatesAnalysisBuildItem.TemplateAnalysis;
Expand Down Expand Up @@ -163,15 +168,37 @@ public CompletionStage<ResultNode> resolve(SectionResolutionContext context) {
};
}
};
}).addLocator(new TemplateLocator() {
@Override
public Optional<TemplateLocation> locate(String id) {
TemplatePathBuildItem found = templatePaths.stream().filter(p -> p.getPath().equals(id)).findAny().orElse(null);
if (found != null) {
try {
byte[] content = Files.readAllBytes(found.getFullPath());
return Optional.of(new TemplateLocation() {
@Override
public Reader read() {
return new StringReader(new String(content, StandardCharsets.UTF_8));
}

@Override
public Optional<Variant> getVariant() {
return Optional.empty();
}
});
} catch (IOException e) {
LOGGER.warn("Unable to read the template from path: " + found.getFullPath(), e);
}
}
;
return Optional.empty();
}
}).build();

for (TemplatePathBuildItem path : templatePaths) {
try {
Template template = dummyEngine
.parse(new String(Files.readAllBytes(path.getFullPath()), StandardCharsets.UTF_8));
Template template = dummyEngine.getTemplate(path.getPath());
if (template != null) {
analysis.add(new TemplateAnalysis(template.getGeneratedId(), template.getExpressions(), path));
} catch (IOException e) {
LOGGER.warn("Unable to analyze the template from path: " + path.getFullPath(), e);
}
}
LOGGER.debugf("Finished analysis of %s templates in %s ms",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.quarkus.qute.Expression;
import io.quarkus.qute.Expressions;
import io.quarkus.qute.TemplateException;

class TypeCheckInfo {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.qute.TemplateException;
import io.quarkus.test.QuarkusUnitTest;

public class NamedBeanNotFoundTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.qute.TemplateException;
import io.quarkus.test.QuarkusUnitTest;

public class NamedBeanPropertyNotFoundTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.qute.TemplateException;
import io.quarkus.test.QuarkusUnitTest;

public class ParamDeclarationWrongClassTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.qute.TemplateException;
import io.quarkus.test.QuarkusUnitTest;

public class PropertyNotFoundTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.qute.TemplateException;
import io.quarkus.test.QuarkusUnitTest;

public class TypeSafeLoopFailureTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class EngineImpl implements Engine {

@Override
public Template parse(String content, Variant variant) {
return new Parser(this).parse(new StringReader(content), Optional.ofNullable(variant));
String generatedId = generateId();
return new Parser(this).parse(new StringReader(content), Optional.ofNullable(variant), generatedId, generatedId);
}

@Override
Expand Down Expand Up @@ -131,7 +132,7 @@ private Template load(String id) {
Optional<TemplateLocation> location = locator.locate(id);
if (location.isPresent()) {
try (Reader r = location.get().read()) {
return new Parser(this).parse(ensureBufferedReader(r), location.get().getVariant());
return new Parser(this).parse(ensureBufferedReader(r), location.get().getVariant(), id, generateId());
} catch (IOException e) {
LOGGER.warn("Unable to close the reader for " + id, e);
}
Expand Down
Loading

0 comments on commit a16aba0

Please sign in to comment.