├── README
├── .gitignore
├── src
└── main
│ └── java
│ └── org
│ └── jboss
│ ├── aa
│ └── A.java
│ └── acme
│ ├── Main.java
│ └── TestCFT.java
└── pom.xml
/README:
--------------------------------------------------------------------------------
1 | Example code for JBoss Maven Transformer Plugin.
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | *.ipr
3 | *.iws
4 | *.iml
5 | target/
6 |
7 |
--------------------------------------------------------------------------------
/src/main/java/org/jboss/aa/A.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2011, Red Hat, Inc., and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.aa;
24 |
25 | /**
26 | * @author Ales Justin
27 | */
28 | public class A
29 | {
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/jboss/acme/Main.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2011, Red Hat, Inc., and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.acme;
24 |
25 | import java.util.Arrays;
26 |
27 | /**
28 | * @author Ales Justin
29 | */
30 | public class Main
31 | {
32 | public static void main(String[] args)
33 | {
34 | if (args == null || args.length == 0)
35 | throw new IllegalArgumentException("Main --- XXXX");
36 |
37 | try
38 | {
39 | Class> clazz = Class.forName(args[0]);
40 | System.out.println(Arrays.toString(clazz.getDeclaredMethods()));
41 | }
42 | catch (ClassNotFoundException e)
43 | {
44 | e.printStackTrace();
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.jboss
7 | jboss-parent
8 | 6-beta-1
9 |
10 |
11 | org.jboss.maven.test
12 | mtp-test
13 | jar
14 | 1.0.0-SNAPSHOT
15 | Transformer Maven Mojo -- Tests
16 |
17 |
18 |
19 | org.jboss.maven.plugins
20 | maven-transformer-plugin
21 | 1.0.0-SNAPSHOT
22 |
23 |
24 | javassist
25 | javassist
26 | 3.12.0.GA
27 |
28 |
29 |
30 |
31 |
32 |
33 | org.jboss.maven.plugins
34 | maven-transformer-plugin
35 | 1.0.0-SNAPSHOT
36 |
37 |
38 | compile
39 |
40 | bytecode
41 |
42 |
43 |
44 |
45 | org/jboss/aa/[a-zA-Z]+
46 | org.jboss.acme.TestCFT
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/main/java/org/jboss/acme/TestCFT.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2011, Red Hat, Inc., and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.acme;
24 |
25 | import java.lang.instrument.ClassFileTransformer;
26 | import java.lang.instrument.IllegalClassFormatException;
27 | import java.security.ProtectionDomain;
28 |
29 | import javassist.ClassPool;
30 | import javassist.CtClass;
31 | import javassist.CtMethod;
32 | import javassist.CtNewMethod;
33 | import javassist.LoaderClassPath;
34 |
35 | /**
36 | * @author Ales Justin
37 | */
38 | public class TestCFT implements ClassFileTransformer
39 | {
40 | public byte[] transform(ClassLoader classLoader, String s, Class> aClass, ProtectionDomain protectionDomain, byte[] bytes) throws IllegalClassFormatException
41 | {
42 | try
43 | {
44 | ClassPool pool = new ClassPool(true);
45 | pool.appendClassPath(new LoaderClassPath(classLoader));
46 | CtClass clazz = pool.get(s);
47 | CtClass thisClass = pool.get(Main.class.getName());
48 | CtMethod method = CtNewMethod.copy(thisClass.getDeclaredMethod("main"), clazz, null);
49 | clazz.addMethod(method);
50 | return clazz.toBytecode();
51 | }
52 | catch (Exception e)
53 | {
54 | e.printStackTrace();
55 | throw new IllegalClassFormatException(e.getMessage());
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------