Package winterwell.utils.io

Source Code of winterwell.utils.io.Version

package winterwell.utils.io;

import java.io.File;

import winterwell.utils.Environment;
import winterwell.utils.Key;
import winterwell.utils.Printer;
import winterwell.utils.StrUtils;
import winterwell.utils.TodoException;

/**
* An object for version info. Pulls info from the {@link Environment}.
*
* @author daniel
* @Deprecated Not such a good idea on 2nd thoughts. delete when ITI is done
*/
@Deprecated
public final class Version {

  private static final Key<Version> KEY_VERSION = new Key<Version>("version");
  static {
    Environment.putDefault(KEY_VERSION, new Version());
  }

  public static String getVersion() {
    Environment env = Environment.get();
    Version v = env.get(KEY_VERSION);
    if (v.props.length == 0)
      return "";
    // special case for only one bit of versioning info
    if (v.props.length == 1)
      return "v" + Printer.toString(env.get(v.props[0]));
    StringBuilder sb = new StringBuilder();
    sb.append("v");
    for (Key k : v.props) {
      Object value = env.get(k);
      assert value != null : k;
      String kv = value.toString();
      sb.append(k + "=" + kv.replace('_', '-') + "_");
    }
    StrUtils.pop(sb, 1);
    String sv = FileUtils.safeFilename(sb.toString(), false);
    return sv.replace("__", "_");
  }

  /**
   * TODO add a version tag to a file name, e.g. myfile.html to
   * myfile.v01.html
   *
   * @param normal
   * @return
   */
  public static File getVersion(File normal) {
    throw new TodoException();
  }

  public static void setVersioningInfo(Key... properties) {
    Environment.get().get(KEY_VERSION).props = properties;
  }

  private Key[] props = new Key[0];

  private Version() {
  }

}
TOP

Related Classes of winterwell.utils.io.Version

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.