[TOOL] Join source files into one (java)

Hey,

I wrote a small python script to take several java source files and create a single one with correct imports.

There is the link, juste place it in the folder which contains your src folder (or modify the variable srcFolder) and run it. This will create (or replace) a file named packed.java (or modify the variable dstName)

https://github.com/TidyMaze/JoinSrc

I hope you will find it useful, feel free to improve it or to make it working for other languages and ask for push :slight_smile:

See you

5 Likes

Huge ! Can you make a .bat version ? :smiley:

I won’t since it will make it OS-dependant, what would be the interest ?

Just to not install Python on my computer :wink:

Nice tool :slight_smile:

You could include an exe built with py2exe, I hear it works quite well.

For all java geeks same with maven

just add tag in your children class to remove import with replacel goal, otherwise it will throws errorsin the resulting class :
/begin import/
import java.*;
/end import/

After you just have to execute mvn yuicompressor:compress; mvn replacer:replace;

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

<groupId>your groupid</groupId>
<artifactId>artifactID</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>your_name</name>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <nosuffix>true</nosuffix>
                <aggregations>
                    <aggregation>
                        <!-- remove files after aggregation (default: false)
                        <removeIncluded>true</removeIncluded>
                        -->
                        <!-- insert new line after each concatenation (default: false) -->
                        <insertNewLine>true</insertNewLine>
                        <output>${basedir}/src/main/final/Player_v${version}.java</output>
                        <!-- files to include, path relative to output's directory or absolute path-->
                        <!--inputDir>base directory for non absolute includes, default to parent dir of output</inputDir-->
                        <includes>
                            <!-- include your class -->
                            <include>${basedir}/src/main/java/YourClass.java</include>
                        </includes>
                        <!-- files to exclude, path relative to output's directory
                        <excludes>
                          <exclude>**/*.pack.js</exclude>
                          <exclude>**/compressed.css</exclude>
                        </excludes>
                        -->
                    </aggregation>
                </aggregations>
            </configuration>
        </plugin>
        <plugin>
            <!-- remove your import -->
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <version>1.5.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>replace</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <ignoreMissingFile>true</ignoreMissingFile>
                <file>${basedir}/src/main/final/Player_v${version}.java</file>
                <outputFile>
                    ${basedir}/src/main/final/Player_v${version}.java
                </outputFile>
                <regex>true</regex>
                <regexFlags>
                    <regexFlag>DOTALL</regexFlag>
                    <regexFlag>MULTILINE</regexFlag>
                </regexFlags>
                <!-- this the token i am using to remove import, you can add your own -->
                <token>\/\*\*begin import\*\*\/.*?\/\*\*end import\*\*\/</token>
                <value></value>
            </configuration>
        </plugin>
    </plugins>
</build>

Thanks, this is very useful
Not sure why it was not in the original script but I found it necessary to replace “public class” with “class”
sorry for my bad Python:
elif ligne.startswith(‘public class’):
tabCode.append(ligne.replace(‘public class’, ‘class’))