Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Rosjava Bootstrap Gradle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CeTI
ROS
ROS Java Packages
Rosjava Bootstrap Gradle
Commits
60d7446f
Commit
60d7446f
authored
10 years ago
by
Daniel Stonier
Browse files
Options
Downloads
Plain Diff
Merge pull request #33 from rosjava/genjava
Single interface generator for genjava.
parents
0ffb8114
74cbd443
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
message_generation/src/main/java/org/ros/internal/message/GenerateInterface.java
+105
-0
105 additions, 0 deletions
...main/java/org/ros/internal/message/GenerateInterface.java
with
105 additions
and
0 deletions
message_generation/src/main/java/org/ros/internal/message/GenerateInterface.java
0 → 100644
+
105
−
0
View file @
60d7446f
/*
* Copyright (C) 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package
org.ros.internal.message
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.List
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.ros.exception.RosMessageRuntimeException
;
import
org.ros.internal.message.definition.MessageDefinitionReflectionProvider
;
import
org.ros.internal.message.definition.MessageDefinitionTupleParser
;
import
org.ros.message.MessageDeclaration
;
import
org.ros.message.MessageFactory
;
import
org.ros.message.MessageIdentifier
;
import
com.google.common.collect.Lists
;
/**
* @author d.stonier@gmail.com (Daniel Stonier)
*/
public
class
GenerateInterface
{
private
static
void
writeInterface
(
MessageDeclaration
messageDeclaration
,
File
outputDirectory
,
boolean
addConstantsAndMethods
,
MessageFactory
messageFactory
)
{
MessageInterfaceBuilder
builder
=
new
MessageInterfaceBuilder
();
builder
.
setPackageName
(
messageDeclaration
.
getPackage
());
builder
.
setInterfaceName
(
messageDeclaration
.
getName
());
builder
.
setMessageDeclaration
(
messageDeclaration
);
builder
.
setAddConstantsAndMethods
(
addConstantsAndMethods
);
try
{
String
content
;
content
=
builder
.
build
(
messageFactory
);
File
file
=
new
File
(
outputDirectory
,
messageDeclaration
.
getType
()
+
".java"
);
System
.
out
.
println
(
"Output File: "
+
file
.
getAbsolutePath
());
FileUtils
.
writeStringToFile
(
file
,
content
);
}
catch
(
Exception
e
)
{
System
.
out
.
printf
(
"Failed to generate interface for %s.\n"
,
messageDeclaration
.
getType
());
e
.
printStackTrace
();
}
}
public
static
void
main
(
String
[]
args
)
{
List
<
String
>
arguments
=
Lists
.
newArrayList
(
args
);
if
(
arguments
.
size
()
!=
3
)
{
System
.
out
.
println
(
"Incorrect usage, please provide two args: _output_directory_, _pkg_ and _path_to_msg/srv_file_"
);
System
.
exit
(
1
);
}
File
outputDirectory
=
new
File
(
arguments
.
remove
(
0
));
String
pkg
=
arguments
.
remove
(
0
);
File
file
=
new
File
(
arguments
.
remove
(
0
));
System
.
out
.
println
(
"Output Directory: "
+
outputDirectory
.
getAbsolutePath
());
System
.
out
.
println
(
"Package: "
+
pkg
);
System
.
out
.
println
(
"Message: "
+
file
.
getAbsolutePath
());
String
name
=
FilenameUtils
.
getBaseName
(
file
.
getName
());
String
extension
=
FilenameUtils
.
getExtension
(
file
.
getName
());
System
.
out
.
println
(
" Name: "
+
name
);
System
.
out
.
println
(
" Extension: "
+
extension
);
String
definition
;
try
{
definition
=
FileUtils
.
readFileToString
(
file
,
"US-ASCII"
);
}
catch
(
IOException
e
)
{
throw
new
RosMessageRuntimeException
(
e
);
}
MessageIdentifier
messageIdentifier
=
MessageIdentifier
.
of
(
pkg
,
name
);
MessageDeclaration
messageDeclaration
=
new
MessageDeclaration
(
messageIdentifier
,
definition
);
MessageDefinitionReflectionProvider
messageDefinitionProvider
=
new
MessageDefinitionReflectionProvider
();
messageDefinitionProvider
.
add
(
messageIdentifier
.
getType
(),
definition
);
MessageFactory
messageFactory
=
new
DefaultMessageFactory
(
messageDefinitionProvider
);
if
(
extension
.
equals
(
"msg"
))
{
writeInterface
(
messageDeclaration
,
outputDirectory
,
true
,
messageFactory
);
}
else
if
(
extension
.
equals
(
"srv"
))
{
writeInterface
(
messageDeclaration
,
outputDirectory
,
false
,
messageFactory
);
List
<
String
>
requestAndResponse
=
MessageDefinitionTupleParser
.
parse
(
definition
,
2
);
MessageDeclaration
requestDeclaration
=
MessageDeclaration
.
of
(
messageIdentifier
.
getType
()
+
"Request"
,
requestAndResponse
.
get
(
0
));
MessageDeclaration
responseDeclaration
=
MessageDeclaration
.
of
(
messageIdentifier
.
getType
()
+
"Response"
,
requestAndResponse
.
get
(
1
));
writeInterface
(
requestDeclaration
,
outputDirectory
,
true
,
messageFactory
);
writeInterface
(
responseDeclaration
,
outputDirectory
,
true
,
messageFactory
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment