@@ -0,0 +1,1972 @@
+package com.winterwell.bob.tasks;%0A%0Aimport java.io.BufferedWriter;%0Aimport java.io.File;%0Aimport java.util.Map;%0Aimport java.util.Properties;%0A%0Aimport com.winterwell.bob.BuildTask;%0Aimport com.winterwell.utils.StrUtils;%0Aimport com.winterwell.utils.containers.Containers;%0Aimport com.winterwell.utils.io.FileUtils;%0Aimport com.winterwell.utils.log.Log;%0Aimport com.winterwell.utils.time.Time;%0Aimport com.winterwell.utils.web.XStreamUtils;%0A%0Apublic class MakeVersionPropertiesTask extends BuildTask %7B%0A%0A%09private File configDir;%0A%09private File appDir;%0A%0A%0A%09public MakeVersionPropertiesTask() %7B%0A%09%09appDir = FileUtils.getWorkingDirectory();%0A%09%09configDir = new File(%22config%22).getAbsoluteFile();%0A%09%7D%0A%09%0A%09public MakeVersionPropertiesTask setAppDir(File appDir) %7B%0A%09%09this.appDir = appDir;%0A%09%09return this;%0A%09%7D%0A%09%0A%09public MakeVersionPropertiesTask setConfigDir(File localConfigDir) %7B%0A%09%09this.configDir = localConfigDir;%0A%09%09return this;%0A%09%7D%0A%09%0A%09@Override%0A%09protected void doTask() throws Exception %7B%0A%09%09if ( ! configDir.exists()) %7B%0A%09%09%09Log.i(LOGTAG, %22make directory %22+configDir);%0A%09%09%09configDir.mkdirs();%0A%09%09%7D%0A%09%09// create the version properties%0A%09%09File creolePropertiesForSite = new File(configDir, %22version.properties%22);%0A%09%09Properties props = creolePropertiesForSite.exists()? FileUtils.loadProperties(creolePropertiesForSite)%0A%09%09%09%09%09%09%09: new Properties();%0A%09%09// set the publish time%0A%09%09props.setProperty(%22publishDate%22, new Time().toISOString());%0A%09%09try %7B%0A%09%09%09// set info on the git branch%0A%09%09%09String branch = GitTask.getGitBranch(appDir);%0A%09%09%09props.setProperty(%22branch%22, branch);%0A%09%09%09// ...and commit IDs%0A%09%09%09Map%3CString, Object%3E info = GitTask.getLastCommitInfo(appDir);%0A%09%09%09for(String k : info.keySet()) %7B%0A%09%09%09%09Object v = info.get(k);%0A%09%09%09%09if (v==null) continue;%0A%09%09%09%09props.setProperty(%22lastCommit.%22+k, v.toString());%0A%09%09%09%7D%0A%09%09%7D catch(Exception ex) %7B%0A%09%09%09// oh well;%0A%09%09%09Log.d(%22git.info.error%22, ex);%0A%09%09%7D%0A%0A%09%09// save%0A%09%09BufferedWriter w = FileUtils.getWriter(creolePropertiesForSite);%0A%09%09props.store(w, null);%0A%09%09FileUtils.close(w);%0A%09%7D%0A%0A%7D%0A

refactor version.properties code into a Bob task