Search in sources :

Example 1 with Splitter

use of com.google.common.base.Splitter in project buck by facebook.

the class ExopackageInstaller method parsePathAndPackageInfo.

@VisibleForTesting
static Optional<PackageInfo> parsePathAndPackageInfo(String packageName, String rawOutput) {
    Iterable<String> lines = Splitter.on(LINE_ENDING).omitEmptyStrings().split(rawOutput);
    String pmPathPrefix = "package:";
    String pmPath = null;
    for (String line : lines) {
        // Ignore silly linker warnings about non-PIC code on emulators
        if (!line.startsWith("WARNING: linker: ")) {
            pmPath = line;
            break;
        }
    }
    if (pmPath == null || !pmPath.startsWith(pmPathPrefix)) {
        LOG.warn("unable to locate package path for [" + packageName + "]");
        return Optional.empty();
    }
    final String packagePrefix = "  Package [" + packageName + "] (";
    final String otherPrefix = "  Package [";
    boolean sawPackageLine = false;
    final Splitter splitter = Splitter.on('=').limit(2);
    String codePath = null;
    String resourcePath = null;
    String nativeLibPath = null;
    String versionCode = null;
    for (String line : lines) {
        // Just ignore everything until we see the line that says we are in the right package.
        if (line.startsWith(packagePrefix)) {
            sawPackageLine = true;
            continue;
        }
        // This should never happen, but if we do see a different package, stop parsing.
        if (line.startsWith(otherPrefix)) {
            break;
        }
        // Ignore lines before our package.
        if (!sawPackageLine) {
            continue;
        }
        // Parse key-value pairs.
        List<String> parts = splitter.splitToList(line.trim());
        if (parts.size() != 2) {
            continue;
        }
        switch(parts.get(0)) {
            case "codePath":
                codePath = parts.get(1);
                break;
            case "resourcePath":
                resourcePath = parts.get(1);
                break;
            case "nativeLibraryPath":
                nativeLibPath = parts.get(1);
                break;
            // Might need to update if people report failures.
            case "legacyNativeLibraryDir":
                nativeLibPath = parts.get(1);
                break;
            case "versionCode":
                // Extra split to get rid of the SDK thing.
                versionCode = parts.get(1).split(" ", 2)[0];
                break;
            default:
                break;
        }
    }
    if (!sawPackageLine) {
        return Optional.empty();
    }
    Preconditions.checkNotNull(codePath, "Could not find codePath");
    Preconditions.checkNotNull(resourcePath, "Could not find resourcePath");
    Preconditions.checkNotNull(nativeLibPath, "Could not find nativeLibraryPath");
    Preconditions.checkNotNull(versionCode, "Could not find versionCode");
    if (!codePath.equals(resourcePath)) {
        throw new IllegalStateException("Code and resource path do not match");
    }
    // Lollipop doesn't give the full path to the apk anymore.  Not sure why it's "base.apk".
    if (!codePath.endsWith(".apk")) {
        codePath += "/base.apk";
    }
    return Optional.of(new PackageInfo(codePath, nativeLibPath, versionCode));
}
Also used : Splitter(com.google.common.base.Splitter) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with Splitter

use of com.google.common.base.Splitter in project pinot by linkedin.

the class MultipleOrEqualitiesToInClauseFilterQueryTreeOptimizer method valueDoubleTabListToElements.

private List<String> valueDoubleTabListToElements(List<String> doubleTabSeparatedElements) {
    Splitter valueSplitter = Splitter.on("\t\t");
    List<String> valueElements = new ArrayList<>();
    for (String value : doubleTabSeparatedElements) {
        valueElements.addAll(valueSplitter.splitToList(value));
    }
    return valueElements;
}
Also used : Splitter(com.google.common.base.Splitter) ArrayList(java.util.ArrayList)

Example 3 with Splitter

use of com.google.common.base.Splitter in project MinecraftForge by MinecraftForge.

the class FMLDeobfuscatingRemapper method setup.

public void setup(File mcDir, LaunchClassLoader classLoader, String deobfFileName) {
    this.classLoader = classLoader;
    try {
        List<String> srgList;
        final String gradleStartProp = System.getProperty("net.minecraftforge.gradle.GradleStart.srg.srg-mcp");
        if (Strings.isNullOrEmpty(gradleStartProp)) {
            // get as a resource
            InputStream classData = getClass().getResourceAsStream(deobfFileName);
            LZMAInputSupplier zis = new LZMAInputSupplier(classData);
            CharSource srgSource = zis.asCharSource(Charsets.UTF_8);
            srgList = srgSource.readLines();
            FMLRelaunchLog.fine("Loading deobfuscation resource %s with %d records", deobfFileName, srgList.size());
        } else {
            srgList = Files.readLines(new File(gradleStartProp), Charsets.UTF_8);
            FMLRelaunchLog.fine("Loading deobfuscation resource %s with %d records", gradleStartProp, srgList.size());
        }
        rawMethodMaps = Maps.newHashMap();
        rawFieldMaps = Maps.newHashMap();
        Builder<String, String> builder = ImmutableBiMap.builder();
        Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults();
        for (String line : srgList) {
            String[] parts = Iterables.toArray(splitter.split(line), String.class);
            String typ = parts[0];
            if ("CL".equals(typ)) {
                parseClass(builder, parts);
            } else if ("MD".equals(typ)) {
                parseMethod(parts);
            } else if ("FD".equals(typ)) {
                parseField(parts);
            }
        }
        classNameBiMap = builder.build();
    } catch (IOException ioe) {
        FMLRelaunchLog.log(Level.ERROR, ioe, "An error occurred loading the deobfuscation map data");
    }
    methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size());
    fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size());
}
Also used : CharSource(com.google.common.io.CharSource) Splitter(com.google.common.base.Splitter) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) File(java.io.File)

Example 4 with Splitter

use of com.google.common.base.Splitter in project kotlin by JetBrains.

the class Project method getProguardFiles.

/**
     * Returns the proguard files configured for this project, if any
     *
     * @return the proguard files, if any
     */
@NonNull
public List<File> getProguardFiles() {
    if (mProguardFiles == null) {
        List<File> files = new ArrayList<File>();
        if (mProguardPath != null) {
            //$NON-NLS-1$
            Splitter splitter = Splitter.on(CharMatcher.anyOf(":;"));
            for (String path : splitter.split(mProguardPath)) {
                if (path.contains("${")) {
                    // Don't analyze the global/user proguard files
                    continue;
                }
                File file = new File(path);
                if (!file.isAbsolute()) {
                    file = new File(getDir(), path);
                }
                if (file.exists()) {
                    files.add(file);
                }
            }
        }
        if (files.isEmpty()) {
            File file = new File(getDir(), OLD_PROGUARD_FILE);
            if (file.exists()) {
                files.add(file);
            }
            file = new File(getDir(), FN_PROJECT_PROGUARD_FILE);
            if (file.exists()) {
                files.add(file);
            }
        }
        mProguardFiles = files;
    }
    return mProguardFiles;
}
Also used : Splitter(com.google.common.base.Splitter) ArrayList(java.util.ArrayList) OutputFile(com.android.build.OutputFile) File(java.io.File) NonNull(com.android.annotations.NonNull)

Example 5 with Splitter

use of com.google.common.base.Splitter in project gerrit by GerritCodeReview.

the class ChangeEmail method getDiffTemplateData.

/**
   * Generate a Soy list of maps representing each line of the unified diff. The line maps will have
   * a 'type' key which maps to one of 'common', 'add' or 'remove' and a 'text' key which maps to
   * the line's content.
   */
private SoyListData getDiffTemplateData() {
    SoyListData result = new SoyListData();
    Splitter lineSplitter = Splitter.on(System.getProperty("line.separator"));
    for (String diffLine : lineSplitter.split(getUnifiedDiff())) {
        SoyMapData lineData = new SoyMapData();
        lineData.put("text", diffLine);
        // Skip empty lines and lines that look like diff headers.
        if (diffLine.isEmpty() || diffLine.startsWith("---") || diffLine.startsWith("+++")) {
            lineData.put("type", "common");
        } else {
            switch(diffLine.charAt(0)) {
                case '+':
                    lineData.put("type", "add");
                    break;
                case '-':
                    lineData.put("type", "remove");
                    break;
                default:
                    lineData.put("type", "common");
                    break;
            }
        }
        result.add(lineData);
    }
    return result;
}
Also used : Splitter(com.google.common.base.Splitter) SoyMapData(com.google.template.soy.data.SoyMapData) SoyListData(com.google.template.soy.data.SoyListData)

Aggregations

Splitter (com.google.common.base.Splitter)86 ArrayList (java.util.ArrayList)19 IOException (java.io.IOException)11 HashSet (java.util.HashSet)10 File (java.io.File)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)5 BufferedReader (java.io.BufferedReader)4 NonNull (com.android.annotations.NonNull)3 URI (java.net.URI)3 URL (java.net.URL)3 ItemStack (net.minecraft.item.ItemStack)3 StringColumn (tech.tablesaw.api.StringColumn)3 CharMatcher (com.google.common.base.CharMatcher)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 CharSource (com.google.common.io.CharSource)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2