Skip to content

Commit c32b72b

Browse files
authored
Merge pull request #6 from Jasper-Hilven/master
Fix supplier passing
2 parents 833c41e + 610b0bb commit c32b72b

File tree

3 files changed

+44
-42
lines changed

3 files changed

+44
-42
lines changed

src/main/java/eu/xenit/gradle/alfrescosdk/AmpPlugin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public void apply(Project project) {
2222
project.getConfigurations().create(AMP_CONFIGURATION);
2323
project.getArtifacts().add(AMP_CONFIGURATION, amp);
2424

25-
amp.setModuleProperties(ampConfig.getModulePropertiesSupplier());
26-
amp.setConfig(ampConfig.getConfigDirSupplier());
27-
amp.setWeb(ampConfig.getWebDirSupplier());
28-
amp.setFileMappingProperties(ampConfig.getFileMappingPropertiesSupplier());
25+
amp.setModuleProperties(ampConfig::getModuleProperties);
26+
amp.setConfig(ampConfig::getConfigDir);
27+
amp.setWeb(ampConfig::getWebDir);
28+
amp.setFileMappingProperties(ampConfig::getFileMappingProperties);
2929

3030
project.getPluginManager().withPlugin(AlfrescoPlugin.PLUGIN_ID, appliedPlugin -> {
3131
FileCollection runtime = project.getConfigurations().getAt("runtime");

src/main/java/eu/xenit/gradle/alfrescosdk/config/AmpConfig.java

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,100 +9,89 @@ public class AmpConfig {
99
public static final String DEFAULT_CONFIG_DIR = "src/main/amp/config";
1010
public static final String DEFAULT_MODULE_PROPERTIES = "src/main/amp/module.properties";
1111
public static final String DEFAULT_WEB_DIR = "src/main/amp/web";
12-
private Supplier<File> moduleProperties;
13-
private Supplier<File> configDir;
14-
private Supplier<File> webDir;
15-
private Supplier<File> fileMappingProperties;
12+
private Supplier<File> modulePropertiesSupplier;
13+
private Supplier<File> configDirSupplier;
14+
private Supplier<File> webDirSupplier;
15+
private Supplier<File> fileMappingPropertiesSupplier;
1616
private boolean dynamicExtension = false;
1717

1818
private final Project project;
19-
public AmpConfig(Project project){
19+
20+
public AmpConfig(Project project) {
2021
this.project = project;
21-
moduleProperties = () -> project.file(DEFAULT_MODULE_PROPERTIES);
22-
configDir = () -> {
22+
modulePropertiesSupplier = () -> project.file(DEFAULT_MODULE_PROPERTIES);
23+
configDirSupplier = () -> {
2324
File file = project.file(DEFAULT_CONFIG_DIR);
24-
if(file.exists()) {
25+
if (file.exists()) {
2526
return file;
2627
} else {
2728
return null;
2829
}
2930
};
30-
webDir = () -> {
31+
webDirSupplier = () -> {
3132
File file = project.file(DEFAULT_WEB_DIR);
32-
if(file.exists()) {
33+
if (file.exists()) {
3334
return file;
3435
} else {
3536
return null;
3637
}
3738
};
39+
fileMappingPropertiesSupplier = () -> {
40+
return null;
41+
};
42+
3843
}
3944

4045
public File getModuleProperties() {
41-
return moduleProperties.get();
46+
return modulePropertiesSupplier.get();
4247
}
4348

4449
public void setModuleProperties(File moduleProperties) {
45-
this.moduleProperties = () -> moduleProperties;
50+
this.modulePropertiesSupplier = () -> moduleProperties;
4651
}
4752

4853
public File getConfigDir() {
49-
return configDir.get();
54+
return configDirSupplier.get();
5055
}
5156

5257
public void setConfigDir(File configDir) {
53-
this.configDir = () -> configDir;
58+
this.configDirSupplier = () -> configDir;
5459
}
5560

5661
public File getWebDir() {
57-
return webDir.get();
62+
return webDirSupplier.get();
5863
}
5964

6065
public void setWebDir(File webDir) {
61-
this.webDir = () -> webDir;
66+
this.webDirSupplier = () -> webDir;
6267
}
6368

6469
public File getFileMappingProperties() {
65-
return fileMappingProperties.get();
70+
return fileMappingPropertiesSupplier.get();
6671
}
6772

6873
public void setModuleProperties(Supplier<File> moduleProperties) {
69-
this.moduleProperties = moduleProperties;
74+
this.modulePropertiesSupplier = moduleProperties;
7075
}
7176

7277
public void setConfigDir(Supplier<File> configDir) {
73-
this.configDir = configDir;
78+
this.configDirSupplier = configDir;
7479
}
7580

7681
public void setWebDir(Supplier<File> webDir) {
77-
this.webDir = webDir;
82+
this.webDirSupplier = webDir;
7883
}
7984

8085
public void setFileMappingProperties(Supplier<File> fileMappingProperties) {
81-
this.fileMappingProperties = fileMappingProperties;
86+
this.fileMappingPropertiesSupplier = fileMappingProperties;
8287
}
8388

8489
public Project getProject() {
8590
return project;
8691
}
8792

8893
public void setFileMappingProperties(File fileMappingProperties) {
89-
this.fileMappingProperties = () -> fileMappingProperties;
90-
}
91-
92-
public Supplier<File> getModulePropertiesSupplier() {
93-
return this.moduleProperties;
94-
}
95-
96-
public Supplier<File> getConfigDirSupplier() {
97-
return this.configDir;
98-
}
99-
100-
public Supplier<File> getWebDirSupplier() {
101-
return this.webDir;
102-
}
103-
104-
public Supplier<File> getFileMappingPropertiesSupplier() {
105-
return this.fileMappingProperties;
94+
this.fileMappingPropertiesSupplier = () -> fileMappingProperties;
10695
}
10796

10897
public boolean getDynamicExtension() {

src/test/java/eu/xenit/gradle/alfrescosdk/AmpPluginTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,17 @@ public void testDeProjectWithConfiguredLib(){
5656
project.evaluate(); // Evaluate the project so that the afterEvaluate can run, which should leave the libs alone
5757
assertNotNull(ampTask.getLibs());
5858
}
59+
@Test
60+
public void testProjectWithConfiguredConfigDir(){
61+
DefaultProject project = getDefaultProject();
62+
project.getPluginManager().apply(AlfrescoPlugin.class);
63+
File need_this = new File("Need this");
64+
project.getExtensions().configure("ampConfig", (AmpConfig ampConfig) -> {
65+
ampConfig.setConfigDir(need_this);
66+
});
67+
Amp ampTask = (Amp) project.getTasks().getByName("amp");
68+
project.evaluate(); // Evaluate the project so that the afterEvaluate can run, which should leave the libs alone
69+
assertEquals(need_this,ampTask.getConfig()); ;
70+
}
71+
5972
}

0 commit comments

Comments
 (0)