use of org.walkmod.conf.ConfigurationProvider in project walkmod-core by walkmod.
the class WalkmodFacadeTest method assertFacadeWithCfgFile.
private void assertFacadeWithCfgFile(WalkModFacade facade, String fileName) {
assertThat(facade, is(not(nullValue())));
File cfg = getValue(facade, "cfg", File.class);
assertThat(cfg.getAbsolutePath(), equalTo(new File(fileName).getAbsolutePath()));
assertDefaultOptions(facade);
ConfigurationProvider configProvider = getValue(facade, "configurationProvider", ConfigurationProvider.class);
assertThat(configProvider, is(nullValue()));
}
use of org.walkmod.conf.ConfigurationProvider in project walkmod-core by walkmod.
the class DefaultConfigurationAdapter method prepare.
@Override
public void prepare() {
Collection<ProviderConfig> providers = config.getProviderConfigurations();
if (providers != null) {
for (ProviderConfig pc : providers) {
Object aux = config.getBean(pc.getType(), pc.getParameters());
if (aux instanceof ConfigurationProvider) {
ConfigurationProvider cp = ((ConfigurationProvider) aux);
cp.init(config);
cp.load();
}
}
}
Collection<MergePolicyConfig> mergePolicies = config.getMergePolicies();
if (mergePolicies != null) {
Map<String, MergeEngine> mergeEngines = new HashMap<String, MergeEngine>();
config.setMergeEngines(mergeEngines);
for (MergePolicyConfig mpc : mergePolicies) {
MergeEngine me = new MergeEngine();
mergeEngines.put(mpc.getName(), me);
String dopTypeLabel = mpc.getDefaultObjectPolicy();
Object dop = null;
Object top = null;
if (dopTypeLabel != null) {
dop = config.getBean(dopTypeLabel, null);
}
if (dop != null && dop instanceof MergePolicy<?>) {
me.setDefaultObjectMergePolicy((MergePolicy) dop);
}
String topTypeLabel = mpc.getDefaultTypePolicy();
if (topTypeLabel != null) {
top = config.getBean(topTypeLabel, null);
}
if ((top != null) && top instanceof MergePolicy<?>) {
me.setDefaultTypeMergePolicy((MergePolicy) top);
}
Map<String, String> policyEntries = mpc.getPolicyEntries();
Class<?> oType = null;
Object pType = null;
Map<Class<?>, MergePolicy> resolvedEntries = new HashMap<Class<?>, MergePolicy>();
if (policyEntries != null && !policyEntries.isEmpty()) {
for (Map.Entry<String, String> entry : policyEntries.entrySet()) {
try {
oType = config.getClassLoader().loadClass(entry.getKey());
} catch (ClassNotFoundException e) {
throw new WalkModException("Invalid policy entry for " + entry.getKey());
}
pType = config.getBean(entry.getValue(), null);
if (pType instanceof MergePolicy) {
resolvedEntries.put(oType, (MergePolicy) pType);
}
}
}
me.setPolicyConfiguration(resolvedEntries);
}
}
}
use of org.walkmod.conf.ConfigurationProvider 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.ConfigurationProvider in project walkmod-core by walkmod.
the class WalkmodFacadeTest method facade_with_configuration_provider.
@Test
public void facade_with_configuration_provider() {
// Note that the constructor does not validate if the file exists
String fileName = "test/any_file.xml";
WalkModFacade facade = new WalkModFacade(new File(fileName), OptionsBuilder.defaultOptions(), new MockConfigurationProvider());
assertThat(facade, is(not(nullValue())));
File cfg = getValue(facade, "cfg", File.class);
assertThat(cfg.exists(), is(false));
assertThat(cfg.getAbsolutePath(), equalTo(new File(fileName).getAbsolutePath()));
assertDefaultOptions(facade);
ConfigurationProvider configProvider = getValue(facade, "configurationProvider", ConfigurationProvider.class);
assertThat(configProvider, is(not(nullValue())));
assertThat(configProvider, instanceOf(MockConfigurationProvider.class));
}
Aggregations