parts = asList(packageName.split("\\."));
100 | String pkg="";
101 | for (String part : parts.subList(0,parts.size())) {
102 | pkg += part;
103 | DynamicRelationshipType partType = DynamicRelationshipType.withName(part);
104 | Relationship rel = node.getSingleRelationship(partType, Direction.OUTGOING);
105 | if (rel==null) {
106 | Node partNode = graph.createNode();
107 | partNode.setProperty("name",part);
108 | partNode.setProperty("package",pkg);
109 | node.createRelationshipTo(partNode,partType);
110 | node = partNode;
111 | } else {
112 | node = rel.getEndNode();
113 | }
114 | pkg += ".";
115 | }
116 | String lastPart=parts.get(parts.size()-1);
117 | node.createRelationshipTo(packageNode,DynamicRelationshipType.withName(lastPart));
118 | }
119 |
120 | public Node getTypeNode(String typeName) {
121 | typeName = toStoredTypeName(typeName);
122 | final Node cachedNode = nodeCache.getCachedNode(typeName);
123 | if (cachedNode != null) return cachedNode;
124 |
125 | for (Relationship inPackage : getPackageForType(typeName).getRelationships(ClassRelations.TYPE, Direction.OUTGOING)) {
126 | final Node typeNode = inPackage.getEndNode();
127 | if (typeNode.hasProperty("name") && typeNode.getProperty("name").equals(typeName)) {
128 | return typeNode;
129 | }
130 | }
131 | return null;
132 | }
133 |
134 | private Node getPackageForType(String typeName) {
135 | String packageName = toPackageName(typeName);
136 | Node cachedNode = packageCache.getCachedNode(packageName);
137 | if (cachedNode!=null) {
138 | return cachedNode;
139 | }
140 | Relationship packageRel = packagesNode.getSingleRelationship(DynamicRelationshipType.withName(packageName), Direction.OUTGOING);
141 | if (packageRel==null) return null;
142 | return packageRel.getEndNode();
143 | }
144 |
145 | private String toPackageName(String typeName) {
146 | int idx = typeName.lastIndexOf(".");
147 | return idx == -1 ? "default" : typeName.substring(0, idx).replace('/', '.');
148 | }
149 |
150 | public Node getTypesNode() {
151 | return getCategoryNode(ClassRelations.ALL_TYPES);
152 | }
153 |
154 | public Node getPackagesNode() {
155 | return getCategoryNode(ClassRelations.ALL_PACKAGES);
156 | }
157 |
158 | public Node getPackageTreeNode() {
159 | return getCategoryNode(ClassRelations.PACKAGE_TREE);
160 | }
161 |
162 | public Node getCategoryNode(ClassRelations type) {
163 | final Node referenceNode = graph.getReferenceNode();
164 | final Relationship relationship = referenceNode.getSingleRelationship(type, Direction.OUTGOING);
165 | if (relationship == null) {
166 | final Transaction tx = graph.beginTx();
167 | try {
168 | final Node categoryNode = graph.createNode();
169 | categoryNode.setProperty("name", type.name());
170 | referenceNode.createRelationshipTo(categoryNode, type);
171 | tx.success();
172 | return categoryNode;
173 | } finally {
174 | tx.finish();
175 | }
176 | } else {
177 | return relationship.getEndNode();
178 | }
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/datasource/util/SizeCountingOutputStream.java:
--------------------------------------------------------------------------------
1 | package org.neo4j.datasource.util;
2 |
3 | import java.io.OutputStream;
4 | import java.io.IOException;
5 |
6 | public class SizeCountingOutputStream extends OutputStream {
7 | private long count;
8 |
9 | public void write(final int b) throws IOException {
10 | count++;
11 | }
12 |
13 | public long getCount() {
14 | return count;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/test/NeoTestHelper.java:
--------------------------------------------------------------------------------
1 | package org.neo4j.test;
2 |
3 | import org.neo4j.kernel.impl.util.FileUtils;
4 |
5 | import java.io.File;
6 | import java.io.IOException;
7 |
8 | public class NeoTestHelper {
9 | public static void dropNeoDb(final String neoStoreName) {
10 | try {
11 | FileUtils.deleteRecursively(new File(neoStoreName));
12 | } catch (IOException ioe) {
13 | System.err.println(ioe.getMessage());
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/resources/streamline.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | StreamLine Brainstorming Rickard and Michael
4 |
5 |
6 | StreamLine Brainstorming Rickard and Michael
7 |
8 | Basic Building Blocks
9 |
10 |
11 | We use a nodespaces of semistructured data to represent each item contained in the application as a
12 | changelog of Quadruples (4 Dimensions) of Person, Location
13 | , Time and Content.
14 | This Quadruple is called Change.
15 |
16 |
17 |
18 | The number of changes that forms a document or communication is called ChangeLog/Stream/ChangeStream/ChangeTree.
19 | In its simplest form it contains only a single entry. A linear thread of changes forms a stream. Whereas a realistic
20 | representation forms a tree originating at the starting root entry and branching off as parallel versions are
21 | created. If versions are merged again this tree evolves to a graph or network of changes. Each change within a
22 | stream must be additionally identified by a version number.
23 | Each change also has a direct relationship to the node representing the whole stream which also contains the
24 | properties
25 | and relationships that are valid (and immutable) for the whole stream.
26 |
27 |
28 |
29 | The person making the change is perhaps not directly connected to the change but rather as
30 | contributor
31 | containing a link to the person and a second to a role in which the contribution was made. Its also possible that
32 | multiple persons made a change at the same time. The location of these persons then would also be attached rather
33 | to the contributor node than to the change node.
34 |
35 |
36 |
37 | The core of the framework is a very fast store for Changes which maintains a HEAD revision. Filtering,
38 | querying the store for different projections of the stream.
39 |
40 |
41 |
42 | All changes in the system form a cloud in the named four dimensions which can be filtered, queried, projected and
43 | represented according to the requirements of the usecase. The perspectives and views choosen to represent the
44 | projected change are also not restricted.
45 |
46 |
47 | Using a REST based approach which separates internal models from the
48 | external representations that are made available to the clients allows a multitude of representations without
49 | coupling these to the internal handling of the model. So for instance displaying a document as mindmap,
50 | text-processor document or version history is just a question of the choosen representations.
51 | Representations could also include highly interactive and visual approaches. See Parallax Freebase for massive
52 | interactive querying and the Vimeo Code Swarm Visualization for SVN repository histories.
53 |
54 |
55 |
56 | The basic approach should be considered as similar to a distributed source control management system (like git or
57 | mercurial). For offline work local copies of the repository with all the functionality must be available.
58 | Individuals
59 | have the responsibility and possibility of deciding which of their locally stored change-set are published to
60 | the public stores or other personal stores. Change identification doesn't rely on files and their attributes but
61 | rather on internal representations (kind of hashes) of the documents edited.
62 |
63 |
64 |
65 | Another idea regarding the processing of changes is the application of tree and graph theory also for applying and
66 | merging changes. Transforming content and changes into parsed tree representations (AST) allows a much more easy
67 | merging that with current text only based diff tools. (See refactoring on the AST/PSI in IntelliJ)
68 | But even then generating, applying and merging the changes is the main challenge of this kind of
69 | application.
70 |
71 |
72 |
73 | Graph based approaches allow us to store semi-structured data. Therefore no two data sets stored in the node
74 | space must be of equal structure. For keeping type information and other aggregating structures we can use
75 | specialized
76 | type nodes which hold connections to all nodes of a certain type. With the relationship based approach to typing
77 | multiple typing is very easy and attaching additional information on the type itself is also provided.
78 | Concrete nodes and their types form spheres of interest which can be easily accessed by traversing the nodespace
79 | either
80 | inside out from the change or outside in from the type nodes.
81 |
82 | Graph databases allow us fast retrieval and traversal of large structures. Supporting functionality for searching
83 | and filtering comes from full text retrieval systems /indexers like lucene.
84 | All access to the graph database is fully transactional so that multithreaded access poses no problem.
85 | As our data structures will be so simple a tuple space based solution for scaling is also possible (e.g. GigaSpaces,
86 | Coherence).
87 |
88 |
89 |
90 | The change will rely on an universal id at the center. All other data is added in addional layers. First core state
91 | and types and then the data, types and behaviour that come with the patterns/principles (implemented by
92 | concerns and sideeffects of the application domain).
93 |
94 |
95 | Basic associated Node Types of a Change
96 |
97 |
98 | Person
99 | Attributes
100 |
101 | - Name
102 | - Portrait
103 | - openId
104 | - public key
105 |
106 | Relationships
107 |
112 |
113 |
114 | Location
115 |
116 |
117 | Location is the place where the change was made. Can be derived using GPS, IP-Lookup, WLAN-Lookup, Mobile-Tracing
118 | whatever.
119 |
120 |
121 | Attributes
122 |
123 | - gps coordinates
124 | - address - perhaps rather node than attribute
125 |
126 | Relationships
127 |
128 | - other nodes regarding locality: city, country, addresses
129 |
130 |
131 |
132 | Time
133 |
134 |
135 | Time is represented as (second) nodes in the nodespace. Only the time nodes that are actually needed by the changes
136 | are created.
137 |
138 | Time nodes form a node hierarchy.
139 |
140 | - Second
141 | - Minute
142 | - Hour
143 | - day of month
144 | - month
145 | - year
146 | - epoch
147 |
148 | Attributes
149 |
150 | - actual timestamp in gmt
151 |
152 | Relationships
153 |
154 | - parent time hierarchy nodes
155 | - incoming: nodes that occur at this timestamp
156 |
157 |
158 |
159 |
160 | Content
161 |
162 |
163 | Content is the data that was produced at this timestamp by this person at this location. It is normally
164 | a part of a larger stream of content (diffs) that form documents or communication.
165 | The content is stored as a log and at the same time a HEAD revision is maintainted as the current representation
166 | of the accumulated changes.
167 |
168 | Immutability and Security
169 |
170 |
171 | Content is immutable and may be digitally signed (using the public key of the associated person and can be encrypted
172 | if needed.
173 |
174 | Attributes
175 |
176 | - metadata
177 | - size
178 | - mime type
179 |
180 | Relationships
181 |
182 | - time
183 | - person
184 | - location
185 | - tag
186 | - document/communication/
187 |
188 |
189 | Values, Principles and Patterns/Practices
190 |
191 |
192 | A system of values is the basis for every domain. Derived from that are principles
193 | that are the general rules of effective work in this domain. The concrete, applicable practices and
194 | patterns are developed based on these principles in a certain context with individual forces that must be
195 | balanced to achieve the desired outcome.
196 | (Design-)Patterns describe roles and relationships. The same goes for concerns of an application domain (e.g.
197 | workflow).
198 | So what we want to do ist to explore the value system of the targeted application domain and look for existing
199 | principles and patterns and apply them as concerns and sideeffects to our existing basic framework. Each concern
200 | might bring along further behaviour and/or data that is added to the basic entities.
201 | When concerns change, the data does not go away but rather stays available
202 | - Model Change does not require instance change
203 |
204 | Literature
205 |
206 | - Christopher Alexander - A Timeless Way of Building
207 | - Kevlin Henney et al - Patterns of Software Architecture 5
208 | - Kent Beck - eXtreme Programming - Explained
209 |
210 |
211 | Applications on top
212 |
213 | Potential Applications
214 |
215 | Workflow Management - StreamFlow
216 |
217 | Workflow Management is a important issue in governental institutions and companies. Existing
218 | solutions are not sufficient and much to complex. A simpler and more flexible approach is needed that is able to
219 | include
220 |
221 | Intented Features
222 |
223 | - Immutable Change Log at the core
224 | - Multitude of representations
225 | - Fast retrieval and querying
226 | - Fast handling of merges, projections
227 | - Easy extension with concerns and sideeffects derived from the best working practices of the domain
228 |
for instance
229 | - Signing, Encryption with PKI
230 | - Roles and role based ACLs
231 |
232 |
233 |
234 | Previous thingking about workflow (partially outdated)
235 | what belongs to a task
236 |
237 | - Content and its Content-Types
238 | - Task as basic data
239 | - People
240 | - Communication
241 | - Type
242 | - Metadata
243 | - Attributes
244 | - Relationships
245 |
246 |
247 | Software Development - StreamSource
248 |
249 | We want to use the software as dogfood / bootstrapping application for its own distributed
250 | development. So that we get annoyed by incomplete, inconsitent, unusable features and will fix them.
251 |
252 |
253 | - Source Code Management
254 | - Agile Methodologies
255 |
256 | - Backlog
257 | - Communication
258 | - Estimation
259 | - Planning
260 | - ...
261 |
262 |
263 | - Task / Issue Management
264 | - Analysis
265 |
266 |
267 |
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/analyser/codecity/Gears.java.save:
--------------------------------------------------------------------------------
1 | package org.neo4j.datasource.java;
2 |
3 |
4 | import com.sun.opengl.util.Animator;
5 |
6 | import javax.media.opengl.*;
7 | import java.awt.*;
8 | import java.awt.event.*;
9 |
10 | /**
11 | * Gears.java
12 | * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel)
13 | *
14 | * This version is equal to Brian Paul's version 1.2 1999/10/21
15 | */
16 |
17 | public class Gears implements GLEventListener, MouseListener, MouseMotionListener {
18 | public static void main(String[] args) {
19 | Frame frame = new Frame("Gear Demo");
20 | GLCanvas canvas = new GLCanvas();
21 |
22 | canvas.addGLEventListener(new Gears());
23 | frame.add(canvas);
24 | frame.setSize(300, 300);
25 | final Animator animator = new Animator(canvas);
26 | frame.addWindowListener(new WindowAdapter() {
27 | public void windowClosing(WindowEvent e) {
28 | // Run this on another thread than the AWT event queue to
29 | // make sure the call to Animator.stop() completes before
30 | // exiting
31 | new Thread(new Runnable() {
32 | public void run() {
33 | animator.stop();
34 | System.exit(0);
35 | }
36 | }).start();
37 | }
38 | });
39 | frame.show();
40 | animator.start();
41 | }
42 |
43 | private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f;
44 | private int gear1, gear2, gear3;
45 | private float angle = 0.0f;
46 |
47 | private int prevMouseX, prevMouseY;
48 | private boolean mouseRButtonDown = false;
49 |
50 | public void init(GLAutoDrawable drawable) {
51 | // Use debug pipeline
52 | // drawable.setGL(new DebugGL(drawable.getGL()));
53 |
54 | GL gl = drawable.getGL();
55 |
56 | System.err.println("INIT GL IS: " + gl.getClass().getName());
57 |
58 | System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities());
59 |
60 | gl.setSwapInterval(1);
61 |
62 | float pos[] = {5.0f, 5.0f, 10.0f, 0.0f};
63 | float red[] = {0.8f, 0.1f, 0.0f, 1.0f};
64 | float green[] = {0.0f, 0.8f, 0.2f, 1.0f};
65 | float blue[] = {0.2f, 0.2f, 1.0f, 1.0f};
66 |
67 | gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos, 0);
68 | gl.glEnable(GL.GL_CULL_FACE);
69 | gl.glEnable(GL.GL_LIGHTING);
70 | gl.glEnable(GL.GL_LIGHT0);
71 | gl.glEnable(GL.GL_DEPTH_TEST);
72 |
73 | /* make the gears */
74 | gear1 = gl.glGenLists(1);
75 | gl.glNewList(gear1, GL.GL_COMPILE);
76 | gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, red, 0);
77 | gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f);
78 | gl.glEndList();
79 |
80 | gear2 = gl.glGenLists(1);
81 | gl.glNewList(gear2, GL.GL_COMPILE);
82 | gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, green, 0);
83 | gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f);
84 | gl.glEndList();
85 |
86 | gear3 = gl.glGenLists(1);
87 | gl.glNewList(gear3, GL.GL_COMPILE);
88 | gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, blue, 0);
89 | gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f);
90 | gl.glEndList();
91 |
92 | gl.glEnable(GL.GL_NORMALIZE);
93 |
94 | drawable.addMouseListener(this);
95 | drawable.addMouseMotionListener(this);
96 | }
97 |
98 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
99 | GL gl = drawable.getGL();
100 |
101 | float h = (float) height / (float) width;
102 |
103 | gl.glMatrixMode(GL.GL_PROJECTION);
104 |
105 | System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR));
106 | System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER));
107 | System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION));
108 | gl.glLoadIdentity();
109 | gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
110 | gl.glMatrixMode(GL.GL_MODELVIEW);
111 | gl.glLoadIdentity();
112 | gl.glTranslatef(0.0f, 0.0f, -40.0f);
113 | }
114 |
115 | public void display(GLAutoDrawable drawable) {
116 | // Turn the gears' teeth
117 | angle += 2.0f;
118 |
119 | // Get the GL corresponding to the drawable we are animating
120 | GL gl = drawable.getGL();
121 |
122 | // Special handling for the case where the GLJPanel is translucent
123 | // and wants to be composited with other Java 2D content
124 | if ((drawable instanceof GLJPanel) &&
125 | !((GLJPanel) drawable).isOpaque() &&
126 | ((GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) {
127 | gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
128 | } else {
129 | gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
130 | }
131 |
132 | // Rotate the entire assembly of gears based on how the user
133 | // dragged the mouse around
134 | gl.glPushMatrix();
135 | gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
136 | gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
137 | gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
138 |
139 | // Place the first gear and call its display list
140 | gl.glPushMatrix();
141 | gl.glTranslatef(-3.0f, -2.0f, 0.0f);
142 | gl.glRotatef(angle, 0.0f, 0.0f, 1.0f);
143 | gl.glCallList(gear1);
144 | gl.glPopMatrix();
145 |
146 | // Place the second gear and call its display list
147 | gl.glPushMatrix();
148 | gl.glTranslatef(3.1f, -2.0f, 0.0f);
149 | gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
150 | gl.glCallList(gear2);
151 | gl.glPopMatrix();
152 |
153 | // Place the third gear and call its display list
154 | gl.glPushMatrix();
155 | gl.glTranslatef(-3.1f, 4.2f, 0.0f);
156 | gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
157 | gl.glCallList(gear3);
158 | gl.glPopMatrix();
159 |
160 | // Remember that every push needs a pop; this one is paired with
161 | // rotating the entire gear assembly
162 | gl.glPopMatrix();
163 | }
164 |
165 | public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
166 | }
167 |
168 | public static void gear(GL gl,
169 | float inner_radius,
170 | float outer_radius,
171 | float width,
172 | int teeth,
173 | float tooth_depth) {
174 | int i;
175 | float r0, r1, r2;
176 | float angle, da;
177 | float u, v, len;
178 |
179 | r0 = inner_radius;
180 | r1 = outer_radius - tooth_depth / 2.0f;
181 | r2 = outer_radius + tooth_depth / 2.0f;
182 |
183 | da = 2.0f * (float) Math.PI / teeth / 4.0f;
184 |
185 | gl.glShadeModel(GL.GL_FLAT);
186 |
187 | gl.glNormal3f(0.0f, 0.0f, 1.0f);
188 |
189 | /* draw front face */
190 | gl.glBegin(GL.GL_QUAD_STRIP);
191 | for (i = 0; i <= teeth; i++) {
192 | angle = i * 2.0f * (float) Math.PI / teeth;
193 | gl.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
194 | gl.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
195 | if (i < teeth) {
196 | gl.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
197 | gl.glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da), width * 0.5f);
198 | }
199 | }
200 | gl.glEnd();
201 |
202 | /* draw front sides of teeth */
203 | gl.glBegin(GL.GL_QUADS);
204 | for (i = 0; i < teeth; i++) {
205 | angle = i * 2.0f * (float) Math.PI / teeth;
206 | gl.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
207 | gl.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
208 | gl.glVertex3f(r2 * (float) Math.cos(angle + 2.0f * da), r2 * (float) Math.sin(angle + 2.0f * da), width * 0.5f);
209 | gl.glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da), width * 0.5f);
210 | }
211 | gl.glEnd();
212 |
213 | /* draw back face */
214 | gl.glBegin(GL.GL_QUAD_STRIP);
215 | for (i = 0; i <= teeth; i++) {
216 | angle = i * 2.0f * (float) Math.PI / teeth;
217 | gl.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
218 | gl.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
219 | gl.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
220 | gl.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
221 | }
222 | gl.glEnd();
223 |
224 | /* draw back sides of teeth */
225 | gl.glBegin(GL.GL_QUADS);
226 | for (i = 0; i < teeth; i++) {
227 | angle = i * 2.0f * (float) Math.PI / teeth;
228 | gl.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
229 | gl.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f);
230 | gl.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
231 | gl.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
232 | }
233 | gl.glEnd();
234 |
235 | /* draw outward faces of teeth */
236 | gl.glBegin(GL.GL_QUAD_STRIP);
237 | for (i = 0; i < teeth; i++) {
238 | angle = i * 2.0f * (float) Math.PI / teeth;
239 | gl.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
240 | gl.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
241 | u = r2 * (float) Math.cos(angle + da) - r1 * (float) Math.cos(angle);
242 | v = r2 * (float) Math.sin(angle + da) - r1 * (float) Math.sin(angle);
243 | len = (float) Math.sqrt(u * u + v * v);
244 | u /= len;
245 | v /= len;
246 | gl.glNormal3f(v, -u, 0.0f);
247 | gl.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
248 | gl.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
249 | gl.glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
250 | gl.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), width * 0.5f);
251 | gl.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f);
252 | u = r1 * (float) Math.cos(angle + 3 * da) - r2 * (float) Math.cos(angle + 2 * da);
253 | v = r1 * (float) Math.sin(angle + 3 * da) - r2 * (float) Math.sin(angle + 2 * da);
254 | gl.glNormal3f(v, -u, 0.0f);
255 | gl.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), width * 0.5f);
256 | gl.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
257 | gl.glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
258 | }
259 | gl.glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), width * 0.5f);
260 | gl.glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), -width * 0.5f);
261 | gl.glEnd();
262 |
263 | gl.glShadeModel(GL.GL_SMOOTH);
264 |
265 | /* draw inside radius cylinder */
266 | gl.glBegin(GL.GL_QUAD_STRIP);
267 | for (i = 0; i <= teeth; i++) {
268 | angle = i * 2.0f * (float) Math.PI / teeth;
269 | gl.glNormal3f(-(float) Math.cos(angle), -(float) Math.sin(angle), 0.0f);
270 | gl.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
271 | gl.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
272 | }
273 | gl.glEnd();
274 | }
275 |
276 | // Methods required for the implementation of MouseListener
277 | public void mouseEntered(MouseEvent e) {
278 | }
279 |
280 | public void mouseExited(MouseEvent e) {
281 | }
282 |
283 | public void mousePressed(MouseEvent e) {
284 | prevMouseX = e.getX();
285 | prevMouseY = e.getY();
286 | if ((e.getModifiers() & e.BUTTON3_MASK) != 0) {
287 | mouseRButtonDown = true;
288 | }
289 | }
290 |
291 | public void mouseReleased(MouseEvent e) {
292 | if ((e.getModifiers() & e.BUTTON3_MASK) != 0) {
293 | mouseRButtonDown = false;
294 | }
295 | }
296 |
297 | public void mouseClicked(MouseEvent e) {
298 | }
299 |
300 | // Methods required for the implementation of MouseMotionListener
301 | public void mouseDragged(MouseEvent e) {
302 | int x = e.getX();
303 | int y = e.getY();
304 | Dimension size = e.getComponent().getSize();
305 |
306 | float thetaY = 360.0f * ((float) (x - prevMouseX) / (float) size.width);
307 | float thetaX = 360.0f * ((float) (prevMouseY - y) / (float) size.height);
308 |
309 | prevMouseX = x;
310 | prevMouseY = y;
311 |
312 | view_rotx += thetaX;
313 | view_roty += thetaY;
314 | }
315 |
316 | public void mouseMoved(MouseEvent e) {
317 | }
318 | }
319 |
320 |
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/analyser/codecity/HelloWorldDemo.java.save:
--------------------------------------------------------------------------------
1 | package org.neo4j.datasource.java;
2 |
3 | // External imports
4 |
5 | import javax.media.opengl.*;
6 | import java.awt.*;
7 |
8 | // Local imports
9 | // None
10 |
11 | /**
12 | * Example application that demonstrates how to put together a single-threaded
13 | * rendering system.
14 | *
15 | * @author Justin Couch
16 | * @version $Revision: 1.5 $
17 | */
18 | public class HelloWorldDemo extends Frame
19 | implements GLEventListener {
20 | public HelloWorldDemo() {
21 | super("Basic JOGL Demo");
22 |
23 | setLayout(new BorderLayout());
24 |
25 | setSize(400, 400);
26 | setLocation(40, 40);
27 |
28 | // Need to set visible first before starting the rendering thread due
29 | // to a bug in JOGL. See JOGL Issue #54 for more information on this.
30 | // http://jogl.dev.java.net
31 | setVisible(true);
32 |
33 | setupJOGL();
34 | }
35 |
36 | //---------------------------------------------------------------
37 | // Methods defined by GLEventListener
38 | //---------------------------------------------------------------
39 |
40 | /**
41 | * Called by the drawable immediately after the OpenGL context is
42 | * initialized; the GLContext has already been made current when
43 | * this method is called.
44 | *
45 | * @param drawable The display context to render to
46 | */
47 | public void init(GLAutoDrawable drawable) {
48 | GL gl = drawable.getGL();
49 |
50 | gl.glClearColor(0, 0, 0, 0);
51 | gl.glMatrixMode(GL.GL_PROJECTION);
52 |
53 | gl.glLoadIdentity();
54 | gl.glFrustum(-20.0f, 20.0f, -20f, 20, 0f, 30.0f);
55 |
56 | gl.glRotatef(20f, 1.0f, 0.0f, 0.0f);
57 | gl.glRotatef(180f, 0.0f, 1.0f, 0.0f);
58 | gl.glRotatef(20f, 0.0f, 0.0f, 1.0f);
59 |
60 | // gl.glOrtho(-1, 1, -1, 1, -1, 1);
61 | }
62 |
63 | /**
64 | * Called by the drawable when the surface resizes itself. Used to
65 | * reset the viewport dimensions.
66 | *
67 | * @param drawable The display context to render to
68 | */
69 | public void reshape(GLAutoDrawable drawable,
70 | int x,
71 | int y,
72 | int width,
73 | int height) {
74 | }
75 |
76 | /**
77 | * Called by the drawable when the display mode or the display device
78 | * associated with the GLDrawable has changed
79 | */
80 | public void displayChanged(GLAutoDrawable drawable,
81 | boolean modeChanged,
82 | boolean deviceChanged) {
83 | }
84 |
85 | /**
86 | * Called by the drawable to perform rendering by the client.
87 | *
88 | * @param drawable The display context to render to
89 | */
90 | public void display(GLAutoDrawable drawable) {
91 | GL gl = drawable.getGL();
92 |
93 | gl.glClear(GL.GL_COLOR_BUFFER_BIT);
94 | drawTriangle(gl);
95 |
96 | gl.glColor3f(1, 0, 0);
97 | drawCube(gl,0,0,0, .2f, .2f);
98 |
99 | gl.glColor3f(0, 1, 0);
100 | drawCube(gl,0,1,0, .5f, .01f);
101 |
102 | gl.glColor3f(0, 0, 1);
103 | drawCube(gl,0,-1,0, .1f, .5f);
104 |
105 | gl.glColor3f(0, 1, 1);
106 | drawCube(gl,0.5f,-0.5f,0, .2f, .2f);
107 |
108 | gl.glFlush();
109 | }
110 |
111 | private void drawTriangle(final GL gl) {
112 | gl.glBegin(GL.GL_TRIANGLES);
113 |
114 | gl.glColor3f(1, 0, 0);
115 | gl.glVertex3f(0.25f, 0.25f, 0);
116 |
117 | gl.glColor3f(0, 1, 0);
118 | gl.glVertex3f(0.5f, 0.25f, 0);
119 |
120 | gl.glColor3f(0, 0, 1);
121 | gl.glVertex3f(0.25f, 0.5f, 0);
122 |
123 | gl.glEnd();
124 | }
125 |
126 | private void drawCube(GL gl, float x, float y, float z, float width,float height) {
127 | gl.glBegin(GL.GL_QUADS);
128 | final float x1 = x - width;
129 | final float y2 = y + width;
130 | final float y1 = y - width;
131 | final float x2 = x + width;
132 | drawCube(gl, x1, y1, z, x2, y2, z+height);
133 | gl.glEnd();
134 | }
135 |
136 |
137 | private void drawCube(final GL gl, final float x1, final float y1, final float z1, final float x2, final float y2, final float z2) {
138 | gl.glVertex3d(x1, y1, z1);
139 | gl.glVertex3d(x2, y1, z1);
140 | gl.glVertex3d(x2, y2, z1);
141 | gl.glVertex3d(x1, y2, z1);
142 |
143 | gl.glVertex3d(x1, y1, z2);
144 | gl.glVertex3d(x2, y1, z2);
145 | gl.glVertex3d(x2, y2, z2);
146 | gl.glVertex3d(x1, y2, z2);
147 |
148 | gl.glVertex3d(x1, y1, z1);
149 | gl.glVertex3d(x2, y1, z1);
150 | gl.glVertex3d(x2, y1, z2);
151 | gl.glVertex3d(x1, y1, z2);
152 |
153 | gl.glVertex3d(x1, y2, z1);
154 | gl.glVertex3d(x2, y2, z1);
155 | gl.glVertex3d(x2, y2, z2);
156 | gl.glVertex3d(x1, y2, z2);
157 |
158 | gl.glVertex3d(x1, y1, z1);
159 | gl.glVertex3d(x1, y2, z1);
160 | gl.glVertex3d(x1, y2, z2);
161 | gl.glVertex3d(x1, y1, z2);
162 |
163 | gl.glVertex3d(x2, y1, z1);
164 | gl.glVertex3d(x2, y2, z1);
165 | gl.glVertex3d(x2, y2, z2);
166 | gl.glVertex3d(x2, y1, z2);
167 | }
168 | //---------------------------------------------------------------
169 | // Local methods
170 | //---------------------------------------------------------------
171 |
172 | /**
173 | * Create the basics of the JOGL screen details.
174 | */
175 | private void setupJOGL() {
176 | GLCapabilities caps = new GLCapabilities();
177 | caps.setDoubleBuffered(true);
178 | caps.setHardwareAccelerated(true);
179 |
180 | GLCanvas canvas = new GLCanvas(caps);
181 | canvas.addGLEventListener(this);
182 |
183 | add(canvas, BorderLayout.CENTER);
184 |
185 | // Animator anim = new Animator(canvas);
186 | // anim.start();
187 | }
188 |
189 | public static void main(String[] args) {
190 | HelloWorldDemo demo = new HelloWorldDemo();
191 | demo.setVisible(true);
192 | }
193 | }
194 |
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/analyser/codecity/JoglFrame.java.save:
--------------------------------------------------------------------------------
1 | package org.neo4j.datasource.java;
2 |
3 | import javax.media.opengl.GLCapabilities;
4 | import javax.media.opengl.GLJPanel;
5 |
6 | public class JoglFrame extends GLJPanel {
7 |
8 | public JoglFrame() {
9 | super(createCaps());
10 | }
11 |
12 | private static GLCapabilities createCaps() {
13 | GLCapabilities caps = new GLCapabilities();
14 | caps.setAlphaBits(8);
15 | return caps;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/analyser/codecity/JoglTest.java.save:
--------------------------------------------------------------------------------
1 | package org.neo4j.datasource.java;
2 |
3 | import org.junit.Test;
4 |
5 | public class JoglTest {
6 | @Test
7 | public void testJogl() {
8 | new JoglFrame().show();
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/analyser/codecity/MooseWriter.java:
--------------------------------------------------------------------------------
1 | package org.neo4j.analyser.codecity;
2 |
3 | import org.neo4j.datasource.java.analyser.ClassFileIterator;
4 | import org.neo4j.datasource.java.analyser.RecordingInspector;
5 | import org.neo4j.datasource.java.declaration.ClassDeclaration;
6 | import org.neo4j.datasource.java.declaration.PackageDeclaration;
7 | import org.neo4j.datasource.java.declaration.bean.PackageDeclarationBean;
8 |
9 | import java.io.*;
10 | import static java.lang.System.currentTimeMillis;
11 | import java.util.*;
12 |
13 | /**
14 | * @author Michael Hunger
15 | * @since 07.10.2009
16 | */
17 | public class MooseWriter {
18 | private final Map classes;
19 | private Set namespaces;
20 | private Collection aPackages;
21 | private int index;
22 |
23 | public MooseWriter(final Map classes) {
24 | this.classes = classes;
25 | index = classes.size() + 2;
26 | System.out.println("max.class.idx = " + index);
27 | this.namespaces = extractNamespaces(classes, index);
28 | index += namespaces.size()+1;
29 | System.out.println("max.ns.idx = " + index);
30 | this.aPackages = extractPackages(namespaces, index);
31 | index += aPackages.size()+1;
32 | System.out.println("max.pkg.idx = " + index);
33 | }
34 |
35 | private Collection extractPackages(Collection namespaces, int startIdx) {
36 | Collection result=new HashSet(namespaces.size());
37 | for (PackageDeclaration namespace : namespaces) {
38 | PackageDeclaration packageDeclaration = new PackageDeclarationBean(namespace.getName(), startIdx++);
39 | result.add(packageDeclaration);
40 | while (!packageDeclaration.isRoot()) {
41 | final PackageDeclaration superPackage = new PackageDeclarationBean(packageDeclaration.getSuperPackage(), startIdx);
42 | if (!result.contains(superPackage)) {
43 | result.add(superPackage);
44 | startIdx++;
45 | }
46 | packageDeclaration =superPackage;
47 | }
48 | }
49 | return result;
50 | }
51 |
52 | private Set extractNamespaces(final Map classes, int startIdx) {
53 | final Set result = new HashSet();
54 | for (final ClassDeclaration declaration : classes.values()) {
55 | final PackageDeclarationBean packageInfo = new PackageDeclarationBean(declaration.getPackage(), startIdx);
56 | if (!result.contains(packageInfo)) {
57 | result.add(packageInfo);
58 | startIdx++;
59 | }
60 | }
61 | return result;
62 | }
63 |
64 | public static void main(final String[] args) throws Exception {
65 | final String file = args[0];
66 | final Class> type = args.length > 1 ? Class.forName(args[1]) : Object.class;
67 | long time= currentTimeMillis();
68 | final Map classes = new ClassParser().loadClasses(type);
69 | time= currentTimeMillis()-time;
70 | System.out.println("reading took " + time+" ms");
71 | time= currentTimeMillis();
72 | new MooseWriter(classes).writeFile(file);
73 | time= currentTimeMillis()-time;
74 | System.out.println("\nwriting took " + time+" ms");
75 | }
76 |
77 | private void writeFile(final String file) {
78 | try {
79 | final Writer os = new BufferedWriter(new FileWriter(file));
80 | writeHeader(os);
81 | writePackages(os);
82 | writeClasses(os,index);
83 | writeFooter(os);
84 | os.close();
85 | } catch (IOException ioe) {
86 | throw new RuntimeException(ioe);
87 | }
88 | }
89 |
90 | private void writeClasses(Writer os, int index) throws IOException {
91 | System.out.println("\nWriting classes");
92 | for (ClassDeclaration declaration : classes.values()) {
93 | os.write("\t\t(FAMIX.Class (id: "+ declaration.getId()+")\n" +
94 | "\t\t\t(name '"+ declaration.getSimpleName()+"')\n" +
95 | "\t\t\t(belongsTo (idref: "+getPackageId(namespaces, declaration.getPackage())+"))\n" +
96 | "\t\t\t(isAbstract false)\n" +
97 | "\t\t\t(isInterface false)\n" +
98 | "\t\t\t(packagedIn (idref: "+getPackageId(aPackages, declaration.getPackage())+")))\n");
99 | if (!declaration.isRoot()) {
100 | os.write("\t\t(FAMIX.InheritanceDefinition (id: "+(index++)+")\n" +
101 | "\t\t\t(subclass (idref: "+ declaration.getId()+"))\n" +
102 | "\t\t\t(superclass (idref: "+ declaration.getSuperClass().getId() +")))\n");
103 | }
104 | }
105 | }
106 |
107 | private int getPackageId(Collection aPackages, String pkgName) {
108 | for (PackageDeclaration namespace : aPackages) {
109 | if (namespace.getName().equals(pkgName)) return namespace.getId();
110 | }
111 | throw new IllegalArgumentException("Unknown package "+pkgName);
112 | }
113 |
114 | private void writePackages(Writer os) throws IOException {
115 | System.out.println("\nWriting namespaces");
116 | for (PackageDeclaration declaration : namespaces) {
117 | os.write("\t\t(FAMIX.Namespace (id: "+ declaration.getId()+")\n" +
118 | "\t\t\t(name '"+toMoose(declaration.getName())+"'))\n");
119 | }
120 | System.out.println("\nWriting packages");
121 | for (PackageDeclaration aPackage : aPackages) {
122 | os.write("\t\t(FAMIX.Package (id: "+aPackage.getId()+")\n" +
123 | "\t\t\t(name '"+toMoose(aPackage.getName())+"')\n" +
124 | "\t\t\t(DIH "+dih(aPackage)+")\n" +
125 | (aPackage.isRoot() ? "" : "\t\t\t(packagedIn (idref: "+getPackageId(aPackages,aPackage.getSuperPackage())+"))")
126 | +")\n");
127 | }
128 | }
129 |
130 | private int dih(PackageDeclaration aPackage) {
131 | return aPackage.getName().split("\\.").length;
132 | }
133 |
134 | private String toMoose(String pkg) {
135 | return pkg.replaceAll("/","::");
136 | }
137 |
138 | private void writeFooter(Writer os) throws IOException {
139 | os.write(")\n" +
140 | "\t(LOC 1000)\n" +
141 | "\t(NOC "+classes.size()+")\n" +
142 | "\t(NOP "+ namespaces.size()+")\n" +
143 | "\t(sourceLanguage 'Java'))\n");
144 | }
145 |
146 | private void writeHeader(Writer os) throws IOException {
147 | os.write("(Moose.Model (id: 1)\n" +
148 | "\t(name 'test')\n" +
149 | "\t(entity");
150 | }
151 |
152 | static class ClassParser {
153 | public Map loadClasses(final Class> type) {
154 | final RecordingInspector inspector = new RecordingInspector();
155 | final ClassFileIterator fileIterator = new ClassFileIterator();
156 | final String jarFileLocation = fileIterator.getJarLocationByClass(type);
157 | for (final String classFileName : fileIterator.getClassFileNames(jarFileLocation)) {
158 | inspector.inspectClass(classFileName);
159 | }
160 | return inspector.getClasses();
161 | }
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/api/core/NeoFileSystemTest.java:
--------------------------------------------------------------------------------
1 | package org.neo4j.api.core;
2 |
3 | import org.junit.After;
4 | import org.junit.Before;
5 | import org.junit.Ignore;
6 | import org.junit.Test;
7 | import org.neo4j.data.file.FileHandler;
8 | import org.neo4j.data.file.FileSystemVisitor;
9 | import org.neo4j.graphdb.*;
10 | import org.neo4j.kernel.EmbeddedGraphDatabase;
11 |
12 | import java.io.File;
13 | import java.util.Collection;
14 | import java.util.Stack;
15 |
16 | import static org.junit.Assert.assertEquals;
17 | import static org.neo4j.test.NeoTestHelper.dropNeoDb;
18 |
19 | public class NeoFileSystemTest {
20 | private GraphDatabaseService neo;
21 | private static final String BASE_DIR = "src";
22 | private static final File START_FILE = new File(BASE_DIR);
23 | private static final String NEODB = "neodb";
24 | private static final String SIZE = "size";
25 | private static final String NAME = "name";
26 |
27 | @Before
28 | public void setUp() {
29 | dropNeoDb(NEODB);
30 | }
31 |
32 | @Test
33 | public void testNoopFileSystem() {
34 | final File startDir = new File(BASE_DIR);
35 | long time = System.currentTimeMillis();
36 | final FileSystemVisitor fileSystemVisitor = new FileSystemVisitor(new FileHandler() {
37 | public void handle(final File file) {
38 | final String name = file.getName();
39 | final long length = file.length();
40 | }
41 |
42 | public void upTo(final File file) {
43 | }
44 | }, startDir);
45 | time = System.currentTimeMillis() - time;
46 | System.out.println("time = " + time + " ms.");
47 | System.out.println("fileSystemVisitor = " + fileSystemVisitor.getCount());
48 | }
49 |
50 |
51 | @Test
52 | public void testFileSystem() {
53 | neo = new EmbeddedGraphDatabase(NEODB);
54 | long time = System.currentTimeMillis();
55 | final FileSystemVisitor fileSystemVisitor = readFileSystem(START_FILE, neo);
56 | time = System.currentTimeMillis() - time;
57 | System.out.println("time = " + time + " ms.");
58 | System.out.println("fileSystemVisitor = " + fileSystemVisitor.getCount());
59 | }
60 |
61 | @Test
62 | @Ignore
63 | public void testTimeFileSystem() {
64 | neo = new EmbeddedGraphDatabase(NEODB);
65 | long time = System.currentTimeMillis();
66 | final FileHandler fileHandler = new FileNodeCreator2(neo);
67 | final FileSystemVisitor fileSystemVisitor = new FileSystemVisitor(fileHandler, new File("/Users/mh/java/neo"));
68 | fileHandler.finish();
69 | time = System.currentTimeMillis() - time;
70 | System.out.println("time = " + time + " ms.");
71 | System.out.println("fileSystemVisitor = " + fileSystemVisitor.getCount());
72 | }
73 |
74 | private FileSystemVisitor readFileSystem(File startDir, final GraphDatabaseService db) {
75 | final FileNodeCreator fileHandler = new FileNodeCreator(db);
76 | final FileSystemVisitor fileSystemVisitor = new FileSystemVisitor(fileHandler, startDir);
77 | fileHandler.finish();
78 | return fileSystemVisitor;
79 | }
80 |
81 | @After
82 | public void tearDown() {
83 | if (neo != null) {
84 | neo.shutdown();
85 | }
86 | }
87 |
88 | @Test
89 | public void queryFileSystemNodes() {
90 | neo = new EmbeddedGraphDatabase(NEODB);
91 | final FileSystemVisitor fileSystemVisitor = readFileSystem(START_FILE, neo);
92 | System.out.println(fileSystemVisitor.getCount());
93 | final Node node = neo.getReferenceNode();
94 | final Traverser fileSizeTraverser = node.traverse(Traverser.Order.BREADTH_FIRST, StopEvaluator.END_OF_GRAPH, new ReturnableEvaluator() {
95 | public boolean isReturnableNode(final TraversalPosition traversalPosition) {
96 | final Node node = traversalPosition.currentNode();
97 | final Long size = (Long) node.getProperty(SIZE, 0L);
98 | return size > 1000;
99 | }
100 | }, Relation.CHILD, Direction.OUTGOING);
101 |
102 | System.out.println("node = " + node);
103 | final Collection allNodes = fileSizeTraverser.getAllNodes();
104 | assertEquals("27 big files", 27, allNodes.size());
105 | }
106 |
107 | enum Relation implements RelationshipType {
108 | CHILD
109 | }
110 |
111 | private static class FileNodeCreator extends FileHandler {
112 | private final Stack nodes = new Stack();
113 | private final GraphDatabaseService graph;
114 | int count = 0;
115 | private Transaction tx;
116 |
117 | public FileNodeCreator(final GraphDatabaseService graph) {
118 | this.graph = graph;
119 | tx = graph.beginTx();
120 | final Node rootNode = graph.getReferenceNode();
121 | rootNode.setProperty(NAME, BASE_DIR);
122 | rootNode.setProperty(SIZE, 0L);
123 | this.nodes.push(rootNode);
124 | }
125 |
126 | public void handle(final File file) {
127 | final Node node = graph.createNode();
128 | node.setProperty(NAME, file.getName());
129 | node.setProperty(SIZE, file.length());
130 | nodes.peek().createRelationshipTo(node, Relation.CHILD);
131 | if (file.isDirectory()) nodes.push(node);
132 | count++;
133 | if (count % 5000 == 0) {
134 | tx.success();
135 | tx.finish();
136 | tx = graph.beginTx();
137 | System.out.println("commit " + count);
138 | }
139 | }
140 |
141 | public void upTo(final File file) {
142 | nodes.pop();
143 | }
144 |
145 | public void finish() {
146 | tx.success();
147 | tx.finish();
148 | }
149 | }
150 |
151 | private static class FileNodeCreator2 extends FileHandler {
152 | private final Stack nodes = new Stack();
153 | private final GraphDatabaseService graph;
154 | int count = 0;
155 | private Transaction tx;
156 |
157 | public FileNodeCreator2(final GraphDatabaseService graph) {
158 | this.graph = graph;
159 | tx = graph.beginTx();
160 | final Node rootNode = graph.getReferenceNode();
161 | rootNode.setProperty(NAME, BASE_DIR);
162 | this.nodes.push(rootNode);
163 | }
164 |
165 | public void handle(final File file) {
166 | final Node node = graph.createNode();
167 | node.setProperty(NAME, file.getName());
168 | nodes.peek().createRelationshipTo(node, Relation.CHILD);
169 | if (file.isDirectory()) nodes.push(node);
170 | count++;
171 | }
172 |
173 | public void upTo(final File file) {
174 | nodes.pop();
175 | }
176 |
177 | public void finish() {
178 | tx.success();
179 | tx.finish();
180 | }
181 | }
182 | }
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/datasource/java/ClassFileFinderTest.java:
--------------------------------------------------------------------------------
1 | package org.neo4j.datasource.java;
2 |
3 | import junit.framework.TestCase;
4 | import org.junit.Test;
5 | import org.neo4j.datasource.java.analyser.ClassFileIterator;
6 | import org.neo4j.datasource.java.analyser.ClassInspectUtils;
7 |
8 | public class ClassFileFinderTest extends TestCase {
9 | private ClassFileIterator classFileIterator;
10 |
11 | @Test
12 | public void testCreateNames() {
13 | checkFindInJar(classFileIterator.getJarLocationFromClassPath("dt.jar"), "javax/swing/text/JTextComponentBeanInfo");
14 | }
15 | @Test
16 | public void testFindObject() {
17 | final String objectClassFile = "java/lang/Object";
18 | checkFindInJar(classFileIterator.getJarLocationByClass(objectClassFile), objectClassFile);
19 | }
20 | @Test
21 | public void testFindJFrame() {
22 | final String objectClassFile = "javax/swing/JFrame";
23 | checkFindInJar(classFileIterator.getJarLocationByClass(objectClassFile), objectClassFile);
24 | }
25 |
26 | @Test
27 | public void testFindTestCase() {
28 | final String objectClassFile = ClassInspectUtils.toSlashName(getClass());
29 | checkFindInJar(classFileIterator.getJarLocationByClass(objectClassFile), objectClassFile);
30 | }
31 |
32 | private void checkFindInJar(final String jarPath, final String classFile) {
33 | System.out.printf("looking for %s in %s",classFile,jarPath);
34 | boolean classFound = false;
35 | for (String className : classFileIterator.getClassFileNames(jarPath)) {
36 | //System.out.println("classNames = " + className);
37 | if (className.equals(classFile)) classFound = true;
38 | }
39 | assertTrue(classFile + " found in " + jarPath, classFound);
40 | }
41 |
42 | @Test
43 | public void testGetJarLocationByClass() {
44 | assertTrue("found in dt.jar", classFileIterator.getJarLocationByClass("javax/swing/text/JTextComponentBeanInfo").startsWith("/Library/Java/JavaVirtualMachines"));
45 | }
46 |
47 | protected void setUp() throws Exception {
48 | super.setUp();
49 | classFileIterator = new ClassFileIterator();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/datasource/java/ClassFileLocatorTest.java:
--------------------------------------------------------------------------------
1 | package org.neo4j.datasource.java;
2 |
3 | import static org.junit.Assert.*;
4 | import org.junit.Test;
5 | import org.neo4j.datasource.java.analyser.ClassFileLocator;
6 | import org.neo4j.datasource.java.analyser.ClassInspectUtils;
7 |
8 | public class ClassFileLocatorTest {
9 | @Test
10 | public void testPath() {
11 | final ClassFileLocator locator = new ClassFileLocator(System.getProperty("java.class.path"));
12 | assertNotNull("found class " + getClass(), locator.resolveClassName(ClassInspectUtils.toSlashName(getClass())));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/datasource/java/ClassInspectorTest.java:
--------------------------------------------------------------------------------
1 | package org.neo4j.datasource.java;
2 |
3 | import junit.framework.TestCase;
4 | import org.junit.Test;
5 | import org.neo4j.datasource.java.analyser.RecordingInspector;
6 | import org.neo4j.datasource.java.declaration.ClassDeclaration;
7 |
8 | public class ClassInspectorTest extends TestCase {
9 | @Test
10 | public void testInspectObject() {
11 | final ClassDeclaration classDeclaration = new RecordingInspector().inspectClass(String.class);
12 | assertEquals("isObject","java.lang.String", classDeclaration.getName());
13 | System.out.println("classInfo.getMethods() = " + classDeclaration.getMethods().values());
14 | System.out.println("classInfo.getFields() = " + classDeclaration.getFields().values());
15 | assertTrue("concat", classDeclaration.getMethods().containsKey("java.lang.String concat(java.lang.String)"));
16 | assertEquals("java.lang.Object", classDeclaration.getSuperClass().getName());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/datasource/java/ClassTraversalTest.java:
--------------------------------------------------------------------------------
1 | package org.neo4j.datasource.java;
2 |
3 | import org.junit.After;
4 | import org.junit.Before;
5 | import org.junit.Test;
6 | import org.neo4j.datasource.java.analyser.ClassInspectUtils;
7 | import org.neo4j.datasource.java.declaration.neo.ClassRelations;
8 | import org.neo4j.datasource.java.declaration.neo.NeoClassDeclaration;
9 | import org.neo4j.datasource.java.declaration.neo.TypeNodeFinder;
10 | import org.neo4j.graphdb.Direction;
11 | import org.neo4j.graphdb.GraphDatabaseService;
12 | import org.neo4j.graphdb.Node;
13 | import org.neo4j.graphdb.Relationship;
14 | import org.neo4j.graphdb.traversal.TraversalDescription;
15 | import org.neo4j.kernel.EmbeddedGraphDatabase;
16 | import org.neo4j.kernel.Traversal;
17 |
18 | import java.io.Serializable;
19 | import java.util.List;
20 | import java.util.Set;
21 |
22 | import static org.junit.Assert.assertEquals;
23 | import static org.junit.Assert.assertTrue;
24 |
25 | public class ClassTraversalTest {
26 | private static final String SERIALIZABLE = Serializable.class.getName();
27 | private static final String OBJECT = Object.class.getName();
28 | private GraphDatabaseService graph;
29 |
30 | @Test
31 | public void testFindAllSerializableSubclasses() {
32 | final Node serializable = getType(graph, SERIALIZABLE);
33 | final TraversalDescription traversal = Traversal.description().relationships(ClassRelations.INTERFACE_TYPE, Direction.INCOMING);
34 | int count=0;
35 | for (Node node : traversal.traverse(serializable).nodes()) {
36 | count++;
37 | }
38 | assertEquals("subnodes of serializable found", 500, count);
39 | }
40 |
41 | @Test
42 | public void testGetObjectMethods() {
43 | final Node ob = getType(graph, OBJECT);
44 | final Iterable methods = ob.getRelationships(ClassRelations.METHOD_OF, Direction.BOTH);
45 | final Set methodNames = new NeoClassDeclaration(ob).getMethods().keySet();
46 | assertTrue("hashCode", methodNames.contains("int hashCode()"));
47 | }
48 |
49 | private Node getType(final GraphDatabaseService graph, String name) {
50 | name = ClassInspectUtils.toClassName(name);
51 | final TypeNodeFinder nodeFinder = new TypeNodeFinder(graph);
52 | final Node serializable = nodeFinder.getTypeNode(name);
53 | assertEquals(name, serializable.getProperty("name"));
54 | return serializable;
55 | }
56 |
57 | @Before
58 | public void setUp() {
59 | graph = new EmbeddedGraphDatabase("classes.jar.neo.save");
60 | }
61 |
62 | @After
63 | public void tearDown() {
64 | if (graph != null)
65 | graph.shutdown();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/datasource/java/RecordingInspectorNeoTest.java:
--------------------------------------------------------------------------------
1 | package org.neo4j.datasource.java;
2 |
3 | import org.junit.After;
4 | import org.junit.Test;
5 | import org.neo4j.datasource.java.analyser.ClassFileIterator;
6 | import org.neo4j.datasource.java.analyser.RecordingInspector;
7 | import org.neo4j.datasource.java.declaration.ClassDeclaration;
8 | import org.neo4j.datasource.java.declaration.neo.NeoDeclarationFactory;
9 | import org.neo4j.graphdb.GraphDatabaseService;
10 | import org.neo4j.graphdb.Transaction;
11 | import org.neo4j.kernel.EmbeddedGraphDatabase;
12 |
13 | import javax.swing.text.JTextComponentBeanInfo;
14 | import java.io.IOException;
15 |
16 | import static org.junit.Assert.assertEquals;
17 | import static org.junit.Assert.assertTrue;
18 | import static org.neo4j.test.NeoTestHelper.dropNeoDb;
19 |
20 | public class RecordingInspectorNeoTest {
21 | private GraphDatabaseService graph;
22 |
23 | @Test
24 | public void testIterateDtJar() {
25 | final String neoStoreName = "dt.jar.neo";
26 | dropNeoDb(neoStoreName);
27 | graph = new EmbeddedGraphDatabase(neoStoreName);
28 | final Transaction tx = graph.beginTx();
29 | final ClassFileIterator fileIterator = new ClassFileIterator();
30 | final String jarFileLocation = fileIterator.getJarLocationByClass(JTextComponentBeanInfo.class);
31 | final RecordingInspector inspector = new RecordingInspector();
32 | inspector.setDeclarationFactory(new NeoDeclarationFactory(graph));
33 | long count = 0;
34 | for (final String classFileName : fileIterator.getClassFileNames(jarFileLocation)) {
35 | inspector.inspectClass(classFileName);
36 | count++;
37 | }
38 | tx.success();
39 | tx.finish();
40 | assertTrue("Files in dt.jar", count > 40);
41 | }
42 |
43 | @Test
44 | public void testIterateClassesJar() throws IOException {
45 | // /Volumes/ramdisk/
46 | final String neoStoreName = "classes.jar.neo";
47 | Class> type = Object.class;
48 | dropNeoDb(neoStoreName);
49 | graph = new EmbeddedGraphDatabase(neoStoreName);
50 | Transaction tx = graph.beginTx();
51 | final RecordingInspector inspector = new RecordingInspector();
52 | final NeoDeclarationFactory infoFactory = new NeoDeclarationFactory(graph);
53 | inspector.setDeclarationFactory(infoFactory);
54 | long count = 0;
55 | final ClassFileIterator fileIterator = new ClassFileIterator();
56 | final String jarFileLocation = fileIterator.getJarLocationByClass(type);
57 |
58 | long time = System.currentTimeMillis();
59 | for (final String classFileName : fileIterator.getClassFileNames(jarFileLocation)) {
60 | final ClassDeclaration classDeclaration = inspector.inspectClass(classFileName);
61 | // System.out.println(classFileName+" -> "+classInfo);
62 | count++;
63 | if (count % 500 == 0) {
64 | tx.success();
65 | tx.finish();
66 | tx = graph.beginTx();
67 |
68 | long delta = (System.currentTimeMillis() - time);
69 | System.out.println("count = " + count + " took " + delta + " ms.");
70 | System.out.println("infoFactory status: " + infoFactory.toString());
71 | time = System.currentTimeMillis();
72 | }
73 | }
74 | tx.success();
75 | tx.finish();
76 | assertTrue("Files in classes.jar", count>1900);
77 | }
78 |
79 | /*
80 | without signature caching and with field/method relationships in both directions
81 | classFileName = java/lang/Object.class
82 | count = 500 took 8397 ms.
83 | count = 1000 took 8039 ms.
84 | count = 1500 took 14713 ms.
85 | count = 2000 took 19289 ms.
86 | count = 2500 took 22172 ms.
87 | count = 3000 took 26939 ms.
88 | count = 3500 took 27085 ms.
89 | count = 4000 took 39363 ms.
90 | count = 4500 took 24075 ms.
91 | count = 5000 took 28837 ms.
92 | count = 5500 took 49173 ms.
93 | count = 6000 took 44835 ms.
94 | count = 6500 took 52506 ms.
95 | count = 7000 took 52505 ms.
96 | count = 7500 took 53512 ms.
97 | count = 8000 took 54138 ms.
98 | count = 8500 took 60008 ms.
99 | */
100 | @After
101 | public void tearDown() {
102 | if (graph != null)
103 | graph.shutdown();
104 | }
105 | }
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/datasource/java/RecordingInspectorTest.java:
--------------------------------------------------------------------------------
1 | package org.neo4j.datasource.java;
2 |
3 | import static org.junit.Assert.*;
4 | import org.junit.Test;
5 | import org.neo4j.datasource.java.analyser.*;
6 | import org.neo4j.datasource.java.declaration.ClassDeclaration;
7 | import org.neo4j.datasource.util.SizeCountingOutputStream;
8 |
9 | import javax.swing.text.JTextComponentBeanInfo;
10 | import java.io.IOException;
11 | import java.io.ObjectOutputStream;
12 | import java.util.Map;
13 |
14 | public class RecordingInspectorTest {
15 | @Test
16 | public void testIterateDtJar() {
17 | final ClassFileIterator fileIterator = new ClassFileIterator();
18 | final RecordingInspector inspector = new RecordingInspector();
19 | long count = 0;
20 | for (final String classFileName : fileIterator.getClassFileNames(fileIterator.getJarLocationByClass(JTextComponentBeanInfo.class))) {
21 | inspector.inspectClass(classFileName);
22 | count++;
23 | }
24 | assertEquals("Files in dt.jar", 47, count);
25 | }
26 |
27 | @Test
28 | public void testIterateClassesJar() throws IOException {
29 | final RecordingInspector inspector = new RecordingInspector();
30 | checkAndRunClassesJar(inspector);
31 | final Map classes = inspector.getClasses();
32 | final SizeCountingOutputStream countingStream = new SizeCountingOutputStream();
33 | new ObjectOutputStream(countingStream).writeObject(classes);
34 | System.out.println("countingStream = " + countingStream.getCount());
35 | assertTrue("20 MB of data", countingStream.getCount() > 20 * 1024 * 1024);
36 | }
37 |
38 | @Test
39 | public void testTimeClassesJar() throws IOException {
40 | final ClassInspector inspector = new ClassInspector(ClassInspectUtils.getClassPath()) {
41 | protected RecursingClassVisitor createVisitor() {
42 | return new NullClassVisitor();
43 | }
44 | };
45 | checkAndRunClassesJar(inspector);
46 | }
47 |
48 | private void checkAndRunClassesJar(final ClassInspector inspector) {
49 | final ClassFileIterator fileIterator = new ClassFileIterator();
50 | final String jarFileLocation = fileIterator.getJarLocationByClass(Object.class);
51 | long count = 0;
52 | long time = System.currentTimeMillis();
53 | for (final String classFileName : fileIterator.getClassFileNames(jarFileLocation)) {
54 | final T result = inspector.inspectClass(classFileName);
55 | count++;
56 | if (count % 500 == 0) {
57 | long delta = (System.currentTimeMillis() - time);
58 | System.out.println("count = " + count + " took " + delta + " ms.");
59 | time = System.currentTimeMillis();
60 | }
61 | }
62 | assertEquals("Files in classes.jar", 19196, count);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/datasource/java/VirtualInspectorTest.java:
--------------------------------------------------------------------------------
1 | package org.neo4j.datasource.java;
2 |
3 | import junit.framework.TestCase;
4 | import org.junit.Test;
5 | import org.neo4j.datasource.java.analyser.ClassInspector;
6 | import org.neo4j.datasource.java.analyser.RecursingClassVisitor;
7 | import org.neo4j.datasource.java.analyser.VirtualVisitor;
8 |
9 | public class VirtualInspectorTest extends TestCase {
10 | @Test
11 | public void testInspectObject() {
12 | new ClassInspector(System.getProperty("java.class.path")) {
13 | protected RecursingClassVisitor createVisitor() {
14 | return VirtualVisitor.visitor(RecursingClassVisitor.class, this, 0);
15 | }
16 | }.inspectClass(Object.class);
17 | }
18 |
19 | @Test
20 | public void testInspectTest() {
21 | new ClassInspector(System.getProperty("java.class.path")) {
22 | protected RecursingClassVisitor createVisitor() {
23 | return VirtualVisitor.visitor(RecursingClassVisitor.class, this, 0);
24 | }
25 | }.inspectClass(getClass());
26 | }
27 | }
--------------------------------------------------------------------------------