Skip to content

Commit

Permalink
buffer file outputs
Browse files Browse the repository at this point in the history
This makes "Resolving MavenDependencyRoots..." output somewhat faster on
my machine.
  • Loading branch information
Bananeweizen authored and laeubi committed Oct 26, 2024
1 parent a999b6d commit dfab8b7
Show file tree
Hide file tree
Showing 30 changed files with 148 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
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;
import java.time.Duration;
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.
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,7 +74,7 @@ protected boolean removeEldestEntry(final Map.Entry<File, CacheLine> eldest) {

/**
* Fetches the cache entry for this URI
*
*
* @param uri
* @return
* @throws FileNotFoundException if the URI is know to be not found
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -201,7 +201,7 @@ private Manifest getManifest(File file) throws IOException {

/**
* See
*
*
* <pre>
* https://help.eclipse.org/latest/topic/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html#osgidev
* </pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,7 +92,7 @@ private static void writeDocuments(Set<File> needsUpdate, Map<File, Document> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,7 +128,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());

Expand Down Expand Up @@ -163,8 +162,8 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
Set<MavenProject> 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);
Expand All @@ -179,7 +178,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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");
}
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,7 +103,7 @@ private static Feature createFeature(Element featureElement, List<IInstallableUn
}
File tempFile = File.createTempFile("feature", ".jar");
tempFile.deleteOnExit();
try (JarOutputStream stream = new JarOutputStream(new FileOutputStream(tempFile))) {
try (JarOutputStream stream = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempFile)))) {
stream.putNextEntry(new ZipEntry(FEATURE_XML_ENTRY));
OutputStreamWriter writer = new OutputStreamWriter(stream);
prettyPrintXml(doc, writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
*******************************************************************************/
package org.eclipse.tycho.p2resolver;

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.HashMap;
Expand Down Expand Up @@ -54,7 +56,6 @@
import org.eclipse.equinox.p2.publisher.IPublisherResult;
import org.eclipse.equinox.p2.publisher.PublisherInfo;
import org.eclipse.equinox.p2.publisher.actions.IFeatureRootAdvice;
import org.eclipse.tycho.p2maven.tmp.BundlesAction;
import org.eclipse.equinox.p2.publisher.eclipse.Feature;
import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
Expand Down Expand Up @@ -92,6 +93,7 @@
import org.eclipse.tycho.p2maven.actions.CategoryDependenciesAction;
import org.eclipse.tycho.p2maven.actions.ProductDependenciesAction;
import org.eclipse.tycho.p2maven.actions.ProductFile2;
import org.eclipse.tycho.p2maven.tmp.BundlesAction;
import org.osgi.framework.BundleException;

@Component(role = P2Generator.class)
Expand Down Expand Up @@ -485,7 +487,7 @@ static void writeArtifactLocations(File outputFile, Map<String, File> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,7 +79,7 @@ public class RepositoryReferenceTool {
* <li>The results of the referenced reactor modules,
* <li>The non-reactor content of the module's target platform.
* </ol>
*
*
* @param module
* The current Maven project
* @param session
Expand Down Expand Up @@ -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));
Expand Down
Loading

0 comments on commit dfab8b7

Please sign in to comment.