how to configure AspectJ with JSR 286 Generic Portlet ??? any link - liferay

we are developing portal application using JSR-286 portlet inside liferay tomcat.We are creating our portlet extending Generic Portlet.Now I want to apply logs on doView() and doModify() methods using AspectJ. I tried with Spring AspectJ. But Spring AspectJ works only on spring managed beans.
any luck

I resolved above problem.
here are some solution to get it done.
Create an Aspect
#Aspect
public class TestAspect {
TestAspect (){
System.out.println("TestAspect Initialized");
}
#Pointcut( "execution(public void doView*(javax.portlet.RenderRequest,javax.portlet.RenderResponse) throws java.io.IOException, javax.portlet.PortletException)" )
private void testDoView() {
}
#Around("testDoView()")
public void logAround(ProceedingJoinPoint joinPoint)
{
System.out.println("AROUND ADVICE START");
try{
joinPoint.proceed(joinPoint.getArgs());
}catch(PortletException portletException){
System.out.println("[AROUND ADVICE] :"+portletExceptionio.getMessgae());
}catch(IOException ioException){
System.out.println("[AROUND ADVICE] :"+ioException.getMessgae());
}
catch(Throwable throwable){
System.out.println("[AROUND ADVICE] :"+throwable.getMessage();
}
System.out.println("AROUND ADVICE EXIT");
}
}
some *.jar files are AspectJ binaries:
aspectjrt.jar - necessary in runtime for correct aspects processing;
aspectjtools.jar - contains implementation of aspectj compiler;
aspectjweaver.jar - bridge between aspectj logic and java instrumentation;
1.In command line enviroment (with Ant-build.xml)
**There are three ways to inject instructions implied by AspectJ aspects:**
<project name="aspectj-example" xmlns:aspectj="antlib:org.aspectj">
<property name="src.dir" value="src/main/java"/>
<property name="resource.dir" value="src/main/resources"/>
<property name="target.dir" value="target"/>
<property name="classes.dir" value="${target.dir}/classes"/>
<taskdef uri="antlib:org.aspectj"
resource="org/aspectj/antlib.xml"
classpath="${resource.dir}/aspectjtools.jar"/>
<path id="aspectj.libs">
<fileset dir="${resource.dir}"/>
</path>
<target name="clean">
<delete dir="${target.dir}"/>
<mkdir dir="${target.dir}"/>
<mkdir dir="${classes.dir}"/>
</target>
way 1: compile-time weaving
<target name="compile-time" depends="clean">
<aspectj:iajc source="1.5" srcdir="${src.dir}" classpathref="aspectj.libs" destDir="${classes.dir}"/>
<java classname="com.aspectj.TestTarget" fork="true">
<classpath>
<path refid="aspectj.libs"/>
<pathelement path="${classes.dir}"/>
</classpath>
</java>
</target>
way 2: post-compile weaving
<target name="post-compile" depends="clean">
<echo message="Compiling..."/>
<javac debug="true" srcdir="${src.dir}" classpathref="aspectj.libs" destdir="${classes.dir}"/>
<echo message="Weaving..."/>
<aspectj:iajc classpathref="aspectj.libs" inpath="${classes.dir}" aspectpath="${src.dir}" outJar="${classes.dir}/test.jar"/>
</target>
way 3: load-time weaving
<target name="load-time" depends="clean">
<echo message="Compiling..."/>
<javac debug="true" srcdir="${src.dir}" classpathref="aspectj.libs" destdir="${classes.dir}"/>
</target>
</project>
2.In Ecilpse (IDE environment)
select your project,than select configure->convert to AspectJ Project.

Related

ant: string manipulation on variable

I have a question based from this question
Replacing characters in Ant property
I want to build a variable (i can't use a property because i'm in a loop) that is pretty much StringA - StringB.
(maybe this is a misunderstanding of properties on my part but they can only be assigned once correct?)
I guess I could build a script function to calculate that, but my guess is that it must be possible to do it in an already existing function, probably something i'm missing.
this would be an example of the code
<for param="file">
<path>
<fileset dir="${mydir}" >
<include name="*.war"/>
</fileset>
</path>
<sequential>
<var name="undeploy_name" value="#{file} function_here ${mydir}" />
<JBossCLI port="${jboss.port.management-native}">
<undeploy namePattern="${undeploy_name}" />
</JBossCLI>
<deployToLiferay file="#{file}" />
</sequential>
</for>
in general I want to deploy several wars. this works fine when I run it once but if I want to make it re-runnable I need to undeploy them first.
I'm just a consumer of this interfaces, Ideally deployToLiferay would auto undeploy but it does not.
thanks for an feedback
edit: if I use something similar to what is define on the linked page i get:
<loadresource property="file-to-deploy">
<propertyresource name="#{file}"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replacestring from="${mydir}" to=""/>
</tokenfilter>
</filterchain>
</loadresource>
10:52:49.541: * /data/contribution.xml:171: The following error occurred while executing this line:
10:52:49.541: * /data/contribution.xml:178: null doesn't exist
line 178 is my loadresource part
ANT is not a programming language. Personally I'd recommend embedding a scripting language like Groovy to process a group of files:
<target name="process-files" depends="resolve">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<fileset id="wars" dir="src/wars" includes="*.war"/>
<groovy>
project.references.wars.each {
ant.echo(message: "I want to do something with this ${it} file")
}
</groovy>
</target>
Example
├── build.xml
└── src
└── wars
├── app1.war
├── app2.war
└── app3.war
Example
process-files:
[echo] I want to do something with this /../src/wars/app1.war file
[echo] I want to do something with this /../src/wars/app2.war file
[echo] I want to do something with this /../src/wars/app3.war file
Update
The following working example shows how Apache ivy can be used to manage build dependencies. This is a capability that exists in other Java build tools like Maven.
<project name="demo" default="process-files" xmlns:ivy="antlib:org.apache.ivy.ant">
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<!--
==================
Normal ANT targets
==================
-->
<target name="process-files" depends="resolve">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<fileset id="wars" dir="src/wars" includes="*.war"/>
<groovy>
project.references.wars.each {
ant.echo(message: "I want to do something with this ${it} file")
}
</groovy>
</target>
<!--
=============================
Dependency management targets
=============================
-->
<target name="resolve" depends="install-ivy">
<ivy:cachepath pathid="build.path">
<dependency org="org.codehaus.groovy" name="groovy-all" rev="2.4.7" conf="default"/>
</ivy:cachepath>
</target>
<target name="install-ivy" unless="ivy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
</project>

How to integrate xUnit.net with CruiseControl.net

I have a continuous integration server that discovers and runs assemblies with NUnit tests. I would like to add some assemblies with xUnit.net tests to the mix. How would I do that?
Download xunit-build-xyzw.zip from xUnit.net on CodePlex and extract it to, for example, C:\Program Files\xUnit.net. Add this location to PATH environment variable
be sure to have no trailing semicolon
Modify your CC.NET *.build script to discover assemblies by convention, as outlined below
note that command line argument syntax no longer has equals sign
In C:\Program Files\CruiseControl.NET\server\ccnet.config, Merge XML files produced by NUnit runner and by xUnit.net runner, as outlined below
merging happens after build, irrespective of build status
be sure results of test run get deleted in the beginning of build script
Restart CC.NET
Download xUnitSummary.xsl from xUnit.net on GitHub and place it in C:\Program Files (x86)\CruiseControl.NET\WebDashboard\xsl
In C:\Program Files\CruiseControl.NET\WebDashboard\dashboard.config, modify buildPlugins element as outlined below
Restart IIS
Additional info:
CruiseControl.Net – Server Installation at Neal's Blog
Step 2:
<project default="RunTests_xUnit">
<target name="RunTests_xUnit" description="Runs the discovered xUnit.net unit tests" depends="someCompileStep">
<!-- Outer loop to search through a list of different locations -->
<!-- Folders to be searched should listed as a semicolon deliminated list in the 'in' attribute -->
<foreach item="String" in="${TestAssemblyOutputPath}" delim=" ;" property="testsPath">
<echo message="Searching for xUnit.net test suites in ${testsPath}" />
<!-- Inner loop to search for dlls containing unit tests -->
<foreach item="File" property="filename">
<in>
<items basedir="${testsPath}">
<!-- see http://nant.sourceforge.net/release/0.91/help/types/fileset.html for how to include or exclude specific files or file patterns -->
<!-- attempt to run tests in any dlls whose name ends with UnitTestSuite.dll' -->
<include name="**UnitTestSuite.dll" />
</items>
</in>
<do>
<property name="testDLLName" value="${path::get-file-name-without-extension(filename)}" />
<echo message="Testing ${testDLLName} with xUnit.net" />
<exec program="${xunit-console.exe}" failonerror="true" resultproperty="resultVal">
<arg line="${testsPath}\${testDLLName}.dll /xml ${xUnitTestLogsFolder}${testDLLName}-xUnitResults.xml" />
</exec>
<fail message="Failures reported in ${testDLLName}." failonerror="true" unless="${int::parse(resultVal)==0}" />
</do>
</foreach>
</foreach>
</target>
</project>
Step 3:
<publishers>
<merge>
<files>
<file>C:\logs-location\xUnitTestLogs\*UnitTestSuite-xUnitResults.xml</file>
<file>C:\logs-location\TestLogs\*Tests-Results.xml</file>
</files>
</merge>
<xmllogger />
<statistics />
</publishers>
Step 5:
<buildPlugins>
<buildReportBuildPlugin>
<xslFileNames>
...
<xslFile>xsl\xUnitSummary.xsl</xslFile>
</xslFileNames>
</buildReportBuildPlugin>
...
<xslReportBuildPlugin description="xUnit.net Report" actionName="xUnitReport" xslFileName="xsl\xUnitSummary.xsl" />
...
</buildPlugins>

NAnt Property to lowercase

I want to protect against incorrect case being placed within a parameter in a nant script.
I want to take the value of x and convert it to lower case, I tried using
string::to-lower()
but that did not work hoping someone has come across this and has a simple solution.
<?xml version="1.0" encoding="utf-8"?>
<project name="test" Default="test" value="net-4.0" >
<property name="x" value="default" unless="${property::exists('x')}"/>
<target name="test">
<echo message="${x}" />
</target>
</project>
UPDATE
I tried the suggestion put forward by Yan with the code below this still outputs capitals I will explain further
I have a nant script that has a parameter that can be passed into it, a property checks for the existence of the parameter and if it exists it uses it, if not there is a default value. I want to take the parameter in whatever form it is given and convert it to lower case while still checking for its existence.
<?xml version="1.0" encoding="utf-8"?>
<property overwrite="true" name="x" value="default" unless="${property::exists('x')}"/>
<property overwrite="true" name="x" value="${string::to-lower(x)}" />
<target name="test">
<echo message="${x}" />
</target>
</project>
I believe this to be the way you think I should do it Yan. I have tested this with the following command line arguments.
nant -buildfile:nant.build test -D:x=TEST
This produces the output
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: test
[property] Read-only property "x" cannot be overwritten.
test:
[echo] TEST
BUILD SUCCEEDED - 0 non-fatal error(s), 1 warning(s)
Total time: 0.1 seconds.
any solution would be much appreciated
When you say parameter, so you mean its name or its value? ie, do you want to ensure x is lowercase, or test (I assume the latter)? If I have the following nant script:
<?xml version="1.0" encoding="utf-8"?>
<project name="test" Default="test" value="net-4.0" >
<property overwrite="false" name="x" value="default"/>
<property overwrite="false" name="x_internal" value="${string::to-lower(x)}" />
<target name="test">
<echo message="${x_internal}" />
</target>
</project>
And call it like this:
nant.exe -buildfile:nant.build test -D:x=TESTx
nant.exe -buildfile:nant.build test -D:X=TESTX
I receive the following response:
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: test
test:
[echo] testx
BUILD SUCCEEDED
Total time: 0 seconds.
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: test
test:
[echo] default
BUILD SUCCEEDED
Total time: 0 seconds.
Is this what you are after?
UPDATE
I think this is what is tripping you up:
Note: properties set on the command-line are always read-only.
(From section 4 in the NAnt Properties documentation)
The function you mentioned should work. See if you spelled the syntax correctly:
<echo message="${string::to-lower(x)}" />

Red5. No scope with my project

i can't create my application with Red5 server. I've got an error
NetConnection.Connect.Rejected: No scope 'TestEcho' on this server.
NetConnection.Connect.Closed
I did something like ping application to test that everything works fine. My class looks like this:
package org.red5.core;
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.service.ServiceUtils;
public class Application extends ApplicationAdapter {
public void appDisconnect(IConnection conn)
{
super.appDisconnect(conn);
}
public boolean appStart()
{
return true;
}
public void appStop()
{}
public boolean appConnect(IConnection conn, Object[] params)
{
return true;
}
public Object echo(Object p)
{
return p;
}
}
Also i have red5-web.xml and red5-web.properties
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!--
Defines a properties file for dereferencing variables
-->
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/red5-web.properties" />
</bean>
<!--
Defines the web context
-->
<bean id="web.context" class="org.red5.server.Context"
autowire="byType" />
<!--
Defines the web scopes
-->
<bean id="web.scope" class="org.red5.server.WebScope"
init-method="register">
<property name="server" ref="red5.server" />
<property name="parent" ref="global.scope" />
<property name="context" ref="web.context" />
<property name="handler" ref="web.handler" />
<property name="contextPath" value="${webapp.contextPath}" />
<property name="virtualHosts" value="${webapp.virtualHosts}" />
</bean>
<!--
Defines the web handler which acts as an applications endpoint
-->
<bean id="web.handler"
class="org.red5.core.Application"
singleton="true" />
</beans>
And
webapp.contextPath=/TestEcho
webapp.virtualHosts=127.0.0.1
So, it's strange but in echo-demo application i can't get connection to rtmp://localhost:1935/TestEcho
And i'd like to notice that demo applications work good, for example, oflaDemo. Where is the problem?....
which version do you use?
if you use red5 1.0, please use
<bean id="web.scope" class="org.red5.server.scope.WebScope" init-method="register">
instead of
<bean id="web.scope" class="org.red5.server.WebScope" init-method="register">
Check the below things
check your folder name with in webapp folder. It should be "TestEcho"
check webAppRootKey in your web.xml file
enable debug in logback.xml in red5 conf folder. check your log while starting.
Ref: https://github.com/arulrajnet/red5Demo/wiki/Different-context-name
I am a bigginer in Red5. I have also Struggled with the same problem. After searching Plenty of forums I have figured it out. In my searching process I have gone through your query also. So I thought it would be helpful if I post solution here.
The problem is with having duplicate red5.jar file. In my scenario I have one jar file in my RED5_HOME and the other in myapp/WEB-INF/lib folder. We should not have two Red5.jar files. red5.jar must be in RED5_HOME directory. So I have removed all the jars including red5.jar from myapp/WEB-INF/lib folder. It Solved my issue.
I just had the very same issue, it was configuration issue with the virtualHost name.
I fixed by changing red5-web.properties from webapp.virtualHosts=localhost to webapp.virtualHosts=*.
Hope it helps
Check something very simple - if you are on Windows - red5 installs and starts a services by default. Then you might have manually copied another version of red5 - which you use for development. That is what happened with me - there was a Windows Service - running red5 - long forgotten. Whereas I was actually running another version of red5 form my filesystem.

JAXB: how to get sources annotated by #generated by ant task?

Is there a way to pass the option -mark-generated, which is applicable to xjc.bat:
%JAXB_HOME%\bin\xjc.bat -mark-generated c:\TEMP\my.xsd
to the corresponding ant task?
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath refid="classpath" />
</taskdef>
<xjc schema="my.xsd" destdir="src" package="gen.example">
<produces dir="src/gen" includes="**/*.java" />
</xjc>
You can pass -mark-generated and other options which are not directly supported in an tag nested under the tag, like this:
<xjc schema="simple.xsd" destdir="src" package="gen.example">
<produces dir="src/gen" includes="**/*.java" />
<arg line="-mark-generated"/>
</xjc>
See the Ant Task reference for details. Happy marshalling!

Resources