Eclipse: Aspectj Maven plugin execution not covered by lifecycle

7 06 2014

aspectj-logoMaven and eclipse integration is not straightforward. There is one m2e eclipse plugin giving support for Maven itself and a lot of other Eclipse plugins to support Maven plugins used in pom.xml.

One of these plugins is the org.codehaus.mojo:aspectj-maven-plugin – the aspectJ Maven plugin. So when you use it in pom.xml and import into eclipse, you will get error:

Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.2:compile (execution: default, phase: process-sources), Maven Project Build Lifecycle Mapping Problem

To fix it

Install AspectJ Maven Eclipse plugin from Eclipse update site (Via eclipse Help -> Install new software…):

http://dist.springsource.org/release/AJDT/configurator/

Prerequisities

To install above maven plugin Eclipse needs to have AspectJ Development Tools Eclipse Plugin and AspectJ compiler installed. If you do not have it, you need to install as well. This is where you can find it (install via eclipse Help -> Install new software…):

http://download.eclipse.org/tools/ajdt/43/update/

Did I help you?
I manage this blog and share my knowledge for free, sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!

Advertisements




Tutorial: Set up Android UIAutomator in Eclipse

8 02 2014

Remember my post about MonkeyTalk? UIAutomator seems to be even better automated andrroid app test suite – it does not require any dedicated libs in Android project and can work in any application (even if you do not have access to its source code. All this because it is nested in Android OS, so it can control anything and emulate clicks in any application.

This post will help you to set up basic UIAutomator test.

Note: remember that UIAutomator will work only in Android 4.1+

Instruction is based on this reference.

1. Create new Java Project
Create new Java project that will generate jar with UIAutomator tests. This jar will be later deployed on the Android device (Not: jar, not apk). The jar is separate from application. Thanks to that, it can automate clicks not only in the app view, but whole Android.

2. Add JUnit library
UIAutomator is built upon the JUnit, so you need to add it to build path by

Right click > Properties > Java Build Path > Add Library > JUnit > select JUnit3

3. Add UIAutomator library
On the same window, click ‘Add External JAR’ and navigate to SDK directory > platforms. There choose the android.jar and uiautomator.jar from latest platform available

4. Create sample uiautomator test case
Add new file to the src directory in your project:
New > JUnit Test Case

Make it extend the UiAutomatorTestCase, give it name you like. Mine test will try to automatically click the device back button:

public void testBackPress() {
	getUiDevice().pressBack();
}

5. Create test project build configuration
Android tools can create ant build.xml file containing the build configuration for test project. It is issued by this command:

/tools/android create uitest-project -n  -t 1 -p 
-n is the project name param
-p is the path to your project param
-t is the target installed on your system

To set the -t param, according to help in this post, execute:

android list targets

and choose the highest id installed, in my case it is:

id: 34 or "Google Inc.:Google APIs:19"
     Name: Google APIs
     Type: Add-On
     Vendor: Google Inc.
     Revision: 2
     Description: Android + Google APIs
     Based on Android 4.4.2 (API level 19)

As a result you should be informed, that the build.xml file was created

6. Build project with ant

Navigate to project directory and build project with ant from command line:

ant build

To avoid the

android-sdk\tools\ant\uibuild.xml:183: Error running javac.exe compiler

Ensure that your default JAVA_HOME points to JDK installation, not the JRE, and check if your compiler is in the PATH. Try to type “javac” in the command prompt. If javac is not found, then you should put your bin directory in the PATH.
For example, in Windows:

SET PATH=c:/jdk1.5.0_07/bin;%PATH%

Then restart eclipse if needed. What is more – I needed to reboot my computer to make it work and find javac!

7. Copy test project to your device

You can do it with file explorer or use adb push command like this:

adb push  /sdcard/

replacing the with path to .jar file generated by and build

8. Run test
execute adb shell command to run the particular class in test:

adb shell uiautomator runtest /sdcard/ -c

which for example may look like:

adb shell uiautomator runtest /sdcard/MyUIAutomatorTest.jar -c com.looksok.uiautomator.TestSampleBackButton

You can even run particular method in chosen class by calling the method name like that:

-c com.looksok.uiautomator.TestSampleBackButton#testMethod

Did I help you?
I manage this blog and share my knowledge for free, sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





Always Remember to override toString() [Effective Java]

5 10 2013

Default implementation of toString() in Object class is class name, ‘@’ sign and hash code. All of it is not enough when you want to print or debug object state if the class is used by you. Even worse, if your class is used by external developers with API you provide.

How to do it in eclipse?

No – you don’t have to implement it by yourself :) Eclipse is here for help. To override toString() simply:

  • in Eclipse editor right click -> Source -> Generate toString()…

or with shortcuts

  • in editor press Alt + Shift + S -> press ‘S’

What you need to remember when overriding toString() manually?

  • Return as much information as needed (that may be interesting)
  • It is obligatory in data classes
  • if you decide that your toString() provide result in format presentable to the user, then you have to clearly document output print format and remain it unchanged for life. In that case you need to be aware that toString() output may be printed in UI somewhere
  • beside toString() you still need to provide accessor methods for class fields, if needed

Effective Java

Effective Java (Joshua Bloch) is a book with advanced Java programming techniques that make Java code more robust and readable. I am currently reading it and this is why these [Effective Java] posts come up here. These are summaries of chapters that are most valuable in my opinion.

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





Android tutorial: custom button background (created programatically)

29 06 2013

This post is an extension to the Android custom button layout tutorial.

Creating custom button background is described here. There, in point 3, I show how to build an XML file with selector background.

The selector file has definitions of backgrounds that are shown depending on a button state: if button is pressed, then show pressed background, else show normal background

XML definition is suitable when you know at a compile time which images you will use. When you have to decide at runtime (for example build layout dynamically) – it is not enough. Then you can substitute the XML file with programatically created object: StateListDrawable.

It means that this XML:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" android:drawable="@drawable/button_left_pressed"/>
    <item android:state_focused="true" android:drawable="@drawable/button_left_pressed"/>
    <item android:drawable="@drawable/button_left_normal"/>
</selector>

is exactly the same, interchangeable and can be created in Java code this way:

int buttonPressedResId = R.drawable.button_left_pressed;
int buttonNormalResId = R.drawable.button_left_normal;

Resources resources = getApplicationContext().getResources();

StateListDrawable states = new StateListDrawable();
states.addState(new int[] {android.R.attr.state_pressed}, resources.getDrawable(buttonPressedResId));
states.addState(new int[] {android.R.attr.state_focused}, resources.getDrawable(buttonPressedResId));
states.addState(new int[] { }, resources.getDrawable(buttonNormalResId));
((Button) findViewById(R.id.calc_addPerson_button)).setBackgroundDrawable(states);

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





Technology Radar: May 2013

1 06 2013

The new technology report was released recently. Prepared by the ThoughtWorks Technology Advisory Board, points out emerging technologies and trends on IT market.

Find the report here (in pdf)

It helps to assess if the novelty you’ve recently found is ready to adopt or was not tested enough yet. There you’ll find out that NoSQL are ready to go, however Node.js not really – still it is good for fast prototyping and mocks but not for production.

The report gathers data in a nice visual graphs and explains each item shortly. Here is the graph sample

TechRadar graph

TechRadar graph

Do you like my blog?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





iOS Tutorial: make call from app programatically

9 02 2013

Making call from iOS requires just two lines of code. These will make call without asking a user, and after the call has ended, the control will not come back to your app (see how to come back to app in further section)

Make a call initiated from app

- (void) dialNumber:(NSString*) number{
	number = [@"tel://" stringByAppendingString:number];
	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:number]];
}

Notice, that the number string should contain digits only.

Come back to your app after call has ended

The prefix:

@"telprompt://"

used instead of prefix:

@"tel://"

in phone number URL will cause two things:

  • user will be prompted if he wants to make a call
  • after the call, the control will come back to your app

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





iOS tutorial: hide keyboard after return / done key press in UITextField

2 02 2013

When user finished editing text in UITextField it is good practice to hide keyboard after Done / Return key press. Another way of hiding keyboard is touch detected anywhere outside the UITextField. Both solutions are described below

1. Hide keyboard after Done / Return button press

To detect the confirm button press you need to implement UITextFieldDelegate protocol’s optional method textFieldShouldReturn:. So in header file add protocol declaration:

@interface MyViewController : UIViewController <UITextFieldDelegate>

Point the delegate that will handle protocol’s events in viewDidLoad():

self.playerNameField.delegate = self;

And in implementation file implement textFieldShouldReturn:

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    if (theTextField == self.playerNameField) {
        [theTextField resignFirstResponder];
    }
    return YES;
}

This will resignFirstResponder (means: hide keyboard) for playerNameField.

2. Hide keyboard after touch outside of UITextField

This is somehow separate to previous point, however also hides the keyboard when it is not needed. To do it you need to detect the touch on the screen. There is method in UIResponder that you should override to be notified about touch event:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    //hides keyboard when another part of layout was touched
    [self.view endEditing:YES];
    [super touchesBegan:touches withEvent:event];
}

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!








%d bloggers like this: