Step #2: Override Jar.initZipOutputStream to inject manifest sections.  This is done
by treating them as if they were 'inline' entries, from a <jar> task perspective.
168318
protected void initZipOutputStream(ZipOutputStream zOut) throws IOException, BuildException 
    {
        if (manifestFiles.size() != 0)
        {
            //
            // Create a default (empty) manifest
            //
            Manifest mergeManifest = Manifest.getDefaultManifest();

            //
            // Iterate through each found manifest file, merging its contents into the
            // merge manifest
            //
            for (File manifestFile : manifestFiles)
            {
                FileInputStream fis = null;
                try
                {
                    fis = new FileInputStream(manifestFile);
                    Manifest resourceManifest = new Manifest(new InputStreamReader(fis));
                    mergeManifest.merge(resourceManifest);
                }
                catch (IOException ioe)
                {
                    throw new BuildException("Unable to read manifest file:" + manifestFile, ioe);
                }
                catch (ManifestException me)
                {
                    throw new BuildException("Unable to process manifest file: "+ manifestFile, me);
                }
                finally 
                {
                    if (fis != null) fis.close();
                }
            }

            //
            // Set the merge manifest as the 'configured' manifest.   This will treat its
            // contents as if they had been included inline with the <jar> task, with
            // similar precedence rules.
            //
            try
            {
                addConfiguredManifest(mergeManifest);
            }
            catch (ManifestException me)
            {
                throw new BuildException("Unable to add new manifest entries:" + me);
            }
        }

        super.initZipOutputStream(zOut);
    }
993496
public void pack( Map<String, URI> agg, OutputStream out )
        throws IOException
    {
        // calculate the final map

        JarOutputStream jout = new JarOutputStream( out );
        try
        {
            // first set manifest if available:
            URI manifest = agg.get( "META-INF/MANIFEST.MF" );
            if( manifest != null )
            {
                JarEntry entry = new JarEntry( "META-INF/MANIFEST.MF" );
                jout.putNextEntry( entry );
                StreamUtils.copyStream( manifest.toURL().openStream(), jout, false );
                jout.closeEntry();
            }
            for( String name : agg.keySet() )
            {
                if( name.equals( "META-INF/MANIFEST.MF" ) )
                {
                    continue;
                }

                JarEntry entry = new JarEntry( name );
                jout.putNextEntry( entry );
                StreamUtils.copyStream( agg.get( name ).toURL().openStream(), jout, false );
                jout.closeEntry();
            }
        } finally
        {
            jout.close();
        }

    }
566478
void performJavaNameSpaceBinding() throws InjectionException
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "performJavaNameSpaceBinding: " + this);

        for (InjectionBinding<A> injectionBinding : ivAllAnnotationsCollection.values())
        {
            // F743-31682 - Only bind to java:global/:app/:module if needed.
            if (injectionBinding.getInjectionScope() == InjectionScope.COMP ||
                ivContext.ivBindNonCompInjectionBindings)
            {
                if (injectionBinding.getBindingObject() == null)
                {
                    if (isTraceOn && tc.isDebugEnabled())
                        Tr.debug(tc, "skipping empty " + injectionBinding);
                }
                else
                {
                    injectionBinding.bindInjectedObject();
                }
            }
            else
            {
                if (isTraceOn && tc.isEntryEnabled())
                    Tr.debug(tc, "skipping non-java:comp " + injectionBinding.toSimpleString());
            }
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "performJavaNameSpaceBinding");
    }
1337492
private OutputStream initializeSource()
    {
    try
      {
      PipedOutputStream pipeOut = new PipedOutputStream();
      PipedInputStream pipeIn = new PipedInputStream( pipeOut);

      filterInput_ = pipeIn;
      return new FilterSourceStream( pipeOut);
      }
    catch( Exception e)
      {
      throw new RuntimeException( "Can't initialize source stream", e);
      }
    }
581823
def inject_mode(arg_namespace):
    """"""

    try:
        injector.inject_into_files(arg_namespace.scheme, arg_namespace.file)
    except (IndexError, FileNotFoundError,
            PermissionError, IsADirectoryError) as exception:
        if isinstance(exception, IndexError):
            print('"{}" has no valid injection marker lines.'.format(
                exception.args[0]))
        if isinstance(exception, FileNotFoundError):
            print('Lacking resource "{}" to complete operation.'.format(
                exception.filename))
        if isinstance(exception, PermissionError):
            print('No write permission for current working directory.')
        if isinstance(exception, IsADirectoryError):
            print('"{}" is a directory. Provide a *.yaml scheme file instead.'
                  .format(exception.filename))
1012627
public OperationBuilder addInputStream(final InputStream in) {
        Assert.checkNotNullParam("in", in);
        if (inputStreams == null) {
            inputStreams = new ArrayList<InputStream>();
        }
        inputStreams.add(in);
        return this;
    }
1007740
@Override
  public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
      return;
    }

    PackageDownloader downloader = new PackageDownloader(getPackageManagerProperties(), getLoggerWrapper());

    File outputFileObject = downloader.downloadFile(getPackageFile(), this.outputFile);
    if (this.unpack) {
      unpackFile(outputFileObject);
    }
  }
1156471
private void processComponentJar(URL jarFileURL, WorkList workList, List<String> implicitClasspath) {
        LOG.debug("Processing {}", jarFileURL);

        if (!jarFileURL.toString().endsWith(".zip") && !jarFileURL.toString().endsWith(".jar")) {
            return;
        }

        try {
            URL manifestURL = new URL("jar:" + jarFileURL.toString() + "!/META-INF/MANIFEST.MF");

            InputStream in = null;
            try {
                in = manifestURL.openStream();
                Manifest manifest = new Manifest(in);

                Attributes mainAttrs = manifest.getMainAttributes();
                String classPath = mainAttrs.getValue("Class-Path");
                if (classPath != null) {
                    String[] fileList = classPath.split("\\s+");

                    for (String jarFile : fileList) {
                        URL referencedURL = workList.createRelativeURL(jarFileURL, jarFile);
                        if (workList.add(new WorkListItem(referencedURL))) {
                            implicitClasspath.add(referencedURL.toString());
                            LOG.debug("Implicit jar: {}", referencedURL);
                        }
                    }
                }
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        } catch (IOException ignore) {
            // Ignore
        }
    }
1067276
function injectAddons(manifestUrls) {
  var addons = {};
  for (var n = 0; n < manifestUrls.length; n++) {
    // Fetch Manifest JSON.
    var url = manifestUrls[n];
    var json = getUrl(url);
    if (!json) {
      log('Unable to fetch manifest JSON: ' + url);
      continue;
    }
    json = JSON.parse(json);
    addons[url] = json;

    // If it has a tracing node, inject scripts.
    var tracingInfo = json['tracing'];
    if (tracingInfo && tracingInfo['scripts']) {
      var tracingScripts = tracingInfo['scripts'];
      for (var m = 0; m < tracingScripts.length; m++) {
        var scriptUrl = resolveUrl(url, tracingScripts[m]);
        if (!injectScriptFile(scriptUrl)) {
          log('Error loading addon ' + url + ':');
          log('Tracing script file not found: ' + scriptUrl);
        }
      }
    }
  }
  return addons;
}
583994
private static void injectImplicitly(Injector.Configuration config) {
		
		ImplicitInjectors.APPLICATION.inject(config);		
		ImplicitInjectors.RESOURCES.inject(config);
		ImplicitInjectors.SYSTEM_SERVICES.inject(config);
		ImplicitInjectors.ICKLE_SERVICES.inject(config);
		ImplicitInjectors.POJOS.inject(config);
	}
129819
@Override
    TarInputStream getInputStreamForRawStream(final InputStream in) throws IOException {
        assert in != null : "Specified inputstream was null";
        return new TarInputStream(in);
    }
677031
public void addExternalJars(File file) throws IllegalAccessException, InvocationTargetException, MalformedURLException {
    assert file.exists() : "Unable to find external file: " + file.getAbsolutePath();
    if( file.isDirectory() ) {
      for( File f : file.listFiles() ) addExternalJars(f);
    } else if( file.getName().endsWith(".jar") ) {
      Log.POST(22, "before (in addExternalJars) invoke _addUrl " + file.toURI().toURL());
      _addUrl.invoke(_systemLoader, file.toURI().toURL());
      Log.POST(22, "after (in addExternalJars) invoke _addUrl " + file.toURI().toURL());
    }
  }
42957
function AndroidManifest(output, path) {

    this._output = output;
    this._path = path;

    var doc = this.read();
    this._package = doc.documentElement.getAttribute("package");
    this._versionCode = doc.documentElement.getAttribute("android:versionCode");
    this._versionName = doc.documentElement.getAttribute("android:versionName");

    this._applicationIcon = null;
    var appNode = this.findApplicationNode(doc);
    if (appNode) {
        this._applicationIcon = appNode.getAttribute("android:icon");
    }

    this._applicationLabel = null;
    appNode = this.findApplicationNode(doc);
    if (appNode) {
        this._applicationLabel = appNode.getAttribute("android:label");
    }

    var activityNode = this.findChildNode(appNode, "activity");
    if (activityNode) {
        this._screenOrientation = activityNode.getAttribute("android:screenOrientation");
    }

    // TODO read other values from manifest and initialize members
}
634013
@SuppressWarnings("rawtypes")
    public static void inject(final IPluginInterface plugin, final IJNRPEExecutionContext context) {

        try {
            Class clazz = plugin.getClass();
            inject(clazz, plugin, context);
            while (IPluginInterface.class.isAssignableFrom(clazz.getSuperclass())) {
                clazz = clazz.getSuperclass();
                inject(clazz, plugin, context);
            }
        } catch (Exception e) {
            throw new Error(e.getMessage(), e);
        }

    }
1006871
@Nonnull
  public final UnifiedResponse setContent (@Nonnull final IHasInputStream aISP)
  {
    ValueEnforcer.notNull (aISP, "InputStreamProvider");
    if (hasContent ())
      logInfo ("Overwriting content with content provider!");
    m_aContentArray = null;
    m_nContentArrayOfs = -1;
    m_nContentArrayLength = -1;
    m_aContentISP = aISP;
    return this;
  }
436142
private static void completeManifest(Manifest manifest, URL url) {

    String path = url.getPath();
    int start = 0;
    int end = path.length();
    if (path.endsWith(JAR_SUFFIX)) {
      // 4 for ".jar"
      end = end - JAR_SUFFIX.length() + 4;
      start = path.lastIndexOf('/', end) + 1;
    }
    String source = path.substring(start, end);
    manifest.getMainAttributes().put(MANIFEST_SOURCE, source);
  }
1052544
@Override
    protected void initInputSource(WstxInputSource newInput, boolean isExt, String entityId)
        throws XMLStreamException
    {
        if (mFlattenWriter != null) {
            // Anything to flush from previous buffer contents?
            mFlattenWriter.flush(mInputBuffer, mInputPtr);
            mFlattenWriter.disableOutput();
            try {
                /* Then let's let base class do the 'real' input source setup;
                 * this includes skipping of optional XML declaration that we
                 * do NOT want to output
                 */
                super.initInputSource(newInput, isExt, entityId);
            } finally {
                // This will effectively skip declaration
                mFlattenWriter.enableOutput(mInputPtr);
            }
        } else {
            super.initInputSource(newInput, isExt, entityId);
        }
    }