* @param pName name of the property to resolve
*
* @return property value, or {@code null} if it could not be found
*/
public String getProperty(final String pPomUrl, final String pName) {
final VirtualFile pPomFile = PomManager.getInstance(project).getFile(pPomUrl);
//
//check some preconfigured properties that are not present in
//configuration files, but Maven expects them because they are
//passed by the maven shell scripts
//
final MavenManager mavenMgr = MavenManager.getInstance();
final VirtualFile mavenHome = mavenMgr.getMavenHome();
if (pName.equals("maven.home"))
return mavenHome == null ? null : mavenHome.getPath();
//
//system properties
//
String value = System.getProperty(pName);
if (value != null && value.trim().length() > 0)
return resolveProperty(pPomFile, value);
//
//user properties
//
try {
final VirtualFile home = getUserHome();
if (home != null && home.isValid() && home.isDirectory() && FileUtils.exists(home)) {
final VirtualFile propsFile = home.findChild("build.properties");
if (propsFile != null && propsFile.isValid() && !propsFile.isDirectory() && FileUtils.exists(
propsFile)) {
value = getFilePropertyValue(propsFile, pName);
if (value != null)
return resolveProperty(pPomFile, value);
}
}
}
catch (IOException e) {
LOG.warn(e.getMessage(), e);
}
//
//starting to use POM - get POM directory
//
if (pPomFile != null) {
final VirtualFile dir = pPomFile.getParent();
if (dir != null) {
//
//build properties
//
try {
value = getFilePropertyValue(dir, "build.properties", pName);
if (value != null)
return resolveProperty(pPomFile, value);
}
catch (IOException e) {
LOG.warn(e.getMessage(), e);
}
//
//project properties
//
try {
value = getFilePropertyValue(dir, "project.properties", pName);
if (value != null)
return resolveProperty(pPomFile, value);
}
catch (IOException e) {
LOG.warn(e.getMessage(), e);
}
}
}
if (mavenHome == null || !FileUtils.exists(mavenHome) || !mavenHome.isValid() || !mavenHome.isDirectory())
return null;
final String baseJarUrl = "jar://" + mavenHome.getPath() + "/lib/maven.jar!/";
//
//maven defaults properties
//
try {
final String url = baseJarUrl + "defaults.properties";
final VirtualFile propsFile = VirtualFileManager.getInstance().findFileByUrl(url);
if (propsFile != null) {
value = getFilePropertyValue(propsFile, pName);
if (value != null)
return resolveProperty(pPomFile, value);
}
}
catch (IOException e) {
LOG.warn(e.getMessage(), e);
}
//
//maven driver properties
//
try {
final String url = baseJarUrl + "driver.properties";
final VirtualFile propsFile = VirtualFileManager.getInstance().findFileByUrl(url);
if (propsFile != null) {
value = getFilePropertyValue(propsFile, pName);
if (value != null)
return resolveProperty(pPomFile, value);
}