/** * Looks for dependencies that have a layout file with the same name as either one of the project * layout files or one of the other dependencies. If such a duplicate occurs then it will fail the * build or generate a warning depending upon the value of the * <strong>failOnConflictingLayouts</strong> build parameter. * * @throws MojoExecutionException */ private void checkForConflictingLayouts() throws MojoExecutionException { final ConflictingLayoutDetector detector = new ConflictingLayoutDetector(); // Add layout files for this project final FileRetriever retriever = new FileRetriever("layout*/*.xml"); detector.addLayoutFiles( getAndroidManifestPackageName(), retriever.getFileNames(resourceDirectory)); // Add layout files for all dependencies. for (final Artifact dependency : getTransitiveDependencyArtifacts(AAR, APKLIB)) { final String packageName = extractPackageNameFromAndroidArtifact(dependency); final String[] layoutFiles = retriever.getFileNames(getUnpackedLibResourceFolder(dependency)); detector.addLayoutFiles(packageName, layoutFiles); } final Collection<ConflictingLayout> conflictingLayouts = detector.getConflictingLayouts(); getLog().debug("checkConflictingLayouts - conflicts : " + conflictingLayouts); if (!conflictingLayouts.isEmpty()) { final List<String> sb = new ArrayList<String>(); sb.add(""); sb.add(""); sb.add("Duplicate layout files have been detected across more than one Android package."); sb.add(""); sb.add( "Such a scenario generally means that the build will fail with a compilation error due to"); sb.add( "missing resource files. You should consider renaming some of the layout files listed below"); sb.add("to avoid the conflict."); sb.add(""); sb.add( "However, if you believe you know better, then you can downgrade the failure to a warning"); sb.add("by setting the failOnConflictingLayouts plugin property to false."); sb.add("But you really don't want to do that."); sb.add(""); sb.add("Conflicting Layouts:"); for (final ConflictingLayout layout : conflictingLayouts) { sb.add( " " + layout.getLayoutFileName() + " packages=" + layout.getPackageNames().toString()); } sb.add(""); if (failOnConflictingLayouts) { final StringBuilder builder = new StringBuilder(); for (final String line : sb) { builder.append(line); builder.append("\n"); } throw new MojoExecutionException(builder.toString()); } for (final String line : sb) { getLog().warn(line); } } }
private String[] findRelativeAidlFileNames(File sourceDirectory) { final FileRetriever retriever = new FileRetriever("**/*.aidl"); final String[] relativeAidlFileNames = retriever.getFileNames(sourceDirectory); if (relativeAidlFileNames.length == 0) { getLog().debug("ANDROID-904-002: No aidl files found"); } else { getLog().info("ANDROID-904-002: Found aidl files: Count = " + relativeAidlFileNames.length); } return relativeAidlFileNames; }