Jan Borsodi avatar Jan Borsodi committed 7031c56

Moved the java template files to the new location. In addition the 'java' command was updated as a result of the move.

Comments (0)

Files changed (5)

         services = list(ui.config.currentTarget().services())
 
     if services:
+        from hob.template import Generator
+        filegen = Generator()
         for extra_file, extra_dir in (('proto/scope_descriptor.proto', 'proto/opera/scope'), ('proto/google/protobuf/descriptor.proto', 'proto/google/protobuf')):
             extra_dir = os.path.normpath(os.path.join(out_dir, extra_dir))
             if not os.path.exists(extra_dir):
                 os.makedirs(extra_dir)
             root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
             fname = os.path.join(extra_dir, os.path.basename(extra_file))
-            shutil.copyfile(os.path.join(root, "templates", extra_file), fname)
+            extra_path = filegen.findFile(extra_file)
+            shutil.copyfile(extra_path, fname)
             ui.outl("Copied %s to '%s'" % (extra_file, fname))
 
     class CodeNames(object):

hob/templates/java/file.mako

+// Generated by the hob compiler.  DO NOT EDIT!
+// source: ${source}.proto
+
+package ${package.options["java_package"].value};
+
+// Java
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+// Protocol Buffer
+import com.google.protobuf.ByteString;
+import com.google.protobuf.GeneratedMessage;
+import com.google.protobuf.InvalidProtocolBufferException;
+
+// Scope SDK
+import com.opera.core.scope.EventListener;
+import com.opera.core.scope.FilterRule;
+import com.opera.core.scope.Message;
+import com.opera.core.scope.MessageCallback;
+import com.opera.core.scope.ProtocolFormat;
+import com.opera.core.scope.ScopeClient;
+import com.opera.core.scope.ScopeErrorException;
+
+// STP
+import com.opera.core.systems.scope.protos.UmsProtos.Command;
+import com.opera.core.systems.scope.protos.UmsProtos.Event;
+import com.opera.core.systems.scope.protos.UmsProtos.Response;
+import com.opera.core.systems.scope.protos.UmsProtos.TransportMessage;
+
+// Messages in service ${service.name}
+## TODO: the java names should be stored in the package/service/message objects
+% for message in service.messages():
+import ${package.options["java_package"].value}.${service.name}.${message.name};
+% endfor
+
+${g.service(service)}

hob/templates/java/service.mako

+<%
+    events = list(service.iterevents())
+    commands = list(service.itercommands())
+%>
+% if service.doc:
+${service.doc.toComment()}
+% endif
+public class ${service.java.class_name} {
+    % if events:
+	public enum EventID {
+    % for event in events[:-1]:
+		${event.name}(${event.id}),
+    % endfor
+    % for event in events[-1:]:
+		${event.name}(${event.id});
+    % endfor
+
+		private EventID(int value) {
+			this.value = value;
+		}
+		
+		private Integer value;
+
+		public Integer getValue() {
+			return value;
+		}
+	}
+    % endif
+
+    % if commands:
+	public enum CommandID {
+    % for command in commands[:-1]:
+		${command.name}(${command.id}),
+    % endfor
+    % for command in commands[-1:]:
+		${command.name}(${command.id});
+    % endfor
+
+		private CommandID(int value) {
+			this.value = value;
+		}
+		
+		private Integer value;
+
+		public Integer getValue() {
+			return value;
+		}
+	}
+    % endif
+
+	private final ScopeClient client;
+	
+	private final ScopeEventsHandler scopeEventsHandler;
+	private final LinkedList<Event> eventsList;
+	
+	public ScopeEventsHandler getScopeEventsHandler() {
+		return scopeEventsHandler;
+	}
+	
+	public ${service.java.class_name}(final ScopeClient client, final ScopeEventsHandler scopeEventsHandler) {
+		this.client = client;
+		this.scopeEventsHandler = scopeEventsHandler;
+		eventsList = new LinkedList<Event>();
+		client.attachEventListener(new EventListener() {	
+			@Override
+			public void onEvent(Event event) {
+				if(!event.getService().equals("${service.java.identifier}"))
+					return;
+				
+				switch (event.getCommandID()) {
+                % for event in events:
+				case ${event.java.enum}.getValue(): // ${event.name}
+					System.out.println("Got event '${event.name}'");
+					try {
+						scopeEventsHandler.${event.java.method_name}(${event.message.java.class_name}.parseFrom(event.getPayload()));
+					} catch (InvalidProtocolBufferException e) {
+						//TODO log
+					}
+					break;
+                % endfor
+
+				default:
+					break;
+				}
+			}
+		});
+	}
+
+    // Commands
+
+    % for command in commands:
+	 public void ${command.java.method_name}(${command.message.java.class_name} ${command.message.java.var_name}, final MessageCallback<${command.response.java.class_name}> callback) {
+	        Command.Builder command = Command.newBuilder();
+	        command.setCommandID(${command.java.enum}.getValue());
+	        command.setFormat(ProtocolFormat.PROTOBUF.getValue());
+	        command.setPayload(ByteString.EMPTY);
+	        command.setService(${service.java.identifier_string});
+	        command.setTag(client.getNextTag());
+	        eventsList.clear();
+	        client.sendCommand(command.build(), new MessageCallback<Response>() {
+	            
+	            @Override
+	            public void onMessageReceived(Response r)  {
+							${command.response.java.class_name} result = null;
+							try {
+								result = ${command.response.java.class_name}.parseFrom(r.getPayload());
+							} catch (InvalidProtocolBufferException ex) {
+								callback.onError(new ScopeErrorException(ex));
+							}
+							callback.onMessageReceived(result);
+						}
+
+				@Override
+				public void onError(ScopeErrorException error) {
+					callback.onError(error);
+					
+				}
+	        });
+	    }
+	    
+	    public ${command.response.java.class_name} ${command.java.method_name}(${command.message.java.class_name} ${command.message.java.var_name}, long timeout, TimeUnit unit) throws ScopeErrorException {
+	        final Message<${command.response.java.class_name}.Builder, ScopeErrorException> message = new Message<${command.response.java.class_name}.Builder, ScopeErrorException>();
+	        final Semaphore lock = client.getClientLock();
+	        MessageCallback<${command.response.java.class_name}> callback = new MessageCallback<${command.response.java.class_name}>() {
+	            
+	            @Override
+	            public void onMessageReceived(${command.response.java.class_name} t) {
+	                message.setPayload(${command.response.java.class_name}.newBuilder().mergeFrom(t));
+	                lock.release();
+	                
+	            }
+
+				@Override
+				public void onError(ScopeErrorException error) {
+					message.setAttachment(error);
+					lock.release();
+				}
+	            
+	            
+	        };
+	        ${command.java.method_name}(list, callback);
+			boolean acquired = false;
+			
+			try {
+				acquired = lock.tryAcquire(timeout, unit);
+			} catch (InterruptedException e) {
+				Thread.currentThread().interrupt();
+			}
+			//release lock if not
+			if(message.hasAttachment())
+				throw message.getAttachment();
+			
+	        return acquired ? message.getPayload().build() : null;
+	    }
+    % endfor
+
+    // Events
+
+    % for event in events:
+	    public ${event.message.java.class_name} ${event.java.method_name}() {
+	    	LinkedList<Event> events = (LinkedList<Event>) ${event.java.method_name}(0);
+	    	System.out.println("got " + events.size() + "events before");
+	    	try {
+				return ${event.message.java.class_name}.parseFrom(events.getLast().getPayload());
+			} catch (InvalidProtocolBufferException e) {
+				// TODO: Should throw back to caller since this is synchronous
+				e.printStackTrace();
+			}
+			return null;
+	    }
+
+	    public List<Event> ${event.java.method_name}(int n) {
+	    	final Semaphore lock = client.getClientLock();
+	    	EventListener handler = new EventListener() {
+				@Override
+				public void onEvent(Event event) {
+					eventsList.add(event);
+					if(event.getService().equals(${service.java.identifier_string}) && event.getCommandID() == ${event.java.enum}.getValue()) {
+						lock.release();
+						client.detachEventListener(this);
+					}
+					
+				}
+			};
+	    	client.attachEventListener(handler);
+	    	 try {
+					lock.tryAcquire(15000, TimeUnit.MILLISECONDS);
+					//if(done) client.detachEventHandler(handler);
+				} catch (InterruptedException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+			
+	    	return eventsList;
+	    }
+
+    % endfor
+}

templates/java/file.mako

-// Generated by the hob compiler.  DO NOT EDIT!
-// source: ${source}.proto
-
-package ${package.options["java_package"].value};
-
-// Java
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-
-// Protocol Buffer
-import com.google.protobuf.ByteString;
-import com.google.protobuf.GeneratedMessage;
-import com.google.protobuf.InvalidProtocolBufferException;
-
-// Scope SDK
-import com.opera.core.scope.EventListener;
-import com.opera.core.scope.FilterRule;
-import com.opera.core.scope.Message;
-import com.opera.core.scope.MessageCallback;
-import com.opera.core.scope.ProtocolFormat;
-import com.opera.core.scope.ScopeClient;
-import com.opera.core.scope.ScopeErrorException;
-
-// STP
-import com.opera.core.systems.scope.protos.UmsProtos.Command;
-import com.opera.core.systems.scope.protos.UmsProtos.Event;
-import com.opera.core.systems.scope.protos.UmsProtos.Response;
-import com.opera.core.systems.scope.protos.UmsProtos.TransportMessage;
-
-// Messages in service ${service.name}
-## TODO: the java names should be stored in the package/service/message objects
-% for message in service.messages():
-import ${package.options["java_package"].value}.${service.name}.${message.name};
-% endfor
-
-${g.service(service)}

templates/java/service.mako

-<%
-    events = list(service.iterevents())
-    commands = list(service.itercommands())
-%>
-% if service.doc:
-${service.doc.toComment()}
-% endif
-public class ${service.java.class_name} {
-    % if events:
-	public enum EventID {
-    % for event in events[:-1]:
-		${event.name}(${event.id}),
-    % endfor
-    % for event in events[-1:]:
-		${event.name}(${event.id});
-    % endfor
-
-		private EventID(int value) {
-			this.value = value;
-		}
-		
-		private Integer value;
-
-		public Integer getValue() {
-			return value;
-		}
-	}
-    % endif
-
-    % if commands:
-	public enum CommandID {
-    % for command in commands[:-1]:
-		${command.name}(${command.id}),
-    % endfor
-    % for command in commands[-1:]:
-		${command.name}(${command.id});
-    % endfor
-
-		private CommandID(int value) {
-			this.value = value;
-		}
-		
-		private Integer value;
-
-		public Integer getValue() {
-			return value;
-		}
-	}
-    % endif
-
-	private final ScopeClient client;
-	
-	private final ScopeEventsHandler scopeEventsHandler;
-	private final LinkedList<Event> eventsList;
-	
-	public ScopeEventsHandler getScopeEventsHandler() {
-		return scopeEventsHandler;
-	}
-	
-	public ${service.java.class_name}(final ScopeClient client, final ScopeEventsHandler scopeEventsHandler) {
-		this.client = client;
-		this.scopeEventsHandler = scopeEventsHandler;
-		eventsList = new LinkedList<Event>();
-		client.attachEventListener(new EventListener() {	
-			@Override
-			public void onEvent(Event event) {
-				if(!event.getService().equals("${service.java.identifier}"))
-					return;
-				
-				switch (event.getCommandID()) {
-                % for event in events:
-				case ${event.java.enum}.getValue(): // ${event.name}
-					System.out.println("Got event '${event.name}'");
-					try {
-						scopeEventsHandler.${event.java.method_name}(${event.message.java.class_name}.parseFrom(event.getPayload()));
-					} catch (InvalidProtocolBufferException e) {
-						//TODO log
-					}
-					break;
-                % endfor
-
-				default:
-					break;
-				}
-			}
-		});
-	}
-
-    // Commands
-
-    % for command in commands:
-	 public void ${command.java.method_name}(${command.message.java.class_name} ${command.message.java.var_name}, final MessageCallback<${command.response.java.class_name}> callback) {
-	        Command.Builder command = Command.newBuilder();
-	        command.setCommandID(${command.java.enum}.getValue());
-	        command.setFormat(ProtocolFormat.PROTOBUF.getValue());
-	        command.setPayload(ByteString.EMPTY);
-	        command.setService(${service.java.identifier_string});
-	        command.setTag(client.getNextTag());
-	        eventsList.clear();
-	        client.sendCommand(command.build(), new MessageCallback<Response>() {
-	            
-	            @Override
-	            public void onMessageReceived(Response r)  {
-							${command.response.java.class_name} result = null;
-							try {
-								result = ${command.response.java.class_name}.parseFrom(r.getPayload());
-							} catch (InvalidProtocolBufferException ex) {
-								callback.onError(new ScopeErrorException(ex));
-							}
-							callback.onMessageReceived(result);
-						}
-
-				@Override
-				public void onError(ScopeErrorException error) {
-					callback.onError(error);
-					
-				}
-	        });
-	    }
-	    
-	    public ${command.response.java.class_name} ${command.java.method_name}(${command.message.java.class_name} ${command.message.java.var_name}, long timeout, TimeUnit unit) throws ScopeErrorException {
-	        final Message<${command.response.java.class_name}.Builder, ScopeErrorException> message = new Message<${command.response.java.class_name}.Builder, ScopeErrorException>();
-	        final Semaphore lock = client.getClientLock();
-	        MessageCallback<${command.response.java.class_name}> callback = new MessageCallback<${command.response.java.class_name}>() {
-	            
-	            @Override
-	            public void onMessageReceived(${command.response.java.class_name} t) {
-	                message.setPayload(${command.response.java.class_name}.newBuilder().mergeFrom(t));
-	                lock.release();
-	                
-	            }
-
-				@Override
-				public void onError(ScopeErrorException error) {
-					message.setAttachment(error);
-					lock.release();
-				}
-	            
-	            
-	        };
-	        ${command.java.method_name}(list, callback);
-			boolean acquired = false;
-			
-			try {
-				acquired = lock.tryAcquire(timeout, unit);
-			} catch (InterruptedException e) {
-				Thread.currentThread().interrupt();
-			}
-			//release lock if not
-			if(message.hasAttachment())
-				throw message.getAttachment();
-			
-	        return acquired ? message.getPayload().build() : null;
-	    }
-    % endfor
-
-    // Events
-
-    % for event in events:
-	    public ${event.message.java.class_name} ${event.java.method_name}() {
-	    	LinkedList<Event> events = (LinkedList<Event>) ${event.java.method_name}(0);
-	    	System.out.println("got " + events.size() + "events before");
-	    	try {
-				return ${event.message.java.class_name}.parseFrom(events.getLast().getPayload());
-			} catch (InvalidProtocolBufferException e) {
-				// TODO: Should throw back to caller since this is synchronous
-				e.printStackTrace();
-			}
-			return null;
-	    }
-
-	    public List<Event> ${event.java.method_name}(int n) {
-	    	final Semaphore lock = client.getClientLock();
-	    	EventListener handler = new EventListener() {
-				@Override
-				public void onEvent(Event event) {
-					eventsList.add(event);
-					if(event.getService().equals(${service.java.identifier_string}) && event.getCommandID() == ${event.java.enum}.getValue()) {
-						lock.release();
-						client.detachEventListener(this);
-					}
-					
-				}
-			};
-	    	client.attachEventListener(handler);
-	    	 try {
-					lock.tryAcquire(15000, TimeUnit.MILLISECONDS);
-					//if(done) client.detachEventHandler(handler);
-				} catch (InterruptedException e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				}
-			
-	    	return eventsList;
-	    }
-
-    % endfor
-}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.