Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,8 @@ public void forceDownloadExternalResource(String url) {
cacheResolverExtension.forceDownloadExternalResource(url);
}

public void waitForDownload(String resourceUri) {
cacheResolverExtension.waitForDownload(resourceUri);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,8 @@ public void evictCache() throws IOException {
public void forceDownloadExternalResource(String url) {
cacheResourcesManager.forceDownloadExternalResource(url);
}

public void waitForDownload(String resourceUri) {
cacheResourcesManager.waitForDownload(resourceUri);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public void checkCanceled() {
private final XMLLinkedEditing linkedEditing;
private final XMLDocumentColor documentColor;

private boolean retriggerValidationWhenDownloadError;

public XMLLanguageService() {
this.formatter = new XMLFormatter(this);
this.highlighting = new XMLHighlighting(this);
Expand All @@ -115,6 +117,7 @@ public XMLLanguageService() {
this.rename = new XMLRename(this);
this.selectionRanges = new XMLSelectionRanges();
this.linkedEditing = new XMLLinkedEditing(this);
setRetriggerValidationWhenDownloadError(true);
}

@Override
Expand Down Expand Up @@ -208,8 +211,15 @@ public CompletableFuture<Path> publishDiagnostics(DOMDocument xmlDocument,

// If there are some XSD, DTD which are downloading, wait for all download and
// re-trigger the validation.
if (retriggerValidationWhenDownloadError) {
List<CompletableFuture<?>> futures = diagnostics.getFutures();
if (!futures.isEmpty()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
CompletableFuture<Void> allFutures = CompletableFuture
.allOf(futures.toArray(new CompletableFuture[futures.size()]));
allFutures.thenAccept(Void -> {
Expand All @@ -219,6 +229,7 @@ public CompletableFuture<Path> publishDiagnostics(DOMDocument xmlDocument,
return null;
});
}
}
return null;
}

Expand Down Expand Up @@ -334,5 +345,9 @@ public LinkedEditingRanges findLinkedEditingRanges(DOMDocument xmlDocument, Posi
CancelChecker cancelChecker) {
return linkedEditing.findLinkedEditingRanges(xmlDocument, position, cancelChecker);
}

public void setRetriggerValidationWhenDownloadError(boolean retriggerValidationWhenDownloadError) {
this.retriggerValidationWhenDownloadError = retriggerValidationWhenDownloadError;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -492,4 +493,16 @@ public void forceDownloadExternalResource(String url) {
private boolean isForceDownloadExternalResource(String url) {
return forceDownloadExternalResources.getIfPresent(url) != null;
}

public void waitForDownload(String resourceUri) {
CompletableFuture<Path> downloadedFile = resourcesLoading.get(resourceUri);
if (downloadedFile != null) {
try {
downloadedFile.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ public void docTypeDownloadProblem() throws Exception {
validation.setResolveExternalEntities(true);

XMLLanguageService ls = new XMLLanguageService();
ls.setRetriggerValidationWhenDownloadError(false);

String xml = "<!DOCTYPE root-element PUBLIC \"public-id\" \"http://localhost:8080/sample.dtd\">\r\n" + //
"<root-element>\r\n" + //
"</root-element>";

String dtdCachePath = CacheResourcesManager.getResourceCachePath("http://localhost:8080/sample.dtd").toString();
String resourceUri = "http://localhost:8080/sample.dtd";
String dtdCachePath = CacheResourcesManager.getResourceCachePath(resourceUri).toString();
String fileURI = "test.xml";
// Downloading...
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls,
Expand All @@ -96,7 +98,8 @@ public void docTypeDownloadProblem() throws Exception {
new Diagnostic(r(1, 1, 1, 13), "Element type \"root-element\" must be declared.",
DiagnosticSeverity.Error, "xml", DTDErrorCode.MSG_ELEMENT_NOT_DECLARED.getCode())));

TimeUnit.SECONDS.sleep(5); // HACK: to make the timing work on slow machines
ContentModelManager contentModelManager = ls.getComponent(ContentModelManager.class);
contentModelManager.waitForDownload(resourceUri);

// Downloaded error
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls,
Expand Down Expand Up @@ -154,6 +157,7 @@ public void entityRefDownloadProblem() throws Exception {
validation.setResolveExternalEntities(true);

XMLLanguageService ls = new XMLLanguageService();
ls.setRetriggerValidationWhenDownloadError(false);

String xml = "<!DOCTYPE root-element [\r\n" + //
" <!ELEMENT root-element (#PCDATA)>\r\n" + //
Expand All @@ -164,7 +168,8 @@ public void entityRefDownloadProblem() throws Exception {
" &abcd;\r\n" + //
"</root-element>";

String dtdCachePath = CacheResourcesManager.getResourceCachePath("http://localhost:8080/sample.dtd").toString();
String resourceUri = "http://localhost:8080/sample.dtd";
String dtdCachePath = CacheResourcesManager.getResourceCachePath(resourceUri).toString();
String fileURI = "test.xml";
// Downloading...
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls,
Expand All @@ -177,7 +182,8 @@ public void entityRefDownloadProblem() throws Exception {
new Diagnostic(r(6, 1, 6, 7), "The entity \"abcd\" was referenced, but not declared.",
DiagnosticSeverity.Error, "xml", DTDErrorCode.EntityNotDeclared.getCode())));

TimeUnit.SECONDS.sleep(5); // HACK: to make the timing work on slow machines
ContentModelManager contentModelManager = ls.getComponent(ContentModelManager.class);
contentModelManager.waitForDownload(resourceUri);

// Downloaded error
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ public void noNamespaceSchemaLocationDownloadProblem() throws Exception {
validation.setResolveExternalEntities(true);

XMLLanguageService ls = new XMLLanguageService();

ls.setRetriggerValidationWhenDownloadError(false);

String xml = "<root-element\r\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xsi:noNamespaceSchemaLocation=\"http://localhost:8080/sample.xsd\">\r\n" + //
" \r\n" + //
"</root-element>";

String xsdCachePath = CacheResourcesManager.getResourceCachePath("http://localhost:8080/sample.xsd").toString();
String resourceUri = "http://localhost:8080/sample.xsd";
String xsdCachePath = CacheResourcesManager.getResourceCachePath(resourceUri).toString();
String fileURI = "test.xml";
// Downloading...
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls, pd(fileURI,
Expand All @@ -99,7 +101,8 @@ public void noNamespaceSchemaLocationDownloadProblem() throws Exception {
new Diagnostic(r(0, 1, 0, 13), "cvc-elt.1.a: Cannot find the declaration of element 'root-element'.",
DiagnosticSeverity.Error, "xml", XMLSchemaErrorCode.cvc_elt_1_a.getCode())));

TimeUnit.SECONDS.sleep(5); // HACK: to make the timing work on slow machines
ContentModelManager contentModelManager = ls.getComponent(ContentModelManager.class);
contentModelManager.waitForDownload(resourceUri);

// Downloaded error
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls, pd(fileURI,
Expand Down Expand Up @@ -154,15 +157,17 @@ public void schemaLocationDownloadProblem() throws Exception {
validation.setResolveExternalEntities(true);

XMLLanguageService ls = new XMLLanguageService();

ls.setRetriggerValidationWhenDownloadError(false);

String xml = "<root-element xmlns=\"https://github.com/eclipse/lemminx\"\r\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xsi:schemaLocation=\"\r\n" + //
" https://github.com/eclipse/lemminx http://localhost:8080/sample.xsd\">\r\n" + //
" \r\n" + //
"</root-element>";

String xsdCachePath = CacheResourcesManager.getResourceCachePath("http://localhost:8080/sample.xsd").toString();
String resourceUri = "http://localhost:8080/sample.xsd";
String xsdCachePath = CacheResourcesManager.getResourceCachePath(resourceUri).toString();
String fileURI = "test.xml";
// Downloading...
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls, pd(fileURI,
Expand All @@ -173,7 +178,8 @@ public void schemaLocationDownloadProblem() throws Exception {
new Diagnostic(r(0, 1, 0, 13), "cvc-elt.1.a: Cannot find the declaration of element 'root-element'.",
DiagnosticSeverity.Error, "xml", XMLSchemaErrorCode.cvc_elt_1_a.getCode())));

TimeUnit.SECONDS.sleep(5); // HACK: to make the timing work on slow machines
ContentModelManager contentModelManager = ls.getComponent(ContentModelManager.class);
contentModelManager.waitForDownload(resourceUri);

// Downloaded error
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls, pd(fileURI,
Expand Down
Loading