|
16 | 16 | */
|
17 | 17 | package com.simpligility.maven.plugins.android.phase09package;
|
18 | 18 |
|
| 19 | +import static com.simpligility.maven.plugins.android.InclusionExclusionResolver.filterArtifacts; |
19 | 20 | import static com.simpligility.maven.plugins.android.common.AndroidExtension.AAR;
|
20 | 21 | import static com.simpligility.maven.plugins.android.common.AndroidExtension.APKLIB;
|
21 | 22 |
|
|
27 | 28 | import java.util.ArrayList;
|
28 | 29 | import java.util.List;
|
29 | 30 |
|
| 31 | +import com.simpligility.maven.plugins.android.IncludeExcludeSet; |
30 | 32 | import org.apache.commons.io.FileUtils;
|
31 | 33 | import org.apache.commons.io.IOUtils;
|
32 | 34 | import org.apache.commons.lang3.StringUtils;
|
@@ -70,6 +72,11 @@ public class AarMojo extends AbstractAndroidMojo
|
70 | 72 | */
|
71 | 73 | public static final String NATIVE_LIBRARIES_FOLDER = "jni";
|
72 | 74 |
|
| 75 | + /** |
| 76 | + * The name of the top level folder in the AAR where JAR libraries are found. |
| 77 | + */ |
| 78 | + public static final String LIBRARIES_FOLDER = "libs"; |
| 79 | + |
73 | 80 | /**
|
74 | 81 | * <p>Classifier to add to the artifact generated. If given, the artifact will be an attachment instead.</p>
|
75 | 82 | */
|
@@ -124,6 +131,57 @@ public class AarMojo extends AbstractAndroidMojo
|
124 | 131 | )
|
125 | 132 | private String obfuscatedJar;
|
126 | 133 |
|
| 134 | + /** |
| 135 | + * Set to {@code false} to automatically include all dependency JARs in the generated AAR. These are placed in |
| 136 | + * a directory called |code libs} in the generated aar. The set of JARs to include can be restricted using the |
| 137 | + * {@code artifactSet} and {@code artifactTypeSet} parameters. If {@code skipDependencies} is {@code true} |
| 138 | + * (default), only those JARs explicitly selected by the {@code artifactSet} and {@code artifactTypeSet} parameters |
| 139 | + * will be included. |
| 140 | + */ |
| 141 | + @Parameter( property = "skipDependencies", defaultValue = "true" ) |
| 142 | + private boolean skipDependencies; |
| 143 | + |
| 144 | + /** |
| 145 | + * Allows to include or exclude artifacts by type. The {@code include} parameter has higher priority than the |
| 146 | + * {@code exclude} parameter. These two parameters can be overridden by the {@code artifactSet} parameter. Empty |
| 147 | + * strings are ignored. Example: |
| 148 | + * <pre> |
| 149 | + * <artifactTypeSet> |
| 150 | + * <includes> |
| 151 | + * <include>aar</include> |
| 152 | + * <includes> |
| 153 | + * <excludes> |
| 154 | + * <exclude>jar</exclude> |
| 155 | + * <excludes> |
| 156 | + * </artifactTypeSet> |
| 157 | + * </pre> |
| 158 | + */ |
| 159 | + @Parameter( property = "artifactTypeSet" ) |
| 160 | + private IncludeExcludeSet artifactTypeSet; |
| 161 | + |
| 162 | + /** |
| 163 | + * Allows to include or exclude artifacts by {@code groupId}, {@code artifactId}, and {@code versionId}. The |
| 164 | + * {@code include} parameter has higher priority than the {@code exclude} parameter. These two parameters can |
| 165 | + * override the {@code artifactTypeSet} and {@code skipDependencies} parameters. Artifact {@code groupId}, |
| 166 | + * {@code artifactId}, and {@code versionId} are specified by a string with the respective values separated using |
| 167 | + * a colon character {@code :}. {@code artifactId} and {@code versionId} can be optional covering an artifact |
| 168 | + * range. Empty strings are ignored. Example: |
| 169 | + * <pre> |
| 170 | + * <artifactTypeSet> |
| 171 | + * <includes> |
| 172 | + * <include>foo-group:foo-artifact:1.0-SNAPSHOT</include> |
| 173 | + * <include>bar-group:bar-artifact</include> |
| 174 | + * <include>baz-group</include> |
| 175 | + * <includes> |
| 176 | + * <excludes> |
| 177 | + * <exclude>qux-group:qux-artifact</exclude> |
| 178 | + * <excludes> |
| 179 | + * </artifactTypeSet> |
| 180 | + * </pre> |
| 181 | + */ |
| 182 | + @Parameter( property = "artifactSet" ) |
| 183 | + private IncludeExcludeSet artifactSet; |
| 184 | + |
127 | 185 | private List<String> sourceFolders = new ArrayList<String>();
|
128 | 186 |
|
129 | 187 | /**
|
@@ -295,6 +353,9 @@ protected File createAarLibraryFile( File classesJar ) throws MojoExecutionExcep
|
295 | 353 | // Lastly, add any native libraries
|
296 | 354 | addNativeLibraries( zipArchiver );
|
297 | 355 |
|
| 356 | + // ... and JAR libraries |
| 357 | + addLibraries( zipArchiver ); |
| 358 | + |
298 | 359 | zipArchiver.createArchive();
|
299 | 360 | }
|
300 | 361 | catch ( ArchiverException e )
|
@@ -365,6 +426,18 @@ private void addNativeLibraries( final ZipArchiver zipArchiver ) throws MojoExec
|
365 | 426 | // TODO: - But where is that directory configured?
|
366 | 427 | }
|
367 | 428 |
|
| 429 | + private void addLibraries( final ZipArchiver zipArchiver ) throws MojoExecutionException |
| 430 | + { |
| 431 | + for ( Artifact artifact : filterArtifacts( getRelevantCompileArtifacts(), skipDependencies, |
| 432 | + artifactTypeSet.getIncludes(), artifactTypeSet.getExcludes(), artifactSet.getIncludes(), |
| 433 | + artifactSet.getExcludes() ) ) |
| 434 | + { |
| 435 | + getLog().debug( "Include library in AAR :" + artifact ); |
| 436 | + |
| 437 | + zipArchiver.addFile( artifact.getFile(), LIBRARIES_FOLDER + "/" + artifact.getFile().getName() ); |
| 438 | + } |
| 439 | + } |
| 440 | + |
368 | 441 | /**
|
369 | 442 | * Makes sure the string ends with "/"
|
370 | 443 | *
|
|
0 commit comments