use of jmri.profile.Profile in project JMRI by JMRI.
the class StartupActionsManager method initialize.
/**
* {@inheritDoc}
*
* Loads the startup action preferences and, if all required managers have
* initialized without exceptions, performs those actions. Startup actions
* are only performed if {@link apps.startup.StartupModel#isValid()} is true
* for the action. It is assumed that the action has retained an Exception
* that can be used to explain why isValid() is false.
*/
@Override
public void initialize(Profile profile) throws InitializationException {
if (!this.isInitialized(profile)) {
boolean perform = true;
try {
this.requiresNoInitializedWithExceptions(profile, Bundle.getMessage("StartupActionsManager.RefusalToInitialize"));
} catch (InitializationException ex) {
perform = false;
}
try {
Element startup;
try {
startup = JDOMUtil.toJDOMElement(ProfileUtils.getAuxiliaryConfiguration(profile).getConfigurationFragment(STARTUP, NAMESPACE, true));
} catch (NullPointerException ex) {
log.debug("Reading element from version 2.9.6 namespace...");
startup = JDOMUtil.toJDOMElement(ProfileUtils.getAuxiliaryConfiguration(profile).getConfigurationFragment(STARTUP, NAMESPACE_OLD, true));
}
for (Element action : startup.getChildren()) {
// NOI18N
String adapter = action.getAttributeValue("class");
// NOI18N
String name = action.getAttributeValue("name");
String override = StartupActionModelUtil.getDefault().getOverride(name);
if (override != null) {
action.setAttribute("name", override);
log.info("Overridding statup action class {} with {}", name, override);
this.addInitializationException(profile, new InitializationException(Bundle.getMessage(Locale.ENGLISH, "StartupActionsOverriddenClasses", name, override), Bundle.getMessage(Locale.ENGLISH, "StartupActionsOverriddenClasses", name, override)));
// after logging difference and creating error message
name = override;
}
// NOI18N
String type = action.getAttributeValue("type");
log.debug("Read {} {} adapter {}", type, name, adapter);
try {
log.debug("Creating {} {} adapter {}...", type, name, adapter);
// no perNode preferences
((XmlAdapter) Class.forName(adapter).newInstance()).load(action, null);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
log.error("Unable to create {} for {}", adapter, action, ex);
this.addInitializationException(profile, new InitializationException(Bundle.getMessage(Locale.ENGLISH, "StartupActionsCreationError", adapter, name), // NOI18N
Bundle.getMessage("StartupActionsCreationError", adapter, name)));
} catch (Exception ex) {
log.error("Unable to load {} into {}", action, adapter, ex);
this.addInitializationException(profile, new InitializationException(Bundle.getMessage(Locale.ENGLISH, "StartupActionsLoadError", adapter, name), // NOI18N
Bundle.getMessage("StartupActionsLoadError", adapter, name)));
}
}
} catch (NullPointerException ex) {
// ignore - this indicates migration has not occured
log.debug("No element to read");
}
if (perform) {
this.actions.stream().filter((action) -> (action.isValid())).forEachOrdered((action) -> {
try {
action.performAction();
} catch (JmriException ex) {
this.addInitializationException(profile, ex);
}
});
}
this.isDirty = false;
this.restartRequired = false;
this.setInitialized(profile, true);
List<Exception> exceptions = this.getInitializationExceptions(profile);
if (exceptions.size() == 1) {
throw new InitializationException(exceptions.get(0));
} else if (exceptions.size() > 1) {
throw new InitializationException(Bundle.getMessage(Locale.ENGLISH, "StartupActionsMultipleErrors"), // NOI18N
Bundle.getMessage("StartupActionsMultipleErrors"));
}
}
}
use of jmri.profile.Profile in project JMRI by JMRI.
the class JmriPreferencesProviderTest method testFindProvider.
/**
* Test of findProvider method, of class JmriPreferencesProvider.
* @throws java.io.IOException
*/
public void testFindProvider() throws IOException {
String id = Long.toString((new Date()).getTime());
Profile p = new Profile(this.getName(), id, new File(this.workspace.toFile(), id));
JmriPreferencesProvider shared = JmriPreferencesProvider.findProvider(p.getPath(), true);
JmriPreferencesProvider privat = JmriPreferencesProvider.findProvider(p.getPath(), false);
assertNotNull(shared);
assertNotNull(privat);
assertNotSame(shared, privat);
FileUtil.delete(p.getPath());
}
use of jmri.profile.Profile in project JMRI by JMRI.
the class JmriConfigurationProviderTest method testFindProvider.
/**
* Test of findProvider method, of class JmriConfigurationProvider.
*
* @throws java.io.IOException
*/
public void testFindProvider() throws IOException {
String id = Long.toString((new Date()).getTime());
Profile p = new Profile(this.getName(), id, new File(this.workspace.toFile(), id));
JmriConfigurationProvider config = JmriConfigurationProvider.findProvider(p);
assertNotNull(config);
FileUtil.delete(p.getPath());
}
use of jmri.profile.Profile in project JMRI by JMRI.
the class JmriConfigurationProviderTest method testGetConfiguration.
/**
* Test of getConfiguration method, of class JmriConfigurationProvider.
*
* @throws java.io.IOException
*/
public void testGetConfiguration() throws IOException {
String id = Long.toString((new Date()).getTime());
Profile project = new Profile(this.getName(), id, new File(this.workspace.toFile(), id));
AuxiliaryConfiguration config = JmriConfigurationProvider.getConfiguration(project);
assertNotNull(config);
FileUtil.delete(project.getPath());
}
use of jmri.profile.Profile in project JMRI by JMRI.
the class WebAppManager method lifeCycleStarted.
private void lifeCycleStarted(LifeCycle lc, Profile profile) {
// register watcher to watch web/app directories everywhere
if (this.watcher.get(profile) != null) {
FileUtil.findFiles("web", ".").stream().filter((file) -> (file.isDirectory())).forEachOrdered((file) -> {
try {
Path path = file.toPath();
WebAppManager.this.watchPaths.put(path.register(this.watcher.get(profile), StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY), path);
} catch (IOException ex) {
log.error("Unable to watch {} for changes.", file);
}
(new Thread() {
@Override
public void run() {
while (WebAppManager.this.watcher.get(profile) != null) {
WatchKey key;
try {
key = WebAppManager.this.watcher.get(profile).take();
} catch (InterruptedException ex) {
return;
}
key.pollEvents().stream().filter((event) -> (event.kind() != OVERFLOW)).forEachOrdered((event) -> {
WebAppManager.this.savePreferences(profile);
});
if (!key.reset()) {
WebAppManager.this.watcher.remove(profile);
}
}
}
}).start();
});
}
}
Aggregations