Skip to content
This repository

Issue 97 #89

Merged
merged 10 commits into from almost 2 years ago

2 participants

Pappy STĂNESCU Manfred Moser
Pappy STĂNESCU

Here is an workaround addressing the problem with missing resources in META-INF.

As already stated, the problem is not in android-maven-plugin itself but in com.android.sdklib.build.ApkBuilder which filters any path starting with META-INF .

This patch copies the META-INF based resources from dependencies into the APK as specified in the plugin configuration by ${android.metaIncludes}.

There are still issues with the obfuscated code because proguard is executed in an earlier stage and any resource supposed to be modified by proguard will remain unchanged

pom.xml
@@ -19,14 +19,14 @@
19 19
     <modelVersion>4.0.0</modelVersion>
1
Manfred Moser Collaborator
mosabua added a note January 16, 2012

Please update your pull request to not include these pom changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/main/java/com/jayway/maven/plugins/android/phase09package/ApkMojo.java
@@ -368,8 +482,9 @@ public boolean accept(File dir, String name) {
368 482
     }
369 483
 
370 484
     private File removeDuplicatesFromJar(File in, List<String> duplicates) {
371  
-        File target = new File(project.getBasedir(), "target");
372  
-        File tmp = new File(target, "unpacked-embedded-jars");
  485
+//        File target = new File(project.getBasedir(), "target");
  486
+        String target = project.getBuild().getOutputDirectory();
  487
+        File tmp = new File(target, "unpacked-wembedded-jars");
2
Manfred Moser Collaborator
mosabua added a note January 16, 2012

is this a typo?

Pappy STĂNESCU
pa314159 added a note January 17, 2012

yes, it was a typo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/main/java/com/jayway/maven/plugins/android/phase09package/ApkMojo.java
((24 lines not shown))
  279
+	/**
  280
+	 * <p>
  281
+	 * Pattern for additional META-INF resources to be packaged into the apk.
  282
+	 * </p>
  283
+	 * <p>
  284
+	 * The APK builder filters these resources and doesn't include them into the apk.
  285
+	 * </p>
  286
+	 * <p>
  287
+	 * This leads to bad behaviour of dependent libraries relying on these resources, for instance service discovery
  288
+	 * doesn't work.
  289
+	 * </p>
  290
+	 * <p>
  291
+	 * See also <a href="http://code.google.com/p/maven-android-plugin/issues/detail?id=97">Issue 97</a>
  292
+	 * </p>
  293
+	 * 
  294
+	 * @parameter expression="${android.metaIncludes}" default-value=""
5
Manfred Moser Collaborator
mosabua added a note January 16, 2012

This should be updated to follow the config parameter convention as documented in code conventions on the wiki with an Apk config class probably and an expression of android.apk.metaIncludes

Pappy STĂNESCU
pa314159 added a note January 17, 2012

I'm aware of that convention, but I followed the convention used by other configuration parameters used by this mojo, see for instance extractDuplicates.

Creating a Dex configuration should cover the rest of the Apk configurations as well - whichever is applicable

Manfred Moser Collaborator
mosabua added a note January 17, 2012

There is a dex one already... I would have to look. In general though the old "convention" is only there because we have not gotten around to completely clean it up yet. So any new parameter should follow the new approach..

Pappy STĂNESCU
pa314159 added a note January 18, 2012

I meant an Apk configuration

I added it with the last commit and also included two "old" configurations plus a deprecation mechanism

Manfred Moser Collaborator
mosabua added a note January 18, 2012

Thats great. I hope to test this out a bit more soon and merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/main/java/com/jayway/maven/plugins/android/phase09package/ApkMojo.java
@@ -255,8 +256,121 @@ void createApkFile(File outputFile, boolean signWithDebugKeyStore) throws MojoEx
255 256
             doAPKWithCommand(outputFile, dexFile, zipArchive, sourceFolders, jarFiles,
256 257
                 nativeFolders, signWithDebugKeyStore);
257 258
         }
  259
+
  260
+// ISSUE-97
1
Manfred Moser Collaborator
mosabua added a note January 16, 2012

remove these comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/main/java/com/jayway/maven/plugins/android/phase09package/ApkMojo.java
((19 lines not shown))
258 274
     }
259 275
 
  276
+// ISSUE-97
  277
+// vvv
1
Manfred Moser Collaborator
mosabua added a note January 16, 2012

remove this comment please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Manfred Moser
Collaborator

So sorry it has taken so long to update. I just got the proguard pull request and the related config work on the proguard, run, pull and push mojos done. There is still lots outstanding ... could you refactor your approach here to use the new ConfigHandler that is now in master?

Manfred Moser
Collaborator
mosabua commented May 03, 2012

Are you going to refactor this as requested to be based off the latest master so we can pull this in?

Manfred Moser
Collaborator
mosabua commented May 21, 2012

Ping?

Pappy STĂNESCU

Pong!

Back to this, been busy last weeks and I'm glad to see my ConfigHelper has been improved

This patch is far behind the original master (3.2.x)... How should I proceed with?

Manfred Moser
Collaborator
mosabua commented May 22, 2012

Maybe pull down master to your machine. Create a new branch off master and apply a patch with the required changes to it. Once you got it tested create a new pull request. And we will just close this one without merging.

added some commits May 23, 2012
Pappy STĂNESCU Merge branch 'master' into issue-97 69e347f
Pappy STĂNESCU @ConfigPojo improvement
added ability to specify the parsed parameter prefix in the @ConfigPojo
annotation
87a2d05
Pappy STĂNESCU

Done, I managed to merge changes from the original master, so we can keep this pull request as is...

You may also have a look at the "modified" branch of this fork, which completely solves the issues with META-INF inclusions. Fill free to get anything you want from there.

Pappy STĂNESCU Updated Apk with the new ConfigHandler
Previous code used the ConfigHelper which was able to handle
configuration parameters deprecation.

Since the new ConfigHandler doesn't provide this mechanism - or I could
not find it - only the new "metaIncludes" parameter follows the POJO
configuration rules.

Other parameters are kept as they are and should be modified by the actual
maintainer of this class.
8c86102
Manfred Moser
Collaborator
mosabua commented May 23, 2012

Looks good. Pulling in.

Manfred Moser mosabua merged commit 5198b8c into from May 23, 2012
Manfred Moser mosabua closed this May 23, 2012
Manfred Moser
Collaborator
mosabua commented May 23, 2012

Btw. can you reveal your name and website or so for the changelog?

Manfred Moser
Collaborator
mosabua commented May 23, 2012

Oh and in terms of further enhancement please create a new pull request and we can discuss there..

Pappy STĂNESCU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 10 unique commits by 1 author.

Jan 08, 2012
Pappy STĂNESCU Changed the artefact version and pointed the repository location to m…
…y own nexus... DO NOT merge this change!
8d2e97b
Pappy STĂNESCU Add resources specified by ${android.metaIncludes} to the final APK,
right after apkbuilder invocation

TODO: must investigate proguard invocation as well
71b197a
Jan 09, 2012
Pappy STĂNESCU honour ${android.extractDuplicates} c8f82e1
Jan 17, 2012
Pappy STĂNESCU rolled back to original pom.xml e7bfd4b
Pappy STĂNESCU followed mosabua's notes on github, excepting ${android.apk.metaInclu…
…des}
edc7f89
Jan 18, 2012
Pappy STĂNESCU - created APK configuration for metaIncludes, extractDuplicates and s…
…ourceDirectories

- added deprecation mechanism for extractDuplicates and sourceDirectories
- added ConfigHelper to parse mojo configurations + two simple tests
2408ecd
Jan 24, 2012
Pappy STĂNESCU handle ILA in ConfigHelper, relaxing deprecated parameters constraints 3f01036
May 23, 2012
Pappy STĂNESCU Merge branch 'master' into issue-97 69e347f
Pappy STĂNESCU @ConfigPojo improvement
added ability to specify the parsed parameter prefix in the @ConfigPojo
annotation
87a2d05
Pappy STĂNESCU Updated Apk with the new ConfigHandler
Previous code used the ConfigHelper which was able to handle
configuration parameters deprecation.

Since the new ConfigHandler doesn't provide this mechanism - or I could
not find it - only the new "metaIncludes" parameter follows the POJO
configuration rules.

Other parameters are kept as they are and should be modified by the actual
maintainer of this class.
8c86102
This page is out of date. Refresh to see the latest.
6  src/main/java/com/jayway/maven/plugins/android/config/ConfigHandler.java
@@ -22,8 +22,7 @@
22 22
 	private Object mojo;
23 23
 	private Object configPojoInstance;
24 24
 	private String configPojoName;
25  
-
26  
-    private static final String PARSED_PARAMETER_PREFIX = "parsed";
  25
+	private String configPojoPrefix;
27 26
 
28 27
 	public ConfigHandler(Object mojo) {
29 28
 		this.mojo = mojo;
@@ -152,7 +151,7 @@ private String toFirstLetterUppercase(String s) {
152 151
 	}
153 152
 
154 153
     private String getFieldNameWithoutParsedPrefix(Field field) {
155  
-        return getFieldNameWithoutPrefix(field, PARSED_PARAMETER_PREFIX);
  154
+        return getFieldNameWithoutPrefix(field, configPojoPrefix);
156 155
     }
157 156
 
158 157
     private void initConfigPojo() {
@@ -160,6 +159,7 @@ private void initConfigPojo() {
160 159
 			Field configPojo = findPropertiesByAnnotation(ConfigPojo.class).iterator().next();
161 160
 			configPojoName = configPojo.getName();
162 161
 			configPojoInstance = configPojo.get(mojo);
  162
+			configPojoPrefix = configPojo.getAnnotation( ConfigPojo.class ).prefix();
163 163
 		}
164 164
 		catch (Exception e) {
165 165
 			// ignore, we can live without a config pojo
1  src/main/java/com/jayway/maven/plugins/android/config/ConfigPojo.java
@@ -17,4 +17,5 @@
17 17
 @Retention(RetentionPolicy.RUNTIME)
18 18
 public @interface ConfigPojo {
19 19
 
  20
+	String prefix() default "parsed";
20 21
 }
21  src/main/java/com/jayway/maven/plugins/android/configuration/Apk.java
... ...
@@ -0,0 +1,21 @@
  1
+
  2
+package com.jayway.maven.plugins.android.configuration;
  3
+
  4
+import java.io.File;
  5
+
  6
+import com.jayway.maven.plugins.android.phase09package.ApkMojo;
  7
+
  8
+/**
  9
+ * Embedded configuration of {@link com.jayway.maven.plugins.android.phase09package.ApkMojo}.
  10
+ * 
  11
+ * @author <a href="mailto:pa314159&#64;gmail.com">Pappy Răzvan STĂNESCU &lt;pa314159&#64;gmail.com&gt;</a>
  12
+ */
  13
+@SuppressWarnings( "unused" )
  14
+public class Apk
  15
+{
  16
+
  17
+	/**
  18
+	 * Mirror of {@link com.jayway.maven.plugins.android.phase09package.ApkMojo#apkMetaIncludes}.
  19
+	 */
  20
+	private String[]	metaIncludes;
  21
+}
89  src/main/java/com/jayway/maven/plugins/android/configuration/ConfigHelper.java
... ...
@@ -0,0 +1,89 @@
  1
+
  2
+package com.jayway.maven.plugins.android.configuration;
  3
+
  4
+import java.lang.reflect.Array;
  5
+import java.lang.reflect.Field;
  6
+
  7
+import org.apache.maven.plugin.AbstractMojo;
  8
+import org.apache.maven.plugin.MojoExecutionException;
  9
+
  10
+/**
  11
+ * Helper for parsing the embedded configuration of a mojo.
  12
+ * 
  13
+ * @author <a href="mailto:pa314159&#64;gmail.com">Pappy Răzvan STĂNESCU &lt;pa314159&#64;gmail.com&gt;</a>
  14
+ */
  15
+public final class ConfigHelper
  16
+{
  17
+
  18
+	static public void copyValues( AbstractMojo mojo, String confFieldName )
  19
+	throws MojoExecutionException
  20
+	{
  21
+		try {
  22
+			final Class<? extends AbstractMojo> mojoClass = mojo.getClass();
  23
+			final Field confField = mojoClass.getDeclaredField( confFieldName );
  24
+
  25
+			confField.setAccessible( true );
  26
+
  27
+			final Object conf = confField.get( mojo );
  28
+
  29
+			if( conf == null ) {
  30
+				return;
  31
+			}
  32
+
  33
+			for( final Field field : conf.getClass().getDeclaredFields() ) {
  34
+				field.setAccessible( true );
  35
+
  36
+				final Object value = field.get( conf );
  37
+
  38
+				if( value == null ) {
  39
+					continue;
  40
+				}
  41
+
  42
+				final Class<?> cls = value.getClass();
  43
+
  44
+				if( (cls == String.class) && (((String) value).length() == 0) ) {
  45
+					continue;
  46
+				}
  47
+				if( cls.isArray() && (Array.getLength( value ) == 0) ) {
  48
+					continue;
  49
+				}
  50
+
  51
+				{
  52
+					String mojoFieldName = field.getName();
  53
+
  54
+					mojoFieldName = Character.toUpperCase( mojoFieldName.charAt( 0 ) ) + mojoFieldName.substring( 1 );
  55
+					mojoFieldName = confFieldName + mojoFieldName;
  56
+
  57
+					try {
  58
+						final Field mojoField = mojoClass.getDeclaredField( mojoFieldName );
  59
+
  60
+						mojoField.setAccessible( true );
  61
+						mojoField.set( mojo, value );
  62
+					}
  63
+					catch( final NoSuchFieldException e ) {
  64
+						;
  65
+					}
  66
+				}
  67
+
  68
+				//  handle deprecated parameters
  69
+				{
  70
+					try {
  71
+						final Field mojoField = mojoClass.getDeclaredField( field.getName() );
  72
+
  73
+						mojoField.setAccessible( true );
  74
+						mojoField.set( mojo, value );
  75
+					}
  76
+					catch( final NoSuchFieldException e ) {
  77
+						;
  78
+					}
  79
+					catch( final IllegalArgumentException e ) {
  80
+						// probably not a deprecated parameter, see Proguard configuration;
  81
+					}
  82
+				}
  83
+			}
  84
+		}
  85
+		catch( final Exception e ) {
  86
+			throw new MojoExecutionException( e.getMessage(), e );
  87
+		}
  88
+	}
  89
+}
146  src/main/java/com/jayway/maven/plugins/android/phase09package/ApkMojo.java
@@ -34,21 +34,26 @@
34 34
 import java.util.zip.ZipFile;
35 35
 import java.util.zip.ZipOutputStream;
36 36
 
37  
-import com.jayway.maven.plugins.android.common.AetherHelper;
38  
-import com.jayway.maven.plugins.android.common.NativeHelper;
39  
-import com.jayway.maven.plugins.android.configuration.Sign;
40 37
 import org.apache.commons.lang.StringUtils;
41 38
 import org.apache.maven.artifact.Artifact;
42 39
 import org.apache.maven.artifact.factory.ArtifactFactory;
43 40
 import org.apache.maven.plugin.MojoExecutionException;
44 41
 import org.apache.maven.plugin.MojoFailureException;
45 42
 import org.codehaus.plexus.util.AbstractScanner;
  43
+import org.codehaus.plexus.util.DirectoryScanner;
  44
+import org.codehaus.plexus.util.SelectorUtils;
46 45
 
47 46
 import com.jayway.maven.plugins.android.AbstractAndroidMojo;
48 47
 import com.jayway.maven.plugins.android.AndroidSigner;
49 48
 import com.jayway.maven.plugins.android.CommandExecutor;
50 49
 import com.jayway.maven.plugins.android.ExecutionException;
51  
-import org.codehaus.plexus.util.DirectoryScanner;
  50
+import com.jayway.maven.plugins.android.common.NativeHelper;
  51
+import com.jayway.maven.plugins.android.config.ConfigHandler;
  52
+import com.jayway.maven.plugins.android.config.ConfigPojo;
  53
+import com.jayway.maven.plugins.android.config.PullParameter;
  54
+import com.jayway.maven.plugins.android.configuration.Apk;
  55
+import com.jayway.maven.plugins.android.configuration.ConfigHelper;
  56
+import com.jayway.maven.plugins.android.configuration.Sign;
52 57
 
53 58
 
54 59
 /**
@@ -182,6 +187,47 @@
182 187
       */
183 188
      protected ArtifactFactory artifactFactory;
184 189
 
  190
+ 	/**
  191
+ 	 * Pattern for additional META-INF resources to be packaged into the apk.
  192
+ 	 * <p>
  193
+ 	 * The APK builder filters these resources and doesn't include them into the apk.
  194
+ 	 * This leads to bad behaviour of dependent libraries relying on these resources,
  195
+ 	 * for instance service discovery doesn't work.<br/>
  196
+ 	 * By specifying this pattern, the android plugin adds these resources to the final apk. 
  197
+ 	 * </p>
  198
+ 	 * <p>The pattern is relative to META-INF, i.e. one must use
  199
+ 	 * <pre>
  200
+ 	 * <code>
  201
+ 	 * 	&lt;apkMetaIncludes&gt;
  202
+ 	 * 		&lt;metaInclude>services/**&lt;/metaInclude&gt;
  203
+ 	 * 	&lt;/apkMetaIncludes&gt;
  204
+ 	 * </code>
  205
+ 	 * </pre>
  206
+ 	 * ... instead of
  207
+ 	 * <pre>
  208
+ 	 * <code>
  209
+ 	 * 	&lt;apkMetaIncludes&gt;
  210
+ 	 * 		&lt;metaInclude>META-INF/services/**&lt;/metaInclude&gt;
  211
+ 	 * 	&lt;/apkMetaIncludes&gt;
  212
+ 	 * </code>
  213
+ 	 * </pre>
  214
+ 	 * <p>
  215
+ 	 * See also <a href="http://code.google.com/p/maven-android-plugin/issues/detail?id=97">Issue 97</a>
  216
+ 	 * </p>
  217
+ 	 * 
  218
+ 	 * @parameter expression="${android.apk.metaIncludes}" default-value=""
  219
+ 	 */
  220
+     @PullParameter( defaultValueGetterMethod = "getDefaultMetaIncludes" )
  221
+ 	private String[]	apkMetaIncludes;
  222
+
  223
+ 	/**
  224
+ 	 * Embedded configuration of this mojo.
  225
+ 	 * 
  226
+ 	 * @parameter
  227
+ 	 */
  228
+ 	@ConfigPojo( prefix="apk" )
  229
+ 	private Apk apk;
  230
+
185 231
     private static final Pattern PATTERN_JAR_EXT = Pattern.compile("^.+\\.jar$", 2);
186 232
 
187 233
     public void execute() throws MojoExecutionException, MojoFailureException {
@@ -191,6 +237,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
191 237
             return;
192 238
         }
193 239
 
  240
+        ConfigHandler cfh = new ConfigHandler( this );
  241
+        
  242
+        cfh.parseConfiguration();
  243
+
194 244
         generateIntermediateAp_();
195 245
 
196 246
         // Initialize apk build configuration
@@ -255,8 +305,90 @@ void createApkFile(File outputFile, boolean signWithDebugKeyStore) throws MojoEx
255 305
             doAPKWithCommand(outputFile, dexFile, zipArchive, sourceFolders, jarFiles,
256 306
                 nativeFolders, signWithDebugKeyStore);
257 307
         }
  308
+
  309
+        if( this.apkMetaIncludes != null && this.apkMetaIncludes.length > 0 ) {
  310
+        	try {
  311
+				addMetaInf( outputFile, jarFiles );
  312
+			}
  313
+			catch( IOException e ) {
  314
+				throw new MojoExecutionException("Could not add META-INF resources.", e);
  315
+			}
  316
+        }
258 317
     }
259 318
 
  319
+	private void addMetaInf( File outputFile, ArrayList<File> jarFiles ) throws IOException
  320
+	{
  321
+		File tmp = File.createTempFile( outputFile.getName(), ".add", outputFile.getParentFile() );
  322
+
  323
+		FileOutputStream fos = new FileOutputStream( tmp );
  324
+		ZipOutputStream zos = new ZipOutputStream( fos );
  325
+		Set<String> entries = new HashSet<String>();
  326
+
  327
+		updateWithMetaInf( zos, outputFile, entries, false );
  328
+
  329
+		for( File f : jarFiles ) {
  330
+			updateWithMetaInf( zos, f, entries, true );
  331
+		}
  332
+
  333
+		zos.close();
  334
+
  335
+		outputFile.delete();
  336
+
  337
+		if( !tmp.renameTo( outputFile ) ) {
  338
+			throw new IOException( String.format( "Cannot rename %s to %s", tmp, outputFile.getName() ) );
  339
+		}
  340
+	}
  341
+
  342
+	private void updateWithMetaInf( ZipOutputStream zos, File jarFile, Set<String> entries, boolean metaInfOnly )
  343
+	throws ZipException, IOException
  344
+	{
  345
+		ZipFile zin = new ZipFile( jarFile );
  346
+
  347
+		for( Enumeration<? extends ZipEntry> en = zin.entries(); en.hasMoreElements(); ) {
  348
+			ZipEntry ze = en.nextElement();
  349
+
  350
+			if( ze.isDirectory() )
  351
+				continue;
  352
+
  353
+			String zn = ze.getName();
  354
+
  355
+			if( metaInfOnly ) {
  356
+				if( !zn.startsWith( "META-INF/" ) ) {
  357
+					continue;
  358
+				}
  359
+
  360
+				if( this.extractDuplicates && !entries.add( zn ) ) {
  361
+					continue;
  362
+				}
  363
+
  364
+				if( !metaInfMatches( zn ) ) {
  365
+					continue;
  366
+				}
  367
+			}
  368
+
  369
+			zos.putNextEntry( new ZipEntry( zn ) );
  370
+
  371
+			InputStream is = zin.getInputStream( ze );
  372
+
  373
+			copyStreamWithoutClosing( is, zos );
  374
+
  375
+			is.close();
  376
+			zos.closeEntry();
  377
+		}
  378
+
  379
+		zin.close();
  380
+	}
  381
+
  382
+	private boolean metaInfMatches( String path )
  383
+	{
  384
+		for( String inc : this.apkMetaIncludes ) {
  385
+			if( SelectorUtils.matchPath( "META-INF/" + inc, path ) )
  386
+				return true;
  387
+		}
  388
+
  389
+		return false;
  390
+	}
  391
+
260 392
     private Map<String, List<File>> m_jars = new HashMap<String, List<File>>();
261 393
 
262 394
     private void computeDuplicateFiles(File jar) throws ZipException, IOException {
@@ -368,7 +500,7 @@ public boolean accept(File dir, String name) {
368 500
     }
369 501
 
370 502
     private File removeDuplicatesFromJar(File in, List<String> duplicates) {
371  
-        File target = new File(project.getBasedir(), "target");
  503
+        String target = project.getBuild().getOutputDirectory();
372 504
         File tmp = new File(target, "unpacked-embedded-jars");
373 505
         tmp.mkdirs();
374 506
         File out = new File(tmp, in.getName());
@@ -837,4 +969,8 @@ protected AndroidSigner getAndroidSigner() {
837 969
             return new AndroidSigner(sign.getDebug());
838 970
         }
839 971
     }
  972
+
  973
+    private String[] getDefaultMetaIncludes() {
  974
+    	return new String[0];
  975
+    }
840 976
 }
89  src/test/java/com/jayway/maven/plugins/android/phase09package/ApkMojoTest.java
... ...
@@ -0,0 +1,89 @@
  1
+
  2
+package com.jayway.maven.plugins.android.phase09package;
  3
+
  4
+import java.util.ArrayList;
  5
+import java.util.List;
  6
+
  7
+import org.junit.After;
  8
+import org.junit.Assert;
  9
+import org.junit.Before;
  10
+import org.junit.Test;
  11
+import org.junit.runner.RunWith;
  12
+import org.junit.runners.Parameterized;
  13
+import org.junit.runners.Parameterized.Parameters;
  14
+
  15
+import com.jayway.maven.plugins.android.AbstractAndroidMojoTestCase;
  16
+import com.jayway.maven.plugins.android.config.ConfigHandler;
  17
+
  18
+@RunWith( Parameterized.class )
  19
+public class ApkMojoTest
  20
+extends AbstractAndroidMojoTestCase<ApkMojo>
  21
+{
  22
+
  23
+	@Parameters
  24
+	static public List<Object[]> suite()
  25
+	{
  26
+		final List<Object[]> suite = new ArrayList<Object[]>();
  27
+
  28
+		suite.add( new Object[] { "apk-config-project1", new String[0] } );
  29
+		suite.add( new Object[] { "apk-config-project2", new String[] { "persistence.xml" } } );
  30
+		suite.add( new Object[] { "apk-config-project2", new String[] { "services/**", "persistence.xml" } } );
  31
+
  32
+		return suite;
  33
+	}
  34
+
  35
+	private final String	projectName;
  36
+
  37
+	private final String[]	expected;
  38
+
  39
+	public ApkMojoTest( String projectName, String[] expected )
  40
+	{
  41
+		this.projectName = projectName;
  42
+		this.expected = expected;
  43
+	}
  44
+
  45
+	@Override
  46
+	public String getPluginGoalName()
  47
+	{
  48
+		return "apk";
  49
+	}
  50
+
  51
+	@Override
  52
+	@Before
  53
+	public void setUp()
  54
+	throws Exception
  55
+	{
  56
+		super.setUp();
  57
+	}
  58
+
  59
+	@Override
  60
+	@After
  61
+	public void tearDown()
  62
+	throws Exception
  63
+	{
  64
+		super.tearDown();
  65
+	}
  66
+
  67
+	@Test
  68
+	public void testConfigHelper()
  69
+	throws Exception
  70
+	{
  71
+		final ApkMojo mojo = createMojo( this.projectName );
  72
+
  73
+		final ConfigHandler cfh = new ConfigHandler( mojo );
  74
+
  75
+		cfh.parseConfiguration();
  76
+
  77
+		final String[] includes = getFieldValue( mojo, "apkMetaIncludes" );
  78
+
  79
+		Assert.assertNotNull( includes );
  80
+		Assert.assertArrayEquals( this.expected, includes );
  81
+	}
  82
+
  83
+	protected <T> T getFieldValue( Object object, String fieldName )
  84
+	throws IllegalAccessException
  85
+	{
  86
+		return (T) super.getVariableValueFromObject( object, fieldName );
  87
+	}
  88
+
  89
+}
17  src/test/resources/apk-config-project1/plugin-config.xml
... ...
@@ -0,0 +1,17 @@
  1
+<?xml version="1.0"?>
  2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4
+	<modelVersion>4.0.0</modelVersion>
  5
+	<groupId>com.jayway.maven.plugins.android.tests</groupId>
  6
+	<artifactId>apk-config-project1</artifactId>
  7
+	<version>15.4.3.1011</version>
  8
+	<build>
  9
+		<plugins>
  10
+			<plugin>
  11
+				<artifactId>android-maven-plugin</artifactId>
  12
+				<configuration>
  13
+				</configuration>
  14
+			</plugin>
  15
+		</plugins>
  16
+	</build>
  17
+</project>
22  src/test/resources/apk-config-project2/plugin-config.xml
... ...
@@ -0,0 +1,22 @@
  1
+<?xml version="1.0"?>
  2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4
+	<modelVersion>4.0.0</modelVersion>
  5
+	<groupId>com.jayway.maven.plugins.android.tests</groupId>
  6
+	<artifactId>apk-config-project2</artifactId>
  7
+	<version>15.4.3.1011</version>
  8
+	<build>
  9
+		<plugins>
  10
+			<plugin>
  11
+				<artifactId>android-maven-plugin</artifactId>
  12
+				<configuration>
  13
+					<apk>
  14
+						<metaIncludes>
  15
+							<include>persistence.xml</include>
  16
+						</metaIncludes>
  17
+					</apk>
  18
+				</configuration>
  19
+			</plugin>
  20
+		</plugins>
  21
+	</build>
  22
+</project>
23  src/test/resources/apk-config-project3/plugin-config.xml
... ...
@@ -0,0 +1,23 @@
  1
+<?xml version="1.0"?>
  2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4
+	<modelVersion>4.0.0</modelVersion>
  5
+	<groupId>com.jayway.maven.plugins.android.tests</groupId>
  6
+	<artifactId>apk-config-project2</artifactId>
  7
+	<version>15.4.3.1011</version>
  8
+	<build>
  9
+		<plugins>
  10
+			<plugin>
  11
+				<artifactId>android-maven-plugin</artifactId>
  12
+				<configuration>
  13
+					<apk>
  14
+						<metaIncludes>
  15
+							<include>services/**</include>
  16
+							<include>persistence.xml</include>
  17
+						</metaIncludes>
  18
+					</apk>
  19
+				</configuration>
  20
+			</plugin>
  21
+		</plugins>
  22
+	</build>
  23
+</project>
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.