Skip to content

Commit c616e32

Browse files
gnl42ruspl-afed
authored andcommitted
Replace IOUtils, part1 #1098
PR #1100 feedback Task-Url: #1098
1 parent a754b92 commit c616e32

42 files changed

Lines changed: 238 additions & 227 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

mylyn.builds/org.eclipse.mylyn.jenkins.core/META-INF/MANIFEST.MF

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Import-Package: com.google.gson;version="2.9.1",
2424
com.sun.xml.bind;version="2.3.3",
2525
javax.xml.bind;version="2.3.3",
2626
javax.xml.bind.annotation;version="2.3.3",
27-
org.apache.commons.io;version="2.8.0",
2827
org.apache.http;version="[4.4.4,4.5.0)",
2928
org.apache.http.client;version="[4.5.2,4.7.0)",
3029
org.apache.http.client.entity;version="[4.5.2,4.7.0)",

mylyn.builds/org.eclipse.mylyn.jenkins.core/src/org/eclipse/mylyn/internal/jenkins/core/client/JenkinsOperation.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import javax.swing.text.html.HTML.Tag;
3131
import javax.xml.bind.JAXBException;
3232

33-
import org.apache.commons.io.IOUtils;
3433
import org.apache.http.Header;
3534
import org.apache.http.HttpResponse;
3635
import org.apache.http.HttpStatus;
@@ -109,7 +108,7 @@ protected void authenticate(IOperationMonitor monitor) throws IOException {
109108
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
110109
try (InputStream inStream = HttpUtil.getResponseBodyAsStream(response.getEntity(), monitor)) {
111110
String charSet = EntityUtils.getContentCharSet(response.getEntity());
112-
String text = IOUtils.toString(inStream,
111+
String text = new String(inStream.readAllBytes(),
113112
charSet != null ? Charset.forName(charSet) : Charset.defaultCharset());
114113
Pattern crumbPattern = Pattern.compile(CRUMB_REGEX);
115114
Matcher matcher = crumbPattern.matcher(text);
@@ -122,23 +121,20 @@ protected void authenticate(IOperationMonitor monitor) throws IOException {
122121
getClient().setAttribute(ID_CONTEXT_CRUMB, crumb);
123122
getClient().setAttribute(ID_CONTEXT_CRUMB_HEADER, crumbHeader);
124123
} else {
125-
throw new AuthenticationException(AUTHENTICATION_FAILED,
126-
new AuthenticationRequest<>(
127-
getClient().getLocation(), AuthenticationType.REPOSITORY));
124+
throw new AuthenticationException(AUTHENTICATION_FAILED, new AuthenticationRequest<>(
125+
getClient().getLocation(), AuthenticationType.REPOSITORY));
128126
}
129127
}
130128
} else if (response.getStatusLine().getStatusCode() >= HttpStatus.SC_INTERNAL_SERVER_ERROR) {
131129
throw new AuthenticationException(response.getStatusLine().getReasonPhrase(),
132-
new AuthenticationRequest<>(getClient().getLocation(),
133-
AuthenticationType.REPOSITORY));
130+
new AuthenticationRequest<>(getClient().getLocation(), AuthenticationType.REPOSITORY));
134131
} else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
135132
legacyAuthentication(monitor, credentials); // Needed for unit tests against https://mylyn.org/hudson-3.3.3
136133
} else {
137134
validate(response, monitor); // Check for proxy errors and such
138135

139136
throw new AuthenticationException(AUTHENTICATION_FAILED,
140-
new AuthenticationRequest<>(getClient().getLocation(),
141-
AuthenticationType.REPOSITORY));
137+
new AuthenticationRequest<>(getClient().getLocation(), AuthenticationType.REPOSITORY));
142138
}
143139
} finally {
144140
HttpUtil.release(request, response, monitor);
@@ -177,8 +173,7 @@ private void legacyAuthentication(IOperationMonitor monitor, UserCredentials cre
177173
if (header != null && header.getValue().endsWith("/loginError")) { //$NON-NLS-1$
178174
getClient().setAuthenticated(false);
179175
throw new AuthenticationException(AUTHENTICATION_FAILED,
180-
new AuthenticationRequest<>(getClient().getLocation(),
181-
AuthenticationType.REPOSITORY));
176+
new AuthenticationRequest<>(getClient().getLocation(), AuthenticationType.REPOSITORY));
182177
}
183178

184179
// success
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 George Lindholm
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v20.html.
7+
*
8+
* Contributors:
9+
* See git history
10+
*******************************************************************************/
11+
12+
package org.eclipse.mylyn.internal.commons.core;
13+
14+
import java.io.File;
15+
import java.io.IOException;
16+
import java.io.InputStream;
17+
import java.net.URL;
18+
import java.nio.charset.StandardCharsets;
19+
import java.nio.file.Files;
20+
import java.nio.file.Path;
21+
import java.util.Comparator;
22+
23+
import org.eclipse.core.runtime.IPath;
24+
25+
public class FileUtil {
26+
27+
public static String readFile(final File file) throws IOException {
28+
return Files.readString(file.toPath());
29+
}
30+
31+
public static String readFile(final Class<?> clazz, final String file) throws IOException {
32+
return new String(clazz.getResource(file).openStream().readAllBytes(), StandardCharsets.UTF_8);
33+
}
34+
35+
public static String readFile(final InputStream stream) throws IOException {
36+
return new String(stream.readAllBytes(), StandardCharsets.UTF_8);
37+
}
38+
39+
public static String readFile(final URL file) throws IOException {
40+
return new String(file.openStream().readAllBytes(), StandardCharsets.UTF_8);
41+
}
42+
43+
public static void deleteTree(final File rootDir) throws IOException {
44+
if (rootDir.exists()) {
45+
Files.walk(rootDir.toPath()) //
46+
.sorted(Comparator.reverseOrder()) //
47+
.map(Path::toFile) //
48+
.forEach(File::delete);
49+
}
50+
}
51+
52+
public static void deleteTree(final IPath rootDir) throws IOException {
53+
deleteTree(rootDir.toFile());
54+
}
55+
}

mylyn.context/org.eclipse.mylyn.context.core/META-INF/MANIFEST.MF

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Bundle-Localization: plugin
99
Require-Bundle: org.eclipse.core.runtime;bundle-version="0.0.0",
1010
org.eclipse.mylyn.commons.core;bundle-version="4.4.0",
1111
org.eclipse.mylyn.monitor.core;bundle-version="4.4.0"
12-
Import-Package: org.apache.commons.io;version="[1.4.0,3.0.0)"
1312
Bundle-ActivationPolicy: lazy
1413
Bundle-Vendor: %Bundle-Vendor
1514
Export-Package: org.eclipse.mylyn.context.core,

mylyn.context/org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/internal/context/core/InteractionContextExternalizer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.zip.ZipFile;
2828
import java.util.zip.ZipOutputStream;
2929

30-
import org.apache.commons.io.IOUtils;
3130
import org.eclipse.core.runtime.CoreException;
3231
import org.eclipse.core.runtime.ISafeRunnable;
3332
import org.eclipse.core.runtime.IStatus;
@@ -167,7 +166,7 @@ public void run() throws Exception {
167166
InteractionContextManager.CONTEXT_FILENAME_ENCODING);
168167
ZipEntry zipEntry = new ZipEntry(encoded);
169168
outputStream.putNextEntry(zipEntry);
170-
IOUtils.copy(additionalContextInformation, outputStream);
169+
additionalContextInformation.transferTo(outputStream);
171170
outputStream.flush();
172171
outputStream.closeEntry();
173172
}

mylyn.context/org.eclipse.mylyn.debug.tests/META-INF/MANIFEST.MF

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="0.0.0",
2323
org.eclipse.ui.ide;bundle-version="0.0.0"
2424
Bundle-RequiredExecutionEnvironment: JavaSE-21
2525
Export-Package: org.eclipse.mylyn.internal.debug.ui;x-internal:=true
26-
Import-Package: org.apache.commons.io;version="2.8.0",
27-
org.junit.jupiter.api;version="[6.0.0,7.0.0)",
26+
Import-Package: org.junit.jupiter.api;version="[6.0.0,7.0.0)",
2827
org.junit.jupiter.api.extension;version="[6.0.0,7.0.0)",
2928
org.junit.platform.launcher;version="[6.0.0,7.0.0)",
3029
org.junit.platform.launcher.listeners;version="[6.0.0,7.0.0)",

mylyn.context/org.eclipse.mylyn.debug.tests/src/org/eclipse/mylyn/internal/debug/ui/BreakpointsContextUtilTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
* SPDX-License-Identifier: EPL-2.0
99
*
1010
* Sebastian Schmidt - initial API and implementation
11+
* See git history
1112
*******************************************************************************/
1213
package org.eclipse.mylyn.internal.debug.ui;
1314

14-
1515
import static org.junit.jupiter.api.Assertions.assertEquals;
1616
import static org.junit.jupiter.api.Assertions.assertTrue;
1717

@@ -21,13 +21,14 @@
2121
import java.io.InputStream;
2222
import java.io.InputStreamReader;
2323
import java.nio.charset.StandardCharsets;
24+
import java.nio.file.Files;
25+
import java.nio.file.StandardCopyOption;
2426
import java.util.ArrayList;
2527
import java.util.Arrays;
2628
import java.util.Collections;
2729
import java.util.List;
2830
import java.util.stream.Collectors;
2931

30-
import org.apache.commons.io.FileUtils;
3132
import org.eclipse.core.resources.IMarker;
3233
import org.eclipse.core.runtime.CoreException;
3334
import org.eclipse.core.runtime.OperationCanceledException;
@@ -68,7 +69,8 @@ void setUp() throws IOException, CoreException {
6869
breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
6970
File contextStore = ContextCorePlugin.getContextStore().getContextDirectory();
7071
tempContextFile = new File(contextStore, contextFileName);
71-
FileUtils.copyFile(contextFile, tempContextFile);
72+
Files.copy(contextFile.toPath(), tempContextFile.toPath(), //
73+
StandardCopyOption.REPLACE_EXISTING);
7274
assertTrue(contextFile.exists());
7375
}
7476

@@ -179,11 +181,13 @@ public void testExportBreakpoints() throws Exception {
179181
InputStream exportedBreakpoints = BreakpointsContextUtil.exportBreakpoints(breakpoints, null);
180182
List<String> expected;
181183
try (BufferedReader reader = new BufferedReader(
182-
new InputStreamReader(CommonTestUtil.getResource(this, "testdata/breakpointFile.xml"), StandardCharsets.UTF_8))) {
184+
new InputStreamReader(CommonTestUtil.getResource(this, "testdata/breakpointFile.xml"),
185+
StandardCharsets.UTF_8))) {
183186
expected = reader.lines().collect(Collectors.toList());
184187
}
185188
List<String> actual;
186-
try (BufferedReader reader = new BufferedReader(new InputStreamReader(exportedBreakpoints, StandardCharsets.UTF_8))) {
189+
try (BufferedReader reader = new BufferedReader(
190+
new InputStreamReader(exportedBreakpoints, StandardCharsets.UTF_8))) {
187191
actual = reader.lines().collect(Collectors.toList());
188192
}
189193
Collections.sort(expected);

mylyn.context/org.eclipse.mylyn.debug.tests/src/org/eclipse/mylyn/internal/debug/ui/BreakpointsStateUtilTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
package org.eclipse.mylyn.internal.debug.ui;
1515

16-
1716
import static org.junit.jupiter.api.Assertions.assertEquals;
1817
import static org.junit.jupiter.api.Assertions.assertFalse;
1918
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -22,6 +21,7 @@
2221
import java.io.FileInputStream;
2322
import java.io.IOException;
2423
import java.io.StringWriter;
24+
import java.nio.file.Files;
2525
import java.util.ArrayList;
2626
import java.util.Collections;
2727
import java.util.List;
@@ -36,14 +36,14 @@
3636
import javax.xml.transform.dom.DOMSource;
3737
import javax.xml.transform.stream.StreamResult;
3838

39-
import org.apache.commons.io.FileUtils;
4039
import org.eclipse.core.runtime.CoreException;
4140
import org.eclipse.core.runtime.IPath;
4241
import org.eclipse.core.runtime.Platform;
4342
import org.eclipse.debug.core.DebugPlugin;
4443
import org.eclipse.debug.core.IBreakpointManager;
4544
import org.eclipse.debug.core.model.IBreakpoint;
4645
import org.eclipse.mylyn.context.sdk.java.WorkspaceSetupHelper;
46+
import org.eclipse.mylyn.internal.commons.core.FileUtil;
4747
import org.junit.jupiter.api.AfterEach;
4848
import org.junit.jupiter.api.BeforeEach;
4949
import org.junit.jupiter.api.Test;
@@ -79,7 +79,7 @@ void setUp() throws Exception {
7979
@AfterEach
8080
void tearDown() throws IOException, CoreException {
8181
deleteAllBreakpoints();
82-
FileUtils.deleteDirectory(pluginStateDir.toFile());
82+
FileUtil.deleteTree(pluginStateDir);
8383
WorkspaceSetupHelper.clearWorkspace();
8484
}
8585

@@ -157,7 +157,8 @@ public void testSaveStateWithoutBreakpoint() throws CoreException {
157157

158158
@Test
159159
public void testRestoreState() throws CoreException, IOException {
160-
FileUtils.copyFile(new File("testdata/breakpointFile.xml"), pluginStateFile);
160+
Files.copy(new File("testdata/breakpointFile.xml").toPath(), pluginStateFile.toPath(), //
161+
java.nio.file.StandardCopyOption.REPLACE_EXISTING);
161162

162163
objectUnderTest.restoreState();
163164

mylyn.context/org.eclipse.mylyn.debug.ui/META-INF/MANIFEST.MF

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ Bundle-RequiredExecutionEnvironment: JavaSE-21
2727
Bundle-ClassPath: .
2828
Export-Package: org.eclipse.mylyn.internal.debug.ui;x-internal:=true,
2929
org.eclipse.mylyn.internal.debug.ui.cnf;x-internal:=true
30-
Import-Package: org.apache.commons.io;version="2.8.0"

mylyn.context/org.eclipse.mylyn.debug.ui/src/org/eclipse/mylyn/internal/debug/ui/BreakpointsStateUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.InputStream;
2222
import java.util.Arrays;
2323

24-
import org.apache.commons.io.IOUtils;
2524
import org.eclipse.core.runtime.IPath;
2625
import org.eclipse.core.runtime.NullProgressMonitor;
2726
import org.eclipse.debug.core.DebugPlugin;
@@ -83,7 +82,7 @@ private void saveStateFile(File stateFile, InputStream exportedBreakpoints) {
8382
}
8483
}
8584
try (FileOutputStream output = new FileOutputStream(stateFile)) {
86-
IOUtils.copy(exportedBreakpoints, output);
85+
exportedBreakpoints.transferTo(output);
8786
} catch (FileNotFoundException e) {
8887
return;
8988
} catch (IOException e) {

0 commit comments

Comments
 (0)