Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ApacheCommonsFileUtils WriteStringToFile Refaster templates #278

Merged
merged 9 commits into from
Sep 14, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.nio.file.Files;

public class ApacheCommonsFileUtils {
private static class GetFile {
Expand Down Expand Up @@ -47,5 +48,18 @@ File after(String name) {
// }
// }

@SuppressWarnings("deprecation")
private static class WriteStringToFile {
@BeforeTemplate
void before(File a, String s) throws Exception {
FileUtils.writeStringToFile(a, s);
}

@AfterTemplate
void after(File a, String s) throws Exception {
Files.write(a.toPath(), s.getBytes());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, AFAICT. We could also add additional recipes to cover some of the other signatures (like writeStringToFile(File, String, boolean), writeStringToFile(File, String, Charset), and writeStringToFile(File, String, Charset, boolean)). But it is probably worth doing a search in the SaaS to check how often these get used. Probably they could all be covered by the same recipe, just using different before templates (all with the same input signatures).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I'll check the SaaS and see how often these overloads get used. I wanted to make sure this first template was accurate before worrying about overloads.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we could use a few more overloads here and merge those separate from the above CopyDirectory. Would you mind finishing this one @AlekSimpson ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would also be good to add a single document example test that shows which variants are replaced.

}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void bar(File fileA, File fileB, URL url, Charset cs, FileFilter filter, CharSeq
import java.io.FileFilter;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -142,7 +143,7 @@ void bar(File fileA, File fileB, URL url, Charset cs, FileFilter filter, CharSeq
strList = FileUtils.readLines(fileA, cs);
FileUtils.writeByteArrayToFile(fileA, bytes);
FileUtils.writeLines(fileA, collection);
FileUtils.writeStringToFile(fileA, s);
Files.write(fileA.toPath(), s.getBytes());
}
}
"""
Expand Down
Loading