Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-08-09 05:41:58 +0000
committerAlexander Kurtakov2017-08-09 05:41:58 +0000
commit6d6be89f965ee2979f2857804518c7175deafc66 (patch)
treee3abb0668291dabfef60cf92d7f1069b5e08aec9
parentb3a1e25e6446174ee200988aad78075129e2f94b (diff)
downloadeclipse.platform.ua-6d6be89f965ee2979f2857804518c7175deafc66.tar.gz
eclipse.platform.ua-6d6be89f965ee2979f2857804518c7175deafc66.tar.xz
eclipse.platform.ua-6d6be89f965ee2979f2857804518c7175deafc66.zip
Change-Id: Ie81a2a361e1213a8d285928db871758c8e566cae Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/linkchecker/LinkTest.java56
1 files changed, 29 insertions, 27 deletions
diff --git a/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/linkchecker/LinkTest.java b/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/linkchecker/LinkTest.java
index 2f9f05e3c..2bf0db734 100644
--- a/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/linkchecker/LinkTest.java
+++ b/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/linkchecker/LinkTest.java
@@ -35,7 +35,7 @@ import org.eclipse.ui.PlatformUI;
import junit.framework.TestCase;
public class LinkTest extends TestCase {
-
+
public void testAllLinks() {
ISearchQuery query = new SearchQuery("*", false, Collections.emptyList(), Platform.getNL());
final Set<URI> indexedPagesURIs = new HashSet<>();
@@ -44,7 +44,7 @@ public class LinkTest extends TestCase {
public void addQTCException(QueryTooComplexException exception) throws QueryTooComplexException {
throw exception;
}
-
+
@Override
public void addHits(List<SearchHit> hits, String wordsSearched) {
hits.stream().map(SearchHit::getHref).map(href -> {
@@ -74,35 +74,37 @@ public class LinkTest extends TestCase {
private Set<String> checkLinks(InputStream stream, URI currentDoc, Set<URI> knownPagesURIs) throws IOException {
Set<String> res = new HashSet<>();
- BufferedReader in = new BufferedReader(new InputStreamReader(stream));
- String inputLine;
- while ((inputLine = in.readLine()) != null) {
- int index = 0;
- while ((index = inputLine.indexOf("<a href=\"", index)) > 0) {
- int closeIndex = inputLine.indexOf('"', index + "<a href=\"".length());
- URI href = URI.create(inputLine.substring(index + "<a href=\"".length(), closeIndex).replace(" ", "%20"));
- index = closeIndex;
- if (href.isAbsolute()) {
- continue;
- }
- URI linkURI = URI.create(currentDoc.toString() + "/../" + href).normalize();
- if (knownPagesURIs.contains(linkURI)) { //page already indexed or successfully visited
- // we already know this help page exists as it is indexed
- continue;
- } else { // page isn't indexed: can be generated navigation page
- //check whether it's existing anyway
- HttpURLConnection connection = (HttpURLConnection) linkURI.toURL().openConnection();
- connection.setRequestMethod("HEAD");
- connection.connect();
- if (connection.getResponseCode() != 200) {
- res.add("Link from " + currentDoc + " to " + href + " is broken: target URI " + linkURI + " doens't exist.");
- } else {
- knownPagesURIs.add(linkURI);
+ try (BufferedReader in = new BufferedReader(new InputStreamReader(stream))) {
+ String inputLine;
+ while ((inputLine = in.readLine()) != null) {
+ int index = 0;
+ while ((index = inputLine.indexOf("<a href=\"", index)) > 0) {
+ int closeIndex = inputLine.indexOf('"', index + "<a href=\"".length());
+ URI href = URI
+ .create(inputLine.substring(index + "<a href=\"".length(), closeIndex).replace(" ", "%20"));
+ index = closeIndex;
+ if (href.isAbsolute()) {
+ continue;
+ }
+ URI linkURI = URI.create(currentDoc.toString() + "/../" + href).normalize();
+ if (knownPagesURIs.contains(linkURI)) { // page already indexed or successfully visited
+ // we already know this help page exists as it is indexed
+ continue;
+ } else { // page isn't indexed: can be generated navigation page
+ // check whether it's existing anyway
+ HttpURLConnection connection = (HttpURLConnection) linkURI.toURL().openConnection();
+ connection.setRequestMethod("HEAD");
+ connection.connect();
+ if (connection.getResponseCode() != 200) {
+ res.add("Link from " + currentDoc + " to " + href + " is broken: target URI " + linkURI
+ + " doens't exist.");
+ } else {
+ knownPagesURIs.add(linkURI);
+ }
}
}
}
}
- in.close();
return res;
}

Back to the top