Setting Up Xtend with Maven and eclipse (Luna)

Xtend is currently my favourite alternative language for the JVM (closely followed by Kotlin). Unfortunately, I did not find a good guide of how to set up a Maven project within eclipse (Luna) which uses Xtend.

Specifically the following guide will allow you to allow you to write test cases in Xtend for your existing Java projects. A great way to get started with Xtend I suppose.

The following describes the necessary steps.

  • Install the Xtend plugin for eclipse as described here.
  • Add the xtend-maven-plugin to your pom.xml as follows:
<plugin>
    <groupId>org.eclipse.xtend</groupId>
    <artifactId>xtend-maven-plugin</artifactId>
    <version>2.7.1</version>
    <executions>
        <execution>
            <goals>
                <goal>testCompile</goal>
            </goals>

            <configuration>
                <testOutputDirectory>${basedir}/src/test/java</testOutputDirectory>
            </configuration>

        </execution>
    </executions>
</plugin> 
  • Also add a dependency to the Xtend runtime libraries
<dependency>
    <groupId>org.eclipse.xtend</groupId>
    <artifactId>org.eclipse.xtend.lib</artifactId>
    <version>2.7.1</version>
    <scope>test</scope>
</dependency>
  • Right click the project and select Maven / Update Project … and update the project.
  • Right clock the project and select Properties
  • Go to the Xtend / Compiler page
  • Set as the ouput director src/test/java

  • Go to the folder src/test/xtend. If the folder does not exist, create it.
  • Right clock the folder src/test/xtend and select Build Path / Use As Source Folder
  • Create a package in the new src/test/xtend folder and right click the package. Select New / Xtend class and define a class such as the following:
package de.mxro.async.map.tests
 

import org.junit.Assert
import org.junit.Test
 

class TestThatNumbersAreEqual {
    
    @Test
    def void test() {
        Assert.assertTrue(3 == 3)
    }
    
    
}
  • Immediately after you save the class a translated class should be created in the folder src/test/java

Now, have fun writing tests using Xtend’s concise syntax – while not affecting any step of your build and development workflow!

To see an example configuration in a complete project, also check out async-map on GitHub.

A Comparison of Data Models in BaaS (Backend-as-a-Service)

While Backed-as-a-Service (BaaS) – and their stepbrothers PaaS – offerings should sensibly support various domain-specific data models for the application they support, these services are inherently built on a ‘meta’ data model. This meta data model lays the constraints for all domain-specific data and should thus be an important consideration in selecting or not selecting a BaaS solution.

I have sifted through the documentation of five popular BaaS solutions and tried to uncover the fundamental model of data underlying these platforms. My findings are presented below.

In a Nutshell

All examined solution but Firebase have a ‘three-tier’ data model where similar JSON documents are aggregated in collections or classes, which allow the effective querying of these documents. These collections of JSON documents in turn are aggregated in databases or per application. Some solutions provide additional mechanisms for defining connections between JSON documents (Parse, usergrid). Firebase features the most unique model; where all data is stored in one very big, hierarchical JSON document.

Parse

Parse stores data internally as flat JSON Documents, called ParseObject, with have the restriction that keys must be alphanumeric strings. Parse automatically creates ‘classes’ for ParseObjects, grouping objects with similar properties. Classes and all objects associated to them belong to applications, which can be defined on the Parse web interface. In addition, Notably, Parse allows for various types of relationships between ParseObjects for one-to-many and many-to-many relationships.

Firebase

Firebase stores data as JSON documents. Essentially, a data store in Firebase is one large JSON document. Data stores are associated with subdomains such as <my store>.firebase.com.

Kinvey

Fundamentally, Kinvey stores data as collections and entities. Entities are essentially JSON documents. Collections belong to applications. Internally, data is stored in a MongoDB cluster.

Apache usergrid_

The Apache usergrid_ documentation did not make it easy to find out about the data model underlying the platform. I think the data is primarily stored as JSON documents named entities on the platform. These in turn (I think) are stored in collections. Collections themselves belong to applications. Notably, Apache usergrid has some support for graph-like data as relationships between entities. Internally, Apache usergrid is based on Cassandara and provides good support for relational/SQL type queries.

BaasBox

Data in BaasBox is stored as JSON documents called documents. These documents are grouped in collections. Collections are ultimately stored in databases. Since every BaasBox server represents one application, databases belong to the application configured for the server.

References

Parse

ParseObject JavaDoc

Parse JavaDoc

Parse Documentation – Data & Security

Firebase

Firebase – How It Works

Firebase – Understanding Data

Kinvey

A backend’s representation inside Kinvey

Android – Data Store

Apache usergrid_

Entity.java in usergrid Java client library

Apache usergrid Documentation

BaasBox

BaasDocument JavaDoc

BaasBox Documentation – Database Management

UML Diagrams created with creately.com.

 

 

 

 

Force Android Studio to Update Maven Snapshot Dependencies

Problem

You are using Gradle to build your Android Studio project and you have linked Maven SNAPSHOT modules.

When you build your project, Gradle/Android Studio does not grab the latest version of the SNAPSHOT module but instead uses a cached version.

Solution

Add the following to your build.gradle:

configurations.all {

resolutionStrategy {

cacheChangingModulesFor 0, ‘seconds’

}

}

References

Gradle DSL Documentation – Resolution Strategy

Gradle Documentation Chapter 50, Section 50.9.22 Refresh

Gradle Forum – Use latest version of changing module

Access Apache on VirtualBox OS from Host OS

Problem

You have a RHEL or CentOS 6 VirtualBox Virtual Machine and a Windows or other host and would like to access a web server on the VM from the Host OS.

Solution

Assure that the Apache Web Server is available and started on the guest OS:

`sudo httpd start`

Assure that firewall allows the guest OS to handle web requests.

Type ` sudo system-config-firewall` and enable the WWW service.

Configure port forwarding for the VM. Go to the VM settings in the Oracle VM VirtualBox Manager / Page ‘Network’.

Click on the button [Port Forwarding] and add an entry such as the following:

Now, on your host OS, you should be able to see the Apache Server test page when opening `http://localhost:8080` in a browser.

Troubleshooting

Since every system is configured differently there might be some problems you encounter. If you don’t see the test page, you could try the following:

  • Disable SELinux by opening the file ` /etc/selinux/config` and setting the configuration to ` SELINUX=disabled` (see a more detailed guide here)
  • This tutorial assumes that you use the default NAT network adapter for you VM. If you use a ‘host-only’ or ‘bridged’ connection, the process will be a bit different.

References

Stackoverflow – How to SSH to a VirtualBox guest externally through a host? Very helpful, also read the comments

Stackoverflow – Apache restart causes DocumentRoot must be a directory, even though it is a directory and there seem to be no privilege issues

CentOS Board – Basic firewall config (just port 80 and ssh 22)

 

Import GitHub project to Android Studio

Problem

You have an existing GitHub project and would like to import it to Android Studio.

Solution

Perform the following steps to import your project.

Step 1: Install git for Windows

It can be downloaded for free from git-scm.com.

Most settings available during the installation process should be compatible with Android studio. Just choose the settings you deem the most appropriate.

Step 2: Link git executable to Android Studio

Open Android Studio and got to Settings. In the Setting dialog open the page Version Control / Git. Here define the path to the git executable you have just installed.

Step 3: Get the Path to your Repository from Github

Go to the GitHub page and get the HTTPs path to your repository. For instance:

https://github.com/mxro/WallOfTheWiseAndroid.git

Step 4: Import the Git project to Android Studio

Go to Android Studio and go to Menu / VCS / Checkout from Version Control / Git

Paste the HTTPS path you obtained from GitHub in the previous step and click on [Clone].

Provide your GitHub username and password.

Now the project should be imported to Android Studio and you should be able to commit and push future changes back to GitHub.

References

Android Studio Git Tutorial (Part 1) « Wii’s Blog

github – How to clone a remote git repository with Android Studio? – Stack Overflow

Setup Android Developer Studio | devroyal.de

Setting Up eclipse Luna with Maven for Android

As of August 2014, don’t even try this.

Officially, the Google Eclipse plugin supports Eclipse 4.4 (Luna) at present. However, in order to be able to create projects which are both Maven projects and Android projects you will need to install the m2e-android plugin. This currently does not support eclipse Luna. Probably, if you create a new Android project based on the archetype suggested by the m2e-android plugin, you might get errors such as:

  • …R cannot be resolved to a variable
  • Plugin execution not covered by lifecycle configuration: com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.2:generate-sources (execution: default-generate-sources, phase: generate-sources)
  • Project configurator “me.gladwell.eclipse.m2e.android.androidDevelopmentToolsProjectConfigurator” is not available. To enable full functionality, install the project configurator and run Maven->Update Project Configuration.
  • Plugin execution not covered by lifecycle configuration: com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.2:proguard (execution: default-proguard, phase: process-classes)

My recommendation is to use Android Studio.

You can easily add Maven dependencies to projects in Android Studio. Just locate the ‘build.gradle’ file in your application directory and add a compile dependency.

Convert Dynamically Sized VirtualBox VDI Hard Drive to Fixed Size

The Problem

You have got a dynamically sized, VDI virtual hard drive in VirtualBox and would like to convert it into a fixed size hard drive.

You are using Windows.

The Solution

  • Locate VBoxManage.exe on your machine. It should be in the VirtualBox program directory (usually found under C:\Program Files\Oracle\VirtualBox) .
  • Open a command prompt (e.g. by searching for “cmd”+Enter Windows 7 or 8).
  • Go to the directory in which VBoxManage.exe is located by typing something like:

cd “C:\Program Files\Oracle\VirtualBox”

  • Convert your dynamically sized hard drive to a fixed size harddrive using the command:

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe clonehd <path-to-source-vdi> <path-to-destination-vdi> –variant Fixed

This might take a while depending on the size of your drive. You probably have used this drive as part of a virtual machine. In order to use the new hard drive you need to go through a few more steps.

  • Open the virtual box manager, go to settings for your machine and remove the old (dynamically sized) drive from the SATA controller for this machine.

  • Go back to the command line and display a list of your currently registered hard drives:

VBoxManage.exe list hdds

  • Manually remove your old drive from the list by running the command:

C:\Program Files\Oracle\VirtualBox>vboxmanage closemedium disk <UUID of your drive> –delete

ATTENTION: This will delete your old hard drive file. You may want to make a backup copy of the image before running this operation.

  • Rename the new (fixed size) hard drive file to the name of your original vdi file. For instance, if your old drive’s name was ‘myhdd-10GB.vdi’ and your new fixed size drive’s name is ‘fixed-10GB.vdi’, rename ‘fixed-10GB.vdi’ to ‘myhdd-10GB.vdi’
  • Go to the VirtualBox Manager and add the freshly renamed drive to the SATA controller for your VM.

Now you should be able to start your VM with the new drive and (hopefully) enjoy the performance benefits of a fixed size drive.

References

HOWTO: Convert VDIs Between Fixed-Sized and Dynamic In VirtualBox

Stackoverflow – Convert VirtualBox dynamic VDI disk image to static, fixed VDI

coderwall – Purge deleted hard disks from Virtual Box