示例#1
1
  /** @return returns a string list of all pathes */
  public static Resource[] getClassPathes() {

    if (classPathes != null) return classPathes;

    ArrayList pathes = new ArrayList();
    String pathSeperator = System.getProperty("path.separator");
    if (pathSeperator == null) pathSeperator = ";";

    // java.ext.dirs
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();

    // pathes from system properties
    String strPathes = System.getProperty("java.class.path");
    if (strPathes != null) {
      Array arr = ListUtil.listToArrayRemoveEmpty(strPathes, pathSeperator);
      int len = arr.size();
      for (int i = 1; i <= len; i++) {
        Resource file = frp.getResource(Caster.toString(arr.get(i, ""), "").trim());
        if (file.exists()) pathes.add(ResourceUtil.getCanonicalResourceEL(file));
      }
    }

    // pathes from url class Loader (dynamic loaded classes)
    ClassLoader cl = new Info().getClass().getClassLoader();
    if (cl instanceof URLClassLoader) getClassPathesFromClassLoader((URLClassLoader) cl, pathes);

    return classPathes = (Resource[]) pathes.toArray(new Resource[pathes.size()]);
  }
示例#2
0
  /**
   * This private worker method attempts to find [java_home]/lib/tools.jar. Note: The tools.jar is a
   * part of the SDK, it is not present in the JRE.
   *
   * @return If tools.jar can be found, a File representing tools.jar. <br>
   *     If tools.jar cannot be found, null.
   */
  private static Resource findToolsJar(Config config, Log log, RefBoolean useOurOwn) {
    log.info("Instrumentation", "looking for tools.jar");
    String javaHome = System.getProperty("java.home");
    Resource javaHomeFile = ResourcesImpl.getFileResourceProvider().getResource(javaHome);

    Resource toolsJarFile = javaHomeFile.getRealResource("lib" + File.separator + "tools.jar");
    if (toolsJarFile.exists()) {
      useOurOwn.setValue(false);
      return toolsJarFile;
    }
    log.info("Instrumentation", "couldn't find tools.jar at: " + toolsJarFile.getAbsolutePath());

    // If we're on an IBM SDK, then remove /jre off of java.home and try again.
    if (javaHomeFile.getAbsolutePath().endsWith(SEP + "jre")) {
      javaHomeFile = javaHomeFile.getParentResource();
      toolsJarFile = javaHomeFile.getRealResource("lib" + SEP + "tools.jar");
      if (!toolsJarFile.exists()) {
        log.info("Instrumentation", "for IBM SDK couldn't find " + toolsJarFile.getAbsolutePath());
      } else {
        useOurOwn.setValue(false);
        return toolsJarFile;
      }
    } else if (System.getProperty("os.name").toLowerCase().indexOf("mac") >= 0) {
      // If we're on a Mac, then change the search path to use ../Classes/classes.jar.
      if (javaHomeFile.getAbsolutePath().endsWith(SEP + "Home")) {
        javaHomeFile = javaHomeFile.getParentResource();
        toolsJarFile = javaHomeFile.getRealResource("Classes" + SEP + "classes.jar");
        if (!toolsJarFile.exists()) {
          log.info("Instrumentation", "for Mac OS couldn't find " + toolsJarFile.getAbsolutePath());
        } else {
          useOurOwn.setValue(false);
          return toolsJarFile;
        }
      }
    }

    // if the engine could not find the tools.jar it is using it's own version
    try {
      toolsJarFile = createToolsJar(config);
    } catch (IOException e) {
      log.error("Instrumentation", e);
    }

    if (!toolsJarFile.exists()) {
      log.info("Instrumentation", "could not be created " + toolsJarFile.getAbsolutePath());
      return null;
    }
    log.info("Instrumentation", "found " + toolsJarFile.getAbsolutePath());
    return toolsJarFile;
  }
示例#3
0
 private void checkSize(ConfigWeb config, Resource dir, long maxSize, ResourceFilter filter) {
   if (!dir.exists()) return;
   Resource res = null;
   int count = ArrayUtil.size(filter == null ? dir.list() : dir.list(filter));
   long size = ResourceUtil.getRealSize(dir, filter);
   PrintWriter out = config.getOutWriter();
   SystemOut.printDate(out, "check size of directory [" + dir + "]");
   SystemOut.printDate(out, "- current size	[" + size + "]");
   SystemOut.printDate(out, "- max size 	[" + maxSize + "]");
   int len = -1;
   while (count > 100000 || size > maxSize) {
     Resource[] files = filter == null ? dir.listResources() : dir.listResources(filter);
     if (len == files.length) break; // protect from inifinti loop
     len = files.length;
     for (int i = 0; i < files.length; i++) {
       if (res == null || res.lastModified() > files[i].lastModified()) {
         res = files[i];
       }
     }
     if (res != null) {
       size -= res.length();
       try {
         res.remove(true);
         count--;
       } catch (IOException e) {
         SystemOut.printDate(out, "cannot remove resource " + res.getAbsolutePath());
         break;
       }
     }
     res = null;
   }
 }
示例#4
0
  private void checkOldClientFile(ConfigWeb config) {
    ExtensionResourceFilter filter = new ExtensionResourceFilter(".script", false);

    // move old structured file in new structure
    try {
      Resource dir = config.getClientScopeDir(), trgres;
      Resource[] children = dir.listResources(filter);
      String src, trg;
      int index;
      for (int i = 0; i < children.length; i++) {
        src = children[i].getName();
        index = src.indexOf('-');

        trg =
            StorageScopeFile.getFolderName(
                src.substring(0, index), src.substring(index + 1), false);
        trgres = dir.getRealResource(trg);
        if (!trgres.exists()) {
          trgres.createFile(true);
          ResourceUtil.copy(children[i], trgres);
        }
        // children[i].moveTo(trgres);
        children[i].delete();
      }
    } catch (Throwable t) {
    }
  }
示例#5
0
  /**
   * gets a file from server and copy it local
   *
   * @return FTPCLient
   * @throws PageException
   * @throws IOException
   */
  private AFTPClient actionGetFile() throws PageException, IOException {
    required("remotefile", remotefile);
    required("localfile", localfile);

    AFTPClient client = getClient();
    Resource local =
        ResourceUtil.toResourceExistingParent(pageContext, localfile); // new File(localfile);
    pageContext.getConfig().getSecurityManager().checkFileLocation(local);
    if (failifexists && local.exists())
      throw new ApplicationException(
          "File ["
              + local
              + "] already exist, if you want to overwrite, set attribute failIfExists to false");
    OutputStream fos = null;
    client.setFileType(getType(local));
    boolean success = false;
    try {
      fos = IOUtil.toBufferedOutputStream(local.getOutputStream());
      success = client.retrieveFile(remotefile, fos);
    } finally {
      IOUtil.closeEL(fos);
      if (!success) local.delete();
    }
    writeCfftp(client);

    return client;
  }
示例#6
0
 /** @return return System directory */
 public static Resource getSystemDirectory() {
   String pathes = System.getProperty("java.library.path");
   ResourceProvider fr = ResourcesImpl.getFileResourceProvider();
   if (pathes != null) {
     String[] arr = ListUtil.toStringArrayEL(ListUtil.listToArray(pathes, File.pathSeparatorChar));
     for (int i = 0; i < arr.length; i++) {
       if (arr[i].toLowerCase().indexOf("windows\\system") != -1) {
         Resource file = fr.getResource(arr[i]);
         if (file.exists() && file.isDirectory() && file.isWriteable())
           return ResourceUtil.getCanonicalResourceEL(file);
       }
     }
     for (int i = 0; i < arr.length; i++) {
       if (arr[i].toLowerCase().indexOf("windows") != -1) {
         Resource file = fr.getResource(arr[i]);
         if (file.exists() && file.isDirectory() && file.isWriteable())
           return ResourceUtil.getCanonicalResourceEL(file);
       }
     }
     for (int i = 0; i < arr.length; i++) {
       if (arr[i].toLowerCase().indexOf("winnt") != -1) {
         Resource file = fr.getResource(arr[i]);
         if (file.exists() && file.isDirectory() && file.isWriteable())
           return ResourceUtil.getCanonicalResourceEL(file);
       }
     }
     for (int i = 0; i < arr.length; i++) {
       if (arr[i].toLowerCase().indexOf("win") != -1) {
         Resource file = fr.getResource(arr[i]);
         if (file.exists() && file.isDirectory() && file.isWriteable())
           return ResourceUtil.getCanonicalResourceEL(file);
       }
     }
     for (int i = 0; i < arr.length; i++) {
       Resource file = fr.getResource(arr[i]);
       if (file.exists() && file.isDirectory() && file.isWriteable())
         return ResourceUtil.getCanonicalResourceEL(file);
     }
   }
   return null;
 }
示例#7
0
 private static Resource getBinDirectory(Config config) {
   Resource dir = ConfigWebUtil.getConfigServerDirectory(config);
   if (dir == null || !dir.isWriteable() || !dir.isReadable())
     dir =
         ResourceUtil.toResource(
             CFMLEngineFactory.getClassLoaderRoot(SystemUtil.getLoaderClassLoader()));
   else {
     dir = dir.getRealResource("bin");
     if (!dir.exists()) dir.mkdir();
   }
   return dir;
 }
示例#8
0
  /**
   * get class pathes from all url ClassLoaders
   *
   * @param ucl URL Class Loader
   * @param pathes Hashmap with allpathes
   */
  private static void getClassPathesFromClassLoader(URLClassLoader ucl, ArrayList pathes) {
    ClassLoader pcl = ucl.getParent();
    // parent first
    if (pcl instanceof URLClassLoader) getClassPathesFromClassLoader((URLClassLoader) pcl, pathes);

    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
    // get all pathes
    URL[] urls = ucl.getURLs();
    for (int i = 0; i < urls.length; i++) {
      Resource file = frp.getResource(urls[i].getPath());
      if (file.exists()) pathes.add(ResourceUtil.getCanonicalResourceEL(file));
    }
  }
示例#9
0
  private static Resource createAgentJar(Log log, Config c) throws IOException {
    Resource trg = getDeployDirectory(c).getRealResource("lucee-external-agent.jar");

    if (!trg.exists() || trg.length() == 0) {
      log.info("Instrumentation", "create " + trg);
      InputStream jar =
          InfoImpl.class.getResourceAsStream("/resource/lib/lucee-external-agent.jar");
      if (jar == null) {
        throw new IOException("could not load jar [/resource/lib/lucee-external-agent.jar]");
      }

      IOUtil.copy(jar, trg, true);
    }
    return trg;
  }
示例#10
0
  private static void addAttachIfNecessary(Config config, Log log) {

    String srcName = null, trgName = null;
    String archBits = (SystemUtil.getJREArch() == SystemUtil.ARCH_64) ? "64" : "32";

    // Windows
    if (SystemUtil.isWindows()) {
      trgName = "attach.dll";
      srcName = "windows" + archBits + "/" + trgName;
    }
    // Linux
    else if (SystemUtil.isLinux()) {
      trgName = "libattach.so";
      srcName = "linux" + archBits + "/" + trgName;
    }
    // Solaris
    else if (SystemUtil.isSolaris()) {
      trgName = "libattach.so";
      srcName = "solaris" + archBits + "/" + trgName;
    }
    // Mac OSX
    else if (SystemUtil.isMacOSX()) {
      trgName = "libattach.dylib";
      srcName = "macosx" + archBits + "/" + trgName;
    }

    if (srcName != null) {

      // create dll if necessary
      Resource binDir = getBinDirectory(config);
      Resource trg = binDir.getRealResource(trgName);
      if (!trg.exists() || trg.length() == 0) {
        log.info("Instrumentation", "deploy /resource/bin/" + srcName + " to " + trg);
        InputStream src = InfoImpl.class.getResourceAsStream("/resource/bin/" + srcName);
        try {
          IOUtil.copy(src, trg, true);
        } catch (IOException e) {
          log.log(Log.LEVEL_ERROR, "Instrumentation", e);
        }
      }

      // set directory to library path
      SystemUtil.addLibraryPathIfNoExist(binDir, log);
    }
  }
示例#11
0
  private static Resource createToolsJar(Config config) throws IOException {
    Resource dir = getDeployDirectory(config);

    String os = "bsd"; // used for Mac OS X
    if (SystemUtil.isWindows()) {
      os = "windows";
    } else if (SystemUtil.isLinux()) { // not MacOSX
      os = "linux";
    } else if (SystemUtil.isSolaris()) {
      os = "solaris";
    }
    String name = "tools-" + os + "-" + TOOLS_VERSION + ".jar";
    Resource trg = dir.getRealResource(name);

    if (!trg.exists() || trg.length() == 0) {

      InputStream jar = InfoImpl.class.getResourceAsStream("/resource/lib/" + name);
      IOUtil.copy(jar, trg, true);
    }
    return trg;
  }
示例#12
0
 /**
  * returns the Temp Directory of the System
  *
  * @return temp directory
  */
 public static Resource getTempDirectory() {
   if (tempFile != null) return tempFile;
   ResourceProvider fr = ResourcesImpl.getFileResourceProvider();
   String tmpStr = System.getProperty("java.io.tmpdir");
   if (tmpStr != null) {
     tempFile = fr.getResource(tmpStr);
     if (tempFile.exists()) {
       tempFile = ResourceUtil.getCanonicalResourceEL(tempFile);
       return tempFile;
     }
   }
   File tmp = null;
   try {
     tmp = File.createTempFile("a", "a");
     tempFile = fr.getResource(tmp.getParent());
     tempFile = ResourceUtil.getCanonicalResourceEL(tempFile);
   } catch (IOException ioe) {
   } finally {
     if (tmp != null) tmp.delete();
   }
   return tempFile;
 }
  @Override
  public void init(lucee.runtime.config.Config config, Resource searchDir)
      throws IOException, SearchException {
    this.config = config;
    this.searchDir = searchDir;
    this.searchFile = searchDir.getRealResource("search.xml");
    if (!searchFile.exists() || searchFile.length() == 0) createSearchFile(searchFile);

    DOMParser parser = new DOMParser();
    InputStream is = null;
    try {
      is = engine.getIOUtil().toBufferedInputStream(searchFile.getInputStream());
      InputSource source = new InputSource(is);
      parser.parse(source);
    } catch (SAXException e) {
      throw new SearchException(e);
    } finally {
      engine.getIOUtil().closeSilent(is);
    }
    doc = parser.getDocument();

    readCollections(config);
  }