@SingletonDefault(implFor = RemoteClasspathService.class)
public class RemoteClasspathServiceImpl implements RemoteClasspathService {

  protected static final Pattern GWT_XML_PATTERN = Pattern.compile(".*gwt[.]*xml");

  protected final ClasspathScanner scanner = X_Inject.instance(ClasspathScanner.class);

  protected final LazyPojo<String> gwtcHome =
      new LazyPojo<String>() {
        protected String initialValue() {
          return System.getProperty(GWTC_HOME);
        };
      };

  protected final LazyPojo<Map<String, String>> gwtModules =
      new LazyPojo<Map<String, String>>() {
        protected Map<String, String> initialValue() {
          Map<String, String> map = new HashMap<String, String>();
          ClasspathResourceMap resources =
              scanner
                  .matchResource(".*[.]gwt[.]*xml")
                  .scan(Thread.currentThread().getContextClassLoader());
          for (StringDataResource resource : resources.findResources("", GWT_XML_PATTERN)) {
            try {
              Xpp3Dom dom = Xpp3DomBuilder.build(resource.open(), "UTF-8");
              String rename = dom.getAttribute("rename-to");
              if (rename != null) {
                String resName = resource.getResourceName().replace('/', '.');
                resName = resName.substring(0, resName.lastIndexOf("gwt") - 1);
                map.put(rename, resName);
                X_Log.trace("Found gwt module rename; ", rename, " -> ", resName);
              }
            } catch (Exception e) {
              X_Log.error(
                  "Error reading xml from ",
                  resource.getResourceName(),
                  e,
                  "\nSet xapi.log.level=TRACE to see the faulty xml");
              X_Log.trace("Faulty xml: ", resource.readAll());
            }
          }
          ;
          return map;
        };
      };

  @Override
  public ClasspathEntry[] getClasspath(String forModule, HttpServletRequest req) {
    boolean isShortName = forModule.indexOf('.') == -1;
    String longName = isShortName ? getLongName(forModule) : forModule;
    String home = gwtcHome.get();
    if (home == null) {
      return classpathFromClassloader(longName, Thread.currentThread().getContextClassLoader());
    }
    return null;
  }

  protected ClasspathEntry[] classpathFromClassloader(String longName, ClassLoader classLoader) {
    URL res = classLoader.getResource("META-INF/" + longName);
    if (res == null) {}
    return null;
  }

  protected String getLongName(String forModule) {
    Map<String, String> map = gwtModules.get();
    return map.containsKey(forModule) ? map.get(forModule) : forModule;
  }

  @Override
  public void setClasspath(
      String forModule, ClasspathEntry[] classpath, HttpServletRequest threadLocalRequest) {}
}
Example #2
0
 public static CharPool getCharPool() {
   return X_Inject.singleton(CharPool.class);
 }