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;
  }
 @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()));
 }
  @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);
  }
Exemple #4
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);
 }
Exemple #7
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"));
    }
  }