Skip to content

Commit

Permalink
Remove usage of deprecated GUtil; move to own PropertiesUtil class
Browse files Browse the repository at this point in the history
  • Loading branch information
vierbergenlars committed Aug 6, 2024
1 parent ddf5b58 commit a147c1b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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));
});
}

Expand All @@ -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));
});
}

Expand Down Expand Up @@ -125,4 +125,5 @@ public SourceDirectorySet getConfig() {
public SourceDirectorySet getWeb() {
return web;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a147c1b

Please sign in to comment.