Package org.jboss.arquillian.extension.byteman.impl.common

Examples of org.jboss.arquillian.extension.byteman.impl.common.BytemanConfiguration


        return null;
    }

    protected List<ExecContext> getExecContexts(Event event) {
        BytemanConfiguration config = BytemanConfiguration.from(descriptorInst.get());
        List<ExecContext> list = new ArrayList<>();
        if (config.clientAgentPort() == config.containerAgentPort()) {
            ExecContext context = new ExecContext(config.clientAgentPort(), EnumSet.complementOf(EnumSet.of(ExecType.CONTAINER)), config);
            list.add(context);
        } else {
            list.add(new ExecContext(config.clientAgentPort(), EnumSet.complementOf(EnumSet.of(ExecType.CONTAINER, ExecType.CLIENT_CONTAINER)), config));
            String address = readAddress(event);
            ExecContext remote;
            if (address != null) {
                remote = new ExecContext(address, config.containerAgentPort(), EnumSet.of(ExecType.CLIENT_CONTAINER), config);
            } else {
                remote = new ExecContext(config.containerAgentPort(), EnumSet.of(ExecType.CLIENT_CONTAINER), config);
            }
            list.add(remote);
        }
        return list;
    }
View Full Code Here


    @Inject
    private Instance<ArquillianDescriptor> descriptorInst;

    @Override
    public Archive<?> createAuxiliaryArchive() {
        BytemanConfiguration config = BytemanConfiguration.from(descriptorInst.get());

        JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "arquillian-byteman.jar")
            .addClasses(Submit.class, ScriptText.class, BMRule.class, BMRules.class, ExecType.class,
                BytemanRemoteExtension.class, GenerateScriptUtil.class, SubmitException.class, BytemanConfiguration.class)
            .addPackages(false,
                org.jboss.arquillian.extension.byteman.impl.container.ScriptInstaller.class.getPackage(),
                org.jboss.arquillian.extension.byteman.impl.common.BytemanConfiguration.class.getPackage())
            .addAsServiceProvider(RemoteLoadableExtension.class, BytemanRemoteExtension.class);

        jar.addAsResource(new StringAsset(config.toString()), BytemanConfiguration.BYTEMAN_CONFIG);

        if (config.autoInstallAgent()) {
            JavaArchive agentJar = ShrinkWrap.create(JavaArchive.class)
                .addPackages(true, "org.jboss.byteman")
                .setManifest(
                    new StringAsset("Manifest-Version: 1.0\n"
                        + "Created-By: Arquillian\n"
View Full Code Here

    @Inject
    private Instance<ArquillianDescriptor> descriptorInst;

    public void install(@Observes(precedence = 1) BeforeSuite event) {
        try {
            BytemanConfiguration config = BytemanConfiguration.from(descriptorInst.get());

            if (!config.autoInstallAgent()) {
                return;
            }
            try {
                // Not only load it, but also attempt to check firstTime variable, since in embedded containers this might be the same jvm
                Class<?> mainClass = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.byteman.agent.Main");
                if (!(Boolean) mainClass.getDeclaredField("firstTime").get(null)) {
                    return;
                }
            } catch (ClassNotFoundException e) {
                // Agent not loaded yet, move on
            }

            String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];

            File bytemanHome = File.createTempFile("byteman", "agent");
            bytemanHome.delete();
            bytemanHome.mkdir();

            File bytemanLib = new File(bytemanHome, "lib");
            bytemanLib.mkdirs();

            InputStream bytemanInputJar = ShrinkWrap.create(JavaArchive.class)
                .addPackages(true, "org.jboss.byteman")
                .setManifest(
                    new StringAsset("Manifest-Version: 1.0\n"
                        + "Created-By: Arquillian\n"
                        + "Implementation-Version: 0.0.0.Arq\n"
                        + "Premain-Class: org.jboss.byteman.agent.Main\n"
                        + "Agent-Class: org.jboss.byteman.agent.Main\n"
                        + "Can-Redefine-Classes: true\n"
                        + "Can-Retransform-Classes: true\n")).as(ZipExporter.class).exportAsInputStream();


            File bytemanJar = new File(bytemanLib, BytemanConfiguration.BYTEMAN_JAR);
            GenerateScriptUtil.copy(bytemanInputJar, new FileOutputStream(bytemanJar));

            VirtualMachine vm = VirtualMachine.attach(pid);
            String agentProperties = config.agentProperties();
            vm.loadAgent(bytemanJar.getAbsolutePath(), "listener:true,port:" + config.clientAgentPort() + (agentProperties != null ? ",prop:" + agentProperties : ""));
            vm.detach();
        } catch (IOException e) {
            throw new RuntimeException("Could not write byteman.jar to disk", e);
        } catch (Exception e) {
            throw new RuntimeException("Could not install byteman agent", e);
View Full Code Here

*/
public class AgentInstaller {

    public void install(@Observes(precedence = 1) BeforeSuite event) {
        try {
            BytemanConfiguration config = BytemanConfiguration.from(
                Thread.currentThread().getContextClassLoader().getResourceAsStream(BytemanConfiguration.BYTEMAN_CONFIG)
            );

            if (!config.autoInstallAgent()) {
                return;
            }
            try {
                // Not only load it, but also attempt to check firstTime variable, since in embedded containers this might be the same jvm
                Class<?> mainClass = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.byteman.agent.Main");
                if (!(Boolean) mainClass.getDeclaredField("firstTime").get(null)) {
                    return;
                }
            } catch (ClassNotFoundException e) {
                // Agent not loaded yet, move on
            }

            String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];

            File bytemanHome = File.createTempFile("byteman", "agent");
            bytemanHome.delete();
            bytemanHome.mkdir();

            File bytemanLib = new File(bytemanHome, "lib");
            bytemanLib.mkdirs();

            InputStream bytemanInputJar = Thread.currentThread().getContextClassLoader().getResourceAsStream(BytemanConfiguration.BYTEMAN_JAR);

            File bytemanJar = new File(bytemanLib, BytemanConfiguration.BYTEMAN_JAR);

            GenerateScriptUtil.copy(bytemanInputJar, new FileOutputStream(bytemanJar));

            VirtualMachine vm = VirtualMachine.attach(pid);
            String agentProperties = config.agentProperties();
            vm.loadAgent(bytemanJar.getAbsolutePath(), "listener:true,port:" + config.containerAgentPort() + (agentProperties != null ? ",prop:" + agentProperties : ""));
            vm.detach();
        } catch (IOException e) {
            throw new RuntimeException("Could not write byteman.jar to disk", e);
        } catch (Exception e) {
            throw new RuntimeException("Could not install byteman agent", e);
View Full Code Here

        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        InputStream scriptStream = cl.getResourceAsStream(BytemanConfiguration.BYTEMAN_SCRIPT);

        try {
            if (scriptStream != null && scriptStream.available() > 0) {
                BytemanConfiguration config = BytemanConfiguration.from(
                    Thread.currentThread().getContextClassLoader().getResourceAsStream(BytemanConfiguration.BYTEMAN_CONFIG)
                );
                String ruleKey = Thread.currentThread().getName();
                String ruleScript = GenerateScriptUtil.toString(scriptStream);
                try {
                    Submit submit = new Submit(Submit.DEFAULT_ADDRESS, config.containerAgentPort());
                    submit.addScripts(Arrays.asList(new ScriptText(ruleKey, ruleScript)));
                } catch (Exception e) {
                    throw new SubmitException("Could not install script from file", e);
                }
            }
View Full Code Here

    public void uninstall(@Observes AfterSuite event) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        InputStream scriptStream = cl.getResourceAsStream(BytemanConfiguration.BYTEMAN_SCRIPT);

        if (scriptStream != null) {
            BytemanConfiguration config = BytemanConfiguration.from(
                Thread.currentThread().getContextClassLoader().getResourceAsStream(BytemanConfiguration.BYTEMAN_CONFIG)
            );

            String ruleKey = Thread.currentThread().getName();
            String ruleScript = GenerateScriptUtil.toString(scriptStream);
            try {
                Submit submit = new Submit(Submit.DEFAULT_ADDRESS, config.containerAgentPort());
                submit.deleteScripts(Arrays.asList(new ScriptText(ruleKey, ruleScript)));
            } catch (Exception e) {
                throw new SubmitException("Could not uninstall script from file", e);
            }
        }
View Full Code Here

            Thread.currentThread().getContextClassLoader().getResourceAsStream(BytemanConfiguration.BYTEMAN_CONFIG)
        );
    }

    protected List<ExecContext> getExecContexts(Event event) {
        BytemanConfiguration configuration = getConfiguration();
        return Collections.singletonList(new ExecContext(configuration.containerAgentPort(), EnumSet.of(ExecType.ALL, ExecType.CONTAINER), configuration));
    }
View Full Code Here

    public void install(@Observes(precedence = 1) BeforeSuite event)
    {
        try
        {
            BytemanConfiguration config = BytemanConfiguration.from(
                    Thread.currentThread().getContextClassLoader().getResourceAsStream(BytemanConfiguration.BYTEMAN_CONFIG)
            );

            if(!config.autoInstallAgent())
            {
                return;
            }
            try
            {
                // Not only load it, but also attempt to check firstTime variable, since in embedded containers this might be the same jvm
                Class<?> mainClass = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.byteman.agent.Main");
                if(!(Boolean)mainClass.getDeclaredField("firstTime").get(null))
                {
                    return;
                }
            }
            catch (ClassNotFoundException e)
            {
                // Agent not loaded yet, move on
            }

            String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];

            File bytemanHome = File.createTempFile("byteman", "agent");
            bytemanHome.delete();
            bytemanHome.mkdir();

            File bytemanLib = new File(bytemanHome, "lib");
            bytemanLib.mkdirs();

            InputStream bytemanInputJar = Thread.currentThread().getContextClassLoader().getResourceAsStream(BytemanConfiguration.BYTEMAN_JAR);

            File bytemanJar = new File(bytemanLib, BytemanConfiguration.BYTEMAN_JAR);

            GenerateScriptUtil.copy(bytemanInputJar, new FileOutputStream(bytemanJar));

            VirtualMachine vm = VirtualMachine.attach(pid);
            String agentProperties = config.agentProperties();
            vm.loadAgent(bytemanJar.getAbsolutePath(), "listener:true,port:" + config.containerAgentPort() + (agentProperties != null ? ",prop:" +  agentProperties:""));
            vm.detach();
        }
        catch (IOException e)
        {
            throw new RuntimeException("Could not write byteman.jar to disk", e);
View Full Code Here

      try
      {
         if(scriptStream != null && scriptStream.available() > 0)
         {
            BytemanConfiguration config = BytemanConfiguration.from(
                    Thread.currentThread().getContextClassLoader().getResourceAsStream(BytemanConfiguration.BYTEMAN_CONFIG)
            );
            String ruleKey = Thread.currentThread().getName();
            String ruleScript = GenerateScriptUtil.toString(scriptStream);
            try
            {
               Submit submit = new Submit(Submit.DEFAULT_ADDRESS, config.containerAgentPort());
               submit.addScripts(Arrays.asList(new ScriptText(ruleKey, ruleScript)));
            }
            catch (Exception e)
            {
               throw new SubmitException("Could not install script from file", e);
View Full Code Here

      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      InputStream scriptStream = cl.getResourceAsStream(BytemanConfiguration.BYTEMAN_SCRIPT);

      if(scriptStream != null)
      {
         BytemanConfiguration config = BytemanConfiguration.from(
                 Thread.currentThread().getContextClassLoader().getResourceAsStream(BytemanConfiguration.BYTEMAN_CONFIG)
         );

         String ruleKey = Thread.currentThread().getName();
         String ruleScript = GenerateScriptUtil.toString(scriptStream);
         try
         {
             Submit submit = new Submit(Submit.DEFAULT_ADDRESS, config.containerAgentPort());
            submit.deleteScripts(Arrays.asList(new ScriptText(ruleKey, ruleScript)));
         }
         catch (Exception e)
         {
            throw new SubmitException("Could not uninstall script from file", e);
View Full Code Here

TOP

Related Classes of org.jboss.arquillian.extension.byteman.impl.common.BytemanConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.