PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/plugin-module-codegen-maven-client/src/main/java/com/atlassian/maven/plugins/amps/codegen/ContextProviderFactory.java

https://bitbucket.org/mmeinhold/amps
Java | 47 lines | 36 code | 8 blank | 3 comment | 1 complexity | ee3a5e234d2c572bf3ea9b183cacd168 MD5 | raw file
 1package com.atlassian.maven.plugins.amps.codegen;
 2
 3import java.io.File;
 4import java.net.URL;
 5import java.net.URLClassLoader;
 6import java.util.ArrayList;
 7import java.util.List;
 8import java.util.Map;
 9import java.util.TreeMap;
10
11import com.atlassian.maven.plugins.amps.codegen.annotations.asm.ProductContextProviderLocator;
12
13/**
14 * @since 3.6
15 */
16public class ContextProviderFactory
17{
18    protected static Map<String, String> providers = new TreeMap<String, String>();
19
20    public static void locateAvailableContextProviders(String productId, List<String> classpathElements) throws Exception
21    {
22        List<URL> conditionURLs = new ArrayList<URL>();
23        for (String path : classpathElements)
24        {
25            File aFile = new File(path);
26            conditionURLs.add(aFile.toURI()
27                    .toURL());
28        }
29
30        URLClassLoader conditionLoader = URLClassLoader.newInstance(conditionURLs.toArray(new URL[]{}));
31        ClassLoader oldLoader = Thread.currentThread()
32                .getContextClassLoader();
33        Thread.currentThread()
34                .setContextClassLoader(conditionLoader);
35
36        ProductContextProviderLocator locator = new ProductContextProviderLocator(productId, providers);
37        locator.parse();
38
39        Thread.currentThread()
40                .setContextClassLoader(oldLoader);
41    }
42
43    public static Map<String, String> getAvailableContextProviders()
44    {
45        return providers;
46    }
47}