groovy.lang.GroovyClassLoader.getResource()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中groovy.lang.GroovyClassLoader.getResource()方法的一些代码示例,展示了GroovyClassLoader.getResource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GroovyClassLoader.getResource()方法的具体详情如下:
包路径:groovy.lang.GroovyClassLoader
类名称:GroovyClassLoader
方法名:getResource

GroovyClassLoader.getResource介绍

暂无

代码示例

代码示例来源:origin: org.codehaus.groovy/groovy

public URL getResource(String name) {
  return delegate.getResource(name);
}

代码示例来源:origin: org.codehaus.groovy/groovy

private URL getSourceFile(String name, String extension) {
  String filename = name.replace('.', '/') + "." + extension;
  URL ret = getResource(filename);
  if (isFile(ret) && getFileForUrl(ret, filename) == null) return null;
  return ret;
}

代码示例来源:origin: groovy/groovy-core

public void testCodeSource() throws IOException, CompilationFailedException {
  URL script = loader.getResource("groovy/ArrayTest.groovy");
  try {
    new GroovyCodeSource(script);
  } catch (RuntimeException re) {
    assertEquals("Could not construct a GroovyCodeSource from a null URL", re.getMessage());
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy

/**
 * Search for classes using ASM decompiler
 */
private LookupResult findDecompiled(String name, CompilationUnit compilationUnit, GroovyClassLoader loader) {
  ClassNode node = ClassHelper.make(name);
  if (node.isResolved()) {
    return new LookupResult(null, node);
  }
  DecompiledClassNode asmClass = null;
  String fileName = name.replace('.', '/') + ".class";
  URL resource = loader.getResource(fileName);
  if (resource != null) {
    try {
      asmClass = new DecompiledClassNode(AsmDecompiler.parseClass(resource), new AsmReferenceResolver(this, compilationUnit));
      if (!asmClass.getName().equals(name)) {
        // this may happen under Windows because getResource is case insensitive under that OS!
        asmClass = null;
      }
    } catch (IOException e) {
      // fall through and attempt other search strategies
    }
  }
  if (asmClass != null) {
    if (isFromAnotherClassLoader(loader, fileName)) {
      return tryAsScript(name, compilationUnit, asmClass);
    }
    return new LookupResult(null, asmClass);
  }
  return null;
}

代码示例来源:origin: org.codehaus.groovy/groovy-jdk14

public URL getResource(String name) {
  return delegate.getResource(name);
}

代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

public URL getResource(String name) {
  return delegate.getResource(name);
}

代码示例来源:origin: org.kohsuke.droovy/groovy

public URL getResource(String name) {
  return delegate.getResource(name);
}

代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal

public URL getResource(String name) {
  return delegate.getResource(name);
}

代码示例来源:origin: stapler/stapler

/**
   * Groovy calls this method to locate .groovy script files,
   * so during the development it's important to check the
   * resource path before target/classes.
   */
  @Override
  public URL getResource(String name) {
    // allow the resource path to take precedence when loading script
    if(MetaClassLoader.debugLoader!=null) {
      URL res = MetaClassLoader.debugLoader.loader.getResource(name);
      if(res!=null)
        return res;
    }
    return super.getResource(name);
  }
};

代码示例来源:origin: freeplane/freeplane

private URL superGetResource(String name) {
  if(name.startsWith(Script.class.getPackage().getName().replace('.', '/') + '/'))
    return Script.class.getClassLoader().getResource(name);
  return super.getResource(name);
}

代码示例来源:origin: org.springframework.boot/spring-boot-cli

@Override
  protected boolean canAdd() {
    for (String path : paths) {
      try {
        if (DependencyCustomizer.this.loader.getResource(path) == null) {
          return false;
        }
        return true;
      }
      catch (Exception ex) {
        // swallow exception and continue
      }
    }
    return DependencyCustomizer.this.canAdd();
  }
};

代码示例来源:origin: org.springframework.boot/spring-boot-cli

@Override
  protected boolean canAdd() {
    for (String path : paths) {
      try {
        if (DependencyCustomizer.this.loader.getResource(path) != null) {
          return true;
        }
        return false;
      }
      catch (Exception ex) {
        // swallow exception and continue
      }
    }
    return DependencyCustomizer.this.canAdd();
  }
};

代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

private URL getSourceFile(String name, String extension) {
  String filename = name.replace('.', '/') + "." + extension;
  URL ret = getResource(filename);
  if (isFile(ret) && getFileForUrl(ret, filename) == null) return null;
  return ret;
}

代码示例来源:origin: org.kohsuke.droovy/groovy

private URL getSourceFile(String name) {
  String filename = name.replace('.', '/') + config.getDefaultScriptExtension();
  URL ret = getResource(filename);
  if (ret != null && ret.getProtocol().equals("file")) {
    String fileWithoutPackage = filename;
    if (fileWithoutPackage.indexOf('/') != -1) {
      int index = fileWithoutPackage.lastIndexOf('/');
      fileWithoutPackage = fileWithoutPackage.substring(index + 1);
    }
    File path = new File(decodeFileName(ret.getFile())).getParentFile();
    if (path.exists() && path.isDirectory()) {
      File file = new File(path, fileWithoutPackage);
      if (file.exists()) {
        // file.exists() might be case insensitive. Let's do
        // case sensitive match for the filename
        File parent = file.getParentFile();
        String[] files = parent.list();
        for (int j = 0; j < files.length; j++) {
          if (files[j].equals(fileWithoutPackage)) return ret;
        }
      }
    }
    //file does not exist!
    return null;
  }
  return ret;
}

代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal

private URL getSourceFile(String name) {
  String filename = name.replace('.', '/') + config.getDefaultScriptExtension();
  URL ret = getResource(filename);
  if (ret != null && ret.getProtocol().equals("file")) {
    String fileWithoutPackage = filename;
    if (fileWithoutPackage.indexOf('/') != -1) {
      int index = fileWithoutPackage.lastIndexOf('/');
      fileWithoutPackage = fileWithoutPackage.substring(index + 1);
    }
    File path = new File(decodeFileName(ret.getFile())).getParentFile();
    if (path.exists() && path.isDirectory()) {
      File file = new File(path, fileWithoutPackage);
      if (file.exists()) {
        // file.exists() might be case insensitive. Let's do
        // case sensitive match for the filename
        File parent = file.getParentFile();
        String[] files = parent.list();
        for (int j = 0; j < files.length; j++) {
          if (files[j].equals(fileWithoutPackage)) return ret;
        }
      }
    }
    //file does not exist!
    return null;
  }
  return ret;
}

代码示例来源:origin: org.codehaus.groovy/groovy-jdk14

private URL getSourceFile(String name) {
  String filename = name.replace('.', '/') + config.getDefaultScriptExtension();
  URL ret = getResource(filename);
  if (isFile(ret) && getFileForUrl(ret,filename)==null) return null;
  return ret;
}

相关文章