diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/internal/PropertiesUtil.java b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/PropertiesUtil.java new file mode 100644 index 0000000..b434609 --- /dev/null +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/PropertiesUtil.java @@ -0,0 +1,46 @@ +package eu.xenit.gradle.alfrescosdk.internal; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import org.gradle.api.UncheckedIOException; + +public final class PropertiesUtil { + private PropertiesUtil() { + throw new UnsupportedOperationException("This utility class can not be instantiated"); + } + + public static Properties loadProperties(File propertyFile) { + try { + try(FileInputStream inputStream = new FileInputStream(propertyFile)) { + return loadProperties(inputStream); + } + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + private static Properties loadProperties(InputStream inputStream) { + Properties properties = new Properties(); + try { + properties.load(inputStream); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + return properties; + } + + public static void saveProperties(Properties properties, File propertyFile) { + try { + try (FileOutputStream propertiesFileOutputStream = new FileOutputStream(propertyFile)) { + properties.store(propertiesFileOutputStream, null); + } + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + +} diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/internal/tasks/DefaultAmpSourceSetConfiguration.java b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/tasks/DefaultAmpSourceSetConfiguration.java index e8c8e16..f17d70f 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/internal/tasks/DefaultAmpSourceSetConfiguration.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/internal/tasks/DefaultAmpSourceSetConfiguration.java @@ -1,5 +1,6 @@ package eu.xenit.gradle.alfrescosdk.internal.tasks; +import eu.xenit.gradle.alfrescosdk.internal.PropertiesUtil; import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSet; import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSetConfiguration; import java.io.File; @@ -13,7 +14,6 @@ import org.gradle.api.provider.Property; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.SourceSet; -import org.gradle.util.GUtil; public class DefaultAmpSourceSetConfiguration implements AmpSourceSetConfiguration { @@ -60,7 +60,7 @@ public AmpSourceSetConfiguration module(String moduleProperties) { @Override public AmpSourceSetConfiguration module(File moduleProperties) { return module(properties -> { - properties.putAll(GUtil.loadProperties(moduleProperties)); + properties.putAll(PropertiesUtil.loadProperties(moduleProperties)); }); } @@ -87,7 +87,7 @@ public AmpSourceSetConfiguration fileMapping(String fileMappingProperties) { @Override public AmpSourceSetConfiguration fileMapping(File fileMappingProperties) { return fileMapping(properties -> { - properties.putAll(GUtil.loadProperties(fileMappingProperties)); + properties.putAll(PropertiesUtil.loadProperties(fileMappingProperties)); }); } @@ -125,4 +125,5 @@ public SourceDirectorySet getConfig() { public SourceDirectorySet getWeb() { return web; } + } diff --git a/src/test/java/eu/xenit/gradle/alfrescosdk/AmpBasePluginTest.java b/src/test/java/eu/xenit/gradle/alfrescosdk/AmpBasePluginTest.java index b5a9990..ab2f5ef 100644 --- a/src/test/java/eu/xenit/gradle/alfrescosdk/AmpBasePluginTest.java +++ b/src/test/java/eu/xenit/gradle/alfrescosdk/AmpBasePluginTest.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import eu.xenit.gradle.alfrescosdk.internal.PropertiesUtil; import eu.xenit.gradle.alfrescosdk.tasks.Amp; import eu.xenit.gradle.alfrescosdk.tasks.AmpSourceSetConfiguration; import java.io.File; @@ -19,7 +20,6 @@ import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.WriteProperties; import org.gradle.testfixtures.ProjectBuilder; -import org.gradle.util.GUtil; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -95,12 +95,12 @@ public void autoConfigureSourceSet() throws IOException { Properties moduleProperties = new Properties(); moduleProperties.setProperty("module.id", "test-amp"); moduleProperties.setProperty("module.version", "1.0.0"); - GUtil.saveProperties(moduleProperties, modulePropertiesFile); + PropertiesUtil.saveProperties(moduleProperties, modulePropertiesFile); File fileMappingPropertiesFile = ampFolder.resolve("file-mapping.properties").toFile(); Properties fileMappingProperties = new Properties(); fileMappingProperties.setProperty("/override", "/"); - GUtil.saveProperties(fileMappingProperties, fileMappingPropertiesFile); + PropertiesUtil.saveProperties(fileMappingProperties, fileMappingPropertiesFile); DefaultProject project = getDefaultProject(); // Java plugin is required for the jar task