blob: a8349bcbb89dabb09407aabdd0d4308e2c27ae27 [file] [log] [blame]
<?php
$ignoredWorkingSets = array('EXCLUDE', 'STEM-Data-EarthScience');
define('DATA_BUILD_MAP_PATH', 'releng/org.eclipse.stem.releng/maps/stem.data.map');
define('BUILD_MAP_PATH', 'releng/org.eclipse.stem.releng/maps/stem.map');
define('BUILD_MAP_DIRECTORY_PATH', 'releng/org.eclipse.stem.releng/maps/directories.properties');
define('WORKING_SET_MATCH', '!WS:');
define('MAP_ENTRY_REGEX', '(.*)@(.*)=(.*)');
define('MAP_ENTRY_PATH_PREFIX', "\${checkoutDir}");
define('REPOSITORY_ROOT_SSH', 'svn+ssh://dev.eclipse.org/svnroot/technology/org.eclipse.stem/');
define('REPOSITORY_ROOT_HTTP', 'http://dev.eclipse.org/svnroot/technology/org.eclipse.stem/');
define('REPOSITORY_ROOT_HTTPS', 'https://dev.eclipse.org/svnroot/technology/org.eclipse.stem/');
define('PROVIDER_ID', 'org.tigris.subversion.subclipse.core.svnnature');
define('PROVIDER_ENTRY_TEMPLATE', '0.9.3,$PATH$,$NAME$');
define('RELENG_WS_ENTRY', '!WS:STEM-Releng');
define('RELENG_PROJECT_ENTRY', 'resource@org.eclipse.stem.releng=COPY,${source.path.releng},org.eclipse.stem.releng');
define('TARGETPLATFORM_PROJECT_ENTRY', 'resource@org.eclipse.stem.releng.targetplatforms=COPY,${source.path.releng},org.eclipse.stem.releng.targetplatforms');
$workingSetEntryTemplates = array();
$workingSetEntryTemplates['default'] = array('factoryID'=>'org.eclipse.ui.internal.model.ResourceFactory','path'=>'$NAME$','type'=>'4');
$workingSetEntryTemplates['plugin'] = array('factoryID'=>'org.eclipse.jdt.ui.PersistableJavaElementFactory', 'elementID'=>'=$NAME$');
$workingSetEntryTemplates['fragment'] = $workingSetEntryTemplates['plugin'];
function getBuildDirectoryMapUrl()
{
$repositoryRoot = getRepositoryRoot(true);
return $repositoryRoot .'/'. BUILD_MAP_DIRECTORY_PATH;
}
function getBuildDirectoryMap()
{
$directoryMapData = @file(getBuildDirectoryMapUrl());
if (!$directoryMapData) {
return false;
}
$repositoryRoot = getRepositoryRoot();
$data = array();
foreach ($directoryMapData as $line) {
$tokens = explode("=", $line);
if (is_array($tokens) && sizeof($tokens) == 2) {
$name = $tokens[0];
$path = $tokens[1];
if ($name == "source.path") {
$path = $repositoryRoot;
$data[$name] = trim($path);
} else {
if (@eregi('^\$\{(.*)\}\/(.*)$', $path, $t2)) {
$path = $data[$t2[1]] . '/'. $t2[2];
$data[$name] = trim($path);
}
}
}
}
return $data;
}
function getBuildMapUrl()
{
$repositoryRoot = getRepositoryRoot(true);
return $repositoryRoot .'/'. BUILD_MAP_PATH;
}
function getDataBuildMapUrl()
{
$repositoryRoot = getRepositoryRoot(true);
return $repositoryRoot .'/'. DATA_BUILD_MAP_PATH;
}
function getRepositoryRoot($forceHttp = false)
{
if (!$forceHttp && isset($_REQUEST['r']) && $_REQUEST['r'] == "ssh") {
$path = REPOSITORY_ROOT_SSH;
} else if (!$forceHttp && isset($_REQUEST['r']) && $_REQUEST['r'] == "https") {
$path = REPOSITORY_ROOT_HTTPS;
} else {
$path = REPOSITORY_ROOT_HTTP;
}
if (isset($_REQUEST['branch'])) {
$path .= "branches/". $_REQUEST['branch'];
} else if (isset($_REQUEST['tag'])) {
$path .= "tags/". $_REQUEST['tag'];
} else {
$path .= "trunk";
}
return $path;
}
function processMapEntry($line, $dirMap)
{
$repositoryRoot = getRepositoryRoot();
$data = array();
$data['line'] = $line;
//feature@org.eclipse.stem.feature=COPY,${checkoutDir}/features,org.eclipse.stem.feature
if (@eregi(MAP_ENTRY_REGEX, $line, $tokens)) {
//COPY,${checkoutDir}/features,org. eclipse.stem.feature
$pathTokens = explode(",", $tokens[3]);
if ($pathTokens[0] == "COPY") {
$dirKey = trim($pathTokens[1]);
$dirKey = substr($dirKey, 2, $dirKey-1);
if (!array_key_exists($dirKey, $dirMap)) {
return false;
}
$path = $dirMap[$dirKey];
// Local entry
$data['path'] = $path . '/' . $pathTokens[2];
//$data['path'] = str_replace(MAP_ENTRY_PATH_PREFIX, $repositoryRoot, $pathTokens[1]) ."/". $tokens[2];
}
$data['type'] = $tokens[1];
$data['name'] = $tokens[2];
}
return $data;
}
function processMapFile($lines)
{
$data = array();
$buildDirMap = getBuildDirectoryMap();
$currentWorkingSet = "EXCLUDE";
foreach ($lines as $line) {
$line = trim($line);
if ($line != "") {
if ($line{0} == "!" || $line{0} == "#") {
// comment line
$lineMatch = strstr($line, WORKING_SET_MATCH);
// Matched a working set string
if ($lineMatch !== FALSE) {
$currentWorkingSet = str_replace(WORKING_SET_MATCH, "", $lineMatch);
}
} else {
if ($currentWorkingSet === false) {
continue;
}
$entry = processMapEntry($line, $buildDirMap);
if (!$entry) {
continue;
}
$data[$currentWorkingSet][] = $entry;
}
}
}
return $data;
}
function buildProviderDOM($xml, $workingSets)
{
global $ignoredWorkingSets;
$xml = createElementDOM($xml, "provider");
createAttributeDOM($xml, "id", PROVIDER_ID);
foreach ($workingSets as $workingSetName => $workingSetEntries) {
if (!isExcludedWorkingSet($workingSetName)) {
// Not an ignored working set. Process.
foreach ($workingSetEntries as $workingSetEntry) {
$projectRef = createElementDOM($xml,"project");
if (!isset($workingSetEntry['path'])) {
continue;
}
$entryString = PROVIDER_ENTRY_TEMPLATE;
$entryString = str_replace("\$PATH\$", $workingSetEntry['path'], $entryString);
$entryString = str_replace("\$NAME\$", $workingSetEntry['name'], $entryString);
createAttributeDOM($projectRef, "reference", $entryString);
}
}
}
}
function isExcludedWorkingSet($wsName)
{
global $ignoredWorkingSets;
$ws = false;
if (isset($_REQUEST['ws'])) {
return !($_REQUEST['ws'] == $wsName);
}
return in_array($wsName, $ignoredWorkingSets);
}
/**
<workingSets editPageId="org.eclipse.jdt.ui.JavaWorkingSetPage" id="1310766141425_10" label="STEM-Tests" name="STEM-Tests">
<item elementID="=org.eclipse.stem.tests.automaticexperiment" factoryID="org.eclipse.jdt.ui.PersistableJavaElementFactory"/>
<item factoryID="org.eclipse.ui.internal.model.ResourceFactory" path="/org.eclipse.stem.core.feature" type="4"/>
</workingSets>
*/
function addWorkingSetEntryDOM($wsXML, $workingSetEntry)
{
if (!isset($workingSetEntry['path'])) {
return;
}
global $workingSetEntryTemplates;
$itemXML = createElementDOM($wsXML, "item");
if (array_key_exists($workingSetEntry['type'],$workingSetEntryTemplates)) {
$attributes = $workingSetEntryTemplates[$workingSetEntry['type']];
} else {
$attributes = $workingSetEntryTemplates['default'];
}
foreach ($attributes as $attributeName => $attributeValue) {
$attributeValue = str_replace("\$PATH\$", $workingSetEntry['path'], $attributeValue);
$attributeValue = str_replace("\$NAME\$", $workingSetEntry['name'], $attributeValue);
createAttributeDOM($itemXML, $attributeName, $attributeValue);
}
}
function buildWorkingSetDOM($rootXML, $workingSets)
{
global $ignoredWorkingSets;
$seq = 0;
foreach ($workingSets as $workingSetName => $workingSetEntries) {
if (!isExcludedWorkingSet($workingSetName)) {
$wsXML = createElementDOM($rootXML, "workingSets");
createAttributeDOM($wsXML, "editPageId", "org.eclipse.jdt.ui.JavaWorkingSetPage");
createAttributeDOM($wsXML, "id", time() ."_". $seq++);
createAttributeDOM($wsXML, "label", $workingSetName);
createAttributeDOM($wsXML, "name", $workingSetName);
foreach ($workingSetEntries as $workingSetEntry) {
addWorkingSetEntryDOM($wsXML, $workingSetEntry);
}
}
}
}
function buildProjectSetDOM($data)
{
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$root = createElementDOM($doc, "psf");
createAttributeDOM($root, "version", "2.0");
buildProviderDOM($root, $data);
buildWorkingSetDOM($root, $data);
return $doc;
}
function createElementDOM($root, $name)
{
if ($root->ownerDocument != NULL) {
$element = $root->ownerDocument->createElement($name);
} else {
$element = $root->createElement($name);
}
$root->appendChild($element);
return $element;
}
function createAttributeDOM($root, $name, $value)
{
$attr = $root->ownerDocument->createAttribute($name);
$attr->value = $value;
$root->appendChild($attr);
}
function addRelengProjects($buildMapData)
{
$buildMapData[] = RELENG_WS_ENTRY;
$buildMapData[] = RELENG_PROJECT_ENTRY;
$buildMapData[] = TARGETPLATFORM_PROJECT_ENTRY;
return $buildMapData;
}
function getBuildMap()
{
$dataBuildMap = @file(getDataBuildMapUrl());
$coreBuildMap = @file(getBuildMapUrl());
$buildMapData = array_merge($coreBuildMap, $dataBuildMap);
if (!$buildMapData) {
return false;
}
//$buildMapData = @file(getBuildMapUrl());
$buildMapData = addRelengProjects($buildMapData);
return $buildMapData;
}
$buildMapData = getBuildMap();
if (!$buildMapData) {
echo "Error: Cannot get project set data. Check that the branch or tag exists. Only branches from STEM 1.2.1 and newer are compatible.";
exit();
}
$data = processMapFile($buildMapData);
//echo "<pre>";
//print_r($data);
//echo "</pre>";
$xml = buildProjectSetDOM($data);
Header("Content-type: text/xml");
echo $xml->saveXML();
exit();
/**
function buildWorkingSetXML($rootXML, $workingSets)
{
global $ignoredWorkingSets;
$seq = 0;
foreach ($workingSets as $workingSetName => $workingSetEntries) {
if (!in_array($workingSetName, $ignoredWorkingSets)) {
$wsXML = $rootXML->addChild("workingSets");
$wsXML->addAttribute("editPageId", "org.eclipse.jdt.ui.JavaWorkingSetPage");
$wsXML->addAttribute("id", time() ."_". $seq++);
$wsXML->addAttribute("label", $workingSetName);
$wsXML->addAttribute("name", $workingSetName);
foreach ($workingSetEntries as $workingSetEntry) {
addWorkingSetEntry($wsXML, $workingSetEntry);
}
}
}
}
function buildProjectSetXML($data)
{
$root = new SimpleXMLElement("<psf/>");
$root->addAttribute("version", "2.0");
buildProviderXML($root, $data);
buildWorkingSetXML($root, $data);
return $root;
}
function buildProviderXML($xml, $workingSets)
{
$xml = $xml->addChild("provider");
$xml->addAttribute("id", PROVIDER_ID);
foreach ($workingSets as $workingSetName => $workingSetEntries) {
if (!in_array($workingSetName, $ignoredWorkingSets)) {
// Not an ignored working set. Process.
foreach ($workingSetEntries as $workingSetEntry) {
$projectRef = $xml->addChild("project");
$entryString = PROVIDER_ENTRY_TEMPLATE;
$entryString = str_replace("\$PATH\$", $workingSetEntry['path'], $entryString);
$entryString = str_replace("\$NAME\$", $workingSetEntry['name'], $entryString);
$projectRef->addAttribute("reference", $entryString);
}
}
}
}
function addWorkingSetEntry($wsXML, $workingSetEntry)
{
global $workingSetEntryTemplates;
$itemRef = $wsXML->addChild("item");
if (array_key_exists($workingSetEntry['type'],$workingSetEntryTemplates)) {
$attributes = $workingSetEntryTemplates[$workingSetEntry['type']];
} else {
$attributes = $workingSetEntryTemplates['default'];
}
foreach ($attributes as $attributeName => $attributeValue) {
$attributeValue = str_replace("\$PATH\$", $workingSetEntry['path'], $attributeValue);
$attributeValue = str_replace("\$NAME\$", $workingSetEntry['name'], $attributeValue);
$itemRef->addAttribute($attributeName, $attributeValue);
}
}
*/
?>