yguard not updating properties file in the jar - ant

I have jar file having some properties files in it like log4j.properties and config.properties. Following is my ant script for yguard. Everything else is working but the properties file updation.
<target name="yguard">
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="lib/yguard.jar" />
<yguard>
<inoutpairs resources="none">
<fileset dir="${basedir}">
<include name="MyApp.jar" />
</fileset>
<mapper type="glob" from="MyApp.jar" to="MyAppObs.jar" />
</inoutpairs>
<externalclasses>
<pathelement location="lib/log4j-1.2.17.jar" />
</externalclasses>
<rename conservemanifest="true" mainclass="com.amit.Application" >
<adjust replaceContent="true" >
<include name="**/*.properties" />
</adjust>
</rename>
</yguard>
</target>
config.properties file
com.amit.Application.param1 = something
I found some question in stackoverflow but they didn't help. One place it was mentioned that the file (like jsp, xml, properties) should be in the jar file which I already have. But my yguard obfuscated file just get the files copied as it is.
I tried many combinations with rename & adjust tags but nothing worked for me.
Following post I already visited
Is it possible to manage logs through Obfuscation with yGuard?
How to include obfuscated jar file into a war file

Apparently you want yGuard to obfuscate the name of the field param1, because com.amit.Application is obviously your entry point and yGuard excludes the given main class automatically. So basically you want the outcome to be something like
com.amit.Application.AÖÜF = something
This isn't possible, because yGuard can only adjust class names in property files, as state here: yGuard Manual

Related

Replace all underscores in filenames using Ant?

What would be the best way to do this using an Ant task:
Start with a bunch of text files with names like this:
Filename_With_Underscores.txt
Another_Filename_With_Underscores.txt
Yet_Another_Filename_With_Underscores.txt
and turn them into this:
Filename+With+Underscores.txt
Another+Filename+With+Underscores.txt
Yet+Another+Filename+With+Underscores.txt
I actually need to change the identically-named folder that each text file is contained in also, that is, to start with this folder/file structure:
Filename_With_Underscores/Filename_With_Underscores.txt
and turn it into this:
Filename+With+Underscores/Filename+With+Underscores.txt
but I can handle that if I know how to rewrite the text file names.
I would know how to replace all underscores with plus signs in the contents of a file, using replaceregexp, but how do I do this to the folder and file names themselves?
I've used a mapper to rewrite folder and file names in the past, for example:
<target name="dita_wrap" description="Wraps each file in a folder with the same name as the file, copies all to new location">
<copy todir="output" verbose="true">
<fileset dir="source"
includes="*/*.dita" />
<regexpmapper handledirsep="true" from="^(.*)/([^/]*)\.dita$"
to="\1/\2/\2.dita" />
</copy>
</target>
However getting something like that to capture and replace each underscore in a filename, no matter how many underscores there might be, is eluding me. Any advice?
You need a <filtermapper>, for example:
<copy todir="output" verbose="true">
<fileset dir="source" includes="*/*.txt" />
<filtermapper>
<replacestring from="_" to="+"/>
</filtermapper>
</copy>
Works for me:
$> find . -type f
./build.xml
./source/Filename_With_Underscores/Filename_With_Underscores.txt
./output/Filename+With+Underscores/Filename+With+Underscores.txt

JaCoCo report looks correct but can not view source

I am new to JaCoCo and trying to figure out why the html report that I am generating is not linked with my source.
The coverage numbers look correct and I can browse down to each class and then each method but I can not see the source. I have tried many different things inside the sourcefiles tag but nothing is working. Has anyone else had this issue? Here is a snippet of my ant script:
...
<test name="test.fw.UITestSuite" todir="${logdir}"/>
</junit>
</jacoco:coverage>
<fail if="TestFailed" status="1" message="UI junit test failure detected"/>
<echo message="${src}"/>
<jacoco:report>
<executiondata>
<file file="jacoco.exec"/>
</executiondata>
<structure name="UI">
<classfiles>
<fileset dir="${build}/fw"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="fw" includes="**./*.java"/>
</sourcefiles>
</structure>
<html destdir="report"/>
</jacoco:report>
</target>
...
Your fileset definition seems odd.
The include must be (the first . is misplaced):
includes="**/*.java
Try simply pointing it to the root of your src dir (there is no need for the includes)
<fileset dir="fw" />
But fw has to be the root of your sources, i.e. it contains the package folders like:
src
-org
-module
-MyClass1.java
-MyClass2.java
I’ve seen this break when using Scala-style package directory names, e.g.,
src/main/java/com.example.foo.bar/Foo.java
for fewer levels of nesting, faster autocompletion, &c., compared to the standard
src/main/java/com/example/foo/bar/Foo.java
Most tools support the first version just fine, but usually if you try it out and everything works fine, by the time you notice something like the jacoco reports not showing the source anymore, you’ve long forgotten the directory name change …

Find all directories in which a file exists, such that the file contains a search string

I have a directory tree that I need to process as follows:
I have a certain file that needs to be copied to a select few sub directories
A sub directory of interest is one that contains a file within which I can regex match a known search string
Ideally I would like to:
Perform a regex match across all files within a directory
If the regex matches, copy the file to that directory
The trouble is that I am quite new to ANT and I'm having difficulties finding my way around. I can't find any tasks in the docs about per directory operations based on regex search. The closest thing I've found is a regex replace task (<replaceregexp>) that can search and replace patterns across files.
Is this even possible? I'd really appreciate a sample to get started with. I apologize for requesting code - I simply don't know how to begin composing the tasks together to achieve this.
Alternatively I have the option of hardcoding all the copy operations per directory, but it would mean manually keeping everything in sync as my project grows. Ideally I'd like to automate it based on the regex search/copy approach I described.
Thanks!
Your requirement is a bit non-standard, so I've solved it using a custom Groovy task.
Here's a working example:
<project name="find-files" default="copy-files">
<!--
======================
Groovy task dependency
======================
-->
<path id="build.path">
<pathelement location="jars/groovy-all-1.8.6.jar"/>
</path>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<!--
=========================
Search for matching files
=========================
-->
<target name="search-files">
<fileset id="filesContainingSearchString" dir="src">
<include name="**/*.txt"/>
<containsregexp expression="[4-6]\.[0-9]"/>
</fileset>
</target>
<!--
===================================
Copy file into each directory found
===================================
-->
<target name="copy-files" depends="search-files">
<groovy>
project.references.filesContainingSearchString.each { file ->
def dir = new File(file.toString()).parent
ant.copy(file:"fileToBeCopied.txt", toDir:dir)
}
</groovy>
</target>
</project>
Notes:
Groovy jar can be downloaded from Maven Central
Use the copy task with a fileset and regular expression selector :
<copy todir="your/target/dir">
<fileset dir="rootdir/of/your/directorytree" includes="**/*.txt">
<containsregexp expression="[4-6]\.[0-9]"/>
</fileset>
</copy>
This example is taken from the ant manual and slightly adapted.
Means select all files with .txt extension anywhere beyond rootdir/of/your/directorytree that match the regular expression (have a 4,5 or 6 followed by a period and a number from 0 to 9) and copy them to your/target/dir.
Just adapt it for your needs.

Ant Copy task with Path instead of FileSet

I'm using Ant 1.7, want to copy files from different paths (they have no relationship, so i cannot use the include selector to filter them out of their root directory). I try to use the <path> inside the <copy> instead of <fileset>, because with <path> i can specify multi paths which is in <fileset> not possible. My ant script looks like this, but it doesn't work.
<target name="copytest">
<!-- copy all files in test1 and test2 into test3 -->
<copy todir="E:/test3">
<path>
<pathelement path="C:/test1;D:/test2"></pathelement>
</path>
</copy>
</target>
Anybody has idea about how to use the <path> inside <copy>? Or maybe anybody has the advise about how to copy files from different source without selector?
Btw, i don't want to hard code the source directories, they will be read from a propertiy file, so writing multi <fileset> inside <copy> should not be considered.
thanks in advance!
This only works if the flatten attribute is set to true:
<copy todir="E:/test3" flatten="true">
<path>
<pathelement path="C:/test1;D:/test2"></pathelement>
</path>
</copy>
This is documented in the Examples section of the Ant Copy task documentation.
<pathelement> generally uses it's path attribute as a reference to classpath or some other predefined location, if you want to give specific file locations outside of the classpath try with location attribute
<pathelement location="D:\lib\helper.jar"/>
The location attribute specifies a single file or directory relative
to the project's base directory (or an absolute filename), while the
path attribute accepts colon- or semicolon-separated lists of
locations. The path attribute is intended to be used with predefined
paths - in any other case, multiple elements with location attributes
should be preferred.
We have the same problem
A bit more complicated that we need to add a specified pattern set to each fileset converted from path
For example, this is the incoming data
<path id="myDirList" path="C:/test1;D:/test2" />
<patternset id="myPatterns" includes="*.html, *.css, etc, " />
We wrote a script to solve this problem
<resources id="myFilesetGroup">
<!-- mulitiple filesets to be generated here
<fileset dir="... dir1, dir2 ...">
<patternset refid="myPatterns"/>
</fileset>
-->
</resources>
<script language="javascript"><![CDATA[
(function () {
var resources = project.getReference("myFilesetGroup");
var sourceDirs = project.getReference("myDirList").list();
var patterRef = new Packages.org.apache.tools.ant.types.Reference(project, "myPatterns");
for (var i = 0; i < sourceDirs.length; i++) {
var fileSet = project.createDataType("fileset");
fileSet.dir = new java.io.File(sourceDirs[i]);
fileSet.createPatternSet().refid = patterRef;
resources.add(fileSet);
}
})();
]]></script>
now you can use this resources in you copy task
<!-- copy all files in test1 and test2 into test3 -->
<copy todir="E:/test3">
<resources refid="myFilesetGroup">
</copy>
I tried this and works fine
<fileset file="${jackson.jaxrs.lib}"/>

iajc fails to weave aspects from a jar but succeedes from class files

So I defined iajc task for my project that does intertype declarations just fine, then there is a separate jar task that creates a project.jar.
Then there is iajc task for junit test target, this task references the project.jar with the goal of weaving its ITDs into test classes like so:
<aspectpath>
<pathelement path="${dist}/project.jar"/>
<fileset dir="${lib.aspect}">
<include name="**/*.jar" />
<include name="**/*.zip" />
</fileset>
</aspectpath>
That does not work - compiler produces errors like class "com....Foo" has to implement method doThings() defined in interface Bar
Then I change the <aspectpath> to this:
<aspectpath>
<pathelement location="${build.dir}"/>
<fileset dir="${lib.aspect}">
<include name="**/*.jar" />
<include name="**/*.zip" />
</fileset>
</aspectpath>
which is basically using the intermediate class files generated by the compiler and it works great.
Then I find that if I use the outjar option instead of destdir in my iajc task then that jar can be used in <aspectpath>.
So a question and a comment then:
Q. is there some parameter that would make it work with the regular <jar> task?
C. the fact that I have to use outjar is not documented at all - the option to output a jar is mentioned but nowhere does it say that that is the only way to produce a jar that will work.

Resources