diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/AmpPlugin.java b/src/main/java/eu/xenit/gradle/alfrescosdk/AmpPlugin.java index b65b587..31b091a 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/AmpPlugin.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/AmpPlugin.java @@ -22,10 +22,10 @@ public void apply(Project project) { project.getConfigurations().create(AMP_CONFIGURATION); project.getArtifacts().add(AMP_CONFIGURATION, amp); - amp.setModuleProperties(ampConfig.getModulePropertiesSupplier()); - amp.setConfig(ampConfig.getConfigDirSupplier()); - amp.setWeb(ampConfig.getWebDirSupplier()); - amp.setFileMappingProperties(ampConfig.getFileMappingPropertiesSupplier()); + amp.setModuleProperties(ampConfig::getModuleProperties); + amp.setConfig(ampConfig::getConfigDir); + amp.setWeb(ampConfig::getWebDir); + amp.setFileMappingProperties(ampConfig::getFileMappingProperties); project.getPluginManager().withPlugin(AlfrescoPlugin.PLUGIN_ID, appliedPlugin -> { FileCollection runtime = project.getConfigurations().getAt("runtime"); diff --git a/src/main/java/eu/xenit/gradle/alfrescosdk/config/AmpConfig.java b/src/main/java/eu/xenit/gradle/alfrescosdk/config/AmpConfig.java index c873725..416c7f6 100644 --- a/src/main/java/eu/xenit/gradle/alfrescosdk/config/AmpConfig.java +++ b/src/main/java/eu/xenit/gradle/alfrescosdk/config/AmpConfig.java @@ -9,76 +9,81 @@ public class AmpConfig { public static final String DEFAULT_CONFIG_DIR = "src/main/amp/config"; public static final String DEFAULT_MODULE_PROPERTIES = "src/main/amp/module.properties"; public static final String DEFAULT_WEB_DIR = "src/main/amp/web"; - private Supplier moduleProperties; - private Supplier configDir; - private Supplier webDir; - private Supplier fileMappingProperties; + private Supplier modulePropertiesSupplier; + private Supplier configDirSupplier; + private Supplier webDirSupplier; + private Supplier fileMappingPropertiesSupplier; private boolean dynamicExtension = false; private final Project project; - public AmpConfig(Project project){ + + public AmpConfig(Project project) { this.project = project; - moduleProperties = () -> project.file(DEFAULT_MODULE_PROPERTIES); - configDir = () -> { + modulePropertiesSupplier = () -> project.file(DEFAULT_MODULE_PROPERTIES); + configDirSupplier = () -> { File file = project.file(DEFAULT_CONFIG_DIR); - if(file.exists()) { + if (file.exists()) { return file; } else { return null; } }; - webDir = () -> { + webDirSupplier = () -> { File file = project.file(DEFAULT_WEB_DIR); - if(file.exists()) { + if (file.exists()) { return file; } else { return null; } }; + fileMappingPropertiesSupplier = () -> { + return null; + }; + } public File getModuleProperties() { - return moduleProperties.get(); + return modulePropertiesSupplier.get(); } public void setModuleProperties(File moduleProperties) { - this.moduleProperties = () -> moduleProperties; + this.modulePropertiesSupplier = () -> moduleProperties; } public File getConfigDir() { - return configDir.get(); + return configDirSupplier.get(); } public void setConfigDir(File configDir) { - this.configDir = () -> configDir; + this.configDirSupplier = () -> configDir; } public File getWebDir() { - return webDir.get(); + return webDirSupplier.get(); } public void setWebDir(File webDir) { - this.webDir = () -> webDir; + this.webDirSupplier = () -> webDir; } public File getFileMappingProperties() { - return fileMappingProperties.get(); + return fileMappingPropertiesSupplier.get(); } public void setModuleProperties(Supplier moduleProperties) { - this.moduleProperties = moduleProperties; + this.modulePropertiesSupplier = moduleProperties; } public void setConfigDir(Supplier configDir) { - this.configDir = configDir; + this.configDirSupplier = configDir; } public void setWebDir(Supplier webDir) { - this.webDir = webDir; + this.webDirSupplier = webDir; } public void setFileMappingProperties(Supplier fileMappingProperties) { - this.fileMappingProperties = fileMappingProperties; + this.fileMappingPropertiesSupplier = fileMappingProperties; } public Project getProject() { @@ -86,23 +91,7 @@ public Project getProject() { } public void setFileMappingProperties(File fileMappingProperties) { - this.fileMappingProperties = () -> fileMappingProperties; - } - - public Supplier getModulePropertiesSupplier() { - return this.moduleProperties; - } - - public Supplier getConfigDirSupplier() { - return this.configDir; - } - - public Supplier getWebDirSupplier() { - return this.webDir; - } - - public Supplier getFileMappingPropertiesSupplier() { - return this.fileMappingProperties; + this.fileMappingPropertiesSupplier = () -> fileMappingProperties; } public boolean getDynamicExtension() { diff --git a/src/test/java/eu/xenit/gradle/alfrescosdk/AmpPluginTest.java b/src/test/java/eu/xenit/gradle/alfrescosdk/AmpPluginTest.java index 10b083c..a4b7f7d 100644 --- a/src/test/java/eu/xenit/gradle/alfrescosdk/AmpPluginTest.java +++ b/src/test/java/eu/xenit/gradle/alfrescosdk/AmpPluginTest.java @@ -56,4 +56,17 @@ public void testDeProjectWithConfiguredLib(){ project.evaluate(); // Evaluate the project so that the afterEvaluate can run, which should leave the libs alone assertNotNull(ampTask.getLibs()); } + @Test + public void testProjectWithConfiguredConfigDir(){ + DefaultProject project = getDefaultProject(); + project.getPluginManager().apply(AlfrescoPlugin.class); + File need_this = new File("Need this"); + project.getExtensions().configure("ampConfig", (AmpConfig ampConfig) -> { + ampConfig.setConfigDir(need_this); + }); + Amp ampTask = (Amp) project.getTasks().getByName("amp"); + project.evaluate(); // Evaluate the project so that the afterEvaluate can run, which should leave the libs alone + assertEquals(need_this,ampTask.getConfig()); ; + } + }