Java Code Examples for net.sourceforge.argparse4j.inf.Namespace#get()

The following examples show how to use net.sourceforge.argparse4j.inf.Namespace#get() . 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: DeleteUserCommitData.java    From clue with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Namespace args, PrintStream out) throws Exception {
	IndexWriter writer = luceneContext.getIndexWriter();
	if (writer != null) {
		String key = args.get("key");
		Iterable<Map.Entry<String, String>> commitData = writer.getLiveCommitData();
		List<Map.Entry<String, String>> commitList = new LinkedList<>();
		for (Map.Entry<String, String> dataEntry : commitData) {
			if (!dataEntry.equals(key)) {
				commitList.add(dataEntry);
			}
		}
	    if (commitList.size() > 0) {
		  writer.setLiveCommitData(commitList);
		  writer.commit();
			luceneContext.refreshReader();
		  out.println("commit data: " + key +" removed.");
	    } else {
		  out.println("no commit data found, no action taken");
	    }
	} else {
		out.println("unable to open writer, index is in readonly mode");
	}
}
 
Example 2
Source File: Main.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Initialize Main - must be called before any other getter can be used.
 *
 * @param argv the command line arguments to be parsed
 */
private static Namespace parseCommands(String[] argv)
{
	Namespace args = getParser().parseArgsOrFail(argv);

	if (args.getInt("verbose") > 0)
	{

		Logging.setCurrentLoggingLevel(Logging.DEBUG);
	}

	settingsDir = args.getString("settingsdir");
	campaignMode = args.getString("campaignmode");
	characterSheet = args.get("D");
	exportSheet = args.get("E");
	partyFile = args.get("p");
	characterFile = args.get("c");
	outputFile = args.get("o");
	startNameGen = args.get("name_generator");

	return args;
}
 
Example 3
Source File: Generate.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
public static GeneratorArguments getGeneratorArguments(
    Namespace ns) {
  final EnabledTransformations enabledTransformations
      = getTransformationDisablingFlags(ns);
  final File donors = ns.get("donors");
  if (!donors.isDirectory()) {
    throw new RuntimeException("Donors directory '" + donors.toString() + "' does not exist.");
  }
  ShaderKind shaderStage = ns.get("shader_stage");
  return new GeneratorArguments(
      ns.getBoolean("small"),
      ns.getBoolean("allow_long_loops"),
      ns.getBoolean("single_pass"),
      ns.getBoolean("aggressively_complicate_control_flow"),
      ns.getBoolean("replace_float_literals"),
      donors,
      ns.get("vulkan"),
      ns.get("max_uniforms"),
      enabledTransformations,
      !ns.getBoolean("no_injection_switch"),
      Optional.ofNullable(shaderStage),
      ns.getFloat("push_constant_probability")
  );
}
 
Example 4
Source File: Main.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Initialize Main - must be called before any other getter can be used.
 *
 * @param argv the command line arguments to be parsed
 */
private static Namespace parseCommands(String[] argv)
{
	Namespace args = getParser().parseArgsOrFail(argv);

	if (args.getInt("verbose") > 0)
	{

		Logging.setCurrentLoggingLevel(Logging.DEBUG);
	}

	settingsDir = args.getString("settingsdir");
	campaignMode = args.getString("campaignmode");
	characterSheet = args.get("D");
	exportSheet = args.get("E");
	partyFile = args.get("p");
	characterFile = args.get("c");
	outputFile = args.get("o");
	startNameGen = args.get("name_generator");

	return args;
}
 
Example 5
Source File: GlslGenerate.java    From graphicsfuzz with Apache License 2.0 5 votes vote down vote up
private static List<String> getGenerateShaderFamilyArgs(Namespace ns,
                                                        File overallOutputDir,
                                                        File shaderJobFile,
                                                        String prefix,
                                                        int innerSeed) {
  List<String> result = new ArrayList<>();
  result.add(shaderJobFile.getAbsolutePath());
  result.add(ns.get("donors").toString());
  result.add(new File(overallOutputDir,
      prefix + "_" + FilenameUtils.removeExtension(shaderJobFile.getName())).getAbsolutePath());
  result.add("--seed");
  result.add(String.valueOf(innerSeed));

  for (String arg : ns.getAttrs().keySet()) {
    switch (arg) {
      // These arguments are either dealt with above, or are irrelevant.
      case "donors":
      case "output_dir":
      case "prefix":
      case "references":
      case "seed":
        continue;
      default:
        break;
    }
    if (ns.get(arg) == null) {
      continue;
    }
    final String replacementArg = arg.replace("_", "-");
    if (ns.get(arg) instanceof Boolean) {
      if (ns.getBoolean(arg)) {
        result.add("--" + replacementArg);
      }
    } else {
      result.add("--" + replacementArg);
      result.add(ns.get(arg).toString());
    }
  }
  return result;
}
 
Example 6
Source File: Child.java    From dockerfile-image-update with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void execute(final Namespace ns, final DockerfileGitHubUtil dockerfileGitHubUtil)
        throws IOException, InterruptedException {
    String branch = ns.get(Constants.GIT_BRANCH);
    String img = ns.get(Constants.IMG);
    String forceTag = ns.get(Constants.FORCE_TAG);

    /* Updates store if a store is specified. */
    dockerfileGitHubUtil.getGitHubJsonStore(ns.get(Constants.STORE)).updateStore(img, forceTag);

    log.info("Retrieving repository and creating fork...");
    GHRepository repo = dockerfileGitHubUtil.getRepo(ns.get(Constants.GIT_REPO));
    GHRepository fork = dockerfileGitHubUtil.getOrCreateFork(repo);
    if (fork == null) {
        log.info("Unable to fork {}. Please make sure that the repo is forkable.",
                repo.getFullName());
        return;
    }

    GitForkBranch gitForkBranch = new GitForkBranch(img, forceTag, branch);

    dockerfileGitHubUtil.createOrUpdateForkBranchToParentDefault(repo, fork, gitForkBranch);

    log.info("Modifying on Github...");
    dockerfileGitHubUtil.modifyAllOnGithub(fork, gitForkBranch.getBranchName(), img, forceTag);
    dockerfileGitHubUtil.createPullReq(repo, gitForkBranch.getBranchName(), fork, ns.get(Constants.GIT_PR_TITLE));
}
 
Example 7
Source File: ComplianceToolMode.java    From verify-service-provider with MIT License 5 votes vote down vote up
@Override
public void run(Bootstrap<?> wildcardBootstrap, Namespace namespace) throws Exception {
    Integer port = namespace.get(PORT);
    String bindHost = namespace.get(BIND_HOST);

    Bootstrap<VerifyServiceProviderConfiguration> bootstrap = (Bootstrap<VerifyServiceProviderConfiguration>) wildcardBootstrap;
    bootstrap.setConfigurationFactoryFactory(complianceToolModeConfigurationFactory(port, bindHost));
    super.run(bootstrap, namespace);
}
 
Example 8
Source File: GenerateSpecsCommand.java    From jobson with Apache License 2.0 5 votes vote down vote up
@Override
protected void run(Bootstrap<ApplicationConfig> bootstrap, Namespace namespace, ApplicationConfig applicationConfig) throws Exception {
    specTemplate = loadResourceFileAsString("spec-template.yml");

    final ArrayList<String> specNames = namespace.get(SPEC_NAMES_ARG);
    final Path specsDir = Paths.get(applicationConfig.getJobSpecConfiguration().getDir());

    if (specsDir.toFile().exists()) {
        ensureSpecsDoNotAlreadyExistIn(specsDir, specNames);
        createDefaultSpecDirs(specsDir, specNames);
    } else {
        System.err.println(specsDir + ": No such directory");
        System.exit(1);
    }
}
 
Example 9
Source File: DiffyCliProcessor.java    From jolt with Apache License 2.0 5 votes vote down vote up
/**
 * Process the Diffy Subcommand
 *
 * @param ns Namespace which contains parsed commandline arguments
 * @return true if no differences are found, false if a difference is found or an error occurs
 */
@Override
public boolean process( Namespace ns ) {
    boolean suppressOutput = ns.getBoolean( "s" );

    Object jsonObject1 = JoltCliUtilities.createJsonObjectFromFile( (File) ns.get( "filePath1" ), suppressOutput );
    File file = ns.get( "filePath2" );
    Object jsonObject2 = JoltCliUtilities.readJsonInput( file, suppressOutput );

    Diffy diffy;
    if ( ns.getBoolean( "a" ) ) {
        diffy = new ArrayOrderObliviousDiffy();
    } else {
        diffy = new Diffy();
    }
    Diffy.Result result = diffy.diff( jsonObject1, jsonObject2 );

    if ( result.isEmpty() ) {
        JoltCliUtilities.printToStandardOut( "Diffy found no differences", suppressOutput );
        return true;
    } else {
        try {
            JoltCliUtilities.printToStandardOut( "Differences found. Input #1 contained this:\n" +
                    JsonUtils.toPrettyJsonString( result.expected ) + "\n" +
                    "Input #2 contained this:\n" +
                    JsonUtils.toPrettyJsonString( result.actual ), suppressOutput );

        }
        catch ( Exception e ) {
            JoltCliUtilities.printToStandardOut( "Differences found, but diffy encountered an error while writing the result.", suppressOutput );
        }
        return false;
    }
}
 
Example 10
Source File: SortCliProcessor.java    From jolt with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param ns Namespace which contains parsed commandline arguments
 * @return true if the sort was successful, false if an error occurred
 */
@Override
public boolean process( Namespace ns ) {

    File file = ns.get( "input" );
    Object jsonObject = JoltCliUtilities.readJsonInput( file, SUPPRESS_OUTPUT );
    if ( jsonObject == null ) {
        return false;
    }

    Sortr sortr = new Sortr();
    Object output = sortr.transform( jsonObject );
    Boolean uglyPrint = ns.getBoolean( "u" );
    return JoltCliUtilities.printJsonObject( output, uglyPrint, SUPPRESS_OUTPUT );
}
 
Example 11
Source File: UseraddCommand.java    From jobson with Apache License 2.0 5 votes vote down vote up
@Override
protected void run(Bootstrap<ApplicationConfig> bootstrap, Namespace namespace, ApplicationConfig applicationConfig) throws Exception {
    final UserId login = new UserId(namespace.get(LOGIN_ARG));
    final File userFile = new File(applicationConfig.getUsersConfiguration().getFile());
    final FilesystemUserDAO dao = new FilesystemUserDAO(userFile);

    final boolean userExists = dao.getUserCredentialsById(login).isPresent();

    if (!userExists) {
        addNewUser(namespace, dao, login);
    } else {
        System.err.println(format("user '%s' already exists, you can set this user's password with `passwd`.", login));
        System.exit(1);
    }
}
 
Example 12
Source File: ComplianceToolModeTest.java    From verify-service-provider with MIT License 5 votes vote down vote up
@Test
public void testThatThereAreDefaults() throws Exception {
    ComplianceToolMode complianceToolMode = new ComplianceToolMode(objectMapper, Validators.newValidator(), mock(VerifyServiceProviderApplication.class));

    final Subparser subparser = createParser();
    complianceToolMode.configure(subparser);

    Namespace namespace = subparser.parseArgs(noArguments());

    MatchingDataset actual = namespace.get(ComplianceToolMode.IDENTITY_DATASET);
    String expectedMatchingDataset = FixtureHelpers.fixture("default-test-identity-dataset.json");
    String receivedMatchingDataset = objectMapper.writeValueAsString(actual);
    assertThat(new JSONObject(receivedMatchingDataset))
            .isEqualToComparingFieldByFieldRecursively(new JSONObject(expectedMatchingDataset));

    String url = namespace.get(ComplianceToolMode.ASSERTION_CONSUMER_URL);
    assertThat(url).isEqualTo(ComplianceToolMode.DEFAULT_CONSUMER_URL);

    Integer timeout = namespace.get(ComplianceToolMode.TIMEOUT);
    assertThat(timeout).isEqualTo(ComplianceToolMode.DEFAULT_TIMEOUT);

    Integer port = namespace.get(ComplianceToolMode.PORT);
    assertThat(port).isEqualTo(ComplianceToolMode.DEFAULT_PORT);

    String host = namespace.get(ComplianceToolMode.BIND_HOST);
    assertThat(host).isEqualTo(ComplianceToolMode.DEFAULT_HOST);

}
 
Example 13
Source File: Generate.java    From graphicsfuzz with Apache License 2.0 5 votes vote down vote up
public static EnabledTransformations getTransformationDisablingFlags(Namespace ns) {
  final EnabledTransformations result = new EnabledTransformations();
  final List<Class<? extends ITransformation>> toDisable = new ArrayList<>();
  if (ns.get("disable") != null) {
    if (ns.get("enable_only") != null) {
      throw new RuntimeException("--disable and --enable_only are not compatible");
    }
    toDisable.addAll(EnabledTransformations.namesToList(ns.get("disable")));
  } else if (ns.get("enable_only") != null) {
    toDisable.addAll(EnabledTransformations.allTransformations());
    toDisable.removeAll(EnabledTransformations.namesToList(ns.get("enable_only")));
  }
  toDisable.forEach(result::disable);
  return result;
}
 
Example 14
Source File: SynthesizeText.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {

    ArgumentParser parser =
        ArgumentParsers.newFor("SynthesizeText")
            .build()
            .defaultHelp(true)
            .description("Synthesize a text, text with audio effect profiles, or ssml.");

    MutuallyExclusiveGroup group = parser.addMutuallyExclusiveGroup().required(true);
    group
        .addArgument("--text")
        .help("The text file from which to synthesize speech.")
        .nargs("+")
        .metavar("TEXT", "EFFECTSPROFILE(optional)");
    group.addArgument("--ssml").help("The ssml file from which to synthesize speech.");

    try {
      Namespace namespace = parser.parseArgs(args);

      if ((namespace.get("text") != null)) {
        if (namespace.getList("text").size() == 2) {
          synthesizeTextWithAudioProfile(
              namespace.getList("text").get(0).toString(),
              namespace.getList("text").get(1).toString());

        } else {
          synthesizeText(namespace.getString("text"));
        }

      } else {
        synthesizeSsml(namespace.getString("ssml"));
      }
    } catch (ArgumentParserException e) {
      parser.handleError(e);
    }
  }
 
Example 15
Source File: ArgsParser.java    From RepoSense with MIT License 4 votes vote down vote up
/**
 * Parses the given string arguments to a {@code CliArguments} object.
 *
 * @throws HelpScreenException if given args contain the --help flag. Help message will be printed out
 * by the {@code ArgumentParser} hence this is to signal to the caller that the program is safe to exit.
 * @throws ParseException if the given string arguments fails to parse to a {@code CliArguments} object.
 */
public static CliArguments parse(String[] args) throws HelpScreenException, ParseException {
    try {
        ArgumentParser parser = getArgumentParser();
        Namespace results = parser.parseArgs(args);

        Path configFolderPath = results.get(CONFIG_FLAGS[0]);
        Path reportFolderPath = results.get(VIEW_FLAGS[0]);
        Path outputFolderPath = results.get(OUTPUT_FLAGS[0]);
        Optional<Date> cliSinceDate = results.get(SINCE_FLAGS[0]);
        Optional<Date> cliUntilDate = results.get(UNTIL_FLAGS[0]);
        boolean isSinceDateProvided = cliSinceDate.isPresent();
        boolean isUntilDateProvided = cliUntilDate.isPresent();
        Date sinceDate = cliSinceDate.orElse(getDateMinusAMonth(cliUntilDate));
        Date untilDate = cliUntilDate.orElse(getCurrentDate());
        List<String> locations = results.get(REPO_FLAGS[0]);
        List<FileType> formats = FileType.convertFormatStringsToFileTypes(results.get(FORMAT_FLAGS[0]));
        boolean isStandaloneConfigIgnored = results.get(IGNORE_FLAGS[0]);
        ZoneId zoneId = results.get(TIMEZONE_FLAGS[0]);

        LogsManager.setLogFolderLocation(outputFolderPath);

        verifySinceDateIsValid(sinceDate);
        verifyDatesRangeIsCorrect(sinceDate, untilDate);

        if (reportFolderPath != null && !reportFolderPath.equals(EMPTY_PATH)
                && configFolderPath.equals(DEFAULT_CONFIG_PATH) && locations == null) {
            return new ViewCliArguments(reportFolderPath);
        }

        boolean isAutomaticallyLaunching = reportFolderPath != null;

        if (isAutomaticallyLaunching && !reportFolderPath.equals(EMPTY_PATH)) {
            logger.info(String.format("Ignoring argument '%s' for --view.", reportFolderPath.toString()));
        }

        if (locations != null) {
            return new LocationsCliArguments(locations, outputFolderPath, sinceDate, untilDate, isSinceDateProvided,
                    isUntilDateProvided, formats, isAutomaticallyLaunching, isStandaloneConfigIgnored, zoneId);
        }

        if (configFolderPath.equals(EMPTY_PATH)) {
            logger.info(MESSAGE_USING_DEFAULT_CONFIG_PATH);
        }
        return new ConfigCliArguments(configFolderPath, outputFolderPath, sinceDate, untilDate, isSinceDateProvided,
                isUntilDateProvided, formats, isAutomaticallyLaunching, isStandaloneConfigIgnored, zoneId);
    } catch (HelpScreenException hse) {
        throw hse;
    } catch (ArgumentParserException ape) {
        throw new ParseException(getArgumentParser().formatUsage() + ape.getMessage() + "\n");
    }
}
 
Example 16
Source File: RunShaderFamily.java    From graphicsfuzz with Apache License 2.0 4 votes vote down vote up
public static void mainHelper(
    String[] args,
    FuzzerServiceManager.Iface managerOverride)
    throws ShaderDispatchException, InterruptedException, IOException, ArgumentParserException {

  ArgumentParser parser = ArgumentParsers.newArgumentParser("RunShaderFamily")
      .defaultHelp(true)
      .description("Get images for all shaders in a shader set.");

  parser.addArgument("--verbose")
      .action(Arguments.storeTrue())
      .help("Verbose output.");

  parser.addArgument("--server")
      .help(
          "URL of server to use for sending get image requests.")
      .type(String.class);

  parser.addArgument("--worker")
      .help("The name of the worker used for get image requests. Used with --server.")
      .type(String.class);

  parser.addArgument("--output")
      .help("Output directory.")
      .setDefault(new File("."))
      .type(File.class);

  parser.addArgument("shader_family")
      .help("Shader family directory, or prefix of single shader job")
      .type(String.class);

  Namespace ns = parser.parseArgs(args);

  final boolean verbose = ns.get("verbose");
  final String shaderFamily = ns.get("shader_family");
  final String server = ns.get("server");
  final String worker = ns.get("worker");
  final File outputDir = ns.get("output");

  if (managerOverride != null && (server == null || worker == null)) {
    throw new ArgumentParserException(
        "Must supply server (dummy string) and worker name when executing in server process.",
        parser);
  }

  if (server != null) {
    if (worker == null) {
      throw new ArgumentParserException("With --server, must supply --worker name.", parser);
    }
  }

  IShaderDispatcher imageGenerator =
      server == null
          ? new LocalShaderDispatcher(false)
          : new RemoteShaderDispatcher(
              server + "/manageAPI",
              worker,
              managerOverride,
              new AtomicLong());

  FileUtils.forceMkdir(outputDir);

  if (!new File(shaderFamily).isDirectory()) {
    if (!new File(shaderFamily + ".json").exists()) {
      throw new ArgumentParserException(
          "Shader family must be a directory or the prefix of a single shader job.", parser);
    }
    // Special case: run get image on a single shader.
    runShader(outputDir, shaderFamily, imageGenerator,
        Optional.empty());
    return;
  }

  IShaderSet shaderSet = new LocalShaderSet(new File(shaderFamily));

  runShaderFamily(shaderSet, outputDir, imageGenerator);
}
 
Example 17
Source File: FuzzyImageComparison.java    From graphicsfuzz with Apache License 2.0 4 votes vote down vote up
public static MainResult mainHelper(String[] args) throws IOException,
    ArgumentParserException {

  // See FuzzyImageComparisonTool for main.

  ArgumentParser parser = ArgumentParsers.newArgumentParser("FuzzyImageComparison")
      .description("Compare two images using a fuzzy pixel comparison. The exit status is "
          + MainResult.EXIT_STATUS_SIMILAR + " if the images are similar, "
          + MainResult.EXIT_STATUS_DIFFERENT + " if the images are different, or another value "
          + "if an error occurs. "
          + "Example: FuzzyImageComparison imageA.png imageB.png 25 4 100 10");

  parser.addArgument("imageA")
      .help("Path to first image file")
      .type(File.class);

  parser.addArgument("imageB")
      .help("Path to second image file")
      .type(File.class);

  parser.addArgument("configurations")
      .help("zero or more configurations (each configuration is a "
          + CONFIG_NUM_ARGS
          + "-tuple of integer arguments): "
          + "componentThreshold "
          + "distanceThreshold "
          + "numBadPixelsThreshold "
          + "numBadSparsePixelsThreshold")
      .nargs("*");

  Namespace ns = parser.parseArgs(args);

  final File imageA = ns.get("imageA");
  final File imageB = ns.get("imageB");
  final List<String> stringConfigurations = new ArrayList<>(ns.get("configurations"));

  if ((stringConfigurations.size() % CONFIG_NUM_ARGS) != 0) {
    throw new ArgumentParserException(
        "Configuration list must be a list of " + CONFIG_NUM_ARGS + "-tuples", parser);
  }

  List<ThresholdConfiguration> configurations = new ArrayList<>();

  for (int i = 0; i < stringConfigurations.size(); i += CONFIG_NUM_ARGS) {
    configurations.add(
        new ThresholdConfiguration(
            Integer.parseInt(stringConfigurations.get(i)),
            Integer.parseInt(stringConfigurations.get(i + 1)),
            Integer.parseInt(stringConfigurations.get(i + 2)),
            Integer.parseInt(stringConfigurations.get(i + 3))
        ));
  }

  if (configurations.isEmpty()) {
    addDefaultConfigurations(configurations);
  }

  compareImages(imageA, imageB, configurations);

  boolean different =
      configurations.stream().anyMatch(ThresholdConfiguration::areImagesDifferent);

  return new MainResult(
      different,
      different ? MainResult.EXIT_STATUS_DIFFERENT : MainResult.EXIT_STATUS_SIMILAR,
      configurations
  );
}
 
Example 18
Source File: RunShaderFamily.java    From graphicsfuzz with Apache License 2.0 4 votes vote down vote up
public static void mainHelper(
    String[] args,
    FuzzerServiceManager.Iface managerOverride)
    throws ShaderDispatchException, InterruptedException, IOException, ArgumentParserException {

  ArgumentParser parser = ArgumentParsers.newArgumentParser("RunShaderFamily")
      .defaultHelp(true)
      .description("Get images for all shaders in a shader family.");

  parser.addArgument("--verbose")
      .action(Arguments.storeTrue())
      .help("Verbose output.");

  parser.addArgument("--server")
      .help(
          "URL of server to use for sending get image requests.")
      .type(String.class);

  parser.addArgument("--worker")
      .help("The worker used for get image requests. Used with --server.")
      .type(String.class);

  parser.addArgument("--output")
      .help("Output directory.")
      .setDefault(new File("."))
      .type(File.class);

  parser.addArgument("shader_family")
      .help("Shader family directory, or a single shader job .json file")
      .type(File.class);


  Namespace ns = parser.parseArgs(args);

  final boolean verbose = ns.get("verbose");
  final File shaderFamily = ns.get("shader_family");
  final String server = ns.get("server");
  final String worker = ns.get("worker");
  final File outputDir = ns.get("output");

  if (managerOverride != null && (server == null || worker == null)) {
    throw new ArgumentParserException(
        "Must supply server (dummy string) and worker name when executing in server process.",
        parser);
  }

  if (server != null) {
    if (worker == null) {
      throw new ArgumentParserException("Must supply worker name with server.", parser);
    }
  }

  ShaderJobFileOperations fileOps = new ShaderJobFileOperations();

  IShaderDispatcher imageGenerator =
      server == null
          ? new LocalShaderDispatcher(false, fileOps, new File(outputDir, "temp"))
          : new RemoteShaderDispatcher(
              server + "/manageAPI",
              worker,
              managerOverride,
              new AtomicLong());

  fileOps.mkdir(outputDir);

  if (!fileOps.isDirectory(shaderFamily)) {
    if (!fileOps.doesShaderJobExist(shaderFamily)) {
      throw new ArgumentParserException(
          "Shader family must be a directory or the prefix of a single shader job.", parser);
    }
    // Special case: run get image on a single shader.
    String shaderName = FilenameUtils.removeExtension(shaderFamily.getName());
    runShader(
        new File(outputDir, shaderName + ".info.json"),
        shaderFamily,
        imageGenerator,
        Optional.empty(),
        fileOps);
    return;
  }

  int numRun = runShaderFamily(shaderFamily, outputDir, imageGenerator, fileOps);

  LOGGER.info("Ran {} shaders.", numRun);
}
 
Example 19
Source File: GenerateAndRunShaders.java    From graphicsfuzz with Apache License 2.0 4 votes vote down vote up
public static void mainHelper(String[] args)
    throws IOException, InterruptedException, ArgumentParserException {
  final Namespace ns = parse(args);
  final ShaderJobFileOperations fileOps = new ShaderJobFileOperations();
  final File referencesDir = ns.get("references");

  if (!fileOps.isDirectory(referencesDir)) {
    throw new IllegalArgumentException("References directory does not exist.");
  }
  final File donors = ns.get("donors");
  if (!fileOps.isDirectory(donors)) {
    throw new IllegalArgumentException("Donors directory does not exist.");
  }
  final File outputDir = ns.get("output_dir");
  fileOps.deleteDirectory(outputDir);
  fileOps.mkdir(outputDir);

  // Queue of shader jobs to be processed.
  final BlockingQueue<ShaderJob> queue =
      new LinkedBlockingQueue<>();

  final File crashStringsToIgnoreFile = ns.get("ignore_crash_strings");
  final Set<String> crashStringsToIgnore = new HashSet<>();
  if (crashStringsToIgnoreFile != null) {
    crashStringsToIgnore.addAll(fileOps.readLines(crashStringsToIgnoreFile));
  }
  File[] shaderJobFiles = fileOps.listShaderJobFiles(referencesDir, (dir, name) -> true);

  if (shaderJobFiles.length <= 0) {
    throw new IllegalArgumentException("No shader jobs found.");
  }

  final Thread consumer = new Thread(new ShaderConsumer(
      LIMIT,
      queue,
      outputDir,
      ns.get("server"),
      ns.get("worker"),
      crashStringsToIgnore,
      fileOps));
  consumer.start();

  final Thread producer = new Thread(new ShaderProducer(
      LIMIT,
      shaderJobFiles,
      queue,
      referencesDir,
      donors,
      ns,
      fileOps));
  producer.start();

  consumer.join();
  producer.join();

}
 
Example 20
Source File: Parent.java    From dockerfile-image-update with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void execute(final Namespace ns, DockerfileGitHubUtil dockerfileGitHubUtil)
        throws IOException, InterruptedException {
    loadDockerfileGithubUtil(dockerfileGitHubUtil);
    String img = ns.get(Constants.IMG);
    String tag = ns.get(Constants.TAG);

    log.info("Updating store...");
    this.dockerfileGitHubUtil.getGitHubJsonStore(ns.get(Constants.STORE)).updateStore(img, tag);

    GitHubPullRequestSender pullRequestSender =
            new GitHubPullRequestSender(dockerfileGitHubUtil, new ForkableRepoValidator(dockerfileGitHubUtil));

    GitForkBranch gitForkBranch =
            new GitForkBranch(ns.get(Constants.IMG), ns.get(Constants.TAG), ns.get(Constants.GIT_BRANCH));

    log.info("Finding Dockerfiles with the given image...");
    Optional<PagedSearchIterable<GHContent>> contentsWithImage = dockerfileGitHubUtil.getGHContents(ns.get(Constants.GIT_ORG), img);
    if (contentsWithImage.isPresent()) {
        Multimap<String, GitHubContentToProcess> pathToDockerfilesInParentRepo =
                pullRequestSender.forkRepositoriesFoundAndGetPathToDockerfiles(contentsWithImage.get(), gitForkBranch);
        List<IOException> exceptions = new ArrayList<>();
        List<String> skippedRepos = new ArrayList<>();

        for (String currUserRepo : pathToDockerfilesInParentRepo.keySet()) {
            Optional<GitHubContentToProcess> forkWithContentPaths =
                    pathToDockerfilesInParentRepo.get(currUserRepo).stream().findFirst();
            if (forkWithContentPaths.isPresent()) {
                try {
                    changeDockerfiles(ns, pathToDockerfilesInParentRepo, forkWithContentPaths.get(), skippedRepos);
                } catch (IOException e) {
                    log.error(String.format("Error changing Dockerfile for %s", forkWithContentPaths.get().getParent().getFullName()), e);
                    exceptions.add(e);
                }
            } else {
                log.warn("Didn't find fork for {} so not changing Dockerfiles", currUserRepo);
            }
        }

        ResultsProcessor.processResults(skippedRepos, exceptions, log);
    }
}