use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class XMLConfigurationProvider method loadReaderConfig.
public void loadReaderConfig(Element element, ChainConfig ac) throws ConfigurationException {
ReaderConfig readerConfig = new ReaderConfig();
if ("reader".equals(element.getNodeName())) {
if ("".equals(element.getAttribute("path"))) {
throw new ConfigurationException("Invalid reader definition: " + "A path attribute must be specified");
}
readerConfig.setPath(element.getAttribute("path"));
if ("".equals(element.getAttribute("type"))) {
readerConfig.setType(null);
} else {
readerConfig.setType(element.getAttribute("type"));
}
readerConfig.setParameters(getParams(element));
NodeList childs = element.getChildNodes();
if (childs != null) {
int max = childs.getLength();
List<String> excludes = new LinkedList<String>();
List<String> includes = new LinkedList<String>();
for (int i = 0; i < max; i++) {
Node n = childs.item(i);
String nodeName = n.getNodeName();
if ("exclude".equals(nodeName)) {
Element exclude = (Element) n;
excludes.add(exclude.getAttribute("wildcard"));
} else if ("include".equals(nodeName)) {
Element include = (Element) n;
includes.add(include.getAttribute("wildcard"));
} else {
throw new ConfigurationException("Invalid reader definition. Only exclude or include tags are supported");
}
}
if (!excludes.isEmpty()) {
String[] excludesArray = new String[excludes.size()];
int j = 0;
for (String exclude : excludes) {
excludesArray[j] = exclude;
j++;
}
readerConfig.setExcludes(excludesArray);
}
if (!includes.isEmpty()) {
String[] includesArray = new String[includes.size()];
int j = 0;
for (String include : includes) {
includesArray[j] = include;
j++;
}
readerConfig.setIncludes(includesArray);
}
}
} else {
throw new ConfigurationException("Invalid architecture definition. " + "A reader element must be defined in the architecture element " + ac.getName());
}
ac.setReaderConfig(readerConfig);
}
use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class YAMLConfigurationProvider method load.
@Override
public void load() throws ConfigurationException {
File file = new File(fileName);
try {
JsonNode node = null;
if (file.exists() && file.length() > 0) {
node = mapper.readTree(file);
configuration.prepareInitializers();
if (node.has("plugins")) {
Iterator<JsonNode> it = node.get("plugins").iterator();
Collection<PluginConfig> pluginList = new LinkedList<PluginConfig>();
while (it.hasNext()) {
JsonNode current = it.next();
String pluginId = current.asText();
String[] split = pluginId.split(":");
if (split.length > 3) {
} else {
String groupId, artifactId, version;
groupId = split[0];
artifactId = split[1];
version = split[2];
PluginConfig plugin = new PluginConfigImpl();
plugin.setGroupId(groupId);
plugin.setArtifactId(artifactId);
plugin.setVersion(version);
pluginList.add(plugin);
}
}
configuration.setPlugins(pluginList);
}
if (node.has("modules")) {
Iterator<JsonNode> it = node.get("modules").iterator();
List<String> modules = new LinkedList<String>();
configuration.setModules(modules);
while (it.hasNext()) {
JsonNode current = it.next();
modules.add(current.asText());
}
configuration.setModules(modules);
}
if (node.has("merge-policies")) {
Iterator<JsonNode> it = node.get("merge-policies").iterator();
Collection<MergePolicyConfig> mergePolicies = new LinkedList<MergePolicyConfig>();
while (it.hasNext()) {
JsonNode next = it.next();
if (next.has("policy")) {
MergePolicyConfig mergeCfg = new MergePolicyConfigImpl();
mergeCfg.setName(next.get("name").asText());
mergeCfg.setDefaultObjectPolicy(next.get("default-object-policy").asText());
mergeCfg.setDefaultTypePolicy(next.get("default-type-policy").asText());
if (next.has("policy")) {
Iterator<JsonNode> it2 = next.get("policy").iterator();
Map<String, String> policies = new HashMap<String, String>();
while (it2.hasNext()) {
JsonNode nextPolicy = it2.next();
String objectType = nextPolicy.get("object-type").asText();
String policyType = nextPolicy.get("policy-type").asText();
policies.put(objectType, policyType);
}
mergeCfg.setPolicyEntries(policies);
}
mergePolicies.add(mergeCfg);
}
}
configuration.setMergePolicies(mergePolicies);
}
if (node.has("conf-providers")) {
Iterator<JsonNode> it = node.get("conf-providers").iterator();
Collection<ProviderConfig> provConfigs = new LinkedList<ProviderConfig>();
while (it.hasNext()) {
JsonNode next = it.next();
ProviderConfig provCfg = new ProviderConfigImpl();
provCfg.setType(next.get("type").asText());
provCfg.setParameters(converter.getParams(next));
provConfigs.add(provCfg);
}
configuration.setProviderConfigurations(provConfigs);
}
if (node.has("chains")) {
Iterator<JsonNode> it = node.get("chains").iterator();
Collection<ChainConfig> chains = new LinkedList<ChainConfig>();
int i = 0;
while (it.hasNext()) {
ChainConfig chainCfg = new ChainConfigImpl();
JsonNode current = it.next();
if (current.has("name")) {
chainCfg.setName(current.get("name").asText());
} else {
chainCfg.setName("chain_" + i);
}
if (current.has("reader")) {
JsonNode reader = current.get("reader");
chainCfg.setReaderConfig(converter.getReader(reader));
} else {
addDefaultReaderConfig(chainCfg);
}
if (current.has("writer")) {
JsonNode writer = current.get("writer");
chainCfg.setWriterConfig(converter.getWriter(writer));
} else {
addDefaultWriterConfig(chainCfg);
}
if (current.has("walker")) {
chainCfg.setWalkerConfig(converter.getWalker(current));
} else {
addDefaultWalker(chainCfg);
if (current.has("transformations")) {
WalkerConfig walkerCfg = chainCfg.getWalkerConfig();
walkerCfg.setTransformations(converter.getTransformationCfgs(current));
}
}
chains.add(chainCfg);
}
configuration.setChainConfigs(chains);
} else if (node.has("transformations")) {
Collection<ChainConfig> chains = new LinkedList<ChainConfig>();
ChainConfig chainCfg = new ChainConfigImpl();
chainCfg.setName("");
addDefaultReaderConfig(chainCfg);
addDefaultWalker(chainCfg);
WalkerConfig walkerCfg = chainCfg.getWalkerConfig();
walkerCfg.setTransformations(converter.getTransformationCfgs(node));
addDefaultWriterConfig(chainCfg);
chains.add(chainCfg);
configuration.setChainConfigs(chains);
}
}
} catch (JsonProcessingException e) {
throw new ConfigurationException("Error parsing the " + fileName + " configuration", e);
} catch (IOException e) {
throw new ConfigurationException("Error reading the " + fileName + " configuration", e);
}
configuration.preparePlugins();
}
use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class IvyConfigurationProvider method initIvy.
/**
* Ivy configuration initialization
*
* @throws ParseException
* If an error occurs when loading ivy settings file
* (ivysettings.xml)
* @throws IOException
* If an error occurs when reading ivy settings file
* (ivysettings.xml)
* @throws ConfigurationException
* If ivy settings file (ivysettings.xml) is not found in
* classpath
*/
public void initIvy() throws ParseException, IOException, ConfigurationException {
if (ivy == null) {
// creates clear ivy settings
IvySettings ivySettings = new IvySettings();
File settingsFile = new File(IVY_SETTINGS_FILE);
if (settingsFile.exists()) {
ivySettings.load(settingsFile);
} else {
URL settingsURL = ClassLoader.getSystemResource(IVY_SETTINGS_FILE);
if (settingsURL == null) {
// file not found in System classloader, we try the current one
settingsURL = this.getClass().getClassLoader().getResource(IVY_SETTINGS_FILE);
// when invoking toURI()
if (settingsURL == null)
throw new ConfigurationException("Ivy settings file (" + IVY_SETTINGS_FILE + ") could not be found in classpath");
}
ivySettings.load(settingsURL);
}
// creates an Ivy instance with settings
ivy = Ivy.newInstance(ivySettings);
}
ivyfile = File.createTempFile("ivy", ".xml");
ivyfile.deleteOnExit();
applyVerbose();
String[] confs = new String[] { "default" };
resolveOptions = new ResolveOptions().setConfs(confs);
if (isOffLine) {
resolveOptions = resolveOptions.setUseCacheOnly(true);
} else {
Map<String, Object> params = configuration.getParameters();
if (params != null) {
Object value = params.get("offline");
if (value != null) {
String offlineOpt = value.toString();
if (offlineOpt != null) {
boolean offline = Boolean.parseBoolean(offlineOpt);
if (offline) {
resolveOptions = resolveOptions.setUseCacheOnly(true);
}
}
}
}
}
}
use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class IvyConfigurationProvider method load.
@Override
public void load() throws ConfigurationException {
Collection<PluginConfig> plugins = configuration.getPlugins();
PluginConfig plugin = null;
Collection<File> jarsToLoad = new LinkedList<File>();
ConfigurationException ce = null;
try {
if (plugins != null) {
Iterator<PluginConfig> it = plugins.iterator();
initIvy();
while (it.hasNext()) {
plugin = it.next();
addArtifact(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion());
}
jarsToLoad = resolveArtifacts();
URL[] urls = new URL[jarsToLoad.size()];
int i = 0;
for (File jar : jarsToLoad) {
urls[i] = jar.toURI().toURL();
i++;
}
URLClassLoader childClassLoader = new URLClassLoader(urls, configuration.getClassLoader());
configuration.setClassLoader(childClassLoader);
}
} catch (Exception e) {
if (!(e instanceof ConfigurationException)) {
if (plugin == null) {
ce = new ConfigurationException("Unable to initialize ivy configuration:" + e.getMessage());
} else {
ce = new ConfigurationException("Unable to resolve the plugin: " + plugin.getGroupId() + " : " + plugin.getArtifactId() + " : " + plugin.getVersion() + ". Reason : " + e.getMessage());
}
} else {
ce = (ConfigurationException) e;
}
throw ce;
}
}
use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class IvyConfigurationProvider method resolveArtifacts.
public Collection<File> resolveArtifacts() throws Exception {
if (ivy != null) {
if (lastResolvedArtifacts.isEmpty() || !lastResolvedArtifacts.containsAll(artifacts)) {
lastResolvedArtifacts = artifacts;
} else {
return artifactFiles;
}
XmlModuleDescriptorWriter.write(md, ivyfile);
ResolveReport report = ivy.resolve(ivyfile.toURL(), resolveOptions);
if (!report.hasError()) {
ArtifactDownloadReport[] artifacts = report.getAllArtifactsReports();
Collection<File> result = new LinkedList<File>();
for (ArtifactDownloadReport item : artifacts) {
result.add(item.getLocalFile());
}
artifactFiles = result;
return result;
} else {
artifactFiles.clear();
List problems = report.getAllProblemMessages();
if (problems == null || problems.isEmpty()) {
throw new ConfigurationException("Ivy can not resolve the artifacts. Undefined cause");
} else {
String msg = "";
Iterator it = problems.iterator();
while (it.hasNext()) {
String error = it.next().toString();
LOG.warn(error);
if ("".equals(msg)) {
msg = error;
} else {
msg = msg + ";" + error;
}
}
throw new ConfigurationException("Ivy can not resolve the artifacts. Cause: " + msg);
}
}
}
return null;
}
Aggregations