I’m in the process of looking at taking some examples that are currently in one format (NOT Mavenized – actually in ANT form) and trying to find an automated way to munge them into something that Eclipse can comprehend. Though I have several years of Java and other odd languages, doing this in Java sounds like using a sledgehammer to drive a nail.
I’ve been looking into scripting languages such as Ruby, Python, Perl, and so on. I have no experience with any of them, but would be happy to learn.
How can I take an example in one format (directory or directory with files) and restructure it into something approximating an Eclipse project? For example, I’d like to take a tree with the following structure
dir my_example
- build.xml
- deployment.xml
- jboss-esb-unfiltered.xml
- log4j.xml
- readme.txt
and convert it to
dir1 my_example_eclipse
- dir src
- [empty]
- dir esbcontent
- dir META-INF
- deployment.xml
- jboss-esb-unfiltered.xml
- log4j.xml
- readme.txt
In addition, I need the ability to create certain hidden files that Eclipse needs. One of these is the .project file like this:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>helloworld</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
</natures>
</projectDescription>
How would I create a text file with one of these scripting languages?
Thanks in advance.
This should do what you need (in Python):
This should work on multiple OSes. This could have been written shorter, but would be more confusing to a newbie. No attempt is made to catch exceptions. For example, os.mkdirs might fail if the new directory already exists.
Change
base_pathandmaven_dirsbefore running.