PropertiesResourceImpl extends ResourceImpl { @Override public void load(Map<?, ?> options) throws IOException { ReentrantReadWriteLock lock = LOCKS .getUnchecked(getURI() == null ? "temp" : getURI() .toFileString()); ReadLock readLock = lock.readLock(); try { if (!readLock.tryLock(2, TimeUnit.MINUTES)) { LOG.warn("Failed to aquire read lock for {}", getURI()); readLock = null; throw new IOException("Could not load " + getURI()); } super.load(options); } catch (InterruptedException e) { LOG.warn("Interrupted while trying to aquire read lock for {}", getURI()); throw new IOException("Could not load " + getURI()); } finally { if (readLock != null) readLock.unlock(); } } PropertiesResourceImpl(URI uri); @Override void load(Map<?, ?> options); @Override void save(Map<?, ?> options); int getSavedProperties(); static final String OPTION_FILEMODE; static final String OPTION_ENCODING; }
@Test public void testIssue55() throws IOException { URI uri = URI.createFileURI("src/test/resources/project/master/org/jabylon/properties/util/Buttons_en.seenls"); getFixture().setURI(uri); getFixture().load(null); PropertyFile file = (PropertyFile)getFixture().getContents().get(0); EList<Property> properties = file.getProperties(); assertEquals(1, properties.size()); Property property = properties.get(0); assertEquals("DTM.CASCADE_SESSION_FRAMES_TEXT", property.getKey()); assertEquals("Cascade", property.getValue()); assertEquals("test", file.getLicenseHeader()); }
@Test public void testReadLicenseHeaderAndComment() throws IOException { URI uri = URI.createFileURI("src/test/resources/licenseHeader.properties"); getFixture().setURI(uri); getFixture().load(null); PropertyFile file = (PropertyFile)getFixture().getContents().get(0); EList<Property> properties = file.getProperties(); assertEquals(1, properties.size()); Property property = properties.get(0); assertEquals("key", property.getKey()); assertEquals("value", property.getValue()); assertEquals("licensed under\napache license\nv3", file.getLicenseHeader()); }
@Test public void testReadNoLicenseHeaderAndComment() throws IOException { URI uri = URI.createFileURI("src/test/resources/noLicenseHeader.properties"); getFixture().setURI(uri); getFixture().load(null); PropertyFile file = (PropertyFile)getFixture().getContents().get(0); EList<Property> properties = file.getProperties(); assertEquals(1, properties.size()); Property property = properties.get(0); assertEquals("key", property.getKey()); assertEquals("value", property.getValue()); assertNull(file.getLicenseHeader()); }
@Test public void testReadPropertiesWithAnnotations() throws IOException { URI uri = URI.createFileURI("src/test/resources/annotations/annotations.properties"); getFixture().setURI(uri); getFixture().load(null); PropertyFile file = (PropertyFile)getFixture().getContents().get(0); EList<Property> properties = file.getProperties(); assertEquals(2, properties.size()); Property property = properties.get(0); assertEquals("key", property.getKey()); assertEquals("value", property.getValue()); property = properties.get(1); assertEquals("key3", property.getKey()); assertEquals("value", property.getValue()); EList<PropertyAnnotation> annotations = property.getAnnotations(); PropertyAnnotation annotation = annotations.get(0); assertEquals("myannotation", annotation.getName()); assertEquals("bar", annotation.getValues().get("foo")); }