@Test public void testSystemPropertyReplacement() { PropertyEditor editor = new ResourceArrayPropertyEditor(); System.setProperty("test.prop", "foo"); try { editor.setAsText("${test.prop}-${bar}"); Resource[] resources = (Resource[]) editor.getValue(); assertEquals("foo-${bar}", resources[0].getFilename()); } finally { System.getProperties().remove("test.prop"); } }
/** * Treat the given text as a location pattern and convert it to a Resource array. */ @Override public void setAsText(String text) { String pattern = resolvePath(text).trim(); try { setValue(this.resourcePatternResolver.getResources(pattern)); } catch (IOException ex) { throw new IllegalArgumentException( "Could not resolve resource location pattern [" + pattern + "]: " + ex.getMessage()); } }
@Before public void setUp() { ResourceArrayPropertyEditor editor = new ResourceArrayPropertyEditor(); editor.setAsText("classpath:jsrBaseContext.xml"); partitioner.setResources((Resource[]) editor.getValue()); }
@Override public Set<Resource> getDeploymentResources() { final ResourceArrayPropertyEditor resolver = new ResourceArrayPropertyEditor(); try { final String[] resourcePattern = camundaBpmProperties.getDeploymentResourcePattern(); logger.debug("resolving deployment resources for pattern {}", (Object[]) resourcePattern); resolver.setValue(resourcePattern); return Arrays.stream((Resource[])resolver.getValue()) .peek(resource -> logger.debug("processing deployment resource {}", resource)) .filter(this::isFile) .peek(resource -> logger.debug("added deployment resource {}", resource)) .collect(Collectors.toSet()); } catch (final RuntimeException e) { logger.error("unable to resolve resources", e); } return EMPTY_SET; }
String pattern = resolvePath((String) element).trim(); try { Resource[] resources = this.resourcePatternResolver.getResources(pattern);
@Override public Set<Resource> getDeploymentResources() { final ResourceArrayPropertyEditor resolver = new ResourceArrayPropertyEditor(); try { final String[] resourcePattern = camundaBpmProperties.getDeploymentResourcePattern(); logger.debug("resolving deployment resources for pattern {}", (Object[]) resourcePattern); resolver.setValue(resourcePattern); return Arrays.stream((Resource[])resolver.getValue()) .peek(resource -> logger.debug("processing deployment resource {}", resource)) .filter(this::isFile) .peek(resource -> logger.debug("added deployment resource {}", resource)) .collect(Collectors.toSet()); } catch (final RuntimeException e) { logger.error("unable to resolve resources", e); } return EMPTY_SET; }
String pattern = resolvePath((String) element).trim(); try { Resource[] resources = this.resourcePatternResolver.getResources(pattern);
@Test public void testVanillaResource() throws Exception { PropertyEditor editor = new ResourceArrayPropertyEditor(); editor.setAsText("classpath:org/springframework/core/io/support/ResourceArrayPropertyEditor.class"); Resource[] resources = (Resource[]) editor.getValue(); assertNotNull(resources); assertTrue(resources[0].exists()); }
/** * Treat the given text as a location pattern and convert it to a Resource array. */ @Override public void setAsText(String text) { String pattern = resolvePath(text).trim(); try { setValue(this.resourcePatternResolver.getResources(pattern)); } catch (IOException ex) { throw new IllegalArgumentException( "Could not resolve resource location pattern [" + pattern + "]: " + ex.getMessage()); } }
@Parameters public static List<Object[]> data() throws Exception { List<Object[]> list = new ArrayList<>(); ResourceArrayPropertyEditor editor = new ResourceArrayPropertyEditor(); editor.setAsText("classpath*:" + ClassUtils.addResourcePathToPackagePath(StepNameTests.class, "*.xml")); Resource[] resources = (Resource[]) editor.getValue(); for (Resource resource : resources) { if (resource.getFile().getName().contains("WrongSchema")) { continue; } list.add(new Object[] { resource }); } return list; }
String pattern = resolvePath((String) element).trim(); try { Resource[] resources = this.resourcePatternResolver.getResources(pattern);
@Test public void testPatternResource() throws Exception { // N.B. this will sometimes fail if you use classpath: instead of classpath*:. // The result depends on the classpath - if test-classes are segregated from classes // and they come first on the classpath (like in Maven) then it breaks, if classes // comes first (like in Spring Build) then it is OK. PropertyEditor editor = new ResourceArrayPropertyEditor(); editor.setAsText("classpath*:org/springframework/core/io/support/Resource*Editor.class"); Resource[] resources = (Resource[]) editor.getValue(); assertNotNull(resources); assertTrue(resources[0].exists()); }
/** * Treat the given text as a location pattern and convert it to a Resource array. */ @Override public void setAsText(String text) { String pattern = resolvePath(text).trim(); try { setValue(this.resourcePatternResolver.getResources(pattern)); } catch (IOException ex) { throw new IllegalArgumentException( "Could not resolve resource location pattern [" + pattern + "]: " + ex.getMessage()); } }
String pattern = resolvePath((String) element).trim(); try { Resource[] resources = this.resourcePatternResolver.getResources(pattern);
@Test(expected = IllegalArgumentException.class) public void testStrictSystemPropertyReplacement() { PropertyEditor editor = new ResourceArrayPropertyEditor( new PathMatchingResourcePatternResolver(), new StandardEnvironment(), false); System.setProperty("test.prop", "foo"); try { editor.setAsText("${test.prop}-${bar}"); Resource[] resources = (Resource[]) editor.getValue(); assertEquals("foo-${bar}", resources[0].getFilename()); } finally { System.getProperties().remove("test.prop"); } }
public void setAsText(String text) { String patternToUse = resolvePath(text).trim(); try { setValue(this.resourcePatternResolver.getResources(patternToUse)); } catch (IOException ex) { throw new IllegalArgumentException( "Could not resolve resource location pattern [" + patternToUse + "]: " + ex.getMessage()); } }
String pattern = resolvePath((String) element).trim(); try { Resource[] resources = this.resourcePatternResolver.getResources(pattern);
this.defaultEditors.put(Properties.class, new PropertiesEditor()); this.defaultEditors.put(Reader.class, new ReaderEditor()); this.defaultEditors.put(Resource[].class, new ResourceArrayPropertyEditor()); this.defaultEditors.put(TimeZone.class, new TimeZoneEditor()); this.defaultEditors.put(URI.class, new URIEditor());
/** * Treat the given text as a location pattern and convert it to a Resource array. */ @Override public void setAsText(String text) { String pattern = resolvePath(text).trim(); try { setValue(this.resourcePatternResolver.getResources(pattern)); } catch (IOException ex) { throw new IllegalArgumentException( "Could not resolve resource location pattern [" + pattern + "]: " + ex.getMessage()); } }
this.defaultEditors.put(Properties.class, new PropertiesEditor()); this.defaultEditors.put(Reader.class, new ReaderEditor()); this.defaultEditors.put(Resource[].class, new ResourceArrayPropertyEditor()); this.defaultEditors.put(TimeZone.class, new TimeZoneEditor()); this.defaultEditors.put(URI.class, new URIEditor());