use of io.clownfish.clownfish.compiler.CfClassLoader in project Clownfish by rawdog71.
the class Clownfish method init.
/**
* Call of the "init" site
* Init is called at the beginning of the Clownfish startup and after changing system properties
* Checks the bootstrap flag of the application.properties and calls a bootstrap routine
* Initializes several variables and starts Quartz job triggers
*/
@PostConstruct
public void init() {
LOGGER.info("INIT CLOWNFISH START");
servicestatus.setMessage("Clownfish is initializing");
servicestatus.setOnline(false);
if (null == authtokenlist) {
authtokenlist = new AuthTokenList();
}
// read all System Properties of the property table
if (null == propertyUtil) {
propertyUtil = new PropertyUtil(propertylist);
}
if (null == cfclassLoader) {
cfclassLoader = new CfClassLoader();
}
if (null == cfclassCompiler) {
cfclassCompiler = new CfClassCompiler();
cfclassCompiler.setClownfish(this);
cfclassCompiler.init(cfclassLoader, propertyUtil, cfjavaService);
}
libloaderpath = propertyUtil.getPropertyValue("folder_libs");
if (null == beanUtil)
beanUtil = new BeanUtil();
if ((!libloaderpath.isBlank()) && (null != libloaderpath))
beanUtil.init(libloaderpath);
mavenpath = propertyUtil.getPropertyValue("folder_maven");
if ((!mavenpath.isBlank()) && (null != mavenpath)) {
if (classpathUtil == null) {
classpathUtil = new ClassPathUtil();
classpathUtil.init(cfclassLoader);
}
classpathUtil.addPath(mavenpath);
}
if (null == mavenlist) {
mavenlist = new MavenList();
mavenlist.setClasspathUtil(classpathUtil);
}
Thread compileThread = new Thread(cfclassCompiler);
compileThread.start();
if (1 == bootstrap) {
bootstrap = 0;
try {
AnsiConsole.systemInstall();
System.out.println(ansi().fg(GREEN));
System.out.println("BOOTSTRAPPING II");
System.out.println(ansi().reset());
Properties props = new Properties();
String propsfile = "application.properties";
InputStream is = new FileInputStream(propsfile);
if (null != is) {
props.load(is);
props.setProperty("bootstrap", String.valueOf(bootstrap));
File f = new File("application.properties");
bootstrap();
OutputStream out = new FileOutputStream(f);
DefaultPropertiesPersister p = new DefaultPropertiesPersister();
p.store(props, out, "Application properties");
} else {
LOGGER.error("application.properties file not found");
}
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
}
/* Hazelcast test */
/*
if (null == hazelConfig) {
hazelConfig = new Config();
}
if (null == hcInstance) {
hcInstance = Hazelcast.newHazelcastInstance(hazelConfig);
}
*/
Package p = FacesContext.class.getPackage();
if (null == clownfishutil) {
clownfishutil = new ClownfishUtil();
}
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = null;
if ((new File("pom.xml")).exists()) {
try {
model = reader.read(new FileReader("pom.xml"));
} catch (FileNotFoundException ex) {
LOGGER.error(ex.getMessage());
} catch (IOException | XmlPullParserException ex) {
LOGGER.error(ex.getMessage());
}
}
if (null != model) {
clownfishutil.setVersion(model.getVersion()).setVersionMojarra(p.getImplementationVersion()).setVersionTomcat(ServerInfo.getServerNumber());
} else {
clownfishutil.setVersion(getClass().getPackage().getImplementationVersion()).setVersionMojarra(p.getImplementationVersion()).setVersionTomcat(ServerInfo.getServerNumber());
}
try {
AnsiConsole.systemInstall();
System.out.println(ansi().fg(GREEN));
System.out.println("INIT CLOWNFISH CMS Version " + clownfishutil.getVersion() + " on Tomcat " + clownfishutil.getVersionTomcat() + " with Mojarra " + clownfishutil.getVersionMojarra());
System.out.println(ansi().fg(RED));
System.out.println(" ... ");
System.out.println(" &@@@@@@@ ");
System.out.println(" .&&%%%@%@@@@ ");
System.out.println(" %%%%%%%%&%%@ ");
System.out.println(" .%%%%%%%%#%%& ");
System.out.println(" /%%%%%%%%%##% &&@@. ");
System.out.println(" .,*//#############% %#%#%@@ ");
System.out.println(" #((############### ###%#%%&@ ");
System.out.println(" // #((((/(/(((((((/ (###(###&% ");
System.out.println(" *((//((#/ #((((#(((((((# (((##%##@ ");
System.out.println(" /(((((#(////# .((((((((((((* *((((###% ");
System.out.println(" /(((((#((###### #(((((##((@@@@& ((((((## ");
System.out.println(" (((((((####@@&#(% #((((####((((&@/ #(((((((* (&@@&# ");
System.out.println(" /(((((((#######(((& *((((##(((((((#@/ #(((((((/ &&%%%%&@@@, ");
System.out.println(" /((((((((((((((#((((& (#((#(##((##((@@ #(#####(* *########%%&@@@.");
System.out.println(" /%#(((((((((((((/((((. ###########(((#@* ((#####(. /#########%%%@@@@");
System.out.println(" ,(((((((((((((((((((/ ###########((((@, ((####### ###########%%%@@@");
System.out.println(" .(((((((((((((/((((* (#########((((#@ ((######% .##########%%%&@@@");
System.out.println(" ,/(((((((((((((& #(#########((((@/ .#((###(((( #########%%%%&@@@");
System.out.println(" /((((((##(& %(((((######(((&/ .#(((((((((. *########%%%&&@@@");
System.out.println(" ,//(#@ /(#(####(((##(((&. (((((((((/ /######%%%&&@@@@");
System.out.println(" ./* .#(########((#((*/. *#(((((((###. /%##%%%%@@@@@@ ");
System.out.println(" /######((#######( ./#######(###(#@ .&@@@@@@@% ");
System.out.println(" /#######%%#(((#((((@. /@%#####(##((@# ");
System.out.println(" /####%%#@& *#(((//(/(%@ *@@@@%#%&@@ ");
System.out.println(" %#%&&@&* *((((///(@@& .##/* ");
System.out.println(" ,,***, *((/(#@@@@@, ");
System.out.println(" *@@@@@@@@% ");
System.out.println(ansi().reset());
// Check Consistence
if (checkConsistency > 0) {
consistencyUtil.checkConsistency();
}
// Generate Hibernate DOM Mapping
if (null == hibernateInitializer) {
hibernateInitializer = new HibernateInit(servicestatus, cfclassService, cfattributService, cfclasscontentService, cfattributcontentService, cflistcontentService, cfclasscontentkeywordService, cfkeywordService, dburl);
hibernateUtil.init(hibernateInitializer);
hibernateUtil.setHibernateInit(hibernateInit);
Thread hibernateThread = new Thread(hibernateUtil);
hibernateThread.start();
/*
hibernateUtil.generateTablesDatamodel(hibernateInit);
// generate Relation Tables
hibernateUtil.generateRelationsDatamodel(hibernateInit);
*/
}
propertylist.setClownfish(this);
if (null == defaultUtil) {
defaultUtil = new DefaultUtil();
}
if (mailUtil == null)
mailUtil = new MailUtil(propertyUtil);
if (pdfUtil == null)
pdfUtil = new PDFUtil(cftemplateService, cftemplateversionService, cfsitedatasourceService, cfdatasourceService, cfsiteService, propertyUtil, templateUtil);
// Set default values
// 1 = Staging mode (fetch sourcecode from commited repository) <= default
modus = STAGING;
// 0 = Development mode (fetch sourcecode from database)
defaultUtil.setCharacterEncoding("UTF-8").setContentType("text/html").setLocale(new Locale("de"));
sapSupport = propertyUtil.getPropertyBoolean("sap_support", sapSupport);
if (sapSupport) {
if (null == sapc) {
sapc = new SAPConnection(SAPCONNECTION, "Clownfish1");
rpytableread = new RPY_TABLE_READ(sapc);
}
}
// Override default values with system properties
String systemContentType = propertyUtil.getPropertyValue("response_contenttype");
String systemCharacterEncoding = propertyUtil.getPropertyValue("response_characterencoding");
String systemLocale = propertyUtil.getPropertyValue("response_locale");
if (!systemCharacterEncoding.isEmpty()) {
defaultUtil.setCharacterEncoding(systemCharacterEncoding);
}
if (!systemContentType.isEmpty()) {
defaultUtil.setContentType(systemContentType);
}
if (!systemLocale.isEmpty()) {
defaultUtil.setLocale(new Locale(systemLocale));
}
if (null == gzipswitch) {
gzipswitch = new GzipSwitch();
}
if (null == markdownUtil) {
markdownUtil = new MarkdownUtil(propertylist);
markdownUtil.initOptions();
} else {
markdownUtil.initOptions();
}
if ((null != folderUtil.getIndex_folder()) && (!folderUtil.getIndex_folder().isEmpty())) {
// Call a parallel thread to index the content in Lucene
if (null == contentIndexer) {
contentIndexer = new ContentIndexer(cfattributcontentService, indexService);
}
Thread contentindexer_thread = new Thread(contentIndexer);
contentindexer_thread.start();
LOGGER.info("CONTENTINDEXER RUN");
if (null == assetIndexer) {
assetIndexer = new AssetIndexer(cfassetService, indexService, propertylist);
}
Thread assetindexer_thread = new Thread(assetIndexer);
assetindexer_thread.start();
LOGGER.info("ASSETINDEXER RUN");
indexService.getWriter().commit();
}
// Init Site Metadata Map
if (null == metainfomap) {
// hzMetainfomap = hcInstance.getMap("metainfos");
metainfomap = new HashMap();
}
metainfomap.put("version", clownfishutil.getVersion());
metainfomap.put("versionMojarra", clownfishutil.getVersionMojarra());
metainfomap.put("versionTomcat", clownfishutil.getVersionTomcat());
// Init Lucene Search Map
if (null == searchcontentmap) {
searchcontentmap = new HashMap<>();
}
if (null == searchassetmap) {
searchassetmap = new HashMap<>();
}
if (null == searchassetmetadatamap) {
searchassetmetadatamap = new HashMap<>();
}
if (null == searchclasscontentmap) {
searchclasscontentmap = new HashMap<>();
}
if (null == searchmetadata) {
searchmetadata = new HashMap<>();
}
searchlimit = propertyUtil.getPropertyInt("lucene_searchlimit", LuceneConstants.MAX_SEARCH);
jobSupport = propertyUtil.getPropertyBoolean("job_support", jobSupport);
if (jobSupport) {
scheduler.clear();
// Fetch the Quartz jobs
quartzlist.init();
quartzlist.setClownfish(this);
List<CfQuartz> joblist = quartzlist.getQuartzlist();
joblist.stream().forEach((quartz) -> {
try {
if (quartz.isActive()) {
JobDetail job = newJob(quartz.getName());
scheduler.scheduleJob(job, trigger(job, quartz.getSchedule()));
System.out.println(ansi().fg(GREEN));
System.out.println("JOB SCHEDULE: " + quartz.getName());
System.out.println(ansi().reset());
}
} catch (SchedulerException ex) {
LOGGER.error(ex.getMessage());
}
});
}
AnsiConsole.systemUninstall();
} catch (SchedulerException | IOException ex) {
LOGGER.error(ex.getMessage());
}
folderUtil.init();
servicestatus.setMessage("Clownfish is online");
servicestatus.setOnline(true);
LOGGER.info("INIT CLOWNFISH END");
}
Aggregations