text
stringlengths 30
1.67M
|
|---|
<s> package com . izforge . izpack . integration ; import static org . hamcrest . MatcherAssert . assertThat ; import java . io . File ; import java . io . IOException ; import org . apache . commons . io . FileUtils ; import org . fest . swing . fixture . DialogFixture ; import org . fest . swing . fixture . FrameFixture ; import org . hamcrest . core . Is ; import com . izforge . izpack . api . GuiId ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . installer . gui . InstallerController ; import com . izforge . izpack . installer . gui . InstallerFrame ; import com . izforge . izpack . installer . language . LanguageDialog ; public class HelperTestMethod { public static final int TIMEOUT = <NUM_LIT> ; public static File prepareInstallation ( InstallData installData ) throws IOException { File installPath = new File ( installData . getDefaultInstallPath ( ) ) ; FileUtils . deleteDirectory ( installPath ) ; assertThat ( installPath . exists ( ) , Is . is ( false ) ) ; return installPath ; } public static void clickDefaultLang ( LanguageDialog languageDialog ) { DialogFixture fixture = prepareDialogFixture ( languageDialog ) ; fixture . button ( GuiId . BUTTON_LANG_OK . id ) . click ( ) ; fixture . cleanUp ( ) ; } public static FrameFixture prepareFrameFixture ( InstallerFrame installerFrame , final InstallerController installerController ) { FrameFixture installerFrameFixture = new FrameFixture ( installerFrame ) ; installerController . buildInstallation ( ) ; installerController . launchInstallation ( ) ; return installerFrameFixture ; } public static DialogFixture prepareDialogFixture ( LanguageDialog languageDialog ) { DialogFixture dialogFixture = new DialogFixture ( languageDialog ) ; dialogFixture . show ( ) ; return dialogFixture ; } public static void waitAndCheckInstallation ( InstallData installData ) throws InterruptedException { waitAndCheckInstallation ( installData , new File ( installData . getInstallPath ( ) ) ) ; } public static void waitAndCheckInstallation ( InstallData installData , File installPath ) throws InterruptedException { while ( ! installData . isCanClose ( ) ) { Thread . sleep ( <NUM_LIT> ) ; } assertThat ( installPath . exists ( ) , Is . is ( true ) ) ; UninstallData uninstallData = new UninstallData ( ) ; for ( String installedFile : uninstallData . getInstalledFilesList ( ) ) { File file = new File ( installedFile ) ; assertThat ( file . exists ( ) , Is . is ( true ) ) ; } } } </s>
|
<s> package com . izforge . izpack . compiler . container ; import org . junit . runners . model . FrameworkMethod ; import org . picocontainer . MutablePicoContainer ; import com . izforge . izpack . installer . container . impl . InstallerContainer ; public class TestConsoleInstallationContainer extends AbstractTestInstallationContainer { public TestConsoleInstallationContainer ( Class < ? > klass , FrameworkMethod frameworkMethod ) { super ( klass , frameworkMethod ) ; initialise ( ) ; } @ Override protected InstallerContainer fillInstallerContainer ( MutablePicoContainer container ) { return new TestConsoleInstallerContainer ( container ) ; } } </s>
|
<s> package com . izforge . izpack . compiler . container ; import java . io . File ; import java . net . URL ; import org . apache . commons . io . FileUtils ; import org . junit . runners . model . FrameworkMethod ; import org . picocontainer . MutablePicoContainer ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . compiler . CompilerConfig ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . test . InstallFile ; import com . izforge . izpack . test . provider . JarFileProvider ; import com . izforge . izpack . test . util . ClassUtils ; import com . izforge . izpack . util . FileUtil ; public class TestCompilationContainer extends CompilerContainer { public static final String APPNAME = "<STR_LIT>" ; private final String installFile ; private File baseDir ; private File targetDir ; public TestCompilationContainer ( String installFile , File targetDir ) { super ( null ) ; this . installFile = installFile ; this . targetDir = targetDir ; initialise ( ) ; } public TestCompilationContainer ( Class < ? > testClass , FrameworkMethod method ) { super ( null ) ; InstallFile installFile = method . getAnnotation ( InstallFile . class ) ; if ( installFile == null ) { installFile = testClass . getAnnotation ( InstallFile . class ) ; } this . installFile = installFile . value ( ) ; initialise ( ) ; } public File getBaseDir ( ) { return baseDir ; } public void launchCompilation ( ) { try { CompilerConfig compilerConfig = getComponent ( CompilerConfig . class ) ; File out = getComponent ( File . class ) ; compilerConfig . executeCompiler ( ) ; ClassUtils . loadJarInSystemClassLoader ( out ) ; } catch ( Exception e ) { throw new IzPackException ( e ) ; } } @ Override protected void fillContainer ( MutablePicoContainer container ) { super . fillContainer ( container ) ; deleteLock ( ) ; URL resource = getClass ( ) . getClassLoader ( ) . getResource ( installFile ) ; if ( resource == null ) { throw new IllegalStateException ( "<STR_LIT>" + installFile ) ; } File file = FileUtil . convertUrlToFile ( resource ) ; baseDir = file . getParentFile ( ) ; if ( targetDir == null ) { targetDir = baseDir ; } File out = new File ( targetDir , "<STR_LIT>" + Math . random ( ) + "<STR_LIT>" ) ; out . deleteOnExit ( ) ; CompilerData data = new CompilerData ( file . getAbsolutePath ( ) , baseDir . getAbsolutePath ( ) , out . getAbsolutePath ( ) , false ) ; container . addConfig ( "<STR_LIT>" , file . getAbsolutePath ( ) ) ; container . addComponent ( CompilerData . class , data ) ; container . addComponent ( File . class , out ) ; container . addAdapter ( new JarFileProvider ( ) ) ; } private void deleteLock ( ) { File file = new File ( System . getProperty ( "<STR_LIT>" ) , "<STR_LIT>" + APPNAME + "<STR_LIT>" ) ; FileUtils . deleteQuietly ( file ) ; } } </s>
|
<s> package com . izforge . izpack . compiler . container ; import org . picocontainer . MutablePicoContainer ; import com . izforge . izpack . installer . container . impl . GUIInstallerContainer ; import com . izforge . izpack . test . util . TestHousekeeper ; import com . izforge . izpack . util . Housekeeper ; public class TestGUIInstallerContainer extends GUIInstallerContainer { public TestGUIInstallerContainer ( ) { super ( ) ; } public TestGUIInstallerContainer ( MutablePicoContainer container ) { super ( container ) ; } @ Override protected void registerComponents ( MutablePicoContainer pico ) { super . registerComponents ( pico ) ; super . getContainer ( ) . removeComponent ( Housekeeper . class ) ; addComponent ( TestHousekeeper . class ) ; } } </s>
|
<s> package com . izforge . izpack . compiler . container ; import java . util . jar . JarFile ; import org . junit . Rule ; import org . junit . runners . model . FrameworkMethod ; import org . picocontainer . MutablePicoContainer ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . core . container . AbstractContainer ; import com . izforge . izpack . installer . container . impl . InstallerContainer ; import com . izforge . izpack . test . junit . UnloadJarRule ; public abstract class AbstractTestInstallationContainer extends AbstractContainer { protected Class klass ; protected FrameworkMethod frameworkMethod ; @ Rule public UnloadJarRule unloadJarRule = new UnloadJarRule ( ) ; public AbstractTestInstallationContainer ( Class klass , FrameworkMethod frameworkMethod ) { this . klass = klass ; this . frameworkMethod = frameworkMethod ; } @ Override protected void fillContainer ( MutablePicoContainer picoContainer ) { TestCompilationContainer compiler = new TestCompilationContainer ( klass , frameworkMethod ) ; compiler . launchCompilation ( ) ; CompilerData data = compiler . getComponent ( CompilerData . class ) ; JarFile installer = compiler . getComponent ( JarFile . class ) ; picoContainer . addComponent ( data ) ; picoContainer . addComponent ( installer ) ; fillInstallerContainer ( picoContainer ) ; } protected abstract InstallerContainer fillInstallerContainer ( MutablePicoContainer picoContainer ) ; } </s>
|
<s> package com . izforge . izpack . compiler . container ; import org . junit . runners . model . FrameworkMethod ; import org . picocontainer . MutablePicoContainer ; import com . izforge . izpack . installer . container . impl . InstallerContainer ; public class TestInstallationContainer extends AbstractTestInstallationContainer { public TestInstallationContainer ( Class klass , FrameworkMethod frameworkMethod ) { super ( klass , frameworkMethod ) ; initialise ( ) ; } @ Override protected InstallerContainer fillInstallerContainer ( MutablePicoContainer container ) { return new TestGUIInstallerContainer ( container ) ; } } </s>
|
<s> package com . izforge . izpack . compiler . container ; import org . picocontainer . MutablePicoContainer ; import com . izforge . izpack . installer . console . ConsoleInstaller ; import com . izforge . izpack . installer . console . TestConsoleInstaller ; import com . izforge . izpack . installer . container . impl . ConsoleInstallerContainer ; import com . izforge . izpack . test . util . TestConsole ; import com . izforge . izpack . test . util . TestHousekeeper ; import com . izforge . izpack . util . Console ; import com . izforge . izpack . util . Housekeeper ; public class TestConsoleInstallerContainer extends ConsoleInstallerContainer { public TestConsoleInstallerContainer ( ) { } public TestConsoleInstallerContainer ( MutablePicoContainer container ) { super ( container ) ; } @ Override protected void registerComponents ( MutablePicoContainer container ) { super . registerComponents ( container ) ; container . removeComponent ( ConsoleInstaller . class ) ; container . addComponent ( TestConsoleInstaller . class ) ; container . removeComponent ( Console . class ) ; container . addComponent ( TestConsole . class ) ; container . removeComponent ( Housekeeper . class ) ; container . addComponent ( TestHousekeeper . class ) ; } } </s>
|
<s> package com . izforge . izpack . installer . data ; import static org . hamcrest . MatcherAssert . assertThat ; import static org . hamcrest . core . Is . is ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import java . io . File ; import java . io . IOException ; import java . util . HashMap ; import java . util . Map ; import java . util . zip . ZipException ; import java . util . zip . ZipFile ; import org . hamcrest . core . IsNot ; import org . junit . After ; import org . junit . Before ; import org . junit . Rule ; import org . junit . Test ; import org . junit . rules . TemporaryFolder ; import org . junit . runner . RunWith ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . data . AutomatedInstallData ; import com . izforge . izpack . api . data . Info ; import com . izforge . izpack . api . rules . Condition ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . compiler . container . TestInstallationContainer ; import com . izforge . izpack . matcher . ZipMatcher ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . InstallFile ; import com . izforge . izpack . test . junit . PicoRunner ; import com . izforge . izpack . util . IoHelper ; @ RunWith ( PicoRunner . class ) @ Container ( TestInstallationContainer . class ) public class UninstallDataWriterTest { @ Rule public TemporaryFolder temporaryFolder = new TemporaryFolder ( ) ; private final UninstallDataWriter uninstallDataWriter ; private final AutomatedInstallData installData ; private final RulesEngine rulesEngine ; public UninstallDataWriterTest ( UninstallDataWriter uninstallDataWriter , AutomatedInstallData installData , RulesEngine rulesEngine ) { this . uninstallDataWriter = uninstallDataWriter ; this . installData = installData ; this . rulesEngine = rulesEngine ; } @ Before public void setUp ( ) { File installPath = new File ( temporaryFolder . getRoot ( ) , "<STR_LIT>" ) ; installData . setInstallPath ( installPath . getAbsolutePath ( ) ) ; } @ After public void tearDown ( ) { System . getProperties ( ) . remove ( "<STR_LIT>" ) ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void testWriteUninstaller ( ) throws IOException { assertTrue ( uninstallDataWriter . write ( ) ) ; ZipFile uninstallJar = getUninstallerJar ( ) ; assertThat ( uninstallJar , ZipMatcher . isZipContainingFiles ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; assertThat ( uninstallJar , IsNot . not ( ZipMatcher . isZipContainingFiles ( "<STR_LIT>" ) ) ) ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void testWriteStandardListener ( ) throws IOException { assertTrue ( uninstallDataWriter . write ( ) ) ; ZipFile uninstallJar = getUninstallerJar ( ) ; assertThat ( uninstallJar , ZipMatcher . isZipContainingFile ( "<STR_LIT>" ) ) ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void testWriteCustomListener ( ) throws IOException { assertTrue ( uninstallDataWriter . write ( ) ) ; ZipFile uninstallJar = getUninstallerJar ( ) ; assertThat ( uninstallJar , ZipMatcher . isZipContainingFiles ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void testWriteNatives ( ) throws IOException { assertTrue ( uninstallDataWriter . write ( ) ) ; ZipFile uninstallJar = getUninstallerJar ( ) ; assertThat ( uninstallJar , ZipMatcher . isZipContainingFiles ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; assertThat ( uninstallJar , IsNot . not ( ZipMatcher . isZipContainingFiles ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void testWriteWindowsRegistrySupport ( ) throws IOException { addOSCondition ( "<STR_LIT>" ) ; installData . getInfo ( ) . setRequirePrivilegedExecutionUninstaller ( true ) ; assertTrue ( uninstallDataWriter . write ( ) ) ; ZipFile uninstallJar = getUninstallerJar ( ) ; assertThat ( uninstallJar , ZipMatcher . isZipContainingFiles ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void testRunWithPrivilegesOnOSX ( ) throws IOException { System . setProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; installData . getInfo ( ) . setRequirePrivilegedExecutionUninstaller ( true ) ; addOSCondition ( "<STR_LIT>" ) ; assertTrue ( uninstallDataWriter . write ( ) ) ; ZipFile uninstallJar = getUninstallerJar ( ) ; assertThat ( uninstallJar , ZipMatcher . isZipContainingFiles ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void testExecAdminWrittenWhenPrivilegedExecutionRequired ( ) throws IOException { installData . getInfo ( ) . setRequirePrivilegedExecutionUninstaller ( true ) ; assertTrue ( uninstallDataWriter . write ( ) ) ; ZipFile uninstallJar = getUninstallerJar ( ) ; assertThat ( uninstallJar , ZipMatcher . isZipContainingFiles ( "<STR_LIT>" ) ) ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void testExecAdminNotWrittenWhenPrivilegedExecutionNotRequired ( ) throws IOException { installData . getInfo ( ) . setRequirePrivilegedExecutionUninstaller ( false ) ; assertTrue ( uninstallDataWriter . write ( ) ) ; ZipFile uninstallJar = getUninstallerJar ( ) ; assertThat ( uninstallJar , IsNot . not ( ZipMatcher . isZipContainingFiles ( "<STR_LIT>" ) ) ) ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void testExecAdminNotWrittenForUnsatisfiedCondition ( ) throws IOException { installData . getInfo ( ) . setRequirePrivilegedExecutionUninstaller ( true ) ; installData . getInfo ( ) . setPrivilegedExecutionConditionID ( "<STR_LIT>" ) ; assertFalse ( rulesEngine . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( uninstallDataWriter . write ( ) ) ; ZipFile uninstallJar = getUninstallerJar ( ) ; assertThat ( uninstallJar , IsNot . not ( ZipMatcher . isZipContainingFiles ( "<STR_LIT>" ) ) ) ; } private void addOSCondition ( final String ruleId ) { Map < String , Condition > rules = new HashMap < String , Condition > ( ) ; rules . put ( ruleId , new Condition ( ) { { setId ( ruleId ) ; } public void readFromXML ( IXMLElement condition ) { } @ Override public boolean isTrue ( ) { return true ; } @ Override public void makeXMLData ( IXMLElement conditionRoot ) { } } ) ; rulesEngine . readConditionMap ( rules ) ; } private ZipFile getUninstallerJar ( ) throws IOException { String dir = IoHelper . translatePath ( installData . getInfo ( ) . getUninstallerPath ( ) , installData . getVariables ( ) ) ; String path = dir + File . separator + installData . getInfo ( ) . getUninstallerName ( ) ; File jar = new File ( path ) ; assertThat ( jar . exists ( ) , is ( true ) ) ; return new ZipFile ( jar ) ; } } </s>
|
<s> package com . izforge . izpack . installer . console ; import com . izforge . izpack . api . data . AutomatedInstallData ; import com . izforge . izpack . installer . data . UninstallDataWriter ; import com . izforge . izpack . installer . requirement . RequirementsChecker ; import com . izforge . izpack . test . util . TestConsole ; import com . izforge . izpack . util . Housekeeper ; public class TestConsoleInstaller extends ConsoleInstaller { public TestConsoleInstaller ( ConsolePanels panels , AutomatedInstallData installData , RequirementsChecker requirements , UninstallDataWriter writer , TestConsole console , Housekeeper housekeeper ) throws Exception { super ( panels , installData , requirements , writer , console , housekeeper ) ; } public TestConsole getConsole ( ) { return ( TestConsole ) super . getConsole ( ) ; } } </s>
|
<s> package com . izforge . izpack . installer . language ; import static org . hamcrest . MatcherAssert . assertThat ; import org . hamcrest . core . Is ; import org . junit . Test ; import org . junit . runner . RunWith ; import org . mockito . Mockito ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . installer . InstallerRequirementDisplay ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . compiler . container . TestInstallationContainer ; import com . izforge . izpack . core . resource . ResourceManager ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . InstallFile ; import com . izforge . izpack . test . junit . PicoRunner ; @ RunWith ( PicoRunner . class ) @ Container ( TestInstallationContainer . class ) public class ConditionCheckTest { private ConditionCheck conditionCheck ; public ConditionCheckTest ( InstallData installData , ResourceManager resourceManager , RulesEngine rules ) { this . conditionCheck = new ConditionCheck ( installData , resourceManager , rules ) ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void testCheckInstallerRequirements ( ) throws Exception { InstallerRequirementDisplay requirementDisplay = Mockito . mock ( InstallerRequirementDisplay . class ) ; assertThat ( conditionCheck . checkInstallerRequirements ( requirementDisplay ) , Is . is ( false ) ) ; Mockito . verify ( requirementDisplay ) . showMissingRequirementMessage ( "<STR_LIT>" ) ; } } </s>
|
<s> package com . izforge . izpack . installer . multiunpacker ; import static com . izforge . izpack . test . util . TestHelper . assertFileEquals ; import static com . izforge . izpack . test . util . TestHelper . assertFileNotExists ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertTrue ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . io . ObjectInputStream ; import java . net . URL ; import java . net . URLClassLoader ; import java . util . ArrayList ; import java . util . List ; import java . util . Properties ; 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 . Info ; import com . izforge . izpack . api . data . OverrideType ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . handler . Prompt ; 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 . compiler . compressor . DefaultPackCompressor ; 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 . packager . impl . MultiVolumePackager ; import com . izforge . izpack . compiler . stream . JarOutputStream ; import com . izforge . izpack . core . data . DefaultVariables ; import com . izforge . izpack . core . io . VolumeLocator ; import com . izforge . izpack . core . resource . ResourceManager ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; import com . izforge . izpack . data . PackInfo ; import com . izforge . izpack . installer . data . InstallData ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . installer . event . InstallerListeners ; import com . izforge . izpack . installer . unpacker . ConsolePackResources ; import com . izforge . izpack . installer . unpacker . FileQueueFactory ; import com . izforge . izpack . installer . unpacker . PackResources ; import com . izforge . izpack . merge . MergeManager ; import com . izforge . izpack . merge . resolve . MergeableResolver ; import com . izforge . izpack . test . util . TestHelper ; import com . izforge . izpack . util . Housekeeper ; import com . izforge . izpack . util . Librarian ; import com . izforge . izpack . util . PlatformModelMatcher ; import com . izforge . izpack . util . Platforms ; public class MultiVolumeUnpackerTest { @ Rule public TemporaryFolder temporaryFolder = new TemporaryFolder ( ) ; @ Test public void testUnpack ( ) throws Exception { File baseDir = temporaryFolder . getRoot ( ) ; File packageDir = new File ( baseDir , "<STR_LIT>" ) ; File installerJar = new File ( packageDir , "<STR_LIT>" ) ; File installDir = new File ( baseDir , "<STR_LIT>" ) ; assertTrue ( packageDir . mkdir ( ) ) ; File file1 = createFile ( baseDir , "<STR_LIT>" , <NUM_LIT> ) ; File file2 = createFile ( baseDir , "<STR_LIT>" , <NUM_LIT> ) ; File file3 = createFile ( baseDir , "<STR_LIT>" , <NUM_LIT> ) ; PackInfo base = createPack ( "<STR_LIT>" , baseDir , file1 , file2 , file3 ) ; File file4 = createFile ( baseDir , "<STR_LIT>" , <NUM_LIT> ) ; File file5 = createFile ( baseDir , "<STR_LIT>" , <NUM_LIT> ) ; File file6 = createFile ( baseDir , "<STR_LIT>" , <NUM_LIT> ) ; PackInfo pack1 = createPack ( "<STR_LIT>" , baseDir , file4 , file5 , file6 ) ; File file7 = createFile ( baseDir , "<STR_LIT>" , <NUM_LIT> ) ; File file8 = createFile ( baseDir , "<STR_LIT>" , <NUM_LIT> ) ; File file9 = createFile ( baseDir , "<STR_LIT>" , <NUM_LIT> ) ; PackInfo pack2 = createPack ( "<STR_LIT>" , baseDir , file7 , file8 , file9 ) ; File file10 = createFile ( baseDir , "<STR_LIT>" , <NUM_LIT:100> ) ; PackInfo pack3 = createPack ( "<STR_LIT>" , baseDir , file10 ) ; pack3 . getPack ( ) . setLoose ( true ) ; MultiVolumePackager packager = createPackager ( baseDir , installerJar ) ; long firstVolumeSize = <NUM_LIT> ; long maxVolumeSize = <NUM_LIT> ; packager . setMaxFirstVolumeSize ( firstVolumeSize ) ; packager . setMaxVolumeSize ( maxVolumeSize ) ; packager . addPack ( base ) ; packager . addPack ( pack1 ) ; packager . addPack ( pack2 ) ; packager . addPack ( pack3 ) ; packager . createInstaller ( ) ; assertTrue ( installerJar . exists ( ) ) ; Resources resources = createResources ( installerJar ) ; checkVolumes ( packageDir , resources , firstVolumeSize , maxVolumeSize ) ; assertTrue ( new File ( packageDir , file10 . getName ( ) ) . exists ( ) ) ; AutomatedInstallData installData = createInstallData ( packageDir , installDir , resources ) ; setSelectedPacks ( installData , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; MultiVolumeUnpacker unpacker = createUnpacker ( resources , installData ) ; unpacker . unpack ( ) ; checkInstalled ( installDir , file1 ) ; checkInstalled ( installDir , file2 ) ; checkInstalled ( installDir , file3 ) ; checkInstalled ( installDir , file7 ) ; checkInstalled ( installDir , file8 ) ; checkInstalled ( installDir , file9 ) ; checkInstalled ( installDir , file10 ) ; assertFileNotExists ( installDir , file4 . getName ( ) ) ; assertFileNotExists ( installDir , file5 . getName ( ) ) ; assertFileNotExists ( installDir , file6 . getName ( ) ) ; } private void setSelectedPacks ( AutomatedInstallData installData , String ... names ) { for ( String name : names ) { for ( Pack pack : installData . getAvailablePacks ( ) ) { if ( pack . getName ( ) . equals ( name ) ) { installData . getSelectedPacks ( ) . add ( pack ) ; break ; } } } assertEquals ( names . length , installData . getSelectedPacks ( ) . size ( ) ) ; } private PackInfo createPack ( String name , File baseDir , File ... files ) throws IOException { PackInfo pack = new PackInfo ( name , name , "<STR_LIT>" + name + "<STR_LIT>" , false , false , null , true , <NUM_LIT:0> ) ; addFiles ( pack , baseDir , files ) ; return pack ; } private void checkVolumes ( File dir , Resources resources , long maxFirstVolumeSize , long maxVolumeSize ) throws IOException { ObjectInputStream info = new ObjectInputStream ( resources . getInputStream ( MultiVolumeUnpacker . VOLUMES_INFO ) ) ; int count = info . readInt ( ) ; String name = info . readUTF ( ) ; info . close ( ) ; assertTrue ( count >= <NUM_LIT:1> ) ; File volume = new File ( dir , name ) ; assertTrue ( volume . exists ( ) ) ; assertEquals ( maxFirstVolumeSize , volume . length ( ) ) ; for ( int i = <NUM_LIT:1> ; i < count ; ++ i ) { volume = new File ( dir , name + "<STR_LIT:.>" + i ) ; assertTrue ( volume . exists ( ) ) ; if ( i < count - <NUM_LIT:1> ) { assertEquals ( maxVolumeSize , volume . length ( ) ) ; } } } private MultiVolumeUnpacker createUnpacker ( Resources resources , AutomatedInstallData installData ) { VariableSubstitutor replacer = new VariableSubstitutorImpl ( installData . getVariables ( ) ) ; Housekeeper housekeeper = Mockito . mock ( Housekeeper . class ) ; RulesEngine rules = Mockito . mock ( RulesEngine . class ) ; UninstallData uninstallData = new UninstallData ( ) ; Librarian librarian = Mockito . mock ( Librarian . class ) ; VolumeLocator locator = Mockito . mock ( VolumeLocator . class ) ; PackResources packResources = new ConsolePackResources ( resources , installData ) ; FileQueueFactory queue = new FileQueueFactory ( Platforms . WINDOWS , librarian ) ; Prompt prompt = Mockito . mock ( Prompt . class ) ; InstallerListeners listeners = new InstallerListeners ( installData , prompt ) ; PlatformModelMatcher matcher = new PlatformModelMatcher ( new Platforms ( ) , Platforms . WINDOWS ) ; MultiVolumeUnpacker unpacker = new MultiVolumeUnpacker ( installData , packResources , rules , replacer , uninstallData , queue , housekeeper , listeners , prompt , locator , matcher ) ; unpacker . setProgressListener ( Mockito . mock ( ProgressListener . class ) ) ; return unpacker ; } private AutomatedInstallData createInstallData ( File mediaDir , File installDir , Resources resources ) throws IOException , ClassNotFoundException { AutomatedInstallData installData = new InstallData ( new DefaultVariables ( ) , Platforms . LINUX ) ; installData . setInstallPath ( installDir . getPath ( ) ) ; installData . setMediaPath ( mediaDir . getPath ( ) ) ; installData . setInfo ( new Info ( ) ) ; List < Pack > packs = getPacks ( resources ) ; installData . setAvailablePacks ( packs ) ; return installData ; } private Resources createResources ( File installerJar ) throws IOException { final URLClassLoader loader = new URLClassLoader ( new URL [ ] { installerJar . toURI ( ) . toURL ( ) } , getClass ( ) . getClassLoader ( ) ) ; return new ResourceManager ( loader ) ; } private MultiVolumePackager createPackager ( File baseDir , File installerJar ) throws IOException { Properties properties = new Properties ( ) ; PackagerListener packagerListener = Mockito . mock ( PackagerListener . class ) ; JarOutputStream jar = new JarOutputStream ( installerJar ) ; MergeManager mergeManager = Mockito . mock ( MergeManager . class ) ; CompilerPathResolver resolver = Mockito . mock ( CompilerPathResolver . class ) ; MergeableResolver mergeableResolver = Mockito . mock ( MergeableResolver . class ) ; PackCompressor compressor = new DefaultPackCompressor ( ) ; CompilerData data = new CompilerData ( null , baseDir . getPath ( ) , installerJar . getPath ( ) , true ) ; MultiVolumePackager packager = new MultiVolumePackager ( properties , packagerListener , jar , mergeManager , resolver , mergeableResolver , compressor , data ) ; packager . setInfo ( new Info ( ) ) ; return packager ; } private void addFiles ( PackInfo pack , File baseDir , File ... files ) throws IOException { for ( File file : files ) { pack . addFile ( baseDir , file , "<STR_LIT>" + file . getName ( ) , null , OverrideType . OVERRIDE_FALSE , null , Blockable . BLOCKABLE_NONE , null , null ) ; } } private List < Pack > getPacks ( Resources resources ) throws IOException , ClassNotFoundException { InputStream in = resources . getInputStream ( "<STR_LIT>" ) ; ObjectInputStream objIn = new ObjectInputStream ( in ) ; int size = objIn . readInt ( ) ; List < Pack > packs = new ArrayList < Pack > ( ) ; for ( int i = <NUM_LIT:0> ; i < size ; i ++ ) { Pack pack = ( Pack ) objIn . readObject ( ) ; packs . add ( pack ) ; } objIn . close ( ) ; return packs ; } private File createFile ( File baseDir , String name , int size ) throws IOException { return TestHelper . createFile ( new File ( baseDir , name ) , size ) ; } private void checkInstalled ( File installDir , File expected ) throws IOException { File file = new File ( installDir , expected . getName ( ) ) ; assertFileEquals ( expected , file ) ; } } </s>
|
<s> package com . izforge . izpack . uninstaller . resource ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertTrue ; import static org . mockito . Mockito . when ; import java . io . ByteArrayInputStream ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . ObjectOutputStream ; import java . util . ArrayList ; import java . util . List ; import org . junit . Before ; import org . junit . Test ; import org . mockito . Mockito ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . util . Platform ; import com . izforge . izpack . util . Platforms ; public class RootScriptsTest { private Resources resources ; @ Before public void setUp ( ) throws IOException { InputStream script1 = createRootScript ( "<STR_LIT>" ) ; InputStream script2 = createRootScript ( "<STR_LIT>" ) ; InputStream script3 = createRootScript ( "<STR_LIT>" ) ; resources = Mockito . mock ( Resources . class ) ; when ( resources . getInputStream ( UninstallData . ROOTSCRIPT + "<STR_LIT:0>" ) ) . thenReturn ( script1 ) ; when ( resources . getInputStream ( UninstallData . ROOTSCRIPT + "<STR_LIT:1>" ) ) . thenReturn ( script2 ) ; when ( resources . getInputStream ( UninstallData . ROOTSCRIPT + "<STR_LIT:2>" ) ) . thenReturn ( script3 ) ; when ( resources . getInputStream ( UninstallData . ROOTSCRIPT + "<STR_LIT:3>" ) ) . thenThrow ( new ResourceNotFoundException ( "<STR_LIT>" ) ) ; } @ Test public void testRootScriptsOnUnix ( ) { final List < String > run = new ArrayList < String > ( ) ; RootScripts scripts = new TestRootScripts ( resources , Platforms . UNIX , run ) ; scripts . run ( ) ; assertEquals ( <NUM_LIT:3> , run . size ( ) ) ; assertEquals ( "<STR_LIT>" , run . get ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , run . get ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , run . get ( <NUM_LIT:2> ) ) ; } @ Test public void testRootScriptsOnNonUnix ( ) { final List < String > run = new ArrayList < String > ( ) ; RootScripts scripts = new TestRootScripts ( resources , Platforms . WINDOWS , run ) ; scripts . run ( ) ; assertTrue ( run . isEmpty ( ) ) ; } private InputStream createRootScript ( String script ) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; ObjectOutputStream objOut = new ObjectOutputStream ( out ) ; objOut . writeUTF ( script ) ; objOut . close ( ) ; return new ByteArrayInputStream ( out . toByteArray ( ) ) ; } private static class TestRootScripts extends RootScripts { private final List < String > scripts ; public TestRootScripts ( Resources resources , Platform platform , List < String > scripts ) { super ( resources , platform ) ; this . scripts = scripts ; } @ Override protected void run ( String script ) { scripts . add ( script ) ; } } } </s>
|
<s> package com . izforge . izpack . uninstaller . resource ; import static org . junit . Assert . assertEquals ; import static org . mockito . Mockito . when ; import java . io . File ; import java . io . IOException ; import java . io . StringReader ; import java . util . List ; import org . apache . commons . io . input . ReaderInputStream ; import org . junit . Before ; import org . junit . Test ; import org . mockito . Mockito ; import com . izforge . izpack . api . resource . Resources ; public class InstallLogTest { private Resources resources ; @ Before public void setUp ( ) throws IOException { String installLog = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; StringReader reader = new StringReader ( installLog ) ; resources = Mockito . mock ( Resources . class ) ; when ( resources . getInputStream ( "<STR_LIT>" ) ) . thenReturn ( new ReaderInputStream ( reader ) ) ; } @ Test public void testStaticGetInstallPath ( ) throws IOException { assertEquals ( "<STR_LIT>" , InstallLog . getInstallPath ( resources ) ) ; } @ Test public void testInstalled ( ) throws IOException { InstallLog log = new InstallLog ( resources ) ; assertEquals ( "<STR_LIT>" , log . getInstallPath ( ) ) ; List < File > installed = log . getInstalled ( ) ; assertEquals ( <NUM_LIT:4> , installed . size ( ) ) ; assertEquals ( new File ( "<STR_LIT>" ) , installed . get ( <NUM_LIT:0> ) ) ; assertEquals ( new File ( "<STR_LIT>" ) , installed . get ( <NUM_LIT:1> ) ) ; assertEquals ( new File ( "<STR_LIT>" ) , installed . get ( <NUM_LIT:2> ) ) ; assertEquals ( new File ( "<STR_LIT>" ) , installed . get ( <NUM_LIT:3> ) ) ; } } </s>
|
<s> package com . izforge . izpack . uninstaller . resource ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertTrue ; import static org . mockito . Mockito . when ; import java . io . ByteArrayInputStream ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . ObjectOutputStream ; import java . util . ArrayList ; import java . util . List ; import org . junit . Before ; import org . junit . Test ; import org . mockito . Mockito ; import com . izforge . izpack . api . handler . Prompt ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . data . ExecutableFile ; import com . izforge . izpack . util . PlatformModelMatcher ; import com . izforge . izpack . util . Platforms ; public class ExecutablesTest { private Resources resources ; @ Before public void setUp ( ) throws IOException { ExecutableFile file1 = new ExecutableFile ( "<STR_LIT>" , ExecutableFile . UNINSTALL , ExecutableFile . ABORT , null , false ) ; ExecutableFile file2 = new ExecutableFile ( "<STR_LIT>" , ExecutableFile . POSTINSTALL , ExecutableFile . ABORT , null , false ) ; ExecutableFile file3 = new ExecutableFile ( "<STR_LIT>" , ExecutableFile . NEVER , ExecutableFile . ABORT , null , false ) ; ExecutableFile file4 = new ExecutableFile ( "<STR_LIT>" , ExecutableFile . UNINSTALL , ExecutableFile . ABORT , null , false ) ; InputStream executables = createExecutables ( file1 , file2 , file3 , file4 ) ; resources = Mockito . mock ( Resources . class ) ; when ( resources . getInputStream ( "<STR_LIT>" ) ) . thenReturn ( executables ) ; } @ Test public void testExecutables ( ) { final List < String > paths = new ArrayList < String > ( ) ; PlatformModelMatcher matcher = new PlatformModelMatcher ( new Platforms ( ) , Platforms . WINDOWS ) ; Executables executables = new Executables ( resources , matcher , Mockito . mock ( Prompt . class ) ) { @ Override protected boolean run ( ExecutableFile file ) { paths . add ( file . path ) ; return true ; } } ; assertTrue ( executables . run ( ) ) ; assertEquals ( <NUM_LIT:2> , paths . size ( ) ) ; assertEquals ( "<STR_LIT>" , paths . get ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , paths . get ( <NUM_LIT:1> ) ) ; } private InputStream createExecutables ( ExecutableFile ... files ) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; ObjectOutputStream objOut = new ObjectOutputStream ( out ) ; objOut . writeInt ( files . length ) ; for ( ExecutableFile file : files ) { objOut . writeObject ( file ) ; } objOut . close ( ) ; return new ByteArrayInputStream ( out . toByteArray ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . uninstaller . event ; import java . io . File ; import java . util . ArrayList ; import java . util . List ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . event . UninstallerListener ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . handler . Prompt ; import com . izforge . izpack . core . handler . ProgressHandler ; import com . izforge . izpack . event . SimpleUninstallerListener ; public class UninstallerListeners { private final List < UninstallerListener > listeners = new ArrayList < UninstallerListener > ( ) ; private final Prompt prompt ; private boolean fileListener ; public UninstallerListeners ( Prompt prompt ) { this . prompt = prompt ; } public void add ( UninstallerListener listener ) { listeners . add ( listener ) ; if ( ! fileListener && listener . isFileListener ( ) ) { fileListener = true ; } } public void initialise ( ) { for ( UninstallerListener listener : listeners ) { listener . initialise ( ) ; } } public void beforeDeletion ( List < File > files , ProgressListener listener ) { ProgressHandler handler = new ProgressHandler ( listener , prompt ) ; for ( UninstallerListener l : listeners ) { try { if ( listener instanceof SimpleUninstallerListener ) { ( ( SimpleUninstallerListener ) listener ) . setHandler ( handler ) ; } l . beforeDelete ( files ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } } public void beforeDelete ( File file , ProgressListener listener ) { ProgressHandler handler = new ProgressHandler ( listener , prompt ) ; if ( fileListener ) { for ( UninstallerListener l : listeners ) { if ( l . isFileListener ( ) ) { if ( listener instanceof SimpleUninstallerListener ) { ( ( SimpleUninstallerListener ) listener ) . setHandler ( handler ) ; } l . beforeDelete ( file ) ; } } } } public void afterDelete ( File file , ProgressListener listener ) { ProgressHandler handler = new ProgressHandler ( listener , prompt ) ; if ( fileListener ) { for ( UninstallerListener l : listeners ) { if ( l . isFileListener ( ) ) { if ( listener instanceof SimpleUninstallerListener ) { ( ( SimpleUninstallerListener ) listener ) . setHandler ( handler ) ; } l . afterDelete ( file ) ; } } } } public void afterDeletion ( List < File > files , ProgressListener listener ) { ProgressHandler handler = new ProgressHandler ( listener , prompt ) ; for ( UninstallerListener l : listeners ) { try { if ( listener instanceof SimpleUninstallerListener ) { ( ( SimpleUninstallerListener ) listener ) . setHandler ( handler ) ; } l . afterDelete ( files , listener ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Throwable exception ) { throw new IzPackException ( exception ) ; } } } } </s>
|
<s> package com . izforge . izpack . uninstaller . event ; import com . izforge . izpack . api . event . ProgressListener ; public abstract class DestroyerListener implements ProgressListener { @ Override public void nextStep ( String stepName , int stepNo , int noOfSubSteps ) { } @ Override public void setSubStepNo ( int subSteps ) { } @ Override public void progress ( String message ) { } @ Override public void restartAction ( String name , String overallMessage , String tip , int steps ) { } } </s>
|
<s> package com . izforge . izpack . uninstaller . container ; import java . util . Properties ; import org . picocontainer . MutablePicoContainer ; import org . picocontainer . PicoException ; import org . picocontainer . injectors . ProviderAdapter ; import com . izforge . izpack . api . container . Container ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . api . factory . ObjectFactory ; import com . izforge . izpack . api . resource . Resources ; 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 . os . RegistryDefaultHandler ; import com . izforge . izpack . core . resource . DefaultLocales ; import com . izforge . izpack . core . resource . DefaultResources ; import com . izforge . izpack . core . resource . ResourceManager ; import com . izforge . izpack . uninstaller . Destroyer ; import com . izforge . izpack . uninstaller . resource . Executables ; import com . izforge . izpack . uninstaller . resource . InstallLog ; import com . izforge . izpack . uninstaller . resource . RootScripts ; import com . izforge . izpack . util . DefaultTargetPlatformFactory ; import com . izforge . izpack . util . Housekeeper ; import com . izforge . izpack . util . Librarian ; import com . izforge . izpack . util . PlatformModelMatcher ; import com . izforge . izpack . util . Platforms ; import com . izforge . izpack . util . TargetFactory ; public abstract class UninstallerContainer extends AbstractContainer { @ Override protected void fillContainer ( MutablePicoContainer container ) { addComponent ( Resources . class , DefaultResources . class ) ; addComponent ( Housekeeper . class ) ; addComponent ( Librarian . class ) ; addComponent ( TargetFactory . class ) ; addComponent ( DefaultObjectFactory . class ) ; addComponent ( DefaultTargetPlatformFactory . class ) ; addComponent ( RegistryDefaultHandler . class ) ; addComponent ( Container . class , this ) ; addComponent ( Properties . class ) ; addComponent ( ResourceManager . class ) ; addComponent ( DefaultLocales . class ) ; addComponent ( Platforms . class ) ; addComponent ( ObjectFactory . class , DefaultObjectFactory . class ) ; addComponent ( InstallLog . class ) ; addComponent ( Executables . class ) ; addComponent ( RootScripts . class ) ; addComponent ( PlatformModelMatcher . class ) ; addComponent ( Destroyer . class ) ; container . addAdapter ( new ProviderAdapter ( new PlatformProvider ( ) ) ) ; container . addAdapter ( new ProviderAdapter ( new UninstallerListenersProvider ( ) ) ) ; container . addAdapter ( new ProviderAdapter ( new MessagesProvider ( ) ) ) ; } } </s>
|
<s> package com . izforge . izpack . uninstaller . container ; import java . io . IOException ; import java . util . List ; import org . picocontainer . injectors . Provider ; import com . izforge . izpack . api . event . UninstallerListener ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . factory . ObjectFactory ; import com . izforge . izpack . api . handler . Prompt ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . uninstaller . event . UninstallerListeners ; public class UninstallerListenersProvider implements Provider { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public UninstallerListeners provide ( Resources resources , ObjectFactory factory , Prompt prompt ) throws IOException , ClassNotFoundException { UninstallerListeners listeners = new UninstallerListeners ( prompt ) ; List < String > classNames = ( List < String > ) resources . getObject ( "<STR_LIT>" ) ; for ( String className : classNames ) { UninstallerListener listener = factory . create ( className , UninstallerListener . class ) ; listeners . add ( listener ) ; } listeners . initialise ( ) ; return listeners ; } } </s>
|
<s> package com . izforge . izpack . uninstaller . container ; import java . io . IOException ; import org . picocontainer . injectors . Provider ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . resource . Locales ; import com . izforge . izpack . api . resource . Messages ; public class MessagesProvider implements Provider { public Messages provide ( Locales locales ) throws IOException { return locales . getMessages ( "<STR_LIT>" ) ; } } </s>
|
<s> package com . izforge . izpack . uninstaller . resource ; import java . io . BufferedReader ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . TreeSet ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . util . file . FileUtils ; public class InstallLog { private static final String INSTALL_LOG = "<STR_LIT>" ; private final String installPath ; private final List < File > files ; public InstallLog ( Resources resources ) { InputStream in = null ; InputStreamReader inReader = null ; try { in = resources . getInputStream ( INSTALL_LOG ) ; inReader = new InputStreamReader ( in ) ; BufferedReader reader = new BufferedReader ( inReader ) ; installPath = getInstallPath ( reader ) ; files = getFiles ( reader ) ; } catch ( IOException exception ) { throw new IzPackException ( exception ) ; } finally { FileUtils . close ( inReader ) ; FileUtils . close ( in ) ; } } public String getInstallPath ( ) { return installPath ; } public List < File > getInstalled ( ) { return files ; } public static String getInstallPath ( Resources resources ) { String installPath = null ; BufferedReader reader = null ; InputStream in = null ; try { in = resources . getInputStream ( INSTALL_LOG ) ; reader = new BufferedReader ( new InputStreamReader ( in ) ) ; installPath = getInstallPath ( reader ) ; } catch ( IOException exception ) { throw new IzPackException ( exception ) ; } finally { FileUtils . close ( reader ) ; FileUtils . close ( in ) ; } return installPath ; } private static String getInstallPath ( BufferedReader reader ) throws IOException { String path = reader . readLine ( ) ; if ( path == null || path . trim ( ) . isEmpty ( ) ) { throw new IOException ( "<STR_LIT>" ) ; } return path ; } private List < File > getFiles ( BufferedReader reader ) throws IOException { TreeSet < File > files = new TreeSet < File > ( Collections . reverseOrder ( ) ) ; String read = reader . readLine ( ) ; while ( read != null ) { files . add ( new File ( read ) ) ; read = reader . readLine ( ) ; } return new ArrayList < File > ( files ) ; } } </s>
|
<s> package com . izforge . izpack . uninstaller . resource ; 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 java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . util . Platform ; import com . izforge . izpack . util . file . FileUtils ; import com . izforge . izpack . util . unix . ShellScript ; public class RootScripts { private final List < String > scripts ; private static final Logger logger = Logger . getLogger ( RootScripts . class . getName ( ) ) ; public RootScripts ( Resources resources , Platform platform ) { if ( platform . isA ( Platform . Name . UNIX ) ) { scripts = getRootScripts ( resources ) ; } else { scripts = null ; } } public void run ( ) { if ( scripts != null ) { for ( String script : scripts ) { run ( script ) ; } } } private List < String > getRootScripts ( Resources resources ) { List < String > result = new ArrayList < String > ( ) ; for ( int index = <NUM_LIT:0> ; ; ++ index ) { try { String name = UninstallData . ROOTSCRIPT + Integer . toString ( index ) ; ObjectInputStream in = null ; try { InputStream inputStream = resources . getInputStream ( name ) ; in = new ObjectInputStream ( inputStream ) ; result . add ( in . readUTF ( ) ) ; } catch ( IOException exception ) { throw new IzPackException ( "<STR_LIT>" + name , exception ) ; } finally { FileUtils . close ( in ) ; } } catch ( ResourceNotFoundException ignore ) { break ; } } return result ; } protected void run ( String script ) { try { boolean enabled = logger . isLoggable ( Level . FINE ) ; if ( enabled ) { logger . fine ( "<STR_LIT>" + script ) ; } File file = File . createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) ; String result = ShellScript . execAndDelete ( new StringBuffer ( script ) , file . getPath ( ) ) ; if ( enabled ) { logger . fine ( "<STR_LIT>" + result ) ; } } catch ( Exception exception ) { logger . log ( Level . WARNING , "<STR_LIT>" + exception . getMessage ( ) , exception ) ; } } } </s>
|
<s> package com . izforge . izpack . uninstaller . resource ; import java . io . ObjectInputStream ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . logging . Logger ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . handler . Prompt ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . core . handler . PromptUIHandler ; import com . izforge . izpack . data . ExecutableFile ; import com . izforge . izpack . util . FileExecutor ; import com . izforge . izpack . util . PlatformModelMatcher ; public class Executables { private final List < ExecutableFile > executables ; private final PlatformModelMatcher matcher ; private final Prompt prompt ; private static final Logger logger = Logger . getLogger ( Executables . class . getName ( ) ) ; public Executables ( Resources resources , PlatformModelMatcher matcher , Prompt prompt ) { this . prompt = prompt ; this . matcher = matcher ; executables = read ( resources ) ; } public boolean run ( ) { for ( ExecutableFile file : executables ) { if ( file . executionStage == ExecutableFile . UNINSTALL && matcher . matchesCurrentPlatform ( file . osList ) ) { if ( ! run ( file ) ) { return false ; } } } return true ; } protected boolean run ( ExecutableFile file ) { FileExecutor executor = new FileExecutor ( Arrays . asList ( file ) ) ; int status = executor . executeFiles ( ExecutableFile . UNINSTALL , matcher , new PromptUIHandler ( prompt ) ) ; if ( status != <NUM_LIT:0> ) { logger . severe ( "<STR_LIT>" + file . path + "<STR_LIT>" + status ) ; return false ; } return true ; } private List < ExecutableFile > read ( Resources resources ) { List < ExecutableFile > executables = new ArrayList < ExecutableFile > ( ) ; try { ObjectInputStream in = new ObjectInputStream ( resources . getInputStream ( "<STR_LIT>" ) ) ; int count = in . readInt ( ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { ExecutableFile file = ( ExecutableFile ) in . readObject ( ) ; executables . add ( file ) ; } } catch ( Exception exception ) { throw new IzPackException ( "<STR_LIT>" , exception ) ; } return executables ; } } </s>
|
<s> package com . izforge . izpack . uninstaller . console ; import java . io . File ; import com . izforge . izpack . uninstaller . Destroyer ; import com . izforge . izpack . uninstaller . event . DestroyerListener ; import com . izforge . izpack . util . Console ; public class ConsoleUninstaller { private final Destroyer destroyer ; private final Console console ; public ConsoleUninstaller ( Destroyer destroyer , DestroyerListener listener , Console console ) { this . destroyer = destroyer ; this . console = console ; destroyer . setProgressListener ( listener ) ; } public void uninstall ( boolean force ) { console . println ( "<STR_LIT>" + force ) ; destroyer . setForceDelete ( force ) ; destroyer . run ( ) ; if ( ! destroyer . getFailedToDelete ( ) . isEmpty ( ) ) { console . println ( "<STR_LIT>" ) ; for ( File file : destroyer . getFailedToDelete ( ) ) { console . println ( file . getPath ( ) ) ; } } } } </s>
|
<s> package com . izforge . izpack . uninstaller . console ; import com . izforge . izpack . api . resource . Messages ; import com . izforge . izpack . uninstaller . event . DestroyerListener ; import com . izforge . izpack . util . Console ; public class ConsoleDestroyerListener extends DestroyerListener { private final Console console ; private final Messages messages ; public ConsoleDestroyerListener ( Console console , Messages messages ) { this . console = console ; this . messages = messages ; } public void startAction ( final String name , final int max ) { console . println ( "<STR_LIT>" + name ) ; } public void stopAction ( ) { console . println ( messages . get ( "<STR_LIT>" ) ) ; } public void progress ( final int subStepNo , final String message ) { console . println ( message ) ; } } </s>
|
<s> package com . izforge . izpack . uninstaller . console ; import org . picocontainer . MutablePicoContainer ; import org . picocontainer . PicoException ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . core . handler . ConsolePrompt ; import com . izforge . izpack . uninstaller . container . UninstallerContainer ; import com . izforge . izpack . util . Console ; public class ConsoleUninstallerContainer extends UninstallerContainer { public ConsoleUninstallerContainer ( ) { initialise ( ) ; } @ Override protected void fillContainer ( MutablePicoContainer container ) { super . fillContainer ( container ) ; addComponent ( Console . class ) ; addComponent ( ConsolePrompt . class ) ; addComponent ( ConsoleDestroyerListener . class ) ; addComponent ( ConsoleUninstaller . class ) ; } } </s>
|
<s> package com . izforge . izpack . uninstaller ; import java . io . IOException ; import java . lang . reflect . Method ; import java . util . logging . Level ; import java . util . logging . Logger ; import javax . swing . JOptionPane ; import javax . swing . SwingUtilities ; import javax . swing . UIManager ; import com . izforge . izpack . core . resource . DefaultResources ; import com . izforge . izpack . uninstaller . console . ConsoleUninstaller ; import com . izforge . izpack . uninstaller . console . ConsoleUninstallerContainer ; import com . izforge . izpack . uninstaller . container . UninstallerContainer ; import com . izforge . izpack . uninstaller . gui . GUIUninstallerContainer ; import com . izforge . izpack . uninstaller . gui . UninstallerFrame ; import com . izforge . izpack . uninstaller . resource . InstallLog ; import com . izforge . izpack . util . Housekeeper ; import com . izforge . izpack . util . Platform ; import com . izforge . izpack . util . Platforms ; import com . izforge . izpack . util . PrivilegedRunner ; import com . izforge . izpack . util . SelfModifier ; public class Uninstaller { private static final String EXEC_ADMIN = "<STR_LIT>" ; private static final Logger logger = Logger . getLogger ( Uninstaller . class . getName ( ) ) ; public static void main ( String [ ] args ) { Platform platform = new Platforms ( ) . getCurrentPlatform ( ) ; try { if ( ! PrivilegedRunner . isPrivilegedMode ( ) && isElevationRequired ( platform ) ) { if ( relaunchWithElevatedRights ( platform ) ) { System . exit ( <NUM_LIT:0> ) ; } } } catch ( IOException exception ) { logger . log ( Level . SEVERE , exception . getMessage ( ) , exception ) ; System . exit ( <NUM_LIT:1> ) ; } boolean console = false ; for ( String arg : args ) { if ( arg . equals ( "<STR_LIT>" ) ) { console = true ; } } if ( console ) { System . out . println ( "<STR_LIT>" ) ; } try { Class < Uninstaller > clazz = Uninstaller . class ; Method target ; if ( console ) { target = clazz . getMethod ( "<STR_LIT>" , new Class [ ] { String [ ] . class } ) ; } else { target = clazz . getMethod ( "<STR_LIT>" , new Class [ ] { String [ ] . class } ) ; } new SelfModifier ( target ) . invoke ( args ) ; } catch ( Exception ioeOrTypo ) { System . err . println ( ioeOrTypo . getMessage ( ) ) ; ioeOrTypo . printStackTrace ( ) ; System . err . println ( "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" ) ; uninstall ( args ) ; } } public static void consoleUninstall ( String [ ] args ) { UninstallerContainer container = new ConsoleUninstallerContainer ( ) ; try { ConsoleUninstaller uninstaller = container . getComponent ( ConsoleUninstaller . class ) ; boolean force = false ; for ( String arg : args ) { if ( arg . equals ( "<STR_LIT>" ) ) { force = true ; } } uninstaller . uninstall ( force ) ; } catch ( Exception err ) { shutdown ( container , err ) ; } } public static void uninstall ( final String [ ] args ) { SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { UninstallerContainer container = new GUIUninstallerContainer ( ) ; try { boolean displayForceOption = true ; boolean forceOptionState = false ; for ( String arg : args ) { if ( arg . equals ( "<STR_LIT>" ) ) { forceOptionState = true ; } else if ( arg . equals ( "<STR_LIT>" ) ) { displayForceOption = false ; } } UIManager . setLookAndFeel ( UIManager . getSystemLookAndFeelClassName ( ) ) ; UninstallerFrame uninstaller = container . getComponent ( UninstallerFrame . class ) ; uninstaller . init ( displayForceOption , forceOptionState ) ; } catch ( Exception err ) { shutdown ( container , err ) ; } } } ) ; } private static void shutdown ( UninstallerContainer container , Exception error ) { logger . log ( Level . SEVERE , error . getMessage ( ) , error ) ; container . getComponent ( Housekeeper . class ) . shutDown ( <NUM_LIT:1> ) ; } private static boolean relaunchWithElevatedRights ( Platform platform ) { boolean result = false ; PrivilegedRunner runner = new PrivilegedRunner ( platform ) ; if ( runner . isPlatformSupported ( ) ) { try { if ( runner . relaunchWithElevatedRights ( ) == <NUM_LIT:0> ) { result = true ; } } catch ( Exception exception ) { exception . printStackTrace ( ) ; } if ( ! result ) { JOptionPane . showMessageDialog ( null , "<STR_LIT>" + "<STR_LIT>" ) ; } } else { JOptionPane . showMessageDialog ( null , "<STR_LIT>" + "<STR_LIT>" ) ; } return result ; } private static boolean isElevationRequired ( Platform platform ) throws IOException { boolean result = false ; if ( Uninstaller . class . getResource ( EXEC_ADMIN ) != null ) { String path = InstallLog . getInstallPath ( new DefaultResources ( ) ) ; PrivilegedRunner runner = new PrivilegedRunner ( platform ) ; result = runner . isElevationNeeded ( path ) ; } return result ; } } </s>
|
<s> package com . izforge . izpack . uninstaller ; import static com . izforge . izpack . api . handler . Prompt . Type . ERROR ; import java . io . File ; import java . io . PrintWriter ; import java . io . StringWriter ; import java . util . ArrayList ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . handler . Prompt ; import com . izforge . izpack . uninstaller . event . UninstallerListeners ; import com . izforge . izpack . uninstaller . resource . Executables ; import com . izforge . izpack . uninstaller . resource . InstallLog ; import com . izforge . izpack . uninstaller . resource . RootScripts ; public class Destroyer implements Runnable { private final InstallLog log ; private final UninstallerListeners listeners ; private final Executables executables ; private final RootScripts rootScripts ; private Prompt prompt ; private ProgressListener listener ; private boolean forceDelete ; private List < File > failed = new ArrayList < File > ( ) ; private static final Logger logger = Logger . getLogger ( Destroyer . class . getName ( ) ) ; public Destroyer ( InstallLog log , UninstallerListeners listeners , Executables executables , RootScripts rootScripts , Prompt prompt ) { this . log = log ; this . listeners = listeners ; this . executables = executables ; this . rootScripts = rootScripts ; this . prompt = prompt ; } public void setPrompt ( Prompt prompt ) { this . prompt = prompt ; } public void setProgressListener ( ProgressListener listener ) { this . listener = listener ; } public void setForceDelete ( boolean force ) { this . forceDelete = force ; } @ Override public void run ( ) { try { if ( ! executables . run ( ) ) { logger . severe ( "<STR_LIT>" ) ; } else { destroy ( ) ; } } catch ( Throwable exception ) { if ( listener != null ) { listener . stopAction ( ) ; } logger . log ( Level . SEVERE , exception . getMessage ( ) , exception ) ; StringWriter trace = new StringWriter ( ) ; exception . printStackTrace ( new PrintWriter ( trace ) ) ; prompt . message ( ERROR , "<STR_LIT>" , trace . toString ( ) ) ; } } public List < File > getFailedToDelete ( ) { return failed ; } private void destroy ( ) throws Exception { List < File > files = log . getInstalled ( ) ; int size = files . size ( ) ; listeners . beforeDeletion ( files , listener ) ; if ( listener != null ) { listener . startAction ( "<STR_LIT>" , size ) ; } for ( int i = <NUM_LIT:0> ; i < size ; i ++ ) { File file = files . get ( i ) ; listeners . beforeDelete ( file , listener ) ; delete ( file ) ; listeners . afterDelete ( file , listener ) ; if ( listener != null ) { listener . progress ( i , file . getAbsolutePath ( ) ) ; } } listeners . afterDeletion ( files , listener ) ; rootScripts . run ( ) ; if ( listener != null ) { listener . progress ( log . getInstalled ( ) . size ( ) , "<STR_LIT>" ) ; } File installPath = new File ( log . getInstallPath ( ) ) ; cleanup ( installPath ) ; checkDeletion ( files , installPath ) ; if ( listener != null ) { listener . stopAction ( ) ; } } private void checkDeletion ( List < File > files , File installPath ) { failed . clear ( ) ; for ( File f : files ) { if ( f . exists ( ) ) { failed . add ( f ) ; } } if ( installPath . exists ( ) ) { failed . add ( installPath ) ; } } private void cleanup ( File file ) { if ( file . isDirectory ( ) ) { File [ ] files = file . listFiles ( ) ; if ( files != null ) { for ( File child : files ) { cleanup ( child ) ; } } delete ( file ) ; } else if ( forceDelete ) { delete ( file ) ; } } private void delete ( File file ) { if ( file . exists ( ) && ! file . delete ( ) ) { logger . info ( "<STR_LIT>" + file ) ; } } } </s>
|
<s> package com . izforge . izpack . uninstaller . gui ; import java . awt . BorderLayout ; import java . awt . Color ; import java . awt . Cursor ; import java . awt . Dimension ; import java . awt . GraphicsEnvironment ; import java . awt . GridBagConstraints ; import java . awt . GridBagLayout ; import java . awt . Insets ; import java . awt . Point ; import java . awt . Window ; import java . awt . event . ActionEvent ; import java . awt . event . ActionListener ; import java . awt . event . KeyAdapter ; import java . awt . event . MouseAdapter ; import java . awt . event . MouseMotionAdapter ; import java . awt . event . WindowAdapter ; import java . awt . event . WindowEvent ; import java . io . File ; import java . net . URL ; import java . util . List ; import javax . swing . ImageIcon ; import javax . swing . JButton ; import javax . swing . JCheckBox ; import javax . swing . JFrame ; import javax . swing . JLabel ; import javax . swing . JOptionPane ; import javax . swing . JPanel ; import javax . swing . JProgressBar ; import javax . swing . JScrollPane ; import javax . swing . JTextArea ; import javax . swing . UIManager ; import com . izforge . izpack . api . resource . Messages ; import com . izforge . izpack . gui . ButtonFactory ; import com . izforge . izpack . gui . GUIPrompt ; import com . izforge . izpack . gui . IconsDatabase ; import com . izforge . izpack . uninstaller . Destroyer ; import com . izforge . izpack . uninstaller . event . DestroyerListener ; import com . izforge . izpack . uninstaller . resource . InstallLog ; import com . izforge . izpack . util . Housekeeper ; public class UninstallerFrame extends JFrame { private final IconsDatabase icons ; private final Messages messages ; protected JCheckBox targetDestroyCheckbox ; private JProgressBar progressBar ; private JButton destroyButton ; private JButton quitButton ; private final Color buttonsHColor = new Color ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; private final InstallLog log ; private final Destroyer destroyer ; private final Housekeeper housekeeper ; public UninstallerFrame ( Destroyer destroyer , InstallLog log , Housekeeper housekeeper , Messages messages ) throws Exception { super ( "<STR_LIT>" ) ; this . destroyer = destroyer ; this . log = log ; this . housekeeper = housekeeper ; this . messages = messages ; icons = new IconsDatabase ( ) ; loadIcons ( ) ; UIManager . put ( "<STR_LIT>" , this . messages . get ( "<STR_LIT>" ) ) ; UIManager . put ( "<STR_LIT>" , this . messages . get ( "<STR_LIT>" ) ) ; UIManager . put ( "<STR_LIT>" , this . messages . get ( "<STR_LIT>" ) ) ; setIconImage ( icons . get ( "<STR_LIT>" ) . getImage ( ) ) ; destroyer . setProgressListener ( new DestroyerListener ( ) { @ Override public void startAction ( String name , int steps ) { started ( steps ) ; } @ Override public void progress ( int subStep , String message ) { UninstallerFrame . this . progress ( subStep , message ) ; } @ Override public void stopAction ( ) { finished ( ) ; } } ) ; } public void init ( boolean displayForceOption , boolean forceOptionState ) { buildGUI ( displayForceOption , forceOptionState ) ; addWindowListener ( new WindowHandler ( ) ) ; pack ( ) ; centerFrame ( this ) ; setResizable ( false ) ; setVisible ( true ) ; } private void buildGUI ( boolean displayForceOption , boolean forceOptionState ) { JPanel contentPane = ( JPanel ) getContentPane ( ) ; GridBagLayout layout = new GridBagLayout ( ) ; contentPane . setLayout ( layout ) ; GridBagConstraints gbConstraints = new GridBagConstraints ( ) ; gbConstraints . insets = new Insets ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) ; ActionsHandler handler = new ActionsHandler ( ) ; JPanel glassPane = ( JPanel ) getGlassPane ( ) ; glassPane . addMouseListener ( new MouseAdapter ( ) { } ) ; glassPane . addMouseMotionListener ( new MouseMotionAdapter ( ) { } ) ; glassPane . addKeyListener ( new KeyAdapter ( ) { } ) ; ButtonFactory . useButtonIcons ( ) ; ButtonFactory . useHighlightButtons ( ) ; JLabel warningLabel = new JLabel ( messages . get ( "<STR_LIT>" ) , icons . get ( "<STR_LIT>" ) , JLabel . TRAILING ) ; buildConstraints ( gbConstraints , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ; gbConstraints . anchor = GridBagConstraints . WEST ; gbConstraints . fill = GridBagConstraints . NONE ; layout . addLayoutComponent ( warningLabel , gbConstraints ) ; contentPane . add ( warningLabel ) ; targetDestroyCheckbox = new JCheckBox ( messages . get ( "<STR_LIT>" ) + log . getInstallPath ( ) , forceOptionState ) ; buildConstraints ( gbConstraints , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ; layout . addLayoutComponent ( targetDestroyCheckbox , gbConstraints ) ; if ( displayForceOption ) { contentPane . add ( targetDestroyCheckbox ) ; } gbConstraints . fill = GridBagConstraints . HORIZONTAL ; progressBar = new JProgressBar ( ) ; progressBar . setStringPainted ( true ) ; progressBar . setString ( messages . get ( "<STR_LIT>" ) ) ; buildConstraints ( gbConstraints , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ; layout . addLayoutComponent ( progressBar , gbConstraints ) ; contentPane . add ( progressBar ) ; destroyButton = ButtonFactory . createButton ( messages . get ( "<STR_LIT>" ) , icons . get ( "<STR_LIT>" ) , buttonsHColor ) ; destroyButton . addActionListener ( handler ) ; buildConstraints ( gbConstraints , <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:0.0> ) ; gbConstraints . fill = GridBagConstraints . NONE ; gbConstraints . anchor = GridBagConstraints . WEST ; layout . addLayoutComponent ( destroyButton , gbConstraints ) ; contentPane . add ( destroyButton ) ; quitButton = ButtonFactory . createButton ( messages . get ( "<STR_LIT>" ) , icons . get ( "<STR_LIT>" ) , buttonsHColor ) ; quitButton . addActionListener ( handler ) ; buildConstraints ( gbConstraints , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:0.0> ) ; gbConstraints . anchor = GridBagConstraints . EAST ; layout . addLayoutComponent ( quitButton , gbConstraints ) ; contentPane . add ( quitButton ) ; destroyer . setPrompt ( new GUIPrompt ( ) { @ Override public void message ( Type type , String message ) { super . message ( type , message ) ; if ( type == Type . ERROR ) { progressBar . setString ( message ) ; } } } ) ; } private void centerFrame ( Window frame ) { Point center = GraphicsEnvironment . getLocalGraphicsEnvironment ( ) . getCenterPoint ( ) ; Dimension frameSize = frame . getSize ( ) ; frame . setLocation ( center . x - frameSize . width / <NUM_LIT:2> , center . y - frameSize . height / <NUM_LIT:2> - <NUM_LIT:10> ) ; } private void buildConstraints ( GridBagConstraints gbc , int gx , int gy , int gw , int gh , double wx , double wy ) { gbc . gridx = gx ; gbc . gridy = gy ; gbc . gridwidth = gw ; gbc . gridheight = gh ; gbc . weightx = wx ; gbc . weighty = wy ; } private void loadIcons ( ) throws Exception { URL url ; ImageIcon img ; url = UninstallerFrame . class . getResource ( "<STR_LIT>" ) ; img = new ImageIcon ( url ) ; icons . put ( "<STR_LIT>" , img ) ; url = UninstallerFrame . class . getResource ( "<STR_LIT>" ) ; img = new ImageIcon ( url ) ; icons . put ( "<STR_LIT>" , img ) ; url = UninstallerFrame . class . getResource ( "<STR_LIT>" ) ; img = new ImageIcon ( url ) ; icons . put ( "<STR_LIT>" , img ) ; url = UninstallerFrame . class . getResource ( "<STR_LIT>" ) ; img = new ImageIcon ( url ) ; icons . put ( "<STR_LIT>" , img ) ; } private void blockGUI ( ) { setCursor ( Cursor . getPredefinedCursor ( Cursor . WAIT_CURSOR ) ) ; getGlassPane ( ) . setVisible ( true ) ; getGlassPane ( ) . setEnabled ( true ) ; } private void releaseGUI ( ) { getGlassPane ( ) . setEnabled ( false ) ; getGlassPane ( ) . setVisible ( false ) ; setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ; } private void started ( int count ) { progressBar . setMinimum ( <NUM_LIT:0> ) ; progressBar . setMaximum ( count ) ; blockGUI ( ) ; } private void progress ( int pos , String message ) { progressBar . setValue ( pos ) ; progressBar . setString ( message ) ; } private void finished ( ) { progressBar . setString ( messages . get ( "<STR_LIT>" ) ) ; targetDestroyCheckbox . setEnabled ( false ) ; destroyButton . setEnabled ( false ) ; releaseGUI ( ) ; List < File > failedToDelete = destroyer . getFailedToDelete ( ) ; if ( ! failedToDelete . isEmpty ( ) ) { StringBuilder buffer = new StringBuilder ( ) ; for ( File f : failedToDelete ) { buffer . append ( f . getPath ( ) ) ; buffer . append ( '<STR_LIT:\n>' ) ; } JTextArea textArea = new JTextArea ( ) ; textArea . setText ( buffer . toString ( ) ) ; textArea . setRows ( <NUM_LIT:10> ) ; textArea . setColumns ( <NUM_LIT> ) ; textArea . setEditable ( false ) ; JScrollPane pane = new JScrollPane ( textArea ) ; BorderLayout layout = new BorderLayout ( ) ; layout . setHgap ( <NUM_LIT:8> ) ; JPanel panel = new JPanel ( layout ) ; JLabel label = new JLabel ( "<STR_LIT>" ) ; panel . add ( label , BorderLayout . NORTH ) ; panel . add ( pane , BorderLayout . CENTER ) ; label = new JLabel ( "<STR_LIT>" ) ; panel . add ( label , BorderLayout . SOUTH ) ; JOptionPane . showMessageDialog ( null , panel , "<STR_LIT>" , JOptionPane . WARNING_MESSAGE ) ; } } private final class WindowHandler extends WindowAdapter { public void windowClosing ( WindowEvent e ) { housekeeper . shutDown ( <NUM_LIT:0> ) ; } } class ActionsHandler implements ActionListener { public void actionPerformed ( ActionEvent e ) { Object src = e . getSource ( ) ; if ( src == quitButton ) { housekeeper . shutDown ( <NUM_LIT:0> ) ; } else if ( src == destroyButton ) { destroyButton . setEnabled ( false ) ; destroyer . setForceDelete ( targetDestroyCheckbox . isSelected ( ) ) ; Thread thread = new Thread ( destroyer , "<STR_LIT>" ) ; thread . start ( ) ; } } } } </s>
|
<s> package com . izforge . izpack . uninstaller . gui ; import org . picocontainer . MutablePicoContainer ; import org . picocontainer . PicoException ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . gui . GUIPrompt ; import com . izforge . izpack . uninstaller . container . UninstallerContainer ; public class GUIUninstallerContainer extends UninstallerContainer { public GUIUninstallerContainer ( ) { initialise ( ) ; } @ Override protected void fillContainer ( MutablePicoContainer container ) { super . fillContainer ( container ) ; addComponent ( UninstallerFrame . class ) ; addComponent ( GUIPrompt . class ) ; } } </s>
|
<s> package com . izforge . izpack . event ; import java . io . File ; import java . util . List ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . event . UninstallerListener ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . handler . AbstractUIProgressHandler ; @ Deprecated public class SimpleUninstallerListener implements UninstallerListener { private AbstractUIProgressHandler handler ; public SimpleUninstallerListener ( ) { super ( ) ; } @ Override public void initialise ( ) { } public void setHandler ( AbstractUIProgressHandler handler ) { this . handler = handler ; } @ Override public void beforeDelete ( List < File > files ) { try { beforeDeletion ( files , handler ) ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void beforeDelete ( File file ) { try { beforeDelete ( file , handler ) ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void afterDelete ( File file ) { try { afterDelete ( file , handler ) ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void afterDelete ( List < File > files , ProgressListener listener ) { try { afterDeletion ( files , handler ) ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } public void beforeDeletion ( List files , AbstractUIProgressHandler handler ) throws Exception { } public void beforeDelete ( File file , AbstractUIProgressHandler handler ) throws Exception { } public void afterDelete ( File file , AbstractUIProgressHandler handler ) throws Exception { } public void afterDeletion ( List files , AbstractUIProgressHandler handler ) throws Exception { } public boolean isFileListener ( ) { return false ; } } </s>
|
<s> package com . izforge . izpack . event ; @ Deprecated public class NativeUninstallerListener extends SimpleUninstallerListener { public NativeUninstallerListener ( ) { super ( ) ; } } </s>
|
<s> package com . izforge . izpack . util ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertTrue ; import java . util . Arrays ; import java . util . List ; import org . junit . Test ; public class JVMHelperTest { @ Test public void testGetJVMArguments ( ) { JVMHelper helper = new JVMHelper ( ) { @ Override protected List < String > getInputArguments ( ) { return Arrays . asList ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } } ; List < String > args = helper . getJVMArguments ( ) ; assertEquals ( <NUM_LIT:5> , args . size ( ) ) ; assertTrue ( args . contains ( "<STR_LIT>" ) ) ; assertTrue ( args . contains ( "<STR_LIT>" ) ) ; assertTrue ( args . contains ( "<STR_LIT>" ) ) ; assertTrue ( args . contains ( "<STR_LIT>" ) ) ; assertTrue ( args . contains ( "<STR_LIT>" ) ) ; } @ Test public void testArgumentWithSpaces ( ) { JVMHelper helper = new JVMHelper ( ) { @ Override protected List < String > getInputArguments ( ) { return Arrays . asList ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } } ; List < String > args = helper . getJVMArguments ( ) ; assertEquals ( <NUM_LIT:2> , args . size ( ) ) ; assertTrue ( args . contains ( "<STR_LIT>" ) ) ; assertTrue ( args . contains ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . util ; import static com . izforge . izpack . util . Platform . Arch ; import static com . izforge . izpack . util . Platform . Name ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertNotNull ; import java . net . URL ; import org . junit . Test ; import com . izforge . izpack . api . exception . IzPackClassNotFoundException ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . factory . ObjectFactory ; public class DefaultTargetPlatformFactoryTest { @ Test public void testParser ( ) { Platforms platforms = new Platforms ( ) ; Platform platform = platforms . getCurrentPlatform ( ) ; DefaultTargetPlatformFactory factory = new DefaultTargetPlatformFactory ( NoDependencyInjectionFactory . INSTANCE , platform , platforms ) { @ Override protected Parser createParser ( Platforms platforms , URL url ) { return new Parser ( platforms , url ) { @ Override protected void warning ( String message ) { throw new IllegalStateException ( "<STR_LIT>" + message ) ; } } ; } } ; DefaultTargetPlatformFactory . Implementations implementations = factory . getImplementations ( A . class ) ; assertNotNull ( implementations ) ; assertEquals ( DefaultA . class . getName ( ) , implementations . getDefault ( ) ) ; assertEquals ( <NUM_LIT:8> , implementations . getPlatforms ( ) . size ( ) ) ; for ( Platform p : implementations . getPlatforms ( ) ) { System . err . println ( p + "<STR_LIT:=>" + implementations . getImplementation ( p ) ) ; } assertEquals ( WinA . class . getName ( ) , implementations . getImplementation ( Platforms . WINDOWS ) ) ; assertEquals ( WinX86 . class . getName ( ) , implementations . getImplementation ( new Platform ( Name . WINDOWS , Arch . X86 ) ) ) ; assertEquals ( WinX64 . class . getName ( ) , implementations . getImplementation ( new Platform ( Name . WINDOWS , Arch . X64 ) ) ) ; assertEquals ( Win7 . class . getName ( ) , implementations . getImplementation ( Platforms . WINDOWS_7 ) ) ; assertEquals ( Win7X64 . class . getName ( ) , implementations . getImplementation ( new Platform ( Name . WINDOWS , "<STR_LIT>" , OsVersionConstants . WINDOWS_7_VERSION , Arch . X64 ) ) ) ; assertEquals ( DebianA . class . getName ( ) , implementations . getImplementation ( Platforms . DEBIAN_LINUX ) ) ; assertEquals ( LinuxA . class . getName ( ) , implementations . getImplementation ( Platforms . LINUX ) ) ; assertEquals ( UnixA . class . getName ( ) , implementations . getImplementation ( Platforms . UNIX ) ) ; } @ Test public void testCreate ( ) throws Exception { Platforms platforms = new Platforms ( ) ; Platform platform = platforms . getCurrentPlatform ( ) ; TargetPlatformFactory factory = new DefaultTargetPlatformFactory ( NoDependencyInjectionFactory . INSTANCE , platform , platforms ) ; assertEquals ( WinA . class , factory . create ( A . class , Platforms . WINDOWS ) . getClass ( ) ) ; assertEquals ( WinA . class , factory . create ( A . class , Platforms . WINDOWS_2003 ) . getClass ( ) ) ; assertEquals ( WinA . class , factory . create ( A . class , Platforms . WINDOWS_XP ) . getClass ( ) ) ; assertEquals ( WinA . class , factory . create ( A . class , Platforms . WINDOWS_VISTA ) . getClass ( ) ) ; Platform windowsX86 = new Platform ( Name . WINDOWS , Arch . X86 ) ; Platform windowsX64 = new Platform ( Name . WINDOWS , Arch . X64 ) ; assertEquals ( WinX86 . class , factory . create ( A . class , windowsX86 ) . getClass ( ) ) ; assertEquals ( WinX64 . class , factory . create ( A . class , windowsX64 ) . getClass ( ) ) ; assertEquals ( UnixA . class , factory . create ( A . class , Platforms . UNIX ) . getClass ( ) ) ; assertEquals ( UnixA . class , factory . create ( A . class , Platforms . SUNOS_SPARC ) . getClass ( ) ) ; assertEquals ( UnixA . class , factory . create ( A . class , Platforms . SUNOS_X86 ) . getClass ( ) ) ; assertEquals ( UnixA . class , factory . create ( A . class , Platforms . MAC_OSX ) . getClass ( ) ) ; assertEquals ( LinuxA . class , factory . create ( A . class , Platforms . LINUX ) . getClass ( ) ) ; assertEquals ( LinuxA . class , factory . create ( A . class , Platforms . UBUNTU_LINUX ) . getClass ( ) ) ; assertEquals ( DebianA . class , factory . create ( A . class , Platforms . DEBIAN_LINUX ) . getClass ( ) ) ; assertEquals ( DefaultA . class , factory . create ( A . class , Platforms . OS_2 ) . getClass ( ) ) ; assertEquals ( Win7 . class , factory . create ( A . class , Platforms . WINDOWS_7 ) . getClass ( ) ) ; Platform win7x64 = new Platform ( Platforms . WINDOWS_7 , Arch . X64 ) ; assertEquals ( Win7X64 . class , factory . create ( A . class , win7x64 ) . getClass ( ) ) ; Platform win7x32 = new Platform ( Platforms . WINDOWS_7 , Arch . X86 ) ; assertEquals ( Win7 . class , factory . create ( A . class , win7x32 ) . getClass ( ) ) ; } public static interface A { } public static class WinA implements A { } public static class Win7 extends WinA { } public static class WinX86 extends WinA { } public static class WinX64 extends WinA { } public static class Win7X64 extends WinX64 { } public static class UnixA implements A { } public static class LinuxA extends UnixA { } public static class DebianA extends LinuxA { } public static class DefaultA implements A { } private static class NoDependencyInjectionFactory implements ObjectFactory { public static ObjectFactory INSTANCE = new NoDependencyInjectionFactory ( ) ; @ Override public < T > T create ( Class < T > type , Object ... parameters ) { try { return type . newInstance ( ) ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public < T > T create ( String className , Class < T > superType , Object ... parameters ) { Class type ; try { type = superType . getClassLoader ( ) . loadClass ( className ) ; if ( ! superType . isAssignableFrom ( type ) ) { throw new ClassCastException ( "<STR_LIT>" + type . getName ( ) + "<STR_LIT>" + superType . getName ( ) ) ; } } catch ( ClassNotFoundException exception ) { throw new IzPackClassNotFoundException ( className , exception ) ; } return create ( ( Class < T > ) type ) ; } } } </s>
|
<s> package com . izforge . izpack . util ; import static com . izforge . izpack . util . Platform . Arch . SPARC ; import static com . izforge . izpack . util . Platform . Arch . X64 ; import static com . izforge . izpack . util . Platform . Arch . X86 ; import static com . izforge . izpack . util . Platform . Name . SUNOS ; import static com . izforge . izpack . util . Platform . Name . UNIX ; import static com . izforge . izpack . util . Platform . Name . WINDOWS ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import java . util . Arrays ; import java . util . Collections ; import org . junit . Test ; import com . izforge . izpack . api . data . binding . OsModel ; public class PlatformModelMatcherTest { private final Platforms platforms ; private final PlatformModelMatcher matcher ; public PlatformModelMatcherTest ( ) { platforms = new Platforms ( ) ; matcher = new PlatformModelMatcher ( platforms , Platforms . WINDOWS ) ; } @ Test public void testArchitectureMatch ( ) { OsModel x86 = new OsModel ( "<STR_LIT>" , null , null , null , null ) ; OsModel x64 = new OsModel ( "<STR_LIT>" , null , null , null , null ) ; OsModel sparc = new OsModel ( "<STR_LIT>" , null , null , null , null ) ; checkMatch ( new Platform ( UNIX , X86 ) , x86 , x64 , sparc ) ; checkMatch ( new Platform ( WINDOWS , X64 ) , x64 , x86 , sparc ) ; checkMatch ( new Platform ( SUNOS , SPARC ) , sparc , x86 , x64 ) ; } @ Test public void testFamilyMatch ( ) { OsModel unix = new OsModel ( null , "<STR_LIT>" , null , null , null ) ; OsModel windows = new OsModel ( null , "<STR_LIT>" , null , null , null ) ; OsModel mac = new OsModel ( null , "<STR_LIT>" , null , null , null ) ; checkMatch ( Platforms . UNIX , unix , windows , mac ) ; checkMatch ( Platforms . WINDOWS , windows , unix , mac ) ; checkMatch ( Platforms . MAC , mac , unix , windows ) ; } @ Test public void testFamilyNameMatch ( ) { OsModel mac = new OsModel ( null , "<STR_LIT>" , null , "<STR_LIT>" , null ) ; OsModel osx = new OsModel ( null , "<STR_LIT>" , null , "<STR_LIT>" , null ) ; checkMatch ( Platforms . MAC , mac , osx ) ; checkMatch ( Platforms . MAC_OSX , osx , mac ) ; } @ Test public void testNameMatch ( ) { OsModel sunos = new OsModel ( null , null , null , "<STR_LIT>" , null ) ; OsModel osx = new OsModel ( null , null , null , "<STR_LIT>" , null ) ; OsModel os2 = new OsModel ( null , null , null , "<STR_LIT>" , null ) ; checkMatch ( Platforms . SUNOS , sunos , osx , os2 ) ; checkMatch ( Platforms . MAC_OSX , osx , sunos , os2 ) ; checkMatch ( Platforms . OS_2 , os2 , sunos , osx ) ; } @ Test public void testVersionMatch ( ) { OsModel xp = new OsModel ( null , null , null , null , OsVersionConstants . WINDOWS_XP_VERSION ) ; OsModel vista = new OsModel ( null , null , null , null , OsVersionConstants . WINDOWS_VISTA_VERSION ) ; OsModel windows7 = new OsModel ( null , null , null , null , OsVersionConstants . WINDOWS_7_VERSION ) ; checkMatch ( Platforms . WINDOWS_XP , xp , vista , windows7 ) ; checkMatch ( Platforms . WINDOWS_VISTA , vista , xp , windows7 ) ; checkMatch ( Platforms . WINDOWS_7 , windows7 , xp , vista ) ; } @ Test public void testJavaVersionMatch ( ) { OsModel v14 = new OsModel ( null , null , "<STR_LIT>" , null , null ) ; OsModel v15 = new OsModel ( null , null , "<STR_LIT>" , null , null ) ; OsModel v16 = new OsModel ( null , null , "<STR_LIT>" , null , null ) ; Platform platform14 = platforms . getPlatform ( OsVersionConstants . WINDOWS , null , null , "<STR_LIT>" ) ; Platform platform15 = platforms . getPlatform ( OsVersionConstants . WINDOWS , null , null , "<STR_LIT>" ) ; Platform platform16 = platforms . getPlatform ( OsVersionConstants . WINDOWS , null , null , "<STR_LIT>" ) ; checkMatch ( platform14 , v14 , v15 , v16 ) ; checkMatch ( platform15 , v15 , v14 , v16 ) ; checkMatch ( platform16 , v16 , v14 , v15 ) ; } @ Test public void testMatchesByFamily ( ) { Platform platform = Platforms . WINDOWS ; OsModel unix = new OsModel ( null , "<STR_LIT>" , null , null , null ) ; OsModel windows = new OsModel ( null , "<STR_LIT>" , null , null , null ) ; OsModel mac = new OsModel ( null , "<STR_LIT>" , null , null , null ) ; assertTrue ( matcher . matches ( platform , null ) ) ; assertTrue ( matcher . matches ( platform , Collections . < OsModel > emptyList ( ) ) ) ; assertTrue ( matcher . matches ( platform , Arrays . asList ( unix , windows , mac ) ) ) ; assertFalse ( matcher . matches ( platform , Arrays . asList ( unix , mac ) ) ) ; } @ Test public void testMatchesByName ( ) { Platform platform = Platforms . MAC_OSX ; OsModel osx = new OsModel ( null , null , null , "<STR_LIT>" , null ) ; OsModel sunos = new OsModel ( null , null , null , "<STR_LIT>" , null ) ; OsModel os2 = new OsModel ( null , null , null , "<STR_LIT>" , null ) ; assertTrue ( matcher . matches ( platform , null ) ) ; assertTrue ( matcher . matches ( platform , Collections . < OsModel > emptyList ( ) ) ) ; assertTrue ( matcher . matches ( platform , Arrays . asList ( osx , os2 , sunos ) ) ) ; assertFalse ( matcher . matches ( platform , Arrays . asList ( sunos , os2 ) ) ) ; } private void checkMatch ( Platform platform , OsModel match , OsModel ... noMatches ) { assertTrue ( matcher . match ( platform , match ) ) ; for ( OsModel model : noMatches ) { assertFalse ( matcher . match ( platform , model ) ) ; } } } </s>
|
<s> package com . izforge . izpack . util ; import static org . junit . Assert . assertEquals ; import java . util . List ; import org . junit . Test ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . data . binding . OsModel ; public class OsConstraintHelperTest { @ Test public void testGetOsList ( ) { XMLElementImpl root = new XMLElementImpl ( "<STR_LIT:root>" ) ; XMLElementImpl os1 = new XMLElementImpl ( "<STR_LIT>" , root ) ; os1 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; os1 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; os1 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; os1 . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; os1 . setAttribute ( "<STR_LIT:version>" , "<STR_LIT>" ) ; XMLElementImpl os2 = new XMLElementImpl ( "<STR_LIT>" , root ) ; os2 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; os2 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; os2 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; os2 . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; os2 . setAttribute ( "<STR_LIT:version>" , "<STR_LIT>" ) ; root . addChild ( os1 ) ; root . addChild ( os2 ) ; root . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; List < OsModel > models = OsConstraintHelper . getOsList ( root ) ; assertEquals ( <NUM_LIT:3> , models . size ( ) ) ; checkModel ( models . get ( <NUM_LIT:0> ) , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; checkModel ( models . get ( <NUM_LIT:1> ) , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; checkModel ( models . get ( <NUM_LIT:2> ) , null , "<STR_LIT>" , null , null , null ) ; } private void checkModel ( OsModel model , String arch , String family , String jre , String name , String version ) { assertEquals ( arch , model . getArch ( ) ) ; assertEquals ( family , model . getFamily ( ) ) ; assertEquals ( jre , model . getJre ( ) ) ; assertEquals ( name , model . getName ( ) ) ; assertEquals ( version , model . getVersion ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . util ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import java . io . File ; import java . util . List ; import org . junit . Test ; public class PrivilegedRunnerTest { @ Test public void testIsPlatformSupported ( ) { assertTrue ( new PrivilegedRunner ( Platforms . UNIX ) . isPlatformSupported ( ) ) ; assertTrue ( new PrivilegedRunner ( Platforms . LINUX ) . isPlatformSupported ( ) ) ; assertTrue ( new PrivilegedRunner ( Platforms . WINDOWS ) . isPlatformSupported ( ) ) ; assertFalse ( new PrivilegedRunner ( Platforms . MAC ) . isPlatformSupported ( ) ) ; assertTrue ( new PrivilegedRunner ( Platforms . MAC_OSX ) . isPlatformSupported ( ) ) ; } @ Test public void testGetElevatorOnUnix ( ) throws Exception { File file = new File ( System . getProperty ( "<STR_LIT>" ) , "<STR_LIT>" ) ; if ( file . exists ( ) ) { assertTrue ( file . delete ( ) ) ; } PrivilegedRunner runner = new PrivilegedRunner ( Platforms . UNIX ) ; List < String > elevatorCommand = runner . getElevator ( "<STR_LIT>" , "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:8> , elevatorCommand . size ( ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:2> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:3> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:4> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:5> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:6> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:7> ) ) ; assertFalse ( file . exists ( ) ) ; } @ Test public void testGetElevatorOnWindows ( ) throws Exception { File script = new File ( System . getProperty ( "<STR_LIT>" ) , "<STR_LIT>" ) ; String scriptPath = script . getCanonicalPath ( ) ; if ( script . exists ( ) ) { assertTrue ( script . delete ( ) ) ; } PrivilegedRunner runner = new PrivilegedRunner ( Platforms . WINDOWS ) ; List < String > elevatorCommand = runner . getElevator ( "<STR_LIT>" , "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:6> , elevatorCommand . size ( ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:0> ) ) ; assertEquals ( scriptPath , elevatorCommand . get ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:2> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:3> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:4> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:5> ) ) ; assertTrue ( script . exists ( ) ) ; assertTrue ( script . length ( ) != <NUM_LIT:0> ) ; assertTrue ( script . delete ( ) ) ; } @ Test public void testGetElevatorOnMacOSX ( ) throws Exception { File script = new File ( System . getProperty ( "<STR_LIT>" ) , "<STR_LIT>" ) ; String scriptPath = script . getCanonicalPath ( ) ; if ( script . exists ( ) ) { assertTrue ( script . delete ( ) ) ; } PrivilegedRunner runner = new PrivilegedRunner ( Platforms . MAC_OSX ) ; List < String > elevatorCommand = runner . getElevator ( "<STR_LIT>" , "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:4> , elevatorCommand . size ( ) ) ; assertEquals ( scriptPath , elevatorCommand . get ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:2> ) ) ; assertEquals ( "<STR_LIT>" , elevatorCommand . get ( <NUM_LIT:3> ) ) ; assertTrue ( script . exists ( ) ) ; assertTrue ( script . length ( ) != <NUM_LIT:0> ) ; assertTrue ( script . delete ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . data ; import com . izforge . izpack . api . data . binding . OsModel ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . List ; public class ExecutableFile implements Serializable { static final long serialVersionUID = <NUM_LIT> ; public final static int POSTINSTALL = <NUM_LIT:0> ; public final static int NEVER = <NUM_LIT:1> ; public final static int UNINSTALL = <NUM_LIT:2> ; public final static int BIN = <NUM_LIT:0> ; public final static int JAR = <NUM_LIT:1> ; public final static int ABORT = <NUM_LIT:0> ; public final static int WARN = <NUM_LIT:1> ; public final static int ASK = <NUM_LIT:2> ; public final static int IGNORE = <NUM_LIT:3> ; public String path ; public int executionStage ; public String mainClass ; public int type ; public int onFailure ; public List < String > argList = null ; public List < OsModel > osList = null ; public boolean keepFile ; private String condition = null ; public ExecutableFile ( ) { this . path = null ; executionStage = NEVER ; mainClass = null ; type = BIN ; onFailure = ASK ; osList = new ArrayList < OsModel > ( ) ; argList = new ArrayList < String > ( ) ; keepFile = false ; } public ExecutableFile ( String path , int executionStage , int onFailure , List < OsModel > osList , boolean keepFile ) { this . path = path ; this . executionStage = executionStage ; this . onFailure = onFailure ; this . osList = osList ; this . keepFile = keepFile ; } public ExecutableFile ( String path , int type , String mainClass , int executionStage , int onFailure , List < String > argList , List < OsModel > osList , boolean keepFile ) { this . path = path ; this . mainClass = mainClass ; this . type = type ; this . executionStage = executionStage ; this . onFailure = onFailure ; this . argList = argList ; this . osList = osList ; this . keepFile = keepFile ; } public String toString ( ) { StringBuffer retval = new StringBuffer ( ) ; retval . append ( "<STR_LIT>" ) . append ( path ) ; retval . append ( "<STR_LIT:n>" ) ; retval . append ( "<STR_LIT>" ) . append ( mainClass ) ; retval . append ( "<STR_LIT:n>" ) ; retval . append ( "<STR_LIT>" ) . append ( type ) ; retval . append ( "<STR_LIT:n>" ) ; retval . append ( "<STR_LIT>" ) . append ( executionStage ) ; retval . append ( "<STR_LIT:n>" ) ; retval . append ( "<STR_LIT>" ) . append ( onFailure ) ; retval . append ( "<STR_LIT:n>" ) ; retval . append ( "<STR_LIT>" ) . append ( argList ) ; retval . append ( "<STR_LIT:n>" ) ; if ( argList != null ) { for ( String anArgList : argList ) { retval . append ( "<STR_LIT>" ) . append ( anArgList ) ; retval . append ( "<STR_LIT:n>" ) ; } } retval . append ( "<STR_LIT:n>" ) ; retval . append ( "<STR_LIT>" ) . append ( osList ) ; retval . append ( "<STR_LIT:n>" ) ; if ( osList != null ) { for ( OsModel anOsList : osList ) { retval . append ( "<STR_LIT>" ) . append ( anOsList ) ; retval . append ( "<STR_LIT:n>" ) ; } } retval . append ( "<STR_LIT>" ) . append ( keepFile ) ; retval . append ( "<STR_LIT:n>" ) ; return retval . toString ( ) ; } public String getCondition ( ) { return this . condition ; } public void setCondition ( String condition ) { this . condition = condition ; } public boolean hasCondition ( ) { return this . condition != null ; } } </s>
|
<s> package com . izforge . izpack . data ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . PanelActionConfiguration ; import com . izforge . izpack . api . handler . AbstractUIHandler ; public interface PanelAction { public static final String PANEL_ACTIONS_TAG = "<STR_LIT>" ; public static final String PANEL_ACTION_TAG = "<STR_LIT>" ; public static final String PANEL_ACTION_STAGE_TAG = "<STR_LIT>" ; public static final String PANEL_ACTION_CONFIGURATION_TAG = "<STR_LIT>" ; public static enum ActionStage { preconstruct , preactivate , prevalidate , postvalidate } public static final String PANEL_ACTION_CLASSNAME_TAG = "<STR_LIT>" ; public void executeAction ( final InstallData adata , AbstractUIHandler handler ) ; public void initialize ( PanelActionConfiguration configuration ) ; } </s>
|
<s> package com . izforge . izpack . data ; import java . io . Serializable ; import java . util . List ; import com . izforge . izpack . api . data . binding . OsModel ; import com . izforge . izpack . api . substitutor . SubstitutionType ; public class ParsableFile implements Serializable { static final long serialVersionUID = - <NUM_LIT> ; private String path ; private final SubstitutionType type ; private final String encoding ; private final List < OsModel > osConstraints ; private String condition ; public ParsableFile ( String path , SubstitutionType type , String encoding , List < OsModel > osConstraints ) { this . path = path ; this . type = type ; this . encoding = encoding ; this . osConstraints = osConstraints ; } public String getPath ( ) { return path ; } public void setPath ( String path ) { this . path = path ; } public SubstitutionType getType ( ) { return type ; } public String getEncoding ( ) { return encoding ; } public List < OsModel > getOsConstraints ( ) { return osConstraints ; } public String getCondition ( ) { return this . condition ; } public void setCondition ( String condition ) { this . condition = condition ; } public boolean hasCondition ( ) { return this . condition != null ; } } </s>
|
<s> package com . izforge . izpack . data ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . LinkedHashMap ; import java . util . List ; import java . util . Map ; import java . util . Set ; import com . izforge . izpack . api . data . Blockable ; import com . izforge . izpack . api . data . OverrideType ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . PackColor ; import com . izforge . izpack . api . data . PackFile ; import com . izforge . izpack . api . data . binding . OsModel ; public class PackInfo implements Serializable { private static final long serialVersionUID = - <NUM_LIT> ; private Pack pack ; public PackColor colour ; private Map < PackFile , File > files = new LinkedHashMap < PackFile , File > ( ) ; private List < ParsableFile > parsables = new ArrayList < ParsableFile > ( ) ; private List < ExecutableFile > executables = new ArrayList < ExecutableFile > ( ) ; private List < UpdateCheck > updateChecks = new ArrayList < UpdateCheck > ( ) ; public PackInfo ( String name , String id , String description , boolean required , boolean loose , String excludegroup , boolean uninstall , long size ) { boolean ispreselected = ( excludegroup == null ) ; pack = new Pack ( name , id , description , null , null , required , ispreselected , loose , excludegroup , uninstall , size ) ; colour = PackColor . WHITE ; } public void setDependencies ( List < String > dependencies ) { pack . setDependencies ( dependencies ) ; } public void setExcludeGroup ( String group ) { pack . setExcludeGroup ( group ) ; } public void setOsConstraints ( List < OsModel > osConstraints ) { pack . setOsConstraints ( osConstraints ) ; } public List < OsModel > getOsConstraints ( List osConstraints ) { return pack . getOsConstraints ( ) ; } public void setPreselected ( boolean preselected ) { pack . setPreselected ( preselected ) ; } public boolean isPreselected ( ) { return pack . isPreselected ( ) ; } public String getGroup ( ) { return pack . getGroup ( ) ; } public void setGroup ( String group ) { pack . setGroup ( group ) ; } public void addInstallGroup ( String group ) { pack . getInstallGroups ( ) . add ( group ) ; } public boolean hasInstallGroup ( String group ) { return pack . getInstallGroups ( ) . contains ( group ) ; } public Set < String > getInstallGroups ( ) { return pack . getInstallGroups ( ) ; } public Pack getPack ( ) { return pack ; } public boolean isHidden ( ) { return pack . isHidden ( ) ; } public void setHidden ( boolean hidden ) { pack . setHidden ( hidden ) ; } public void addFile ( File baseDir , File file , String targetfile , List < OsModel > osList , OverrideType override , String overrideRenameTo , Blockable blockable , Map additionals , String condition ) throws IOException { if ( ! file . exists ( ) ) { throw new FileNotFoundException ( file . toString ( ) ) ; } PackFile packFile = new PackFile ( baseDir , file , targetfile , osList , override , overrideRenameTo , blockable , additionals ) ; packFile . setLoosePackInfo ( pack . isLoose ( ) ) ; packFile . setCondition ( condition ) ; files . put ( packFile , file ) ; } public Set < PackFile > getPackFiles ( ) { return files . keySet ( ) ; } public File getFile ( PackFile packFile ) { return files . get ( packFile ) ; } public void addParsable ( ParsableFile parsable ) { parsables . add ( parsable ) ; } public List < ParsableFile > getParsables ( ) { return parsables ; } public void addExecutable ( ExecutableFile executable ) { executables . add ( executable ) ; } public List < ExecutableFile > getExecutables ( ) { return executables ; } public void addUpdateCheck ( UpdateCheck updateCheck ) { updateChecks . add ( updateCheck ) ; } public List < UpdateCheck > getUpdateChecks ( ) { return updateChecks ; } public void addDependency ( String dependency ) { pack . addDependency ( dependency ) ; } public List < String > getDependencies ( ) { return pack . getDependencies ( ) ; } public String getParent ( ) { return pack . getParent ( ) ; } public void setParent ( String p ) { pack . setParent ( p ) ; } public String toString ( ) { return pack . getName ( ) ; } public void setPackImgId ( String packImgId ) { pack . setImageId ( packImgId ) ; } public String getCondition ( ) { return this . pack . getCondition ( ) ; } public void setCondition ( String condition ) { this . pack . setCondition ( condition ) ; } public void addValidator ( String validatorClassName ) { pack . addValidator ( validatorClassName ) ; } } </s>
|
<s> package com . izforge . izpack . data ; public enum CustomDataType { INSTALLER_LISTENER ( "<STR_LIT>" ) , UNINSTALLER_LISTENER ( "<STR_LIT>" ) , UNINSTALLER_LIB ( "<STR_LIT>" ) , UNINSTALLER_JAR ( "<STR_LIT>" ) ; private String attribute ; CustomDataType ( String attribute ) { this . attribute = attribute ; } public String getAttribute ( ) { return attribute ; } } </s>
|
<s> package com . izforge . izpack . data ; import com . izforge . izpack . api . data . binding . OsModel ; import java . io . Serializable ; import java . util . List ; public class CustomData implements Serializable { static final long serialVersionUID = <NUM_LIT> ; public static final int INSTALLER_LISTENER = <NUM_LIT:0> ; public static final int UNINSTALLER_LISTENER = <NUM_LIT:1> ; public static final int UNINSTALLER_LIB = <NUM_LIT:2> ; public static final int UNINSTALLER_JAR = <NUM_LIT:3> ; public List < String > contents ; public String listenerName ; public List < OsModel > osConstraints = null ; public int type = <NUM_LIT:0> ; public CustomData ( String listenerName , List < String > contents , List < OsModel > osConstraints , int type ) { this . listenerName = listenerName ; this . contents = contents ; this . osConstraints = osConstraints ; this . type = type ; } } </s>
|
<s> package com . izforge . izpack . data ; import java . io . Serializable ; import java . util . ArrayList ; public class UpdateCheck implements Serializable { static final long serialVersionUID = - <NUM_LIT> ; public ArrayList < String > includesList = null ; public ArrayList < String > excludesList = null ; boolean caseSensitive = true ; public UpdateCheck ( ) { } public UpdateCheck ( ArrayList < String > includes , ArrayList < String > excludes ) { this . includesList = includes ; this . excludesList = excludes ; } public UpdateCheck ( ArrayList < String > includes , ArrayList < String > excludes , String casesensitive ) { this . includesList = includes ; this . excludesList = excludes ; this . caseSensitive = ( ( casesensitive != null ) && "<STR_LIT:yes>" . equalsIgnoreCase ( casesensitive ) ) ; } } </s>
|
<s> package com . izforge . izpack . util . config ; import java . io . File ; import java . io . IOException ; import java . util . logging . Logger ; import com . izforge . izpack . util . config . base . Ini ; public class SingleIniFileTask extends ConfigFileTask { private static final Logger logger = Logger . getLogger ( SingleIniFileTask . class . getName ( ) ) ; @ Override protected void readSourceConfigurable ( ) throws Exception { if ( oldFile != null ) { try { if ( ! oldFile . exists ( ) ) { logger . warning ( "<STR_LIT>" + oldFile . getAbsolutePath ( ) + "<STR_LIT>" ) ; return ; } logger . fine ( "<STR_LIT>" + oldFile . getAbsolutePath ( ) ) ; fromConfigurable = new Ini ( this . oldFile ) ; } catch ( IOException ioe ) { throw new Exception ( ioe . toString ( ) ) ; } } } @ Override protected void readConfigurable ( ) throws Exception { if ( newFile != null && newFile . exists ( ) ) { try { logger . fine ( "<STR_LIT>" + newFile . getAbsolutePath ( ) ) ; configurable = new Ini ( newFile ) ; } catch ( IOException ioe ) { throw new Exception ( "<STR_LIT>" + ioe . toString ( ) ) ; } } else if ( toFile != null && toFile . exists ( ) ) { try { logger . fine ( "<STR_LIT>" + toFile . getAbsolutePath ( ) ) ; configurable = new Ini ( toFile ) ; } catch ( IOException ioe ) { throw new Exception ( "<STR_LIT>" + ioe . toString ( ) ) ; } } else { configurable = new Ini ( ) ; } } @ Override protected void writeConfigurable ( ) throws Exception { try { if ( ! toFile . exists ( ) ) { if ( createConfigurable ) { File parent = toFile . getParentFile ( ) ; if ( parent != null && ! parent . exists ( ) ) { parent . mkdirs ( ) ; } logger . fine ( "<STR_LIT>" + toFile . getAbsolutePath ( ) ) ; toFile . createNewFile ( ) ; } else { logger . warning ( "<STR_LIT>" + toFile . getAbsolutePath ( ) + "<STR_LIT>" ) ; return ; } } Ini ini = ( Ini ) configurable ; ini . setFile ( toFile ) ; ini . setComment ( getComment ( ) ) ; ini . store ( ) ; } catch ( IOException ioe ) { throw new Exception ( ioe ) ; } if ( cleanup && oldFile . exists ( ) ) { if ( ! oldFile . delete ( ) ) { logger . warning ( "<STR_LIT>" + oldFile + "<STR_LIT>" ) ; } } } } </s>
|
<s> package com . izforge . izpack . util . config ; import java . text . DateFormat ; import java . text . DecimalFormat ; import java . text . ParseException ; import java . text . SimpleDateFormat ; import java . util . Calendar ; import java . util . Date ; import java . util . EnumSet ; import java . util . HashMap ; import java . util . Hashtable ; import java . util . List ; import java . util . Map ; import java . util . Set ; import java . util . Vector ; import java . util . logging . Logger ; import com . izforge . izpack . util . config . SingleConfigurableTask . Entry . LookupType ; import com . izforge . izpack . util . config . base . BasicProfile ; import com . izforge . izpack . util . config . base . Config ; import com . izforge . izpack . util . config . base . Configurable ; import com . izforge . izpack . util . config . base . Ini ; import com . izforge . izpack . util . config . base . OptionMap ; import com . izforge . izpack . util . config . base . Options ; import com . izforge . izpack . util . config . base . Reg ; public abstract class SingleConfigurableTask implements ConfigurableTask { private static final Logger logger = Logger . getLogger ( SingleConfigurableTask . class . getName ( ) ) ; private boolean patchPreserveEntries = true ; private boolean patchPreserveValues = true ; private boolean patchResolveVariables = false ; protected boolean createConfigurable = true ; private boolean escape = Config . getGlobal ( ) . isEscape ( ) ; private boolean escapeNewLine = Config . getGlobal ( ) . isEscapeNewline ( ) ; private boolean headerComment = false ; private boolean emptyLines = true ; private boolean autoNumbering = true ; private String operator = Config . getGlobal ( ) . getOperator ( ) ; protected Configurable configurable ; protected Configurable fromConfigurable ; private Vector < Entry > entries = new Vector < Entry > ( ) ; public void setPatchPreserveEntries ( boolean preserveEntries ) { this . patchPreserveEntries = preserveEntries ; } public void setPatchPreserveValues ( boolean preserveValues ) { patchPreserveValues = preserveValues ; } public void setPatchResolveVariables ( boolean resolve ) { patchResolveVariables = resolve ; } public void setEscape ( boolean escape ) { this . escape = escape ; } public void setEscapeNewLine ( boolean escapeNewLine ) { this . escapeNewLine = escapeNewLine ; } public void setHeaderComment ( boolean headerComment ) { this . headerComment = headerComment ; } public void setEmptyLines ( boolean emptyLines ) { this . emptyLines = emptyLines ; } public void setAutoNumbering ( boolean autoNumbering ) { this . autoNumbering = autoNumbering ; } public void setOperator ( String operator ) { this . operator = operator ; } public void setCreate ( boolean create ) { createConfigurable = create ; } @ Override public void execute ( ) throws Exception { Config . getGlobal ( ) . setHeaderComment ( headerComment ) ; Config . getGlobal ( ) . setEmptyLines ( emptyLines ) ; Config . getGlobal ( ) . setAutoNumbering ( autoNumbering ) ; Config . getGlobal ( ) . setEscape ( escape ) ; Config . getGlobal ( ) . setEscapeNewline ( escapeNewLine ) ; Config . getGlobal ( ) . setOperator ( operator ) ; checkAttributes ( ) ; readConfigurable ( ) ; readSourceConfigurable ( ) ; patchConfigurable ( ) ; executeNestedEntries ( ) ; writeConfigurable ( ) ; } private String getValueFromOptionMap ( OptionMap map , String key , int index ) { return ( patchResolveVariables ? map . fetch ( key , index ) : map . get ( key , index ) ) ; } private void keepOptions ( String key , String fromValue , String lookupValue , LookupType lookupType ) { int found = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < ( ( Options ) configurable ) . length ( key ) ; i ++ ) { if ( lookupValue != null ) { String origValue = getValueFromOptionMap ( ( OptionMap ) configurable , key , i ) ; if ( origValue != null ) { switch ( lookupType ) { case REGEXP : if ( origValue . matches ( lookupValue ) ) { logger . fine ( "<STR_LIT>" + key + "<STR_LIT:\">" ) ; ( ( Options ) configurable ) . put ( key , fromValue , i ) ; found ++ ; } break ; default : if ( origValue . equals ( lookupValue ) ) { ( ( Options ) configurable ) . put ( key , fromValue , i ) ; found ++ ; } break ; } } } else { ( ( Options ) configurable ) . put ( key , fromValue , i ) ; found ++ ; } } logger . fine ( "<STR_LIT>" + found + "<STR_LIT>" + key + "<STR_LIT>" + fromValue ) ; if ( found == <NUM_LIT:0> ) { logger . fine ( "<STR_LIT>" + key + "<STR_LIT>" + fromValue ) ; ( ( Options ) configurable ) . add ( key , fromValue ) ; } } private void deleteOptions ( String key , String lookupValue , LookupType lookupType ) { for ( int i = <NUM_LIT:0> ; i < ( ( Options ) configurable ) . length ( key ) ; i ++ ) { if ( lookupValue == null ) { String origValue = getValueFromOptionMap ( ( OptionMap ) configurable , key , i ) ; if ( origValue != null ) { switch ( lookupType ) { case REGEXP : if ( origValue . matches ( lookupValue ) ) { logger . fine ( "<STR_LIT>" + key + "<STR_LIT:\">" ) ; ( ( Options ) configurable ) . remove ( key , i ) ; i -- ; } break ; default : if ( origValue . equals ( lookupValue ) ) { logger . fine ( "<STR_LIT>" + key + "<STR_LIT:\">" ) ; ( ( Options ) configurable ) . remove ( key , i ) ; i -- ; } break ; } } } else { logger . fine ( "<STR_LIT>" + key + "<STR_LIT:\">" ) ; ( ( Options ) configurable ) . remove ( key ) ; i -- ; } } } private void deleteConfigurableEntry ( String section , String key , String lookupValue , LookupType lookupType ) throws Exception { if ( configurable instanceof Options ) { deleteOptions ( key , lookupValue , lookupType ) ; } else if ( configurable instanceof Ini ) { ( ( Ini ) configurable ) . remove ( section , key ) ; } else if ( configurable instanceof Reg ) { ( ( Reg ) configurable ) . remove ( section , key ) ; } else { throw new Exception ( "<STR_LIT>" + configurable . getClass ( ) . getName ( ) ) ; } } private void keepConfigurableValue ( String section , String key , String lookupValue , LookupType lookupType ) throws Exception { if ( fromConfigurable != null ) { if ( configurable instanceof Options ) { for ( int i = <NUM_LIT:0> ; i < ( ( Options ) fromConfigurable ) . length ( key ) ; i ++ ) { String fromValue = getValueFromOptionMap ( ( OptionMap ) fromConfigurable , key , i ) ; if ( fromValue != null ) { if ( lookupValue != null ) { switch ( lookupType ) { case REGEXP : if ( fromValue . matches ( lookupValue ) ) { keepOptions ( key , fromValue , lookupValue , lookupType ) ; } break ; default : if ( ! fromValue . equals ( lookupValue ) ) { keepOptions ( key , fromValue , lookupValue , lookupType ) ; } break ; } } else { keepOptions ( key , fromValue , lookupValue , lookupType ) ; } } } } else if ( configurable instanceof Ini ) { Ini . Section fromSection = ( ( Ini ) fromConfigurable ) . get ( section ) ; Ini . Section toSection = ( ( Ini ) configurable ) . get ( section ) ; if ( fromSection != null ) { if ( toSection == null ) { logger . fine ( "<STR_LIT>" + section + "<STR_LIT:]>" ) ; toSection = ( ( Ini ) configurable ) . add ( section ) ; } if ( toSection != null ) { String fromValue = ( patchResolveVariables ? fromSection . fetch ( key ) : fromSection . get ( key ) ) ; if ( ! toSection . containsKey ( key ) ) { logger . fine ( "<STR_LIT>" + key + "<STR_LIT>" + section + "<STR_LIT>" + fromValue ) ; toSection . add ( key , fromValue ) ; } else { logger . fine ( "<STR_LIT>" + key + "<STR_LIT>" + section + "<STR_LIT>" + fromValue ) ; toSection . put ( key , fromValue ) ; } } } } else if ( configurable instanceof Reg ) { Reg . Key fromRegKey = ( ( Reg ) fromConfigurable ) . get ( section ) ; Reg . Key toRegKey = ( ( Reg ) configurable ) . get ( section ) ; if ( fromRegKey != null ) { if ( toRegKey == null ) { logger . fine ( "<STR_LIT>" + section ) ; toRegKey = ( ( Reg ) configurable ) . add ( section ) ; } if ( toRegKey != null ) { String fromValue = ( patchResolveVariables ? fromRegKey . fetch ( key ) : fromRegKey . get ( key ) ) ; if ( ! toRegKey . containsKey ( key ) ) { logger . fine ( "<STR_LIT>" + key + "<STR_LIT>" + section + "<STR_LIT::U+0020>" + fromValue ) ; toRegKey . add ( key , fromValue ) ; } else { logger . fine ( "<STR_LIT>" + key + "<STR_LIT>" + section + "<STR_LIT::U+0020>" + fromValue ) ; toRegKey . put ( key , fromValue ) ; } } } } else { throw new Exception ( "<STR_LIT>" + configurable . getClass ( ) . getName ( ) ) ; } } } private void patchConfigurable ( ) throws Exception { if ( fromConfigurable != null ) { Set < String > toKeySet ; Set < String > fromKeySet ; if ( configurable instanceof Options ) { toKeySet = ( ( Options ) configurable ) . keySet ( ) ; fromKeySet = ( ( Options ) fromConfigurable ) . keySet ( ) ; for ( String key : fromKeySet ) { String fromValue = ( patchResolveVariables ? ( ( Options ) fromConfigurable ) . fetch ( key ) : ( ( Options ) fromConfigurable ) . get ( key ) ) ; if ( patchPreserveEntries && ! toKeySet . contains ( key ) ) { logger . fine ( "<STR_LIT>" + key + "<STR_LIT:\">" ) ; ( ( Options ) configurable ) . add ( key , fromValue ) ; } else if ( patchPreserveValues && ( ( Options ) configurable ) . keySet ( ) . contains ( key ) ) { logger . fine ( "<STR_LIT>" + key + "<STR_LIT>" + fromValue + "<STR_LIT:\">" ) ; ( ( Options ) configurable ) . put ( key , fromValue ) ; } } } else if ( configurable instanceof Ini ) { Set < String > sectionKeySet = ( ( Ini ) configurable ) . keySet ( ) ; Set < String > fromSectionKeySet = ( ( Ini ) fromConfigurable ) . keySet ( ) ; for ( String fromSectionKey : fromSectionKeySet ) { if ( sectionKeySet . contains ( fromSectionKey ) ) { Ini . Section fromSection = ( ( Ini ) fromConfigurable ) . get ( fromSectionKey ) ; Ini . Section toSection = ( ( Ini ) configurable ) . get ( fromSectionKey ) ; fromKeySet = fromSection . keySet ( ) ; toKeySet = null ; if ( toSection != null ) toKeySet = toSection . keySet ( ) ; for ( String fromKey : fromKeySet ) { if ( toSection == null ) { logger . fine ( "<STR_LIT>" + fromSectionKey + "<STR_LIT:]>" ) ; toSection = ( ( Ini ) configurable ) . add ( fromSectionKey ) ; } String fromValue = ( patchResolveVariables ? fromSection . fetch ( fromKey ) : fromSection . get ( fromKey ) ) ; if ( patchPreserveEntries && ! toKeySet . contains ( fromKey ) ) { logger . fine ( "<STR_LIT>" + fromKey + "<STR_LIT>" + fromSectionKey + "<STR_LIT>" + fromValue ) ; toSection . add ( fromKey , fromValue ) ; } else if ( patchPreserveValues && toKeySet . contains ( fromKey ) ) { logger . fine ( "<STR_LIT>" + fromKey + "<STR_LIT>" + fromSectionKey + "<STR_LIT>" + fromValue ) ; toSection . put ( fromKey , fromValue ) ; } } } } } else if ( configurable instanceof Reg ) { Set < String > rootKeySet = ( ( Reg ) configurable ) . keySet ( ) ; Set < String > fromRootKeySet = ( ( Reg ) fromConfigurable ) . keySet ( ) ; for ( String fromRootKey : fromRootKeySet ) { if ( rootKeySet . contains ( fromRootKey ) ) { Reg . Key fromRegKey = ( ( Reg ) fromConfigurable ) . get ( fromRootKey ) ; Reg . Key toRegKey = ( ( Reg ) configurable ) . get ( fromRootKey ) ; fromKeySet = fromRegKey . keySet ( ) ; toKeySet = null ; if ( toRegKey != null ) toKeySet = toRegKey . keySet ( ) ; for ( String fromKey : fromKeySet ) { if ( toRegKey == null ) { logger . fine ( "<STR_LIT>" + fromRootKey ) ; toRegKey = ( ( Reg ) configurable ) . add ( fromRootKey ) ; } String fromValue = ( patchResolveVariables ? fromRegKey . fetch ( fromKey ) : fromRegKey . get ( fromKey ) ) ; if ( patchPreserveEntries && ! toKeySet . contains ( fromKey ) ) { logger . fine ( "<STR_LIT>" + fromKey + "<STR_LIT>" + fromRootKey + "<STR_LIT::U+0020>" + fromValue ) ; toRegKey . add ( fromKey , fromValue ) ; } else if ( patchPreserveValues && toKeySet . contains ( fromKey ) ) { logger . fine ( "<STR_LIT>" + fromKey + "<STR_LIT>" + fromRootKey + "<STR_LIT::U+0020>" + fromValue ) ; toRegKey . put ( fromKey , fromValue ) ; } } } } } else { throw new Exception ( "<STR_LIT>" + configurable . getClass ( ) . getName ( ) ) ; } } } private void executeNestedEntries ( ) throws Exception { for ( Entry entry : entries ) { switch ( entry . getOperation ( ) ) { case REMOVE : deleteConfigurableEntry ( entry . getSection ( ) , entry . getKey ( ) , entry . getValue ( ) , entry . getLookupType ( ) ) ; break ; case KEEP : keepConfigurableValue ( entry . getSection ( ) , entry . getKey ( ) , entry . getValue ( ) , entry . getLookupType ( ) ) ; break ; default : entry . executeOn ( configurable ) ; } } } protected abstract void checkAttributes ( ) throws Exception ; protected abstract void readSourceConfigurable ( ) throws Exception ; protected abstract void readConfigurable ( ) throws Exception ; protected abstract void writeConfigurable ( ) throws Exception ; public void addEntry ( Entry entry ) { entries . addElement ( entry ) ; } public static class Entry { private static final int DEFAULT_INT_VALUE = <NUM_LIT:0> ; private static final String DEFAULT_DATE_VALUE = "<STR_LIT>" ; private static final String DEFAULT_STRING_VALUE = "<STR_LIT>" ; protected String section = null ; protected String key = null ; protected String value = null ; private boolean resolveVariables = false ; private LookupType lookupType = LookupType . PLAIN ; private Type type = Type . STRING ; private Operation operation = Operation . SET ; private String defaultValue = null ; private String pattern = null ; private Unit unit = Unit . DAY ; public String getSection ( ) { return section ; } public void setSection ( String section ) { this . section = section ; } public String getKey ( ) { return key ; } public void setKey ( String value ) { this . key = value ; } public void setValue ( String value ) { this . value = value ; } public void setResolveVariables ( boolean resolve ) { this . resolveVariables = resolve ; } public String getValue ( ) { return value ; } public LookupType getLookupType ( ) { return lookupType ; } public Type getType ( ) { return type ; } public Operation getOperation ( ) { return operation ; } public void setOperation ( Operation operation ) { this . operation = operation ; } public void setType ( Type type ) { this . type = type ; } public void setLookupType ( LookupType lookupType ) { this . lookupType = lookupType ; } public void setDefault ( String value ) { this . defaultValue = value ; } public void setPattern ( String value ) { this . pattern = value ; } public void setUnit ( Unit unit ) { this . unit = unit ; } private void executeOnOptions ( Options configurable ) throws Exception { List < String > values = configurable . getAll ( key ) ; String newValue = null ; boolean contains = false ; if ( values != null ) { for ( int i = <NUM_LIT:0> ; i < values . toArray ( ) . length ; i ++ ) { String origValue = getValueFromOptions ( configurable , i ) ; newValue = execute ( origValue ) ; if ( origValue != null && value != null ) { switch ( lookupType ) { case REGEXP : if ( origValue . matches ( value ) ) { logger . fine ( "<STR_LIT>" + key + "<STR_LIT>" + newValue + "<STR_LIT:\">" ) ; configurable . put ( key , newValue , i ) ; contains = true ; } break ; default : if ( origValue . equals ( value ) ) { logger . fine ( "<STR_LIT>" + key + "<STR_LIT>" + newValue + "<STR_LIT:\">" ) ; configurable . put ( key , newValue , i ) ; contains = true ; } break ; } } } } if ( ! contains ) { logger . fine ( "<STR_LIT>" + key + "<STR_LIT>" + newValue + "<STR_LIT:\">" ) ; configurable . put ( key , newValue ) ; } } private void executeOnProfile ( BasicProfile profile ) throws Exception { String oldValue = getValueFromProfile ( profile ) ; profile . put ( section , key , execute ( oldValue ) ) ; } private String getValueFromOptions ( OptionMap map , int index ) { return resolveVariables ? map . fetch ( key , index ) : map . get ( key , index ) ; } private String getValueFromProfile ( BasicProfile profile ) { return resolveVariables ? profile . fetch ( section , key ) : profile . get ( section , key ) ; } private String execute ( String oldValue ) throws Exception { String newValue = null ; switch ( type ) { case INTEGER : newValue = executeInteger ( oldValue ) ; break ; case DATE : newValue = executeDate ( oldValue ) ; break ; case STRING : newValue = executeString ( oldValue ) ; break ; default : throw new Exception ( "<STR_LIT>" + type ) ; } if ( newValue == null ) { newValue = "<STR_LIT>" ; } return newValue ; } protected void executeOn ( Configurable configurable ) throws Exception { checkParameters ( ) ; if ( configurable instanceof Options ) { executeOnOptions ( ( Options ) configurable ) ; } else if ( configurable instanceof Ini ) { executeOnProfile ( ( BasicProfile ) configurable ) ; } else if ( configurable instanceof Reg ) { executeOnProfile ( ( BasicProfile ) configurable ) ; } else { throw new Exception ( "<STR_LIT>" + configurable . getClass ( ) . getName ( ) ) ; } } private String executeDate ( String oldValue ) throws Exception { Calendar currentValue = Calendar . getInstance ( ) ; if ( pattern == null ) { pattern = "<STR_LIT>" ; } DateFormat fmt = new SimpleDateFormat ( pattern ) ; String currentStringValue = getCurrentValue ( oldValue ) ; if ( currentStringValue == null ) { currentStringValue = DEFAULT_DATE_VALUE ; } if ( "<STR_LIT>" . equals ( currentStringValue ) ) { currentValue . setTime ( new Date ( ) ) ; } else { try { currentValue . setTime ( fmt . parse ( currentStringValue ) ) ; } catch ( ParseException pe ) { } } if ( operation != Operation . SET ) { int offset = <NUM_LIT:0> ; try { offset = Integer . parseInt ( value ) ; if ( operation == Operation . DECREMENT ) { offset = - <NUM_LIT:1> * offset ; } } catch ( NumberFormatException e ) { throw new Exception ( "<STR_LIT>" + key ) ; } currentValue . add ( unit . getCalendarField ( ) , offset ) ; } return fmt . format ( currentValue . getTime ( ) ) ; } private String executeInteger ( String oldValue ) throws Exception { int currentValue = DEFAULT_INT_VALUE ; int newValue = DEFAULT_INT_VALUE ; DecimalFormat fmt = ( pattern != null ) ? new DecimalFormat ( pattern ) : new DecimalFormat ( ) ; try { String curval = getCurrentValue ( oldValue ) ; if ( curval != null ) { currentValue = fmt . parse ( curval ) . intValue ( ) ; } else { currentValue = <NUM_LIT:0> ; } } catch ( NumberFormatException nfe ) { } catch ( ParseException pe ) { } if ( operation == Operation . SET ) { newValue = currentValue ; } else { int operationValue = <NUM_LIT:1> ; if ( value != null ) { try { operationValue = fmt . parse ( value ) . intValue ( ) ; } catch ( NumberFormatException nfe ) { } catch ( ParseException pe ) { } } if ( operation == Operation . INCREMENT ) { newValue = currentValue + operationValue ; } else if ( operation == Operation . DECREMENT ) { newValue = currentValue - operationValue ; } } return fmt . format ( newValue ) ; } private String executeString ( String oldValue ) throws Exception { String newValue = DEFAULT_STRING_VALUE ; String currentValue = getCurrentValue ( oldValue ) ; if ( currentValue == null ) { currentValue = DEFAULT_STRING_VALUE ; } if ( operation == Operation . SET ) { newValue = currentValue ; } else if ( operation == Operation . INCREMENT ) { newValue = currentValue + value ; } return newValue ; } private void checkParameters ( ) throws Exception { if ( type == Type . STRING && operation == Operation . DECREMENT ) { throw new Exception ( "<STR_LIT>" + "<STR_LIT>" + key + "<STR_LIT:)>" ) ; } if ( value == null && defaultValue == null ) { throw new Exception ( "<STR_LIT>" + "<STR_LIT>" + key + "<STR_LIT:)>" ) ; } if ( key == null ) { throw new Exception ( "<STR_LIT>" ) ; } if ( type == Type . STRING && pattern != null ) { throw new Exception ( "<STR_LIT>" + "<STR_LIT>" + key + "<STR_LIT:)>" ) ; } } private String getCurrentValue ( String oldValue ) { String ret = null ; if ( operation == Operation . SET ) { if ( value != null && defaultValue == null ) { ret = value ; } if ( value == null && defaultValue != null && oldValue != null ) { ret = oldValue ; } if ( value == null && defaultValue != null && oldValue == null ) { ret = defaultValue ; } if ( value != null && defaultValue != null && oldValue != null ) { ret = value ; } if ( value != null && defaultValue != null && oldValue == null ) { ret = defaultValue ; } } else { ret = ( oldValue == null ) ? defaultValue : oldValue ; } return ret ; } public enum Operation { INCREMENT ( "<STR_LIT:+>" ) , DECREMENT ( "<STR_LIT:->" ) , SET ( "<STR_LIT:=>" ) , REMOVE ( "<STR_LIT>" ) , KEEP ( "<STR_LIT>" ) ; private static Map < String , Operation > lookup ; private String attribute ; Operation ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , Operation > ( ) ; for ( Operation operation : EnumSet . allOf ( Operation . class ) ) { lookup . put ( operation . getAttribute ( ) , operation ) ; } } public String getAttribute ( ) { return attribute ; } public static Operation getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } } public enum Type { INTEGER ( "<STR_LIT:int>" ) , DATE ( "<STR_LIT:date>" ) , STRING ( "<STR_LIT:string>" ) ; private static Map < String , Type > lookup ; private String attribute ; Type ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , Type > ( ) ; for ( Type type : EnumSet . allOf ( Type . class ) ) { lookup . put ( type . getAttribute ( ) , type ) ; } } public String getAttribute ( ) { return attribute ; } public static Type getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } } public enum LookupType { PLAIN ( "<STR_LIT>" ) , REGEXP ( "<STR_LIT>" ) ; private static Map < String , LookupType > lookup ; private String attribute ; LookupType ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , LookupType > ( ) ; for ( LookupType type : EnumSet . allOf ( LookupType . class ) ) { lookup . put ( type . getAttribute ( ) , type ) ; } } public String getAttribute ( ) { return attribute ; } public static LookupType getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } } } public enum Unit { MILLISECOND ( "<STR_LIT>" ) , SECOND ( "<STR_LIT>" ) , MINUTE ( "<STR_LIT>" ) , HOUR ( "<STR_LIT>" ) , DAY ( "<STR_LIT>" ) , WEEK ( "<STR_LIT>" ) , MONTH ( "<STR_LIT>" ) , YEAR ( "<STR_LIT>" ) ; private static Map < String , Unit > lookup ; private static Hashtable < Unit , Integer > calendarFields ; private String attribute ; Unit ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , Unit > ( ) ; for ( Unit unit : EnumSet . allOf ( Unit . class ) ) { lookup . put ( unit . getAttribute ( ) , unit ) ; } calendarFields = new Hashtable < Unit , Integer > ( ) ; calendarFields . put ( MILLISECOND , new Integer ( Calendar . MILLISECOND ) ) ; calendarFields . put ( SECOND , new Integer ( Calendar . SECOND ) ) ; calendarFields . put ( MINUTE , new Integer ( Calendar . MINUTE ) ) ; calendarFields . put ( HOUR , new Integer ( Calendar . HOUR_OF_DAY ) ) ; calendarFields . put ( DAY , new Integer ( Calendar . DATE ) ) ; calendarFields . put ( WEEK , new Integer ( Calendar . WEEK_OF_YEAR ) ) ; calendarFields . put ( MONTH , new Integer ( Calendar . MONTH ) ) ; calendarFields . put ( YEAR , new Integer ( Calendar . YEAR ) ) ; } public String getAttribute ( ) { return attribute ; } public static Unit getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } public int getCalendarField ( ) { return calendarFields . get ( this ) ; } } } </s>
|
<s> package com . izforge . izpack . util . config ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . InputStream ; import java . util . ArrayList ; import java . util . LinkedList ; import java . util . List ; import java . util . Properties ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . util . file . DirectoryScanner ; import com . izforge . izpack . util . file . types . FileSet ; import com . izforge . izpack . util . xmlmerge . AbstractXmlMergeException ; import com . izforge . izpack . util . xmlmerge . ConfigurationException ; import com . izforge . izpack . util . xmlmerge . XmlMerge ; import com . izforge . izpack . util . xmlmerge . config . ConfigurableXmlMerge ; import com . izforge . izpack . util . xmlmerge . config . PropertyXPathConfigurer ; public class SingleXmlFileMergeTask implements ConfigurableTask { private static final Logger logger = Logger . getLogger ( SingleXmlFileMergeTask . class . getName ( ) ) ; protected File origfile ; protected File patchfile ; protected File tofile ; protected File conffile ; protected boolean cleanup ; protected Properties confProps = new Properties ( ) ; public void setOriginalFile ( File origfile ) { this . origfile = origfile ; } public void setPatchFile ( File patchfile ) { this . patchfile = patchfile ; } public void setToFile ( File tofile ) { this . tofile = tofile ; } public void setConfigFile ( File confFile ) { this . conffile = confFile ; } public void setCleanup ( boolean cleanup ) { this . cleanup = cleanup ; } List < FileSet > filesets = new ArrayList < FileSet > ( ) ; public void addFileSet ( FileSet fileset ) { filesets . add ( fileset ) ; } public void addProperty ( String key , String value ) { confProps . setProperty ( key , value ) ; } public void validate ( ) throws Exception { if ( tofile == null ) { throw new Exception ( "<STR_LIT>" ) ; } if ( filesets . isEmpty ( ) && patchfile == null ) { throw new Exception ( "<STR_LIT>" ) ; } if ( origfile == null ) { throw new Exception ( "<STR_LIT>" ) ; } if ( ! confProps . isEmpty ( ) && conffile != null ) { throw new Exception ( "<STR_LIT>" ) ; } } @ Override public void execute ( ) throws Exception { validate ( ) ; LinkedList < File > filesToMerge = new LinkedList < File > ( ) ; if ( origfile != null ) { if ( origfile . exists ( ) ) { filesToMerge . add ( origfile ) ; } else { logger . warning ( "<STR_LIT>" + origfile + "<STR_LIT>" ) ; return ; } } else { logger . warning ( "<STR_LIT>" ) ; return ; } if ( patchfile != null && patchfile . exists ( ) ) filesToMerge . add ( patchfile ) ; for ( FileSet fs : filesets ) { DirectoryScanner ds = fs . getDirectoryScanner ( ) ; String [ ] includedFiles = ds . getIncludedFiles ( ) ; for ( String includedFile : includedFiles ) { filesToMerge . add ( new File ( ds . getBasedir ( ) , includedFile ) ) ; } } if ( filesToMerge . size ( ) < <NUM_LIT:2> ) { logger . warning ( "<STR_LIT>" ) ; return ; } if ( conffile != null ) { InputStream configIn = null ; try { configIn = new FileInputStream ( conffile ) ; confProps . load ( configIn ) ; } catch ( IOException e ) { throw new Exception ( e ) ; } finally { if ( configIn != null ) { try { configIn . close ( ) ; } catch ( IOException e ) { logger . log ( Level . WARNING , "<STR_LIT>" + conffile + "<STR_LIT>" + e . getMessage ( ) , e ) ; } } } } XmlMerge xmlMerge ; try { xmlMerge = new ConfigurableXmlMerge ( new PropertyXPathConfigurer ( confProps ) ) ; } catch ( ConfigurationException e ) { throw new Exception ( e ) ; } try { xmlMerge . merge ( filesToMerge . toArray ( new File [ filesToMerge . size ( ) ] ) , tofile ) ; } catch ( AbstractXmlMergeException e ) { throw new Exception ( e ) ; } if ( cleanup ) { for ( File file : filesToMerge ) { if ( file . exists ( ) && ! file . equals ( tofile ) ) { if ( ! file . delete ( ) ) { logger . warning ( "<STR_LIT>" + file + "<STR_LIT>" ) ; } } } } } } </s>
|
<s> package com . izforge . izpack . util . config ; import java . io . IOException ; import java . util . logging . Logger ; import com . izforge . izpack . util . config . base . Reg ; public class RegistryTask extends SingleConfigurableTask { private static final Logger logger = Logger . getLogger ( RegistryTask . class . getName ( ) ) ; protected String key ; protected String fromKey ; public void setKey ( String key ) { this . key = key ; } public void setFromKey ( String key ) { this . fromKey = key ; } @ Override protected void readSourceConfigurable ( ) throws Exception { if ( this . fromKey != null ) { try { logger . fine ( "<STR_LIT>" + this . fromKey ) ; fromConfigurable = new Reg ( this . fromKey ) ; } catch ( IOException ioe ) { throw new Exception ( ioe . toString ( ) ) ; } } } @ Override protected void readConfigurable ( ) throws Exception { if ( this . key != null ) { try { logger . fine ( "<STR_LIT>" + this . key ) ; configurable = new Reg ( this . key ) ; } catch ( IOException ioe ) { throw new Exception ( ioe . toString ( ) ) ; } } } @ Override protected void writeConfigurable ( ) throws Exception { if ( configurable == null ) { logger . warning ( "<STR_LIT>" + this . key + "<STR_LIT>" ) ; return ; } try { Reg r = ( Reg ) configurable ; r . store ( ) ; } catch ( IOException ioe ) { throw new Exception ( ioe ) ; } } @ Override protected void checkAttributes ( ) throws Exception { if ( this . key == null ) { throw new Exception ( "<STR_LIT>" ) ; } } } </s>
|
<s> package com . izforge . izpack . util . config ; import java . io . File ; import java . io . IOException ; import java . util . logging . Logger ; import com . izforge . izpack . util . config . base . Options ; public class SingleOptionFileTask extends ConfigFileTask { private static final Logger logger = Logger . getLogger ( SingleOptionFileTask . class . getName ( ) ) ; @ Override protected void readSourceConfigurable ( ) throws Exception { if ( oldFile != null ) { try { if ( ! oldFile . exists ( ) ) { logger . warning ( "<STR_LIT>" + oldFile . getAbsolutePath ( ) + "<STR_LIT>" ) ; return ; } logger . fine ( "<STR_LIT>" + oldFile . getAbsolutePath ( ) ) ; fromConfigurable = new Options ( this . oldFile ) ; } catch ( IOException ioe ) { throw new Exception ( ioe . toString ( ) ) ; } } } @ Override protected void readConfigurable ( ) throws Exception { if ( newFile != null && newFile . exists ( ) ) { try { logger . fine ( "<STR_LIT>" + newFile . getAbsolutePath ( ) ) ; configurable = new Options ( newFile ) ; } catch ( IOException ioe ) { throw new Exception ( "<STR_LIT>" + ioe . toString ( ) ) ; } } else if ( toFile != null && toFile . exists ( ) ) { try { logger . fine ( "<STR_LIT>" + toFile . getAbsolutePath ( ) ) ; configurable = new Options ( toFile ) ; } catch ( IOException ioe ) { throw new Exception ( "<STR_LIT>" + ioe . toString ( ) ) ; } } else { configurable = new Options ( ) ; } } @ Override protected void writeConfigurable ( ) throws Exception { try { if ( ! toFile . exists ( ) ) { if ( createConfigurable ) { File parent = toFile . getParentFile ( ) ; if ( parent != null && ! parent . exists ( ) ) { parent . mkdirs ( ) ; } logger . fine ( "<STR_LIT>" + toFile . getAbsolutePath ( ) ) ; toFile . createNewFile ( ) ; } else { logger . warning ( "<STR_LIT>" + toFile . getAbsolutePath ( ) + "<STR_LIT>" ) ; return ; } } Options opts = ( Options ) configurable ; opts . setFile ( toFile ) ; opts . setComment ( getComment ( ) ) ; opts . store ( ) ; } catch ( IOException ioe ) { throw new Exception ( ioe ) ; } if ( cleanup && oldFile . exists ( ) ) { if ( ! oldFile . delete ( ) ) { logger . warning ( "<STR_LIT>" + oldFile + "<STR_LIT>" ) ; } } } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; public final class Warnings { public static final String UNCHECKED = "<STR_LIT:unchecked>" ; private Warnings ( ) { assert true ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import java . io . IOException ; import java . io . InputStream ; import java . io . LineNumberReader ; import java . io . Reader ; import java . net . URL ; import com . izforge . izpack . util . config . base . Config ; class IniSource { public static final char INCLUDE_BEGIN = '<CHAR_LIT>' ; public static final char INCLUDE_END = '<CHAR_LIT:>>' ; public static final char INCLUDE_OPTIONAL = '<CHAR_LIT>' ; private static final char ESCAPE_CHAR = '<STR_LIT:\\>' ; private URL _base ; private IniSource _chain ; private final String _commentChars ; private final Config _config ; private final HandlerBase _handler ; private final LineNumberReader _reader ; IniSource ( InputStream input , HandlerBase handler , String comments , Config config ) { this ( new UnicodeInputStreamReader ( input , config . getFileEncoding ( ) ) , handler , comments , config ) ; } IniSource ( Reader input , HandlerBase handler , String comments , Config config ) { _reader = new LineNumberReader ( input ) ; _handler = handler ; _commentChars = comments ; _config = config ; } IniSource ( URL input , HandlerBase handler , String comments , Config config ) throws IOException { this ( new UnicodeInputStreamReader ( input . openStream ( ) , config . getFileEncoding ( ) ) , handler , comments , config ) ; _base = input ; } int getLineNumber ( ) { int ret ; if ( _chain == null ) { ret = _reader . getLineNumber ( ) ; } else { ret = _chain . getLineNumber ( ) ; } return ret ; } String readLine ( ) throws IOException { String line ; if ( _chain == null ) { line = readLineLocal ( ) ; } else { line = _chain . readLine ( ) ; if ( line == null ) { _chain = null ; line = readLine ( ) ; } } return line ; } private void close ( ) throws IOException { _reader . close ( ) ; } private int countEndingEscapes ( String line ) { int escapeCount = <NUM_LIT:0> ; for ( int i = line . length ( ) - <NUM_LIT:1> ; ( i >= <NUM_LIT:0> ) && ( line . charAt ( i ) == ESCAPE_CHAR ) ; i -- ) { escapeCount ++ ; } return escapeCount ; } private void handleComment ( StringBuilder buff ) { if ( buff . length ( ) != <NUM_LIT:0> ) { buff . deleteCharAt ( buff . length ( ) - <NUM_LIT:1> ) ; _handler . handleComment ( buff . toString ( ) ) ; buff . delete ( <NUM_LIT:0> , buff . length ( ) ) ; } } private void handleEmptyLine ( ) { _handler . handleEmptyLine ( ) ; } private String handleInclude ( String input ) throws IOException { String line = input ; if ( _config . isInclude ( ) && ( line . length ( ) > <NUM_LIT:2> ) && ( line . charAt ( <NUM_LIT:0> ) == INCLUDE_BEGIN ) && ( line . charAt ( line . length ( ) - <NUM_LIT:1> ) == INCLUDE_END ) ) { line = line . substring ( <NUM_LIT:1> , line . length ( ) - <NUM_LIT:1> ) . trim ( ) ; boolean optional = line . charAt ( <NUM_LIT:0> ) == INCLUDE_OPTIONAL ; if ( optional ) { line = line . substring ( <NUM_LIT:1> ) . trim ( ) ; } URL loc = ( _base == null ) ? new URL ( line ) : new URL ( _base , line ) ; if ( optional ) { try { _chain = new IniSource ( loc , _handler , _commentChars , _config ) ; } catch ( IOException x ) { assert true ; } finally { line = readLine ( ) ; } } else { _chain = new IniSource ( loc , _handler , _commentChars , _config ) ; line = readLine ( ) ; } } return line ; } private String readLineLocal ( ) throws IOException { String line = readLineSkipComments ( ) ; if ( line == null ) { close ( ) ; } else { line = handleInclude ( line ) ; } return line ; } private String readLineSkipComments ( ) throws IOException { String line ; StringBuilder comment = new StringBuilder ( ) ; StringBuilder buff = new StringBuilder ( ) ; for ( line = _reader . readLine ( ) ; line != null ; line = _reader . readLine ( ) ) { line = line . trim ( ) ; if ( line . length ( ) == <NUM_LIT:0> ) { if ( _config . isEmptyLines ( ) && comment . length ( ) == <NUM_LIT:0> ) { handleEmptyLine ( ) ; } else { handleComment ( comment ) ; } } else if ( ( _commentChars . indexOf ( line . charAt ( <NUM_LIT:0> ) ) >= <NUM_LIT:0> ) && ( buff . length ( ) == <NUM_LIT:0> ) ) { comment . append ( line . substring ( <NUM_LIT:1> ) ) ; comment . append ( _config . getLineSeparator ( ) ) ; } else { handleComment ( comment ) ; if ( ! _config . isEscapeNewline ( ) || ( ( countEndingEscapes ( line ) & <NUM_LIT:1> ) == <NUM_LIT:0> ) ) { buff . append ( line ) ; line = buff . toString ( ) ; break ; } buff . append ( line . subSequence ( <NUM_LIT:0> , line . length ( ) - <NUM_LIT:1> ) ) ; } } if ( ( line == null ) && ( comment . length ( ) != <NUM_LIT:0> ) ) { handleComment ( comment ) ; } return line ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import java . io . IOException ; import java . io . InputStream ; import java . io . Reader ; import java . net . URL ; import com . izforge . izpack . util . config . base . Config ; import com . izforge . izpack . util . config . base . InvalidFileFormatException ; public class OptionsParser extends AbstractParser { private static final String COMMENTS = "<STR_LIT>" ; private static final String OPERATORS = "<STR_LIT>" ; public OptionsParser ( ) { super ( OPERATORS , COMMENTS ) ; } public static OptionsParser newInstance ( ) { return ServiceFinder . findService ( OptionsParser . class ) ; } public static OptionsParser newInstance ( Config config ) { OptionsParser instance = newInstance ( ) ; instance . setConfig ( config ) ; return instance ; } public void parse ( InputStream input , OptionsHandler handler ) throws IOException , InvalidFileFormatException { parse ( newIniSource ( input , handler ) , handler ) ; } public void parse ( Reader input , OptionsHandler handler ) throws IOException , InvalidFileFormatException { parse ( newIniSource ( input , handler ) , handler ) ; } public void parse ( URL input , OptionsHandler handler ) throws IOException , InvalidFileFormatException { parse ( newIniSource ( input , handler ) , handler ) ; } private void parse ( IniSource source , OptionsHandler handler ) throws IOException , InvalidFileFormatException { handler . startOptions ( ) ; for ( String line = source . readLine ( ) ; line != null ; line = source . readLine ( ) ) { parseOptionLine ( line , handler , source . getLineNumber ( ) ) ; } handler . endOptions ( ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; public interface BeanAccess { void propAdd ( String propertyName , String value ) ; String propDel ( String propertyName ) ; String propGet ( String propertyName ) ; String propGet ( String propertyName , int index ) ; int propLength ( String propertyName ) ; String propSet ( String propertyName , String value ) ; String propSet ( String propertyName , String value , int index ) ; } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import java . io . IOException ; import java . io . InputStream ; import java . io . Reader ; import java . net . URL ; import java . util . Locale ; import com . izforge . izpack . util . config . base . Config ; import com . izforge . izpack . util . config . base . InvalidFileFormatException ; abstract class AbstractParser { private final String _comments ; private Config _config = Config . getGlobal ( ) ; private final String _operators ; protected AbstractParser ( String operators , String comments ) { _operators = operators ; _comments = comments ; } protected Config getConfig ( ) { return _config ; } protected void setConfig ( Config value ) { _config = value ; } protected void parseError ( String line , int lineNumber ) throws InvalidFileFormatException { throw new InvalidFileFormatException ( "<STR_LIT>" + lineNumber + "<STR_LIT>" + line ) ; } IniSource newIniSource ( InputStream input , HandlerBase handler ) { return new IniSource ( input , handler , _comments , getConfig ( ) ) ; } IniSource newIniSource ( Reader input , HandlerBase handler ) { return new IniSource ( input , handler , _comments , getConfig ( ) ) ; } IniSource newIniSource ( URL input , HandlerBase handler ) throws IOException { return new IniSource ( input , handler , _comments , getConfig ( ) ) ; } void parseOptionLine ( String line , HandlerBase handler , int lineNumber ) throws InvalidFileFormatException { int idx = indexOfOperator ( line ) ; String name = null ; String value = null ; if ( idx < <NUM_LIT:0> ) { if ( getConfig ( ) . isEmptyOption ( ) ) { name = line ; } else { parseError ( line , lineNumber ) ; } } else { name = unescapeFilter ( line . substring ( <NUM_LIT:0> , idx ) ) . trim ( ) ; value = unescapeFilter ( line . substring ( idx + <NUM_LIT:1> ) ) . trim ( ) ; } if ( name . length ( ) == <NUM_LIT:0> ) { parseError ( line , lineNumber ) ; } if ( getConfig ( ) . isLowerCaseOption ( ) ) { name = name . toLowerCase ( Locale . getDefault ( ) ) ; } handler . handleOption ( name , value ) ; } String unescapeFilter ( String line ) { return getConfig ( ) . isEscape ( ) ? EscapeTool . getInstance ( ) . unescape ( line ) : line ; } private int indexOfOperator ( String line ) { int idx = - <NUM_LIT:1> ; for ( char c : _operators . toCharArray ( ) ) { int index = line . indexOf ( c ) ; if ( ( index >= <NUM_LIT:0> ) && ( ( idx == - <NUM_LIT:1> ) || ( index < idx ) ) ) { idx = index ; } } return idx ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; public interface IniHandler extends HandlerBase { void endIni ( ) ; void endSection ( ) ; @ Override void handleComment ( String comment ) ; @ Override void handleOption ( String optionName , String optionValue ) ; void startIni ( ) ; void startSection ( String sectionName ) ; } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; interface HandlerBase { void handleEmptyLine ( ) ; void handleComment ( String comment ) ; void handleOption ( String optionName , String optionValue ) ; } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import java . io . IOException ; import java . io . InputStream ; import java . io . Reader ; import java . net . URL ; import java . util . Locale ; import com . izforge . izpack . util . config . base . Config ; import com . izforge . izpack . util . config . base . InvalidFileFormatException ; public class IniParser extends AbstractParser { private static final String COMMENTS = "<STR_LIT>" ; private static final String OPERATORS = "<STR_LIT>" ; static final char SECTION_BEGIN = '<CHAR_LIT:[>' ; static final char SECTION_END = '<CHAR_LIT:]>' ; public IniParser ( ) { super ( OPERATORS , COMMENTS ) ; } public static IniParser newInstance ( ) { return ServiceFinder . findService ( IniParser . class ) ; } public static IniParser newInstance ( Config config ) { IniParser instance = newInstance ( ) ; instance . setConfig ( config ) ; return instance ; } public void parse ( InputStream input , IniHandler handler ) throws IOException , InvalidFileFormatException { parse ( newIniSource ( input , handler ) , handler ) ; } public void parse ( Reader input , IniHandler handler ) throws IOException , InvalidFileFormatException { parse ( newIniSource ( input , handler ) , handler ) ; } public void parse ( URL input , IniHandler handler ) throws IOException , InvalidFileFormatException { parse ( newIniSource ( input , handler ) , handler ) ; } private void parse ( IniSource source , IniHandler handler ) throws IOException , InvalidFileFormatException { handler . startIni ( ) ; String sectionName = null ; for ( String line = source . readLine ( ) ; line != null ; line = source . readLine ( ) ) { if ( line . charAt ( <NUM_LIT:0> ) == SECTION_BEGIN ) { if ( sectionName != null ) { handler . endSection ( ) ; } sectionName = parseSectionLine ( line , source , handler ) ; } else { if ( sectionName == null ) { if ( getConfig ( ) . isGlobalSection ( ) ) { sectionName = getConfig ( ) . getGlobalSectionName ( ) ; handler . startSection ( sectionName ) ; } else { parseError ( line , source . getLineNumber ( ) ) ; } } parseOptionLine ( line , handler , source . getLineNumber ( ) ) ; } } if ( sectionName != null ) { handler . endSection ( ) ; } handler . endIni ( ) ; } private String parseSectionLine ( String line , IniSource source , IniHandler handler ) throws InvalidFileFormatException { String sectionName ; if ( line . charAt ( line . length ( ) - <NUM_LIT:1> ) != SECTION_END ) { parseError ( line , source . getLineNumber ( ) ) ; } sectionName = unescapeFilter ( line . substring ( <NUM_LIT:1> , line . length ( ) - <NUM_LIT:1> ) . trim ( ) ) ; if ( ( sectionName . length ( ) == <NUM_LIT:0> ) && ! getConfig ( ) . isUnnamedSection ( ) ) { parseError ( line , source . getLineNumber ( ) ) ; } if ( getConfig ( ) . isLowerCaseSection ( ) ) { sectionName = sectionName . toLowerCase ( Locale . getDefault ( ) ) ; } handler . startSection ( sectionName ) ; return sectionName ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import com . izforge . izpack . util . config . base . Config ; import com . izforge . izpack . util . config . base . Ini ; import com . izforge . izpack . util . config . base . Profile ; public class IniBuilder extends AbstractProfileBuilder implements IniHandler { private Ini _ini ; public static IniBuilder newInstance ( Ini ini ) { IniBuilder instance = newInstance ( ) ; instance . setIni ( ini ) ; return instance ; } public void setIni ( Ini value ) { _ini = value ; } @ Override Config getConfig ( ) { return _ini . getConfig ( ) ; } @ Override Profile getProfile ( ) { return _ini ; } private static IniBuilder newInstance ( ) { return ServiceFinder . findService ( IniBuilder . class ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import java . io . PrintWriter ; import java . io . Writer ; import com . izforge . izpack . util . config . base . Config ; public class OptionsFormatter extends AbstractFormatter implements OptionsHandler { public static OptionsFormatter newInstance ( Writer out , Config config ) { OptionsFormatter instance = newInstance ( ) ; instance . setOutput ( ( out instanceof PrintWriter ) ? ( PrintWriter ) out : new PrintWriter ( out ) ) ; instance . setConfig ( config ) ; return instance ; } public void endOptions ( ) { getOutput ( ) . flush ( ) ; } public void startOptions ( ) { assert true ; } private static OptionsFormatter newInstance ( ) { return ServiceFinder . findService ( OptionsFormatter . class ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; public interface OptionsHandler extends HandlerBase { void endOptions ( ) ; @ Override void handleComment ( String comment ) ; @ Override void handleOption ( String optionName , String optionValue ) ; void startOptions ( ) ; } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import com . izforge . izpack . util . config . base . Config ; import com . izforge . izpack . util . config . base . Options ; public class OptionsBuilder implements OptionsHandler { private boolean _header ; private String _lastComment ; private int _emptyLines = <NUM_LIT:0> ; private Options _options ; public static OptionsBuilder newInstance ( Options opts ) { OptionsBuilder instance = newInstance ( ) ; instance . setOptions ( opts ) ; return instance ; } public void setOptions ( Options value ) { _options = value ; } @ Override public void endOptions ( ) { if ( ( _lastComment != null ) && _header ) { setHeaderComment ( ) ; } } @ Override public void handleComment ( String comment ) { if ( ( _lastComment != null ) && _header ) { setHeaderComment ( ) ; _header = false ; } _lastComment = ( _lastComment == null ? comment : _lastComment + getConfig ( ) . getLineSeparator ( ) + comment ) ; } @ Override public void handleEmptyLine ( ) { _emptyLines ++ ; } @ Override public void handleOption ( String name , String value ) { String newName = name ; if ( getConfig ( ) . isAutoNumbering ( ) && name . matches ( "<STR_LIT>" ) ) { String [ ] parts = name . split ( "<STR_LIT:\\.>" ) ; newName = name . substring ( <NUM_LIT:0> , name . length ( ) - parts [ parts . length - <NUM_LIT:1> ] . length ( ) - <NUM_LIT:1> ) + "<STR_LIT:.>" ; int pos = Integer . parseInt ( parts [ parts . length - <NUM_LIT:1> ] ) ; if ( ! _options . containsKey ( newName ) ) { _options . add ( newName , null ) ; } for ( int i = _options . getAll ( newName ) . size ( ) ; i <= pos ; i ++ ) { _options . add ( newName , null ) ; } _options . put ( newName , value , pos ) ; } else { if ( getConfig ( ) . isMultiOption ( ) ) { _options . add ( newName , value ) ; } else { _options . put ( newName , value ) ; } } if ( _emptyLines > <NUM_LIT:0> ) { if ( ! _header ) { putEmptyLines ( newName ) ; } _emptyLines = <NUM_LIT:0> ; } if ( _lastComment != null ) { if ( _header ) { setHeaderComment ( ) ; } else { putComment ( newName ) ; } _lastComment = null ; } _header = false ; } @ Override public void startOptions ( ) { if ( getConfig ( ) . isHeaderComment ( ) ) { _header = true ; } } protected static OptionsBuilder newInstance ( ) { return ServiceFinder . findService ( OptionsBuilder . class ) ; } private Config getConfig ( ) { return _options . getConfig ( ) ; } private void setHeaderComment ( ) { if ( getConfig ( ) . isComment ( ) ) { _options . setComment ( _lastComment ) ; } } private void putComment ( String key ) { if ( getConfig ( ) . isComment ( ) && _lastComment != null ) { _options . putComment ( key , _lastComment ) ; } } private void putEmptyLines ( String key ) { if ( getConfig ( ) . isEmptyLines ( ) ) { for ( int i = <NUM_LIT:0> ; i < _emptyLines ; i ++ ) { _options . addEmptyLine ( key ) ; } } } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; public class WinEscapeTool extends EscapeTool { private static final int ANSI_HEX_DIGITS = <NUM_LIT:2> ; private static final int ANSI_OCTAL_DIGITS = <NUM_LIT:3> ; private static final int OCTAL_RADIX = <NUM_LIT:8> ; private static final WinEscapeTool INSTANCE = new WinEscapeTool ( ) ; public static WinEscapeTool getInstance ( ) { return INSTANCE ; } @ Override void escapeBinary ( StringBuilder buff , char c ) { buff . append ( "<STR_LIT>" ) ; buff . append ( HEX [ ( c > > > HEX_DIGIT_3_OFFSET ) & HEX_DIGIT_MASK ] ) ; buff . append ( HEX [ c & HEX_DIGIT_MASK ] ) ; } @ Override int unescapeBinary ( StringBuilder buff , char escapeType , String line , int index ) { int ret = index ; if ( escapeType == '<CHAR_LIT>' ) { try { buff . append ( ( char ) Integer . parseInt ( line . substring ( index , index + ANSI_HEX_DIGITS ) , HEX_RADIX ) ) ; ret = index + ANSI_HEX_DIGITS ; } catch ( Exception x ) { throw new IllegalArgumentException ( "<STR_LIT>" , x ) ; } } else if ( escapeType == '<CHAR_LIT>' ) { try { buff . append ( ( char ) Integer . parseInt ( line . substring ( index , index + ANSI_OCTAL_DIGITS ) , OCTAL_RADIX ) ) ; ret = index + ANSI_OCTAL_DIGITS ; } catch ( Exception x ) { throw new IllegalArgumentException ( "<STR_LIT>" , x ) ; } } return ret ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import java . io . UnsupportedEncodingException ; import java . nio . charset . Charset ; import java . util . Arrays ; import com . izforge . izpack . util . config . base . Registry ; import com . izforge . izpack . util . config . base . Registry . Type ; public class RegEscapeTool extends EscapeTool { private static final RegEscapeTool INSTANCE = ServiceFinder . findService ( RegEscapeTool . class ) ; private static final Charset HEX_CHARSET = Charset . forName ( "<STR_LIT>" ) ; private static final int LOWER_DIGIT = <NUM_LIT> ; private static final int UPPER_DIGIT = <NUM_LIT> ; private static final int DIGIT_SIZE = <NUM_LIT:4> ; public static final RegEscapeTool getInstance ( ) { return INSTANCE ; } public TypeValuesPair decode ( String raw ) { Type type = type ( raw ) ; String value = ( type == Type . REG_SZ ) ? unquote ( raw ) : raw . substring ( type . toString ( ) . length ( ) + <NUM_LIT:1> ) ; String [ ] values ; switch ( type ) { case REG_EXPAND_SZ : case REG_MULTI_SZ : value = bytes2string ( binary ( value ) ) ; break ; case REG_DWORD : value = String . valueOf ( Long . parseLong ( value , HEX_RADIX ) ) ; break ; case REG_SZ : break ; default : break ; } if ( type == Type . REG_MULTI_SZ ) { values = splitMulti ( value ) ; } else { values = new String [ ] { value } ; } return new TypeValuesPair ( type , values ) ; } public String encode ( TypeValuesPair data ) { String ret = null ; if ( data . getType ( ) == Type . REG_SZ ) { ret = quote ( data . getValues ( ) [ <NUM_LIT:0> ] ) ; } else if ( data . getValues ( ) [ <NUM_LIT:0> ] != null ) { ret = encode ( data . getType ( ) , data . getValues ( ) ) ; } return ret ; } byte [ ] binary ( String value ) { byte [ ] bytes = new byte [ value . length ( ) ] ; int idx = <NUM_LIT:0> ; int shift = DIGIT_SIZE ; for ( int i = <NUM_LIT:0> ; i < value . length ( ) ; i ++ ) { char c = value . charAt ( i ) ; if ( Character . isWhitespace ( c ) ) { continue ; } if ( c == '<CHAR_LIT:U+002C>' ) { idx ++ ; shift = DIGIT_SIZE ; } else { int digit = Character . digit ( c , HEX_RADIX ) ; if ( digit >= <NUM_LIT:0> ) { bytes [ idx ] |= digit << shift ; shift = <NUM_LIT:0> ; } } } return Arrays . copyOfRange ( bytes , <NUM_LIT:0> , idx + <NUM_LIT:1> ) ; } String encode ( Type type , String [ ] values ) { StringBuilder buff = new StringBuilder ( ) ; buff . append ( type . toString ( ) ) ; buff . append ( Type . SEPARATOR_CHAR ) ; switch ( type ) { case REG_EXPAND_SZ : buff . append ( hexadecimal ( values [ <NUM_LIT:0> ] ) ) ; break ; case REG_DWORD : buff . append ( String . format ( "<STR_LIT>" , Long . parseLong ( values [ <NUM_LIT:0> ] ) ) ) ; break ; case REG_MULTI_SZ : int n = values . length ; for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { buff . append ( hexadecimal ( values [ i ] ) ) ; buff . append ( '<CHAR_LIT:U+002C>' ) ; } buff . append ( "<STR_LIT>" ) ; break ; default : buff . append ( values [ <NUM_LIT:0> ] ) ; break ; } return buff . toString ( ) ; } String hexadecimal ( String value ) { StringBuilder buff = new StringBuilder ( ) ; if ( ( value != null ) && ( value . length ( ) != <NUM_LIT:0> ) ) { byte [ ] bytes = string2bytes ( value ) ; for ( byte aByte : bytes ) { buff . append ( Character . forDigit ( ( aByte & UPPER_DIGIT ) > > DIGIT_SIZE , HEX_RADIX ) ) ; buff . append ( Character . forDigit ( aByte & LOWER_DIGIT , HEX_RADIX ) ) ; buff . append ( '<CHAR_LIT:U+002C>' ) ; } buff . append ( "<STR_LIT>" ) ; } return buff . toString ( ) ; } Registry . Type type ( String raw ) { Registry . Type type ; if ( raw . charAt ( <NUM_LIT:0> ) == DOUBLE_QUOTE ) { type = Registry . Type . REG_SZ ; } else { int idx = raw . indexOf ( Registry . TYPE_SEPARATOR ) ; type = ( idx < <NUM_LIT:0> ) ? Registry . Type . REG_SZ : Registry . Type . fromString ( raw . substring ( <NUM_LIT:0> , idx ) ) ; } return type ; } private String bytes2string ( byte [ ] bytes ) { String str ; try { str = new String ( bytes , <NUM_LIT:0> , bytes . length - <NUM_LIT:2> , HEX_CHARSET ) ; } catch ( NoSuchMethodError x ) { try { str = new String ( bytes , <NUM_LIT:0> , bytes . length , HEX_CHARSET . name ( ) ) ; } catch ( UnsupportedEncodingException ex ) { throw new IllegalStateException ( ex ) ; } } return str ; } private String [ ] splitMulti ( String value ) { int len = value . length ( ) ; int start ; int end ; int n = <NUM_LIT:0> ; start = <NUM_LIT:0> ; for ( end = value . indexOf ( <NUM_LIT:0> , start ) ; end >= <NUM_LIT:0> ; end = value . indexOf ( <NUM_LIT:0> , start ) ) { n ++ ; start = end + <NUM_LIT:1> ; if ( start >= len ) { break ; } } String [ ] values = new String [ n ] ; start = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { end = value . indexOf ( <NUM_LIT:0> , start ) ; values [ i ] = value . substring ( start , end ) ; start = end + <NUM_LIT:1> ; } return values ; } private byte [ ] string2bytes ( String value ) { byte [ ] bytes ; try { bytes = value . getBytes ( HEX_CHARSET ) ; } catch ( NoSuchMethodError x ) { try { bytes = value . getBytes ( HEX_CHARSET . name ( ) ) ; } catch ( UnsupportedEncodingException ex ) { throw new IllegalStateException ( ex ) ; } } return bytes ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import java . beans . Introspector ; import java . beans . PropertyChangeListener ; import java . beans . PropertyChangeSupport ; import java . beans . PropertyVetoException ; import java . beans . VetoableChangeListener ; import java . beans . VetoableChangeSupport ; import java . lang . reflect . Array ; import java . lang . reflect . InvocationHandler ; import java . lang . reflect . Method ; public abstract class AbstractBeanInvocationHandler implements InvocationHandler { private static final String PROPERTY_CHANGE_LISTENER = "<STR_LIT>" ; private static final String VETOABLE_CHANGE_LISTENER = "<STR_LIT>" ; private static final String ADD_PREFIX = "<STR_LIT>" ; private static final String READ_PREFIX = "<STR_LIT:get>" ; private static final String REMOVE_PREFIX = "<STR_LIT>" ; private static final String READ_BOOLEAN_PREFIX = "<STR_LIT>" ; private static final String WRITE_PREFIX = "<STR_LIT>" ; private static final String HAS_PREFIX = "<STR_LIT>" ; private static enum Prefix { READ ( READ_PREFIX ) , READ_BOOLEAN ( READ_BOOLEAN_PREFIX ) , WRITE ( WRITE_PREFIX ) , ADD_CHANGE ( ADD_PREFIX + PROPERTY_CHANGE_LISTENER ) , ADD_VETO ( ADD_PREFIX + VETOABLE_CHANGE_LISTENER ) , REMOVE_CHANGE ( REMOVE_PREFIX + PROPERTY_CHANGE_LISTENER ) , REMOVE_VETO ( REMOVE_PREFIX + VETOABLE_CHANGE_LISTENER ) , HAS ( HAS_PREFIX ) ; private int _len ; private String _value ; private Prefix ( String value ) { _value = value ; _len = value . length ( ) ; } public static Prefix parse ( String str ) { Prefix ret = null ; for ( Prefix p : values ( ) ) { if ( str . startsWith ( p . getValue ( ) ) ) { ret = p ; break ; } } return ret ; } public String getTail ( String input ) { return Introspector . decapitalize ( input . substring ( _len ) ) ; } public String getValue ( ) { return _value ; } } private PropertyChangeSupport _pcSupport ; private Object _proxy ; private VetoableChangeSupport _vcSupport ; @ Override public Object invoke ( Object proxy , Method method , Object [ ] args ) throws PropertyVetoException { Object ret = null ; Prefix prefix = Prefix . parse ( method . getName ( ) ) ; if ( prefix != null ) { String tail = prefix . getTail ( method . getName ( ) ) ; updateProxy ( proxy ) ; switch ( prefix ) { case READ : ret = getProperty ( prefix . getTail ( method . getName ( ) ) , method . getReturnType ( ) ) ; break ; case READ_BOOLEAN : ret = getProperty ( prefix . getTail ( method . getName ( ) ) , method . getReturnType ( ) ) ; break ; case WRITE : setProperty ( tail , args [ <NUM_LIT:0> ] , method . getParameterTypes ( ) [ <NUM_LIT:0> ] ) ; break ; case HAS : ret = Boolean . valueOf ( hasProperty ( prefix . getTail ( method . getName ( ) ) ) ) ; break ; case ADD_CHANGE : addPropertyChangeListener ( ( String ) args [ <NUM_LIT:0> ] , ( PropertyChangeListener ) args [ <NUM_LIT:1> ] ) ; break ; case ADD_VETO : addVetoableChangeListener ( ( String ) args [ <NUM_LIT:0> ] , ( VetoableChangeListener ) args [ <NUM_LIT:1> ] ) ; break ; case REMOVE_CHANGE : removePropertyChangeListener ( ( String ) args [ <NUM_LIT:0> ] , ( PropertyChangeListener ) args [ <NUM_LIT:1> ] ) ; break ; case REMOVE_VETO : removeVetoableChangeListener ( ( String ) args [ <NUM_LIT:0> ] , ( VetoableChangeListener ) args [ <NUM_LIT:1> ] ) ; break ; default : break ; } } return ret ; } protected abstract Object getPropertySpi ( String property , Class < ? > clazz ) ; protected abstract void setPropertySpi ( String property , Object value , Class < ? > clazz ) ; protected abstract boolean hasPropertySpi ( String property ) ; protected synchronized Object getProperty ( String property , Class < ? > clazz ) { Object o ; try { o = getPropertySpi ( property , clazz ) ; if ( o == null ) { o = zero ( clazz ) ; } else if ( clazz . isArray ( ) && ( o instanceof String [ ] ) && ! clazz . equals ( String [ ] . class ) ) { String [ ] str = ( String [ ] ) o ; o = Array . newInstance ( clazz . getComponentType ( ) , str . length ) ; for ( int i = <NUM_LIT:0> ; i < str . length ; i ++ ) { Array . set ( o , i , parse ( str [ i ] , clazz . getComponentType ( ) ) ) ; } } else if ( ( o instanceof String ) && ! clazz . equals ( String . class ) ) { o = parse ( ( String ) o , clazz ) ; } } catch ( Exception x ) { o = zero ( clazz ) ; } return o ; } protected synchronized void setProperty ( String property , Object value , Class < ? > clazz ) throws PropertyVetoException { boolean pc = ( _pcSupport != null ) && _pcSupport . hasListeners ( property ) ; boolean vc = ( _vcSupport != null ) && _vcSupport . hasListeners ( property ) ; Object oldVal = null ; Object newVal = ( ( value != null ) && clazz . equals ( String . class ) && ! ( value instanceof String ) ) ? value . toString ( ) : value ; if ( pc || vc ) { oldVal = getProperty ( property , clazz ) ; } if ( vc ) { fireVetoableChange ( property , oldVal , value ) ; } setPropertySpi ( property , newVal , clazz ) ; if ( pc ) { firePropertyChange ( property , oldVal , value ) ; } } protected synchronized Object getProxy ( ) { return _proxy ; } protected synchronized void addPropertyChangeListener ( String property , PropertyChangeListener listener ) { if ( _pcSupport == null ) { _pcSupport = new PropertyChangeSupport ( _proxy ) ; } _pcSupport . addPropertyChangeListener ( property , listener ) ; } protected synchronized void addVetoableChangeListener ( String property , VetoableChangeListener listener ) { if ( _vcSupport == null ) { _vcSupport = new VetoableChangeSupport ( _proxy ) ; } _vcSupport . addVetoableChangeListener ( property , listener ) ; } protected synchronized void firePropertyChange ( String property , Object oldValue , Object newValue ) { if ( _pcSupport != null ) { _pcSupport . firePropertyChange ( property , oldValue , newValue ) ; } } protected synchronized void fireVetoableChange ( String property , Object oldValue , Object newValue ) throws PropertyVetoException { if ( _vcSupport != null ) { _vcSupport . fireVetoableChange ( property , oldValue , newValue ) ; } } protected synchronized boolean hasProperty ( String property ) { boolean ret ; try { ret = hasPropertySpi ( property ) ; } catch ( Exception x ) { ret = false ; } return ret ; } protected Object parse ( String value , Class < ? > clazz ) throws IllegalArgumentException { return BeanTool . getInstance ( ) . parse ( value , clazz ) ; } protected synchronized void removePropertyChangeListener ( String property , PropertyChangeListener listener ) { if ( _pcSupport != null ) { _pcSupport . removePropertyChangeListener ( property , listener ) ; } } protected synchronized void removeVetoableChangeListener ( String property , VetoableChangeListener listener ) { if ( _vcSupport != null ) { _vcSupport . removeVetoableChangeListener ( property , listener ) ; } } protected Object zero ( Class < ? > clazz ) { return BeanTool . getInstance ( ) . zero ( clazz ) ; } private synchronized void updateProxy ( Object value ) { if ( _proxy == null ) { _proxy = value ; } } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import java . io . PrintWriter ; import java . io . Writer ; import com . izforge . izpack . util . config . base . Config ; public class IniFormatter extends AbstractFormatter implements IniHandler { public static IniFormatter newInstance ( Writer out , Config config ) { IniFormatter instance = newInstance ( ) ; instance . setOutput ( ( out instanceof PrintWriter ) ? ( PrintWriter ) out : new PrintWriter ( out ) ) ; instance . setConfig ( config ) ; return instance ; } @ Override public void endIni ( ) { getOutput ( ) . flush ( ) ; } @ Override public void endSection ( ) { getOutput ( ) . print ( getConfig ( ) . getLineSeparator ( ) ) ; } @ Override public void startIni ( ) { assert true ; } @ Override public void startSection ( String sectionName ) { setHeader ( false ) ; if ( ! getConfig ( ) . isGlobalSection ( ) || ! sectionName . equals ( getConfig ( ) . getGlobalSectionName ( ) ) ) { getOutput ( ) . print ( IniParser . SECTION_BEGIN ) ; getOutput ( ) . print ( escapeFilter ( sectionName ) ) ; getOutput ( ) . print ( IniParser . SECTION_END ) ; getOutput ( ) . print ( getConfig ( ) . getLineSeparator ( ) ) ; } } private static IniFormatter newInstance ( ) { return ServiceFinder . findService ( IniFormatter . class ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import java . io . BufferedReader ; import java . io . InputStream ; import java . io . InputStreamReader ; final class ServiceFinder { private static final String SERVICES_PATH = "<STR_LIT>" ; private ServiceFinder ( ) { } static < T > T findService ( Class < T > clazz ) { try { return clazz . cast ( findServiceClass ( clazz ) . newInstance ( ) ) ; } catch ( Exception x ) { throw ( IllegalArgumentException ) new IllegalArgumentException ( "<STR_LIT>" + clazz . getName ( ) + "<STR_LIT>" + x ) . initCause ( x ) ; } } @ SuppressWarnings ( Warnings . UNCHECKED ) static < T > Class < ? extends T > findServiceClass ( Class < T > clazz ) throws IllegalArgumentException { ClassLoader classLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; String serviceClassName = findServiceClassName ( clazz . getName ( ) ) ; Class < T > ret = clazz ; if ( serviceClassName != null ) { try { ret = ( Class < T > ) ( ( classLoader == null ) ? Class . forName ( serviceClassName ) : classLoader . loadClass ( serviceClassName ) ) ; } catch ( ClassNotFoundException x ) { throw ( IllegalArgumentException ) new IllegalArgumentException ( "<STR_LIT>" + serviceClassName + "<STR_LIT>" ) . initCause ( x ) ; } } return ret ; } static String findServiceClassName ( String serviceId ) throws IllegalArgumentException { String serviceClassName = null ; try { String systemProp = System . getProperty ( serviceId ) ; if ( systemProp != null ) { serviceClassName = systemProp ; } } catch ( SecurityException x ) { assert true ; } if ( serviceClassName == null ) { serviceClassName = loadLine ( SERVICES_PATH + serviceId ) ; } return serviceClassName ; } private static String loadLine ( String servicePath ) { String ret = null ; try { InputStream is = null ; ClassLoader classLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( classLoader == null ) { is = ClassLoader . getSystemResourceAsStream ( servicePath ) ; } else { is = classLoader . getResourceAsStream ( servicePath ) ; } if ( is != null ) { BufferedReader rd = new BufferedReader ( new InputStreamReader ( is , "<STR_LIT:UTF-8>" ) ) ; String line = rd . readLine ( ) ; rd . close ( ) ; if ( line != null ) { line = line . trim ( ) ; if ( line . length ( ) != <NUM_LIT:0> ) { ret = line . split ( "<STR_LIT>" ) [ <NUM_LIT:0> ] ; } } } } catch ( Exception x ) { assert true ; } return ret ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import com . izforge . izpack . util . config . base . Config ; import com . izforge . izpack . util . config . base . Profile ; import com . izforge . izpack . util . config . base . Reg ; import com . izforge . izpack . util . config . base . Registry . Key ; import com . izforge . izpack . util . config . base . Registry . Type ; public class RegBuilder extends AbstractProfileBuilder { private Reg _reg ; public static RegBuilder newInstance ( Reg reg ) { RegBuilder instance = newInstance ( ) ; instance . setReg ( reg ) ; return instance ; } public void setReg ( Reg value ) { _reg = value ; } @ Override public void handleEmptyLine ( ) { } @ Override public void handleOption ( String rawName , String rawValue ) { String name = ( rawName . charAt ( <NUM_LIT:0> ) == EscapeTool . DOUBLE_QUOTE ) ? RegEscapeTool . getInstance ( ) . unquote ( rawName ) : rawName ; TypeValuesPair tv = RegEscapeTool . getInstance ( ) . decode ( rawValue ) ; if ( tv . getType ( ) != Type . REG_SZ ) { ( ( Key ) getCurrentSection ( ) ) . putType ( name , tv . getType ( ) ) ; } for ( String value : tv . getValues ( ) ) { super . handleOption ( name , value ) ; } } @ Override Config getConfig ( ) { return _reg . getConfig ( ) ; } @ Override Profile getProfile ( ) { return _reg ; } private static RegBuilder newInstance ( ) { return ServiceFinder . findService ( RegBuilder . class ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import com . izforge . izpack . util . config . base . CommentedMap ; import com . izforge . izpack . util . config . base . Config ; import com . izforge . izpack . util . config . base . Ini ; import com . izforge . izpack . util . config . base . Profile ; abstract class AbstractProfileBuilder implements IniHandler { private Profile . Section _currentSection ; private boolean _header ; private String _lastComment ; private int _emptyLines = <NUM_LIT:0> ; @ Override public void endIni ( ) { if ( ( _lastComment != null ) && _header ) { setHeaderComment ( ) ; } } @ Override public void endSection ( ) { _currentSection = null ; } @ Override public void handleComment ( String comment ) { if ( ( _lastComment != null ) && _header ) { _header = false ; setHeaderComment ( ) ; } _lastComment = comment ; } @ Override public void handleEmptyLine ( ) { _emptyLines ++ ; } @ Override public void handleOption ( String name , String value ) { _header = false ; if ( getConfig ( ) . isMultiOption ( ) ) { _currentSection . add ( name , value ) ; } else { _currentSection . put ( name , value ) ; } if ( _lastComment != null ) { putComment ( _currentSection , name ) ; _lastComment = null ; } if ( _emptyLines > <NUM_LIT:0> ) { putEmptyLines ( _currentSection , name ) ; _emptyLines = <NUM_LIT:0> ; } } @ Override public void startIni ( ) { if ( getConfig ( ) . isHeaderComment ( ) ) { _header = true ; } } @ Override public void startSection ( String sectionName ) { if ( getConfig ( ) . isMultiSection ( ) ) { _currentSection = getProfile ( ) . add ( sectionName ) ; } else { Ini . Section s = getProfile ( ) . get ( sectionName ) ; _currentSection = ( s == null ) ? getProfile ( ) . add ( sectionName ) : s ; } if ( _lastComment != null ) { if ( _header ) { setHeaderComment ( ) ; } else { putComment ( getProfile ( ) , sectionName ) ; } _lastComment = null ; } if ( _emptyLines > <NUM_LIT:0> ) { if ( ! _header ) { putEmptyLines ( getProfile ( ) , sectionName ) ; } _emptyLines = <NUM_LIT:0> ; } _header = false ; } abstract Config getConfig ( ) ; abstract Profile getProfile ( ) ; Profile . Section getCurrentSection ( ) { return _currentSection ; } private void setHeaderComment ( ) { if ( getConfig ( ) . isComment ( ) ) { getProfile ( ) . setComment ( _lastComment ) ; } } private void putComment ( CommentedMap < String , ? > map , String key ) { if ( getConfig ( ) . isComment ( ) ) { map . putComment ( key , _lastComment ) ; } } private void putEmptyLines ( CommentedMap < String , ? > map , String key ) { if ( getConfig ( ) . isEmptyLines ( ) ) { for ( int i = <NUM_LIT:0> ; i < _emptyLines ; i ++ ) { map . addEmptyLine ( key ) ; } } } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; public class EscapeTool { private static final String ESCAPE_LETTERS = "<STR_LIT>" ; private static final String ESCAPEABLE_CHARS = "<STR_LIT>" ; private static final char ESCAPE_CHAR = '<STR_LIT:\\>' ; static final char [ ] HEX = "<STR_LIT>" . toCharArray ( ) ; private static final EscapeTool INSTANCE = ServiceFinder . findService ( EscapeTool . class ) ; private static final char ASCII_MIN = <NUM_LIT> ; private static final char ASCII_MAX = <NUM_LIT> ; static final int HEX_DIGIT_MASK = <NUM_LIT> ; static final int HEX_DIGIT_3_OFFSET = <NUM_LIT:4> ; static final int HEX_DIGIT_2_OFFSET = <NUM_LIT:8> ; static final int HEX_DIGIT_1_OFFSET = <NUM_LIT:12> ; static final int HEX_RADIX = <NUM_LIT:16> ; private static final int UNICODE_HEX_DIGITS = <NUM_LIT:4> ; static final char DOUBLE_QUOTE = '<CHAR_LIT:">' ; public static EscapeTool getInstance ( ) { return INSTANCE ; } public String escape ( String line ) { int len = line . length ( ) ; StringBuilder buffer = new StringBuilder ( len * <NUM_LIT:2> ) ; for ( int i = <NUM_LIT:0> ; i < len ; i ++ ) { char c = line . charAt ( i ) ; int idx = ESCAPEABLE_CHARS . indexOf ( c ) ; if ( idx >= <NUM_LIT:0> ) { buffer . append ( ESCAPE_CHAR ) ; buffer . append ( ESCAPE_LETTERS . charAt ( idx ) ) ; } else { if ( ( c < ASCII_MIN ) || ( c > ASCII_MAX ) ) { escapeBinary ( buffer , c ) ; } else { buffer . append ( c ) ; } } } return buffer . toString ( ) ; } public String quote ( String value ) { String ret = value ; if ( ( value != null ) && ( value . length ( ) != <NUM_LIT:0> ) ) { StringBuilder buff = new StringBuilder ( ) ; buff . append ( DOUBLE_QUOTE ) ; for ( int i = <NUM_LIT:0> ; i < value . length ( ) ; i ++ ) { char c = value . charAt ( i ) ; if ( ( c == ESCAPE_CHAR ) || ( c == DOUBLE_QUOTE ) ) { buff . append ( ESCAPE_CHAR ) ; } buff . append ( c ) ; } buff . append ( DOUBLE_QUOTE ) ; ret = buff . toString ( ) ; } return ret ; } public String unescape ( String line ) { int n = line . length ( ) ; StringBuilder buffer = new StringBuilder ( n ) ; int i = <NUM_LIT:0> ; while ( i < n ) { char c = line . charAt ( i ++ ) ; if ( c == ESCAPE_CHAR ) { c = line . charAt ( i ++ ) ; int next = unescapeBinary ( buffer , c , line , i ) ; if ( next == i ) { int idx = ESCAPE_LETTERS . indexOf ( c ) ; if ( idx >= <NUM_LIT:0> ) { c = ESCAPEABLE_CHARS . charAt ( idx ) ; } buffer . append ( c ) ; } else { i = next ; } } else { buffer . append ( c ) ; } } return buffer . toString ( ) ; } public String unquote ( String value ) { StringBuilder buff = new StringBuilder ( ) ; boolean escape = false ; for ( int i = <NUM_LIT:1> ; i < ( value . length ( ) - <NUM_LIT:1> ) ; i ++ ) { char c = value . charAt ( i ) ; if ( c == ESCAPE_CHAR ) { if ( ! escape ) { escape = true ; continue ; } escape = false ; } buff . append ( c ) ; } return buff . toString ( ) ; } void escapeBinary ( StringBuilder buff , char c ) { buff . append ( "<STR_LIT>" ) ; buff . append ( HEX [ ( c > > > HEX_DIGIT_1_OFFSET ) & HEX_DIGIT_MASK ] ) ; buff . append ( HEX [ ( c > > > HEX_DIGIT_2_OFFSET ) & HEX_DIGIT_MASK ] ) ; buff . append ( HEX [ ( c > > > HEX_DIGIT_3_OFFSET ) & HEX_DIGIT_MASK ] ) ; buff . append ( HEX [ c & HEX_DIGIT_MASK ] ) ; } int unescapeBinary ( StringBuilder buff , char escapeType , String line , int index ) { int ret = index ; if ( escapeType == '<CHAR_LIT>' ) { try { buff . append ( ( char ) Integer . parseInt ( line . substring ( index , index + UNICODE_HEX_DIGITS ) , HEX_RADIX ) ) ; ret = index + UNICODE_HEX_DIGITS ; } catch ( Exception x ) { throw new IllegalArgumentException ( "<STR_LIT>" , x ) ; } } return ret ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import java . beans . IntrospectionException ; import java . beans . Introspector ; import java . beans . PropertyDescriptor ; import java . io . File ; import java . lang . reflect . Array ; import java . lang . reflect . Method ; import java . lang . reflect . Proxy ; import java . net . URI ; import java . net . URL ; import java . util . TimeZone ; public class BeanTool { private static final String PARSE_METHOD = "<STR_LIT>" ; private static final BeanTool INSTANCE = ServiceFinder . findService ( BeanTool . class ) ; public static final BeanTool getInstance ( ) { return INSTANCE ; } public void inject ( Object bean , BeanAccess props ) { for ( PropertyDescriptor pd : getPropertyDescriptors ( bean . getClass ( ) ) ) { try { Method method = pd . getWriteMethod ( ) ; String name = pd . getName ( ) ; if ( ( method != null ) && ( props . propLength ( name ) != <NUM_LIT:0> ) ) { Object value ; if ( pd . getPropertyType ( ) . isArray ( ) ) { value = Array . newInstance ( pd . getPropertyType ( ) . getComponentType ( ) , props . propLength ( name ) ) ; for ( int i = <NUM_LIT:0> ; i < props . propLength ( name ) ; i ++ ) { Array . set ( value , i , parse ( props . propGet ( name , i ) , pd . getPropertyType ( ) . getComponentType ( ) ) ) ; } } else { value = parse ( props . propGet ( name ) , pd . getPropertyType ( ) ) ; } method . invoke ( bean , value ) ; } } catch ( Exception x ) { throw ( IllegalArgumentException ) ( new IllegalArgumentException ( "<STR_LIT>" + pd . getDisplayName ( ) ) . initCause ( x ) ) ; } } } public void inject ( BeanAccess props , Object bean ) { for ( PropertyDescriptor pd : getPropertyDescriptors ( bean . getClass ( ) ) ) { try { Method method = pd . getReadMethod ( ) ; if ( ( method != null ) && ! "<STR_LIT:class>" . equals ( pd . getName ( ) ) ) { Object value = method . invoke ( bean , ( Object [ ] ) null ) ; if ( value != null ) { if ( pd . getPropertyType ( ) . isArray ( ) ) { for ( int i = <NUM_LIT:0> ; i < Array . getLength ( value ) ; i ++ ) { Object v = Array . get ( value , i ) ; if ( ( v != null ) && ! v . getClass ( ) . equals ( String . class ) ) { v = v . toString ( ) ; } props . propAdd ( pd . getName ( ) , ( String ) v ) ; } } else { props . propSet ( pd . getName ( ) , value . toString ( ) ) ; } } } } catch ( Exception x ) { throw new IllegalArgumentException ( "<STR_LIT>" + pd . getDisplayName ( ) , x ) ; } } } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public < T > T parse ( String value , Class < T > clazz ) throws IllegalArgumentException { if ( clazz == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } Object o = null ; if ( value == null ) { o = zero ( clazz ) ; } else if ( clazz . isPrimitive ( ) ) { o = parsePrimitiveValue ( value , clazz ) ; } else { if ( clazz == String . class ) { o = value ; } else if ( clazz == Character . class ) { o = new Character ( value . charAt ( <NUM_LIT:0> ) ) ; } else { o = parseSpecialValue ( value , clazz ) ; } } return ( T ) o ; } public < T > T proxy ( Class < T > clazz , BeanAccess props ) { return clazz . cast ( Proxy . newProxyInstance ( Thread . currentThread ( ) . getContextClassLoader ( ) , new Class [ ] { clazz } , new BeanInvocationHandler ( props ) ) ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public < T > T zero ( Class < T > clazz ) { Object o = null ; if ( clazz . isPrimitive ( ) ) { if ( clazz == Boolean . TYPE ) { o = Boolean . FALSE ; } else if ( clazz == Byte . TYPE ) { o = Byte . valueOf ( ( byte ) <NUM_LIT:0> ) ; } else if ( clazz == Character . TYPE ) { o = new Character ( '<STR_LIT>' ) ; } else if ( clazz == Double . TYPE ) { o = new Double ( <NUM_LIT:0.0> ) ; } else if ( clazz == Float . TYPE ) { o = new Float ( <NUM_LIT:0.0f> ) ; } else if ( clazz == Integer . TYPE ) { o = Integer . valueOf ( <NUM_LIT:0> ) ; } else if ( clazz == Long . TYPE ) { o = Long . valueOf ( <NUM_LIT> ) ; } else if ( clazz == Short . TYPE ) { o = Short . valueOf ( ( short ) <NUM_LIT:0> ) ; } } return ( T ) o ; } @ SuppressWarnings ( Warnings . UNCHECKED ) protected Object parseSpecialValue ( String value , Class clazz ) throws IllegalArgumentException { Object o ; try { if ( clazz == File . class ) { o = new File ( value ) ; } else if ( clazz == URL . class ) { o = new URL ( value ) ; } else if ( clazz == URI . class ) { o = new URI ( value ) ; } else if ( clazz == Class . class ) { o = Class . forName ( value ) ; } else if ( clazz == TimeZone . class ) { o = TimeZone . getTimeZone ( value ) ; } else { Method parser = clazz . getMethod ( PARSE_METHOD , new Class [ ] { String . class } ) ; o = parser . invoke ( null , new Object [ ] { value } ) ; } } catch ( Exception x ) { throw ( IllegalArgumentException ) new IllegalArgumentException ( ) . initCause ( x ) ; } return o ; } private PropertyDescriptor [ ] getPropertyDescriptors ( Class clazz ) { try { return Introspector . getBeanInfo ( clazz ) . getPropertyDescriptors ( ) ; } catch ( IntrospectionException x ) { throw new IllegalArgumentException ( x ) ; } } private Object parsePrimitiveValue ( String value , Class clazz ) throws IllegalArgumentException { Object o = null ; try { if ( clazz == Boolean . TYPE ) { o = Boolean . valueOf ( value ) ; } else if ( clazz == Byte . TYPE ) { o = Byte . valueOf ( value ) ; } else if ( clazz == Character . TYPE ) { o = new Character ( value . charAt ( <NUM_LIT:0> ) ) ; } else if ( clazz == Double . TYPE ) { o = Double . valueOf ( value ) ; } else if ( clazz == Float . TYPE ) { o = Float . valueOf ( value ) ; } else if ( clazz == Integer . TYPE ) { o = Integer . valueOf ( value ) ; } else if ( clazz == Long . TYPE ) { o = Long . valueOf ( value ) ; } else if ( clazz == Short . TYPE ) { o = Short . valueOf ( value ) ; } } catch ( Exception x ) { throw ( IllegalArgumentException ) new IllegalArgumentException ( ) . initCause ( x ) ; } return o ; } static class BeanInvocationHandler extends AbstractBeanInvocationHandler { private final BeanAccess _backend ; BeanInvocationHandler ( BeanAccess backend ) { _backend = backend ; } @ Override protected Object getPropertySpi ( String property , Class < ? > clazz ) { Object ret = null ; if ( clazz . isArray ( ) ) { int length = _backend . propLength ( property ) ; if ( length != <NUM_LIT:0> ) { String [ ] all = new String [ length ] ; for ( int i = <NUM_LIT:0> ; i < all . length ; i ++ ) { all [ i ] = _backend . propGet ( property , i ) ; } ret = all ; } } else { ret = _backend . propGet ( property ) ; } return ret ; } @ Override protected void setPropertySpi ( String property , Object value , Class < ? > clazz ) { if ( clazz . isArray ( ) ) { _backend . propDel ( property ) ; for ( int i = <NUM_LIT:0> ; i < Array . getLength ( value ) ; i ++ ) { _backend . propAdd ( property , Array . get ( value , i ) . toString ( ) ) ; } } else { _backend . propSet ( property , value . toString ( ) ) ; } } @ Override protected boolean hasPropertySpi ( String property ) { return _backend . propLength ( property ) != <NUM_LIT:0> ; } } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import com . izforge . izpack . util . config . base . Registry . Type ; public class TypeValuesPair { private final Type _type ; private final String [ ] _values ; @ SuppressWarnings ( "<STR_LIT>" ) public TypeValuesPair ( Type type , String [ ] values ) { _type = type ; _values = values ; } public Type getType ( ) { return _type ; } public String [ ] getValues ( ) { return _values ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import java . io . PrintWriter ; import com . izforge . izpack . util . config . base . Config ; abstract class AbstractFormatter implements HandlerBase { private static final char COMMENT = '<CHAR_LIT>' ; private static final char SPACE = '<CHAR_LIT:U+0020>' ; private Config _config = Config . getGlobal ( ) ; private boolean _header = true ; private PrintWriter _output ; @ Override public void handleEmptyLine ( ) { if ( getConfig ( ) . isEmptyLines ( ) ) { getOutput ( ) . print ( getConfig ( ) . getLineSeparator ( ) ) ; } } @ Override public void handleComment ( String comment ) { if ( getConfig ( ) . isComment ( ) && ( ! _header || getConfig ( ) . isHeaderComment ( ) ) && ( comment != null ) && ( comment . length ( ) != <NUM_LIT:0> ) ) { for ( String line : comment . split ( getConfig ( ) . getLineSeparator ( ) ) ) { getOutput ( ) . print ( COMMENT ) ; getOutput ( ) . print ( line ) ; getOutput ( ) . print ( getConfig ( ) . getLineSeparator ( ) ) ; } if ( _header ) { getOutput ( ) . print ( getConfig ( ) . getLineSeparator ( ) ) ; } } _header = false ; } @ Override public void handleOption ( String optionName , String optionValue ) { final String operator = getConfig ( ) . getOperator ( ) ; if ( getConfig ( ) . isStrictOperator ( ) ) { if ( getConfig ( ) . isEmptyOption ( ) || ( optionValue != null ) ) { getOutput ( ) . print ( escapeFilter ( optionName ) ) ; getOutput ( ) . print ( operator ) ; } if ( optionValue != null ) { getOutput ( ) . print ( escapeFilter ( optionValue ) ) ; } if ( getConfig ( ) . isEmptyOption ( ) || ( optionValue != null ) ) { getOutput ( ) . print ( getConfig ( ) . getLineSeparator ( ) ) ; } } else { String value = ( ( optionValue == null ) && getConfig ( ) . isEmptyOption ( ) ) ? "<STR_LIT>" : optionValue ; final boolean isOperatorDefault = operator . equals ( Config . DEFAULT_OPERATOR ) ; if ( value != null ) { getOutput ( ) . print ( escapeFilter ( optionName ) ) ; if ( isOperatorDefault ) { getOutput ( ) . print ( SPACE ) ; } getOutput ( ) . print ( operator ) ; if ( isOperatorDefault ) { getOutput ( ) . print ( SPACE ) ; } getOutput ( ) . print ( escapeFilter ( value ) ) ; getOutput ( ) . print ( getConfig ( ) . getLineSeparator ( ) ) ; } } setHeader ( false ) ; } protected Config getConfig ( ) { return _config ; } protected void setConfig ( Config value ) { _config = value ; } protected PrintWriter getOutput ( ) { return _output ; } protected void setOutput ( PrintWriter value ) { _output = value ; } void setHeader ( boolean value ) { _header = value ; } String escapeFilter ( String input ) { return getConfig ( ) . isEscape ( ) ? EscapeTool . getInstance ( ) . escape ( input ) : input ; } } </s>
|
<s> package com . izforge . izpack . util . config . base . spi ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . PushbackInputStream ; import java . io . Reader ; import java . nio . charset . Charset ; class UnicodeInputStreamReader extends Reader { private static final int BOM_SIZE = <NUM_LIT:4> ; private static enum Bom { UTF32BE ( "<STR_LIT>" , new byte [ ] { ( byte ) <NUM_LIT:0x00> , ( byte ) <NUM_LIT:0x00> , ( byte ) <NUM_LIT> , ( byte ) <NUM_LIT> } ) , UTF32LE ( "<STR_LIT>" , new byte [ ] { ( byte ) <NUM_LIT> , ( byte ) <NUM_LIT> , ( byte ) <NUM_LIT:0x00> , ( byte ) <NUM_LIT:0x00> } ) , UTF16BE ( "<STR_LIT>" , new byte [ ] { ( byte ) <NUM_LIT> , ( byte ) <NUM_LIT> } ) , UTF16LE ( "<STR_LIT>" , new byte [ ] { ( byte ) <NUM_LIT> , ( byte ) <NUM_LIT> } ) , UTF8 ( "<STR_LIT:UTF-8>" , new byte [ ] { ( byte ) <NUM_LIT> , ( byte ) <NUM_LIT> , ( byte ) <NUM_LIT> } ) ; private final byte [ ] _bytes ; private Charset _charset ; @ SuppressWarnings ( "<STR_LIT>" ) private Bom ( String charsetName , byte [ ] bytes ) { try { _charset = Charset . forName ( charsetName ) ; } catch ( Exception x ) { _charset = null ; } _bytes = bytes ; } private static Bom find ( byte [ ] data ) { Bom ret = null ; for ( Bom bom : values ( ) ) { if ( bom . supported ( ) && bom . match ( data ) ) { ret = bom ; break ; } } return ret ; } private boolean match ( byte [ ] data ) { boolean ok = true ; for ( int i = <NUM_LIT:0> ; i < _bytes . length ; i ++ ) { if ( data [ i ] != _bytes [ i ] ) { ok = false ; break ; } } return ok ; } private boolean supported ( ) { return _charset != null ; } } private final Charset _defaultEncoding ; private InputStreamReader _reader ; private final PushbackInputStream _stream ; UnicodeInputStreamReader ( InputStream in , Charset defaultEnc ) { _stream = new PushbackInputStream ( in , BOM_SIZE ) ; _defaultEncoding = defaultEnc ; } public void close ( ) throws IOException { init ( ) ; _reader . close ( ) ; } public int read ( char [ ] cbuf , int off , int len ) throws IOException { init ( ) ; return _reader . read ( cbuf , off , len ) ; } protected void init ( ) throws IOException { if ( _reader != null ) { return ; } Charset encoding ; byte [ ] data = new byte [ BOM_SIZE ] ; int n ; int unread ; n = _stream . read ( data , <NUM_LIT:0> , data . length ) ; Bom bom = Bom . find ( data ) ; if ( bom == null ) { encoding = _defaultEncoding ; unread = n ; } else { encoding = bom . _charset ; unread = data . length - bom . _bytes . length ; } if ( unread > <NUM_LIT:0> ) { _stream . unread ( data , ( n - unread ) , unread ) ; } _reader = new InputStreamReader ( _stream , encoding ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; public interface OptionMap extends MultiMap < String , String > , CommentedMap < String , String > { < T > T getAll ( Object key , Class < T > clazz ) ; void add ( String key , Object value ) ; void add ( String key , Object value , int index ) ; < T > T as ( Class < T > clazz ) ; < T > T as ( Class < T > clazz , String keyPrefix ) ; String fetch ( Object key ) ; String fetch ( Object key , String defaultValue ) ; String fetch ( Object key , int index ) ; < T > T fetch ( Object key , Class < T > clazz ) ; < T > T fetch ( Object key , Class < T > clazz , T defaultValue ) ; < T > T fetch ( Object key , int index , Class < T > clazz ) ; < T > T fetchAll ( Object key , Class < T > clazz ) ; void from ( Object bean ) ; void from ( Object bean , String keyPrefix ) ; String get ( Object key , String defaultValue ) ; < T > T get ( Object key , Class < T > clazz ) ; < T > T get ( Object key , Class < T > clazz , T defaultValue ) ; < T > T get ( Object key , int index , Class < T > clazz ) ; String put ( String key , Object value ) ; String put ( String key , Object value , int index ) ; void putAll ( String key , Object value ) ; void to ( Object bean ) ; void to ( Object bean , String keyPrefix ) ; } </s>
|
<s> package com . izforge . izpack . util . config . base ; import com . izforge . izpack . util . config . base . spi . IniHandler ; import com . izforge . izpack . util . config . base . spi . RegEscapeTool ; import com . izforge . izpack . util . config . base . spi . TypeValuesPair ; public class BasicRegistry extends BasicProfile implements Registry { private static final long serialVersionUID = - <NUM_LIT> ; private String _version ; public BasicRegistry ( ) { _version = VERSION ; } @ Override public String getVersion ( ) { return _version ; } @ Override public void setVersion ( String value ) { _version = value ; } @ Override public Key add ( String name ) { return ( Key ) super . add ( name ) ; } @ Override public Key get ( Object key ) { return ( Key ) super . get ( key ) ; } @ Override public Key get ( Object key , int index ) { return ( Key ) super . get ( key , index ) ; } @ Override public Key put ( String key , Section value ) { return ( Key ) super . put ( key , value ) ; } @ Override public Key put ( String key , Section value , int index ) { return ( Key ) super . put ( key , value , index ) ; } @ Override public Key remove ( Section section ) { return ( Key ) super . remove ( section ) ; } @ Override public Key remove ( Object key ) { return ( Key ) super . remove ( key ) ; } @ Override public Key remove ( Object key , int index ) { return ( Key ) super . remove ( key , index ) ; } @ Override Key newSection ( String name ) { return new BasicRegistryKey ( this , name ) ; } @ Override void store ( IniHandler formatter , Section section , String option ) { store ( formatter , section . getComment ( option ) ) ; Type type = ( ( Key ) section ) . getType ( option , Type . REG_SZ ) ; String rawName = option . equals ( Key . DEFAULT_NAME ) ? option : RegEscapeTool . getInstance ( ) . quote ( option ) ; String [ ] values = new String [ section . length ( option ) ] ; for ( int i = <NUM_LIT:0> ; i < values . length ; i ++ ) { values [ i ] = section . get ( option , i ) ; } String rawValue = RegEscapeTool . getInstance ( ) . encode ( new TypeValuesPair ( type , values ) ) ; formatter . handleOption ( rawName , rawValue ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . io . * ; import java . net . URL ; import com . izforge . izpack . util . config . base . spi . IniBuilder ; import com . izforge . izpack . util . config . base . spi . IniFormatter ; import com . izforge . izpack . util . config . base . spi . IniHandler ; import com . izforge . izpack . util . config . base . spi . IniParser ; public class Ini extends BasicProfile implements Persistable , Configurable { private static final long serialVersionUID = - <NUM_LIT> ; private Config _config ; private File _file ; public Ini ( ) { _config = Config . getGlobal ( ) ; } public Ini ( Reader input ) throws IOException , InvalidFileFormatException { this ( ) ; load ( input ) ; } public Ini ( InputStream input ) throws IOException , InvalidFileFormatException { this ( ) ; load ( input ) ; } public Ini ( URL input ) throws IOException , InvalidFileFormatException { this ( ) ; load ( input ) ; } public Ini ( File input ) throws IOException , InvalidFileFormatException { this ( ) ; _file = input ; load ( ) ; } @ Override public Config getConfig ( ) { return _config ; } @ Override public void setConfig ( Config value ) { _config = value ; } @ Override public File getFile ( ) { return _file ; } @ Override public void setFile ( File value ) { _file = value ; } @ Override public void load ( ) throws IOException , InvalidFileFormatException { if ( _file == null ) { throw new FileNotFoundException ( ) ; } load ( _file ) ; } @ Override public void load ( InputStream input ) throws IOException , InvalidFileFormatException { load ( new InputStreamReader ( input , getConfig ( ) . getFileEncoding ( ) ) ) ; } @ Override public void load ( Reader input ) throws IOException , InvalidFileFormatException { IniParser . newInstance ( getConfig ( ) ) . parse ( input , newBuilder ( ) ) ; } @ Override public void load ( File input ) throws IOException , InvalidFileFormatException { load ( input . toURI ( ) . toURL ( ) ) ; } @ Override public void load ( URL input ) throws IOException , InvalidFileFormatException { IniParser . newInstance ( getConfig ( ) ) . parse ( input , newBuilder ( ) ) ; } @ Override public void store ( ) throws IOException { if ( _file == null ) { throw new FileNotFoundException ( ) ; } store ( _file ) ; } @ Override public void store ( OutputStream output ) throws IOException { store ( new OutputStreamWriter ( output , getConfig ( ) . getFileEncoding ( ) ) ) ; } @ Override public void store ( Writer output ) throws IOException { store ( IniFormatter . newInstance ( output , getConfig ( ) ) ) ; } @ Override public void store ( File output ) throws IOException { OutputStream stream = new FileOutputStream ( output ) ; store ( stream ) ; stream . close ( ) ; } protected IniHandler newBuilder ( ) { return IniBuilder . newInstance ( this ) ; } @ Override protected void store ( IniHandler formatter , Profile . Section section ) { if ( getConfig ( ) . isEmptySection ( ) || ( section . size ( ) != <NUM_LIT:0> ) ) { super . store ( formatter , section ) ; } } @ Override protected void store ( IniHandler formatter , Profile . Section section , String option , int index ) { if ( getConfig ( ) . isMultiOption ( ) || ( index == ( section . length ( option ) - <NUM_LIT:1> ) ) ) { super . store ( formatter , section , option , index ) ; } } @ Override boolean isTreeMode ( ) { return getConfig ( ) . isTree ( ) ; } @ Override char getPathSeparator ( ) { return getConfig ( ) . getPathSeparator ( ) ; } @ Override boolean isPropertyFirstUpper ( ) { return getConfig ( ) . isPropertyFirstUpper ( ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . Collection ; import java . util . HashSet ; import java . util . LinkedHashMap ; import java . util . List ; import java . util . Map ; import java . util . Set ; import com . izforge . izpack . util . config . base . spi . Warnings ; public class BasicMultiMap < K , V > implements MultiMap < K , V > , Serializable { private static final long serialVersionUID = <NUM_LIT> ; private final Map < K , List < V > > _impl ; public BasicMultiMap ( ) { this ( new LinkedHashMap < K , List < V > > ( ) ) ; } public BasicMultiMap ( Map < K , List < V > > impl ) { _impl = impl ; } @ Override public List < V > getAll ( Object key ) { return _impl . get ( key ) ; } @ Override public boolean isEmpty ( ) { return _impl . isEmpty ( ) ; } @ Override public void add ( K key , V value ) { getList ( key , true ) . add ( value ) ; } @ Override public void add ( K key , V value , int index ) { getList ( key , true ) . add ( index , value ) ; } @ Override public void clear ( ) { _impl . clear ( ) ; } @ Override public boolean containsKey ( Object key ) { return _impl . containsKey ( key ) ; } @ Override public boolean containsValue ( Object value ) { boolean ret = false ; for ( List < V > all : _impl . values ( ) ) { if ( all . contains ( value ) ) { ret = true ; break ; } } return ret ; } @ Override public Set < Entry < K , V > > entrySet ( ) { Set < Entry < K , V > > ret = new HashSet < Entry < K , V > > ( ) ; for ( K key : keySet ( ) ) { ret . add ( new ShadowEntry ( key ) ) ; } return ret ; } @ Override public V get ( Object key ) { List < V > values = getList ( key , false ) ; return ( values == null ) ? null : values . get ( values . size ( ) - <NUM_LIT:1> ) ; } @ Override public V get ( Object key , int index ) { List < V > values = getList ( key , false ) ; return ( values == null ) ? null : values . get ( index ) ; } @ Override public Set < K > keySet ( ) { return _impl . keySet ( ) ; } @ Override public int length ( Object key ) { List < V > values = getList ( key , false ) ; return ( values == null ) ? <NUM_LIT:0> : values . size ( ) ; } @ Override public V put ( K key , V value ) { V ret = null ; List < V > values = getList ( key , true ) ; if ( values . isEmpty ( ) ) { values . add ( value ) ; } else { ret = values . set ( values . size ( ) - <NUM_LIT:1> , value ) ; } return ret ; } @ Override public V put ( K key , V value , int index ) { return getList ( key , false ) . set ( index , value ) ; } @ SuppressWarnings ( Warnings . UNCHECKED ) @ Override public void putAll ( Map < ? extends K , ? extends V > map ) { if ( map instanceof MultiMap ) { MultiMap < K , V > mm = ( MultiMap < K , V > ) map ; for ( Object key : mm . keySet ( ) ) { putAll ( ( K ) key , mm . getAll ( key ) ) ; } } else { for ( K key : map . keySet ( ) ) { put ( key , map . get ( key ) ) ; } } } @ Override public List < V > putAll ( K key , List < V > values ) { List < V > ret = _impl . get ( key ) ; _impl . put ( key , new ArrayList < V > ( values ) ) ; return ret ; } @ Override public V remove ( Object key ) { List < V > prev = _impl . remove ( key ) ; return ( prev == null ) ? null : prev . get ( <NUM_LIT:0> ) ; } @ Override public V remove ( Object key , int index ) { V ret = null ; List < V > values = getList ( key , false ) ; if ( values != null ) { ret = values . remove ( index ) ; if ( values . isEmpty ( ) ) { _impl . remove ( key ) ; } } return ret ; } @ Override public int size ( ) { return _impl . size ( ) ; } @ Override public String toString ( ) { return _impl . toString ( ) ; } @ Override public Collection < V > values ( ) { List < V > all = new ArrayList < V > ( _impl . size ( ) ) ; for ( List < V > values : _impl . values ( ) ) { all . addAll ( values ) ; } return all ; } @ SuppressWarnings ( Warnings . UNCHECKED ) private List < V > getList ( Object key , boolean create ) { List < V > values = _impl . get ( key ) ; if ( ( values == null ) && create ) { values = new ArrayList < V > ( ) ; _impl . put ( ( K ) key , values ) ; } return values ; } class ShadowEntry implements Map . Entry < K , V > { private final K _key ; ShadowEntry ( K key ) { _key = key ; } @ Override public K getKey ( ) { return _key ; } @ Override public V getValue ( ) { return get ( _key ) ; } @ Override public V setValue ( V value ) { return put ( _key , value ) ; } } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . util . ArrayList ; import java . util . List ; import java . util . regex . Pattern ; class BasicProfileSection extends BasicOptionMap implements Profile . Section { private static final long serialVersionUID = <NUM_LIT> ; private static final String [ ] EMPTY_STRING_ARRAY = { } ; private static final char REGEXP_ESCAPE_CHAR = '<STR_LIT:\\>' ; private final Pattern _childPattern ; private final String _name ; private final BasicProfile _profile ; protected BasicProfileSection ( BasicProfile profile , String name ) { _profile = profile ; _name = name ; _childPattern = newChildPattern ( name ) ; } @ Override public Profile . Section getChild ( String key ) { return _profile . get ( childName ( key ) ) ; } @ Override public String getName ( ) { return _name ; } @ Override public Profile . Section getParent ( ) { Profile . Section ret = null ; int idx = _name . lastIndexOf ( _profile . getPathSeparator ( ) ) ; if ( idx >= <NUM_LIT:0> ) { String name = _name . substring ( <NUM_LIT:0> , idx ) ; ret = _profile . get ( name ) ; } return ret ; } @ Override public String getSimpleName ( ) { int idx = _name . lastIndexOf ( _profile . getPathSeparator ( ) ) ; return ( idx < <NUM_LIT:0> ) ? _name : _name . substring ( idx + <NUM_LIT:1> ) ; } @ Override public Profile . Section addChild ( String key ) { String name = childName ( key ) ; return _profile . add ( name ) ; } @ Override public String [ ] childrenNames ( ) { List < String > names = new ArrayList < String > ( ) ; for ( String key : _profile . keySet ( ) ) { if ( _childPattern . matcher ( key ) . matches ( ) ) { names . add ( key . substring ( _name . length ( ) + <NUM_LIT:1> ) ) ; } } return names . toArray ( EMPTY_STRING_ARRAY ) ; } @ Override public Profile . Section lookup ( String ... parts ) { StringBuilder buff = new StringBuilder ( ) ; for ( String part : parts ) { if ( buff . length ( ) != <NUM_LIT:0> ) { buff . append ( _profile . getPathSeparator ( ) ) ; } buff . append ( part ) ; } return _profile . get ( childName ( buff . toString ( ) ) ) ; } @ Override public void removeChild ( String key ) { String name = childName ( key ) ; _profile . remove ( name ) ; } @ Override boolean isPropertyFirstUpper ( ) { return _profile . isPropertyFirstUpper ( ) ; } @ Override void resolve ( StringBuilder buffer ) { _profile . resolve ( buffer , this ) ; } private String childName ( String key ) { StringBuilder buff = new StringBuilder ( _name ) ; buff . append ( _profile . getPathSeparator ( ) ) ; buff . append ( key ) ; return buff . toString ( ) ; } private Pattern newChildPattern ( String name ) { StringBuilder buff = new StringBuilder ( ) ; buff . append ( '<CHAR_LIT>' ) ; buff . append ( Pattern . quote ( name ) ) ; buff . append ( REGEXP_ESCAPE_CHAR ) ; buff . append ( _profile . getPathSeparator ( ) ) ; buff . append ( "<STR_LIT>" ) ; buff . append ( REGEXP_ESCAPE_CHAR ) ; buff . append ( _profile . getPathSeparator ( ) ) ; buff . append ( "<STR_LIT>" ) ; return Pattern . compile ( buff . toString ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . util . Map ; public interface CommentedMap < K , V > extends Map < K , V > { String getComment ( Object key ) ; String putComment ( K key , String comment ) ; String removeComment ( Object key ) ; int getNewLineCount ( Object key ) ; Integer addEmptyLine ( K key ) ; } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . io . IOException ; public class InvalidFileFormatException extends IOException { private static final long serialVersionUID = - <NUM_LIT> ; public InvalidFileFormatException ( String message ) { super ( message ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . io . Serializable ; import java . nio . charset . Charset ; @ SuppressWarnings ( "<STR_LIT>" ) public class Config implements Cloneable , Serializable { public static final String KEY_PREFIX = "<STR_LIT>" ; public static final String PROP_EMPTY_OPTION = "<STR_LIT>" ; public static final String PROP_EMPTY_SECTION = "<STR_LIT>" ; public static final String PROP_GLOBAL_SECTION = "<STR_LIT>" ; public static final String PROP_GLOBAL_SECTION_NAME = "<STR_LIT>" ; public static final String PROP_INCLUDE = "<STR_LIT>" ; public static final String PROP_LOWER_CASE_OPTION = "<STR_LIT>" ; public static final String PROP_LOWER_CASE_SECTION = "<STR_LIT>" ; public static final String PROP_MULTI_OPTION = "<STR_LIT>" ; public static final String PROP_MULTI_SECTION = "<STR_LIT>" ; public static final String PROP_STRICT_OPERATOR = "<STR_LIT>" ; public static final String PROP_OPERATOR = "<STR_LIT>" ; public static final String PROP_UNNAMED_SECTION = "<STR_LIT>" ; public static final String PROP_ESCAPE = "<STR_LIT>" ; public static final String PROP_ESCAPE_NEWLINE = "<STR_LIT>" ; public static final String PROP_PATH_SEPARATOR = "<STR_LIT>" ; public static final String PROP_TREE = "<STR_LIT>" ; public static final String PROP_PROPERTY_FIRST_UPPER = "<STR_LIT>" ; public static final String PROP_FILE_ENCODING = "<STR_LIT>" ; public static final String PROP_LINE_SEPARATOR = "<STR_LIT>" ; public static final String PROP_COMMENT = "<STR_LIT>" ; public static final String PROP_HEADER_COMMENT = "<STR_LIT>" ; public static final String PROP_EMPTY_LINES = "<STR_LIT>" ; public static final String PROP_AUTO_NUMBERING = "<STR_LIT>" ; public static final boolean DEFAULT_EMPTY_OPTION = false ; public static final boolean DEFAULT_EMPTY_SECTION = false ; public static final boolean DEFAULT_GLOBAL_SECTION = false ; public static final String DEFAULT_GLOBAL_SECTION_NAME = "<STR_LIT:?>" ; public static final boolean DEFAULT_INCLUDE = false ; public static final boolean DEFAULT_LOWER_CASE_OPTION = false ; public static final boolean DEFAULT_LOWER_CASE_SECTION = false ; public static final boolean DEFAULT_MULTI_OPTION = true ; public static final boolean DEFAULT_MULTI_SECTION = false ; public static final boolean DEFAULT_STRICT_OPERATOR = false ; public static final boolean DEFAULT_UNNAMED_SECTION = false ; public static final boolean DEFAULT_ESCAPE = true ; public static final boolean DEFAULT_ESCAPE_NEWLINE = true ; public static final boolean DEFAULT_TREE = true ; public static final boolean DEFAULT_PROPERTY_FIRST_UPPER = false ; public static final boolean DEFAULT_COMMENT = true ; public static final boolean DEFAULT_HEADER_COMMENT = true ; public static final boolean DEFAULT_EMPTY_LINES = false ; public static final boolean DEFAULT_AUTO_NUMBERING = false ; public static final char DEFAULT_PATH_SEPARATOR = '<CHAR_LIT:/>' ; public static final String DEFAULT_LINE_SEPARATOR = getSystemProperty ( "<STR_LIT>" , "<STR_LIT:n>" ) ; public static final String DEFAULT_OPERATOR = "<STR_LIT:=>" ; public static final Charset DEFAULT_FILE_ENCODING = Charset . forName ( "<STR_LIT:UTF-8>" ) ; private static final Config GLOBAL = new Config ( ) ; private static final long serialVersionUID = <NUM_LIT> ; private boolean _comment ; private boolean _emptyOption ; private boolean _emptySection ; private boolean _escape ; private boolean _escapeNewline ; private Charset _fileEncoding ; private boolean _globalSection ; private String _globalSectionName ; private boolean _headerComment ; private boolean _include ; private String _lineSeparator ; private boolean _lowerCaseOption ; private boolean _lowerCaseSection ; private boolean _multiOption ; private boolean _multiSection ; private char _pathSeparator ; private boolean _propertyFirstUpper ; private boolean _strictOperator ; private String _operator ; private boolean _tree ; private boolean _unnamedSection ; private boolean _emptyLines ; private boolean _autoNumbering ; public Config ( ) { reset ( ) ; } public static String getEnvironment ( String name ) { return getEnvironment ( name , null ) ; } public static String getEnvironment ( String name , String defaultValue ) { String value ; try { value = System . getenv ( name ) ; } catch ( SecurityException x ) { value = null ; } return ( value == null ) ? defaultValue : value ; } public static Config getGlobal ( ) { return GLOBAL ; } public static String getSystemProperty ( String name ) { return getSystemProperty ( name , null ) ; } public static String getSystemProperty ( String name , String defaultValue ) { String value ; try { value = System . getProperty ( name ) ; } catch ( SecurityException x ) { value = null ; } return ( value == null ) ? defaultValue : value ; } public void setComment ( boolean value ) { _comment = value ; } public boolean isEscape ( ) { return _escape ; } public boolean isEscapeNewline ( ) { return _escapeNewline ; } public boolean isInclude ( ) { return _include ; } public boolean isTree ( ) { return _tree ; } public void setEmptyOption ( boolean value ) { _emptyOption = value ; } public void setEmptySection ( boolean value ) { _emptySection = value ; } public void setEscape ( boolean value ) { _escape = value ; } public void setEscapeNewline ( boolean value ) { _escapeNewline = value ; } public Charset getFileEncoding ( ) { return _fileEncoding ; } public void setFileEncoding ( Charset value ) { _fileEncoding = value ; } public void setGlobalSection ( boolean value ) { _globalSection = value ; } public String getGlobalSectionName ( ) { return _globalSectionName ; } public void setGlobalSectionName ( String value ) { _globalSectionName = value ; } public void setHeaderComment ( boolean value ) { _headerComment = value ; } public void setEmptyLines ( boolean value ) { _emptyLines = value ; } public void setAutoNumbering ( boolean value ) { _autoNumbering = value ; } public void setInclude ( boolean value ) { _include = value ; } public String getLineSeparator ( ) { return _lineSeparator ; } public void setLineSeparator ( String value ) { _lineSeparator = value ; } public void setLowerCaseOption ( boolean value ) { _lowerCaseOption = value ; } public void setLowerCaseSection ( boolean value ) { _lowerCaseSection = value ; } public void setMultiOption ( boolean value ) { _multiOption = value ; } public void setMultiSection ( boolean value ) { _multiSection = value ; } public boolean isEmptyOption ( ) { return _emptyOption ; } public boolean isEmptySection ( ) { return _emptySection ; } public boolean isGlobalSection ( ) { return _globalSection ; } public boolean isLowerCaseOption ( ) { return _lowerCaseOption ; } public boolean isLowerCaseSection ( ) { return _lowerCaseSection ; } public boolean isMultiOption ( ) { return _multiOption ; } public boolean isMultiSection ( ) { return _multiSection ; } public boolean isUnnamedSection ( ) { return _unnamedSection ; } public char getPathSeparator ( ) { return _pathSeparator ; } public void setPathSeparator ( char value ) { _pathSeparator = value ; } public void setPropertyFirstUpper ( boolean value ) { _propertyFirstUpper = value ; } public boolean isPropertyFirstUpper ( ) { return _propertyFirstUpper ; } public boolean isStrictOperator ( ) { return _strictOperator ; } public void setStrictOperator ( boolean value ) { _strictOperator = value ; } public String getOperator ( ) { return _operator ; } public void setOperator ( String _operator ) { this . _operator = _operator ; } public boolean isComment ( ) { return _comment ; } public boolean isHeaderComment ( ) { return _headerComment ; } public boolean isEmptyLines ( ) { return _emptyLines ; } public boolean isAutoNumbering ( ) { return _autoNumbering ; } public void setTree ( boolean value ) { _tree = value ; } public void setUnnamedSection ( boolean value ) { _unnamedSection = value ; } @ Override public Config clone ( ) { try { return ( Config ) super . clone ( ) ; } catch ( CloneNotSupportedException x ) { throw new AssertionError ( x ) ; } } public final void reset ( ) { _emptyOption = getBoolean ( PROP_EMPTY_OPTION , DEFAULT_EMPTY_OPTION ) ; _emptySection = getBoolean ( PROP_EMPTY_SECTION , DEFAULT_EMPTY_SECTION ) ; _globalSection = getBoolean ( PROP_GLOBAL_SECTION , DEFAULT_GLOBAL_SECTION ) ; _globalSectionName = getString ( PROP_GLOBAL_SECTION_NAME , DEFAULT_GLOBAL_SECTION_NAME ) ; _include = getBoolean ( PROP_INCLUDE , DEFAULT_INCLUDE ) ; _lowerCaseOption = getBoolean ( PROP_LOWER_CASE_OPTION , DEFAULT_LOWER_CASE_OPTION ) ; _lowerCaseSection = getBoolean ( PROP_LOWER_CASE_SECTION , DEFAULT_LOWER_CASE_SECTION ) ; _multiOption = getBoolean ( PROP_MULTI_OPTION , DEFAULT_MULTI_OPTION ) ; _multiSection = getBoolean ( PROP_MULTI_SECTION , DEFAULT_MULTI_SECTION ) ; _strictOperator = getBoolean ( PROP_STRICT_OPERATOR , DEFAULT_STRICT_OPERATOR ) ; _operator = getString ( PROP_OPERATOR , DEFAULT_OPERATOR ) ; _unnamedSection = getBoolean ( PROP_UNNAMED_SECTION , DEFAULT_UNNAMED_SECTION ) ; _escape = getBoolean ( PROP_ESCAPE , DEFAULT_ESCAPE ) ; _escapeNewline = getBoolean ( PROP_ESCAPE_NEWLINE , DEFAULT_ESCAPE_NEWLINE ) ; _pathSeparator = getChar ( PROP_PATH_SEPARATOR , DEFAULT_PATH_SEPARATOR ) ; _tree = getBoolean ( PROP_TREE , DEFAULT_TREE ) ; _propertyFirstUpper = getBoolean ( PROP_PROPERTY_FIRST_UPPER , DEFAULT_PROPERTY_FIRST_UPPER ) ; _lineSeparator = getString ( PROP_LINE_SEPARATOR , DEFAULT_LINE_SEPARATOR ) ; _fileEncoding = getCharset ( PROP_FILE_ENCODING , DEFAULT_FILE_ENCODING ) ; _comment = getBoolean ( PROP_COMMENT , DEFAULT_COMMENT ) ; _headerComment = getBoolean ( PROP_HEADER_COMMENT , DEFAULT_HEADER_COMMENT ) ; _emptyLines = getBoolean ( PROP_EMPTY_LINES , DEFAULT_EMPTY_LINES ) ; _autoNumbering = getBoolean ( PROP_AUTO_NUMBERING , DEFAULT_AUTO_NUMBERING ) ; } private boolean getBoolean ( String name , boolean defaultValue ) { String value = getSystemProperty ( KEY_PREFIX + name ) ; return ( value == null ) ? defaultValue : Boolean . parseBoolean ( value ) ; } private char getChar ( String name , char defaultValue ) { String value = getSystemProperty ( KEY_PREFIX + name ) ; return ( value == null ) ? defaultValue : value . charAt ( <NUM_LIT:0> ) ; } private Charset getCharset ( String name , Charset defaultValue ) { String value = getSystemProperty ( KEY_PREFIX + name ) ; return ( value == null ) ? defaultValue : Charset . forName ( value ) ; } private String getString ( String name , String defaultValue ) { return getSystemProperty ( KEY_PREFIX + name , defaultValue ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; import java . io . Reader ; import java . io . Writer ; import java . net . URL ; public interface Persistable { File getFile ( ) ; void setFile ( File value ) ; void load ( ) throws IOException , InvalidFileFormatException ; void load ( InputStream input ) throws IOException , InvalidFileFormatException ; void load ( Reader input ) throws IOException , InvalidFileFormatException ; void load ( File input ) throws IOException , InvalidFileFormatException ; void load ( URL input ) throws IOException , InvalidFileFormatException ; void store ( ) throws IOException ; void store ( OutputStream output ) throws IOException ; void store ( Writer output ) throws IOException ; void store ( File output ) throws IOException ; } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . nio . charset . Charset ; import java . util . HashMap ; import java . util . Map ; public interface Registry extends Profile { enum Hive { HKEY_CLASSES_ROOT , HKEY_CURRENT_CONFIG , HKEY_CURRENT_USER , HKEY_LOCAL_MACHINE , HKEY_USERS ; } enum Type { REG_NONE ( "<STR_LIT>" ) , REG_SZ ( "<STR_LIT>" ) , REG_EXPAND_SZ ( "<STR_LIT>" ) , REG_BINARY ( "<STR_LIT>" ) , REG_DWORD ( "<STR_LIT>" ) , REG_DWORD_BIG_ENDIAN ( "<STR_LIT>" ) , REG_LINK ( "<STR_LIT>" ) , REG_MULTI_SZ ( "<STR_LIT>" ) , REG_RESOURCE_LIST ( "<STR_LIT>" ) , REG_FULL_RESOURCE_DESCRIPTOR ( "<STR_LIT>" ) , REG_RESOURCE_REQUIREMENTS_LIST ( "<STR_LIT>" ) , REG_QWORD ( "<STR_LIT>" ) ; private static final Map < String , Type > MAPPING ; static { MAPPING = new HashMap < String , Type > ( ) ; for ( Type t : values ( ) ) { MAPPING . put ( t . toString ( ) , t ) ; } } public static final char SEPARATOR_CHAR = '<CHAR_LIT::>' ; public static final String SEPARATOR = String . valueOf ( SEPARATOR_CHAR ) ; public static final char REMOVE_CHAR = '<CHAR_LIT:->' ; public static final String REMOVE = String . valueOf ( REMOVE_CHAR ) ; private final String _prefix ; private Type ( String prefix ) { _prefix = prefix ; } public static Type fromString ( String str ) { return MAPPING . get ( str ) ; } @ Override public String toString ( ) { return _prefix ; } } char ESCAPE_CHAR = '<STR_LIT:\\>' ; Charset FILE_ENCODING = Charset . forName ( "<STR_LIT>" ) ; char KEY_SEPARATOR = '<STR_LIT:\\>' ; String LINE_SEPARATOR = "<STR_LIT>" ; char TYPE_SEPARATOR = '<CHAR_LIT::>' ; String VERSION = "<STR_LIT>" ; String getVersion ( ) ; void setVersion ( String value ) ; @ Override Key get ( Object key ) ; @ Override Key get ( Object key , int index ) ; @ Override Key put ( String key , Section value ) ; @ Override Key put ( String key , Section value , int index ) ; @ Override Key remove ( Object key ) ; @ Override Key remove ( Object key , int index ) ; interface Key extends Section { String DEFAULT_NAME = "<STR_LIT:@>" ; @ Override Key getChild ( String key ) ; @ Override Key getParent ( ) ; Type getType ( Object key ) ; Type getType ( Object key , Type defaulType ) ; @ Override Key addChild ( String key ) ; @ Override Key lookup ( String ... path ) ; Type putType ( String key , Type type ) ; Type removeType ( Object key ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . io . * ; import java . net . URL ; import com . izforge . izpack . util . config . base . spi . IniFormatter ; import com . izforge . izpack . util . config . base . spi . IniHandler ; import com . izforge . izpack . util . config . base . spi . IniParser ; import com . izforge . izpack . util . config . base . spi . RegBuilder ; public class Reg extends BasicRegistry implements Registry , Persistable , Configurable { private static final long serialVersionUID = - <NUM_LIT> ; protected static final String DEFAULT_SUFFIX = "<STR_LIT>" ; protected static final String TMP_PREFIX = "<STR_LIT>" ; private static final int STDERR_BUFF_SIZE = <NUM_LIT> ; private static final String PROP_OS_NAME = "<STR_LIT>" ; private static final boolean WINDOWS = Config . getSystemProperty ( PROP_OS_NAME , "<STR_LIT>" ) . startsWith ( "<STR_LIT>" ) ; private static final char CR = '<STR_LIT>' ; private static final char LF = '<STR_LIT:\n>' ; private Config _config ; private File _file ; public Reg ( ) { Config cfg = Config . getGlobal ( ) . clone ( ) ; cfg . setEscape ( false ) ; cfg . setGlobalSection ( false ) ; cfg . setEmptyOption ( true ) ; cfg . setMultiOption ( true ) ; cfg . setStrictOperator ( true ) ; cfg . setEmptySection ( true ) ; cfg . setPathSeparator ( KEY_SEPARATOR ) ; cfg . setFileEncoding ( FILE_ENCODING ) ; cfg . setLineSeparator ( LINE_SEPARATOR ) ; _config = cfg ; } public Reg ( String registryKey ) throws IOException { this ( ) ; read ( registryKey ) ; } public Reg ( File input ) throws IOException , InvalidFileFormatException { this ( ) ; _file = input ; load ( ) ; } public Reg ( URL input ) throws IOException , InvalidFileFormatException { this ( ) ; load ( input ) ; } public Reg ( InputStream input ) throws IOException , InvalidFileFormatException { this ( ) ; load ( input ) ; } public Reg ( Reader input ) throws IOException , InvalidFileFormatException { this ( ) ; load ( input ) ; } public static boolean isWindows ( ) { return WINDOWS ; } @ Override public Config getConfig ( ) { return _config ; } public void setConfig ( Config value ) { _config = value ; } @ Override public File getFile ( ) { return _file ; } @ Override public void setFile ( File value ) { _file = value ; } @ Override public void load ( ) throws IOException , InvalidFileFormatException { if ( _file == null ) { throw new FileNotFoundException ( ) ; } load ( _file ) ; } @ Override public void load ( InputStream input ) throws IOException , InvalidFileFormatException { load ( new InputStreamReader ( input , getConfig ( ) . getFileEncoding ( ) ) ) ; } @ Override public void load ( URL input ) throws IOException , InvalidFileFormatException { load ( new InputStreamReader ( input . openStream ( ) , getConfig ( ) . getFileEncoding ( ) ) ) ; } @ Override public void load ( Reader input ) throws IOException , InvalidFileFormatException { int newline = <NUM_LIT:2> ; StringBuilder buff = new StringBuilder ( ) ; for ( int c = input . read ( ) ; c != - <NUM_LIT:1> ; c = input . read ( ) ) { if ( c == LF ) { newline -- ; if ( newline == <NUM_LIT:0> ) { break ; } } else if ( ( c != CR ) && ( newline != <NUM_LIT:1> ) ) { buff . append ( ( char ) c ) ; } } if ( buff . length ( ) == <NUM_LIT:0> ) { throw new InvalidFileFormatException ( "<STR_LIT>" ) ; } if ( ! buff . toString ( ) . equals ( getVersion ( ) ) ) { throw new InvalidFileFormatException ( "<STR_LIT>" + buff . toString ( ) ) ; } IniParser . newInstance ( getConfig ( ) ) . parse ( input , newBuilder ( ) ) ; } @ Override public void load ( File input ) throws IOException , InvalidFileFormatException { load ( input . toURI ( ) . toURL ( ) ) ; } public void read ( String registryKey ) throws IOException { File tmp = createTempFile ( ) ; try { regExport ( registryKey , tmp ) ; load ( tmp ) ; } finally { tmp . delete ( ) ; } } @ Override public void store ( ) throws IOException { if ( _file == null ) { throw new FileNotFoundException ( ) ; } store ( _file ) ; } @ Override public void store ( OutputStream output ) throws IOException { store ( new OutputStreamWriter ( output , getConfig ( ) . getFileEncoding ( ) ) ) ; } @ Override public void store ( Writer output ) throws IOException { output . write ( getVersion ( ) ) ; output . write ( getConfig ( ) . getLineSeparator ( ) ) ; output . write ( getConfig ( ) . getLineSeparator ( ) ) ; store ( IniFormatter . newInstance ( output , getConfig ( ) ) ) ; } @ Override public void store ( File output ) throws IOException { OutputStream stream = new FileOutputStream ( output ) ; store ( stream ) ; stream . close ( ) ; } public void write ( ) throws IOException { File tmp = createTempFile ( ) ; try { store ( tmp ) ; regImport ( tmp ) ; } finally { tmp . delete ( ) ; } } protected IniHandler newBuilder ( ) { return RegBuilder . newInstance ( this ) ; } @ Override boolean isTreeMode ( ) { return getConfig ( ) . isTree ( ) ; } @ Override char getPathSeparator ( ) { return getConfig ( ) . getPathSeparator ( ) ; } @ Override boolean isPropertyFirstUpper ( ) { return getConfig ( ) . isPropertyFirstUpper ( ) ; } void exec ( String [ ] args ) throws IOException { Process proc = Runtime . getRuntime ( ) . exec ( args ) ; try { int status = proc . waitFor ( ) ; if ( status != <NUM_LIT:0> ) { Reader in = new InputStreamReader ( proc . getErrorStream ( ) ) ; char [ ] buff = new char [ STDERR_BUFF_SIZE ] ; int n = in . read ( buff ) ; in . close ( ) ; throw new IOException ( new String ( buff , <NUM_LIT:0> , n ) . trim ( ) ) ; } } catch ( InterruptedException x ) { throw ( IOException ) ( new InterruptedIOException ( ) . initCause ( x ) ) ; } } private File createTempFile ( ) throws IOException { File ret = File . createTempFile ( TMP_PREFIX , DEFAULT_SUFFIX ) ; ret . deleteOnExit ( ) ; return ret ; } private void regExport ( String registryKey , File file ) throws IOException { requireWindows ( ) ; exec ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , registryKey , file . getAbsolutePath ( ) } ) ; } private void regImport ( File file ) throws IOException { requireWindows ( ) ; exec ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , file . getAbsolutePath ( ) } ) ; } private void requireWindows ( ) { if ( ! WINDOWS ) { throw new UnsupportedOperationException ( "<STR_LIT>" ) ; } } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . lang . reflect . Array ; import java . lang . reflect . Proxy ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import com . izforge . izpack . util . config . base . spi . AbstractBeanInvocationHandler ; import com . izforge . izpack . util . config . base . spi . BeanTool ; import com . izforge . izpack . util . config . base . spi . IniHandler ; public class BasicProfile extends CommonMultiMap < String , Profile . Section > implements Profile { private static final String SECTION_SYSTEM_PROPERTIES = "<STR_LIT>" ; private static final String SECTION_ENVIRONMENT = "<STR_LIT>" ; private static final Pattern EXPRESSION = Pattern . compile ( "<STR_LIT>" ) ; private static final int G_SECTION = <NUM_LIT:2> ; private static final int G_SECTION_IDX = <NUM_LIT:4> ; private static final int G_OPTION = <NUM_LIT:5> ; private static final int G_OPTION_IDX = <NUM_LIT:7> ; private static final long serialVersionUID = - <NUM_LIT> ; private String _comment ; private final boolean _propertyFirstUpper ; private final boolean _treeMode ; public BasicProfile ( ) { this ( false , false ) ; } public BasicProfile ( boolean treeMode , boolean propertyFirstUpper ) { _treeMode = treeMode ; _propertyFirstUpper = propertyFirstUpper ; } @ Override public String getComment ( ) { return _comment ; } @ Override public void setComment ( String value ) { _comment = value ; } @ Override public Section add ( String name ) { if ( isTreeMode ( ) ) { int idx = name . lastIndexOf ( getPathSeparator ( ) ) ; if ( idx > <NUM_LIT:0> ) { String parent = name . substring ( <NUM_LIT:0> , idx ) ; if ( ! containsKey ( parent ) ) { add ( parent ) ; } } } Section section = newSection ( name ) ; add ( name , section ) ; return section ; } @ Override public void add ( String section , String option , Object value ) { getOrAdd ( section ) . add ( option , value ) ; } @ Override public < T > T as ( Class < T > clazz ) { return as ( clazz , null ) ; } @ Override public < T > T as ( Class < T > clazz , String prefix ) { return clazz . cast ( Proxy . newProxyInstance ( Thread . currentThread ( ) . getContextClassLoader ( ) , new Class [ ] { clazz } , new BeanInvocationHandler ( prefix ) ) ) ; } @ Override public String fetch ( Object sectionName , Object optionName ) { Section sec = get ( sectionName ) ; return ( sec == null ) ? null : sec . fetch ( optionName ) ; } @ Override public < T > T fetch ( Object sectionName , Object optionName , Class < T > clazz ) { Section sec = get ( sectionName ) ; return ( sec == null ) ? BeanTool . getInstance ( ) . zero ( clazz ) : sec . fetch ( optionName , clazz ) ; } @ Override public String get ( Object sectionName , Object optionName ) { Section sec = get ( sectionName ) ; return ( sec == null ) ? null : sec . get ( optionName ) ; } @ Override public < T > T get ( Object sectionName , Object optionName , Class < T > clazz ) { Section sec = get ( sectionName ) ; return ( sec == null ) ? BeanTool . getInstance ( ) . zero ( clazz ) : sec . get ( optionName , clazz ) ; } @ Override public String put ( String sectionName , String optionName , Object value ) { return getOrAdd ( sectionName ) . put ( optionName , value ) ; } @ Override public Section remove ( Section section ) { return remove ( ( Object ) section . getName ( ) ) ; } @ Override public String remove ( Object sectionName , Object optionName ) { Section sec = get ( sectionName ) ; return ( sec == null ) ? null : sec . remove ( optionName ) ; } boolean isTreeMode ( ) { return _treeMode ; } char getPathSeparator ( ) { return PATH_SEPARATOR ; } boolean isPropertyFirstUpper ( ) { return _propertyFirstUpper ; } Section newSection ( String name ) { return new BasicProfileSection ( this , name ) ; } void resolve ( StringBuilder buffer , Section owner ) { Matcher m = EXPRESSION . matcher ( buffer ) ; while ( m . find ( ) ) { String sectionName = m . group ( G_SECTION ) ; String optionName = m . group ( G_OPTION ) ; int optionIndex = parseOptionIndex ( m ) ; Section section = parseSection ( m , owner ) ; String value = null ; if ( SECTION_ENVIRONMENT . equals ( sectionName ) ) { value = Config . getEnvironment ( optionName ) ; } else if ( SECTION_SYSTEM_PROPERTIES . equals ( sectionName ) ) { value = Config . getSystemProperty ( optionName ) ; } else if ( section != null ) { value = ( optionIndex == - <NUM_LIT:1> ) ? section . fetch ( optionName ) : section . fetch ( optionName , optionIndex ) ; } if ( value != null ) { buffer . replace ( m . start ( ) , m . end ( ) , value ) ; m . reset ( buffer ) ; } } } void store ( IniHandler formatter ) { formatter . startIni ( ) ; store ( formatter , getComment ( ) ) ; for ( Ini . Section s : values ( ) ) { store ( formatter , s ) ; } formatter . endIni ( ) ; } void store ( IniHandler formatter , Section s ) { store ( formatter , getNewLineCount ( s . getName ( ) ) ) ; store ( formatter , getComment ( s . getName ( ) ) ) ; formatter . startSection ( s . getName ( ) ) ; for ( String name : s . keySet ( ) ) { store ( formatter , s , name ) ; } formatter . endSection ( ) ; } void store ( IniHandler formatter , int emptyLines ) { for ( int i = <NUM_LIT:0> ; i < emptyLines ; i ++ ) { formatter . handleEmptyLine ( ) ; } } void store ( IniHandler formatter , String comment ) { formatter . handleComment ( comment ) ; } void store ( IniHandler formatter , Section section , String option ) { store ( formatter , section . getNewLineCount ( option ) ) ; store ( formatter , section . getComment ( option ) ) ; int n = section . length ( option ) ; for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { store ( formatter , section , option , i ) ; } } void store ( IniHandler formatter , Section section , String option , int index ) { formatter . handleOption ( option , section . get ( option , index ) ) ; } private Section getOrAdd ( String sectionName ) { Section section = get ( sectionName ) ; return ( ( section == null ) ) ? add ( sectionName ) : section ; } private int parseOptionIndex ( Matcher m ) { return ( m . group ( G_OPTION_IDX ) == null ) ? - <NUM_LIT:1> : Integer . parseInt ( m . group ( G_OPTION_IDX ) ) ; } private Section parseSection ( Matcher m , Section owner ) { String sectionName = m . group ( G_SECTION ) ; int sectionIndex = parseSectionIndex ( m ) ; return ( sectionName == null ) ? owner : ( ( sectionIndex == - <NUM_LIT:1> ) ? get ( sectionName ) : get ( sectionName , sectionIndex ) ) ; } private int parseSectionIndex ( Matcher m ) { return ( m . group ( G_SECTION_IDX ) == null ) ? - <NUM_LIT:1> : Integer . parseInt ( m . group ( G_SECTION_IDX ) ) ; } private final class BeanInvocationHandler extends AbstractBeanInvocationHandler { private final String _prefix ; private BeanInvocationHandler ( String prefix ) { _prefix = prefix ; } @ Override protected Object getPropertySpi ( String property , Class < ? > clazz ) { String key = transform ( property ) ; Object o = null ; if ( containsKey ( key ) ) { if ( clazz . isArray ( ) ) { o = Array . newInstance ( clazz . getComponentType ( ) , length ( key ) ) ; for ( int i = <NUM_LIT:0> ; i < length ( key ) ; i ++ ) { Array . set ( o , i , get ( key , i ) . as ( clazz . getComponentType ( ) ) ) ; } } else { o = get ( key ) . as ( clazz ) ; } } return o ; } @ Override protected void setPropertySpi ( String property , Object value , Class < ? > clazz ) { String key = transform ( property ) ; remove ( key ) ; if ( value != null ) { if ( clazz . isArray ( ) ) { for ( int i = <NUM_LIT:0> ; i < Array . getLength ( value ) ; i ++ ) { Section sec = add ( key ) ; sec . from ( Array . get ( value , i ) ) ; } } else { Section sec = add ( key ) ; sec . from ( value ) ; } } } @ Override protected boolean hasPropertySpi ( String property ) { return containsKey ( transform ( property ) ) ; } String transform ( String property ) { String ret = ( _prefix == null ) ? property : ( _prefix + property ) ; if ( isPropertyFirstUpper ( ) ) { StringBuilder buff = new StringBuilder ( ) ; buff . append ( Character . toUpperCase ( property . charAt ( <NUM_LIT:0> ) ) ) ; buff . append ( property . substring ( <NUM_LIT:1> ) ) ; ret = buff . toString ( ) ; } return ret ; } } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . io . * ; import java . net . URL ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import com . izforge . izpack . util . config . base . spi . IniHandler ; import com . izforge . izpack . util . config . base . spi . Warnings ; public class ConfigParser implements Serializable { private static final long serialVersionUID = <NUM_LIT> ; private PyIni _ini ; @ SuppressWarnings ( Warnings . UNCHECKED ) public ConfigParser ( ) { this ( Collections . EMPTY_MAP ) ; } public ConfigParser ( Map < String , String > defaults ) { _ini = new PyIni ( defaults ) ; } public boolean getBoolean ( String section , String option ) throws NoSectionException , NoOptionException , InterpolationException { boolean ret ; String value = get ( section , option ) ; if ( "<STR_LIT:1>" . equalsIgnoreCase ( value ) || "<STR_LIT:yes>" . equalsIgnoreCase ( value ) || "<STR_LIT:true>" . equalsIgnoreCase ( value ) || "<STR_LIT>" . equalsIgnoreCase ( value ) ) { ret = true ; } else if ( "<STR_LIT:0>" . equalsIgnoreCase ( value ) || "<STR_LIT>" . equalsIgnoreCase ( value ) || "<STR_LIT:false>" . equalsIgnoreCase ( value ) || "<STR_LIT>" . equalsIgnoreCase ( value ) ) { ret = false ; } else { throw new IllegalArgumentException ( value ) ; } return ret ; } public double getDouble ( String section , String option ) throws NoSectionException , NoOptionException , InterpolationException { return Double . parseDouble ( get ( section , option ) ) ; } public float getFloat ( String section , String option ) throws NoSectionException , NoOptionException , InterpolationException { return Float . parseFloat ( get ( section , option ) ) ; } public int getInt ( String section , String option ) throws NoSectionException , NoOptionException , InterpolationException { return Integer . parseInt ( get ( section , option ) ) ; } public long getLong ( String section , String option ) throws NoSectionException , NoOptionException , InterpolationException { return Long . parseLong ( get ( section , option ) ) ; } public void addSection ( String section ) throws DuplicateSectionException { if ( _ini . containsKey ( section ) ) { throw new DuplicateSectionException ( section ) ; } else if ( PyIni . DEFAULT_SECTION_NAME . equalsIgnoreCase ( section ) ) { throw new IllegalArgumentException ( section ) ; } _ini . add ( section ) ; } public Map < String , String > defaults ( ) { return _ini . getDefaults ( ) ; } @ SuppressWarnings ( Warnings . UNCHECKED ) public String get ( String section , String option ) throws NoSectionException , NoOptionException , InterpolationException { return get ( section , option , false , Collections . EMPTY_MAP ) ; } @ SuppressWarnings ( Warnings . UNCHECKED ) public String get ( String section , String option , boolean raw ) throws NoSectionException , NoOptionException , InterpolationException { return get ( section , option , raw , Collections . EMPTY_MAP ) ; } public String get ( String sectionName , String optionName , boolean raw , Map < String , String > variables ) throws NoSectionException , NoOptionException , InterpolationException { String value = requireOption ( sectionName , optionName ) ; if ( ! raw && ( value != null ) && ( value . indexOf ( PyIni . SUBST_CHAR ) >= <NUM_LIT:0> ) ) { value = _ini . fetch ( sectionName , optionName , variables ) ; } return value ; } public boolean hasOption ( String sectionName , String optionName ) { Ini . Section section = _ini . get ( sectionName ) ; return ( section != null ) && section . containsKey ( optionName ) ; } public boolean hasSection ( String sectionName ) { return _ini . containsKey ( sectionName ) ; } @ SuppressWarnings ( Warnings . UNCHECKED ) public List < Map . Entry < String , String > > items ( String sectionName ) throws NoSectionException , InterpolationMissingOptionException { return items ( sectionName , false , Collections . EMPTY_MAP ) ; } @ SuppressWarnings ( Warnings . UNCHECKED ) public List < Map . Entry < String , String > > items ( String sectionName , boolean raw ) throws NoSectionException , InterpolationMissingOptionException { return items ( sectionName , raw , Collections . EMPTY_MAP ) ; } public List < Map . Entry < String , String > > items ( String sectionName , boolean raw , Map < String , String > variables ) throws NoSectionException , InterpolationMissingOptionException { Ini . Section section = requireSection ( sectionName ) ; Map < String , String > ret ; if ( raw ) { ret = new HashMap < String , String > ( section ) ; } else { ret = new HashMap < String , String > ( ) ; for ( String key : section . keySet ( ) ) { ret . put ( key , _ini . fetch ( section , key , variables ) ) ; } } return new ArrayList < Map . Entry < String , String > > ( ret . entrySet ( ) ) ; } public List < String > options ( String sectionName ) throws NoSectionException { requireSection ( sectionName ) ; return new ArrayList < String > ( _ini . get ( sectionName ) . keySet ( ) ) ; } public void read ( String ... filenames ) throws IOException , ParsingException { for ( String filename : filenames ) { read ( new File ( filename ) ) ; } } public void read ( Reader reader ) throws IOException , ParsingException { try { _ini . load ( reader ) ; } catch ( InvalidFileFormatException x ) { throw new ParsingException ( x ) ; } } public void read ( URL url ) throws IOException , ParsingException { try { _ini . load ( url ) ; } catch ( InvalidFileFormatException x ) { throw new ParsingException ( x ) ; } } public void read ( File file ) throws IOException , ParsingException { try { _ini . load ( new FileReader ( file ) ) ; } catch ( InvalidFileFormatException x ) { throw new ParsingException ( x ) ; } } public void read ( InputStream stream ) throws IOException , ParsingException { try { _ini . load ( stream ) ; } catch ( InvalidFileFormatException x ) { throw new ParsingException ( x ) ; } } public boolean removeOption ( String sectionName , String optionName ) throws NoSectionException { Ini . Section section = requireSection ( sectionName ) ; boolean ret = section . containsKey ( optionName ) ; section . remove ( optionName ) ; return ret ; } public boolean removeSection ( String sectionName ) { boolean ret = _ini . containsKey ( sectionName ) ; _ini . remove ( sectionName ) ; return ret ; } public List < String > sections ( ) { return new ArrayList < String > ( _ini . keySet ( ) ) ; } public void set ( String sectionName , String optionName , Object value ) throws NoSectionException { Ini . Section section = requireSection ( sectionName ) ; if ( value == null ) { section . remove ( optionName ) ; } else { section . put ( optionName , value . toString ( ) ) ; } } public void write ( Writer writer ) throws IOException { _ini . store ( writer ) ; } public void write ( OutputStream stream ) throws IOException { _ini . store ( stream ) ; } public void write ( File file ) throws IOException { _ini . store ( new FileWriter ( file ) ) ; } protected Ini getIni ( ) { return _ini ; } private String requireOption ( String sectionName , String optionName ) throws NoSectionException , NoOptionException { Ini . Section section = requireSection ( sectionName ) ; String option = section . get ( optionName ) ; if ( option == null ) { throw new NoOptionException ( optionName ) ; } return option ; } private Ini . Section requireSection ( String sectionName ) throws NoSectionException { Ini . Section section = _ini . get ( sectionName ) ; if ( section == null ) { throw new NoSectionException ( sectionName ) ; } return section ; } public static class ConfigParserException extends Exception { private static final long serialVersionUID = - <NUM_LIT> ; public ConfigParserException ( String message ) { super ( message ) ; } } public static final class DuplicateSectionException extends ConfigParserException { private static final long serialVersionUID = - <NUM_LIT> ; private DuplicateSectionException ( String message ) { super ( message ) ; } } public static class InterpolationException extends ConfigParserException { private static final long serialVersionUID = <NUM_LIT> ; protected InterpolationException ( String message ) { super ( message ) ; } } public static final class InterpolationMissingOptionException extends InterpolationException { private static final long serialVersionUID = <NUM_LIT> ; private InterpolationMissingOptionException ( String message ) { super ( message ) ; } } public static final class NoOptionException extends ConfigParserException { private static final long serialVersionUID = <NUM_LIT> ; private NoOptionException ( String message ) { super ( message ) ; } } public static final class NoSectionException extends ConfigParserException { private static final long serialVersionUID = <NUM_LIT> ; private NoSectionException ( String message ) { super ( message ) ; } } public static final class ParsingException extends IOException { private static final long serialVersionUID = - <NUM_LIT> ; private ParsingException ( Throwable cause ) { super ( cause . getMessage ( ) ) ; initCause ( cause ) ; } } static class PyIni extends Ini { private static final char SUBST_CHAR = '<CHAR_LIT>' ; private static final Pattern EXPRESSION = Pattern . compile ( "<STR_LIT>" ) ; private static final int G_OPTION = <NUM_LIT:1> ; protected static final String DEFAULT_SECTION_NAME = "<STR_LIT>" ; private static final long serialVersionUID = - <NUM_LIT> ; private final Map < String , String > _defaults ; private Ini . Section _defaultSection ; public PyIni ( Map < String , String > defaults ) { _defaults = defaults ; Config cfg = getConfig ( ) . clone ( ) ; cfg . setEscape ( false ) ; cfg . setMultiOption ( false ) ; cfg . setMultiSection ( false ) ; cfg . setLowerCaseOption ( true ) ; cfg . setLowerCaseSection ( true ) ; super . setConfig ( cfg ) ; } @ Override public void setConfig ( Config value ) { assert true ; } public Map < String , String > getDefaults ( ) { return _defaults ; } @ Override public Section add ( String name ) { Section section ; if ( DEFAULT_SECTION_NAME . equalsIgnoreCase ( name ) ) { if ( _defaultSection == null ) { _defaultSection = newSection ( name ) ; } section = _defaultSection ; } else { section = super . add ( name ) ; } return section ; } public String fetch ( String sectionName , String optionName , Map < String , String > variables ) throws InterpolationMissingOptionException { return fetch ( get ( sectionName ) , optionName , variables ) ; } protected Ini . Section getDefaultSection ( ) { return _defaultSection ; } protected String fetch ( Ini . Section section , String optionName , Map < String , String > variables ) throws InterpolationMissingOptionException { String value = section . get ( optionName ) ; if ( ( value != null ) && ( value . indexOf ( SUBST_CHAR ) >= <NUM_LIT:0> ) ) { StringBuilder buffer = new StringBuilder ( value ) ; resolve ( buffer , section , variables ) ; value = buffer . toString ( ) ; } return value ; } protected void resolve ( StringBuilder buffer , Ini . Section owner , Map < String , String > vars ) throws InterpolationMissingOptionException { Matcher m = EXPRESSION . matcher ( buffer ) ; while ( m . find ( ) ) { String optionName = m . group ( G_OPTION ) ; String value = owner . get ( optionName ) ; if ( value == null ) { value = vars . get ( optionName ) ; } if ( value == null ) { value = _defaults . get ( optionName ) ; } if ( ( value == null ) && ( _defaultSection != null ) ) { value = _defaultSection . get ( optionName ) ; } if ( value == null ) { throw new InterpolationMissingOptionException ( optionName ) ; } buffer . replace ( m . start ( ) , m . end ( ) , value ) ; m . reset ( buffer ) ; } } @ Override protected void store ( IniHandler formatter ) { formatter . startIni ( ) ; if ( _defaultSection != null ) { store ( formatter , _defaultSection ) ; } for ( Ini . Section s : values ( ) ) { store ( formatter , s ) ; } formatter . endIni ( ) ; } @ Override protected void store ( IniHandler formatter , Section section ) { formatter . startSection ( section . getName ( ) ) ; for ( String name : section . keySet ( ) ) { formatter . handleOption ( name , section . get ( name ) ) ; } formatter . endSection ( ) ; } } } </s>
|
<s> package com . izforge . izpack . util . config . base ; public interface Profile extends MultiMap < String , Profile . Section > , CommentedMap < String , Profile . Section > { char PATH_SEPARATOR = '<CHAR_LIT:/>' ; String getComment ( ) ; void setComment ( String value ) ; Section add ( String sectionName ) ; void add ( String sectionName , String optionName , Object value ) ; < T > T as ( Class < T > clazz ) ; < T > T as ( Class < T > clazz , String prefix ) ; String fetch ( Object sectionName , Object optionName ) ; < T > T fetch ( Object sectionName , Object optionName , Class < T > clazz ) ; String get ( Object sectionName , Object optionName ) ; < T > T get ( Object sectionName , Object optionName , Class < T > clazz ) ; String put ( String sectionName , String optionName , Object value ) ; Section remove ( Profile . Section section ) ; String remove ( Object sectionName , Object optionName ) ; interface Section extends OptionMap { Section getChild ( String key ) ; String getName ( ) ; Section getParent ( ) ; String getSimpleName ( ) ; Section addChild ( String key ) ; String [ ] childrenNames ( ) ; Section lookup ( String ... path ) ; void removeChild ( String key ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . lang . reflect . Array ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import com . izforge . izpack . util . config . base . spi . BeanAccess ; import com . izforge . izpack . util . config . base . spi . BeanTool ; import com . izforge . izpack . util . config . base . spi . Warnings ; public class BasicOptionMap extends CommonMultiMap < String , String > implements OptionMap { private static final char SUBST_CHAR = '<CHAR_LIT>' ; private static final String SYSTEM_PROPERTY_PREFIX = "<STR_LIT>" ; private static final String ENVIRONMENT_PREFIX = "<STR_LIT>" ; private static final int SYSTEM_PROPERTY_PREFIX_LEN = SYSTEM_PROPERTY_PREFIX . length ( ) ; private static final int ENVIRONMENT_PREFIX_LEN = ENVIRONMENT_PREFIX . length ( ) ; private static final Pattern EXPRESSION = Pattern . compile ( "<STR_LIT>" ) ; private static final int G_OPTION = <NUM_LIT:2> ; private static final int G_INDEX = <NUM_LIT:4> ; private static final long serialVersionUID = <NUM_LIT> ; private BeanAccess _defaultBeanAccess ; private final boolean _propertyFirstUpper ; public BasicOptionMap ( ) { this ( false ) ; } public BasicOptionMap ( boolean propertyFirstUpper ) { _propertyFirstUpper = propertyFirstUpper ; } @ Override @ SuppressWarnings ( Warnings . UNCHECKED ) public < T > T getAll ( Object key , Class < T > clazz ) { requireArray ( clazz ) ; T value ; value = ( T ) Array . newInstance ( clazz . getComponentType ( ) , length ( key ) ) ; for ( int i = <NUM_LIT:0> ; i < length ( key ) ; i ++ ) { Array . set ( value , i , BeanTool . getInstance ( ) . parse ( get ( key , i ) , clazz . getComponentType ( ) ) ) ; } return value ; } @ Override public void add ( String key , Object value ) { super . add ( key , ( ( value == null ) || ( value instanceof String ) ) ? ( String ) value : String . valueOf ( value ) ) ; } @ Override public void add ( String key , Object value , int index ) { super . add ( key , ( ( value == null ) || ( value instanceof String ) ) ? ( String ) value : String . valueOf ( value ) , index ) ; } @ Override public < T > T as ( Class < T > clazz ) { return BeanTool . getInstance ( ) . proxy ( clazz , getDefaultBeanAccess ( ) ) ; } @ Override public < T > T as ( Class < T > clazz , String keyPrefix ) { return BeanTool . getInstance ( ) . proxy ( clazz , newBeanAccess ( keyPrefix ) ) ; } @ Override public String fetch ( Object key ) { int len = length ( key ) ; return ( len == <NUM_LIT:0> ) ? null : fetch ( key , len - <NUM_LIT:1> ) ; } @ Override public String fetch ( Object key , String defaultValue ) { String str = get ( key ) ; return ( str == null ) ? defaultValue : str ; } @ Override public String fetch ( Object key , int index ) { String value = get ( key , index ) ; if ( ( value != null ) && ( value . indexOf ( SUBST_CHAR ) >= <NUM_LIT:0> ) ) { StringBuilder buffer = new StringBuilder ( value ) ; resolve ( buffer ) ; value = buffer . toString ( ) ; } return value ; } @ Override public < T > T fetch ( Object key , Class < T > clazz ) { return BeanTool . getInstance ( ) . parse ( fetch ( key ) , clazz ) ; } @ Override public < T > T fetch ( Object key , Class < T > clazz , T defaultValue ) { String str = fetch ( key ) ; return ( str == null ) ? defaultValue : BeanTool . getInstance ( ) . parse ( str , clazz ) ; } @ Override public < T > T fetch ( Object key , int index , Class < T > clazz ) { return BeanTool . getInstance ( ) . parse ( fetch ( key , index ) , clazz ) ; } @ Override @ SuppressWarnings ( Warnings . UNCHECKED ) public < T > T fetchAll ( Object key , Class < T > clazz ) { requireArray ( clazz ) ; T value ; value = ( T ) Array . newInstance ( clazz . getComponentType ( ) , length ( key ) ) ; for ( int i = <NUM_LIT:0> ; i < length ( key ) ; i ++ ) { Array . set ( value , i , BeanTool . getInstance ( ) . parse ( fetch ( key , i ) , clazz . getComponentType ( ) ) ) ; } return value ; } @ Override public void from ( Object bean ) { BeanTool . getInstance ( ) . inject ( getDefaultBeanAccess ( ) , bean ) ; } @ Override public void from ( Object bean , String keyPrefix ) { BeanTool . getInstance ( ) . inject ( newBeanAccess ( keyPrefix ) , bean ) ; } @ Override public < T > T get ( Object key , Class < T > clazz ) { return BeanTool . getInstance ( ) . parse ( get ( key ) , clazz ) ; } @ Override public String get ( Object key , String defaultValue ) { String str = get ( key ) ; return ( str == null ) ? defaultValue : str ; } @ Override public < T > T get ( Object key , Class < T > clazz , T defaultValue ) { String str = get ( key ) ; return ( str == null ) ? defaultValue : BeanTool . getInstance ( ) . parse ( str , clazz ) ; } @ Override public < T > T get ( Object key , int index , Class < T > clazz ) { return BeanTool . getInstance ( ) . parse ( get ( key , index ) , clazz ) ; } @ Override public String put ( String key , Object value ) { return super . put ( key , ( ( value == null ) || ( value instanceof String ) ) ? ( String ) value : String . valueOf ( value ) ) ; } @ Override public String put ( String key , Object value , int index ) { return super . put ( key , ( ( value == null ) || ( value instanceof String ) ) ? ( String ) value : String . valueOf ( value ) , index ) ; } @ Override public void putAll ( String key , Object value ) { if ( value != null ) { requireArray ( value . getClass ( ) ) ; } remove ( key ) ; if ( value != null ) { int n = Array . getLength ( value ) ; for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { add ( key , Array . get ( value , i ) ) ; } } } @ Override public void to ( Object bean ) { BeanTool . getInstance ( ) . inject ( bean , getDefaultBeanAccess ( ) ) ; } @ Override public void to ( Object bean , String keyPrefix ) { BeanTool . getInstance ( ) . inject ( bean , newBeanAccess ( keyPrefix ) ) ; } synchronized BeanAccess getDefaultBeanAccess ( ) { if ( _defaultBeanAccess == null ) { _defaultBeanAccess = newBeanAccess ( ) ; } return _defaultBeanAccess ; } boolean isPropertyFirstUpper ( ) { return _propertyFirstUpper ; } BeanAccess newBeanAccess ( ) { return new Access ( ) ; } BeanAccess newBeanAccess ( String propertyNamePrefix ) { return new Access ( propertyNamePrefix ) ; } void resolve ( StringBuilder buffer ) { Matcher m = EXPRESSION . matcher ( buffer ) ; while ( m . find ( ) ) { String name = m . group ( G_OPTION ) ; int index = ( m . group ( G_INDEX ) == null ) ? - <NUM_LIT:1> : Integer . parseInt ( m . group ( G_INDEX ) ) ; String value ; if ( name . startsWith ( ENVIRONMENT_PREFIX ) ) { value = Config . getEnvironment ( name . substring ( ENVIRONMENT_PREFIX_LEN ) ) ; } else if ( name . startsWith ( SYSTEM_PROPERTY_PREFIX ) ) { value = Config . getSystemProperty ( name . substring ( SYSTEM_PROPERTY_PREFIX_LEN ) ) ; } else { value = ( index == - <NUM_LIT:1> ) ? fetch ( name ) : fetch ( name , index ) ; } if ( value != null ) { buffer . replace ( m . start ( ) , m . end ( ) , value ) ; m . reset ( buffer ) ; } } } private void requireArray ( Class clazz ) { if ( ! clazz . isArray ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } class Access implements BeanAccess { private final String _prefix ; Access ( ) { this ( null ) ; } Access ( String prefix ) { _prefix = prefix ; } @ Override public void propAdd ( String propertyName , String value ) { add ( transform ( propertyName ) , value ) ; } @ Override public String propDel ( String propertyName ) { return remove ( transform ( propertyName ) ) ; } @ Override public String propGet ( String propertyName ) { return fetch ( transform ( propertyName ) ) ; } @ Override public String propGet ( String propertyName , int index ) { return fetch ( transform ( propertyName ) , index ) ; } @ Override public int propLength ( String propertyName ) { return length ( transform ( propertyName ) ) ; } @ Override public String propSet ( String propertyName , String value ) { return put ( transform ( propertyName ) , value ) ; } @ Override public String propSet ( String propertyName , String value , int index ) { return put ( transform ( propertyName ) , value , index ) ; } private String transform ( String orig ) { String ret = orig ; if ( ( ( _prefix != null ) || isPropertyFirstUpper ( ) ) && ( orig != null ) ) { StringBuilder buff = new StringBuilder ( ) ; if ( _prefix != null ) { buff . append ( _prefix ) ; } if ( isPropertyFirstUpper ( ) ) { buff . append ( Character . toUpperCase ( orig . charAt ( <NUM_LIT:0> ) ) ) ; buff . append ( orig . substring ( <NUM_LIT:1> ) ) ; } else { buff . append ( orig ) ; } ret = buff . toString ( ) ; } return ret ; } } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . io . IOException ; import java . io . InputStream ; import java . io . Reader ; import java . net . URL ; import java . util . ArrayList ; import java . util . List ; import java . util . prefs . AbstractPreferences ; import java . util . prefs . BackingStoreException ; public class IniPreferences extends AbstractPreferences { private static final String [ ] EMPTY = { } ; private final Ini _ini ; public IniPreferences ( Ini ini ) { super ( null , "<STR_LIT>" ) ; _ini = ini ; } public IniPreferences ( Reader input ) throws IOException , InvalidFileFormatException { super ( null , "<STR_LIT>" ) ; _ini = new Ini ( input ) ; } public IniPreferences ( InputStream input ) throws IOException , InvalidFileFormatException { super ( null , "<STR_LIT>" ) ; _ini = new Ini ( input ) ; } public IniPreferences ( URL input ) throws IOException , InvalidFileFormatException { super ( null , "<STR_LIT>" ) ; _ini = new Ini ( input ) ; } protected Ini getIni ( ) { return _ini ; } @ Override protected String getSpi ( String key ) throws UnsupportedOperationException { throw new UnsupportedOperationException ( ) ; } @ Override protected String [ ] childrenNamesSpi ( ) throws BackingStoreException { List < String > names = new ArrayList < String > ( ) ; for ( String name : _ini . keySet ( ) ) { if ( name . indexOf ( _ini . getPathSeparator ( ) ) < <NUM_LIT:0> ) { names . add ( name ) ; } } return names . toArray ( EMPTY ) ; } @ Override protected SectionPreferences childSpi ( String name ) { Ini . Section sec = _ini . get ( name ) ; boolean isNew = sec == null ; if ( isNew ) { sec = _ini . add ( name ) ; } return new SectionPreferences ( this , sec , isNew ) ; } @ Override protected void flushSpi ( ) throws BackingStoreException { assert true ; } @ Override protected String [ ] keysSpi ( ) throws BackingStoreException { return EMPTY ; } @ Override protected void putSpi ( String key , String value ) throws UnsupportedOperationException { throw new UnsupportedOperationException ( ) ; } @ Override protected void removeNodeSpi ( ) throws BackingStoreException , UnsupportedOperationException { throw new UnsupportedOperationException ( ) ; } @ Override protected void removeSpi ( String key ) throws UnsupportedOperationException { throw new UnsupportedOperationException ( ) ; } @ Override protected void syncSpi ( ) throws BackingStoreException { assert true ; } protected class SectionPreferences extends AbstractPreferences { private final Ini . Section _section ; SectionPreferences ( AbstractPreferences parent , Ini . Section section , boolean isNew ) { super ( parent , section . getSimpleName ( ) ) ; _section = section ; newNode = isNew ; } @ Override public void flush ( ) throws BackingStoreException { parent ( ) . flush ( ) ; } @ Override public void sync ( ) throws BackingStoreException { parent ( ) . sync ( ) ; } @ Override protected String getSpi ( String key ) { return _section . fetch ( key ) ; } @ Override protected String [ ] childrenNamesSpi ( ) throws BackingStoreException { return _section . childrenNames ( ) ; } @ Override protected SectionPreferences childSpi ( String name ) throws UnsupportedOperationException { Ini . Section child = _section . getChild ( name ) ; boolean isNew = child == null ; if ( isNew ) { child = _section . addChild ( name ) ; } return new SectionPreferences ( this , child , isNew ) ; } @ Override protected void flushSpi ( ) throws BackingStoreException { assert true ; } @ Override protected String [ ] keysSpi ( ) throws BackingStoreException { return _section . keySet ( ) . toArray ( EMPTY ) ; } @ Override protected void putSpi ( String key , String value ) { _section . put ( key , value ) ; } @ Override protected void removeNodeSpi ( ) throws BackingStoreException { _ini . remove ( _section ) ; } @ Override protected void removeSpi ( String key ) { _section . remove ( key ) ; } @ Override protected void syncSpi ( ) throws BackingStoreException { assert true ; } } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import com . izforge . izpack . util . config . base . Registry . Key ; class BasicRegistryKey extends BasicProfileSection implements Registry . Key { private static final long serialVersionUID = - <NUM_LIT> ; private static final String META_TYPE = "<STR_LIT:type>" ; public BasicRegistryKey ( BasicRegistry registry , String name ) { super ( registry , name ) ; } @ Override public Key getChild ( String key ) { return ( Key ) super . getChild ( key ) ; } @ Override public Key getParent ( ) { return ( Key ) super . getParent ( ) ; } @ Override public Registry . Type getType ( Object key ) { return ( Registry . Type ) getMeta ( META_TYPE , key ) ; } @ Override public Registry . Type getType ( Object key , Registry . Type defaultType ) { Registry . Type type = getType ( key ) ; return ( type == null ) ? defaultType : type ; } @ Override public Key addChild ( String key ) { return ( Key ) super . addChild ( key ) ; } @ Override public Key lookup ( String ... path ) { return ( Key ) super . lookup ( path ) ; } @ Override public Registry . Type putType ( String key , Registry . Type type ) { return ( Registry . Type ) putMeta ( META_TYPE , key , type ) ; } @ Override public Registry . Type removeType ( Object key ) { return ( Registry . Type ) removeMeta ( META_TYPE , key ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . io . * ; import java . net . URL ; import com . izforge . izpack . util . config . base . spi . OptionsBuilder ; import com . izforge . izpack . util . config . base . spi . OptionsFormatter ; import com . izforge . izpack . util . config . base . spi . OptionsHandler ; import com . izforge . izpack . util . config . base . spi . OptionsParser ; public class Options extends BasicOptionMap implements Persistable , Configurable { private static final long serialVersionUID = - <NUM_LIT> ; private String _comment ; private Config _config ; private File _file ; public Options ( ) { _config = Config . getGlobal ( ) . clone ( ) ; _config . setEmptyOption ( true ) ; } public Options ( Reader input ) throws IOException , InvalidFileFormatException { this ( ) ; load ( input ) ; } public Options ( InputStream input ) throws IOException , InvalidFileFormatException { this ( ) ; load ( input ) ; } public Options ( URL input ) throws IOException , InvalidFileFormatException { this ( ) ; load ( input ) ; } public Options ( File input ) throws IOException , InvalidFileFormatException { this ( ) ; _file = input ; load ( ) ; } public String getComment ( ) { return _comment ; } public void setComment ( String value ) { _comment = value ; } @ Override public Config getConfig ( ) { return _config ; } @ Override public void setConfig ( Config value ) { _config = value ; } @ Override public File getFile ( ) { return _file ; } @ Override public void setFile ( File value ) { _file = value ; } @ Override public void load ( ) throws IOException , InvalidFileFormatException { if ( _file == null ) { throw new FileNotFoundException ( ) ; } load ( _file ) ; } @ Override public void load ( InputStream input ) throws IOException , InvalidFileFormatException { load ( new InputStreamReader ( input , getConfig ( ) . getFileEncoding ( ) ) ) ; } @ Override public void load ( Reader input ) throws IOException , InvalidFileFormatException { OptionsParser . newInstance ( getConfig ( ) ) . parse ( input , newBuilder ( ) ) ; } @ Override public void load ( URL input ) throws IOException , InvalidFileFormatException { OptionsParser . newInstance ( getConfig ( ) ) . parse ( input , newBuilder ( ) ) ; } @ Override public void load ( File input ) throws IOException , InvalidFileFormatException { load ( input . toURI ( ) . toURL ( ) ) ; } @ Override public void store ( ) throws IOException { if ( _file == null ) { throw new FileNotFoundException ( ) ; } store ( _file ) ; } @ Override public void store ( OutputStream output ) throws IOException { store ( new OutputStreamWriter ( output , getConfig ( ) . getFileEncoding ( ) ) ) ; } @ Override public void store ( Writer output ) throws IOException { store ( OptionsFormatter . newInstance ( output , getConfig ( ) ) ) ; } @ Override public void store ( File output ) throws IOException { OutputStream stream = new FileOutputStream ( output ) ; store ( stream ) ; stream . close ( ) ; } protected OptionsHandler newBuilder ( ) { return OptionsBuilder . newInstance ( this ) ; } protected void store ( OptionsHandler formatter ) throws IOException { formatter . startOptions ( ) ; storeComment ( formatter , _comment ) ; for ( String name : keySet ( ) ) { storeNewLines ( formatter , getNewLineCount ( name ) ) ; storeComment ( formatter , getComment ( name ) ) ; int n = getConfig ( ) . isMultiOption ( ) || getConfig ( ) . isAutoNumbering ( ) ? length ( name ) : <NUM_LIT:1> ; for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { String value = get ( name , i ) ; if ( getConfig ( ) . isAutoNumbering ( ) && name . endsWith ( "<STR_LIT:.>" ) ) { if ( value != null ) { formatter . handleOption ( name + i , value ) ; } } else { formatter . handleOption ( name , value ) ; } } } formatter . endOptions ( ) ; } @ Override boolean isPropertyFirstUpper ( ) { return getConfig ( ) . isPropertyFirstUpper ( ) ; } private void storeNewLines ( OptionsHandler formatter , int emptyLines ) { for ( int i = <NUM_LIT:0> ; i < emptyLines ; i ++ ) { formatter . handleEmptyLine ( ) ; } } private void storeComment ( OptionsHandler formatter , String comment ) { formatter . handleComment ( comment ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . io . InputStream ; import java . net . URI ; import java . net . URL ; import java . util . Properties ; import java . util . prefs . Preferences ; import java . util . prefs . PreferencesFactory ; public class IniPreferencesFactory implements PreferencesFactory { public static final String PROPERTIES = "<STR_LIT>" ; public static final String KEY_USER = "<STR_LIT>" ; public static final String KEY_SYSTEM = "<STR_LIT>" ; private Preferences _system ; private Preferences _user ; @ Override public synchronized Preferences systemRoot ( ) { if ( _system == null ) { _system = newIniPreferences ( KEY_SYSTEM ) ; } return _system ; } @ Override public synchronized Preferences userRoot ( ) { if ( _user == null ) { _user = newIniPreferences ( KEY_USER ) ; } return _user ; } String getIniLocation ( String key ) { String location = Config . getSystemProperty ( key ) ; if ( location == null ) { try { Properties props = new Properties ( ) ; props . load ( Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( PROPERTIES ) ) ; location = props . getProperty ( key ) ; } catch ( Exception x ) { assert true ; } } return location ; } URL getResource ( String location ) throws IllegalArgumentException { try { URI uri = new URI ( location ) ; URL url ; if ( uri . getScheme ( ) == null ) { url = Thread . currentThread ( ) . getContextClassLoader ( ) . getResource ( location ) ; } else { url = uri . toURL ( ) ; } return url ; } catch ( Exception x ) { throw ( IllegalArgumentException ) new IllegalArgumentException ( ) . initCause ( x ) ; } } InputStream getResourceAsStream ( String location ) throws IllegalArgumentException { try { return getResource ( location ) . openStream ( ) ; } catch ( Exception x ) { throw ( IllegalArgumentException ) new IllegalArgumentException ( ) . initCause ( x ) ; } } Preferences newIniPreferences ( String key ) { Ini ini = new Ini ( ) ; String location = getIniLocation ( key ) ; if ( location != null ) { try { ini . load ( getResourceAsStream ( location ) ) ; } catch ( Exception x ) { throw ( IllegalArgumentException ) new IllegalArgumentException ( ) . initCause ( x ) ; } } return new IniPreferences ( ini ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; public interface Configurable { Config getConfig ( ) ; void setConfig ( Config value ) ; } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . util . Map ; import java . util . SortedMap ; import java . util . TreeMap ; public class CommonMultiMap < K , V > extends BasicMultiMap < K , V > implements CommentedMap < K , V > { private static final long serialVersionUID = - <NUM_LIT> ; private static final String SEPARATOR = "<STR_LIT>" ; private static final String FIRST_CATEGORY = "<STR_LIT>" ; private static final String LAST_CATEGORY = "<STR_LIT>" ; private static final String META_COMMENT = "<STR_LIT>" ; private static final String META_NEWLINE_COUNT = "<STR_LIT>" ; private SortedMap < String , Object > _meta ; @ Override public int getNewLineCount ( Object key ) { Integer emptyLines = ( Integer ) getMeta ( META_NEWLINE_COUNT , key ) ; return emptyLines == null ? <NUM_LIT:0> : emptyLines . intValue ( ) ; } @ Override public Integer addEmptyLine ( K key ) { Integer newLines = ( Integer ) getMeta ( META_NEWLINE_COUNT , key ) ; if ( newLines == null ) { newLines = Integer . valueOf ( <NUM_LIT:0> ) ; } return ( Integer ) putMeta ( META_NEWLINE_COUNT , key , Integer . valueOf ( newLines . intValue ( ) + <NUM_LIT:1> ) ) ; } @ Override public String getComment ( Object key ) { return ( String ) getMeta ( META_COMMENT , key ) ; } @ Override public void clear ( ) { super . clear ( ) ; if ( _meta != null ) { _meta . clear ( ) ; } } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) @ Override public void putAll ( Map < ? extends K , ? extends V > map ) { super . putAll ( map ) ; if ( map instanceof CommonMultiMap ) { @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) Map < String , String > meta = ( ( CommonMultiMap ) map ) . _meta ; if ( meta != null ) { meta ( ) . putAll ( meta ) ; } } } @ Override public String putComment ( K key , String comment ) { return ( String ) putMeta ( META_COMMENT , key , comment ) ; } @ Override public V remove ( Object key ) { V ret = super . remove ( key ) ; removeMeta ( key ) ; return ret ; } @ Override public V remove ( Object key , int index ) { V ret = super . remove ( key , index ) ; if ( length ( key ) == <NUM_LIT:0> ) { removeMeta ( key ) ; } return ret ; } @ Override public String removeComment ( Object key ) { return ( String ) removeMeta ( META_COMMENT , key ) ; } Object getMeta ( String category , Object key ) { return ( _meta == null ) ? null : _meta . get ( makeKey ( category , key ) ) ; } Object putMeta ( String category , K key , Object value ) { return meta ( ) . put ( makeKey ( category , key ) , value ) ; } void removeMeta ( Object key ) { if ( _meta != null ) { _meta . subMap ( makeKey ( FIRST_CATEGORY , key ) , makeKey ( LAST_CATEGORY , key ) ) . clear ( ) ; } } Object removeMeta ( String category , Object key ) { return ( _meta == null ) ? null : _meta . remove ( makeKey ( category , key ) ) ; } private String makeKey ( String category , Object key ) { StringBuilder buff = new StringBuilder ( ) ; buff . append ( String . valueOf ( key ) ) ; buff . append ( SEPARATOR ) ; buff . append ( category ) ; return buff . toString ( ) ; } private Map < String , Object > meta ( ) { if ( _meta == null ) { _meta = new TreeMap < String , Object > ( ) ; } return _meta ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . io . Reader ; import java . net . URL ; import com . izforge . izpack . util . config . base . spi . WinEscapeTool ; public class Wini extends Ini { private static final long serialVersionUID = - <NUM_LIT> ; public static final char PATH_SEPARATOR = '<STR_LIT:\\>' ; public Wini ( ) { Config cfg = Config . getGlobal ( ) . clone ( ) ; cfg . setEscape ( false ) ; cfg . setEscapeNewline ( false ) ; cfg . setGlobalSection ( true ) ; cfg . setEmptyOption ( true ) ; cfg . setMultiOption ( false ) ; cfg . setPathSeparator ( PATH_SEPARATOR ) ; setConfig ( cfg ) ; } public Wini ( File input ) throws IOException , InvalidFileFormatException { this ( ) ; setFile ( input ) ; load ( ) ; } public Wini ( URL input ) throws IOException , InvalidFileFormatException { this ( ) ; load ( input ) ; } public Wini ( InputStream input ) throws IOException , InvalidFileFormatException { this ( ) ; load ( input ) ; } public Wini ( Reader input ) throws IOException , InvalidFileFormatException { this ( ) ; load ( input ) ; } public String escape ( String value ) { return WinEscapeTool . getInstance ( ) . escape ( value ) ; } public String unescape ( String value ) { return WinEscapeTool . getInstance ( ) . unescape ( value ) ; } } </s>
|
<s> package com . izforge . izpack . util . config . base ; import java . util . List ; import java . util . Map ; public interface MultiMap < K , V > extends Map < K , V > { List < V > getAll ( Object key ) ; void add ( K key , V value ) ; void add ( K key , V value , int index ) ; V get ( Object key , int index ) ; int length ( Object key ) ; V put ( K key , V value , int index ) ; List < V > putAll ( K key , List < V > values ) ; V remove ( Object key , int index ) ; } </s>
|
<s> package com . izforge . izpack . util . config ; import java . io . File ; public class OptionFileCopyTask extends ConfigurableFileCopyTask { @ Override protected void doFileOperation ( File oldFile , File newFile , File toFile , boolean patchPreserveEntries , boolean patchPreserveValues , boolean patchResolveVariables ) throws Exception { SingleOptionFileTask task = new SingleOptionFileTask ( ) ; task . setOldFile ( oldFile ) ; task . setNewFile ( newFile ) ; task . setToFile ( toFile ) ; task . setCreate ( true ) ; task . setPatchPreserveEntries ( patchPreserveEntries ) ; task . setPatchPreserveValues ( patchPreserveValues ) ; task . setPatchResolveVariables ( patchResolveVariables ) ; task . execute ( ) ; } } </s>
|
<s> package com . izforge . izpack . util . config ; import java . io . File ; public abstract class ConfigFileTask extends SingleConfigurableTask { protected File oldFile ; protected File newFile ; protected File toFile ; protected boolean cleanup ; private String comment ; public void setNewFile ( File file ) { this . newFile = file ; } public void setOldFile ( File file ) { this . oldFile = file ; } public void setToFile ( File file ) { this . toFile = file ; } public void setCleanup ( boolean cleanup ) { this . cleanup = cleanup ; } public void setComment ( String hdr ) { comment = hdr ; } protected String getComment ( ) { return this . comment ; } @ Override protected void checkAttributes ( ) throws Exception { if ( this . toFile == null ) { throw new Exception ( "<STR_LIT>" ) ; } } } </s>
|
<s> package com . izforge . izpack . util . config ; public interface ConfigurableTask { public void execute ( ) throws Exception ; } </s>
|
<s> package com . izforge . izpack . util . config ; import java . io . File ; import java . io . IOException ; import java . util . Enumeration ; import java . util . logging . Logger ; import com . izforge . izpack . util . file . FileCopyTask ; public abstract class ConfigurableFileCopyTask extends FileCopyTask implements ConfigurableTask { private static final Logger logger = Logger . getLogger ( ConfigurableFileCopyTask . class . getName ( ) ) ; private boolean patchPreserveEntries = true ; private boolean patchPreserveValues = true ; private boolean patchResolveVariables = false ; protected boolean cleanup ; public void setPatchPreserveEntries ( boolean preserveEntries ) { this . patchPreserveEntries = preserveEntries ; } public void setPatchPreserveValues ( boolean preserveValues ) { patchPreserveValues = preserveValues ; } public void setPatchResolveExpressions ( boolean resolve ) { patchResolveVariables = resolve ; } public void setCleanup ( boolean cleanup ) { this . cleanup = cleanup ; } protected abstract void doFileOperation ( File oldFile , File newFile , File toFile , boolean patchPreserveEntries , boolean patchPreserveValues , boolean patchResolveVariables ) throws Exception ; @ Override protected void doFileOperations ( ) throws Exception { if ( fileCopyMap . size ( ) > <NUM_LIT:0> ) { logger . fine ( "<STR_LIT>" + fileCopyMap . size ( ) + "<STR_LIT>" + ( fileCopyMap . size ( ) == <NUM_LIT:1> ? "<STR_LIT>" : "<STR_LIT:s>" ) + "<STR_LIT>" + destDir . getAbsolutePath ( ) ) ; Enumeration < String > e = fileCopyMap . keys ( ) ; while ( e . hasMoreElements ( ) ) { String fromFile = e . nextElement ( ) ; String [ ] toFiles = fileCopyMap . get ( fromFile ) ; for ( String toFile : toFiles ) { if ( fromFile . equals ( toFile ) ) { logger . warning ( "<STR_LIT>" + fromFile ) ; continue ; } logger . fine ( "<STR_LIT>" + fromFile + "<STR_LIT>" + toFile ) ; File to = new File ( toFile ) ; File parent = to . getParentFile ( ) ; if ( parent != null && ! parent . exists ( ) ) { parent . mkdirs ( ) ; } if ( ! to . exists ( ) ) { to . createNewFile ( ) ; } File toTmp = File . createTempFile ( "<STR_LIT>" , null , parent ) ; try { File from = new File ( fromFile ) ; doFileOperation ( from , to , toTmp , patchPreserveEntries , patchPreserveValues , patchResolveVariables ) ; getFileUtils ( ) . copyFile ( toTmp , to , forceOverwrite , preserveLastModified ) ; if ( cleanup && from . exists ( ) ) { if ( ! from . delete ( ) ) { logger . warning ( "<STR_LIT>" + from + "<STR_LIT>" ) ; } } } catch ( IOException be ) { String msg = "<STR_LIT>" + fromFile + "<STR_LIT>" + toFile + "<STR_LIT>" + be . getMessage ( ) ; File targetFile = new File ( toFile ) ; if ( targetFile . exists ( ) && ! targetFile . delete ( ) ) { msg += "<STR_LIT>" + toFile ; } throw new Exception ( msg , be ) ; } finally { toTmp . delete ( ) ; } } } } } } </s>
|
<s> package com . izforge . izpack . util . config ; import java . io . File ; public class IniFileCopyTask extends ConfigurableFileCopyTask { @ Override protected void doFileOperation ( File oldFile , File newFile , File toFile , boolean patchPreserveEntries , boolean patchPreserveValues , boolean patchResolveVariables ) throws Exception { SingleIniFileTask task = new SingleIniFileTask ( ) ; task . setOldFile ( oldFile ) ; task . setNewFile ( newFile ) ; task . setToFile ( toFile ) ; task . setCreate ( true ) ; task . setPatchPreserveEntries ( patchPreserveEntries ) ; task . setPatchPreserveValues ( patchPreserveValues ) ; task . setPatchResolveVariables ( patchResolveVariables ) ; task . execute ( ) ; } } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.