5: Create DescriptionProvider
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.bartek.esa.core.desc.provider;
|
||||
|
||||
import com.bartek.esa.error.EsaException;
|
||||
import io.vavr.control.Try;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
public class DescriptionProvider {
|
||||
private static final String DESCRIPTION_FILE = "description.properties";
|
||||
private final Properties properties = new Properties();
|
||||
|
||||
@Inject
|
||||
public DescriptionProvider() {
|
||||
Optional.ofNullable(DescriptionProvider.class.getClassLoader().getResourceAsStream(DESCRIPTION_FILE))
|
||||
.ifPresent(p -> Try.run(() -> properties.load(p)).getOrElseThrow(EsaException::new));
|
||||
}
|
||||
|
||||
public String getDescriptionForClass(Class<?> clazz) {
|
||||
String clazzCanonicalName = properties.getProperty(clazz.getCanonicalName());
|
||||
return clazzCanonicalName != null ? clazzCanonicalName : "No description provided.";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bartek.esa.core.di;
|
||||
|
||||
import com.bartek.esa.core.desc.provider.DescriptionProvider;
|
||||
import com.bartek.esa.core.executor.PluginExecutor;
|
||||
import com.bartek.esa.core.java.JavaSyntaxRegexProvider;
|
||||
import dagger.Module;
|
||||
@@ -17,4 +18,9 @@ public class CoreModule {
|
||||
public JavaSyntaxRegexProvider javaSyntaxRegexProvider() {
|
||||
return new JavaSyntaxRegexProvider();
|
||||
}
|
||||
|
||||
@Provides
|
||||
public DescriptionProvider descriptionProvider() {
|
||||
return new DescriptionProvider();
|
||||
}
|
||||
}
|
||||
|
||||
0
src/main/resources/description.properties
Normal file
0
src/main/resources/description.properties
Normal file
Reference in New Issue
Block a user