2..27 – noch nicht angekommen

So, nun bin ich in der zweiten Woche meiner Auszeit. Einige Leute fragen schon, wie es läuft und wie es geht und was ich so mache…

Meine Antwort derzeit ist, dass ich noch nicht angekommen bin. Es fällt mir zum Beispiel schwer 2 Stunden am Stück an einem Buch zu lesen. Mich überkommt immer noch so eine Unruhe.

Aber ich habe schon ein paar Erfahrungen gemacht, die ich ohne diese Pause nicht gemacht hätte. Da ist dieses Projekt vert.x . Ich lese jeden Eintrag in der Google Group, jeden Twitter Pieps von @TimFox und jedes Ticket was aufgemacht wird und bekomme so sehr viel von dem Projekt mit. Auch andere kämpfen mit Git und nicht jeder Schalter  ist sofort klar. Warum ist die vorgeschlagen Verzeichnisstruktur von Maven so nett und warum sollte man nicht grössere Codeänderungen ankündigen und dann lange nicht machen. Alle warten darauf und sie kommen nicht…

Und mir geht der Code von dieser einen Klasse nicht aus dem Kopf. Da ist dieser Code in org.vertx.java.deploy.impl.cli.Starter :

    private Starter(String[] sargs) {
	String vertxVersion = String.format("vert.x %s", System.getProperty("vertx.version", "0.0.0-UNKNOWN!"));
    if (sargs.length < 1) {
      displaySyntax();
    } else {
      String command = sargs[0].toLowerCase();
      Args args = new Args(sargs);
      if ("version".equals(command)) {
        log.info(vertxVersion);
      } else {
        if (sargs.length < 2) {
          displaySyntax();
        } else {
          String operand = sargs[1];
          switch (command) {
            case "version":
              log.info(vertxVersion);
              break;
            case "run":
              runVerticle(false, operand, args);
              break;
            case "runmod":
              runVerticle(true, operand, args);
              break;
            case "install":
              installModule(operand, args);
              break;
            case "uninstall":
              uninstallModule(operand);
              break;
            default:
              displaySyntax();
          }
        }
      }
    }
  }
...

  private void runVerticle(boolean module, String main, Args args) {
    boolean clustered = args.map.get("-cluster") != null;
    if (clustered) {
      log.info("Starting clustering...");
      int clusterPort = args.getInt("-cluster-port");
      if (clusterPort == -1) {
        clusterPort = 25500;
      }
      String clusterHost = args.map.get("-cluster-host");
      if (clusterHost == null) {
        clusterHost = getDefaultAddress();
        if (clusterHost == null) {
          log.error("Unable to find a default network interface for clustering. Please specify one using -cluster-host");
          return;
        } else {
          log.info("No cluster-host specified so using address " + clusterHost);
        }
      }
      vertx = new DefaultVertx(clusterPort, clusterHost);
    }
    String repo = args.map.get("-repo");
    mgr = new VerticleManager(vertx, repo);

    boolean worker = args.map.get("-worker") != null;

    String cp = args.map.get("-cp");
    if (cp == null) {
      cp = ".";
    }

    // Convert to URL[]

    String[] parts;

    if (cp.contains(CP_SEPARATOR)) {
      parts = cp.split(CP_SEPARATOR);
    } else {
      parts = new String[] { cp };
    }
    int index = 0;
    final URL[] urls = new URL[parts.length];
    for (String part: parts) {
      try {
        URL url = new File(part).toURI().toURL();
        urls[index++] = url;
      } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Invalid path " + part + " in cp " + cp) ;
      }
    }

    String sinstances = args.map.get("-instances");
    int instances;
    if (sinstances != null) {
      try {
        instances = Integer.parseInt(sinstances);

        if (instances != -1 && instances < 1) {
          log.error("Invalid number of instances");
          displaySyntax();
          return;
        }
      } catch (NumberFormatException e) {
        displaySyntax();
        return;
      }
    } else {
      instances = 1;
    }

    String configFile = args.map.get("-conf");
    JsonObject conf;

    if (configFile != null) {
      try {
        String sconf = new Scanner(new File(configFile)).useDelimiter("\A").next();
        try {
          conf = new JsonObject(sconf);
        } catch (DecodeException e) {
          log.error("Configuration file does not contain a valid JSON object");
          return;
        }
      } catch (FileNotFoundException e) {
        log.error("Config file " + configFile + " does not exist");
        return;
      }
    } else {
      conf = null;
    }

    Handler doneHandler = new Handler() {
      public void handle(String id) {
        if (id == null) {
          // Failed to deploy
          mgr.unblock();
        }
      }
    };
    if (module) {
      mgr.deployMod(main, conf, instances, null, doneHandler);
    } else {
      mgr.deploy(worker, main, conf, urls, instances, null, doneHandler);
    }

    addShutdownHook();
    mgr.block();
  }

Ich habe in der letzen Woche so viel über diesen Zeilen nachgedacht. Meine erste Reaktion war: “Das muss umgebaut werden.” Der Boolean “module” ist nicht gut: lieber zwei Methoden runVertical und runModule – ja und dann muss das Auslesen von den Konfigurationsparametern an anderer Stelle gemacht werden… und überhaupt lässt sich das Ding derzeit mit ”

vertx version version version version

aufrufen. Kein Fehler – komisch. Ich werde das umschreiben … macht das Sinn? Dies sind keine funktionalen Erweiterungen – und bekomme ich es so hin, dass es verständlicher sein wird? Unsicherheit!

 

It’s never to late for git.

If not already done, every software developer must try GIT – the fast, distributed version control system. It’s such a nice and useful tool. Once every week I find a new little nice feature.

The last month I used the git-client together with a svn-remote repository and I will never use the svn client again. It is so handy to have the full history of the repository on my notebook.  I can commit my changes every time to my local repository and merging/branching is just fun.  I’m so much faster …

Here my path to git

Here my favorite git client in action (the command line client 😉 :

git command line

There are plugins for eclise, idea, windows, mac… So give it a try and have fun!

And if you want to have the little nice prompt add the following lines to your .bashrc:

...
#-----------------------------------
# git in prompt
#-----------------------------------
        RED="[33[0;31m]"
     YELLOW="[33[0;33m]"
      GREEN="[33[0;32m]"
       BLUE="[33[0;34m]"
  LIGHT_RED="[33[1;31m]"
LIGHT_GREEN="[33[1;32m]"
      WHITE="[33[1;37m]"
 LIGHT_GRAY="[33[0;37m]"
 COLOR_NONE="[e[0m]"

function parse_git_branch {
        git rev-parse --git-dir &> /dev/null
        git_status="$(git status 2> /dev/null)"
        branch_pattern="^# On branch ([^${IFS}]*)"
        remote_pattern="# Your branch is (.*) of"
        diverge_pattern="# Your branch and (.*) have diverged"

        if [[ ! ${git_status} =~ "working directory clean" ]]; then
                state="${RED}?"
        else
                state="${GREEN}?"
        fi

        # add an else if or two here if you want to get more specific
        if [[ ${git_status} =~ ${remote_pattern} ]]; then
                if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
                        remote="${YELLOW}?"
                else
                        remote="${YELLOW}?"
                fi
        fi

        if [[ ${git_status} =~ ${diverge_pattern} ]]; then
                remote="${YELLOW}?"
        fi

        if [[ ${git_status} =~ ${branch_pattern} ]]; then
                branch=${BASH_REMATCH[1]}
                echo " (${branch})${remote}${state}"
        fi
}
function prompt_func() {
        previous_return_value=$?;
        prompt="${GREEN}${USER:-$(type whoami >/dev/null && whoami)}@$(type uname >/dev/null && uname -n) ${BLUE}[w${GREEN}$(parse_git_branch)${BLUE}]${COLOR_NONE} "
        if test $previous_return_value -eq 0
        then
                # PS1="${prompt}? "
                PS1="${prompt} \$ "
        else
                #PS1="${prompt}${RED}?${COLOR_NONE}"
                PS1="${prompt}${RED}\$ ${COLOR_NONE}"
        fi
}

PROMPT_COMMAND=prompt_func

I found this script at github and changed it a little bit. Thx to trapni.

Ein Herz für FLOSS

wenn mein Herz für etwas höherschlägt (ausgenommen natürlich meine Frau :)), dann für freie und offene Software (FLOSS). Ich mag z.B. den Sourcecode anschauen, wenn ich die API Beschreibung nicht verstehe oder sich eine Methode nicht so verhält wie ich es mir vorstelle, ich mag die Begeisterung der Leute die an FLOSS mitarbeiten und die vielen netten Werkzeuge die ich jeden Tag verwende, ich mag das Gemeinschaftsgefühl und den Geist offener Standards, ich mag wie in diesem Umfeld Ideen ausgetauscht werden und Wissen weitergegeben wird, ich mag es einfach und deshalb unterstütze ich auch Bruce Perens Aufruf.