use of org.walkmod.conf.entities.ChainConfig in project walkmod-core by walkmod.
the class YAMLConfigurationProviderTest method testTransformationsYaml.
@Test
public void testTransformationsYaml() {
YAMLConfigurationProvider provider = new YAMLConfigurationProvider("src/test/resources/yaml/basic.yml");
Configuration conf = new ConfigurationImpl();
provider.init(conf);
provider.load();
Assert.assertNotNull(conf.getChainConfigs());
ChainConfig cc = conf.getChainConfigs().iterator().next();
Assert.assertNotNull(cc.getWalkerConfig().getTransformations());
Iterator<TransformationConfig> it = cc.getWalkerConfig().getTransformations().iterator();
TransformationConfig tc = it.next();
Assert.assertEquals("walkmod:commons:method-refactor", tc.getType());
Assert.assertEquals("src/conf/refactoring-methods.json", tc.getParameters().get("refactoringConfigFile"));
}
use of org.walkmod.conf.entities.ChainConfig in project walkmod-core by walkmod.
the class YAMLConfigurationProviderTest method testChainsYaml.
@Test
public void testChainsYaml() {
YAMLConfigurationProvider provider = new YAMLConfigurationProvider("src/test/resources/yaml/chains.yml");
Configuration conf = new ConfigurationImpl();
provider.init(conf);
provider.load();
Assert.assertNotNull(conf.getChainConfigs());
ChainConfig cc = conf.getChainConfigs().iterator().next();
Iterator<TransformationConfig> it = cc.getWalkerConfig().getTransformations().iterator();
TransformationConfig first = it.next();
Assert.assertEquals("walkmod:commons:method-refactor", first.getType());
Assert.assertNotNull(cc.getReaderConfig());
Assert.assertNotNull(cc.getWriterConfig());
}
use of org.walkmod.conf.entities.ChainConfig in project walkmod-core by walkmod.
the class AddTransformationYMLAction method doAction.
@Override
public void doAction(JsonNode chainsNode) throws Exception {
ArrayNode transformationsNode = null;
boolean isMultiModule = chainsNode.has("modules");
ObjectMapper mapper = provider.getObjectMapper();
if (!isMultiModule) {
boolean validChainName = chain != null && !"".equals(chain) && !"default".equals(chain);
if (!chainsNode.has("chains")) {
if (chainsNode.has("transformations")) {
JsonNode aux = chainsNode.get("transformations");
if (aux.isArray()) {
transformationsNode = (ArrayNode) aux;
}
if (!validChainName) {
ObjectNode auxRoot = (ObjectNode) chainsNode;
if (transformationsNode == null) {
transformationsNode = new ArrayNode(mapper.getNodeFactory());
}
auxRoot.set("transformations", transformationsNode);
} else {
// reset the root
chainsNode = new ObjectNode(mapper.getNodeFactory());
ObjectNode auxRoot = (ObjectNode) chainsNode;
// the default chain list added
ObjectNode chainObject = new ObjectNode(mapper.getNodeFactory());
chainObject.set("name", new TextNode("default"));
chainObject.set("transformations", transformationsNode);
ArrayNode chainsListNode = new ArrayNode(mapper.getNodeFactory());
// the requested chain added
ObjectNode newChain = new ObjectNode(mapper.getNodeFactory());
newChain.set("name", new TextNode(chain));
if (path != null && !"".equals(path.trim())) {
ObjectNode readerNode = new ObjectNode(mapper.getNodeFactory());
newChain.set("reader", readerNode);
populateWriterReader(readerNode, path, null, null, null, null);
ObjectNode writerNode = new ObjectNode(mapper.getNodeFactory());
newChain.set("writer", writerNode);
populateWriterReader(writerNode, path, null, null, null, null);
}
transformationsNode = new ArrayNode(mapper.getNodeFactory());
newChain.set("transformations", transformationsNode);
if (before == null || !"default".equals(before)) {
chainsListNode.add(chainObject);
}
chainsListNode.add(newChain);
if (before != null && "default".equals(before)) {
chainsListNode.add(chainObject);
}
auxRoot.set("chains", chainsListNode);
}
} else {
ObjectNode auxRoot = (ObjectNode) chainsNode;
transformationsNode = new ArrayNode(mapper.getNodeFactory());
boolean writeChainInfo = validChainName;
if (!writeChainInfo) {
writeChainInfo = path != null && !"".equals(path.trim());
chain = "default";
}
if (writeChainInfo) {
ArrayNode auxChainsList = new ArrayNode(mapper.getNodeFactory());
ObjectNode aux = new ObjectNode(mapper.getNodeFactory());
auxChainsList.add(aux);
aux.set("name", new TextNode(chain));
if (path != null && !"".equals(path.trim())) {
ObjectNode readerNode = new ObjectNode(mapper.getNodeFactory());
aux.set("reader", readerNode);
populateWriterReader(readerNode, path, null, null, null, null);
}
auxRoot.set("chains", auxChainsList);
if (path != null && !"".equals(path.trim())) {
ObjectNode writerNode = new ObjectNode(mapper.getNodeFactory());
aux.set("writer", writerNode);
populateWriterReader(writerNode, path, null, null, null, null);
}
auxRoot = aux;
}
auxRoot.set("transformations", transformationsNode);
}
} else {
if (validChainName) {
JsonNode aux = chainsNode.get("chains");
boolean found = false;
if (aux.isArray()) {
Iterator<JsonNode> it = aux.elements();
while (it.hasNext()) {
JsonNode next = it.next();
if (next.has("name")) {
String id = next.get("name").asText();
if (chain.equals(id)) {
found = true;
if (next.has("transformations")) {
JsonNode auxTrans = next.get("transformations");
if (auxTrans.isArray()) {
transformationsNode = (ArrayNode) auxTrans;
} else {
throw new Exception("The chain [" + chain + "] does not have a valid transformations node");
}
} else if (next.isObject()) {
ObjectNode auxNext = (ObjectNode) next;
transformationsNode = new ArrayNode(mapper.getNodeFactory());
auxNext.set("transformations", transformationsNode);
} else {
throw new Exception("The chain [" + chain + "] does not have a valid structure");
}
}
}
}
if (!found) {
ChainConfig chainCfg = new ChainConfigImpl();
chainCfg.setName(chain);
WalkerConfig walkerCfg = new WalkerConfigImpl();
List<TransformationConfig> transfs = new LinkedList<TransformationConfig>();
transfs.add(transformationCfg);
walkerCfg.setTransformations(transfs);
chainCfg.setWalkerConfig(walkerCfg);
provider.addChainConfig(chainCfg, false, before);
return;
}
}
} else {
ObjectNode node = new ObjectNode(mapper.getNodeFactory());
node.set("name", new TextNode(chain));
ArrayNode transNodes = new ArrayNode(mapper.getNodeFactory());
node.set("transformations", transNodes);
ArrayNode array = (ArrayNode) chainsNode.get("chains");
array.add(node);
ObjectNode transformationNode = new ObjectNode(mapper.getNodeFactory());
transNodes.add(transformationNode);
createTransformation(transformationNode, transformationCfg);
return;
}
}
if (transformationsNode != null) {
ObjectNode transformationNode = new ObjectNode(mapper.getNodeFactory());
if (order != null && order < transformationsNode.size()) {
transformationsNode.insert(order, transformationNode);
} else {
transformationsNode.add(transformationNode);
}
createTransformation(transformationNode, transformationCfg);
provider.write(chainsNode);
return;
} else if (chain != null) {
throw new Exception("The chain [" + chain + "] does not exists");
}
}
}
use of org.walkmod.conf.entities.ChainConfig 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.ChainConfig in project walkmod-core by walkmod.
the class ConfigurationImpl method execute.
@Override
public void execute(String userDir, Options options, String... chains) {
ChainAdapterFactory apf = new DefaultChainAdapterFactory();
Summary.getInstance().clear();
Collection<ChainConfig> chainCfgs = getChainConfigs();
if (chainCfgs != null && !chainCfgs.isEmpty()) {
if (chains == null || chains.length == 0) {
executeAllChains(options, apf);
} else {
for (String chain : chains) {
executeChain(userDir, options, apf, chain);
}
}
}
}
Aggregations