text
stringlengths
30
1.67M
<s> package com . izforge . izpack . compiler . container . provider ; import org . picocontainer . injectors . Provider ; import com . izforge . izpack . compiler . helper . AssertionHelper ; import com . izforge . izpack . compiler . helper . XmlCompilerHelper ; public class XmlCompilerHelperProvider implements Provider { public XmlCompilerHelper provide ( String installFile , AssertionHelper assertionHelper ) { return new XmlCompilerHelper ( assertionHelper ) ; } } </s>
<s> package com . izforge . izpack . compiler . container . provider ; import org . picocontainer . injectors . Provider ; import com . izforge . izpack . compiler . compressor . BZip2PackCompressor ; import com . izforge . izpack . compiler . compressor . DefaultPackCompressor ; import com . izforge . izpack . compiler . compressor . PackCompressor ; import com . izforge . izpack . compiler . compressor . RawPackCompressor ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . merge . MergeManager ; public class PackCompressorProvider implements Provider { public PackCompressor provide ( CompilerData compilerData , MergeManager mergeManager ) { String format = compilerData . getComprFormat ( ) ; if ( format . equals ( "<STR_LIT>" ) ) { return new BZip2PackCompressor ( mergeManager ) ; } else if ( format . equals ( "<STR_LIT>" ) ) { return new RawPackCompressor ( ) ; } return new DefaultPackCompressor ( ) ; } } </s>
<s> package com . izforge . izpack . compiler . container . provider ; import java . io . File ; import java . io . IOException ; import java . util . zip . Deflater ; import org . picocontainer . injectors . Provider ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . stream . JarOutputStream ; public class JarOutputStreamProvider implements Provider { public JarOutputStream provide ( CompilerData compilerData ) throws IOException { JarOutputStream jarOutputStream ; File file = new File ( compilerData . getOutput ( ) ) ; if ( file . exists ( ) ) { file . delete ( ) ; } if ( compilerData . isMkdirs ( ) ) { file . getParentFile ( ) . mkdirs ( ) ; } jarOutputStream = new JarOutputStream ( file ) ; int level = compilerData . getComprLevel ( ) ; if ( level >= <NUM_LIT:0> && level < <NUM_LIT:10> ) { jarOutputStream . setLevel ( level ) ; } else { jarOutputStream . setLevel ( Deflater . BEST_COMPRESSION ) ; } jarOutputStream . setPreventClose ( true ) ; return jarOutputStream ; } } </s>
<s> package com . izforge . izpack . compiler . container . provider ; import java . io . IOException ; import java . io . OutputStream ; import org . apache . commons . compress . compressors . CompressorException ; import org . apache . commons . compress . compressors . CompressorStreamFactory ; import org . apache . tools . zip . ZipEntry ; import org . picocontainer . injectors . Provider ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . stream . JarOutputStream ; public class CompressedOutputStreamProvider implements Provider { public OutputStream provide ( CompilerData compilerData , JarOutputStream jarOutputStream ) throws CompressorException , IOException { OutputStream outputStream = jarOutputStream ; String comprFormat = compilerData . getComprFormat ( ) ; if ( comprFormat . equals ( "<STR_LIT>" ) ) { ZipEntry entry = new ZipEntry ( "<STR_LIT>" ) ; entry . setMethod ( ZipEntry . STORED ) ; entry . setComment ( "<STR_LIT>" ) ; jarOutputStream . putNextEntry ( entry ) ; jarOutputStream . flush ( ) ; outputStream = new CompressorStreamFactory ( ) . createCompressorOutputStream ( "<STR_LIT>" , jarOutputStream ) ; jarOutputStream . closeEntry ( ) ; } return outputStream ; } } </s>
<s> package com . izforge . izpack . compiler . container ; import java . util . Properties ; import org . picocontainer . MutablePicoContainer ; import org . picocontainer . injectors . ProviderAdapter ; import org . picocontainer . parameters . ComponentParameter ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . api . factory . ObjectFactory ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . compiler . Compiler ; import com . izforge . izpack . compiler . CompilerConfig ; import com . izforge . izpack . compiler . cli . CliAnalyzer ; import com . izforge . izpack . compiler . container . provider . CompilerDataProvider ; import com . izforge . izpack . compiler . container . provider . CompressedOutputStreamProvider ; import com . izforge . izpack . compiler . container . provider . JarOutputStreamProvider ; import com . izforge . izpack . compiler . container . provider . PackCompressorProvider ; import com . izforge . izpack . compiler . container . provider . XmlCompilerHelperProvider ; import com . izforge . izpack . compiler . data . PropertyManager ; import com . izforge . izpack . compiler . helper . AssertionHelper ; import com . izforge . izpack . compiler . helper . CompilerHelper ; import com . izforge . izpack . compiler . listener . CmdlinePackagerListener ; import com . izforge . izpack . compiler . resource . ResourceFinder ; import com . izforge . izpack . core . container . AbstractContainer ; import com . izforge . izpack . core . container . PlatformProvider ; import com . izforge . izpack . core . factory . DefaultObjectFactory ; import com . izforge . izpack . core . rules . ConditionContainer ; import com . izforge . izpack . core . rules . RulesEngineImpl ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; import com . izforge . izpack . merge . MergeManager ; import com . izforge . izpack . merge . MergeManagerImpl ; import com . izforge . izpack . util . Platform ; import com . izforge . izpack . util . PlatformModelMatcher ; import com . izforge . izpack . util . Platforms ; public class CompilerContainer extends AbstractContainer { public CompilerContainer ( ) { initialise ( ) ; } protected CompilerContainer ( MutablePicoContainer container ) { super ( container ) ; } @ Override protected void fillContainer ( MutablePicoContainer container ) { addComponent ( Properties . class ) ; addComponent ( CompilerContainer . class , this ) ; addComponent ( CliAnalyzer . class ) ; addComponent ( CmdlinePackagerListener . class ) ; addComponent ( Compiler . class ) ; addComponent ( ResourceFinder . class ) ; addComponent ( CompilerConfig . class ) ; addComponent ( ConditionContainer . class , ConditionContainer . class ) ; addComponent ( AssertionHelper . class ) ; addComponent ( PropertyManager . class ) ; addComponent ( VariableSubstitutor . class , VariableSubstitutorImpl . class ) ; addComponent ( CompilerHelper . class ) ; container . addComponent ( RulesEngine . class , RulesEngineImpl . class , new ComponentParameter ( ConditionContainer . class ) , new ComponentParameter ( Platform . class ) ) ; addComponent ( MergeManager . class , MergeManagerImpl . class ) ; container . addComponent ( ObjectFactory . class , DefaultObjectFactory . class , new ComponentParameter ( CompilerContainer . class ) ) ; container . addComponent ( PlatformModelMatcher . class ) ; addComponent ( Platforms . class ) ; new ResolverContainerFiller ( ) . fillContainer ( this ) ; container . addAdapter ( new ProviderAdapter ( new XmlCompilerHelperProvider ( ) ) ) . addAdapter ( new ProviderAdapter ( new JarOutputStreamProvider ( ) ) ) . addAdapter ( new ProviderAdapter ( new CompressedOutputStreamProvider ( ) ) ) . addAdapter ( new ProviderAdapter ( new PackCompressorProvider ( ) ) ) . addAdapter ( new ProviderAdapter ( new PlatformProvider ( ) ) ) ; } public void processCompileDataFromArgs ( String [ ] args ) { getContainer ( ) . addAdapter ( new ProviderAdapter ( new CompilerDataProvider ( args ) ) ) ; } } </s>
<s> package com . izforge . izpack . compiler . container ; import java . io . IOException ; import java . io . InputStream ; import java . util . Map ; import java . util . Properties ; import com . izforge . izpack . api . container . Container ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . compiler . util . CompilerClassLoader ; import com . izforge . izpack . compiler . merge . CompilerPathResolver ; import com . izforge . izpack . compiler . util . DefaultClassNameMapper ; import com . izforge . izpack . merge . resolve . MergeableResolver ; public class ResolverContainerFiller { public void fillContainer ( Container container ) { Properties properties = container . getComponent ( Properties . class ) ; for ( Map . Entry < Object , Object > entry : getPanelDependencies ( ) . entrySet ( ) ) { properties . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } container . addComponent ( DefaultClassNameMapper . class ) ; container . addComponent ( CompilerClassLoader . class ) ; container . addComponent ( CompilerPathResolver . class ) ; container . addComponent ( MergeableResolver . class ) ; } private Properties getPanelDependencies ( ) { Properties properties = new Properties ( ) ; try { InputStream inStream = getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ; properties . load ( inStream ) ; } catch ( IOException e ) { throw new IzPackException ( e ) ; } return properties ; } } </s>
<s> package com . izforge . izpack . compiler . cli ; import java . util . List ; import org . apache . commons . cli . CommandLine ; import org . apache . commons . cli . CommandLineParser ; import org . apache . commons . cli . HelpFormatter ; import org . apache . commons . cli . Options ; import org . apache . commons . cli . ParseException ; import org . apache . commons . cli . PosixParser ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . exception . HelpRequestedException ; import com . izforge . izpack . compiler . exception . NoArgumentException ; public class CliAnalyzer { private static final String ARG_IZPACK_HOME = "<STR_LIT>" ; private static final String ARG_BASEDIR = "<STR_LIT:b>" ; private static final String ARG_KIND = "<STR_LIT>" ; private static final String ARG_OUTPUT = "<STR_LIT>" ; private static final String ARG_COMPRESSION_FORMAT = "<STR_LIT:c>" ; private static final String ARG_COMPRESSION_LEVEL = "<STR_LIT>" ; private Options getOptions ( ) { Options options = new Options ( ) ; options . addOption ( "<STR_LIT:?>" , false , "<STR_LIT>" ) ; options . addOption ( ARG_IZPACK_HOME , true , "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; options . addOption ( ARG_BASEDIR , true , "<STR_LIT>" + "<STR_LIT>" ) ; options . addOption ( ARG_KIND , true , "<STR_LIT>" ) ; options . addOption ( ARG_OUTPUT , true , "<STR_LIT>" ) ; options . addOption ( ARG_COMPRESSION_FORMAT , true , "<STR_LIT>" + "<STR_LIT>" ) ; options . addOption ( ARG_COMPRESSION_LEVEL , true , "<STR_LIT>" + "<STR_LIT>" ) ; return options ; } public CompilerData printAndParseArgs ( String [ ] args ) throws ParseException { printHeader ( ) ; CompilerData result = parseArgs ( args ) ; printTail ( result ) ; return result ; } private void printHeader ( ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + CompilerData . IZPACK_VERSION + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + CompilerData . VERSION + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } private void printTail ( CompilerData result ) { System . out . println ( "<STR_LIT>" + result . getInstallFile ( ) ) ; System . out . println ( "<STR_LIT>" + result . getOutput ( ) ) ; System . out . println ( "<STR_LIT>" + result . getBasedir ( ) ) ; System . out . println ( "<STR_LIT>" + result . getKind ( ) ) ; System . out . println ( "<STR_LIT>" + result . getComprFormat ( ) ) ; System . out . println ( "<STR_LIT>" + result . getComprLevel ( ) ) ; System . out . println ( "<STR_LIT>" + CompilerData . IZPACK_HOME ) ; System . out . println ( "<STR_LIT>" ) ; } public CompilerData parseArgs ( String [ ] args ) throws ParseException { CommandLineParser parser = new PosixParser ( ) ; CommandLine commandLine = parser . parse ( getOptions ( ) , args ) ; return analyzeCommandLine ( commandLine ) ; } private void printHelp ( ) { HelpFormatter formatter = new HelpFormatter ( ) ; String cmdLineUsage = "<STR_LIT>" ; String header = "<STR_LIT>" ; String footer = "<STR_LIT>" ; formatter . printHelp ( cmdLineUsage , header , getOptions ( ) , footer ) ; } private CompilerData analyzeCommandLine ( CommandLine commandLine ) { validateCommandLine ( commandLine ) ; String installFile ; String baseDir = "<STR_LIT:.>" ; String output = "<STR_LIT>" ; if ( commandLine . hasOption ( "<STR_LIT:?>" ) ) { printHelp ( ) ; throw new HelpRequestedException ( ) ; } List argList = commandLine . getArgList ( ) ; installFile = ( String ) argList . get ( <NUM_LIT:0> ) ; if ( commandLine . hasOption ( ARG_BASEDIR ) ) { baseDir = commandLine . getOptionValue ( ARG_BASEDIR ) . trim ( ) ; } if ( commandLine . hasOption ( ARG_OUTPUT ) ) { output = commandLine . getOptionValue ( ARG_OUTPUT ) . trim ( ) ; } CompilerData compilerData = new CompilerData ( installFile , baseDir , output , false ) ; if ( commandLine . hasOption ( ARG_COMPRESSION_FORMAT ) ) { compilerData . setComprFormat ( commandLine . getOptionValue ( ARG_COMPRESSION_FORMAT ) . trim ( ) ) ; } if ( commandLine . hasOption ( ARG_COMPRESSION_LEVEL ) ) { compilerData . setComprLevel ( Integer . parseInt ( commandLine . getOptionValue ( ARG_COMPRESSION_LEVEL ) . trim ( ) ) ) ; } if ( commandLine . hasOption ( ARG_IZPACK_HOME ) ) { CompilerData . setIzpackHome ( commandLine . getOptionValue ( ARG_IZPACK_HOME ) . trim ( ) ) ; } if ( commandLine . hasOption ( ARG_KIND ) ) { compilerData . setKind ( commandLine . getOptionValue ( ARG_KIND ) . trim ( ) ) ; } return compilerData ; } private void validateCommandLine ( CommandLine commandLine ) { if ( commandLine . getArgList ( ) . size ( ) == <NUM_LIT:0> ) { printHelp ( ) ; throw new NoArgumentException ( ) ; } } } </s>
<s> package com . izforge . izpack . compiler . compressor ; import java . io . BufferedOutputStream ; import java . io . OutputStream ; public class RawPackCompressor extends PackCompressorBase { private static final String [ ] THIS_FORMAT_NAMES = { "<STR_LIT>" , "<STR_LIT>" } ; public RawPackCompressor ( ) { formatNames = THIS_FORMAT_NAMES ; } public OutputStream getOutputStream ( OutputStream os ) { return ( new BufferedOutputStream ( os ) ) ; } } </s>
<s> package com . izforge . izpack . compiler . compressor ; import com . izforge . izpack . merge . MergeManager ; public class BZip2PackCompressor extends PackCompressorBase { private static final String [ ] THIS_FORMAT_NAMES = { "<STR_LIT>" } ; private static final String THIS_DECODER_MAPPER = "<STR_LIT>" ; private static final String THIS_ENCODER_CLASS_NAME = "<STR_LIT>" ; public BZip2PackCompressor ( MergeManager mergeManager ) { mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; formatNames = THIS_FORMAT_NAMES ; decoderMapper = THIS_DECODER_MAPPER ; encoderClassName = THIS_ENCODER_CLASS_NAME ; } } </s>
<s> package com . izforge . izpack . compiler . compressor ; public abstract class PackCompressorBase implements PackCompressor { protected String [ ] formatNames = null ; protected String decoderMapper = null ; protected String encoderClassName = null ; protected Class [ ] paramsClasses = null ; private int level = - <NUM_LIT:1> ; public PackCompressorBase ( ) { super ( ) ; } public String getEncoderClassName ( ) { return ( encoderClassName ) ; } public boolean useStandardCompression ( ) { return ( false ) ; } public String [ ] getCompressionFormatSymbols ( ) { return formatNames ; } public String getDecoderMapperName ( ) { return ( decoderMapper ) ; } public void setCompressionLevel ( int level ) { this . level = level ; } public int getCompressionLevel ( ) { return ( level ) ; } public boolean needsBufferedOutputStream ( ) { return ( true ) ; } } </s>
<s> package com . izforge . izpack . compiler . compressor ; import java . io . OutputStream ; public class DefaultPackCompressor extends PackCompressorBase { private static final String [ ] THIS_FORMAT_NAMES = { "<STR_LIT:default>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; private static final String THIS_DECODER_MAPPER = null ; private static final String THIS_ENCODER_CLASS_NAME = null ; public DefaultPackCompressor ( ) { formatNames = THIS_FORMAT_NAMES ; decoderMapper = THIS_DECODER_MAPPER ; encoderClassName = THIS_ENCODER_CLASS_NAME ; } public OutputStream getOutputStream ( OutputStream os ) { return ( null ) ; } public boolean useStandardCompression ( ) { return ( true ) ; } public boolean needsBufferedOutputStream ( ) { return ( false ) ; } } </s>
<s> package com . izforge . izpack . compiler . compressor ; public interface PackCompressor { String [ ] getCompressionFormatSymbols ( ) ; String getEncoderClassName ( ) ; String getDecoderMapperName ( ) ; boolean useStandardCompression ( ) ; void setCompressionLevel ( int level ) ; int getCompressionLevel ( ) ; } </s>
<s> package com . izforge . izpack . compiler . util ; public interface ClassNameMapper { String map ( String className ) ; } </s>
<s> package com . izforge . izpack . compiler . util ; import java . util . HashMap ; import java . util . Map ; import com . izforge . izpack . event . AntActionInstallerListener ; import com . izforge . izpack . event . AntActionUninstallerListener ; import com . izforge . izpack . event . BSFInstallerListener ; import com . izforge . izpack . event . BSFUninstallerListener ; import com . izforge . izpack . event . ConfigurationInstallerListener ; import com . izforge . izpack . event . ProgressBarInstallerListener ; import com . izforge . izpack . event . RegistryInstallerListener ; import com . izforge . izpack . event . RegistryUninstallerListener ; import com . izforge . izpack . event . SummaryLoggerInstallerListener ; import com . izforge . izpack . installer . web . DownloadPanel ; import com . izforge . izpack . panels . checkedhello . CheckedHelloPanel ; import com . izforge . izpack . panels . compile . CompilePanel ; import com . izforge . izpack . panels . datacheck . DataCheckPanel ; import com . izforge . izpack . panels . defaulttarget . DefaultTargetPanel ; import com . izforge . izpack . panels . extendedinstall . ExtendedInstallPanel ; import com . izforge . izpack . panels . finish . FinishPanel ; import com . izforge . izpack . panels . hello . HelloPanel ; import com . izforge . izpack . panels . htmlhello . HTMLHelloPanel ; import com . izforge . izpack . panels . htmlinfo . HTMLInfoPanel ; import com . izforge . izpack . panels . htmllicence . HTMLLicencePanel ; import com . izforge . izpack . panels . imgpacks . ImgPacksPanel ; import com . izforge . izpack . panels . info . InfoPanel ; import com . izforge . izpack . panels . install . InstallPanel ; import com . izforge . izpack . panels . installationgroup . InstallationGroupPanel ; import com . izforge . izpack . panels . installationtype . InstallationTypePanel ; import com . izforge . izpack . panels . jdkpath . JDKPathPanel ; import com . izforge . izpack . panels . licence . LicencePanel ; import com . izforge . izpack . panels . packs . PacksPanel ; import com . izforge . izpack . panels . process . ProcessPanel ; import com . izforge . izpack . panels . selectprinter . SelectPrinterPanel ; import com . izforge . izpack . panels . shortcut . ShortcutPanel ; import com . izforge . izpack . panels . simplefinish . SimpleFinishPanel ; import com . izforge . izpack . panels . sudo . SudoPanel ; import com . izforge . izpack . panels . summary . SummaryPanel ; import com . izforge . izpack . panels . target . TargetPanel ; import com . izforge . izpack . panels . treepacks . TreePacksPanel ; import com . izforge . izpack . panels . userinput . UserInputPanel ; import com . izforge . izpack . panels . userinput . validator . HostAddressValidator ; import com . izforge . izpack . panels . userinput . validator . IsPortValidator ; import com . izforge . izpack . panels . userinput . validator . NotEmptyValidator ; import com . izforge . izpack . panels . userinput . validator . PasswordEncryptionValidator ; import com . izforge . izpack . panels . userinput . validator . PasswordEqualityValidator ; import com . izforge . izpack . panels . userinput . validator . PortValidator ; import com . izforge . izpack . panels . userinput . validator . RegularExpressionValidator ; import com . izforge . izpack . panels . userpath . UserPathPanel ; import com . izforge . izpack . panels . xinfo . XInfoPanel ; public class DefaultClassNameMapper implements ClassNameMapper { private final Map < String , String > mappings = new HashMap < String , String > ( ) ; public DefaultClassNameMapper ( ) { addMapping ( AntActionInstallerListener . class , BSFInstallerListener . class , ConfigurationInstallerListener . class , ProgressBarInstallerListener . class , RegistryInstallerListener . class , SummaryLoggerInstallerListener . class ) ; addMapping ( AntActionUninstallerListener . class , BSFUninstallerListener . class , RegistryUninstallerListener . class ) ; addMapping ( CheckedHelloPanel . class , CompilePanel . class , DataCheckPanel . class , DefaultTargetPanel . class , DownloadPanel . class , ExtendedInstallPanel . class , FinishPanel . class , HTMLHelloPanel . class , HTMLInfoPanel . class , HTMLLicencePanel . class , HelloPanel . class , ImgPacksPanel . class , InfoPanel . class , InstallationGroupPanel . class , InstallationTypePanel . class , InstallPanel . class , JDKPathPanel . class , LicencePanel . class , PacksPanel . class , ProcessPanel . class , SelectPrinterPanel . class , ShortcutPanel . class , SimpleFinishPanel . class , SudoPanel . class , SummaryPanel . class , TargetPanel . class , TreePacksPanel . class , UserInputPanel . class , UserPathPanel . class , XInfoPanel . class ) ; addMapping ( HostAddressValidator . class , IsPortValidator . class , NotEmptyValidator . class , PasswordEncryptionValidator . class , PasswordEqualityValidator . class , PortValidator . class , RegularExpressionValidator . class ) ; } @ Override public String map ( String className ) { return mappings . get ( className ) ; } private void addMapping ( Class ... types ) { for ( Class type : types ) { if ( mappings . put ( type . getSimpleName ( ) , type . getName ( ) ) != null ) { throw new IllegalStateException ( "<STR_LIT>" + type . getSimpleName ( ) ) ; } } } } </s>
<s> package com . izforge . izpack . compiler . util ; import java . net . URL ; import java . net . URLClassLoader ; import com . izforge . izpack . api . exception . IzPackClassNotFoundException ; public class CompilerClassLoader extends URLClassLoader { private final ClassNameMapper mapper ; public CompilerClassLoader ( ClassNameMapper mapper ) { this ( CompilerClassLoader . class . getClassLoader ( ) , mapper ) ; } public CompilerClassLoader ( ClassLoader parent , ClassNameMapper mapper ) { super ( new URL [ <NUM_LIT:0> ] , parent ) ; this . mapper = mapper ; } @ Override public void addURL ( URL url ) { super . addURL ( url ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public < T > Class < T > loadClass ( String name , Class < T > type ) { Class < T > result ; try { Class loaded = loadClass ( name ) ; if ( ! type . isAssignableFrom ( loaded ) ) { throw new ClassCastException ( "<STR_LIT>" + loaded . getName ( ) + "<STR_LIT>" + type . getName ( ) ) ; } else { result = loaded ; } } catch ( ClassNotFoundException exception ) { throw new IzPackClassNotFoundException ( name , exception ) ; } return result ; } @ Override protected Class < ? > findClass ( String name ) throws ClassNotFoundException { Class < ? > result ; String mapping = mapper . map ( name ) ; if ( mapping != null ) { result = loadClass ( mapping ) ; } else { result = super . findClass ( name ) ; } return result ; } } </s>
<s> package com . izforge . izpack . compiler . helper ; import java . net . MalformedURLException ; import java . net . URL ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . exception . CompilerException ; public class XmlCompilerHelper { private AssertionHelper assertionHelper ; public XmlCompilerHelper ( AssertionHelper assertionHelper ) { this . assertionHelper = assertionHelper ; } public String requireContent ( IXMLElement element ) throws CompilerException { String content = element . getContent ( ) ; if ( content == null || content . length ( ) == <NUM_LIT:0> ) { assertionHelper . parseError ( element , "<STR_LIT:<>" + element . getName ( ) + "<STR_LIT>" ) ; } return content ; } public URL requireURLContent ( IXMLElement element ) throws CompilerException { URL url = null ; try { url = new URL ( requireContent ( element ) . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) ) ; } catch ( MalformedURLException x ) { assertionHelper . parseError ( element , "<STR_LIT:<>" + element . getName ( ) + "<STR_LIT>" , x ) ; } return url ; } public IXMLElement requireChildNamed ( IXMLElement parent , String name ) throws CompilerException { IXMLElement child = parent . getFirstChildNamed ( name ) ; if ( child == null ) { assertionHelper . parseError ( parent , "<STR_LIT:<>" + parent . getName ( ) + "<STR_LIT>" + name + "<STR_LIT:>>" ) ; } return child ; } public int requireIntAttribute ( IXMLElement element , String attribute ) throws CompilerException { String value = element . getAttribute ( attribute ) ; if ( value == null || value . length ( ) == <NUM_LIT:0> ) { assertionHelper . parseError ( element , "<STR_LIT:<>" + element . getName ( ) + "<STR_LIT>" + attribute + "<STR_LIT:'>" ) ; } try { return Integer . parseInt ( value ) ; } catch ( NumberFormatException x ) { assertionHelper . parseError ( element , "<STR_LIT:'>" + attribute + "<STR_LIT>" ) ; } return <NUM_LIT:0> ; } public boolean requireYesNoAttribute ( IXMLElement element , String attribute ) throws CompilerException { return validateYesNoAttribute ( element , attribute , null ) ; } public boolean validateYesNoAttribute ( IXMLElement element , String attribute , Boolean defaultValue ) throws CompilerException { if ( element != null ) { String value = element . getAttribute ( attribute ) ; if ( value == null ) { if ( defaultValue == null ) { assertionHelper . parseError ( element , "<STR_LIT:<>" + element . getName ( ) + "<STR_LIT>" + attribute + "<STR_LIT>" ) ; } } else { if ( "<STR_LIT:yes>" . equalsIgnoreCase ( value . trim ( ) ) || "<STR_LIT:true>" . equalsIgnoreCase ( value . trim ( ) ) ) { return true ; } else { if ( "<STR_LIT>" . equalsIgnoreCase ( value . trim ( ) ) || "<STR_LIT:false>" . equalsIgnoreCase ( value . trim ( ) ) ) { return false ; } } final String msg = "<STR_LIT:<>" + element . getName ( ) + "<STR_LIT>" + value + "<STR_LIT>" + attribute + "<STR_LIT>" ; if ( defaultValue == null ) { assertionHelper . parseError ( element , msg + "<STR_LIT>" ) ; } else { assertionHelper . parseWarn ( element , msg ) ; } } } return defaultValue . booleanValue ( ) ; } public String requireAttribute ( IXMLElement element , String attribute ) throws CompilerException { String value = element . getAttribute ( attribute ) ; if ( value == null ) { assertionHelper . parseError ( element , "<STR_LIT:<>" + element . getName ( ) + "<STR_LIT>" + attribute + "<STR_LIT:'>" ) ; } return value ; } public long getLong ( IXMLElement element , String attribute , long defaultValue ) throws CompilerException { long result = defaultValue ; String value = element . getAttribute ( attribute ) ; if ( value != null ) { try { result = Long . parseLong ( value ) ; } catch ( NumberFormatException exception ) { assertionHelper . parseError ( element , "<STR_LIT:'>" + attribute + "<STR_LIT>" + value ) ; } } return result ; } } </s>
<s> package com . izforge . izpack . compiler . helper ; import java . io . IOException ; import java . net . URL ; import java . util . ArrayList ; import java . util . List ; import java . util . jar . JarInputStream ; import java . util . zip . ZipEntry ; import org . apache . commons . lang . StringUtils ; public class CompilerHelper { public String resolveCustomActionsJarPath ( String name ) { StringBuilder stringBuilder = new StringBuilder ( ) ; stringBuilder . append ( "<STR_LIT>" ) ; stringBuilder . append ( "<STR_LIT>" ) ; stringBuilder . append ( convertNameToDashSeparated ( name ) ) ; stringBuilder . append ( "<STR_LIT>" ) ; return stringBuilder . toString ( ) ; } public StringBuilder convertNameToDashSeparated ( String name ) { StringBuilder res = new StringBuilder ( ) ; for ( String part : StringUtils . splitByCharacterTypeCamelCase ( name ) ) { res . append ( '<CHAR_LIT:->' ) ; res . append ( part . toLowerCase ( ) ) ; } return res ; } public String getFullClassName ( URL url , String className ) throws IOException { JarInputStream jis = new JarInputStream ( url . openStream ( ) ) ; ZipEntry zentry ; while ( ( zentry = jis . getNextEntry ( ) ) != null ) { String name = zentry . getName ( ) ; int lastPos = name . lastIndexOf ( "<STR_LIT:.class>" ) ; if ( lastPos < <NUM_LIT:0> ) { continue ; } name = name . replace ( '<CHAR_LIT:/>' , '<CHAR_LIT:.>' ) ; int pos = - <NUM_LIT:1> ; int nonCasePos = - <NUM_LIT:1> ; if ( className != null ) { pos = name . indexOf ( className ) ; nonCasePos = name . toLowerCase ( ) . indexOf ( className . toLowerCase ( ) ) ; } if ( pos != - <NUM_LIT:1> && name . length ( ) == pos + className . length ( ) + <NUM_LIT:6> ) { jis . close ( ) ; return ( name . substring ( <NUM_LIT:0> , lastPos ) ) ; } if ( nonCasePos != - <NUM_LIT:1> && name . length ( ) == nonCasePos + className . length ( ) + <NUM_LIT:6> ) { throw new IllegalArgumentException ( "<STR_LIT>" + className + "<STR_LIT>" + name + "<STR_LIT>" ) ; } } jis . close ( ) ; return ( null ) ; } public List < String > getContainedFilePaths ( URL url ) throws IOException { JarInputStream jis = new JarInputStream ( url . openStream ( ) ) ; ZipEntry zentry ; ArrayList < String > fullNames = new ArrayList < String > ( ) ; while ( ( zentry = jis . getNextEntry ( ) ) != null ) { String name = zentry . getName ( ) ; if ( ! zentry . isDirectory ( ) ) { fullNames . add ( name ) ; } } jis . close ( ) ; return ( fullNames ) ; } } </s>
<s> package com . izforge . izpack . compiler . helper ; import java . io . File ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . exception . CompilerException ; public class AssertionHelper { private String installFile ; public AssertionHelper ( String installFile ) { this . installFile = installFile ; } public void parseError ( String message ) throws CompilerException { throw new CompilerException ( this . installFile + "<STR_LIT::>" + message ) ; } public void parseError ( IXMLElement parent , String message ) throws CompilerException { throw new CompilerException ( this . installFile + "<STR_LIT::>" + parent . getLineNr ( ) + "<STR_LIT::U+0020>" + message ) ; } public void parseError ( IXMLElement parent , String message , Throwable cause ) throws CompilerException { throw new CompilerException ( this . installFile + "<STR_LIT::>" + parent . getLineNr ( ) + "<STR_LIT::U+0020>" + message , cause ) ; } public void parseWarn ( IXMLElement parent , String message ) { System . out . println ( "<STR_LIT>" + this . installFile + "<STR_LIT::>" + parent . getLineNr ( ) + "<STR_LIT::U+0020>" + message ) ; } public void assertIsNormalReadableFile ( File fileToCheck , String fileDescription ) throws CompilerException { if ( fileToCheck != null ) { if ( ! fileToCheck . exists ( ) ) { throw new CompilerException ( fileDescription + "<STR_LIT>" + fileToCheck ) ; } if ( ! fileToCheck . isFile ( ) ) { throw new CompilerException ( fileDescription + "<STR_LIT>" + fileToCheck ) ; } if ( ! fileToCheck . canRead ( ) ) { throw new CompilerException ( fileDescription + "<STR_LIT>" + fileToCheck ) ; } } } } </s>
<s> package com . izforge . izpack . compiler . helper ; import java . util . List ; import java . util . Map ; import com . izforge . izpack . api . data . Blockable ; import com . izforge . izpack . api . data . OverrideType ; import com . izforge . izpack . api . data . binding . OsModel ; import com . izforge . izpack . util . file . types . FileSet ; public class TargetFileSet extends FileSet { private String targetDir ; List < OsModel > osList ; OverrideType override ; String overrideRenameTo ; Blockable blockable ; Map additionals ; String condition ; public String getTargetDir ( ) { return targetDir ; } public void setTargetDir ( String targetDir ) { this . targetDir = targetDir ; } public List < OsModel > getOsList ( ) { return osList ; } public void setOsList ( List < OsModel > osList ) { this . osList = osList ; } public OverrideType getOverride ( ) { return override ; } public void setOverride ( OverrideType override ) { this . override = override ; } public String getOverrideRenameTo ( ) { return overrideRenameTo ; } public void setOverrideRenameTo ( String overrideRenameTo ) { this . overrideRenameTo = overrideRenameTo ; } public Blockable getBlockable ( ) { return blockable ; } public void setBlockable ( Blockable blockable ) { this . blockable = blockable ; } public Map getAdditionals ( ) { return additionals ; } public void setAdditionals ( Map additionals ) { this . additionals = additionals ; } public String getCondition ( ) { return condition ; } public void setCondition ( String condition ) { this . condition = condition ; } } </s>
<s> package com . izforge . izpack . compiler . resource ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . net . MalformedURLException ; import java . net . URL ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . IXMLParser ; import com . izforge . izpack . api . adaptator . impl . XMLParser ; import com . izforge . izpack . api . exception . CompilerException ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . data . PropertyManager ; import com . izforge . izpack . compiler . helper . AssertionHelper ; import com . izforge . izpack . compiler . helper . XmlCompilerHelper ; public class ResourceFinder { private AssertionHelper assertionHelper ; private CompilerData compilerData ; private PropertyManager propertyManager ; private XmlCompilerHelper xmlCompilerHelper ; public ResourceFinder ( AssertionHelper assertionHelper , CompilerData compilerData , PropertyManager propertyManager , XmlCompilerHelper xmlCompilerHelper ) { this . assertionHelper = assertionHelper ; this . compilerData = compilerData ; this . propertyManager = propertyManager ; this . xmlCompilerHelper = xmlCompilerHelper ; } public URL findProjectResource ( String path , String desc , IXMLElement parent ) throws CompilerException { URL url = null ; File resource = new File ( path ) ; if ( ! resource . isAbsolute ( ) ) { resource = new File ( compilerData . getBasedir ( ) , path ) ; } if ( ! resource . exists ( ) ) { assertionHelper . parseError ( parent , desc + "<STR_LIT>" + resource ) ; } try { url = resource . toURI ( ) . toURL ( ) ; } catch ( MalformedURLException how ) { assertionHelper . parseError ( parent , desc + "<STR_LIT:(>" + resource + "<STR_LIT:)>" , how ) ; } return url ; } public URL findIzPackResource ( String path , String desc , IXMLElement parent , boolean ignoreWhenNotFound ) throws CompilerException { URL url = getClass ( ) . getResource ( "<STR_LIT:/>" + path ) ; if ( url == null ) { File resource = new File ( path ) ; if ( ! resource . isAbsolute ( ) ) { resource = new File ( CompilerData . IZPACK_HOME , path ) ; } if ( resource . exists ( ) ) { try { url = resource . toURI ( ) . toURL ( ) ; } catch ( MalformedURLException how ) { assertionHelper . parseError ( parent , desc + "<STR_LIT:(>" + resource + "<STR_LIT:)>" , how ) ; } } else { if ( ignoreWhenNotFound ) { assertionHelper . parseWarn ( parent , desc + "<STR_LIT>" + resource ) ; } else { assertionHelper . parseError ( parent , desc + "<STR_LIT>" + resource ) ; } } } return url ; } public URL findIzPackResource ( String path , String desc , IXMLElement parent ) throws CompilerException { return findIzPackResource ( path , desc , parent , false ) ; } public IXMLElement getXMLTree ( ) throws IOException { IXMLParser parser = new XMLParser ( ) ; IXMLElement data ; if ( compilerData . getInstallFile ( ) != null ) { File file = new File ( compilerData . getInstallFile ( ) ) . getAbsoluteFile ( ) ; assertionHelper . assertIsNormalReadableFile ( file , "<STR_LIT>" ) ; FileInputStream inputStream = new FileInputStream ( compilerData . getInstallFile ( ) ) ; data = parser . parse ( inputStream , file . getAbsolutePath ( ) ) ; inputStream . close ( ) ; propertyManager . setProperty ( "<STR_LIT>" , file . toString ( ) ) ; } else if ( compilerData . getInstallText ( ) != null ) { data = parser . parse ( compilerData . getInstallText ( ) ) ; } else { throw new CompilerException ( "<STR_LIT>" ) ; } if ( ! "<STR_LIT>" . equalsIgnoreCase ( data . getElement ( ) . getLocalName ( ) ) ) { assertionHelper . parseError ( data , "<STR_LIT>" ) ; } if ( ! CompilerData . VERSION . equalsIgnoreCase ( xmlCompilerHelper . requireAttribute ( data , "<STR_LIT:version>" ) ) ) { assertionHelper . parseError ( data , "<STR_LIT>" ) ; } return data ; } } </s>
<s> package com . izforge . izpack . compiler . stream ; import java . io . BufferedOutputStream ; import java . io . File ; import java . io . IOException ; import java . io . OutputStream ; import java . util . jar . JarFile ; import java . util . jar . Manifest ; public class JarOutputStream extends org . apache . tools . zip . ZipOutputStream { private static final int JAR_MAGIC = <NUM_LIT> ; private boolean firstEntry = true ; private boolean preventClose = false ; public JarOutputStream ( OutputStream out ) { super ( out ) ; } public JarOutputStream ( File fout , Manifest man ) throws IOException { super ( fout ) ; if ( man == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } org . apache . tools . zip . ZipEntry e = new org . apache . tools . zip . ZipEntry ( JarFile . MANIFEST_NAME ) ; putNextEntry ( e ) ; man . write ( new BufferedOutputStream ( this ) ) ; closeEntry ( ) ; } public JarOutputStream ( File arg0 ) throws IOException { super ( arg0 ) ; } public void putNextEntry ( org . apache . tools . zip . ZipEntry ze ) throws IOException { if ( firstEntry ) { byte [ ] edata = ze . getExtra ( ) ; if ( edata != null && ! hasMagic ( edata ) ) { byte [ ] tmp = new byte [ edata . length + <NUM_LIT:4> ] ; System . arraycopy ( tmp , <NUM_LIT:4> , edata , <NUM_LIT:0> , edata . length ) ; edata = tmp ; } else { edata = new byte [ <NUM_LIT:4> ] ; } set16 ( edata , <NUM_LIT:0> , JAR_MAGIC ) ; set16 ( edata , <NUM_LIT:2> , <NUM_LIT:0> ) ; ze . setExtra ( edata ) ; firstEntry = false ; } super . putNextEntry ( ze ) ; } public boolean isPreventClose ( ) { return preventClose ; } public void setPreventClose ( boolean preventClose ) { this . preventClose = preventClose ; } public void close ( ) throws IOException { if ( ! isPreventClose ( ) ) { super . close ( ) ; } } public void closeAlways ( ) throws IOException { setPreventClose ( false ) ; close ( ) ; } private static boolean hasMagic ( byte [ ] edata ) { try { int i = <NUM_LIT:0> ; while ( i < edata . length ) { if ( get16 ( edata , i ) == JAR_MAGIC ) { return true ; } i += get16 ( edata , i + <NUM_LIT:2> ) + <NUM_LIT:4> ; } } catch ( ArrayIndexOutOfBoundsException e ) { } return false ; } private static int get16 ( byte [ ] b , int off ) { return ( b [ off ] & <NUM_LIT> ) | ( ( b [ off + <NUM_LIT:1> ] & <NUM_LIT> ) << <NUM_LIT:8> ) ; } private static void set16 ( byte [ ] b , int off , int value ) { b [ off ] = ( byte ) value ; b [ off + <NUM_LIT:1> ] = ( byte ) ( value > > <NUM_LIT:8> ) ; } } </s>
<s> package com . izforge . izpack . compiler . packager ; import java . io . File ; import java . net . URL ; import java . util . List ; import java . util . Map ; import java . util . Properties ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . data . DynamicInstallerRequirementValidator ; import com . izforge . izpack . api . data . DynamicVariable ; import com . izforge . izpack . api . data . GUIPrefs ; import com . izforge . izpack . api . data . Info ; import com . izforge . izpack . api . data . InstallerRequirement ; import com . izforge . izpack . api . data . Panel ; import com . izforge . izpack . api . rules . Condition ; import com . izforge . izpack . data . CustomData ; import com . izforge . izpack . data . PackInfo ; public interface IPackager { public abstract void createInstaller ( ) throws Exception ; public abstract void setInfo ( Info info ) ; public abstract void setGUIPrefs ( GUIPrefs prefs ) ; void setSplashScreenImage ( File file ) ; public abstract Properties getVariables ( ) ; public abstract void addCustomJar ( CustomData ca , URL url ) ; public abstract void addPack ( PackInfo pack ) ; public abstract List < PackInfo > getPacksList ( ) ; public abstract void addLangPack ( String iso3 , URL xmlURL , URL flagURL ) ; public abstract void addResource ( String resId , URL url ) ; public abstract void addNativeLibrary ( String name , URL url ) ; public abstract void addJarContent ( URL jarURL ) ; public abstract void addNativeUninstallerLibrary ( CustomData data ) ; public abstract void addInstallerRequirements ( List < InstallerRequirement > conditions ) ; public abstract void addConfigurationInformation ( IXMLElement data ) ; public abstract Map < String , Condition > getRules ( ) ; public abstract Map < String , List < DynamicVariable > > getDynamicVariables ( ) ; public abstract List < DynamicInstallerRequirementValidator > getDynamicInstallerRequirements ( ) ; void addPanel ( Panel panel ) ; } </s>
<s> package com . izforge . izpack . compiler . packager . impl ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . ObjectOutputStream ; import java . io . OutputStream ; import java . util . Enumeration ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Properties ; import java . util . jar . JarEntry ; import java . util . jar . JarFile ; import java . util . jar . Pack200 ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . PackFile ; import com . izforge . izpack . compiler . compressor . PackCompressor ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . listener . PackagerListener ; import com . izforge . izpack . compiler . merge . CompilerPathResolver ; import com . izforge . izpack . compiler . stream . JarOutputStream ; import com . izforge . izpack . core . io . ByteCountingOutputStream ; import com . izforge . izpack . data . ExecutableFile ; import com . izforge . izpack . data . PackInfo ; import com . izforge . izpack . data . ParsableFile ; import com . izforge . izpack . data . UpdateCheck ; import com . izforge . izpack . merge . MergeManager ; import com . izforge . izpack . merge . resolve . MergeableResolver ; import com . izforge . izpack . util . IoHelper ; public class Packager extends PackagerBase { private final OutputStream outputStream ; public Packager ( Properties properties , PackagerListener listener , JarOutputStream jarOutputStream , PackCompressor compressor , OutputStream outputStream , MergeManager mergeManager , CompilerPathResolver pathResolver , MergeableResolver mergeableResolver , CompilerData compilerData ) { super ( properties , listener , jarOutputStream , mergeManager , pathResolver , mergeableResolver , compressor , compilerData ) ; this . outputStream = outputStream ; } @ Override protected void writePacks ( ) throws IOException { List < PackInfo > packs = getPacksList ( ) ; final int num = packs . size ( ) ; sendMsg ( "<STR_LIT>" + num + "<STR_LIT>" + ( num > <NUM_LIT:1> ? "<STR_LIT:s>" : "<STR_LIT>" ) + "<STR_LIT>" ) ; Map < File , Object [ ] > storedFiles = new HashMap < File , Object [ ] > ( ) ; Map < Integer , File > pack200Map = new HashMap < Integer , File > ( ) ; int pack200Counter = <NUM_LIT:0> ; JarOutputStream installerJar = getInstallerJar ( ) ; installerJar . setEncoding ( "<STR_LIT:utf-8>" ) ; int packNumber = <NUM_LIT:0> ; IXMLElement root = new XMLElementImpl ( "<STR_LIT>" ) ; for ( PackInfo packInfo : packs ) { Pack pack = packInfo . getPack ( ) ; pack . setFileSize ( <NUM_LIT:0> ) ; sendMsg ( "<STR_LIT>" + packNumber + "<STR_LIT::U+0020>" + pack . getName ( ) , PackagerListener . MSG_VERBOSE ) ; org . apache . tools . zip . ZipEntry entry = new org . apache . tools . zip . ZipEntry ( RESOURCES_PATH + "<STR_LIT>" + pack . getName ( ) ) ; installerJar . putNextEntry ( entry ) ; installerJar . flush ( ) ; ByteCountingOutputStream dos = new ByteCountingOutputStream ( outputStream ) ; ObjectOutputStream objOut = new ObjectOutputStream ( dos ) ; objOut . writeInt ( packInfo . getPackFiles ( ) . size ( ) ) ; for ( PackFile packFile : packInfo . getPackFiles ( ) ) { boolean addFile = ! pack . isLoose ( ) ; boolean pack200 = false ; File file = packInfo . getFile ( packFile ) ; if ( file . getName ( ) . toLowerCase ( ) . endsWith ( "<STR_LIT>" ) && getInfo ( ) . isPack200Compression ( ) && isNotSignedJar ( file ) ) { packFile . setPack200Jar ( true ) ; pack200 = true ; } Object [ ] info = storedFiles . get ( file ) ; if ( info != null && ! packSeparateJars ( ) ) { packFile . setPreviousPackFileRef ( ( String ) info [ <NUM_LIT:0> ] , ( Long ) info [ <NUM_LIT:1> ] ) ; addFile = false ; } objOut . writeObject ( packFile ) ; if ( addFile && ! packFile . isDirectory ( ) ) { long pos = dos . getByteCount ( ) ; if ( pack200 ) { pack200Map . put ( pack200Counter , file ) ; objOut . writeInt ( pack200Counter ) ; pack200Counter = pack200Counter + <NUM_LIT:1> ; } else { FileInputStream inStream = new FileInputStream ( file ) ; long bytesWritten = IoHelper . copyStream ( inStream , objOut ) ; inStream . close ( ) ; if ( bytesWritten != packFile . length ( ) ) { throw new IOException ( "<STR_LIT>" + file ) ; } } storedFiles . put ( file , new Object [ ] { pack . getName ( ) , pos } ) ; } pack . addFileSize ( packFile . size ( ) ) ; } if ( pack . getFileSize ( ) > pack . getSize ( ) ) { pack . setSize ( pack . getFileSize ( ) ) ; } objOut . writeInt ( packInfo . getParsables ( ) . size ( ) ) ; for ( ParsableFile parsableFile : packInfo . getParsables ( ) ) { objOut . writeObject ( parsableFile ) ; } objOut . writeInt ( packInfo . getExecutables ( ) . size ( ) ) ; for ( ExecutableFile executableFile : packInfo . getExecutables ( ) ) { objOut . writeObject ( executableFile ) ; } objOut . writeInt ( packInfo . getUpdateChecks ( ) . size ( ) ) ; for ( UpdateCheck updateCheck : packInfo . getUpdateChecks ( ) ) { objOut . writeObject ( updateCheck ) ; } objOut . flush ( ) ; if ( ! getCompressor ( ) . useStandardCompression ( ) ) { outputStream . close ( ) ; } installerJar . closeEntry ( ) ; if ( packSeparateJars ( ) ) { installerJar . closeAlways ( ) ; } IXMLElement child = new XMLElementImpl ( "<STR_LIT>" , root ) ; child . setAttribute ( "<STR_LIT:name>" , pack . getName ( ) ) ; child . setAttribute ( "<STR_LIT:size>" , Long . toString ( pack . getSize ( ) ) ) ; child . setAttribute ( "<STR_LIT>" , Long . toString ( pack . getFileSize ( ) ) ) ; if ( pack . getLangPackId ( ) != null ) { child . setAttribute ( "<STR_LIT:id>" , pack . getLangPackId ( ) ) ; } root . addChild ( child ) ; packNumber ++ ; } installerJar . putNextEntry ( new org . apache . tools . zip . ZipEntry ( RESOURCES_PATH + "<STR_LIT>" ) ) ; ObjectOutputStream out = new ObjectOutputStream ( installerJar ) ; out . writeInt ( packs . size ( ) ) ; for ( PackInfo packInfo : packs ) { out . writeObject ( packInfo . getPack ( ) ) ; } out . flush ( ) ; installerJar . closeEntry ( ) ; Pack200 . Packer packer = createAgressivePack200Packer ( ) ; for ( Integer key : pack200Map . keySet ( ) ) { File file = pack200Map . get ( key ) ; installerJar . putNextEntry ( new org . apache . tools . zip . ZipEntry ( RESOURCES_PATH + "<STR_LIT>" + key ) ) ; JarFile jar = new JarFile ( file ) ; packer . pack ( jar , installerJar ) ; jar . close ( ) ; installerJar . closeEntry ( ) ; } } private Pack200 . Packer createAgressivePack200Packer ( ) { Pack200 . Packer packer = Pack200 . newPacker ( ) ; Map < String , String > packerProperties = packer . properties ( ) ; packerProperties . put ( Pack200 . Packer . EFFORT , "<STR_LIT>" ) ; packerProperties . put ( Pack200 . Packer . SEGMENT_LIMIT , "<STR_LIT:-1>" ) ; packerProperties . put ( Pack200 . Packer . KEEP_FILE_ORDER , Pack200 . Packer . FALSE ) ; packerProperties . put ( Pack200 . Packer . DEFLATE_HINT , Pack200 . Packer . FALSE ) ; packerProperties . put ( Pack200 . Packer . MODIFICATION_TIME , Pack200 . Packer . LATEST ) ; packerProperties . put ( Pack200 . Packer . CODE_ATTRIBUTE_PFX + "<STR_LIT>" , Pack200 . Packer . STRIP ) ; packerProperties . put ( Pack200 . Packer . CODE_ATTRIBUTE_PFX + "<STR_LIT>" , Pack200 . Packer . STRIP ) ; packerProperties . put ( Pack200 . Packer . CODE_ATTRIBUTE_PFX + "<STR_LIT>" , Pack200 . Packer . STRIP ) ; return packer ; } private boolean isNotSignedJar ( File file ) throws IOException { JarFile jar = new JarFile ( file ) ; Enumeration < JarEntry > entries = jar . entries ( ) ; while ( entries . hasMoreElements ( ) ) { JarEntry entry = entries . nextElement ( ) ; if ( entry . getName ( ) . startsWith ( "<STR_LIT>" ) && entry . getName ( ) . endsWith ( "<STR_LIT>" ) ) { jar . close ( ) ; return false ; } } jar . close ( ) ; return true ; } @ Override public void addConfigurationInformation ( IXMLElement data ) { } } </s>
<s> package com . izforge . izpack . compiler . packager . impl ; import java . io . File ; import java . io . FilterOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . ObjectOutputStream ; import java . net . URL ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Properties ; import java . util . Set ; import java . util . zip . ZipInputStream ; import org . apache . commons . io . FileUtils ; import org . apache . commons . io . IOUtils ; import com . izforge . izpack . api . data . DynamicInstallerRequirementValidator ; import com . izforge . izpack . api . data . DynamicVariable ; import com . izforge . izpack . api . data . GUIPrefs ; import com . izforge . izpack . api . data . Info ; import com . izforge . izpack . api . data . InstallerRequirement ; import com . izforge . izpack . api . data . Panel ; import com . izforge . izpack . api . rules . Condition ; import com . izforge . izpack . compiler . compressor . PackCompressor ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . listener . PackagerListener ; import com . izforge . izpack . compiler . merge . PanelMerge ; import com . izforge . izpack . compiler . merge . CompilerPathResolver ; import com . izforge . izpack . compiler . packager . IPackager ; import com . izforge . izpack . compiler . stream . JarOutputStream ; import com . izforge . izpack . data . CustomData ; import com . izforge . izpack . data . PackInfo ; import com . izforge . izpack . merge . MergeManager ; import com . izforge . izpack . merge . resolve . MergeableResolver ; import com . izforge . izpack . util . FileUtil ; import com . izforge . izpack . util . IoHelper ; public abstract class PackagerBase implements IPackager { public static final String RESOURCES_PATH = "<STR_LIT>" ; private final Properties properties ; private final PackagerListener listener ; private final JarOutputStream installerJar ; private final MergeManager mergeManager ; private final CompilerPathResolver pathResolver ; private final MergeableResolver mergeableResolver ; private final PackCompressor compressor ; private final CompilerData compilerData ; private List < InstallerRequirement > installerRequirements ; private Info info ; private GUIPrefs guiPrefs ; private File splashScreenImage ; protected List < Panel > panelList = new ArrayList < Panel > ( ) ; private final List < PackInfo > packsList = new ArrayList < PackInfo > ( ) ; private List < String > langpackNameList = new ArrayList < String > ( ) ; private List < CustomData > customDataList = new ArrayList < CustomData > ( ) ; private final Map < String , URL > installerResourceURLMap = new HashMap < String , URL > ( ) ; private final Map < String , Condition > rules = new HashMap < String , Condition > ( ) ; private final Map < String , List < DynamicVariable > > dynamicVariables = new HashMap < String , List < DynamicVariable > > ( ) ; private List < DynamicInstallerRequirementValidator > dynamicInstallerRequirements = new ArrayList < DynamicInstallerRequirementValidator > ( ) ; private Set < Object [ ] > includedJarURLs = new HashSet < Object [ ] > ( ) ; private Map < FilterOutputStream , Set < String > > alreadyWrittenFiles = new HashMap < FilterOutputStream , Set < String > > ( ) ; public PackagerBase ( Properties properties , PackagerListener listener , JarOutputStream installerJar , MergeManager mergeManager , CompilerPathResolver pathResolver , MergeableResolver mergeableResolver , PackCompressor compressor , CompilerData compilerData ) { this . properties = properties ; this . listener = listener ; this . installerJar = installerJar ; this . mergeManager = mergeManager ; this . pathResolver = pathResolver ; this . mergeableResolver = mergeableResolver ; this . compressor = compressor ; this . compilerData = compilerData ; } public void addCustomJar ( CustomData ca , URL url ) { if ( ca != null ) { customDataList . add ( ca ) ; } if ( url != null ) { addJarContent ( url ) ; } } public void addJarContent ( URL jarURL ) { sendMsg ( "<STR_LIT>" + jarURL . getFile ( ) , PackagerListener . MSG_VERBOSE ) ; mergeManager . addResourceToMerge ( mergeableResolver . getMergeableFromURL ( jarURL ) ) ; } public void addLangPack ( String iso3 , URL xmlURL , URL flagURL ) { sendMsg ( "<STR_LIT>" + iso3 , PackagerListener . MSG_VERBOSE ) ; langpackNameList . add ( iso3 ) ; addResource ( "<STR_LIT>" + iso3 , flagURL ) ; installerResourceURLMap . put ( "<STR_LIT>" + iso3 + "<STR_LIT>" , xmlURL ) ; } public void addNativeLibrary ( String name , URL url ) { sendMsg ( "<STR_LIT>" + name , PackagerListener . MSG_VERBOSE ) ; installerResourceURLMap . put ( "<STR_LIT>" + name , url ) ; } public void addNativeUninstallerLibrary ( CustomData data ) { customDataList . add ( data ) ; } public void addPack ( PackInfo pack ) { packsList . add ( pack ) ; } public void addPanel ( Panel panel ) { sendMsg ( "<STR_LIT>" + panel . getPanelId ( ) + "<STR_LIT>" + panel . getClassName ( ) ) ; panelList . add ( panel ) ; PanelMerge mergeable = pathResolver . getPanelMerge ( panel . getClassName ( ) ) ; mergeManager . addResourceToMerge ( mergeable ) ; } public void addResource ( String resId , URL url ) { sendMsg ( "<STR_LIT>" + resId , PackagerListener . MSG_VERBOSE ) ; installerResourceURLMap . put ( resId , url ) ; } public List < PackInfo > getPacksList ( ) { return packsList ; } public Properties getVariables ( ) { return properties ; } public void setGUIPrefs ( GUIPrefs prefs ) { sendMsg ( "<STR_LIT>" , PackagerListener . MSG_VERBOSE ) ; guiPrefs = prefs ; } @ Override public void setSplashScreenImage ( File file ) { splashScreenImage = file ; } public void setInfo ( Info info ) { sendMsg ( "<STR_LIT>" , PackagerListener . MSG_VERBOSE ) ; this . info = info ; if ( ! compressor . useStandardCompression ( ) && compressor . getDecoderMapperName ( ) != null ) { this . info . setPackDecoderClassName ( compressor . getDecoderMapperName ( ) ) ; } } public Info getInfo ( ) { return info ; } public Map < String , Condition > getRules ( ) { return this . rules ; } public Map < String , List < DynamicVariable > > getDynamicVariables ( ) { return dynamicVariables ; } public List < DynamicInstallerRequirementValidator > getDynamicInstallerRequirements ( ) { return dynamicInstallerRequirements ; } public void addInstallerRequirements ( List < InstallerRequirement > conditions ) { this . installerRequirements = conditions ; } @ Override public void createInstaller ( ) throws Exception { info . setInstallerBase ( compilerData . getOutput ( ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ) ; sendStart ( ) ; writeInstaller ( ) ; getInstallerJar ( ) . closeAlways ( ) ; sendStop ( ) ; } protected boolean packSeparateJars ( ) { return info != null && info . getWebDirURL ( ) != null ; } protected void writeInstaller ( ) throws IOException { writeManifest ( ) ; writeSkeletonInstaller ( ) ; writeInstallerObject ( "<STR_LIT>" , info ) ; writeInstallerObject ( "<STR_LIT>" , properties ) ; writeInstallerObject ( "<STR_LIT>" , guiPrefs ) ; writeInstallerObject ( "<STR_LIT>" , panelList ) ; writeInstallerObject ( "<STR_LIT>" , customDataList ) ; writeInstallerObject ( "<STR_LIT>" , langpackNameList ) ; writeInstallerObject ( "<STR_LIT>" , rules ) ; writeInstallerObject ( "<STR_LIT>" , dynamicVariables ) ; writeInstallerObject ( "<STR_LIT>" , dynamicInstallerRequirements ) ; writeInstallerObject ( "<STR_LIT>" , installerRequirements ) ; writeInstallerResources ( ) ; writeIncludedJars ( ) ; writePacks ( ) ; } protected void writeManifest ( ) throws IOException { List < String > lines = IOUtils . readLines ( getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ) ; if ( splashScreenImage != null ) { String destination = String . format ( "<STR_LIT>" , splashScreenImage . getName ( ) ) ; mergeManager . addResourceToMerge ( splashScreenImage . getAbsolutePath ( ) , destination ) ; lines . add ( String . format ( "<STR_LIT>" , destination ) ) ; } lines . add ( "<STR_LIT>" ) ; File tempManifest = com . izforge . izpack . util . file . FileUtils . createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) ; FileUtils . writeLines ( tempManifest , lines ) ; mergeManager . addResourceToMerge ( tempManifest . getAbsolutePath ( ) , "<STR_LIT>" ) ; } protected void writeSkeletonInstaller ( ) throws IOException { sendMsg ( "<STR_LIT>" , PackagerListener . MSG_VERBOSE ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . merge ( installerJar ) ; } protected void writeInstallerObject ( String entryName , Object object ) throws IOException { installerJar . putNextEntry ( new org . apache . tools . zip . ZipEntry ( RESOURCES_PATH + entryName ) ) ; ObjectOutputStream out = new ObjectOutputStream ( installerJar ) ; try { out . writeObject ( object ) ; } catch ( IOException e ) { throw new IOException ( "<STR_LIT>" + object . getClass ( ) . getName ( ) + "<STR_LIT>" + entryName + "<STR_LIT:\">" , e ) ; } finally { out . flush ( ) ; installerJar . closeEntry ( ) ; } } protected void writeInstallerResources ( ) throws IOException { sendMsg ( "<STR_LIT>" + installerResourceURLMap . size ( ) + "<STR_LIT>" ) ; for ( Map . Entry < String , URL > stringURLEntry : installerResourceURLMap . entrySet ( ) ) { URL url = stringURLEntry . getValue ( ) ; InputStream in = url . openStream ( ) ; org . apache . tools . zip . ZipEntry newEntry = new org . apache . tools . zip . ZipEntry ( RESOURCES_PATH + stringURLEntry . getKey ( ) ) ; long dateTime = FileUtil . getFileDateTime ( url ) ; if ( dateTime != - <NUM_LIT:1> ) { newEntry . setTime ( dateTime ) ; } installerJar . putNextEntry ( newEntry ) ; IoHelper . copyStream ( in , installerJar ) ; installerJar . closeEntry ( ) ; in . close ( ) ; } } protected void writeIncludedJars ( ) throws IOException { sendMsg ( "<STR_LIT>" + includedJarURLs . size ( ) + "<STR_LIT>" ) ; for ( Object [ ] includedJarURL : includedJarURLs ) { InputStream is = ( ( URL ) includedJarURL [ <NUM_LIT:0> ] ) . openStream ( ) ; ZipInputStream inJarStream = new ZipInputStream ( is ) ; IoHelper . copyZip ( inJarStream , installerJar , ( List < String > ) includedJarURL [ <NUM_LIT:1> ] , alreadyWrittenFiles ) ; } } protected abstract void writePacks ( ) throws IOException ; protected JarOutputStream getInstallerJar ( ) { return installerJar ; } protected PackCompressor getCompressor ( ) { return compressor ; } protected void sendMsg ( String job ) { sendMsg ( job , PackagerListener . MSG_INFO ) ; } protected void sendMsg ( String job , int priority ) { if ( listener != null ) { listener . packagerMsg ( job , priority ) ; } } protected void sendStart ( ) { if ( listener != null ) { listener . packagerStart ( ) ; } } protected void sendStop ( ) { if ( listener != null ) { listener . packagerStop ( ) ; } } } </s>
<s> package com . izforge . izpack . compiler . packager . impl ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . ObjectOutputStream ; import java . util . List ; import java . util . Properties ; import java . util . Set ; import java . util . logging . Logger ; import org . apache . commons . io . FileUtils ; import org . apache . tools . zip . ZipEntry ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . PackFile ; import com . izforge . izpack . api . data . XPackFile ; import com . izforge . izpack . compiler . compressor . PackCompressor ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . listener . PackagerListener ; import com . izforge . izpack . compiler . merge . CompilerPathResolver ; import com . izforge . izpack . compiler . stream . JarOutputStream ; import com . izforge . izpack . core . io . FileSpanningOutputStream ; import com . izforge . izpack . data . ExecutableFile ; import com . izforge . izpack . data . PackInfo ; import com . izforge . izpack . data . ParsableFile ; import com . izforge . izpack . data . UpdateCheck ; import com . izforge . izpack . merge . MergeManager ; import com . izforge . izpack . merge . resolve . MergeableResolver ; import com . izforge . izpack . util . IoHelper ; public class MultiVolumePackager extends PackagerBase { private long maxFirstVolumeSize = FileSpanningOutputStream . DEFAULT_VOLUME_SIZE ; private long maxVolumeSize = FileSpanningOutputStream . DEFAULT_VOLUME_SIZE ; private static final String VOLUME_SIZE = "<STR_LIT>" ; private static final String FIRST_VOLUME_FREE_SPACE = "<STR_LIT>" ; private static final Logger logger = Logger . getLogger ( MultiVolumePackager . class . getName ( ) ) ; public MultiVolumePackager ( Properties properties , PackagerListener listener , JarOutputStream installerJar , MergeManager mergeManager , CompilerPathResolver pathResolver , MergeableResolver mergeableResolver , PackCompressor compressor , CompilerData compilerData ) { super ( properties , listener , installerJar , mergeManager , pathResolver , mergeableResolver , compressor , compilerData ) ; } public void setMaxFirstVolumeSize ( long size ) { maxFirstVolumeSize = size ; } public void setMaxVolumeSize ( long size ) { maxVolumeSize = size ; } public void addConfigurationInformation ( IXMLElement data ) { if ( data != null ) { long freeSpace = Long . valueOf ( data . getAttribute ( FIRST_VOLUME_FREE_SPACE , "<STR_LIT:0>" ) ) ; long size = Long . valueOf ( data . getAttribute ( VOLUME_SIZE , Long . toString ( maxVolumeSize ) ) ) ; setMaxFirstVolumeSize ( size - freeSpace ) ; setMaxVolumeSize ( size ) ; } } @ Override protected void writePacks ( ) throws IOException { String classname = getClass ( ) . getSimpleName ( ) ; getVariables ( ) . setProperty ( classname + "<STR_LIT:.>" + FIRST_VOLUME_FREE_SPACE , Long . toString ( maxFirstVolumeSize ) ) ; getVariables ( ) . setProperty ( classname + "<STR_LIT:.>" + VOLUME_SIZE , Long . toString ( maxVolumeSize ) ) ; List < PackInfo > packs = getPacksList ( ) ; final int count = packs . size ( ) ; sendMsg ( "<STR_LIT>" + count + "<STR_LIT>" + ( count > <NUM_LIT:1> ? "<STR_LIT:s>" : "<STR_LIT>" ) + "<STR_LIT>" ) ; logger . fine ( "<STR_LIT>" + count + "<STR_LIT>" + ( count > <NUM_LIT:1> ? "<STR_LIT:s>" : "<STR_LIT>" ) + "<STR_LIT>" ) ; logger . fine ( "<STR_LIT>" + maxFirstVolumeSize ) ; logger . fine ( "<STR_LIT>" + maxVolumeSize ) ; File volume = new File ( getInfo ( ) . getInstallerBase ( ) + "<STR_LIT>" ) . getAbsoluteFile ( ) ; int volumes = writePacks ( packs , volume ) ; logger . fine ( "<STR_LIT>" + volumes + "<STR_LIT>" ) ; JarOutputStream installerJar = getInstallerJar ( ) ; installerJar . putNextEntry ( new ZipEntry ( RESOURCES_PATH + "<STR_LIT>" ) ) ; ObjectOutputStream out = new ObjectOutputStream ( installerJar ) ; out . writeInt ( volumes ) ; out . writeUTF ( volume . getName ( ) ) ; out . flush ( ) ; installerJar . closeEntry ( ) ; installerJar . putNextEntry ( new ZipEntry ( RESOURCES_PATH + "<STR_LIT>" ) ) ; out = new ObjectOutputStream ( installerJar ) ; out . writeInt ( count ) ; for ( PackInfo pack : packs ) { out . writeObject ( pack . getPack ( ) ) ; } out . flush ( ) ; installerJar . closeEntry ( ) ; } private int writePacks ( List < PackInfo > packs , File volume ) throws IOException { FileSpanningOutputStream volumes = new FileSpanningOutputStream ( volume , maxFirstVolumeSize , maxVolumeSize ) ; File targetDir = volume . getParentFile ( ) ; if ( targetDir == null ) { throw new IOException ( "<STR_LIT>" + volume ) ; } for ( PackInfo packInfo : packs ) { writePack ( packInfo , volumes , targetDir ) ; } volumes . flush ( ) ; volumes . close ( ) ; return volumes . getVolumes ( ) ; } private void writePack ( PackInfo packInfo , FileSpanningOutputStream volumes , File targetDir ) throws IOException { Pack pack = packInfo . getPack ( ) ; pack . setFileSize ( <NUM_LIT:0> ) ; String name = pack . getName ( ) ; sendMsg ( "<STR_LIT>" + name , PackagerListener . MSG_VERBOSE ) ; logger . fine ( "<STR_LIT>" + name ) ; ZipEntry entry = new ZipEntry ( RESOURCES_PATH + "<STR_LIT>" + name ) ; JarOutputStream installerJar = getInstallerJar ( ) ; installerJar . putNextEntry ( entry ) ; ObjectOutputStream packStream = new ObjectOutputStream ( installerJar ) ; writePackFiles ( packInfo , volumes , pack , packStream , targetDir ) ; packStream . writeInt ( packInfo . getParsables ( ) . size ( ) ) ; for ( ParsableFile file : packInfo . getParsables ( ) ) { packStream . writeObject ( file ) ; } packStream . writeInt ( packInfo . getExecutables ( ) . size ( ) ) ; for ( ExecutableFile file : packInfo . getExecutables ( ) ) { packStream . writeObject ( file ) ; } packStream . writeInt ( packInfo . getUpdateChecks ( ) . size ( ) ) ; for ( UpdateCheck check : packInfo . getUpdateChecks ( ) ) { packStream . writeObject ( check ) ; } packStream . flush ( ) ; } private void writePackFiles ( PackInfo packInfo , FileSpanningOutputStream volumes , Pack pack , ObjectOutputStream packStream , File targetDir ) throws IOException { Set < PackFile > files = packInfo . getPackFiles ( ) ; packStream . writeInt ( files . size ( ) ) ; for ( PackFile packfile : files ) { XPackFile pf = new XPackFile ( packfile ) ; File file = packInfo . getFile ( packfile ) ; logger . fine ( "<STR_LIT>" + file . getAbsolutePath ( ) ) ; if ( ! pf . isDirectory ( ) ) { if ( ! pack . isLoose ( ) ) { writePackFile ( file , volumes , pf ) ; } else { FileUtils . copyFile ( file , new File ( targetDir , pf . getRelativeSourcePath ( ) ) ) ; } } packStream . writeObject ( pf ) ; packStream . flush ( ) ; pack . addFileSize ( pf . length ( ) ) ; } if ( pack . getFileSize ( ) > pack . getSize ( ) ) { pack . setSize ( pack . getFileSize ( ) ) ; } } private void writePackFile ( File file , FileSpanningOutputStream volumes , XPackFile packFile ) throws IOException { long beforePosition = volumes . getFilePointer ( ) ; packFile . setArchiveFilePosition ( beforePosition ) ; int volumeCount = volumes . getVolumes ( ) ; FileInputStream in = new FileInputStream ( file ) ; long bytesWritten = IoHelper . copyStream ( in , volumes ) ; long afterPosition = volumes . getFilePointer ( ) ; logger . fine ( "<STR_LIT>" + packFile . sourcePath + "<STR_LIT>" + beforePosition + "<STR_LIT>" + afterPosition ) ; if ( volumes . getFilePointer ( ) != ( beforePosition + bytesWritten ) ) { logger . fine ( "<STR_LIT>" + file . getName ( ) ) ; logger . fine ( "<STR_LIT>" + beforePosition + "<STR_LIT:/>" + bytesWritten + "<STR_LIT:/>" + ( beforePosition + bytesWritten ) + "<STR_LIT:/>" + volumes . getFilePointer ( ) + "<STR_LIT:)>" ) ; logger . fine ( "<STR_LIT>" + volumeCount + "<STR_LIT:/>" + volumes . getVolumes ( ) + "<STR_LIT:)>" ) ; throw new IOException ( "<STR_LIT>" ) ; } if ( bytesWritten != packFile . length ( ) ) { throw new IOException ( "<STR_LIT>" + file ) ; } in . close ( ) ; } } </s>
<s> package com . izforge . izpack . compiler . bootstrap ; import java . util . Date ; import com . izforge . izpack . compiler . CompilerConfig ; import com . izforge . izpack . compiler . container . CompilerContainer ; import com . izforge . izpack . compiler . exception . HelpRequestedException ; import com . izforge . izpack . compiler . exception . NoArgumentException ; public class CompilerLauncher { public static void main ( String [ ] args ) { int exitCode = <NUM_LIT:1> ; try { CompilerContainer compilerContainer = new CompilerContainer ( ) ; compilerContainer . processCompileDataFromArgs ( args ) ; CompilerConfig compiler = compilerContainer . getComponent ( CompilerConfig . class ) ; compiler . executeCompiler ( ) ; while ( compiler . isAlive ( ) ) { Thread . sleep ( <NUM_LIT:100> ) ; } if ( compiler . wasSuccessful ( ) ) { exitCode = <NUM_LIT:0> ; } System . out . println ( "<STR_LIT>" + new Date ( ) ) ; } catch ( NoArgumentException ignored ) { } catch ( HelpRequestedException ignored ) { } catch ( Exception err ) { System . err . println ( "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" + err . getMessage ( ) ) ; err . printStackTrace ( ) ; System . err . println ( "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" ) ; } System . exit ( exitCode ) ; } } </s>
<s> package com . izforge . izpack . compiler . exception ; public class HelpRequestedException extends RuntimeException { } </s>
<s> package com . izforge . izpack . compiler . exception ; public class NoArgumentException extends RuntimeException { } </s>
<s> package com . izforge . izpack . compiler . data ; import java . io . File ; import java . net . URI ; import java . net . URL ; import java . util . ResourceBundle ; import com . izforge . izpack . api . data . Info ; import com . izforge . izpack . util . FileUtil ; public class CompilerData { public static String IZPACK_HOME = "<STR_LIT:.>" ; public final static String VERSION = "<STR_LIT>" ; public final static String STANDARD = "<STR_LIT>" ; public final static String WEB = "<STR_LIT>" ; private String comprFormat = "<STR_LIT:default>" ; private String kind = STANDARD ; private String installFile ; private String installText ; protected String basedir ; private String output ; private boolean mkdirs = false ; private int comprLevel = - <NUM_LIT:1> ; Info externalInfo = new Info ( ) ; public final static String IZPACK_VERSION = ResourceBundle . getBundle ( "<STR_LIT:version>" ) . getString ( "<STR_LIT>" ) ; private final static String IZ_TEST_FILE = "<STR_LIT>" ; private final static String IZ_TEST_SUBDIR = "<STR_LIT>" + File . separator + "<STR_LIT>" + File . separator + "<STR_LIT>" ; private CompilerData ( ) { String izHome = System . getProperty ( "<STR_LIT>" ) ; if ( izHome != null ) { IZPACK_HOME = izHome ; } else { izHome = System . getenv ( "<STR_LIT>" ) ; if ( izHome != null ) { IZPACK_HOME = izHome ; } } } public CompilerData ( String installFile , String basedir , String output , boolean mkdirs ) { this ( ) ; this . installFile = installFile ; this . basedir = basedir ; this . output = output ; this . mkdirs = mkdirs ; } public CompilerData ( String comprFormat , String kind , String installFile , String installText , String basedir , String output , boolean mkdirs , int comprLevel ) { this ( installFile , basedir , output , mkdirs ) ; this . comprFormat = comprFormat ; this . kind = kind ; this . installText = installText ; this . comprLevel = comprLevel ; } public CompilerData ( String comprFormat , String kind , String installFile , String installText , String basedir , String output , boolean mkdirs , int comprLevel , Info externalInfo ) { this ( comprFormat , kind , installFile , installText , basedir , output , mkdirs , comprLevel ) ; this . externalInfo = externalInfo ; } public static void setIzpackHome ( String izHome ) { IZPACK_HOME = izHome ; } public String getKind ( ) { return kind ; } public void setKind ( String kind ) { this . kind = kind ; } public String getInstallFile ( ) { return installFile ; } public String getInstallText ( ) { return installText ; } public String getBasedir ( ) { return basedir ; } public void setBasedir ( String basedir ) { this . basedir = basedir ; } public String getOutput ( ) { return output ; } public boolean isMkdirs ( ) { return mkdirs ; } public void setMkdirs ( boolean mkdirs ) { this . mkdirs = mkdirs ; } public String getComprFormat ( ) { return comprFormat ; } public void setComprFormat ( String comprFormat ) { this . comprFormat = comprFormat ; } public int getComprLevel ( ) { return comprLevel ; } public void setComprLevel ( int comprLevel ) { this . comprLevel = comprLevel ; } public Info getExternalInfo ( ) { return this . externalInfo ; } public void resolveIzpackHome ( ) { IZPACK_HOME = resolveIzPackHome ( IZPACK_HOME ) ; } private static String resolveIzPackHome ( String home ) { File test = new File ( home , IZ_TEST_SUBDIR + File . separator + IZ_TEST_FILE ) ; if ( test . exists ( ) ) { return ( home ) ; } String self = CompilerData . class . getName ( ) ; self = self . replace ( '<CHAR_LIT:.>' , '<CHAR_LIT:/>' ) ; self = "<STR_LIT:/>" + self + "<STR_LIT:.class>" ; URL url = Compiler . class . getResource ( self ) ; String name = FileUtil . convertUrlToFilePath ( url ) ; int start = name . indexOf ( self ) ; name = name . substring ( <NUM_LIT:0> , start ) ; if ( name . endsWith ( "<STR_LIT:!>" ) ) { if ( name . endsWith ( "<STR_LIT>" ) || name . endsWith ( "<STR_LIT>" ) || name . matches ( "<STR_LIT>" ) ) { return ( "<STR_LIT:.>" ) ; } name = name . substring ( <NUM_LIT:0> , name . length ( ) - <NUM_LIT:1> ) ; } File root ; if ( URI . create ( name ) . isAbsolute ( ) ) { root = new File ( URI . create ( name ) ) ; } else { root = new File ( name ) ; } while ( true ) { if ( root == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } test = new File ( root , IZ_TEST_SUBDIR + File . separator + IZ_TEST_FILE ) ; if ( test . exists ( ) ) { return ( root . getAbsolutePath ( ) ) ; } root = root . getParentFile ( ) ; } } } </s>
<s> package com . izforge . izpack . compiler . data ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . StringReader ; import java . io . StringWriter ; import java . util . Enumeration ; import java . util . Properties ; import java . util . Vector ; import org . apache . tools . ant . taskdefs . Execute ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . exception . CompilerException ; import com . izforge . izpack . api . substitutor . SubstitutionType ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . compiler . helper . AssertionHelper ; import com . izforge . izpack . compiler . listener . PackagerListener ; public class PropertyManager { private Properties properties ; private CompilerData compilerData ; private VariableSubstitutor variableSubstitutor ; private PackagerListener packagerListener ; private AssertionHelper assertionHelper ; public PropertyManager ( Properties properties , VariableSubstitutor variableSubstitutor , CompilerData compilerData , PackagerListener packagerListener , AssertionHelper assertionHelper ) { this . assertionHelper = assertionHelper ; this . properties = properties ; this . variableSubstitutor = variableSubstitutor ; this . compilerData = compilerData ; this . packagerListener = packagerListener ; this . setProperty ( "<STR_LIT>" , CompilerData . IZPACK_VERSION ) ; this . setProperty ( "<STR_LIT>" , compilerData . getBasedir ( ) ) ; } public boolean addProperty ( String name , String value ) { if ( properties . containsKey ( name ) ) { return false ; } addPropertySubstitute ( name , value ) ; return true ; } public boolean setProperty ( String name , String value ) { if ( System . getProperties ( ) . containsKey ( name ) ) { return false ; } addPropertySubstitute ( name , value ) ; return true ; } public String getProperty ( String name ) { return properties . getProperty ( name ) ; } public void execute ( IXMLElement xmlProp ) throws CompilerException { File file = null ; String name = xmlProp . getAttribute ( "<STR_LIT:name>" ) ; String value = xmlProp . getAttribute ( "<STR_LIT:value>" ) ; String environnement = xmlProp . getAttribute ( "<STR_LIT>" ) ; if ( environnement != null && ! environnement . endsWith ( "<STR_LIT:.>" ) ) { environnement += "<STR_LIT:.>" ; } String prefix = xmlProp . getAttribute ( "<STR_LIT>" ) ; if ( prefix != null && ! prefix . endsWith ( "<STR_LIT:.>" ) ) { prefix += "<STR_LIT:.>" ; } String filename = xmlProp . getAttribute ( "<STR_LIT:file>" ) ; if ( filename != null ) { file = new File ( filename ) ; } if ( name != null ) { if ( value == null ) { assertionHelper . parseError ( xmlProp , "<STR_LIT>" ) ; } } else { if ( file == null && environnement == null ) { assertionHelper . parseError ( xmlProp , "<STR_LIT>" ) ; } } if ( file == null && prefix != null ) { assertionHelper . parseError ( xmlProp , "<STR_LIT>" ) ; } if ( ( name != null ) && ( value != null ) ) { addProperty ( name , value ) ; } else if ( file != null ) { loadFile ( file , xmlProp , prefix ) ; } else if ( environnement != null ) { loadEnvironment ( environnement , xmlProp , file ) ; } } private void loadFile ( File file , IXMLElement xmlProp , String prefix ) throws CompilerException { Properties props = new Properties ( ) ; packagerListener . packagerMsg ( "<STR_LIT>" + file . getAbsolutePath ( ) , PackagerListener . MSG_VERBOSE ) ; try { if ( file . exists ( ) ) { FileInputStream fis = new FileInputStream ( file ) ; try { props . load ( fis ) ; } finally { fis . close ( ) ; } addProperties ( props , xmlProp , file , prefix ) ; } else { packagerListener . packagerMsg ( "<STR_LIT>" + file . getAbsolutePath ( ) , PackagerListener . MSG_VERBOSE ) ; } } catch ( IOException ex ) { assertionHelper . parseError ( xmlProp , "<STR_LIT>" + file . getAbsolutePath ( ) , ex ) ; } } protected void loadEnvironment ( String prefix , IXMLElement xmlProp , File file ) throws CompilerException { Properties props = new Properties ( ) ; packagerListener . packagerMsg ( "<STR_LIT>" + prefix , PackagerListener . MSG_VERBOSE ) ; Vector osEnv = Execute . getProcEnvironment ( ) ; for ( Enumeration e = osEnv . elements ( ) ; e . hasMoreElements ( ) ; ) { String entry = ( String ) e . nextElement ( ) ; int pos = entry . indexOf ( '<CHAR_LIT:=>' ) ; if ( pos == - <NUM_LIT:1> ) { packagerListener . packagerMsg ( "<STR_LIT>" + prefix , PackagerListener . MSG_WARN ) ; } else { props . put ( prefix + entry . substring ( <NUM_LIT:0> , pos ) , entry . substring ( pos + <NUM_LIT:1> ) ) ; } } addProperties ( props , xmlProp , file , prefix ) ; } public void addProperties ( Properties props , IXMLElement xmlProp , File file , String prefix ) throws CompilerException { resolveAllProperties ( props , xmlProp , file ) ; Enumeration e = props . keys ( ) ; while ( e . hasMoreElements ( ) ) { String name = ( String ) e . nextElement ( ) ; String value = props . getProperty ( name ) ; if ( prefix != null ) { name = prefix + name ; } addPropertySubstitute ( name , value ) ; } } private void addPropertySubstitute ( String name , String value ) { try { value = variableSubstitutor . substitute ( value , SubstitutionType . TYPE_AT ) ; } catch ( Exception e ) { } properties . put ( name , value ) ; } private void resolveAllProperties ( Properties props , IXMLElement xmlProp , File file ) throws CompilerException { variableSubstitutor . setBracesRequired ( true ) ; for ( Enumeration e = props . keys ( ) ; e . hasMoreElements ( ) ; ) { String name = ( String ) e . nextElement ( ) ; String value = props . getProperty ( name ) ; int mods = - <NUM_LIT:1> ; do { StringReader read = new StringReader ( value ) ; StringWriter write = new StringWriter ( ) ; try { try { mods = variableSubstitutor . substitute ( read , write , SubstitutionType . TYPE_AT ) ; } catch ( Exception e1 ) { throw new IOException ( e1 . getMessage ( ) ) ; } props . put ( name , value ) ; } catch ( IOException ex ) { assertionHelper . parseError ( xmlProp , "<STR_LIT>" + file . getAbsolutePath ( ) , ex ) ; } } while ( mods != <NUM_LIT:0> ) ; } } } </s>
<s> package com . izforge . izpack . compiler . listener ; public class CmdlinePackagerListener implements PackagerListener { public void packagerMsg ( String info ) { packagerMsg ( info , MSG_INFO ) ; } public void packagerMsg ( String info , int priority ) { final String prefix ; switch ( priority ) { case MSG_DEBUG : prefix = "<STR_LIT>" ; break ; case MSG_ERR : prefix = "<STR_LIT>" ; break ; case MSG_WARN : prefix = "<STR_LIT>" ; break ; case MSG_INFO : case MSG_VERBOSE : default : prefix = "<STR_LIT>" ; } System . out . println ( prefix + info ) ; } public void packagerStart ( ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( ) ; } public void packagerStop ( ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" ) ; } } </s>
<s> package com . izforge . izpack . compiler . listener ; public interface PackagerListener { public static final int MSG_DEBUG = <NUM_LIT:0> ; public static final int MSG_ERR = <NUM_LIT:1> ; public static final int MSG_INFO = <NUM_LIT:2> ; public static final int MSG_VERBOSE = <NUM_LIT:3> ; public static final int MSG_WARN = <NUM_LIT:4> ; public void packagerMsg ( String info ) ; public void packagerMsg ( String info , int priority ) ; public void packagerStart ( ) ; public void packagerStop ( ) ; } </s>
<s> package com . izforge . izpack . compiler . listener ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . exception . CompilerException ; import com . izforge . izpack . compiler . packager . IPackager ; import java . util . Map ; public interface CompilerListener { public final static int BEGIN = <NUM_LIT:1> ; public final static int END = <NUM_LIT:2> ; Map reviseAdditionalDataMap ( Map existentDataMap , IXMLElement element ) throws CompilerException ; void notify ( String position , int state , IXMLElement data , IPackager packager ) ; } </s>
<s> package com . izforge . izpack . compiler . listener ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . exception . CompilerException ; import com . izforge . izpack . compiler . packager . IPackager ; import com . izforge . izpack . data . PackInfo ; import java . util . Map ; public class SimpleCompilerListener implements CompilerListener { public SimpleCompilerListener ( ) { super ( ) ; } public Map reviseAdditionalDataMap ( Map existentDataMap , IXMLElement element ) throws CompilerException { return null ; } public void afterPack ( PackInfo pack , int packNumber , IPackager packager ) { } public void beforePack ( PackInfo pack , int packNumber , IPackager packager ) { } public void notify ( String position , int state , IXMLElement data , IPackager packager ) { } } </s>
<s> package com . izforge . izpack . compiler ; import java . io . IOException ; import java . net . URL ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Set ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . PackColor ; import com . izforge . izpack . api . data . binding . OsModel ; import com . izforge . izpack . api . data . binding . Stage ; import com . izforge . izpack . api . event . InstallerListener ; import com . izforge . izpack . api . event . UninstallerListener ; import com . izforge . izpack . api . exception . CompilerException ; import com . izforge . izpack . api . exception . IzPackClassNotFoundException ; import com . izforge . izpack . compiler . helper . CompilerHelper ; import com . izforge . izpack . compiler . util . CompilerClassLoader ; import com . izforge . izpack . compiler . packager . IPackager ; import com . izforge . izpack . data . CustomData ; import com . izforge . izpack . data . PackInfo ; public class Compiler extends Thread { private IPackager packager ; private boolean compileFailed = true ; private final CompilerHelper compilerHelper ; private final CompilerClassLoader loader ; private static final Logger logger = Logger . getLogger ( Compiler . class . getName ( ) ) ; public Compiler ( CompilerClassLoader loader , CompilerHelper compilerHelper ) { this . loader = loader ; this . compilerHelper = compilerHelper ; } public void setPackager ( IPackager packager ) { this . packager = packager ; } @ Override public void run ( ) { try { createInstaller ( ) ; } catch ( CompilerException ce ) { logger . severe ( ce . getMessage ( ) ) ; } catch ( Exception e ) { logger . log ( Level . SEVERE , e . getMessage ( ) , e ) ; } } public void createInstaller ( ) throws Exception { packager . createInstaller ( ) ; this . compileFailed = false ; } public boolean wasSuccessful ( ) { return ! this . compileFailed ; } public void checkDependencies ( ) throws CompilerException { checkDependencies ( packager . getPacksList ( ) ) ; } public void checkExcludes ( ) throws CompilerException { checkExcludes ( packager . getPacksList ( ) ) ; } public void checkExcludes ( List < PackInfo > packs ) throws CompilerException { for ( int q = <NUM_LIT:0> ; q < packs . size ( ) ; q ++ ) { PackInfo packinfo1 = packs . get ( q ) ; Pack pack1 = packinfo1 . getPack ( ) ; for ( int w = <NUM_LIT:0> ; w < q ; w ++ ) { PackInfo packinfo2 = packs . get ( w ) ; Pack pack2 = packinfo2 . getPack ( ) ; if ( pack1 . getExcludeGroup ( ) != null && pack2 . getExcludeGroup ( ) != null ) { if ( pack1 . getExcludeGroup ( ) . equals ( pack2 . getExcludeGroup ( ) ) ) { if ( pack1 . isPreselected ( ) && pack2 . isPreselected ( ) ) { error ( "<STR_LIT>" + pack1 . getName ( ) + "<STR_LIT:U+0020andU+0020>" + pack2 . getName ( ) + "<STR_LIT>" + pack1 . getExcludeGroup ( ) + "<STR_LIT>" ) ; } } } } } } public void checkDependencies ( List < PackInfo > packs ) throws CompilerException { Map < String , PackInfo > names = new HashMap < String , PackInfo > ( ) ; for ( PackInfo pack : packs ) { names . put ( pack . getPack ( ) . getName ( ) , pack ) ; } int result = dfs ( packs , names ) ; if ( result == - <NUM_LIT:2> ) { error ( "<STR_LIT>" ) ; } else if ( result == - <NUM_LIT:1> ) { error ( "<STR_LIT>" ) ; } } private int dfs ( List < PackInfo > packs , Map < String , PackInfo > names ) { Map < Edge , PackColor > edges = new HashMap < Edge , PackColor > ( ) ; for ( PackInfo pack : packs ) { if ( pack . colour == PackColor . WHITE ) { if ( dfsVisit ( pack , names , edges ) != <NUM_LIT:0> ) { return - <NUM_LIT:1> ; } } } return checkBackEdges ( edges ) ; } private int checkBackEdges ( Map < Edge , PackColor > edges ) { Set < Edge > keys = edges . keySet ( ) ; for ( final Edge key : keys ) { PackColor color = edges . get ( key ) ; if ( color == PackColor . GREY ) { return - <NUM_LIT:2> ; } } return <NUM_LIT:0> ; } private class Edge { PackInfo u ; PackInfo v ; Edge ( PackInfo u , PackInfo v ) { this . u = u ; this . v = v ; } } private int dfsVisit ( PackInfo u , Map < String , PackInfo > names , Map < Edge , PackColor > edges ) { u . colour = PackColor . GREY ; List < String > deps = u . getDependencies ( ) ; if ( deps != null ) { for ( String name : deps ) { PackInfo v = names . get ( name ) ; if ( v == null ) { System . out . println ( "<STR_LIT>" + name ) ; return - <NUM_LIT:1> ; } Edge edge = new Edge ( u , v ) ; if ( edges . get ( edge ) == null ) { edges . put ( edge , v . colour ) ; } if ( v . colour == PackColor . WHITE ) { final int result = dfsVisit ( v , names , edges ) ; if ( result != <NUM_LIT:0> ) { return result ; } } } } u . colour = PackColor . BLACK ; return <NUM_LIT:0> ; } private void error ( String message ) throws CompilerException { compileFailed = true ; throw new CompilerException ( message ) ; } public void addJar ( URL url , boolean uninstaller ) throws IOException { loader . addURL ( url ) ; List < String > paths = compilerHelper . getContainedFilePaths ( url ) ; if ( uninstaller ) { CustomData data = new CustomData ( null , paths , null , CustomData . UNINSTALLER_JAR ) ; packager . addCustomJar ( data , url ) ; } else { packager . addJarContent ( url ) ; } } public void addListener ( String className , Stage stage , List < OsModel > constraints ) { int type = ( stage == Stage . install ) ? CustomData . INSTALLER_LISTENER : CustomData . UNINSTALLER_LISTENER ; Class clazz ; if ( stage == Stage . install ) { clazz = loader . loadClass ( className , InstallerListener . class ) ; } else { clazz = loader . loadClass ( className , UninstallerListener . class ) ; } CustomData data = new CustomData ( clazz . getName ( ) , null , constraints , type ) ; packager . addCustomJar ( data , null ) ; } } </s>
<s> package com . izforge . izpack . compiler . merge ; import java . io . File ; import java . io . FileFilter ; import java . util . ArrayList ; import java . util . List ; import org . apache . tools . zip . ZipOutputStream ; import com . izforge . izpack . api . merge . Mergeable ; public class PanelMerge implements Mergeable { private List < Mergeable > packageMerge ; private Class panelClass ; private FileFilter fileFilter ; public PanelMerge ( final Class panelClass , List < Mergeable > packageMergeable ) { this . panelClass = panelClass ; packageMerge = packageMergeable ; fileFilter = new FileFilter ( ) { public boolean accept ( File pathname ) { return pathname . isDirectory ( ) || pathname . getAbsolutePath ( ) . contains ( "<STR_LIT:/>" + panelClass + "<STR_LIT:.class>" ) ; } } ; } public void merge ( ZipOutputStream outputStream ) { for ( Mergeable mergeable : packageMerge ) { mergeable . merge ( outputStream ) ; } } public List < File > recursivelyListFiles ( FileFilter fileFilter ) { ArrayList < File > result = new ArrayList < File > ( ) ; for ( Mergeable mergeable : packageMerge ) { result . addAll ( mergeable . recursivelyListFiles ( fileFilter ) ) ; } return result ; } public File find ( FileFilter fileFilter ) { for ( Mergeable mergeable : packageMerge ) { File file = mergeable . find ( fileFilter ) ; if ( file != null ) { return file ; } } return null ; } public void merge ( java . util . zip . ZipOutputStream outputStream ) { for ( Mergeable mergeable : packageMerge ) { mergeable . merge ( outputStream ) ; } } public Class getPanelClass ( ) { return panelClass ; } @ Override public String toString ( ) { return "<STR_LIT>" + "<STR_LIT>" + packageMerge + "<STR_LIT>" + panelClass + "<STR_LIT>" + fileFilter + '<CHAR_LIT:}>' ; } } </s>
<s> package com . izforge . izpack . compiler . merge ; import java . io . IOException ; import java . net . URL ; import java . util . ArrayList ; import java . util . Enumeration ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Properties ; import com . izforge . izpack . api . exception . CompilerException ; import com . izforge . izpack . api . merge . Mergeable ; import com . izforge . izpack . compiler . util . CompilerClassLoader ; import com . izforge . izpack . installer . automation . PanelAutomationHelper ; import com . izforge . izpack . installer . console . AbstractPanelConsole ; import com . izforge . izpack . installer . gui . IzPanel ; import com . izforge . izpack . merge . resolve . MergeableResolver ; import com . izforge . izpack . merge . resolve . PathResolver ; public class CompilerPathResolver extends PathResolver { private final CompilerClassLoader loader ; private final Properties panelDependencies ; public CompilerPathResolver ( MergeableResolver mergeableResolver , CompilerClassLoader loader , Properties panelDependencies ) { super ( mergeableResolver ) ; this . loader = loader ; this . panelDependencies = panelDependencies ; } public PanelMerge getPanelMerge ( String className ) { Class type = loader . loadClass ( className , IzPanel . class ) ; Map < String , List < Mergeable > > mergeableByPackage = new HashMap < String , List < Mergeable > > ( ) ; List < Mergeable > mergeable = new ArrayList < Mergeable > ( ) ; getMergeableByPackage ( type , mergeableByPackage ) ; for ( List < Mergeable > pkg : mergeableByPackage . values ( ) ) { mergeable . addAll ( pkg ) ; } return new PanelMerge ( type , mergeable ) ; } public List < Mergeable > getMergeablePackage ( Package merge ) { List < Mergeable > result = new ArrayList < Mergeable > ( ) ; String destination = merge . getName ( ) . replaceAll ( "<STR_LIT:\\.>" , "<STR_LIT:/>" ) ; Enumeration < URL > urls ; try { urls = getClass ( ) . getClassLoader ( ) . getResources ( destination ) ; } catch ( IOException exception ) { throw new CompilerException ( "<STR_LIT>" + merge . getName ( ) , exception ) ; } MergeableResolver mergeableResolver = getMergeableResolver ( ) ; while ( urls . hasMoreElements ( ) ) { URL obtainPackage = urls . nextElement ( ) ; result . add ( mergeableResolver . getMergeableFromURLWithDestination ( obtainPackage , destination + "<STR_LIT:/>" ) ) ; } return result ; } private void getMergeableByPackage ( Class type , Map < String , List < Mergeable > > mergeable ) { String pkg = type . getPackage ( ) . getName ( ) ; if ( ! mergeable . containsKey ( pkg ) ) { mergeable . put ( pkg , getMergeablePackage ( type . getPackage ( ) ) ) ; if ( panelDependencies . containsKey ( type . getSimpleName ( ) ) ) { String dependPackage = ( String ) panelDependencies . get ( type . getSimpleName ( ) ) ; if ( ! mergeable . containsKey ( dependPackage ) ) { mergeable . put ( dependPackage , getMergeableFromPackageName ( dependPackage ) ) ; } } for ( Class iface : type . getInterfaces ( ) ) { getMergeableByPackage ( iface , mergeable ) ; } Class superClass = type . getSuperclass ( ) ; if ( superClass != null && ! superClass . equals ( IzPanel . class ) && ! superClass . equals ( AbstractPanelConsole . class ) && ! superClass . equals ( PanelAutomationHelper . class ) && ! superClass . equals ( Object . class ) ) { getMergeableByPackage ( superClass , mergeable ) ; } } } } </s>
<s> package com . izforge . izpack . event ; import java . io . ByteArrayOutputStream ; import java . io . File ; import java . io . InputStream ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . logging . Logger ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . PackFile ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . event . ProgressNotifiers ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . util . file . FileUtils ; import com . izforge . izpack . util . helper . SpecHelper ; public class BSFInstallerListener extends AbstractProgressInstallerListener { public static final String SPEC_FILE_NAME = "<STR_LIT>" ; private final Map < String , List < BSFAction > > actions = new HashMap < String , List < BSFAction > > ( ) ; private final List < BSFAction > uninstActions = new ArrayList < BSFAction > ( ) ; private final VariableSubstitutor replacer ; private UninstallData uninstallData ; private final Resources resources ; private SpecHelper spec ; private static final Logger logger = Logger . getLogger ( BSFInstallerListener . class . getName ( ) ) ; public BSFInstallerListener ( InstallData installData , VariableSubstitutor replacer , Resources resources , UninstallData uninstallData , ProgressNotifiers notifiers ) { super ( installData , notifiers ) ; this . replacer = replacer ; this . uninstallData = uninstallData ; this . resources = resources ; spec = new SpecHelper ( resources ) ; } @ Override public void initialise ( ) { try { spec . readSpec ( SPEC_FILE_NAME , replacer ) ; } catch ( Exception exception ) { throw new IzPackException ( "<STR_LIT>" + SPEC_FILE_NAME , exception ) ; } } @ Override public void beforePacks ( List < Pack > packs ) { if ( spec == null ) { return ; } for ( Pack pack : packs ) { IXMLElement packElement = spec . getPackForName ( pack . getName ( ) ) ; if ( packElement == null ) { continue ; } List < BSFAction > packActions = new ArrayList < BSFAction > ( ) ; List < IXMLElement > scriptEntries = packElement . getChildrenNamed ( "<STR_LIT>" ) ; if ( scriptEntries != null && ! scriptEntries . isEmpty ( ) ) { for ( IXMLElement scriptEntry : scriptEntries ) { BSFAction action = readAction ( scriptEntry ) ; if ( action != null ) { packActions . add ( action ) ; String script = action . getScript ( ) . toLowerCase ( ) ; if ( script . contains ( BSFAction . BEFOREDELETE ) || script . contains ( BSFAction . AFTERDELETE ) || script . contains ( BSFAction . BEFOREDELETION ) || script . contains ( BSFAction . AFTERDELETION ) ) { uninstActions . add ( action ) ; } } } if ( ! packActions . isEmpty ( ) ) { setProgressNotifier ( ) ; } } actions . put ( pack . getName ( ) , packActions ) ; } for ( Pack pack : packs ) { performAllActions ( pack , ActionBase . BEFOREPACKS , null , packs , packs . size ( ) ) ; } } @ Override public void beforePack ( Pack pack , int i ) { performAllActions ( pack , ActionBase . BEFOREPACK , null , pack , i ) ; } @ Override public void afterPack ( Pack pack , int i ) { performAllActions ( pack , ActionBase . AFTERPACK , null , pack , i ) ; } @ Override public void afterPacks ( List < Pack > packs , ProgressListener listener ) { if ( notifyProgress ( ) ) { listener . nextStep ( getMessage ( "<STR_LIT>" ) , getProgressNotifierId ( ) , getActionCount ( packs ) ) ; } for ( Pack pack : packs ) { performAllActions ( pack , ActionBase . AFTERPACKS , listener , packs ) ; } if ( ! uninstActions . isEmpty ( ) ) { uninstallData . addAdditionalData ( "<STR_LIT>" , uninstActions ) ; } } @ Override public boolean isFileListener ( ) { return true ; } @ Override public void beforeDir ( File dir , PackFile packFile , Pack pack ) { performAllActions ( pack , BSFAction . BEFOREDIR , null , dir , packFile ) ; } @ Override public void afterDir ( File dir , PackFile packFile , Pack pack ) { performAllActions ( pack , BSFAction . AFTERDIR , null , dir , packFile ) ; } @ Override public void beforeFile ( File file , PackFile packFile , Pack pack ) { performAllActions ( pack , BSFAction . BEFOREFILE , null , file , packFile ) ; } @ Override public void afterFile ( File file , PackFile packFile , Pack pack ) { performAllActions ( pack , BSFAction . AFTERFILE , null , file , packFile ) ; } private int getActionCount ( List < Pack > packs ) { int count = <NUM_LIT:0> ; for ( Pack pack : packs ) { List < BSFAction > actList = actions . get ( pack . getName ( ) ) ; if ( actList != null ) { count += actList . size ( ) ; } } return ( count ) ; } private void performAllActions ( Pack pack , String order , ProgressListener listener , Object ... args ) { String packName = pack . getName ( ) ; List < BSFAction > actList = actions . get ( packName ) ; if ( actList == null || actList . isEmpty ( ) ) { return ; } logger . fine ( "<STR_LIT>" + order + "<STR_LIT>" + packName + "<STR_LIT>" ) ; for ( BSFAction act : actList ) { if ( notifyProgress ( ) && order . equals ( ActionBase . AFTERPACKS ) ) { listener . progress ( ( act . getMessageID ( ) != null ) ? getMessage ( act . getMessageID ( ) ) : "<STR_LIT>" ) ; } if ( ActionBase . BEFOREPACKS . equalsIgnoreCase ( order ) ) { act . init ( ) ; } act . execute ( order , args , getInstallData ( ) ) ; if ( ActionBase . AFTERPACKS . equalsIgnoreCase ( order ) ) { act . destroy ( ) ; } } } private BSFAction readAction ( IXMLElement element ) { BSFAction action = new BSFAction ( ) ; String src = element . getAttribute ( "<STR_LIT:src>" ) ; if ( src != null ) { InputStream is = null ; InputStream subis = null ; ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; try { byte buf [ ] = new byte [ <NUM_LIT:10> * <NUM_LIT> ] ; int read ; is = resources . getInputStream ( src ) ; subis = new SpecHelper ( resources ) . substituteVariables ( is , replacer ) ; while ( ( read = subis . read ( buf ) ) != - <NUM_LIT:1> ) { baos . write ( buf , <NUM_LIT:0> , read ) ; } action . setScript ( new String ( baos . toByteArray ( ) ) ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new InstallerException ( exception ) ; } finally { FileUtils . close ( subis ) ; FileUtils . close ( is ) ; } } else { String script = element . getContent ( ) ; if ( script == null ) { script = "<STR_LIT>" ; } action . setScript ( script ) ; } String language = element . getAttribute ( "<STR_LIT>" ) ; action . setLanguage ( language ) ; return action ; } } </s>
<s> package com . izforge . izpack . event ; import java . util . ArrayList ; import java . util . List ; import java . util . logging . Logger ; public class ConfigurationAction extends ActionBase { private static final long serialVersionUID = <NUM_LIT> ; private static final transient Logger logger = Logger . getLogger ( ConfigurationAction . class . getName ( ) ) ; private List < ConfigurationActionTask > actionTasks = null ; public ConfigurationAction ( ) { super ( ) ; } public void performInstallAction ( ) throws Exception { logger . fine ( "<STR_LIT>" + actionTasks . size ( ) + "<STR_LIT>" ) ; for ( ConfigurationActionTask task : actionTasks ) { task . execute ( ) ; } } public List < ConfigurationActionTask > getActionTasks ( ) { return actionTasks ; } public void setActionTasks ( List < ConfigurationActionTask > configtasks ) { this . actionTasks = configtasks ; } public void addActionTasks ( List < ConfigurationActionTask > configtasks ) { if ( configtasks == null ) { configtasks = new ArrayList < ConfigurationActionTask > ( ) ; } this . actionTasks . addAll ( configtasks ) ; } } </s>
<s> package com . izforge . izpack . event ; import java . io . File ; import java . io . InputStream ; import java . io . ObjectInputStream ; import java . util . Collections ; import java . util . List ; import com . izforge . izpack . api . event . AbstractUninstallerListener ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . resource . Resources ; public class BSFUninstallerListener extends AbstractUninstallerListener { private final Resources resources ; private List < BSFAction > actions ; public BSFUninstallerListener ( Resources resources ) { this . resources = resources ; } @ Override public void initialise ( ) { InputStream in ; try { in = resources . getInputStream ( "<STR_LIT>" ) ; ObjectInputStream objIn = new ObjectInputStream ( in ) ; actions = ( List < BSFAction > ) objIn . readObject ( ) ; if ( actions == null ) { actions = Collections . emptyList ( ) ; } else { for ( BSFAction action : actions ) { action . init ( ) ; } } objIn . close ( ) ; in . close ( ) ; } catch ( ResourceNotFoundException ignore ) { } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void beforeDelete ( List < File > files ) { for ( BSFAction action : actions ) { action . executeUninstall ( BSFAction . BEFOREDELETION , files ) ; } } @ Override public void afterDelete ( List < File > files , ProgressListener listener ) { for ( BSFAction action : actions ) { action . executeUninstall ( BSFAction . AFTERDELETION , files , listener ) ; action . destroy ( ) ; } } @ Override public void beforeDelete ( File file ) { for ( BSFAction action : actions ) { action . executeUninstall ( BSFAction . BEFOREDELETE , file ) ; } } @ Override public void afterDelete ( File file ) { for ( BSFAction action : actions ) { action . executeUninstall ( BSFAction . AFTERDELETE , file ) ; } } public boolean isFileListener ( ) { return true ; } } </s>
<s> package com . izforge . izpack . event ; import java . util . HashMap ; import java . util . Map ; import java . util . Properties ; import java . util . logging . Level ; import java . util . logging . Logger ; import org . apache . bsf . BSFEngine ; import org . apache . bsf . BSFException ; import org . apache . bsf . BSFManager ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . exception . IzPackException ; public class BSFAction extends ActionBase { private static final long serialVersionUID = <NUM_LIT> ; public static final String BSFACTIONS = "<STR_LIT>" ; public static final String BSFACTION = "<STR_LIT>" ; public static final String BEFOREFILE = "<STR_LIT>" ; public static final String AFTERFILE = "<STR_LIT>" ; public static final String BEFOREDIR = "<STR_LIT>" ; public static final String AFTERDIR = "<STR_LIT>" ; public static final String BEFOREDELETE = "<STR_LIT>" ; public static final String AFTERDELETE = "<STR_LIT>" ; public static final String BEFOREDELETION = "<STR_LIT>" ; public static final String AFTERDELETION = "<STR_LIT>" ; private String script = null ; private String language = null ; private String scriptName = null ; private transient BSFManager manager = null ; private transient BSFEngine engine = null ; private static Map < String , MethodDescriptor > orderMethodMap = null ; private Properties variables = new Properties ( ) ; private static final Logger logger = Logger . getLogger ( BSFAction . class . getName ( ) ) ; private static class MethodDescriptor { private String name ; private String argNames [ ] ; public MethodDescriptor ( String name , String ... argNames ) { super ( ) ; this . name = name ; this . argNames = argNames ; } } private static interface MethodExistenceChecker { boolean isMethodDefined ( String method , String scriptName , BSFEngine engine , BSFManager manager ) throws BSFException ; } private static Map < String , MethodExistenceChecker > langToMethodCheckerMap = new HashMap < String , MethodExistenceChecker > ( ) ; static { orderMethodMap = new HashMap < String , MethodDescriptor > ( ) ; orderMethodMap . put ( BSFAction . BEFOREDELETION , new MethodDescriptor ( "<STR_LIT>" , "<STR_LIT>" ) ) ; orderMethodMap . put ( BSFAction . AFTERDELETION , new MethodDescriptor ( "<STR_LIT>" , "<STR_LIT>" ) ) ; orderMethodMap . put ( BSFAction . BEFOREDELETE , new MethodDescriptor ( "<STR_LIT>" , "<STR_LIT:file>" ) ) ; orderMethodMap . put ( BSFAction . AFTERDELETE , new MethodDescriptor ( "<STR_LIT>" , "<STR_LIT:file>" ) ) ; orderMethodMap . put ( BSFAction . BEFOREDIR , new MethodDescriptor ( "<STR_LIT>" , "<STR_LIT:file>" , "<STR_LIT>" ) ) ; orderMethodMap . put ( BSFAction . AFTERDIR , new MethodDescriptor ( "<STR_LIT>" , "<STR_LIT:file>" , "<STR_LIT>" ) ) ; orderMethodMap . put ( BSFAction . BEFOREFILE , new MethodDescriptor ( "<STR_LIT>" , "<STR_LIT:file>" , "<STR_LIT>" ) ) ; orderMethodMap . put ( BSFAction . AFTERFILE , new MethodDescriptor ( "<STR_LIT>" , "<STR_LIT:file>" , "<STR_LIT>" ) ) ; orderMethodMap . put ( BEFOREPACKS , new MethodDescriptor ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; orderMethodMap . put ( AFTERPACKS , new MethodDescriptor ( "<STR_LIT>" , "<STR_LIT>" ) ) ; orderMethodMap . put ( BEFOREPACK , new MethodDescriptor ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:i>" ) ) ; orderMethodMap . put ( AFTERPACK , new MethodDescriptor ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:i>" ) ) ; langToMethodCheckerMap . put ( "<STR_LIT>" , new MethodExistenceChecker ( ) { public boolean isMethodDefined ( String method , String scriptName , BSFEngine engine , BSFManager manager ) throws BSFException { String script = "<STR_LIT>" + method + "<STR_LIT>" ; Object res = engine . eval ( scriptName , <NUM_LIT:1> , <NUM_LIT:1> , script ) ; return res != null ; } } ) ; } public BSFAction ( ) { super ( ) ; } public void setScript ( String script ) { this . script = script ; } public String getScript ( ) { return script ; } public void setLanguage ( String language ) { this . language = language ; } public void init ( ) { if ( manager == null ) { manager = new BSFManager ( ) ; } if ( engine == null ) { try { engine = manager . loadScriptingEngine ( language ) ; scriptName = "<STR_LIT>" + language ; engine . exec ( scriptName , <NUM_LIT:1> , <NUM_LIT:1> , script ) ; } catch ( BSFException exception ) { throw new IzPackException ( "<STR_LIT>" , exception ) ; } } } public void destroy ( ) { if ( engine != null ) { engine . terminate ( ) ; engine = null ; } if ( manager != null ) { manager . terminate ( ) ; manager = null ; } } public void executeUninstall ( String order , Object ... params ) { MethodDescriptor desc = orderMethodMap . get ( order ) ; if ( desc != null ) { try { for ( int i = <NUM_LIT:0> ; i < desc . argNames . length ; i ++ ) { if ( params [ i ] != null ) { manager . declareBean ( desc . argNames [ i ] , params [ i ] , params [ i ] . getClass ( ) ) ; } } manager . declareBean ( "<STR_LIT>" , variables , Properties . class ) ; MethodExistenceChecker checker = langToMethodCheckerMap . get ( language ) ; if ( checker != null ) { if ( ! checker . isMethodDefined ( desc . name , scriptName , engine , manager ) ) { return ; } } else { engine . eval ( scriptName , <NUM_LIT:1> , <NUM_LIT:1> , desc . name ) ; } engine . exec ( scriptName , <NUM_LIT:1> , <NUM_LIT:1> , desc . name + "<STR_LIT>" ) ; } catch ( BSFException exception ) { throw new IzPackException ( "<STR_LIT>" + desc . name , exception ) ; } finally { undeclareBeans ( desc , "<STR_LIT>" ) ; } } } public void execute ( String order , Object [ ] params , InstallData installData ) { MethodDescriptor desc = orderMethodMap . get ( order ) ; if ( desc != null ) { try { for ( int i = <NUM_LIT:0> ; i < desc . argNames . length ; i ++ ) { if ( params [ i ] != null ) { manager . declareBean ( desc . argNames [ i ] , params [ i ] , params [ i ] . getClass ( ) ) ; } } manager . declareBean ( "<STR_LIT>" , installData , InstallData . class ) ; manager . declareBean ( "<STR_LIT>" , installData , InstallData . class ) ; MethodExistenceChecker checker = langToMethodCheckerMap . get ( language ) ; if ( checker != null ) { if ( ! checker . isMethodDefined ( desc . name , scriptName , engine , manager ) ) { return ; } } else { engine . eval ( scriptName , <NUM_LIT:1> , <NUM_LIT:1> , desc . name ) ; } engine . exec ( scriptName , <NUM_LIT:1> , <NUM_LIT:1> , desc . name + "<STR_LIT>" ) ; } catch ( BSFException exception ) { throw new IzPackException ( "<STR_LIT>" + desc . name , exception ) ; } finally { undeclareBeans ( desc , "<STR_LIT>" , "<STR_LIT>" ) ; } } } private void undeclareBeans ( MethodDescriptor desc , String ... names ) { try { for ( int i = <NUM_LIT:0> ; i < desc . argNames . length ; i ++ ) { manager . undeclareBean ( desc . argNames [ i ] ) ; } for ( String name : names ) { manager . undeclareBean ( name ) ; } } catch ( BSFException exception ) { logger . log ( Level . INFO , "<STR_LIT>" + exception . getMessage ( ) , exception ) ; } } } </s>
<s> package com . izforge . izpack . event ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . OutputStream ; import java . util . List ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . util . SummaryProcessor ; import com . izforge . izpack . util . IoHelper ; import com . izforge . izpack . util . file . FileUtils ; public class SummaryLoggerInstallerListener extends AbstractProgressInstallerListener { public SummaryLoggerInstallerListener ( InstallData installData ) { super ( installData ) ; } @ Override public void afterPacks ( List < Pack > packs , ProgressListener listener ) { if ( getInstallData ( ) instanceof GUIInstallData ) { GUIInstallData installData = ( GUIInstallData ) getInstallData ( ) ; if ( ! installData . isInstallSuccess ( ) ) { return ; } if ( installData . getPanels ( ) . isEmpty ( ) ) { return ; } String path = installData . getInfo ( ) . getSummaryLogFilePath ( ) ; if ( path == null ) { return ; } path = IoHelper . translatePath ( path , installData . getVariables ( ) ) ; File parent = new File ( path ) . getParentFile ( ) ; if ( ! parent . exists ( ) ) { parent . mkdirs ( ) ; } String summary = SummaryProcessor . getSummary ( installData ) ; OutputStream out = null ; try { out = new FileOutputStream ( path ) ; out . write ( summary . getBytes ( "<STR_LIT:utf-8>" ) ) ; } catch ( IOException exception ) { throw new IzPackException ( "<STR_LIT>" + path , exception ) ; } finally { FileUtils . close ( out ) ; } } } } </s>
<s> package com . izforge . izpack . event ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . PrintStream ; import java . util . ArrayList ; import java . util . List ; import java . util . Properties ; import org . apache . tools . ant . BuildLogger ; import org . apache . tools . ant . DefaultLogger ; import org . apache . tools . ant . DemuxOutputStream ; import org . apache . tools . ant . Project ; import org . apache . tools . ant . Target ; import org . apache . tools . ant . input . DefaultInputHandler ; import org . apache . tools . ant . taskdefs . Ant ; import org . apache . tools . ant . util . JavaEnvUtils ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . util . file . FileUtils ; public class AntAction extends ActionBase { private static final long serialVersionUID = <NUM_LIT> ; public static final String ANTACTIONS = "<STR_LIT>" ; public static final String ANTACTION = "<STR_LIT>" ; public static final String ANTCALL = "<STR_LIT>" ; private boolean quiet = false ; private boolean verbose = false ; private Properties properties = null ; private List < String > targets = null ; private List < String > uninstallTargets = null ; private File logFile = null ; private File buildFile = null ; private String conditionId = null ; private List < String > propertyFiles = null ; public AntAction ( ) { super ( ) ; properties = new Properties ( ) ; targets = new ArrayList < String > ( ) ; uninstallTargets = new ArrayList < String > ( ) ; propertyFiles = new ArrayList < String > ( ) ; } public void performInstallAction ( ) throws Exception { performAction ( false ) ; } public void performUninstallAction ( ) { performAction ( true ) ; } public void performAction ( boolean uninstall ) { if ( verbose ) { System . out . println ( "<STR_LIT>" + buildFile ) ; } SecurityManager oldsm = null ; if ( ! JavaEnvUtils . isJavaVersion ( "<STR_LIT:1.0>" ) && ! JavaEnvUtils . isJavaVersion ( "<STR_LIT>" ) ) { oldsm = System . getSecurityManager ( ) ; } PrintStream err = System . err ; PrintStream out = System . out ; try { Project antProj = new Project ( ) ; antProj . setName ( "<STR_LIT>" ) ; antProj . addBuildListener ( createLogger ( ) ) ; antProj . setInputHandler ( new DefaultInputHandler ( ) ) ; antProj . setSystemProperties ( ) ; addProperties ( antProj , getProperties ( ) ) ; addPropertiesFromPropertyFiles ( antProj ) ; antProj . fireBuildStarted ( ) ; antProj . init ( ) ; List < Ant > antcalls = new ArrayList < Ant > ( ) ; List < String > choosenTargets = ( uninstall ) ? uninstallTargets : targets ; if ( choosenTargets . size ( ) > <NUM_LIT:0> ) { Ant antcall = null ; for ( String choosenTarget : choosenTargets ) { antcall = ( Ant ) antProj . createTask ( "<STR_LIT>" ) ; antcall . setAntfile ( getBuildFile ( ) . getAbsolutePath ( ) ) ; antcall . setTarget ( choosenTarget ) ; antcalls . add ( antcall ) ; } } Target target = new Target ( ) ; target . setName ( "<STR_LIT>" ) ; for ( Ant antcall : antcalls ) { target . addTask ( antcall ) ; } antProj . addTarget ( target ) ; System . setOut ( new PrintStream ( new DemuxOutputStream ( antProj , false ) ) ) ; System . setErr ( new PrintStream ( new DemuxOutputStream ( antProj , true ) ) ) ; antProj . executeTarget ( "<STR_LIT>" ) ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } finally { if ( oldsm != null ) { System . setSecurityManager ( oldsm ) ; } System . setOut ( out ) ; System . setErr ( err ) ; } } public String getConditionId ( ) { return conditionId ; } public void setConditionId ( String conditionId ) { this . conditionId = conditionId ; } public File getBuildFile ( ) { return buildFile ; } public void setBuildFile ( File buildFile ) { this . buildFile = buildFile ; } public File getLogFile ( ) { return logFile ; } public void setLogFile ( File logFile ) { this . logFile = logFile ; } public List < String > getPropertyFiles ( ) { return propertyFiles ; } public void addPropertyFile ( String propertyFile ) { this . propertyFiles . add ( propertyFile ) ; } public void setPropertyFiles ( List < String > propertyFiles ) { this . propertyFiles = propertyFiles ; } public Properties getProperties ( ) { return properties ; } public void setProperties ( Properties properties ) { this . properties = properties ; } public void setProperty ( String name , String value ) { this . properties . put ( name , value ) ; } public String getProperty ( String name ) { return this . properties . getProperty ( name ) ; } public boolean isQuiet ( ) { return quiet ; } public void setQuiet ( boolean quiet ) { this . quiet = quiet ; } public List < String > getTargets ( ) { return targets ; } public void setTargets ( ArrayList < String > targets ) { this . targets = targets ; } public void addTarget ( String target ) { this . targets . add ( target ) ; } public List < String > getUninstallTargets ( ) { return uninstallTargets ; } public void setUninstallTargets ( ArrayList < String > targets ) { this . uninstallTargets = targets ; } public void addUninstallTarget ( String target ) { this . uninstallTargets . add ( target ) ; } public boolean isVerbose ( ) { return verbose ; } public void setVerbose ( boolean verbose ) { this . verbose = verbose ; } private BuildLogger createLogger ( ) { int msgOutputLevel = <NUM_LIT:2> ; if ( verbose ) { msgOutputLevel = <NUM_LIT:4> ; } else if ( quiet ) { msgOutputLevel = <NUM_LIT:1> ; } BuildLogger logger = new DefaultLogger ( ) ; logger . setMessageOutputLevel ( msgOutputLevel ) ; if ( logFile != null ) { PrintStream printStream ; try { logFile . getParentFile ( ) . mkdirs ( ) ; printStream = new PrintStream ( new FileOutputStream ( logFile ) ) ; logger . setOutputPrintStream ( printStream ) ; logger . setErrorPrintStream ( printStream ) ; } catch ( FileNotFoundException e ) { logger . setOutputPrintStream ( System . out ) ; logger . setErrorPrintStream ( System . err ) ; } } else { logger . setOutputPrintStream ( System . out ) ; logger . setErrorPrintStream ( System . err ) ; } return logger ; } private void addProperties ( Project proj , Properties props ) { if ( proj == null ) { return ; } if ( props . size ( ) > <NUM_LIT:0> ) { for ( Object o : props . keySet ( ) ) { String key = ( String ) o ; proj . setProperty ( key , props . getProperty ( key ) ) ; } } } private void addPropertiesFromPropertyFiles ( Project proj ) { if ( proj == null ) { return ; } Properties props = new Properties ( ) ; FileInputStream fis = null ; try { for ( String propertyFile : propertyFiles ) { File file = new File ( propertyFile ) ; if ( file . exists ( ) ) { fis = new FileInputStream ( file ) ; props . load ( fis ) ; fis . close ( ) ; } else { throw new IzPackException ( "<STR_LIT>" + file + "<STR_LIT>" ) ; } } } catch ( IOException exception ) { throw new IzPackException ( exception ) ; } finally { FileUtils . close ( fis ) ; } addProperties ( proj , props ) ; } } </s>
<s> package com . izforge . izpack . event ; import com . izforge . izpack . api . resource . Resources ; @ Deprecated public class NativeInstallerListener extends SimpleInstallerListener { public NativeInstallerListener ( Resources resources ) { super ( resources ) ; } public NativeInstallerListener ( Resources resources , boolean useSpecHelper ) { super ( resources , useSpecHelper ) ; } } </s>
<s> package com . izforge . izpack . event ; import java . io . File ; import java . text . MessageFormat ; import java . util . ArrayList ; import java . util . EnumSet ; import java . util . HashMap ; import java . util . Iterator ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . Properties ; import java . util . Vector ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . data . DynamicVariable ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . event . ProgressNotifiers ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . data . DynamicVariableImpl ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; import com . izforge . izpack . core . variable . ConfigFileValue ; import com . izforge . izpack . core . variable . EnvironmentValue ; import com . izforge . izpack . core . variable . ExecValue ; import com . izforge . izpack . core . variable . JarEntryConfigValue ; import com . izforge . izpack . core . variable . PlainConfigFileValue ; import com . izforge . izpack . core . variable . PlainValue ; import com . izforge . izpack . core . variable . RegistryValue ; import com . izforge . izpack . core . variable . ZipEntryConfigFileValue ; import com . izforge . izpack . core . variable . filters . LocationFilter ; import com . izforge . izpack . core . variable . filters . RegularExpressionFilter ; import com . izforge . izpack . util . FileUtil ; import com . izforge . izpack . util . config . ConfigFileTask ; import com . izforge . izpack . util . config . ConfigurableFileCopyTask ; import com . izforge . izpack . util . config . ConfigurableTask ; import com . izforge . izpack . util . config . IniFileCopyTask ; import com . izforge . izpack . util . config . OptionFileCopyTask ; import com . izforge . izpack . util . config . RegistryTask ; import com . izforge . izpack . util . config . SingleConfigurableTask ; import com . izforge . izpack . util . config . SingleConfigurableTask . Entry ; import com . izforge . izpack . util . config . SingleConfigurableTask . Entry . LookupType ; import com . izforge . izpack . util . config . SingleConfigurableTask . Entry . Operation ; import com . izforge . izpack . util . config . SingleConfigurableTask . Entry . Type ; import com . izforge . izpack . util . config . SingleConfigurableTask . Unit ; import com . izforge . izpack . util . config . SingleIniFileTask ; import com . izforge . izpack . util . config . SingleOptionFileTask ; import com . izforge . izpack . util . config . SingleXmlFileMergeTask ; import com . izforge . izpack . util . file . FileNameMapper ; import com . izforge . izpack . util . file . GlobPatternMapper ; import com . izforge . izpack . util . file . types . FileSet ; import com . izforge . izpack . util . file . types . Mapper ; import com . izforge . izpack . util . helper . SpecHelper ; public class ConfigurationInstallerListener extends AbstractProgressInstallerListener { private static final Logger logger = Logger . getLogger ( ConfigurationInstallerListener . class . getName ( ) ) ; public static final String SPEC_FILE_NAME = "<STR_LIT>" ; private static final String ERRMSG_CONFIGACTION_BADATTR = "<STR_LIT>" ; private final Map < String , Map < Object , List < ConfigurationAction > > > actions = new HashMap < String , Map < Object , List < ConfigurationAction > > > ( ) ; private final Resources resources ; private final VariableSubstitutor replacer ; private SpecHelper spec ; private VariableSubstitutor substlocal ; public ConfigurationInstallerListener ( InstallData installData , Resources resources , VariableSubstitutor replacer , ProgressNotifiers notifiers ) { super ( installData , notifiers ) ; this . resources = resources ; this . replacer = replacer ; } public Map < String , Map < Object , List < ConfigurationAction > > > getActions ( ) { return actions ; } @ Override public void initialise ( ) { spec = new SpecHelper ( resources ) ; try { spec . readSpec ( SPEC_FILE_NAME , replacer ) ; } catch ( Exception exception ) { throw new IzPackException ( "<STR_LIT>" + SPEC_FILE_NAME , exception ) ; } } @ Override public void beforePacks ( List < Pack > packs ) { if ( spec . getSpec ( ) == null ) { return ; } for ( Pack p : packs ) { logger . fine ( "<STR_LIT>" + p . getName ( ) ) ; IXMLElement pack = spec . getPackForName ( p . getName ( ) ) ; if ( pack == null ) { continue ; } logger . fine ( "<STR_LIT>" + p . getName ( ) ) ; Map < Object , List < ConfigurationAction > > packActions = new HashMap < Object , List < ConfigurationAction > > ( ) ; packActions . put ( ActionBase . BEFOREPACK , new ArrayList < ConfigurationAction > ( ) ) ; packActions . put ( ActionBase . AFTERPACK , new ArrayList < ConfigurationAction > ( ) ) ; packActions . put ( ActionBase . BEFOREPACKS , new ArrayList < ConfigurationAction > ( ) ) ; packActions . put ( ActionBase . AFTERPACKS , new ArrayList < ConfigurationAction > ( ) ) ; List < IXMLElement > configActionEntries = pack . getChildrenNamed ( "<STR_LIT>" ) ; if ( configActionEntries != null ) { logger . fine ( "<STR_LIT>" + configActionEntries . size ( ) + "<STR_LIT>" ) ; if ( configActionEntries . size ( ) >= <NUM_LIT:1> ) { Iterator < IXMLElement > entriesIter = configActionEntries . iterator ( ) ; while ( entriesIter != null && entriesIter . hasNext ( ) ) { ConfigurationAction act = readConfigAction ( entriesIter . next ( ) ) ; if ( act != null ) { logger . fine ( "<STR_LIT>" + act . getOrder ( ) + "<STR_LIT>" + act . getActionTasks ( ) . size ( ) + "<STR_LIT>" ) ; ( packActions . get ( act . getOrder ( ) ) ) . add ( act ) ; } } if ( ( packActions . get ( ActionBase . AFTERPACKS ) ) . size ( ) > <NUM_LIT:0> ) { setProgressNotifier ( ) ; } } if ( ( packActions . get ( ActionBase . AFTERPACKS ) ) . size ( ) > <NUM_LIT:0> ) { this . setProgressNotifier ( ) ; } } actions . put ( p . getName ( ) , packActions ) ; } for ( Pack p : packs ) { String currentPack = p . getName ( ) ; performAllActions ( currentPack , ActionBase . BEFOREPACKS , null ) ; } } @ Override public void beforePack ( Pack pack , int i ) { performAllActions ( pack . getName ( ) , ActionBase . BEFOREPACK , null ) ; } @ Override public void afterPack ( Pack pack , int i ) { performAllActions ( pack . getName ( ) , ActionBase . AFTERPACK , null ) ; } @ Override public void afterPacks ( List < Pack > packs , ProgressListener listener ) { if ( notifyProgress ( ) ) { listener . nextStep ( getMessage ( "<STR_LIT>" ) , getProgressNotifierId ( ) , getActionCount ( packs , ActionBase . AFTERPACKS ) ) ; } for ( Pack pack : packs ) { String currentPack = pack . getName ( ) ; performAllActions ( currentPack , ActionBase . AFTERPACKS , listener ) ; } } private int getActionCount ( List < Pack > packs , String order ) { int retval = <NUM_LIT:0> ; for ( Pack pack : packs ) { String currentPack = pack . getName ( ) ; List < ConfigurationAction > actList = getActions ( currentPack , order ) ; if ( actList != null ) { retval += actList . size ( ) ; } } return ( retval ) ; } protected List < ConfigurationAction > getActions ( String packName , String order ) { if ( actions == null ) { return null ; } Map < Object , List < ConfigurationAction > > packActions = actions . get ( packName ) ; if ( packActions == null || packActions . size ( ) == <NUM_LIT:0> ) { return null ; } return packActions . get ( order ) ; } private void performAllActions ( String packName , String order , ProgressListener listener ) throws InstallerException { List < ConfigurationAction > actList = getActions ( packName , order ) ; if ( actList == null || actList . size ( ) == <NUM_LIT:0> ) { return ; } logger . fine ( "<STR_LIT>" + order + "<STR_LIT>" + packName + "<STR_LIT>" ) ; for ( ConfigurationAction act : actList ) { if ( notifyProgress ( ) && order . equals ( ActionBase . AFTERPACKS ) ) { listener . progress ( ( act . getMessageID ( ) != null ) ? getMessage ( act . getMessageID ( ) ) : "<STR_LIT>" ) ; } else { try { act . performInstallAction ( ) ; } catch ( Exception e ) { throw new InstallerException ( e ) ; } } } } private ConfigurationAction readConfigAction ( IXMLElement el ) throws InstallerException { if ( el == null ) { return null ; } ConfigurationAction act = new ConfigurationAction ( ) ; try { act . setOrder ( spec . getRequiredAttribute ( el , ActionBase . ORDER ) ) ; } catch ( Exception e ) { throw new InstallerException ( e ) ; } substlocal = new VariableSubstitutorImpl ( readVariables ( el ) ) ; act . setActionTasks ( readConfigurables ( el ) ) ; act . addActionTasks ( readConfigurableSets ( el ) ) ; return act ; } private String substituteVariables ( String name ) { try { name = replacer . substitute ( name ) ; } catch ( Exception exception ) { logger . log ( Level . WARNING , "<STR_LIT>" + name , exception ) ; } if ( substlocal != null ) { try { name = substlocal . substitute ( name ) ; } catch ( Exception exception ) { logger . log ( Level . WARNING , "<STR_LIT>" + name , exception ) ; } } return name ; } protected List < ConfigurationActionTask > readConfigurableSets ( IXMLElement parent ) throws InstallerException { List < ConfigurationActionTask > configtasks = new ArrayList < ConfigurationActionTask > ( ) ; for ( IXMLElement el : parent . getChildrenNamed ( "<STR_LIT>" ) ) { String attrib = requireAttribute ( el , "<STR_LIT:type>" ) ; ConfigType configType ; if ( attrib != null ) { configType = ConfigType . getFromAttribute ( attrib ) ; if ( configType == null ) { throw new InstallerException ( "<STR_LIT>" + attrib + "<STR_LIT:'>" ) ; } } else { throw new InstallerException ( "<STR_LIT>" ) ; } ConfigurableTask task ; switch ( configType ) { case OPTIONS : task = new OptionFileCopyTask ( ) ; readConfigurableSetCommonAttributes ( el , ( ConfigurableFileCopyTask ) task ) ; break ; case INI : task = new IniFileCopyTask ( ) ; readConfigurableSetCommonAttributes ( el , ( ConfigurableFileCopyTask ) task ) ; break ; default : throw new InstallerException ( "<STR_LIT>" + configType . getAttribute ( ) + "<STR_LIT>" ) ; } configtasks . add ( new ConfigurationActionTask ( task , getAttribute ( el , "<STR_LIT>" ) , getInstallData ( ) . getRules ( ) ) ) ; } return configtasks ; } private void readConfigurableSetCommonAttributes ( IXMLElement el , ConfigurableFileCopyTask task ) throws InstallerException { InstallData idata = getInstallData ( ) ; task . setToDir ( FileUtil . getAbsoluteFile ( getAttribute ( el , "<STR_LIT>" ) , idata . getInstallPath ( ) ) ) ; task . setToFile ( FileUtil . getAbsoluteFile ( getAttribute ( el , "<STR_LIT>" ) , idata . getInstallPath ( ) ) ) ; task . setFile ( FileUtil . getAbsoluteFile ( getAttribute ( el , "<STR_LIT>" ) , idata . getInstallPath ( ) ) ) ; String boolattr = getAttribute ( el , "<STR_LIT>" ) ; if ( boolattr != null ) { task . setPatchPreserveEntries ( Boolean . parseBoolean ( boolattr ) ) ; } boolattr = getAttribute ( el , "<STR_LIT>" ) ; if ( boolattr != null ) { task . setPatchPreserveValues ( Boolean . parseBoolean ( boolattr ) ) ; } boolattr = getAttribute ( el , "<STR_LIT>" ) ; if ( boolattr != null ) { task . setPatchResolveExpressions ( Boolean . parseBoolean ( boolattr ) ) ; } boolattr = getAttribute ( el , "<STR_LIT>" ) ; if ( boolattr != null ) { task . setFailOnError ( Boolean . parseBoolean ( boolattr ) ) ; } boolattr = getAttribute ( el , "<STR_LIT>" ) ; if ( boolattr != null ) { task . setIncludeEmptyDirs ( Boolean . parseBoolean ( boolattr ) ) ; } boolattr = getAttribute ( el , "<STR_LIT>" ) ; if ( boolattr != null ) { task . setOverwrite ( Boolean . parseBoolean ( boolattr ) ) ; } boolattr = getAttribute ( el , "<STR_LIT>" ) ; if ( boolattr != null ) { task . setPreserveLastModified ( Boolean . parseBoolean ( boolattr ) ) ; } boolattr = getAttribute ( el , "<STR_LIT>" ) ; if ( boolattr != null ) { task . setEnableMultipleMappings ( Boolean . parseBoolean ( boolattr ) ) ; } boolattr = getAttribute ( el , "<STR_LIT>" ) ; if ( boolattr != null ) { task . setCleanup ( Boolean . parseBoolean ( boolattr ) ) ; } for ( FileSet fs : readFileSets ( el ) ) { task . addFileSet ( fs ) ; } try { for ( FileNameMapper mapper : readMapper ( el ) ) { task . add ( mapper ) ; } } catch ( Exception e ) { throw new InstallerException ( e . getMessage ( ) ) ; } } private void readSingleConfigurableTaskCommonAttributes ( IXMLElement el , SingleConfigurableTask task ) throws InstallerException { String attr = getAttribute ( el , "<STR_LIT>" ) ; if ( attr != null ) { task . setCreate ( Boolean . parseBoolean ( attr ) ) ; } attr = getAttribute ( el , "<STR_LIT>" ) ; if ( attr != null ) { task . setPatchPreserveEntries ( Boolean . parseBoolean ( attr ) ) ; } attr = getAttribute ( el , "<STR_LIT>" ) ; if ( attr != null ) { task . setPatchPreserveValues ( Boolean . parseBoolean ( attr ) ) ; } attr = getAttribute ( el , "<STR_LIT>" ) ; if ( attr != null ) { task . setPatchResolveVariables ( Boolean . parseBoolean ( attr ) ) ; } attr = getAttribute ( el , "<STR_LIT>" ) ; if ( attr != null ) { task . setEscape ( Boolean . parseBoolean ( attr ) ) ; } attr = getAttribute ( el , "<STR_LIT>" ) ; if ( attr != null ) { task . setEscapeNewLine ( Boolean . parseBoolean ( attr ) ) ; } attr = getAttribute ( el , "<STR_LIT>" ) ; if ( attr != null ) { task . setHeaderComment ( Boolean . parseBoolean ( attr ) ) ; } attr = getAttribute ( el , "<STR_LIT>" ) ; if ( attr != null ) { task . setEmptyLines ( Boolean . parseBoolean ( attr ) ) ; } attr = getAttribute ( el , "<STR_LIT>" ) ; if ( attr != null ) { task . setOperator ( attr ) ; } } private void readConfigFileTaskCommonAttributes ( InstallData idata , IXMLElement el , ConfigFileTask task ) throws InstallerException { File tofile = FileUtil . getAbsoluteFile ( requireAttribute ( el , "<STR_LIT>" ) , idata . getInstallPath ( ) ) ; task . setToFile ( tofile ) ; task . setOldFile ( FileUtil . getAbsoluteFile ( getAttribute ( el , "<STR_LIT>" ) , idata . getInstallPath ( ) ) ) ; File newfile = FileUtil . getAbsoluteFile ( getAttribute ( el , "<STR_LIT>" ) , idata . getInstallPath ( ) ) ; task . setNewFile ( newfile ) ; String boolattr = getAttribute ( el , "<STR_LIT>" ) ; if ( boolattr != null ) { task . setCleanup ( Boolean . parseBoolean ( boolattr ) ) ; } } protected List < ConfigurationActionTask > readConfigurables ( IXMLElement parent ) throws InstallerException { List < ConfigurationActionTask > configtasks = new ArrayList < ConfigurationActionTask > ( ) ; InstallData idata = getInstallData ( ) ; for ( IXMLElement el : parent . getChildrenNamed ( "<STR_LIT>" ) ) { String attrib = requireAttribute ( el , "<STR_LIT:type>" ) ; ConfigType configType ; if ( attrib != null ) { configType = ConfigType . getFromAttribute ( attrib ) ; if ( configType == null ) { throw new InstallerException ( "<STR_LIT>" + attrib + "<STR_LIT:'>" ) ; } } else { throw new InstallerException ( "<STR_LIT>" ) ; } ConfigurableTask task ; switch ( configType ) { case OPTIONS : task = new SingleOptionFileTask ( ) ; readConfigFileTaskCommonAttributes ( idata , el , ( ConfigFileTask ) task ) ; readSingleConfigurableTaskCommonAttributes ( el , ( SingleConfigurableTask ) task ) ; readAndAddEntries ( el , ( SingleConfigurableTask ) task ) ; break ; case INI : task = new SingleIniFileTask ( ) ; readConfigFileTaskCommonAttributes ( idata , el , ( ConfigFileTask ) task ) ; readSingleConfigurableTaskCommonAttributes ( el , ( SingleConfigurableTask ) task ) ; readAndAddEntries ( el , ( SingleConfigurableTask ) task ) ; break ; case XML : task = new SingleXmlFileMergeTask ( ) ; File tofile = FileUtil . getAbsoluteFile ( requireAttribute ( el , "<STR_LIT>" ) , idata . getInstallPath ( ) ) ; ( ( SingleXmlFileMergeTask ) task ) . setToFile ( tofile ) ; ( ( SingleXmlFileMergeTask ) task ) . setPatchFile ( FileUtil . getAbsoluteFile ( getAttribute ( el , "<STR_LIT>" ) , idata . getInstallPath ( ) ) ) ; File originalfile = FileUtil . getAbsoluteFile ( getAttribute ( el , "<STR_LIT>" ) , idata . getInstallPath ( ) ) ; if ( originalfile == null ) { originalfile = tofile ; } ( ( SingleXmlFileMergeTask ) task ) . setOriginalFile ( originalfile ) ; ( ( SingleXmlFileMergeTask ) task ) . setConfigFile ( FileUtil . getAbsoluteFile ( getAttribute ( el , "<STR_LIT>" ) , idata . getInstallPath ( ) ) ) ; String boolattr = getAttribute ( el , "<STR_LIT>" ) ; if ( boolattr != null ) { ( ( SingleXmlFileMergeTask ) task ) . setCleanup ( Boolean . parseBoolean ( boolattr ) ) ; } List < FileSet > fslist = readFileSets ( el ) ; for ( FileSet fs : fslist ) { ( ( SingleXmlFileMergeTask ) task ) . addFileSet ( fs ) ; } readAndAddXPathProperties ( el , ( SingleXmlFileMergeTask ) task ) ; break ; case REGISTRY : task = new RegistryTask ( ) ; ( ( RegistryTask ) task ) . setFromKey ( requireAttribute ( el , "<STR_LIT>" ) ) ; ( ( RegistryTask ) task ) . setKey ( requireAttribute ( el , "<STR_LIT>" ) ) ; readSingleConfigurableTaskCommonAttributes ( el , ( SingleConfigurableTask ) task ) ; break ; default : throw new InstallerException ( "<STR_LIT>" + configType . getAttribute ( ) + "<STR_LIT>" ) ; } configtasks . add ( new ConfigurationActionTask ( task , getAttribute ( el , "<STR_LIT>" ) , getInstallData ( ) . getRules ( ) ) ) ; } return configtasks ; } public void readAndAddEntries ( IXMLElement parent , SingleConfigurableTask task ) throws InstallerException { for ( IXMLElement el : parent . getChildrenNamed ( "<STR_LIT>" ) ) { Entry entry = createEntryFromXML ( el ) ; if ( task instanceof SingleOptionFileTask ) { entry . setKey ( el . getAttribute ( "<STR_LIT:key>" ) ) ; entry . setValue ( getAttribute ( el , "<STR_LIT:value>" ) ) ; } else if ( task instanceof SingleIniFileTask ) { entry . setSection ( el . getAttribute ( "<STR_LIT>" ) ) ; entry . setKey ( el . getAttribute ( "<STR_LIT:key>" ) ) ; entry . setValue ( getAttribute ( el , "<STR_LIT:value>" ) ) ; } else if ( task instanceof RegistryTask ) { entry . setSection ( el . getAttribute ( "<STR_LIT:key>" ) ) ; entry . setKey ( el . getAttribute ( "<STR_LIT:value>" ) ) ; entry . setValue ( getAttribute ( el , "<STR_LIT:data>" ) ) ; } task . addEntry ( entry ) ; } } private Entry createEntryFromXML ( IXMLElement parent ) throws InstallerException { Entry e = new Entry ( ) ; String attrib = parent . getAttribute ( "<STR_LIT>" ) ; if ( attrib != null ) { Type type = Type . getFromAttribute ( attrib ) ; if ( type == null ) { throw new InstallerException ( MessageFormat . format ( ERRMSG_CONFIGACTION_BADATTR , "<STR_LIT>" , attrib ) ) ; } e . setType ( type ) ; } attrib = parent . getAttribute ( "<STR_LIT>" ) ; if ( attrib != null ) { LookupType lookupType = LookupType . getFromAttribute ( attrib ) ; if ( lookupType == null ) { throw new InstallerException ( MessageFormat . format ( ERRMSG_CONFIGACTION_BADATTR , "<STR_LIT>" , attrib ) ) ; } e . setLookupType ( lookupType ) ; } attrib = parent . getAttribute ( "<STR_LIT>" ) ; if ( attrib != null ) { Operation operation = Operation . getFromAttribute ( attrib ) ; if ( operation == null ) { throw new InstallerException ( MessageFormat . format ( ERRMSG_CONFIGACTION_BADATTR , "<STR_LIT>" , attrib ) ) ; } e . setOperation ( operation ) ; } attrib = parent . getAttribute ( "<STR_LIT>" ) ; if ( attrib != null ) { Unit unit = Unit . getFromAttribute ( attrib ) ; if ( unit == null ) { throw new InstallerException ( MessageFormat . format ( ERRMSG_CONFIGACTION_BADATTR , "<STR_LIT>" , attrib ) ) ; } e . setUnit ( unit ) ; } e . setDefault ( parent . getAttribute ( "<STR_LIT:default>" ) ) ; e . setPattern ( parent . getAttribute ( "<STR_LIT>" ) ) ; return e ; } private void readAndAddXPathProperties ( IXMLElement parent , SingleXmlFileMergeTask task ) throws InstallerException { for ( IXMLElement f : parent . getChildrenNamed ( "<STR_LIT>" ) ) { task . addProperty ( requireAttribute ( f , "<STR_LIT:key>" ) , requireAttribute ( f , "<STR_LIT:value>" ) ) ; } } private List < FileSet > readFileSets ( IXMLElement parent ) throws InstallerException { Iterator < IXMLElement > iter = parent . getChildrenNamed ( "<STR_LIT>" ) . iterator ( ) ; List < FileSet > fslist = new ArrayList < FileSet > ( ) ; try { String installPath = getInstallData ( ) . getInstallPath ( ) ; while ( iter . hasNext ( ) ) { IXMLElement f = iter . next ( ) ; FileSet fs = new FileSet ( ) ; String strattr = getAttribute ( f , "<STR_LIT>" ) ; if ( strattr != null ) { fs . setDir ( FileUtil . getAbsoluteFile ( strattr , installPath ) ) ; } strattr = getAttribute ( f , "<STR_LIT:file>" ) ; if ( strattr != null ) { fs . setFile ( FileUtil . getAbsoluteFile ( strattr , installPath ) ) ; } else { if ( fs . getDir ( ) == null ) { throw new InstallerException ( "<STR_LIT>" ) ; } } strattr = getAttribute ( f , "<STR_LIT>" ) ; if ( strattr != null ) { fs . setIncludes ( strattr ) ; } strattr = getAttribute ( f , "<STR_LIT>" ) ; if ( strattr != null ) { fs . setExcludes ( strattr ) ; } String boolval = getAttribute ( f , "<STR_LIT>" ) ; if ( boolval != null ) { fs . setCaseSensitive ( Boolean . parseBoolean ( boolval ) ) ; } boolval = getAttribute ( f , "<STR_LIT>" ) ; if ( boolval != null ) { fs . setDefaultexcludes ( Boolean . parseBoolean ( boolval ) ) ; } boolval = getAttribute ( f , "<STR_LIT>" ) ; if ( boolval != null ) { fs . setFollowSymlinks ( Boolean . parseBoolean ( boolval ) ) ; } readAndAddIncludes ( f , fs ) ; readAndAddExcludes ( f , fs ) ; fslist . add ( fs ) ; } } catch ( Exception e ) { throw new InstallerException ( e ) ; } return fslist ; } private List < FileNameMapper > readMapper ( IXMLElement parent ) throws InstallerException { Iterator < IXMLElement > iter = parent . getChildrenNamed ( "<STR_LIT>" ) . iterator ( ) ; List < FileNameMapper > mappers = new ArrayList < FileNameMapper > ( ) ; try { while ( iter . hasNext ( ) ) { IXMLElement f = iter . next ( ) ; String attrib = requireAttribute ( f , "<STR_LIT:type>" ) ; Mapper . MapperType mappertype ; if ( attrib != null ) { mappertype = Mapper . MapperType . getFromAttribute ( attrib ) ; if ( mappertype == null ) { throw new InstallerException ( "<STR_LIT>" + attrib + "<STR_LIT:'>" ) ; } } else { throw new InstallerException ( "<STR_LIT>" ) ; } FileNameMapper mapper = ( FileNameMapper ) Class . forName ( mappertype . getImplementation ( ) ) . newInstance ( ) ; if ( mapper instanceof GlobPatternMapper ) { String boolval = getAttribute ( f , "<STR_LIT>" ) ; if ( boolval != null ) { ( ( GlobPatternMapper ) mapper ) . setCaseSensitive ( Boolean . parseBoolean ( boolval ) ) ; } mapper . setFrom ( requireAttribute ( f , "<STR_LIT>" ) ) ; mapper . setTo ( requireAttribute ( f , "<STR_LIT>" ) ) ; } else { throw new InstallerException ( "<STR_LIT>" + "<STR_LIT>" ) ; } mappers . add ( mapper ) ; } } catch ( Exception e ) { throw new InstallerException ( e ) ; } return mappers ; } private void readAndAddIncludes ( IXMLElement parent , FileSet fileset ) throws InstallerException { for ( IXMLElement f : parent . getChildrenNamed ( "<STR_LIT>" ) ) { fileset . createInclude ( ) . setName ( requireAttribute ( f , "<STR_LIT:name>" ) ) ; } } private void readAndAddExcludes ( IXMLElement parent , FileSet fileset ) throws InstallerException { for ( IXMLElement f : parent . getChildrenNamed ( "<STR_LIT>" ) ) { fileset . createExclude ( ) . setName ( requireAttribute ( f , "<STR_LIT:name>" ) ) ; } } private int getConfigFileType ( String varname , String type ) throws InstallerException { int filetype = ConfigFileValue . CONFIGFILE_TYPE_OPTIONS ; if ( type != null ) { if ( type . equalsIgnoreCase ( "<STR_LIT>" ) ) { filetype = ConfigFileValue . CONFIGFILE_TYPE_OPTIONS ; } else if ( type . equalsIgnoreCase ( "<STR_LIT>" ) ) { filetype = ConfigFileValue . CONFIGFILE_TYPE_XML ; } else if ( type . equalsIgnoreCase ( "<STR_LIT>" ) ) { filetype = ConfigFileValue . CONFIGFILE_TYPE_INI ; } else { parseError ( "<STR_LIT>" + varname + "<STR_LIT>" + type ) ; } } return filetype ; } protected Properties readVariables ( IXMLElement parent ) throws InstallerException { List < DynamicVariable > dynamicVariables = null ; IXMLElement vars = parent . getFirstChildNamed ( "<STR_LIT>" ) ; if ( vars != null ) { dynamicVariables = new LinkedList < DynamicVariable > ( ) ; for ( IXMLElement var : parent . getChildrenNamed ( "<STR_LIT>" ) ) { String name = requireAttribute ( var , "<STR_LIT:name>" ) ; DynamicVariable dynamicVariable = new DynamicVariableImpl ( ) ; dynamicVariable . setName ( name ) ; String value = getAttribute ( var , "<STR_LIT:value>" ) ; if ( value != null ) { dynamicVariable . setValue ( new PlainValue ( value ) ) ; } else { IXMLElement valueElement = var . getFirstChildNamed ( "<STR_LIT:value>" ) ; if ( valueElement != null ) { value = valueElement . getContent ( ) ; if ( value == null ) { parseError ( "<STR_LIT>" + name ) ; } dynamicVariable . setValue ( new PlainValue ( value ) ) ; } } value = getAttribute ( var , "<STR_LIT>" ) ; if ( value != null ) { if ( dynamicVariable . getValue ( ) == null ) { dynamicVariable . setValue ( new EnvironmentValue ( value ) ) ; } else { parseError ( "<STR_LIT>" + name ) ; } } value = getAttribute ( var , "<STR_LIT>" ) ; if ( value != null ) { String regroot = getAttribute ( var , "<STR_LIT>" ) ; String regvalue = getAttribute ( var , "<STR_LIT>" ) ; if ( dynamicVariable . getValue ( ) == null ) { dynamicVariable . setValue ( new RegistryValue ( regroot , value , regvalue ) ) ; } else { parseError ( "<STR_LIT>" + name ) ; } } value = var . getAttribute ( "<STR_LIT:file>" ) ; if ( value != null ) { String stype = var . getAttribute ( "<STR_LIT:type>" ) ; String filesection = var . getAttribute ( "<STR_LIT>" ) ; String filekey = requireAttribute ( var , "<STR_LIT:key>" ) ; if ( dynamicVariable . getValue ( ) == null ) { dynamicVariable . setValue ( new PlainConfigFileValue ( value , getConfigFileType ( name , stype ) , filesection , filekey ) ) ; } else { parseError ( "<STR_LIT>" + name ) ; } } value = var . getAttribute ( "<STR_LIT>" ) ; if ( value != null ) { String entryname = requireAttribute ( var , "<STR_LIT>" ) ; String stype = var . getAttribute ( "<STR_LIT:type>" ) ; String filesection = var . getAttribute ( "<STR_LIT>" ) ; String filekey = requireAttribute ( var , "<STR_LIT:key>" ) ; if ( dynamicVariable . getValue ( ) == null ) { dynamicVariable . setValue ( new ZipEntryConfigFileValue ( value , entryname , getConfigFileType ( name , stype ) , filesection , filekey ) ) ; } else { parseError ( "<STR_LIT>" + name ) ; } } value = var . getAttribute ( "<STR_LIT>" ) ; if ( value != null ) { String entryname = requireAttribute ( var , "<STR_LIT>" ) ; String stype = var . getAttribute ( "<STR_LIT:type>" ) ; String filesection = var . getAttribute ( "<STR_LIT>" ) ; String filekey = requireAttribute ( var , "<STR_LIT:key>" ) ; if ( dynamicVariable . getValue ( ) == null ) { dynamicVariable . setValue ( new JarEntryConfigValue ( value , entryname , getConfigFileType ( name , stype ) , filesection , filekey ) ) ; } else { parseError ( "<STR_LIT>" + name ) ; } } value = getAttribute ( var , "<STR_LIT>" ) ; if ( value != null ) { if ( dynamicVariable . getValue ( ) == null ) { String dir = var . getAttribute ( "<STR_LIT>" ) ; String exectype = var . getAttribute ( "<STR_LIT:type>" ) ; String boolval = var . getAttribute ( "<STR_LIT>" ) ; boolean stderr = false ; if ( boolval != null ) { stderr = Boolean . parseBoolean ( boolval ) ; } if ( value . length ( ) <= <NUM_LIT:0> ) { parseError ( "<STR_LIT>" + name ) ; } Vector < String > cmd = new Vector < String > ( ) ; cmd . add ( value ) ; List < IXMLElement > args = var . getChildrenNamed ( "<STR_LIT>" ) ; if ( args != null ) { for ( IXMLElement arg : args ) { String content = arg . getContent ( ) ; if ( content != null ) { cmd . add ( content ) ; } } } String [ ] cmdarr = new String [ cmd . size ( ) ] ; if ( exectype . equalsIgnoreCase ( "<STR_LIT>" ) || exectype == null ) { dynamicVariable . setValue ( new ExecValue ( cmd . toArray ( cmdarr ) , dir , false , stderr ) ) ; } else if ( exectype . equalsIgnoreCase ( "<STR_LIT>" ) ) { dynamicVariable . setValue ( new ExecValue ( cmd . toArray ( cmdarr ) , dir , true , stderr ) ) ; } else { parseError ( "<STR_LIT>" + exectype + "<STR_LIT>" + name ) ; } } else { parseError ( "<STR_LIT>" + name ) ; } } if ( dynamicVariable . getValue ( ) == null ) { parseError ( "<STR_LIT>" + name ) ; } value = getAttribute ( var , "<STR_LIT>" ) ; if ( value != null ) { dynamicVariable . setCheckonce ( Boolean . valueOf ( value ) ) ; } value = getAttribute ( var , "<STR_LIT>" ) ; if ( value != null ) { dynamicVariable . setIgnoreFailure ( Boolean . valueOf ( value ) ) ; } IXMLElement filters = var . getFirstChildNamed ( "<STR_LIT>" ) ; if ( filters != null ) { List < IXMLElement > filterList = filters . getChildren ( ) ; for ( IXMLElement filterElement : filterList ) { if ( filterElement . getName ( ) . equals ( "<STR_LIT>" ) ) { String expression = filterElement . getAttribute ( "<STR_LIT>" ) ; String selectexpr = filterElement . getAttribute ( "<STR_LIT>" ) ; String replaceexpr = filterElement . getAttribute ( "<STR_LIT>" ) ; String defaultvalue = filterElement . getAttribute ( "<STR_LIT>" ) ; String scasesensitive = filterElement . getAttribute ( "<STR_LIT>" ) ; String sglobal = filterElement . getAttribute ( "<STR_LIT>" ) ; dynamicVariable . addFilter ( new RegularExpressionFilter ( expression , selectexpr , replaceexpr , defaultvalue , Boolean . valueOf ( scasesensitive != null ? scasesensitive : "<STR_LIT:true>" ) , Boolean . valueOf ( sglobal != null ? sglobal : "<STR_LIT:false>" ) ) ) ; } else if ( filterElement . getName ( ) . equals ( "<STR_LIT>" ) ) { String basedir = filterElement . getAttribute ( "<STR_LIT>" ) ; dynamicVariable . addFilter ( new LocationFilter ( basedir ) ) ; } } } try { dynamicVariable . validate ( ) ; } catch ( Exception e ) { parseError ( "<STR_LIT>" + name + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } for ( DynamicVariable dynvar : dynamicVariables ) { String conditionid = getAttribute ( var , "<STR_LIT>" ) ; dynamicVariable . setConditionid ( conditionid ) ; if ( dynvar . getName ( ) . equals ( name ) ) { dynamicVariables . remove ( dynvar ) ; parseWarn ( var , "<STR_LIT>" + name + "<STR_LIT>" ) ; } dynamicVariables . add ( dynamicVariable ) ; } } } return evaluateDynamicVariables ( dynamicVariables ) ; } private Properties evaluateDynamicVariables ( List < DynamicVariable > dynamicvariables ) throws InstallerException { Properties props = new Properties ( ) ; if ( dynamicvariables != null ) { logger . fine ( "<STR_LIT>" ) ; RulesEngine rules = getInstallData ( ) . getRules ( ) ; for ( DynamicVariable dynvar : dynamicvariables ) { String name = dynvar . getName ( ) ; logger . fine ( "<STR_LIT>" + name ) ; boolean refresh = false ; String conditionid = dynvar . getConditionid ( ) ; logger . fine ( "<STR_LIT>" + conditionid ) ; if ( ( conditionid != null ) && ( conditionid . length ( ) > <NUM_LIT:0> ) ) { if ( ( rules != null ) && rules . isConditionTrue ( conditionid ) ) { logger . fine ( "<STR_LIT>" + name + "<STR_LIT>" + conditionid + "<STR_LIT:\">" ) ; refresh = true ; } } else { logger . fine ( "<STR_LIT>" + name + "<STR_LIT>" + conditionid + "<STR_LIT:\">" ) ; refresh = true ; } if ( refresh ) { try { String newValue = dynvar . evaluate ( replacer ) ; if ( newValue != null ) { logger . fine ( "<STR_LIT>" + name + "<STR_LIT::U+0020>" + newValue ) ; props . setProperty ( name , newValue ) ; } else { logger . fine ( "<STR_LIT>" + name + "<STR_LIT>" + dynvar . getValue ( ) ) ; } } catch ( Exception e ) { throw new InstallerException ( e ) ; } } } } return props ; } protected String requireAttribute ( IXMLElement element , String attribute ) throws InstallerException { String value = getAttribute ( element , attribute ) ; if ( value == null ) { parseError ( element , "<STR_LIT:<>" + element . getName ( ) + "<STR_LIT>" + attribute + "<STR_LIT:'>" ) ; } return value ; } protected String getAttribute ( IXMLElement element , String attribute ) throws InstallerException { String value = element . getAttribute ( attribute ) ; if ( value != null ) { return substituteVariables ( value ) ; } return value ; } protected void parseError ( String message ) throws InstallerException { throw new InstallerException ( SPEC_FILE_NAME + "<STR_LIT::>" + message ) ; } protected void parseError ( IXMLElement parent , String message ) throws InstallerException { throw new InstallerException ( SPEC_FILE_NAME + "<STR_LIT::>" + parent . getLineNr ( ) + "<STR_LIT::U+0020>" + message ) ; } protected void parseWarn ( IXMLElement parent , String message ) { System . out . println ( "<STR_LIT>" + SPEC_FILE_NAME + "<STR_LIT::>" + parent . getLineNr ( ) + "<STR_LIT::U+0020>" + message ) ; } public enum ConfigType { OPTIONS ( "<STR_LIT>" ) , INI ( "<STR_LIT>" ) , XML ( "<STR_LIT>" ) , REGISTRY ( "<STR_LIT>" ) ; private static Map < String , ConfigType > lookup ; private String attribute ; ConfigType ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , ConfigType > ( ) ; for ( ConfigType operation : EnumSet . allOf ( ConfigType . class ) ) { lookup . put ( operation . getAttribute ( ) , operation ) ; } } public String getAttribute ( ) { return attribute ; } public static ConfigType getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } } } </s>
<s> package com . izforge . izpack . event ; import java . util . List ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . event . ProgressNotifiers ; public class ProgressBarInstallerListener extends AbstractProgressInstallerListener { private static final Logger logger = Logger . getLogger ( ProgressBarInstallerListener . class . getName ( ) ) ; public ProgressBarInstallerListener ( InstallData installData , ProgressNotifiers notifiers ) { super ( installData , notifiers ) ; } @ Override public void afterPacks ( List < Pack > packs , ProgressListener listener ) { ProgressNotifiers notifiers = getProgressNotifiers ( ) ; int count = notifiers . getNotifiers ( ) ; if ( count > <NUM_LIT:0> ) { String progress = getMessage ( "<STR_LIT>" ) ; String tip = getMessage ( "<STR_LIT>" ) ; if ( "<STR_LIT>" . equals ( tip ) || "<STR_LIT>" . equals ( progress ) ) { logger . fine ( "<STR_LIT>" ) ; return ; } notifiers . setNotifyProgress ( true ) ; listener . restartAction ( "<STR_LIT>" , progress , tip , count ) ; } } } </s>
<s> package com . izforge . izpack . event ; import java . io . ByteArrayInputStream ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . io . ObjectInputStream ; import java . util . ArrayList ; import java . util . List ; import com . izforge . izpack . api . event . AbstractUninstallerListener ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . util . IoHelper ; public class AntActionUninstallerListener extends AbstractUninstallerListener { private List < AntAction > befDel = new ArrayList < AntAction > ( ) ; private List < AntAction > antActions = new ArrayList < AntAction > ( ) ; public AntActionUninstallerListener ( ) { super ( ) ; } @ Override public void initialise ( ) { String buildResource = getBuildResource ( ) ; List < AntAction > allActions ; try { InputStream in = getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ; if ( in == null ) { return ; } ObjectInputStream objIn = new ObjectInputStream ( in ) ; allActions = ( List < AntAction > ) objIn . readObject ( ) ; objIn . close ( ) ; in . close ( ) ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } for ( AntAction action : allActions ) { if ( null != buildResource ) { action . setBuildFile ( new File ( buildResource ) ) ; } if ( action . getUninstallOrder ( ) . equals ( ActionBase . BEFOREDELETION ) ) { befDel . add ( action ) ; } else { if ( null == buildResource ) { File tmpFile ; try { tmpFile = IoHelper . copyToTempFile ( action . getBuildFile ( ) , "<STR_LIT>" ) ; } catch ( IOException exception ) { throw new IzPackException ( exception ) ; } action . setBuildFile ( tmpFile ) ; } List < String > props = action . getPropertyFiles ( ) ; if ( props != null ) { ArrayList < String > newProps = new ArrayList < String > ( ) ; for ( String propName : props ) { File propFile ; try { propFile = IoHelper . copyToTempFile ( propName , "<STR_LIT>" ) ; newProps . add ( propFile . getCanonicalPath ( ) ) ; } catch ( IOException exception ) { throw new IzPackException ( exception ) ; } } action . setPropertyFiles ( newProps ) ; } antActions . add ( action ) ; } } } @ Override public void beforeDelete ( List < File > files ) { for ( AntAction act : befDel ) { act . performUninstallAction ( ) ; } } @ Override public void afterDelete ( List < File > files , ProgressListener listener ) { for ( AntAction act : antActions ) { act . performUninstallAction ( ) ; } } private String getBuildResource ( ) { String buildResource = null ; try { InputStream is = getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ; if ( is != null ) { ObjectInputStream ois = new ObjectInputStream ( is ) ; byte [ ] content = ( byte [ ] ) ois . readObject ( ) ; if ( null != content ) { ByteArrayInputStream bin = new ByteArrayInputStream ( content ) ; File buildFile = IoHelper . copyToTempFile ( bin , "<STR_LIT>" , null ) ; buildResource = buildFile . getAbsolutePath ( ) ; } ois . close ( ) ; is . close ( ) ; } } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } return buildResource ; } } </s>
<s> package com . izforge . izpack . event ; import java . io . Serializable ; import java . util . HashSet ; public class ActionBase implements Serializable { private static final long serialVersionUID = <NUM_LIT> ; public static final String PACK = "<STR_LIT>" ; public static final String NAME = "<STR_LIT:name>" ; public static final String CONDITIONID = "<STR_LIT>" ; public static final String ORDER = "<STR_LIT>" ; public static final String BEFOREPACK = "<STR_LIT>" ; public static final String AFTERPACK = "<STR_LIT>" ; public static final String BEFOREPACKS = "<STR_LIT>" ; public static final String AFTERPACKS = "<STR_LIT>" ; public static final String UNINSTALL_ORDER = "<STR_LIT>" ; public static final String BEFOREDELETION = "<STR_LIT>" ; public static final String AFTERDELETION = "<STR_LIT>" ; public static final String PROPERTY = "<STR_LIT>" ; public static final String VALUE = "<STR_LIT:value>" ; public static final String YES = "<STR_LIT:yes>" ; public static final String NO = "<STR_LIT>" ; public static final String FALSE = "<STR_LIT:false>" ; public static final String TRUE = "<STR_LIT:true>" ; public static final String QUIET = "<STR_LIT>" ; public static final String VERBOSE = "<STR_LIT>" ; public static final String LOGFILE = "<STR_LIT>" ; public static final String BUILDFILE = "<STR_LIT>" ; public static final String BUILDRESOURCE = "<STR_LIT>" ; public static final String PROPERTYFILE = "<STR_LIT>" ; public static final String PATH = "<STR_LIT:path>" ; public static final String SRCDIR = "<STR_LIT>" ; public static final String TARGETDIR = "<STR_LIT>" ; public static final String TARGET = "<STR_LIT:target>" ; public static final String UNINSTALL_TARGET = "<STR_LIT>" ; public static final String ACTION = "<STR_LIT>" ; public static final String UNINSTALL_ACTION = "<STR_LIT>" ; public static final String ONDEST = "<STR_LIT>" ; public static final String COPY = "<STR_LIT>" ; public static final String REMOVE = "<STR_LIT>" ; public static final String REWIND = "<STR_LIT>" ; public static final String TOUCH = "<STR_LIT>" ; public static final String MOVE = "<STR_LIT>" ; public static final String OVERRIDE = "<STR_LIT>" ; public static final String UPDATE = "<STR_LIT>" ; public static final String NOTHING = "<STR_LIT>" ; public static final String FILESET = "<STR_LIT>" ; public static final String MESSAGEID = "<STR_LIT>" ; public static final String INCLUDE = "<STR_LIT>" ; public static final String INCLUDES = "<STR_LIT>" ; public static final String EXCLUDE = "<STR_LIT>" ; public static final String EXCLUDES = "<STR_LIT>" ; public static final String OS = "<STR_LIT>" ; public static final String FAMILY = "<STR_LIT>" ; public static final String VERSION = "<STR_LIT:version>" ; public static final String ARCH = "<STR_LIT>" ; public static final String CASESENSITIVE = "<STR_LIT>" ; public static final String UNIX = "<STR_LIT>" ; public static final String WINDOWS = "<STR_LIT>" ; public static final String MAC = "<STR_LIT>" ; public static final String ASKTRUE = "<STR_LIT>" ; public static final String ASKFALSE = "<STR_LIT>" ; private static final HashSet < String > installOrders = new HashSet < String > ( ) ; private static final HashSet < String > uninstallOrders = new HashSet < String > ( ) ; protected String uninstallOrder = ActionBase . BEFOREDELETION ; protected String order = null ; protected String messageID = null ; static { installOrders . add ( ActionBase . BEFOREPACK ) ; installOrders . add ( ActionBase . AFTERPACK ) ; installOrders . add ( ActionBase . BEFOREPACKS ) ; installOrders . add ( ActionBase . AFTERPACKS ) ; uninstallOrders . add ( ActionBase . BEFOREDELETION ) ; uninstallOrders . add ( ActionBase . AFTERDELETION ) ; } public ActionBase ( ) { super ( ) ; } public String getOrder ( ) { return order ; } public void setOrder ( String order ) throws Exception { if ( ! installOrders . contains ( order ) ) { throw new Exception ( "<STR_LIT>" ) ; } this . order = order ; } public String getUninstallOrder ( ) { return uninstallOrder ; } public void setUninstallOrder ( String order ) throws Exception { if ( ! uninstallOrders . contains ( order ) ) { throw new Exception ( "<STR_LIT>" ) ; } this . uninstallOrder = order ; } public String getMessageID ( ) { return messageID ; } public void setMessageID ( String messageID ) { this . messageID = messageID ; } } </s>
<s> package com . izforge . izpack . event ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . util . Iterator ; import java . util . List ; import java . util . StringTokenizer ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . exception . NativeLibException ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . exception . WrappedNativeLibException ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . os . RegistryDefaultHandler ; import com . izforge . izpack . core . os . RegistryHandler ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . installer . unpacker . IUnpacker ; import com . izforge . izpack . util . CleanupClient ; import com . izforge . izpack . util . Housekeeper ; import com . izforge . izpack . util . IoHelper ; import com . izforge . izpack . util . file . FileUtils ; import com . izforge . izpack . util . helper . SpecHelper ; public class RegistryInstallerListener extends AbstractProgressInstallerListener implements CleanupClient { private static final Logger logger = Logger . getLogger ( RegistryInstallerListener . class . getName ( ) ) ; static final String SPEC_FILE_NAME = "<STR_LIT>" ; private static final String REG_KEY = "<STR_LIT:key>" ; private static final String REG_VALUE = "<STR_LIT:value>" ; private static final String REG_ROOT = "<STR_LIT:root>" ; private static final String REG_BASENAME = "<STR_LIT:name>" ; private static final String REG_KEYPATH = "<STR_LIT>" ; private static final String REG_DWORD = "<STR_LIT>" ; private static final String REG_STRING = "<STR_LIT:string>" ; private static final String REG_MULTI = "<STR_LIT>" ; private static final String REG_BIN = "<STR_LIT>" ; private static final String REG_DATA = "<STR_LIT:data>" ; private static final String REG_OVERRIDE = "<STR_LIT>" ; private static final String SAVE_PREVIOUS = "<STR_LIT>" ; private List registryModificationLog ; private IUnpacker unpacker ; private VariableSubstitutor substituter ; private final UninstallData uninstallData ; private final Resources resources ; private final RulesEngine rules ; private final Housekeeper housekeeper ; private final RegistryHandler registry ; private final SpecHelper spec ; static final String UNINSTALLER_ICON = "<STR_LIT>" ; public RegistryInstallerListener ( IUnpacker unpacker , VariableSubstitutor substituter , InstallData installData , UninstallData uninstallData , Resources resources , RulesEngine rules , Housekeeper housekeeper , RegistryDefaultHandler handler ) { super ( installData ) ; this . substituter = substituter ; this . unpacker = unpacker ; this . uninstallData = uninstallData ; this . resources = resources ; this . rules = rules ; this . housekeeper = housekeeper ; this . registry = handler . getInstance ( ) ; spec = new SpecHelper ( resources ) ; } @ Override public void initialise ( ) { if ( registry != null ) { Variables variables = getInstallData ( ) . getVariables ( ) ; String uninstallName = variables . get ( "<STR_LIT>" ) + "<STR_LIT:U+0020>" + variables . get ( "<STR_LIT>" ) ; registry . setUninstallName ( uninstallName ) ; } } @ Override public void afterPacks ( List < Pack > packs , ProgressListener listener ) { if ( registry != null ) { try { spec . readSpec ( SPEC_FILE_NAME , substituter ) ; } catch ( Exception exception ) { throw new IzPackException ( "<STR_LIT>" + SPEC_FILE_NAME , exception ) ; } try { afterPacks ( packs ) ; } catch ( NativeLibException e ) { throw new WrappedNativeLibException ( e , getInstallData ( ) . getMessages ( ) ) ; } } } public void cleanUp ( ) { InstallData installData = getInstallData ( ) ; if ( ! installData . isInstallSuccess ( ) && registryModificationLog != null && ! registryModificationLog . isEmpty ( ) ) { try { registry . activateLogging ( ) ; registry . setLoggingInfo ( registryModificationLog ) ; registry . rewind ( ) ; } catch ( Exception e ) { logger . log ( Level . SEVERE , e . getMessage ( ) , e ) ; } } } private void afterPacks ( List < Pack > packs ) throws NativeLibException , InstallerException { housekeeper . registerForCleanup ( this ) ; IXMLElement uninstallerPack = null ; unpacker . setDisableInterrupt ( true ) ; registry . activateLogging ( ) ; if ( spec . getSpec ( ) != null ) { uninstallerPack = spec . getPackForName ( "<STR_LIT>" ) ; performPack ( uninstallerPack ) ; for ( Pack selectedPack : packs ) { IXMLElement pack = spec . getPackForName ( selectedPack . getName ( ) ) ; performPack ( pack ) ; } } String uninstallSuffix = getInstallData ( ) . getVariable ( "<STR_LIT>" ) ; if ( uninstallSuffix != null ) { registry . setUninstallName ( registry . getUninstallName ( ) + "<STR_LIT:U+0020>" + uninstallSuffix ) ; } if ( uninstallerPack == null ) { registerUninstallKey ( ) ; } List < Object > info = registry . getLoggingInfo ( ) ; if ( info != null ) { uninstallData . addAdditionalData ( "<STR_LIT>" , info ) ; } registryModificationLog = info ; } private void performPack ( IXMLElement pack ) throws InstallerException , NativeLibException { if ( pack == null ) { return ; } String packCondition = pack . getAttribute ( "<STR_LIT>" ) ; if ( packCondition != null ) { logger . fine ( "<STR_LIT>" + packCondition + "<STR_LIT>" ) ; if ( ! rules . isConditionTrue ( packCondition ) ) { logger . fine ( "<STR_LIT>" + packCondition + "<STR_LIT>" ) ; return ; } } List < IXMLElement > regEntries = pack . getChildren ( ) ; if ( regEntries == null ) { return ; } for ( IXMLElement regEntry : regEntries ) { String condition = regEntry . getAttribute ( "<STR_LIT>" ) ; if ( condition != null ) { logger . fine ( "<STR_LIT>" + condition + "<STR_LIT>" ) ; if ( ! rules . isConditionTrue ( condition ) ) { logger . fine ( "<STR_LIT>" + condition + "<STR_LIT>" ) ; continue ; } } String type = regEntry . getName ( ) ; if ( type . equalsIgnoreCase ( REG_KEY ) ) { performKeySetting ( regEntry ) ; } else if ( type . equalsIgnoreCase ( REG_VALUE ) ) { performValueSetting ( regEntry ) ; } else { spec . parseError ( regEntry , "<STR_LIT>" ) ; } } } private void performValueSetting ( IXMLElement regEntry ) throws InstallerException , NativeLibException { String name = spec . getRequiredAttribute ( regEntry , REG_BASENAME ) ; name = substituter . substitute ( name ) ; String keypath = spec . getRequiredAttribute ( regEntry , REG_KEYPATH ) ; keypath = substituter . substitute ( keypath ) ; String root = spec . getRequiredAttribute ( regEntry , REG_ROOT ) ; int rootId = resolveRoot ( regEntry , root ) ; registry . setRoot ( rootId ) ; String override = regEntry . getAttribute ( REG_OVERRIDE , "<STR_LIT:true>" ) ; if ( ! "<STR_LIT:true>" . equalsIgnoreCase ( override ) ) { if ( registry . getValue ( keypath , name , null ) != null ) { return ; } } registry . setLogPrevSetValueFlag ( "<STR_LIT:true>" . equalsIgnoreCase ( regEntry . getAttribute ( SAVE_PREVIOUS , "<STR_LIT:true>" ) ) ) ; String value = regEntry . getAttribute ( REG_DWORD ) ; if ( value != null ) { value = substituter . substitute ( value ) ; registry . setValue ( keypath , name , Long . parseLong ( value ) ) ; return ; } value = regEntry . getAttribute ( REG_STRING ) ; if ( value != null ) { value = substituter . substitute ( value ) ; registry . setValue ( keypath , name , value ) ; return ; } List < IXMLElement > values = regEntry . getChildrenNamed ( REG_MULTI ) ; if ( values != null && ! values . isEmpty ( ) ) { Iterator < IXMLElement > multiIter = values . iterator ( ) ; String [ ] multiString = new String [ values . size ( ) ] ; for ( int i = <NUM_LIT:0> ; multiIter . hasNext ( ) ; ++ i ) { IXMLElement element = multiIter . next ( ) ; multiString [ i ] = spec . getRequiredAttribute ( element , REG_DATA ) ; multiString [ i ] = substituter . substitute ( multiString [ i ] ) ; } registry . setValue ( keypath , name , multiString ) ; return ; } values = regEntry . getChildrenNamed ( REG_BIN ) ; if ( values != null && ! values . isEmpty ( ) ) { Iterator < IXMLElement > multiIter = values . iterator ( ) ; StringBuilder buf = new StringBuilder ( ) ; while ( multiIter . hasNext ( ) ) { IXMLElement element = multiIter . next ( ) ; String tmp = spec . getRequiredAttribute ( element , REG_DATA ) ; buf . append ( tmp ) ; if ( ! tmp . endsWith ( "<STR_LIT:U+002C>" ) && multiIter . hasNext ( ) ) { buf . append ( "<STR_LIT:U+002C>" ) ; } } byte [ ] bytes = extractBytes ( regEntry , substituter . substitute ( buf . toString ( ) ) ) ; registry . setValue ( keypath , name , bytes ) ; return ; } spec . parseError ( regEntry , "<STR_LIT>" ) ; } private byte [ ] extractBytes ( IXMLElement element , String byteString ) throws InstallerException { StringTokenizer st = new StringTokenizer ( byteString , "<STR_LIT:U+002C>" ) ; byte [ ] retval = new byte [ st . countTokens ( ) ] ; int i = <NUM_LIT:0> ; while ( st . hasMoreTokens ( ) ) { byte value = <NUM_LIT:0> ; String token = st . nextToken ( ) . trim ( ) ; try { int tval = Integer . parseInt ( token , <NUM_LIT:16> ) ; if ( tval < <NUM_LIT:0> || tval > <NUM_LIT> ) { throw new InstallerException ( "<STR_LIT>" + tval ) ; } if ( tval > <NUM_LIT> ) { tval -= <NUM_LIT> ; } value = ( byte ) tval ; } catch ( NumberFormatException nfe ) { spec . parseError ( element , "<STR_LIT>" + "<STR_LIT>" ) ; } retval [ i ++ ] = value ; } return ( retval ) ; } private void performKeySetting ( IXMLElement regEntry ) throws InstallerException , NativeLibException { String path = spec . getRequiredAttribute ( regEntry , REG_KEYPATH ) ; path = substituter . substitute ( path ) ; String root = spec . getRequiredAttribute ( regEntry , REG_ROOT ) ; int rootId = resolveRoot ( regEntry , root ) ; registry . setRoot ( rootId ) ; if ( ! registry . keyExist ( path ) ) { registry . createKey ( path ) ; } } private int resolveRoot ( IXMLElement regEntry , String root ) { String root1 = substituter . substitute ( root ) ; Integer tmp = RegistryHandler . ROOT_KEY_MAP . get ( root1 ) ; if ( tmp != null ) { return ( tmp ) ; } spec . parseError ( regEntry , "<STR_LIT>" + root1 + "<STR_LIT>" ) ; return <NUM_LIT:0> ; } private void registerUninstallKey ( ) throws NativeLibException { String uninstallName = registry . getUninstallName ( ) ; if ( uninstallName == null ) { return ; } InstallData installData = getInstallData ( ) ; String keyName = RegistryHandler . UNINSTALL_ROOT + uninstallName ; String uninstallerPath = IoHelper . translatePath ( installData . getInfo ( ) . getUninstallerPath ( ) , installData . getVariables ( ) ) ; String cmd = "<STR_LIT:\">" + installData . getVariable ( "<STR_LIT>" ) + "<STR_LIT>" + uninstallerPath + "<STR_LIT:\\>" + installData . getInfo ( ) . getUninstallerName ( ) + "<STR_LIT:\">" ; String appVersion = installData . getVariable ( "<STR_LIT>" ) ; String appUrl = installData . getVariable ( "<STR_LIT>" ) ; try { registry . setRoot ( RegistryHandler . HKEY_LOCAL_MACHINE ) ; registry . setValue ( keyName , "<STR_LIT>" , uninstallName ) ; } catch ( NativeLibException exception ) { logger . warning ( "<STR_LIT>" + exception . getMessage ( ) ) ; registry . setRoot ( RegistryHandler . HKEY_CURRENT_USER ) ; registry . setValue ( keyName , "<STR_LIT>" , uninstallName ) ; } registry . setValue ( keyName , "<STR_LIT>" , cmd ) ; registry . setValue ( keyName , "<STR_LIT>" , appVersion ) ; if ( appUrl != null && appUrl . length ( ) > <NUM_LIT:0> ) { registry . setValue ( keyName , "<STR_LIT>" , appUrl ) ; } InputStream in = null ; FileOutputStream out = null ; try { in = resources . getInputStream ( UNINSTALLER_ICON ) ; String iconPath = installData . getVariable ( "<STR_LIT>" ) + File . separator + "<STR_LIT>" + File . separator + "<STR_LIT>" ; out = new FileOutputStream ( iconPath ) ; IoHelper . copyStream ( in , out ) ; registry . setValue ( keyName , "<STR_LIT>" , iconPath ) ; } catch ( ResourceNotFoundException exception ) { logger . info ( exception . getMessage ( ) ) ; } catch ( IOException exception ) { throw new InstallerException ( exception ) ; } finally { FileUtils . close ( in ) ; FileUtils . close ( out ) ; } } } </s>
<s> package com . izforge . izpack . event ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . event . AbstractInstallerListener ; import com . izforge . izpack . api . event . InstallerListener ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . event . ProgressNotifiers ; public abstract class AbstractProgressInstallerListener extends AbstractInstallerListener { private final InstallData installData ; private final ProgressNotifiers notifiers ; public AbstractProgressInstallerListener ( InstallData installData ) { this ( installData , null ) ; } public AbstractProgressInstallerListener ( InstallData installData , ProgressNotifiers notifiers ) { this . installData = installData ; this . notifiers = notifiers ; } protected boolean notifyProgress ( ) { return ( notifiers != null && notifiers . notifyProgress ( ) ) ; } protected int getProgressNotifierId ( ) { return notifiers != null ? notifiers . indexOf ( this ) + <NUM_LIT:1> : <NUM_LIT:0> ; } protected void setProgressNotifier ( ) { if ( notifiers != null ) { notifiers . addNotifier ( this ) ; } } protected ProgressNotifiers getProgressNotifiers ( ) { return notifiers ; } protected InstallData getInstallData ( ) { return installData ; } protected String getMessage ( String id ) { return installData . getMessages ( ) . get ( id ) ; } } </s>
<s> package com . izforge . izpack . event ; import java . util . logging . Logger ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . util . config . ConfigurableTask ; public class ConfigurationActionTask { private static final Logger logger = Logger . getLogger ( ConfigurationActionTask . class . getName ( ) ) ; private String condition ; private ConfigurableTask task ; private RulesEngine rules ; public ConfigurationActionTask ( ConfigurableTask task , String condition , RulesEngine rules ) { this . task = task ; this . condition = condition ; this . rules = rules ; } public ConfigurableTask getConfigurableTask ( ) { return task ; } public void setConfigurableTask ( ConfigurableTask task ) { this . task = task ; } public String getCondition ( ) { return condition ; } public void setCondition ( String condition ) { this . condition = condition ; } public void execute ( ) throws Exception { if ( condition == null || condition . trim ( ) . length ( ) == <NUM_LIT:0> || rules . isConditionTrue ( condition ) ) { logger . fine ( "<STR_LIT>" + task . getClass ( ) . getName ( ) ) ; this . task . execute ( ) ; } else { logger . fine ( "<STR_LIT>" + condition + "<STR_LIT>" + task . getClass ( ) . getName ( ) ) ; } } } </s>
<s> package com . izforge . izpack . event ; import java . io . File ; import java . io . InputStream ; import java . io . ObjectInputStream ; import java . util . List ; import com . izforge . izpack . api . event . AbstractUninstallerListener ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . exception . NativeLibException ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . exception . WrappedNativeLibException ; import com . izforge . izpack . api . resource . Messages ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . core . os . RegistryDefaultHandler ; import com . izforge . izpack . core . os . RegistryHandler ; public class RegistryUninstallerListener extends AbstractUninstallerListener { private final RegistryDefaultHandler handler ; private final Resources resources ; private final Messages messages ; private List actions ; public RegistryUninstallerListener ( RegistryDefaultHandler handler , Resources resources , Messages messages ) { this . handler = handler ; this . resources = resources ; this . messages = messages ; } @ Override public void initialise ( ) { try { InputStream in = resources . getInputStream ( "<STR_LIT>" ) ; ObjectInputStream objIn = new ObjectInputStream ( in ) ; actions = ( List ) objIn . readObject ( ) ; objIn . close ( ) ; in . close ( ) ; } catch ( ResourceNotFoundException ignore ) { } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void beforeDelete ( List < File > files ) { if ( actions == null || actions . isEmpty ( ) ) { return ; } try { RegistryHandler registryHandler = handler . getInstance ( ) ; if ( registryHandler == null ) { return ; } registryHandler . activateLogging ( ) ; registryHandler . setLoggingInfo ( actions ) ; registryHandler . rewind ( ) ; } catch ( NativeLibException e ) { throw new WrappedNativeLibException ( e , messages ) ; } } } </s>
<s> package com . izforge . izpack . event ; import java . io . BufferedInputStream ; import java . io . BufferedOutputStream ; import java . io . ByteArrayOutputStream ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . logging . Logger ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . event . ProgressNotifiers ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . util . FileUtil ; import com . izforge . izpack . util . file . FileUtils ; import com . izforge . izpack . util . helper . SpecHelper ; public class AntActionInstallerListener extends AbstractProgressInstallerListener { public static final String SPEC_FILE_NAME = "<STR_LIT>" ; private final Map < String , Map < Object , List < AntAction > > > actions = new HashMap < String , Map < Object , List < AntAction > > > ( ) ; private List < AntAction > uninstActions = new ArrayList < AntAction > ( ) ; private VariableSubstitutor replacer ; private UninstallData uninstallData ; private SpecHelper spec ; private static final Logger logger = Logger . getLogger ( AntActionInstallerListener . class . getName ( ) ) ; public AntActionInstallerListener ( VariableSubstitutor replacer , Resources resources , InstallData installData , UninstallData uninstallData , ProgressNotifiers notifiers ) { super ( installData , notifiers ) ; this . replacer = replacer ; this . uninstallData = uninstallData ; spec = new SpecHelper ( resources ) ; } @ Override public void beforePacks ( List < Pack > packs ) { try { spec . readSpec ( SPEC_FILE_NAME , replacer ) ; } catch ( Exception exception ) { throw new IzPackException ( "<STR_LIT>" + SPEC_FILE_NAME , exception ) ; } if ( spec . getSpec ( ) == null ) { return ; } for ( Pack pack : packs ) { IXMLElement packElement = spec . getPackForName ( pack . getName ( ) ) ; if ( packElement == null ) { continue ; } Map < Object , List < AntAction > > packActions = new HashMap < Object , List < AntAction > > ( ) ; packActions . put ( ActionBase . BEFOREPACK , new ArrayList < AntAction > ( ) ) ; packActions . put ( ActionBase . AFTERPACK , new ArrayList < AntAction > ( ) ) ; packActions . put ( ActionBase . BEFOREPACKS , new ArrayList < AntAction > ( ) ) ; packActions . put ( ActionBase . AFTERPACKS , new ArrayList < AntAction > ( ) ) ; List < IXMLElement > antCallEntries = packElement . getChildrenNamed ( AntAction . ANTCALL ) ; if ( antCallEntries != null && antCallEntries . size ( ) >= <NUM_LIT:1> ) { for ( IXMLElement antCallEntry : antCallEntries ) { AntAction act = readAntCall ( antCallEntry ) ; if ( act != null ) { List < AntAction > antActions = packActions . get ( act . getOrder ( ) ) ; antActions . add ( act ) ; } } if ( ! packActions . get ( ActionBase . AFTERPACKS ) . isEmpty ( ) ) { setProgressNotifier ( ) ; } } actions . put ( pack . getName ( ) , packActions ) ; } for ( Pack pack : packs ) { String currentPack = pack . getName ( ) ; performAllActions ( currentPack , ActionBase . BEFOREPACKS , null ) ; } } @ Override public void beforePack ( Pack pack , int i ) { performAllActions ( pack . getName ( ) , ActionBase . BEFOREPACK , null ) ; } @ Override public void afterPack ( Pack pack , int i ) { performAllActions ( pack . getName ( ) , ActionBase . AFTERPACK , null ) ; } @ Override public void afterPacks ( List < Pack > packs , ProgressListener listener ) { if ( notifyProgress ( ) ) { int count = getActionCount ( packs , ActionBase . AFTERPACKS ) ; listener . nextStep ( getMessage ( "<STR_LIT>" ) , getProgressNotifierId ( ) , count ) ; } for ( Pack pack : packs ) { String currentPack = pack . getName ( ) ; performAllActions ( currentPack , ActionBase . AFTERPACKS , listener ) ; } if ( ! uninstActions . isEmpty ( ) ) { uninstallData . addAdditionalData ( "<STR_LIT>" , uninstActions ) ; } } private int getActionCount ( List < Pack > packs , String order ) { int result = <NUM_LIT:0> ; for ( Pack pack : packs ) { String currentPack = pack . getName ( ) ; List < AntAction > actList = getActions ( currentPack , order ) ; if ( actList != null ) { result += actList . size ( ) ; } } return result ; } protected List < AntAction > getActions ( String packName , String order ) { Map < Object , List < AntAction > > packActions = actions . get ( packName ) ; if ( packActions == null || packActions . isEmpty ( ) ) { return null ; } return packActions . get ( order ) ; } private void performAllActions ( String packName , String order , ProgressListener listener ) throws InstallerException { List < AntAction > actList = getActions ( packName , order ) ; if ( actList == null || actList . isEmpty ( ) ) { return ; } boolean notifyProgress = notifyProgress ( ) && order . equals ( ActionBase . AFTERPACKS ) ; logger . fine ( "<STR_LIT>" + order + "<STR_LIT>" + packName + "<STR_LIT>" ) ; RulesEngine rules = getInstallData ( ) . getRules ( ) ; for ( AntAction act : actList ) { if ( notifyProgress ) { String message = ( act . getMessageID ( ) != null ) ? getMessage ( act . getMessageID ( ) ) : "<STR_LIT>" ; listener . progress ( message ) ; } try { String conditionId = act . getConditionId ( ) ; if ( conditionId == null || rules . isConditionTrue ( conditionId ) ) { act . performInstallAction ( ) ; } } catch ( Exception e ) { throw new InstallerException ( e ) ; } if ( ! act . getUninstallTargets ( ) . isEmpty ( ) ) { uninstActions . add ( act ) ; } } } private AntAction readAntCall ( IXMLElement el ) { String buildFile ; String buildResource ; if ( el == null ) { return null ; } AntAction act = new AntAction ( ) ; try { act . setOrder ( spec . getRequiredAttribute ( el , ActionBase . ORDER ) ) ; act . setUninstallOrder ( el . getAttribute ( ActionBase . UNINSTALL_ORDER , ActionBase . BEFOREDELETION ) ) ; } catch ( Exception e ) { throw new InstallerException ( e ) ; } act . setQuiet ( spec . isAttributeYes ( el , ActionBase . QUIET , false ) ) ; act . setVerbose ( spec . isAttributeYes ( el , ActionBase . VERBOSE , false ) ) ; buildFile = el . getAttribute ( ActionBase . BUILDFILE ) ; act . setConditionId ( el . getAttribute ( ActionBase . CONDITIONID ) ) ; buildResource = processBuildfileResource ( spec , el ) ; if ( null == buildFile && null == buildResource ) { throw new InstallerException ( "<STR_LIT>" + SPEC_FILE_NAME + "<STR_LIT>" ) ; } if ( null != buildFile && null != buildResource ) { throw new InstallerException ( "<STR_LIT>" + SPEC_FILE_NAME + "<STR_LIT>" ) ; } InstallData installData = getInstallData ( ) ; if ( null != buildFile ) { try { act . setBuildFile ( FileUtil . getAbsoluteFile ( replacer . substitute ( buildFile ) , installData . getInstallPath ( ) ) ) ; } catch ( Exception e ) { act . setBuildFile ( FileUtil . getAbsoluteFile ( buildFile , installData . getInstallPath ( ) ) ) ; } } else { act . setBuildFile ( new File ( buildResource ) ) ; } String str = el . getAttribute ( ActionBase . LOGFILE ) ; if ( str != null ) { try { act . setLogFile ( FileUtil . getAbsoluteFile ( replacer . substitute ( str ) , installData . getInstallPath ( ) ) ) ; } catch ( Exception e ) { act . setLogFile ( FileUtil . getAbsoluteFile ( str , installData . getInstallPath ( ) ) ) ; } } String msgId = el . getAttribute ( ActionBase . MESSAGEID ) ; if ( msgId != null && msgId . length ( ) > <NUM_LIT:0> ) { act . setMessageID ( msgId ) ; } for ( IXMLElement propEl : el . getChildrenNamed ( ActionBase . PROPERTYFILE ) ) { act . addPropertyFile ( spec . getRequiredAttribute ( propEl , ActionBase . PATH ) ) ; } for ( IXMLElement propEl : el . getChildrenNamed ( ActionBase . PROPERTY ) ) { act . setProperty ( spec . getRequiredAttribute ( propEl , ActionBase . NAME ) , spec . getRequiredAttribute ( propEl , ActionBase . VALUE ) ) ; } for ( IXMLElement targEl : el . getChildrenNamed ( ActionBase . TARGET ) ) { act . addTarget ( spec . getRequiredAttribute ( targEl , ActionBase . NAME ) ) ; } for ( IXMLElement utargEl : el . getChildrenNamed ( ActionBase . UNINSTALL_TARGET ) ) { act . addUninstallTarget ( spec . getRequiredAttribute ( utargEl , ActionBase . NAME ) ) ; } if ( null != buildResource && act . getUninstallTargets ( ) . size ( ) > <NUM_LIT:0> ) { addBuildResourceToUninstallerData ( buildResource ) ; } return act ; } private String processBuildfileResource ( SpecHelper spec , IXMLElement el ) { String buildResource = null ; String attr = el . getAttribute ( ActionBase . BUILDRESOURCE ) ; if ( null != attr ) { BufferedInputStream bis = new BufferedInputStream ( spec . getResource ( attr ) ) ; BufferedOutputStream bos = null ; try { File tempFile = File . createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) ; tempFile . deleteOnExit ( ) ; bos = new BufferedOutputStream ( new FileOutputStream ( tempFile ) ) ; int aByte ; while ( - <NUM_LIT:1> != ( aByte = bis . read ( ) ) ) { bos . write ( aByte ) ; } bis . close ( ) ; bos . close ( ) ; buildResource = tempFile . getAbsolutePath ( ) ; } catch ( Exception x ) { throw new InstallerException ( "<STR_LIT>" , x ) ; } finally { FileUtils . close ( bos ) ; } } return buildResource ; } private void addBuildResourceToUninstallerData ( String buildResource ) throws InstallerException { byte [ ] content ; File buildFile = new File ( buildResource ) ; ByteArrayOutputStream bos = new ByteArrayOutputStream ( ( int ) buildFile . length ( ) ) ; BufferedInputStream bis = null ; try { bis = new BufferedInputStream ( new FileInputStream ( buildFile ) ) ; int aByte ; while ( - <NUM_LIT:1> != ( aByte = bis . read ( ) ) ) { bos . write ( aByte ) ; } content = bos . toByteArray ( ) ; uninstallData . addAdditionalData ( "<STR_LIT>" , content ) ; } catch ( Exception x ) { throw new InstallerException ( "<STR_LIT>" , x ) ; } finally { FileUtils . close ( bis ) ; FileUtils . close ( bos ) ; } } } </s>
<s> package com . izforge . izpack . event ; import static org . junit . Assert . assertArrayEquals ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertNotNull ; import static org . junit . Assert . assertTrue ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . util . Arrays ; import java . util . Properties ; import org . junit . Before ; import org . junit . Rule ; import org . junit . Test ; import org . junit . rules . TemporaryFolder ; import org . junit . runner . RunWith ; import org . mockito . Mockito ; import com . coi . tools . os . win . RegDataContainer ; import com . izforge . izpack . api . data . AutomatedInstallData ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . exception . NativeLibException ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . resource . Messages ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . data . DefaultVariables ; import com . izforge . izpack . core . os . RegistryDefaultHandler ; import com . izforge . izpack . core . os . RegistryHandler ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . installer . unpacker . IUnpacker ; import com . izforge . izpack . test . RunOn ; import com . izforge . izpack . test . junit . PlatformRunner ; import com . izforge . izpack . test . util . TestLibrarian ; import com . izforge . izpack . util . Housekeeper ; import com . izforge . izpack . util . Librarian ; import com . izforge . izpack . util . Platform ; import com . izforge . izpack . util . Platforms ; import com . izforge . izpack . util . PrivilegedRunner ; import com . izforge . izpack . util . TargetFactory ; import com . izforge . izpack . util . os . Win_RegistryHandler ; @ RunWith ( PlatformRunner . class ) @ RunOn ( Platform . Name . WINDOWS ) public class RegistryInstallerListenerTest { @ Rule public TemporaryFolder temporaryFolder = new TemporaryFolder ( ) ; private VariableSubstitutor replacer ; private InstallData installData ; private Resources resources ; private IUnpacker unpacker ; private UninstallData uninstallData ; private RulesEngine rules ; private Housekeeper housekeeper ; private RegistryDefaultHandler handler ; private RegistryHandler registry ; @ Before public void setUp ( ) throws IOException { assertFalse ( "<STR_LIT>" , new PrivilegedRunner ( Platforms . WINDOWS ) . isElevationNeeded ( ) ) ; Properties properties = new Properties ( ) ; Variables variables = new DefaultVariables ( properties ) ; replacer = new VariableSubstitutorImpl ( variables ) ; AutomatedInstallData data = new AutomatedInstallData ( variables , Platforms . WINDOWS ) ; data . setMessages ( Mockito . mock ( Messages . class ) ) ; installData = data ; File installDir = temporaryFolder . getRoot ( ) ; installData . setInstallPath ( installDir . getPath ( ) ) ; resources = Mockito . mock ( Resources . class ) ; InputStream specStream = getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ; assertNotNull ( specStream ) ; Mockito . when ( resources . getInputStream ( RegistryInstallerListener . SPEC_FILE_NAME ) ) . thenReturn ( specStream ) ; Mockito . when ( resources . getInputStream ( RegistryInstallerListener . UNINSTALLER_ICON ) ) . thenThrow ( new ResourceNotFoundException ( "<STR_LIT>" ) ) ; unpacker = Mockito . mock ( IUnpacker . class ) ; uninstallData = new UninstallData ( ) ; rules = Mockito . mock ( RulesEngine . class ) ; housekeeper = Mockito . mock ( Housekeeper . class ) ; handler = Mockito . mock ( RegistryDefaultHandler . class ) ; TargetFactory factory = Mockito . mock ( TargetFactory . class ) ; Mockito . when ( factory . getNativeLibraryExtension ( ) ) . thenReturn ( "<STR_LIT>" ) ; Librarian librarian = new TestLibrarian ( factory , housekeeper ) ; registry = new Win_RegistryHandler ( librarian ) ; Mockito . when ( handler . getInstance ( ) ) . thenReturn ( registry ) ; } @ Test public void testRegistry ( ) throws NativeLibException { String appName = "<STR_LIT>" ; String appVersion = "<STR_LIT:1.0>" ; String uninstallName = appName + "<STR_LIT:->" + appVersion ; String appURL = "<STR_LIT>" ; String uninstallKey = RegistryHandler . UNINSTALL_ROOT + uninstallName ; String key = "<STR_LIT>" + uninstallName ; deleteKey ( uninstallKey ) ; deleteKey ( key + "<STR_LIT>" ) ; deleteKey ( key + "<STR_LIT>" ) ; deleteKey ( key + "<STR_LIT>" ) ; deleteKey ( key + "<STR_LIT>" ) ; deleteKey ( key + "<STR_LIT>" ) ; deleteKey ( key ) ; installData . setVariable ( "<STR_LIT>" , appName ) ; installData . setVariable ( "<STR_LIT>" , appVersion ) ; installData . setVariable ( "<STR_LIT>" , uninstallName ) ; installData . setVariable ( "<STR_LIT>" , appURL ) ; RegistryInstallerListener listener = new RegistryInstallerListener ( unpacker , replacer , installData , uninstallData , resources , rules , housekeeper , handler ) ; listener . initialise ( ) ; ProgressListener progressListener = Mockito . mock ( ProgressListener . class ) ; Pack pack = new Pack ( "<STR_LIT>" , null , null , null , null , true , true , false , null , true , <NUM_LIT:0> ) ; listener . afterPacks ( Arrays . asList ( pack ) , progressListener ) ; assertStringEquals ( uninstallKey , "<STR_LIT>" , uninstallName ) ; assertStringEquals ( uninstallKey , "<STR_LIT>" , "<STR_LIT>" + installData . getInstallPath ( ) + "<STR_LIT>" ) ; assertStringEquals ( uninstallKey , "<STR_LIT>" , installData . getInstallPath ( ) + "<STR_LIT>" ) ; assertStringEquals ( uninstallKey , "<STR_LIT>" , appURL ) ; assertKeyExists ( key + "<STR_LIT>" ) ; assertStringEquals ( key , "<STR_LIT>" , installData . getInstallPath ( ) ) ; assertLongEquals ( key , "<STR_LIT>" , <NUM_LIT> ) ; assertBytesEquals ( key , "<STR_LIT>" , new byte [ ] { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } ) ; assertStringsEquals ( key , "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; installData . setInstallSuccess ( false ) ; listener . cleanUp ( ) ; assertKeyNotExists ( uninstallKey ) ; assertKeyNotExists ( key ) ; } private void assertKeyExists ( String key ) throws NativeLibException { registry . setRoot ( RegistryHandler . HKEY_LOCAL_MACHINE ) ; assertTrue ( registry . keyExist ( key ) ) ; } private void assertKeyNotExists ( String key ) throws NativeLibException { registry . setRoot ( RegistryHandler . HKEY_LOCAL_MACHINE ) ; assertFalse ( registry . keyExist ( key ) ) ; } private void assertStringEquals ( String key , String name , String expected ) throws NativeLibException { RegDataContainer value = getValue ( key , name , RegDataContainer . REG_SZ , "<STR_LIT>" ) ; assertEquals ( expected , value . getStringData ( ) ) ; } private void assertLongEquals ( String key , String name , long expected ) throws NativeLibException { RegDataContainer value = getValue ( key , name , RegDataContainer . REG_DWORD , "<STR_LIT>" ) ; assertEquals ( expected , value . getDwordData ( ) ) ; } private void assertBytesEquals ( String key , String name , byte [ ] expected ) throws NativeLibException { RegDataContainer value = getValue ( key , name , RegDataContainer . REG_BINARY , "<STR_LIT>" ) ; assertArrayEquals ( expected , value . getBinData ( ) ) ; } private void assertStringsEquals ( String key , String name , String [ ] expected ) throws NativeLibException { RegDataContainer value = getValue ( key , name , RegDataContainer . REG_MULTI_SZ , "<STR_LIT>" ) ; assertArrayEquals ( expected , value . getMultiStringData ( ) ) ; } private RegDataContainer getValue ( String key , String name , int type , String typeName ) throws NativeLibException { assertKeyExists ( key ) ; assertTrue ( registry . valueExist ( key , name ) ) ; RegDataContainer value = registry . getValue ( key , name ) ; assertEquals ( "<STR_LIT>" + name + "<STR_LIT>" + typeName , type , value . getType ( ) ) ; return value ; } private void deleteKey ( String key ) throws NativeLibException { registry . setRoot ( RegistryHandler . HKEY_LOCAL_MACHINE ) ; if ( registry . keyExist ( key ) ) { registry . deleteKey ( key ) ; } } } </s>
<s> package com . izforge . izpack . event ; import static com . izforge . izpack . test . util . TestHelper . assertFileExists ; import static com . izforge . izpack . test . util . TestHelper . assertFileNotExists ; import static org . junit . Assert . assertNotNull ; import static org . junit . Assert . assertTrue ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . util . Arrays ; import java . util . List ; import java . util . Properties ; import org . apache . commons . io . FileUtils ; import org . junit . Before ; import org . junit . Rule ; import org . junit . Test ; import org . junit . rules . TemporaryFolder ; import org . mockito . Mockito ; import com . izforge . izpack . api . data . AutomatedInstallData ; import com . izforge . izpack . api . data . Blockable ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . OverrideType ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . PackFile ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . event . ProgressNotifiers ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . data . DefaultVariables ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . installer . event . ProgressNotifiersImpl ; import com . izforge . izpack . util . Platforms ; public class BSFInstallerListenerTest { @ Rule public TemporaryFolder temporaryFolder = new TemporaryFolder ( ) ; private VariableSubstitutor replacer ; private InstallData installData ; private File installDir ; @ Before public void setUp ( ) throws IOException { Properties properties = new Properties ( ) ; Variables variables = new DefaultVariables ( properties ) ; replacer = new VariableSubstitutorImpl ( variables ) ; installData = new AutomatedInstallData ( variables , Platforms . MANDRIVA_LINUX ) ; installDir = temporaryFolder . getRoot ( ) ; installData . setInstallPath ( installDir . getPath ( ) ) ; } @ Test public void testGroovyActions ( ) throws IOException { Resources resources = Mockito . mock ( Resources . class ) ; InputStream specStream = getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ; assertNotNull ( specStream ) ; Mockito . when ( resources . getInputStream ( BSFInstallerListener . SPEC_FILE_NAME ) ) . thenReturn ( specStream ) ; checkListener ( resources , "<STR_LIT>" ) ; } @ Test public void testBeanshellActions ( ) throws IOException { Resources resources = Mockito . mock ( Resources . class ) ; InputStream specStream = getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ; assertNotNull ( specStream ) ; Mockito . when ( resources . getInputStream ( BSFInstallerListener . SPEC_FILE_NAME ) ) . thenReturn ( specStream ) ; checkListener ( resources , "<STR_LIT>" ) ; } private void checkListener ( Resources resources , String suffix ) throws IOException { Pack pack = new Pack ( "<STR_LIT>" , null , null , null , null , true , true , false , null , true , <NUM_LIT:0> ) ; List < Pack > packs = Arrays . asList ( pack ) ; ProgressListener progressListener = Mockito . mock ( ProgressListener . class ) ; UninstallData uninstallData = new UninstallData ( ) ; ProgressNotifiers notifiers = new ProgressNotifiersImpl ( ) ; BSFInstallerListener listener = new BSFInstallerListener ( installData , replacer , resources , uninstallData , notifiers ) ; listener . initialise ( ) ; assertFileNotExists ( installDir , "<STR_LIT>" + suffix ) ; listener . beforePacks ( packs ) ; assertFileExists ( installDir , "<STR_LIT>" + suffix ) ; assertFileNotExists ( installDir , "<STR_LIT>" + suffix ) ; listener . beforePack ( pack , <NUM_LIT:0> ) ; assertFileExists ( installDir , "<STR_LIT>" + suffix ) ; File dir = new File ( installDir , "<STR_LIT>" ) ; assertTrue ( dir . mkdir ( ) ) ; assertFileNotExists ( installDir , "<STR_LIT>" + suffix ) ; PackFile dirPackFile = new PackFile ( installDir , dir , dir . getName ( ) , null , OverrideType . OVERRIDE_TRUE , null , Blockable . BLOCKABLE_NONE ) ; listener . beforeDir ( dir , dirPackFile , pack ) ; assertFileExists ( installDir , "<STR_LIT>" + suffix ) ; assertFileNotExists ( installDir , "<STR_LIT>" + suffix ) ; listener . afterDir ( dir , dirPackFile , pack ) ; assertFileExists ( installDir , "<STR_LIT>" + suffix ) ; File file = new File ( installDir , "<STR_LIT>" ) ; FileUtils . touch ( file ) ; assertFileNotExists ( installDir , "<STR_LIT>" + suffix ) ; PackFile packFile = new PackFile ( installDir , file , file . getName ( ) , null , OverrideType . OVERRIDE_TRUE , null , Blockable . BLOCKABLE_NONE ) ; listener . beforeFile ( file , packFile , pack ) ; assertFileExists ( installDir , "<STR_LIT>" + suffix ) ; assertFileNotExists ( installDir , "<STR_LIT>" + suffix ) ; listener . afterFile ( file , packFile , pack ) ; assertFileExists ( installDir , "<STR_LIT>" + suffix ) ; assertFileNotExists ( installDir , "<STR_LIT>" + suffix ) ; listener . afterPack ( pack , <NUM_LIT:0> ) ; assertFileExists ( installDir , "<STR_LIT>" + suffix ) ; assertFileNotExists ( installDir , "<STR_LIT>" + suffix ) ; listener . afterPacks ( packs , progressListener ) ; assertFileExists ( installDir , "<STR_LIT>" + suffix ) ; } } </s>
<s> package com . izforge . izpack . event ; import static com . izforge . izpack . test . util . TestHelper . assertFileExists ; import static com . izforge . izpack . test . util . TestHelper . assertFileNotExists ; import static org . junit . Assert . assertNotNull ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . util . Arrays ; import java . util . List ; import java . util . Properties ; import org . junit . Before ; import org . junit . Rule ; import org . junit . Test ; import org . junit . rules . TemporaryFolder ; import org . mockito . Mockito ; import com . izforge . izpack . api . data . AutomatedInstallData ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . event . ProgressNotifiers ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . data . DefaultVariables ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . installer . event . ProgressNotifiersImpl ; import com . izforge . izpack . util . IoHelper ; import com . izforge . izpack . util . Platforms ; public class AntActionInstallerListenerTest { @ Rule public TemporaryFolder temporaryFolder = new TemporaryFolder ( ) ; private VariableSubstitutor replacer ; private InstallData installData ; private File installDir ; private Resources resources ; @ Before public void setUp ( ) throws IOException { Properties properties = new Properties ( ) ; Variables variables = new DefaultVariables ( properties ) ; replacer = new VariableSubstitutorImpl ( variables ) ; installData = new AutomatedInstallData ( variables , Platforms . OS_2 ) ; installDir = temporaryFolder . getRoot ( ) ; installData . setInstallPath ( installDir . getPath ( ) ) ; IoHelper . copyStream ( getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) , new FileOutputStream ( new File ( installDir , "<STR_LIT>" ) ) ) ; resources = Mockito . mock ( Resources . class ) ; InputStream specStream = getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ; assertNotNull ( specStream ) ; Mockito . when ( resources . getInputStream ( AntActionInstallerListener . SPEC_FILE_NAME ) ) . thenReturn ( specStream ) ; } @ Test public void testAntTargets ( ) { Pack pack = new Pack ( "<STR_LIT>" , null , null , null , null , true , true , false , null , true , <NUM_LIT:0> ) ; List < Pack > packs = Arrays . asList ( pack ) ; ProgressListener progressListener = Mockito . mock ( ProgressListener . class ) ; UninstallData uninstallData = new UninstallData ( ) ; ProgressNotifiers notifiers = new ProgressNotifiersImpl ( ) ; AntActionInstallerListener listener = new AntActionInstallerListener ( replacer , resources , installData , uninstallData , notifiers ) ; listener . initialise ( ) ; assertFileNotExists ( installDir , "<STR_LIT>" ) ; listener . beforePacks ( packs ) ; assertFileExists ( installDir , "<STR_LIT>" ) ; assertFileNotExists ( installDir , "<STR_LIT>" ) ; listener . beforePack ( pack , <NUM_LIT:0> ) ; assertFileExists ( installDir , "<STR_LIT>" ) ; assertFileNotExists ( installDir , "<STR_LIT>" ) ; listener . afterPack ( pack , <NUM_LIT:0> ) ; assertFileExists ( installDir , "<STR_LIT>" ) ; assertFileNotExists ( installDir , "<STR_LIT>" ) ; listener . afterPacks ( packs , progressListener ) ; assertFileExists ( installDir , "<STR_LIT>" ) ; } } </s>
<s> package com . izforge . izpack . event ; import static com . izforge . izpack . test . util . TestHelper . assertFileExists ; import static com . izforge . izpack . test . util . TestHelper . assertFileNotExists ; import static org . junit . Assert . assertNotNull ; import java . io . ByteArrayInputStream ; import java . io . ByteArrayOutputStream ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . io . ObjectOutputStream ; import java . util . Arrays ; import java . util . List ; import java . util . Properties ; import org . apache . commons . io . FileUtils ; import org . junit . Before ; import org . junit . Rule ; import org . junit . Test ; import org . junit . rules . TemporaryFolder ; import org . mockito . Mockito ; import com . izforge . izpack . api . data . AutomatedInstallData ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . event . UninstallerListener ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . data . DefaultVariables ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . installer . event . ProgressNotifiersImpl ; import com . izforge . izpack . util . Platforms ; public class BSFUninstallerListenerTest { @ Rule public TemporaryFolder temporaryFolder = new TemporaryFolder ( ) ; private File installDir ; @ Before public void setUp ( ) { installDir = temporaryFolder . getRoot ( ) ; } @ Test public void testGroovy ( ) throws IOException { List < BSFAction > actions = getActions ( "<STR_LIT>" , "<STR_LIT>" ) ; checkListener ( actions , "<STR_LIT>" ) ; } @ Test public void testBeanshell ( ) throws IOException { List < BSFAction > actions = getActions ( "<STR_LIT>" , "<STR_LIT>" ) ; checkListener ( actions , "<STR_LIT>" ) ; } public void checkListener ( List < BSFAction > actions , String suffix ) throws IOException { UninstallerListener listener = createListener ( actions ) ; listener . initialise ( ) ; File file1 = new File ( installDir , "<STR_LIT>" ) ; File file2 = new File ( installDir , "<STR_LIT>" ) ; List < File > files = Arrays . asList ( file1 , file2 ) ; for ( File file : files ) { FileUtils . touch ( file ) ; } System . setProperty ( "<STR_LIT>" , installDir . getPath ( ) ) ; assertFileNotExists ( installDir , "<STR_LIT>" + suffix ) ; listener . beforeDelete ( files ) ; assertFileExists ( installDir , "<STR_LIT>" + suffix ) ; assertFileNotExists ( installDir , "<STR_LIT>" + suffix ) ; listener . beforeDelete ( file1 ) ; assertFileExists ( installDir , "<STR_LIT>" + suffix ) ; assertFileNotExists ( installDir , "<STR_LIT>" + suffix ) ; listener . afterDelete ( file1 ) ; assertFileExists ( installDir , "<STR_LIT>" + suffix ) ; assertFileNotExists ( installDir , "<STR_LIT>" + suffix ) ; listener . afterDelete ( files , Mockito . mock ( ProgressListener . class ) ) ; assertFileExists ( installDir , "<STR_LIT>" + suffix ) ; } private BSFUninstallerListener createListener ( List < BSFAction > actions ) throws IOException { assertNotNull ( actions ) ; ByteArrayOutputStream byteOutput = new ByteArrayOutputStream ( ) ; ObjectOutputStream objectOutput = new ObjectOutputStream ( byteOutput ) ; objectOutput . writeObject ( actions ) ; objectOutput . close ( ) ; Resources resources = Mockito . mock ( Resources . class ) ; ByteArrayInputStream byteInput = new ByteArrayInputStream ( byteOutput . toByteArray ( ) ) ; Mockito . when ( resources . getInputStream ( "<STR_LIT>" ) ) . thenReturn ( byteInput ) ; return new BSFUninstallerListener ( resources ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private List < BSFAction > getActions ( String resource , String packName ) { Properties properties = new Properties ( ) ; Variables variables = new DefaultVariables ( properties ) ; VariableSubstitutor replacer = new VariableSubstitutorImpl ( variables ) ; InstallData installData = new AutomatedInstallData ( variables , Platforms . SUNOS ) ; installData . setInstallPath ( installDir . getPath ( ) ) ; Resources resources = Mockito . mock ( Resources . class ) ; InputStream specStream = getClass ( ) . getResourceAsStream ( resource ) ; assertNotNull ( specStream ) ; Mockito . when ( resources . getInputStream ( BSFInstallerListener . SPEC_FILE_NAME ) ) . thenReturn ( specStream ) ; UninstallData uninstallData = new UninstallData ( ) ; BSFInstallerListener listener = new BSFInstallerListener ( installData , replacer , resources , uninstallData , new ProgressNotifiersImpl ( ) ) ; listener . initialise ( ) ; Pack pack = new Pack ( packName , null , null , null , null , true , true , false , null , true , <NUM_LIT:0> ) ; List < Pack > packs = Arrays . asList ( pack ) ; listener . beforePacks ( packs ) ; listener . afterPacks ( packs , Mockito . mock ( ProgressListener . class ) ) ; return ( List < BSFAction > ) uninstallData . getAdditionalData ( ) . get ( "<STR_LIT>" ) ; } } </s>
<s> package g5 . ambience . model ; import g5 . ambience . util . Auth ; import java . io . Serializable ; import javax . persistence . * ; import java . security . MessageDigest ; import java . security . NoSuchAlgorithmException ; import java . util . Date ; import java . util . Set ; @ Entity @ Table ( name = "<STR_LIT>" ) public class UserEntity implements Serializable { private static final long serialVersionUID = <NUM_LIT:1L> ; @ Id @ Column ( unique = true , nullable = false , length = <NUM_LIT> ) private String username ; @ Temporal ( TemporalType . DATE ) @ Column ( name = "<STR_LIT>" ) private Date ccExpiration ; @ Column ( name = "<STR_LIT>" , length = <NUM_LIT> ) private String ccName ; @ Column ( name = "<STR_LIT>" ) private int ccNumber ; @ Column ( name = "<STR_LIT>" ) private int ccSecurity ; @ Column ( length = <NUM_LIT> ) private String city ; @ Temporal ( TemporalType . DATE ) private Date dob ; @ Column ( nullable = false , length = <NUM_LIT> ) private String email ; @ Column ( name = "<STR_LIT>" , length = <NUM_LIT> ) private String firstName ; @ Column ( name = "<STR_LIT>" , length = <NUM_LIT> ) private String lastName ; @ Column ( name = "<STR_LIT>" , length = <NUM_LIT> ) private String membershipPlan ; @ Column ( name = "<STR_LIT>" , nullable = false , length = <NUM_LIT:32> ) private String passwordHash ; @ Column ( name = "<STR_LIT>" , length = <NUM_LIT:100> ) private String profileImage ; @ Column ( length = <NUM_LIT> ) private String role ; @ Column ( length = <NUM_LIT> ) private String state ; @ Column ( length = <NUM_LIT> ) private String street ; @ Column ( name = "<STR_LIT>" , length = <NUM_LIT> ) private String streetOpt ; private int zipcode ; @ OneToMany ( mappedBy = "<STR_LIT>" , cascade = CascadeType . PERSIST ) private Set < BundleEntity > bundleEntities ; public UserEntity ( ) { } public UserEntity ( String username , String password , String email , String firstName , String lastName , String role ) { this . username = username ; this . passwordHash = password ; this . email = email ; this . firstName = firstName ; this . lastName = lastName ; this . role = role ; } public String getUsername ( ) { return this . username ; } public void setUsername ( String username ) { this . username = username ; } public Date getCcExpiration ( ) { return this . ccExpiration ; } public void setCcExpiration ( Date ccExpiration ) { this . ccExpiration = ccExpiration ; } public String getCcName ( ) { return this . ccName ; } public void setCcName ( String ccName ) { this . ccName = ccName ; } public int getCcNumber ( ) { return this . ccNumber ; } public void setCcNumber ( int ccNumber ) { this . ccNumber = ccNumber ; } public int getCcSecurity ( ) { return this . ccSecurity ; } public void setCcSecurity ( int ccSecurity ) { this . ccSecurity = ccSecurity ; } public String getCity ( ) { return this . city ; } public void setCity ( String city ) { this . city = city ; } public Date getDob ( ) { return this . dob ; } public void setDob ( Date dob ) { this . dob = dob ; } public String getEmail ( ) { return this . email ; } public void setEmail ( String email ) { this . email = email ; } public String getFirstName ( ) { return this . firstName ; } public void setFirstName ( String firstName ) { this . firstName = firstName ; } public String getLastName ( ) { return this . lastName ; } public void setLastName ( String lastName ) { this . lastName = lastName ; } public String getMembershipPlan ( ) { return this . membershipPlan ; } public void setMembershipPlan ( String membershipPlan ) { this . membershipPlan = membershipPlan ; } public String getPasswordHash ( ) { return this . passwordHash ; } public void setPasswordHash ( String password ) { this . passwordHash = password ; } public String getProfileImage ( ) { return this . profileImage ; } public void setProfileImage ( String profileImage ) { this . profileImage = profileImage ; } public String getRole ( ) { return this . role ; } public void setRole ( String role ) { this . role = role ; } public String getState ( ) { return this . state ; } public void setState ( String state ) { this . state = state ; } public String getStreet ( ) { return this . street ; } public void setStreet ( String street ) { this . street = street ; } public String getStreetOpt ( ) { return this . streetOpt ; } public void setStreetOpt ( String streetOpt ) { this . streetOpt = streetOpt ; } public int getZipcode ( ) { return this . zipcode ; } public void setZipcode ( int zipcode ) { this . zipcode = zipcode ; } public Set < BundleEntity > getBundleEntities ( ) { return this . bundleEntities ; } public void setBundleEntities ( Set < BundleEntity > bundleEntities ) { this . bundleEntities = bundleEntities ; } } </s>
<s> package g5 . ambience . model ; import java . io . Serializable ; import javax . persistence . * ; @ Embeddable public class BundleEntityPK implements Serializable { private static final long serialVersionUID = <NUM_LIT:1L> ; @ Column ( name = "<STR_LIT>" , unique = true , nullable = false ) private int itemId ; @ Temporal ( TemporalType . DATE ) @ Column ( name = "<STR_LIT>" , unique = true , nullable = false ) private java . util . Date checkedOutDate ; @ Column ( unique = true , nullable = false , length = <NUM_LIT> ) private String username ; public BundleEntityPK ( ) { } public int getItemId ( ) { return this . itemId ; } public void setItemId ( int itemId ) { this . itemId = itemId ; } public java . util . Date getCheckedOutDate ( ) { return this . checkedOutDate ; } public void setCheckedOutDate ( java . util . Date checkedOutDate ) { this . checkedOutDate = checkedOutDate ; } public String getUsername ( ) { return this . username ; } public void setUsername ( String username ) { this . username = username ; } public boolean equals ( Object other ) { if ( this == other ) { return true ; } if ( ! ( other instanceof BundleEntityPK ) ) { return false ; } BundleEntityPK castOther = ( BundleEntityPK ) other ; return ( this . itemId == castOther . itemId ) && this . checkedOutDate . equals ( castOther . checkedOutDate ) && this . username . equals ( castOther . username ) ; } public int hashCode ( ) { final int prime = <NUM_LIT:31> ; int hash = <NUM_LIT> ; hash = hash * prime + this . itemId ; hash = hash * prime + this . checkedOutDate . hashCode ( ) ; hash = hash * prime + this . username . hashCode ( ) ; return hash ; } } </s>
<s> package g5 . ambience . model ; import java . io . Serializable ; import javax . persistence . * ; import java . util . Date ; import java . util . Set ; @ Entity @ Table ( name = "<STR_LIT>" ) public class ItemEntity implements Serializable { private static final long serialVersionUID = <NUM_LIT:1L> ; @ Id @ GeneratedValue ( strategy = GenerationType . AUTO ) @ Column ( name = "<STR_LIT>" , unique = true , nullable = false ) private int itemId ; @ Column ( length = <NUM_LIT> ) private String developer ; @ Column ( length = <NUM_LIT> ) private String director ; @ Column ( name = "<STR_LIT>" , length = <NUM_LIT:10> ) private String esrbRating ; @ Column ( nullable = false , length = <NUM_LIT> ) private String genre ; @ Column ( name = "<STR_LIT>" , nullable = false , length = <NUM_LIT> ) private String imageUrl ; @ Column ( name = "<STR_LIT>" , nullable = false ) private boolean isOut ; @ Column ( name = "<STR_LIT>" , length = <NUM_LIT:5> ) private String mpaaRating ; @ Column ( length = <NUM_LIT> ) private String platform ; @ Column ( name = "<STR_LIT>" , nullable = false ) private int referenceNumber ; @ Column ( name = "<STR_LIT>" , nullable = false ) private int releaseYear ; @ Column ( nullable = false , length = <NUM_LIT> ) private String synopsis ; @ Column ( nullable = false , length = <NUM_LIT> ) private String title ; @ Column ( name = "<STR_LIT>" , length = <NUM_LIT> ) private String trailerUrl ; @ Column ( nullable = false , length = <NUM_LIT> ) private String type ; @ Column ( name = "<STR_LIT>" ) private int userRating ; @ OneToMany ( mappedBy = "<STR_LIT>" ) private Set < BundleEntity > bundleEntities ; public ItemEntity ( ) { } public ItemEntity ( int itemId , String title , int releaseYear , String type , String platform , String genre , boolean isOut , int userRating , String esrbRating , int referenceNumber , String director , String trailerUrl , String synopsis , String imageUrl , String developer , String mpaaRating ) { this . itemId = itemId ; this . title = title ; this . releaseYear = releaseYear ; this . type = type ; this . platform = platform ; this . genre = genre ; this . isOut = isOut ; this . userRating = userRating ; this . esrbRating = esrbRating ; this . referenceNumber = referenceNumber ; this . director = director ; this . trailerUrl = trailerUrl ; this . synopsis = synopsis ; this . imageUrl = imageUrl ; this . developer = developer ; this . mpaaRating = mpaaRating ; } public int getItemId ( ) { return this . itemId ; } public void setItemId ( int itemId ) { this . itemId = itemId ; } public String getDeveloper ( ) { return this . developer ; } public void setDeveloper ( String developer ) { this . developer = developer ; } public String getDirector ( ) { return this . director ; } public void setDirector ( String director ) { this . director = director ; } public String getEsrbRating ( ) { return this . esrbRating ; } public void setEsrbRating ( String esrbRating ) { this . esrbRating = esrbRating ; } public String getGenre ( ) { return this . genre ; } public void setGenre ( String genre ) { this . genre = genre ; } public String getImageUrl ( ) { return this . imageUrl ; } public void setImageUrl ( String imageUrl ) { this . imageUrl = imageUrl ; } public boolean getIsOut ( ) { return this . isOut ; } public void setIsOut ( boolean isOut ) { this . isOut = isOut ; } public String getMpaaRating ( ) { return this . mpaaRating ; } public void setMpaaRating ( String mpaaRating ) { this . mpaaRating = mpaaRating ; } public String getPlatform ( ) { return this . platform ; } public void setPlatform ( String platform ) { this . platform = platform ; } public int getReferenceNumber ( ) { return this . referenceNumber ; } public void setReferenceNumber ( int referenceNumber ) { this . referenceNumber = referenceNumber ; } public int getReleaseYear ( ) { return this . releaseYear ; } public void setReleaseYear ( int releaseYear ) { this . releaseYear = releaseYear ; } public String getSynopsis ( ) { return this . synopsis ; } public void setSynopsis ( String synopsis ) { this . synopsis = synopsis ; } public String getTitle ( ) { return this . title ; } public void setTitle ( String title ) { this . title = title ; } public String getTrailerUrl ( ) { return this . trailerUrl ; } public void setTrailerUrl ( String trailerUrl ) { this . trailerUrl = trailerUrl ; } public String getType ( ) { return this . type ; } public void setType ( String type ) { this . type = type ; } public int getUserRating ( ) { return this . userRating ; } public void setUserRating ( int userRating ) { this . userRating = userRating ; } public Set < BundleEntity > getBundleEntities ( ) { return this . bundleEntities ; } public void setBundleEntities ( Set < BundleEntity > bundleEntities ) { this . bundleEntities = bundleEntities ; } } </s>
<s> package g5 . ambience . model ; import java . io . Serializable ; import javax . persistence . * ; import java . util . Date ; @ Entity @ Table ( name = "<STR_LIT>" ) public class BundleEntity implements Serializable { private static final long serialVersionUID = <NUM_LIT:1L> ; @ EmbeddedId private BundleEntityPK id ; @ Temporal ( TemporalType . TIMESTAMP ) @ Column ( name = "<STR_LIT>" ) private Date returnedDate ; @ Column ( name = "<STR_LIT>" ) private int userRating ; @ ManyToOne @ JoinColumn ( name = "<STR_LIT>" , nullable = false , insertable = false , updatable = false ) private ItemEntity itemEntity ; @ ManyToOne @ JoinColumn ( name = "<STR_LIT:username>" , nullable = false , insertable = false , updatable = false ) private UserEntity userEntity ; public BundleEntity ( ) { } public BundleEntityPK getId ( ) { return this . id ; } public void setId ( BundleEntityPK id ) { this . id = id ; } public Date getReturnedDate ( ) { return this . returnedDate ; } public void setReturnedDate ( Date returnedDate ) { this . returnedDate = returnedDate ; } public int getUserRating ( ) { return this . userRating ; } public void setUserRating ( int userRating ) { this . userRating = userRating ; } public ItemEntity getItemEntity ( ) { return this . itemEntity ; } public void setItemEntity ( ItemEntity itemEntity ) { this . itemEntity = itemEntity ; } public UserEntity getUserEntity ( ) { return this . userEntity ; } public void setUserEntity ( UserEntity userEntity ) { this . userEntity = userEntity ; } } </s>
<s> package g5 . ambience . controller ; import g5 . ambience . model . BundleEntity ; import g5 . ambience . model . ItemEntity ; import g5 . ambience . model . UserEntity ; import g5 . ambience . util . Auth ; import java . util . List ; import java . util . Set ; import javax . persistence . EntityManager ; import javax . persistence . Persistence ; import javax . persistence . PersistenceContext ; import javax . persistence . TypedQuery ; import org . primefaces . context . RequestContext ; public class ItemController { private int itemId ; private String developer ; private String director ; private String esrbRating ; private String genre ; private String imageUrl ; private boolean isOut ; private String mpaaRating ; private String platform ; private int referenceNumber ; private int releaseYear ; private String synopsis ; private String title ; private String trailerUrl ; private String type ; private int userRating ; private Set < BundleEntity > bundleEntities ; private List < ItemEntity > allItems ; private List < ItemEntity > movies ; private List < ItemEntity > games ; private List < ItemEntity > topTen ; private List < ItemEntity > latestItems ; private ItemEntity selectedItem ; private UserEntity currentUser ; @ PersistenceContext ( unitName = "<STR_LIT>" ) EntityManager em ; public ItemController ( ) { if ( em == null ) { em = ( EntityManager ) Persistence . createEntityManagerFactory ( "<STR_LIT>" ) . createEntityManager ( ) ; } } private void createMovie ( int itemId , String title , int releaseYear , String type , String platform , String genre , boolean isOut , int userRating , int referenceNumber , String director , String trailerUrl , String synopsis , String imageUrl , String mpaaRating ) { try { String esrbRating = "<STR_LIT>" ; String developer = "<STR_LIT>" ; ItemEntity item = new ItemEntity ( itemId , title , releaseYear , type , platform , genre , isOut , userRating , esrbRating , referenceNumber , director , trailerUrl , synopsis , imageUrl , developer , mpaaRating ) ; em . getTransaction ( ) . begin ( ) ; em . persist ( item ) ; em . getTransaction ( ) . commit ( ) ; } catch ( Exception e ) { System . err . println ( e . getMessage ( ) ) ; } finally { } } private void createGame ( int itemId , String title , int releaseYear , String type , String platform , String genre , boolean isOut , int userRating , String esrbRating , int referenceNumber , String trailerUrl , String synopsis , String imageUrl , String developer ) { try { String mpaaRating = "<STR_LIT>" ; String director = "<STR_LIT>" ; ItemEntity item = new ItemEntity ( itemId , title , releaseYear , type , platform , genre , isOut , userRating , esrbRating , referenceNumber , director , trailerUrl , synopsis , imageUrl , developer , mpaaRating ) ; em . getTransaction ( ) . begin ( ) ; em . persist ( item ) ; em . getTransaction ( ) . commit ( ) ; } catch ( Exception e ) { System . err . println ( e . getMessage ( ) ) ; } finally { } } public void deleteItem ( int itemId ) { try { ItemEntity item = em . find ( ItemEntity . class , itemId ) ; em . getTransaction ( ) . begin ( ) ; em . remove ( item ) ; em . getTransaction ( ) . commit ( ) ; } catch ( Exception e ) { System . err . println ( e . getMessage ( ) ) ; } finally { } } public void updateItem ( int itemId , String title , int releaseYear , String type , String platform , String genre , boolean isOut , int userRating , String esrbRating , int referenceNumber , String director , String trailerUrl , String synopsis , String imageUrl , String developer , String mpaaRating ) { try { ItemEntity item = em . find ( ItemEntity . class , itemId ) ; em . getTransaction ( ) . begin ( ) ; em . merge ( item ) ; em . getTransaction ( ) . commit ( ) ; } catch ( Exception e ) { System . err . println ( e . getMessage ( ) ) ; } finally { } } public List < ItemEntity > searchItem ( int itemId ) { try { TypedQuery < ItemEntity > query = em . createQuery ( "<STR_LIT>" , ItemEntity . class ) ; query . setParameter ( "<STR_LIT>" , itemId ) ; return ( List < ItemEntity > ) query . getResultList ( ) ; } catch ( Exception e ) { System . err . println ( e . getMessage ( ) ) ; } finally { } return null ; } public List < ItemEntity > searchItem ( String title ) { try { TypedQuery < ItemEntity > query = em . createQuery ( "<STR_LIT>" , ItemEntity . class ) ; query . setParameter ( "<STR_LIT:title>" , title ) ; return ( List < ItemEntity > ) query . getResultList ( ) ; } catch ( Exception e ) { System . err . println ( e . getMessage ( ) ) ; } finally { } return null ; } public List < ItemEntity > findAllItems ( ) { TypedQuery < ItemEntity > query = em . createQuery ( "<STR_LIT>" , ItemEntity . class ) ; return ( List < ItemEntity > ) query . getResultList ( ) ; } public List < ItemEntity > findItemsWithRatingGreaterThan ( int value ) { TypedQuery < ItemEntity > query = em . createQuery ( "<STR_LIT>" , ItemEntity . class ) ; query . setParameter ( "<STR_LIT:value>" , value ) ; return ( List < ItemEntity > ) query . getResultList ( ) ; } public List < ItemEntity > findAllItems ( String type ) { TypedQuery < ItemEntity > query = em . createQuery ( "<STR_LIT>" , ItemEntity . class ) ; query . setParameter ( "<STR_LIT:type>" , type ) ; return ( List < ItemEntity > ) query . getResultList ( ) ; } public List < ItemEntity > findUniqueItemsByType ( String type , int numItems ) { TypedQuery < ItemEntity > query = em . createQuery ( "<STR_LIT>" , ItemEntity . class ) ; if ( numItems > <NUM_LIT:0> ) { query . setParameter ( "<STR_LIT:type>" , type ) . setMaxResults ( numItems ) ; } else { query . setParameter ( "<STR_LIT:type>" , type ) ; } return ( List < ItemEntity > ) query . getResultList ( ) ; } public String item ( ) { return "<STR_LIT>" ; } public int getItemId ( ) { return itemId ; } public void setItemId ( int itemId ) { this . itemId = itemId ; } public String getDeveloper ( ) { return developer ; } public void setDeveloper ( String developer ) { this . developer = developer ; } public String getDirector ( ) { return director ; } public void setDirector ( String director ) { this . director = director ; } public String getEsrbRating ( ) { return esrbRating ; } public void setEsrbRating ( String esrbRating ) { this . esrbRating = esrbRating ; } public String getGenre ( ) { return genre ; } public void setGenre ( String genre ) { this . genre = genre ; } public String getImageUrl ( ) { return imageUrl ; } public void setImageUrl ( String imageUrl ) { this . imageUrl = imageUrl ; } public boolean getIsOut ( ) { return isOut ; } public void setIsOut ( boolean isOut ) { this . isOut = isOut ; } public String getMpaaRating ( ) { return mpaaRating ; } public void setMpaaRating ( String mpaaRating ) { this . mpaaRating = mpaaRating ; } public String getPlatform ( ) { return platform ; } public void setPlatform ( String platform ) { this . platform = platform ; } public int getReferenceNumber ( ) { return referenceNumber ; } public void setReferenceNumber ( int referenceNumber ) { this . referenceNumber = referenceNumber ; } public int getReleaseYear ( ) { return releaseYear ; } public void setReleaseYear ( int releaseYear ) { this . releaseYear = releaseYear ; } public String getSynopsis ( ) { return synopsis ; } public void setSynopsis ( String synopsis ) { this . synopsis = synopsis ; } public String getTitle ( ) { return title ; } public void setTitle ( String title ) { this . title = title ; } public String getTrailerUrl ( ) { return trailerUrl ; } public void setTrailerUrl ( String trailerUrl ) { this . trailerUrl = trailerUrl ; } public String getType ( ) { return type ; } public void setType ( String type ) { this . type = type ; } public int getUserRating ( ) { return userRating ; } public void setUserRating ( int userRating ) { this . userRating = userRating ; } public Set < BundleEntity > getBundleEntities ( ) { return bundleEntities ; } public void setBundleEntities ( Set < BundleEntity > bundleEntities ) { this . bundleEntities = bundleEntities ; } public List < ItemEntity > getAllItems ( ) { return allItems = findAllItems ( ) ; } public void setAllItems ( List < ItemEntity > allItems ) { this . allItems = allItems ; } public ItemEntity getSelectedItem ( ) { return selectedItem ; } public void setSelectedItem ( ItemEntity selectedItem ) { this . selectedItem = selectedItem ; } public UserEntity getCurrentUser ( ) { return currentUser ; } public void setCurrentUser ( UserEntity currentUser ) { this . currentUser = currentUser ; } public List < ItemEntity > getMovies ( ) { return movies = findUniqueItemsByType ( "<STR_LIT>" , <NUM_LIT:0> ) ; } public void setMovies ( List < ItemEntity > movies ) { this . movies = movies ; } public List < ItemEntity > getGames ( ) { return games = findUniqueItemsByType ( "<STR_LIT>" , <NUM_LIT:0> ) ; } public void setGames ( List < ItemEntity > games ) { this . games = games ; } public List < ItemEntity > getTopTen ( ) { return topTen = findItemsWithRatingGreaterThan ( <NUM_LIT:3> ) ; } public void setTopTen ( List < ItemEntity > topTen ) { this . topTen = topTen ; } public List < ItemEntity > getLatestItems ( ) { return latestItems ; } public void setLatestItems ( List < ItemEntity > latestItems ) { this . latestItems = latestItems ; } } </s>
<s> package g5 . ambience . controller ; import java . util . Date ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Set ; import javax . annotation . PostConstruct ; import javax . faces . application . FacesMessage ; import javax . faces . bean . ManagedProperty ; import javax . faces . component . UIComponent ; import javax . faces . context . FacesContext ; import javax . faces . context . Flash ; import javax . persistence . EntityManager ; import javax . persistence . Persistence ; import javax . persistence . PersistenceContext ; import javax . persistence . TypedQuery ; import g5 . ambience . model . BundleEntity ; import g5 . ambience . model . BundleEntityPK ; import g5 . ambience . model . ItemEntity ; import g5 . ambience . model . UserEntity ; import g5 . ambience . util . Auth ; public class UserController { private String password ; private String username ; private String firstName ; private String lastName ; private String email ; private boolean isLoggedIn ; private String dashOrProfile ; private String loginLogout ; private ItemEntity item ; private UserEntity user ; private List < BundleEntity > bundleEntities ; private List < UserEntity > members ; private List < ItemEntity > bundleItems ; @ PersistenceContext ( unitName = "<STR_LIT>" ) EntityManager em ; FacesContext fc ; FacesMessage fm ; public UserController ( ) { if ( em == null ) { em = ( EntityManager ) Persistence . createEntityManagerFactory ( "<STR_LIT>" ) . createEntityManager ( ) ; } setUser ( new UserEntity ( ) ) ; } private UserEntity getUserByUsernameAndPassword ( String username , String password ) { try { UserEntity user = em . find ( UserEntity . class , username ) ; String hash = Auth . hash_password ( password ) ; if ( user . getPasswordHash ( ) . equals ( hash ) ) { return user ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { } return null ; } private void createUser ( String username , String password , String email , String firstName , String lastName , String role ) { try { String hash = null ; hash = Auth . hash_password ( password ) ; UserEntity user = new UserEntity ( username , hash , email , firstName , lastName , role ) ; em . getTransaction ( ) . begin ( ) ; em . persist ( user ) ; em . getTransaction ( ) . commit ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { } } private void updateUser ( String username , String password , String email , String firstName , String lastName , String role ) { try { String hash = null ; hash = Auth . hash_password ( password ) ; UserEntity user = new UserEntity ( username , hash , email , firstName , lastName , role ) ; em . getTransaction ( ) . begin ( ) ; em . merge ( user ) ; em . flush ( ) ; em . getTransaction ( ) . commit ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { } } public String registerUser ( ) { createUser ( this . getUsername ( ) , this . getPassword ( ) , this . getEmail ( ) , this . getFirstName ( ) , this . getLastName ( ) , "<STR_LIT>" ) ; return "<STR_LIT>" ; } public String update ( ) { updateUser ( this . getUsername ( ) , this . getPassword ( ) , this . getEmail ( ) , this . getFirstName ( ) , this . getLastName ( ) , "<STR_LIT>" ) ; return "<STR_LIT>" ; } public String login ( ) { try { if ( getUserByUsernameAndPassword ( this . getUsername ( ) , this . getPassword ( ) ) != null ) { user = getUserByUsernameAndPassword ( this . username , this . password ) ; setLoggedIn ( true ) ; if ( getUserByUsernameAndPassword ( this . getUsername ( ) , this . getPassword ( ) ) . getRole ( ) . equals ( "<STR_LIT:admin>" ) ) { setDashOrProfile ( "<STR_LIT>" ) ; return "<STR_LIT>" ; } else if ( getUserByUsernameAndPassword ( this . getUsername ( ) , this . getPassword ( ) ) . getRole ( ) . equals ( "<STR_LIT>" ) ) { setDashOrProfile ( "<STR_LIT>" ) ; return "<STR_LIT>" ; } } else { message ( "<STR_LIT>" , "<STR_LIT>" ) ; } } catch ( NullPointerException e ) { message ( "<STR_LIT>" , "<STR_LIT>" ) ; System . err . println ( e . getMessage ( ) ) ; } return null ; } public String logout ( ) { if ( isLoggedIn ) { FacesContext . getCurrentInstance ( ) . getExternalContext ( ) . invalidateSession ( ) ; } return "<STR_LIT:index>" ; } public void addItemToBundle ( ItemEntity item ) { System . out . println ( item . getTitle ( ) ) ; try { em . getTransaction ( ) . begin ( ) ; UserEntity user = em . find ( UserEntity . class , this . username ) ; BundleEntity bundle = new BundleEntity ( ) ; BundleEntityPK compositePk = new BundleEntityPK ( ) ; compositePk . setCheckedOutDate ( new Date ( ) ) ; compositePk . setItemId ( item . getItemId ( ) ) ; compositePk . setUsername ( user . getUsername ( ) ) ; bundle . setId ( compositePk ) ; Set < BundleEntity > bundles = new HashSet < BundleEntity > ( ) ; bundles . add ( bundle ) ; user . setBundleEntities ( bundles ) ; em . persist ( bundle ) ; em . persist ( user ) ; em . flush ( ) ; em . getTransaction ( ) . commit ( ) ; } finally { } } public String addToBundle ( ) { try { addItemToBundle ( item ) ; } catch ( NullPointerException e ) { System . err . println ( e . getMessage ( ) ) ; } return null ; } public List < ItemEntity > findUsersBundleItems ( String username ) { TypedQuery < ItemEntity > query = em . createQuery ( "<STR_LIT>" , ItemEntity . class ) ; query . setParameter ( "<STR_LIT:username>" , username ) ; return query . getResultList ( ) ; } public ItemEntity getItemFromBundle ( BundleEntity bundle ) { item = bundle . getItemEntity ( ) ; return item ; } public List < UserEntity > findAllMembers ( int limit ) { TypedQuery < UserEntity > query ; if ( limit > <NUM_LIT:0> ) { query = em . createQuery ( "<STR_LIT>" , UserEntity . class ) ; query . setMaxResults ( limit ) ; } else { query = em . createQuery ( "<STR_LIT>" , UserEntity . class ) ; } return query . getResultList ( ) ; } public void message ( String message , String id ) { FacesContext facesContext = FacesContext . getCurrentInstance ( ) ; Flash flash = facesContext . getExternalContext ( ) . getFlash ( ) ; flash . setKeepMessages ( false ) ; FacesMessage facesMessage = new FacesMessage ( message ) ; facesContext . addMessage ( id , facesMessage ) ; } public String profile ( ) { return "<STR_LIT>" ; } public boolean isLoggedIn ( ) { return isLoggedIn ; } public void setLoggedIn ( boolean isLoggedIn ) { this . isLoggedIn = isLoggedIn ; } public ItemEntity getItem ( ) { return item ; } public void setItem ( ItemEntity item ) { this . item = item ; } public String getPassword ( ) { return password ; } public void setPassword ( String password ) { this . password = password ; } public String getUsername ( ) { return username ; } public void setUsername ( String username ) { this . username = username ; } public String getFirstName ( ) { return firstName ; } public void setFirstName ( String firstName ) { this . firstName = firstName ; } public String getLastName ( ) { return lastName ; } public void setLastName ( String lastName ) { this . lastName = lastName ; } public String getEmail ( ) { return email ; } public void setEmail ( String email ) { this . email = email ; } public UserEntity getUser ( ) { return user ; } public void setUser ( UserEntity user ) { this . user = user ; } public String getLoginLogout ( ) { return loginLogout ; } public void setLoginLogout ( String loginLogout ) { this . loginLogout = loginLogout ; } public List < UserEntity > getMembers ( ) { return members = findAllMembers ( <NUM_LIT:0> ) ; } public void setMembers ( List < UserEntity > members ) { this . members = members ; } public String getDashOrProfile ( ) { return dashOrProfile ; } public void setDashOrProfile ( String dashOrProfile ) { this . dashOrProfile = dashOrProfile ; } public List < ItemEntity > getBundleItems ( ) { return bundleItems = findUsersBundleItems ( username ) ; } public void setBundleItems ( List < ItemEntity > bundleItems ) { this . bundleItems = bundleItems ; } } </s>
<s> package g5 . ambience . util ; import java . util . * ; import java . util . Date ; import java . sql . * ; import java . security . MessageDigest ; public class Auth { private boolean allowed ; private static String username ; private static String password ; private static String hash ; private static String query_hash ; public Auth ( ) { allowed = false ; } public static void run_auth ( String pass ) { password = pass ; try { hash = hash_password ( password ) ; System . out . println ( "<STR_LIT>" + hash ) ; } catch ( Exception e ) { System . out . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } try { query_hash = query_hash ( ) ; System . out . println ( "<STR_LIT>" + query_hash ) ; } catch ( ClassNotFoundException e ) { System . out . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } } public static String hash_password ( String password ) throws Exception { MessageDigest md = MessageDigest . getInstance ( "<STR_LIT>" ) ; md . update ( password . getBytes ( ) ) ; byte byte_data [ ] = md . digest ( ) ; StringBuffer sb = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < byte_data . length ; i ++ ) { sb . append ( Integer . toString ( ( byte_data [ i ] & <NUM_LIT> ) + <NUM_LIT> , <NUM_LIT:16> ) . substring ( <NUM_LIT:1> ) ) ; } return sb . toString ( ) ; } @ SuppressWarnings ( "<STR_LIT>" ) private static String query_hash ( ) throws ClassNotFoundException { Connection conn ; CallableStatement cs ; try { Class . forName ( "<STR_LIT>" ) . newInstance ( ) ; } catch ( InstantiationException e ) { e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } try { conn = DriverManager . getConnection ( "<STR_LIT>" , "<STR_LIT:root>" , "<STR_LIT>" ) ; cs = conn . prepareCall ( "<STR_LIT>" ) ; cs . registerOutParameter ( <NUM_LIT:2> , Types . CHAR ) ; cs . setString ( <NUM_LIT:1> , username ) ; cs . execute ( ) ; query_hash = cs . getString ( <NUM_LIT:2> ) ; } catch ( SQLException e ) { System . out . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } return query_hash ; } public boolean is_allowed ( ) { boolean allowed ; if ( hash . equals ( query_hash ) ) { System . out . println ( "<STR_LIT>" ) ; allowed = true ; } else { System . out . println ( "<STR_LIT>" ) ; allowed = false ; } return allowed ; } } </s>
<s> package g5 . ambience . test ; import static org . junit . Assert . * ; import g5 . ambience . model . UserEntity ; import javax . persistence . EntityManager ; import javax . persistence . Persistence ; import org . junit . After ; import org . junit . AfterClass ; import org . junit . Before ; import org . junit . BeforeClass ; import org . junit . Test ; public class UserEntityTest { private static EntityManager em = null ; @ BeforeClass public static void setUpBeforeClass ( ) throws Exception { if ( em == null ) { em = ( EntityManager ) Persistence . createEntityManagerFactory ( "<STR_LIT>" ) . createEntityManager ( ) ; } } @ AfterClass public static void tearDownAfterClass ( ) throws Exception { } @ Before public void setUp ( ) throws Exception { } @ After public void tearDown ( ) throws Exception { } @ Test public void testUserEntity ( ) { em . getTransaction ( ) . begin ( ) ; UserEntity user1 = new UserEntity ( ) ; user1 . setUsername ( "<STR_LIT:user>" ) ; user1 . setPasswordHash ( "<STR_LIT>" ) ; user1 . setEmail ( "<STR_LIT>" ) ; em . persist ( user1 ) ; em . flush ( ) ; em . getTransaction ( ) . commit ( ) ; } @ Test public void testUserEntityStringStringStringStringString ( ) { em . getTransaction ( ) . begin ( ) ; UserEntity user2 = new UserEntity ( "<STR_LIT:admin>" , "<STR_LIT:password>" , "<STR_LIT:email>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; em . persist ( user2 ) ; em . flush ( ) ; em . getTransaction ( ) . commit ( ) ; } @ Test public void testUserAll ( ) { em . getTransaction ( ) . begin ( ) ; UserEntity user1 = em . find ( UserEntity . class , "<STR_LIT:user>" ) ; UserEntity user2 = em . find ( UserEntity . class , "<STR_LIT:admin>" ) ; em . remove ( user1 ) ; em . remove ( user2 ) ; em . getTransaction ( ) . commit ( ) ; } @ Test public void testGetUsername ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetUsername ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetCcExpiration ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetCcExpiration ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetCcName ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetCcName ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetCcNumber ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetCcNumber ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetCcSecurity ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetCcSecurity ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetCity ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetCity ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetDob ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetDob ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetEmail ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetEmail ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetFirstName ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetFirstName ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetLastName ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetLastName ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetMembershipPlan ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetMembershipPlan ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetPasswordHash ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetPasswordHash ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetProfileImage ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetProfileImage ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetRole ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetRole ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetState ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetState ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetStreet ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetStreet ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetStreetOpt ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetStreetOpt ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetZipcode ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetZipcode ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testGetBundleEntities ( ) { fail ( "<STR_LIT>" ) ; } @ Test public void testSetBundleEntities ( ) { fail ( "<STR_LIT>" ) ; } } </s>
<s> package net . sf . json . spring . web . servlet . view ; import java . util . HashMap ; import java . util . Map ; import junit . framework . TestCase ; import net . sf . jstester . JsTester ; import net . sf . json . JSONSerializer ; import org . springframework . mock . web . MockHttpServletRequest ; import org . springframework . mock . web . MockHttpServletResponse ; import org . springframework . mock . web . MockServletContext ; import org . springframework . web . context . support . StaticWebApplicationContext ; public class JsonViewTest extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( JsonViewTest . class ) ; } private JsTester jsTester ; private MockServletContext servletContext ; private MockHttpServletRequest servletRequest ; private MockHttpServletResponse servletResponse ; public JsonViewTest ( String testName ) { super ( testName ) ; } public void testRenderObjectGraph ( ) throws Exception { JsonView view = new JsonView ( ) ; Map model = new HashMap ( ) ; model . put ( "<STR_LIT>" , Boolean . TRUE ) ; model . put ( "<STR_LIT>" , new Integer ( <NUM_LIT:1> ) ) ; model . put ( "<STR_LIT>" , "<STR_LIT:string>" ) ; Map bean = new HashMap ( ) ; bean . put ( "<STR_LIT:name>" , "<STR_LIT>" ) ; bean . put ( "<STR_LIT>" , new boolean [ ] { true , false } ) ; model . put ( "<STR_LIT>" , bean ) ; view . render ( model , servletRequest , servletResponse ) ; jsTester . eval ( toJsScript ( servletResponse ) ) ; jsTester . assertNotNull ( "<STR_LIT>" ) ; jsTester . assertIsObject ( "<STR_LIT>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT:true>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT:1>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT>" ) ; jsTester . assertIsObject ( "<STR_LIT>" ) ; jsTester . assertIsArray ( "<STR_LIT>" ) ; jsTester . assertEquals ( "<STR_LIT:2>" , "<STR_LIT>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testRenderObjectGraphWithPropertyExclusion ( ) throws Exception { JsonView view = new JsonView ( ) ; view . setExcludedProperties ( new String [ ] { "<STR_LIT>" } ) ; Map model = new HashMap ( ) ; model . put ( "<STR_LIT>" , Boolean . TRUE ) ; model . put ( "<STR_LIT>" , new Integer ( <NUM_LIT:1> ) ) ; model . put ( "<STR_LIT>" , "<STR_LIT:string>" ) ; Map bean = new HashMap ( ) ; bean . put ( "<STR_LIT:name>" , "<STR_LIT>" ) ; bean . put ( "<STR_LIT>" , new boolean [ ] { true , false } ) ; model . put ( "<STR_LIT>" , bean ) ; view . render ( model , servletRequest , servletResponse ) ; jsTester . eval ( toJsScript ( servletResponse ) ) ; jsTester . assertNotNull ( "<STR_LIT>" ) ; jsTester . assertIsObject ( "<STR_LIT>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT:true>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT:1>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT>" ) ; jsTester . assertIsObject ( "<STR_LIT>" ) ; jsTester . assertIsUndefined ( "<STR_LIT>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testRenderSimpleProperties ( ) throws Exception { JsonView view = new JsonView ( ) ; Map model = new HashMap ( ) ; model . put ( "<STR_LIT>" , Boolean . TRUE ) ; model . put ( "<STR_LIT>" , new Integer ( <NUM_LIT:1> ) ) ; model . put ( "<STR_LIT>" , "<STR_LIT:string>" ) ; view . render ( model , servletRequest , servletResponse ) ; jsTester . eval ( toJsScript ( servletResponse ) ) ; jsTester . assertNotNull ( "<STR_LIT>" ) ; jsTester . assertIsObject ( "<STR_LIT>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT:true>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT:1>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testForceTopLevelArray ( ) throws Exception { JsonView view = new JsonView ( ) ; view . setForceTopLevelArray ( true ) ; Map model = new HashMap ( ) ; model . put ( "<STR_LIT>" , Boolean . TRUE ) ; model . put ( "<STR_LIT>" , new Integer ( <NUM_LIT:1> ) ) ; model . put ( "<STR_LIT>" , "<STR_LIT:string>" ) ; view . render ( model , servletRequest , servletResponse ) ; jsTester . eval ( toJsScript ( servletResponse ) ) ; jsTester . assertNotNull ( "<STR_LIT>" ) ; jsTester . assertIsArray ( "<STR_LIT>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT:true>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT:1>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void testCharEncoding ( ) throws Exception { JsonView view = new JsonView ( ) ; view . setForceTopLevelArray ( true ) ; Map model = new HashMap ( ) ; model . put ( "<STR_LIT>" , "<STR_LIT>" ) ; view . render ( model , servletRequest , servletResponse ) ; jsTester . eval ( toJsScript ( servletResponse ) ) ; jsTester . assertNotNull ( "<STR_LIT>" ) ; jsTester . assertIsArray ( "<STR_LIT>" ) ; jsTester . assertEquals ( "<STR_LIT>" , "<STR_LIT>" ) ; } protected void setUp ( ) throws Exception { servletContext = new MockServletContext ( ) ; StaticWebApplicationContext wac = new StaticWebApplicationContext ( ) ; wac . setServletContext ( servletContext ) ; servletRequest = new MockHttpServletRequest ( servletContext ) ; servletResponse = new MockHttpServletResponse ( ) ; servletResponse . setBufferSize ( <NUM_LIT:100> ) ; jsTester = new JsTester ( ) ; jsTester . onSetUp ( ) ; } protected void tearDown ( ) throws Exception { jsTester . onTearDown ( ) ; } private String toJsScript ( MockHttpServletResponse response ) throws Exception { String json = response . getContentAsString ( ) ; if ( json . startsWith ( "<STR_LIT>" ) && ! json . endsWith ( "<STR_LIT>" ) ) { json += "<STR_LIT>" ; } if ( json . startsWith ( "<STR_LIT:{>" ) && ! json . endsWith ( "<STR_LIT:}>" ) ) { json += "<STR_LIT:}>" ; } if ( json . startsWith ( "<STR_LIT:[>" ) && ! json . endsWith ( "<STR_LIT:]>" ) ) { json += "<STR_LIT:]>" ; } return "<STR_LIT>" + json + "<STR_LIT>" ; } } </s>
<s> package net . sf . json . spring . web . servlet . view ; import java . util . Map ; import javax . servlet . http . HttpServletRequest ; import javax . servlet . http . HttpServletResponse ; import net . sf . json . JSON ; import net . sf . json . JSONArray ; import net . sf . json . JSONSerializer ; import net . sf . json . JsonConfig ; import net . sf . json . util . PropertyFilter ; import net . sf . json . filters . OrPropertyFilter ; import org . springframework . web . servlet . view . AbstractView ; public class JsonView extends AbstractView { private static final String DEFAULT_JSON_CONTENT_TYPE = "<STR_LIT>" ; private boolean forceTopLevelArray = false ; private boolean skipBindingResult = true ; private JsonConfig jsonConfig = new JsonConfig ( ) ; public JsonView ( ) { super ( ) ; setContentType ( DEFAULT_JSON_CONTENT_TYPE ) ; } public JsonConfig getJsonConfig ( ) { return jsonConfig ; } public boolean isForceTopLevelArray ( ) { return forceTopLevelArray ; } public boolean isIgnoreDefaultExcludes ( ) { return jsonConfig . isIgnoreDefaultExcludes ( ) ; } public boolean isSkipBindingResult ( ) { return skipBindingResult ; } public void setExcludedProperties ( String [ ] excludedProperties ) { jsonConfig . setExcludes ( excludedProperties ) ; } public void setForceTopLevelArray ( boolean forceTopLevelArray ) { this . forceTopLevelArray = forceTopLevelArray ; } public void setIgnoreDefaultExcludes ( boolean ignoreDefaultExcludes ) { jsonConfig . setIgnoreDefaultExcludes ( ignoreDefaultExcludes ) ; } public void setJsonConfig ( JsonConfig jsonConfig ) { this . jsonConfig = jsonConfig != null ? jsonConfig : new JsonConfig ( ) ; if ( skipBindingResult ) { PropertyFilter jsonPropertyFilter = this . jsonConfig . getJsonPropertyFilter ( ) ; if ( jsonPropertyFilter == null ) { this . jsonConfig . setJsonPropertyFilter ( new BindingResultPropertyFilter ( ) ) ; } else { this . jsonConfig . setJsonPropertyFilter ( new OrPropertyFilter ( new BindingResultPropertyFilter ( ) , jsonPropertyFilter ) ) ; } } } public void setSkipBindingResult ( boolean skipBindingResult ) { this . skipBindingResult = skipBindingResult ; } protected JSON createJSON ( Map model , HttpServletRequest request , HttpServletResponse response ) { return defaultCreateJSON ( model ) ; } protected final JSON defaultCreateJSON ( Map model ) { if ( skipBindingResult && jsonConfig . getJsonPropertyFilter ( ) == null ) { this . jsonConfig . setJsonPropertyFilter ( new BindingResultPropertyFilter ( ) ) ; } return JSONSerializer . toJSON ( model , jsonConfig ) ; } protected String [ ] getExcludedProperties ( ) { return jsonConfig . getExcludes ( ) ; } protected void renderMergedOutputModel ( Map model , HttpServletRequest request , HttpServletResponse response ) throws Exception { response . setContentType ( getContentType ( ) ) ; writeJSON ( model , request , response ) ; } protected void writeJSON ( Map model , HttpServletRequest request , HttpServletResponse response ) throws Exception { JSON json = createJSON ( model , request , response ) ; if ( forceTopLevelArray ) { json = new JSONArray ( ) . element ( json ) ; } json . write ( response . getWriter ( ) ) ; } private static class BindingResultPropertyFilter implements PropertyFilter { public boolean apply ( Object source , String name , Object value ) { return name . startsWith ( "<STR_LIT>" ) ; } } } </s>
<s> package net . sf . json ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import net . sf . json . sample . ObjectBean ; public final class PropertyConstants { private static final String ARRAY = "<STR_LIT>" ; private static final String BEAN = "<STR_LIT>" ; private static final String BOOLEAN = "<STR_LIT>" ; private static final String BYTE = "<STR_LIT>" ; private static final String CHAR = "<STR_LIT>" ; private static final String CLASS = "<STR_LIT>" ; private static Map classes = new HashMap ( ) ; private static final String DOUBLE = "<STR_LIT>" ; private static final String FLOAT = "<STR_LIT>" ; private static final String FUNCTION = "<STR_LIT>" ; private static final String INT = "<STR_LIT>" ; private static final String LIST = "<STR_LIT>" ; private static final String LONG = "<STR_LIT>" ; private static final String SHORT = "<STR_LIT>" ; private static final String STRING = "<STR_LIT>" ; private static Map values = new HashMap ( ) ; static { values . put ( BYTE , new Byte ( Byte . MAX_VALUE ) ) ; values . put ( SHORT , new Short ( Short . MAX_VALUE ) ) ; values . put ( INT , new Integer ( Integer . MAX_VALUE ) ) ; values . put ( LONG , new Long ( Long . MAX_VALUE ) ) ; values . put ( FLOAT , new Float ( Float . MAX_VALUE ) ) ; values . put ( DOUBLE , new Double ( Double . MAX_VALUE ) ) ; values . put ( BOOLEAN , Boolean . TRUE ) ; values . put ( CHAR , new Character ( '<CHAR_LIT>' ) ) ; values . put ( STRING , "<STR_LIT>" ) ; values . put ( FUNCTION , new JSONFunction ( "<STR_LIT>" ) ) ; values . put ( ARRAY , new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> } ) ; List list = new ArrayList ( ) ; list . add ( "<STR_LIT:a>" ) ; list . add ( "<STR_LIT:b>" ) ; values . put ( LIST , list ) ; values . put ( CLASS , Object . class ) ; values . put ( BEAN , new ObjectBean ( ) ) ; classes . put ( BYTE , Byte . class ) ; classes . put ( SHORT , Short . class ) ; classes . put ( INT , Integer . class ) ; classes . put ( LONG , Long . class ) ; classes . put ( FLOAT , Float . class ) ; classes . put ( DOUBLE , Double . class ) ; classes . put ( BOOLEAN , Boolean . class ) ; classes . put ( CHAR , Character . class ) ; classes . put ( STRING , String . class ) ; classes . put ( FUNCTION , JSONFunction . class ) ; classes . put ( ARRAY , int [ ] . class ) ; classes . put ( LIST , List . class ) ; classes . put ( CLASS , Class . class ) ; classes . put ( BEAN , ObjectBean . class ) ; } public static String [ ] getProperties ( ) { return new String [ ] { BYTE , SHORT , INT , LONG , FLOAT , DOUBLE , CHAR , BOOLEAN , STRING , FUNCTION , ARRAY , LIST , CLASS , BEAN } ; } public static Class getPropertyClass ( String key ) { return ( Class ) classes . get ( key ) ; } public static Object getPropertyValue ( String key ) { return values . get ( key ) ; } } </s>
<s> package net . sf . json ; import java . io . StringWriter ; import junit . framework . TestCase ; public abstract class AbstractJSONTest extends TestCase { public AbstractJSONTest ( String name ) { super ( name ) ; } public void testIsArray ( ) { boolean isArray = ( ( Boolean ) getIsArrayExpectations ( ) [ <NUM_LIT:0> ] ) . booleanValue ( ) ; JSON json = ( JSON ) getIsArrayExpectations ( ) [ <NUM_LIT:1> ] ; assertEquals ( isArray , json . isArray ( ) ) ; } public void testToString ( ) { String expected = ( String ) getToStringExpectations1 ( ) [ <NUM_LIT:0> ] ; JSON json = ( JSON ) getToStringExpectations1 ( ) [ <NUM_LIT:1> ] ; assertEquals ( expected , json . toString ( ) ) ; } public void testToString_indentFactor ( ) { String expected = ( String ) getToStringExpectations2 ( ) [ <NUM_LIT:0> ] ; JSON json = ( JSON ) getToStringExpectations2 ( ) [ <NUM_LIT:1> ] ; assertEquals ( expected , json . toString ( getIndentFactor ( ) ) ) ; } public void testToString_indentFactor_indent ( ) { String expected = ( String ) getToStringExpectations3 ( ) [ <NUM_LIT:0> ] ; JSON json = ( JSON ) getToStringExpectations3 ( ) [ <NUM_LIT:1> ] ; assertEquals ( expected , json . toString ( getIndentFactor ( ) , getIndent ( ) ) ) ; } public void testWrite ( ) throws Exception { StringWriter w = new StringWriter ( ) ; String expected = ( String ) getWriteExpectations ( ) [ <NUM_LIT:0> ] ; JSON json = ( JSON ) getWriteExpectations ( ) [ <NUM_LIT:1> ] ; json . write ( w ) ; assertEquals ( expected , w . getBuffer ( ) . toString ( ) ) ; } protected abstract int getIndent ( ) ; protected abstract int getIndentFactor ( ) ; protected abstract Object [ ] getIsArrayExpectations ( ) ; protected abstract Object [ ] getToStringExpectations1 ( ) ; protected abstract Object [ ] getToStringExpectations2 ( ) ; protected abstract Object [ ] getToStringExpectations3 ( ) ; protected abstract Object [ ] getWriteExpectations ( ) ; } </s>
<s> package net . sf . json ; import java . util . Calendar ; import java . util . Date ; import java . util . HashMap ; import java . util . Map ; import junit . framework . TestCase ; import net . sf . json . processors . JsDateJsonBeanProcessor ; import net . sf . json . processors . JsDateJsonValueProcessor ; import net . sf . json . sample . DateBean ; import net . sf . json . sample . IdentityJsonValueProcessor ; import net . sf . json . test . JSONAssert ; public class TestJSONObjectWithProcessors extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectWithProcessors . class ) ; } private Date date ; private JsonConfig jsonConfig ; public TestJSONObjectWithProcessors ( String name ) { super ( name ) ; } public void testBeanWithDateProperty_fromObject_withJsonBeanProcessor ( ) { DateBean bean = new DateBean ( ) ; bean . setDate ( date ) ; bean . setValue ( <NUM_LIT> ) ; jsonConfig . registerJsonBeanProcessor ( Date . class , new JsDateJsonBeanProcessor ( ) ) ; JSONObject jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT:value>" ) ) ; JSONObject jsDate = jsonObject . getJSONObject ( "<STR_LIT:date>" ) ; assertJsDate ( jsDate ) ; } public void testBeanWithDateProperty_fromObject_withJsonValueProcessor_1 ( ) { DateBean bean = new DateBean ( ) ; bean . setDate ( date ) ; bean . setValue ( <NUM_LIT> ) ; jsonConfig . registerJsonValueProcessor ( DateBean . class , Date . class , new JsDateJsonValueProcessor ( ) ) ; JSONObject jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT:value>" ) ) ; JSONObject jsDate = jsonObject . getJSONObject ( "<STR_LIT:date>" ) ; assertJsDate ( jsDate ) ; } public void testBeanWithDateProperty_fromObject_withJsonValueProcessor_2 ( ) { DateBean bean = new DateBean ( ) ; bean . setDate ( date ) ; bean . setValue ( <NUM_LIT> ) ; jsonConfig . registerJsonValueProcessor ( DateBean . class , "<STR_LIT:date>" , new JsDateJsonValueProcessor ( ) ) ; JSONObject jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT:value>" ) ) ; JSONObject jsDate = jsonObject . getJSONObject ( "<STR_LIT:date>" ) ; assertJsDate ( jsDate ) ; } public void testBeanWithDateProperty_fromObject_withJsonValueProcessor_3 ( ) { DateBean bean = new DateBean ( ) ; bean . setDate ( date ) ; bean . setValue ( <NUM_LIT> ) ; jsonConfig . registerJsonValueProcessor ( Date . class , new JsDateJsonValueProcessor ( ) ) ; JSONObject jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT:value>" ) ) ; JSONObject jsDate = jsonObject . getJSONObject ( "<STR_LIT:date>" ) ; assertJsDate ( jsDate ) ; } public void testBeanWithDateProperty_fromObject_withJsonValueProcessor_4 ( ) { DateBean bean = new DateBean ( ) ; bean . setDate ( date ) ; bean . setValue ( <NUM_LIT> ) ; jsonConfig . registerJsonValueProcessor ( "<STR_LIT:date>" , new JsDateJsonValueProcessor ( ) ) ; JSONObject jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT:value>" ) ) ; JSONObject jsDate = jsonObject . getJSONObject ( "<STR_LIT:date>" ) ; assertJsDate ( jsDate ) ; } public void testBeanWithDateProperty_put ( ) { DateBean bean = new DateBean ( ) ; bean . setValue ( <NUM_LIT> ) ; jsonConfig . registerJsonBeanProcessor ( Date . class , new JsDateJsonBeanProcessor ( ) ) ; JSONObject jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT:value>" ) ) ; JSONObject jsDate = jsonObject . getJSONObject ( "<STR_LIT:date>" ) ; JSONAssert . assertNull ( jsDate ) ; jsonObject . element ( "<STR_LIT:date>" , date , jsonConfig ) ; jsDate = jsonObject . getJSONObject ( "<STR_LIT:date>" ) ; assertJsDate ( jsDate ) ; } public void testDateAsBean_fromObject ( ) { jsonConfig . registerJsonBeanProcessor ( Date . class , new JsDateJsonBeanProcessor ( ) ) ; JSONObject jsDate = JSONObject . fromObject ( date , jsonConfig ) ; assertJsDate ( jsDate ) ; } public void testNumericValueWithProcessor_Byte ( ) { Map bean = new HashMap ( ) ; bean . put ( "<STR_LIT:value>" , new Byte ( Byte . MAX_VALUE ) ) ; jsonConfig . registerJsonValueProcessor ( "<STR_LIT:value>" , new IdentityJsonValueProcessor ( ) ) ; JSONObject jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( jsonObject ) ; assertEquals ( new Integer ( Byte . MAX_VALUE ) , jsonObject . get ( "<STR_LIT:value>" ) ) ; } public void testNumericValueWithProcessor_Short ( ) { Map bean = new HashMap ( ) ; bean . put ( "<STR_LIT:value>" , new Short ( Short . MAX_VALUE ) ) ; jsonConfig . registerJsonValueProcessor ( "<STR_LIT:value>" , new IdentityJsonValueProcessor ( ) ) ; JSONObject jsonObject = JSONObject . fromObject ( bean , jsonConfig ) ; assertNotNull ( jsonObject ) ; assertEquals ( new Integer ( Short . MAX_VALUE ) , jsonObject . get ( "<STR_LIT:value>" ) ) ; } protected void setUp ( ) throws Exception { Calendar c = Calendar . getInstance ( ) ; c . set ( Calendar . YEAR , <NUM_LIT> ) ; c . set ( Calendar . MONTH , <NUM_LIT:5> ) ; c . set ( Calendar . DAY_OF_MONTH , <NUM_LIT> ) ; c . set ( Calendar . HOUR_OF_DAY , <NUM_LIT:12> ) ; c . set ( Calendar . MINUTE , <NUM_LIT> ) ; c . set ( Calendar . SECOND , <NUM_LIT> ) ; c . set ( Calendar . MILLISECOND , <NUM_LIT> ) ; date = c . getTime ( ) ; jsonConfig = new JsonConfig ( ) ; } private void assertJsDate ( JSONObject jsDate ) { JSONAssert . assertNotNull ( jsDate ) ; int year = jsDate . getInt ( "<STR_LIT>" ) ; assertTrue ( year == <NUM_LIT> || year == <NUM_LIT> ) ; assertEquals ( <NUM_LIT:5> , jsDate . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsDate . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:12> , jsDate . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsDate . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsDate . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsDate . getInt ( "<STR_LIT>" ) ) ; } } </s>
<s> package net . sf . json ; import junit . framework . TestCase ; public abstract class AbstractJSONArrayStaticBuildersTestCase extends TestCase { public AbstractJSONArrayStaticBuildersTestCase ( String testName ) { super ( testName ) ; } public void testFromObject ( ) { JSONArray jsonArray = JSONArray . fromObject ( getSource ( ) ) ; assertNotNull ( jsonArray ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; JSONObject jsonObject = jsonArray . getJSONObject ( <NUM_LIT:0> ) ; assertJSONObject ( jsonObject , getProperties ( ) ) ; assertTrue ( ! jsonObject . has ( "<STR_LIT:class>" ) ) ; } public void testFromObject_excludes ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setExcludes ( getExclusions ( ) ) ; JSONArray jsonArray = JSONArray . fromObject ( getSource ( ) , jsonConfig ) ; assertNotNull ( jsonArray ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; JSONObject jsonObject = jsonArray . getJSONObject ( <NUM_LIT:0> ) ; assertJSONObject ( jsonObject , getProperties ( ) ) ; String [ ] excluded = getExclusions ( ) ; for ( int i = <NUM_LIT:0> ; i < excluded . length ; i ++ ) { assertTrue ( ! jsonObject . has ( excluded [ i ] ) ) ; } assertTrue ( ! jsonObject . has ( "<STR_LIT:class>" ) ) ; assertTrue ( ! jsonObject . has ( "<STR_LIT>" ) ) ; } public void testFromObject_excludes_ignoreDefaults ( ) { JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setExcludes ( getExclusions ( ) ) ; jsonConfig . setIgnoreDefaultExcludes ( true ) ; JSONArray jsonArray = JSONArray . fromObject ( getSource ( ) , jsonConfig ) ; assertNotNull ( jsonArray ) ; assertEquals ( <NUM_LIT:1> , jsonArray . size ( ) ) ; JSONObject jsonObject = jsonArray . getJSONObject ( <NUM_LIT:0> ) ; assertJSONObject ( jsonObject , getProperties ( ) ) ; assertTrue ( jsonObject . has ( "<STR_LIT:class>" ) ) ; assertTrue ( ! jsonObject . has ( "<STR_LIT>" ) ) ; } protected String [ ] getExclusions ( ) { return new String [ ] { "<STR_LIT>" } ; } protected String [ ] getProperties ( ) { return PropertyConstants . getProperties ( ) ; } protected abstract Object getSource ( ) ; private void assertJSONObject ( JSONObject json , String [ ] properties ) { assertNotNull ( json ) ; for ( int i = <NUM_LIT:0> ; i < properties . length ; i ++ ) { assertTrue ( json . has ( properties [ i ] ) ) ; } } } </s>
<s> package net . sf . json ; import java . util . ArrayList ; import java . util . List ; import junit . framework . TestCase ; import net . sf . json . sample . JsonEventAdpater ; public class TestJSONArrayEvents extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONArrayEvents . class ) ; } private JsonConfig jsonConfig ; private JsonEventAdpater jsonEventAdpater ; public TestJSONArrayEvents ( String name ) { super ( name ) ; } public void testFromObject_array ( ) { JSONArray . fromObject ( new Object [ ] { "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:3>" } , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_error ( ) { try { JSONArray . fromObject ( "<STR_LIT:{}>" , jsonConfig ) ; fail ( "<STR_LIT>" ) ; } catch ( JSONException expected ) { assertEquals ( <NUM_LIT:1> , jsonEventAdpater . getError ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getWarning ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getArrayStart ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getArrayEnd ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getObjectStart ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getObjectEnd ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getElementAdded ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getPropertySet ( ) ) ; } } public void testFromObject_JSONArray ( ) { JSONArray array = new JSONArray ( ) . element ( "<STR_LIT:1>" ) . element ( "<STR_LIT:2>" ) . element ( "<STR_LIT:3>" ) ; JSONArray . fromObject ( array , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_list ( ) { List list = new ArrayList ( ) ; list . add ( "<STR_LIT:1>" ) ; list . add ( "<STR_LIT:2>" ) ; list . add ( "<STR_LIT:3>" ) ; JSONArray . fromObject ( list , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_primitive_boolean ( ) { JSONArray . fromObject ( new boolean [ ] { true , false , true } , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_primitive_byte ( ) { JSONArray . fromObject ( new byte [ ] { ( byte ) <NUM_LIT:1> , ( byte ) <NUM_LIT:2> , ( byte ) <NUM_LIT:3> } , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_primitive_double ( ) { JSONArray . fromObject ( new double [ ] { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_primitive_float ( ) { JSONArray . fromObject ( new float [ ] { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_primitive_int ( ) { JSONArray . fromObject ( new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_primitive_long ( ) { JSONArray . fromObject ( new long [ ] { <NUM_LIT:1L> , <NUM_LIT> , <NUM_LIT> } , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_primitive_short ( ) { JSONArray . fromObject ( new short [ ] { ( short ) <NUM_LIT:1> , ( short ) <NUM_LIT:2> , ( short ) <NUM_LIT:3> } , jsonConfig ) ; assertEvents ( ) ; } public void testFromObject_string ( ) { JSONArray . fromObject ( "<STR_LIT>" , jsonConfig ) ; assertEvents ( ) ; } protected void setUp ( ) throws Exception { jsonEventAdpater = new JsonEventAdpater ( ) ; jsonConfig = new JsonConfig ( ) ; jsonConfig . addJsonEventListener ( jsonEventAdpater ) ; jsonConfig . enableEventTriggering ( ) ; } private void assertEvents ( ) { assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getError ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getWarning ( ) ) ; assertEquals ( <NUM_LIT:1> , jsonEventAdpater . getArrayStart ( ) ) ; assertEquals ( <NUM_LIT:1> , jsonEventAdpater . getArrayEnd ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getObjectStart ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getObjectEnd ( ) ) ; assertEquals ( <NUM_LIT:3> , jsonEventAdpater . getElementAdded ( ) ) ; assertEquals ( <NUM_LIT:0> , jsonEventAdpater . getPropertySet ( ) ) ; } } </s>
<s> package net . sf . json ; public class TestJSONObjectStaticBuilders_String extends AbstractJSONObjectStaticBuildersTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectStaticBuilders_String . class ) ; } public TestJSONObjectStaticBuilders_String ( String name ) { super ( name ) ; } protected Object getSource ( ) { return "<STR_LIT>" ; } } </s>
<s> package net . sf . json ; import java . util . List ; import junit . framework . TestCase ; import net . sf . json . test . JSONAssert ; public class TestJSONArrayAsList extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONArrayAsList . class ) ; } private JSONArray jsonArray ; public TestJSONArrayAsList ( String name ) { super ( name ) ; } public void testAdd ( ) { assertEquals ( <NUM_LIT:5> , jsonArray . size ( ) ) ; jsonArray . add ( "<STR_LIT:value>" ) ; assertEquals ( <NUM_LIT:6> , jsonArray . size ( ) ) ; } public void testAdd_index_value ( ) { assertEquals ( <NUM_LIT:5> , jsonArray . size ( ) ) ; Object first = jsonArray . get ( <NUM_LIT:0> ) ; jsonArray . add ( <NUM_LIT:0> , "<STR_LIT:value>" ) ; assertEquals ( <NUM_LIT:6> , jsonArray . size ( ) ) ; assertEquals ( "<STR_LIT:value>" , jsonArray . get ( <NUM_LIT:0> ) ) ; assertEquals ( first , jsonArray . get ( <NUM_LIT:1> ) ) ; } public void testAddAll ( ) { JSONArray array = new JSONArray ( ) ; array . addAll ( jsonArray ) ; JSONAssert . assertEquals ( jsonArray , array ) ; } public void testAddAll_index_value ( ) { JSONArray array = new JSONArray ( ) . element ( "<STR_LIT:value>" ) ; array . addAll ( <NUM_LIT:0> , jsonArray ) ; assertEquals ( <NUM_LIT:6> , array . size ( ) ) ; assertEquals ( "<STR_LIT:value>" , array . get ( <NUM_LIT:5> ) ) ; } public void testClear ( ) { assertEquals ( <NUM_LIT:5> , jsonArray . size ( ) ) ; jsonArray . clear ( ) ; assertEquals ( <NUM_LIT:0> , jsonArray . size ( ) ) ; } public void testContains ( ) { assertTrue ( jsonArray . contains ( "<STR_LIT:1>" ) ) ; assertFalse ( jsonArray . contains ( "<STR_LIT:2>" ) ) ; } public void testContainsAll ( ) { assertTrue ( jsonArray . containsAll ( jsonArray ) ) ; } public void testIndexOf ( ) { jsonArray . element ( "<STR_LIT:1>" ) ; assertEquals ( <NUM_LIT:0> , jsonArray . indexOf ( "<STR_LIT:1>" ) ) ; } public void testIsEmpty ( ) { assertFalse ( jsonArray . isEmpty ( ) ) ; } public void testLastIndexOf ( ) { jsonArray . element ( "<STR_LIT:1>" ) ; assertEquals ( <NUM_LIT:5> , jsonArray . lastIndexOf ( "<STR_LIT:1>" ) ) ; } public void testRemove ( ) { assertEquals ( <NUM_LIT:5> , jsonArray . size ( ) ) ; jsonArray . remove ( "<STR_LIT:string>" ) ; assertEquals ( <NUM_LIT:4> , jsonArray . size ( ) ) ; assertTrue ( ! jsonArray . contains ( "<STR_LIT:string>" ) ) ; } public void testRemove_index ( ) { assertEquals ( <NUM_LIT:5> , jsonArray . size ( ) ) ; jsonArray . remove ( <NUM_LIT:2> ) ; assertEquals ( <NUM_LIT:4> , jsonArray . size ( ) ) ; assertTrue ( ! jsonArray . contains ( "<STR_LIT:string>" ) ) ; } public void testRemoveAll ( ) { assertEquals ( <NUM_LIT:5> , jsonArray . size ( ) ) ; jsonArray . removeAll ( jsonArray ) ; assertEquals ( <NUM_LIT:0> , jsonArray . size ( ) ) ; } public void testRetainAll ( ) { assertEquals ( <NUM_LIT:5> , jsonArray . size ( ) ) ; jsonArray . retainAll ( jsonArray ) ; assertEquals ( <NUM_LIT:5> , jsonArray . size ( ) ) ; } public void testSubList ( ) { List actual = jsonArray . subList ( <NUM_LIT:0> , <NUM_LIT:3> ) ; JSONArray expected = new JSONArray ( ) . element ( "<STR_LIT:1>" ) . element ( "<STR_LIT:true>" ) . element ( "<STR_LIT:string>" ) ; JSONAssert . assertEquals ( expected , JSONArray . fromObject ( actual ) ) ; } protected void setUp ( ) throws Exception { jsonArray = new JSONArray ( ) . element ( "<STR_LIT:1>" ) . element ( "<STR_LIT:true>" ) . element ( "<STR_LIT:string>" ) . element ( "<STR_LIT>" ) . element ( "<STR_LIT>" ) ; } } </s>
<s> package net . sf . json . processors ; import java . util . Calendar ; import java . util . Date ; import junit . framework . TestCase ; import net . sf . json . JSONObject ; import net . sf . json . JsonConfig ; public class TestJsDateJsonBeanProcessor extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJsDateJsonBeanProcessor . class ) ; } private JsDateJsonBeanProcessor processor ; public TestJsDateJsonBeanProcessor ( String testName ) { super ( testName ) ; } public void testProcessBean ( ) { Calendar c = Calendar . getInstance ( ) ; c . set ( Calendar . YEAR , <NUM_LIT> ) ; c . set ( Calendar . MONTH , <NUM_LIT:5> ) ; c . set ( Calendar . DAY_OF_MONTH , <NUM_LIT> ) ; c . set ( Calendar . HOUR_OF_DAY , <NUM_LIT:12> ) ; c . set ( Calendar . MINUTE , <NUM_LIT> ) ; c . set ( Calendar . SECOND , <NUM_LIT> ) ; c . set ( Calendar . MILLISECOND , <NUM_LIT> ) ; Date date = c . getTime ( ) ; JSONObject jsonObject = processor . processBean ( date , new JsonConfig ( ) ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:5> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:12> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; } public void testProcessBean_sqlDate ( ) { Calendar c = Calendar . getInstance ( ) ; c . set ( Calendar . YEAR , <NUM_LIT> ) ; c . set ( Calendar . MONTH , <NUM_LIT:5> ) ; c . set ( Calendar . DAY_OF_MONTH , <NUM_LIT> ) ; c . set ( Calendar . HOUR_OF_DAY , <NUM_LIT:12> ) ; c . set ( Calendar . MINUTE , <NUM_LIT> ) ; c . set ( Calendar . SECOND , <NUM_LIT> ) ; c . set ( Calendar . MILLISECOND , <NUM_LIT> ) ; Date date = c . getTime ( ) ; JSONObject jsonObject = processor . processBean ( new java . sql . Date ( date . getTime ( ) ) , new JsonConfig ( ) ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:5> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:12> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; } protected void setUp ( ) throws Exception { processor = new JsDateJsonBeanProcessor ( ) ; } } </s>
<s> package net . sf . json . processors ; import java . util . Calendar ; import java . util . Date ; import junit . framework . TestCase ; import net . sf . json . JSONObject ; import net . sf . json . JsonConfig ; public class TestJsDateJsonValueProcessor extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJsDateJsonValueProcessor . class ) ; } private JsDateJsonValueProcessor processor ; public TestJsDateJsonValueProcessor ( String testName ) { super ( testName ) ; } public void testProcessBean ( ) { Calendar c = Calendar . getInstance ( ) ; c . set ( Calendar . YEAR , <NUM_LIT> ) ; c . set ( Calendar . MONTH , <NUM_LIT:5> ) ; c . set ( Calendar . DAY_OF_MONTH , <NUM_LIT> ) ; c . set ( Calendar . HOUR_OF_DAY , <NUM_LIT:12> ) ; c . set ( Calendar . MINUTE , <NUM_LIT> ) ; c . set ( Calendar . SECOND , <NUM_LIT> ) ; c . set ( Calendar . MILLISECOND , <NUM_LIT> ) ; Date date = c . getTime ( ) ; JSONObject jsonObject = ( JSONObject ) processor . processObjectValue ( "<STR_LIT:date>" , date , new JsonConfig ( ) ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:5> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:12> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; } public void testProcessBean_sqlDate ( ) { Calendar c = Calendar . getInstance ( ) ; c . set ( Calendar . YEAR , <NUM_LIT> ) ; c . set ( Calendar . MONTH , <NUM_LIT:5> ) ; c . set ( Calendar . DAY_OF_MONTH , <NUM_LIT> ) ; c . set ( Calendar . HOUR_OF_DAY , <NUM_LIT:12> ) ; c . set ( Calendar . MINUTE , <NUM_LIT> ) ; c . set ( Calendar . SECOND , <NUM_LIT> ) ; c . set ( Calendar . MILLISECOND , <NUM_LIT> ) ; Date date = c . getTime ( ) ; JSONObject jsonObject = ( JSONObject ) processor . processObjectValue ( "<STR_LIT:date>" , new java . sql . Date ( date . getTime ( ) ) , new JsonConfig ( ) ) ; assertNotNull ( jsonObject ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:5> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:12> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , jsonObject . getInt ( "<STR_LIT>" ) ) ; } protected void setUp ( ) throws Exception { processor = new JsDateJsonValueProcessor ( ) ; } } </s>
<s> package net . sf . json . processors ; import junit . framework . TestSuite ; public class AllTests extends TestSuite { public static TestSuite suite ( ) throws Exception { TestSuite suite = new TestSuite ( ) ; suite . setName ( "<STR_LIT>" ) ; suite . addTest ( new TestSuite ( TestJsDateJsonBeanProcessor . class ) ) ; suite . addTest ( new TestSuite ( TestJsDateJsonValueProcessor . class ) ) ; suite . addTest ( new TestSuite ( TestJsonBeanProcessorMatcher . class ) ) ; return suite ; } } </s>
<s> package net . sf . json . processors ; import java . util . Iterator ; import java . util . Set ; public class StartsWithJsonBeanProcessorMatcher extends JsonBeanProcessorMatcher { private String pattern ; public StartsWithJsonBeanProcessorMatcher ( String pattern ) { this . pattern = pattern ; } public Object getMatch ( Class target , Set set ) { if ( target != null && set != null && target . getName ( ) . startsWith ( pattern ) ) { for ( Iterator i = set . iterator ( ) ; i . hasNext ( ) ; ) { Class c = ( Class ) i . next ( ) ; if ( c . getName ( ) . startsWith ( pattern ) ) { return c ; } } } return null ; } } </s>
<s> package net . sf . json . processors ; import java . util . HashSet ; import java . util . Set ; import junit . framework . TestCase ; public class TestJsonBeanProcessorMatcher extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJsonBeanProcessorMatcher . class ) ; } public void testGetMatchUsingStartsWith ( ) { Set set = new HashSet ( ) ; set . add ( JsonBeanProcessorMatcher . class ) ; set . add ( JsonBeanProcessorMatcher . DEFAULT . getClass ( ) ) ; JsonBeanProcessorMatcher matcher = new StartsWithJsonBeanProcessorMatcher ( "<STR_LIT>" ) ; assertEquals ( JsonBeanProcessorMatcher . DEFAULT . getClass ( ) , matcher . getMatch ( JsonBeanProcessorMatcher . DEFAULT . getClass ( ) , set ) ) ; } } </s>
<s> package net . sf . json ; import net . sf . json . processors . PropertyNameProcessor ; public class PrefixerPropertyNameProcessor implements PropertyNameProcessor { private final String prefix ; public PrefixerPropertyNameProcessor ( String prefix ) { this . prefix = prefix ; } public String processPropertyName ( Class beanClass , String name ) { return prefix + name ; } } </s>
<s> package net . sf . json ; import java . math . BigInteger ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Set ; import junit . framework . TestCase ; import net . sf . ezmorph . MorphUtils ; import net . sf . ezmorph . bean . MorphDynaBean ; import net . sf . ezmorph . bean . MorphDynaClass ; import net . sf . json . sample . BeanA ; public class TestJSONArrayCollections extends TestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONArrayCollections . class ) ; } public TestJSONArrayCollections ( String testName ) { super ( testName ) ; } public void testToList_bean_elements ( ) { List expected = new ArrayList ( ) ; expected . add ( new BeanA ( ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray , BeanA . class ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_BigDecimal ( ) { List expected = new ArrayList ( ) ; expected . add ( MorphUtils . BIGDECIMAL_ZERO ) ; expected . add ( MorphUtils . BIGDECIMAL_ONE ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_BigInteger ( ) { List expected = new ArrayList ( ) ; expected . add ( BigInteger . ZERO ) ; expected . add ( BigInteger . ONE ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Boolean ( ) { List expected = new ArrayList ( ) ; expected . add ( Boolean . TRUE ) ; expected . add ( Boolean . FALSE ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Byte ( ) { List expected = new ArrayList ( ) ; expected . add ( new Integer ( <NUM_LIT:1> ) ) ; expected . add ( new Integer ( <NUM_LIT:2> ) ) ; List bytes = new ArrayList ( ) ; bytes . add ( new Byte ( ( byte ) <NUM_LIT:1> ) ) ; bytes . add ( new Byte ( ( byte ) <NUM_LIT:2> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( bytes ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Character ( ) { List expected = new ArrayList ( ) ; expected . add ( "<STR_LIT:A>" ) ; expected . add ( "<STR_LIT:B>" ) ; List chars = new ArrayList ( ) ; chars . add ( new Character ( '<CHAR_LIT:A>' ) ) ; chars . add ( new Character ( '<CHAR_LIT>' ) ) ; JSONArray jsonArray = JSONArray . fromObject ( chars ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Double ( ) { List expected = new ArrayList ( ) ; expected . add ( new Double ( <NUM_LIT> ) ) ; expected . add ( new Double ( <NUM_LIT> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_dynaBean_elements ( ) throws Exception { List expected = new ArrayList ( ) ; expected . add ( createDynaBean ( ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Float ( ) { List expected = new ArrayList ( ) ; expected . add ( new Double ( <NUM_LIT> ) ) ; expected . add ( new Double ( <NUM_LIT> ) ) ; List floats = new ArrayList ( ) ; floats . add ( new Float ( <NUM_LIT> ) ) ; floats . add ( new Float ( <NUM_LIT> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( floats ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Integer ( ) { List expected = new ArrayList ( ) ; expected . add ( new Integer ( <NUM_LIT:1> ) ) ; expected . add ( new Integer ( <NUM_LIT:2> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_JSONFunction_elements ( ) { List expected = new ArrayList ( ) ; expected . add ( new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_JSONFunction_elements_2 ( ) { List expected = new ArrayList ( ) ; expected . add ( "<STR_LIT>" ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Long ( ) { List expected = new ArrayList ( ) ; expected . add ( new Integer ( <NUM_LIT:1> ) ) ; expected . add ( new Integer ( <NUM_LIT:2> ) ) ; List longs = new ArrayList ( ) ; longs . add ( new Long ( <NUM_LIT:1L> ) ) ; longs . add ( new Long ( <NUM_LIT> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( longs ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Long2 ( ) { List expected = new ArrayList ( ) ; expected . add ( new Long ( Integer . MAX_VALUE + <NUM_LIT:1L> ) ) ; expected . add ( new Long ( Integer . MAX_VALUE + <NUM_LIT> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_null_elements ( ) { List expected = new ArrayList ( ) ; expected . add ( null ) ; expected . add ( null ) ; expected . add ( null ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_Short ( ) { List expected = new ArrayList ( ) ; expected . add ( new Integer ( <NUM_LIT:1> ) ) ; expected . add ( new Integer ( <NUM_LIT:2> ) ) ; List shorts = new ArrayList ( ) ; shorts . add ( new Short ( ( short ) <NUM_LIT:1> ) ) ; shorts . add ( new Short ( ( short ) <NUM_LIT:2> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( shorts ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_String ( ) { List expected = new ArrayList ( ) ; expected . add ( "<STR_LIT:A>" ) ; expected . add ( "<STR_LIT:B>" ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToList_String_multi ( ) { List a = new ArrayList ( ) ; a . add ( "<STR_LIT:a>" ) ; a . add ( "<STR_LIT:b>" ) ; List b = new ArrayList ( ) ; b . add ( "<STR_LIT:1>" ) ; b . add ( "<STR_LIT:2>" ) ; List expected = new ArrayList ( ) ; expected . add ( a ) ; expected . add ( b ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; List actual = ( List ) JSONArray . toCollection ( jsonArray ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_bean_elements ( ) { Set expected = new HashSet ( ) ; expected . add ( new BeanA ( ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; jsonConfig . setRootClass ( BeanA . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_BigDecimal ( ) { Set expected = new HashSet ( ) ; expected . add ( MorphUtils . BIGDECIMAL_ZERO ) ; expected . add ( MorphUtils . BIGDECIMAL_ONE ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_BigInteger ( ) { Set expected = new HashSet ( ) ; expected . add ( BigInteger . ZERO ) ; expected . add ( BigInteger . ONE ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_Boolean ( ) { Set expected = new HashSet ( ) ; expected . add ( Boolean . TRUE ) ; expected . add ( Boolean . FALSE ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_Byte ( ) { Set expected = new HashSet ( ) ; expected . add ( new Integer ( <NUM_LIT:1> ) ) ; expected . add ( new Integer ( <NUM_LIT:2> ) ) ; Set bytes = new HashSet ( ) ; bytes . add ( new Byte ( ( byte ) <NUM_LIT:1> ) ) ; bytes . add ( new Byte ( ( byte ) <NUM_LIT:2> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( bytes ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_Character ( ) { Set expected = new HashSet ( ) ; expected . add ( "<STR_LIT:A>" ) ; expected . add ( "<STR_LIT:B>" ) ; Set chars = new HashSet ( ) ; chars . add ( new Character ( '<CHAR_LIT:A>' ) ) ; chars . add ( new Character ( '<CHAR_LIT>' ) ) ; JSONArray jsonArray = JSONArray . fromObject ( chars ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_Double ( ) { Set expected = new HashSet ( ) ; expected . add ( new Double ( <NUM_LIT> ) ) ; expected . add ( new Double ( <NUM_LIT> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_dynaBean_elements ( ) throws Exception { Set expected = new HashSet ( ) ; expected . add ( createDynaBean ( ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_Float ( ) { Set expected = new HashSet ( ) ; expected . add ( new Double ( <NUM_LIT> ) ) ; expected . add ( new Double ( <NUM_LIT> ) ) ; Set floats = new HashSet ( ) ; floats . add ( new Float ( <NUM_LIT> ) ) ; floats . add ( new Float ( <NUM_LIT> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( floats ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_Integer ( ) { Set expected = new HashSet ( ) ; expected . add ( new Integer ( <NUM_LIT:1> ) ) ; expected . add ( new Integer ( <NUM_LIT:2> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_JSONFunction_elements ( ) { Set expected = new HashSet ( ) ; expected . add ( new JSONFunction ( new String [ ] { "<STR_LIT:a>" } , "<STR_LIT>" ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_Long ( ) { Set expected = new HashSet ( ) ; expected . add ( new Integer ( <NUM_LIT:1> ) ) ; expected . add ( new Integer ( <NUM_LIT:2> ) ) ; Set longs = new HashSet ( ) ; longs . add ( new Long ( <NUM_LIT:1L> ) ) ; longs . add ( new Long ( <NUM_LIT> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( longs ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_Long2 ( ) { Set expected = new HashSet ( ) ; expected . add ( new Long ( Integer . MAX_VALUE + <NUM_LIT:1L> ) ) ; expected . add ( new Long ( Integer . MAX_VALUE + <NUM_LIT> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_null_elements ( ) { Set expected = new HashSet ( ) ; expected . add ( null ) ; expected . add ( null ) ; expected . add ( null ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_Short ( ) { Set expected = new HashSet ( ) ; expected . add ( new Integer ( <NUM_LIT:1> ) ) ; expected . add ( new Integer ( <NUM_LIT:2> ) ) ; Set shorts = new HashSet ( ) ; shorts . add ( new Short ( ( short ) <NUM_LIT:1> ) ) ; shorts . add ( new Short ( ( short ) <NUM_LIT:2> ) ) ; JSONArray jsonArray = JSONArray . fromObject ( shorts ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_String ( ) { Set expected = new HashSet ( ) ; expected . add ( "<STR_LIT:A>" ) ; expected . add ( "<STR_LIT:B>" ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } public void testToSet_String_multi ( ) { Set a = new HashSet ( ) ; a . add ( "<STR_LIT:a>" ) ; a . add ( "<STR_LIT:b>" ) ; Set b = new HashSet ( ) ; b . add ( "<STR_LIT:1>" ) ; b . add ( "<STR_LIT:2>" ) ; Set expected = new HashSet ( ) ; expected . add ( a ) ; expected . add ( b ) ; JSONArray jsonArray = JSONArray . fromObject ( expected ) ; JsonConfig jsonConfig = new JsonConfig ( ) ; jsonConfig . setCollectionType ( Set . class ) ; Set actual = ( Set ) JSONArray . toCollection ( jsonArray , jsonConfig ) ; Assertions . assertEquals ( expected , actual ) ; } private MorphDynaBean createDynaBean ( ) throws Exception { Map properties = new HashMap ( ) ; properties . put ( "<STR_LIT:name>" , String . class ) ; MorphDynaClass dynaClass = new MorphDynaClass ( properties ) ; MorphDynaBean dynaBean = ( MorphDynaBean ) dynaClass . newInstance ( ) ; dynaBean . setDynaBeanClass ( dynaClass ) ; dynaBean . set ( "<STR_LIT:name>" , "<STR_LIT>" ) ; return dynaBean ; } } </s>
<s> package net . sf . json ; import java . util . HashMap ; import java . util . Map ; public class TestJSONObjectStaticBuilders_Map extends AbstractJSONObjectStaticBuildersTestCase { public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( TestJSONObjectStaticBuilders_Map . class ) ; } public TestJSONObjectStaticBuilders_Map ( String name ) { super ( name ) ; } protected Object getSource ( ) { Map map = new HashMap ( ) ; String [ ] props = getProperties ( ) ; for ( int i = <NUM_LIT:0> ; i < props . length ; i ++ ) { map . put ( props [ i ] , PropertyConstants . getPropertyValue ( props [ i ] ) ) ; } map . put ( "<STR_LIT:class>" , "<STR_LIT>" ) ; map . put ( "<STR_LIT>" , "<STR_LIT>" ) ; return map ; } } </s>
<s> package net . sf . json . sample ; import java . math . BigDecimal ; import java . math . BigInteger ; public class NumberBean { private BigDecimal pbigdec ; private BigInteger pbigint ; private byte pbyte ; private double pdouble ; private float pfloat ; private int pint ; private long plong ; private short pshort ; private Byte pwbyte ; private Double pwdouble ; private Float pwfloat ; private Integer pwint ; private Long pwlong ; private Short pwshort ; public BigDecimal getPbigdec ( ) { return pbigdec ; } public BigInteger getPbigint ( ) { return pbigint ; } public byte getPbyte ( ) { return pbyte ; } public double getPdouble ( ) { return pdouble ; } public float getPfloat ( ) { return pfloat ; } public int getPint ( ) { return pint ; } public long getPlong ( ) { return plong ; } public short getPshort ( ) { return pshort ; } public Byte getPwbyte ( ) { return pwbyte ; } public Double getPwdouble ( ) { return pwdouble ; } public Float getPwfloat ( ) { return pwfloat ; } public Integer getPwint ( ) { return pwint ; } public Long getPwlong ( ) { return pwlong ; } public Short getPwshort ( ) { return pwshort ; } public void setPbigdec ( BigDecimal pbigdec ) { this . pbigdec = pbigdec ; } public void setPbigint ( BigInteger pbigint ) { this . pbigint = pbigint ; } public void setPbyte ( byte pbyte ) { this . pbyte = pbyte ; } public void setPdouble ( double pdouble ) { this . pdouble = pdouble ; } public void setPfloat ( float pfloat ) { this . pfloat = pfloat ; } public void setPint ( int pint ) { this . pint = pint ; } public void setPlong ( long plong ) { this . plong = plong ; } public void setPshort ( short pshort ) { this . pshort = pshort ; } public void setPwbyte ( Byte pwbyte ) { this . pwbyte = pwbyte ; } public void setPwdouble ( Double pwdouble ) { this . pwdouble = pwdouble ; } public void setPwfloat ( Float pwfloat ) { this . pwfloat = pwfloat ; } public void setPwint ( Integer pwint ) { this . pwint = pwint ; } public void setPwlong ( Long pwlong ) { this . pwlong = pwlong ; } public void setPwshort ( Short pwshort ) { this . pwshort = pwshort ; } } </s>
<s> package net . sf . json . sample ; import java . lang . reflect . InvocationTargetException ; import net . sf . json . JSONObject ; import net . sf . json . util . NewBeanInstanceStrategy ; public class UnstandardBeanInstanceStrategy extends NewBeanInstanceStrategy { public Object newInstance ( Class target , JSONObject source ) throws InstantiationException , IllegalAccessException , SecurityException , NoSuchMethodException , InvocationTargetException { return new UnstandardBean ( source . getInt ( "<STR_LIT:id>" ) ) ; } } </s>
<s> package net . sf . json . sample ; public class JavaIdentifierBean { private String camelCase ; private String under_score ; private String whitespace ; public String getCamelCase ( ) { return camelCase ; } public String getUnder_score ( ) { return under_score ; } public String getWhitespace ( ) { return whitespace ; } public void setCamelCase ( String camelCase ) { this . camelCase = camelCase ; } public void setUnder_score ( String under_score ) { this . under_score = under_score ; } public void setWhitespace ( String whitespace ) { this . whitespace = whitespace ; } } </s>
<s> package net . sf . json . sample ; import net . sf . json . JsonConfig ; import net . sf . json . processors . JsonValueProcessor ; import net . sf . json . util . JSONUtils ; public class IdentityJsonValueProcessor implements JsonValueProcessor { public Object processArrayValue ( Object value , JsonConfig jsonConfig ) { return process ( value , jsonConfig ) ; } public Object processObjectValue ( String key , Object value , JsonConfig jsonConfig ) { return process ( value , jsonConfig ) ; } private Object process ( Object value , JsonConfig jsonConfig ) { if ( JSONUtils . isNumber ( value ) ) { value = JSONUtils . transformNumber ( ( Number ) value ) ; } return value ; } } </s>
<s> package net . sf . json . sample ; import net . sf . ezmorph . object . AbstractObjectMorpher ; public class IdBean { private Id id ; public Id getId ( ) { return id ; } public void setId ( Id id ) { this . id = id ; } public static class Id { private long value ; public Id ( ) { value = <NUM_LIT:0> ; } public Id ( long value ) { super ( ) ; this . value = value ; } public boolean equals ( Object obj ) { if ( obj == this ) { return true ; } if ( obj == null ) { return false ; } if ( ! ( obj instanceof Id ) ) { return false ; } Id other = ( Id ) obj ; return value == other . value ; } public long getValue ( ) { return value ; } public int hashCode ( ) { return getClass ( ) . hashCode ( ) + ( int ) value ; } public void setValue ( long value ) { this . value = value ; } } public static class IdMorpher extends AbstractObjectMorpher { public Object morph ( Object value ) { if ( value != null ) { if ( value instanceof Number ) { return new IdBean . Id ( ( ( Number ) value ) . longValue ( ) ) ; } else if ( value instanceof String ) { return new IdBean . Id ( new Long ( ( String ) value ) . longValue ( ) ) ; } } return null ; } public Class morphsTo ( ) { return IdBean . Id . class ; } } } </s>
<s> package net . sf . json . sample ; import java . util . List ; public class EmptyBean { private Object [ ] arrayp ; private Byte bytep ; private Character charp ; private Double doublep ; private Float floatp ; private Integer intp ; private List listp ; private Long longp ; private Short shortp ; private String stringp ; public Object [ ] getArrayp ( ) { return arrayp ; } public Byte getBytep ( ) { return bytep ; } public Character getCharp ( ) { return charp ; } public Double getDoublep ( ) { return doublep ; } public Float getFloatp ( ) { return floatp ; } public Integer getIntp ( ) { return intp ; } public List getListp ( ) { return listp ; } public Long getLongp ( ) { return longp ; } public Short getShortp ( ) { return shortp ; } public String getStringp ( ) { return stringp ; } public void setArrayp ( Object [ ] arrayp ) { this . arrayp = arrayp ; } public void setBytep ( Byte bytep ) { this . bytep = bytep ; } public void setCharp ( Character charp ) { this . charp = charp ; } public void setDoublep ( Double doublep ) { this . doublep = doublep ; } public void setFloatp ( Float floatp ) { this . floatp = floatp ; } public void setIntp ( Integer intp ) { this . intp = intp ; } public void setListp ( List listp ) { this . listp = listp ; } public void setLongp ( Long longp ) { this . longp = longp ; } public void setShortp ( Short shortp ) { this . shortp = shortp ; } public void setStringp ( String stringp ) { this . stringp = stringp ; } } </s>
<s> package net . sf . json . sample ; import java . util . List ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class MediaListBean { private Object media ; private List media2 ; public Object getMedia ( ) { return media ; } public List getMedia2 ( ) { return media2 ; } public void setMedia ( Object media ) { this . media = media ; } public void setMedia2 ( List media2 ) { this . media2 = media2 ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . EqualsBuilder ; import org . apache . commons . lang . builder . HashCodeBuilder ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class ValueBean { private int value ; public boolean equals ( Object obj ) { if ( obj == this ) { return true ; } if ( obj == null ) { return false ; } if ( ! ValueBean . class . isAssignableFrom ( obj . getClass ( ) ) ) { return false ; } return EqualsBuilder . reflectionEquals ( this , obj ) ; } public int getValue ( ) { return value ; } public int hashCode ( ) { return HashCodeBuilder . reflectionHashCode ( this ) ; } public void setValue ( int value ) { this . value = value ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import net . sf . json . JSONString ; import org . apache . commons . lang . ArrayUtils ; public class ArrayJSONStringBean implements JSONString { private String value ; public String getValue ( ) { return value ; } public void setValue ( String value ) { this . value = value ; } public String toJSONString ( ) { return ArrayUtils . toString ( value . split ( "<STR_LIT:U+002C>" ) ) . replace ( '<CHAR_LIT>' , '<CHAR_LIT:[>' ) . replace ( '<CHAR_LIT:}>' , '<CHAR_LIT:]>' ) ; } } </s>
<s> package net . sf . json . sample ; import net . sf . json . JSONFunction ; public class BeanWithFunc { private JSONFunction function ; public BeanWithFunc ( JSONFunction function ) { this . function = function ; } public BeanWithFunc ( String function ) { this . function = new JSONFunction ( function ) ; } public JSONFunction getFunction ( ) { return function ; } public void setFunction ( JSONFunction function ) { this . function = function ; } } </s>
<s> package net . sf . json . sample ; import java . util . HashSet ; import java . util . Set ; import org . apache . commons . lang . builder . EqualsBuilder ; import org . apache . commons . lang . builder . HashCodeBuilder ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class SetBean { private Set attributes = new HashSet ( ) ; public void addAttribute ( Object value ) { this . attributes . add ( value ) ; } public boolean equals ( Object obj ) { if ( obj == this ) { return true ; } if ( obj == null ) { return false ; } if ( ! SetBean . class . isAssignableFrom ( obj . getClass ( ) ) ) { return false ; } return EqualsBuilder . reflectionEquals ( this , obj ) ; } public Set getAttributes ( ) { return attributes ; } public int hashCode ( ) { return HashCodeBuilder . reflectionHashCode ( this ) ; } public void setAttributes ( Set attributes ) { this . attributes = attributes ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class ObjectBean { private Object parray ; private Object pbean ; private Object pboolean ; private Object pbyte ; private Object pchar ; private Object pclass ; private Object pdouble ; private Object pexcluded ; private Object pfloat ; private Object pfunction ; private Object pint ; private Object plist ; private Object plong ; private Object pmap ; private Object pshort ; private Object pstring ; public Object getParray ( ) { return parray ; } public Object getPbean ( ) { return pbean ; } public Object getPboolean ( ) { return pboolean ; } public Object getPbyte ( ) { return pbyte ; } public Object getPchar ( ) { return pchar ; } public Object getPclass ( ) { return pclass ; } public Object getPdouble ( ) { return pdouble ; } public Object getPexcluded ( ) { return pexcluded ; } public Object getPfloat ( ) { return pfloat ; } public Object getPfunction ( ) { return pfunction ; } public Object getPint ( ) { return pint ; } public Object getPlist ( ) { return plist ; } public Object getPlong ( ) { return plong ; } public Object getPmap ( ) { return pmap ; } public Object getPshort ( ) { return pshort ; } public Object getPstring ( ) { return pstring ; } public void setParray ( Object parray ) { this . parray = parray ; } public void setPbean ( Object bean ) { this . pbean = bean ; } public void setPboolean ( Object pboolean ) { this . pboolean = pboolean ; } public void setPbyte ( Object pbyte ) { this . pbyte = pbyte ; } public void setPchar ( Object pchar ) { this . pchar = pchar ; } public void setPclass ( Object pclass ) { this . pclass = pclass ; } public void setPdouble ( Object pdouble ) { this . pdouble = pdouble ; } public void setPexcluded ( Object pexcluded ) { this . pexcluded = pexcluded ; } public void setPfloat ( Object pfloat ) { this . pfloat = pfloat ; } public void setPfunction ( Object pfunction ) { this . pfunction = pfunction ; } public void setPint ( Object pint ) { this . pint = pint ; } public void setPlist ( Object plist ) { this . plist = plist ; } public void setPlong ( Object plong ) { this . plong = plong ; } public void setPmap ( Object pmap ) { this . pmap = pmap ; } public void setPshort ( Object pshort ) { this . pshort = pshort ; } public void setPstring ( Object pstring ) { this . pstring = pstring ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; public class ParentBean extends ValueBean { private ChildBean child ; public ChildBean getChild ( ) { return child ; } public void setChild ( ChildBean child ) { this . child = child ; child . setParent ( this ) ; } } </s>
<s> package net . sf . json . sample ; import java . util . Date ; public class DateBean extends ValueBean { private Date date ; public Date getDate ( ) { return date ; } public void setDate ( Date date ) { this . date = date ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class PackageProtectedBean { private int value ; PackageProtectedBean ( ) { } public int getValue ( ) { return value ; } public void setValue ( int value ) { this . value = value ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import java . util . ArrayList ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class MediaList { private ArrayList media ; public ArrayList getMedia ( ) { return media ; } public void setMedia ( ArrayList media ) { this . media = media ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class BeanC { private BeanA beanA = new BeanA ( ) ; private BeanB beanB = new BeanB ( ) ; public BeanA getBeanA ( ) { return beanA ; } public BeanB getBeanB ( ) { return beanB ; } public void setBeanA ( BeanA beanA ) { this . beanA = beanA ; } public void setBeanB ( BeanB beanB ) { this . beanB = beanB ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>
<s> package net . sf . json . sample ; import org . apache . commons . lang . builder . ToStringBuilder ; import org . apache . commons . lang . builder . ToStringStyle ; public class Player { private MediaList mediaList ; public MediaList getMediaList ( ) { return mediaList ; } public void setMediaList ( MediaList mediaList ) { this . mediaList = mediaList ; } public String toString ( ) { return ToStringBuilder . reflectionToString ( this , ToStringStyle . MULTI_LINE_STYLE ) ; } } </s>