Java Code Examples for play.vfs.VirtualFile#getRealFile()

The following examples show how to use play.vfs.VirtualFile#getRealFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestRunnerPlugin.java    From restcommander with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoad() {
    VirtualFile appRoot = VirtualFile.open(Play.applicationPath);
    Play.javaPath.add(appRoot.child("test"));
    for (VirtualFile module : Play.modules.values()) {
        File modulePath = module.getRealFile();
        if (!modulePath.getAbsolutePath().startsWith(Play.frameworkPath.getAbsolutePath()) && !Play.javaPath.contains(module.child("test"))) {
            Play.javaPath.add(module.child("test"));
        }
    }
}
 
Example 2
Source File: ClassStateHashCreator.java    From restcommander with Apache License 2.0 5 votes vote down vote up
private String getClassDefsForFile( VirtualFile current ) {

        File realFile = current.getRealFile();
        // first we look in cache

        FileWithClassDefs fileWithClassDefs = classDefsInFileCache.get( realFile );
        if( fileWithClassDefs != null && fileWithClassDefs.fileNotChanges() ) {
            // found the file in cache and it has not changed on disk
            return fileWithClassDefs.getClassDefs();
        }

        // didn't find it or it has changed on disk
        // we must re-parse it

        StringBuilder buf = new StringBuilder();
        Matcher matcher = classDefFinderPattern.matcher(current.contentAsString());
        buf.append(current.getName());
        buf.append("(");
        while (matcher.find()) {
            buf.append(matcher.group(1));
            buf.append(",");
        }
        buf.append(")");
        String classDefs = buf.toString();

        // store it in cache
        classDefsInFileCache.put( realFile, new FileWithClassDefs(realFile, classDefs));
        return classDefs;
    }
 
Example 3
Source File: AgentConfigProvider.java    From restcommander with Apache License 2.0 5 votes vote down vote up
public void saveConfigFile(CONFIG_FILE_TYPE configFile,
		String configFileContent) {

	if (configFile == null) {
		models.utils.LogUtils.printLogError("ERROR reading config: configFile is empty.");
	}

	// String nodeGroupConfFileLocation =
	// Play.configuration.getProperty("agentmaster.nodegroup.conf.file.location");

	// in test
	String nodeGroupConfFileLocation = "conf/"
			+ configFile.toString().toLowerCase(Locale.ENGLISH) + ".conf";
	try {

		VirtualFile vf = VirtualFile
				.fromRelativePath(nodeGroupConfFileLocation);
		File realFile = vf.getRealFile();

		boolean append = false;
		FileWriter fw = new FileWriter(realFile, append);
		fw.write(configFileContent);

		fw.close();
		models.utils.LogUtils.printLogNormal("Completed saveConfigFile with size: "
				+ configFileContent.length() + " at "
				+ DateUtils.getNowDateTimeStr());

	} catch (Throwable e) {
		models.utils.LogUtils.printLogError("Error in saveConfigFile."
				+ e.getLocalizedMessage());
		e.printStackTrace();
	}

}
 
Example 4
Source File: AgentUtils.java    From restcommander with Apache License 2.0 5 votes vote down vote up
public static void saveStringToFile(String filePath, String fileContent) {

		if (filePath == null) {
			models.utils.LogUtils.printLogError("ERROR reading filePath: filePath is empty.");
		}

		// String nodeGroupConfFileLocation =
		// Play.configuration.getProperty("agentmaster.nodegroup.conf.file.location");

		// in test
		try {

			VirtualFile vf = VirtualFile.fromRelativePath(filePath);
			File realFile = vf.getRealFile();

			boolean append = false;
			FileWriter fw = new FileWriter(realFile, append);
			fw.write(fileContent);

			fw.close();
			models.utils.LogUtils.printLogNormal("Completed saveStringToFile with size: "
					+ fileContent.length() / VarUtils.CONVERSION_1024
					+ " KB Path: " + filePath + " at "
					+ DateUtils.getNowDateTimeStr());

		} catch (Throwable e) {
			models.utils.LogUtils.printLogError("Error in saveStringToFile."
					+ e.getLocalizedMessage());
			e.printStackTrace();
		}

	}
 
Example 5
Source File: AgentConfigProvider.java    From restcommander with Apache License 2.0 4 votes vote down vote up
/**
 * In the end: will always call
 * updateAllAgentDataFromNodeGroupSourceMetadatas() to initialize
 * NodeGroupDataMap object if needed in allAgentData
 */
public String readConfigFile(CONFIG_FILE_TYPE configFile) {

	if (configFile == null) {
		return "ERROR reading config: configFile is empty.";
	}

	// String nodeGroupConfFileLocation =
	// Play.configuration.getProperty("agentmaster.nodegroup.conf.file.location");

	StringBuilder sb = new StringBuilder();

	// in test
	String nodeGroupConfFileLocation = "conf/"
			+ configFile.toString().toLowerCase(Locale.ENGLISH) + ".conf";
	try {

		VirtualFile vf = VirtualFile
				.fromRelativePath(nodeGroupConfFileLocation);
		File realFile = vf.getRealFile();

		FileReader fr = new FileReader(realFile);
		BufferedReader reader = new BufferedReader(fr);
		String line = null;

		while ((line = reader.readLine()) != null) {
			sb.append(line).append("\n");
		}

		models.utils.LogUtils.printLogNormal("Completed readConfigFile with size: "
				+ sb.toString().length() / 1024.0 + " KB at "
				+ DateUtils.getNowDateTimeStr());

	} catch (Throwable e) {
		models.utils.LogUtils.printLogError("Error in readConfigFile."
				+ e.getLocalizedMessage());
		e.printStackTrace();
	}

	return sb.toString();

}
 
Example 6
Source File: AgentConfigProvider.java    From restcommander with Apache License 2.0 4 votes vote down vote up
public synchronized void updateAggregationMetadatasFromConf() {

		// String nodeGroupConfFileLocation =
		// Play.configuration.getProperty("agentmaster.aggregation.conf.file.location");

		// in test
		try {

			VirtualFile vf = VirtualFile
					.fromRelativePath(ConfUtils.aggregationConfFileLocation);
			File realFile = vf.getRealFile();

			FileReader fr = new FileReader(realFile);
			BufferedReader reader = new BufferedReader(fr);
			String line = null;
			String requestContentLine = null;
			String requestContentTemplate = null;

			String aggregationType = null;

			adp.aggregationMetadatas.clear();
			while ((line = reader.readLine()) != null) {

				// trim the comments or empty lines
				if (line.trim().length() == 0
						|| (line.trim().length() >= 1 && line.trim()
								.startsWith("%"))
						|| line.trim().startsWith("```")) {
					continue;
				}

				aggregationType = line.trim();

				// assuming the next line is the request content: parse it to
				// get the post content
				// fix: trim ending / beging white spaces
				requestContentLine = reader.readLine().trim();
				requestContentTemplate = requestContentLine.replace("```", "");

				adp.aggregationMetadatas.put(aggregationType,
						requestContentTemplate);
			}

			models.utils.LogUtils.printLogNormal
					 ("Completed updateAggregationMetadatasFromConf with size: "
							+ adp.aggregationMetadatas.size()
							+ " at "
							+ DateUtils.getNowDateTimeStr());
			reader.close();
			fr.close();
		} catch (Throwable e) {
			models.utils.LogUtils.printLogError("Error in updateAggregationMetadatasFromConf."
					+ e.getLocalizedMessage());
			e.printStackTrace();
		}

	}
 
Example 7
Source File: AgentConfigProvider.java    From restcommander with Apache License 2.0 4 votes vote down vote up
/**
 * For common http headers
 * 
 * TODO
 */
public synchronized void updateCommonHttpHeaderFromConf() {

	// in test
	try {

		VirtualFile vf = VirtualFile
				.fromRelativePath(ConfUtils.httpHeaderConfFileLocation);
		File realFile = vf.getRealFile();

		FileReader fr = new FileReader(realFile);
		BufferedReader reader = new BufferedReader(fr);
		String httpHeaderType = null;
		String line = null;
		String httpHeaderKey = null;
		String httpHeaderValue = null;
		String httpHeaderValueLine = null;
		// HttpHeaderMetadata
		adp.headerMetadataMap.clear();

		while ((line = reader.readLine()) != null) {

			// trim the comments or empty lines
			if (line.trim().length() == 0
					|| (line.trim().length() >= 1 && line.trim()
							.startsWith("%"))
					|| line.trim().startsWith("```")) {
				continue;
			}

			Map<String, String> headerMap = new HashMap<String, String>();

			httpHeaderType = line.trim();

			boolean startTagParsed = false;
			boolean endTagParsed = false;
			while ((line = reader.readLine()) != null) {
				if (line.equalsIgnoreCase(VarUtils.HTTPHEADER_CONF_TAG_HTTP_HEADER_LIST_START1)) {
					startTagParsed = true;
				} else if (line
						.equalsIgnoreCase(VarUtils.HTTPHEADER_CONF_TAG_HTTP_HEADER_LIST_END1)) {
					endTagParsed = true;
					break;
				} else if (startTagParsed == true && endTagParsed == false) {
					// fixed bug: when fqdn has a space in the end.
					// Assuming FQDN dont have a space in the middle
					String lineTrimmed = line.trim();
					if (lineTrimmed != null && !lineTrimmed.isEmpty()) {

						httpHeaderKey = lineTrimmed;
						httpHeaderValueLine = reader.readLine().trim();
						httpHeaderValue = httpHeaderValueLine.replace(
								"```", "");
						headerMap.put(httpHeaderKey, httpHeaderValue);
					} else {
						continue; // read next line
					}

				}// end else if
			}// end while

			HttpHeaderMetadata httpHeaderMetadata = new HttpHeaderMetadata(
					httpHeaderType, headerMap);
			adp.headerMetadataMap.put(httpHeaderType, httpHeaderMetadata);
		}

		models.utils.LogUtils.printLogNormal
				 ("Completed updateCommonHttpHeaderFromConf headerMap size: "
						+ adp.headerMetadataMap.size()
						+ " at "
						+ DateUtils.getNowDateTimeStr());
		reader.close();
		fr.close();
	} catch (Throwable e) {
		models.utils.LogUtils.printLogError("Error in updateCommonHttpHeaderFromConf.."
				+ e.getLocalizedMessage());
		e.printStackTrace();
	}

}
 
Example 8
Source File: LogConsole.java    From restcommander with Apache License 2.0 4 votes vote down vote up
public static String readConfigFile(String fileName, String numLines) {
 int lineCountForDisplay = 0;
 if("all".equalsIgnoreCase(numLines)) {
     lineCountForDisplay = 0;
 } else {
     lineCountForDisplay = Integer.parseInt(numLines);
 }
    if (fileName == null) {
        return "ERROR reading config: configFile is empty.";
    }
    List<String> linesTotal = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();
    
    String logDir = (fileName.contains("models.utils.LogUtils.printLogNormal")) ? "logs/" : "log/";
    
    String logFileLocation = logDir
            + fileName.toString().toLowerCase(Locale.ENGLISH) ;
    try {
       
        VirtualFile vf = VirtualFile
                .fromRelativePath(logFileLocation);
        File realFile = vf.getRealFile();
        FileReader fr = new FileReader(realFile);
        BufferedReader reader = new BufferedReader(fr);
        String line = null;
        while ((line = reader.readLine()) != null) {
            line = line + "<br />";
            linesTotal.add(line);
        }
    } catch (Throwable e) {
        models.utils.LogUtils.printLogError("Error in readConfigFile."
                + e.getLocalizedMessage());
       // e.printStackTrace();
    }
    
    if(VarUtils.IN_DETAIL_DEBUG){
    	models.utils.LogUtils.printLogNormal("linesTotal size:"+linesTotal.size());
    	models.utils.LogUtils.printLogNormal("lineCountForDisplay:"+lineCountForDisplay);
    	
    }
    if(lineCountForDisplay == 0) {
        for (int j= 0; j< linesTotal.size(); j++) {
            sb.append(linesTotal.get(j));
        }
    } else if (linesTotal.size() > lineCountForDisplay) {
        for (int j= (linesTotal.size() - lineCountForDisplay); j< linesTotal.size(); j++) {
            sb.append(linesTotal.get(j));
        }
    } else {
        for (int j= 0; j< linesTotal.size(); j++) {
            sb.append(linesTotal.get(j));
        }
    }
    
    if(VarUtils.IN_DETAIL_DEBUG){
    	models.utils.LogUtils.printLogNormal("linesTotal size:"+linesTotal.size());
    	
    }
    return sb.toString();
}