コード例 #1
0
	def __init__(self, targetName, **kwargs): # unusually, we pass in the targetname here, since there are usually so many different "javac"s
		ProcessOutputHandler.__init__(self, 'javac', **kwargs)
		self._current = None
		self._chunks = []
		self._logbasename = None
		self._contents = ''
		self._targetName = targetName
コード例 #2
0
 def handleEnd(self, returnCode=None):
     # linker failures often have no errors but a really useful message in the first warning, so include that in the error message
     if returnCode and self.getWarnings() and not self.getErrors():
         raise BuildException(
             '%s failed with return code %s (first warning: %s)' %
             (self._name, returnCode, self.getWarnings()[0]))
     ProcessOutputHandler.handleEnd(self, returnCode=returnCode)
コード例 #3
0
ファイル: java.py プロジェクト: ramanawithu/xpybuild
 def run(self, context):
     options = self.options
     classpath = os.pathsep.join(self.classpath.resolve(context))
     javadoc(self.path,
             self.sources.resolve(context),
             classpath,
             options,
             outputHandler=ProcessOutputHandler.create(
                 'javadoc', treatStdErrAsErrors=False, options=options))
コード例 #4
0
    def run(self, context):
        self.keystore = context.expandPropertyValues(self.keystore)
        options = self.options

        mkdir(self.path)
        for src, dest in self.jars.resolveWithDestinations(context):
            if '..' in dest:
                # to avoid people abusing this to copy files outside the dest directory!
                raise Exception(
                    'This target does not permit destination paths to contain ".." relative path expressions'
                )

            try:
                with open(src, 'rb') as s:
                    with openForWrite(os.path.join(self.path, dest),
                                      'wb') as d:
                        d.write(s.read())

                shutil.copystat(src, os.path.join(self.path, dest))

                # When we re-jar with the user specified manifest entries, jar will complain
                # about duplicate attributes IF the original MANIFEST.MF already has those entries.
                # This is happening for latest version of SL where Application-Name, Permission etc
                # were already there.
                #
                # The block of code below will first extract the original MANIFEST.MF from the source
                # jar file, read all manifest entry to a list.  When constructing the new manifest entries,
                # make sure the old MANIFEST.MF doesn't have that entry before putting the new manifest entry
                # to the list.  This will avoid the duplicate attribute error.
                #

                if self.manifestDefaults:

                    lines = []

                    # read each line of MANIFEST.MF of the original jar and put them in lines
                    with zipfile.ZipFile(src, 'r') as zf:
                        lst = zf.infolist()
                        for zi in lst:
                            fn = zi.filename
                            if fn.lower().endswith('manifest.mf'):
                                try:
                                    manifest_txt = zf.read(zi.filename)
                                except Exception, e:
                                    raise BuildException(
                                        'Failed reading the manifest file %s with exception:%s'
                                        % (fn, e))

                                # if we have all manifest text, parse and save each line
                                if manifest_txt:
                                    # CR LF | LF | CR  can be there as line feed and hence the code below
                                    lines = manifest_txt.replace(
                                        '\r\n', '\n').replace('\r',
                                                              '\n').split('\n')

                                # done
                                break

                    original_entries = collections.OrderedDict(
                    )  # to ensure we don't overwrite/duplicate these
                    # populate the manifest_entries with original values from original manifest
                    for l in lines:
                        if ':' in l and not l.startswith(
                                ' '
                        ):  # ignore continuation lines etc because keys are all we care about
                            key, value = l.split(':', 1)
                            original_entries[key] = value.strip()

                    # build up a list of the new manifest entries (will be merged into any existing manifest by jar)
                    manifest_entries = collections.OrderedDict()
                    for i in self.manifestDefaults:
                        # if entry isn't there yet, add to the list
                        if i not in original_entries:
                            manifest_entries[i] = context.expandPropertyValues(
                                self.manifestDefaults[i])

                    # create the manifest file
                    # we want to add the manifest entries explicitly specified here but
                    # NOT the 'default' manifest entries we usually add, since these
                    # are likely to have been set already, and we do not want duplicates
                    mkdir(self.workDir)
                    manifest = os.path.join(self.workDir,
                                            "MANIFEST.MF")  # manifest file

                    options = dict(options)
                    options['jar.manifest.defaults'] = {}
                    create_manifest(manifest, manifest_entries, options)

                    # update the EXISTING jar file with the new manifest entries, which will be merged into
                    # existing manifest by the jar tool
                    jar(os.path.join(self.path, dest),
                        manifest,
                        None,
                        options,
                        update=True)

                signjar(os.path.join(self.path, dest),
                        self.keystore,
                        options,
                        alias=self.alias,
                        storepass=self.storepass,
                        outputHandler=ProcessOutputHandler(
                            'signjars',
                            treatStdErrAsErrors=False,
                            options=options))
            except BuildException, e:
                raise BuildException('Error processing %s: %s' %
                                     (os.path.basename(dest), e))
コード例 #5
0
    def run(self, context):
        options = self.options

        # make sure temp dir exists
        mkdir(self.workDir)

        classes = os.path.join(self.workDir,
                               "classes")  # output dir for classes

        # create the classpath, sorting within PathSet (for determinism), but retaining original order of
        # PathSet elements in the list
        classpath = os.pathsep.join(self.classpath.resolve(context))

        # compile everything
        mkdir(
            classes
        )  # (need this for assembling other files to package later on, even if we don't do any javac)
        if self.compile:
            mkdir(self.getOption('javac.logs'))
            javac(classes,
                  self.compile.resolve(context),
                  classpath,
                  options=options,
                  logbasename=options.get('javac.logs') + '/' +
                  targetNameToUniqueId(self.name),
                  targetname=self.name)

        manifest = os.path.join(self.workDir, "MANIFEST.MF")  # manifest file

        if isinstance(self.manifest, basestring):
            manifest = context.getFullPath(self.manifest, self.baseDir)
        elif self.manifest == None:
            manifest = None
        else:  # generate one
            # rewrite property values in the manifest
            manifest_entries = {}
            for i in self.manifest:
                manifest_entries[i] = context.expandPropertyValues(
                    self.manifest[i])

            # determine classpath for manifest
            classpath_entries = []

            if "Class-path" not in manifest_entries:  # assuming it wasn't hardcoded, set it here
                for src, dest in self.classpath.resolveWithDestinations(
                        context):
                    # we definitely do want to support use of ".." in destinations here, it can be very useful
                    classpath_entries.append(dest)
                assert isinstance(
                    options['jar.manifest.classpathAppend'], list), options[
                        'jar.manifest.classpathAppend']  # must not be a string
                classpath_entries.extend(
                    options['jar.manifest.classpathAppend'] or [])

                # need to always use / not \ for these to be valid
                classpath_entries = [
                    p.replace(os.path.sep, '/').replace('\\', '/')
                    for p in classpath_entries if p
                ]

                if classpath_entries:
                    manifest_entries["Class-path"] = " ".join(
                        classpath_entries)  # include the classpath from here
            if not manifest_entries.get(
                    'Class-path'
            ):  # suppress this element entirely if not needed, otherwise there would be no way to have an empty classpath
                manifest_entries.pop('Class-path', '')

            # create the manifest file
            create_manifest(manifest, manifest_entries, options=options)

        # copy in the additional things to include
        for (src, dest) in self.package.resolveWithDestinations(context):
            if '..' in dest:
                raise Exception(
                    'This target does not permit packaged destination paths to contain ".." relative path expressions'
                )
            mkdir(os.path.dirname(os.path.join(classes, dest)))
            destpath = normLongPath(classes + '/' + dest)
            srcpath = normLongPath(src)

            if os.path.isdir(srcpath):
                mkdir(destpath)
            else:
                with open(srcpath, 'rb') as s:
                    with openForWrite(destpath, 'wb') as d:
                        d.write(s.read())

        # create the jar
        jar(self.path,
            manifest,
            classes,
            options=options,
            preserveManifestFormatting=self.preserveManifestFormatting,
            outputHandler=ProcessOutputHandler('jar',
                                               treatStdErrAsErrors=False,
                                               options=options))
コード例 #6
0
ファイル: compilers.py プロジェクト: CaribouJohn/xpybuild
			def __init__(self, name, **kwargs):
				ProcessOutputHandler.__init__(self, name, **kwargs)
コード例 #7
0
ファイル: compilers.py プロジェクト: CaribouJohn/xpybuild
	def handleEnd(self, returnCode=None):
		# linker failures often have no errors but a really useful message in the first warning, so include that in the error message
		if returnCode and self.getWarnings() and not self.getErrors():
			raise BuildException('%s failed with return code %s (first warning: %s)'%(self._name, returnCode, self.getWarnings()[0]))
		ProcessOutputHandler.handleEnd(self, returnCode=returnCode)
コード例 #8
0
ファイル: compilers.py プロジェクト: CaribouJohn/xpybuild
			def __init__(self, name, **kwargs):
				ProcessOutputHandler.__init__(self, name, treatStdErrAsErrors=False, **kwargs)
コード例 #9
0
 def __init__(self, name, **kwargs):
     ProcessOutputHandler.__init__(self, name, **kwargs)
     self.fatalerrors = []
コード例 #10
0
 def __init__(self, name, **kwargs):
     ProcessOutputHandler.__init__(self,
                                   name,
                                   treatStdErrAsErrors=False,
                                   **kwargs)
コード例 #11
0
ファイル: process.py プロジェクト: CaribouJohn/xpybuild
	
	log.info('Executing %s process: %s', processName, ' '.join(['"%s"'%s if ' ' in s else s for s in args]))
	if cwd != os.getcwd():
		log.info('%s working directory: %s', processName, cwd)
	if env: 
		log.info('%s environment overrides: %s', processName, ', '.join(sorted(['%s=%s'%(k, env[k]) for k in env])))
	try:
		if cwd:
			process = subprocess.Popen(args, env=environs, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd)
		else:
			process = subprocess.Popen(args, env=environs, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
	except Exception, e:
		raise EnvironmentError('Cannot start process "%s": %s'%(args[0], e))

	if not outputHandler: # use short processName not longer displayName for per-line prefixes, the extra context isn't necessary anyway
		outputHandler = ProcessOutputHandler(processName) # can't pass options in as we don't have it here

	# give the full arguments as the process display name (unless really long) since it's impossible to identify the target otherwise
	if not displayName:
		displayName = str(args)
		if len(displayName)>200: displayName=displayName[:200]+'...]'
	(out, err, timedout) = _wait_with_timeout(process, displayName, timeout, True)
	
	outputEncoding = outputEncoding or getStdoutEncoding()
	log.debug('%s outputEncoding assumed to be: %s', processName, outputEncoding)
		
	# probably best to be tolerant about unexpected chars, given how hard it is to predict what subprocesses will write in 
	out = unicode(out, outputEncoding, errors='replace')
	err = unicode(err, outputEncoding, errors='replace')
	
	hasfailed = True
コード例 #12
0
ファイル: process.py プロジェクト: ddfourni/xpybuild
        if cwd:
            process = subprocess.Popen(args,
                                       env=environs,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       cwd=cwd)
        else:
            process = subprocess.Popen(args,
                                       env=environs,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)
    except Exception, e:
        raise EnvironmentError('Cannot start process "%s": %s' % (args[0], e))

    if not outputHandler:  # use short processName not longer displayName for per-line prefixes, the extra context isn't necessary anyway
        outputHandler = ProcessOutputHandler(
            processName)  # can't pass options in as we don't have it here

    # give the full arguments as the process display name (unless really long) since it's impossible to identify the target otherwise
    if not displayName:
        displayName = str(args)
        if len(displayName) > 200: displayName = displayName[:200] + '...]'
    (out, err, timedout) = _wait_with_timeout(process, displayName, timeout,
                                              True)

    outputEncoding = outputEncoding or getStdoutEncoding()
    log.debug('%s outputEncoding assumed to be: %s', processName,
              outputEncoding)

    # probably best to be tolerant about unexpected chars, given how hard it is to predict what subprocesses will write in
    out = unicode(out, outputEncoding, errors='replace')
    err = unicode(err, outputEncoding, errors='replace')
コード例 #13
0
 def __init__(self, name, **kwargs):
     ProcessOutputHandler.__init__(self, name, **kwargs)
コード例 #14
0
ファイル: process.py プロジェクト: ramanawithu/xpybuild
	
	log.info('Executing %s process: %s', processName, ' '.join(['"%s"'%s if ' ' in s else s for s in args]))
	if cwd != os.getcwd():
		log.info('%s working directory: %s', processName, cwd)
	if env: 
		log.info('%s environment overrides: %s', processName, ', '.join(sorted(['%s=%s'%(k, env[k]) for k in env])))
	try:
		if cwd:
			process = subprocess.Popen(args, env=environs, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd)
		else:
			process = subprocess.Popen(args, env=environs, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
	except Exception, e:
		raise EnvironmentError('Cannot start process "%s": %s'%(args[0], e))

	if not outputHandler: # use short processName not longer displayName for per-line prefixes, the extra context isn't necessary anyway
		outputHandler = ProcessOutputHandler.create(processName, options=options)

	# give the full arguments as the process display name (unless really long) since it's impossible to identify the target otherwise
	if not displayName:
		displayName = str(args)
		if len(displayName)>200: displayName=displayName[:200]+'...]'
	(out, err, timedout) = _wait_with_timeout(process, displayName, timeout, True)
	
	outputEncoding = outputEncoding or getStdoutEncoding()
	log.debug('%s outputEncoding assumed to be: %s', processName, outputEncoding)
		
	# probably best to be tolerant about unexpected chars, given how hard it is to predict what subprocesses will write in 
	out = unicode(out, outputEncoding, errors='replace')
	err = unicode(err, outputEncoding, errors='replace')
	
	hasfailed = True