Skip to content

Commit

Permalink
Merge pull request #6 from Jasper-Hilven/master
Browse files Browse the repository at this point in the history
Fix supplier passing
  • Loading branch information
thijslemmens authored Oct 30, 2018
2 parents 833c41e + 610b0bb commit c32b72b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 42 deletions.
8 changes: 4 additions & 4 deletions src/main/java/eu/xenit/gradle/alfrescosdk/AmpPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
65 changes: 27 additions & 38 deletions src/main/java/eu/xenit/gradle/alfrescosdk/config/AmpConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,100 +9,89 @@ 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<File> moduleProperties;
private Supplier<File> configDir;
private Supplier<File> webDir;
private Supplier<File> fileMappingProperties;
private Supplier<File> modulePropertiesSupplier;
private Supplier<File> configDirSupplier;
private Supplier<File> webDirSupplier;
private Supplier<File> 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<File> moduleProperties) {
this.moduleProperties = moduleProperties;
this.modulePropertiesSupplier = moduleProperties;
}

public void setConfigDir(Supplier<File> configDir) {
this.configDir = configDir;
this.configDirSupplier = configDir;
}

public void setWebDir(Supplier<File> webDir) {
this.webDir = webDir;
this.webDirSupplier = webDir;
}

public void setFileMappingProperties(Supplier<File> fileMappingProperties) {
this.fileMappingProperties = fileMappingProperties;
this.fileMappingPropertiesSupplier = fileMappingProperties;
}

public Project getProject() {
return project;
}

public void setFileMappingProperties(File fileMappingProperties) {
this.fileMappingProperties = () -> fileMappingProperties;
}

public Supplier<File> getModulePropertiesSupplier() {
return this.moduleProperties;
}

public Supplier<File> getConfigDirSupplier() {
return this.configDir;
}

public Supplier<File> getWebDirSupplier() {
return this.webDir;
}

public Supplier<File> getFileMappingPropertiesSupplier() {
return this.fileMappingProperties;
this.fileMappingPropertiesSupplier = () -> fileMappingProperties;
}

public boolean getDynamicExtension() {
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/eu/xenit/gradle/alfrescosdk/AmpPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()); ;
}

}

0 comments on commit c32b72b

Please sign in to comment.