Fixed build dependency issues by moving hal core into hal-core folder/subproject
30
build.gradle
|
|
@ -3,14 +3,20 @@ plugins {
|
|||
id 'application'
|
||||
}
|
||||
|
||||
allprojects {
|
||||
apply plugin: 'java'
|
||||
// ------------------------------------
|
||||
// Hal common configuration
|
||||
// ------------------------------------
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
subprojects {
|
||||
apply plugin: 'java-library'
|
||||
|
||||
dependencies {
|
||||
implementation 'se.koc:zutil:1.0.0-SNAPSHOT'
|
||||
|
|
@ -41,7 +47,9 @@ allprojects {
|
|||
// ------------------------------------
|
||||
|
||||
dependencies {
|
||||
implementation 'org.xerial:sqlite-jdbc:3.32.3.2'
|
||||
project.subprojects.each { subProject ->
|
||||
runtime subProject
|
||||
}
|
||||
}
|
||||
|
||||
distributions {
|
||||
|
|
@ -50,26 +58,10 @@ distributions {
|
|||
from 'hal.conf.example'
|
||||
from 'hal-default.db'
|
||||
from 'logging.properties'
|
||||
|
||||
project.subprojects.each { sub ->
|
||||
into('lib') {
|
||||
from sub.jar
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass = 'se.hal.HalServer'
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Hal plugin common configuration
|
||||
// ------------------------------------
|
||||
|
||||
subprojects {
|
||||
dependencies {
|
||||
implementation project(':')
|
||||
}
|
||||
}
|
||||
7
hal-core/build.gradle
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// ------------------------------------
|
||||
// Hal core configuration
|
||||
// ------------------------------------
|
||||
|
||||
dependencies {
|
||||
implementation 'org.xerial:sqlite-jdbc:3.32.3.2'
|
||||
}
|
||||
0
resource/web/css/bootstrap-switch.css → hal-core/resource/web/css/bootstrap-switch.css
vendored
Executable file → Normal file
0
resource/web/css/bootstrap-switch.min.css → hal-core/resource/web/css/bootstrap-switch.min.css
vendored
Executable file → Normal file
0
resource/web/css/bootstrap-theme.css → hal-core/resource/web/css/bootstrap-theme.css
vendored
Executable file → Normal file
0
resource/web/css/bootstrap-theme.min.css → hal-core/resource/web/css/bootstrap-theme.min.css
vendored
Executable file → Normal file
0
resource/web/css/bootstrap.css → hal-core/resource/web/css/bootstrap.css
vendored
Executable file → Normal file
0
resource/web/css/bootstrap.min.css → hal-core/resource/web/css/bootstrap.min.css
vendored
Executable file → Normal file
0
resource/web/css/c3.css → hal-core/resource/web/css/c3.css
Executable file → Normal file
0
resource/web/css/c3.min.css → hal-core/resource/web/css/c3.min.css
vendored
Executable file → Normal file
0
resource/web/css/hal.css → hal-core/resource/web/css/hal.css
Executable file → Normal file
0
resource/web/css/jquery.filer.css → hal-core/resource/web/css/jquery.filer.css
Executable file → Normal file
0
resource/web/event_config.tmpl → hal-core/resource/web/event_config.tmpl
Executable file → Normal file
0
resource/web/event_detail.tmpl → hal-core/resource/web/event_detail.tmpl
Executable file → Normal file
0
resource/web/event_overview.tmpl → hal-core/resource/web/event_overview.tmpl
Executable file → Normal file
0
resource/web/fonts/glyphicons-halflings-regular.eot → hal-core/resource/web/fonts/glyphicons-halflings-regular.eot
Executable file → Normal file
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
0
resource/web/fonts/glyphicons-halflings-regular.woff2 → hal-core/resource/web/fonts/glyphicons-halflings-regular.woff2
Executable file → Normal file
0
resource/web/img/lightbulb_off.svg → hal-core/resource/web/img/lightbulb_off.svg
Executable file → Normal file
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
0
resource/web/img/lightbulb_on.svg → hal-core/resource/web/img/lightbulb_on.svg
Executable file → Normal file
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
0
resource/web/img/temperature.svg → hal-core/resource/web/img/temperature.svg
Executable file → Normal file
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
0
resource/web/js/bootstrap-switch.js → hal-core/resource/web/js/bootstrap-switch.js
vendored
Executable file → Normal file
0
resource/web/js/bootstrap-switch.min.js → hal-core/resource/web/js/bootstrap-switch.min.js
vendored
Executable file → Normal file
0
resource/web/js/bootstrap.js → hal-core/resource/web/js/bootstrap.js
vendored
Executable file → Normal file
0
resource/web/js/bootstrap.min.js → hal-core/resource/web/js/bootstrap.min.js
vendored
Executable file → Normal file
0
resource/web/js/c3.LICENSE → hal-core/resource/web/js/c3.LICENSE
Executable file → Normal file
0
resource/web/js/c3.js → hal-core/resource/web/js/c3.js
Executable file → Normal file
0
resource/web/js/c3.min.js → hal-core/resource/web/js/c3.min.js
vendored
Executable file → Normal file
0
resource/web/js/d3.LICENSE → hal-core/resource/web/js/d3.LICENSE
Executable file → Normal file
0
resource/web/js/d3.js → hal-core/resource/web/js/d3.js
vendored
Executable file → Normal file
0
resource/web/js/d3.min.js → hal-core/resource/web/js/d3.min.js
vendored
Executable file → Normal file
0
resource/web/js/hal.js → hal-core/resource/web/js/hal.js
Executable file → Normal file
0
resource/web/js/jquery.filer.js → hal-core/resource/web/js/jquery.filer.js
Executable file → Normal file
0
resource/web/js/jquery.filer.min.js → hal-core/resource/web/js/jquery.filer.min.js
vendored
Executable file → Normal file
0
resource/web/js/moment.js → hal-core/resource/web/js/moment.js
Executable file → Normal file
0
resource/web/js/svg.draggable.js → hal-core/resource/web/js/svg.draggable.js
Executable file → Normal file
0
resource/web/js/svg.draggable.min.js → hal-core/resource/web/js/svg.draggable.min.js
vendored
Executable file → Normal file
0
resource/web/js/svg.js → hal-core/resource/web/js/svg.js
Executable file → Normal file
0
resource/web/js/svg.min.js → hal-core/resource/web/js/svg.min.js
vendored
Executable file → Normal file
0
resource/web/js/svg.title.js → hal-core/resource/web/js/svg.title.js
Executable file → Normal file
0
resource/web/main_alerts.tmpl → hal-core/resource/web/main_alerts.tmpl
Executable file → Normal file
0
resource/web/main_index.tmpl → hal-core/resource/web/main_index.tmpl
Executable file → Normal file
0
resource/web/map.tmpl → hal-core/resource/web/map.tmpl
Executable file → Normal file
0
resource/web/pc_heatmap.tmpl → hal-core/resource/web/pc_heatmap.tmpl
Executable file → Normal file
0
resource/web/pc_overview.tmpl → hal-core/resource/web/pc_overview.tmpl
Executable file → Normal file
0
resource/web/sensor_config.tmpl → hal-core/resource/web/sensor_config.tmpl
Executable file → Normal file
0
resource/web/sensor_detail.tmpl → hal-core/resource/web/sensor_detail.tmpl
Executable file → Normal file
0
resource/web/sensor_overview.tmpl → hal-core/resource/web/sensor_overview.tmpl
Executable file → Normal file
0
resource/web/trigger.tmpl → hal-core/resource/web/trigger.tmpl
Executable file → Normal file
0
resource/web/user_config.tmpl → hal-core/resource/web/user_config.tmpl
Executable file → Normal file
0
src/se/hal/ControllerManager.java → hal-core/src/se/hal/ControllerManager.java
Executable file → Normal file
0
src/se/hal/HalContext.java → hal-core/src/se/hal/HalContext.java
Executable file → Normal file
166
hal-core/src/se/hal/HalServer.java
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
package se.hal;
|
||||
|
||||
|
||||
import se.hal.intf.HalDaemon;
|
||||
import se.hal.intf.HalWebPage;
|
||||
import se.hal.intf.HalJsonPage;
|
||||
import se.hal.page.*;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.struct.PluginConfig;
|
||||
import se.hal.struct.Sensor;
|
||||
import se.hal.struct.TriggerFlow;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HttpServer;
|
||||
import zutil.net.http.page.HttpFilePage;
|
||||
import zutil.net.http.page.HttpRedirectPage;
|
||||
import zutil.plugin.PluginData;
|
||||
import zutil.plugin.PluginManager;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Main class for Hal
|
||||
*/
|
||||
public class HalServer {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
private static ScheduledExecutorService daemonExecutor;
|
||||
private static List<HalDaemon> daemons = new ArrayList<>();
|
||||
|
||||
private static HttpServer http;
|
||||
private static List<HalWebPage> pages = new ArrayList<>();
|
||||
|
||||
private static PluginManager pluginManager;
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
try {
|
||||
// init logging
|
||||
LogUtil.readConfiguration("logging.properties");
|
||||
|
||||
// init DB and other configurations
|
||||
HalContext.initialize();
|
||||
DBConnection db = HalContext.getDB();
|
||||
|
||||
// ------------------------------------
|
||||
// Init Plugins
|
||||
// ------------------------------------
|
||||
|
||||
logger.info("Looking for plugins.");
|
||||
pluginManager = new PluginManager();
|
||||
|
||||
// Disable plugins based on settings
|
||||
for (PluginData plugin : getPlugins()) {
|
||||
PluginConfig pluginConfig = PluginConfig.getPluginConfig(db, plugin.getName());
|
||||
|
||||
if (pluginConfig != null && !pluginConfig.isEnabled()) {
|
||||
logger.info("Disabling plugin '" + plugin.getName() + "'.");
|
||||
plugin.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Init Managers
|
||||
// ------------------------------------
|
||||
|
||||
logger.info("Initializing managers.");
|
||||
|
||||
HalAlertManager.initialize();
|
||||
ControllerManager.initialize(pluginManager);
|
||||
TriggerManager.initialize(pluginManager);
|
||||
|
||||
// ------------------------------------
|
||||
// Import sensors,events and triggers
|
||||
// ------------------------------------
|
||||
|
||||
logger.info("Initializing Sensors and Events.");
|
||||
|
||||
for (Sensor sensor : Sensor.getLocalSensors(db)) {
|
||||
ControllerManager.getInstance().register(sensor);
|
||||
}
|
||||
for (Event event : Event.getLocalEvents(db)) {
|
||||
ControllerManager.getInstance().register(event);
|
||||
}
|
||||
// Import triggers
|
||||
for (TriggerFlow flow : TriggerFlow.getTriggerFlows(db)) {
|
||||
TriggerManager.getInstance().register(flow);
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Init daemons
|
||||
// ------------------------------------
|
||||
|
||||
logger.info("Initializing daemons.");
|
||||
|
||||
// We set only one thread for easier troubleshooting
|
||||
daemonExecutor = Executors.newScheduledThreadPool(1);
|
||||
for (Iterator<HalDaemon> it = pluginManager.getSingletonIterator(HalDaemon.class); it.hasNext(); ) {
|
||||
HalDaemon daemon = it.next();
|
||||
logger.info("Registering daemon: " + daemon.getClass());
|
||||
registerDaemon(daemon);
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Init http server
|
||||
// ------------------------------------
|
||||
|
||||
logger.info("Initializing HTTP Server.");
|
||||
|
||||
HalWebPage.getRootNav().createSubNav("Sensors");
|
||||
HalWebPage.getRootNav().createSubNav("Events").setWeight(100);
|
||||
HalWebPage.getRootNav().createSubNav("Settings").setWeight(200);
|
||||
|
||||
http = new HttpServer(HalContext.getIntegerProperty(HalContext.PROPERTY_HTTP_PORT));
|
||||
http.setDefaultPage(new HttpFilePage(FileUtil.find("resource/web/")));
|
||||
http.setPage("/", new HttpRedirectPage("/map"));
|
||||
http.setPage(HalAlertManager.getInstance().getUrl(), HalAlertManager.getInstance());
|
||||
for (Iterator<HalWebPage> it = pluginManager.getSingletonIterator(HalJsonPage.class); it.hasNext(); )
|
||||
registerPage(it.next());
|
||||
for (Iterator<HalWebPage> it = pluginManager.getSingletonIterator(HalWebPage.class); it.hasNext(); )
|
||||
registerPage(it.next());
|
||||
http.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Startup failed.", e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void setPluginEnabled(String name, boolean enabled) throws SQLException {
|
||||
DBConnection db = HalContext.getDB();
|
||||
PluginConfig pluginConfig = PluginConfig.getPluginConfig(db, name);
|
||||
|
||||
if (pluginConfig == null)
|
||||
pluginConfig = new PluginConfig(name);
|
||||
|
||||
logger.info("Plugin '" + name + "' has been " + (enabled ? "enabled" : "disabled") + ", change will take affect after restart.");
|
||||
pluginManager.getPluginData(name).setEnabled(enabled);
|
||||
|
||||
pluginConfig.setEnabled(enabled);
|
||||
pluginConfig.save(db);
|
||||
}
|
||||
|
||||
public static List<PluginData> getPlugins() {
|
||||
return pluginManager.toArray();
|
||||
}
|
||||
|
||||
|
||||
public static void registerDaemon(HalDaemon daemon){
|
||||
daemons.add(daemon);
|
||||
daemon.initiate(daemonExecutor);
|
||||
}
|
||||
|
||||
public static void registerPage(HalWebPage page){
|
||||
pages.add(page);
|
||||
http.setPage(page.getId(), page);
|
||||
}
|
||||
}
|
||||