private void mountFiles(String path, Class<?> clazz) {
    try {
      List<Resource> list = new ArrayList<>();
      String packagePath = clazz.getPackage().getName().replace('.', '/');

      PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
      Resource[] res = resolver.getResources("classpath:" + packagePath + "/*.png");
      if (res != null) {
        list.addAll(Arrays.asList(res));
      }
      res = resolver.getResources("classpath:" + packagePath + "/*.gif");
      if (res != null) {
        list.addAll(Arrays.asList(res));
      }

      for (Resource resource : list) {
        URI uri = resource.getURI();
        File file = new File(uri.toString());
        mountResource(
            path + "/" + file.getName(), new SharedResourceReference(clazz, file.getName()));
      }
    } catch (Exception ex) {
      LoggingUtils.logUnexpectedException(LOGGER, "Couldn't mount files", ex);
    }
  }
  /** {@inheritDoc} */
  public void afterPropertiesSet() throws Exception {
    PathMatchingResourcePatternResolver resourcePatternResolver =
        new PathMatchingResourcePatternResolver();

    for (String location : locations) {
      Resource[] findings = resourcePatternResolver.getResources(location);

      for (Resource resource : findings) {
        if (resource.getFilename().endsWith(".xsd")) {
          log.info("Loading XSD schema resource " + resource.getFilename());
          SimpleXsdSchema schema = new SimpleXsdSchema(resource);
          schema.afterPropertiesSet();
          schemas.add(schema);
        } else if (resource.getFilename().endsWith(".wsdl")) {
          log.info("Loading WSDL schema resource " + resource.getFilename());
          WsdlXsdSchema wsdl = new WsdlXsdSchema(resource);
          wsdl.afterPropertiesSet();
          schemas.add(wsdl);
        } else {
          log.warn(
              "Skipped resource other than XSD schema for repository ("
                  + resource.getFilename()
                  + ")");
        }
      }
    }

    // Add default Citrus message schemas if available on classpath
    addCitrusSchema("citrus-mail-message");
    addCitrusSchema("citrus-ftp-message");
    addCitrusSchema("citrus-ssh-message");
  }
  protected Set<String> getTemplateNamesFromPath(String path) throws IOException {

    if (resourceLoader != null && grailsApplication.isWarDeployed()) {
      try {
        PathMatchingResourcePatternResolver resolver =
            new PathMatchingResourcePatternResolver(resourceLoader);
        return extractNames(
            resolver.getResources("/WEB-INF/templates/angular-scaffolding/" + path + "/*.gsp"));
      } catch (Exception e) {
        return Collections.emptySet();
      }
    }

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Set<String> resources = new HashSet<String>();

    String templatesDirPath = basedir + "/src/templates/angular-scaffolding/" + path;
    Resource templatesDir = new FileSystemResource(templatesDirPath);
    if (templatesDir.exists()) {
      try {
        resources.addAll(
            extractNames(resolver.getResources("file:" + templatesDirPath + "/*.gsp")));
      } catch (Exception e) {
        log.error("Error while loading views from " + basedir, e);
      }
    }

    return resources;
  }
 private Set<File> getEndToEndFilesFromResources() throws IOException {
   PathMatchingResourcePatternResolver res = new PathMatchingResourcePatternResolver();
   Resource[] resources = res.getResources("classpath*:" + FILE_PREFIX + ".*.*." + FILE_POSTFIX);
   HashSet<File> files = new HashSet<File>();
   for (Resource r : resources) {
     files.add(r.getFile());
   }
   return files;
 }
  @Bean
  public SqlSessionFactoryBean sqlSessionFactory() throws Exception {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();

    SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(dataSource());
    sessionFactory.setTypeAliasesPackage("demo.model");
    sessionFactory.setMapperLocations(resolver.getResources("classpath:sqlmap/*.xml"));
    return sessionFactory;
  }
Exemple #6
0
 @org.springframework.context.annotation.Bean
 public org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory(
     javax.sql.DataSource dataSource) throws java.lang.Exception {
   final org.mybatis.spring.SqlSessionFactoryBean sessionFactory =
       new org.mybatis.spring.SqlSessionFactoryBean();
   sessionFactory.setDataSource(dataSource);
   final org.springframework.core.io.support.PathMatchingResourcePatternResolver resolver =
       new org.springframework.core.io.support.PathMatchingResourcePatternResolver();
   sessionFactory.setMapperLocations(resolver.getResources("classpath*:**/*Mapper.xml"));
   return sessionFactory.getObject();
 }
 public Resource[] resolveResources(String pattern) {
   try {
     return resolver.getResources(pattern);
   } catch (Exception e) {
     return NO_RESOURCES;
   }
 }
  public String deploy(String fileName) {

    try {
      File f = new File(fileName);
      URL url = null;
      if (!f.exists()) {
        LogUtil.getCoreLog().info("Search classpath ...");
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        String path = "classpath:**/*" + fileName;
        Resource[] res = resolver.getResources(path);
        if (res.length > 0) {
          url = res[0].getURL();
        } else return path + " can not find in " + url;
      } else {
        url = f.toURI().toURL();
      }
      LogUtil.getCoreLog().info("Jar file path:" + url);
      JarFileService srv = JpaContext.getService(JarFileService.class);
      ReleasedJarFile jarFile = srv.deploy(url);
      String fname = null;
      try {
        fname = url.toURI().toURL().getFile();
      } catch (MalformedURLException | URISyntaxException e) {
        throw new GemliteException("Not a vaild url:" + url, e);
      }
      if (!srv.splitVersion(jarFile, fname)) {
        throw new GemliteException(fname + " not a valid jar file.");
      }

      //     if (!srv.checkDuplicate(jarFile))
      //     {
      //       throw new GemliteException(jarFile.getFileName() + " has no change.");
      //     }

      DeployParameter param =
          new DeployParameter(
              jarFile.getModuleName(), jarFile.getModuleType(), jarFile.getContent());
      FunctionUtil.deploy(param);
      srv.save(jarFile);
    } catch (IOException | GemliteException e) {
      e.printStackTrace();
      LogUtil.getCoreLog().error(fileName, e);
      return e.getMessage();
    }
    return "Deploy success";
  }
Exemple #9
0
  static {
    Package p = GrailsUtil.class.getPackage();
    String version = p != null ? p.getImplementationVersion() : null;
    if (version == null || isBlank(version)) {
      PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
      try {
        Resource[] manifests = resolver.getResources("classpath*:META-INF/MANIFEST.MF");
        Manifest grailsManifest = null;
        for (int i = 0; i < manifests.length; i++) {
          Resource r = manifests[i];
          InputStream inputStream = null;
          Manifest mf = null;
          try {
            inputStream = r.getInputStream();
            mf = new Manifest(inputStream);
          } finally {
            IOUtils.closeQuietly(inputStream);
          }
          String implTitle = mf.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_TITLE);
          if (!isBlank(implTitle) && implTitle.equals(GRAILS_IMPLEMENTATION_TITLE)) {
            grailsManifest = mf;
            break;
          }
        }

        if (grailsManifest != null) {
          version =
              grailsManifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
        }

        if (isBlank(version)) {
          LOG.error(
              "Unable to read Grails version from MANIFEST.MF. Are you sure the grails-core jar is on the classpath? ");
          version = "Unknown";
        }
      } catch (Exception e) {
        version = "Unknown";
        LOG.error(
            "Unable to read Grails version from MANIFEST.MF. Are you sure it the grails-core jar is on the classpath? "
                + e.getMessage(),
            e);
      }
    }
    GRAILS_VERSION = version;
  }
 /**
  * Uses the propertyFileBaseName to locate all .properties files on the classpath that match the
  * pattern "properties/{0 or more directories here/{somename}_displayer.properties", and sets the
  * locations field of the parent class to these Resources
  *
  * @param propertyFileBaseName the propertyFileBaseName to set
  * @throws IllegalArgumentException if any IOException is thrown attempting to resolve resource
  */
 public void setPropertyFileBaseName(String propertyFileBaseName) {
   this.propertyFileBaseName = propertyFileBaseName;
   PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
   Resource[] resources = new Resource[0];
   try {
     resources =
         resolver.getResources(
             "classpath*:properties/**/*_" + propertyFileBaseName + ".properties");
   } catch (IOException e) {
     Assert.isTrue(
         false,
         "IO exception when attempting to resolve resources for "
             + "classpath*:properties/**/*_"
             + propertyFileBaseName
             + ".properties");
   }
   this.setLocations(resources);
 }
 private Resource resolveExceptionSafe(String pathPattern) {
   try {
     Resource[] resources = patchMatchingResolver.getResources("file:" + pathPattern);
     if (resources != null && resources.length > 0) {
       return resources[0];
     }
   } catch (IOException e) {
     return null;
   }
   return null;
 }
 protected Resource[] getPluginBundles(String pluginName) {
   Resource[] pluginBundles;
   try {
     pluginBundles =
         resourceResolver.getResources(
             WEB_INF_PLUGINS_PATH + pluginName + "/grails-app/i18n/*.properties");
   } catch (Exception e) {
     pluginBundles = new Resource[0];
   }
   return pluginBundles;
 }
  /** Returns a list of all the executable Gant scripts available to this application. */
  public List<Resource> getAvailableScripts() {
    List<Resource> scripts = new ArrayList<Resource>();
    if (settings.getGrailsHome() != null) {
      addCommandScripts(new File(settings.getGrailsHome(), "scripts"), scripts);
    }
    addCommandScripts(new File(settings.getBaseDir(), "scripts"), scripts);
    addCommandScripts(new File(settings.getUserHome(), ".grails/scripts"), scripts);

    for (File dir : pluginPathSupport.listKnownPluginDirs()) {
      addPluginScripts(dir, scripts);
    }

    PathMatchingResourcePatternResolver resolver =
        new PathMatchingResourcePatternResolver(settings.getRootLoader());
    try {
      final Resource[] resources = resolver.getResources("classpath*:META-INF/scripts/*.groovy");
      scripts.addAll(Arrays.asList(resources));
    } catch (IOException e) {
      // ignore
    }
    return scripts;
  }
Exemple #14
0
  public static void main(String[] args) throws IOException, InterruptedException {
    if (args.length != 2) {
      printUsage();
      System.exit(0);
    }

    String emotAIAPIBaseUrl = args[0];
    String accessToken = args[1];

    PathMatchingResourcePatternResolver fileResolver =
        new PathMatchingResourcePatternResolver(EmotAIDemo.class.getClassLoader());
    Resource[] resources = fileResolver.getResources("images");
    File dir = resources[0].getFile();
    File imagesDir = new File(dir, "/face/cropped");

    EmotAI emotAI = new EmotAITemplate(emotAIAPIBaseUrl, accessToken);

    // Create a display for the images
    ImageDisplay<Long> imageDisplay = new ImageDisplay<Long>(250, 250);

    for (File imageFile : imagesDir.listFiles(new JpegFileFilter())) {
      // Read each image
      BufferedImage image = ImageIO.read(imageFile);

      // Get the emotion profile for each image
      EmotionProfile emotionProfile = emotAI.emotionOperations().getFaceImageEmotionProfile(image);

      // Output emotion, and display image
      System.out.println(imageFile.getName() + " : " + emotionProfile);
      imageDisplay.onFrameUpdate(new SerializableBufferedImageAdapter(image), 1l);

      // Sleep for 1 second
      Thread.sleep(1000);
    }

    System.exit(1);
  }
Exemple #15
0
  public Brand() {
    brandingPath = System.getProperty("user.home") + "/.celerio/branding.properties";
    logoPath = System.getProperty("user.home") + "/.celerio/" + logoFilename;
    try {

      Properties p = new Properties();
      File f = new File(brandingPath);
      if (f.exists()) {
        p.load(new FileInputStream(f));
        companyName = p.getProperty("company_name", companyName);
        companyUrl = p.getProperty("company_url", companyUrl);
        footer = p.getProperty("footer", footer);
        rootPackage = p.getProperty("root_package", rootPackage);
      } else {
        p.setProperty("root_package", rootPackage);
        p.setProperty("company_name", companyName);
        p.setProperty("company_url", companyUrl);
        p.setProperty("footer", footer);
        if (!f.getParentFile().exists()) {
          f.getParentFile().mkdirs();
        }
        p.store(new FileOutputStream(f), "CELERIO BRANDING");
      }

      // copy logo if not present
      File logo = new File(logoPath);
      if (!logo.exists()) {
        PathMatchingResourcePatternResolver o = new PathMatchingResourcePatternResolver();
        Resource defaultBrandLogo = o.getResource("classpath:/brand-logo.png");
        new FileOutputStream(logo).write(IOUtils.toByteArray(defaultBrandLogo.getInputStream()));
      }

    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
 /** @return the watchedResources */
 public Resource[] getWatchedResources() {
   if (watchedResources.length == 0) {
     if (watchedResourcePatternReferences != null) {
       for (String resourcesReference : watchedResourcePatternReferences) {
         try {
           Resource[] tmp = resolver.getResources(resourcesReference);
           if (tmp.length > 0) {
             watchedResources = (Resource[]) ArrayUtils.addAll(watchedResources, tmp);
           }
         } catch (Exception e) {
           // ignore
         }
       }
     }
   }
   return watchedResources;
 }
Exemple #17
0
  /**
   * 设置BaseNames。
   *
   * @param baseNames String[]
   */
  public void setBaseNames(String[] baseNames) {
    List<String> baseNameList = new ArrayList<String>();
    try {
      for (String baseName : baseNames) {
        Resource[] resources = resolver.getResources(baseName);
        for (Resource resource : resources) {
          String fileName = resource.getURI().toString();
          baseNameList.add(fileName.substring(0, fileName.indexOf(PROPERTY_POSTFIX)));

          if (log.isInfoEnabled()) {
            log.info("Add properties file: [" + resource.getDescription() + "]");
          }
        }
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    this.rMessageSource.setCacheSeconds(this.getCacheMillis());
    this.rMessageSource.setBasenames(baseNameList.toArray(new String[baseNameList.size()]));
  }
  public Set getPluginClasses() {

    // just in case we try to use this twice
    foundPluginClasses.clear();

    try {
      Resource[] resources =
          resolver.getResources(
              "classpath*:org/codehaus/groovy/griffon/**/plugins/**/*GriffonPlugin.class");
      if (resources.length > 0) {
        loadCorePluginsFromResources(resources);
      } else {
        LOG.warn(
            "WARNING: Griffon was unable to load core plugins dynamically. This is normally a problem with the container class loader configuration, see troubleshooting and FAQ for more info. ");
        loadCorePluginsStatically();
      }
    } catch (IOException e) {
      throw new PluginException("I/O exception configuring core plug-ins: " + e.getMessage(), e);
    }
    return foundPluginClasses;
  }
Exemple #19
0
 /**
  * Reads all of the resource files under the specified path and returns a sequence of String
  * arrays. The resource files are specified as comma-separated values. Each row in a resource file
  * is one element of the resulting list.
  *
  * @param suffix filename suffix. Matches against files with this suffix in their filename.
  * @return list of String[] elements that represent CSV values
  */
 public static List<String[]> readProperties(String suffix) {
   List<String[]> result = new ArrayList<>();
   try {
     String locationPattern = "classpath*:plugins/*" + suffix;
     Resource[] resources = resolver.getResources(locationPattern);
     for (Resource resource : resources) {
       log.debug("readProperties found resource {}", resource);
       String filename = resource.getDescription();
       InputStreamReader reader = new InputStreamReader(resource.getInputStream());
       try (CsvListReader csvParser = new CsvListReader(reader, csvParserOptions)) {
         List<String> next;
         while ((next = csvParser.read()) != null) {
           result.add(next.toArray(new String[next.size()]));
         }
       } catch (SuperCsvException e) {
         log.warn("In " + filename + ", " + e);
       }
     }
   } catch (IOException e) {
     log.error(e.toString());
   }
   return result;
 }
  /**
   * Returns the i18n message bundles for the provided plugin or an empty array if the plugin does
   * not contain any .properties files in its grails-app/i18n folder.
   *
   * @param grailsPlugin The grails plugin that may or may not contain i18n internationalization
   *     files.
   * @return An array of {@code Resource} objects representing the internationalization files or an
   *     empty array if no files are found.
   */
  protected Resource[] getPluginBundles(GrailsPlugin grailsPlugin) {
    if (grailsPlugin instanceof BinaryGrailsPlugin) {
      return NO_RESOURCES;
    }

    try {
      String basePath;

      // If the plugin is inline, use the absolute path to the internationalization files
      // in order to convert to resources.  Otherwise, use the relative WEB-INF path.
      String inlinePath = getInlinePluginPath(grailsPlugin);
      if (inlinePath == null) {
        basePath = WEB_INF_PLUGINS_PATH + grailsPlugin.getFileSystemName();
      } else {
        basePath = inlinePath;
      }
      return resourceResolver.getResources(basePath + "/grails-app/i18n/*.properties");
    } catch (IOException e) {
      LOG.debug(
          "Could not resolve any resources for plugin " + grailsPlugin.getFileSystemName(), e);
      return NO_RESOURCES;
    }
  }
 private static Resource[] getResources(ClassLoader classLoader) throws IOException {
   PathMatchingResourcePatternResolver resolver =
       new PathMatchingResourcePatternResolver(classLoader);
   return resolver.getResources(PATTERN);
 }