use of org.springframework.roo.process.manager.MutableFile in project spring-roo by spring-projects.
the class PropFilesManagerServiceImpl method removeProperty.
@Override
public void removeProperty(LogicalPath propertyFilePath, String propertyFilename, String prefix, String key) {
Validate.notNull(prefix, "Prefix could be blank but not null");
Validate.notNull(propertyFilePath, "Property file path required");
Validate.notBlank(propertyFilename, "Property filename required");
Validate.notBlank(key, "Key required");
final String filePath = getProjectOperations().getPathResolver().getIdentifier(propertyFilePath, propertyFilename);
MutableFile mutableFile = null;
final Properties props = new Properties();
if (getFileManager().exists(filePath)) {
mutableFile = getFileManager().updateFile(filePath);
loadProperties(props, mutableFile.getInputStream());
} else {
throw new IllegalStateException(String.format("ERROR: '%s' properties file doesn't exists.", filePath));
}
// Including prefix if needed
if (StringUtils.isNotBlank(prefix)) {
key = prefix.concat(".").concat(key);
}
if (props.containsKey(key)) {
props.remove(key);
storeProps(props, mutableFile.getOutputStream(), "Updated at " + new Date());
}
}
use of org.springframework.roo.process.manager.MutableFile in project spring-roo by spring-projects.
the class LoggingOperationsImpl method setupProperties.
private void setupProperties(final LogLevel logLevel, final LoggerPackage loggerPackage) {
final String filePath = pathResolver.getFocusedIdentifier(Path.SRC_MAIN_RESOURCES, "log4j.properties");
MutableFile log4jMutableFile = null;
final Properties props = new Properties();
InputStream inputStream = null;
try {
if (fileManager.exists(filePath)) {
log4jMutableFile = fileManager.updateFile(filePath);
inputStream = log4jMutableFile.getInputStream();
props.load(inputStream);
} else {
log4jMutableFile = fileManager.createFile(filePath);
inputStream = FileUtils.getInputStream(getClass(), "log4j-template.properties");
Validate.notNull(inputStream, "Could not acquire log4j configuration template");
props.load(inputStream);
}
} catch (final IOException ioe) {
throw new IllegalStateException(ioe);
} finally {
IOUtils.closeQuietly(inputStream);
}
final JavaPackage topLevelPackage = projectOperations.getTopLevelPackage(projectOperations.getFocusedModuleName());
final String logStr = "log4j.logger.";
switch(loggerPackage) {
case ROOT:
props.remove("log4j.rootLogger");
props.setProperty("log4j.rootLogger", logLevel.name() + ", stdout");
break;
case PROJECT:
props.remove(logStr + topLevelPackage.getFullyQualifiedPackageName());
props.setProperty(logStr + topLevelPackage.getFullyQualifiedPackageName(), logLevel.name());
break;
default:
for (final String packageName : loggerPackage.getPackageNames()) {
props.remove(logStr + packageName);
props.setProperty(logStr + packageName, logLevel.name());
}
break;
}
OutputStream outputStream = null;
try {
outputStream = log4jMutableFile.getOutputStream();
props.store(outputStream, "Updated at " + new Date());
} catch (final IOException ioe) {
throw new IllegalStateException(ioe);
} finally {
IOUtils.closeQuietly(outputStream);
}
}
Aggregations