Skip to content

Commit

Permalink
add env replace
Browse files Browse the repository at this point in the history
  • Loading branch information
vintagewang committed Jun 9, 2012
1 parent c549c55 commit a81e7d2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/jwrapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
<-XX:PermSize>128M</-XX:PermSize>
<-XX:MaxPermSize>128M</-XX:MaxPermSize>
</options>
</java>
</java>
17 changes: 17 additions & 0 deletions src/JWUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

#ifdef WIN32
#include <Windows.h>
#endif
Expand Down Expand Up @@ -66,4 +68,19 @@ namespace JWUtil

return result;
}

void setEnv(const char* name, const char* value)
{
assert(NULL != name);
assert(NULL != value);

#ifdef WIN32
std::string envFull = name;
envFull += "=";
envFull += value;
_putenv(envFull.c_str());
#else
setenv(name, value, 1);
#endif
}
}
5 changes: 5 additions & 0 deletions src/JWUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace JWUtil
* 获取当前程序可执行程序的全路径,含文件名
*/
std::string getCurrentExeFilePath();

/**
* 设置环境变量
*/
void setEnv(const char* name, const char* value);
};

#endif // end of _JW_JWUTIL_H__
33 changes: 32 additions & 1 deletion src/JavaConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ bool JavaConfig::load()
return false;
}


JWUtil::setEnv("JAVA_HOME", this->javaHome.c_str());

return true;
}

Expand All @@ -102,10 +105,38 @@ void JavaConfig::printAll()
printf("classPathList %2d = [%s]\n", i, this->classPathList[i].c_str());
}
}

}

std::string JavaConfig::getConfigFile()
{
return JWUtil::getCurrentExeFilePath() + ".xml";
}

bool JavaConfig::expandMacro(std::string& value)
{
bool result = true;
for(std::size_t start = 0; result
&& std::string::npos != (start = value.find("${", start));) {
start += 2;
std::size_t end = value.find("}", start);
result = end != std::string::npos;
if(result) {
std::string var = value.substr(start, end - start);

// 可执行程序所在目录
if(var == "cpd") {

}
// 当前工作目录
else if(var == "cwd") {

}
// 环境变量
else {

}
}
}

return result;
}
1 change: 1 addition & 0 deletions src/JavaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class JavaConfig

private:
static std::string getConfigFile();
static bool expandMacro(std::string& value);
};

#endif // end of _JW_JAVA_CONFIG_H__

0 comments on commit a81e7d2

Please sign in to comment.