1 package com.atlassian.maven.plugins.amps.codegen;
2
3 import java.io.File;
4 import java.net.URL;
5 import java.net.URLClassLoader;
6 import java.util.*;
7
8 import com.atlassian.maven.plugins.amps.codegen.annotations.asm.ProductConditionsLocator;
9
10
11
12
13 public class ConditionFactory
14 {
15 protected static Map<String, String> conditions = new TreeMap<String, String>();
16
17 public static void locateAvailableConditions(String productId, List<String> classpathElements) throws Exception
18 {
19 List<URL> conditionURLs = new ArrayList<URL>();
20 for (String path : classpathElements)
21 {
22 File aFile = new File(path);
23 conditionURLs.add(aFile.toURI()
24 .toURL());
25 }
26
27 URLClassLoader conditionLoader = URLClassLoader.newInstance(conditionURLs.toArray(new URL[]{}));
28 ClassLoader oldLoader = Thread.currentThread()
29 .getContextClassLoader();
30 Thread.currentThread()
31 .setContextClassLoader(conditionLoader);
32
33 ProductConditionsLocator locator = new ProductConditionsLocator(productId, conditions);
34 locator.parse();
35
36 Thread.currentThread()
37 .setContextClassLoader(oldLoader);
38 }
39
40 public static Map<String, String> getAvailableConditions()
41 {
42 return Collections.unmodifiableMap(conditions);
43 }
44 }