use of org.walkmod.conf.entities.Configuration in project walkmod-core by walkmod.
the class YAMLConfigurationProviderTest method testAddChainTransformation.
@Test
public void testAddChainTransformation() throws Exception {
Map<String, String> params = new HashMap<String, String>();
params.put("refactoringConfigFile", "src/conf/refactoring-methods.json");
AddTransformationCommand command = new AddTransformationCommand("walkmod:commons:method-refactor", null, false, null, null, null, params, false);
File file = new File("src/test/resources/yaml/addchain.yml");
if (file.exists()) {
file.delete();
}
file.createNewFile();
FileUtils.write(file, "");
try {
YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
Configuration conf = new ConfigurationImpl();
provider.init(conf);
TransformationConfig transformationCfg = command.buildTransformationCfg();
provider.addTransformationConfig(null, null, transformationCfg, false, null, null);
String output = FileUtils.readFileToString(file);
String desiredOutput = "transformations:\n";
desiredOutput += "- type: \"walkmod:commons:method-refactor\"\n";
desiredOutput += " params:\n";
desiredOutput += " refactoringConfigFile: \"src/conf/refactoring-methods.json\"";
Assert.assertEquals(desiredOutput, output);
} finally {
if (file.exists()) {
file.delete();
}
}
}
use of org.walkmod.conf.entities.Configuration in project walkmod-core by walkmod.
the class YAMLConfigurationProviderTest method testAddPluginRecursively.
@Test
public void testAddPluginRecursively() throws Exception {
File dir = new File("src/test/resources/multimoduleyaml");
dir.mkdirs();
File module0 = new File(dir, "module0");
module0.mkdir();
File moduleCfg = new File(module0, "walkmod.yml");
File file = new File(dir, "walkmod.yml");
if (file.exists()) {
file.delete();
}
file.createNewFile();
try {
YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
Configuration conf = new ConfigurationImpl();
provider.init(conf);
provider.addModules(Arrays.asList("module0"));
PluginConfig pluginCfg = new PluginConfigImpl();
pluginCfg.setGroupId("org.walkmod");
pluginCfg.setArtifactId("myplugin");
pluginCfg.setVersion("1.0");
provider.addPluginConfig(pluginCfg, true);
String output = FileUtils.readFileToString(moduleCfg);
String desiredOutput = "plugins:\n";
desiredOutput += "- \"org.walkmod:myplugin:1.0\"";
Assert.assertEquals(desiredOutput, output);
} finally {
if (dir.exists()) {
FileUtils.deleteDirectory(dir);
}
}
}
use of org.walkmod.conf.entities.Configuration in project walkmod-core by walkmod.
the class DefaultChainWalkerAdapter method prepare.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void prepare() throws WalkModException {
walker.setResource(getModel());
walker.setRootNamespace(config.getRootNamespace());
ChainWriter mw = ap.getChainWriter();
mw.setExcludes(config.getChainConfig().getWriterConfig().getExcludes());
mw.setIncludes(config.getChainConfig().getWriterConfig().getIncludes());
walker.setWriter(ap.getChainWriter());
walker.setChainConfig(config.getChainConfig());
ChainConfig ac = config.getChainConfig();
Object visitor;
Configuration c = ac.getConfiguration();
Parser parser = null;
String parserType = config.getParserConfig().getType();
if (parserType != null) {
Object parserInstance = c.getBean(parserType, config.getParserConfig().getParameters());
if (parserInstance != null) {
if (parserInstance instanceof Parser) {
parser = (Parser) parserInstance;
walker.setParser(parser);
} else {
throw new WalkModException("The parser " + parserType + " must implement " + Parser.class.getName());
}
} else {
throw new WalkModException("The parser " + parserType + " does not exist.");
}
}
Collection<TransformationConfig> cfgs = getTransformationConfig();
if (cfgs != null) {
for (TransformationConfig config : cfgs) {
setName(config.getName());
visitor = config.getVisitorInstance();
if (visitor == null || "".equals(config.getType())) {
visitor = c.getBean(config.getType(), config.getParameters());
}
if (visitor instanceof ResourceModifier) {
((ResourceModifier) visitor).setResource(getModel());
}
if (visitor instanceof ParserAware) {
((ParserAware) visitor).setParser(parser);
}
if (visitor != null) {
LOG.debug("setting chain[\"" + ac.getName() + "\"].transformation[\"" + getName() + "\"].walker = " + walker.getClass().getName());
LOG.debug("setting chain[\"" + ac.getName() + "\"].transformation[\"" + getName() + "\"].visitor = " + visitor.getClass().getName());
visitors.add(visitor);
} else {
walker = null;
visitor = null;
LOG.debug("Transformation[" + getName() + "] without walker and visitor");
}
}
}
walker.setVisitors(visitors);
wi.init(this);
}
use of org.walkmod.conf.entities.Configuration in project walkmod-core by walkmod.
the class WalkModFacade method install.
/**
* Downloads the list of declared plugins in the configuration file using Ivy. Ignores the
* ConfigurationProvided if passed in the constructor.
*
* @throws InvalidConfigurationException
* if the walkmod configuration is invalid and it is working in no verbose mode.
*/
public void install() throws InvalidConfigurationException {
if (cfg.exists()) {
if (options.isVerbose()) {
log.info(cfg.getAbsoluteFile() + " [ok]");
}
// Uses Ivy always
ConfigurationProvider cp = new IvyConfigurationProvider(options.isOffline(), options.isVerbose());
if (options.isVerbose()) {
log.info("** THE PLUGIN INSTALLATION STARTS **");
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
}
long startTime = System.currentTimeMillis();
long endTime = startTime;
DecimalFormat myFormatter = new DecimalFormat("###.###");
DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss", Locale.US);
boolean error = false;
try {
userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
System.setProperty("user.dir", options.getExecutionDirectory().getCanonicalPath());
ConfigurationManager cfgManager = new ConfigurationManager(cfg, cp);
Configuration cf = cfgManager.getConfiguration();
List<String> modules = cf.getModules();
if (modules != null && !modules.isEmpty()) {
for (String module : modules) {
File aux = new File(module).getAbsoluteFile();
if (aux.isDirectory()) {
if (options.isVerbose()) {
log.info("** MODULE " + aux.getAbsoluteFile() + " [ok] **");
}
WalkModFacade facade = new WalkModFacade(OptionsBuilder.options(options).executionDirectory(aux).build());
facade.install();
} else {
log.error("The module " + aux.getAbsolutePath() + " is not an existing directory");
}
}
}
} catch (Exception e) {
System.setProperty("user.dir", userDir);
if (options.isVerbose()) {
error = true;
endTime = System.currentTimeMillis();
double time = 0;
if (endTime > startTime) {
time = (double) (endTime - startTime) / (double) 1000;
}
String timeMsg = myFormatter.format(time);
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
log.info("PLUGIN INSTALLATION FAILS");
System.out.println();
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
log.info("Total time: " + timeMsg + " seconds");
log.info("Finished at: " + df.format(new Date()));
log.info("Final memory: " + (Runtime.getRuntime().freeMemory()) / 1048576 + " M/ " + (Runtime.getRuntime().totalMemory() / 1048576) + " M");
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
if (options.isPrintErrors()) {
log.error("Plugin installations fails", e);
} else {
log.info("Plugin installations fails. Please, execute walkmod with -e to see the details");
}
if (options.isThrowException()) {
RuntimeException re = new RuntimeException();
re.setStackTrace(e.getStackTrace());
throw re;
}
} else {
throw new InvalidConfigurationException(e);
}
}
if (!error) {
System.setProperty("user.dir", userDir);
if (options.isVerbose()) {
endTime = System.currentTimeMillis();
double time = 0;
if (endTime > startTime) {
time = (double) (endTime - startTime) / (double) 1000;
}
String timeMsg = myFormatter.format(time);
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
System.out.println();
log.info("PLUGIN INSTALLATION COMPLETE");
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
log.info("Total time: " + timeMsg + " seconds");
log.info("Finished at: " + df.format(new Date()));
log.info("Final memory: " + (Runtime.getRuntime().freeMemory()) / 1048576 + " M/ " + (Runtime.getRuntime().totalMemory() / 1048576) + " M");
System.out.print("----------------------------------------");
System.out.println("----------------------------------------");
}
}
} else {
if (options.isVerbose()) {
log.error(cfg.getAbsolutePath() + " does not exist. The root directory of your project must contain a walkmod.xml");
} else {
throw new WalkModException(cfg.getAbsolutePath() + " does not exist. The root directory of your project must contain a walkmod.xml");
}
}
}
use of org.walkmod.conf.entities.Configuration in project walkmod-core by walkmod.
the class WalkModFacade method getConfiguration.
/**
* Returns the equivalent configuration representation of the Walkmod config file.
*
* @return Configuration object representation of the config file.
* @throws Exception
* If the walkmod configuration file can't be read.
*/
public Configuration getConfiguration() throws Exception {
Configuration result = null;
if (cfg.exists()) {
userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
System.setProperty("user.dir", options.getExecutionDirectory().getAbsolutePath());
try {
ConfigurationManager manager = new ConfigurationManager(cfg, false);
manager.executeConfigurationProviders();
result = manager.getConfiguration();
} finally {
System.setProperty("user.dir", userDir);
}
}
return result;
}
Aggregations