예제 #1
0
    exit(1);
}
array_shift($_SERVER['argv']);
// shift the script name
$restrictedDirectory = '';
$options = array('verbose' => false);
if (substr($_SERVER['argv'][0], 0, 1) == '-') {
    $sw = substr(array_shift($_SERVER['argv']), 1);
    $options['verbose'] = strpos($sw, 'v') !== false;
    if (strpos($sw, 'd') !== false) {
        $restrictedDirectory = array_shift($_SERVER['argv']);
    }
}
list($sourcefile, $distfile) = $_SERVER['argv'];
if ($restrictedDirectory != '') {
    $s = realpath($sourcefile);
    if (strpos($s, $restrictedDirectory) !== 0) {
        exit(1);
    }
}
try {
    $proc = new jPreProcessor();
    $proc->setVars($_SERVER);
    $dist = $proc->parseFile($sourcefile);
} catch (Exception $e) {
    echo $e;
    exit(1);
}
jBuildUtils::createDir(dirname($distfile));
file_put_contents($distfile, $dist);
exit(0);
예제 #2
0
 /**
  * read the given manifest file and copy files
  * @param string $ficlist manifest file name
  * @param string $sourcepath main directory where it reads files
  * @param string $distpath main directory were files are copied
  */
 public static function process($ficlist, $sourcepath, $distpath, $preprocvars, $preprocmanifest = false)
 {
     $stripcomment = self::$stripComment;
     $verbose = self::$verbose;
     $preproc = new jPreProcessor();
     $sourcedir = jBuildUtils::normalizeDir($sourcepath);
     $distdir = jBuildUtils::normalizeDir($distpath);
     if ($preprocmanifest) {
         $preproc->setVars($preprocvars);
         try {
             $content = $preproc->parseFile($ficlist);
         } catch (Exception $e) {
             throw new Exception("cannot preprocess the manifest file " . $ficlist . " (" . $e . ")\n");
         }
         $script = explode("\n", $content);
     } else {
         $script = file($ficlist);
     }
     $currentdestdir = '';
     $currentsrcdir = '';
     foreach ($script as $nbline => $line) {
         $nbline++;
         if (preg_match(';^(cd|sd|dd|\\*|!|\\*!|c|\\*c|cch)?\\s+([a-zA-Z0-9\\/.\\-_]+)\\s*(?:\\(([a-zA-Z0-9\\%\\/.\\-_]*)\\))?\\s*$;m', $line, $m)) {
             if ($m[1] == 'dd') {
                 $currentdestdir = jBuildUtils::normalizeDir($m[2]);
                 jBuildUtils::createDir($distdir . $currentdestdir, self::$usedVcs);
             } elseif ($m[1] == 'sd') {
                 $currentsrcdir = jBuildUtils::normalizeDir($m[2]);
             } elseif ($m[1] == 'cd') {
                 $currentsrcdir = jBuildUtils::normalizeDir($m[2]);
                 $currentdestdir = jBuildUtils::normalizeDir($m[2]);
                 jBuildUtils::createDir($distdir . $currentdestdir, self::$usedVcs);
             } else {
                 $doPreprocessing = strpos($m[1], '*') !== false;
                 $doCompression = strpos($m[1], 'c') !== false && $m[1] != 'cch' || $stripcomment && strpos($m[1], '!') === false;
                 if ($m[2] == '') {
                     throw new Exception("{$ficlist} : file required on line {$nbline} \n");
                 }
                 if (!isset($m[3]) || $m[3] == '') {
                     $m[3] = $m[2];
                 }
                 $destfile = $distdir . $currentdestdir . $m[3];
                 $sourcefile = $sourcedir . $currentsrcdir . $m[2];
                 $addIntoRepo = !file_exists($destfile);
                 if ($doPreprocessing) {
                     if ($verbose) {
                         echo "process  {$sourcefile} \tto\t{$destfile} \n";
                     }
                     $preproc->setVars($preprocvars);
                     try {
                         $contents = $preproc->parseFile($sourcefile);
                     } catch (Exception $e) {
                         throw new Exception("{$ficlist} : line {$nbline}, cannot process file " . $m[2] . " (" . $e . ")\n");
                     }
                     if ($doCompression) {
                         if (preg_match("/\\.php\$/", $destfile)) {
                             if ($verbose) {
                                 echo "     strip php comment ";
                             }
                             $contents = self::stripPhpComments($contents);
                             if ($verbose) {
                                 echo "OK\n";
                             }
                         } else {
                             if (preg_match("/\\.js\$/", $destfile)) {
                                 if ($verbose) {
                                     echo "compress javascript file \n";
                                 }
                                 $packer = new JavaScriptPacker($contents, 0, true, false);
                                 $contents = $packer->pack();
                             }
                         }
                     }
                     file_put_contents($destfile, $contents);
                 } elseif ($doCompression && preg_match("/\\.php\$/", $destfile)) {
                     if ($verbose) {
                         echo "strip comment in  {$sourcefile}\tto\t" . $destfile . "\n";
                     }
                     $src = file_get_contents($sourcefile);
                     file_put_contents($destfile, self::stripPhpComments($src));
                 } elseif ($doCompression && preg_match("/\\.js\$/", $destfile)) {
                     if ($verbose) {
                         echo "compress javascript file " . $destfile . "\n";
                     }
                     $script = file_get_contents($sourcefile);
                     $packer = new JavaScriptPacker($script, 0, true, false);
                     file_put_contents($destfile, $packer->pack());
                 } elseif ($m[1] == 'cch') {
                     if (strpos($m[3], '%charset%') === false) {
                         throw new Exception("{$ficlist} : line {$nbline}, dest file " . $m[3] . " doesn't contains %charset% pattern.\n");
                     }
                     if ($verbose) {
                         echo "convert charset\tsources\t" . $sourcedir . $currentsrcdir . $m[2] . "   " . $m[3] . "\n";
                     }
                     $encoding = preg_split('/[\\s,]+/', self::$targetPropertiesFilesCharset);
                     $content = file_get_contents($sourcefile);
                     if (self::$sourcePropertiesFilesDefaultCharset != '') {
                         $encode = self::$sourcePropertiesFilesDefaultCharset;
                     } else {
                         $encode = mb_detect_encoding($content);
                     }
                     foreach ($encoding as $val) {
                         $encodefile = str_replace('%charset%', $val, $destfile);
                         if ($verbose) {
                             echo "\tencode into " . $encodefile . "\n";
                         }
                         $addIntoRepo = !file_exists($encodefile);
                         $file = fopen($encodefile, "w");
                         fwrite($file, mb_convert_encoding($content, $val, $encode));
                         fclose($file);
                         if ($addIntoRepo) {
                             $d = getcwd();
                             chdir(dirname($encodefile));
                             if (self::$usedVcs == 'svn') {
                                 exec("svn add {$encodefile}");
                             } else {
                                 if (self::$usedVcs == 'hg') {
                                     exec("hg add {$encodefile}");
                                 }
                             }
                             chdir($d);
                         }
                     }
                     $addIntoRepo = false;
                 } else {
                     if ($verbose) {
                         echo "copy  " . $sourcedir . $currentsrcdir . $m[2] . "\tto\t" . $destfile . "\n";
                     }
                     if (!copy($sourcefile, $destfile)) {
                         throw new Exception("{$ficlist} : cannot copy file " . $m[2] . ", line {$nbline} \n");
                     }
                 }
                 if ($addIntoRepo) {
                     $d = getcwd();
                     chdir(dirname($destfile));
                     if (self::$usedVcs == 'svn') {
                         exec("svn add {$destfile}");
                     } else {
                         if (self::$usedVcs == 'hg') {
                             exec("hg add {$destfile}");
                         }
                     }
                     chdir($d);
                 }
             }
         } elseif (preg_match("!^\\s*(\\#.*)?\$!", $line)) {
             // we ignore comments
         } else {
             throw new Exception("{$ficlist} : syntax error on line {$nbline} \n");
         }
     }
 }
예제 #3
0
$IS_NIGHTLY = strpos($LIB_VERSION, 'SERIAL') !== false;
if ($IS_NIGHTLY) {
    $PACKAGE_NAME = 'jelix-' . str_replace('SERIAL', '', $LIB_VERSION);
    if (substr($PACKAGE_NAME, -1, 1) == '.') {
        $PACKAGE_NAME = substr($PACKAGE_NAME, 0, -1);
    }
    $PACKAGE_NAME .= '-pdf-fonts';
    $LIB_VERSION = str_replace('SERIAL', $SOURCE_REVISION, $LIB_VERSION);
} else {
    $PACKAGE_NAME = 'jelix-' . $LIB_VERSION . '-pdf-fonts';
}
if ($PACKAGE_ZIP) {
    $BUILD_TARGET_PATH = jBuildUtils::normalizeDir($MAIN_TARGET_PATH) . $PACKAGE_NAME . '/';
} else {
    $BUILD_TARGET_PATH = jBuildUtils::normalizeDir($MAIN_TARGET_PATH);
}
//----------------- build the package
//... directory creation
jBuildUtils::createDir($BUILD_TARGET_PATH);
//... copying files
jManifest::process('build/manifests/fonts.mn', '.', $BUILD_TARGET_PATH, ENV::getAll());
//... packages
//if($PACKAGE_TAR_GZ){
//    exec('tar czf '.$MAIN_TARGET_PATH.'/'.$PACKAGE_NAME.'.tar.gz -C '.$MAIN_TARGET_PATH.' '.$PACKAGE_NAME);
//}
if ($PACKAGE_ZIP) {
    chdir($MAIN_TARGET_PATH);
    exec('zip -r ' . $PACKAGE_NAME . '.zip ' . $PACKAGE_NAME);
    chdir(dirname(__FILE__));
}
exit(0);
예제 #4
0
if ($VERSION == 'SERIAL') {
    $VERSION = 'SERIAL-' . $SOURCE_REVISION;
    $IS_NIGHTLY = true;
} else {
    $IS_NIGHTLY = false;
}
if ($PACKAGE_TAR_GZ || $PACKAGE_ZIP) {
    $BUILD_SUBPATH = 'additionnal-modules/';
    if ($IS_NIGHTLY) {
        $PACKAGE_NAME = 'additionnal-modules-nightly';
    } else {
        $PACKAGE_NAME = 'additionnal-modules-HG-' . $SOURCE_REVISION;
    }
} else {
    $BUILD_SUBPATH = 'lib/jelix-modules/';
}
//----------------- Génération des sources
//... creation des repertoires
jBuildUtils::createDir($MAIN_TARGET_PATH . $BUILD_SUBPATH);
//... execution des manifests
jManifest::process('build/manifests/jelix-modules.mn', 'lib/jelix-modules/', $MAIN_TARGET_PATH . $BUILD_SUBPATH, ENV::getAll());
//... packages
if ($PACKAGE_TAR_GZ) {
    exec('tar czf ' . $MAIN_TARGET_PATH . $PACKAGE_NAME . '.tar.gz -C ' . $MAIN_TARGET_PATH . ' ' . $BUILD_SUBPATH);
}
if ($PACKAGE_ZIP) {
    chdir($MAIN_TARGET_PATH);
    exec('zip -r ' . $PACKAGE_NAME . '.zip ' . $BUILD_SUBPATH);
    chdir(dirname(__FILE__));
}
exit(0);
예제 #5
0
파일: buildapp.php 프로젝트: hadrienl/jelix
    $PACKAGE_NAME = $APPNAME . '-' . $VERSION;
}
Env::setFromFile('LIB_VERSION', 'lib/jelix/VERSION', true);
$IS_LIB_NIGHTLY = strpos($LIB_VERSION, 'SERIAL') !== false;
if ($IS_LIB_NIGHTLY) {
    $LIB_VERSION = str_replace('SERIAL', $SOURCE_REVISION, $LIB_VERSION);
}
if (preg_match('/\\.([a-z0-9\\-]+)$/i', $LIB_VERSION, $m)) {
    $LIB_VERSION_MAX = substr($LIB_VERSION, 0, -strlen($m[1])) . "*";
} else {
    $LIB_VERSION_MAX = $LIB_VERSION;
}
if ($PACKAGE_TAR_GZ || $PACKAGE_ZIP) {
    //$MAIN_TARGET_PATH = jBuildUtils::normalizeDir($MAIN_TARGET_PATH).$PACKAGE_NAME;
}
//----------------- Génération des sources
//... creation des repertoires
jBuildUtils::createDir($MAIN_TARGET_PATH);
//... execution des manifests
jManifest::process('build/manifests/' . $APPNAME . '.mn', '.', $MAIN_TARGET_PATH, ENV::getAll());
file_put_contents($MAIN_TARGET_PATH . $APPDIR . '/VERSION', $VERSION);
//... packages
if ($PACKAGE_TAR_GZ) {
    exec('tar czf ' . $MAIN_TARGET_PATH . $PACKAGE_NAME . '.tar.gz -C ' . $MAIN_TARGET_PATH . ' ' . $APPNAME);
}
if ($PACKAGE_ZIP) {
    chdir($MAIN_TARGET_PATH);
    exec('zip -r ' . $PACKAGE_NAME . '.zip ' . $APPNAME);
    chdir(dirname(__FILE__));
}
exit(0);
예제 #6
0
jManifest::process('build/manifests/jelix-admin-modules.mn', '.', $BUILD_TARGET_PATH, ENV::getAll());
if ($INCLUDE_ALL_FONTS) {
    jManifest::process('build/manifests/fonts.mn', '.', $BUILD_TARGET_PATH, ENV::getAll());
}
if ($ENABLE_PHP_JELIX && ($PACKAGE_TAR_GZ || $PACKAGE_ZIP)) {
    jManifest::process('build/manifests/jelix-ext-php.mn', '.', $BUILD_TARGET_PATH, ENV::getAll());
}
// jtpl standalone for wizard
Env::setFromFile('JTPL_VERSION', 'lib/jelix/tpl/VERSION', true);
if ($IS_NIGHTLY) {
    $JTPL_VERSION = str_replace('SERIAL', $SOURCE_REVISION, $JTPL_VERSION);
}
$var = ENV::getAll();
$var['JTPL_STANDALONE'] = true;
$jtplpath = $BUILD_TARGET_PATH . 'lib/installwizard/jtpl/';
jBuildUtils::createDir($jtplpath);
jManifest::process('build/manifests/jtpl-standalone.mn', '.', $jtplpath, $var);
file_put_contents($jtplpath . '/VERSION', $JTPL_VERSION);
// the standalone checker
$var = ENV::getAll();
$var['STANDALONE_CHECKER'] = true;
jManifest::process('build/manifests/jelix-checker.mn', '.', $BUILD_TARGET_PATH, $var);
file_put_contents($BUILD_TARGET_PATH . 'lib/jelix/VERSION', $LIB_VERSION);
// creation du fichier d'infos sur le build
$view = array('EDITION_NAME', 'PHP_VERSION_TARGET', 'SOURCE_REVISION', 'ENABLE_PHP_XMLRPC', 'ENABLE_PHP_JELIX', 'WITH_BYTECODE_CACHE', 'ENABLE_DEVELOPER', 'ENABLE_OPTIMIZED_SOURCE', 'STRIP_COMMENT');
$infos = '; --- build date:  ' . date('Y-m-d H:i') . "\n; --- lib version: {$LIB_VERSION}\n" . ENV::getIniContent($view);
file_put_contents($BUILD_TARGET_PATH . 'lib/jelix/BUILD', $infos);
//... packages
if ($PACKAGE_TAR_GZ || $PACKAGE_ZIP) {
    file_put_contents($MAIN_TARGET_PATH . '/PACKAGE_NAME', $PACKAGE_NAME);
}