Skip to content

Commit a01e558

Browse files
committedOct 22, 2013
First commit (migrated from svn)
1 parent 1f845d5 commit a01e558

File tree

10 files changed

+811
-0
lines changed

10 files changed

+811
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<books>
2+
<book>
3+
<id>book:urn:org:netkernel:introspect:maven</id>
4+
<title>Maven Repository Server</title>
5+
<desc>Documentation for the dynamically introspected maven repository server</desc>
6+
<author/>
7+
<publisher/>
8+
<date/>
9+
<modified>/</modified>
10+
<!-- <icon>res:/org/netkernel/lang/groovy/img/icon.png</icon> -->
11+
<keywords/>
12+
<toc>
13+
<item id="doc:introspect:maven:guide"/>
14+
<item id="doc:introspect:maven:license"/>
15+
</toc>
16+
</book>
17+
</books>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<docs>
2+
3+
<doc>
4+
<id>doc:introspect:maven:guide</id>
5+
<title>Maven Guide</title>
6+
<desc>A guide to the introspected dynamic maven repository server</desc>
7+
<uri>res:/org/netkernel/introspect/maven/doc/guide.txt</uri>
8+
</doc>
9+
10+
<doc>
11+
<id>doc:introspect:maven:license</id>
12+
<title>License</title>
13+
<desc>License information for Maven server module</desc>
14+
<uri>res:/org/netkernel/introspect/maven/doc/license.txt</uri>
15+
</doc>
16+
17+
</docs>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<connection>
2+
<type>HTTPFulcrum</type>
3+
</connection>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<module version="2.0">
2+
<meta>
3+
<identity>
4+
<uri>urn:org:netkernel:introspect:maven</uri>
5+
<version>1.1.1</version>
6+
</identity>
7+
<info>
8+
<name>Maven / Introspected Repository Server</name>
9+
<description>A Maven repository derived from introspecting the deployed NetKernel System</description>
10+
</info>
11+
</meta>
12+
<system>
13+
<dynamic/>
14+
</system>
15+
16+
<rootspace name="Maven - Core Application Space" public="true">
17+
<!--***********************************
18+
Application Space - presents all paths
19+
*****************************************-->
20+
<overlay>
21+
<prototype>RESTOverlay</prototype>
22+
<config>
23+
<basepath>/netkernel-maven/</basepath>
24+
</config>
25+
<space>
26+
<mapper>
27+
<config>res:/resources/mapperConfig.xml</config>
28+
<space name="Maven - Mapped Space">
29+
<import>
30+
<uri>urn:org:netkernel:introspect:maven:common</uri>
31+
</import>
32+
</space>
33+
</mapper>
34+
</space>
35+
</overlay>
36+
<accessor>
37+
<grammar>
38+
<active>
39+
<identifier>active:MavenLibraryIntrospect</identifier>
40+
</active>
41+
</grammar>
42+
<class>org.netkernel.introspect.maven.endpoint.LibraryIntrospectAccessor</class>
43+
</accessor>
44+
<import>
45+
<private/>
46+
<uri>urn:org:netkernel:introspect:maven:common</uri>
47+
</import>
48+
<import>
49+
<private/>
50+
<uri>urn:org:netkernel:tpt:http</uri>
51+
</import>
52+
<fileset>
53+
<regex>res:/etc/system/SimpleDynamicImportHook.xml</regex>
54+
</fileset>
55+
</rootspace>
56+
57+
58+
<rootspace name="Maven - Common Toolbox" uri="urn:org:netkernel:introspect:maven:common" public="false">
59+
<!--***********************************
60+
Common resources:
61+
Local Filesets
62+
Imports of language libraries, http, etc
63+
*******************************************-->
64+
<fileset>
65+
<regex>res:/resources/.*</regex>
66+
</fileset>
67+
<import>
68+
<uri>urn:org:netkernel:lang:groovy</uri>
69+
</import>
70+
<import>
71+
<uri>urn:org:netkernel:ext:layer1</uri>
72+
</import>
73+
<import>
74+
<uri>urn:org:netkernel:xml:core</uri>
75+
</import>
76+
<import>
77+
<uri>urn:org:netkernel:mod:security</uri>
78+
</import>
79+
</rootspace>
80+
81+
<rootspace name="Maven - Documentation" uri="urn:org:netkernel:introspect:maven:doc" public="true">
82+
<!--***********************************
83+
Common resources:
84+
Local Filesets
85+
Imports of language libraries, http, etc
86+
*******************************************-->
87+
<fileset>
88+
<regex>res:/etc/system/(Books|Docs)\.xml</regex>
89+
</fileset>
90+
<fileset>
91+
<regex>res:/org/netkernel/introspect/maven/doc/.*</regex>
92+
</fileset>
93+
94+
</rootspace>
95+
96+
</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
==Dynamic Maven Server==
2+
3+
The dynamic [http://maven.apache.org/|Maven] server provides a maven repository comprising the core NetKernel system libraries. The following parts of NetKernel are dynamically introspected and logically mapped into a
4+
maven repository REST structure.
5+
6+
*[ install ] / lib / *.jar - the core NetKernel foundation libraries including the NetKernel kernel, kernel API, layer0, standard module and cache.
7+
*[ install ] / modules / urn.org.netkernel.*.jar - modules provided as part of the NKEE/NKSE installation which export a classpath.
8+
9+
==Important Requirement==
10+
11+
The Maven server will only introspectively discover jarred libraries and modules. It is therefore essential that if you are setting up a NetKernel as your maven repository server that when
12+
you install it, you do '''*not*''' choose the "expand jarred libraries" option in the installer.
13+
14+
==Interface==
15+
16+
The Maven repository runs on the Front-End-Fulcrum server at:
17+
18+
http://localhost:8080/netkernel-maven/
19+
20+
To use a repository with a CI or remote build system then make sure to replace "localhost" with the hostname of your NetKernel instance.
21+
22+
====Core Libraries====
23+
24+
The core libraries (discovered in lib/ ) can be found on the following logical maven path...
25+
26+
http://localhost:8080/netkernel-maven/urn/com/ten60/core/
27+
28+
Core libraries belong to the '''urn.com.ten60.core''' group. Each maven library artifact is named with a short name derived from the name of the introspected jar.
29+
30+
For example...
31+
32+
lib / urn.com.ten60.core.module.standard-x.x.x.jar
33+
34+
Appears in the maven repository as...
35+
36+
{literal}
37+
group: urn.com.ten60.core
38+
artifactId: module.standard
39+
version: x.x.x
40+
{/literal}
41+
42+
====Module Libraries====
43+
44+
System modules that export a classpath can be found on the following path...
45+
46+
http://localhost:8080/netkernel-maven/urn/org/netkernel/
47+
48+
Module libraries belong to the '''urn.org.netkernel''' group. A maven module library artifact is named with a short name derived from the shipped jar.
49+
50+
For example...
51+
52+
modules / urn.org.netkernel.lang.groovy-x.x.x.jar
53+
54+
Appears in the maven repository as...
55+
56+
{literal}
57+
group: urn.org.netkernel
58+
artifactId: lang.groovy
59+
version: x.x.x
60+
{/literal}
61+
62+
Please note, only jarred modules that export a classpath are considered for inclusion in the logical maven repository - since if a module doesn't export a classpath there would be no point attempting to build against it.
63+
64+
====Expanded Module Jars====
65+
66+
If a module contains jars in a lib/ directory then these are considered to be dependencies and mapped into the special group '''urn.org.netkernel.expanded.lib''' in the maven repository - the expanded lib jars
67+
are uniquely identified with the version number of the module from which they are exported. They can be found on the following path...
68+
69+
http://localhost:8080/netkernel-maven/urn/org/netkernel/expanded/lib/
70+
71+
Please note that if you build against a module that has expanded lib jars then these will be automatically included as classpath dependencies.
72+
73+
==Dynamic Introspection==
74+
75+
The Maven repository is a logical constuct that is created by transforming a "discovered library resource" that is provided by an accessor that actively introspects a live system. Since this resource is in the ROC domain
76+
it is cached and the logical maven repository resources are also cached.
77+
78+
Whenever updates to the NetKernel system are made (via apposite) then new libraries will be automatically discovered and immediately appear in the logical maven repository.
79+
80+
==Acknowledgements==
81+
82+
The idea of a dynamically introspected maven repository was first proposed by Brian Sletten. Both Brian and Randy Kahle provided feedback and testing during development.
83+
84+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
=License=
2+
3+
The resources and source code of the '''urn:org:netkernel:introspect:maven''' module are licensed under the [http://www.1060research.com/license|1060 Public License v1.2].
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
package org.netkernel.introspect.maven.endpoint;
2+
3+
import java.util.HashMap;
4+
5+
import org.netkernel.layer0.boot.BootUtils;
6+
import org.netkernel.layer0.nkf.INKFRequest;
7+
import org.netkernel.layer0.nkf.INKFRequestContext;
8+
import org.netkernel.layer0.representation.IHDSNode;
9+
import org.netkernel.layer0.representation.IHDSNodeList;
10+
import org.netkernel.layer0.representation.impl.HDSBuilder;
11+
import org.netkernel.module.standard.endpoint.StandardAccessorImpl;
12+
13+
public class LibraryIntrospectAccessor extends StandardAccessorImpl
14+
{
15+
private static final String COM_BASE="urn.com.ten60.core";
16+
private static final String ORG_BASE="urn.org.netkernel";
17+
private static final String LIB_BASE="urn.org.netkernel.expanded.lib";
18+
19+
public LibraryIntrospectAccessor()
20+
{ this.declareThreadSafe();
21+
}
22+
23+
@Override
24+
public void onSource(INKFRequestContext aContext) throws Exception
25+
{
26+
String installPath=BootUtils.getInstallPath(aContext.getKernelContext().getKernel().getConfiguration());
27+
String libPath=installPath+"lib/";
28+
29+
//Find kernel and core libraries
30+
HDSBuilder b=new HDSBuilder();
31+
b.pushNode("fls");
32+
b.addNode("root", libPath);
33+
b.addNode("filter", ".*.jar");
34+
b.addNode("uri", "true");
35+
36+
INKFRequest req=aContext.createRequest("active:fls");
37+
req.addArgumentByValue("operator", b.getRoot());
38+
req.setRepresentationClass(IHDSNode.class);
39+
IHDSNode rep=(IHDSNode)aContext.issueRequest(req);
40+
41+
//Parse and place into a tree structure
42+
b=new HDSBuilder();
43+
String base=COM_BASE+".";
44+
String[] baseA=base.split("\\.");
45+
for(int i=0; i<baseA.length; i++)
46+
{ b.pushNode(baseA[i], null);
47+
}
48+
for(IHDSNode n : rep.getNodes("//res"))
49+
{ String raw=(String)n.getValue();
50+
String s=raw.replaceAll("\\.jar", "");
51+
String[] sa=s.split("-");
52+
String version=sa[1];
53+
String name=sa[0];
54+
name=name.substring(base.length());
55+
b.pushNode("artifact", name);
56+
b.addNode(name, null);
57+
b.addNode(name+version, null);
58+
b.addNode(raw, null);
59+
b.addNode("group", COM_BASE);
60+
b.addNode("name", name);
61+
b.addNode("version", version);
62+
b.addNode("jar", raw);
63+
b.addNode("fullname", s);
64+
b.addNode("uri", n.getFirstValue("uri"));
65+
IHDSNode deps=aContext.source("res:/resources/static-dependencies.xml", IHDSNode.class);
66+
IHDSNodeList d=deps.getNodes("//"+name);
67+
if(d.size()>0)
68+
{ b.pushNode("dependencies");
69+
for(int i=0; i<d.size(); i++)
70+
{ IHDSNode m=d.get(i);
71+
b.pushNode("dependency");
72+
b.addNode("groupId", COM_BASE);
73+
b.addNode("artifactId", m.getValue());
74+
b.addNode("version", "[1.1.1,)");
75+
b.popNode();
76+
}
77+
b.popNode();
78+
}
79+
b.popNode();
80+
}
81+
82+
//Find system modules
83+
libPath=installPath+"modules/";
84+
85+
HDSBuilder b2=new HDSBuilder();
86+
b2.pushNode("fls");
87+
b2.addNode("root", libPath);
88+
b2.addNode("filter", ".*urn\\.org\\.netkernel\\..*?.jar");
89+
b2.addNode("uri", "true");
90+
91+
req=aContext.createRequest("active:fls");
92+
req.addArgumentByValue("operator", b2.getRoot());
93+
req.setRepresentationClass(IHDSNode.class);
94+
rep=(IHDSNode)aContext.issueRequest(req);
95+
96+
//Parse and place into the tree
97+
libPath=installPath+"lib/expanded/";
98+
base=ORG_BASE+".";
99+
baseA=base.split("\\.");
100+
IHDSNode urnnode=b.getRoot().getFirstNode("/urn");
101+
b.setCursor(urnnode);
102+
for(int i=1; i<baseA.length; i++)
103+
{ b.pushNode(baseA[i], null);
104+
}
105+
HDSBuilder b3=new HDSBuilder();
106+
b3.pushNode("libs");
107+
for(IHDSNode n : rep.getNodes("//res"))
108+
{ String raw=(String)n.getValue();
109+
String s=raw.replaceAll("\\.jar", "");
110+
String[] sa=s.split("-");
111+
String version=sa[1];
112+
String fullname=sa[0];
113+
String name=fullname.substring(base.length());
114+
String uri=(String)n.getFirstValue("uri");
115+
//Imported Dependencies
116+
IHDSNode module=aContext.source("jar:"+uri+"!/module.xml", IHDSNode.class);
117+
IHDSNode exports=module.getFirstNode("/module/system/classloader/exports");
118+
if(exports!=null)
119+
{ //Only add the module to maven if it actually exports a classpath
120+
b.pushNode("artifact", name);
121+
b.addNode(name, null);
122+
b.addNode(name+version, null);
123+
b.addNode(raw, null);
124+
b.addNode("name", name);
125+
b.addNode("group", ORG_BASE);
126+
b.addNode("version", version);
127+
b.addNode("jar", raw);
128+
b.addNode("fullname", s);
129+
b.addNode("uri", uri);
130+
//Static Dependencies
131+
b.pushNode("dependencies");
132+
b.pushNode("dependency");
133+
b.addNode("groupId", COM_BASE);
134+
b.addNode("artifactId", "netkernel.api");
135+
b.addNode("version", "[1.1.1,)");
136+
b.popNode();
137+
b.pushNode("dependency");
138+
b.addNode("groupId", COM_BASE);
139+
b.addNode("artifactId", "netkernel.impl");
140+
b.addNode("version", "[1.1.1,)");
141+
b.popNode();
142+
b.pushNode("dependency");
143+
b.addNode("groupId", COM_BASE);
144+
b.addNode("artifactId", "layer0");
145+
b.addNode("version", "[1.1.1,)");
146+
b.popNode();
147+
b.pushNode("dependency");
148+
b.addNode("groupId", COM_BASE);
149+
b.addNode("artifactId", "module.standard");
150+
b.addNode("version", "[1.1.1,)");
151+
b.popNode();
152+
b.pushNode("dependency");
153+
b.addNode("groupId", COM_BASE);
154+
b.addNode("artifactId", "cache.se");
155+
b.addNode("version", "[1.1.1,)");
156+
b.popNode();
157+
//Find any imports
158+
IHDSNodeList imports=module.getNodes("//import");
159+
HashMap added=new HashMap();
160+
for(int i=0; i<imports.size(); i++)
161+
{ IHDSNode imp=imports.get(i);
162+
String is=((String)imp.getFirstValue("uri")).replaceAll(":", ".");
163+
if(is.startsWith(base))
164+
{ is=is.substring(base.length());
165+
if(added.get(is)==null)
166+
{ b.pushNode("dependency");
167+
b.addNode("groupId", ORG_BASE);
168+
b.addNode("artifactId", is);
169+
b.addNode("version", "[1.1.1,)");
170+
b.popNode();
171+
added.put(is, is);
172+
}
173+
}
174+
}
175+
//Find any expanded jar libraries
176+
b2=new HDSBuilder();
177+
b2.pushNode("fls");
178+
b2.addNode("root", libPath);
179+
String filter = ".*?"+fullname.replaceAll("\\.","\\\\.")+"-"+version.replaceAll("\\.","\\\\.")+".*.jar";
180+
b2.addNode("filter", filter);
181+
b2.addNode("uri", "true");
182+
183+
req=aContext.createRequest("active:fls");
184+
req.addArgumentByValue("operator", b2.getRoot());
185+
req.setRepresentationClass(IHDSNode.class);
186+
rep=(IHDSNode)aContext.issueRequest(req);
187+
188+
for(IHDSNode n2 : rep.getNodes("//res"))
189+
{
190+
String id=((String)n2.getValue()).replaceAll("\\.jar","");
191+
b.pushNode("dependency");
192+
b.addNode("groupId", LIB_BASE);
193+
b.addNode("artifactId", id);
194+
b.addNode("version", version);
195+
b.popNode();
196+
b3.pushNode("lib");
197+
b3.addNode("artifactId", id);
198+
b3.addNode("version", version);
199+
b3.importNode(n2);
200+
b3.popNode();
201+
}
202+
b.popNode();
203+
b.popNode();
204+
}
205+
}
206+
//Process discovered expanded library artifacts
207+
b.setCursor(b.getRoot().getFirstNode("/urn/org/netkernel")); //Reset cursor to the /urn/org/netkernel path and add the expanded/lib/ path
208+
b.pushNode("expanded");
209+
b.pushNode("lib");
210+
for(IHDSNode n : b3.getRoot().getNodes("//lib"))
211+
{ String name=(String)n.getFirstValue("artifactId");
212+
String version=(String)n.getFirstValue("version");
213+
String raw=LIB_BASE+"."+name+"-"+version+".jar";
214+
b.pushNode("artifact", name);
215+
b.addNode(name, null);
216+
b.addNode(name+version, null);
217+
b.addNode(raw, null);
218+
b.addNode("group", LIB_BASE);
219+
b.addNode("name", name);
220+
b.addNode("version", version);
221+
b.addNode("jar", name+".jar");
222+
b.addNode("fullname", ORG_BASE+"."+name);
223+
b.addNode("uri", n.getFirstValue("res/uri"));
224+
b.popNode();
225+
}
226+
aContext.createResponseFrom(b.getRoot());
227+
}
228+
}
229+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<config>
2+
<endpoint>
3+
<meta>
4+
<rest>
5+
<simple>{path}</simple>
6+
<Etag>MD5</Etag>
7+
<compress/>
8+
</rest>
9+
</meta>
10+
<grammar>
11+
<active>
12+
<identifier>active:mavenRESTServer</identifier>
13+
<argument name="path"/>
14+
</active>
15+
</grammar>
16+
<request>
17+
<identifier>active:groovy</identifier>
18+
<argument name="operator">res:/resources/mavenRESTServer.gy</argument>
19+
<argument name="path">arg:path</argument>
20+
</request>
21+
</endpoint>
22+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
import org.netkernel.layer0.representation.*;
2+
import org.netkernel.layer0.representation.impl.*;
3+
import org.netkernel.urii.impl.*;
4+
import java.text.*;
5+
6+
path=context.getThisRequest().getArgumentValue("path")
7+
libs=context.source("active:MavenLibraryIntrospect", IHDSNode.class)
8+
code=200;
9+
10+
resp=null;
11+
if(path.contains("maven-metadata"))
12+
{
13+
if(path.endsWith("xml"))
14+
{
15+
p=null;
16+
pa=path.split("/")
17+
p=pa[pa.length-2]
18+
n=libs.getFirstNode("//"+p).getParent()
19+
20+
resp="Metadata";
21+
b=new HDSBuilder();
22+
b.pushNode("metadata")
23+
b.addNode("groupId", n.getParent().getXPath().replaceAll("/", ".").substring(1))
24+
artifactId=n.getFirstValue("name")
25+
b.addNode("artifactId",artifactId)
26+
b.pushNode("versioning")
27+
28+
b.pushNode("versions")
29+
//Iterate over versions here
30+
s="//"+n.getFirstValue("name")
31+
r=n;
32+
while(r.getParent()!=null)
33+
{ r=r.getParent();
34+
}
35+
c=r.getNodes(s)
36+
map=new HashMap();
37+
for(int i=0; i<c.size(); i++)
38+
{ v=c.get(i).getParent().getFirstValue("version");
39+
vs=new Version(v)
40+
map.put(vs, v);
41+
}
42+
for(key in map.keySet().sort())
43+
{ v=map.get(key);
44+
b.addNode("version",v)
45+
}
46+
47+
b.popNode()
48+
max=b.getRoot().getFirstValue("/metadata/versioning/versions/version[1]");
49+
b.addNode("release", max );
50+
n=r.getFirstNode("//"+artifactId+max)
51+
uri=n.getParent().getFirstValue("uri")
52+
f=new File(URI.create(uri))
53+
lm=new Date(f.lastModified());
54+
sdf=new SimpleDateFormat("yyyyMMddHHmmss")
55+
sb=new StringBuffer();
56+
sdf.format(lm, sb, new FieldPosition(DateFormat.MONTH_FIELD))
57+
b.addNode("lastModified", sb.toString())
58+
resp=context.createResponseFrom(b.getRoot())
59+
resp.setMimeType("text/xml");
60+
resp.setHeader("httpResponse:/code", code);
61+
return;
62+
}
63+
else if(path.endsWith("md5"))
64+
{ path="active:mavenRESTServer+path@"+path.replaceAll("md5", "xml")
65+
req=context.createRequest("active:md5sum")
66+
req.addArgument("operand", path);
67+
resp=context.issueRequest(req);
68+
resp=context.createResponseFrom(resp)
69+
resp.setHeader("httpResponse:/code", code);
70+
resp.setMimeType("text/plain");
71+
return;
72+
73+
}
74+
else if(path.endsWith("sha1"))
75+
{ path="active:mavenRESTServer+path@"+path.replaceAll("sha1", "xml")
76+
req=context.createRequest("active:sha1sum")
77+
req.addArgument("operand", path);
78+
resp=context.issueRequest(req);
79+
resp=context.createResponseFrom(resp)
80+
resp.setHeader("httpResponse:/code", code);
81+
resp.setMimeType("text/plain");
82+
return;
83+
84+
}
85+
}
86+
if(path.contains(".pom"))
87+
{
88+
pa=path.split("/")
89+
jar=pa[pa.length-1].replaceAll("pom.*", "jar")
90+
pa=path.split(jar.substring(0, jar.indexOf("-")))
91+
base=pa[0].replaceAll("/", ".");
92+
93+
n=libs.getFirstNode("//"+base+jar).getParent();
94+
95+
if(path.endsWith("pom"))
96+
{
97+
b=new HDSBuilder()
98+
b.pushNode("project")
99+
b.addNode("@xmlns", "http://maven.apache.org/POM/4.0.0")
100+
b.addNode("@xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
101+
b.addNode("@xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0\nhttp://maven.apache.org/xsd/maven-4.0.0.xsd")
102+
b.addNode("modelVersion", "4.0.0")
103+
b.addNode("groupId", n.getParent().getXPath().replaceAll("/", ".").substring(1))
104+
artifactId=n.getFirstValue("name")
105+
b.addNode("artifactId", artifactId)
106+
b.addNode("packaging", "jar")
107+
b.addNode("version", n.getFirstValue("version"))
108+
b.addNode("name", n.getFirstValue("name")+" **AUTO GENERATED - WILL BE MAPPED TO STATIC TEXT DESCRIPTION FOR CORE LIBS**")
109+
//Find hostname
110+
hostname=context.source("httpRequest:/url")
111+
hostname=hostname.substring(0, hostname.indexOf("/netkernel-maven/"));
112+
b.addNode("url", hostname+"/netkernel-maven/")
113+
//Dependencies
114+
n=n.getNodes("//dependency")
115+
if(n.size()>0)
116+
{ b.pushNode("dependencies")
117+
for(int i=0; i<n.size(); i++)
118+
{ m=n.get(i);
119+
b.importNode(m);
120+
}
121+
}
122+
resp=context.createResponseFrom(b.getRoot())
123+
resp.setMimeType("text/xml");
124+
resp.setHeader("httpResponse:/code", code);
125+
return;
126+
}
127+
else if(path.endsWith("md5"))
128+
{ path="active:mavenRESTServer+path@"+path.replaceAll(".md5", "")
129+
req=context.createRequest("active:md5sum")
130+
req.addArgument("operand", path);
131+
resp=context.issueRequest(req);
132+
resp=context.createResponseFrom(resp)
133+
resp.setHeader("httpResponse:/code", code);
134+
resp.setMimeType("text/plain");
135+
return;
136+
137+
}
138+
else if(path.endsWith("sha1"))
139+
{ path="active:mavenRESTServer+path@"+path.replaceAll(".sha1", "")
140+
req=context.createRequest("active:sha1sum")
141+
req.addArgument("operand", path);
142+
resp=context.issueRequest(req);
143+
resp=context.createResponseFrom(resp)
144+
resp.setHeader("httpResponse:/code", code);
145+
resp.setMimeType("text/plain");
146+
return;
147+
148+
}
149+
}
150+
if(path.endsWith(".jar"))
151+
{ pa=path.split("/")
152+
jar=pa[pa.length-1]
153+
pa=path.split(jar.substring(0, jar.indexOf("-")))
154+
base=pa[0].replaceAll("/", ".");
155+
println(base+jar);
156+
n=libs.getFirstNode("//"+base+jar)
157+
uri=n.getParent().getFirstValue("uri");
158+
resp=context.sourceForResponse(uri);
159+
resp=context.createResponseFrom(resp)
160+
resp.setHeader("httpResponse:/code", code);
161+
return;
162+
}
163+
else if(path.endsWith(".md5"))
164+
{ pa=path.split("/")
165+
jar=pa[pa.length-1].replaceAll("\\.md5", "");
166+
pa=path.split(jar.substring(0, jar.indexOf("-")))
167+
base=pa[0].replaceAll("/", ".");
168+
n=libs.getFirstNode("//"+base+jar)
169+
uri=n.getParent().getFirstValue("uri");
170+
req=context.createRequest("active:md5sum")
171+
req.addArgument("operand", uri);
172+
resp=context.issueRequest(req);
173+
resp=context.createResponseFrom(resp)
174+
resp.setHeader("httpResponse:/code", code);
175+
resp.setMimeType("text/plain");
176+
return;
177+
}
178+
else if(path.endsWith(".sha1"))
179+
{ pa=path.split("/")
180+
jar=pa[pa.length-1].replaceAll("\\.sha1", "");
181+
pa=path.split(jar.substring(0, jar.indexOf("-")))
182+
base=pa[0].replaceAll("/", ".");
183+
n=libs.getFirstNode("//"+base+jar)
184+
uri=n.getParent().getFirstValue("uri");
185+
req=context.createRequest("active:sha1sum")
186+
req.addArgument("operand", uri);
187+
resp=context.issueRequest(req);
188+
resp=context.createResponseFrom(resp)
189+
resp.setHeader("httpResponse:/code", code);
190+
resp.setMimeType("text/plain");
191+
return;
192+
}
193+
else
194+
{ p=null;
195+
if(path.equals(""))
196+
{ path="/";
197+
p="/"
198+
}
199+
else
200+
{ pa=path.split("/")
201+
p=pa[pa.length-1]
202+
}
203+
//Test if we're a version?
204+
if(p.matches("\\d+\\.\\d+\\.\\d+"))
205+
{ //We're a version
206+
p=pa[pa.length-2]+pa[pa.length-1]
207+
n=libs.getFirstNode("//"+p);
208+
if(n!=null)
209+
{
210+
p=n.getParent();
211+
name=p.getFirstValue("name")
212+
version=p.getFirstValue("version")
213+
resp="""<div>
214+
<a href=".."><-- Parent</a>
215+
<br/>
216+
<br/>
217+
<a href="./${name}-${version}.jar">${name}-${version}.jar</a>
218+
<br/>
219+
<a href="./${name}-${version}.jar.md5">${name}-${version}.jar.md5</a>
220+
<br/>
221+
<a href="./${name}-${version}.jar.sha1">${name}-${version}.jar.sha1</a>
222+
<br/>
223+
<a href="./${name}-${version}.pom">${name}-${version}.pom</a>
224+
<br/>
225+
<a href="./${name}-${version}.pom.md5">${name}-${version}.pom.md5</a>
226+
<br/>
227+
<a href="./${name}-${version}.pom.sha1">${name}-${version}.pom.sha1</a>
228+
</div>
229+
""";
230+
}
231+
else
232+
{ resp="UNKNOWN";
233+
code=404;
234+
}
235+
}
236+
else
237+
{ //Try the path sub-part to see if this is an artifact
238+
n=libs.getFirstNode("//"+p)
239+
if(n!=null)
240+
{
241+
parent=n.getParent();
242+
if(parent!=null && parent.getName().equals("artifact"))
243+
{ s="//"+n.getParent().getFirstValue("name")
244+
r=n;
245+
while(r.getParent()!=null)
246+
{ r=r.getParent();
247+
}
248+
c=r.getNodes(s)
249+
resp="""<div>
250+
<a href=".."><-- Parent</a>
251+
<br/>
252+
<br/>
253+
""";
254+
map=new HashMap();
255+
for(int i=0; i<c.size(); i++)
256+
{ v=c.get(i).getParent().getFirstValue("version");
257+
vs=new Version(v)
258+
map.put(vs, c.get(i));
259+
}
260+
for(key in map.keySet().sort())
261+
{ v=map.get(key);
262+
path=v.getParent().getXPath()+"/"+key+"/";
263+
resp+="""<a href="./$key/">$key/</a><br/>"""
264+
}
265+
resp+="""<br/>
266+
<a href="maven-metadata.xml">maven-metadata.xml</a><br/>
267+
<a href="maven-metadata.md5">maven-metadata.md5</a><br/>
268+
<a href="maven-metadata.sha1">maven-metadata.sha1</a><br/>
269+
</div>"""
270+
271+
}
272+
else
273+
{ //Regular navigation
274+
n=libs.getFirstNode(path)
275+
if(n==null)
276+
{ resp="UNKNOWN";
277+
code=404;
278+
}
279+
else
280+
{
281+
c=n.getChildren();
282+
resp="""<div>
283+
<a href=".."><-- Parent</a>
284+
<br/>
285+
<br/>
286+
""";
287+
map=new HashMap();
288+
for(int i=0; i<c.length; i++)
289+
{
290+
cn=c[i].getName();
291+
if(cn.equals("artifact"))
292+
{
293+
cn=c[i].getFirstValue("name");
294+
if(map.get(cn)==null)
295+
{ map.put(cn, c[i]);
296+
}
297+
}
298+
else
299+
{ path=c[i].getXPath();
300+
resp+="""<a href="/netkernel-maven$path">$cn/</a><br/>"""
301+
}
302+
}
303+
for(key in map.keySet().sort())
304+
{ n=map.get(key)
305+
cn=n.getFirstValue("name");
306+
path=n.getParent().getXPath()+"/"+cn+"/";
307+
resp+="""<a href="/netkernel-maven$path">$cn/</a><br/>"""
308+
}
309+
resp+="</div>"
310+
}
311+
}
312+
}
313+
}
314+
}
315+
316+
resp+="""<img src="http://www.1060research.com/netkernel/poweredbynetkernel.png" style="padding: 20px;"/>""";
317+
resp="<html><body><h1>NetKernel Introspected Maven Repository</h1>"+resp+"</body></html>";
318+
319+
resp=context.createResponseFrom(resp.toString())
320+
resp.setMimeType("text/html")
321+
resp.setHeader("httpResponse:/code", code);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<dependencies>
2+
<netkernel.impl>netkernel.api</netkernel.impl>
3+
<boot>netkernel.api</boot>
4+
<boot>netkernel.impl</boot>
5+
<boot>cache.se</boot>
6+
<boot>layer0</boot>
7+
<boot>module.standard</boot>
8+
<layer0>netkernel.api</layer0>
9+
<layer0>netkernel.impl</layer0>
10+
<module.standard>netkernel.api</module.standard>
11+
<module.standard>netkernel.impl</module.standard>
12+
<module.standard>layer0</module.standard>
13+
<cache.se>netkernel.api</cache.se>
14+
<cache.se>netkernel.impl</cache.se>
15+
<cache.se>layer0</cache.se>
16+
<cache.ee>netkernel.api</cache.ee>
17+
<cache.ee>netkernel.impl</cache.ee>
18+
<cache.ee>layer0</cache.ee>
19+
</dependencies>

0 commit comments

Comments
 (0)
Please sign in to comment.