Exemplo n.º 1
0
  public void runParseTest(
      String fieldTerminator,
      String lineTerminator,
      String encloser,
      String escape,
      boolean encloseRequired)
      throws IOException {

    ClassLoader prevClassLoader = null;

    String[] argv =
        getArgv(true, fieldTerminator, lineTerminator, encloser, escape, encloseRequired);
    runImport(argv);
    try {
      String tableClassName = getTableName();

      argv = getArgv(false, fieldTerminator, lineTerminator, encloser, escape, encloseRequired);
      SqoopOptions opts = new ImportTool().parseArguments(argv, null, null, true);

      CompilationManager compileMgr = new CompilationManager(opts);
      String jarFileName = compileMgr.getJarFilename();

      // Make sure the user's class is loaded into our address space.
      prevClassLoader = ClassLoaderStack.addJarFile(jarFileName, tableClassName);

      JobConf job = new JobConf();
      job.setJar(jarFileName);

      // Tell the job what class we're testing.
      job.set(ReparseMapper.USER_TYPE_NAME_KEY, tableClassName);

      // use local mode in the same JVM.
      ConfigurationHelper.setJobtrackerAddr(job, "local");
      if (!BaseSqoopTestCase.isOnPhysicalCluster()) {
        job.set(CommonArgs.FS_DEFAULT_NAME, CommonArgs.LOCAL_FS);
      }
      String warehouseDir = getWarehouseDir();
      Path warehousePath = new Path(warehouseDir);
      Path inputPath = new Path(warehousePath, getTableName());
      Path outputPath = new Path(warehousePath, getTableName() + "-out");

      job.setMapperClass(ReparseMapper.class);
      job.setNumReduceTasks(0);
      FileInputFormat.addInputPath(job, inputPath);
      FileOutputFormat.setOutputPath(job, outputPath);

      job.setOutputKeyClass(Text.class);
      job.setOutputValueClass(NullWritable.class);

      JobClient.runJob(job);
    } catch (InvalidOptionsException ioe) {
      fail(ioe.toString());
    } catch (ParseException pe) {
      fail(pe.toString());
    } finally {
      if (null != prevClassLoader) {
        ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
      }
    }
  }
Exemplo n.º 2
0
  public static void main(String... args) {

    try {
      CommandLineParser parser = new DefaultParser();
      CommandLine cmd = parser.parse(createOptions(), args);

      if (cmd.hasOption("h")) {
        printHelp();
      } else {
        GeneratorParameter parameter = extractParameter(cmd);
        if (parameter.hasSufficientData()) {
          TestHelper testHelper = new TestHelper();
          testHelper.generateTestHelper(parameter);
        } else {
          log.error(
              "Parameters are not sufficient, exiting. "
                  + "WMPRT folder, output folder and namespace must be set.");
        }
      }

    } catch (ParseException e) {
      log.error(e.toString());
    }
  }
	@SuppressWarnings("static-access")
	public static void main(String[] args) {
		try {
			final String vers = System.getProperty("java.version");
			final String requiredJVM = "1.5.0";
			final Package self = Package
					.getPackage("org.openscience.jchempaint");
			String version = GT._("Could not determine JCP version");
			if (self != null) {
				version = JCPPropertyHandler.getInstance(true).getVersion();
			}
			if (vers.compareTo(requiredJVM) < 0) {
				System.err
						.println(GT
								._("WARNING: JChemPaint {0} must be run with a Java VM version {1} or higher.",
										new String[] { version, requiredJVM }));
				System.err.println(GT._("Your JVM version is {0}", vers));
				System.exit(1);
			}

			final Options options = new Options();
			options.addOption("h", "help", false, GT._("gives this help page"));
			options.addOption("v", "version", false,
					GT._("gives JChemPaints version number"));
			options.addOption("d", "debug", false,
					"switches on various debug options");
			options.addOption(OptionBuilder.withArgName("property=value")
					.hasArg().withValueSeparator()
					.withDescription(GT._("supported options are given below"))
					.create("D"));

			CommandLine line = null;
			try {
				final CommandLineParser parser = new PosixParser();
				line = parser.parse(options, args);
			} catch (final UnrecognizedOptionException exception) {
				System.err.println(exception.getMessage());
				System.exit(-1);
			} catch (final ParseException exception) {
				System.err.println("Unexpected exception: "
						+ exception.toString());
			}

			if (line.hasOption("v")) {
				System.out.println("JChemPaint v." + version + "\n");
				System.exit(0);
			}

			if (line.hasOption("h")) {
				System.out.println("JChemPaint v." + version + "\n");

				final HelpFormatter formatter = new HelpFormatter();
				formatter.printHelp("JChemPaint", options);

				// now report on the -D options
				System.out.println();
				System.out
						.println("The -D options are as follows (defaults in parathesis):");
				System.out.println("  cdk.debugging     [true|false] (false)");
				System.out.println("  cdk.debug.stdout  [true|false] (false)");
				System.out
						.println("  user.language     [ar|ca|cs|de|en|es|hu|nb|nl|pl|pt|ru|th] (en)");
				System.out
						.println("  user.language     [ar|ca|cs|de|hu|nb|nl|pl|pt_BR|ru|th] (EN)");

				System.exit(0);
			}
			boolean debug = false;
			if (line.hasOption("d")) {
				debug = true;
			}

			// Set Look&Feel
			final Properties props = JCPPropertyHandler.getInstance(true)
					.getJCPProperties();
			try {
				UIManager.setLookAndFeel(props.getProperty("LookAndFeelClass"));
			} catch (final Throwable e) {
				final String sys = UIManager.getSystemLookAndFeelClassName();
				UIManager.setLookAndFeel(sys);
				props.setProperty("LookAndFeelClass", sys);
			}

			// Language
			props.setProperty("General.language",
					System.getProperty("user.language", "en"));

			// Process command line arguments
			String modelFilename = "";
			args = line.getArgs();
			if (args.length > 0) {
				modelFilename = args[0];
				final File file = new File(modelFilename);
				if (!file.exists()) {
					System.err.println(GT._("File does not exist") + ": "
							+ modelFilename);
					System.exit(-1);
				}
				showInstance(file, null, null, debug);
			} else {
				showEmptyInstance(debug);
			}

		} catch (final Throwable t) {
			System.err.println("uncaught exception: " + t);
			t.printStackTrace(System.err);
		}
	}
Exemplo n.º 4
0
  public static void main(String[] args) {
    Options options = new Options();

    Option inputOpt = OptionBuilder.create(IN);
    inputOpt.setArgName("INPUT");
    inputOpt.setDescription("Input model");
    inputOpt.setArgs(1);
    inputOpt.setRequired(true);

    Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS);
    inClassOpt.setArgName("CLASS");
    inClassOpt.setDescription("FQN of EPackage implementation class");
    inClassOpt.setArgs(1);
    inClassOpt.setRequired(true);

    options.addOption(inputOpt);
    options.addOption(inClassOpt);

    CommandLineParser parser = new PosixParser();

    try {
      CommandLine commandLine = parser.parse(options, args);

      URI uri = URI.createFileURI(commandLine.getOptionValue(IN));

      Class<?> inClazz =
          XmiTraverser.class.getClassLoader().loadClass(commandLine.getOptionValue(EPACKAGE_CLASS));
      inClazz.getMethod("init").invoke(null);

      ResourceSet resourceSet = new ResourceSetImpl();
      resourceSet
          .getResourceFactoryRegistry()
          .getExtensionToFactoryMap()
          .put("xmi", new XMIResourceFactoryImpl());
      resourceSet
          .getResourceFactoryRegistry()
          .getExtensionToFactoryMap()
          .put("zxmi", new XMIResourceFactoryImpl());

      Resource resource = resourceSet.createResource(uri);

      Map<String, Object> loadOpts = new HashMap<String, Object>();
      resource.load(loadOpts);

      LOG.log(Level.INFO, "Start counting");
      int count = 0;
      long begin = System.currentTimeMillis();
      for (Iterator<EObject> iterator = resource.getAllContents();
          iterator.hasNext();
          iterator.next(), count++) ;
      long end = System.currentTimeMillis();
      LOG.log(Level.INFO, "End counting");
      LOG.log(Level.INFO, MessageFormat.format("Resource {0} contains {1} elements", uri, count));
      LOG.log(
          Level.INFO,
          MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin)));

      resource.unload();

    } catch (ParseException e) {
      MessageUtil.showError(e.toString());
      MessageUtil.showError("Current arguments: " + Arrays.toString(args));
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp("java -jar <this-file.jar>", options, true);
    } catch (Throwable e) {
      MessageUtil.showError(e.toString());
    }
  }
  public static void main(String[] args) {
    Options options = new Options();

    Option inputOpt = OptionBuilder.create(IN);
    inputOpt.setArgName("INPUT");
    inputOpt.setDescription("Input CDO resource directory");
    inputOpt.setArgs(1);
    inputOpt.setRequired(true);

    Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS);
    inClassOpt.setArgName("CLASS");
    inClassOpt.setDescription("FQN of EPackage implementation class");
    inClassOpt.setArgs(1);
    inClassOpt.setRequired(true);

    Option repoOpt = OptionBuilder.create(REPO_NAME);
    repoOpt.setArgName("REPO_NAME");
    repoOpt.setDescription("CDO Repository name");
    repoOpt.setArgs(1);
    repoOpt.setRequired(true);

    options.addOption(inputOpt);
    options.addOption(inClassOpt);
    options.addOption(repoOpt);

    CommandLineParser parser = new PosixParser();

    try {
      CommandLine commandLine = parser.parse(options, args);

      String repositoryDir = commandLine.getOptionValue(IN);
      String repositoryName = commandLine.getOptionValue(REPO_NAME);

      Class<?> inClazz =
          CdoQueryGetBranchStatements.class
              .getClassLoader()
              .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS));
      inClazz.getMethod("init").invoke(null);

      EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName);
      try {
        server.run();
        CDOSession session = server.openSession();
        CDOTransaction transaction = session.openTransaction();
        Resource resource = transaction.getRootResource();
        {
          Runtime.getRuntime().gc();
          long initialUsedMemory =
              Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
          LOG.log(
              Level.INFO,
              MessageFormat.format(
                  "Used memory before query: {0}",
                  MessageUtil.byteCountToDisplaySize(initialUsedMemory)));
          LOG.log(Level.INFO, "Start query");
          long begin = System.currentTimeMillis();
          Set<TextElement> list = ASE2015JavaQueries.getCommentsTagContent(resource);
          long end = System.currentTimeMillis();
          LOG.log(Level.INFO, "End query");
          LOG.log(
              Level.INFO, MessageFormat.format("Query result contains {0} elements", list.size()));
          LOG.log(
              Level.INFO,
              MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin)));
          Runtime.getRuntime().gc();
          long finalUsedMemory =
              Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
          LOG.log(
              Level.INFO,
              MessageFormat.format(
                  "Used memory after query: {0}",
                  MessageUtil.byteCountToDisplaySize(finalUsedMemory)));
          LOG.log(
              Level.INFO,
              MessageFormat.format(
                  "Memory use increase: {0}",
                  MessageUtil.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory)));
        }

        transaction.close();
        session.close();
      } finally {
        server.stop();
      }
    } catch (ParseException e) {
      MessageUtil.showError(e.toString());
      MessageUtil.showError("Current arguments: " + Arrays.toString(args));
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp("java -jar <this-file.jar>", options, true);
    } catch (Throwable e) {
      MessageUtil.showError(e.toString());
    }
  }