Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* $Id: Packager.java 2238 2008-07-09 19:42:35Z jponge $
* IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
*
* http://izpack.org/
* http://izpack.codehaus.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.izforge.izpack.compiler;
import com.izforge.izpack.Pack;
import com.izforge.izpack.PackFile;
import com.izforge.izpack.util.FileUtil;
import net.n3.nanoxml.XMLElement;
import net.n3.nanoxml.XMLWriter;
import java.io.*;
import java.net.URL;
import java.util.*;
import java.util.jar.JarFile;
import java.util.jar.Pack200;
import java.util.jar.JarEntry;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
/**
* The packager class. The packager is used by the compiler to put files into an installer, and
* create the actual installer files.
*
* @author Julien Ponge
* @author Chadwick McHenry
*/
public class Packager extends PackagerBase
{
/**
* Executable zipped output stream. First to open, last to close.
* Attention! This is our own JarOutputStream, not the java standard!
*/
private com.izforge.izpack.util.JarOutputStream primaryJarStream;
/**
* The constructor.
*
* @throws CompilerException
*/
public Packager() throws CompilerException
{
this("default");
}
/**
* Extended constructor.
*
* @param compr_format Compression format to be used for packs
* compression format (if supported)
* @throws CompilerException
*/
public Packager(String compr_format) throws CompilerException
{
this(compr_format, -1);
}
/**
* Extended constructor.
*
* @param compr_format Compression format to be used for packs
* @param compr_level Compression level to be used with the chosen
* compression format (if supported)
* @throws CompilerException
*/
public Packager(String compr_format, int compr_level) throws CompilerException
{
initPackCompressor(compr_format, compr_level);
}
/* (non-Javadoc)
* @see com.izforge.izpack.compiler.IPackager#createInstaller(java.io.File)
*/
public void createInstaller(File primaryFile) throws Exception
{
// preliminary work
String baseName = primaryFile.getName();
if (baseName.endsWith(".jar"))
{
baseName = baseName.substring(0, baseName.length() - 4);
baseFile = new File(primaryFile.getParentFile(), baseName);
}
else
{
baseFile = primaryFile;
}
info.setInstallerBase(baseFile.getName());
packJarsSeparate = (info.getWebDirURL() != null);
// primary (possibly only) jar. -1 indicates primary
primaryJarStream = getJarOutputStream(baseFile.getName() + ".jar");
sendStart();
writeInstaller();
// Finish up. closeAlways is a hack for pack compressions other than
// default. Some of it (e.g. BZip2) closes the slave of it also.
// But this should not be because the jar stream should be open
// for the next pack. Therefore an own JarOutputStream will be used
// which close method will be blocked.
primaryJarStream.closeAlways();
sendStop();
}
/***********************************************************************************************
* Private methods used when writing out the installer to jar files.
**********************************************************************************************/
/**
* Write skeleton installer to primary jar. It is just an included jar, except that we copy the
* META-INF as well.
*/
protected void writeSkeletonInstaller() throws IOException
{
sendMsg("Copying the skeleton installer", PackagerListener.MSG_VERBOSE);
InputStream is = Packager.class.getResourceAsStream("/" + SKELETON_SUBPATH);
if (is == null)
{
File skeleton = new File(Compiler.IZPACK_HOME, SKELETON_SUBPATH);
is = new FileInputStream(skeleton);
}
ZipInputStream inJarStream = new ZipInputStream(is);
copyZip(inJarStream, primaryJarStream);
}
/**
* Write an arbitrary object to primary jar.
*/
protected void writeInstallerObject(String entryName, Object object) throws IOException
{
primaryJarStream.putNextEntry(new org.apache.tools.zip.ZipEntry(entryName));
ObjectOutputStream out = new ObjectOutputStream(primaryJarStream);
out.writeObject(object);
out.flush();
primaryJarStream.closeEntry();
}
/**
* Write the data referenced by URL to primary jar.
*/
protected void writeInstallerResources() throws IOException
{
sendMsg("Copying " + installerResourceURLMap.size() + " files into installer");
Iterator i = installerResourceURLMap.keySet().iterator();
while (i.hasNext())
{
String name = i.next();
InputStream in = (installerResourceURLMap.get(name)).openStream();
org.apache.tools.zip.ZipEntry newEntry = new org.apache.tools.zip.ZipEntry(name);
long dateTime = FileUtil.getFileDateTime(installerResourceURLMap.get(name));
if (dateTime != -1)
{
newEntry.setTime(dateTime);
}
primaryJarStream.putNextEntry(newEntry);
PackagerHelper.copyStream(in, primaryJarStream);
primaryJarStream.closeEntry();
in.close();
}
}
/**
* Copy included jars to primary jar.
*/
protected void writeIncludedJars() throws IOException
{
sendMsg("Merging " + includedJarURLs.size() + " jars into installer");
Iterator