Search in sources :

Example 1 with RoleChecker

use of org.jenkinsci.remoting.RoleChecker in project jenkin-qtest-plugin by QASymphony.

the class StoreResultServiceImpl method readResult.

private static Map<Integer, SubmittedResult> readResult(FilePath resultFile, String url, Long projectId) throws StoreResultException {
    SortedMap<Integer, String> lines = null;
    try {
        lines = resultFile.act(new FilePath.FileCallable<SortedMap<Integer, String>>() {

            @Override
            public SortedMap<Integer, String> invoke(File file, VirtualChannel virtualChannel) throws IOException, InterruptedException {
                FileReader fileReader = new FileReader(file);
                SortedMap<Integer, String> lines;
                try {
                    lines = fileReader.readAll();
                } finally {
                    if (null != fileReader)
                        fileReader.close();
                }
                return lines;
            }

            @Override
            public void checkRoles(RoleChecker roleChecker) throws SecurityException {
            }
        });
    } catch (Exception e) {
        throw new StoreResultException(String.format("Cannot read from result file:%s, %s", resultFile.getName(), e.getMessage()));
    }
    return buildSubmittedResult(lines, url, projectId);
}
Also used : VirtualChannel(hudson.remoting.VirtualChannel) RoleChecker(org.jenkinsci.remoting.RoleChecker) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) FileReader(com.qasymphony.ci.plugin.store.file.FileReader) File(java.io.File) IOException(java.io.IOException) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException)

Example 2 with RoleChecker

use of org.jenkinsci.remoting.RoleChecker in project jenkin-qtest-plugin by QASymphony.

the class StoreResultServiceImpl method store.

@Override
public Boolean store(Job job, final SubmittedResult result) throws StoreResultException {
    FilePath resultFolder = getResultFolder(job);
    try {
        resultFolder.mkdirs();
    } catch (Exception e) {
        throw new StoreResultException(String.format("Cannot make result folder:%s, %s", resultFolder.getName(), e.getMessage()));
    }
    FilePath resultFile = getResultFile(resultFolder, result.getBuildNumber() / BREAK_FILE_BY);
    try {
        resultFile.act(new FilePath.FileCallable<String>() {

            @Override
            public String invoke(File file, VirtualChannel virtualChannel) throws IOException, InterruptedException {
                BufferedWriter writer = null;
                try {
                    writer = new BufferedWriter(new FileWriter(file.getPath(), true));
                    writer.write(JsonUtils.toJson(result));
                    writer.newLine();
                    return null;
                } finally {
                    if (null != writer)
                        writer.close();
                }
            }

            @Override
            public void checkRoles(RoleChecker roleChecker) throws SecurityException {
            }
        });
    } catch (Exception e) {
        throw new StoreResultException("Cannot store result to file:" + e.getMessage());
    }
    return true;
}
Also used : FilePath(hudson.FilePath) VirtualChannel(hudson.remoting.VirtualChannel) FileWriter(java.io.FileWriter) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) IOException(java.io.IOException) IOException(java.io.IOException) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) BufferedWriter(java.io.BufferedWriter) RoleChecker(org.jenkinsci.remoting.RoleChecker) File(java.io.File)

Aggregations

StoreResultException (com.qasymphony.ci.plugin.exception.StoreResultException)2 VirtualChannel (hudson.remoting.VirtualChannel)2 File (java.io.File)2 IOException (java.io.IOException)2 RoleChecker (org.jenkinsci.remoting.RoleChecker)2 FileReader (com.qasymphony.ci.plugin.store.file.FileReader)1 FilePath (hudson.FilePath)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1