@Test
 public void getDocumentoClasificado() throws Exception {
   Documento documento = clasificarDocumentoDeTest(TEST_FILE_CONTENT);
   BinaryResponse response = gestorDocumentalService.getDocumento(documento);
   assertEquals(TEST_FILENAME, response.nombre);
   assertEquals(TEST_FILE_CONTENT, IO.readContentAsString(response.contenido.getInputStream()));
 }
Beispiel #2
0
  public static synchronized Stack<Evolution> listApplicationEvolutions() {
    Stack<Evolution> evolutions = new Stack<Evolution>();
    evolutions.add(new Evolution(0, "", "", true));
    if (evolutionsDirectory.exists()) {
      for (File evolution : evolutionsDirectory.listFiles()) {
        if (evolution.getName().matches("^[0-9]+[.]sql$")) {
          if (Logger.isTraceEnabled()) {
            Logger.trace("Loading evolution %s", evolution);
          }

          int version =
              Integer.parseInt(evolution.getName().substring(0, evolution.getName().indexOf(".")));
          String sql = IO.readContentAsString(evolution);
          StringBuffer sql_up = new StringBuffer();
          StringBuffer sql_down = new StringBuffer();
          StringBuffer current = new StringBuffer();
          for (String line : sql.split("\r?\n")) {
            if (line.trim().matches("^#.*[!]Ups")) {
              current = sql_up;
            } else if (line.trim().matches("^#.*[!]Downs")) {
              current = sql_down;
            } else if (line.trim().startsWith("#")) {
              // skip
            } else if (!StringUtils.isEmpty(line.trim())) {
              current.append(line).append("\n");
            }
          }
          evolutions.add(new Evolution(version, sql_up.toString(), sql_down.toString(), true));
        }
      }
      Collections.sort(evolutions);
    }
    return evolutions;
  }
Beispiel #3
0
 private static void writePID(File root) {
   String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
   File pidfile = new File(root, PID_FILE);
   if (pidfile.exists()) {
     throw new RuntimeException(
         "The " + PID_FILE + " already exists. Is the server already running?");
   }
   IO.write(pid.getBytes(), pidfile);
 }
  @Test
  public void getDocumento() throws Exception {
    Documento d = saveTmpDocumento(TEST_FILE_CONTENT, TEST_FILENAME);

    BinaryResponse response = gestorDocumentalService.getDocumento(d);
    assertEquals(TEST_FILENAME, response.nombre);

    String responseContent = IO.readContentAsString(response.contenido.getInputStream());
    assertEquals(TEST_FILE_CONTENT, responseContent);
  }
Beispiel #5
0
 private void findDependencies(File sass, List<File> all) {
   try {
     if (sass.exists()) {
       all.add(sass);
       Matcher m = imports.matcher(IO.readContentAsString(sass));
       while (m.find()) {
         String fileName = m.group(1);
         for (String path : sassPaths) {
           File depImport = findImport(path, fileName);
           if (depImport != null) {
             findDependencies(depImport, all);
             break;
           }
         }
       }
     }
   } catch (Exception e) {
     Logger.error(e, "in SASS.findDependencies");
   }
 }
  /*
   * Get the set of modules for the current project. This include old-style (using application.conf)
   * and new style, with dependencies starting at 1.2 (load everything from the modules/ dir)
   */
  private Set<File> modules() {
    Set<File> modules = new HashSet<File>();

    // Old-skool
    for (Map.Entry<String, String> entry : properties().entrySet()) {
      if (!entry.getKey().startsWith("module.")) {
        continue;
      }
      String s = project.replaceProperties(entry.getValue());
      File moduleDir;
      if (!FileUtils.isAbsolutePath(s)) {
        moduleDir = new File(new File(applicationDir, "conf"), s);
      } else {
        moduleDir = new File(s);
      }
      if (!moduleDir.exists()) {
        project.log(
            "Failed add non existing module to classpath! " + moduleDir.getAbsolutePath(),
            Project.MSG_WARN);
        continue;
      }
      modules.add(moduleDir);
    }

    // 1.2+ fashion
    File modulesDir = new File(applicationDir, "modules");
    if (modulesDir.exists()) {
      for (File child : modulesDir.listFiles()) {
        if (child == null) {
          // No-op
        } else if (child.isDirectory()) {
          modules.add(child);
        } else {
          modules.add(new File(IO.readContentAsString(child)));
        }
      }
    }
    return modules;
  }
 public static void getFile(String path) throws IOException {
   File f = new File(path);
   String contents = IO.readContentAsString(f);
   renderText(contents);
 }
Beispiel #8
0
  /** Load all modules. You can even specify the list using the MODULES environement variable. */
  public static void loadModules() {
    if (System.getenv("MODULES") != null) {
      // Modules path is prepended with a env property
      if (System.getenv("MODULES") != null && System.getenv("MODULES").trim().length() > 0) {
        for (String m :
            System.getenv("MODULES")
                .split(System.getProperty("os.name").startsWith("Windows") ? ";" : ":")) {
          File modulePath = new File(m);
          if (!modulePath.exists() || !modulePath.isDirectory()) {
            Logger.error(
                "Module %s will not be loaded because %s does not exist",
                modulePath.getName(), modulePath.getAbsolutePath());
          } else {
            final String modulePathName = modulePath.getName();
            final String moduleName =
                modulePathName.contains("-")
                    ? modulePathName.substring(0, modulePathName.lastIndexOf("-"))
                    : modulePathName;
            addModule(moduleName, modulePath);
          }
        }
      }
    }

    // Load modules from modules/ directory, but get the order from the dependencies.yml file
    // .listFiles() returns items in an OS dependant sequence, which is bad
    // See #781
    // the yaml parser wants play.version as an environment variable
    System.setProperty("play.version", Play.version);
    DependenciesManager dm = new DependenciesManager(applicationPath, frameworkPath, null);

    File localModules = Play.getFile("modules");
    List<String> modules = new ArrayList<String>();
    if (localModules.exists() && localModules.isDirectory()) {
      try {
        modules = dm.retrieveModules();
      } catch (Exception e) {
        Logger.error(
            "There was a problem parsing "
                + DependenciesManager.MODULE_ORDER_CONF
                + " (module will not be loaded in order of the dependencies.yml)",
            e);
        // Load module without considering the dependencies.yml order
        modules = Arrays.asList(localModules.list());
      }
      for (Iterator<String> iter = modules.iterator(); iter.hasNext(); ) {
        String moduleName = (String) iter.next();

        File module = new File(localModules, moduleName);

        if (moduleName.contains("-")) {
          moduleName = moduleName.substring(0, moduleName.indexOf("-"));
        }

        if (module.isDirectory()) {
          addModule(moduleName, module);
        } else {

          File modulePath = new File(IO.readContentAsString(module).trim());
          if (!modulePath.exists() || !modulePath.isDirectory()) {
            Logger.error(
                "Module %s will not be loaded because %s does not exist",
                moduleName, modulePath.getAbsolutePath());
          } else {
            addModule(moduleName, modulePath);
          }
        }
      }
    }

    // Auto add special modules
    if (Play.runningInTestMode()) {
      addModule("_testrunner", new File(Play.frameworkPath, "modules/testrunner"));
    }

    if (Play.mode == Mode.DEV) {
      addModule("_docviewer", new File(Play.frameworkPath, "modules/docviewer"));
    }
  }
Beispiel #9
0
  private static Properties readOneConfigurationFile(String filename) {
    Properties propsFromFile = null;

    VirtualFile appRoot = VirtualFile.open(applicationPath);

    VirtualFile conf = appRoot.child("conf/" + filename);
    if (confs.contains(conf)) {
      throw new RuntimeException(
          "Detected recursive @include usage. Have seen the file " + filename + " before");
    }

    try {
      propsFromFile = IO.readUtf8Properties(conf.inputstream());
    } catch (RuntimeException e) {
      if (e.getCause() instanceof IOException) {
        Logger.fatal("Cannot read " + filename);
        fatalServerErrorOccurred();
      }
    }
    confs.add(conf);

    // OK, check for instance specifics configuration
    Properties newConfiguration = new OrderSafeProperties();
    Pattern pattern = Pattern.compile("^%([a-zA-Z0-9_\\-]+)\\.(.*)$");
    for (Object key : propsFromFile.keySet()) {
      Matcher matcher = pattern.matcher(key + "");
      if (!matcher.matches()) {
        newConfiguration.put(key, propsFromFile.get(key).toString().trim());
      }
    }
    for (Object key : propsFromFile.keySet()) {
      Matcher matcher = pattern.matcher(key + "");
      if (matcher.matches()) {
        String instance = matcher.group(1);
        if (instance.equals(id)) {
          newConfiguration.put(matcher.group(2), propsFromFile.get(key).toString().trim());
        }
      }
    }
    propsFromFile = newConfiguration;
    // Resolve ${..}
    pattern = Pattern.compile("\\$\\{([^}]+)}");
    for (Object key : propsFromFile.keySet()) {
      String value = propsFromFile.getProperty(key.toString());
      Matcher matcher = pattern.matcher(value);
      StringBuffer newValue = new StringBuffer(100);
      while (matcher.find()) {
        String jp = matcher.group(1);
        String r;
        if (jp.equals("application.path")) {
          r = Play.applicationPath.getAbsolutePath();
        } else if (jp.equals("play.path")) {
          r = Play.frameworkPath.getAbsolutePath();
        } else {
          r = System.getProperty(jp);
          if (r == null) {
            r = System.getenv(jp);
          }
          if (r == null) {
            Logger.warn("Cannot replace %s in configuration (%s=%s)", jp, key, value);
            continue;
          }
        }
        matcher.appendReplacement(newValue, r.replaceAll("\\\\", "\\\\\\\\"));
      }
      matcher.appendTail(newValue);
      propsFromFile.setProperty(key.toString(), newValue.toString());
    }
    // Include
    Map<Object, Object> toInclude = new HashMap<Object, Object>(16);
    for (Object key : propsFromFile.keySet()) {
      if (key.toString().startsWith("@include.")) {
        try {
          String filenameToInclude = propsFromFile.getProperty(key.toString());
          toInclude.putAll(readOneConfigurationFile(filenameToInclude));
        } catch (Exception ex) {
          Logger.warn("Missing include: %s", key);
        }
      }
    }
    propsFromFile.putAll(toInclude);

    return propsFromFile;
  }