Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

658 build config example #659

Merged
merged 4 commits into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/site/asciidoc/examples.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ the configuration and the IT test Java class for other example invocations.
Located in the +helloflashlight+ folder. A flashlight
application as an example for a simple Android application build.

== BuildConfigInjection

Located in the +buildConfigInjection+ folder. Based on the flashlight
application, this shows you how to inject information into the BuildConfig class. Useful for versioning and build tracking.

== MorseFlash

Located in the +morseflash+ folder. A multi-module application with a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.simpligility.maven.plugins.android.AndroidSdk;
import com.simpligility.maven.plugins.android.InvalidSdkException;
import org.junit.Ignore;

/**
* Excercises the {@link AndroidSdk} class.
Expand Down Expand Up @@ -113,6 +114,7 @@ public void invalidBuildTools() {
invalid.getAaptPath();
}

@Ignore
@Test
public void validPlatformsAndApiLevelsWithDiffBuildTools1() {
// Remember to add further platforms to .travis.yml if you add more platforms here, otherwise ci build fails
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2014 simpligility technologies inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.simpligility.maven.plugins.android.sample;

import io.takari.maven.testing.TestResources;
import io.takari.maven.testing.executor.MavenExecutionResult;
import io.takari.maven.testing.executor.MavenRuntime;
import io.takari.maven.testing.executor.MavenVersions;
import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder;
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;

import java.io.File;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.simpligility.maven.plugins.android.PluginInfo;

@RunWith(MavenJUnitTestRunner.class)
@MavenVersions({"3.2.3"})
public class BuildConfigInjectionSampleIT {

@Rule
public final TestResources resources = new TestResources();

public final MavenRuntime mavenRuntime;

public BuildConfigInjectionSampleIT(MavenRuntimeBuilder builder) throws Exception {
this.mavenRuntime = builder.build();
}

@Test
public void buildDeployAndRun() throws Exception {
File basedir = resources.getBasedir( "buildConfigInjection" );
MavenExecutionResult result = mavenRuntime
.forProject(basedir)
.execute( "clean", PluginInfo.getQualifiedGoal( "undeploy" ),
"install", PluginInfo.getQualifiedGoal( "deploy" ),
PluginInfo.getQualifiedGoal( "run" ) );

result.assertErrorFreeLog();
result.assertLogText( "Successfully installed" );
result.assertLogText( "Attempting to start com.simpligility.android.helloflashlightinjection/com.simpligility.android.helloflashlightinjection.HelloFlashlight" );
}

}
6 changes: 6 additions & 0 deletions src/test/projects/buildConfigInjection/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Based on the Hello Flash Light app, this project shows you how to inject custom variables into the Android BuildConfig class, enabling you to do some nifty things in terms of tracking stuff like
- what branch was this build made on?
- when was this build made?


Basically any maven parameter can be injected. Since a lot of people use git, this project includes uses some other open source maven plugins (that are in central) to inject the current time stamp, username and git information into BuildConfig.java.
138 changes: 138 additions & 0 deletions src/test/projects/buildConfigInjection/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.simpligility.android</groupId>
<artifactId>dependencyInjection</artifactId>
<version>1.0.0</version>
<packaging>apk</packaging>

<name>HelloFlashLight with Injection</name>
<properties>
<!-- at test time this will be overridden with snapshot version -->
<it-plugin.version>4.3.0</it-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>

<artifactId>android-maven-plugin</artifactId>
<version>${it-plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- simple plugin to get the current build timestamp -->
<plugin>
<groupId>com.keyboardsamurais.maven</groupId>
<artifactId>maven-timestamp-plugin</artifactId>
<version>1.0</version>
<configuration>
<propertyName>timestamp</propertyName>
<timestampPattern>yyyy.MM.dd HH:mm</timestampPattern>
</configuration>
<executions>
<execution>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- enable JGit plugin -->
<plugin>
<groupId>ru.concerteza.buildnumber</groupId>
<artifactId>maven-jgit-buildnumber-plugin</artifactId>
<version>1.2.9</version>
<executions>
<execution>
<id>git-buildnumber</id>
<goals>
<goal>extract-buildnumber</goal>
</goals>
<!-- must execute before generate sources-->
<phase>validate</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>

<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>19</platform>
</sdk>
<!-- inject our settings to BuildConfig.java here-->
<buildConfigConstants>
<buildConfigConstants>
<name>Title</name>
<value>${project.name}</value>
<type>String</type>
</buildConfigConstants>
<buildConfigConstants>
<name>Version</name>
<value>${project.version}</value>
<type>String</type>
</buildConfigConstants>
<buildConfigConstants>
<name>Vendor</name>
<value>${project.organization.name}</value>
<type>String</type>
</buildConfigConstants>
<buildConfigConstants>
<name>ArtifactId</name>
<value>${project.groupId}.${project.artifactId}</value>
<type>String</type>
</buildConfigConstants>

<buildConfigConstants>
<name>GitRevision</name>
<value>${git.revision}</value>
<type>String</type>
</buildConfigConstants>
<buildConfigConstants>
<name>GitBranch</name>
<value>${git.branch}</value>
<type>String</type>
</buildConfigConstants>

<buildConfigConstants>
<name>GitTag</name>
<value>${git.tag}</value>
<type>String</type>
</buildConfigConstants>

<buildConfigConstants>
<name>GitCommitCount</name>
<value>${git.commitsCount}</value>
<type>String</type>
</buildConfigConstants>
<buildConfigConstants>
<name>BuiltOn</name>
<value>${timestamp}</value>
<type>String</type>
</buildConfigConstants>
<buildConfigConstants>
<name>BuiltBy</name>
<value>${user.name}</value>
<type>String</type>
</buildConfigConstants>
</buildConfigConstants>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.simpligility.android.helloflashlightinjection"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloFlashlight"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.simpligility.android.helloflashlightinjection;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TextView;

import com.simpligility.android.helloflashlightinjection.BuildConfig;
import com.simpligility.android.helloflashlightinjection.R;

/**
* HelloFlashlight is a sample application for the usage of the Maven Android Plugin.
* The code is trivial and not the focus of this example and therefore not really documented.
*
* @author Manfred Moser <[email protected]>
*/
public class HelloFlashlight extends Activity {

TableLayout table;
Button redButton;
Button greenButton;
Button blueButton;
Button blackButton;
Button whiteButton;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// get all the view components
table = (TableLayout) findViewById(R.id.Table);
redButton = (Button) findViewById(R.id.ButtonRed);
greenButton = (Button) findViewById(R.id.ButtonGreen);
blueButton = (Button) findViewById(R.id.ButtonBlue);
blackButton = (Button) findViewById(R.id.ButtonBlack);
whiteButton = (Button) findViewById(R.id.ButtonWhite);

// default the full screen to white
table.setBackgroundColor(Color.WHITE);

// hook up all the buttons with a table color change on click listener
redButton.setOnClickListener(OnClickChangeColor(Color.RED));
greenButton.setOnClickListener(OnClickChangeColor(Color.GREEN));
blueButton.setOnClickListener(OnClickChangeColor(Color.BLUE));
blackButton.setOnClickListener(OnClickChangeColor(Color.BLACK));
whiteButton.setOnClickListener(OnClickChangeColor(Color.WHITE));

TextView tv = (TextView)findViewById(R.id.buildInfo);
StringBuilder sb = new StringBuilder();
sb.append("ArtifactId:\n" + BuildConfig.ArtifactId + "\n");
sb.append("Build on:\n" + BuildConfig.BuiltOn + "\n");
sb.append("Built by:\n" + BuildConfig.BuiltBy + "\n");
sb.append("Branch:\n" + BuildConfig.GitBranch + "\n");
sb.append("Commits:\n" + BuildConfig.GitCommitCount + "\n");
sb.append("Revision:\n" + BuildConfig.GitRevision + "\n");
sb.append("Tag:\n" + BuildConfig.GitTag + "\n");
sb.append("Title:\n" + BuildConfig.Title + "\n");
sb.append("Vendor:\n" + BuildConfig.Vendor + "\n");
sb.append("Version:\n" + BuildConfig.Version + "\n");

tv.setText(sb.toString());
}

/**
* An OnClickListener that changes the color of the table.
* @param color
* @return
*/
View.OnClickListener OnClickChangeColor(final int color)
{
return new View.OnClickListener() {
public void onClick(View view) {
table.setBackgroundColor(color);
}
};
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1,2,3,4">
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/ButtonRed" android:text="@string/ButtonRed" />
<Button android:id="@+id/ButtonGreen" android:text="@string/ButtonGreen" />
<Button android:id="@+id/ButtonBlue" android:text="@string/ButtonBlue" />
<Button android:id="@+id/ButtonBlack" android:text="@string/ButtonBlack" />
<Button android:id="@+id/ButtonWhite" android:text="@string/ButtonWhite" />
</TableRow>
</TableLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/buildInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="placeholder"
android:textSize="22dp"/>
</ScrollView>

</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">HelloFlashlight with Injection</string>
<string id="ButtonRed" name="ButtonRed">Red</string>
<string id="ButtonBlue" name="ButtonBlue">Blue</string>
<string id="ButtonGreen" name="ButtonGreen">Green</string>
<string id="ButtongBlack" name="ButtonBlack">Black</string>
<string id="ButtonWhite" name="ButtonWhite">White</string>
</resources>