All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.kuriositaet.pomerator.POMGenerator Maven / Gradle / Ivy

The newest version!
package de.kuriositaet.pomerator;

import util.io.IO;
import util.json.JSON;

import java.util.List;
import java.util.Map;

import static de.kuriositaet.pomerator.Stuff.obj2xml;
import static de.kuriositaet.pomerator.Stuff.p;

/**
 * Created by a2800276 on 2017-01-25.
 */
public class POMGenerator {
	static class POMConfig {
		String groupId;
		String artifactId;
		String version;
		String projectName;
		String description;
		String url;
		String licenseName;
		String licenseURL;
		String scmURL;
		String developerEmail;
		String developerName;
		String developerURL;
		String developerId;
		List dependencies;

		POMConfig() {}
		POMConfig(Map m) {
			this();
			populate( m );
		}
		void populate(Map m) {
			groupId        = get(m,"groupId");
			artifactId     = get(m,"artifactId");
			version        = get(m,"version");
			projectName    = get(m,"projectName");
			description    = get(m,"description");
			url            = get(m,"url");
			licenseName    = get(m,"licenseName");
			licenseURL     = get(m,"licenseURL");
			scmURL         = get(m,"scmURL");
			developerEmail = get(m,"developerEmail");
			developerName  = get(m,"developerName");
			developerURL   = get(m,"developerURL");
			developerId    = get(m,"developerId");
			dependencies   = (List) m.get("dependencies");
		}
		static String get(Map m, String k) {
			return (String)m.get(k);
		}
	}
	// arg:
	// 1 : groupId
	// 2 : artifactId
	// 3 : version
	// 4 : project name
	// 5 : description
	// 6 : url
	// 7 : license name
	// 8 : license url
	// 9 : scm url
	// 10 : developer email
	// 11 : developer name
	// 12 : developer url
	// 13 : developer id
	// 14 : dependencies
	static String template =
			"          \n"+
			"   4.0.0\n"+
			"\n"+
			"   %1$s\n"+
			"   %2$s\n"+
			"   %3$s\n"+
			" \n"+
			"  %4$s\n"+
			"  %5$s\n"+
			"  %6$s\n"+
			"  \n"+
			"    \n"+
			"      %7$s\n"+
			"      %8$s\n"+
			"    \n"+
			"  \n"+
			"  \n"+
			"    %9$s\n"+
			"  \n"+
			"  \n"+
			"    \n"+
			"      %10$s\n"+
			"      %11$s\n"+
			"      %12$s\n"+
			"      %13$s\n"+
			"    \n"+
			"  \n"+
			"  \n"+
			"    %14$s\n"+
			"  \n"+
			"\n";


	public static void generatePOM (String fn, POMConfig cfg) {
		// arg:
		// 1 : groupId
		// 2 : artifactId
		// 3 : version
		// 4 : project name
		// 5 : description
		// 6 : url
		// 7 : license name
		// 8 : license url
		// 9 : scm url
		// 10 : developer email
		// 11 : developer name
		// 12 : developer url
		// 13 : developer id
		// 14 : dependencies
		String pom = String.format(template,
				cfg.groupId,
				cfg.artifactId,
				cfg.version,
				cfg.projectName,
				cfg.description,
				cfg.url,
				cfg.licenseName,
				cfg.licenseURL,
				cfg.scmURL,
				cfg.developerEmail,
				cfg.developerName,
				cfg.developerURL,
				cfg.developerId,
				obj2xml(cfg.dependencies, 2 , "dependency").trim()

		);

		IO.writeAll(pom.getBytes(), fn);
	}

	public static POMConfig loadCfg(String fn) {
		String json = IO.readAllString( fn );
		Map jsoncfg = (Map) JSON.parse( json );
		POMConfig cfg = new POMConfig(jsoncfg);
		return cfg;
	}

	public static void main (String [] args) {
//		POMConfig cfg = loadCfg( args[0] );
//		generatePOM( "fuckyou.pom", cfg );
		p(template);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy