Search in sources :

Example 1 with ArgDecl

use of jena.cmd.ArgDecl in project jena by apache.

the class TestCmdLine method test_Flag1.

@Test
public void test_Flag1() {
    String[] args = new String[] { "" };
    CmdLineArgs cl = new CmdLineArgs(args);
    ArgDecl argA = new ArgDecl(false, "-a");
    cl.add(argA);
    cl.process();
    assertTrue("-a argument found", !cl.contains(argA));
}
Also used : ArgDecl(jena.cmd.ArgDecl) CmdLineArgs(jena.cmd.CmdLineArgs) Test(org.junit.Test)

Example 2 with ArgDecl

use of jena.cmd.ArgDecl in project jena by apache.

the class TestCmdLine method test_Flag2.

@Test
public void test_Flag2() {
    String[] args = new String[] { "-a" };
    CmdLineArgs cl = new CmdLineArgs(args);
    ArgDecl argA = new ArgDecl(false, "-a");
    cl.add(argA);
    cl.process();
    assertTrue("No -a argument found", cl.contains(argA));
}
Also used : ArgDecl(jena.cmd.ArgDecl) CmdLineArgs(jena.cmd.CmdLineArgs) Test(org.junit.Test)

Example 3 with ArgDecl

use of jena.cmd.ArgDecl in project jena by apache.

the class FusekiCmd method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    int x = 0;
    Logger log = Fuseki.serverLog;
    if (contains(argFusekiConfig))
        fusekiConfigFile = getValue(argFusekiConfig);
    ArgDecl assemblerDescDecl = new ArgDecl(ArgDecl.HasValue, "desc", "dataset");
    if (contains(argMem))
        x++;
    if (contains(argFile))
        x++;
    if (contains(assemblerDescDecl))
        x++;
    if (contains(argTDB))
        x++;
    if (contains(argMemTDB))
        x++;
    if (fusekiConfigFile != null) {
        if (x >= 1)
            throw new CmdException("Dataset specified on the command line but a configuration file also given.");
    } else {
        if (x != 1)
            throw new CmdException("Required: either --config=FILE or one of --mem, --file, --loc or --desc");
    }
    if (contains(argMem)) {
        log.info("Dataset: in-memory");
        dsg = DatasetGraphFactory.create();
    }
    if (contains(argFile)) {
        dsg = DatasetGraphFactory.create();
        // replace by RiotLoader after ARQ refresh.
        String filename = getValue(argFile);
        log.info("Dataset: in-memory: load file: " + filename);
        if (!FileOps.exists(filename))
            throw new CmdException("File not found: " + filename);
        Lang language = RDFLanguages.filenameToLang(filename);
        if (language == null)
            throw new CmdException("Can't guess language for file: " + filename);
        InputStream input = IO.openFile(filename);
        if (RDFLanguages.isQuads(language))
            RDFDataMgr.read(dsg, filename);
        else
            RDFDataMgr.read(dsg.getDefaultGraph(), filename);
    }
    if (contains(argMemTDB)) {
        log.info("TDB dataset: in-memory");
        dsg = TDBFactory.createDatasetGraph();
    }
    if (contains(argTDB)) {
        String dir = getValue(argTDB);
        if (Objects.equals(dir, Names.memName)) {
            log.info("TDB dataset: in-memory");
        } else {
            if (!FileOps.exists(dir))
                throw new CmdException("Directory not found: " + dir);
            log.info("TDB dataset: directory=" + dir);
        }
        dsg = TDBFactory.createDatasetGraph(dir);
    }
    // Otherwise
    if (contains(assemblerDescDecl)) {
        log.info("Dataset from assembler");
        Dataset ds = modDataset.createDataset();
        if (ds != null)
            dsg = ds.asDatasetGraph();
    }
    if (contains(argFusekiConfig)) {
        if (dsg != null)
            throw new CmdException("(internal error) Dataset specificed on the command line but a a configuration file also given.");
        fusekiConfigFile = getValue(argFusekiConfig);
    }
    if (contains(argPort)) {
        String portStr = getValue(argPort);
        try {
            port = Integer.parseInt(portStr);
        } catch (NumberFormatException ex) {
            throw new CmdException(argPort.getKeyName() + " : bad port number: " + portStr);
        }
    }
    if (contains(argMgtPort)) {
        String mgtPortStr = getValue(argMgtPort);
        try {
            mgtPort = Integer.parseInt(mgtPortStr);
        } catch (NumberFormatException ex) {
            throw new CmdException(argMgtPort.getKeyName() + " : bad port number: " + mgtPortStr);
        }
    }
    if (contains(argLocalhost))
        listenLocal = true;
    if (fusekiConfigFile == null && dsg == null)
        throw new CmdException("No dataset defined and no configuration file: " + argUsage);
    if (dsg != null) {
        if (getPositional().size() == 0)
            throw new CmdException("No dataset path name given");
        if (getPositional().size() > 1)
            throw new CmdException("Multiple dataset path names given");
        datasetPath = getPositionalArg(0);
        if (datasetPath.length() > 0 && !datasetPath.startsWith("/"))
            throw new CmdException("Dataset path name must begin with a /: " + datasetPath);
        allowUpdate = contains(argAllowUpdate);
    }
    if (contains(argTimeout)) {
        String str = getValue(argTimeout);
        ARQ.getContext().set(ARQ.queryTimeout, str);
    }
    if (contains(argJettyConfig)) {
        jettyConfigFile = getValue(argJettyConfig);
        if (!FileOps.exists(jettyConfigFile))
            throw new CmdException("No such file: " + jettyConfigFile);
    }
    if (contains(argBasicAuth)) {
        authConfigFile = getValue(argBasicAuth);
        if (!FileOps.exists(authConfigFile))
            throw new CmdException("No such file: " + authConfigFile);
    }
    if (contains(argHome)) {
        List<String> args = super.getValues(argHome);
        homeDir = args.get(args.size() - 1);
    }
    if (contains(argPages)) {
        List<String> args = super.getValues(argPages);
        pagesDir = args.get(args.size() - 1);
    }
    if (contains(argGZip)) {
        if (!hasValueOfTrue(argGZip) && !hasValueOfFalse(argGZip))
            throw new CmdException(argGZip.getNames().get(0) + ": Not understood: " + getValue(argGZip));
        enableCompression = super.hasValueOfTrue(argGZip);
    }
    if (contains(argUber))
        SPARQLServer.überServlet = true;
    if (contains(argGSP)) {
        SPARQLServer.überServlet = true;
        Fuseki.graphStoreProtocolPostCreate = true;
    }
}
Also used : CmdException(jena.cmd.CmdException) InputStream(java.io.InputStream) Dataset(org.apache.jena.query.Dataset) ArgDecl(jena.cmd.ArgDecl) Lang(org.apache.jena.riot.Lang) Logger(org.slf4j.Logger)

Example 4 with ArgDecl

use of jena.cmd.ArgDecl in project jena by apache.

the class TestCmdLine method test_nArg1.

@Test
public void test_nArg1() {
    String[] args = new String[] { "-arg=V1", "--arg=V2", "-v" };
    CmdLineArgs cl = new CmdLineArgs(args);
    ArgDecl argA = new ArgDecl(true, "-arg");
    cl.add(argA);
    ArgDecl argV = new ArgDecl(false, "-v");
    cl.add(argV);
    cl.process();
    assertTrue("No -arg= argument found", cl.contains(argA));
    Iterator<String> iter = cl.getValues("arg").iterator();
    assertEquals("Argument 1", iter.next(), "V1");
    assertEquals("Argument 2", iter.next(), "V2");
}
Also used : ArgDecl(jena.cmd.ArgDecl) CmdLineArgs(jena.cmd.CmdLineArgs) Test(org.junit.Test)

Example 5 with ArgDecl

use of jena.cmd.ArgDecl in project jena by apache.

the class TestCmdLine method test_Arg1.

@Test
public void test_Arg1() {
    String[] args = new String[] { "" };
    CmdLineArgs cl = new CmdLineArgs(args);
    ArgDecl argA = new ArgDecl(true, "-arg");
    cl.add(argA);
    cl.process();
    assertTrue("-arg argument found", !cl.contains(argA));
}
Also used : ArgDecl(jena.cmd.ArgDecl) CmdLineArgs(jena.cmd.CmdLineArgs) Test(org.junit.Test)

Aggregations

ArgDecl (jena.cmd.ArgDecl)7 CmdLineArgs (jena.cmd.CmdLineArgs)6 Test (org.junit.Test)6 InputStream (java.io.InputStream)1 CmdException (jena.cmd.CmdException)1 Dataset (org.apache.jena.query.Dataset)1 Lang (org.apache.jena.riot.Lang)1 Logger (org.slf4j.Logger)1