OpenDayLight Toaster Tutorial Part 1 - opendaylight

I'm confused on the structure for part 1 of the md-sal toaster tutorial.
src/main/yang/toaster.yang
pom.xml
or is it
api/src/main/yang/toaster.yang
pom.xml
When I mvn clean install with the 1st one, the project builds but does not generate any java code. The second does not build but based on the tutorial, it should work.
Also, can I build this project from anywhere or does it need to be built in the controller/opendaylight/md-sal/ path?

You can build the project from anywhere. In the checked-in Toaster project (part of Controller), the YANG module is in src/main/yang/toaster.yang. If you build that project (the toaster module), you’ll find the generated Java code in target/generated-sources/mdsal-binding/org/opendaylight/yang/gen/v1/http/netconfcentral/org/ns/toaster/rev091120/.

As the link for this has changed (as it has for lot of OpenDaylight references) I'm adding an update to this post.
Pages that where "wiki" can now generally be found at "wiki-archive" (obviously haven't exhaustively tested that for all old ODL links).
The toaster tutorial (which are live as of 10/7/21) can now be found at the following link.
https://wiki-archive.opendaylight.org/view/OpenDaylight_Controller:MD-SAL:Toaster_Step-By-Step
Some of the code in the example fails to compile due to imports not being defined or specified. The code can be found in the "controller" project under "md-sal/samples". There's a link to this on the example page or you can download the project by running:
git clone https://github.com/opendaylight/controller.git

Related

Is there a sample project in github that shows how to use the maven-shade-plugin?

As the title says, I'm looking for a simple example in github that contains a code example that shows how to use the [the maven-shade-plugin] to rename classes when two versions of a library must be included in an application.
I found this answer on SO: https://stackoverflow.com/a/13620420/3281336 which shows exactly what I'm trying to do and I'm looking for a github repo that has that code example in it.
In the mean time, I'm starting to create my on version of this example and will post what I've created if no one points one out to me.
I have found several web pages that describe the plugin but nothing that has included a pointer to a repo with sample code.
Some useful writes up on the maven-shade-plugin
The plugin documentation: https://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html
What is the maven-shade-plugin used for, and why would you want to relocate Java packages? - the answer that included the diagram that shows how maven-shade-plugin allows two versions of a library to be included in an application.
In the same question this answer was great because it gave several real-life examples of how and why the maven-shade-plugin is used: https://stackoverflow.com/a/19386712/3281336
What is the maven-shade-plugin used for, and why would you want to relocate Java packages?
Difference between maven plugins ( assembly-plugins , jar-plugins , shaded-plugins) - differences between the different plugins to create a JAR executable.
Searching on google there were several articles I found that explained how to use the maven-shade-plugin. Some were:
https://howtodoinjava.com/maven/maven-shade-plugin-create-uberfat-jar-example/
https://mkyong.com/maven/create-a-fat-jar-file-maven-shade-plugin/
I created a github repo so others can learn/benefit from this question and answer.
The github repo is public at: https://github.com/steranka/maven-shade-example
The Readme.md explains the solution. Some if it is documented here in the event that goes away (some day).
Overview of the application
This is an example that illustrates the problem that occurs in most large projects and how the
maven-shade-plugin works to fix the problem.
This code example was developed in order to allow me to understand how the maven-shade-plugin works
with a real code but very simplified.
The idea of the simplicity was inspired by the StackOverflow answer: What is the maven-shade-plugin used for, and why would you want to relocate Java packages?
which explains why the maven-shade-plugin is needed and the problem it solves.
In this code the following JAR files exist
helloworld.jar - A Java executable jar that is the main program.
loglib.jar - There are two versions of this jar file (in different directories).
goodlib.jar - This is another JAR file that uses version 1 of loglib.jar (dir loglibv1).
Overview of the Dependency Tree
The following diagram shows the dependency tree for the helloworld application.
Each of the pom files create a JAR file so there are 4 (four) jar files created by this code example.
Summary of the Problem
The next diagram shows the loglib.jar file being used in both the main application (helloworld)
It shows the class LogIt contains a method sayHello which takes one argument String name in version 1.0.0 of the package (liblog.jar)
and sayHello takes two arguments in the 2nd version of the package.
While this example is contrived to demonstrate the general problem
that faces Java developers on more complex code bases, this simplified version of the problem is intended to make the problem
easy to understand and to fix.
So by default, when a FAT jar is created for the HelloWorld application, the Fat jar only contains one copy of the class file com.steranka.play.LogIt.
The result is that either the HelloWorld class will crash or the GoodFeature class will crash. Where crash means throw an exception
Below is an example of the exception I saw when I first ran the application.
Hello World!
What's up, Sam
Exception in thread "main" java.lang.NoSuchMethodError: 'java.lang.String com.steranka.play.LogIt.sayHello(java.lang.String)'
at com.steranka.play.GoodFeature.sayGoodbye(GoodFeature.java:6)
at com.steranka.play.HelloWorldApp.main(HelloWorldApp.java:15)
This problem occurs because version 2.0.0 of the loglib.jar was used which contained the signature:
sayHello(String name, String greeting)
and the code in GoodFeature.sayGoodbye had bytecode which called the version 1.0.0 of the signature which was:
sayHello(String name)
Since that signature did not exist, the exception occured.
The Solution
The solution is to include both versions of the loglib jar file as shown in the next diagram.
Next Steps
If you want to follow along with what I did, and learn how I solved this problem
continue here with the doc/01-Starting.md file.

Library development/debug with Maven

I am in the processing of integrating Maven into my my projects. While maven has plenty of pros i'm finding it difficult to figure out how to maintain my current development process, which is as follows:
For creating SDKs I will create a sample app, which will depend on and directly reference the SDK source code, all from within the same code project. This means that I can make easily change/debug the SDK code with one click run/debugging.
I fear this won't really be possible with Maven. Can I create some type of Hybrid approach, where I continue my normal development approach and then push builds to Maven when it is appropriate.
Update - For Clarity
My problem is that when everything is done through maven, the dependencies are built and published to Maven. Then, the dependent project pulls down compiled references and uses them. My issues is that I don't want to go through this whole process every time I make a small change to a dependency.Thanks.
You should try creating parent level pom.xml with two modules - your library and simple app to test it. In simple app's pom.xml provide a dependency on library module.
Then open in your IDE parent pom as maven project. This should be sufficient for normal debug.
Other possible approach - install you library artifact into maven repo with sources. In this case you will be able to debug it, but test app still have to load use jars from repo.

Project Setup for Github/Openshift/Spring MVC

This is a general question, which I'm sure has been asked before, but all the resources I'm finding suffer from the typical coder problem of assuming I know things that I don't know.
I'm trying to use Openshift to deploy a Spring MVC project from a Github repo. What I don't know is what my github link is supposed to contain.
I initially assumed that the github repo should simply contain the code of my project, where I'm linking all of my development code to. However, when applying this the result is a 404 page with no additional information.
Does the github repo require a WAR? Does it need to be set up in a specific way? I've been able to successfully deploy this project from a WAR to another server, so I know the code is working properly, but I can't seem to find any documentation on the expectations for project design that openshift has for my github repo.
Am I doing this right? Is my problem with the github contents, or is it elsewhere?
You should try creating a default project for whichever java server cartridge you are using, and look at the structure. It's a standard Maven project, but there is some difference in the pom.xml so that it knows how to deploy the war file it compiles.

Best way to incorporate Volley (or other library) into Android Studio project

I've seen different advice on the best way to do this This question covers creating a jar. Elsewhere, I've seen advice to simply copy the volley source into your own project. This section on libraries at android.com would seem the most authoritative. However, after compiling volley, I don't have an aal library, whereas that section says I should have.
So my question is this: I have an existing Android Studio project with a standard layout, and a git repository; what should I do to add volley? Where should I download it to? How should I add it to Android Studio? Which Gradle files, if any, do I need to modify.
Hopefully, for those of you have done this a few times, this should be bread-and-butter stuff, but I haven't been able to find a straightforward description.
--
Updating, per Scott Barta's suggestion.
The gradle.build file in the volley repository has this line.
apply plugin: 'android-library'
According to the documentation: "Library projects do not generate an APK, they generate a .aar package (which stands for Android archive)." However, when I build the volley project, no .aar is created.
My feeling is that as Volley is a library project, created by the Android team, it is most probably intended to be generated and used as .aar package. Any advice on whether it would be preferable to generate a .aar, and how to do that, would be appreciated.
As pointed out by others as well, Volley is officially available on Github:
Add this line to your gradle dependencies for volley:
compile 'com.android.volley:volley:1.0.0'
To install volley from source read below:
I like to keep the official volley repository in my app. That way I get it from the official source and can get updates without depending on anyone else and mitigating concerns expressed by other people.
Added volley as a submodule alongside app.
git submodule add -b master https://github.com/google/volley.git volley
In my settings.gradle, added the following line to add volley as a module.
include ':volley'
In my app/build.gradle, I added a compile dependency for the volley project
compile project(':volley')
That's all! Volley can now be used in my project.
Everytime I want to sync the volley module with Google's repo, i run this.
git submodule foreach git pull
LATEST UPDATE:
Use the official version from jCenter instead.
dependencies {
compile 'com.android.volley:volley:1.0.0'
}
The dependencies below points to deprecated volley that is no longer maintained.
ORIGINAL ANSWER
You can use this in dependency section of your build.gradle file to use volley
dependencies {
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
}
UPDATED:
Its not official but a mirror copy of official Volley. It is regularly synced and updated with official Volley Repository so you can go ahead to use it without any worry.
https://github.com/mcxiaoke/android-volley
Nowadays
dependencies {
compile 'com.android.volley:volley:1.0.0'
}
A lot of different ways to do it back in the day (original answer)
Add volley.jar as library
Download it from: http://api.androidhive.info/volley/volley.jar
Place it in your [MyProjectPath]/app/libs/ folder
Use the source files from git (a rather manual/general way described here)
Download / install the git client (if you don't have it on your system yet): http://git-scm.com/downloads
(or via git clone https://github.com/git/git ... sry bad one, but couldn't resist ^^)
Execute git clone https://android.googlesource.com/platform/frameworks/volley
Copy the com folder from within [path_where_you_typed_git_clone]/volley/src to your projects app/src/main/java folder (Integrate it instead, if you already have a com folder there!! ;-))
The files show up immediately in Android Studio. For Eclipse you will have to right-click on the src folder and press refresh (or F5) first.
Use gradle via the "unofficial" maven mirror
In your project's src/build.gradle file add following volley dependency:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// ...
compile 'com.mcxiaoke.volley:library:1.+'
}
Click on Try Again which should right away appear on the top of the file, or just Build it if not
The main "advantage" here is, that this will keep the version up to date for you, whereas in the other two cases you would have to manually update volley.
On the "downside" it is not officially from google, but a third party weekly mirror.
But both of these points, are really relative to what you would need/want.
Also if you don't want updates, just put the desired version there instead e.g. compile 'com.mcxiaoke.volley:library:1.0.7'.
As of today, there is an official Android-hosted copy of Volley available on JCenter:
compile 'com.android.volley:volley:1.0.0'
This was compiled from the AOSP volley source code.
UPDATE:
compile 'com.android.volley:volley:1.0.0'
OLD ANSWER:
You need the next in your build.gradle of your app module:
dependencies {
compile 'com.mcxiaoke.volley:library:1.0.19'
(Rest of your dependencies)
}
This is not the official repo but is a highly trusted one.
For incorporate volley in android studio,
paste the following command in terminal ( git clone https://android.googlesource.com/platform/frameworks/volley ) and run it. Refer android developer tutorial for this.
It will create a folder name volley in the src directory.
Then go to android studio and right click on the project.
choose New -> Module from the list.
Then click on import existing Project from the below list.
you will see a text input area namely source directory, browse the folder you downloaded (volley) and then click on finish.
you will see a folder volley in your project view.
the switch to android view and open the build:gradle(Module:app) file and append the following line in the dependency area:
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
Now synchronise your project and also build your project.
I have set up Volley as a separate Project. That way its not tied to any project and exist independently.
I also have a Nexus server (Internal repo) setup so I can access volley as
compile 'com.mycompany.volley:volley:1.0.4' in any project I need.
Any time I update Volley project, I just need to change the version number in other projects.
I feel very comfortable with this approach.
add
compile 'com.mcxiaoke.volley:library:1.0.19'
compile project('volley')
in the dependencies, under build.gradle file of your app
DO NOT DISTURB THE build.gradle FILE OF YOUR LIBRARY. IT'S YOUR APP'S GRADLE FILE ONLY YOU NEED TO ALTER
This solution is for Kotlin DSL (build.gradle.kts):
dependencies {
implementation("com.android.volley:volley:1.2.1")
// ...
}

How can I set up my project hierarchy in QtCreator?

I'm quite new to QtCreator, so perhaps I left my heart in eclipse-ville, but I can't for the life of me understand how I should be setting up a project hierarchy in QtCreator. I understand there is an option to create a kind of root project and then from there add sub-projects to it, which makes sense but it leaves me wondering whether or not this is necessary at the time of creating the project, e.g. can I just create a library in one project and reference it later by another project?
I've tried setting up a blanket type of project by creating a new subdirs project and then adding the main program as a subproject, but then how should I add my library project?
Ideally, I'd like to create one project as the main application and reference another project as a library. Help?
The documentation of Qt Creator contains two sections that may help you find the answers to your questions:
Adding Subprojects to Projects
Adding Libraries to Projects
EDIT:
You can find a really simple sample project here: QtSymbianDllExample. "It is intended to demonstrate how to create and use a DLL with Qt on the Symbian platform". It is a sample for Symbian development but that is irrelevant now, I do not have a Symbian phone. What is important is that it contains a root project (QtSymbianDllExample\qtssymbiandllexample.pro) and two subprojects (QtSymbianDllExample\qtenginedll\qtenginedll.pro, QtSymbianDllExample\testui_simpledllengine\testui_simpledllengine.pro) which you can examine and compare to you projects. I have checked that I can build the root project by doing the following steps:
Download and install the Windows Offline Installer from http://www.qt.io/download/
Download and extract QtSymbianDllExample.zip
Run Qt Creator
File / Open File or Project... Select qtssymbiandllexample.pro
Build / Run qmake
Build / Build project "qtsymbiandllexample"

Resources