Ejemplo n.º 1
0
PDMBUILDER_API void getCodeInfo(char *url,char *version,char *localpath)
{
	SourceCode *sourceCode = getSourceCode();
	
	strcpy(url,sourceCode->GetUrl().c_str());
	strcpy(version,sourceCode->GetVersion().c_str());
	strcpy(localpath,sourceCode->GetLocalPath().c_str());

	delete sourceCode;
	//url = (char *)sourceCode->GetUrl().c_str();
	//version = (char *)sourceCode->GetVersion().c_str();
	//localpath = (char *)sourceCode->GetLocalPath().c_str();
}
Ejemplo n.º 2
0
PDMBUILDER_API string checkout(string workspace)
{
	SourceCode *sourceCode = getSourceCode();

	char ExportCmd[500];
	memset(ExportCmd,0,sizeof(ExportCmd));

	string url  = sourceCode->GetUrl();
	string log("<---------------------------checkout--------------------------->\nCheckout: ");
	log.append(url).append("\n");
	//string fullpath(workspace+"\\"+sourceCode->GetLocalPath());
	string fullpath = sourceCode->GetLocalPath();
	fullpath = changeSeparator(fullpath);

	if(sourceCode->GetVersion() == "head"){
		sprintf(ExportCmd, "svn checkout --force --non-interactive --username %s --password %s %s \"%s\"",buildName.c_str(),buildPassword.c_str(),sourceCode->GetUrl().c_str(), fullpath.c_str());
	}else{
		sprintf(ExportCmd, "svn checkout -r %s --force  --non-interactive --username %s --password %s %s \"%s\"",buildName.c_str(),buildPassword.c_str(),sourceCode->GetVersion().c_str(),sourceCode->GetUrl().c_str(),fullpath.c_str());
	}

	int exitCode = 0;
	log += ExeCommand(ExportCmd,exitCode,(char *)workspace.c_str());
	if (exitCode>0&&exitCode!=STILL_ACTIVE)
	{
		return log +"\nerror";
	}
	int errorindex = log.find("svn: E");
	if (errorindex!=string::npos)
	{
		return log +"\nerror";
	}
	if ("head" == sourceCode->GetVersion())
	{
		//int length = log.length();
		int index = log.rfind("Checked out revision");
		if(index!=string::npos){
			int in = log.rfind(".");
			index += 21;
			sourceVersion = log.substr(index,in-index);
		}
	}else{
		sourceVersion = sourceCode->GetVersion();
	}
	delete sourceCode;
	
	return log;
}
Ejemplo n.º 3
0
PDMBUILDER_API bool checkSourceCode()
{
	SourceCode *sourceCode = getSourceCode();

	//string url = sourceCode->GetUrl();
	
	string fullpath(workspace+"\\"+sourceCode->GetLocalPath());
	//string fullpath = sourceCode->GetLocalPath();
	string log ;
	fullpath = changeSeparator(fullpath);
	string svnPath(fullpath+"\\.svn");
	if (!PathFileExists(svnPath.c_str()))
	{
		//printf("to checkout");
		log += checkout(workspace);
		
		//printf("svn checkout\n");
		int accessInt = log.find("Access to");
		if (accessInt!=string::npos)
		{
			if (log.find("forbidden")!=string::npos)
			{
				string nextNumFile(fullpath+"\\nextBuildNumber");
				if (!PathFileExists(nextNumFile.c_str()))
				{
					writeLog(log,workspace+"\\log");
					delete sourceCode;
					return true;
				}
				if (forceFlag!="false")
				{
					writeLog(log,workspace+"\\log");
				}
				delete sourceCode;
				return false;
			}
		}
		int errorint = log.find("error");
		if (errorint!=string::npos&&errorint==log.length()-5)
		{
			writeLog(log,workspace+"\\log");
			delete sourceCode;
			return false;
		}
		writeLog(log,workspace+"\\log");
		//writeLog(log,workspace+"\\log");
		delete sourceCode;
		return true;
	}

	char updateCmd[500];
	memset(updateCmd,0,sizeof(updateCmd));

	sprintf(updateCmd,"svn update --force --non-interactive --username %s --password %s --accept tf \"%s\"",buildName.c_str(),buildPassword.c_str(),sourceCode->GetLocalPath().c_str());
	//printf("to update");
	int exitCode = 0;
	log.assign("<---------------------------checkout--------------------------->\n ");
	log += ExeCommand(updateCmd,exitCode,(char *)workspace.c_str());
	//printf("svn update\n");
	if (exitCode>0&&exitCode!=STILL_ACTIVE)
	{
		log += "update source code error";
		if (forceFlag!="false")
		{
			writeLog(log,workspace+"\\log");
		}
		delete sourceCode;
		return false;
	}else if (log.find("svn cleanup")!=string::npos)
	{
		char cleanupCmd[100];
		memset(cleanupCmd,0,sizeof(cleanupCmd));
		sprintf(cleanupCmd,"svn cleanup");
		ExeCommand(cleanupCmd,exitCode,(char *)workspace.c_str());

		log = ExeCommand(updateCmd,exitCode,(char *)workspace.c_str());
		if (exitCode>0&&exitCode!=STILL_ACTIVE)
		{
			log += "update source code error";
			if (forceFlag!="false")
			{
				writeLog(log,workspace+"\\log");
			}
			delete sourceCode;
			return false;
		}
	}
	int index = log.find("Updated to revision");
	
	if (index>0)
	{
		index += 20;
		int in = log.find_last_of(".");
		sourceVersion = log.substr(index,in-index);
		
		writeLog(log,workspace+"\\log");
		delete sourceCode;
		return true;
	}else
	{
		int rindex = log.rfind("At revision");
		if (rindex!=string::npos)
		{
			int lindex = log.rfind(".");
			rindex += 12;
			sourceVersion = log.substr(rindex,lindex-rindex);
		}
		if (forceFlag!="false")
		{
			writeLog(log,workspace+"\\log");
		}
		
		delete sourceCode;
		return false;
	}
}