configure programmatically

0 views
Skip to first unread message

francisco treacy

unread,
Aug 19, 2008, 12:49:18 PM8/19/08
to Salve
hi igor,

is there a way of configuring salve programmatically, i.e. without the
META-INF/salve.xml file?

i already "know" the packages to be instrumented in my java Agent
(which in turn calls salve's Agent premain), so i'd like to pass those
values to initialize salve. that is, without the salve.xml file.

i looked at the code but found it quite tough to implement a different
config strategy.

thanks in advance,

francisco

Igor Vaynberg

unread,
Aug 25, 2008, 3:18:06 PM8/25/08
to salve...@googlegroups.com
hi francisco,

just got back from a vacation so bare with me. i just checked in a
small refactoring of the agent to break it up into more classes that
should make it easy for you to plug in your own implementation of
salve.Config.

let me know if this helps.

-igor

francisco treacy

unread,
Aug 25, 2008, 4:02:01 PM8/25/08
to salve...@googlegroups.com
no worries; it's known people happen to go on vacations sometimes :)

i'd love to test those changes right away, but my development laptop
just died... so bare with me. in a few days i'll setup the dev
environment again on a new computer and i'll let you know.
anyway code you checked in will surely facilitate the task, basically
implementing the abstract transformer i am good to go.

the interest is actually to finish a part of a little utility i plan
to commit shortly: http://code.google.com/p/gluw/ . this setup seems
to work perfectly for me so i wanted to share it (btw i implemented a
custom locator in front of guice's and works great).

francisco

francisco treacy

unread,
Sep 3, 2008, 11:17:16 AM9/3/08
to Salve
hi igor,

i came up with a quick CustomConfig (basically i always want to use
DependencyInstrumentor for classes in my defined packages)....which
seems to work perfectly well. however i haven't deeply tested it. do
you think always returning Scope.ALL is ok in this case?

public class CustomTransformer extends AbstractTransformer {

String[] packages;

public CustomTransformer(String... packages) {
this.packages = packages;
}

@Override
protected Config getConfig(ClassLoader loader, String className) {
return new CustomConfig(packages);
}

}

class CustomConfig implements Config {

private Instrumentor instrumentor = new DependencyInstrumentor();
private List<String> packageList;

public CustomConfig(String... packages) {
packageList = Arrays.asList(packages);
}

@Override
public Collection<Instrumentor> getInstrumentors(String className) {
String name = className.replace('/', '.');
for (String pkg : packageList) {
if (name.startsWith(pkg)) {
return Arrays.asList(instrumentor);
}
}
return Collections.emptyList();
}

@Override
public Scope getScope(Instrumentor inst) {
return Scope.ALL;
}

}

thanks,
francisco


On Aug 25, 10:02 pm, "francisco treacy" <francisco.tre...@gmail.com>
wrote:
> no worries; it's known people happen to go on vacations sometimes :)
>
> i'd love to test those changes right away, but my development laptop
> just died... so bare with me. in a few days i'll setup the dev
> environment again on a new computer and i'll let you know.
> anyway code you checked in will surely facilitate the task, basically
> implementing the abstract transformer i am good to go.
>
> the interest is actually to finish a part of a little utility i plan
> to commit shortly:http://code.google.com/p/gluw/. this setup seems
> to work perfectly for me so i wanted to share it (btw i implemented a
> custom locator in front of guice's and works great).
>
> francisco
>

Igor Vaynberg

unread,
Sep 3, 2008, 12:48:29 PM9/3/08
to salve...@googlegroups.com
should be fine. scope is there to speed up the process by eliminating
scanning of bytecode for classes you know you are not going to
instrument. but since instrumenting a class with no @dependency is a
noop in your case, it wont have any sideeffects.

-igor

Reply all
Reply to author
Forward
0 new messages