Ejemplo n.º 1
0
 public void setupLoadOnly(String deobfFileName, boolean loadAll) {
   try {
     File mapData = new File(deobfFileName);
     LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData));
     InputSupplier<InputStreamReader> srgSupplier =
         CharStreams.newReaderSupplier(zis, Charsets.UTF_8);
     List<String> srgList = CharStreams.readLines(srgSupplier);
     rawMethodMaps = Maps.newHashMap();
     rawFieldMaps = Maps.newHashMap();
     Builder<String, String> builder = ImmutableBiMap.<String, String>builder();
     Builder<String, String> mcpBuilder = ImmutableBiMap.<String, String>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);
         parseMCPClass(mcpBuilder, parts);
       } else if ("MD".equals(typ) && loadAll) {
         parseMethod(parts);
       } else if ("FD".equals(typ) && loadAll) {
         parseField(parts);
       }
     }
     classNameBiMap = builder.build();
     mcpNameBiMap = mcpBuilder.build();
   } catch (IOException ioe) {
     FMLRelaunchLog.log(Level.ERROR, "An error occurred loading the deobfuscation map data", ioe);
   }
   methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size());
   fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size());
 }
  @BeforeClass
  public static void createJavaProjects() throws IOException {
    JavaProjectClient.createJavaProject(PROJECT_NAME_1);

    final String content =
        CharStreams.toString(
            CharStreams.newReaderSupplier(new PMDConfigurationSupplier(), Charsets.UTF_8));
    JavaProjectClient.createFileInProject(PROJECT_NAME_1, PMD_XML, content);

    JavaProjectClient.createJavaProject(PROJECT_NAME_2);

    rules = File.createTempFile(PMDConfigurationsTest.class.getSimpleName() + "-", ".xml");
    Files.copy(new PMDConfigurationSupplier(), rules);
  }
Ejemplo n.º 3
0
  private List<ServiceDescriptor> getServiceInventory(SlotStatus slotStatus) {
    Assignment assignment = slotStatus.getAssignment();
    if (assignment == null) {
      return null;
    }

    String config = assignment.getConfig();

    File cacheFile = getCacheFile(config);
    if (cacheFile.canRead()) {
      try {
        String json = CharStreams.toString(Files.newReaderSupplier(cacheFile, Charsets.UTF_8));
        List<ServiceDescriptor> descriptors = descriptorsJsonCodec.fromJson(json);
        invalidServiceInventory.remove(config);
        return descriptors;
      } catch (Exception ignored) {
        // delete the bad cache file
        cacheFile.delete();
      }
    }

    InputSupplier<? extends InputStream> configFile =
        ConfigUtils.newConfigEntrySupplier(repository, config, "airship-service-inventory.json");
    if (configFile == null) {
      return null;
    }

    try {
      String json;
      try {
        json = CharStreams.toString(CharStreams.newReaderSupplier(configFile, Charsets.UTF_8));
      } catch (FileNotFoundException e) {
        // no service inventory in the config, so replace with json null so caching works
        json = "null";
      }
      invalidServiceInventory.remove(config);

      // cache json
      cacheFile.getParentFile().mkdirs();
      Files.write(json, cacheFile, Charsets.UTF_8);

      List<ServiceDescriptor> descriptors = descriptorsJsonCodec.fromJson(json);
      return descriptors;
    } catch (Exception e) {
      if (invalidServiceInventory.add(config)) {
        log.error(e, "Unable to read service inventory for %s" + config);
      }
    }
    return null;
  }
Ejemplo n.º 4
0
 private String tryGetVersion() {
   try {
     InputSupplier<? extends InputStream> versionFileSupplier =
         new InputSupplier<InputStream>() {
           @Override
           public InputStream getInput() throws IOException {
             return VersionCommand.class.getClassLoader().getResourceAsStream("VERSION");
           }
         };
     return CharStreams.toString(
         CharStreams.newReaderSupplier(versionFileSupplier, Charsets.UTF_8));
   } catch (IOException e) {
     throw Throwables.propagate(e);
   }
 }
Ejemplo n.º 5
0
 public void setup(File mcDir, LaunchClassLoader classLoader, String deobfFileName) {
   this.classLoader = classLoader;
   try {
     InputStream classData = getClass().getResourceAsStream(deobfFileName);
     LZMAInputSupplier zis = new LZMAInputSupplier(classData);
     InputSupplier<InputStreamReader> srgSupplier =
         CharStreams.newReaderSupplier(zis, Charsets.UTF_8);
     List<String> srgList = CharStreams.readLines(srgSupplier);
     rawMethodMaps = Maps.newHashMap();
     rawFieldMaps = Maps.newHashMap();
     Builder<String, String> builder = ImmutableBiMap.<String, String>builder();
     Builder<String, String> mcpBuilder = ImmutableBiMap.<String, String>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);
         parseMCPClass(mcpBuilder, parts);
       } else if ("MD".equals(typ)) {
         parseMethod(parts);
       } else if ("FD".equals(typ)) {
         parseField(parts);
       }
     }
     classNameBiMap = builder.build();
     // Special case some mappings for modloader mods
     mcpBuilder.put("BaseMod", "net/minecraft/src/BaseMod");
     mcpBuilder.put("ModLoader", "net/minecraft/src/ModLoader");
     mcpBuilder.put("EntityRendererProxy", "net/minecraft/src/EntityRendererProxy");
     mcpBuilder.put("MLProp", "net/minecraft/src/MLProp");
     mcpBuilder.put("TradeEntry", "net/minecraft/src/TradeEntry");
     mcpNameBiMap = mcpBuilder.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());
 }
Ejemplo n.º 6
0
 public static String toString(InputSupplier<? extends InputStream> supplier) throws IOException {
   return CharStreams.toString(CharStreams.newReaderSupplier(supplier, Charsets.UTF_8));
 }
Ejemplo n.º 7
0
  private static IncrementalIndex makeRealtimeIndex(final String resourceFilename) {
    final URL resource = TestIndex.class.getClassLoader().getResource(resourceFilename);
    log.info("Realtime loading index file[%s]", resource);

    final IncrementalIndex retVal =
        new IncrementalIndex(
            new DateTime("2011-01-12T00:00:00.000Z").getMillis(),
            QueryGranularity.NONE,
            METRIC_AGGS);

    final AtomicLong startTime = new AtomicLong();
    int lineCount;
    try {
      lineCount =
          CharStreams.readLines(
              CharStreams.newReaderSupplier(
                  new InputSupplier<InputStream>() {
                    @Override
                    public InputStream getInput() throws IOException {
                      return resource.openStream();
                    }
                  },
                  Charsets.UTF_8),
              new LineProcessor<Integer>() {
                StringInputRowParser parser =
                    new StringInputRowParser(
                        new TimestampSpec("ts", "iso"),
                        new DelimitedDataSpec(
                            "\t", Arrays.asList(COLUMNS), Arrays.asList(DIMENSIONS)),
                        Arrays.<String>asList());
                boolean runOnce = false;
                int lineCount = 0;

                @Override
                public boolean processLine(String line) throws IOException {
                  if (!runOnce) {
                    startTime.set(System.currentTimeMillis());
                    runOnce = true;
                  }

                  final String[] splits = line.split("\t");

                  retVal.add(parser.parse(line));

                  ++lineCount;
                  return true;
                }

                @Override
                public Integer getResult() {
                  return lineCount;
                }
              });
    } catch (IOException e) {
      realtimeIndex = null;
      throw Throwables.propagate(e);
    }

    log.info(
        "Loaded %,d lines in %,d millis.", lineCount, System.currentTimeMillis() - startTime.get());

    return retVal;
  }