Example usage for java.io File setExecutable

List of usage examples for java.io File setExecutable

Introduction

In this page you can find the example usage for java.io File setExecutable.

Prototype

public boolean setExecutable(boolean executable) 

Source Link

Document

A convenience method to set the owner's execute permission for this abstract pathname.

Usage

From source file:name.martingeisse.ecobuild.moduletool.output.OutputTool.java

protected void handleFile(IModuleToolContext context, State state, String[] segments,
        boolean takeFromSourceTree, String autoSuffix) throws IOException {

    // basic command syntax check
    if (segments.length != 2 && segments.length != 3) {
        context.getLogger().logError("Found 'file' command with " + segments.length + " arguments");
        return;//from www .ja  va 2 s  . co  m
    }

    // parse the copy-source module path
    final ModulePath copySourceModulePath;
    try {
        copySourceModulePath = new ModulePath(segments[1] + autoSuffix);
    } catch (UserMessageBuildException e) {
        context.getLogger().logError("Found 'file' command with malformed copy-source path. " + e.getMessage());
        return;
    }

    // build the module from which the file shall be copied
    if (!takeFromSourceTree) {
        context.buildDependency(copySourceModulePath.getParent());
    }

    // parse the copy-destination module path
    final ModulePath copyDestinationModulePath;
    if (segments.length == 2) {
        copyDestinationModulePath = null;
    } else {
        try {
            copyDestinationModulePath = new ModulePath(segments[2] + autoSuffix);
        } catch (UserMessageBuildException e) {
            context.getLogger()
                    .logError("Found 'file' command with malformed copy-destination path. " + e.getMessage());
            return;
        }
    }

    // resolve the copy-source path
    File copySourceFilePath;
    try {
        if (takeFromSourceTree) {
            copySourceFilePath = copySourceModulePath.resolve(context.getRootSourceFolder(),
                    context.getModuleSourceFolder());
        } else {
            copySourceFilePath = copySourceModulePath.resolve(context.getRootBuildFolder(),
                    context.getModuleBuildFolder());
        }
    } catch (UserMessageBuildException e) {
        context.getLogger()
                .logError("Found 'file' command with unresolvable copy-source path. " + e.getMessage());
        return;
    }

    // resolve the copy-destination path
    File copyDestinationFilePath;
    if (copyDestinationModulePath != null) {
        try {
            copyDestinationFilePath = copyDestinationModulePath.resolve(context.getMainBuildFolder(),
                    state.currentFolder);
        } catch (UserMessageBuildException e) {
            context.getLogger().logError(
                    "Found 'file' command with unresolvable copy-destination path. " + e.getMessage());
            return;
        }
    } else {
        copyDestinationFilePath = new File(state.currentFolder, copySourceFilePath.getName());
    }

    // copy the file
    try {
        FileUtils.copyFile(copySourceFilePath, copyDestinationFilePath);
        if (copySourceFilePath.canExecute()) {
            copyDestinationFilePath.setExecutable(true);
        }
    } catch (FileNotFoundException e) {
        context.getLogger().logError("Copy failed for 'file' command: " + e.getMessage());
        return;
    } catch (IOException e) {
        context.getLogger().logError("Copy failed for 'file' command. ", e);
        return;
    }

}

From source file:de.flapdoodle.embedmongo.extract.TgzExtractor.java

@Override
public void extract(RuntimeConfig runtime, File source, File destination, Pattern file) throws IOException {

    IProgressListener progressListener = runtime.getProgressListener();
    String progressLabel = "Extract " + source;
    progressListener.start(progressLabel);

    FileInputStream fin = new FileInputStream(source);
    BufferedInputStream in = new BufferedInputStream(fin);
    GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);

    TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn);
    try {//from  ww  w . j ava2s .  c o  m
        TarArchiveEntry entry;
        while ((entry = tarIn.getNextTarEntry()) != null) {
            if (file.matcher(entry.getName()).matches()) {
                //               System.out.println("File: " + entry.getName());
                if (tarIn.canReadEntryData(entry)) {
                    //                  System.out.println("Can Read: " + entry.getName());
                    long size = entry.getSize();
                    Files.write(tarIn, size, destination);
                    destination.setExecutable(true);
                    //                  System.out.println("DONE");
                    progressListener.done(progressLabel);
                }
                break;

            } else {
                //               System.out.println("SKIP File: " + entry.getName());
            }
        }

    } finally {
        tarIn.close();
        gzIn.close();
    }
}

From source file:com.photon.maven.plugins.android.AbstractEmulatorMojo.java

/**
 * Writes the script to start the emulator in the background for unix based environments.
 *
 * @return absolute path name of start script
 * @throws IOException//from  w  w  w  . jav  a2  s.  c o m
 * @throws MojoExecutionException
 */
private String writeEmulatorStartScriptUnix() throws MojoExecutionException {
    String filename = SCRIPTFOLDER + "/android-maven-plugin-emulator-start.sh";

    File sh;
    sh = new File("/bin/bash");
    if (!sh.exists()) {
        sh = new File("/usr/bin/bash");
    }
    if (!sh.exists()) {
        sh = new File("/bin/sh");
    }

    File file = new File(filename);
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(new FileWriter(file));
        writer.println("#!" + sh.getAbsolutePath());
        writer.print(assembleStartCommandLine());
        writer.print(" 1>/dev/null 2>&1 &"); // redirect outputs and run as background task
    } catch (IOException e) {
        getLog().error("Failure writing file " + filename);
    } finally {
        if (writer != null) {
            writer.flush();
            writer.close();
        }
    }
    file.setExecutable(true);
    return filename;
}

From source file:it.drwolf.ridire.index.sketch.AsyncSketchCreator.java

private void compactLines(List<File> tableFile, File finalTable) throws ExecuteException, IOException {
    Executor executor = new DefaultExecutor();
    File tempTabTot = File.createTempFile("ridireTABTOT", ".tbl");
    File tempSh = File.createTempFile("ridireSH", ".sh");
    StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append("export LC_ALL=C\n");
    stringBuffer/*from ww  w.  jav  a  2 s  . c o m*/
            .append("cat " + StringUtils.join(tableFile, " ") + " > " + tempTabTot.getAbsolutePath() + "\n");
    stringBuffer.append("awk '{a[$2]+= $1; s+=$1}END{for(i in a){print a[i],i;}; print s \"\t\"}' "
            + tempTabTot.getAbsolutePath() + " | sort -k1nr -k2 > " + finalTable.getAbsolutePath());
    FileUtils.writeStringToFile(tempSh, stringBuffer.toString());
    tempSh.setExecutable(true);
    CommandLine commandLine = new CommandLine(tempSh.getAbsolutePath());
    executor.execute(commandLine);
    FileUtils.deleteQuietly(tempTabTot);
    FileUtils.deleteQuietly(tempSh);
}

From source file:org.moe.gradle.MoeSDK.java

private void validate(int type, @NotNull Path path, @NotNull String sub) throws IOException {
    Require.nonNull(path);/*  w  ww .java  2  s.  com*/
    Require.nonNull(sub);

    final Path fullPath = sub.length() == 0 ? path : path.resolve(sub);
    final File file = fullPath.toFile();
    if (!file.exists()) {
        throw new IOException("no filesystem entry exists at " + file.getAbsolutePath());
    }
    if ((type & DIR) != 0 && !file.isDirectory()) {
        throw new IOException("expected a directory at " + file.getAbsolutePath());
    }
    if ((type & FIL) != 0 && !file.isFile()) {
        throw new IOException("expected a file at " + file.getAbsolutePath());
    }
    if ((type & EXE) != 0 && !file.canExecute() && !file.setExecutable(true)) {
        throw new IOException("file is not executable at " + file.getAbsolutePath());
    }
}

From source file:io.github.bonigarcia.wdm.Downloader.java

public static final File extract(File compressedFile, String export) throws IOException {
    log.trace("Compressed file {}", compressedFile);

    File file = null;
    if (compressedFile.getName().toLowerCase().endsWith("tar.bz2")) {
        file = unBZip2(compressedFile);/*from   w ww .  j  av a 2 s  .  c  o m*/
    } else if (compressedFile.getName().toLowerCase().endsWith("tar.gz")) {
        file = unTarGz(compressedFile);
    } else if (compressedFile.getName().toLowerCase().endsWith("gz")) {
        file = unGzip(compressedFile);
    } else {
        ZipFile zipFolder = new ZipFile(compressedFile);
        Enumeration<?> enu = zipFolder.entries();

        while (enu.hasMoreElements()) {
            ZipEntry zipEntry = (ZipEntry) enu.nextElement();

            String name = zipEntry.getName();
            long size = zipEntry.getSize();
            long compressedSize = zipEntry.getCompressedSize();
            log.trace("Unzipping {} (size: {} KB, compressed size: {} KB)", name, size, compressedSize);

            file = new File(compressedFile.getParentFile() + File.separator + name);
            if (!file.exists() || WdmConfig.getBoolean("wdm.override")) {
                if (name.endsWith("/")) {
                    file.mkdirs();
                    continue;
                }

                File parent = file.getParentFile();
                if (parent != null) {
                    parent.mkdirs();
                }

                InputStream is = zipFolder.getInputStream(zipEntry);
                FileOutputStream fos = new FileOutputStream(file);
                byte[] bytes = new byte[1024];
                int length;
                while ((length = is.read(bytes)) >= 0) {
                    fos.write(bytes, 0, length);
                }
                is.close();
                fos.close();
                file.setExecutable(true);
            } else {
                log.debug(file + " already exists");
            }

        }
        zipFolder.close();
    }

    file = checkPhantom(compressedFile, export);

    log.trace("Resulting binary file {}", file.getAbsoluteFile());
    return file.getAbsoluteFile();
}

From source file:org.rhq.server.control.command.AbstractInstall.java

protected int updateAndMoveExistingAgent(final File agentBasedir, final File oldAgentDir,
        final File agentInstallerJar) throws Exception {

    // Make sure we use the appropriate java version, don't just fall back to PATH
    String javaExeFilePath = System.getProperty("rhq.java-exe-file-path");

    org.apache.commons.exec.CommandLine commandLine = new org.apache.commons.exec.CommandLine(javaExeFilePath) //
            .addArgument("-jar").addArgument(agentInstallerJar.getAbsolutePath()) //
            .addArgument("--update=" + oldAgentDir.getAbsolutePath()) //
            .addArgument("--log=" + new File(getLogDir(), "rhq-agent-update.log")) //
            .addArgument("--launch=false"); // we can't launch this copy - we still have to move it to the new location

    int exitValue = ExecutorAssist.execute(getBaseDir(), commandLine);
    log.info("The agent installer finished updating with exit value " + exitValue);

    // We need to now move the new, updated agent over to the new agent location.
    // renameTo() may fail if we are crossing file system boundaries, so try a true copy as a fallback.
    if (!agentBasedir.equals(oldAgentDir)) {
        // BZ 1118906 - we need to guard against the possibility that one or both of these are symlinks which aren't
        // "equal" to each other but yet still point to the same location. If they point to the same location
        // it is as if they are "equal" and we should do nothing.
        if (!agentBasedir.getCanonicalPath().equals(oldAgentDir.getCanonicalPath())) {
            FileUtil.purge(agentBasedir, true); // clear the way for the new upgraded agent
            if (!oldAgentDir.renameTo(agentBasedir)) {
                FileUtil.copyDirectory(oldAgentDir, agentBasedir);

                // we need to retain the execute bits for the executable scripts and libraries
                FileVisitor visitor = new FileVisitor() {
                    @Override//from w w  w  . j a  va  2 s .c  om
                    public void visit(File file) {
                        String filename = file.getName();
                        if (filename.contains(".so") || filename.contains(".sl")
                                || filename.contains(".dylib")) {
                            file.setExecutable(true);
                        } else if (filename.endsWith(".sh")) {
                            file.setExecutable(true);
                        }
                    }
                };

                FileUtil.forEachFile(new File(agentBasedir, "bin"), visitor);
                FileUtil.forEachFile(new File(agentBasedir, "lib"), visitor);
            }
        }
    }

    return exitValue;
}

From source file:com.jayway.maven.plugins.android.AbstractEmulatorMojo.java

/**
 * Writes the script to start the emulator in the background for unix based environments.
 *
 * @return absolute path name of start script
 * @throws IOException//from ww w  .j  a v a  2 s  .c  o m
 * @throws MojoExecutionException
 */
private String writeEmulatorStartScriptUnix() throws MojoExecutionException {
    String filename = SCRIPT_FOLDER + "/android-maven-plugin-emulator-start.sh";

    File sh;
    sh = new File("/bin/bash");
    if (!sh.exists()) {
        sh = new File("/usr/bin/bash");
    }
    if (!sh.exists()) {
        sh = new File("/bin/sh");
    }

    File file = new File(filename);
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(new FileWriter(file));
        writer.println("#!" + sh.getAbsolutePath());
        writer.print(assembleStartCommandLine());
        writer.print(" 1>/dev/null 2>&1 &"); // redirect outputs and run as background task
    } catch (IOException e) {
        getLog().error("Failure writing file " + filename);
    } finally {
        if (writer != null) {
            writer.flush();
            writer.close();
        }
    }
    file.setExecutable(true);
    return filename;
}

From source file:it.drwolf.ridire.index.cwb.CWBPatternSearcher.java

@SuppressWarnings("unchecked")
public void test() {
    String query = "set AutoShow off;\nset ProgressBar off;\nset PrettyPrint off;\nset Context 5 words;\nset LeftKWICDelim '--%%%--';\nset RightKWICDelim '--%%%--';\nshow -cpos;\nA=\"e\";\ncat A 0 9 > \"/home/drwolf/ridirecleaner_tmp/res.tbl\";";
    File temp = null;//  w w w.j  a va  2s. c om
    try {
        temp = File.createTempFile("ridireQ", ".query");
        FileUtils.writeStringToFile(temp, query);
        Executor executor = new DefaultExecutor();
        CommandLine commandLine = new CommandLine("/usr/local/cwb-3.4.3/bin/cqp");
        commandLine.addArgument("-f").addArgument(temp.getAbsolutePath()).addArgument("-D")
                .addArgument("RIDIRE2").addArgument("-r").addArgument("/usr/local/share/cwb/registry/");
        executor.execute(commandLine);
        File resFile = new File("/home/drwolf/ridirecleaner_tmp/res.tbl");
        List<String> lines = FileUtils.readLines(resFile);
        this.resultsSimple = new ArrayList<CWBResult>();
        for (String l : lines) {
            String[] res = l.split("--%%%--");
            CWBResult item = new CWBResult(res[0], res[1], res[2], "", null, null);
            this.resultsSimple.add(item);
        }
        this.entityManager.createNativeQuery("drop table if exists pippo").executeUpdate();
        this.entityManager.createNativeQuery(
                "CREATE TABLE `pippo` (`text_id` varchar(40) DEFAULT NULL,`beginPosition` int(11) DEFAULT NULL,`endPosition` int(11) DEFAULT NULL,`refnumber` bigint(20) NOT NULL,`dist` smallint(6) NOT NULL,`word` varchar(40) NOT NULL,`lemma` varchar(40) NOT NULL, `pos` varchar(40) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8")
                .executeUpdate();
        File tmpAwk = File.createTempFile("ridireAWK", ".awk");
        String awk = "BEGIN{ OFS = FS = \"\t\" } { print $3, $1, $2, NR-1, -5, $4 } { print $3, $1, $2, NR-1, -4, $5 } { print $3, $1, $2, NR-1, -3, $6 } { print $3, $1, $2, NR-1, -2, $7 } { print $3, $1, $2, NR-1, -1, $8 } { print $3, $1, $2, NR-1, 1, $9 } { print $3, $1, $2, NR-1, 2, $10 } { print $3, $1, $2, NR-1, 3, $11 } { print $3, $1, $2, NR-1, 4, $12 } { print $3, $1, $2, NR-1, 5, $13 } ";
        FileUtils.writeStringToFile(tmpAwk, awk);
        File tmpTabulate = File.createTempFile("ridireTAB", ".tab");
        String tabulate = "set AutoShow off;\nset ProgressBar off;\nset PrettyPrint off;\nset Context 5 words;\nset LeftKWICDelim '--%%%--';\nset RightKWICDelim '--%%%--';\nshow -cpos;\nA=\"e\";\ntabulate A match, matchend, match text_id, match[-5] word, match[-4] word, match[-3] word, match[-2] word, match[-1] word, matchend[1] word, matchend[2] word, matchend[3] word, matchend[4] word, matchend[5] word "
                + ">  \"| awk -f '" + tmpAwk.getAbsolutePath() + "' > '" + tmpTabulate.getAbsolutePath()
                + "'\";";
        File tempSh = File.createTempFile("ridireSH", ".sh");
        FileUtils.writeStringToFile(tempSh, tabulate);
        tempSh.setExecutable(true);
        executor = new DefaultExecutor();
        executor.setExitValue(0);
        ExecuteWatchdog watchdog = new ExecuteWatchdog(CWBPatternSearcher.TIMEOUT);
        executor.setWatchdog(watchdog);
        commandLine = new CommandLine("/usr/local/cwb-3.4.3/bin/cqp");
        commandLine.addArgument("-f").addArgument(tempSh.getAbsolutePath()).addArgument("-D")
                .addArgument("RIDIRE2").addArgument("-r").addArgument("/usr/local/share/cwb/registry/");
        executor.execute(commandLine);
        FileUtils.deleteQuietly(tempSh);
        this.entityManager
                .createNativeQuery(
                        "LOAD DATA LOCAL INFILE '" + tmpTabulate.getAbsolutePath() + "' INTO TABLE " + "pippo")
                .executeUpdate();
        long n = ((Number) this.entityManager.createNativeQuery("select sum(freq) as somma from freq_forma_all")
                .getSingleResult()).longValue();
        long r1 = ((Number) this.entityManager
                .createNativeQuery("select count(*) from pippo where dist between -3 and 3").getSingleResult())
                        .longValue();
        String nativeQuery = "select pippo.word, count(pippo.word) as observed," + " (" + r1
                + " * (freq_forma_all.freq) / " + n + ") as expected, sign(COUNT(pippo.word) - (" + r1
                + " * (freq_forma_all.freq) / " + n
                + ")) * 2 * ( IF(COUNT(pippo.word) > 0, COUNT(pippo.word) * log(COUNT(pippo.word) / (" + r1
                + " * (freq_forma_all.freq) / " + n + ")), 0) + IF((" + r1 + " - COUNT(pippo.word)) > 0, (" + r1
                + " - COUNT(pippo.word)) * log((" + r1 + " - COUNT(pippo.word)) / (" + r1 + " * (" + n
                + " - (freq_forma_all.freq)) / " + n
                + ")), 0) + IF(((freq_forma_all.freq) - COUNT(pippo.word)) > 0, ((freq_forma_all.freq) - COUNT(pippo.word)) * log(((freq_forma_all.freq) - COUNT(pippo.word)) / ("
                + (n - r1) + " * (freq_forma_all.freq) / " + n + ")), 0) + IF((" + (n - r1)
                + " - ((freq_forma_all.freq) - COUNT(pippo.word))) > 0, (" + (n - r1)
                + " - ((freq_forma_all.freq) - COUNT(pippo.word))) * log((" + (n - r1)
                + " - ((freq_forma_all.freq) - COUNT(pippo.word))) / (" + (n - r1) + " * (" + n
                + " - (freq_forma_all.freq)) / " + n
                + ")), 0) ) as significance, freq_forma_all.freq, count(distinct(text_id)) as text_id_count from pippo, freq_forma_all where pippo.word = freq_forma_all.item and dist between -3 and 3 and freq_forma_all.freq >= 1 group by pippo.word having observed >= 1 order by significance desc LIMIT 0, 50 ";
        List<Object[]> res = this.entityManager.createNativeQuery(nativeQuery).getResultList();
        for (Object[] r : res) {
            System.out.println(r[0] + "\t" + r[3]);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:it.drwolf.ridire.index.cwb.CWBConcordancer.java

@SuppressWarnings("unchecked")
public void test() {
    String query = "set AutoShow off;\nset ProgressBar off;\nset PrettyPrint off;\nset Context 5 words;\nset LeftKWICDelim '--%%%--';\nset RightKWICDelim '--%%%--';\nshow -cpos;\nA=\"e\";\ncat A 0 9 > \"/home/drwolf/ridirecleaner_tmp/res.tbl\";";
    File temp = null;/* w ww .j a  v  a2 s . co m*/
    try {
        temp = File.createTempFile("ridireQ", ".query");
        FileUtils.writeStringToFile(temp, query);
        Executor executor = new DefaultExecutor();
        CommandLine commandLine = new CommandLine("/usr/local/cwb-3.4.3/bin/cqp");
        commandLine.addArgument("-f").addArgument(temp.getAbsolutePath()).addArgument("-D")
                .addArgument("RIDIRE2").addArgument("-r").addArgument("/usr/local/share/cwb/registry/");
        executor.execute(commandLine);
        File resFile = new File("/home/drwolf/ridirecleaner_tmp/res.tbl");
        List<String> lines = FileUtils.readLines(resFile);
        this.resultsSimple = new ArrayList<CWBResult>();
        for (String l : lines) {
            String[] res = l.split("--%%%--");
            CWBResult item = new CWBResult(res[0], res[1], res[2], "", null, null);
            this.resultsSimple.add(item);
        }
        this.entityManager.createNativeQuery("drop table if exists pippo").executeUpdate();
        this.entityManager.createNativeQuery(
                "CREATE TABLE `pippo` (`text_id` varchar(40) DEFAULT NULL,`beginPosition` int(11) DEFAULT NULL,`endPosition` int(11) DEFAULT NULL,`refnumber` bigint(20) NOT NULL,`dist` smallint(6) NOT NULL,`word` varchar(40) NOT NULL,`lemma` varchar(40) NOT NULL, `pos` varchar(40) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8")
                .executeUpdate();
        File tmpAwk = File.createTempFile("ridireAWK", ".awk");
        String awk = "BEGIN{ OFS = FS = \"\t\" } { print $3, $1, $2, NR-1, -5, $4 } { print $3, $1, $2, NR-1, -4, $5 } { print $3, $1, $2, NR-1, -3, $6 } { print $3, $1, $2, NR-1, -2, $7 } { print $3, $1, $2, NR-1, -1, $8 } { print $3, $1, $2, NR-1, 1, $9 } { print $3, $1, $2, NR-1, 2, $10 } { print $3, $1, $2, NR-1, 3, $11 } { print $3, $1, $2, NR-1, 4, $12 } { print $3, $1, $2, NR-1, 5, $13 } ";
        FileUtils.writeStringToFile(tmpAwk, awk);
        File tmpTabulate = File.createTempFile("ridireTAB", ".tab");
        String tabulate = "set AutoShow off;\nset ProgressBar off;\nset PrettyPrint off;\nset Context 5 words;\nset LeftKWICDelim '--%%%--';\nset RightKWICDelim '--%%%--';\nshow -cpos;\nA=\"e\";\ntabulate A match, matchend, match text_id, match[-5] word, match[-4] word, match[-3] word, match[-2] word, match[-1] word, matchend[1] word, matchend[2] word, matchend[3] word, matchend[4] word, matchend[5] word "
                + ">  \"| awk -f '" + tmpAwk.getAbsolutePath() + "' > '" + tmpTabulate.getAbsolutePath()
                + "'\";";
        File tempSh = File.createTempFile("ridireSH", ".sh");
        FileUtils.writeStringToFile(tempSh, tabulate);
        tempSh.setExecutable(true);
        executor = new DefaultExecutor();
        executor.setExitValue(0);
        ExecuteWatchdog watchdog = new ExecuteWatchdog(CWBConcordancer.TIMEOUT);
        executor.setWatchdog(watchdog);
        commandLine = new CommandLine("/usr/local/cwb-3.4.3/bin/cqp");
        commandLine.addArgument("-f").addArgument(tempSh.getAbsolutePath()).addArgument("-D")
                .addArgument("RIDIRE2").addArgument("-r").addArgument("/usr/local/share/cwb/registry/");
        executor.execute(commandLine);
        FileUtils.deleteQuietly(tempSh);
        this.entityManager
                .createNativeQuery(
                        "LOAD DATA LOCAL INFILE '" + tmpTabulate.getAbsolutePath() + "' INTO TABLE " + "pippo")
                .executeUpdate();
        long n = ((Number) this.entityManager.createNativeQuery("select sum(freq) as somma from freq_forma_all")
                .getSingleResult()).longValue();
        long r1 = ((Number) this.entityManager
                .createNativeQuery("select count(*) from pippo where dist between -3 and 3").getSingleResult())
                        .longValue();
        String nativeQuery = "select pippo.word, count(pippo.word) as observed," + " (" + r1
                + " * (freq_forma_all.freq) / " + n + ") as expected, sign(COUNT(pippo.word) - (" + r1
                + " * (freq_forma_all.freq) / " + n
                + ")) * 2 * ( IF(COUNT(pippo.word) > 0, COUNT(pippo.word) * log(COUNT(pippo.word) / (" + r1
                + " * (freq_forma_all.freq) / " + n + ")), 0) + IF((" + r1 + " - COUNT(pippo.word)) > 0, (" + r1
                + " - COUNT(pippo.word)) * log((" + r1 + " - COUNT(pippo.word)) / (" + r1 + " * (" + n
                + " - (freq_forma_all.freq)) / " + n
                + ")), 0) + IF(((freq_forma_all.freq) - COUNT(pippo.word)) > 0, ((freq_forma_all.freq) - COUNT(pippo.word)) * log(((freq_forma_all.freq) - COUNT(pippo.word)) / ("
                + (n - r1) + " * (freq_forma_all.freq) / " + n + ")), 0) + IF((" + (n - r1)
                + " - ((freq_forma_all.freq) - COUNT(pippo.word))) > 0, (" + (n - r1)
                + " - ((freq_forma_all.freq) - COUNT(pippo.word))) * log((" + (n - r1)
                + " - ((freq_forma_all.freq) - COUNT(pippo.word))) / (" + (n - r1) + " * (" + n
                + " - (freq_forma_all.freq)) / " + n
                + ")), 0) ) as significance, freq_forma_all.freq, count(distinct(text_id)) as text_id_count from pippo, freq_forma_all where pippo.word = freq_forma_all.item and dist between -3 and 3 and freq_forma_all.freq >= 1 group by pippo.word having observed >= 1 order by significance desc LIMIT 0, 50 ";
        List<Object[]> res = this.entityManager.createNativeQuery(nativeQuery).getResultList();
        for (Object[] r : res) {
            System.out.println(r[0] + "\t" + r[3]);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}