PageRenderTime 28ms CodeModel.GetById 14ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

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

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