Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jessica Hawkwell
/
lang-toolkit
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 75fdc163
authored
Jul 04, 2017
by
Jessica Hawkwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed classloader, made unlinked loading work
1 parent
fca8b3a4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
119 additions
and
18 deletions
apps/bootstrap/src/main/java/me/felinewith/lang_toolkit/apps/bootstrap/BootstrapApp.java
apps/bootstrap/src/main/java/me/felinewith/lang_toolkit/apps/bootstrap/BootstrapClassLoader.java
apps/bootstrap/src/main/java/me/felinewith/lang_toolkit/apps/bootstrap/IStrappedApp.java
apps/bootstrap/src/main/java/me/felinewith/lang_toolkit/apps/bootstrap/util/LoaderHelper.java
apps/langbuilder/src/main/java/me/felinewith/lang_toolkit/apps/langbuilder/LangBuilder.java
pom.xml
apps/bootstrap/src/main/java/me/felinewith/lang_toolkit/apps/bootstrap/BootstrapApp.java
View file @
75fdc16
...
...
@@ -3,9 +3,12 @@ package me.felinewith.lang_toolkit.apps.bootstrap;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Properties
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
me.felinewith.lang_toolkit.apps.bootstrap.util.LoaderHelper
;
/**
*
...
...
@@ -18,6 +21,10 @@ public class BootstrapApp {
public
static
void
init
(
String
[]
args
)
{
ClassLoader
cl
=
BootstrapApp
.
class
.
getClassLoader
();
System
.
out
.
print
(
"ClassLoader: "
);
System
.
out
.
println
(
cl
.
toString
());
// fetch all available bootstrap descriptors
Enumeration
<
URL
>
urls
=
null
;
try
{
urls
=
cl
.
getResources
(
"bootstrap/bootstrap.properties"
);
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
BootstrapApp
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
...
...
@@ -25,6 +32,7 @@ public class BootstrapApp {
Properties
props
=
new
Properties
();
URL
u
;
if
(
urls
!=
null
)
{
// load up all the descriptors
while
(
urls
.
hasMoreElements
()
)
{
u
=
urls
.
nextElement
();
...
...
@@ -34,14 +42,67 @@ public class BootstrapApp {
}
}
// TODO: initialize app then iterate plugins
}
}
props
.
list
(
System
.
out
);
LoaderHelper
<
IStrappedApp
>
appHelper
=
new
LoaderHelper
<>(
cl
,
IStrappedApp
.
class
);
LoaderHelper
<
IStrappedPlugin
>
plugHelper
=
new
LoaderHelper
<>(
cl
,
IStrappedPlugin
.
class
);
public
BootstrapApp
(
ClassLoader
classloader
,
String
[]
arguments
)
{
cl
=
classloader
;
args
=
arguments
;
}
IStrappedApp
app
=
null
;
IStrappedPlugin
plug
=
null
;
HashMap
<
String
,
IStrappedPlugin
>
plugins
=
new
HashMap
<>();
// get the app
if
(
props
.
containsKey
(
"app"
)
)
{
try
{
app
=
appHelper
.
fetchClass
(
props
.
getProperty
(
"app"
));
}
catch
(
ClassNotFoundException
|
InstantiationException
|
IllegalAccessException
ex
)
{
Logger
.
getLogger
(
BootstrapApp
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
;
}
}
else
{
Logger
.
getLogger
(
BootstrapApp
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
new
NoClassDefFoundError
(
"Application did not provide an application class."
));
return
;
}
if
(
app
==
null
)
{
Logger
.
getLogger
(
BootstrapApp
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
new
ClassNotFoundException
(
"Application class could not be loaded."
));
return
;
}
// run through plugins
Iterator
<
String
>
it
=
props
.
stringPropertyNames
().
iterator
();
String
name
;
while
(
it
.
hasNext
()
)
{
name
=
it
.
next
();
if
(
!
name
.
equals
(
"app"
)
)
{
try
{
plug
=
plugHelper
.
fetchClass
(
props
.
getProperty
(
name
));
}
catch
(
ClassNotFoundException
|
InstantiationException
|
IllegalAccessException
ex
)
{
Logger
.
getLogger
(
BootstrapApp
.
class
.
getName
()).
log
(
Level
.
WARNING
,
null
,
ex
);
}
if
(
plug
!=
null
)
{
plugins
.
put
(
plug
.
getName
(),
plug
);
}
plug
=
null
;
}
}
// start it up
app
.
preStart
(
args
);
// check plugins
if
(
!
plugins
.
isEmpty
()
)
{
// register all the plugins
Iterator
<
IStrappedPlugin
>
itp
=
plugins
.
values
().
iterator
();
while
(
itp
.
hasNext
()
)
{
plug
=
itp
.
next
();
app
.
registerPlugin
(
plug
);
}
}
// readySetGO!
app
.
start
();
}
}
}
apps/bootstrap/src/main/java/me/felinewith/lang_toolkit/apps/bootstrap/BootstrapClassLoader.java
View file @
75fdc16
...
...
@@ -92,7 +92,7 @@ public class BootstrapClassLoader extends ClassLoader
public
void
init
()
{
Iterator
<
String
>
paths
;
paths
=
cpDirs
(
System
.
getProperty
(
"java.class.path"
));
paths
=
cpDirs
(
System
.
getProperty
(
"java.class.path"
)
.
concat
(
" ./libs"
)
);
File
f
;
String
s
;
...
...
@@ -198,15 +198,17 @@ public class BootstrapClassLoader extends ClassLoader
Iterator
<
File
>
it
=
jars
.
values
().
iterator
();
File
f
;
JarFile
jf
;
ZipEntry
z
e
;
JarEntry
j
e
;
while
(
it
.
hasNext
()
)
{
f
=
it
.
next
();
jf
=
new
JarFile
(
f
);
ze
=
jf
.
getEntry
(
name
);
je
=
jf
.
getJarEntry
(
name
);
if
(
je
!=
null
)
{
ar
.
add
(
new
URL
(
"jar:file:"
.
concat
(
f
.
getCanonicalPath
()).
concat
(
"!/"
).
concat
(
name
)));
}
jf
.
close
();
if
(
ze
!=
null
)
{
ar
.
add
(
new
URL
(
"jar:file:"
.
concat
(
f
.
getCanonicalPath
()).
concat
(
"!/"
).
concat
(
name
)));
}
}
return
new
Iterator2Enum
<>(
ar
.
iterator
());
...
...
apps/bootstrap/src/main/java/me/felinewith/lang_toolkit/apps/bootstrap/IStrappedApp.java
View file @
75fdc16
...
...
@@ -5,7 +5,7 @@ package me.felinewith.lang_toolkit.apps.bootstrap;
* @author jlhawkwell
*/
public
interface
IStrappedApp
{
public
void
preStart
();
public
void
preStart
(
String
[]
args
);
public
void
registerPlugin
(
IStrappedPlugin
plugin
);
public
void
start
();
}
apps/bootstrap/src/main/java/me/felinewith/lang_toolkit/apps/bootstrap/util/LoaderHelper.java
0 → 100644
View file @
75fdc16
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
me
.
felinewith
.
lang_toolkit
.
apps
.
bootstrap
.
util
;
/**
*
* @author jlhawkwell
*/
public
class
LoaderHelper
<
T
>
{
ClassLoader
cl
;
Class
<
T
>
t
;
public
LoaderHelper
(
ClassLoader
classLoader
,
Class
<
T
>
test
)
{
cl
=
classLoader
;
t
=
test
;
}
public
T
fetchClass
(
String
className
)
throws
ClassNotFoundException
,
InstantiationException
,
IllegalAccessException
{
Class
<?>
clz
=
null
;
Object
o
=
null
;
clz
=
cl
.
loadClass
(
className
);
if
(
clz
==
null
)
{
return
null
;
}
o
=
clz
.
newInstance
();
if
(
o
==
null
)
{
return
null
;
}
if
(
!
t
.
isInstance
(
o
)
)
{
throw
new
ClassCastException
(
"Discovered class does not match type"
);
}
return
t
.
cast
(
o
);
}
}
apps/langbuilder/src/main/java/me/felinewith/lang_toolkit/apps/langbuilder/LangBuilder.java
View file @
75fdc16
...
...
@@ -11,10 +11,12 @@ import me.felinewith.lang_toolkit.apps.bootstrap.IStrappedPlugin;
*/
public
class
LangBuilder
implements
IStrappedApp
{
private
String
[]
args
;
private
HashMap
<
String
,
IStrappedPlugin
>
plugins
;
private
JFrame
window
;
@Override
public
void
preStart
()
{
@Override
public
void
preStart
(
String
[]
argsStrings
)
{
args
=
argsStrings
;
plugins
=
new
HashMap
<>();
window
=
new
JFrame
(
"LangBuilder"
);
...
...
pom.xml
View file @
75fdc16
...
...
@@ -50,7 +50,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
</snapshotRepository>
<site>
<id>
Main
</id>
<name>
Candle POS
</name>
<name>
${project.name}
</name>
<url>
${gl.pages}
</url>
</site>
</distributionManagement>
...
...
@@ -112,9 +112,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
</snapshots>
</repository>
<repository>
<id>
in
ternal
</id>
<name>
SPM
Internal
</name>
<url>
https://mvn.felinewith.me/repository/
in
ternal
</url>
<id>
ex
ternal
</id>
<name>
SPM
Externals
</name>
<url>
https://mvn.felinewith.me/repository/
ex
ternal
</url>
<releases>
<enabled>
true
</enabled>
</releases>
...
...
@@ -159,7 +159,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
</dependencies>
<build>
<defaultGoal>
clean test package
site
</defaultGoal>
<defaultGoal>
clean test package
</defaultGoal>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment