what is the right format of -adaptresourcefilenames in ProGuard - resources

I have an application JAR file I would like to obfuscate using ProGuard. It contains "AppName\resources" folder and several "ClassName.properties" files in it.
What is the right format of -adaptresourcefilenames option in my config file to adapt the properties files to classes?

The option -adaptresourcefilenames expects the resource files names to start at the same root directory level as the class names. E.g., it can rename mypackage/MyClass.properties (without any directory prefix) corresponding to
the obfuscated name of mypackage/MyClass.class (also without any directory prefix).
In this case, you could work on the unzipped application, specifying the input and output directories so the relative paths correspond again:
-injars input(!AppName/resources/**)
-outjars output
-injars input/AppName/resources
-outjars output/AppName/resources

Related

Python - working with unkown directory name versions

I'm using python to download an application from a content distribution network. The application downloads as self extract file cabinet. When executed it creates a directory using a version naming format. For example app-version2/../app.exe, Thus I cannot rely on the folder name as it may change in the future. I'm trying to find the best way to work with the content inside the folder without depending on the actual folder name.
My idea was to rename the folder using os.listdir() and then os.rename(app-version2, myapp) This would work but is not automated. What would be the best automated method to find a folder name that contains version numbers and change that to something more static?
Assuming you want to find the path of the directory which begins with app, you can accomplish this using pathlib.Path:
from pathlib import Path
app_path = next(Path().glob('app*'))
This will give you the path to the first file or directory in your current directory whose name begins with "app".

How to get the paths of files in sub directories that contain specific string in a directory python

I have a directory that contains few sub directories. In each sub directory there are few files, and I'd like to get the full paths of the files that contain the word "raw" in their filename and that ends with ".txt" (in each directory there is a file with "raw" in it's name).
Anyone knows how to do it elegantly with python 3?
We can use the Path.resolve method to get the absolute path to the directory, then use Path.glob to collect the Path objects representing the paths of the files we want to retrieve.
from pathlib import Path
paths = [path for path in Path('path/to/dir').resolve().glob("**/*raw*.txt")]
Here your search is specified by **/*raw*.txt. This will return some number of Path objects (the exact type will depend on the operating system you use).
If you want them as strings, you can substitute [str(path) for path in ..] above

how to access puppet variable in custom facts?

I am extracting a zip at a location, in extracted folder directory there is a install.jar.I want to copy a file to the directory where install.jar is available. Now the zip I am extracting may have different folder structure every time, because of this I can not use
file{'EXTRACTED_PATH/ant.properties':
ensure: present
}
So I wrote a custom fact that will find out path of a install jar & I accessed value in manifest like
$install_jar_location=$::getinstallerpath
Now in facts file I have to give path to search, this path I want to pass as a parameter.
for that I have declared one variable in manifest file
$installer_location="/home/oracle/Installer"
how can I access it in my custom fact.I tried to do following but $installer_locationvariable value is coming up blank.
Facter.add(:getinstallerpath) do
setcode do
Facter::Util::Resolution.exec("echo \"$(dirname \"$(find $installer_location -name \*install*.jar)\")\" ")
end
end

How to determine if file system path is directory or file?

I'm looking to determine if a file system path is directory or file. I'm not looking to checking for the type an existing path. I'm trying to determine if the path function argument string is a referring to a directory or file.
How do I make a distinction between a file and a directory when this:
/Users/thomas/Desktop/node
The following path could refer to a directory node, or a file node without an extension.
I was thinking about using a trailing / to connote directory.
So this would mean a directory:
/Users/thomas/Desktop/node/
And this would mean a file:
/Users/thomas/Desktop/node
However node's path methods like .resolve() and .join() do not take into consideration the trailing / and always remove it. So is this good practice?
There is no way to check if an arbitrary string is a directory or file if it does not exist.
However for existing paths, you can use fs.stat() on the path, which will give you an object that has methods for checking the path type (e.g. isDirectory(), isFile(), etc).

How to get the directory path in groovy

I want to store file in my_application/PdfReports directory ,i am writing the code to store in the file which is in my_application/grails-app/domain/com/my_company/my_application/reports/ReportExporter.groovy .
So how to get the path my_application/PdfReportsv to store files.
If you are deploying the web-app as a war, then I'm not sure the path my_application/PdfReports makes any sense.
The war file (and exploded war folder) will be the contents of your web-app folder, with related grails stuff inside the WEB-INF folder
Why not use a custom absolute path which you can define in your Config.groovy file
Or, to get the real disk based path for your web-application, you could do something like:
String webAppPath = new File( servletContext.getRealPath( '/index.gsp' ) ).parentFile.absolutePath
from inside a controller

Resources