List of usage examples for org.apache.commons.io FileUtils iterateFiles
public static Iterator iterateFiles(File directory, String[] extensions, boolean recursive)
From source file:com.nimbits.server.process.BlobStoreImpl.java
@Override public List<Value> getSeries(final ValueService valueService, final Entity entity, final Optional<Range<Date>> timespan, final Optional<Range<Integer>> range, final Optional<String> mask) { //TODO - some way to test if a count has been reached before reading all files if no timespan is give - like test the list by processing it to see if it's complete //enough to return while reading other files. String root = settingsService.getSetting(ServerSetting.storeDirectory); String path = root + "/" + entity.getKey(); List<Value> allvalues = new ArrayList<>(INITIAL_CAPACITY); List<String> allReadFiles = new ArrayList<>(INITIAL_CAPACITY); File file = new File(path); Range<Date> maxRange = timespan.isPresent() ? Range.closed(defragmenter.zeroOutDateToStart(timespan.get().lowerEndpoint()), defragmenter.zeroOutDateToStart(timespan.get().upperEndpoint())) : Range.closed(defragmenter.zeroOutDateToStart(new Date(0)), defragmenter.zeroOutDateToStart(new Date())); // all dates if (file.exists()) { List<String> dailyFolderPaths = new ArrayList<>(); for (String dailyFolderPath : file.list()) { File node = new File(dailyFolderPath); if (!node.getName().endsWith(SNAPSHOT)) { Long timestamp = Long.valueOf(dailyFolderPath); if (maxRange.contains(new Date(timestamp))) { dailyFolderPaths.add(root + "/" + entity.getKey() + "/" + dailyFolderPath); }/*from w w w . j a v a2s . c o m*/ } } if (!dailyFolderPaths.isEmpty()) { Collections.sort(dailyFolderPaths); Collections.reverse(dailyFolderPaths); for (String sortedDayPath : dailyFolderPaths) { Iterator result2 = FileUtils.iterateFiles(new File(sortedDayPath), null, false); List<String> filePaths = new ArrayList<>(); while (result2.hasNext()) { File listItem = (File) result2.next(); String filePath = listItem.getName(); if (!filePath.endsWith(SNAPSHOT)) { filePaths.add(sortedDayPath + "/" + filePath); } } Collections.sort(filePaths); Collections.reverse(filePaths); for (String sortedFilePath : filePaths) { List<Value> values = readValuesFromFile(sortedFilePath); allvalues.addAll(values); allReadFiles.add(sortedFilePath); } } } List<Value> filtered = storageIO.filterValues(allvalues, timespan, range, mask); if (allReadFiles.size() > INITIAL_CAPACITY) { //TODO will break if # of days = initial capacity // logger.info("Defragmenting " + allReadFiles.size()); deleteAndRestore(this, valueService, entity, allvalues, allReadFiles); } // logger.info("****** returning " + filtered.size()); return ImmutableList.copyOf(filtered); } else { logger.info("file not found"); return Collections.emptyList(); } }
From source file:edu.wustl.xipHost.avt2ext.AVTRetrieve2.java
@SuppressWarnings("unchecked") void retrieve(TargetElement targetElement, ADRetrieveTarget retrieveTarget) throws IOException { List<SubElement> subElements = targetElement.getSubElements(); Map<Integer, Object> dicomCriteria = null; Map<String, Object> adAimCriteria = null; File importDir = null;//from w w w. j a v a 2s .co m for (SubElement subElement : subElements) { dicomCriteria = subElement.getCriteria().getDICOMCriteria(); adAimCriteria = subElement.getCriteria().getAIMCriteria(); importDir = new File(subElement.getPath()); if (adAimCriteria == null) { logger.debug("AD AIM criteria: " + adAimCriteria); } else { logger.debug("AD AIM retrieve criteria:"); Set<String> keys = adAimCriteria.keySet(); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String key = iter.next(); String value = (String) adAimCriteria.get(key); if (!value.isEmpty()) { logger.debug("Key: " + key + " Value: " + value); } } } //TODO: provide logging for DICOM criteria logger.debug("Import location: " + importDir.getCanonicalPath()); logger.debug("Retrieve target: " + retrieveTarget.toString()); File dirPath = importDir.getAbsoluteFile(); if (retrieveTarget == ADRetrieveTarget.DICOM_AND_AIM) { //Retrieve DICOM List<DicomObject> retrievedDICOM = adService.retrieveDicomObjs(dicomCriteria, adAimCriteria); for (int i = 0; i < retrievedDICOM.size(); i++) { DicomObject dicom = retrievedDICOM.get(i); String filePrefix = dicom.getString(Tag.SOPInstanceUID); String fileName = null; IOFileFilter fileFilter = FileFilterUtils.trueFileFilter(); Iterator<File> tmpFiles = FileUtils.iterateFiles(importDir, fileFilter, null); while (tmpFiles.hasNext()) { File tmpFile = tmpFiles.next(); if (tmpFile.getName().startsWith(filePrefix)) { fileName = tmpFile.getAbsolutePath(); } } FileOutputStream fos = new FileOutputStream(fileName); BufferedOutputStream bos = new BufferedOutputStream(fos); DicomOutputStream dout = new DicomOutputStream(bos); dout.writeDicomFile(dicom); dout.close(); } //Retrieve AIM List<String> annotationUIDs = adService.findAnnotations(dicomCriteria, adAimCriteria); Set<String> uniqueAnnotUIDs = new HashSet<String>(annotationUIDs); Iterator<String> iter = uniqueAnnotUIDs.iterator(); while (iter.hasNext()) { String uid = iter.next(); ImageAnnotation loadedAnnot = adService.getAnnotation(uid); String strXML = loadedAnnot.getAIM(); byte[] source = strXML.getBytes(); InputStream is = new ByteArrayInputStream(source); try { document = builder.build(is); } catch (JDOMException e) { logger.error(e, e); } //Ensure dirPath is correctly assign. There are references below of this variable File outFile = new File(dirPath + File.separator + uid); FileOutputStream outStream = new FileOutputStream(outFile); outToXMLFile.output(document, outStream); outStream.flush(); outStream.close(); //Retrieve DICOM SEG //temporarily voided. AVTQuery needs to be modified to query for DICOM SEG objects // Set<String> dicomSegSOPInstanceUIDs = new HashSet<String>(); List<DicomObject> segObjects = adService.retrieveSegmentationObjects(uid); for (int i = 0; i < segObjects.size(); i++) { DicomObject dicom = segObjects.get(i); String sopInstanceUID = dicom.getString(Tag.SOPInstanceUID); //Check if DICOM SEG was not serialized in reference to another AIM if (!dicomSegSOPInstanceUIDs.contains(sopInstanceUID)) { dicomSegSOPInstanceUIDs.add(sopInstanceUID); DicomObject dicomSeg = adService.getDicomObject(sopInstanceUID); String message = "DICOM SEG " + sopInstanceUID + " cannot be loaded from file system!"; if (dicomSeg == null) { throw new FileNotFoundException(message); } else { String filePrefix = sopInstanceUID; IOFileFilter fileFilter = FileFilterUtils.trueFileFilter(); Iterator<File> tmpFiles = FileUtils.iterateFiles(importDir, fileFilter, null); //DICOM SEG tmp file not found e.g. DICOM SEG belongs to not specified Study for which TargetIteratorRunner was not requested boolean dicomSegFound = false; while (tmpFiles.hasNext()) { File tmpFile = tmpFiles.next(); if (tmpFile.getName().startsWith(filePrefix)) { dicomSegFound = true; } } if (dicomSegFound == true) { File outDicomSegFile = new File(dirPath + File.separator + sopInstanceUID); FileOutputStream fos = new FileOutputStream(outDicomSegFile); BufferedOutputStream bos = new BufferedOutputStream(fos); DicomOutputStream dout = new DicomOutputStream(bos); dout.writeDicomFile(dicomSeg); dout.close(); } else if (dicomSegFound == false) { //There wouldn't be UUIDs for this case since it was not found with the TargetIteratorRunner //TODO: build notification, add to the MultiValueMap etc. //Eliminate duplicate code with dicomSegFound = true File outDicomSegFile = new File(dirPath + File.separator + sopInstanceUID); FileOutputStream fos = new FileOutputStream(outDicomSegFile); BufferedOutputStream bos = new BufferedOutputStream(fos); DicomOutputStream dout = new DicomOutputStream(bos); dout.writeDicomFile(dicomSeg); dout.close(); } } } } // } } else if (retrieveTarget == ADRetrieveTarget.AIM_SEG) { //Retrieve AIM List<String> annotationUIDs = adService.findAnnotations(dicomCriteria, adAimCriteria); Set<String> uniqueAnnotUIDs = new HashSet<String>(annotationUIDs); Iterator<String> iter = uniqueAnnotUIDs.iterator(); Set<String> segDicomInstances = new HashSet<String>(); while (iter.hasNext()) { String uid = iter.next(); ImageAnnotation loadedAnnot = adService.getAnnotation(uid); String strXML = loadedAnnot.getAIM(); byte[] source = strXML.getBytes(); InputStream is = new ByteArrayInputStream(source); try { document = builder.build(is); } catch (JDOMException e) { logger.error(e, e); } File outFile = new File(dirPath + uid + ".xml"); FileOutputStream outStream = new FileOutputStream(outFile); outToXMLFile.output(document, outStream); outStream.flush(); outStream.close(); List<DicomObject> segObjects = adService.retrieveSegmentationObjects(uid); for (int i = 0; i < segObjects.size(); i++) { DicomObject dicom = segObjects.get(i); String sopInstanceUID = dicom.getString(Tag.SOPInstanceUID); //Check of segDicom was not serialized in reference to another AIM if (!segDicomInstances.contains(sopInstanceUID)) { segDicomInstances.add(sopInstanceUID); DicomObject segDicom = adService.getDicomObject(sopInstanceUID); if (segDicom == null) { String message = "DICOM SEG " + sopInstanceUID + " cannot be loaded from file system!"; throw new FileNotFoundException(message); } else { String filePrefix = sopInstanceUID; String fileName = null; IOFileFilter fileFilter = FileFilterUtils.trueFileFilter(); Iterator<File> tmpFiles = FileUtils.iterateFiles(importDir, fileFilter, null); while (tmpFiles.hasNext()) { File tmpFile = tmpFiles.next(); if (tmpFile.getName().startsWith(filePrefix)) { fileName = tmpFile.getName(); } } DicomOutputStream dout = new DicomOutputStream(new FileOutputStream(fileName)); dout.writeDicomFile(segDicom); dout.close(); } } } } } } }
From source file:com.liferay.maven.plugins.ThemeMergeMojo.java
protected void doExecute() throws Exception { if (!workDir.exists()) { workDir.mkdirs();/*from w w w.j a v a 2 s . c o m*/ } String parentThemeGroupId = "liferay.portal"; String parentThemeArtifactId = "portal-web"; String parentThemeVersion = liferayVersion; String[] excludes = { "html/themes/classic/_diffs/**", "html/themes/control_panel/_diffs/**" }; String[] includes = { "html/themes/_unstyled/**", "html/themes/_styled/**", "html/themes/classic/**", "html/themes/control_panel/**" }; if (!parentTheme.equals("_styled") && !parentTheme.equals("_unstyled") && !parentTheme.equals("classic") && !parentTheme.equals("control_panel")) { String[] parentThemeArray = parentTheme.split(":"); parentThemeGroupId = parentThemeArray[0]; parentThemeArtifactId = parentThemeArray[1]; parentThemeVersion = parentThemeArray[2]; excludes = new String[] { "WEB-INF/**" }; includes = null; } Artifact artifact = artifactFactory.createArtifact(parentThemeGroupId, parentThemeArtifactId, parentThemeVersion, "", "war"); artifactResolver.resolve(artifact, remoteArtifactRepositories, localArtifactRepository); UnArchiver unArchiver = archiverManager.getUnArchiver(artifact.getFile()); unArchiver.setDestDirectory(workDir); unArchiver.setSourceFile(artifact.getFile()); IncludeExcludeFileSelector includeExcludeFileSelector = new IncludeExcludeFileSelector(); includeExcludeFileSelector.setExcludes(excludes); includeExcludeFileSelector.setIncludes(includes); unArchiver.setFileSelectors(new FileSelector[] { includeExcludeFileSelector }); unArchiver.extract(); webappDirectory.mkdirs(); if (parentThemeArtifactId.equals("portal-web")) { FileUtils.copyDirectory(new File(workDir, "html/themes/_unstyled"), webappDirectory); getLog().info("Copying html/themes/_unstyled to " + webappDirectory); if (!"_unstyled".equals(parentTheme)) { FileUtils.copyDirectory(new File(workDir, "html/themes/_styled"), webappDirectory); getLog().info("Copying html/themes/_styled to " + webappDirectory); } if (!"_unstyled".equals(parentTheme) && !"_styled".equals(parentTheme)) { FileUtils.copyDirectory(new File(workDir, "html/themes/" + parentTheme), webappDirectory); getLog().info("Copying html/themes/" + parentTheme + " to " + webappDirectory); } } else { FileUtils.copyDirectory(workDir, webappDirectory); } File initFile = new File(webappDirectory, "templates/init." + themeType); FileUtils.deleteQuietly(initFile); File templatesDirectory = new File(webappDirectory, "templates/"); String[] extensions = null; if (themeType.equals("ftl")) { extensions = new String[] { "vm" }; } else { extensions = new String[] { "ftl" }; } Iterator<File> itr = FileUtils.iterateFiles(templatesDirectory, extensions, false); while (itr.hasNext()) { File file = itr.next(); FileUtils.deleteQuietly(file); } }
From source file:it.geosolutions.geobatch.global.XStreamCatalogLoader.java
protected void loadFlows(File dataDir, final Catalog catalog) { // ////from w ww . ja va 2 s .c o m // // load all flows // // // final Iterator<File> it = FileUtils.iterateFiles(dataDir, new String[] { "xml" }, false); while (it.hasNext()) { final File flowConfigFile = it.next(); // skip catalog config file if (flowConfigFile.getName().equalsIgnoreCase(catalog.getId() + ".xml")) continue; try { // loaded if (LOGGER.isInfoEnabled()) LOGGER.info("Loading flow from file " + flowConfigFile.getAbsolutePath()); // try to load the flow and add it to the catalog // TODO change this: DAO flowLoader = new XStreamFlowConfigurationDAO(dataDir.getAbsolutePath(), alias); String id = FilenameUtils.getBaseName(flowConfigFile.getName()); FileBasedCatalogImpl fbcImpl = ((FileBasedCatalogImpl) CatalogHolder.getCatalog()); final FileBasedFlowManager flowManager = new FileBasedFlowManager(id, flowLoader, fbcImpl.getDataDirHandler()); // flow.setId(FilenameUtils.getBaseName(o.getName())); // flowManager.setDAO(flowLoader); // flowManager.load(); // TODO ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // add to the catalog catalog.add(flowManager); // loaded if (LOGGER.isInfoEnabled()) LOGGER.info(new StringBuilder("Loaded flow from file ").append(flowConfigFile.getAbsolutePath()) .toString()); } catch (Throwable t) { if (LOGGER.isWarnEnabled()) LOGGER.warn("Skipping flow", t); } } }
From source file:ca.brood.softlogger.dataoutput.CSVOutputModule.java
private void updateFilename() throws Exception { String theFileName;//from w w w.j a va2 s . co m String oldFileName; Calendar cal = Calendar.getInstance(); theFileName = csvSubdirectory + "/" + String.format("%1$tY%1$tm%1$td-%1$tH.%1$tM.%1$tS", cal) + "-" + m_OutputDevice.getDescription() + ".csv"; try { if (!csvSubdirectory.equals(".")) { File csvDir = new File(csvSubdirectory); if (!csvDir.isDirectory()) { csvDir.mkdirs(); } } } catch (Exception e) { log.error("Error - couldn't create the CSV destination directory: " + csvSubdirectory, e); throw e; } if (writer == null) { writer = new CSVFileWriter(theFileName); //Move all CSV files from csvSubdirectory to completedFileDirectory if (completedFileDirectory.length() > 0) { String[] extensions = new String[1]; extensions[0] = "csv"; File csvDir = new File(csvSubdirectory); File completedDir = new File(completedFileDirectory); try { Iterator<File> fileIter = FileUtils.iterateFiles(csvDir, extensions, false); while (fileIter.hasNext()) { FileUtils.moveFileToDirectory(fileIter.next(), completedDir, true); } } catch (Exception e) { log.error("Couldn't move existing CSV files on startup.", e); } } } else { oldFileName = writer.getFilename(); writer.setFilename(theFileName); if (!oldFileName.equalsIgnoreCase(theFileName)) { //File name has changed, move the old file if required try { if (completedFileDirectory.length() > 0) { File completedDir = new File(completedFileDirectory); if (!completedDir.isDirectory()) { completedDir.mkdirs(); } File oldFile = new File(oldFileName); if (oldFile.exists()) { String movedFileName = completedFileDirectory + "/" + oldFile.getName(); File movedFile = new File(movedFileName); log.debug("Moving " + oldFileName + " to " + movedFileName); FileUtils.moveFile(oldFile, movedFile); } } } catch (Exception e) { log.error("Couldn't move the completed CSV file", e); } } } }
From source file:com.ec2box.manage.action.UploadAndPushAction.java
@Action(value = "/admin/push", results = { @Result(name = "success", location = "/admin/upload_result.jsp") }) public String push() { Long userId = AuthUtil.getUserId(servletRequest.getSession()); Long sessionId = AuthUtil.getSessionId(servletRequest.getSession()); try {/* ww w.ja va2 s . c o m*/ //get next pending system pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId); if (pendingSystemStatus != null) { //get session for system SchSession session = null; for (Integer instanceId : SecureShellAction.getUserSchSessionMap().get(sessionId).getSchSessionMap() .keySet()) { //if host system id matches pending system then upload if (pendingSystemStatus.getId().equals(SecureShellAction.getUserSchSessionMap().get(sessionId) .getSchSessionMap().get(instanceId).getHostSystem().getId())) { session = SecureShellAction.getUserSchSessionMap().get(sessionId).getSchSessionMap() .get(instanceId); } } if (session != null) { //push upload to system currentSystemStatus = SSHUtil.pushUpload(pendingSystemStatus, session.getSession(), UPLOAD_PATH + "/" + uploadFileName, pushDir + "/" + uploadFileName); //update system status SystemStatusDB.updateSystemStatus(currentSystemStatus, userId); pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId); } } //if push has finished to all servers then delete uploaded file if (pendingSystemStatus == null) { File delFile = new File(UPLOAD_PATH, uploadFileName); FileUtils.deleteQuietly(delFile); //delete all expired files in upload path File delDir = new File(UPLOAD_PATH); if (delDir.isDirectory()) { //set expire time to delete all files older than 48 hrs Calendar expireTime = Calendar.getInstance(); expireTime.add(Calendar.HOUR, -48); Iterator<File> filesToDelete = FileUtils.iterateFiles(delDir, new AgeFileFilter(expireTime.getTime()), TrueFileFilter.TRUE); while (filesToDelete.hasNext()) { delFile = filesToDelete.next(); delFile.delete(); } } } hostSystemList = SystemStatusDB.getAllSystemStatus(userId); } catch (Exception e) { e.printStackTrace(); } return SUCCESS; }
From source file:com.siemens.scr.avt.ad.io.AnnotationBatchLoader.java
private void parseSegDicomFromDirectroy(File directory) throws IOException { Iterator<File> fileIterator = FileUtils.iterateFiles(directory, new SuffixFileFilter(".dcm"), TrueFileFilter.INSTANCE);// ww w. jav a2 s . com while (fileIterator.hasNext()) { File file = fileIterator.next(); DicomObject dob = DicomParser.read(file); if (dob == null) continue; String dicomUID = dob.getString(Tag.MediaStorageSOPInstanceUID); sopInstanceUID2URL.put(dicomUID, file); } }
From source file:de.felixschulze.maven.plugins.xcode.GHUnitTestMojo.java
/** * Execute the xcode command line utility. *//*from ww w . jav a2s . c o m*/ public void execute() throws MojoExecutionException { if (executeGHUnitTests) { if (!iosSimCommandLine.exists()) { throw new MojoExecutionException( "Invalid path for ios-sim: " + iosSimCommandLine.getAbsolutePath()); } if (appName == null) { throw new MojoExecutionException("AppName must be defined."); } if (!xcodeSdk.contains("iphonesimulator")) { throw new MojoExecutionException("GHUnit-Tests can only run on simulator"); } File appDirectory = new File(buildDirectory, xcodeConfiguration + "-iphonesimulator"); File testResultsDirectory = new File(buildDirectory, "test-results"); File appFile = new File(appDirectory, appName + ".app"); CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor(); executor.setLogger(this.getLog()); List<String> commands = new ArrayList<String>(); commands.add("launch"); commands.add(appFile.getAbsolutePath()); if (testDevice != null) { commands.add("--family"); commands.add(testDevice); } if (!testNoAutoExit) { commands.add("--setenv"); commands.add("GHUNIT_AUTOEXIT=YES"); } if (teamCityLog) { commands.add("--setenv"); commands.add("GHUNIT_AUTORUN=1"); commands.add("--setenv"); commands.add("WRITE_JUNIT_XML=1"); commands.add("--setenv"); commands.add("JUNIT_XML_DIR=" + testResultsDirectory.getAbsolutePath()); } if (retinaDevice) { commands.add("--retina"); } if (tallDevice) { commands.add("--tall"); } ProcessHelper.killSimulatorProcess(getLog()); try { getLog().info(iosSimCommandLine.getAbsolutePath() + " " + commands.toString()); executor.executeCommand(iosSimCommandLine.getAbsolutePath(), commands, false, true); final String errorOut = executor.getStandardError(); String regexSimulatorTimeOut = ".*Simulator session timed out.(.*)"; Boolean sessionTimedOut = Pattern.compile(regexSimulatorTimeOut, Pattern.DOTALL).matcher(errorOut) .matches(); if (sessionTimedOut) { if (teamCityLog) { getLog().error(TeamCityHelper.createBuildStatusFailureLog("Simulator session timed out.")); } getLog().error("Simulator session timed out."); throw new MojoExecutionException("Simulator session timed out."); } String regex = ".*Executed [0-9]* of [0-9]* tests, with [0-9]* failures in [0-9]*.[0-9]* seconds(.*)"; Boolean success = Pattern.compile(regex, Pattern.DOTALL).matcher(errorOut).matches(); if (!success) { if (teamCityLog) { getLog().error(TeamCityHelper .createBuildStatusFailureLog("Tests failed - The app may be crashed")); } getLog().error("Tests failed - The app may be crashed"); throw new MojoExecutionException("Tests failed - The app may be crashed"); } } catch (ExecutionException e) { throw new MojoExecutionException("Error while executing: ", e); } //Test results if (teamCityLog) { String[] extension = { "xml" }; Iterator<File> fileIterator = FileUtils.iterateFiles(testResultsDirectory, extension, true); while (fileIterator.hasNext()) { File testXml = fileIterator.next(); getLog().info("##teamcity[importData type='junit' path='" + testXml.getAbsolutePath() + "']"); } } //Coverage if (generateCoverageReport) { if (!lcovCommandLine.exists()) { throw new MojoExecutionException("Invalid path for lcov: " + lcovCommandLine.getAbsolutePath()); } if (!genHtmlCommandLine.exists()) { throw new MojoExecutionException( "Invalid path for genhtml: " + genHtmlCommandLine.getAbsolutePath()); } commands = new ArrayList<String>(); commands.add("--directory"); File coverageObjectsDir = buildDirectory; String buildFolderName; if (coverageAppName != null) { buildFolderName = coverageAppName + ".build"; } else { buildFolderName = appName + ".build"; } String[] directoryStructure = { xcodeProject.getName().replace(".xcodeproj", ".build"), xcodeConfiguration + "-iphonesimulator", buildFolderName, "Objects-normal", "i386" }; for (String currentDir : directoryStructure) { coverageObjectsDir = new File(coverageObjectsDir.getAbsolutePath(), currentDir); } commands.add(coverageObjectsDir.getAbsolutePath()); commands.add("--capture"); commands.add("--output-file"); File coverageOutPutFile = new File(buildDirectory, "main.info"); commands.add(coverageOutPutFile.getAbsolutePath()); commands.add("-b"); commands.add(basedir); File coverageTargetOutPutFile = new File(buildDirectory, appName + ".info"); getLog().info(lcovCommandLine.getAbsolutePath() + " " + commands.toString()); try { executor.executeCommand(lcovCommandLine.getAbsolutePath(), commands, false); commands = new ArrayList<String>(); commands.add("-o"); commands.add(coverageTargetOutPutFile.getAbsolutePath()); commands.add("--extract"); commands.add(coverageOutPutFile.getAbsolutePath()); commands.add("'*" + coverageTarget + "/*'"); getLog().info(lcovCommandLine.getAbsolutePath() + " " + commands.toString()); executor.executeCommand(lcovCommandLine.getAbsolutePath(), commands, false); final String errorOut = executor.getStandardOut(); String regex = ".*.*lines......: ([0-9]*.[0-9])*% \\(([0-9]*) of ([0-9]*) lines\\)(.*)"; Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); Matcher matcher = pattern.matcher(errorOut); while (matcher.find()) { if (teamCityLog) { getLog().info("##teamcity[buildStatisticValue key='CodeCoverageL' value='" + matcher.group(1) + "'"); getLog().info("##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='" + matcher.group(2) + "'"); getLog().info("##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='" + matcher.group(3) + "'"); } } } catch (ExecutionException e) { throw new MojoExecutionException("Error while executing lcov: ", e); } //Generate HTML Report File coverageReportDir = new File(new File(buildDirectory, "artifacts"), "coverage"); coverageReportDir.mkdirs(); try { commands = new ArrayList<String>(); commands.add(coverageTargetOutPutFile.getAbsolutePath()); commands.add("--prefix"); commands.add(basedir); commands.add("--output-directory"); commands.add(coverageReportDir.getAbsolutePath()); getLog().info(genHtmlCommandLine.getAbsolutePath() + " " + commands.toString()); executor.executeCommand(genHtmlCommandLine.getAbsolutePath(), commands, false); } catch (ExecutionException e) { throw new MojoExecutionException("Error while executing genhtml: ", e); } } ProcessHelper.killSimulatorProcess(getLog()); } else { getLog().info("Skipping GHUnit-Tests."); } }
From source file:com.cisco.step.jenkins.plugins.jenkow.WfUtil.java
static void deployAllToEngine() { File repoDir = JenkowWorkflowRepository.getRepositoryDir(); if (!repoDir.exists()) { LOGGER.info("no workflow source repository"); return;/*from w ww . ja v a 2s . c o m*/ } LOGGER.info("deploying all workflow engine"); RepositoryService repoSvc = JenkowEngine.getEngine().getRepositoryService(); Map<String, Date> deplTimes = new HashMap<String, Date>(); for (Deployment depl : repoSvc.createDeploymentQuery().list()) { //System.out.println(" depl: id="+depl.getId()+" name="+depl.getName()+" time="+depl.getDeploymentTime()); deplTimes.put(depl.getId(), depl.getDeploymentTime()); } Map<String, Date> pDefTimes = new HashMap<String, Date>(); for (ProcessDefinition pDef : repoSvc.createProcessDefinitionQuery().latestVersion().list()) { //System.out.println(" pDef:"+pDef+" deplId="+pDef.getDeploymentId()+" key="+pDef.getKey()); Date t = deplTimes.get(pDef.getDeploymentId()); if (t != null) pDefTimes.put(pDef.getKey(), t); } for (Iterator it = FileUtils.iterateFiles(repoDir, new String[] { Consts.WORKFLOW_EXT }, /*recursive=*/true); it.hasNext();) { File wff = (File) it.next(); String wfn = wff.getName(); int p = wfn.lastIndexOf('.'); if (p > -1) wfn = wfn.substring(0, p); Date prevDeplTime = pDefTimes.get(wfn); //System.out.println(" f="+wff+" wfn="+wfn+" deplTime="+prevDeplTime+" wff.lastModified="+new Date(wff.lastModified())); if (prevDeplTime == null || prevDeplTime.before(new Date(wff.lastModified()))) { try { WfUtil.deployToEngine(wff); } catch (FileNotFoundException e) { LOGGER.log(Level.SEVERE, "file not found " + wff, e); } } } }
From source file:com.keybox.manage.action.UploadAndPushAction.java
@Action(value = "/admin/push", results = { @Result(name = "success", location = "/admin/upload_result.jsp") }) public String push() { Long userId = AuthUtil.getUserId(servletRequest.getSession()); Long sessionId = AuthUtil.getSessionId(servletRequest.getSession()); try {//from ww w .j av a 2s . c o m //get next pending system pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId); if (pendingSystemStatus != null) { //get session for system SchSession session = null; for (Integer instanceId : SecureShellAction.getUserSchSessionMap().get(sessionId).getSchSessionMap() .keySet()) { //if host system id matches pending system then upload if (pendingSystemStatus.getId().equals(SecureShellAction.getUserSchSessionMap().get(sessionId) .getSchSessionMap().get(instanceId).getHostSystem().getId())) { session = SecureShellAction.getUserSchSessionMap().get(sessionId).getSchSessionMap() .get(instanceId); } } if (session != null) { //push upload to system currentSystemStatus = SSHUtil.pushUpload(pendingSystemStatus, session.getSession(), UPLOAD_PATH + "/" + uploadFileName, pushDir + "/" + uploadFileName); //update system status SystemStatusDB.updateSystemStatus(currentSystemStatus, userId); pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId); } } //if push has finished to all servers then delete uploaded file if (pendingSystemStatus == null) { File delFile = new File(UPLOAD_PATH, uploadFileName); FileUtils.deleteQuietly(delFile); //delete all expired files in upload path File delDir = new File(UPLOAD_PATH); if (delDir.isDirectory()) { //set expire time to delete all files older than 48 hrs Calendar expireTime = Calendar.getInstance(); expireTime.add(Calendar.HOUR, -48); Iterator<File> filesToDelete = FileUtils.iterateFiles(delDir, new AgeFileFilter(expireTime.getTime()), TrueFileFilter.TRUE); while (filesToDelete.hasNext()) { delFile = filesToDelete.next(); delFile.delete(); } } } hostSystemList = SystemStatusDB.getAllSystemStatus(userId); } catch (Exception e) { log.error(e.toString(), e); } return SUCCESS; }