From c4143c22ad01dfe4540f0959d26b844d5c074c1e Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Fri, 25 Feb 2022 09:55:59 +0100 Subject: [PATCH] cleaning up old code that uses old log4j pieces --- .../META-INF/MANIFEST.MF | 3 +- ...tClasspathNamespaceDefinitionResolver.java | 12 +- .../META-INF/MANIFEST.MF | 1 - .../core/templates/TemplateProcessor.java | 12 +- .../commons/core/util/FileCopyUtils.java | 241 ---------------- .../commons/core/util/StreamUtils.java | 263 ------------------ 6 files changed, 15 insertions(+), 517 deletions(-) delete mode 100644 eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/util/FileCopyUtils.java delete mode 100644 eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/util/StreamUtils.java diff --git a/eclipse-extensions/org.springframework.ide.eclipse.xml.namespaces/META-INF/MANIFEST.MF b/eclipse-extensions/org.springframework.ide.eclipse.xml.namespaces/META-INF/MANIFEST.MF index 8ada24d01..25a9db71d 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.xml.namespaces/META-INF/MANIFEST.MF +++ b/eclipse-extensions/org.springframework.ide.eclipse.xml.namespaces/META-INF/MANIFEST.MF @@ -40,4 +40,5 @@ Export-Package: org.springframework.ide.eclipse.xml.namespaces, Bundle-ActivationPolicy: lazy Require-Bundle: com.google.guava, io.projectreactor.reactor-core;bundle-version="3.1.9", - org.reactivestreams.reactive-streams;bundle-version="1.0.2" + org.reactivestreams.reactive-streams;bundle-version="1.0.2", + org.apache.commons.io;bundle-version="2.8.0" diff --git a/eclipse-extensions/org.springframework.ide.eclipse.xml.namespaces/src/org/springframework/ide/eclipse/xml/namespaces/internal/ProjectClasspathNamespaceDefinitionResolver.java b/eclipse-extensions/org.springframework.ide.eclipse.xml.namespaces/src/org/springframework/ide/eclipse/xml/namespaces/internal/ProjectClasspathNamespaceDefinitionResolver.java index 6ec4925f7..50855cad6 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.xml.namespaces/src/org/springframework/ide/eclipse/xml/namespaces/internal/ProjectClasspathNamespaceDefinitionResolver.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.xml.namespaces/src/org/springframework/ide/eclipse/xml/namespaces/internal/ProjectClasspathNamespaceDefinitionResolver.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Spring IDE Developers + * Copyright (c) 2010, 2022 Spring IDE Developers * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -23,6 +23,7 @@ import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.apache.commons.io.IOUtils; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Preferences.IPropertyChangeListener; import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; @@ -40,7 +41,6 @@ import org.springframework.ide.eclipse.xml.namespaces.model.NamespaceDefinition; import org.springframework.ide.eclipse.xml.namespaces.util.TargetNamespaceScanner; import org.springsource.ide.eclipse.commons.core.SpringCorePreferences; import org.springsource.ide.eclipse.commons.core.util.CollectionUtils; -import org.springsource.ide.eclipse.commons.core.util.FileCopyUtils; import org.springsource.ide.eclipse.commons.frameworks.core.util.StringUtils; /** @@ -208,7 +208,13 @@ public class ProjectClasspathNamespaceDefinitionResolver implements INamespaceDe return iconFile; } - FileCopyUtils.copy(cls.getResourceAsStream(icon), new FileOutputStream(iconFile)); + try ( + InputStream is = cls.getResourceAsStream(icon); + FileOutputStream os = new FileOutputStream(iconFile); + ) { + IOUtils.copy(is, os); + } + return iconFile; } catch (Exception e) { diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/META-INF/MANIFEST.MF b/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/META-INF/MANIFEST.MF index dc767f78e..c89ff5f02 100644 --- a/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/META-INF/MANIFEST.MF +++ b/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/META-INF/MANIFEST.MF @@ -13,7 +13,6 @@ Require-Bundle: org.eclipse.core.resources, org.eclipse.jdt.launching, org.eclipse.wst.common.project.facet.core, org.apache.commons.collections, - org.apache.log4j, org.eclipse.platform, org.springsource.ide.eclipse.commons.frameworks.core;bundle-version="3.5.0", org.springsource.ide.eclipse.commons.jdk_tools;resolution:=optional, diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/templates/TemplateProcessor.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/templates/TemplateProcessor.java index 84e9a5b20..c78441bcd 100644 --- a/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/templates/TemplateProcessor.java +++ b/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/templates/TemplateProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 Pivotal Software, Inc. + * Copyright (c) 2012, 2021 VMware Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -21,10 +21,10 @@ import java.io.Writer; import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.springsource.ide.eclipse.commons.core.FileUtil; +import org.springsource.ide.eclipse.commons.internal.core.CorePlugin; /** * @author Terry Denney @@ -35,8 +35,6 @@ import org.springsource.ide.eclipse.commons.core.FileUtil; */ public class TemplateProcessor { - private static Logger logger = Logger.getLogger(TemplateProcessor.class); - protected Map replacementContext = new HashMap(); // protected SpringVersionProcessor springProcessor; @@ -55,14 +53,13 @@ public class TemplateProcessor { public void process(File source, File target) throws IOException { if (FileUtil.isBinaryFile(source)) { - logger.debug("Copying binary file " + source); FileUtil.copy(source, target); } else if (source.isDirectory()) { try { FileUtil.copyDirectory(source, target, new NullProgressMonitor()); } catch (CoreException e) { - logger.error("Problem while attempting to copy template directory", e); + CorePlugin.log("Problem while attempting to copy template directory", e); } String[] names = source.list(); if (names!=null) { @@ -74,7 +71,6 @@ public class TemplateProcessor { } } else { - logger.debug("Template processing text file " + source); process(new FileReader(source), new FileWriter(target)); } } @@ -125,7 +121,7 @@ public class TemplateProcessor { } if (input.indexOf("my") >= 0) { - logger.warn("May have failed to replace token " + input); + CorePlugin.log("May have failed to replace token " + input, null); } return input; } diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/util/FileCopyUtils.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/util/FileCopyUtils.java deleted file mode 100644 index 1a52f0926..000000000 --- a/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/util/FileCopyUtils.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 2002-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springsource.ide.eclipse.commons.core.util; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.apache.log4j.lf5.util.StreamUtils; -import org.eclipse.core.runtime.Assert; - -/** - * Simple utility methods for file and stream copying. All copy methods use a block size - * of 4096 bytes, and close all affected streams when done. A variation of the copy - * methods from this class that leave streams open can be found in {@link StreamUtils}. - * - *

Mainly for use within the framework, but also useful for application code. - * - * @author Juergen Hoeller - * @since 06.10.2003 - * @see StreamUtils - * @see FileSystemUtils - */ -public abstract class FileCopyUtils { - -// /** -// * The default buffer size used when copying bytes. -// */ -// public static final int BUFFER_SIZE = StreamUtils.BUFFER_SIZE; -// -// -// //--------------------------------------------------------------------- -// // Copy methods for java.io.File -// //--------------------------------------------------------------------- -// -// /** -// * Copy the contents of the given input File to the given output File. -// * @param in the file to copy from -// * @param out the file to copy to -// * @return the number of bytes copied -// * @throws IOException in case of I/O errors -// */ -// public static int copy(File in, File out) throws IOException { -// Assert.notNull(in, "No input File specified"); -// Assert.notNull(out, "No output File specified"); -// return copy(Files.newInputStream(in.toPath()), Files.newOutputStream(out.toPath())); -// } -// -// /** -// * Copy the contents of the given byte array to the given output File. -// * @param in the byte array to copy from -// * @param out the file to copy to -// * @throws IOException in case of I/O errors -// */ -// public static void copy(byte[] in, File out) throws IOException { -// Assert.notNull(in, "No input byte array specified"); -// Assert.notNull(out, "No output File specified"); -// copy(new ByteArrayInputStream(in), Files.newOutputStream(out.toPath())); -// } -// -// /** -// * Copy the contents of the given input File into a new byte array. -// * @param in the file to copy from -// * @return the new byte array that has been copied to -// * @throws IOException in case of I/O errors -// */ -// public static byte[] copyToByteArray(File in) throws IOException { -// Assert.notNull(in, "No input File specified"); -// return copyToByteArray(Files.newInputStream(in.toPath())); -// } -// -// - //--------------------------------------------------------------------- - // Copy methods for java.io.InputStream / java.io.OutputStream - //--------------------------------------------------------------------- - - /** - * Copy the contents of the given InputStream to the given OutputStream. - * Closes both streams when done. - * @param in the stream to copy from - * @param out the stream to copy to - * @throws IOException in case of I/O errors - */ - public static void copy(InputStream in, OutputStream out) throws IOException { - Assert.isNotNull(in, "No InputStream specified"); - Assert.isNotNull(out, "No OutputStream specified"); - - try { - StreamUtils.copy(in, out); - } - finally { - try { - in.close(); - } - catch (IOException ex) { - } - try { - out.close(); - } - catch (IOException ex) { - } - } - } -// -// /** -// * Copy the contents of the given byte array to the given OutputStream. -// * Closes the stream when done. -// * @param in the byte array to copy from -// * @param out the OutputStream to copy to -// * @throws IOException in case of I/O errors -// */ -// public static void copy(byte[] in, OutputStream out) throws IOException { -// Assert.notNull(in, "No input byte array specified"); -// Assert.notNull(out, "No OutputStream specified"); -// -// try { -// out.write(in); -// } -// finally { -// try { -// out.close(); -// } -// catch (IOException ex) { -// } -// } -// } -// -// /** -// * Copy the contents of the given InputStream into a new byte array. -// * Closes the stream when done. -// * @param in the stream to copy from (may be {@code null} or empty) -// * @return the new byte array that has been copied to (possibly empty) -// * @throws IOException in case of I/O errors -// */ -// public static byte[] copyToByteArray(@Nullable InputStream in) throws IOException { -// if (in == null) { -// return new byte[0]; -// } -// -// ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE); -// copy(in, out); -// return out.toByteArray(); -// } -// -// -// //--------------------------------------------------------------------- -// // Copy methods for java.io.Reader / java.io.Writer -// //--------------------------------------------------------------------- -// -// /** -// * Copy the contents of the given Reader to the given Writer. -// * Closes both when done. -// * @param in the Reader to copy from -// * @param out the Writer to copy to -// * @return the number of characters copied -// * @throws IOException in case of I/O errors -// */ -// public static int copy(Reader in, Writer out) throws IOException { -// Assert.notNull(in, "No Reader specified"); -// Assert.notNull(out, "No Writer specified"); -// -// try { -// int byteCount = 0; -// char[] buffer = new char[BUFFER_SIZE]; -// int bytesRead = -1; -// while ((bytesRead = in.read(buffer)) != -1) { -// out.write(buffer, 0, bytesRead); -// byteCount += bytesRead; -// } -// out.flush(); -// return byteCount; -// } -// finally { -// try { -// in.close(); -// } -// catch (IOException ex) { -// } -// try { -// out.close(); -// } -// catch (IOException ex) { -// } -// } -// } -// -// /** -// * Copy the contents of the given String to the given output Writer. -// * Closes the writer when done. -// * @param in the String to copy from -// * @param out the Writer to copy to -// * @throws IOException in case of I/O errors -// */ -// public static void copy(String in, Writer out) throws IOException { -// Assert.notNull(in, "No input String specified"); -// Assert.notNull(out, "No Writer specified"); -// -// try { -// out.write(in); -// } -// finally { -// try { -// out.close(); -// } -// catch (IOException ex) { -// } -// } -// } -// -// /** -// * Copy the contents of the given Reader into a String. -// * Closes the reader when done. -// * @param in the reader to copy from (may be {@code null} or empty) -// * @return the String that has been copied to (possibly empty) -// * @throws IOException in case of I/O errors -// */ -// public static String copyToString(@Nullable Reader in) throws IOException { -// if (in == null) { -// return ""; -// } -// -// StringWriter out = new StringWriter(); -// copy(in, out); -// return out.toString(); -// } - -} diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/util/StreamUtils.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/util/StreamUtils.java deleted file mode 100644 index 41de8c003..000000000 --- a/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/util/StreamUtils.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright 2002-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springsource.ide.eclipse.commons.core.util; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.eclipse.core.runtime.Assert; - -/** - * Simple utility methods for dealing with streams. The copy methods of this class are - * similar to those defined in {@link FileCopyUtils} except that all affected streams are - * left open when done. All copy methods use a block size of 4096 bytes. - * - *

Mainly for use within the framework, but also useful for application code. - * - * @author Juergen Hoeller - * @author Phillip Webb - * @author Brian Clozel - * @since 3.2.2 - * @see FileCopyUtils - */ -public abstract class StreamUtils { - - /** - * The default buffer size used why copying bytes. - */ - public static final int BUFFER_SIZE = 4096; - -// private static final byte[] EMPTY_CONTENT = new byte[0]; -// -// -// /** -// * Copy the contents of the given InputStream into a new byte array. -// * Leaves the stream open when done. -// * @param in the stream to copy from (may be {@code null} or empty) -// * @return the new byte array that has been copied to (possibly empty) -// * @throws IOException in case of I/O errors -// */ -// public static byte[] copyToByteArray(@Nullable InputStream in) throws IOException { -// if (in == null) { -// return new byte[0]; -// } -// -// ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE); -// copy(in, out); -// return out.toByteArray(); -// } -// -// /** -// * Copy the contents of the given InputStream into a String. -// * Leaves the stream open when done. -// * @param in the InputStream to copy from (may be {@code null} or empty) -// * @return the String that has been copied to (possibly empty) -// * @throws IOException in case of I/O errors -// */ -// public static String copyToString(@Nullable InputStream in, Charset charset) throws IOException { -// if (in == null) { -// return ""; -// } -// -// StringBuilder out = new StringBuilder(); -// InputStreamReader reader = new InputStreamReader(in, charset); -// char[] buffer = new char[BUFFER_SIZE]; -// int bytesRead = -1; -// while ((bytesRead = reader.read(buffer)) != -1) { -// out.append(buffer, 0, bytesRead); -// } -// return out.toString(); -// } -// -// /** -// * Copy the contents of the given byte array to the given OutputStream. -// * Leaves the stream open when done. -// * @param in the byte array to copy from -// * @param out the OutputStream to copy to -// * @throws IOException in case of I/O errors -// */ -// public static void copy(byte[] in, OutputStream out) throws IOException { -// Assert.notNull(in, "No input byte array specified"); -// Assert.notNull(out, "No OutputStream specified"); -// -// out.write(in); -// } -// -// /** -// * Copy the contents of the given String to the given output OutputStream. -// * Leaves the stream open when done. -// * @param in the String to copy from -// * @param charset the Charset -// * @param out the OutputStream to copy to -// * @throws IOException in case of I/O errors -// */ -// public static void copy(String in, Charset charset, OutputStream out) throws IOException { -// Assert.notNull(in, "No input String specified"); -// Assert.notNull(charset, "No charset specified"); -// Assert.notNull(out, "No OutputStream specified"); -// -// Writer writer = new OutputStreamWriter(out, charset); -// writer.write(in); -// writer.flush(); -// } -// - /** - * Copy the contents of the given InputStream to the given OutputStream. - * Leaves both streams open when done. - * @param in the InputStream to copy from - * @param out the OutputStream to copy to - * @return the number of bytes copied - * @throws IOException in case of I/O errors - */ - public static int copy(InputStream in, OutputStream out) throws IOException { - Assert.isNotNull(in, "No InputStream specified"); - Assert.isNotNull(out, "No OutputStream specified"); - - int byteCount = 0; - byte[] buffer = new byte[BUFFER_SIZE]; - int bytesRead = -1; - while ((bytesRead = in.read(buffer)) != -1) { - out.write(buffer, 0, bytesRead); - byteCount += bytesRead; - } - out.flush(); - return byteCount; - } - -// /** -// * Copy a range of content of the given InputStream to the given OutputStream. -// *

If the specified range exceeds the length of the InputStream, this copies -// * up to the end of the stream and returns the actual number of copied bytes. -// *

Leaves both streams open when done. -// * @param in the InputStream to copy from -// * @param out the OutputStream to copy to -// * @param start the position to start copying from -// * @param end the position to end copying -// * @return the number of bytes copied -// * @throws IOException in case of I/O errors -// * @since 4.3 -// */ -// public static long copyRange(InputStream in, OutputStream out, long start, long end) throws IOException { -// Assert.notNull(in, "No InputStream specified"); -// Assert.notNull(out, "No OutputStream specified"); -// -// long skipped = in.skip(start); -// if (skipped < start) { -// throw new IOException("Skipped only " + skipped + " bytes out of " + start + " required"); -// } -// -// long bytesToCopy = end - start + 1; -// byte[] buffer = new byte[StreamUtils.BUFFER_SIZE]; -// while (bytesToCopy > 0) { -// int bytesRead = in.read(buffer); -// if (bytesRead == -1) { -// break; -// } -// else if (bytesRead <= bytesToCopy) { -// out.write(buffer, 0, bytesRead); -// bytesToCopy -= bytesRead; -// } -// else { -// out.write(buffer, 0, (int) bytesToCopy); -// bytesToCopy = 0; -// } -// } -// return (end - start + 1 - bytesToCopy); -// } -// -// /** -// * Drain the remaining content of the given InputStream. -// * Leaves the InputStream open when done. -// * @param in the InputStream to drain -// * @return the number of bytes read -// * @throws IOException in case of I/O errors -// * @since 4.3 -// */ -// public static int drain(InputStream in) throws IOException { -// Assert.notNull(in, "No InputStream specified"); -// byte[] buffer = new byte[BUFFER_SIZE]; -// int bytesRead = -1; -// int byteCount = 0; -// while ((bytesRead = in.read(buffer)) != -1) { -// byteCount += bytesRead; -// } -// return byteCount; -// } -// -// /** -// * Return an efficient empty {@link InputStream}. -// * @return a {@link ByteArrayInputStream} based on an empty byte array -// * @since 4.2.2 -// */ -// public static InputStream emptyInput() { -// return new ByteArrayInputStream(EMPTY_CONTENT); -// } -// -// /** -// * Return a variant of the given {@link InputStream} where calling -// * {@link InputStream#close() close()} has no effect. -// * @param in the InputStream to decorate -// * @return a version of the InputStream that ignores calls to close -// */ -// public static InputStream nonClosing(InputStream in) { -// Assert.notNull(in, "No InputStream specified"); -// return new NonClosingInputStream(in); -// } -// -// /** -// * Return a variant of the given {@link OutputStream} where calling -// * {@link OutputStream#close() close()} has no effect. -// * @param out the OutputStream to decorate -// * @return a version of the OutputStream that ignores calls to close -// */ -// public static OutputStream nonClosing(OutputStream out) { -// Assert.notNull(out, "No OutputStream specified"); -// return new NonClosingOutputStream(out); -// } -// -// -// private static class NonClosingInputStream extends FilterInputStream { -// -// public NonClosingInputStream(InputStream in) { -// super(in); -// } -// -// @Override -// public void close() throws IOException { -// } -// } -// -// -// private static class NonClosingOutputStream extends FilterOutputStream { -// -// public NonClosingOutputStream(OutputStream out) { -// super(out); -// } -// -// @Override -// public void write(byte[] b, int off, int let) throws IOException { -// // It is critical that we override this method for performance -// this.out.write(b, off, let); -// } -// -// @Override -// public void close() throws IOException { -// } -// } - -}