google-java-format: format whole project - java

I'm using google-java-format to format Java code according to Google Java Style. However, I only find documentation and examples showing how to format one file using the CLI.
Is there a built-in way to format an entire Java project directly using the CLI (without looping using a shell script or something else)?

After a quick read of the google-java-format documentation,
it is intended to function one file at a time
or on a group of files,
each listed on the command line.
There appears to be plugins for intelliJ and Eclipse.
If you need to format every file in your project,
you will need to do one of the following:
Feed a list of every file. This is fairly easy with a script; use xargs.
If you use IntelliJ, check the plugin options. It likely has some kind of selection mechanism.
As above, the Eclipse plugin likely has some kind of selection mechanism, as well.

Related

Read Parquet Files using Apache Arrow

I have some Parquet files that I've written in Python using PyArrow (Apache Arrow):
pyarrow.parquet.write_table(table, "example.parquet")
Now I want to read these files (and preferably get an Arrow Table) using a Java program.
In Python, I can simply use the following to get an Arrow Table from my Parquet file:
table = pyarrow.parquet.read_table("example.parquet")
Is there an equivalent and easy solution in Java?
I couldn't really find any good / working examples nor any usefull documentation for Java (only for Python). Or some examples don't provide all needed Maven dependencies. I also don't want to use a Hadoop file system, I just want to use local files.
Note: I also found out that I can't use "Apache Avro" because my Parquet files contains column names with the symbols [, ] and $ which are invalid characters in Apache Avro.
Also, can you please provide Maven dependencies if your solution uses Maven.
I am on Windows and using Eclipse.
Update (November 2020): I never found a suitable solution and just stuck with Python for my usecase.
it's somewhat an overkill, but you can use Spark.
https://spark.apache.org/docs/latest/sql-data-sources-parquet.html

Add copyright at the end of Java class while writing documentation?

I'm writing documentation for my java file. In that documentation, I want to add some html links at the end of each generated file. For that, what I have to use while writing java documentation?
If you are using Eclipse as IDE, you can use the plugin JAutodoc:
http://jautodoc.sourceforge.net/
To add a default text at the beggining of each text file.
According to the javadoc manual (can't find a newer version right now), you should use -footer when you generate your java API documentation from the CLI, for instance:
javadoc -footer "<b>Copyright 2015 Lakshmi Prasanna</b><br>" com.mypackage
Here's a similar example, but that uses -header instead.
Now, if you use a good IDE, at the very least it should allow you to type that somewhere in the project settings. Back in the day Eclipse wasn't very flexible, so I had to make an Ant script (yuck).
EDIT:
One limitation with this approach is that the CLI -options depend on the tool. This works with the standard javadoc command but might not work with another vendor's doclet. However I'm not sure there's a universal way to achieve what the OP asked.
Anyway, it seems to be: NOT -footer but -bottom.

Is there an equivalent of "vim: set ft=cpp:" or "-*- c++ -*-" for Eclipse?

There are occasions when there is some code in a file that does not have any extension. Such files will have code written in a single language, but each such file may be written using a different language (like C, C++, assembly language, wiki markup, and HTML for example). Similarly, the problem also happens when there is a common extension in the file name, but different files use different programming languages.
The problem I want to solve is to avoid making each individual developer that has checked out a workspace from having to figure out what kind of file a source file is (there is either no extension, or the extension does not imply the source language used). To do so, the author of the file has the responsibility of putting the right magic in the file to let the file be opened properly. Since Eclipse has the ability to disable the formatter based on some embedded text in the file, I thought it should be possible to specify the file type as well. The Open With feature allows an individual developer to change how a file is interpreted, but must be done again each time a new workspace is checked out.
In Emacs or Vim, I can place magic strings at the top of the file to indicate how I want the file to be rendered within the editor. For example:
/* -*- c++ -*- */
/* vim: set ft=cpp: */
Is there some equivalent magic for Eclipse? My attempts at finding a solution constantly pointed out how to disable the formatter. Clearly, my inexperience with Eclipse is capping my Google-Fu.
If there is no file extension, then things are a little harder. Instead of double-clicking to open the file, right-click -> Open with... -> other -> C++ editor. This will remember your choice for that file only.
ref:Quick way to set custom syntax highlighting in Eclipse
Of all the free plugins providing Vim functionality within Eclipse that are available as of 8 November 2013, namely
Vrapper
ViPlugin
Vimplugin
Eclim
...none seem to support modelines. Nevertheless, a Vrapper user asked more than a year ago if such support existed.
Note that Eclim is a special case. It might solve your problem since it allows you to use Vim as an embedded Eclipse editor. However, from within the Vim instance, Eclipse's key bindings will not work. I guess it's a trade-off between access to features and convenience. From Eclim's website:
Please be aware that the embedded vim does not behave like a standard
eclipse editor. It's a separate program (vim) embedded into eclipse,
so eclipse features are provided by eclim's vim plugins and not the
usual eclipse key bindings, context menus, etc. For those that just
want vim like key bindings in their eclipse editors, vrapper is an
excellent alternative which provides exactly that.
There used to be a commercial plugin called Viable but development seems to have stalled since 2011. Also, some users report that it breaks under Juno.
Finally, although your question is about Eclipse, it turns out NetBeans does have a plugin that supports modelines. It's called jVi. Another plugin for Netbeans is VIEX, in case you're interested.
Hope that helps!
Sources:
What vim plugins are available for Eclipse?
What are some good plugins for developing Java in VIM?
I'm not aware of any Eclipse plugin able to deal with vim-style modelines. However, AnyEdit gives you a pretty precise control over tab size and related prefs. And you can always search the marketplace.

How to add external tags file into CEDET in Emacs

I tried to use CEDET to get auto completion in Emacs and that works fine for C/C++. But I cannot find anything about how to use CEDET with Java without the help of JDEE, which is thought out of date and not compatible to CEDET 1.1. I got a tags file using utility found here but I don't know how to integrate that into CEDET system. According to CEDET's website, that's possible. But they don't explain how to do it. Is there someone willing to answer this question?
Here is some sample of the tags file generated by that utility:
java.applet.Applet$AccessibleApplet
protected java.applet.Applet$AccessibleApplet(java.applet.Applet)
public java.applet.Applet$AccessibleApplet.getAccessibleRole() returns javax.accessibility.AccessibleRole
public java.applet.Applet$AccessibleApplet.getAccessibleStateSet() returns javax.accessibility.AccessibleStateSet
It is possible to have CEDET pull in tags from a .jar file. It works by using javap to extract the tags in text form, and then it parses that data.
It isn't very easy to set up since in CEDET, the concept of where to find your library files is part of EDE, the project management system, not the parser and smart completion system. The only Java based project supported in CEDET 1.1 is Android.
The basics is to first enable the javap database by loading it with (require 'semanticdb-javap) in CEDET 1.1, or (require 'semantic/db-javap) in the bzr version of CEDET.
Once you've done that, you can configure it via the cedet-java-classpath-extension. I'm a little fuzzy on the details of what happens next, but folks have reported success on the mailing list.
If you use CEDET from the bzr repository, there is the ede-java-root project, which is similar to the ede-cpp-root project. That project type lets you configure what your library path is. The doc for that is in the ede/java-root.el file with the project type, and shows you the basics of how to use it.

Java library to create cabinet files on Unix?

Is there a Java library to create cabinet files on Unix. I don't need any compression support. I just want to create a plain cab file using Java.
Something similar to cablib (http://sourceforge.net/projects/cablib/) which can only be used for reading cab files would be perfect.
If there is really no library can I use a feasible work around? E.g. create a ZIP file and somehow convert it into a CAB file?
If there is really no library can I use a feasible work around?
Comments have suggested using the Linux Icab tool.
E.g. create a ZIP file and somehow convert it into a CAB file?
The ZIP file format is different in too many respects for there to be a simple transformation to turn a ZIP file into a CAB file.
Edit: The answer below isn't a pure java solution. Ant's CAB task documentation says it relies on a 3rd-party tool: Either MS's "CABARC" or the open-source "libcabinet", which seems to no longer exist. So there is no benefit to this approach compared to a 3rd-party system call.
Previous Answer (read above first):
If you need a pure java way of creating cab files (not extracting them), you can use ant's built-in "cab" task.
This gives you a few options:
Call the ant task from within your java code by using ant's
Launcher class;
Find the source code for the task definition (here) , and remove references to the ant context to create your own Cab extract utility
Run ant via a system call.

Categories