com.android.resources.ResourceFolderType Java Examples

The following examples show how to use com.android.resources.ResourceFolderType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceCompiler.java    From bazel with Apache License 2.0 6 votes vote down vote up
static String interpolateAapt2Filename(ResourceFolderType resourceFolderType, Path file) {
  // res/<not values>/foo.bar -> foo.bar
  String filename = file.getFileName().toString();
  if (!resourceFolderType.equals(ResourceFolderType.VALUES)) {
    return filename;
  }

  int periodIndex = filename.indexOf('.');

  // res/values/foo -> foo.arsc
  if (periodIndex == -1) {
    return filename + ".arsc";
  }

  // res/values/foo.bar.baz -> throw error.
  if (filename.lastIndexOf('.') != periodIndex) {
    throw new CompileError(
        new IllegalArgumentException(
            "aapt2 does not support compiling resource xmls with multiple periods in the "
                + "filename: "
                + file));
  }

  // res/values/foo.xml -> foo.arsc
  return filename.substring(0, periodIndex) + ".arsc";
}
 
Example #2
Source File: FolderConfiguration.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the name of a folder with the configuration.
 */
@NonNull
public String getFolderName(@NonNull ResourceFolderType folder) {
    StringBuilder result = new StringBuilder(folder.getName());

    for (ResourceQualifier qualifier : mQualifiers) {
        if (qualifier != null) {
            String segment = qualifier.getFolderSegment();
            if (segment != null && !segment.isEmpty()) {
                result.append(SdkConstants.RES_QUALIFIER_SEP);
                result.append(segment);
            }
        }
    }

    return result.toString();
}
 
Example #3
Source File: ResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Processes a folder and adds it to the list of existing folders.
 * @param folder the folder to process
 * @return the ResourceFolder created from this folder, or null if the process failed.
 */
@Nullable
public ResourceFolder processFolder(@NonNull IAbstractFolder folder) {
    ensureInitialized();

    // split the name of the folder in segments.
    String[] folderSegments = folder.getName().split(SdkConstants.RES_QUALIFIER_SEP);

    // get the enum for the resource type.
    ResourceFolderType type = ResourceFolderType.getTypeByName(folderSegments[0]);

    if (type != null) {
        // get the folder configuration.
        FolderConfiguration config = FolderConfiguration.getConfig(folderSegments);

        if (config != null) {
            return add(type, config, folder);
        }
    }

    return null;
}
 
Example #4
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link ResourceFile} matching the given name,
 * {@link ResourceFolderType} and configuration.
 * <p>
 * This only works with files generating one resource named after the file
 * (for instance, layouts, bitmap based drawable, xml, anims).
 *
 * @param name the resource name or file name
 * @param type the folder type search for
 * @param config the folder configuration to match for
 * @return the matching file or <code>null</code> if no match was found.
 */
@Nullable
public ResourceFile getMatchingFile(
        @NonNull String name,
        @NonNull ResourceFolderType type,
        @NonNull FolderConfiguration config) {
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(type);
    for (ResourceType t : types) {
        if (t == ResourceType.ID) {
            continue;
        }
        ResourceFile match = getMatchingFile(name, t, config);
        if (match != null) {
            return match;
        }
    }

    return null;
}
 
Example #5
Source File: ResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link ResourceFile} matching the given name,
 * {@link ResourceFolderType} and configuration.
 * <p/>
 * This only works with files generating one resource named after the file
 * (for instance, layouts, bitmap based drawable, xml, anims).
 *
 * @param name the resource name or file name
 * @param type the folder type search for
 * @param config the folder configuration to match for
 * @return the matching file or <code>null</code> if no match was found.
 */
@Nullable
public ResourceFile getMatchingFile(
        @NonNull String name,
        @NonNull ResourceFolderType type,
        @NonNull FolderConfiguration config) {
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(type);
    for (ResourceType t : types) {
        if (t == ResourceType.ID) {
            continue;
        }
        ResourceFile match = getMatchingFile(name, t, config);
        if (match != null) {
            return match;
        }
    }

    return null;
}
 
Example #6
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * Processes a folder and adds it to the list of existing folders.
 * @param folder the folder to process
 * @return the ResourceFolder created from this folder, or null if the process failed.
 */
@Nullable
public ResourceFolder processFolder(@NonNull IAbstractFolder folder) {
    ensureInitialized();

    // split the name of the folder in segments.
    String[] folderSegments = folder.getName().split(SdkConstants.RES_QUALIFIER_SEP);

    // get the enum for the resource type.
    ResourceFolderType type = ResourceFolderType.getTypeByName(folderSegments[0]);

    if (type != null) {
        // get the folder configuration.
        FolderConfiguration config = FolderConfiguration.getConfig(folderSegments);

        if (config != null) {
            return add(type, config, folder);
        }
    }

    return null;
}
 
Example #7
Source File: ResourceFolder.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
private ResourceFile createResourceFile(IAbstractFile file) {
    // check if that's a single or multi resource type folder. We have a special case
    // for ID generating resource types (layout/menu, and XML drawables, etc.).
    // MultiResourceFile handles the case when several resource types come from a single file
    // (values files).

    ResourceFile resFile;
    if (mType != ResourceFolderType.VALUES) {
        if (FolderTypeRelationship.isIdGeneratingFolderType(mType) &&
            SdkUtils.endsWithIgnoreCase(file.getName(), SdkConstants.DOT_XML)) {
            List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(mType);
            ResourceType primaryType = types.get(0);
            resFile = new IdGeneratingResourceFile(file, this, primaryType);
        } else {
            resFile = new SingleResourceFile(file, this);
        }
    } else {
        resFile = new MultiResourceFile(file, this, namespace);
    }
    return resFile;
}
 
Example #8
Source File: ApiDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns true if this attribute is in a drawable document with one of the
 * root tags that require API 21
 */
private static boolean isAlreadyWarnedDrawableFile(@NonNull XmlContext context,
        @NonNull Attr attribute, int attributeApiLevel) {
    // Don't complain if it's in a drawable file where we've already
    // flagged the root drawable type as being unsupported
    if (context.getResourceFolderType() == ResourceFolderType.DRAWABLE
            && attributeApiLevel == 21) {
        String root = attribute.getOwnerDocument().getDocumentElement().getTagName();
        if (TAG_RIPPLE.equals(root)
                || TAG_VECTOR.equals(root)
                || TAG_ANIMATED_VECTOR.equals(root)
                || TAG_ANIMATED_SELECTOR.equals(root)) {
            return true;
        }
    }

    return false;
}
 
Example #9
Source File: ResourcePrefixDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void beforeCheckFile(@NonNull Context context) {
    if (mPrefix != null && context instanceof XmlContext) {
        XmlContext xmlContext = (XmlContext) context;
        ResourceFolderType folderType = xmlContext.getResourceFolderType();
        if (folderType != null && folderType != ResourceFolderType.VALUES) {
            String name = LintUtils.getBaseName(context.file.getName());
            if (!name.startsWith(mPrefix)) {
                // Attempt to report the error on the root tag of the associated
                // document to make suppressing the error with a tools:suppress
                // attribute etc possible
                if (xmlContext.document != null) {
                    Element root = xmlContext.document.getDocumentElement();
                    if (root != null) {
                        xmlContext.report(ISSUE, root, xmlContext.getLocation(root),
                                getErrorMessage(name));
                        return;
                    }
                }
                context.report(ISSUE, Location.create(context.file),
                        getErrorMessage(name));
            }
        }
    }
}
 
Example #10
Source File: ResourcePrefixDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    if (mPrefix == null || context.getResourceFolderType() != ResourceFolderType.VALUES) {
        return;
    }

    for (Element item : LintUtils.getChildren(element)) {
        Attr nameAttribute = item.getAttributeNode(ATTR_NAME);
        if (nameAttribute != null) {
            String name = nameAttribute.getValue();
            if (!name.startsWith(mPrefix)) {
                String message = getErrorMessage(name);
                context.report(ISSUE, nameAttribute, context.getLocation(nameAttribute),
                        message);
            }
        }
    }
}
 
Example #11
Source File: GeneratedResourceClassifier.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static boolean mayHaveNonStringTranslations(String dirName) {
  // String translations only sit in the values-xx-rYY directories, so we can rule out other
  // directories quickly.
  if (!dirName.contains(SdkConstants.RES_QUALIFIER_SEP)) {
    return true;
  }
  if (ResourceFolderType.getFolderType(dirName) != ResourceFolderType.VALUES) {
    return true;
  }
  FolderConfiguration config = FolderConfiguration.getConfigForFolder(dirName);
  // Conservatively say it's interesting if there is an unrecognized configuration.
  if (config == null) {
    return true;
  }
  // If this is a translation mixed with something else, consider it a translation directory.
  boolean hasTranslation = false;
  for (ResourceQualifier qualifier : config.getQualifiers()) {
    if (qualifier instanceof LocaleQualifier) {
      hasTranslation = true;
    }
  }
  return !hasTranslation;
}
 
Example #12
Source File: ResourceFolder.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns whether a file in the folder is generating a resource of a specified type.
 * @param type The {@link ResourceType} being looked up.
 */
public boolean hasResources(ResourceType type) {
    // Check if the folder type is able to generate resource of the type that was asked.
    // this is a first check to avoid going through the files.
    List<ResourceFolderType> folderTypes = FolderTypeRelationship.getRelatedFolders(type);

    boolean valid = false;
    for (ResourceFolderType rft : folderTypes) {
        if (rft == mType) {
            valid = true;
            break;
        }
    }

    if (valid) {
        if (mFiles != null) {
            for (ResourceFile f : mFiles) {
                if (f.hasResources(type)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example #13
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Processes a folder and adds it to the list of existing folders.
 * @param folder the folder to process
 * @return the ResourceFolder created from this folder, or null if the process failed.
 */
@Nullable
public ResourceFolder processFolder(@NonNull IAbstractFolder folder) {
    ensureInitialized();

    // split the name of the folder in segments.
    String[] folderSegments = folder.getName().split(SdkConstants.RES_QUALIFIER_SEP);

    // get the enum for the resource type.
    ResourceFolderType type = ResourceFolderType.getTypeByName(folderSegments[0]);

    if (type != null) {
        // get the folder configuration.
        FolderConfiguration config = FolderConfiguration.getConfig(folderSegments);

        if (config != null) {
            return add(type, config, folder);
        }
    }

    return null;
}
 
Example #14
Source File: BlazeNewResourceCreationHandler.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public CreateXmlResourcePanel createNewResourceValuePanel(
    Module module,
    ResourceType resourceType,
    ResourceFolderType folderType,
    @Nullable String resourceName,
    @Nullable String resourceValue,
    boolean chooseName,
    boolean chooseValue,
    boolean chooseFilename,
    @Nullable VirtualFile defaultFile,
    @Nullable VirtualFile contextFile,
    Function<Module, IdeResourceNameValidator> nameValidatorFactory) {
  return new BlazeCreateXmlResourcePanel(
      module,
      resourceType,
      folderType,
      resourceName,
      resourceValue,
      chooseName,
      chooseValue,
      chooseFilename,
      defaultFile,
      contextFile,
      nameValidatorFactory);
}
 
Example #15
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void clear() {
    mCleared = true;
    mFolderMap = new EnumMap<ResourceFolderType, List<ResourceFolder>>(
            ResourceFolderType.class);
    mResourceMap = new EnumMap<ResourceType, Map<String, ResourceItem>>(
            ResourceType.class);

    mReadOnlyListMap =
        new IdentityHashMap<Map<String, ResourceItem>, Collection<ResourceItem>>();
}
 
Example #16
Source File: ParsedAndroidData.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
  try {
    if (!Files.isDirectory(path) && !path.getFileName().toString().startsWith(".")) {
      if (folderType == ResourceFolderType.VALUES) {
        DataResourceXml.parse(
            XmlResourceValues.getXmlInputFactory(),
            path,
            fqnFactory,
            overwritingConsumer,
            combiningResources);
      } else if (folderType != null) {
        FullyQualifiedName key = fqnFactory.parse(path);
        if (ID_PROVIDING_RESOURCE_TYPES.contains(folderType)
            && path.getFileName().toString().endsWith(SdkConstants.DOT_XML)) {
          DataValueFileWithIds.parse(
              XmlResourceValues.getXmlInputFactory(),
              path,
              key,
              fqnFactory,
              overwritingConsumer,
              combiningResources);
        } else {
          overwritingConsumer.accept(key, DataValueFile.of(path));
        }
      }
    }
  } catch (IllegalArgumentException | XMLStreamException e) {
    errors.add(e);
  }
  return super.visitFile(path, attrs);
}
 
Example #17
Source File: OverdrawDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean appliesTo(@NonNull ResourceFolderType folderType) {
    // Look in layouts for drawable resources
    return super.appliesTo(folderType)
            // and in resource files for theme definitions
            || folderType == ResourceFolderType.VALUES
            // and in drawable files for bitmap tiling modes
            || folderType == ResourceFolderType.DRAWABLE;
}
 
Example #18
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
/**
 * Removes a {@link ResourceFolder} associated with the specified {@link IAbstractFolder}.
 *
 * @param type The type of the folder
 * @param removedFolder the IAbstractFolder object.
 * @param context the scanning context
 * @return the {@link ResourceFolder} that was removed, or null if no matches were found.
 */
@Nullable
public ResourceFolder removeFolder(
        @NonNull ResourceFolderType type,
        @NonNull IAbstractFolder removedFolder,
        @Nullable ScanningContext context) {
    ensureInitialized();

    // get the list of folders for the resource type.
    List<ResourceFolder> list = mFolderMap.get(type);

    if (list != null) {
        int count = list.size();
        for (int i = 0 ; i < count ; i++) {
            ResourceFolder resFolder = list.get(i);
            IAbstractFolder folder = resFolder.getFolder();
            if (removedFolder.equals(folder)) {
                // we found the matching ResourceFolder. we need to remove it.
                list.remove(i);

                // remove its content
                resFolder.dispose(context);

                return resFolder;
            }
        }
    }

    return null;
}
 
Example #19
Source File: ResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public synchronized void clear() {
    mCleared = true;
    mFolderMap = new EnumMap<ResourceFolderType, List<ResourceFolder>>(
            ResourceFolderType.class);
    mResourceMap = new EnumMap<ResourceType, Map<String, ResourceItem>>(
            ResourceType.class);

    mReadOnlyListMap =
        new IdentityHashMap<Map<String, ResourceItem>, Collection<ResourceItem>>();
}
 
Example #20
Source File: LintDetectorTest.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
protected String lintFiles(String... relativePaths) throws Exception {
    List<File> files = new ArrayList<File>();
    File targetDir = getTargetDir();
    for (String relativePath : relativePaths) {
        File file = getTestfile(targetDir, relativePath);
        assertNotNull(file);
        files.add(file);
    }

    Collections.sort(files, new Comparator<File>() {
        @Override
        public int compare(File file1, File file2) {
            ResourceFolderType folder1 = ResourceFolderType.getFolderType(
                    file1.getParentFile().getName());
            ResourceFolderType folder2 = ResourceFolderType.getFolderType(
                    file2.getParentFile().getName());
            if (folder1 != null && folder2 != null && folder1 != folder2) {
                return folder1.compareTo(folder2);
            }
            return file1.compareTo(file2);
        }
    });

    addManifestFile(targetDir);

    return checkLint(files);
}
 
Example #21
Source File: ResourceUsageAnalyzer.java    From bazel with Apache License 2.0 5 votes vote down vote up
private void recordResources(Path resDir)
    throws IOException, SAXException, ParserConfigurationException {

  File[] resourceFolders = resDir.toFile().listFiles();
  if (resourceFolders != null) {
    for (File folder : resourceFolders) {
      ResourceFolderType folderType = ResourceFolderType.getFolderType(folder.getName());
      if (folderType != null) {
        recordResources(folderType, folder);
      }
    }
  }
}
 
Example #22
Source File: PrivateResourceDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void beforeCheckFile(@NonNull Context context) {
    File file = context.file;
    boolean isXmlFile = LintUtils.isXmlFile(file);
    if (!isXmlFile && !LintUtils.isBitmapFile(file)) {
        return;
    }
    String parentName = file.getParentFile().getName();
    int dash = parentName.indexOf('-');
    if (dash != -1 || FD_RES_VALUES.equals(parentName)) {
        return;
    }
    ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName);
    if (folderType == null) {
        return;
    }
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType);
    if (types.isEmpty()) {
        return;
    }
    ResourceType type = types.get(0);
    String resourceName = getResourceFieldName(getBaseName(file.getName()));
    if (isPrivate(context, type, resourceName)) {
        String message = createOverrideErrorMessage(context, type, resourceName);
        Location location = Location.create(file);
        context.report(ISSUE, location, message);
    }
}
 
Example #23
Source File: ResourceFolder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link ResourceFolder}
 * @param type The type of the folder
 * @param config The configuration of the folder
 * @param folder The associated {@link IAbstractFolder} object.
 * @param repository The associated {@link ResourceRepository}
 */
protected ResourceFolder(ResourceFolderType type, FolderConfiguration config,
        IAbstractFolder folder, ResourceRepository repository) {
    mType = type;
    mConfiguration = config;
    mFolder = folder;
    mRepository = repository;
}
 
Example #24
Source File: ResourceCycleDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean appliesTo(@NonNull ResourceFolderType folderType) {
    return folderType == ResourceFolderType.VALUES
            || folderType == ResourceFolderType.COLOR
            || folderType == ResourceFolderType.DRAWABLE
            || folderType == ResourceFolderType.LAYOUT;
}
 
Example #25
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public synchronized void clear() {
    mCleared = true;
    mFolderMap = new EnumMap<ResourceFolderType, List<ResourceFolder>>(
            ResourceFolderType.class);
    mResourceMap = new EnumMap<ResourceType, Map<String, ResourceItem>>(
            ResourceType.class);

    mReadOnlyListMap =
        new IdentityHashMap<Map<String, ResourceItem>, Collection<ResourceItem>>();
}
 
Example #26
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of {@link ResourceFolder} for a specific {@link ResourceFolderType}.
 *
 * @param type The {@link ResourceFolderType}
 */
@Nullable
public List<ResourceFolder> getFolders(@NonNull ResourceFolderType type) {
    ensureInitialized();

    return mFolderMap.get(type);
}
 
Example #27
Source File: VectorDrawableRenderer.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Collection<File> getFilesToBeGenerated(File inputXmlFile) {
    FolderConfiguration originalConfiguration = getFolderConfiguration(inputXmlFile);

    // Create all the PNG files and duplicate the XML into folders with the version qualifier.
    Collection<File> filesToBeGenerated = Lists.newArrayList();
    for (Density density : mDensities) {
        FolderConfiguration newConfiguration = FolderConfiguration.copyOf(originalConfiguration);
        newConfiguration.setDensityQualifier(new DensityQualifier(density));

        File directory = new File(
                mOutputDir,
                newConfiguration.getFolderName(ResourceFolderType.DRAWABLE));
        File pngFile = new File(
                directory,
                inputXmlFile.getName().replace(".xml", ".png"));

        filesToBeGenerated.add(pngFile);

        newConfiguration.setVersionQualifier(new VersionQualifier(MIN_SDK_WITH_VECTOR_SUPPORT));
        File destination = new File(
                mOutputDir,
                newConfiguration.getFolderName(ResourceFolderType.DRAWABLE));
        File xmlCopy = new File(destination, inputXmlFile.getName());
        filesToBeGenerated.add(xmlCopy);
    }

    return filesToBeGenerated;
}
 
Example #28
Source File: DetectMissingPrefix.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean appliesTo(@NonNull ResourceFolderType folderType) {
    return folderType == LAYOUT
            || folderType == MENU
            || folderType == DRAWABLE
            || folderType == ANIM
            || folderType == ANIMATOR
            || folderType == COLOR
            || folderType == INTERPOLATOR;
}
 
Example #29
Source File: ProtoResourceUsageAnalyzer.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void acceptOpaqueFileType(Path path) {
  try {
    String pathString = path.toString();
    if (pathString.endsWith(".js")) {
      model.tokenizeJs(
          declaredResource, new String(Files.readAllBytes(path), StandardCharsets.UTF_8));
    } else if (pathString.endsWith(".css")) {
      model.tokenizeCss(
          declaredResource, new String(Files.readAllBytes(path), StandardCharsets.UTF_8));
    } else if (pathString.endsWith(".html")) {
      model.tokenizeHtml(
          declaredResource, new String(Files.readAllBytes(path), StandardCharsets.UTF_8));
    } else if (pathString.endsWith(".xml")) {
      // Force parsing of raw xml files to get any missing keep attributes.
      // The tool keep and discard attributes are held in raw files.
      // There is already processing to handle this, but there has been flakiness.
      // This step is to ensure as much stability as possible until the flakiness can be
      // diagnosed.
      model.recordResourceReferences(
          ResourceFolderType.getTypeByName(declaredResource.type.getName()),
          XmlUtils.parseDocumentSilently(
              new String(Files.readAllBytes(path), StandardCharsets.UTF_8), true),
          declaredResource);

    } else {
      // Path is a reference to the apk zip -- unpack it before getting a file reference.
      model.tokenizeUnknownBinary(
          declaredResource,
          Files.copy(
                  path,
                  Files.createTempFile("binary-resource", null),
                  StandardCopyOption.REPLACE_EXISTING)
              .toFile());
    }
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #30
Source File: ResourceSet.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a FolderData for the given folder.
 *
 * @param folder the folder.
 * @return the FolderData object, or null if we can't determine the {#link ResourceFolderType}
 * of the folder.
 */
@Nullable
private FolderData getFolderData(File folder) throws MergingException {
    FolderData fd = new FolderData();

    String folderName = folder.getName();
    int pos = folderName.indexOf(ResourceConstants.RES_QUALIFIER_SEP);
    if (pos != -1) {
        fd.folderType = ResourceFolderType.getTypeByName(folderName.substring(0, pos));
        if (fd.folderType == null) {
            return null;
        }

        FolderConfiguration folderConfiguration = FolderConfiguration.getConfigForFolder(folderName);
        if (folderConfiguration == null) {
            throw MergingException.withMessage("Invalid resource directory name")
                    .withFile(folder).build();
        }

        if (mNormalizeResources) {
            // normalize it
            folderConfiguration.normalize();
        }

        // get the qualifier portion from the folder config.
        // the returned string starts with "-" so we remove that.
        fd.qualifiers = folderConfiguration.getUniqueKey().substring(1);

    } else {
        fd.folderType = ResourceFolderType.getTypeByName(folderName);
    }

    if (fd.folderType != null && fd.folderType != ResourceFolderType.VALUES) {
        fd.type = FolderTypeRelationship.getRelatedResourceTypes(fd.folderType).get(0);
    }

    return fd;
}