Skip to content

Commit

Permalink
Replace deprecated Guava Files.toString
Browse files Browse the repository at this point in the history
With Java 11's Files.readString().

Change-Id: Ie7e03ec01346eb92436455746d281ecb28277357
  • Loading branch information
akurtakov committed Mar 15, 2022
1 parent dd3a280 commit 803292b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2021 Tasktop Technologies and others.
* Copyright (c) 2013, 2022 Tasktop Technologies and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -24,6 +24,7 @@
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand All @@ -48,8 +49,6 @@
import org.eclipse.mylyn.wikitext.splitter.SplittingStrategy;
import org.eclipse.mylyn.wikitext.util.ServiceLocator;

import com.google.common.io.Files;

@Mojo(name = "eclipse-help", defaultPhase = LifecyclePhase.COMPILE)
public class MarkupToEclipseHelpMojo extends AbstractMojo {
/**
Expand Down Expand Up @@ -237,7 +236,7 @@ private void copy(File sourceFile, String relativePath) {
ensureFolderExists("target folder", targetFolder, true);
File targetFile = new File(targetFolder, sourceFile.getName());
try {
Files.copy(sourceFile, targetFile);
Files.copy(sourceFile.toPath(), targetFile.toPath());
} catch (IOException e) {
throw new BuildFailureException(
format("Cannot copy {0} to {1}: {2}", sourceFile, targetFile, e.getMessage()), e);
Expand Down Expand Up @@ -460,7 +459,7 @@ protected void ensureFolderExists(String name, File folder, boolean createIfMiss

protected String readFully(File inputFile) {
try {
return Files.toString(inputFile, Charset.forName(sourceEncoding));
return Files.readString(inputFile.toPath(), Charset.forName(sourceEncoding));
} catch (IOException e) {
throw new BuildFailureException(format("Cannot read source file {0}: {1}", inputFile, e.getMessage()), e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013 Tasktop Technologies and others.
* Copyright (c) 2013, 2022 Tasktop Technologies and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -32,6 +32,7 @@
import java.io.StringWriter;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.UUID;

Expand All @@ -48,8 +49,6 @@
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;

import com.google.common.io.Files;

public class MarkupToEclipseHelpMojoTest {

@Rule
Expand Down Expand Up @@ -270,7 +269,7 @@ private void assertHasContent(String path, String expectedContent) {
assertTrue(file.toString(), file.exists());
assertTrue(file.toString(), file.isFile());
try {
String content = Files.toString(file, StandardCharsets.UTF_8);
String content = Files.readString(file.toPath(), StandardCharsets.UTF_8);
assertTrue(String.format("expected %s but got %s", expectedContent, content),
content.contains(expectedContent));
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2021 David Green and others.
* Copyright (c) 2007, 2022 David Green and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -18,6 +18,7 @@

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -29,8 +30,6 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import com.google.common.io.Files;

public class WikiToDocTaskTest {

@Rule
Expand Down Expand Up @@ -94,7 +93,7 @@ public void testMapPageNameToHref() throws Exception {
task.execute();

File result = task.computeHtmlOutputFile(path);
String content = Files.toString(result, StandardCharsets.UTF_8);
String content = Files.readString(result.toPath(), StandardCharsets.UTF_8);
assertTrue(content.contains(
"<p>Link to <a href=\"#IActivatable\" title=\"GEF/GEF4/Common#IActivatable\">IActivatable</a> is here</p>"));
}
Expand Down Expand Up @@ -137,7 +136,7 @@ public void testLink() throws Exception {
assertEquals("'Installation.html' page exists", true, installationPage.exists());
File taskListPage = new File(mainPage.getParentFile(), "Task-List.html");
assertEquals("'Task-List.html' page exists", true, taskListPage.exists());
String content = Files.toString(taskListPage, StandardCharsets.UTF_8);
String content = Files.readString(taskListPage.toPath(), StandardCharsets.UTF_8);
assertTrue(content.contains(
"<a href=\"Installation.html#Recommended_GTK_Setup_for_KDE\" title=\"Mylyn/FAQ#Recommended_GTK_Setup_for_KDE\">Recommended GTK Setup for KDE</a> section."));
}
Expand Down

0 comments on commit 803292b

Please sign in to comment.