I have written a custom build script for my android app. I included some "easy" preprocessing, so I can define comments like
//#ifdef something
... CODE
//#endif
and get rid of the Code part if configured so. The Problem is, that after preprocessing I don't need some modules anymore, so I leave them out. What remains is the import statement for that module which bites me, if I want to build the app finally. I'm searching for a way within my preprocessing, to organize the java Imports inside my script after preprocessing happens. Any Solution without the need for additional "clicks" is very welcome.
Sometimes you're really need preprocessor (quite rare). But you could actually achieve same goal with right build process.
Anyway back to the question you could use next technique:
//#ifdef something
... IMPORTS
//#endif
take a look at http://code.google.com/p/java-comment-preprocessor/
p.s.
example of usage for one of my cases
http://code.google.com/p/java-comment-preprocessor/wiki/ExampleOfUsageForJ2ME
Related
I dislike the build tools that exist for Java. So I wrote my own. But there is one feature that it doesn't have yet; auto-import of changes into the IntelliJ project.
I'm having trouble finding information on how to do this. Tutorials on how to write IntelliJ plugins throw tons of useless stuff at me (creating UI for example).
I know this isn't your typical stackoverflow I-have-a-bug question but I'm quite lost and could use a pointer in the right direction.
If you need to know when a certian file was changed and auto-import information from this file you can use VirtualFileManager.addVirtualFileListener().
Or even use fileDocumentManagerListener extension point. Whatever suits your needs more.
So far I've managed to create a simple IntelliJ plugin. The start is fairly simple. IntelliJ has the plugin project skeleton built in. File->new Project is enough there.
From there I've created a class that implements ModuleComponent. The documentation here (https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_components.html) says it will be loaded whenever a module is opened.
To get it to work I had to add this stuff in the plugin.xml:
<module-components>
<component>
<interface-class>packagename.ClassName</interface-class>
<implementation-class>packagename.ClassName</implementation-class>
</component>
</module-components>
The documentation manages to hide this next step but its possible to give the ModuleComponent a constructor like so:
public ClassName(final Module module) {}
This should give me an instance of the Module class to read values from and to modify the way I need.
As it turns out IntelliJ makes it difficult to figure out how to do things. There is no Javadoc for example. People seem to suggest reading the source code. Weird..
A quick look through the methods of Module didn't really help me much. Google let me know that in order to make changes to the Module I could do the following:
ModuleRootManager.getInstance(module).getModifiableModel()
I can call several methods on this model and finally call .commit() when I'm done to persist the changes. The ModifiableRootModel has two methods that look very promissing:
ModifiableRootModel.addModuleOrderEntry()
ModifiableRootModel.addLibraryEntry()
The first takes a Module instance. I'm hoping that if I add the correct Module this will allow me to well, add modules :). I can think of two situations here. First, the module is already loaded in the project, in which case I will need to find it and add it. And second, the module is not loaded yet so I will need to tell IntelliJ to load it and add it to the project.
The second method takes a Library instance. Just new Library() doesn't work, and google isn't very helpful here. From my buildfile I can extract the groupId:artifactId:version:scope value. So I'll need a way to turn those strings into a Library that works.
This is how far I've gotten so far. Current problems are:
I need to find the already loaded modules so I can find the one I'm linking to
I need a way to add a module to the project if it hasn't been loaded yet
I need a way to turn a maven style dependency into a Library object so I can add it to the module
I need a way to list all the existing modules and libraries so I don't end up adding duplicates
I am looking for a solution that can be run on a continuous integration server (TeamCity) which seems to rule out IDE specific solutions like the externalization that is built into eclipse.
I need to generate warnings when strings are found in the java source files, unless they have been somehow flagged (by comment or annotation) as not requiring internationalization, eg the // $NON-NLS-1$ comment for eclipse.
The code is built using maven in teamcity.
I have not been able to find existing solutions or any ideas on how a custom solution might be hooked into either maven or teamcity (note I am not hugely familiar with either so could be overlooking something fairly obvious).
It seems that you need some specifically crafted Static Code Analysis tool.
I am afraid that no such thing exists yet (or I should say no such thing is available for public use...). I am not sure if you would be able to create warnings from the tool though. I know it would be possible with Gradle, but integrating Gradle task with Java code is not an easiest thing to do (BTDT).
Maybe some simple HTML report would do? In this case, you can simply use Scanner with regular expressions that matches all the strings literals... That is unless you'll find exclusions (another RegExp) in the same line. That's pretty basic thing to do.
I'm a new person in this area (plugin developing) and I want to create some kind of plugin for my app:
I've developed an android application and now I need to make a toolkit for the students for future work on this app. The idea is:
1) to make a manual for that app, so that students can read about classes and structure not in separate .doc file but inside Eclipse IDE, probably with some links to the code.
2) to make a supervise of the app's functions (so that students can check if all features (performance-UI design, connection to the external server/API's, etc) of the app are working properly, in case if they will change something). All these data should be in separate frame (looks like a toolkit). (I found information related to this here http://www.ibm.com/developerworks/opensource/tutorials/os-eclipse-jfeature/section5.html, but I'm not sure if it's gonna work for my idea)
I will be glad to get some links of tutorials that are related to my task as well as your suggestions for the set of the toolkit features (but also with links how to make it).
Thank you very much in advance! Hope to get your help :)
The thing for the manual is Javadoc, you can use it in eclipse with java as well as in android.
here are some links, first:
http://en.wikipedia.org/wiki/Javadoc
Then I can quickly explain why javadoc can be useful for you, first of all it allows to create a real manual (java API are created with javadoc) with (in my opinion) the easiest way you can imagine.
You have to use a special comment tag that is:
/**
*
**/
When you put this before any declaration (methods, class, interfaces, fields etc) it will be included in the javadoc.
You have standard things that can be added for example you can specify a description of the method, what it #return what #params it need and many other things, being very careful and precise you can link javadoc with each other, and create very complex and precise documentation.
In eclipse javadoc is useful because eclipse itself allows the user to interact with javadoc by default. For example if you want to know what a method do, just simply hang the mouse over the name of the method and a little yellow dialog will appear. If you also use ctrl-space you can have some tips also in it. Pressing ctrl-space shows for example all avaible public methods, with javadoc for each method you have the yellow description dialog. If you are instantiating a new object you can see how many (and what kind of parameters they have) constructor are definited and so on, I think it is very useful and important.
For the second things if I understand what you want probably something like JUnit (a unit for the testing) can be ok for you.
http://www.junit.org
JUnit is a unit for testing the code, can be fully integrated with eclipse.
In few word, for each part of the code you should write one or more test to check if its behaviour is correct. Once you've written some test you can run them automatically with an user-friendly interface that tell you how many test are failed, how many passed and what kind of error there are.
Why is useful to test each little (stupid?) thing of my code?
Imagine you have a working code (your code).
Imagine you have someone working on it (your students).
How can a user be sure that any change he/she do it's ok with the existing code?
He/she should run the program and check each functionality one by one in order to find an error.
You understand that this is impossible. so JUnit do it for you with just one click (and if you want also in background).
So the student can add the code, and run the tests in order to see if the pre-existing code is still working.
The students can also write his own test to test automatically if all is ok. JUnit in facts allow you to test each part of the code without depending from the other, in this way, you can also test an internet connection without being connected to the net just "mocking" the connection.
I let this part without explanation because It is a long and complicated part. I gave you that "input" to stimulate you to read about testing and XP programming.
Ah, and welcome to stackoverflow! if you like this answer and think that answer correct to your question you can check it with the little check on the left.
I am currently developing a simple plugin that retrieves results from a Jenkins build. I am extending Notifier and using build.getResults() to get the information. However, when I upload my plugin, I can't set it as a post-build action.
When I run my builds, they break on build.getResults() since I am trying to get the results while the build is still running.
What can I do to properly get the build result ?
Best thing is to look at existing plugins which use Notifier extension point (click to expand implementing plugins list).
Check that you have the Descriptor implemenation (inner) class, as well as config.jelly. Also check jenkins.out and jenkins.err logs for any exceptions (such as malformed config.jelly).
Edit: Actually, Notifier subclass of this plugin looks really simple as Notifiers go: https://wiki.jenkins-ci.org/display/JENKINS/The+Continuous+Integration+Game+plugin , see especially its GamePublisher.java and corresponding config.jelly, and it's GameDescriptor.java, which has been made a full outer class (often descriptor is inner class). Also if you want options into Jenkins' Global configuration, you need a global.jelly, but if you don't have such options, that is something you can just leave out (unlike config.jelly, which you must have for Notifier even if it is empty, like here).
As a general note, it can be really annoying when things do not work, and you do not get any error, your stuff simply is just not displayed by Jenkins... If you just want to get things to work for you, using Groovy build step might be easier, but if you want to get things to work for others, then doing a decent full plugin reduces support requests.
Since this sounds so simple, are you sure you need a plugin ? Take a look at using a Groovy Postbuild step instead; they're much easier to write. There are some good usage examples in the link. If you decide you really need a plugin, see if you can extend an existing one rather than writing your own; it's an easier way to understand the ins and outs of Jenkins plugin writing.
Is there an IDE/Tool/script/something that can show call hierarchy and/or data flow in Scala+Java programs (preferably from source code).
Or (as a backup plan) is there a tool that can show it using Java bytecode? (And preferably give the option to go to source code, if provided by user).
All that, preferably integrated into an IDE and/or Maven :-)
The requirement to support Scala is crucial in this question. I Already know of and use such tools for Java, in 3 IDEs. They do not work very well (actually: at all) when Scala is involved.
TIA
Poor man's call hierarchy: Comment the method out and see where your red squigglies show up. [/me ducks]
Did you tried Eclipse?
SBT can do that. You'll have to check it out to get more information, because I haven't done it.
EDIT
Sorry, I confused things. SBT can generate component dependencies, not call hierarchy.