I'm trying to obfuscate a JAR file using the yguard 3.0.0 maven plugin. The obfuscated JAR is as almost as expected, it is shrinked and with all the private methods and variables renamed. I need that package names will be renamed too and this is performed, but the spring XML files needed to start my Tomcat are not being updated with the obfuscated packages.
My ant task is the following:
<configuration>
<tasks>
<property name="runtime-classpath" refid="maven.runtime.classpath"/>
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="${runtime-classpath}"/>
<yguard>
<inoutpair in="C:/test/webapp.jar" out="C:/test/webapp_obfuscated.jar" />
<shrink>
<property name="error-checking" value="pedantic"/>
</shrink>
<rename>
<adjust replaceContent="true" replaceName="true">
<include name="ApplicationContext.xml"/>
</adjust>
</rename>
</yguard>
</tasks>
</configuration>
Note that here in my example, I'm only trying to deal with the ApplicationContext.xml, but this file remains with the same classnames that the no obfuscated version. I'm sure that the yguard task is doing something into my ApplicationContext.xml because I have a tag in the file and the path to a file is properly obfuscated but the classnames and the other stuff no:
<!-- Properties ldap -->
<bean id="ldapProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean" scope="singleton">
<property name="ignoreResourceNotFound" value="true"/>
<property name="locations">
<list>
<value>classpath:A/A/B/E/ldap.properties</value> <--Obfuscated!-->
</list>
</property>
</bean>
<bean id="authenticationBO" class="com.grifols.grb.authentication.bo.AuthenticationBO" scope="singleton">
<property name="dbAccess" ref="dbAccessGRB"/>
<property name="usersSecurityBO" ref="usersSecurityBO" />
<property name="settings" ref="settings" />
<property name="ldapProperties" ref="ldapProperties" />
</bean>
According to the Yguard documentation I think that I only have to use replaceContent="true" and detail which file but I'm not
Any idea? I really appreciate any help you can provide.
Ivan
yGuard is able to replace either file/path names or class names in resource files, but not both at once.
I.e.
<adjust replaceContent="true">
will adjust
<example>
<class>com.yworks.yguard.StringReplacer</class>
<file>com/yworks/yguard/StringReplacer.properties</file>
</example>
to
<example>
<class>com.yworks.yguard.StringReplacer</class>
<file>A/A/A/SR.properties</file>
</example>
With
<adjust replaceContent="true" replaceContentSeparator=".">
the result will be
<example>
<class>A.A.A.SR</class>
<file>com/yworks/yguard/StringReplacer.properties</file>
</example>
However, the desired result
<example>
<class>A.A.A.SR</class>
<file>A/A/A/SR.properties</file>
</example>
is not (yet) supported.
Related
we have bean defined in one project as below:
<bean class="a.b.c.d.classA" id="classA">
<property name="prop1" ref="ref1"/>
</bean>
We are importing this configuration in another project and want to overwrite bean definition during patch installation.
So, here we need change class but other details will keep as it is (no change in bean id).
<bean class="a.b.c.d.classB" id="classA">
<property name="prop1" ref="ref1"/>
</bean>
With patch install XML file , we thought to do it using ant call like this:
<xmltask source="beans.xml" dest="beans.xml">
<remove path="/beans/bean[#id='classA']/#class"/>
</xmltask>
<antcall target="abcd">
<param name="file_path" value="beans.xml"/>
<param name="item.path" value="/beans/bean[#id='classA']"/>
<param name="item.name.path" value="class"/>
<param name="item.name.value" value="a.b.c.d.classB"/>
</antcall>
Above approach is somehow not working, may be missing something. So, what changes can we do?
I am trying to configure sonar for my project. First I am trying in local environment. Below is my configuration
<project name="dev" default="war" xmlns:sonar="antlib:org.sonar.ant">
<!-- Define the SonarQube global properties (the most usual way is to pass these properties via the command line) -->
<property name="sonar.host.url" value="http://localhost:9000/sonar" />
<!-- Define the SonarQube project properties -->
<property name="sonar.projectKey" value="org.codehaus.sonar:sonarqube-scanner-ant" />
<property name="sonar.projectName" value="Example of SonarQube Scanner for Ant Usage" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.language" value="java" />
<property name="sonar.sources" value="src" />
<property name="sonar.java.binaries" value="build" />
<property name="sonar.java.libraries" value="lib/*.jar" />
<property name="sonar.sourceEncoding" value="UTF-8" />
<!-- Code for clean compile the java files code comes here -->
<!-- Define SonarQube Scanner for Ant Target -->
<target name="sonar">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- Update the following line, or put the "sonarqube-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
<classpath path="C:/eclipse-oxygen2-wf/plugins/org.apache.ant_1.10.1.v20170504-0840/lib/sonarqube-ant-task-2.5.jar" />
</taskdef>
<sonar:sonar/>
</target>
</project>
I am using sonarqube7.2.1 ansonarqube-ant-task-2.5.jar. When I run the below command it gives me IllegalStateException
ant sonar
Is there something I am missing here?
Below is the console output
Buildfile: C:\workspace\project_sonar\build.xml
sonar:
[sonar:sonar] Apache Ant(TM) version 1.10.1 compiled on February 2 2017
[sonar:sonar] SonarQube Ant Task version: 2.5
[sonar:sonar] Loaded from: file:/C:/sonar/sonarqube-ant-task-2.5.jar
[sonar:sonar] User cache: C:\Users\Usha\.sonar\cache
BUILD FAILED
C:\workspace\project_sonar\build.xml:231: java.lang.IllegalStateException: not started
I got custom checkstyle.xml file with entry for MethodCount like this:
<module name="MethodCount">
<property name="maxTotal" value="20"/>
<property name="maxPrivate" value="10"/>
<property name="maxPublic" value="10"/>
<property name="severity" value="error"/>
</module>
However this creates a problem for huge model classes with getters and setters, which are provided by another web service. Can i somehow exclude this methods? Or is this considered a bad practice to not count those?
You can create suppression.xml file:
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<suppress files="\w*(Dto.java|Entity.java)\b" checks="MethodCount"/>
</suppressions>
And point it in checkstyle.xml
<module name="SuppressionFilter">
<property name="file" value="./suppression.xml"/>
</module>
Then you will suppress check MethodCount for files ending with Entity.java or Dto.java
AFAIK you cannot suppress only getters/setters. Generally, for data structures like entities or dtos it is not a problem for having more than 5 fields with getters and setters.
But if you have real objects adding setter/getters for each field is considering a bad practice.
Not very sure if it's what you need but you can ignore getter and setter methods from inspections:
Goto Settings (CTRL+Alt+S),
then Editor->Inspections->Java->Class metrics->Class with too many methods
My NetBeans project creates my.jar file in /dist/ directory. Trying to edit build.xml to copy this file to another location using ssh. But how to know what is target file name property?
<property name="username" value="aaa"/>
<property name="password" value="bbb"/>
<property name="ip" value="10.1.100.55"/>
<property name="dir" value="/opt/aaa/"/>
<scp file="${dist.jar.dir}${??target??}" todir="${username}:${password}#${ip}:${dir}" trust="true" />
Your Netbeans project has a nbproject/project.properties file, which gets included in build.xml (indirectly) and contains lots of useful variables - including the one that contains a file path to the built jar file. It should be called dist.jar.
<scp file="${dist.jar}" todir="${username}:${password}#${ip}:${dir}" trust="true" />
Check the actual properties file for more variable names, such as dist.dir, src.dir, etc.
I have defined a Spring application context xml which will be edited by end users to add new beans.Something like:
<bean name="myBeanName1" class="com.xxx.Yyy">
<property name="type" value="type1" />
<property name="name" value="name1" />
<property name="arguments" value="arg1" />
</bean>
<bean name="myBeanName2" class="com.xxx.Yyy">
<property name="type" value="type2" />
<property name="name" value="name2" />
<property name="arguments" value="arg2" />
</bean>
.
.
.
Now I am asked to change this to a normal xml so that users wont be bothered by bean property and class names:
<def name="Name1">
<type>type1</type>
<argument>arg1</argument
</def>
<def name="Name2">
<type>type2</type>
<argument>arg2</argument
</def>
As my code is using the bean, how can I use the new xml with minimal code change so that it is converted to a bean definition as earlier and things work as before?.
I dont know if Spring has a solution for this out of the box. What I thought was applying stylesheet to the new xml to create my older bean. Any other better/elegant solution for this?
Edit: Now that user input is not inside the bean anymore, is it possible to use the new xml to inject to a #Component class?
Spring supports creating custom tags. You need to create xsd schema, NamespaceHandlerm, implement BeanDefinitionParsers and make spring aware of these by creating spring.handlers & spring.schemas special files.
Have a look at Extensible XML authoring
Example:
<beans xmlns declaration goes here>
<yournamespace:yourcustomtag id="some id">
<yournamespace:some_other_tag your-custom-attribute="some value" />
</yournamespace:yourcustomtag>
</beans>