Code Monkey home page Code Monkey logo

cake.filehelpers's Introduction

Cake.FileHelpers

A set of aliases for http://cakebuild.net to help with simple File operations such as Reading, Writing and Replacing text.

You can easily reference Cake.FileHelpers directly in your build script via a cake addin:

#addin "Cake.FileHelpers"

Aliases

Please visit the Cake Documentation for a list of available aliases:

http://cakebuild.net/dsl/file-helpers

Discussion

For questions and to discuss ideas & feature requests, use the GitHub discussions on the Cake GitHub repository, under the Extension Q&A category.

Join in the discussion on the Cake repository

Apache License 2.0

Apache Cake.FileHelpers Copyright 2015. The Apache Software Foundation This product includes software developed at The Apache Software Foundation (http://www.apache.org/).

cake.filehelpers's People

Contributors

ap0llo avatar augustoproiete avatar dependabot[bot] avatar devlead avatar erikschierboom avatar gep13 avatar ghuntley avatar gitfool avatar gudahtt avatar jericho avatar jtone123 avatar nils-a avatar redth avatar skovsende-simcorp avatar squid-box avatar twenzel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cake.filehelpers's Issues

Add overloads to allow specify multiple replacements

Another improvement would be to add overloads for all Replace aliases to pass multiple replacements - for both simple and regex replacements.
The current aliases would simply delegate to these new aliases, depending on implementation and whether or not you want to maintain backwards compat.

Cake.FileHelpers update reference to Cake.Core version 0.28.0

Hello,

I am trying to run a build.cake file on my mac, and I am keep getting this error. How can I manually update the references, or is there a plan to update in a near future?

The assembly 'Cake.FileHelpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null' is referencing an older version of Cake.Core (0.26.1). For best compatibility it should target Cake.Core version 0.28.0. Could not load /Users/johnsmith/tmp/project/src/tools/Addins/Cake.Powershell.0.4.6/lib/net46/System.Management.Automation.dll (missing Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35))

Thank you for you help,

Regards, Tony

Support .NET Core

I would really like to use this addin from my Cake.CoreCLR project, however this is not possible at the moment. I would be happy to tried and create a PR to make it .NET Core compatible, but that would involve converting the projects to the new .NET SDK, which means that the .csproj files will change. Not only that, but they can then only be opened in Visual Studio 2017, although then can of course be run using the .NET CLI. Is this something you would be interested in?

Compatibility with latest cake release 0.22.0

Hi, Cake.FileHelpers doesn't appear to be compatible with 0.22.0 build of cake (now in public nuget channel) I've pinned our current builds of cake to 0.21.1 which was the last working build. Is there any current plan to recompile against the new version of Cake.Core?

FileFilterExclude / FileFilterInclude

Hi folks,

I needed a functionality to filter a set of files (FilePathCollection) given by an array of wildcard path strings, e.g:

string[] filter= new string[] {
            @"**/*.gif",
            @"**/*.jpg",
            @"**/*.png"
        };

Specifically I needed the possibility to get all the files that match the filter criteria (IncludeFiles) and on the opposite to get all the files that do NOT match the filter criteria (ExcludeFiles).

Unfortunately I'm not familiar with pull requests - but if any one is interested feel free to include the attached methods in this library!

FileFilter.txt

Add "Remove ReadOnly-Attribute" method

I raise this issue as a result of a gitter discussion.

My scenario: I have a couple of .config files checked in the source control (TFS VC), which needs to be replaced (or re-generated) before I invoke MSBuild.
I use "DeleteFiles" and/or "CleanDirectories" for this kind of stuff from Cake, but both will fail because they refuse to delete "read-only" protected files.

Gary told me that this behavior is by design and is in most cases the logical choice. He pointed me to the FileHelper addin - maybe this would be a good place for this kind of functionality.

My current workaround is trivial:

public void EnsureFileIsWritable(string filePath)
{
    System.IO.File.SetAttributes(filePath, FileAttributes.Normal);
}

If you are interested in a PR just let me know.

Use Cake's IFileSystem for read/write operations instead of System.IO.File

Expected Behavior

When using a mock implementation of IFileSystem for testing a task that uses Cake.FileHelpers, the mocked file system is being used.

Current Behavior

Even though the ICakeContext passed to the File* aliases uses a mock implementation of IFileSystem, the current machine's real file system is used.

Possible Solution

Adapt the aliases provided by Cake.FileHelpers to avoid using System.IO.File and instead use the IFileSystem of the current ICakeContext.

Steps to Reproduce (for bugs)

The following example shows a test that should succeeds but instead fails with a DirectoryNotFoundException.
(The source code for FakeCakeContext can be found here)

public class FileHelpersTest
{
    [Fact]
    public void FileReadText_returns_expected_content()
    {
        // ARRANGE
        var path = (FilePath)"X:\\SomeFile.txt";
        var context = new FakeCakeContext();
        context.FileSystem.CreateFile(path).SetContent("Hello World");

        // ACT 
        var content = context.FileReadText(path);

        // ASSERT
        Assert.Equal("Hello World", content);
    }
}

Context

I am writing tests for Cake (Frosting) tasks that use "Cake.FileHelpers" and would like to use the FakeFileSystem class from the "Cake.Testing" package to mock the file system used by the tasks.

Your Environment

  • Addin version used: 6.0.
  • Cake Version used: 3.0.0
  • Operating System: Windows 11

Update Cake.Core reference following Cake 3.0.0 release

With the release of Cake 3.0.0, Cake.Core has also been updated. Using the latest released version of Cake.FileHelpers produces warnings when building.

image

Possible Solution

Update the referenced Cake.Core package to 3.0.0.

Steps to Reproduce (for bugs)

  1. Setup a project that uses Cake.FileHelpers.
  2. Use Cake 3.0.0 in that project.
  3. Build the project.

Your Environment

  • Addin version used: 5.0.0
  • Cake Version used: 3.0.0
  • Operating System: Windows 10.0.19045 Build 19045

Add cake-addin tag to Cake.FileHelpers NuGet package

The NuGet Gallery will soon include a "Cake" tab with instructions on how to use NuGet packages in Cake build scripts. I'd like to suggest that you include the tag cake-addin in the NuGet package of this addin, so that the NuGet Gallery can display the correct instructions to install this addin.

The UI will look similar to this:

image

Documentation on best practices on tags for Cake addins: https://cakebuild.net/docs/extending/addins/best-practices#tags

Workflows are referencing vulnerable actions

Hello, there!

As part of the university research we are currently doing regarding the security of Github Actions, we noticed that one or many of the workflows that are part of this repository are referencing vulnerable versions of the third-party actions. As part of a disclosure process, we decided to open issues to notify GitHub Community.

Please note that there are could be some false positives in our methodology, thus not all of the open issues could be valid. If that is the case, please let us know, so that we can improve on our approach. You can contact me directly using an email: ikoishy [at] ncsu.edu

Thanks in advance

  1. The workflow release-notes.yml is referencing action gittools/actions/gitversion/setup using references v0.9.9. However this reference is missing the commit 90150b4 which may contain fix to the vulnerability.
  2. The workflow release-notes.yml is referencing action gittools/actions/gitversion/execute using references v0.9.9. However this reference is missing the commit 90150b4 which may contain fix to the vulnerability.

The vulnerability fix that is missing by actions' versions could be related to:
(1) CVE fix
(2) upgrade of vulnerable dependency
(3) fix to secret leak and others.
Please consider updating the reference to the action.

If you end up updating the reference, please let us know. We need the stats for the paper :-)

fix compatibility for Cake.Core version 0.26.0

Cake.exe : Error: The assembly 'Cake.FileHelpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 
At C:\projects\jackett\build.ps1:233 char:1
+ &$CAKE_EXE $cakeArguments
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Error: The asse...KeyToken=null' :String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
is referencing an older version of Cake.Core (0.22.0). 
This assembly need to reference at least Cake.Core version 0.26.0. 
Another option is to downgrade Cake to an
 earlier version. 
It's not recommended, but you can explicitly opt-out of assembly verification 
by configuring the Skip Verification setting to true
(i.e. command line parameter "--settings_skipverification=true", 
environment variable "CAKE_SETTINGS_SKIPVERIFICATION=true", 
read more about configuration at https://cakebuild.net/docs/fundamentals/configuration)
Command executed with exception: 

Version 2.0.0 is not compatible with Cake 0.21.1

When trying to add CakeFileHelpers to a cake file using Cake 0.21.1, I get this error during script addin installation:

'NETStandard.Library' already has a dependency defined for 'Microsoft.NETCore.Platforms'.
NuGet exited with 1
Could not find any assemblies compatible with .NETFramework,Version=v4.5.
Error: Failed to install addin 'Cake.FileHelpers'.

Was this intentional? If so, I didn't see any information about this in the docs.

Add overloads to pass Encoding

It's important to have flexibility at the boundaries, especially where you read and write files, so all methods should have overloads for passing System.Text.Encoding. This also lets you control Byte Order Mark (BOM) handling.

[Feature Request] `ReplaceRegexMatchGroupInFiles`

Expected Behavior

// "foo bar baz" >>> "foo BAR baz"
ReplaceRegexMatchGroupInFiles("file.txt", "foo (.*) baz", "BAR", 1, RegexOptions.None);

Current Behavior

// "foo bar baz" >>> "BAR"
ReplaceRegexInFiles("file.txt", "foo (.*) baz", "BAR", RegexOptions.None);

Possible Solution

current workaround:

// "foo bar baz" >>> "foo BAR baz"
ReplaceRegexInFiles("file.txt", "foo (.*) baz", "foo BAR baz", RegexOptions.None);

But that is very ugly for complex/long regexes.

The form shown above in "expected behavior" is better. The signature should be similar to that of FindRegexMatchGroupInFile which takes a regex group index.

Steps to Reproduce (for bugs)

n/a

Context

n/a

Your Environment

  • Addin version used: 5.0.0
  • Cake Version used: 2.2.0
  • Operating System: linux

FileHelpers.xxxLines Method (String, IEnumerable<String>)

Hey Redth,

It would be super swell if the following methods also had an option to consume an IENumerable:

FileWriteLines(FilePath, ​String[])​
FileAppendLines(FilePath, ​String[])​

Which would this

FileWriteLines("test", process.GetStandardOutput().ToArray());

becomes

FileWriteLines("test", process.GetStandardOutput());

Would it be possible to use the Cake Contrib Icon for your NuGet Package?

Thanks again for creating this Cake Addin, we really appreciate the effort that you have put in to creating it.

We, the Cake Team, recently announced a new Cake Contrib Icon, details of which can be found here:

http://cakebuild.net/blog/2017/06/new-cake-contrib-icon

Would you consider changing the nuspec file for your NuGet Package to use this new Cake Contrib Icon? If so, the recommended URL to use is:

https://cdn.rawgit.com/cake-contrib/graphics/a5cf0f881c390650144b2243ae551d5b9f836196/png/cake-contrib-medium.png

Details of the above URL can be found in the repository here:

https://github.com/cake-contrib/graphics

Please let me know if you have any questions.

"Append" aliases (partially) overwrite the file instead of appending to it

The "FileAppend*" aliases (FileAppendText and FileAppendLines), (partially) overwrite an existing file (writing starts at offset 0) instead of appending to it.

Expected Behavior

The content of an existing file is retained and additional text is appended to the end of the file

Current Behavior

The content of an existing file is (partially) overwritten.
When the content being appended is shorter than the existing content, the file's content is only partially replaced.

Possible Solution

When opening a file stream, use FileMode.Append instead of OpenOrCreate:

using var streamWriter = CreateStreamWriter(context, file, FileMode.OpenOrCreate);

Your Environment

  • Addin version used: 6.1.2
  • Cake Version used: 3.0.0
  • Operating System: Windows 10

Recommended changes resulting from automated audit

We performed an automated audit of your Cake addin and found that it does not follow all the best practices.

We encourage you to make the following modifications:

  • You are currently referencing Cake.Core 0.26.1. Please upgrade to 0.28.0
  • You are currently referencing Cake.Common 0.26.1. Please upgrade to 0.28.0
  • The Cake.Core reference should be private. Specifically, your addin's .csproj should have a line similar to this: <PackageReference Include="Cake.Core" Version="0.28.0" PrivateAssets="All" />
  • The Cake.Common reference should be private. Specifically, your addin's .csproj should have a line similar to this: <PackageReference Include="Cake.Common" Version="0.28.0" PrivateAssets="All" />
  • Your addin should target netstandard2.0. Please note that there is no need to multi-target, netstandard2.0 is sufficient.
  • The nuget package for your addin should use the cake-contrib icon. Specifically, your addin's .csproj should have a line like this: <PackageIconUrl>https://cdn.rawgit.com/cake-contrib/graphics/a5cf0f881c390650144b2243ae551d5b9f836196/png/cake-contrib-medium.png</PackageIconUrl>.

Apologies if this is already being worked on, or if there are existing open issues, this issue was created based on what is currently published for this package on NuGet.org and in the project on github.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.