use of org.apache.xbean.finder.ClassFinder in project aries by apache.
the class EnableAnnotationTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
ClassFinder classFinder = new ClassFinder(EnableAnnotationTest.class.getClassLoader());
beanClasses = findClasses(classFinder, Arrays.asList(TxBean.class.getPackage().getName()));
}
use of org.apache.xbean.finder.ClassFinder in project aries by apache.
the class GenerateMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
List<String> toScan = getPackagesToScan();
if (!sourcesChanged()) {
getLog().info("Skipping blueprint generation because source files were not changed");
return;
}
BlueprintConfigurationImpl blueprintConfiguration = new BlueprintConfigurationImpl(namespaces, defaultActivation, customParameters);
try {
ClassFinder classFinder = createProjectScopeFinder();
Set<Class<?>> classes = FilteredClassFinder.findClasses(classFinder, toScan);
Blueprint blueprint = new Blueprint(blueprintConfiguration, classes);
writeBlueprintIfNeeded(blueprint);
} catch (Exception e) {
throw new MojoExecutionException("Error building commands help", e);
}
}
use of org.apache.xbean.finder.ClassFinder in project karaf by apache.
the class GenerateServiceMetadata method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
try {
boolean addSourceDirectory = false;
StringBuilder requirements = new StringBuilder();
StringBuilder capabilities = new StringBuilder();
ClassFinder finder = createFinder(classLoader);
List<Class<?>> classes = finder.findAnnotatedClasses(Services.class);
List<Class<?>> activators = new ArrayList<>();
for (Class<?> clazz : classes) {
URL classUrl = clazz.getClassLoader().getResource(clazz.getName().replace('.', '/') + ".class");
URL outputDirectoryUrl = new File(project.getBuild().getOutputDirectory()).toURI().toURL();
if (classUrl == null || !classUrl.getPath().startsWith(outputDirectoryUrl.getPath())) {
System.out.println("Ignoring " + classUrl);
continue;
}
if (BundleActivator.class.isAssignableFrom(clazz)) {
activators.add(clazz);
}
Properties props = new Properties();
Services services = clazz.getAnnotation(Services.class);
if (services != null) {
for (RequireService req : services.requires()) {
String fltWithClass = combine(req.filter(), "(objectClass=" + req.value().getName() + ")");
addServiceReq(requirements, fltWithClass);
props.setProperty(req.value().getName(), req.filter());
}
for (ProvideService cap : services.provides()) {
addServiceCap(capabilities, cap);
}
}
Managed managed = clazz.getAnnotation(Managed.class);
if (managed != null) {
props.setProperty("pid", managed.value());
}
File file = new File(outputDirectory, "OSGI-INF/karaf-tracker/" + clazz.getName());
file.getParentFile().mkdirs();
try (OutputStream os = buildContext.newFileOutputStream(file)) {
props.store(os, null);
}
addSourceDirectory = true;
}
if (addSourceDirectory) {
Resource resource = new Resource();
resource.setDirectory(outputDirectory);
project.addResource(resource);
}
project.getProperties().setProperty(requirementsProperty, requirements.toString());
project.getProperties().setProperty(capabilitiesProperty, capabilities.toString());
if (activators.size() == 1) {
project.getProperties().setProperty(activatorProperty, activators.get(0).getName());
}
project.getProperties().setProperty("BNDExtension-Private-Package", "org.apache.karaf.util.tracker");
project.getProperties().setProperty("BNDPrependExtension-Import-Package", "!org.apache.karaf.util.tracker.annotation");
List<Class<?>> services = finder.findAnnotatedClasses(Service.class);
Set<String> packages = new TreeSet<>();
for (Class<?> clazz : services) {
packages.add(clazz.getPackage().getName());
}
if (!packages.isEmpty()) {
project.getProperties().setProperty("BNDExtension-Karaf-Commands", join(packages, ","));
}
} catch (Exception e) {
throw new MojoExecutionException("Error building commands help", e);
}
}
use of org.apache.xbean.finder.ClassFinder in project karaf by apache.
the class GenerateHelpMojo method createFinder.
private ClassFinder createFinder(String classloaderType) throws Exception {
ClassFinder finder;
if ("project".equals(classloaderType)) {
List<URL> urls = new ArrayList<>();
for (Object object : project.getCompileClasspathElements()) {
String path = (String) object;
urls.add(new File(path).toURI().toURL());
}
ClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader());
finder = new ClassFinder(loader, urls);
} else if ("plugin".equals(classLoader)) {
finder = new ClassFinder(getClass().getClassLoader());
} else {
throw new MojoFailureException("classLoader attribute must be 'project' or 'plugin'");
}
return finder;
}
use of org.apache.xbean.finder.ClassFinder in project tomee by apache.
the class InterceptorData method scan.
public static InterceptorData scan(final Class<?> clazz) {
final InterceptorData model = CACHE.get(clazz);
if (model != null) {
final InterceptorData data = new InterceptorData(clazz);
data.aroundInvoke.addAll(model.getAroundInvoke());
data.postConstruct.addAll(model.getPostConstruct());
data.preDestroy.addAll(model.getPreDestroy());
data.postActivate.addAll(model.getPostActivate());
data.prePassivate.addAll(model.getPrePassivate());
data.afterBegin.addAll(model.getAfterBegin());
data.beforeCompletion.addAll(model.getBeforeCompletion());
data.afterCompletion.addAll(model.getAfterCompletion());
data.aroundTimeout.addAll(model.getAroundTimeout());
return data;
}
final ClassFinder finder = new ClassFinder(clazz);
final InterceptorData data = new InterceptorData(clazz);
add(finder, data.aroundInvoke, AroundInvoke.class);
add(finder, data.postConstruct, PostConstruct.class);
add(finder, data.preDestroy, PreDestroy.class);
add(finder, data.postActivate, PostActivate.class);
add(finder, data.prePassivate, PrePassivate.class);
add(finder, data.afterBegin, AfterBegin.class);
add(finder, data.beforeCompletion, BeforeCompletion.class);
add(finder, data.afterCompletion, AfterCompletion.class);
add(finder, data.aroundTimeout, AroundTimeout.class);
return data;
}
Aggregations