Re: [aspectj-users] Hello world Agent with aspectjweaver

2024-01-20 Thread kypdk via aspectj-users
If you do not have the necessary technical knowledge about aspectj, you can
say you do not know about this subject. Other than that, you can't tell me
what job to do and how. I did not consult you on this matter.

I say again, if you don't know about this subject, you can just say you
don't know, you won't tell me what is necessary or not. You should know
your place. I can know what is good for me and what is not.

DO YOU UNDERSTAND ME?

The question I ask is, can aspectj work as an agent in an easy way?

Alexander Kriegisch via aspectj-users , 18 Oca
2024 Per, 07:42 tarihinde şunu yazdı:

> Why not just
>
>- use the aspectjweaver Java agent,
>- package your timing aspect and an aop.xml config file in an aspect
>library and
>- put the aspect library on the normal classpath?
>
> Why write an extra agent, if AspectJ already has one that does what you
> need? You still did not explain anything that would require your
> complicated approach. Not that it would not work, if done correctly, but it
> seems to be totally unnecessary. Just use a regular LTW approach
> <https://github.com/eclipse-aspectj/aspectj/blob/75a9c663ab7b382cdd97f39acd2588cfe1f76f03/docs/devguide/ltw.adoc>.
> No separate agent, no Maven Shade necessary.
> --
> Alexander Kriegisch
> https://scrum-master.de
>
>
> kypdk schrieb am 17.01.2024 20:33 (GMT +07:00):
>
> First of all, thank you very much for your answer.
>
> Since the coding experiments I have made are AI-guided, I cannot say that
> they will be consistent.
>
> Very simply, to write a simple agent that calculates the total running
> time of the application I am making as an agent, from the after-before
> start and end time of the methods running on the JVM.
>
> I can do it with Aspectj using AOP technique.
>
> I want to do it for legacy applications running on JDK8.
>
> regards
>
> Alexander Kriegisch via aspectj-users , 17 Oca
> 2024 Çar, 12:25 tarihinde şunu yazdı:
>
>> This is not trivial. So please, provide a full reproducer project on
>> GitHub including the target code to be woven, so I do not have to fill in
>> the gaps here.
>>
>> What I noticed at first glance is, that class StartAgent to be and do
>> multiple things at once:
>>
>>1. It is a java agent.
>>2. It tries to inject another java agent aspectjweaver into the
>>bootstrap classloader, which begs the question why you are not doing that
>>from the JVM command line, if you are already using a -javaagent
>>parameter anyway. Then the springboard agent would not even be necessary.
>>The next question would be why you think you need it on the bootstrap
>>classloader at all.
>>3. It is an aspect, i.e. it is accessing classes from aspectjweaver
>>from the system classloader already, before it even has a chance to inject
>>the jar into the bootstrap classloader.
>>
>> Your springboard agent should not directly import or reference any
>> classes from aspectjweaver or aspectjrt before the weaver JAR has been
>> added to the bootstrap loader. If later for any reason the springboard
>> agent needs to kick off some action involving classes referencing weaver
>> classes, you ought to load and start them via reflection, e.g.
>> Class.forName etc.
>>
>> It looks as if you are making a simple matter overly complicated. The
>> justification for what you are trying to do could only be a very special
>> use case, which you have failed to describe. So I have no way to be sure,
>> whether there is not a simpler approach. Lacking additional evidence, I
>> would assume there is.
>>
>> BTW, are you on JDK 8 or on 9+? I am asking for a specific reason too
>> early to discuss now.
>> --
>> Alexander Kriegisch
>> https://scrum-master.de
>>
>>
>> kypdk via aspectj-users schrieb am 17.01.2024 03:20 (GMT +07:00):
>>
>> Hello,
>>
>> What I want to do is to trigger the before advice on the agent when the
>> methods run on the generator.jar
>>
>> Could you help me ,I would greatly appreciate it
>>
>> regards
>>
>> java -javaagent:JavaAgent.jar -jar Generator.jar
>>
>>
>> import org.aspectj.lang.JoinPoint;
>> import org.aspectj.lang.annotation.Aspect;
>> import org.aspectj.lang.annotation.Before;
>> import org.aspectj.weaver.loadtime.Agent;
>>
>> import java.io.IOException;
>> import java.lang.instrument.Instrumentation;
>> import java.util.jar.JarFile;
>>
>> @Aspect
>> public class StartAgent {
>>
>> public static void premain(String agentArgs

Re: [aspectj-users] Hello world Agent with aspectjweaver

2024-01-17 Thread kypdk via aspectj-users
First of all, thank you very much for your answer.

Since the coding experiments I have made are AI-guided, I cannot say that
they will be consistent.

Very simply, to write a simple agent that calculates the total running time
of the application I am making as an agent, from the after-before start and
end time of the methods running on the JVM.

I can do it with Aspectj using AOP technique.

I want to do it for legacy applications running on JDK8.

regards

Alexander Kriegisch via aspectj-users , 17 Oca
2024 Çar, 12:25 tarihinde şunu yazdı:

> This is not trivial. So please, provide a full reproducer project on
> GitHub including the target code to be woven, so I do not have to fill in
> the gaps here.
>
> What I noticed at first glance is, that class StartAgent to be and do
> multiple things at once:
>
>1. It is a java agent.
>2. It tries to inject another java agent aspectjweaver into the
>bootstrap classloader, which begs the question why you are not doing that
>from the JVM command line, if you are already using a -javaagent
>parameter anyway. Then the springboard agent would not even be necessary.
>The next question would be why you think you need it on the bootstrap
>classloader at all.
>3. It is an aspect, i.e. it is accessing classes from aspectjweaver
>from the system classloader already, before it even has a chance to inject
>the jar into the bootstrap classloader.
>
> Your springboard agent should not directly import or reference any classes
> from aspectjweaver or aspectjrt before the weaver JAR has been added to
> the bootstrap loader. If later for any reason the springboard agent needs
> to kick off some action involving classes referencing weaver classes, you
> ought to load and start them via reflection, e.g. Class.forName etc.
>
> It looks as if you are making a simple matter overly complicated. The
> justification for what you are trying to do could only be a very special
> use case, which you have failed to describe. So I have no way to be sure,
> whether there is not a simpler approach. Lacking additional evidence, I
> would assume there is.
>
> BTW, are you on JDK 8 or on 9+? I am asking for a specific reason too
> early to discuss now.
> --
> Alexander Kriegisch
> https://scrum-master.de
>
>
> kypdk via aspectj-users schrieb am 17.01.2024 03:20 (GMT +07:00):
>
> Hello,
>
> What I want to do is to trigger the before advice on the agent when the
> methods run on the generator.jar
>
> Could you help me ,I would greatly appreciate it
>
> regards
>
> java -javaagent:JavaAgent.jar -jar Generator.jar
>
>
> import org.aspectj.lang.JoinPoint;
> import org.aspectj.lang.annotation.Aspect;
> import org.aspectj.lang.annotation.Before;
> import org.aspectj.weaver.loadtime.Agent;
>
> import java.io.IOException;
> import java.lang.instrument.Instrumentation;
> import java.util.jar.JarFile;
>
> @Aspect
> public class StartAgent {
>
> public static void premain(String agentArgs, Instrumentation 
> instrumentation) {
> System.out.println("Java Agent Started");
>
> String aspectjWeaverPath = "aspectjweaver.jar";
> try {
> instrumentation.appendToBootstrapClassLoaderSearch(new 
> JarFile(aspectjWeaverPath));
> } catch (IOException e) {
> System.out.println(e);
> }
>
> Agent.premain(agentArgs, instrumentation);
> }
>
> @Before("execution(* *(..))")
> public void beforeMethodExecution(JoinPoint joinPoint) {
> System.out.println("Before method execution: " + 
> joinPoint.getSignature().toShortString());
> }
> }
>
> 
> org.apache.maven.plugins
> maven-shade-plugin
> 3.2.4
> 
> 
>  implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
> 
> StartAgent
> true
> true
> 
> ${project.version}
> 
> 
> 
>
> 
> 
> *:*
> 
> META-INF/*.SF
> META-INF/*.DSA
> META-INF/*.RSA
> 
> 
> 
> 
> 
> 
> package
> 
> shade
> 
> 
> 
> 
>
>
>
> ___
> aspectj-users mailing list
> aspectj-users@eclipse.org
> To unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/aspectj-users
>
___
aspectj-users mailing list
aspectj-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/aspectj-users


[aspectj-users] Hello world Agent with aspectjweaver

2024-01-16 Thread kypdk via aspectj-users
Hello,

What I want to do is to trigger the before advice on the agent when the
methods run on the generator.jar

Could you help me ,I would greatly appreciate it

regards

java -javaagent:JavaAgent.jar -jar Generator.jar


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.weaver.loadtime.Agent;

import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.util.jar.JarFile;

@Aspect
public class StartAgent {

public static void premain(String agentArgs, Instrumentation
instrumentation) {
System.out.println("Java Agent Started");

String aspectjWeaverPath = "aspectjweaver.jar";
try {
instrumentation.appendToBootstrapClassLoaderSearch(new
JarFile(aspectjWeaverPath));
} catch (IOException e) {
System.out.println(e);
}

Agent.premain(agentArgs, instrumentation);
}

@Before("execution(* *(..))")
public void beforeMethodExecution(JoinPoint joinPoint) {
System.out.println("Before method execution: " +
joinPoint.getSignature().toShortString());
}
}


org.apache.maven.plugins
maven-shade-plugin
3.2.4




StartAgent
true
true

${project.version}






*:*

META-INF/*.SF
META-INF/*.DSA
META-INF/*.RSA






package

shade




___
aspectj-users mailing list
aspectj-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/aspectj-users