From b93ed84d7e8012d98992deb363384612487aa0c5 Mon Sep 17 00:00:00 2001 From: Michael Keppler Date: Fri, 25 Oct 2024 19:25:48 +0200 Subject: [PATCH] buffer file outputs This makes "Resolving MavenDependencyRoots..." output somewhat faster on my machine. (cherry picked from commit dfab8b7428f618cddedb0cc2ca4979b4dc4fcf68) --- .../FtpTransportProtocolHandler.java | 30 ++++++++++++------- .../transport/SharedHttpCacheStorage.java | 8 +++-- .../DefaultEquinoxInstallationFactory.java | 4 +-- .../tycho/core/EcJLogFileEnhancer.java | 5 ++-- .../maven/TychoMavenLifecycleParticipant.java | 11 ++++--- .../MavenTargetDefinitionContent.java | 4 ++- .../ArtifactRepositoryBaseImpl.java | 3 +- .../FileBasedTychoRepositoryIndex.java | 2 +- .../repository/module/ModuleArtifactMap.java | 11 ++++--- .../tycho/p2/resolver/FeatureGenerator.java | 3 +- .../tycho/p2resolver/P2GeneratorImpl.java | 6 ++-- .../p2tools/MirrorApplicationServiceImpl.java | 8 +++-- .../p2tools/RepositoryReferenceTool.java | 7 +++-- .../tests/spi/TychoTargetLocationLoader.java | 6 ++-- .../tycho/core/locking/LockProcess.java | 9 ++---- .../MetadataSerializableImplTest.java | 4 ++- .../ModuleArtifactRepositoryTest.java | 3 +- .../runner/ConvertSchemaToHtmlRunner.java | 5 ++-- .../tycho/versionbump/UpdateTargetMojo.java | 6 ++-- .../security/storage/StorageUtils.java | 26 ++++++++-------- .../tycho/test/util/TargetDefinitionUtil.java | 8 +++-- .../plugins/p2/CategoryP2MetadataMojo.java | 4 ++- .../p2/repository/MavenP2SiteMojo.java | 22 ++++++++------ .../tycho/packaging/PackagePluginMojo.java | 15 +++++----- ...avenCentralArtifactCoordinateResolver.java | 6 ++-- .../eclipse/tycho/source/OsgiSourceMojo.java | 11 +++---- .../tycho/source/SourceFeatureMojo.java | 4 ++- .../surefire/AbstractEclipseTestMojo.java | 9 +++--- .../eclipse/tycho/surefire/BndTestMojo.java | 10 ++++--- .../tycho/versions/engine/TargetFiles.java | 5 ++-- 30 files changed, 148 insertions(+), 107 deletions(-) diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/FtpTransportProtocolHandler.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/FtpTransportProtocolHandler.java index 15f375176d..89f431daec 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/FtpTransportProtocolHandler.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/FtpTransportProtocolHandler.java @@ -1,14 +1,13 @@ package org.eclipse.tycho.p2maven.transport; -import org.apache.commons.io.FileUtils; -import org.apache.commons.net.ftp.*; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable; -import org.eclipse.tycho.MavenRepositorySettings.Credentials; +import static java.lang.String.format; -import java.io.*; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; import java.net.SocketException; import java.net.URI; import java.nio.file.Files; @@ -16,7 +15,18 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import static java.lang.String.format; +import org.apache.commons.io.FileUtils; +import org.apache.commons.net.ftp.FTP; +import org.apache.commons.net.ftp.FTPClient; +import org.apache.commons.net.ftp.FTPCmd; +import org.apache.commons.net.ftp.FTPConnectionClosedException; +import org.apache.commons.net.ftp.FTPFile; +import org.apache.commons.net.ftp.FTPReply; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable; +import org.eclipse.tycho.MavenRepositorySettings.Credentials; /** * Handles files discovery over the FTP protocol. @@ -93,7 +103,7 @@ public File getFile(final URI uri) throws IOException { final File tempFile = Files.createTempFile(parent.toPath(), "download", ".tmp").toFile(); tempFile.deleteOnExit(); - try (final OutputStream os = new FileOutputStream(tempFile)) { + try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(tempFile))) { if (!client.retrieveFile(remotePath, os)) { final String message = client.getReplyString(); throw new IOException(format("Error retrieving file: %s. Message: %s", remotePath, message)); diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/SharedHttpCacheStorage.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/SharedHttpCacheStorage.java index bd173b2153..b39b3c556c 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/SharedHttpCacheStorage.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/SharedHttpCacheStorage.java @@ -12,11 +12,13 @@ *******************************************************************************/ package org.eclipse.tycho.p2maven.transport; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URI; import java.text.DateFormat; @@ -72,7 +74,7 @@ protected boolean removeEldestEntry(final Map.Entry eldest) { /** * Fetches the cache entry for this URI - * + * * @param uri * @return * @throws FileNotFoundException if the URI is know to be not found @@ -266,7 +268,7 @@ public synchronized File fetchFile(URI uri, HttpTransportFactory transportFactor } response.checkResponseCode(); tempFile = File.createTempFile("download", ".tmp", file.getParentFile()); - try (FileOutputStream os = new FileOutputStream(tempFile)) { + try (OutputStream os = new BufferedOutputStream(new FileOutputStream(tempFile))) { response.transferTo(os); } catch (IOException e) { tempFile.delete(); @@ -390,7 +392,7 @@ protected void updateHeader(Headers response, int code) throws IOException, File } } FileUtils.forceMkdir(file.getParentFile()); - try (FileOutputStream out = new FileOutputStream(headerFile)) { + try (OutputStream out = new BufferedOutputStream(new FileOutputStream(headerFile))) { // we store the header here, this might be a 404 response or (permanent) // redirect we probably need to work with later on header.store(out, null); diff --git a/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxInstallationFactory.java b/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxInstallationFactory.java index c0cbaf8c69..a767a42df4 100644 --- a/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxInstallationFactory.java +++ b/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxInstallationFactory.java @@ -150,7 +150,7 @@ public EquinoxInstallation createInstallation(EquinoxInstallationDescription des File configIni = new File(location, TychoConstants.CONFIG_INI_PATH); File configurationLocation = configIni.getParentFile(); configurationLocation.mkdirs(); - try (FileOutputStream fos = new FileOutputStream(configIni)) { + try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(configIni))) { p.store(fos, null); } @@ -201,7 +201,7 @@ private Manifest getManifest(File file) throws IOException { /** * See - * + * *
      * https://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html#osgidev
      * 
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/EcJLogFileEnhancer.java b/tycho-core/src/main/java/org/eclipse/tycho/core/EcJLogFileEnhancer.java index 69b8c9cd30..3b6198512a 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/EcJLogFileEnhancer.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/EcJLogFileEnhancer.java @@ -14,11 +14,10 @@ import java.io.File; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -93,7 +92,7 @@ private static void writeDocuments(Set needsUpdate, Map do throws IOException, FileNotFoundException { for (File file : needsUpdate) { Document document = documents.get(file); - try (Writer w = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); + try (Writer w = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8); XMLWriter xw = new XMLWriter(w)) { document.toXML(xw); } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java b/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java index e3126fbe2d..f044041a33 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java @@ -17,9 +17,8 @@ import java.io.BufferedWriter; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStreamWriter; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -132,7 +131,7 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti try { validate(projects); - // setting this system property to let EF figure out where the traffic + // setting this system property to let EF figure out where the traffic // is coming from (#467418) System.setProperty(P2_USER_AGENT_KEY, P2_USER_AGENT_VALUE + TychoVersion.getTychoVersion()); @@ -166,8 +165,8 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti Set visited = new HashSet<>(); modelWriter.write(new File(project.getBasedir(), "pom-model.xml"), Map.of(), project.getModel()); - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(new File(project.getBasedir(), "requirements.txt"))))) { + try (BufferedWriter writer = Files.newBufferedWriter( + new File(project.getBasedir(), "requirements.txt").toPath())) { writer.write(project.getId() + ":\r\n"); dumpProjectRequirements(project, writer, closure, dependencyProjects, "\t", visited); @@ -182,7 +181,7 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti } } catch (BuildFailureException e) { // build failure is not an internal (unexpected) error, so avoid printing a stack - // trace by wrapping it in MavenExecutionException + // trace by wrapping it in MavenExecutionException throw new MavenExecutionException(e.getMessage(), e); } buildListeners.notifyBuildStart(session); diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/MavenTargetDefinitionContent.java b/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/MavenTargetDefinitionContent.java index cf11df5d2f..283b1c5234 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/MavenTargetDefinitionContent.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/MavenTargetDefinitionContent.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.tycho.core.resolver; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -368,7 +369,8 @@ private IInstallableUnit generateSourceBundle(String symbolicName, String bundle attr.putValue(Constants.BUNDLE_NAME, "Source Bundle for " + symbolicName + ":" + bundleVersion); attr.putValue(Constants.BUNDLE_SYMBOLICNAME, symbolicName + ".source"); attr.putValue(Constants.BUNDLE_VERSION, bundleVersion); - try (JarOutputStream stream = new JarOutputStream(new FileOutputStream(tempFile), manifest)) { + try (JarOutputStream stream = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempFile)), + manifest)) { try (JarFile jar = new JarFile(sourceFile)) { Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/ArtifactRepositoryBaseImpl.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/ArtifactRepositoryBaseImpl.java index bbdbc5be10..c99851bc6f 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/ArtifactRepositoryBaseImpl.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/ArtifactRepositoryBaseImpl.java @@ -17,6 +17,7 @@ import static org.eclipse.tycho.p2.repository.ArtifactProviderImplUtilities.canWriteToSink; import static org.eclipse.tycho.p2.repository.BundleConstants.BUNDLE_ID; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -440,7 +441,7 @@ public OutputStream beginWrite() throws IllegalStateException, ArtifactSinkExcep artifactFile.getParentFile().mkdirs(); try { - currentOutputStream = new FileOutputStream(artifactFile); + currentOutputStream = new BufferedOutputStream(new FileOutputStream(artifactFile)); } catch (FileNotFoundException e) { throw new ArtifactSinkException("I/O error while creating artifact file " + artifactFile, e); } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/FileBasedTychoRepositoryIndex.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/FileBasedTychoRepositoryIndex.java index a88db13366..1e1cbb527c 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/FileBasedTychoRepositoryIndex.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/FileBasedTychoRepositoryIndex.java @@ -110,7 +110,7 @@ public synchronized void save() throws IOException { reconcile(); // minimize time window for corrupting the file by first writing to a temp file, then moving it File tempFile = File.createTempFile("index", "tmp", indexFile.getParentFile()); - write(new FileOutputStream(tempFile)); + write(new BufferedOutputStream(new FileOutputStream(tempFile))); if (indexFile.isFile()) { indexFile.delete(); } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/module/ModuleArtifactMap.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/module/ModuleArtifactMap.java index 8c566bcc96..f4a78de6ca 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/module/ModuleArtifactMap.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/module/ModuleArtifactMap.java @@ -14,10 +14,12 @@ import static org.eclipse.tycho.p2.repository.BundleConstants.BUNDLE_ID; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; @@ -34,7 +36,7 @@ /** * {@link RepositoryReader} that reads the artifact file locations from the * "local-artifacts.properties" file. - * + * * @see TychoConstants#FILE_NAME_LOCAL_ARTIFACTS */ class ModuleArtifactMap { @@ -56,7 +58,7 @@ public static ModuleArtifactMap createInstance(File repositoryRoot) throws Provi } private ModuleArtifactMap(File repositoryRoot) { - // TODO constant FILE_NAME_LOCAL_ARTIFACTS should only be needed here + // TODO constant FILE_NAME_LOCAL_ARTIFACTS should only be needed here this.mapFile = new File(repositoryRoot, TychoConstants.FILE_NAME_LOCAL_ARTIFACTS); this.automaticArtifactFolder = new File(repositoryRoot, "extraArtifacts"); } @@ -143,7 +145,8 @@ private void store() throws ProvisionException { if (entry.getKey() == null) { outputProperties.put(TychoConstants.KEY_ARTIFACT_MAIN, entry.getValue().getAbsolutePath()); } else { - outputProperties.put(TychoConstants.KEY_ARTIFACT_ATTACHED + entry.getKey(), entry.getValue().getAbsolutePath()); + outputProperties.put(TychoConstants.KEY_ARTIFACT_ATTACHED + entry.getKey(), + entry.getValue().getAbsolutePath()); } } @@ -159,7 +162,7 @@ private void store() throws ProvisionException { } private static void writeProperties(Properties properties, File outputFile) throws IOException { - try (FileOutputStream outputStream = new FileOutputStream(outputFile);) { + try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile))) { properties.store(outputStream, null); } } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/FeatureGenerator.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/FeatureGenerator.java index b9a0c459cf..73db3f33c2 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/FeatureGenerator.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/FeatureGenerator.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.tycho.p2.resolver; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -108,7 +109,7 @@ private static Feature createFeature(Element featureElement, List artifactLo } private static void writeProperties(Properties properties, File outputFile) throws IOException { - try (FileOutputStream outputStream = new FileOutputStream(outputFile)) { + try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile))) { properties.store(outputStream, null); } } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java index fc91096441..e9565dac03 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java @@ -13,9 +13,11 @@ *******************************************************************************/ package org.eclipse.tycho.p2tools; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URI; import java.net.URLConnection; @@ -521,7 +523,8 @@ private void writeP2Index(File repositoryDestination) throws FacadeException { properties.setProperty("version", "1"); properties.setProperty("artifact.repository.factory.order", "artifacts.xml,!"); properties.setProperty("metadata.repository.factory.order", "content.xml,!"); - try (FileOutputStream stream = new FileOutputStream(new File(repositoryDestination, P2_INDEX_FILE))) { + try (OutputStream stream = new BufferedOutputStream( + new FileOutputStream(new File(repositoryDestination, P2_INDEX_FILE)))) { properties.store(stream, null); } catch (IOException e) { throw new FacadeException("writing index file failed", e); @@ -531,7 +534,8 @@ private void writeP2Index(File repositoryDestination) throws FacadeException { private void compressXml(File repositoryDestination, String name) throws FacadeException { File jarFile = new File(repositoryDestination, name + ".jar"); File xmlFile = new File(repositoryDestination, name + ".xml"); - try (JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(jarFile))) { + try (JarOutputStream jarOutputStream = new JarOutputStream( + new BufferedOutputStream(new FileOutputStream(jarFile)))) { jarOutputStream.putNextEntry(new JarEntry(xmlFile.getName())); Files.copy(xmlFile.toPath(), jarOutputStream); } catch (IOException e) { diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/RepositoryReferenceTool.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/RepositoryReferenceTool.java index 4a49f823bf..e79dcbf5cf 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/RepositoryReferenceTool.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/RepositoryReferenceTool.java @@ -12,9 +12,11 @@ *******************************************************************************/ package org.eclipse.tycho.p2tools; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; @@ -77,7 +79,7 @@ public class RepositoryReferenceTool { *
  • The results of the referenced reactor modules, *
  • The non-reactor content of the module's target platform. * - * + * * @param module * The current Maven project * @param session @@ -120,7 +122,8 @@ private void addTargetPlatformRepository(RepositoryReferences sources, MavenSess try { File repositoryLocation = new File(project.getBuild().getDirectory(), "targetPlatformRepository"); repositoryLocation.mkdirs(); - try (FileOutputStream stream = new FileOutputStream(new File(repositoryLocation, "content.xml"))) { + try (OutputStream stream = new BufferedOutputStream( + new FileOutputStream(new File(repositoryLocation, "content.xml")))) { TargetPlatform targetPlatform = projectManager.getTargetPlatform(project) .orElseThrow(() -> new MojoFailureException(TychoConstants.TYCHO_NOT_CONFIGURED + project)); diff --git a/tycho-core/src/test/java/org/eclipse/m2e/pde/target/tests/spi/TychoTargetLocationLoader.java b/tycho-core/src/test/java/org/eclipse/m2e/pde/target/tests/spi/TychoTargetLocationLoader.java index 378047f603..b7bb94e7ac 100644 --- a/tycho-core/src/test/java/org/eclipse/m2e/pde/target/tests/spi/TychoTargetLocationLoader.java +++ b/tycho-core/src/test/java/org/eclipse/m2e/pde/target/tests/spi/TychoTargetLocationLoader.java @@ -12,10 +12,9 @@ *******************************************************************************/ package org.eclipse.m2e.pde.target.tests.spi; +import java.io.BufferedWriter; import java.io.File; -import java.io.FileOutputStream; import java.io.InputStream; -import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -75,8 +74,7 @@ public int getPriority() { @Override public ITargetLocation resolveMavenTarget(String targetXML, File tempDir) throws Exception { File targetFile = new File(tempDir, "test.target"); - try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(targetFile), - StandardCharsets.UTF_8)) { + try (BufferedWriter writer = Files.newBufferedWriter(targetFile.toPath(), StandardCharsets.UTF_8)) { writer.write(""); writer.write(targetXML); writer.write(""); diff --git a/tycho-core/src/test/java/org/eclipse/tycho/core/locking/LockProcess.java b/tycho-core/src/test/java/org/eclipse/tycho/core/locking/LockProcess.java index 9c1a00ad25..bf77ccc37b 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/core/locking/LockProcess.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/core/locking/LockProcess.java @@ -13,6 +13,7 @@ package org.eclipse.tycho.core.locking; +import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -95,12 +96,8 @@ private void copyClassFile() { String classNamePath = LockProcess.class.getName().replace('.', '/') + ".class"; File tmpClassFile = new File(tmpClassDir, classNamePath); tmpClassFile.getParentFile().mkdirs(); - try (OutputStream out = new FileOutputStream(tmpClassFile)) { - byte[] buffer = new byte[1024]; - int read = 0; - while ((read = in.read(buffer, 0, buffer.length)) != -1) { - out.write(buffer, 0, read); - } + try (OutputStream out = new BufferedOutputStream(new FileOutputStream(tmpClassFile))) { + in.transferTo(out); in.close(); } } catch (IOException e) { diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/MetadataSerializableImplTest.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/MetadataSerializableImplTest.java index fc9a99874d..05f398173f 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/MetadataSerializableImplTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/MetadataSerializableImplTest.java @@ -14,10 +14,12 @@ import static org.junit.Assert.assertEquals; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -84,7 +86,7 @@ private Set deserialize(File tmpDir) throws ProvisionException private void serialize(MetadataSerializableImpl subject, Set units, File tmpDir) throws FileNotFoundException, IOException { - try (FileOutputStream os = new FileOutputStream(new File(tmpDir, "content.xml"))) { + try (OutputStream os = new BufferedOutputStream(new FileOutputStream(new File(tmpDir, "content.xml")))) { subject.serialize(os, units); } } diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/ModuleArtifactRepositoryTest.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/ModuleArtifactRepositoryTest.java index db6d10bff5..c5d7c3df32 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/ModuleArtifactRepositoryTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/ModuleArtifactRepositoryTest.java @@ -236,8 +236,7 @@ private static void generateDefaultRepositoryArtifacts(File location) throws IOE private static void generateBinaryTestFile(File file, int size) throws IOException { file.getParentFile().mkdirs(); - try (FileOutputStream fos = new FileOutputStream(file)) { - OutputStream os = new BufferedOutputStream(fos); + try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { for (int i = 0; i < size; ++i) { os.write(0); } diff --git a/tycho-extras/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/runner/ConvertSchemaToHtmlRunner.java b/tycho-extras/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/runner/ConvertSchemaToHtmlRunner.java index bb94a85fc9..12bdf69fb7 100644 --- a/tycho-extras/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/runner/ConvertSchemaToHtmlRunner.java +++ b/tycho-extras/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/runner/ConvertSchemaToHtmlRunner.java @@ -17,14 +17,13 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Serializable; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -146,7 +145,7 @@ public ISchema createSchema(ISchemaDescriptor descriptor, String location) { } File file = new File(directory, id.replace('.', '_') + ".html"); //$NON-NLS-1$ try (PrintWriter out = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8), true)) { + Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8), true)) { fTransformer.transform(schema, out, cssURL, SchemaTransformer.BUILD); } } finally { diff --git a/tycho-extras/tycho-version-bump-plugin/src/main/java/org/eclipse/tycho/versionbump/UpdateTargetMojo.java b/tycho-extras/tycho-version-bump-plugin/src/main/java/org/eclipse/tycho/versionbump/UpdateTargetMojo.java index c296b2a938..bd60b13ed8 100644 --- a/tycho-extras/tycho-version-bump-plugin/src/main/java/org/eclipse/tycho/versionbump/UpdateTargetMojo.java +++ b/tycho-extras/tycho-version-bump-plugin/src/main/java/org/eclipse/tycho/versionbump/UpdateTargetMojo.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.tycho.versionbump; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -47,7 +48,7 @@ /** * This allows to update a target file to use newer version of specified items, e.g. IUs from * updatesites or maven coordinates. In the simplest form this is called like - * + * *
      * mvn -f [path to target project] tycho-version-bump:update-target
      * 
    @@ -162,7 +163,8 @@ protected void doUpdate(File file) throws Exception { } if (changed) { String enc = target.getEncoding() != null ? target.getEncoding() : "UTF-8"; - try (Writer w = new OutputStreamWriter(new FileOutputStream(file), enc); XMLWriter xw = new XMLWriter(w)) { + try (Writer w = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), enc); + XMLWriter xw = new XMLWriter(w)) { try { target.toXML(xw); } finally { diff --git a/tycho-its/projects/resolver.split/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/StorageUtils.java b/tycho-its/projects/resolver.split/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/StorageUtils.java index b5e707ad8a..f49d75cef3 100644 --- a/tycho-its/projects/resolver.split/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/StorageUtils.java +++ b/tycho-its/projects/resolver.split/org.eclipse.equinox.security/src/org/eclipse/equinox/internal/security/storage/StorageUtils.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -22,13 +22,13 @@ /** * PLEASE READ BEFORE CHANGING THIS FILE - * + * * At present most of the methods expect only file URLs. The API methods * take URLs for possible future expansion, and there is some code below * that would work with some other URL types, but the only supported URL * types at this time are file URLs. Also note that URL paths should not - * be encoded (spaces should be spaces, not "%x20"). - * + * be encoded (spaces should be spaces, not "%x20"). + * * On encoding: Java documentation recommends using File.toURI().toURL(). * However, in this process non-alphanumeric characters (including spaces) * get encoded and can not be used with the rest of Eclipse methods that @@ -73,10 +73,10 @@ static public OutputStream getOutputStream(URL url) throws IOException { if (parent != null && !parent.exists()) parent.mkdirs(); } - return new FileOutputStream(file); + return new BufferedOutputStream(new FileOutputStream(file)); } - // note that code below does not work for File URLs - "by design" Java - // does not support creating output streams on file URLs. Code below should work + // note that code below does not work for File URLs - "by design" Java + // does not support creating output streams on file URLs. Code below should work // for HTTP URLs; no idea as to the other types of URLs URLConnection connection = url.openConnection(); connection.setDoOutput(true); @@ -89,7 +89,7 @@ static public InputStream getInputStream(URL url) throws IOException { try { return url.openStream(); } catch (FileNotFoundException e) { - return null; // this is all right, means new file + return null; // this is all right, means new file } } @@ -114,7 +114,7 @@ static public boolean isFile(URL url) { } /** - * The {@link String#getBytes()} truncates non-ASCII chars. As a result + * The {@link String#getBytes()} truncates non-ASCII chars. As a result * new String(string.getBytes()) is not the same as the original string. Moreover, * the default Java encoding can be changed via system variables or startup conditions. */ @@ -126,10 +126,10 @@ static public byte[] getBytes(String string) { /** * The new String(byte[]) method uses default system encoding which - * might not properly process non-ASCII characters. - * - * Pairing {@link #getBytes(String)} and {@link #getString(byte[])} methods allows round trip - * of non-ASCII characters. + * might not properly process non-ASCII characters. + * + * Pairing {@link #getBytes(String)} and {@link #getString(byte[])} methods allows round trip + * of non-ASCII characters. */ static public String getString(byte[] bytes) { if (bytes == null) diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/util/TargetDefinitionUtil.java b/tycho-its/src/test/java/org/eclipse/tycho/test/util/TargetDefinitionUtil.java index d856859e4d..670ed9791c 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/util/TargetDefinitionUtil.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/util/TargetDefinitionUtil.java @@ -13,10 +13,12 @@ *******************************************************************************/ package org.eclipse.tycho.test.util; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.net.URI; import java.net.URISyntaxException; @@ -55,7 +57,7 @@ public static void makeURLsAbsolute(File targetDefinitionFile, File relocationBa repository.setAttribute("location", relocationBasedir.toURI().resolve(repositoryURL).toString()); } } - try (FileOutputStream output = new FileOutputStream(targetDefinitionFile)) { + try (OutputStream output = new BufferedOutputStream(new FileOutputStream(targetDefinitionFile))) { TargetDefinitionFile.writeDocument(platform, output); } } @@ -83,7 +85,7 @@ public static void setRepositoryURLs(File targetDefinitionFile, String url) } } } - try (FileOutputStream output = new FileOutputStream(targetDefinitionFile)) { + try (OutputStream output = new BufferedOutputStream(new FileOutputStream(targetDefinitionFile))) { TargetDefinitionFile.writeDocument(platform, output); } } @@ -110,7 +112,7 @@ public static void setRepositoryURLs(File targetDefinitionFile, String repositor } } } - try (FileOutputStream output = new FileOutputStream(targetDefinitionFile)) { + try (OutputStream output = new BufferedOutputStream(new FileOutputStream(targetDefinitionFile))) { TargetDefinitionFile.writeDocument(platform, output); } } diff --git a/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/CategoryP2MetadataMojo.java b/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/CategoryP2MetadataMojo.java index 4138fc5c90..734f737ab8 100644 --- a/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/CategoryP2MetadataMojo.java +++ b/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/CategoryP2MetadataMojo.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.tycho.plugins.p2; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -76,7 +77,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { try { if (jar && xmlFile.exists()) { //need to recreate the jar - try (JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(jarFile))) { + try (JarOutputStream jarOutputStream = new JarOutputStream( + new BufferedOutputStream(new FileOutputStream(jarFile)))) { jarOutputStream.putNextEntry(new JarEntry(xmlFile.getName())); Files.copy(xmlFile.toPath(), jarOutputStream); } diff --git a/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/MavenP2SiteMojo.java b/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/MavenP2SiteMojo.java index cd3d935c85..43f51872b7 100644 --- a/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/MavenP2SiteMojo.java +++ b/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/MavenP2SiteMojo.java @@ -12,15 +12,16 @@ *******************************************************************************/ package org.eclipse.tycho.plugins.p2.repository; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -85,7 +86,7 @@ *
  • The metadata of the page is attached to the current project with type=zip and * classifier=p2site and could be deployed using standard maven techniques
  • * - * + * * Please note: Only valid OSGi bundles are included, there is no way to automatically wrap * plain jars and they are silently ignored. This is intentional, as the goal of a p2-maven-site is * to use exactly the same artifact that is deployed in the maven repository. @@ -93,7 +94,7 @@ *

    * The produced p2-maven-site can then be consumed by Tycho or PDE targets (m2eclipse is required * for this), in the following way: A tycho-repository section: - * + * *

         <repository>
         <id>my-p2-maven-site
    @@ -101,9 +102,9 @@
             <layout>p2
         </repository>
      * 
    - * + * * A target location of type software-site: - * + * *
      *  <location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
             <repository location="mvn:[groupId]:[artifactId]:[version]:zip:p2site"/>
    @@ -190,7 +191,7 @@ public class MavenP2SiteMojo extends AbstractMojo {
     
         /**
          * The output directory of the jar file
    -     * 
    +     *
          * By default this is the Maven "target/" directory.
          */
         @Parameter(property = "project.build.directory", required = true)
    @@ -271,7 +272,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
                 try {
                     File categoryGenFile = File.createTempFile("category", ".xml");
                     try (PrintWriter writer = new PrintWriter(
    -                        new OutputStreamWriter(new FileOutputStream(categoryGenFile), StandardCharsets.UTF_8))) {
    +                        Files.newBufferedWriter(categoryGenFile.toPath(), StandardCharsets.UTF_8))) {
                         writer.println("");
                         writer.println("");
                         writer.println("");
    @@ -344,7 +345,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
                     publicKeysFile = File.createTempFile("publicKeys", ".pgp");
                     publicKeysFile.deleteOnExit();
                     PGPPublicKeyRingCollection collection = new PGPPublicKeyRingCollection(publicKeys.values());
    -                try (OutputStream out = new ArmoredOutputStream(new FileOutputStream(publicKeysFile))) {
    +                try (OutputStream out = new ArmoredOutputStream(
    +                        new BufferedOutputStream(new FileOutputStream(publicKeysFile)))) {
                         collection.encode(out);
                     }
                     arguments.add("-publicKeys");
    @@ -468,7 +470,9 @@ protected File createMavenAdvice(Artifact artifact) throws MojoExecutionExceptio
                 addProvidesAndProperty(properties, TychoConstants.PROP_EXTENSION, artifact.getType(), cnt++);
                 addProvidesAndProperty(properties, TychoConstants.PROP_CLASSIFIER, artifact.getClassifier(), cnt++);
                 addProvidesAndProperty(properties, "maven-scope", artifact.getScope(), cnt++);
    -            properties.store(new FileOutputStream(p2), null);
    +            try (OutputStream os = new BufferedOutputStream(new FileOutputStream(p2))) {
    +                properties.store(os, null);
    +            }
                 return p2;
             } catch (IOException e) {
                 throw new MojoExecutionException("failed to generate p2.inf", e);
    diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java
    index debb862271..a4ee87780d 100644
    --- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java
    +++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java
    @@ -10,7 +10,7 @@
      * Contributors:
      *    Sonatype Inc. - initial API and implementation
      *    Christoph Läubrich 	- Issue #177 - Automatically translate maven-pom information to osgi Bundle-Header
    - *    						- Issue #572 - Insert dynamic dependencies into the jar included pom 
    + *    						- Issue #572 - Insert dynamic dependencies into the jar included pom
      *******************************************************************************/
     package org.eclipse.tycho.packaging;
     
    @@ -20,6 +20,7 @@
     import java.io.FileOutputStream;
     import java.io.IOException;
     import java.io.InputStream;
    +import java.io.OutputStream;
     import java.util.ArrayList;
     import java.util.List;
     import java.util.Objects;
    @@ -87,7 +88,7 @@ public class PackagePluginMojo extends AbstractTychoPackagingMojo {
     	 * configuration is specified, the default value is true. If the
     	 * maven descriptor should not be added to the artifact, use the following
     	 * configuration:
    -	 * 
    +	 *
     	 * 
     	 * <plugin>
     	 *   <groupId>org.eclipse.tycho</groupId>
    @@ -110,19 +111,19 @@ public class PackagePluginMojo extends AbstractTychoPackagingMojo {
     	 * MANIFEST header. When using this parameter, property ${tycho.scmUrl} must be
     	 * set and be a valid
     	 * maven SCM URL.
    -	 * 
    +	 *
     	 * Example configuration:
    -	 * 
    +	 *
     	 * 
     	 *         <sourceReferences>
     	 *           <generate>true</generate>
     	 *         </sourceReferences>
     	 * 
    - * + * * Note that a {@link SourceReferencesProvider} component must be registered for * the SCM type being used. You may also override the generated value by * configuring: - * + * *
     	 *         <sourceReferences>
     	 *           <generate>true</generate>
    @@ -327,7 +328,7 @@ protected void writeManifest(File output, Manifest mf) throws IOException {
     		if (!parentFile.mkdirs() && !parentFile.exists()) {
     			throw new IOException("creating target directory " + parentFile.getAbsolutePath() + " failed");
     		}
    -		try (BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(output))) {
    +		try (OutputStream os = new BufferedOutputStream(new FileOutputStream(output))) {
     			mf.write(os);
     		}
     	}
    diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/reverseresolve/MavenCentralArtifactCoordinateResolver.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/reverseresolve/MavenCentralArtifactCoordinateResolver.java
    index e5612c915a..c1bae1b283 100644
    --- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/reverseresolve/MavenCentralArtifactCoordinateResolver.java
    +++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/reverseresolve/MavenCentralArtifactCoordinateResolver.java
    @@ -12,11 +12,13 @@
      *******************************************************************************/
     package org.eclipse.tycho.packaging.reverseresolve;
     
    +import java.io.BufferedOutputStream;
     import java.io.File;
     import java.io.FileInputStream;
     import java.io.FileOutputStream;
     import java.io.IOException;
     import java.io.InputStream;
    +import java.io.OutputStream;
     import java.nio.file.Files;
     import java.security.MessageDigest;
     import java.util.List;
    @@ -43,7 +45,7 @@
     import kong.unirest.json.JSONObject;
     
     /**
    - * 
    + *
      * Use the maven rest API to find an artifact based on its sha1 sum.
      */
     @Component(role = ArtifactCoordinateResolver.class, hint = "central")
    @@ -158,7 +160,7 @@ private void cacheResult(File cacheFile, Dependency dependency) {
     			properties.setProperty(KEY_ARTIFACT_ID, dependency.getArtifactId());
     			properties.setProperty(KEY_VERSION, dependency.getVersion());
     			properties.setProperty(KEY_TYPE, dependency.getType());
    -			try (FileOutputStream stream = new FileOutputStream(cacheFile)) {
    +			try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(cacheFile))) {
     				properties.store(stream, null);
     			}
     		} catch (IOException e) {
    diff --git a/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/OsgiSourceMojo.java b/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/OsgiSourceMojo.java
    index 257e3cffb4..7fc40f9717 100644
    --- a/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/OsgiSourceMojo.java
    +++ b/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/OsgiSourceMojo.java
    @@ -20,6 +20,7 @@
     import static org.osgi.framework.Constants.BUNDLE_VENDOR;
     import static org.osgi.framework.Constants.BUNDLE_VERSION;
     
    +import java.io.BufferedOutputStream;
     import java.io.File;
     import java.io.FileOutputStream;
     import java.io.IOException;
    @@ -137,10 +138,10 @@ public class OsgiSourceMojo extends AbstractSourceJarMojo {
     
         /**
          * Additional files to be included in the source bundle jar. This can be used when
    -     * src.includes in build.properties is not flexible enough , e.g. for files which would
    -     * otherwise conflict with files in bin.includes
    + * src.includes in build.properties is not flexible enough , e.g. for files which + * would otherwise conflict with files in bin.includes
    * Example:
    - * + * *
          * <additionalFileSets>
          *  <fileSet>
    @@ -148,7 +149,7 @@ public class OsgiSourceMojo extends AbstractSourceJarMojo {
          *   <includes>
          *    <include>**/*</include>
          *   </includes>
    -     *  </fileSet>     
    +     *  </fileSet>
          * </additionalFileSets>
          * 
    */ @@ -276,7 +277,7 @@ static Resource generateL10nFile(MavenProject project, Path basedir, UnaryOperat sourceL10nProps.setProperty(I18N_KEY_BUNDLE_VENDOR, bundleVendor); File l10nPropsFile = new File(l10nOutputDir, MANIFEST_BUNDLE_LOCALIZATION_FILENAME); l10nPropsFile.getParentFile().mkdirs(); - try (OutputStream out = new FileOutputStream(l10nPropsFile)) { + try (OutputStream out = new BufferedOutputStream(new FileOutputStream(l10nPropsFile))) { sourceL10nProps.store(out, "Source Bundle Localization"); } catch (IOException e) { throw new MojoExecutionException("error while generating source bundle localization file", e); diff --git a/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/SourceFeatureMojo.java b/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/SourceFeatureMojo.java index 0ef867fad2..3b79e99819 100644 --- a/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/SourceFeatureMojo.java +++ b/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/SourceFeatureMojo.java @@ -14,10 +14,12 @@ *******************************************************************************/ package org.eclipse.tycho.source; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -348,7 +350,7 @@ private static Properties readPropertiesIfExists(File propertiesFile) throws IOE private static void writeProperties(Properties props, File propertiesFile) throws IOException { propertiesFile.getParentFile().mkdirs(); - try (FileOutputStream out = new FileOutputStream(propertiesFile)) { + try (OutputStream out = new BufferedOutputStream(new FileOutputStream(propertiesFile))) { props.store(out, ""); } } diff --git a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractEclipseTestMojo.java b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractEclipseTestMojo.java index 1ea7408f8b..ce2bda839d 100644 --- a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractEclipseTestMojo.java +++ b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractEclipseTestMojo.java @@ -23,6 +23,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; @@ -515,7 +516,7 @@ public abstract class AbstractEclipseTestMojo extends AbstractTestMojo { /** * Additional root IUs to install, only relevant if {@link #testRuntime} is * p2Installed. - * + * *
          * <install>
          *    <iu>
    @@ -531,7 +532,7 @@ public abstract class AbstractEclipseTestMojo extends AbstractTestMojo {
         /**
          * Additional repositories used to install units from, only relevant if {@link #testRuntime} is
          * p2Installed.
    -     * 
    +     *
          * 
         * <repositories>
         *   <repository>
    @@ -539,7 +540,7 @@ public abstract class AbstractEclipseTestMojo extends AbstractTestMojo {
         *   </repository>
         * </repositories>
          * 
    - * + * */ @Parameter(name = "repositories") private List repositories; @@ -978,7 +979,7 @@ private void storeProperties(Map propertiesMap, File file) throw Properties p = new Properties(); p.putAll(propertiesMap); try { - try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { + try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { p.store(out, null); } } catch (IOException e) { diff --git a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/BndTestMojo.java b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/BndTestMojo.java index 54aa31856c..0ea221bc00 100644 --- a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/BndTestMojo.java +++ b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/BndTestMojo.java @@ -12,8 +12,10 @@ ******************************************************************************/ package org.eclipse.tycho.surefire; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; @@ -148,7 +150,7 @@ public class BndTestMojo extends AbstractTestMojo { /** * Configure the tester to use usually one of - * + * *
      *
    • {@value #TESTER_DEFAULT}
    • *
    • {@value #TESTER_JUNIT_PLATFORM}
    • @@ -167,7 +169,7 @@ public class BndTestMojo extends AbstractTestMojo { /** * Configure the run framework to use usually one of - * + * *
        *
      • {@value #FW_FELIX}
      • *
      • {@value #FW_EQUINOX}
      • @@ -186,7 +188,7 @@ public class BndTestMojo extends AbstractTestMojo { *
      • {@value #ENGINE_VINTAGE_ENGINE} - if your test only contains JUnit 3/4
      • *
      • {@value #ENGINES_DEFAULT} - if you want to use both engines
      • *
      - * + * */ @Parameter(defaultValue = ENGINES_DEFAULT, required = true) private String testEngines; @@ -230,7 +232,7 @@ protected void runTests(ScanResult scanResult) throws MojoExecutionException, Mo properties.setProperty(Constants.RUNFW, runfw); properties.setProperty(Constants.RUNPROPERTIES, buildRunProperties()); try { - try (FileOutputStream out = new FileOutputStream(runfile)) { + try (OutputStream out = new BufferedOutputStream(new FileOutputStream(runfile))) { properties.store(out, null); } String javaExecutable = getJavaExecutable(); diff --git a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/TargetFiles.java b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/TargetFiles.java index 90abc2de45..c2814b0789 100644 --- a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/TargetFiles.java +++ b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/TargetFiles.java @@ -6,12 +6,13 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * Christoph Läubrich - initial API and implementation *******************************************************************************/ package org.eclipse.tycho.versions.engine; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -52,7 +53,7 @@ public void write(File targetFile) throws IOException { private void writeTarget(File targetFile, Document document) throws IOException, UnsupportedEncodingException, FileNotFoundException { String enc = document.getEncoding() != null ? document.getEncoding() : "UTF-8"; - try (Writer w = new OutputStreamWriter(new FileOutputStream(targetFile), enc); + try (Writer w = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(targetFile)), enc); XMLWriter xw = new XMLWriter(w)) { try { document.toXML(xw);