All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.android.ide.common.blame.parser.aapt.AbstractAaptOutputParser Maven / Gradle / Ivy

/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.ide.common.blame.parser.aapt;

import static com.android.SdkConstants.ANDROID_MANIFEST_XML;
import static com.android.SdkConstants.ATTR_NAME;
import static com.android.SdkConstants.ATTR_TYPE;
import static com.android.SdkConstants.DOT_XML;
import static com.android.SdkConstants.TAG_ITEM;

import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.annotations.VisibleForTesting;
import com.android.ide.common.blame.Message;
import com.android.ide.common.blame.SourceFile;
import com.android.ide.common.blame.SourceFilePosition;
import com.android.ide.common.blame.SourcePosition;
import com.android.ide.common.blame.parser.util.OutputLineReader;
import com.android.ide.common.blame.parser.ParsingFailedException;
import com.android.ide.common.blame.parser.PatternAwareOutputParser;
import com.android.resources.ResourceFolderType;
import com.android.utils.ILogger;
import com.android.utils.SdkUtils;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

@VisibleForTesting
public abstract class AbstractAaptOutputParser implements PatternAwareOutputParser {
    /**
     * Portion of the error message which states the context in which the error occurred, such as
     * which property was being processed and what the string value was that caused the error.
     * 
     * error: No resource found that matches the given name (at 'text' with value '@string/foo')
     * 
*/ private static final Pattern PROPERTY_NAME_AND_VALUE = Pattern .compile("\\(at '(.+)' with value '(.*)'\\)"); /** * Portion of error message which points to the second occurrence of a repeated resource * definition.

Example: error: Resource entry repeatedStyle1 already has bag item * android:gravity. */ private static final Pattern REPEATED_RESOURCE = Pattern .compile("Resource entry (.+) already has bag item (.+)\\."); /** * Suffix of error message which points to the first occurrence of a repeated resource * definition. Example: Originally defined here. */ private static final String ORIGINALLY_DEFINED_HERE = "Originally defined here."; private static final Pattern NO_RESOURCE_FOUND = Pattern .compile("No resource found that matches the given name: attr '(.+)'\\."); /** * Portion of error message which points to a missing required attribute in a resource * definition.

Example: error: error: A 'name' attribute is required for