/usr/share/drush/commands/drush_make/contrib/drush_make_d_o.convert.inc is in drush-make 2.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | <?php
class DrushMakeDrupalorgVersionChecker {
function latestVersion($project_name, $version) {
// Project types that are valid for the version checker.
$allowed_project_types = array(
'core',
'module',
'theme',
);
$project = array(
'name' => $project_name,
'core' => $this->core,
'version' => $version,
'location' => drush_get_option('drush-make-update-default-url'),
);
$project = drush_make_updatexml($project);
// Because the version data we get back from the XML may not be the same
// data we passed, and because we can fail even if version data is
// returned, track both the success/failure of the request, and the
// version data.
// Check for bad projects and branch releases.
if (empty($project) || preg_match('/.*-dev$/', $project['version'])) {
// Use the passed version if no version was returned.
if (empty($project)) {
$final_version = $version;
}
else {
$final_version = $project['version'];
}
if ($project_name == 'drupal') {
drush_make_error('BUILD_ERROR', dt("Drupal core does not have an official release for version '%version' yet.", array('%version' => $final_version)));
}
else {
drush_make_error('BUILD_ERROR', dt("Project '%project' does not have an official release for version '%version'.", array('%project' => $project_name, '%version' => $final_version)));
}
$result = FALSE;
}
// Make sure the project is an allowed project type.
elseif (!in_array($project['type'], $allowed_project_types)) {
drush_make_error('BUILD_ERROR', dt("Project %project of type '%type' is not permitted.", array('%project' => $project_name, '%type' => $project['type'])));
$final_version = $project['version'];
$result = FALSE;
}
else {
$final_version = $project['version'];
$result = TRUE;
}
return array($result, $final_version);
}
}
class DrushMakeDrupalorgConverter extends DrushMakeDrupalorgVersionChecker {
function __construct($from, $to = NULL) {
$this->from = $from;
$this->to = $to;
$this->log = array();
}
function run() {
if ($this->read()) {
if ($this->convert()) {
$this->write();
}
}
}
function read() {
if (!($this->old_info = drush_make_parse_info_file($this->from))) {
drush_make_error('FILE_ERROR', dt("Unable to parse file %file", array('%file' => $this->from)));
return FALSE;
}
return TRUE;
}
function log($message, $type = 'ok') {
// Save the log messages so they can be put into the output for the .make
// file.
if (empty($this->to)) {
$this->log[] = "[$type]: \t $message";
}
// Only log to screen if we're outputting the conversion to file.
else {
drush_log($message, $type);
}
}
function convert() {
// Run the regular validation first. This performs basic syntax
// validation, and also pre-converts special syntax into a standard
// format. Since the info file validation doesn't return any data if
// validation fails, we have to bail here.
if (!($this->old_info = drush_make_validate_info_file($this->old_info))) {
return FALSE;
}
// The list of currently allowed top-leval attributes.
$top_level_attribute_whitelist = array('core', 'api', 'core_release', 'projects');
// The list of currently allowed project-level attributes.
$project_attribute_whitelist = array('version', 'subdir', 'patch');
// The list of currently disallowed projects.
$project_disallowed_list = array('drupal');
// Assume no errors to start.
$errors = FALSE;
// First order of business: convert core version.
$parts = explode('.', $this->old_info['core']);
$core_major = $parts[0];
$this->core = $core_major . '.x';
// Check for a stable release on the branch.
list($result, $final_version) = $this->latestVersion('drupal', $core_major);
if ($result) {
$this->new_info['core'] = $final_version;
$this->log(dt('Setting the Drupal core version to %version.', array('%version' => $final_version)));
}
else {
$errors = TRUE;
}
$this->new_info['api'] = 2;
if (isset($this->old_info['projects'])) {
foreach ($this->old_info['projects'] as $project => $project_data) {
// Skip conversion for disallowed projects.
if (in_array($project, $project_disallowed_list)) {
if ($project == 'drupal') {
$this->log(dt("It is not permitted to include Drupal core as a project in an install profile -- it has been removed"), 'warning');
}
else {
$this->log(dt("Removed disallowed project '%project'", array('%project' => $project)), 'warning');
}
continue;
}
// Clean out disallowed project attributes.
foreach ($project_data as $attribute => $attribute_value) {
if (!in_array($attribute, $project_attribute_whitelist)) {
$this->log(dt("The '%attribute' attribute is not allowed for the '%project' project, removing.", array('%attribute' => $attribute, '%project' => $project)), 'warning');
unset($project_data[$attribute]);
}
}
// Check that patches do in fact come from drupal.org.
if (isset($project_data['patch'])) {
foreach ($project_data['patch'] as $key => $patch) {
if (strpos($patch, 'http://drupal.org/files/issues') !== 0) {
$this->log(dt("The patch '%patch' is not hosted on drupal.org -- it has been removed.", array('%patch' => $patch)), 'warning');
unset($project_data['patches'][$key]);
}
}
}
// Reset the versioning variables to start fresh for every project.
$version = NULL;
$result = FALSE;
$final_version = '';
// Figure out the basic version string.
if (empty($project_data['version'])) {
$version = DRUSH_MAKE_VERSION_BEST;
}
elseif (preg_match('/^(\d+)((\.\d+)(-[a-z0-9]+)?)?$/', $project_data['version'], $matches)) {
// Branch version only.
if (empty($matches[2])) {
$version = $matches[1];
}
// Development snapshots not allowed.
elseif (!empty($matches[4]) && $matches[4] == '-dev') {
drush_make_error('BUILD_ERROR', dt("An official release is required for '%project' -- a development version cannot be used.", array('%project' => $project)));
$errors = TRUE;
// Move on, nothing more needs to be done with this project.
continue;
}
// All regular releases.
else {
$version = $matches[1] . $matches[2];
}
}
// Use the update XML to verify this project actually has a valid
// release.
if (isset($version)) {
list($result, $final_version) = $this->latestVersion($project, $version);
}
if ($result) {
$this->log(dt("Setting version for project '%project' to '%version'", array('%project' => $project, '%version' => $final_version)));
$project_data['version'] = $final_version;
if (array_keys($project_data) == array('version')) {
$project_data = $project_data['version'];
}
$this->new_info['projects'][$project] = $project_data;
}
else {
$errors = TRUE;
}
}
}
// Clean out disallowed top-level attributes.
foreach ($this->old_info as $attribute => $attribute_value) {
if (!in_array($attribute, $top_level_attribute_whitelist)) {
$this->log(dt("The '%attribute' make file attribute is not allowed, removing.", array('%attribute' => $attribute, )), 'warning');
}
}
if ($errors) {
return FALSE;
}
return TRUE;
}
function write() {
$output = $this->render($this->new_info);
// Write to stdout.
if (empty($this->to)) {
$log = '';
if (!empty($this->log)) {
$log .= dt("; Logged conversion messages follow. The final converted .make file follows these messages.\n");
foreach ($this->log as $message) {
$log .= "; $message\n";
}
}
print $log . $output;
}
// Write to file.
else {
if (file_put_contents($this->to, $output)) {
drush_log(dt("Successfully wrote converted .make file %file.", array('%file' => $this->to)), 'ok');
}
else {
drush_make_error('FILE_ERROR', dt("Unable to write .make file %file.", array('%file' => $this->to)));
}
}
}
function render($info, $parents = array()) {
$output = '';
foreach ($info as $key => $value) {
if (is_numeric($key)) {
$key = '';
}
if (is_array($value)) {
$p = $parents;
$p[] = $key;
$output .= $this->render($value, $p);
}
else {
// For simplicity
$first = TRUE;
$p = $parents;
$p[] = $key;
foreach ($p as $parent) {
if ($first) {
$key_definition = $parent;
$first = FALSE;
}
else {
$key_definition .= '[' . $parent . ']';
}
}
$output .= "$key_definition = $value\n";
}
if (count($parents) < 2) {
$output .= "\n";
}
}
return $output;
}
}
|