Can I enforce code style policy in eclipse IDE for c++ code? - eclipse

I want that whatever code style i defined in eclipse editor ..should be followed by coders, so can i enforce it as program will not even build without satisfying all the rules???

It think that's not possible out of the box with Eclipse.
There are two problems to solve:
Check the source code for satifying the rules.
There is no support for this in CDT, but there seem to be other tools (see discussion A free tool to check C/C++ source code against a set of coding standards?).
Integrate the check into the build process.
To catch all possible build chains (Internal CDT Build, Makefiles,...), you need to hook into the build process with your own builder which is executed before the CDT build. This requires a plugin to be written.
If your build is using makefiles, it should be rather easy to integrate such a tool into the build process.

Related

is there any demo for eclipse cdt api use?

I want to use the eclipse cdt api to resolve c++ code AST tree for code analysis.
base on the blow question answer, I try to create a default Workspace and project by java code. The Workspace init method require many IDE source support, when i fix one resouce issue, another comes. is there any demo for this?
Using CDT without Eclipse
If you want to parser a single source file, it is enough to use cdt.core only. If you want to use the higher level(semantic) you need to replace a lot dependences about those IDE packages. I did a project using Eclipse-JDT and use JavaCore and Workspace to generate IJavaProject. It is similar with CDT. I also do some research about static-code-analysis using JDT/CDT.

Eclipse CDT: combine a make project with a cmake one

I have a standard C project in Eclipse CDT. Naturally it uses make. I have decided to add some JSON support to my application to be able to load/save its configuration in a readable format that the user (if such desire occurs) can alter those manually and/or through an external tool. I've looked up two options so far namely Jansson and Json-C. The problem is that both are using cmake, which, if I recall correctly, can be imported in Eclipse CDT without problems (though in itself CDT can't create cmake projects).
I was thinking of adding a script for the pre-build step of my project that runs cmake (as an external command) and sets up the JSON library (static and/or dynamic) so that when the build process of my projects starts the library file will be available.
Is there a better way to combine a cmake with a make project in Eclipse CDT? I know that cmake basically generates a Makefile but I've never done such a combination before.
Even if there is a JSON C library somewhere out ther that uses make (I'm 99.9% sure there is such thing :D) I'd still like to know how to tackle this situation.

Using CDT without Eclipse

I want to use CDT parser in a project. The project would be a command-line, stand-alone project, i.e., not an Eclipse plugin.
All solutions that I've seen requires using a IWorkspace. But, I want to use the CDT parser on single files outside eclipse. Is there any way to do that?
It depends what you mean by "without Eclipse".
CDT's code is built on top of the Eclipse Platform, so you're going to need to be running an application that includes the Eclipse Platform. However, there's no reason that application can't be a command-line application. These are called "headless" applications in the Eclipse community, and you can find many tutorials for making one (here's one).
Requiring an IWorkspace shouldn't be a problem. You can e.g. create a workspace and a project in a temporary folder, and copy the code to be analyzed there.
If, for some reason, you really want to use just CDT's parser in an application that doesn't include the Eclipse Platform, you can probably copy the parser code from CDT, and replace any dependencies it has on the Eclipse Platform with your own implementations. However, this is likely to be a more labour-intensive approach, and I wouldn't recommend it.

Compare to the IDE for Java,do we still need Ant?

Not long before I had digged into Ant and use it doing simple practice(compile,unit test,package).Now my usual work is under Eclipse for java development,the usual work can all be simply done through Eclipse' function:in-time compiling、click button to deploy、various wizard..
So I am wondering under Eclipse do we have a need for Ant.
And if it is, at which aspect should we use Ant along with Eclipse.
Building applications is not about just building them in your IDE. You need to setup an automated build and deploy method that can be run for, say, continuous integration and deployment. The built package has to be deloyed to various environments and finally production. You cannot build them out of your own box. You cannot build it out of your IDE. You need separate build system. That is where build tools like ANT come in.
Also note that the capabilities of IDEs for doing build, deploy is limited and that is not their strength. It is, however, possible to make use of ANT and its build scripts and run them out of eclipse. This way, you have a single set of scripts for both your local ( developer ) build and the main build process. With ANT being JAVA based, you can also suit your build tool to your needs by writing custom tasks etc.
Also, when you make use of something as standard as ANT for your build system, you can move to a different IDE like Intellij IDEA and still make use of the build system that you know.
Do you need Ant if you can build through the IDE? Of course not! You can see that yourself.
Should you still have a IDE independent build with standard tools? Of course!
Note I didn't say Ant. There are a number of build tools such as Maven or Gradle that are made to build Java programs. However, there are reasons why you want an IDE independent build system:
You have a Continuous Integration Server: You do have one. Right? If you don't get one. A Continuous Integration Server automatically builds your project (and runs every test) each time a change is committed to the version control system. It catches mistakes. It also provides an OFFICIAL BUILD. No more It worked on my machine! excuses. If the Continuous Integration Server can't build it and successfully run the tests, the software isn't good.
You have others who need to work with your project on a different computer in a different environment: The problem with IDEs is that its specific to your system. Someone else checks out your project, and they may be using a different IDE. They maybe have a slightly different setup. An independent build scripting language like Ant guarantees that they can rebuild your project as intended.
If you share a project with someone else, you need an independent standard method way of being able to build that project and to know exactly what is required for that build to work. IDEs can hide that information.
I am a benchmark tester using Ant everyday. Our environment has 7 test machines and 1 console machine. For each test run, the ant script updates the working copy, restarts the database, build the product and the Grinder with proper properties and deploy them to the machines, and starts them and the monitoring softwares. With the 1000-line-buildfile, I can just type in an "ant A B C D E"-like line in the terminal on the console machine. I don't think it's a good idea to do this in a IDE like eclipse or NetBeans or anything else.
Also, in my company's product, ant is widely used. We use ant to build sample data for the benchmark test; we use ant to update Tomcat which is going to be bundled with our product; we also use ant to build and run selenium tests.
What's more, when you want to release the source code, including the IDE project files is not a good idea because there are a lot of IDEs. And what if the user just want to get a fresh build from your latest code (if you don't provide nightly build)? Providing a set of ant (or other build tool) buildfiles is a good idea. With this, you can manage your classpath for the build.
The shortest answer here wold be flexibility. The IDEs may came with pre-defined functionalities and may even allow you to choose some options using wizards. It is like generating html with Dreamweaver or such tools. It will never be as flexible as the pure thing. For example NetBeans uses Ant underneath.
Quoted from: Netbeans: Build Tools
The default NetBeans IDE project system is built directly on top of
the Ant build system. All of the project commands, such as "Build
Project" and "Run File in Debugger", call targets in the project's Ant
script. You can therefore build and run your project outside the IDE
exactly as it is built and run inside the IDE.
Even after you use tools for that purpose you are most likely still to brush up. So, what I am saying is, what the IDEs do for you is only a subset of what you can do with the pure ant or maven( if you use it). For simple tasks such as compile and run, IDEs do pretty much a good job! But if you have a use case as complex as deploying on CI IDEs won't help you. You need the whole flexibility of your build tools.

GWT Post build command in Eclipse

I am starting getting used to Eclipse, but I have much more experience with Visual Studio. In Visual Studio it is possible to run auto commands after the build has finished.
Now I am creating a GWT project and several other projects at once in one solution (or workspace) in Eclipse. Some files which are compiled with the GWT project needs to be copied to another location when they have been compiled. I am currently doing this manually and would like to do it automatically. I am not doing it often, since the project works fine in debug mode (...?gwt.codesvr=localhost:9997).
But where is the location for executing a post build command for a GWT project in eclipse? Is it possible?
Just open project properties, choose 'Builders' item and click on 'New...' button.
Good question! I'm using Eclipse since about 2003, and I remember that I also wanted a functionality like that back then. However, I got so used to using ant for any serious build, that I completely forgot about it.
There is some useful ant integration in Eclipse (e.g. the ant view), and if you create your GWT project with webAppCreator you already get a few good ant targets you can build upon.
It would still be nice sometimes to have something more GUI-like to do simple multi-step builds with Eclipse. I haven't found anything like that yet, but it's absolutely possible that it exists, especially as a plugin.