Bug fixes
This commit is contained in:
parent
c22c866000
commit
a199165756
10 changed files with 171 additions and 55 deletions
|
|
@ -89,8 +89,9 @@ public class CompactLogFormatter extends Formatter{
|
||||||
ret.append( data );
|
ret.append( data );
|
||||||
ret.append( array[i] );
|
ret.append( array[i] );
|
||||||
}
|
}
|
||||||
|
ret.append( '\n' );
|
||||||
}
|
}
|
||||||
ret.append( '\n' );
|
|
||||||
if( record.getThrown() != null ){
|
if( record.getThrown() != null ){
|
||||||
StringOutputStream out = new StringOutputStream();
|
StringOutputStream out = new StringOutputStream();
|
||||||
record.getThrown().printStackTrace(new PrintStream(out));
|
record.getThrown().printStackTrace(new PrintStream(out));
|
||||||
|
|
|
||||||
31
src/zutil/osal/HALLinuxImpl.java
Normal file
31
src/zutil/osal/HALLinuxImpl.java
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 Ziver
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package zutil.osal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Ziver on 2015-04-07.
|
||||||
|
*/
|
||||||
|
public class HALLinuxImpl implements HardwareAbstractionLayer{
|
||||||
|
|
||||||
|
protected HALLinuxImpl(){}
|
||||||
|
}
|
||||||
29
src/zutil/osal/HardwareAbstractionLayer.java
Normal file
29
src/zutil/osal/HardwareAbstractionLayer.java
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 Ziver
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package zutil.osal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Ziver on 2015-04-07.
|
||||||
|
*/
|
||||||
|
public interface HardwareAbstractionLayer {
|
||||||
|
}
|
||||||
|
|
@ -58,7 +58,7 @@ public abstract class OSAbstractionLayer {
|
||||||
* @param cmd the command to run
|
* @param cmd the command to run
|
||||||
* @return first line of the command
|
* @return first line of the command
|
||||||
*/
|
*/
|
||||||
protected String getFirstLineFromCommand(String cmd) {
|
protected static String getFirstLineFromCommand(String cmd) {
|
||||||
String[] tmp = runCommand(cmd);
|
String[] tmp = runCommand(cmd);
|
||||||
if(tmp.length > 1)
|
if(tmp.length > 1)
|
||||||
return tmp[0];
|
return tmp[0];
|
||||||
|
|
@ -71,7 +71,7 @@ public abstract class OSAbstractionLayer {
|
||||||
* @param cmd the command to run
|
* @param cmd the command to run
|
||||||
* @return a String list of the output of the command
|
* @return a String list of the output of the command
|
||||||
*/
|
*/
|
||||||
public String[] runCommand(String cmd) {
|
public static String[] runCommand(String cmd) {
|
||||||
ArrayList<String> ret = new ArrayList<String>();
|
ArrayList<String> ret = new ArrayList<String>();
|
||||||
try {
|
try {
|
||||||
Runtime runtime = Runtime.getRuntime();
|
Runtime runtime = Runtime.getRuntime();
|
||||||
|
|
@ -125,4 +125,6 @@ public abstract class OSAbstractionLayer {
|
||||||
* @return the path to the global configuration folder e.g Linux: "/etc
|
* @return the path to the global configuration folder e.g Linux: "/etc
|
||||||
*/
|
*/
|
||||||
public abstract File getGlobalConfigPath();
|
public abstract File getGlobalConfigPath();
|
||||||
|
|
||||||
|
public abstract HardwareAbstractionLayer getHAL();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ import java.io.File;
|
||||||
* User: Ziver
|
* User: Ziver
|
||||||
*/
|
*/
|
||||||
public class OsalLinuxImpl extends OSAbstractionLayer {
|
public class OsalLinuxImpl extends OSAbstractionLayer {
|
||||||
|
private static HALLinuxImpl hal;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OSType getOSType() {
|
public OSType getOSType() {
|
||||||
return OSType.Linux;
|
return OSType.Linux;
|
||||||
|
|
@ -72,4 +74,11 @@ public class OsalLinuxImpl extends OSAbstractionLayer {
|
||||||
public File getGlobalConfigPath() {
|
public File getGlobalConfigPath() {
|
||||||
return new File("/etc");
|
return new File("/etc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HardwareAbstractionLayer getHAL() {
|
||||||
|
if(hal == null)
|
||||||
|
hal = new HALLinuxImpl();
|
||||||
|
return hal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,17 +30,17 @@ import java.io.File;
|
||||||
public class OsalWindowsImpl extends OSAbstractionLayer {
|
public class OsalWindowsImpl extends OSAbstractionLayer {
|
||||||
@Override
|
@Override
|
||||||
public OSType getOSType() {
|
public OSType getOSType() {
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getOSName() {
|
public String getOSName() {
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getOSVersion() {
|
public String getOSVersion() {
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -55,16 +55,21 @@ public class OsalWindowsImpl extends OSAbstractionLayer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getUserConfigPath() {
|
public File getUserConfigPath() {
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getGlobalConfigPath() {
|
public File getGlobalConfigPath() {
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HardwareAbstractionLayer getHAL() {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ public class Templator {
|
||||||
super.compile(str);
|
super.compile(str);
|
||||||
}
|
}
|
||||||
else if(obj instanceof Integer){
|
else if(obj instanceof Integer){
|
||||||
if ((Integer) obj > 0)
|
if ((Integer) obj != 0)
|
||||||
super.compile(str);
|
super.compile(str);
|
||||||
}
|
}
|
||||||
else if(obj instanceof Iterable){
|
else if(obj instanceof Iterable){
|
||||||
|
|
@ -273,7 +273,7 @@ public class Templator {
|
||||||
|
|
||||||
// Reset map to parent object
|
// Reset map to parent object
|
||||||
if(prevObj != null)
|
if(prevObj != null)
|
||||||
set(".", obj);
|
set(".", prevObj);
|
||||||
else
|
else
|
||||||
remove(".");
|
remove(".");
|
||||||
}
|
}
|
||||||
|
|
@ -326,31 +326,29 @@ public class Templator {
|
||||||
|
|
||||||
protected class TemplateDataAttribute implements TemplateEntity {
|
protected class TemplateDataAttribute implements TemplateEntity {
|
||||||
private String tag;
|
private String tag;
|
||||||
private String key;
|
private String[] keys;
|
||||||
private String attrib;
|
|
||||||
|
|
||||||
public TemplateDataAttribute(String tag){
|
public TemplateDataAttribute(String tag){
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
String[] s = tag.trim().split("\\.", 2);
|
this.keys = tag.trim().split("\\.");
|
||||||
this.key = s[0];
|
if(this.keys.length == 0)
|
||||||
if(this.key.isEmpty()) // tag starts with "."
|
this.keys = new String[]{"."};
|
||||||
this.key = ".";
|
if(this.keys[0].isEmpty()) // if tag starts with "."
|
||||||
if(s.length > 1)
|
this.keys[0] = ".";
|
||||||
this.attrib = s[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Object getObject(){
|
public Object getObject(){
|
||||||
if (data.containsKey(tag))
|
if (data.containsKey(tag))
|
||||||
return data.get(tag);
|
return data.get(tag);
|
||||||
else if (data.containsKey(key) && data.get(key) != null) {
|
else if (data.containsKey(keys[0]) && data.get(keys[0]) != null) {
|
||||||
if (attrib != null) {
|
Object obj = data.get(keys[0]);
|
||||||
Object obj = getFieldValue(data.get(key), attrib);
|
for(int i=1; i<keys.length; ++i){
|
||||||
if(obj != null)
|
obj = getFieldValue(obj, keys[i]);
|
||||||
return obj;
|
if(obj == null)
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
else
|
return obj;
|
||||||
return data.get(key);
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -358,10 +356,14 @@ public class Templator {
|
||||||
try {
|
try {
|
||||||
if(obj.getClass().isArray() && "length".equals(attrib))
|
if(obj.getClass().isArray() && "length".equals(attrib))
|
||||||
return Array.getLength(obj);
|
return Array.getLength(obj);
|
||||||
for (Field field : obj.getClass().getDeclaredFields()) {
|
else if(obj instanceof Collection && "length".equals(attrib))
|
||||||
if(field.getName().equals(attrib)) {
|
return ((Collection) obj).size();
|
||||||
field.setAccessible(true);
|
else {
|
||||||
return field.get(obj);
|
for (Field field : obj.getClass().getDeclaredFields()) {
|
||||||
|
if (field.getName().equals(attrib)) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
return field.get(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (IllegalAccessException e){
|
}catch (IllegalAccessException e){
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import java.net.URLClassLoader;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -51,28 +52,49 @@ public class PluginData {
|
||||||
|
|
||||||
|
|
||||||
protected PluginData(DataNode data) throws ClassNotFoundException, MalformedURLException {
|
protected PluginData(DataNode data) throws ClassNotFoundException, MalformedURLException {
|
||||||
classMap = new HashMap<Class, Class>();
|
classMap = new HashMap<Class, Class>();
|
||||||
objectMap = new HashMap<Class, Object>();
|
objectMap = new HashMap<Class, Object>();
|
||||||
|
|
||||||
pluginVersion = data.getDouble("version");
|
pluginVersion = data.getDouble("version");
|
||||||
pluginName = data.getString("name");
|
pluginName = data.getString("name");
|
||||||
log.fine("Plugin: "+this);
|
log.fine("Plugin: " + this);
|
||||||
|
|
||||||
DataNode node = data.get("interfaces");
|
DataNode node = data.get("interfaces");
|
||||||
Iterator<String> intfIt = node.keyIterator();
|
if(node.isMap())
|
||||||
while (intfIt.hasNext()) {
|
addInterfaces(node);
|
||||||
String intf = intfIt.next();
|
else if(node.isList()) {
|
||||||
log.finer("Plugin interface: "+ intf+" --> "+node.get(intf).getString());
|
Iterator<DataNode> intfs_it = node.iterator();
|
||||||
classMap.put(
|
while (intfs_it.hasNext()) {
|
||||||
getClassByName(intf),
|
addInterfaces(intfs_it.next());
|
||||||
getClassByName(node.get(intf).getString()));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void addInterfaces(DataNode node){
|
||||||
private static Class getClassByName(String name) throws ClassNotFoundException, MalformedURLException {
|
Iterator<String> intf_it = node.keyIterator();
|
||||||
return Class.forName(name);
|
while (intf_it.hasNext()) {
|
||||||
|
String pluginIntf = intf_it.next();
|
||||||
|
String className = node.get(pluginIntf).getString();
|
||||||
|
try {
|
||||||
|
Class.forName(className); // Check if class is available, will throw exception if class is not found
|
||||||
|
log.finer("Plugin interface: " + pluginIntf + " --> " + className);
|
||||||
|
classMap.put(
|
||||||
|
getClassByName(pluginIntf),
|
||||||
|
getClassByName(className));
|
||||||
|
}catch (Exception e){
|
||||||
|
log.finer("Plugin interface: " + pluginIntf + " --> (Not Available) " + className);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
private static Class getClassByName(String name) {
|
||||||
|
try {
|
||||||
|
return Class.forName(name);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.log(Level.WARNING, null, e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public double getVersion(){
|
public double getVersion(){
|
||||||
return pluginVersion;
|
return pluginVersion;
|
||||||
}
|
}
|
||||||
|
|
@ -84,11 +106,11 @@ public class PluginData {
|
||||||
if(classMap.containsKey(intf)) {
|
if(classMap.containsKey(intf)) {
|
||||||
try {
|
try {
|
||||||
Class subClass = classMap.get(intf);
|
Class subClass = classMap.get(intf);
|
||||||
if (objectMap.containsKey(subClass))
|
if (!objectMap.containsKey(subClass))
|
||||||
objectMap.put(intf, subClass.newInstance());
|
objectMap.put(subClass, subClass.newInstance());
|
||||||
return (T) objectMap.get(subClass);
|
return (T) objectMap.get(subClass);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.log(Level.WARNING, null, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,7 @@ package zutil.plugin;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.sun.xml.internal.stream.util.ReadOnlyIterator;
|
import com.sun.xml.internal.stream.util.ReadOnlyIterator;
|
||||||
|
|
@ -97,11 +95,26 @@ public class PluginManager<T> implements Iterable<PluginData>{
|
||||||
public Iterator<PluginData> iterator() {
|
public Iterator<PluginData> iterator() {
|
||||||
return plugins.values().iterator();
|
return plugins.values().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> Iterator<T> iterator(Class<T> intf) {
|
public <T> Iterator<T> iterator(Class<T> intf) {
|
||||||
return new PluginInterfaceIterator<T>(plugins.values().iterator(), intf);
|
return new PluginInterfaceIterator<T>(plugins.values().iterator(), intf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<PluginData> toArray() {
|
||||||
|
ArrayList<PluginData> list = new ArrayList<PluginData>();
|
||||||
|
Iterator<PluginData> it = iterator();
|
||||||
|
while(it.hasNext())
|
||||||
|
list.add(it.next());
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public <T> ArrayList<T> toArray(Class<T> intf) {
|
||||||
|
ArrayList<T> list = new ArrayList<T>();
|
||||||
|
Iterator<T> it = iterator(intf);
|
||||||
|
while(it.hasNext())
|
||||||
|
list.add(it.next());
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class PluginInterfaceIterator<T> implements Iterator<T> {
|
public class PluginInterfaceIterator<T> implements Iterator<T> {
|
||||||
private Class<T> intf;
|
private Class<T> intf;
|
||||||
private Iterator<PluginData> it;
|
private Iterator<PluginData> it;
|
||||||
|
|
@ -129,7 +142,9 @@ public class PluginManager<T> implements Iterable<PluginData>{
|
||||||
public T next() {
|
public T next() {
|
||||||
if(!hasNext())
|
if(!hasNext())
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
return next.getObject(intf);
|
T tmp = next.getObject(intf);
|
||||||
|
next = null;
|
||||||
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
version = 1.0,
|
version = 1.0,
|
||||||
name = "Nice name of Plugin"
|
name = "Nice name of Plugin"
|
||||||
interfaces = {
|
interfaces = [
|
||||||
"plugin.interface.class" = "plugin.implementation.class",
|
{"plugin.interface.class" = "plugin.implementation.class"},
|
||||||
"wa.server.plugin.WAFrontend" = "wa.server.plugin.apache.ApacheFrontend",
|
{"wa.server.plugin.WAFrontend" = "wa.server.plugin.apache.ApacheFrontend"},
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue