package leigh.build;

import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;
import leigh.mecha.util.UniversalJob;

import java.io.*;
import java.util.Properties;

/**
 * Iterate through the provided path, find all build.gradle files containing a semantic version, and if any versions
 * contain suffixes, modify them to drop the suffixes and then re-write the property file back to disk.
 *
 * @author Alex Leigh
 */
public class ReleaseApp {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(ReleaseApp.class);

    public static void main(String[] args) throws IOException {
        if (args.length != 1) {
            logger.info("Usage: ReleaseApp properties");
            System.exit(UniversalJob.RET_BADARGS);
        }

        File propFile = new File(args[0]);
        Properties p = new Properties();
        p.load(new BufferedInputStream(new FileInputStream(propFile)));
        if (VersionUtil.release(p, "_ver")) {
            p.store(new FileOutputStream(propFile), "Updated with ReleaseApp");
        }
    }
}
