text
stringlengths 30
1.67M
|
|---|
<s> package com . izforge . izpack . core . substitutor ; import java . util . Properties ; import com . izforge . izpack . api . substitutor . SubstitutionType ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import junit . framework . TestCase ; public class SubstitutorTest extends TestCase { private final String umlautString = "<STR_LIT>" ; private final String cyrillicString = "<STR_LIT>" ; private final String japanesString = "<STR_LIT>" ; protected VariableSubstitutor subst = new VariableSubstitutorImpl ( ( Properties ) null ) ; public SubstitutorTest ( String arg0 ) { super ( arg0 ) ; } protected void setUp ( ) throws Exception { super . setUp ( ) ; } protected void tearDown ( ) throws Exception { super . tearDown ( ) ; } public void testUmlautString ( ) { String returnStr = umlautString ; try { returnStr = subst . substitute ( umlautString , SubstitutionType . TYPE_PLAIN ) ; } catch ( Exception e ) { } assertEquals ( umlautString , returnStr ) ; } public void testCyrillicString ( ) { String returnStr = cyrillicString ; try { returnStr = subst . substitute ( cyrillicString , SubstitutionType . TYPE_PLAIN ) ; } catch ( Exception e ) { } assertEquals ( cyrillicString , returnStr ) ; } public void testJapaneseString ( ) { String returnStr = japanesString ; try { returnStr = subst . substitute ( japanesString , SubstitutionType . TYPE_PLAIN ) ; } catch ( Exception e ) { } assertEquals ( japanesString , returnStr ) ; } } </s>
|
<s> package com . izforge . izpack . core . substitutor ; import static org . hamcrest . MatcherAssert . assertThat ; import java . util . Properties ; import org . hamcrest . core . Is ; import org . junit . Before ; import org . junit . Test ; import com . izforge . izpack . api . substitutor . SubstitutionType ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; public class VariableSubstitutorImplTest { private VariableSubstitutor variableSubstitutor ; @ Before public void setupVariableSubstitutor ( ) { Properties properties = new Properties ( System . getProperties ( ) ) ; properties . put ( "<STR_LIT>" , "<STR_LIT:one>" ) ; properties . put ( "<STR_LIT>" , "<STR_LIT:two>" ) ; variableSubstitutor = new VariableSubstitutorImpl ( properties ) ; } @ Test public void shouldNotSubstitute ( ) throws Exception { String res = variableSubstitutor . substitute ( "<STR_LIT>" , SubstitutionType . TYPE_PLAIN ) ; assertThat ( res , Is . is ( "<STR_LIT>" ) ) ; res = variableSubstitutor . substitute ( "<STR_LIT>" , SubstitutionType . TYPE_PLAIN ) ; assertThat ( res , Is . is ( "<STR_LIT>" ) ) ; } @ Test public void shouldSubstitutePlainText ( ) throws Exception { assertThat ( variableSubstitutor . substitute ( "<STR_LIT>" , SubstitutionType . TYPE_PLAIN ) , Is . is ( "<STR_LIT>" ) ) ; assertThat ( variableSubstitutor . substitute ( "<STR_LIT>" , SubstitutionType . TYPE_PLAIN ) , Is . is ( "<STR_LIT>" ) ) ; } @ Test public void shouldSubstituteAntType ( ) throws Exception { assertThat ( variableSubstitutor . substitute ( "<STR_LIT>" , SubstitutionType . TYPE_ANT ) , Is . is ( "<STR_LIT>" ) ) ; } @ Test public void shouldSubstituteShellType ( ) throws Exception { assertThat ( variableSubstitutor . substitute ( "<STR_LIT>" , SubstitutionType . TYPE_SHELL ) , Is . is ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . core . variable . filters ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . fail ; import java . io . File ; import java . util . Properties ; import org . junit . Test ; import com . izforge . izpack . api . data . ValueFilter ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; public class LocationFilterTest { @ Test public void testOneDirUp ( ) { VariableSubstitutor subst = new VariableSubstitutorImpl ( System . getProperties ( ) ) ; ValueFilter filter = new LocationFilter ( "<STR_LIT>" ) ; try { assertEquals ( "<STR_LIT>" . replace ( '<STR_LIT:\\>' , File . separatorChar ) , filter . filter ( "<STR_LIT>" , subst ) ) ; } catch ( Exception e ) { fail ( e . toString ( ) ) ; } } @ Test public void testOneDirUpWithSubstitution ( ) { Properties props = new Properties ( ) ; props . setProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; VariableSubstitutor subst = new VariableSubstitutorImpl ( props ) ; ValueFilter filter = new LocationFilter ( "<STR_LIT>" ) ; try { assertEquals ( "<STR_LIT>" . replace ( '<STR_LIT:\\>' , File . separatorChar ) , filter . filter ( "<STR_LIT>" , subst ) ) ; } catch ( Exception e ) { fail ( e . toString ( ) ) ; } } } </s>
|
<s> package com . izforge . izpack . core ; import org . junit . Test ; import com . izforge . izpack . api . data . Pack ; import junit . framework . TestCase ; public class PackTest { @ Test public void testToByteUnitsString ( ) { TestCase . assertEquals ( "<STR_LIT>" , Pack . toByteUnitsString ( <NUM_LIT:5> ) ) ; TestCase . assertEquals ( "<STR_LIT>" , Pack . toByteUnitsString ( <NUM_LIT> ) ) ; TestCase . assertEquals ( "<STR_LIT>" , Pack . toByteUnitsString ( <NUM_LIT> ) ) ; TestCase . assertEquals ( "<STR_LIT>" , Pack . toByteUnitsString ( <NUM_LIT> * <NUM_LIT> ) ) ; TestCase . assertEquals ( "<STR_LIT>" , Pack . toByteUnitsString ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) ) ; } } </s>
|
<s> package com . izforge . izpack . core . factory ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertNotNull ; import static org . junit . Assert . assertNotSame ; import static org . junit . Assert . assertSame ; import static org . junit . Assert . assertTrue ; import static org . junit . Assert . fail ; import org . junit . Test ; import com . izforge . izpack . api . container . Container ; import com . izforge . izpack . api . factory . ObjectFactory ; import com . izforge . izpack . core . container . DefaultContainer ; public class DefaultObjectFactoryTest { private final Container container ; private final ObjectFactory factory ; public DefaultObjectFactoryTest ( ) { container = new DefaultContainer ( ) ; factory = new DefaultObjectFactory ( container ) ; } @ Test public void testCreateNoParameters ( ) { container . addComponent ( C . class , new C ( new A ( ) ) ) ; A a1 = factory . create ( A . class ) ; assertNotNull ( a1 ) ; assertFalse ( a1 instanceof C ) ; B b1 = factory . create ( B . class ) ; assertNotNull ( b1 ) ; A a2 = factory . create ( A . class ) ; assertFalse ( a2 instanceof C ) ; assertNotNull ( a2 ) ; assertNotSame ( a2 , a1 ) ; } @ Test public void testCreateWithInjection ( ) { A a1 = new A ( ) ; container . addComponent ( A . class , a1 ) ; C c = factory . create ( C . class ) ; assertNotNull ( c ) ; assertSame ( a1 , c . a ) ; A a2 = factory . create ( A . class ) ; assertNotNull ( a2 ) ; assertNotSame ( a1 , a2 ) ; } @ Test public void testCreateWithParameters ( ) { A a = new A ( ) ; B b = new B ( ) ; D d1 = factory . create ( D . class , a , b ) ; assertNotNull ( d1 ) ; assertSame ( a , d1 . a ) ; assertSame ( b , d1 . b ) ; D d2 = factory . create ( D . class , b , a ) ; assertNotNull ( d2 ) ; assertNotSame ( d2 , d1 ) ; assertSame ( a , d2 . a ) ; assertSame ( b , d2 . b ) ; } @ Test public void testCreateByClassNameNoParameters ( ) { A a1 = factory . create ( A . class . getName ( ) , A . class ) ; A a2 = factory . create ( A . class . getName ( ) , A . class ) ; assertNotNull ( a1 ) ; assertNotNull ( a2 ) ; assertNotSame ( a1 , a2 ) ; container . addComponent ( A . class , new A ( ) ) ; A c1 = factory . create ( C . class . getName ( ) , A . class ) ; assertNotNull ( c1 ) ; assertTrue ( c1 instanceof C ) ; try { factory . create ( B . class . getName ( ) , A . class ) ; fail ( "<STR_LIT>" ) ; } catch ( ClassCastException expected ) { } } @ Test public void testCreateByClassNameWithParameters ( ) { A a = new A ( ) ; B b = new B ( ) ; Object d1 = factory . create ( D . class . getName ( ) , Object . class , a , b ) ; assertNotNull ( d1 ) ; assertSame ( a , ( ( D ) d1 ) . a ) ; assertSame ( b , ( ( D ) d1 ) . b ) ; Object d2 = factory . create ( D . class . getName ( ) , Object . class , b , a ) ; assertNotNull ( d2 ) ; assertNotSame ( d2 , d1 ) ; assertSame ( a , ( ( D ) d2 ) . a ) ; assertSame ( b , ( ( D ) d2 ) . b ) ; } @ Test public void testCreateByClassNameWithInjection ( ) { A a1 = new A ( ) ; container . addComponent ( A . class , a1 ) ; A c = factory . create ( C . class . getName ( ) , A . class ) ; assertNotNull ( c ) ; assertTrue ( c instanceof C ) ; assertSame ( a1 , ( ( C ) c ) . a ) ; } public static class A { } public static class B { } public static class C extends A { public final A a ; public C ( A a ) { this . a = a ; } } public static class D { public final A a ; public final B b ; public D ( A a , B b ) { this . a = a ; this . b = b ; } } } </s>
|
<s> package com . izforge . izpack . core . data ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertNull ; import java . util . HashMap ; import java . util . Map ; import org . junit . Test ; import com . izforge . izpack . api . data . AutomatedInstallData ; import com . izforge . izpack . api . data . DynamicVariable ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . rules . Condition ; import com . izforge . izpack . core . container . DefaultContainer ; import com . izforge . izpack . core . rules . ConditionContainer ; import com . izforge . izpack . core . rules . RulesEngineImpl ; import com . izforge . izpack . core . rules . process . VariableCondition ; import com . izforge . izpack . core . variable . PlainValue ; import com . izforge . izpack . util . Platforms ; public class DefaultVariablesTest { private final Variables variables = new DefaultVariables ( ) ; @ Test public void testStringVariables ( ) { variables . set ( "<STR_LIT>" , "<STR_LIT:value1>" ) ; assertEquals ( variables . get ( "<STR_LIT>" ) , "<STR_LIT:value1>" ) ; variables . set ( "<STR_LIT:null>" , null ) ; assertNull ( variables . get ( "<STR_LIT:null>" ) ) ; assertEquals ( "<STR_LIT:default>" , variables . get ( "<STR_LIT:null>" , "<STR_LIT:default>" ) ) ; assertNull ( variables . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT:default>" , variables . get ( "<STR_LIT>" , "<STR_LIT:default>" ) ) ; } @ Test public void testBooleanVariables ( ) { variables . set ( "<STR_LIT>" , "<STR_LIT:true>" ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:false>" ) ; assertEquals ( true , variables . getBoolean ( "<STR_LIT>" ) ) ; assertEquals ( false , variables . getBoolean ( "<STR_LIT>" ) ) ; variables . set ( "<STR_LIT:null>" , null ) ; assertEquals ( false , variables . getBoolean ( "<STR_LIT:null>" ) ) ; assertEquals ( true , variables . getBoolean ( "<STR_LIT:null>" , true ) ) ; assertEquals ( false , variables . getBoolean ( "<STR_LIT>" ) ) ; assertEquals ( true , variables . getBoolean ( "<STR_LIT>" , true ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:yes>" ) ; assertEquals ( false , variables . getBoolean ( "<STR_LIT>" ) ) ; assertEquals ( true , variables . getBoolean ( "<STR_LIT>" , true ) ) ; } @ Test public void testIntVariables ( ) { variables . set ( "<STR_LIT>" , "<STR_LIT:0>" ) ; variables . set ( "<STR_LIT>" , Integer . toString ( Integer . MIN_VALUE ) ) ; variables . set ( "<STR_LIT>" , Integer . toString ( Integer . MAX_VALUE ) ) ; assertEquals ( <NUM_LIT:0> , variables . getInt ( "<STR_LIT>" ) ) ; assertEquals ( Integer . MIN_VALUE , variables . getInt ( "<STR_LIT>" ) ) ; assertEquals ( Integer . MAX_VALUE , variables . getInt ( "<STR_LIT>" ) ) ; variables . set ( "<STR_LIT:null>" , null ) ; assertEquals ( - <NUM_LIT:1> , variables . getInt ( "<STR_LIT:null>" ) ) ; assertEquals ( <NUM_LIT> , variables . getInt ( "<STR_LIT:null>" , <NUM_LIT> ) ) ; assertEquals ( - <NUM_LIT:1> , variables . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , variables . getInt ( "<STR_LIT>" , <NUM_LIT> ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT>" ) ; assertEquals ( - <NUM_LIT:1> , variables . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , variables . getInt ( "<STR_LIT>" , <NUM_LIT> ) ) ; variables . set ( "<STR_LIT>" , Long . toString ( Long . MIN_VALUE ) ) ; variables . set ( "<STR_LIT>" , Long . toString ( Long . MAX_VALUE ) ) ; assertEquals ( - <NUM_LIT:1> , variables . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , variables . getInt ( "<STR_LIT>" , <NUM_LIT> ) ) ; assertEquals ( - <NUM_LIT:1> , variables . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , variables . getInt ( "<STR_LIT>" , <NUM_LIT> ) ) ; } @ Test public void testLongVariables ( ) { variables . set ( "<STR_LIT>" , "<STR_LIT:0>" ) ; assertEquals ( <NUM_LIT:0> , variables . getLong ( "<STR_LIT>" ) ) ; variables . set ( "<STR_LIT:null>" , null ) ; assertEquals ( - <NUM_LIT:1> , variables . getLong ( "<STR_LIT:null>" ) ) ; assertEquals ( <NUM_LIT> , variables . getLong ( "<STR_LIT:null>" , <NUM_LIT> ) ) ; assertEquals ( - <NUM_LIT:1> , variables . getLong ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , variables . getLong ( "<STR_LIT>" , <NUM_LIT> ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT>" ) ; assertEquals ( - <NUM_LIT:1> , variables . getLong ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , variables . getLong ( "<STR_LIT>" , <NUM_LIT> ) ) ; } @ Test public void testReplace ( ) { variables . set ( "<STR_LIT>" , "<STR_LIT:Hello>" ) ; variables . set ( "<STR_LIT>" , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , variables . replace ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , variables . replace ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , variables . replace ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , variables . replace ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , variables . replace ( "<STR_LIT>" ) ) ; assertNull ( variables . replace ( null ) ) ; } @ Test public void testDynamicVariables ( ) { variables . add ( createDynamic ( "<STR_LIT>" , "<STR_LIT>" ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:a>" ) ; assertNull ( variables . get ( "<STR_LIT>" ) ) ; variables . refresh ( ) ; assertEquals ( "<STR_LIT:a>" , variables . get ( "<STR_LIT>" ) ) ; } @ Test public void testConditionalDynamicVariables ( ) { Map < String , Condition > conditions = new HashMap < String , Condition > ( ) ; conditions . put ( "<STR_LIT>" , new VariableCondition ( "<STR_LIT>" , "<STR_LIT>" ) ) ; conditions . put ( "<STR_LIT>" , new VariableCondition ( "<STR_LIT>" , "<STR_LIT>" ) ) ; AutomatedInstallData installData = new AutomatedInstallData ( variables , Platforms . FREEBSD ) ; RulesEngineImpl rules = new RulesEngineImpl ( installData , new ConditionContainer ( new DefaultContainer ( ) ) , installData . getPlatform ( ) ) ; rules . readConditionMap ( conditions ) ; ( ( DefaultVariables ) variables ) . setRules ( rules ) ; variables . add ( createDynamic ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; variables . add ( createDynamic ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT>" ) ; variables . refresh ( ) ; assertEquals ( "<STR_LIT>" , variables . get ( "<STR_LIT>" ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT>" ) ; variables . refresh ( ) ; assertEquals ( "<STR_LIT>" , variables . get ( "<STR_LIT>" ) ) ; } private DynamicVariable createDynamic ( String name , String value ) { return createDynamic ( name , value , null ) ; } private DynamicVariable createDynamic ( String name , String value , String conditionId ) { DynamicVariableImpl result = new DynamicVariableImpl ( ) ; result . setName ( name ) ; result . setValue ( new PlainValue ( value ) ) ; result . setConditionid ( conditionId ) ; return result ; } } </s>
|
<s> package com . izforge . izpack . core . data ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . fail ; import java . io . File ; import java . util . Properties ; import org . junit . Test ; import com . izforge . izpack . api . data . DynamicVariable ; import com . izforge . izpack . api . data . ValueFilter ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; import com . izforge . izpack . core . variable . PlainValue ; import com . izforge . izpack . core . variable . filters . LocationFilter ; public class DynamicVariableImplTest { @ Test public void testSimple ( ) { Properties props = new Properties ( ) ; props . setProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; VariableSubstitutor subst = new VariableSubstitutorImpl ( props ) ; ValueFilter filter = new LocationFilter ( "<STR_LIT>" ) ; DynamicVariable dynvar = new DynamicVariableImpl ( ) ; dynvar . setValue ( new PlainValue ( "<STR_LIT>" ) ) ; dynvar . addFilter ( filter ) ; try { assertEquals ( "<STR_LIT>" . replace ( '<STR_LIT:\\>' , File . separatorChar ) , dynvar . evaluate ( subst ) ) ; } catch ( Exception e ) { fail ( e . toString ( ) ) ; } } } </s>
|
<s> package com . coi . tools . os . win . resources ; import java . util . ListResourceBundle ; public class NativeLibErr extends ListResourceBundle { private static final Object [ ] [ ] contents = { { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } } ; public NativeLibErr ( ) { super ( ) ; } protected Object [ ] [ ] getContents ( ) { return contents ; } } </s>
|
<s> package com . coi . tools . os . win . resources ; import java . util . ListResourceBundle ; public class NativeLibErr_de extends ListResourceBundle { private static final Object [ ] [ ] contents = { { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" } } ; protected Object [ ] [ ] getContents ( ) { return contents ; } public NativeLibErr_de ( ) { super ( ) ; } } </s>
|
<s> package com . coi . tools . os . win ; import com . izforge . izpack . api . exception . NativeLibException ; import java . util . ArrayList ; import java . util . List ; public class RegistryImpl implements MSWinConstants { private static final String DEFAULT_PLACEHOLDER = "<STR_LIT>" ; private int currentRoot = HKEY_CURRENT_USER ; private boolean logPrevSetValueFlag = true ; private List logging = new ArrayList ( ) ; private boolean doLogging = false ; public RegistryImpl ( ) { super ( ) ; } public int getRoot ( ) { return currentRoot ; } public void setRoot ( int i ) { currentRoot = i ; } public boolean getLogPrevSetValueFlag ( ) { return logPrevSetValueFlag ; } public void setLogPrevSetValueFlag ( boolean flagVal ) { logPrevSetValueFlag = flagVal ; } public RegDataContainer getValue ( String key , String value ) throws NativeLibException { if ( key == null ) { key = "<STR_LIT>" ; } return ( getValue ( currentRoot , key , value ) ) ; } public Object getValueAsObject ( String key , String value ) throws NativeLibException { if ( key == null ) { key = "<STR_LIT>" ; } return ( getValue ( currentRoot , key , value ) . getDataAsObject ( ) ) ; } public String [ ] getSubkeys ( String key ) throws NativeLibException { if ( key == null ) { key = "<STR_LIT>" ; } return ( getSubkeyNames ( currentRoot , key ) ) ; } public String [ ] getValueNames ( String key ) throws NativeLibException { if ( key == null ) { key = "<STR_LIT>" ; } return ( getValueNames ( currentRoot , key ) ) ; } public void createKey ( String key ) throws NativeLibException { createKey ( currentRoot , key ) ; } public void createKey ( int root , String key ) throws NativeLibException { int pathEnd = key . lastIndexOf ( '<STR_LIT:\\>' ) ; if ( pathEnd > <NUM_LIT:0> ) { String subkey = key . substring ( <NUM_LIT:0> , pathEnd ) ; if ( ! exist ( root , subkey ) ) { createKey ( root , subkey ) ; } } createKeyN ( root , key ) ; RegistryLogItem rli = new RegistryLogItem ( RegistryLogItem . CREATED_KEY , root , key , null , null , null ) ; log ( rli ) ; } public boolean keyExist ( String key ) throws NativeLibException { return ( keyExist ( currentRoot , key ) ) ; } public boolean keyExist ( int root , String key ) throws NativeLibException { try { return ( exist ( root , key ) ) ; } catch ( NativeLibException ne ) { String em = ne . getLibMessage ( ) ; if ( "<STR_LIT>" . equals ( em ) ) { return ( false ) ; } throw ( ne ) ; } } public boolean valueExist ( String key , String value ) throws NativeLibException { if ( key == null ) { key = "<STR_LIT>" ; } try { this . getValue ( currentRoot , key , value ) ; } catch ( NativeLibException ne ) { String em = ne . getLibMessage ( ) ; if ( "<STR_LIT>" . equals ( em ) || "<STR_LIT>" . equals ( em ) ) { return ( false ) ; } throw ( ne ) ; } return ( true ) ; } public void setValue ( String key , String value , String contents ) throws NativeLibException { setValue ( currentRoot , key , value , new RegDataContainer ( contents ) ) ; } public void setValue ( String key , String value , String [ ] contents ) throws NativeLibException { setValue ( currentRoot , key , value , new RegDataContainer ( contents ) ) ; } public void setValue ( String key , String value , byte [ ] contents ) throws NativeLibException { setValue ( currentRoot , key , value , new RegDataContainer ( contents ) ) ; } public void setValue ( String key , String value , long contents ) throws NativeLibException { setValue ( currentRoot , key , value , new RegDataContainer ( contents ) ) ; } public void setValue ( String key , String value , RegDataContainer contents ) throws NativeLibException { setValue ( currentRoot , key , value , contents ) ; } public void setValue ( int root , String key , String value , RegDataContainer contents ) throws NativeLibException { RegDataContainer oldContents = null ; String localValue = value ; if ( key == null ) { key = "<STR_LIT>" ; } if ( value == null ) { value = "<STR_LIT>" ; } key = key . replace ( '<CHAR_LIT:/>' , '<STR_LIT:\\>' ) ; synchronized ( logging ) { if ( ! logPrevSetValueFlag ) { setValueR ( root , key , value , contents ) ; return ; } try { oldContents = getValue ( currentRoot , key , value ) ; } catch ( NativeLibException ne ) { String em = ne . getLibMessage ( ) ; if ( "<STR_LIT>" . equals ( em ) || "<STR_LIT>" . equals ( em ) ) { setValueR ( root , key , value , contents ) ; return ; } throw ( ne ) ; } setValueN ( root , key , value , contents ) ; if ( value . length ( ) == <NUM_LIT:0> ) { localValue = DEFAULT_PLACEHOLDER ; } RegistryLogItem rli = new RegistryLogItem ( RegistryLogItem . CHANGED_VALUE , root , key , localValue , contents , oldContents ) ; log ( rli ) ; } } public void deleteKey ( String key ) throws NativeLibException { deleteKeyL ( currentRoot , key ) ; } public void deleteKeyIfEmpty ( String key ) throws NativeLibException { deleteKeyIfEmpty ( currentRoot , key ) ; } public void deleteKeyIfEmpty ( int root , String key ) throws NativeLibException { if ( keyExist ( root , key ) && isKeyEmpty ( root , key ) ) { deleteKeyL ( root , key ) ; } } public void deleteValue ( String key , String value ) throws NativeLibException { deleteValueL ( currentRoot , key , value ) ; } private void deleteKeyL ( int root , String key ) throws NativeLibException { RegistryLogItem rli = new RegistryLogItem ( RegistryLogItem . REMOVED_KEY , root , key , null , null , null ) ; log ( rli ) ; deleteKeyN ( root , key ) ; } private void deleteValueL ( int root , String key , String value ) throws NativeLibException { if ( key == null ) { key = "<STR_LIT>" ; } RegDataContainer oldContents = getValue ( currentRoot , key , value ) ; RegistryLogItem rli = new RegistryLogItem ( RegistryLogItem . REMOVED_VALUE , root , key , value , null , oldContents ) ; log ( rli ) ; deleteValueN ( currentRoot , key , value ) ; } public void rewind ( ) throws IllegalArgumentException , NativeLibException { synchronized ( logging ) { suspendLogging ( ) ; for ( Object aLogging : logging ) { RegistryLogItem rli = ( RegistryLogItem ) aLogging ; String rliValueName = ( DEFAULT_PLACEHOLDER . equals ( rli . getValueName ( ) ) ) ? "<STR_LIT>" : rli . getValueName ( ) ; switch ( rli . getType ( ) ) { case RegistryLogItem . CREATED_KEY : deleteKeyIfEmpty ( rli . getRoot ( ) , rli . getKey ( ) ) ; break ; case RegistryLogItem . REMOVED_KEY : createKeyN ( rli . getRoot ( ) , rli . getKey ( ) ) ; break ; case RegistryLogItem . CREATED_VALUE : RegDataContainer currentContents = null ; try { currentContents = getValue ( rli . getRoot ( ) , rli . getKey ( ) , rliValueName ) ; } catch ( NativeLibException nle ) { break ; } if ( currentContents . equals ( rli . getNewValue ( ) ) ) { deleteValueN ( rli . getRoot ( ) , rli . getKey ( ) , rliValueName ) ; } break ; case RegistryLogItem . REMOVED_VALUE : try { getValue ( rli . getRoot ( ) , rli . getKey ( ) , rliValueName ) ; } catch ( NativeLibException nle ) { setValueN ( rli . getRoot ( ) , rli . getKey ( ) , rliValueName , rli . getOldValue ( ) ) ; } break ; case RegistryLogItem . CHANGED_VALUE : try { currentContents = getValue ( rli . getRoot ( ) , rli . getKey ( ) , rliValueName ) ; } catch ( NativeLibException nle ) { break ; } if ( currentContents . equals ( rli . getNewValue ( ) ) ) { setValueN ( rli . getRoot ( ) , rli . getKey ( ) , rliValueName , rli . getOldValue ( ) ) ; } break ; } } } } private void setValueR ( int root , String key , String value , RegDataContainer contents ) throws NativeLibException { String localValue = value ; if ( ! exist ( root , key ) ) { createKey ( root , key ) ; } setValueN ( root , key , value , contents ) ; if ( value . length ( ) == <NUM_LIT:0> ) { localValue = DEFAULT_PLACEHOLDER ; } StringBuffer sb = new StringBuffer ( ) ; sb . append ( "<STR_LIT>" ) . append ( Integer . toString ( root ) ) . append ( "<STR_LIT:;>" ) . append ( key ) . append ( "<STR_LIT:;>" ) . append ( localValue ) ; RegistryLogItem rli = new RegistryLogItem ( RegistryLogItem . CREATED_VALUE , root , key , localValue , contents , null ) ; log ( rli ) ; } private native boolean exist ( int root , String key ) throws NativeLibException ; private native void createKeyN ( int root , String key ) throws NativeLibException ; private native void setValueN ( int root , String key , String value , RegDataContainer contents ) throws NativeLibException ; private native RegDataContainer getValue ( int root , String key , String value ) throws NativeLibException ; private native void deleteValueN ( int root , String key , String value ) throws NativeLibException ; private native void deleteKeyN ( int root , String key ) throws NativeLibException ; private native boolean isKeyEmpty ( int root , String key ) throws NativeLibException ; private native String [ ] getSubkeyNames ( int root , String key ) throws NativeLibException ; private native String [ ] getValueNames ( int root , String key ) throws NativeLibException ; public void resetLogging ( ) { logging = new ArrayList ( ) ; activateLogging ( ) ; } public void suspendLogging ( ) { doLogging = false ; } public void activateLogging ( ) { doLogging = true ; } public List < Object > getLoggingInfo ( ) { ArrayList < Object > retval = new ArrayList < Object > ( logging . size ( ) ) ; for ( Object aLogging : logging ) { try { retval . add ( ( ( RegistryLogItem ) aLogging ) . clone ( ) ) ; } catch ( CloneNotSupportedException e ) { e . printStackTrace ( ) ; } } return ( retval ) ; } public void setLoggingInfo ( List info ) { resetLogging ( ) ; addLoggingInfo ( info ) ; } public void addLoggingInfo ( List info ) { for ( Object anInfo : info ) { try { logging . add ( ( ( RegistryLogItem ) anInfo ) . clone ( ) ) ; } catch ( CloneNotSupportedException e ) { e . printStackTrace ( ) ; } } } private void log ( RegistryLogItem item ) { if ( doLogging && logging != null ) { logging . add ( <NUM_LIT:0> , item ) ; } } } </s>
|
<s> package com . coi . tools . os . win ; public interface MSWinConstants { static final int HKEY_CLASSES_ROOT = <NUM_LIT> ; static final int HKEY_CURRENT_USER = <NUM_LIT> ; static final int HKEY_LOCAL_MACHINE = <NUM_LIT> ; static final int HKEY_USERS = <NUM_LIT> ; static final int HKEY_PERFORMANCE_DATA = <NUM_LIT> ; static final int HKEY_CURRENT_CONFIG = <NUM_LIT> ; static final int HKEY_DYN_DATA = <NUM_LIT> ; static final int REG_NONE = <NUM_LIT:0> ; static final int REG_SZ = <NUM_LIT:1> ; static final int REG_EXPAND_SZ = <NUM_LIT:2> ; static final int REG_BINARY = <NUM_LIT:3> ; static final int REG_DWORD = <NUM_LIT:4> ; static final int REG_LINK = <NUM_LIT:6> ; static final int REG_MULTI_SZ = <NUM_LIT:7> ; static final int FILE_READ_DATA = <NUM_LIT> ; static final int FILE_LIST_DIRECTORY = <NUM_LIT> ; static final int FILE_WRITE_DATA = <NUM_LIT> ; static final int FILE_ADD_FILE = <NUM_LIT> ; static final int FILE_APPEND_DATA = <NUM_LIT> ; static final int FILE_ADD_SUBDIRECTORY = <NUM_LIT> ; static final int FILE_CREATE_PIPE_INSTANCE = <NUM_LIT> ; static final int FILE_READ_EA = <NUM_LIT> ; static final int FILE_WRITE_EA = <NUM_LIT> ; static final int FILE_EXECUTE = <NUM_LIT> ; static final int FILE_TRAVERSE = <NUM_LIT> ; static final int FILE_DELETE_CHILD = <NUM_LIT> ; static final int FILE_READ_ATTRIBUTES = <NUM_LIT> ; static final int FILE_WRITE_ATTRIBUTES = <NUM_LIT> ; static final int DELETE = <NUM_LIT> ; static final int READ_CONTROL = <NUM_LIT> ; static final int WRITE_DAC = <NUM_LIT> ; static final int WRITE_OWNER = <NUM_LIT> ; static final int SYNCHRONIZE = <NUM_LIT> ; static final int STANDARD_RIGHTS_REQUIRED = <NUM_LIT> ; static final int STANDARD_RIGHTS_READ = <NUM_LIT> ; static final int STANDARD_RIGHTS_WRITE = <NUM_LIT> ; static final int STANDARD_RIGHTS_EXECUTE = <NUM_LIT> ; static final int STANDARD_RIGHTS_ALL = <NUM_LIT> ; static final int SPECIFIC_RIGHTS_ALL = <NUM_LIT> ; static final int FILE_ALL_ACCESS = <NUM_LIT> ; static final int FILE_GENERIC_READ = <NUM_LIT> ; static final int FILE_GENERIC_WRITE = <NUM_LIT> ; static final int FILE_GENERIC_EXECUTE = <NUM_LIT> ; static final int ACCESS_SYSTEM_SECURITY = <NUM_LIT> ; static final int MAXIMUM_ALLOWED = <NUM_LIT> ; static final int GENERIC_READ = <NUM_LIT> ; static final int GENERIC_WRITE = <NUM_LIT> ; static final int GENERIC_EXECUTE = <NUM_LIT> ; static final int GENERIC_ALL = <NUM_LIT> ; static final int FILE_CASE_SENSITIVE_SEARCH = <NUM_LIT> ; static final int FILE_CASE_PRESERVED_NAMES = <NUM_LIT> ; static final int FILE_UNICODE_ON_DISK = <NUM_LIT> ; static final int FILE_PERSISTENT_ACLS = <NUM_LIT> ; static final int FILE_FILE_COMPRESSION = <NUM_LIT> ; static final int FILE_VOLUME_QUOTAS = <NUM_LIT> ; static final int FILE_SUPPORTS_SPARSE_FILES = <NUM_LIT> ; static final int FILE_SUPPORTS_REPARSE_POINTS = <NUM_LIT> ; static final int FILE_SUPPORTS_REMOTE_STORAGE = <NUM_LIT> ; static final int FILE_VOLUME_IS_COMPRESSED = <NUM_LIT> ; static final int FILE_SUPPORTS_OBJECT_IDS = <NUM_LIT> ; static final int FILE_SUPPORTS_ENCRYPTION = <NUM_LIT> ; } </s>
|
<s> package com . coi . tools . os . win ; import java . util . ArrayList ; public class AccessControlList extends java . util . ArrayList { private static final long serialVersionUID = - <NUM_LIT> ; private ArrayList < AccessControlEntry > permissions = new ArrayList < AccessControlEntry > ( ) ; public AccessControlList ( ) { super ( ) ; } public void setACE ( String owner , int allowed , int denied ) { AccessControlEntry ace = new AccessControlEntry ( owner , allowed , denied ) ; permissions . add ( ace ) ; } public AccessControlEntry getACE ( int num ) { return ( ( AccessControlEntry ) ( ( permissions . get ( num ) ) . clone ( ) ) ) ; } public int getACECount ( ) { return ( permissions . size ( ) ) ; } public static class AccessControlEntry implements Cloneable { private String owner ; private int accessAllowdMask ; private int accessDeniedMask ; public AccessControlEntry ( ) { super ( ) ; } public AccessControlEntry ( String owner2 , int allowed , int denied ) { owner = owner2 ; accessAllowdMask = allowed ; accessDeniedMask = denied ; } public String getOwner ( ) { return owner ; } public void setOwner ( String owner ) { this . owner = owner ; } public int getAccessAllowdMask ( ) { return accessAllowdMask ; } public void setAccessAllowdMask ( int accessAllowdMask ) { this . accessAllowdMask = accessAllowdMask ; } public int getAccessDeniedMask ( ) { return accessDeniedMask ; } public void setAccessDeniedMask ( int accessDeniedMask ) { this . accessDeniedMask = accessDeniedMask ; } public Object clone ( ) { try { return ( super . clone ( ) ) ; } catch ( CloneNotSupportedException e ) { e . printStackTrace ( ) ; } return ( null ) ; } } } </s>
|
<s> package com . coi . tools . os . win ; import java . io . Serializable ; public class RegDataContainer implements Cloneable , Serializable , MSWinConstants { private static final long serialVersionUID = <NUM_LIT> ; private static final int [ ] VALID_TYPES = { <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:7> } ; private long dwordData = <NUM_LIT:0> ; private String stringData = null ; private String [ ] multiStringData = null ; private byte [ ] binData = null ; private int type = <NUM_LIT:0> ; public RegDataContainer ( ) { super ( ) ; } public RegDataContainer ( int type ) throws IllegalArgumentException { super ( ) ; if ( ! isValidType ( type ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } this . type = type ; } public RegDataContainer ( long data ) { super ( ) ; type = REG_DWORD ; dwordData = data ; } public RegDataContainer ( String data ) { super ( ) ; if ( containsPlaceholder ( data ) ) { setType ( REG_EXPAND_SZ ) ; } else { setType ( REG_SZ ) ; } stringData = data ; } public RegDataContainer ( String [ ] data ) { super ( ) ; type = REG_MULTI_SZ ; multiStringData = data ; } public RegDataContainer ( byte [ ] data ) { super ( ) ; type = REG_BINARY ; binData = data ; } public byte [ ] getBinData ( ) { return binData ; } public long getDwordData ( ) { return dwordData ; } public String [ ] getMultiStringData ( ) { return multiStringData ; } public String getStringData ( ) { return stringData ; } public int getType ( ) { return type ; } public void setBinData ( byte [ ] bytes ) { binData = bytes ; } public void setDwordData ( long dwordData ) { this . dwordData = dwordData ; } public void setMultiStringData ( String [ ] strings ) { multiStringData = strings ; } public void setStringData ( String stringData ) { this . stringData = stringData ; } public void setType ( int type ) { this . type = type ; } public boolean isValidType ( int type ) { for ( int validType : VALID_TYPES ) { if ( type == validType ) { return ( true ) ; } } return ( false ) ; } public Object getDataAsObject ( ) { switch ( type ) { case REG_SZ : case REG_EXPAND_SZ : return ( getStringData ( ) ) ; case REG_BINARY : return ( getBinData ( ) ) ; case REG_DWORD : return ( getDwordData ( ) ) ; case REG_MULTI_SZ : return ( getMultiStringData ( ) ) ; default : return ( null ) ; } } public Object clone ( ) throws CloneNotSupportedException { RegDataContainer retval = ( RegDataContainer ) super . clone ( ) ; if ( multiStringData != null ) { retval . multiStringData = new String [ multiStringData . length ] ; System . arraycopy ( multiStringData , <NUM_LIT:0> , retval . multiStringData , <NUM_LIT:0> , multiStringData . length ) ; } if ( binData != null ) { retval . binData = new byte [ binData . length ] ; System . arraycopy ( binData , <NUM_LIT:0> , retval . binData , <NUM_LIT:0> , binData . length ) ; } return ( retval ) ; } public boolean equals ( Object anObject ) { if ( this == anObject ) { return ( true ) ; } if ( anObject instanceof RegDataContainer ) { RegDataContainer other = ( RegDataContainer ) anObject ; if ( other . type != type ) { return ( false ) ; } switch ( type ) { case REG_DWORD : return ( other . dwordData == dwordData ) ; case REG_SZ : case REG_EXPAND_SZ : if ( stringData == null ) { return ( other . stringData == null ) ; } return ( stringData . equals ( other . stringData ) ) ; case REG_BINARY : if ( binData == null ) { return ( other . binData == null ) ; } if ( other . binData != null && binData . length == other . binData . length ) { for ( int i = <NUM_LIT:0> ; i < binData . length ; ++ i ) { if ( binData [ i ] != other . binData [ i ] ) { return ( false ) ; } } return ( true ) ; } return ( false ) ; case REG_MULTI_SZ : if ( multiStringData == null ) { return ( other . multiStringData == null ) ; } if ( other . multiStringData != null && multiStringData . length == other . multiStringData . length ) { for ( int i = <NUM_LIT:0> ; i < multiStringData . length ; ++ i ) { if ( multiStringData [ i ] != null ) { if ( ! multiStringData [ i ] . equals ( other . multiStringData [ i ] ) ) { return ( false ) ; } } else if ( other . multiStringData [ i ] == null ) { return ( false ) ; } } return ( true ) ; } return ( false ) ; } } return ( false ) ; } public int hashCode ( ) { int result ; result = ( int ) ( dwordData ^ ( dwordData > > > <NUM_LIT:32> ) ) ; result = <NUM_LIT> * result + ( stringData != null ? stringData . hashCode ( ) : <NUM_LIT:0> ) ; result = <NUM_LIT> * result + type ; return result ; } private boolean containsPlaceholder ( String str ) { return str . contains ( "<STR_LIT:%>" ) ; } } </s>
|
<s> package com . coi . tools . os . win ; import java . io . Serializable ; public class RegistryLogItem implements Cloneable , Serializable { private static final long serialVersionUID = <NUM_LIT> ; public static final int REMOVED_KEY = <NUM_LIT:1> ; public static final int CREATED_KEY = <NUM_LIT:2> ; public static final int REMOVED_VALUE = <NUM_LIT:3> ; public static final int CREATED_VALUE = <NUM_LIT:4> ; public static final int CHANGED_VALUE = <NUM_LIT:5> ; private int type ; private int root ; private String key ; private String valueName ; private RegDataContainer newValue = null ; private RegDataContainer oldValue = null ; private RegistryLogItem ( ) { super ( ) ; } public RegistryLogItem ( int type , int root , String key , String valueName , RegDataContainer newValue , RegDataContainer oldValue ) { this . type = type ; this . root = root ; this . key = key ; this . valueName = valueName ; this . newValue = newValue ; this . oldValue = oldValue ; } public String getKey ( ) { return key ; } public RegDataContainer getNewValue ( ) { return newValue ; } public RegDataContainer getOldValue ( ) { return oldValue ; } public int getRoot ( ) { return root ; } public int getType ( ) { return type ; } public String getValueName ( ) { return valueName ; } public void setKey ( String key ) { this . key = key ; } public void setNewValue ( RegDataContainer container ) { newValue = container ; } public void setOldValue ( RegDataContainer container ) { oldValue = container ; } public void setRoot ( int i ) { root = i ; } public void setType ( int i ) { type = i ; } public void setValueName ( String valueName ) { this . valueName = valueName ; } public Object clone ( ) throws CloneNotSupportedException { RegistryLogItem retval = ( RegistryLogItem ) super . clone ( ) ; if ( newValue != null ) { retval . newValue = ( RegDataContainer ) newValue . clone ( ) ; } if ( oldValue != null ) { retval . oldValue = ( RegDataContainer ) oldValue . clone ( ) ; } return ( retval ) ; } } </s>
|
<s> package com . coi . tools . os . izpack ; import com . coi . tools . os . win . RegistryImpl ; import com . izforge . izpack . util . Librarian ; import com . izforge . izpack . util . NativeLibraryClient ; public class Registry extends RegistryImpl implements NativeLibraryClient { private final COIOSHelper helper ; public Registry ( Librarian librarian ) { super ( ) ; helper = new COIOSHelper ( librarian ) ; helper . addDependant ( this ) ; } public void freeLibrary ( String name ) { helper . freeLibrary ( name ) ; } } </s>
|
<s> package com . coi . tools . os . izpack ; import com . izforge . izpack . util . Librarian ; import com . izforge . izpack . util . NativeLibraryClient ; public class COIOSHelper { private int used = <NUM_LIT:0> ; private boolean destroyed = false ; private final Librarian librarian ; private native void FreeLibrary ( String name ) ; public COIOSHelper ( Librarian librarian ) { this . librarian = librarian ; } public synchronized void freeLibrary ( String name ) { used -- ; if ( ! destroyed ) { FreeLibrary ( name ) ; destroyed = true ; } } public synchronized void addDependant ( NativeLibraryClient dependant ) { used ++ ; librarian . loadLibrary ( "<STR_LIT>" , dependant ) ; } } </s>
|
<s> package com . izforge . izpack . merge ; import com . izforge . izpack . api . merge . Mergeable ; public interface MergeManager extends Mergeable { void addResourceToMerge ( String resourcePath ) ; void addResourceToMerge ( String resourcePath , String destination ) ; void addResourceToMerge ( Mergeable mergeable ) ; } </s>
|
<s> package com . izforge . izpack . merge ; public enum TypeFile { FILE , DIRECTORY , JAR_CONTENT } </s>
|
<s> package com . izforge . izpack . merge . jar ; import java . io . File ; import java . io . FileFilter ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . OutputStream ; import java . net . URL ; import java . util . ArrayList ; import java . util . List ; import java . util . Map ; import java . util . jar . JarInputStream ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import java . util . zip . ZipEntry ; import java . util . zip . ZipInputStream ; import org . apache . tools . zip . ZipOutputStream ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . exception . MergeException ; import com . izforge . izpack . merge . AbstractMerge ; import com . izforge . izpack . util . FileUtil ; import com . izforge . izpack . util . IoHelper ; public class JarMerge extends AbstractMerge { private String jarPath ; private String regexp ; private String destination ; public JarMerge ( URL resource , String jarPath , Map < OutputStream , List < String > > mergeContent ) { this . jarPath = jarPath ; this . mergeContent = mergeContent ; destination = FileUtil . convertUrlToFilePath ( resource ) . replaceAll ( this . jarPath , "<STR_LIT>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT:/>" ) ; StringBuilder builder = new StringBuilder ( destination . replace ( "<STR_LIT:$>" , "<STR_LIT>" ) ) ; if ( destination . endsWith ( "<STR_LIT:/>" ) ) { builder . append ( "<STR_LIT>" ) ; } else { builder . append ( "<STR_LIT>" ) ; } regexp = builder . toString ( ) ; } public JarMerge ( String jarPath , String pathInsideJar , String destination , Map < OutputStream , List < String > > mergeContent ) { this . jarPath = jarPath ; this . destination = destination ; this . mergeContent = mergeContent ; StringBuilder builder = new StringBuilder ( ) . append ( pathInsideJar ) ; if ( pathInsideJar . endsWith ( "<STR_LIT:/>" ) ) { builder . append ( "<STR_LIT>" ) ; } else { builder . append ( "<STR_LIT>" ) ; } regexp = builder . toString ( ) ; } public File find ( FileFilter fileFilter ) { try { ArrayList < String > fileNameInZip = getFileNameInZip ( ) ; for ( String fileName : fileNameInZip ) { File file = new File ( jarPath + "<STR_LIT>" + fileName ) ; if ( fileFilter . accept ( file ) ) { return file ; } } } catch ( IOException e ) { throw new RuntimeException ( e ) ; } return null ; } public List < File > recursivelyListFiles ( FileFilter fileFilter ) { try { ArrayList < String > fileNameInZip = getFileNameInZip ( ) ; ArrayList < File > result = new ArrayList < File > ( ) ; ArrayList < File > filteredResult = new ArrayList < File > ( ) ; for ( String fileName : fileNameInZip ) { result . add ( new File ( jarPath + "<STR_LIT:!>" + fileName ) ) ; } for ( File file : result ) { if ( fileFilter . accept ( file ) ) { filteredResult . add ( file ) ; } } return filteredResult ; } catch ( IOException e ) { throw new MergeException ( e ) ; } } public ArrayList < String > getFileNameInZip ( ) throws IOException { ZipInputStream inputStream = new ZipInputStream ( new FileInputStream ( jarPath ) ) ; ArrayList < String > arrayList = new ArrayList < String > ( ) ; ZipEntry zipEntry ; while ( ( zipEntry = inputStream . getNextEntry ( ) ) != null ) { arrayList . add ( zipEntry . getName ( ) ) ; } return arrayList ; } public void merge ( java . util . zip . ZipOutputStream outputStream ) { Pattern pattern = Pattern . compile ( regexp ) ; List < String > mergeList = getMergeList ( outputStream ) ; ZipEntry zentry ; try { JarInputStream jarInputStream = new JarInputStream ( new FileInputStream ( new File ( jarPath ) ) ) ; while ( ( zentry = jarInputStream . getNextEntry ( ) ) != null ) { Matcher matcher = pattern . matcher ( zentry . getName ( ) ) ; if ( matcher . matches ( ) && ! isSignature ( zentry . getName ( ) ) ) { if ( mergeList . contains ( zentry . getName ( ) ) ) { continue ; } mergeList . add ( zentry . getName ( ) ) ; String matchFile = matcher . group ( <NUM_LIT:1> ) ; StringBuilder dest = new StringBuilder ( destination ) ; if ( matchFile != null && matchFile . length ( ) > <NUM_LIT:0> ) { if ( dest . length ( ) > <NUM_LIT:0> && dest . charAt ( dest . length ( ) - <NUM_LIT:1> ) != '<CHAR_LIT:/>' ) { dest . append ( '<CHAR_LIT:/>' ) ; } dest . append ( matchFile ) ; } IoHelper . copyStreamToJar ( jarInputStream , outputStream , dest . toString ( ) . replaceAll ( "<STR_LIT>" , "<STR_LIT:/>" ) , zentry . getTime ( ) ) ; } } jarInputStream . close ( ) ; } catch ( IOException e ) { throw new IzPackException ( e ) ; } } public void merge ( ZipOutputStream outJar ) { Pattern pattern = Pattern . compile ( regexp ) ; List < String > mergeList = getMergeList ( outJar ) ; ZipEntry zentry ; try { JarInputStream jarInputStream = new JarInputStream ( new FileInputStream ( new File ( jarPath ) ) ) ; while ( ( zentry = jarInputStream . getNextEntry ( ) ) != null ) { Matcher matcher = pattern . matcher ( zentry . getName ( ) ) ; if ( matcher . matches ( ) && ! isSignature ( zentry . getName ( ) ) ) { if ( mergeList . contains ( zentry . getName ( ) ) ) { continue ; } mergeList . add ( zentry . getName ( ) ) ; String matchFile = matcher . group ( <NUM_LIT:1> ) ; StringBuilder dest = new StringBuilder ( destination ) ; if ( matchFile != null && matchFile . length ( ) > <NUM_LIT:0> ) { if ( dest . length ( ) > <NUM_LIT:0> && dest . charAt ( dest . length ( ) - <NUM_LIT:1> ) != '<CHAR_LIT:/>' ) { dest . append ( '<CHAR_LIT:/>' ) ; } dest . append ( matchFile ) ; } IoHelper . copyStreamToJar ( jarInputStream , outJar , dest . toString ( ) . replaceAll ( "<STR_LIT>" , "<STR_LIT:/>" ) , zentry . getTime ( ) ) ; } } jarInputStream . close ( ) ; } catch ( IOException e ) { throw new MergeException ( e ) ; } } @ Override public String toString ( ) { return "<STR_LIT>" + "<STR_LIT>" + jarPath + '<STR_LIT>' + "<STR_LIT>" + regexp + '<STR_LIT>' + "<STR_LIT>" + destination + '<STR_LIT>' + '<CHAR_LIT:}>' ; } @ Override public boolean equals ( Object o ) { if ( this == o ) { return true ; } if ( o == null || getClass ( ) != o . getClass ( ) ) { return false ; } JarMerge jarMerge = ( JarMerge ) o ; return ( jarPath != null ) ? jarPath . equals ( jarMerge . jarPath ) : jarMerge . jarPath == null ; } @ Override public int hashCode ( ) { return jarPath != null ? jarPath . hashCode ( ) : <NUM_LIT:0> ; } private boolean isSignature ( String name ) { return name . matches ( "<STR_LIT>" ) || name . matches ( "<STR_LIT>" ) ; } } </s>
|
<s> package com . izforge . izpack . merge . resolve ; import java . io . OutputStream ; import java . net . URL ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import com . izforge . izpack . api . merge . Mergeable ; import com . izforge . izpack . merge . file . FileMerge ; import com . izforge . izpack . merge . jar . JarMerge ; public class MergeableResolver { private Map < OutputStream , List < String > > mergeContent = new HashMap < OutputStream , List < String > > ( ) ; public MergeableResolver ( ) { } public Mergeable getMergeableFromURL ( URL url ) { if ( ! ResolveUtils . isJar ( url ) ) { return new FileMerge ( url , mergeContent ) ; } return new JarMerge ( url , ResolveUtils . processUrlToJarPath ( url ) , mergeContent ) ; } public Mergeable getMergeableFromURL ( URL url , String resourcePath ) { if ( ResolveUtils . isJar ( url ) ) { return new JarMerge ( url , ResolveUtils . processUrlToJarPath ( url ) , mergeContent ) ; } else { return new FileMerge ( url , resourcePath , mergeContent ) ; } } public Mergeable getMergeableFromURLWithDestination ( URL url , String destination ) { if ( ResolveUtils . isJar ( url ) ) { if ( ResolveUtils . isFileInJar ( url ) ) { return new JarMerge ( ResolveUtils . processUrlToJarPath ( url ) , ResolveUtils . processUrlToInsidePath ( url ) , destination , mergeContent ) ; } return new JarMerge ( ResolveUtils . processUrlToJarPath ( url ) , ResolveUtils . processUrlToJarPackage ( url ) , destination , mergeContent ) ; } else { return new FileMerge ( url , destination , mergeContent ) ; } } } </s>
|
<s> package com . izforge . izpack . merge . resolve ; import java . io . File ; import java . io . IOException ; import java . net . JarURLConnection ; import java . net . MalformedURLException ; import java . net . URL ; import java . net . URLClassLoader ; import java . util . Arrays ; import java . util . Collection ; import java . util . Collections ; import java . util . Enumeration ; import java . util . HashSet ; import java . util . Set ; import java . util . zip . ZipFile ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . util . FileUtil ; public class ResolveUtils { public static final String CLASSNAME_PREFIX = "<STR_LIT>" ; public static final String BASE_CLASSNAME_PATH = CLASSNAME_PREFIX . replaceAll ( "<STR_LIT:\\.>" , "<STR_LIT:/>" ) + "<STR_LIT:/>" ; public static boolean isJar ( URL url ) { if ( "<STR_LIT>" . equals ( url . getProtocol ( ) ) ) { return true ; } String file = FileUtil . convertUrlToFilePath ( url ) ; if ( file . contains ( "<STR_LIT:!>" ) ) { file = file . substring ( <NUM_LIT:0> , file . lastIndexOf ( '<CHAR_LIT>' ) ) ; } File classFile = new File ( file ) ; return isJar ( classFile ) ; } public static boolean isJar ( File classFile ) { ZipFile zipFile = null ; try { zipFile = new ZipFile ( classFile ) ; zipFile . getName ( ) ; } catch ( IOException e ) { return false ; } finally { if ( zipFile != null ) { try { zipFile . close ( ) ; } catch ( IOException ignored ) { } } } return true ; } public static boolean isFileInJar ( URL resource ) { return resource . getPath ( ) . matches ( "<STR_LIT>" ) ; } public static String getCurrentClasspath ( ) { StringBuilder stringBuilder = new StringBuilder ( ) ; for ( URL url : getClassPathUrl ( ) ) { stringBuilder . append ( FileUtil . convertUrlToFilePath ( url ) ) ; stringBuilder . append ( '<STR_LIT:\n>' ) ; } return stringBuilder . toString ( ) ; } static Collection < URL > getClassPathUrl ( ) { Collection < URL > result = new HashSet < URL > ( ) ; java . net . URLClassLoader loader = ( URLClassLoader ) Thread . currentThread ( ) . getContextClassLoader ( ) ; result . addAll ( Arrays . asList ( loader . getURLs ( ) ) ) ; try { Enumeration < URL > urlEnumeration = loader . getResources ( "<STR_LIT>" ) ; result . addAll ( Collections . list ( urlEnumeration ) ) ; urlEnumeration = loader . getResources ( "<STR_LIT>" ) ; result . addAll ( Collections . list ( urlEnumeration ) ) ; } catch ( IOException ignored ) { } return result ; } public static URL getFileFromPath ( String path ) { URL resource = ClassLoader . getSystemResource ( path ) ; if ( resource != null ) { return resource ; } try { File file = new File ( path ) ; if ( file . exists ( ) ) { return file . toURI ( ) . toURL ( ) ; } } catch ( MalformedURLException e ) { throw new IzPackException ( e ) ; } return null ; } public static Set < URL > getJarUrlForPackage ( String packageName ) { URLClassLoader loader = ( URLClassLoader ) Thread . currentThread ( ) . getContextClassLoader ( ) ; Set < URL > result = new HashSet < URL > ( ) ; try { Enumeration < URL > urls = loader . getResources ( packageName ) ; while ( urls . hasMoreElements ( ) ) { URL url = urls . nextElement ( ) ; JarURLConnection connection = ( JarURLConnection ) url . openConnection ( ) ; result . add ( connection . getJarFileURL ( ) ) ; } } catch ( IOException ioex ) { } return result ; } public static URL processUrlToJarUrl ( URL url ) throws MalformedURLException { return new URL ( "<STR_LIT:file>" , url . getHost ( ) , processUrlToJarPath ( url ) ) ; } public static String processUrlToJarPath ( URL resource ) { String res = FileUtil . convertUrlToFilePath ( resource ) ; res = res . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( res . contains ( "<STR_LIT:!>" ) ) { return res . substring ( <NUM_LIT:0> , res . lastIndexOf ( "<STR_LIT:!>" ) ) ; } return res ; } public static String processUrlToInsidePath ( URL resource ) { String path = resource . getPath ( ) ; if ( path . contains ( "<STR_LIT:!>" ) ) { return path . substring ( path . lastIndexOf ( "<STR_LIT:!>" ) + <NUM_LIT:2> ) ; } return path ; } public static String processUrlToJarPackage ( URL resource ) { String res = FileUtil . convertUrlToFilePath ( resource ) ; res = res . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; res = res . substring ( res . lastIndexOf ( "<STR_LIT:!>" ) + <NUM_LIT:1> ) ; res = res . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( res . endsWith ( "<STR_LIT:/>" ) ) { return res ; } return res + "<STR_LIT:/>" ; } public static String getPanelsPackagePathFromClassName ( String className ) { if ( className . contains ( "<STR_LIT:.>" ) ) { return className . substring ( <NUM_LIT:0> , className . lastIndexOf ( "<STR_LIT:.>" ) ) . replaceAll ( "<STR_LIT:\\.>" , "<STR_LIT:/>" ) + "<STR_LIT:/>" ; } return BASE_CLASSNAME_PATH ; } public static boolean isFile ( URL url ) { return ! FileUtil . convertUrlToFile ( url ) . isDirectory ( ) ; } public static String convertPathToPosixPath ( String path ) { return path . replaceAll ( "<STR_LIT>" , "<STR_LIT:/>" ) ; } public static String convertPathToPosixPath ( File file ) { return convertPathToPosixPath ( file . getAbsolutePath ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . merge . resolve ; import java . io . IOException ; import java . net . URL ; import java . net . URLClassLoader ; import java . util . ArrayList ; import java . util . Enumeration ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . merge . Mergeable ; public class PathResolver { private final MergeableResolver mergeableResolver ; public PathResolver ( MergeableResolver mergeableResolver ) { this . mergeableResolver = mergeableResolver ; } public Set < URL > resolvePath ( String sourcePath ) { Set < URL > result = findResources ( sourcePath ) ; if ( result . isEmpty ( ) ) { throw new IzPackException ( "<STR_LIT>" + sourcePath + "<STR_LIT>" + "<STR_LIT>" + ResolveUtils . getCurrentClasspath ( ) ) ; } return result ; } public List < Mergeable > getMergeableFromPath ( String resourcePath ) { Set < URL > urlList = resolvePath ( resourcePath ) ; List < Mergeable > result = new ArrayList < Mergeable > ( ) ; for ( URL url : urlList ) { result . add ( mergeableResolver . getMergeableFromURL ( url , resourcePath ) ) ; } return result ; } public List < Mergeable > getMergeableFromPackageName ( String dependPackage ) { return getMergeableFromPath ( dependPackage . replaceAll ( "<STR_LIT:\\.>" , "<STR_LIT:/>" ) + "<STR_LIT:/>" ) ; } public List < Mergeable > getMergeableJarFromPackageName ( String packageName ) { Set < URL > urlSet = ResolveUtils . getJarUrlForPackage ( packageName ) ; ArrayList < Mergeable > list = new ArrayList < Mergeable > ( ) ; for ( URL url : urlSet ) { list . add ( mergeableResolver . getMergeableFromURL ( url ) ) ; } return list ; } public List < Mergeable > getMergeableFromPath ( String resourcePath , String destination ) { Set < URL > urlList = resolvePath ( resourcePath ) ; List < Mergeable > result = new ArrayList < Mergeable > ( ) ; for ( URL url : urlList ) { result . add ( mergeableResolver . getMergeableFromURLWithDestination ( url , destination ) ) ; } return result ; } protected Set < URL > findResources ( String resourcePath ) { Set < URL > result = new HashSet < URL > ( ) ; URL path = ResolveUtils . getFileFromPath ( resourcePath ) ; if ( path != null ) { result . add ( path ) ; } ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( loader instanceof URLClassLoader ) { try { Enumeration < URL > iterator = ( ( URLClassLoader ) loader ) . findResources ( resourcePath ) ; while ( iterator . hasMoreElements ( ) ) { URL url = iterator . nextElement ( ) ; result . add ( url ) ; } } catch ( IOException e ) { throw new IzPackException ( e ) ; } } return result ; } protected MergeableResolver getMergeableResolver ( ) { return mergeableResolver ; } } </s>
|
<s> package com . izforge . izpack . merge ; import java . io . OutputStream ; import java . util . ArrayList ; import java . util . List ; import java . util . Map ; import com . izforge . izpack . api . merge . Mergeable ; public abstract class AbstractMerge implements Mergeable { protected Map < OutputStream , List < String > > mergeContent ; protected List < String > getMergeList ( OutputStream outputStream ) { if ( ! mergeContent . containsKey ( outputStream ) ) { mergeContent . put ( outputStream , new ArrayList < String > ( ) ) ; } return mergeContent . get ( outputStream ) ; } } </s>
|
<s> package com . izforge . izpack . merge ; import java . io . File ; import java . net . URL ; import java . util . Arrays ; import java . util . List ; import java . util . Set ; import com . izforge . izpack . api . exception . MergeException ; import com . izforge . izpack . merge . resolve . ResolveUtils ; import com . izforge . izpack . util . FileUtil ; public class ClassResolver { public static final List < String > packageBegin = Arrays . asList ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; public static String processFileToClassName ( File file ) { String absolutePath = ResolveUtils . convertPathToPosixPath ( file . getAbsolutePath ( ) ) ; for ( String packageString : packageBegin ) { if ( ! absolutePath . contains ( packageString ) ) { continue ; } return absolutePath . substring ( absolutePath . lastIndexOf ( packageString ) ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT:/>" , "<STR_LIT:.>" ) ; } throw new MergeException ( "<STR_LIT>" + file . getPath ( ) ) ; } public static String processFileToClassName ( File file , Package aPackage ) { String absolutePath = ResolveUtils . convertPathToPosixPath ( file . getAbsolutePath ( ) ) ; String packagePath = convertPackageToPath ( aPackage . getName ( ) ) ; if ( ClassResolver . isFilePathContainingPackage ( file . getAbsolutePath ( ) , aPackage ) ) { return absolutePath . substring ( absolutePath . lastIndexOf ( packagePath ) ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT:/>" , "<STR_LIT:.>" ) ; } throw new MergeException ( "<STR_LIT>" + file + "<STR_LIT>" + aPackage ) ; } public static String processURLToClassName ( URL url ) { return processFileToClassName ( FileUtil . convertUrlToFile ( url ) ) ; } public static boolean isFullClassName ( String className ) { return className . contains ( "<STR_LIT:.>" ) ; } public static String getLastPackagePart ( String packageName ) { String [ ] packages = packageName . split ( "<STR_LIT:\\.>" ) ; return packages [ packages . length - <NUM_LIT:1> ] ; } public static String convertPackageToPath ( String packageName ) { return packageName . replaceAll ( "<STR_LIT:\\.>" , "<STR_LIT:/>" ) ; } public static boolean isFilePathContainingPackage ( String filePath , Package aPackage ) { return filePath . contains ( aPackage . getName ( ) . replaceAll ( "<STR_LIT:\\.>" , "<STR_LIT:/>" ) ) ; } public static boolean isFilePathInsidePackageSet ( String filePath , Set < Package > packageSet ) { for ( Package aPackage : packageSet ) { if ( filePath . contains ( aPackage . getName ( ) . replaceAll ( "<STR_LIT:\\.>" , "<STR_LIT:/>" ) ) ) { return true ; } } return false ; } public static boolean isUrlContainingPackage ( URL url , String aPackage ) { return FileUtil . convertUrlToFilePath ( url ) . contains ( aPackage . replaceAll ( "<STR_LIT:\\.>" , "<STR_LIT:/>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . merge . file ; import java . io . File ; import java . io . FileFilter ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . OutputStream ; import java . net . URL ; import java . util . ArrayList ; import java . util . List ; import java . util . Map ; import org . apache . tools . zip . ZipOutputStream ; import com . izforge . izpack . api . exception . MergeException ; import com . izforge . izpack . merge . AbstractMerge ; import com . izforge . izpack . merge . resolve . ResolveUtils ; import com . izforge . izpack . util . FileUtil ; import com . izforge . izpack . util . IoHelper ; public class FileMerge extends AbstractMerge { private File sourceToCopy ; private String destination ; public FileMerge ( URL url , Map < OutputStream , List < String > > mergeContent ) { this ( url , "<STR_LIT>" , mergeContent ) ; } public FileMerge ( URL url , String destination , Map < OutputStream , List < String > > mergeContent ) { this . mergeContent = mergeContent ; this . sourceToCopy = FileUtil . convertUrlToFile ( url ) ; this . destination = destination ; } public File find ( FileFilter fileFilter ) { return findRecursivelyForFile ( fileFilter , sourceToCopy ) ; } public List < File > recursivelyListFiles ( FileFilter fileFilter ) { List < File > result = new ArrayList < File > ( ) ; findRecursivelyForFiles ( fileFilter , sourceToCopy , result ) ; return result ; } private File findRecursivelyForFile ( FileFilter fileFilter , File currentFile ) { if ( currentFile . isDirectory ( ) ) { for ( File files : currentFile . listFiles ( fileFilter ) ) { File file = findRecursivelyForFile ( fileFilter , files ) ; if ( file != null ) { return file ; } } } else { return currentFile ; } return null ; } private void findRecursivelyForFiles ( FileFilter fileFilter , File currentFile , List < File > result ) { if ( currentFile . isDirectory ( ) ) { for ( File files : currentFile . listFiles ( fileFilter ) ) { result . add ( currentFile ) ; findRecursivelyForFiles ( fileFilter , files , result ) ; } } else { result . add ( currentFile ) ; } } public void merge ( ZipOutputStream outputStream ) { List < String > mergeList = getMergeList ( outputStream ) ; try { if ( mergeList . contains ( sourceToCopy . getAbsolutePath ( ) ) ) { return ; } mergeList . add ( sourceToCopy . getAbsolutePath ( ) ) ; copyFileToJar ( sourceToCopy , outputStream ) ; } catch ( IOException e ) { throw new MergeException ( e ) ; } } public void merge ( java . util . zip . ZipOutputStream outputStream ) { try { copyFileToJar ( sourceToCopy , outputStream ) ; } catch ( IOException e ) { throw new MergeException ( e ) ; } } private void copyFileToJar ( File fileToCopy , java . util . zip . ZipOutputStream outputStream ) throws IOException { if ( fileToCopy . isDirectory ( ) ) { for ( File file : fileToCopy . listFiles ( ) ) { copyFileToJar ( file , outputStream ) ; } } else { String entryName = resolveName ( fileToCopy , this . destination ) ; List < String > mergeList = getMergeList ( outputStream ) ; if ( mergeList . contains ( entryName ) ) { return ; } mergeList . add ( entryName ) ; FileInputStream inputStream = new FileInputStream ( fileToCopy ) ; IoHelper . copyStreamToJar ( inputStream , outputStream , entryName , fileToCopy . lastModified ( ) ) ; inputStream . close ( ) ; } } private void copyFileToJar ( File fileToCopy , ZipOutputStream outputStream ) throws IOException { FileInputStream inputStream = null ; if ( fileToCopy . isDirectory ( ) ) { for ( File file : fileToCopy . listFiles ( ) ) { copyFileToJar ( file , outputStream ) ; } } else { inputStream = new FileInputStream ( fileToCopy ) ; } String entryName = resolveName ( fileToCopy , this . destination ) ; List < String > mergeList = getMergeList ( outputStream ) ; if ( mergeList . contains ( entryName ) ) { return ; } mergeList . add ( entryName ) ; if ( inputStream != null ) { IoHelper . copyStreamToJar ( inputStream , outputStream , entryName , fileToCopy . lastModified ( ) ) ; inputStream . close ( ) ; } } private String resolveName ( File fileToCopy , String destination ) { if ( isFile ( destination ) ) { return destination ; } String path = ResolveUtils . convertPathToPosixPath ( this . sourceToCopy . getAbsolutePath ( ) ) ; if ( destination . equals ( "<STR_LIT>" ) ) { path = ResolveUtils . convertPathToPosixPath ( this . sourceToCopy . getParentFile ( ) . getAbsolutePath ( ) ) ; } path = path + '<CHAR_LIT:/>' ; StringBuilder builder = new StringBuilder ( ) ; builder . append ( destination ) ; String absolutePath = ResolveUtils . convertPathToPosixPath ( fileToCopy . getAbsolutePath ( ) ) ; builder . append ( absolutePath . replaceAll ( path , "<STR_LIT>" ) ) ; return builder . toString ( ) . replaceAll ( "<STR_LIT>" , "<STR_LIT:/>" ) ; } private boolean isFile ( String destination ) { if ( destination . length ( ) == <NUM_LIT:0> ) { return false ; } if ( ! destination . contains ( "<STR_LIT:/>" ) ) { return true ; } return ! destination . endsWith ( "<STR_LIT:/>" ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + "<STR_LIT>" + sourceToCopy + "<STR_LIT>" + destination + '<STR_LIT>' + '<CHAR_LIT:}>' ; } } </s>
|
<s> package com . izforge . izpack . merge ; import java . io . File ; import java . io . FileFilter ; import java . util . ArrayList ; import java . util . List ; import org . apache . tools . zip . ZipOutputStream ; import com . izforge . izpack . api . merge . Mergeable ; import com . izforge . izpack . merge . resolve . PathResolver ; public class MergeManagerImpl implements MergeManager { private List < Mergeable > mergeableList ; private PathResolver pathResolver ; public MergeManagerImpl ( PathResolver pathResolver ) { this . pathResolver = pathResolver ; mergeableList = new ArrayList < Mergeable > ( ) ; } @ Override public void addResourceToMerge ( Mergeable mergeable ) { mergeableList . add ( mergeable ) ; } @ Override public void addResourceToMerge ( String resourcePath ) { mergeableList . addAll ( pathResolver . getMergeableFromPath ( resourcePath ) ) ; } @ Override public void addResourceToMerge ( String resourcePath , String destination ) { mergeableList . addAll ( pathResolver . getMergeableFromPath ( resourcePath , destination ) ) ; } @ Override public void merge ( ZipOutputStream outputStream ) { for ( Mergeable mergeable : mergeableList ) { mergeable . merge ( outputStream ) ; } mergeableList . clear ( ) ; } @ Override public void merge ( java . util . zip . ZipOutputStream outputStream ) { for ( Mergeable mergeable : mergeableList ) { mergeable . merge ( outputStream ) ; } mergeableList . clear ( ) ; } @ Override public List < File > recursivelyListFiles ( FileFilter fileFilter ) { ArrayList < File > result = new ArrayList < File > ( ) ; for ( Mergeable mergeable : mergeableList ) { result . addAll ( mergeable . recursivelyListFiles ( fileFilter ) ) ; } return result ; } @ Override public File find ( FileFilter fileFilter ) { for ( Mergeable mergeable : mergeableList ) { File file = mergeable . find ( fileFilter ) ; if ( file != null ) { return file ; } } return null ; } @ Override public String toString ( ) { return "<STR_LIT>" + "<STR_LIT>" + mergeableList + "<STR_LIT>" + pathResolver + '<CHAR_LIT:}>' ; } } </s>
|
<s> package com . izforge . izpack . core . data ; import java . io . Serializable ; import com . izforge . izpack . api . data . DynamicInstallerRequirementValidator ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . rules . RulesEngine ; public class DynamicInstallerRequirementValidatorImpl implements DynamicInstallerRequirementValidator , Serializable { private static final long serialVersionUID = - <NUM_LIT> ; private String conditionId ; private Status severity ; private String messageId ; public DynamicInstallerRequirementValidatorImpl ( String conditionId , Status severity , String messageId ) { this . conditionId = conditionId ; this . severity = severity ; this . messageId = messageId ; } public Status validateData ( InstallData idata ) { RulesEngine rules = idata . getRules ( ) ; if ( ! rules . isConditionTrue ( conditionId ) ) { return severity ; } return Status . OK ; } public String getErrorMessageId ( ) { if ( this . messageId != null ) { return this . messageId ; } return null ; } public String getWarningMessageId ( ) { if ( this . messageId != null ) { return this . messageId ; } return null ; } public boolean getDefaultAnswer ( ) { return ( this . severity != Status . ERROR ) ; } } </s>
|
<s> package com . izforge . izpack . core . data ; import java . util . LinkedList ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . DynamicVariable ; import com . izforge . izpack . api . data . Value ; import com . izforge . izpack . api . data . ValueFilter ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; public class DynamicVariableImpl implements DynamicVariable { private static final long serialVersionUID = - <NUM_LIT> ; private static final transient Logger logger = Logger . getLogger ( DynamicVariableImpl . class . getName ( ) ) ; private String name ; private Value value ; private String conditionid ; private List < ValueFilter > filters ; private boolean checkonce = false ; private boolean ignorefailure = true ; private transient String currentValue ; @ Override public void addFilter ( ValueFilter filter ) { if ( filters == null ) { filters = new LinkedList < ValueFilter > ( ) ; } filters . add ( filter ) ; } @ Override public List < ValueFilter > getFilters ( ) { return filters ; } @ Override public void validate ( ) throws Exception { if ( name == null ) { throw new Exception ( "<STR_LIT>" ) ; } if ( value == null ) { throw new Exception ( "<STR_LIT>" + name ) ; } value . validate ( ) ; if ( filters != null ) { for ( ValueFilter filter : filters ) { filter . validate ( ) ; } } } private String filterValue ( String value , VariableSubstitutor ... substitutors ) throws Exception { String newValue = value ; if ( value != null && filters != null ) { logger . fine ( "<STR_LIT>" + name + "<STR_LIT:=>" + newValue ) ; for ( ValueFilter filter : filters ) { newValue = filter . filter ( newValue , substitutors ) ; logger . fine ( "<STR_LIT>" + filter . getClass ( ) . getSimpleName ( ) + "<STR_LIT::U+0020>" + name + "<STR_LIT:=>" + newValue ) ; } } return newValue ; } @ Override public String evaluate ( VariableSubstitutor ... substitutors ) throws Exception { String newValue = currentValue ; if ( value == null ) { return null ; } if ( checkonce && currentValue != null ) { return filterValue ( currentValue , substitutors ) ; } try { newValue = value . resolve ( substitutors ) ; if ( checkonce ) { currentValue = newValue ; } newValue = filterValue ( newValue , substitutors ) ; } catch ( Exception e ) { if ( ! ignorefailure ) { throw e ; } logger . log ( Level . WARNING , "<STR_LIT>" + getName ( ) + "<STR_LIT>" + e , e ) ; } return newValue ; } @ Override public String getName ( ) { return name ; } @ Override public void setName ( String name ) { if ( name != null ) { this . name = name ; } } @ Override public Value getValue ( ) { return this . value ; } @ Override public void setValue ( Value value ) { if ( value != null ) { this . value = value ; } } @ Override public String getConditionid ( ) { return this . conditionid ; } @ Override public void setConditionid ( String conditionid ) { if ( conditionid != null ) { this . conditionid = conditionid ; } } public boolean isCheckonce ( ) { return checkonce ; } @ Override public void setCheckonce ( boolean checkonce ) { this . checkonce = checkonce ; } public boolean isIgnoreFailure ( ) { return ignorefailure ; } @ Override public void setIgnoreFailure ( boolean ignore ) { this . ignorefailure = ignore ; } @ Override public boolean equals ( Object obj ) { if ( ( obj == null ) || ! ( obj instanceof DynamicVariable ) ) { return false ; } DynamicVariable compareObj = ( DynamicVariable ) obj ; return ( name . equals ( compareObj . getName ( ) ) && ( conditionid == null || conditionid . equals ( compareObj . getConditionid ( ) ) ) ) ; } @ Override public int hashCode ( ) { return name . hashCode ( ) ^ conditionid . hashCode ( ) ; } } </s>
|
<s> package com . izforge . izpack . core . data ; import java . util . ArrayList ; import java . util . List ; import java . util . Properties ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . DynamicVariable ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; public class DefaultVariables implements Variables { private final Properties properties ; private List < DynamicVariable > dynamicVariables = new ArrayList < DynamicVariable > ( ) ; private final VariableSubstitutor replacer ; private RulesEngine rules ; private static final Logger logger = Logger . getLogger ( DefaultVariables . class . getName ( ) ) ; public DefaultVariables ( ) { this ( new Properties ( ) ) ; } public DefaultVariables ( Properties properties ) { this . properties = properties ; replacer = new VariableSubstitutorImpl ( properties ) ; } public void setRules ( RulesEngine rules ) { this . rules = rules ; } @ Override public void set ( String name , String value ) { if ( value != null ) { properties . setProperty ( name , value ) ; } else { properties . remove ( name ) ; } } @ Override public String get ( String name ) { return properties . getProperty ( name ) ; } @ Override public String get ( String name , String defaultValue ) { return properties . getProperty ( name , defaultValue ) ; } @ Override public boolean getBoolean ( String name ) { return getBoolean ( name , false ) ; } @ Override public boolean getBoolean ( String name , boolean defaultValue ) { String value = get ( name ) ; if ( value == null ) { return defaultValue ; } else if ( value . equalsIgnoreCase ( "<STR_LIT:true>" ) ) { return true ; } else if ( value . equalsIgnoreCase ( "<STR_LIT:false>" ) ) { return false ; } return defaultValue ; } @ Override public int getInt ( String name ) { return getInt ( name , - <NUM_LIT:1> ) ; } @ Override public int getInt ( String name , int defaultValue ) { int result = defaultValue ; String value = get ( name ) ; if ( value != null ) { try { result = Integer . valueOf ( value ) ; } catch ( NumberFormatException ignore ) { } } return result ; } @ Override public long getLong ( String name ) { return getLong ( name , - <NUM_LIT:1> ) ; } @ Override public long getLong ( String name , long defaultValue ) { long result = defaultValue ; String value = get ( name ) ; if ( value != null ) { try { result = Long . valueOf ( value ) ; } catch ( NumberFormatException ignore ) { } } return result ; } @ Override public String replace ( String value ) { if ( value != null ) { try { value = replacer . substitute ( value ) ; } catch ( Exception exception ) { logger . log ( Level . WARNING , exception . getMessage ( ) , exception ) ; } } return value ; } @ Override public synchronized void add ( DynamicVariable variable ) { dynamicVariables . add ( variable ) ; } @ Override public synchronized void refresh ( ) { for ( DynamicVariable variable : dynamicVariables ) { String conditionId = variable . getConditionid ( ) ; boolean log = logger . isLoggable ( Level . FINE ) ; if ( conditionId != null && ! rules . isConditionTrue ( conditionId ) ) { if ( log ) { logger . fine ( "<STR_LIT>" + variable . getName ( ) + "<STR_LIT>" + conditionId ) ; } } else { String newValue ; try { newValue = variable . evaluate ( replacer ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( "<STR_LIT>" , exception ) ; } if ( newValue != null ) { set ( variable . getName ( ) , newValue ) ; if ( log ) { logger . fine ( "<STR_LIT>" + variable . getName ( ) + "<STR_LIT>" + newValue ) ; } } else if ( log ) { logger . fine ( "<STR_LIT>" + variable . getName ( ) + "<STR_LIT>" + variable . getValue ( ) ) ; } } } } @ Override public Properties getProperties ( ) { return properties ; } } </s>
|
<s> package com . izforge . izpack . core . io ; import java . io . File ; import java . io . IOException ; public interface VolumeLocator { File getVolume ( String path , boolean corrupt ) throws IOException ; } </s>
|
<s> package com . izforge . izpack . core . io ; import java . io . IOException ; import java . io . OutputStream ; public class ByteCountingOutputStream extends OutputStream { private long count ; private OutputStream os ; public ByteCountingOutputStream ( OutputStream os ) { setOutputStream ( os ) ; } public void write ( byte [ ] b , int off , int len ) throws IOException { os . write ( b , off , len ) ; count += len ; } public void write ( byte [ ] b ) throws IOException { os . write ( b ) ; count += b . length ; } public void write ( int b ) throws IOException { os . write ( b ) ; count ++ ; } public void close ( ) throws IOException { os . close ( ) ; } public void flush ( ) throws IOException { os . flush ( ) ; } public long getByteCount ( ) { return count ; } protected void setOutputStream ( OutputStream stream ) { this . os = stream ; count = <NUM_LIT:0> ; } } </s>
|
<s> package com . izforge . izpack . core . io ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . InputStream ; import java . util . Arrays ; import java . util . logging . Level ; import java . util . logging . Logger ; import java . util . zip . GZIPInputStream ; import com . izforge . izpack . util . file . FileUtils ; public class FileSpanningInputStream extends InputStream { private final SpanningInputStream spanningInputStream ; private GZIPInputStream zippedInputStream ; private long filePointer ; private static final Logger logger = Logger . getLogger ( FileSpanningInputStream . class . getName ( ) ) ; public FileSpanningInputStream ( File volume , int volumes ) throws IOException { spanningInputStream = new SpanningInputStream ( volume , volumes ) ; zippedInputStream = new GZIPInputStream ( spanningInputStream ) ; } public void setLocator ( VolumeLocator locator ) { spanningInputStream . setLocator ( locator ) ; } @ Override public int available ( ) throws IOException { return zippedInputStream . available ( ) ; } @ Override public void close ( ) throws IOException { zippedInputStream . close ( ) ; spanningInputStream . close ( ) ; } @ Override public int read ( ) throws IOException { int read = zippedInputStream . read ( ) ; if ( read != - <NUM_LIT:1> ) { ++ filePointer ; } return read ; } @ Override public int read ( byte [ ] b , int off , int len ) throws IOException { int count = - <NUM_LIT:1> ; while ( len != <NUM_LIT:0> ) { int read = zippedInputStream . read ( b , off , len ) ; if ( read == - <NUM_LIT:1> ) { break ; } else { off += read ; len -= read ; count = ( count == - <NUM_LIT:1> ) ? read : count + read ; } } if ( count != - <NUM_LIT:1> ) { filePointer += count ; } return count ; } @ Override public long skip ( long n ) throws IOException { long skipped = zippedInputStream . skip ( n ) ; long count = skipped ; while ( skipped != - <NUM_LIT:1> && skipped < n ) { n -= skipped ; skipped = zippedInputStream . skip ( n ) ; if ( skipped != - <NUM_LIT:1> ) { count += skipped ; } } if ( count != - <NUM_LIT:1> ) { filePointer += count ; } return count ; } public File getVolume ( ) { return spanningInputStream . getVolume ( ) ; } public long getFilePointer ( ) { return filePointer ; } private static final class SpanningInputStream extends InputStream { private InputStream stream ; private String basePath ; private int index = <NUM_LIT:0> ; private final int volumes ; private final byte [ ] magicNumber ; private VolumeLocator locator ; private File current ; public SpanningInputStream ( File volume , int volumes ) throws IOException { basePath = volume . getAbsolutePath ( ) ; stream = new FileInputStream ( volume ) ; current = volume ; this . volumes = volumes ; magicNumber = new byte [ FileSpanningOutputStream . MAGIC_NUMBER_LENGTH ] ; if ( stream . read ( magicNumber ) != FileSpanningOutputStream . MAGIC_NUMBER_LENGTH ) { FileUtils . close ( stream ) ; throw new CorruptVolumeException ( ) ; } if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "<STR_LIT>" + volume + "<STR_LIT>" + FileSpanningOutputStream . formatMagic ( magicNumber ) ) ; } } public void setLocator ( VolumeLocator locator ) { this . locator = locator ; } @ Override public int read ( byte [ ] b , int off , int len ) throws IOException { int count = - <NUM_LIT:1> ; while ( len != <NUM_LIT:0> ) { int read = stream . read ( b , off , len ) ; if ( read == - <NUM_LIT:1> ) { if ( ! openNextVolume ( ) ) { break ; } } else { off += read ; len -= read ; count = ( count == - <NUM_LIT:1> ) ? read : count + read ; } } return count ; } @ Override public int read ( ) throws IOException { int read = stream . read ( ) ; if ( read == - <NUM_LIT:1> && openNextVolume ( ) ) { read = stream . read ( ) ; } return read ; } public File getVolume ( ) { return current ; } @ Override public void close ( ) throws IOException { stream . close ( ) ; } private boolean openNextVolume ( ) throws IOException { boolean result ; if ( index + <NUM_LIT:1> >= volumes ) { logger . fine ( "<STR_LIT>" ) ; result = false ; } else { String volumePath = basePath + "<STR_LIT:.>" + ( index + <NUM_LIT:1> ) ; File volume = new File ( volumePath ) ; boolean found = false ; while ( ! found ) { if ( volume . exists ( ) ) { try { FileUtils . close ( stream ) ; stream = new FileInputStream ( volume ) ; current = volume ; checkMagicNumber ( ) ; found = true ; } catch ( CorruptVolumeException exception ) { if ( locator == null ) { throw exception ; } else { volume = locator . getVolume ( volume . getAbsolutePath ( ) , true ) ; } } } else if ( locator != null ) { volume = locator . getVolume ( volume . getAbsolutePath ( ) , false ) ; } else { throw new VolumeNotFoundException ( "<STR_LIT>" + volume . getAbsolutePath ( ) , volume . getAbsolutePath ( ) ) ; } } ++ index ; result = true ; } return result ; } private void checkMagicNumber ( ) throws IOException { logger . fine ( "<STR_LIT>" ) ; byte [ ] volumeMagicNo = new byte [ FileSpanningOutputStream . MAGIC_NUMBER_LENGTH ] ; try { if ( stream . read ( volumeMagicNo ) != volumeMagicNo . length ) { logger . fine ( "<STR_LIT>" ) ; throw new CorruptVolumeException ( ) ; } if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "<STR_LIT>" + FileSpanningOutputStream . formatMagic ( volumeMagicNo ) ) ; if ( ! Arrays . equals ( magicNumber , volumeMagicNo ) ) { throw new CorruptVolumeException ( ) ; } } } catch ( IOException exception ) { FileUtils . close ( stream ) ; throw exception ; } } } } </s>
|
<s> package com . izforge . izpack . core . io ; import java . io . IOException ; public class VolumeNotFoundException extends IOException { protected String volumename ; protected long alreadyskippedbytes ; private static final long serialVersionUID = <NUM_LIT> ; public VolumeNotFoundException ( ) { super ( ) ; } public VolumeNotFoundException ( String message , String volumename ) { super ( message ) ; this . volumename = volumename ; } public String getVolumename ( ) { return volumename ; } public long getAlreadyskippedbytes ( ) { return alreadyskippedbytes ; } public void setAlreadyskippedbytes ( long alreadyskippedbytes ) { this . alreadyskippedbytes = alreadyskippedbytes ; } } </s>
|
<s> package com . izforge . izpack . core . io ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . OutputStream ; import java . util . Random ; import java . util . logging . Level ; import java . util . logging . Logger ; import java . util . zip . GZIPOutputStream ; public class FileSpanningOutputStream extends OutputStream { public static final long KB = <NUM_LIT:1000> ; public static final long MB = <NUM_LIT:1000> * KB ; public static final long DEFAULT_VOLUME_SIZE = <NUM_LIT> * MB ; protected static final int MAGIC_NUMBER_LENGTH = <NUM_LIT:10> ; private static final int MIN_VOLUME_SIZE = MAGIC_NUMBER_LENGTH + <NUM_LIT:1> ; private SpanningOutputStream spanningOutputStream ; private GZIPOutputStream gzipOutputStream ; private long filePointer ; private static final Logger logger = Logger . getLogger ( FileSpanningOutputStream . class . getName ( ) ) ; public FileSpanningOutputStream ( String volumePath , long maxFirstVolumeSize , long maxVolumeSize ) throws IOException { this ( new File ( volumePath ) , maxFirstVolumeSize , maxVolumeSize ) ; } public FileSpanningOutputStream ( File volume , long maxVolumeSize ) throws IOException { this ( volume , maxVolumeSize , maxVolumeSize ) ; } public FileSpanningOutputStream ( File volume , long maxFirstVolumeSize , long maxVolumeSize ) throws IOException { spanningOutputStream = new SpanningOutputStream ( volume , maxFirstVolumeSize , maxVolumeSize ) ; gzipOutputStream = new GZIPOutputStream ( spanningOutputStream ) ; } @ Override public void close ( ) throws IOException { flush ( ) ; gzipOutputStream . close ( ) ; } @ Override public void write ( byte [ ] b , int off , int len ) throws IOException { gzipOutputStream . write ( b , off , len ) ; filePointer += len ; } @ Override public void write ( byte [ ] b ) throws IOException { write ( b , <NUM_LIT:0> , b . length ) ; } @ Override public void write ( int b ) throws IOException { gzipOutputStream . write ( b ) ; filePointer ++ ; } @ Override public void flush ( ) throws IOException { gzipOutputStream . flush ( ) ; } public int getVolumes ( ) { return spanningOutputStream . getVolumes ( ) ; } public long getFilePointer ( ) { return filePointer ; } static String formatMagic ( byte [ ] magic ) { StringBuilder builder = new StringBuilder ( ) ; for ( byte b : magic ) { if ( builder . length ( ) != <NUM_LIT:0> ) { builder . append ( '<CHAR_LIT:U+0020>' ) ; } builder . append ( Integer . toHexString ( ( int ) b & <NUM_LIT> ) ) ; } return builder . toString ( ) ; } private static class SpanningOutputStream extends ByteCountingOutputStream { private final long maxVolumeSize ; private int index ; private String basePath ; private byte [ ] magic ; private final long maxFirstVolumeSize ; public SpanningOutputStream ( File volume , long maxFirstVolumeSize , long maxVolumeSize ) throws IOException { super ( new FileOutputStream ( volume ) ) ; if ( maxVolumeSize < MIN_VOLUME_SIZE ) { throw new IllegalArgumentException ( "<STR_LIT>" + maxVolumeSize ) ; } if ( maxFirstVolumeSize < MIN_VOLUME_SIZE ) { throw new IllegalArgumentException ( "<STR_LIT>" + maxFirstVolumeSize ) ; } basePath = volume . getAbsolutePath ( ) ; this . maxVolumeSize = maxVolumeSize ; this . maxFirstVolumeSize = maxFirstVolumeSize ; magic = generateMagicNumber ( ) ; initVolume ( ) ; } @ Override public void write ( byte [ ] b , int off , int len ) throws IOException { long available = getAvailable ( ) ; if ( available < len ) { logger . fine ( "<STR_LIT>" + available + "<STR_LIT:)>" ) ; if ( available > <NUM_LIT:0> ) { super . write ( b , off , ( int ) available ) ; off += available ; len -= available ; } createNextVolume ( ) ; write ( b , off , len ) ; } else { super . write ( b , off , len ) ; } } @ Override public void write ( int b ) throws IOException { long available = getAvailable ( ) ; if ( available == <NUM_LIT:0> ) { createNextVolume ( ) ; } super . write ( b ) ; } private void createNextVolume ( ) throws IOException { close ( ) ; ++ index ; String name = basePath + "<STR_LIT:.>" + index ; setOutputStream ( new FileOutputStream ( name ) ) ; initVolume ( ) ; } public int getVolumes ( ) { return index + <NUM_LIT:1> ; } private void initVolume ( ) throws IOException { write ( magic ) ; } private long getAvailable ( ) { long count = getByteCount ( ) ; return ( index == <NUM_LIT:0> ) ? maxFirstVolumeSize - count : maxVolumeSize - count ; } private byte [ ] generateMagicNumber ( ) { byte [ ] result = new byte [ MAGIC_NUMBER_LENGTH ] ; Random random = new Random ( ) ; random . nextBytes ( result ) ; if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "<STR_LIT>" + formatMagic ( magic ) ) ; } return result ; } } } </s>
|
<s> package com . izforge . izpack . core . io ; import java . io . IOException ; public class CorruptVolumeException extends IOException { private static final long serialVersionUID = - <NUM_LIT> ; private String volumename ; public CorruptVolumeException ( ) { } public CorruptVolumeException ( String msg , String volumename ) { super ( msg ) ; this . volumename = volumename ; } public String getVolumename ( ) { return volumename ; } public void setVolumename ( String volumename ) { this . volumename = volumename ; } } </s>
|
<s> package com . izforge . izpack . core . regex ; import java . util . Vector ; import com . izforge . izpack . api . regex . RegularExpressionProcessor ; import com . izforge . izpack . util . regex . RegexUtil ; import com . izforge . izpack . util . regex . Regexp ; import com . izforge . izpack . util . regex . RegularExpression ; public class RegularExpressionProcessorImpl implements RegularExpressionProcessor { private String input ; private RegularExpression regexp ; private String select ; private String replace ; private String defaultValue ; private boolean caseSensitive = true ; private boolean global = true ; public void setInput ( String input ) { this . input = input ; } public void setDefaultValue ( String defaultValue ) { this . defaultValue = defaultValue ; } public void setRegexp ( String regex ) throws RuntimeException { this . regexp = new RegularExpression ( ) ; this . regexp . setPattern ( regex ) ; } public void setReplace ( String replace ) { if ( select != null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } this . replace = replace ; } public void setSelect ( String select ) { if ( replace != null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } this . select = select ; } public void setCaseSensitive ( boolean caseSensitive ) { this . caseSensitive = caseSensitive ; } public void setGlobal ( boolean global ) { this . global = global ; } protected String doReplace ( ) throws RuntimeException { if ( replace == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } int options = <NUM_LIT:0> ; if ( ! caseSensitive ) { options |= Regexp . MATCH_CASE_INSENSITIVE ; } if ( global ) { options |= Regexp . REPLACE_ALL ; } Regexp sregex = regexp . getRegexp ( ) ; String output = null ; if ( sregex . matches ( input , options ) ) { output = sregex . substitute ( input , replace , options ) ; } if ( output == null ) { if ( defaultValue != null ) { return defaultValue ; } else if ( replace != null ) { return input ; } } return output ; } protected String doSelect ( ) throws RuntimeException { if ( select == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } int options = <NUM_LIT:0> ; if ( ! caseSensitive ) { options |= Regexp . MATCH_CASE_INSENSITIVE ; } Regexp sregex = regexp . getRegexp ( ) ; String output = select ; Vector < String > groups = sregex . getGroups ( input , options ) ; if ( groups != null && groups . size ( ) > <NUM_LIT:0> ) { output = RegexUtil . select ( select , groups ) ; } else { output = null ; } if ( output == null ) { output = defaultValue ; } return output ; } protected void validate ( ) { if ( regexp == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } if ( replace == null && select == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } public String execute ( ) { validate ( ) ; if ( replace != null ) { return doReplace ( ) ; } else { return doSelect ( ) ; } } } </s>
|
<s> package com . izforge . izpack . core . handler ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . handler . AbstractUIProgressHandler ; import com . izforge . izpack . api . handler . Prompt ; public class ProgressHandler extends PromptUIHandler implements AbstractUIProgressHandler { private final ProgressListener listener ; public ProgressHandler ( ProgressListener listener , Prompt prompt ) { super ( prompt ) ; this . listener = listener ; } @ Override public void startAction ( String name , int stepCount ) { listener . startAction ( name , stepCount ) ; } @ Override public void stopAction ( ) { listener . stopAction ( ) ; } @ Override public void nextStep ( String stepName , int stepNo , int subStepCount ) { listener . nextStep ( stepName , stepNo , subStepCount ) ; } @ Override public void setSubStepNo ( int subSteps ) { listener . setSubStepNo ( subSteps ) ; } @ Override public void progress ( int subStepNo , String message ) { listener . progress ( subStepNo , message ) ; } @ Override public void progress ( String message ) { listener . progress ( message ) ; } @ Override public void restartAction ( String name , String overallMessage , String tip , int steps ) { listener . restartAction ( name , overallMessage , tip , steps ) ; } } </s>
|
<s> package com . izforge . izpack . core . handler ; import com . izforge . izpack . api . handler . Prompt ; import com . izforge . izpack . util . Console ; public class ConsolePrompt implements Prompt { private final Console console ; public ConsolePrompt ( Console console ) { this . console = console ; } @ Override public void message ( Type type , String message ) { console . println ( message ) ; } @ Override public void message ( Type type , String title , String message ) { message ( type , message ) ; } @ Override public Option confirm ( Type type , String message , Options options ) { return confirm ( type , null , message , options ) ; } @ Override public Option confirm ( Type type , String message , Options options , Option defaultOption ) { return confirm ( type , null , message , options , defaultOption ) ; } @ Override public Option confirm ( Type type , String title , String message , Options options ) { return confirm ( type , title , message , options , null ) ; } @ Override public Option confirm ( Type type , String title , String message , Options options , Option defaultOption ) { Option result ; console . println ( message ) ; if ( options == Options . OK_CANCEL ) { String defaultValue = ( defaultOption != null && defaultOption == Option . OK ) ? "<STR_LIT>" : "<STR_LIT:C>" ; String selected = console . prompt ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:C>" } , defaultValue ) ; if ( "<STR_LIT>" . equals ( selected ) ) { result = Option . OK ; } else { result = Option . CANCEL ; } } else if ( options == Options . YES_NO_CANCEL ) { String defaultValue = "<STR_LIT:C>" ; if ( defaultOption != null ) { if ( defaultOption == Option . YES ) { defaultValue = "<STR_LIT:Y>" ; } else if ( defaultOption == Option . NO ) { defaultValue = "<STR_LIT:N>" ; } } String selected = console . prompt ( "<STR_LIT>" , new String [ ] { "<STR_LIT:Y>" , "<STR_LIT:N>" , "<STR_LIT:C>" } , defaultValue ) ; if ( "<STR_LIT:Y>" . equals ( selected ) ) { result = Option . YES ; } else if ( "<STR_LIT:N>" . equals ( selected ) ) { result = Option . NO ; } else { result = Option . CANCEL ; } } else { String defaultValue = "<STR_LIT:N>" ; if ( defaultOption != null && defaultOption == Option . YES ) { defaultValue = "<STR_LIT:Y>" ; } String selected = console . prompt ( "<STR_LIT>" , new String [ ] { "<STR_LIT:Y>" , "<STR_LIT:N>" } , defaultValue ) ; if ( "<STR_LIT:Y>" . equals ( selected ) ) { result = Option . YES ; } else { result = Option . NO ; } } return result ; } } </s>
|
<s> package com . izforge . izpack . core . handler ; import static com . izforge . izpack . api . handler . Prompt . Option ; import static com . izforge . izpack . api . handler . Prompt . Option . CANCEL ; import static com . izforge . izpack . api . handler . Prompt . Option . NO ; import static com . izforge . izpack . api . handler . Prompt . Option . OK ; import static com . izforge . izpack . api . handler . Prompt . Option . YES ; import static com . izforge . izpack . api . handler . Prompt . Options . OK_CANCEL ; import static com . izforge . izpack . api . handler . Prompt . Options . YES_NO ; import static com . izforge . izpack . api . handler . Prompt . Options . YES_NO_CANCEL ; import static com . izforge . izpack . api . handler . Prompt . Type . ERROR ; import static com . izforge . izpack . api . handler . Prompt . Type . INFORMATION ; import static com . izforge . izpack . api . handler . Prompt . Type . QUESTION ; import static com . izforge . izpack . api . handler . Prompt . Type . WARNING ; import com . izforge . izpack . api . handler . AbstractUIHandler ; import com . izforge . izpack . api . handler . Prompt ; public class PromptUIHandler implements AbstractUIHandler { private final Prompt prompt ; public PromptUIHandler ( Prompt prompt ) { this . prompt = prompt ; } @ Override public void emitNotification ( String message ) { prompt . message ( INFORMATION , message ) ; } @ Override public boolean emitWarning ( String title , String message ) { return prompt . confirm ( WARNING , title , message , OK_CANCEL , OK ) == OK ; } @ Override public void emitError ( String title , String message ) { prompt . message ( ERROR , title , message ) ; } @ Override public void emitErrorAndBlockNext ( String title , String message ) { emitError ( title , message ) ; } public int askQuestion ( String title , String question , int choices ) { return askQuestion ( title , question , choices , - <NUM_LIT:1> ) ; } public int askQuestion ( String title , String question , int choices , int default_choice ) { int choice ; if ( choices == AbstractUIHandler . CHOICES_YES_NO ) { Option defaultValue ; switch ( default_choice ) { case ANSWER_YES : defaultValue = YES ; break ; case ANSWER_NO : defaultValue = NO ; break ; default : defaultValue = null ; } Option selected = prompt . confirm ( QUESTION , question , YES_NO , defaultValue ) ; choice = ( selected == OK ) ? AbstractUIHandler . ANSWER_YES : AbstractUIHandler . ANSWER_NO ; } else { Prompt . Option defaultValue ; switch ( default_choice ) { case ANSWER_YES : defaultValue = YES ; break ; case ANSWER_NO : defaultValue = NO ; break ; case ANSWER_CANCEL : defaultValue = CANCEL ; break ; default : defaultValue = null ; } Option selected = prompt . confirm ( QUESTION , question , YES_NO_CANCEL , defaultValue ) ; if ( selected == YES ) { choice = AbstractUIHandler . ANSWER_YES ; } else if ( selected == NO ) { choice = AbstractUIHandler . ANSWER_NO ; } else { choice = AbstractUIHandler . ANSWER_CANCEL ; } } return choice ; } } </s>
|
<s> package com . izforge . izpack . core . container ; import com . izforge . izpack . api . container . Container ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . api . exception . IzPackClassNotFoundException ; public abstract class AbstractDelegatingContainer implements Container { private final Container container ; public AbstractDelegatingContainer ( Container container ) { this . container = container ; } @ Override public < T > void addComponent ( Class < T > componentType ) { container . addComponent ( componentType ) ; } @ Override public void addComponent ( Object componentKey , Object implementation ) { container . addComponent ( componentKey , implementation ) ; } @ Override public < T > T getComponent ( Class < T > componentType ) { return container . getComponent ( componentType ) ; } @ Override public Object getComponent ( Object componentKeyOrType ) { return container . getComponent ( componentKeyOrType ) ; } @ Override public Container createChildContainer ( ) { return container . createChildContainer ( ) ; } @ Override public boolean removeChildContainer ( Container child ) { return container . removeChildContainer ( child ) ; } @ Override public void dispose ( ) { container . dispose ( ) ; } @ Override public < T > Class < T > getClass ( String className , Class < T > superType ) { return container . getClass ( className , superType ) ; } } </s>
|
<s> package com . izforge . izpack . core . container ; import org . picocontainer . Characteristics ; import org . picocontainer . MutablePicoContainer ; import org . picocontainer . PicoBuilder ; import org . picocontainer . PicoException ; import com . izforge . izpack . api . container . Container ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . api . exception . IzPackClassNotFoundException ; import com . izforge . izpack . api . exception . IzPackException ; public abstract class AbstractContainer implements Container { private MutablePicoContainer container ; public AbstractContainer ( ) { this ( null ) ; } public AbstractContainer ( MutablePicoContainer container ) { if ( container != null ) { initialise ( container ) ; } } @ Override public < T > void addComponent ( Class < T > componentType ) { try { container . as ( Characteristics . USE_NAMES ) . addComponent ( componentType ) ; } catch ( PicoException exception ) { throw new ContainerException ( exception ) ; } } @ Override public void addComponent ( Object componentKey , Object implementation ) { try { container . addComponent ( componentKey , implementation ) ; } catch ( PicoException exception ) { throw new ContainerException ( exception ) ; } } @ Override public < T > T getComponent ( Class < T > componentType ) { try { return container . getComponent ( componentType ) ; } catch ( PicoException exception ) { throw new ContainerException ( exception ) ; } } @ Override public Object getComponent ( Object componentKeyOrType ) { try { return container . getComponent ( componentKeyOrType ) ; } catch ( PicoException exception ) { throw new ContainerException ( exception ) ; } } public void addConfig ( String name , Object value ) { try { container . addConfig ( name , value ) ; } catch ( IzPackException exception ) { throw new ContainerException ( exception ) ; } } @ Override public Container createChildContainer ( ) { try { return new ChildContainer ( container ) ; } catch ( PicoException exception ) { throw new ContainerException ( exception ) ; } } @ Override public boolean removeChildContainer ( Container child ) { boolean removed = false ; if ( child instanceof AbstractContainer ) { removed = container . removeChildContainer ( ( ( AbstractContainer ) child ) . container ) ; } return removed ; } @ Override public void dispose ( ) { container . dispose ( ) ; } @ Override @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public < T > Class < T > getClass ( String className , Class < T > superType ) { Class type ; try { ClassLoader classLoader = superType . getClassLoader ( ) ; if ( classLoader == null ) { classLoader = getClass ( ) . getClassLoader ( ) ; } type = classLoader . 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 ( Class < T > ) type ; } protected void initialise ( ) { initialise ( createContainer ( ) ) ; } protected void initialise ( MutablePicoContainer container ) { if ( this . container != null ) { throw new ContainerException ( "<STR_LIT>" ) ; } this . container = container ; try { fillContainer ( container ) ; } catch ( ContainerException exception ) { throw exception ; } catch ( Exception exception ) { throw new ContainerException ( exception ) ; } } protected void fillContainer ( MutablePicoContainer container ) { fillContainer ( ) ; } protected void fillContainer ( ) { } protected MutablePicoContainer getContainer ( ) { return container ; } protected MutablePicoContainer createContainer ( ) { return new PicoBuilder ( ) . withConstructorInjection ( ) . withCaching ( ) . build ( ) ; } private static class ChildContainer extends AbstractContainer { public ChildContainer ( MutablePicoContainer parent ) { super ( parent . makeChildContainer ( ) ) ; } } } </s>
|
<s> package com . izforge . izpack . core . container ; import com . izforge . izpack . api . container . Container ; import com . izforge . izpack . api . exception . ContainerException ; public class DefaultContainer extends AbstractContainer { public DefaultContainer ( ) { initialise ( ) ; } } </s>
|
<s> package com . izforge . izpack . core . container ; import java . util . logging . Logger ; import org . picocontainer . injectors . Provider ; import com . izforge . izpack . util . Platform ; import com . izforge . izpack . util . Platforms ; public class PlatformProvider implements Provider { private static final Logger logger = Logger . getLogger ( PlatformProvider . class . getName ( ) ) ; public Platform provide ( Platforms platforms ) { Platform platform = platforms . getCurrentPlatform ( ) ; logger . info ( "<STR_LIT>" + platform ) ; return platform ; } } </s>
|
<s> package com . izforge . izpack . core . rules ; import java . io . OutputStream ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Set ; import java . util . UUID ; import java . util . logging . Logger ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . XMLException ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . adaptator . impl . XMLWriter ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . rules . Condition ; import com . izforge . izpack . api . rules . ConditionReference ; import com . izforge . izpack . api . rules . ConditionWithMultipleOperands ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . core . rules . logic . AndCondition ; import com . izforge . izpack . core . rules . logic . NotCondition ; import com . izforge . izpack . core . rules . logic . OrCondition ; import com . izforge . izpack . core . rules . logic . XorCondition ; import com . izforge . izpack . core . rules . process . CompareNumericsCondition ; import com . izforge . izpack . core . rules . process . CompareVersionsCondition ; import com . izforge . izpack . core . rules . process . EmptyCondition ; import com . izforge . izpack . core . rules . process . ExistsCondition ; import com . izforge . izpack . core . rules . process . JavaCondition ; import com . izforge . izpack . core . rules . process . PackSelectionCondition ; import com . izforge . izpack . core . rules . process . RefCondition ; import com . izforge . izpack . core . rules . process . UserCondition ; import com . izforge . izpack . core . rules . process . VariableCondition ; import com . izforge . izpack . util . Platform ; import com . izforge . izpack . util . Platforms ; public class RulesEngineImpl implements RulesEngine { private final Map < String , String > panelConditions = new HashMap < String , String > ( ) ; private final Map < String , String > packConditions = new HashMap < String , String > ( ) ; private final Map < String , String > optionalPackConditions = new HashMap < String , String > ( ) ; private final Map < String , Condition > conditionsMap = new HashMap < String , Condition > ( ) ; private final Set < ConditionReference > refConditions = new HashSet < ConditionReference > ( ) ; private final InstallData installData ; private final ConditionContainer container ; private static final Logger logger = Logger . getLogger ( RulesEngineImpl . class . getName ( ) ) ; private static final Map < String , String > TYPE_CLASS_NAMES = new HashMap < String , String > ( ) ; static { TYPE_CLASS_NAMES . put ( "<STR_LIT>" , AndCondition . class . getName ( ) ) ; TYPE_CLASS_NAMES . put ( "<STR_LIT>" , NotCondition . class . getName ( ) ) ; TYPE_CLASS_NAMES . put ( "<STR_LIT>" , OrCondition . class . getName ( ) ) ; TYPE_CLASS_NAMES . put ( "<STR_LIT>" , XorCondition . class . getName ( ) ) ; TYPE_CLASS_NAMES . put ( "<STR_LIT>" , CompareNumericsCondition . class . getName ( ) ) ; TYPE_CLASS_NAMES . put ( "<STR_LIT>" , CompareVersionsCondition . class . getName ( ) ) ; TYPE_CLASS_NAMES . put ( "<STR_LIT>" , EmptyCondition . class . getName ( ) ) ; TYPE_CLASS_NAMES . put ( "<STR_LIT>" , ExistsCondition . class . getName ( ) ) ; TYPE_CLASS_NAMES . put ( "<STR_LIT>" , JavaCondition . class . getName ( ) ) ; TYPE_CLASS_NAMES . put ( "<STR_LIT>" , PackSelectionCondition . class . getName ( ) ) ; TYPE_CLASS_NAMES . put ( "<STR_LIT>" , RefCondition . class . getName ( ) ) ; TYPE_CLASS_NAMES . put ( "<STR_LIT:user>" , UserCondition . class . getName ( ) ) ; TYPE_CLASS_NAMES . put ( "<STR_LIT>" , VariableCondition . class . getName ( ) ) ; } public RulesEngineImpl ( ConditionContainer container , Platform platform ) { this . installData = null ; this . container = container ; initStandardConditions ( platform ) ; } public RulesEngineImpl ( InstallData installData , ConditionContainer container , Platform platform ) { this . installData = installData ; this . container = container ; if ( installData != null ) { initStandardConditions ( platform ) ; } } @ Override public void readConditionMap ( Map < String , Condition > rules ) { for ( Map . Entry < String , Condition > entry : rules . entrySet ( ) ) { Condition condition = entry . getValue ( ) ; if ( ! ( condition instanceof BuiltinCondition ) ) { conditionsMap . put ( entry . getKey ( ) , condition ) ; condition . setInstallData ( installData ) ; resolveBuiltinConditions ( condition ) ; } } } @ Override public Set < String > getKnownConditionIds ( ) { return conditionsMap . keySet ( ) ; } @ Override @ Deprecated public Condition instanciateCondition ( IXMLElement condition ) { return createCondition ( condition ) ; } @ Override public Condition createCondition ( IXMLElement condition ) { String id = condition . getAttribute ( "<STR_LIT:id>" ) ; String type = condition . getAttribute ( "<STR_LIT:type>" ) ; Condition result = null ; if ( type != null ) { String className = getClassName ( type ) ; Class < Condition > conditionClass = container . getClass ( className , Condition . class ) ; try { if ( id == null || id . isEmpty ( ) || "<STR_LIT>" . equals ( id ) ) { id = className + "<STR_LIT:->" + UUID . randomUUID ( ) . toString ( ) ; logger . fine ( "<STR_LIT>" + id + "<STR_LIT>" ) ; } container . addComponent ( id , conditionClass ) ; result = ( Condition ) container . getComponent ( id ) ; result . setId ( id ) ; result . setInstallData ( installData ) ; result . readFromXML ( condition ) ; conditionsMap . put ( id , result ) ; if ( result instanceof ConditionReference ) { refConditions . add ( ( ConditionReference ) result ) ; } } catch ( Exception e ) { throw new IzPackException ( e ) ; } } return result ; } @ Override public void resolveConditions ( ) throws Exception { for ( ConditionReference refCondition : refConditions ) { refCondition . resolveReference ( ) ; } } @ Override public void analyzeXml ( IXMLElement conditionsSpec ) { if ( conditionsSpec == null ) { logger . fine ( "<STR_LIT>" ) ; return ; } if ( conditionsSpec . hasChildren ( ) ) { List < IXMLElement > childs = conditionsSpec . getChildrenNamed ( "<STR_LIT>" ) ; for ( IXMLElement condition : childs ) { Condition cond = createCondition ( condition ) ; if ( cond != null && ! ( cond instanceof BuiltinCondition ) ) { String condid = cond . getId ( ) ; cond . setInstallData ( installData ) ; if ( ( condid != null ) && ! ( "<STR_LIT>" . equals ( condid ) ) ) { resolveBuiltinConditions ( cond ) ; conditionsMap . put ( condid , cond ) ; } } } List < IXMLElement > panelconditionels = conditionsSpec . getChildrenNamed ( "<STR_LIT>" ) ; for ( IXMLElement panelel : panelconditionels ) { String panelid = panelel . getAttribute ( "<STR_LIT>" ) ; String conditionid = panelel . getAttribute ( "<STR_LIT>" ) ; this . panelConditions . put ( panelid , conditionid ) ; } List < IXMLElement > packconditionels = conditionsSpec . getChildrenNamed ( "<STR_LIT>" ) ; for ( IXMLElement panelel : packconditionels ) { String panelid = panelel . getAttribute ( "<STR_LIT>" ) ; String conditionid = panelel . getAttribute ( "<STR_LIT>" ) ; this . packConditions . put ( panelid , conditionid ) ; String optional = panelel . getAttribute ( "<STR_LIT>" ) ; if ( optional != null ) { boolean optionalinstall = Boolean . valueOf ( optional ) ; if ( optionalinstall ) { this . optionalPackConditions . put ( panelid , conditionid ) ; } } } } } @ Override public Condition getCondition ( String id ) { Condition result = conditionsMap . get ( id ) ; if ( result == null ) { if ( id . startsWith ( "<STR_LIT:@>" ) ) { result = parseComplexCondition ( id . substring ( <NUM_LIT:1> ) ) ; } else { result = getConditionByExpr ( new StringBuffer ( id ) ) ; } } return result ; } @ Override public boolean isConditionTrue ( String id , InstallData installData ) { Condition cond = getCondition ( id ) ; if ( cond != null ) { return isConditionTrue ( cond , installData ) ; } logger . warning ( "<STR_LIT>" + id + "<STR_LIT>" ) ; return false ; } @ Override public boolean isConditionTrue ( Condition cond , InstallData installData ) { if ( cond != null ) { if ( installData != null ) { cond . setInstallData ( installData ) ; } return isConditionTrue ( cond ) ; } return false ; } @ Override public boolean isConditionTrue ( String id ) { Condition cond = getCondition ( id ) ; if ( cond != null ) { return isConditionTrue ( cond ) ; } logger . warning ( "<STR_LIT>" + id + "<STR_LIT>" ) ; return false ; } @ Override public boolean isConditionTrue ( Condition cond ) { if ( cond . getInstallData ( ) == null ) { cond . setInstallData ( this . installData ) ; } boolean value = cond . isTrue ( ) ; logger . fine ( "<STR_LIT>" + cond . getId ( ) + "<STR_LIT::U+0020>" + Boolean . toString ( value ) ) ; return value ; } @ Override public boolean canShowPanel ( String panelid , Variables variables ) { if ( ! this . panelConditions . containsKey ( panelid ) ) { logger . fine ( "<STR_LIT>" + panelid + "<STR_LIT>" ) ; return true ; } Condition condition = getCondition ( this . panelConditions . get ( panelid ) ) ; boolean b = condition . isTrue ( ) ; logger . fine ( "<STR_LIT>" + panelid + "<STR_LIT>" + condition . getId ( ) + "<STR_LIT>" + b ) ; return b ; } @ Override public boolean canInstallPack ( String packid , Variables variables ) { if ( packid == null ) { return true ; } if ( ! this . packConditions . containsKey ( packid ) ) { logger . fine ( "<STR_LIT>" + packid + "<STR_LIT>" ) ; return true ; } Condition condition = getCondition ( this . packConditions . get ( packid ) ) ; boolean b = condition . isTrue ( ) ; logger . fine ( "<STR_LIT>" + packid + "<STR_LIT>" + condition . getId ( ) + "<STR_LIT>" + b ) ; return b ; } @ Override public boolean canInstallPackOptional ( String packid , Variables variables ) { if ( ! this . optionalPackConditions . containsKey ( packid ) ) { logger . fine ( "<STR_LIT>" + packid + "<STR_LIT>" ) ; return false ; } else { logger . fine ( "<STR_LIT>" + packid + "<STR_LIT>" ) ; return true ; } } @ Override public void addCondition ( Condition condition ) { if ( condition != null ) { String id = condition . getId ( ) ; if ( conditionsMap . containsKey ( id ) ) { logger . warning ( "<STR_LIT>" + id + "<STR_LIT>" ) ; } else { conditionsMap . put ( id , condition ) ; } } else { logger . warning ( "<STR_LIT>" ) ; } } @ Override public void writeRulesXML ( OutputStream out ) { XMLWriter xmlOut = new XMLWriter ( ) ; xmlOut . setOutput ( out ) ; XMLElementImpl conditionsel = new XMLElementImpl ( "<STR_LIT>" ) ; for ( Condition condition : conditionsMap . values ( ) ) { IXMLElement conditionEl = createConditionElement ( condition , conditionsel ) ; condition . makeXMLData ( conditionEl ) ; conditionsel . addChild ( conditionEl ) ; } logger . fine ( "<STR_LIT>" ) ; try { xmlOut . write ( conditionsel ) ; } catch ( XMLException e ) { throw new IzPackException ( e ) ; } } @ Override public IXMLElement createConditionElement ( Condition condition , IXMLElement root ) { XMLElementImpl xml = new XMLElementImpl ( "<STR_LIT>" , root ) ; xml . setAttribute ( "<STR_LIT:id>" , condition . getId ( ) ) ; xml . setAttribute ( "<STR_LIT:type>" , condition . getClass ( ) . getCanonicalName ( ) ) ; return xml ; } private void initStandardConditions ( Platform platform ) { logger . fine ( "<STR_LIT>" ) ; initOsConditions ( platform ) ; if ( ( installData != null ) && ( installData . getAllPacks ( ) != null ) ) { logger . fine ( "<STR_LIT>" ) ; for ( Pack pack : installData . getAllPacks ( ) ) { PackSelectionCondition selectionCondition = new PackSelectionCondition ( ) ; selectionCondition . setInstallData ( installData ) ; selectionCondition . setId ( "<STR_LIT>" + pack . getName ( ) ) ; selectionCondition . setPack ( pack . getName ( ) ) ; conditionsMap . put ( selectionCondition . getId ( ) , selectionCondition ) ; String condition = pack . getCondition ( ) ; if ( condition != null && ! condition . isEmpty ( ) ) { logger . fine ( "<STR_LIT>" + condition + "<STR_LIT>" + pack . getName ( ) + "<STR_LIT:\">" ) ; packConditions . put ( pack . getName ( ) , condition ) ; } } } } private void initOsConditions ( Platform platform ) { createPlatformCondition ( "<STR_LIT>" , platform , Platforms . AIX ) ; createPlatformCondition ( "<STR_LIT>" , platform , Platforms . WINDOWS ) ; createPlatformCondition ( "<STR_LIT>" , platform , Platforms . WINDOWS_XP ) ; createPlatformCondition ( "<STR_LIT>" , platform , Platforms . WINDOWS_2003 ) ; createPlatformCondition ( "<STR_LIT>" , platform , Platforms . WINDOWS_VISTA ) ; createPlatformCondition ( "<STR_LIT>" , platform , Platforms . WINDOWS_7 ) ; createPlatformCondition ( "<STR_LIT>" , platform , Platforms . LINUX ) ; createPlatformCondition ( "<STR_LIT>" , platform , Platforms . SUNOS ) ; createPlatformCondition ( "<STR_LIT>" , platform , Platforms . MAC ) ; createPlatformCondition ( "<STR_LIT>" , platform , Platforms . MAC_OSX ) ; createPlatformCondition ( "<STR_LIT>" , platform , Platforms . SUNOS_X86 ) ; createPlatformCondition ( "<STR_LIT>" , platform , Platforms . SUNOS_SPARC ) ; } private void createPlatformCondition ( String conditionId , Platform current , Platform platform ) { boolean isA = current . isA ( platform ) ; Condition condition = new StaticCondition ( isA ) ; condition . setInstallData ( installData ) ; condition . setId ( conditionId ) ; conditionsMap . put ( condition . getId ( ) , condition ) ; } private Condition parseComplexCondition ( String expression ) { Condition result = null ; if ( expression . contains ( "<STR_LIT>" ) ) { result = parseComplexOrCondition ( expression ) ; } else if ( expression . contains ( "<STR_LIT>" ) ) { result = parseComplexAndCondition ( expression ) ; } else if ( expression . contains ( "<STR_LIT>" ) ) { result = parseComplexXorCondition ( expression ) ; } else if ( expression . contains ( "<STR_LIT:!>" ) ) { result = parseComplexNotCondition ( expression ) ; } else { result = conditionsMap . get ( expression ) ; } result . setInstallData ( installData ) ; return result ; } private Condition parseComplexOrCondition ( String expression ) { String [ ] parts = expression . split ( "<STR_LIT>" , <NUM_LIT:2> ) ; OrCondition orCondition = new OrCondition ( this ) ; orCondition . addOperands ( parseComplexCondition ( parts [ <NUM_LIT:0> ] . trim ( ) ) , parseComplexCondition ( parts [ <NUM_LIT:1> ] . trim ( ) ) ) ; return orCondition ; } private Condition parseComplexXorCondition ( String expression ) { String [ ] parts = expression . split ( "<STR_LIT>" , <NUM_LIT:2> ) ; XorCondition xorCondition = new XorCondition ( this ) ; xorCondition . addOperands ( parseComplexCondition ( parts [ <NUM_LIT:0> ] . trim ( ) ) , parseComplexCondition ( parts [ <NUM_LIT:1> ] . trim ( ) ) ) ; return xorCondition ; } private Condition parseComplexAndCondition ( String expression ) { String [ ] parts = expression . split ( "<STR_LIT>" , <NUM_LIT:2> ) ; AndCondition andCondition = new AndCondition ( this ) ; andCondition . addOperands ( parseComplexCondition ( parts [ <NUM_LIT:0> ] . trim ( ) ) , parseComplexCondition ( parts [ <NUM_LIT:1> ] . trim ( ) ) ) ; return andCondition ; } private Condition parseComplexNotCondition ( String expression ) { Condition result = null ; result = NotCondition . createFromCondition ( parseComplexCondition ( expression . substring ( <NUM_LIT:1> ) . trim ( ) ) , this ) ; return result ; } private Condition getConditionByExpr ( StringBuffer conditionexpr ) { Condition result = null ; int index = <NUM_LIT:0> ; while ( index < conditionexpr . length ( ) ) { char currentchar = conditionexpr . charAt ( index ) ; switch ( currentchar ) { case '<CHAR_LIT>' : Condition op1 = conditionsMap . get ( conditionexpr . substring ( <NUM_LIT:0> , index ) ) ; conditionexpr . delete ( <NUM_LIT:0> , index + <NUM_LIT:1> ) ; result = new AndCondition ( this ) ; ( ( ConditionWithMultipleOperands ) result ) . addOperands ( op1 , getConditionByExpr ( conditionexpr ) ) ; break ; case '<CHAR_LIT>' : op1 = conditionsMap . get ( conditionexpr . substring ( <NUM_LIT:0> , index ) ) ; conditionexpr . delete ( <NUM_LIT:0> , index + <NUM_LIT:1> ) ; result = new OrCondition ( this ) ; ( ( ConditionWithMultipleOperands ) result ) . addOperands ( op1 , getConditionByExpr ( conditionexpr ) ) ; break ; case '<STR_LIT:\\>' : op1 = conditionsMap . get ( conditionexpr . substring ( <NUM_LIT:0> , index ) ) ; conditionexpr . delete ( <NUM_LIT:0> , index + <NUM_LIT:1> ) ; result = new XorCondition ( this ) ; ( ( ConditionWithMultipleOperands ) result ) . addOperands ( op1 , getConditionByExpr ( conditionexpr ) ) ; break ; case '<CHAR_LIT>' : if ( index > <NUM_LIT:0> ) { logger . warning ( "<STR_LIT>" ) ; } else { conditionexpr . deleteCharAt ( index ) ; result = NotCondition . createFromCondition ( getConditionByExpr ( conditionexpr ) , this ) ; } break ; default : } index ++ ; } if ( conditionexpr . length ( ) > <NUM_LIT:0> ) { result = conditionsMap . get ( conditionexpr . toString ( ) ) ; if ( result != null ) { result . setInstallData ( installData ) ; conditionexpr . delete ( <NUM_LIT:0> , conditionexpr . length ( ) ) ; } } return result ; } private String getClassName ( String type ) { String result ; if ( type . indexOf ( '<CHAR_LIT:.>' ) != - <NUM_LIT:1> ) { result = type ; } else { result = TYPE_CLASS_NAMES . get ( type ) ; if ( result == null ) { result = type ; } } return result ; } private void resolveBuiltinConditions ( Condition condition ) { if ( condition instanceof ConditionReference ) { ConditionReference not = ( ConditionReference ) condition ; if ( not . getReferencedCondition ( ) instanceof StaticCondition ) { not . setReferencedCondition ( conditionsMap . get ( not . getReferencedCondition ( ) . getId ( ) ) ) ; } else { resolveBuiltinConditions ( not . getReferencedCondition ( ) ) ; } } else if ( condition instanceof ConditionWithMultipleOperands ) { ConditionWithMultipleOperands c = ( ConditionWithMultipleOperands ) condition ; List < Condition > operands = c . getOperands ( ) ; for ( int i = <NUM_LIT:0> ; i < operands . size ( ) ; ++ i ) { Condition operand = operands . get ( i ) ; if ( operand instanceof StaticCondition ) { operands . set ( i , conditionsMap . get ( operand . getId ( ) ) ) ; } else { resolveBuiltinConditions ( operand ) ; } } } } private static abstract class BuiltinCondition extends Condition { @ Override public void readFromXML ( IXMLElement condition ) throws Exception { } @ Override public void makeXMLData ( IXMLElement conditionRoot ) { } } private static class StaticCondition extends BuiltinCondition { private final boolean result ; public StaticCondition ( boolean result ) { this . result = result ; } @ Override public boolean isTrue ( ) { return result ; } } } </s>
|
<s> package com . izforge . izpack . core . rules ; import com . izforge . izpack . api . container . Container ; import com . izforge . izpack . core . container . AbstractDelegatingContainer ; public class ConditionContainer extends AbstractDelegatingContainer { public ConditionContainer ( Container parent ) { super ( parent . createChildContainer ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . core . rules . process ; import java . io . File ; import java . util . EnumSet ; import java . util . HashMap ; import java . util . Map ; import java . util . logging . Logger ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . rules . Condition ; public class ExistsCondition extends Condition { private static final long serialVersionUID = - <NUM_LIT> ; private static final transient Logger logger = Logger . getLogger ( ExistsCondition . class . getName ( ) ) ; private ContentType contentType ; private String content ; public ExistsCondition ( ) { } public ExistsCondition ( ContentType contentType ) { this . contentType = contentType ; } @ Override public boolean isTrue ( ) { boolean result = false ; switch ( contentType ) { case VARIABLE : if ( this . content != null ) { String value = this . getInstallData ( ) . getVariable ( this . content ) ; if ( value != null ) { result = true ; } } break ; case FILE : if ( this . content != null ) { Variables variables = getInstallData ( ) . getVariables ( ) ; File file = new File ( variables . replace ( this . content ) ) ; if ( file . exists ( ) ) { result = true ; } } break ; default : logger . warning ( "<STR_LIT>" + contentType . getAttribute ( ) + "<STR_LIT>" ) ; break ; } return result ; } @ Override public void readFromXML ( IXMLElement xmlcondition ) throws Exception { if ( xmlcondition != null ) { if ( xmlcondition . getChildrenCount ( ) != <NUM_LIT:1> ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT>" ) ; } else { IXMLElement child = xmlcondition . getChildAtIndex ( <NUM_LIT:0> ) ; this . contentType = ContentType . getFromAttribute ( child . getName ( ) ) ; if ( this . contentType != null ) { this . content = child . getContent ( ) ; } else { throw new Exception ( "<STR_LIT>" + child . getName ( ) + "<STR_LIT>" + getId ( ) + "<STR_LIT:\">" ) ; } if ( this . content == null || this . content . length ( ) == <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT>" ) ; } } } } public ContentType getContentType ( ) { return contentType ; } public void setContentType ( ContentType contentType ) { this . contentType = contentType ; } public String getContent ( ) { return content ; } public void setContent ( String content ) { this . content = content ; } @ Override public void makeXMLData ( IXMLElement conditionRoot ) { XMLElementImpl el = new XMLElementImpl ( this . contentType . getAttribute ( ) , conditionRoot ) ; el . setContent ( this . content ) ; conditionRoot . addChild ( el ) ; } public enum ContentType { VARIABLE ( "<STR_LIT>" ) , FILE ( "<STR_LIT:file>" ) ; private static Map < String , ContentType > lookup ; private String attribute ; ContentType ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , ContentType > ( ) ; for ( ContentType operation : EnumSet . allOf ( ContentType . class ) ) { lookup . put ( operation . getAttribute ( ) , operation ) ; } } public String getAttribute ( ) { return attribute ; } public static ContentType getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } } } </s>
|
<s> package com . izforge . izpack . core . rules . process ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . rules . CompareCondition ; import com . izforge . izpack . api . rules . ComparisonOperator ; public class CompareNumericsCondition extends CompareCondition { private static final long serialVersionUID = - <NUM_LIT> ; private static final transient Logger logger = Logger . getLogger ( CompareNumericsCondition . class . getName ( ) ) ; @ Override public boolean isTrue ( ) { boolean result = false ; InstallData installData = getInstallData ( ) ; if ( installData != null && operand1 != null && operand2 != null ) { Variables variables = installData . getVariables ( ) ; String arg1 = variables . replace ( operand1 ) ; String arg2 = variables . replace ( operand2 ) ; if ( operator == null ) { operator = ComparisonOperator . EQUAL ; } try { int leftValue = Integer . valueOf ( arg1 ) ; int rightValue = Integer . valueOf ( arg2 ) ; switch ( operator ) { case EQUAL : result = leftValue == rightValue ; break ; case NOTEQUAL : result = leftValue != rightValue ; break ; case GREATER : result = leftValue > rightValue ; break ; case GREATEREQUAL : result = leftValue >= rightValue ; break ; case LESS : result = leftValue < rightValue ; break ; case LESSEQUAL : result = leftValue <= rightValue ; break ; default : break ; } } catch ( NumberFormatException nfe ) { logger . warning ( "<STR_LIT>" ) ; } } return result ; } } </s>
|
<s> package com . izforge . izpack . core . rules . process ; import java . io . File ; import java . util . EnumSet ; import java . util . HashMap ; import java . util . Map ; import java . util . logging . Logger ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . rules . Condition ; public class EmptyCondition extends Condition { private static final long serialVersionUID = - <NUM_LIT> ; private static final transient Logger logger = Logger . getLogger ( EmptyCondition . class . getName ( ) ) ; private ContentType contentType ; private String content ; public EmptyCondition ( ) { } @ Override public boolean isTrue ( ) { boolean result = false ; Variables variables = getInstallData ( ) . getVariables ( ) ; switch ( contentType ) { case STRING : if ( this . content == null ) { return true ; } String s = variables . replace ( this . content ) ; if ( s != null && s . length ( ) == <NUM_LIT:0> ) { result = true ; } break ; case VARIABLE : if ( this . content != null ) { String value = this . getInstallData ( ) . getVariable ( this . content ) ; if ( value != null && value . length ( ) == <NUM_LIT:0> ) { result = true ; } } break ; case FILE : if ( this . content != null ) { File file = new File ( variables . replace ( this . content ) ) ; if ( ! file . exists ( ) && file . length ( ) == <NUM_LIT:0> ) { result = true ; } } break ; case DIR : if ( this . content != null ) { File file = new File ( variables . replace ( this . content ) ) ; if ( ! file . exists ( ) || file . isDirectory ( ) && file . listFiles ( ) . length == <NUM_LIT:0> ) { result = true ; } } break ; default : logger . warning ( "<STR_LIT>" + contentType . getAttribute ( ) + "<STR_LIT>" ) ; break ; } return result ; } @ Override public void readFromXML ( IXMLElement xmlcondition ) throws Exception { if ( xmlcondition != null ) { if ( xmlcondition . getChildrenCount ( ) != <NUM_LIT:1> ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT>" ) ; } IXMLElement child = xmlcondition . getChildAtIndex ( <NUM_LIT:0> ) ; this . contentType = ContentType . getFromAttribute ( child . getName ( ) ) ; if ( this . contentType != null ) { this . content = child . getContent ( ) ; } else { throw new Exception ( "<STR_LIT>" + child . getName ( ) + "<STR_LIT>" + getId ( ) + "<STR_LIT:\">" ) ; } if ( this . content == null || this . content . length ( ) == <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT>" ) ; } } } public ContentType getContentType ( ) { return contentType ; } public void setContentType ( ContentType contentType ) { this . contentType = contentType ; } public String getContent ( ) { return content ; } public void setContent ( String content ) { this . content = content ; } @ Override public void makeXMLData ( IXMLElement conditionRoot ) { XMLElementImpl el = new XMLElementImpl ( this . contentType . getAttribute ( ) , conditionRoot ) ; el . setContent ( this . content ) ; conditionRoot . addChild ( el ) ; } public enum ContentType { VARIABLE ( "<STR_LIT>" ) , STRING ( "<STR_LIT:string>" ) , FILE ( "<STR_LIT:file>" ) , DIR ( "<STR_LIT>" ) ; private static Map < String , ContentType > lookup ; private String attribute ; ContentType ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , ContentType > ( ) ; for ( ContentType operation : EnumSet . allOf ( ContentType . class ) ) { lookup . put ( operation . getAttribute ( ) , operation ) ; } } public String getAttribute ( ) { return attribute ; } public static ContentType getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } } } </s>
|
<s> package com . izforge . izpack . core . rules . process ; import java . util . List ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . rules . Condition ; public class PackSelectionCondition extends Condition { private static final long serialVersionUID = <NUM_LIT> ; private String name ; @ Override public void readFromXML ( IXMLElement xmlcondition ) throws Exception { try { name = xmlcondition . getFirstChildNamed ( "<STR_LIT:name>" ) . getContent ( ) ; } catch ( Exception e ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT:\">" ) ; } } private boolean isTrue ( List < Pack > selectedpacks ) { if ( selectedpacks != null ) { for ( Pack selectedpack : selectedpacks ) { if ( name . equals ( selectedpack . getName ( ) ) ) { return true ; } } } return false ; } @ Override public boolean isTrue ( ) { return this . isTrue ( getInstallData ( ) . getSelectedPacks ( ) ) ; } @ Override public String getDependenciesDetails ( ) { StringBuilder details = new StringBuilder ( ) ; details . append ( this . getId ( ) ) ; details . append ( "<STR_LIT>" ) ; details . append ( this . name ) ; details . append ( "<STR_LIT>" ) ; return details . toString ( ) ; } @ Override public void makeXMLData ( IXMLElement conditionRoot ) { XMLElementImpl packel = new XMLElementImpl ( "<STR_LIT:name>" , conditionRoot ) ; packel . setContent ( this . name ) ; conditionRoot . addChild ( packel ) ; } public void setPack ( String name ) { this . name = name ; } } </s>
|
<s> package com . izforge . izpack . core . rules . process ; import java . util . logging . Logger ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . rules . Condition ; public class UserCondition extends Condition { private static final long serialVersionUID = - <NUM_LIT> ; private static final transient Logger logger = Logger . getLogger ( UserCondition . class . getName ( ) ) ; private String requiredUsername ; public UserCondition ( ) { this ( null ) ; } public UserCondition ( String requiredUsername ) { this . requiredUsername = requiredUsername ; } @ Override public boolean isTrue ( ) { boolean result = false ; if ( this . requiredUsername == null ) { logger . warning ( "<STR_LIT>" + getId ( ) + "<STR_LIT>" ) ; } else { String actualUsername = System . getProperty ( "<STR_LIT>" ) ; if ( actualUsername != null && ! actualUsername . isEmpty ( ) ) { result = this . requiredUsername . equals ( actualUsername ) ; } else { logger . warning ( "<STR_LIT>" + getId ( ) + "<STR_LIT>" ) ; } } return result ; } @ Override public void readFromXML ( IXMLElement xmlcondition ) throws Exception { IXMLElement userElement = xmlcondition . getFirstChildNamed ( "<STR_LIT>" ) ; if ( userElement == null ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT:\">" ) ; } else { this . requiredUsername = userElement . getContent ( ) ; } } @ Override public void makeXMLData ( IXMLElement conditionRoot ) { XMLElementImpl requiredUserEl = new XMLElementImpl ( "<STR_LIT>" , conditionRoot ) ; requiredUserEl . setContent ( this . requiredUsername ) ; conditionRoot . addChild ( requiredUserEl ) ; } } </s>
|
<s> package com . izforge . izpack . core . rules . process ; import java . lang . reflect . Field ; import java . lang . reflect . Method ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . rules . Condition ; public class JavaCondition extends Condition { private static final long serialVersionUID = - <NUM_LIT> ; private static final transient Logger logger = Logger . getLogger ( JavaCondition . class . getName ( ) ) ; protected String classname ; protected String methodname ; protected String fieldname ; protected boolean complete ; protected String returnvalue ; protected String returnvaluetype ; protected Class < ? > usedclass ; protected Field usedfield ; protected Method usedmethod ; public JavaCondition ( ) { } public JavaCondition ( String classname , String fieldname , boolean complete , String returnvalue , String returnvaluetype ) { this . classname = classname ; this . fieldname = fieldname ; this . complete = complete ; this . returnvalue = returnvalue ; this . returnvaluetype = returnvaluetype ; } @ Override public boolean isTrue ( ) { if ( ! this . complete ) { return false ; } else { if ( this . usedclass == null ) { try { this . usedclass = Class . forName ( this . classname ) ; } catch ( ClassNotFoundException e ) { logger . warning ( "<STR_LIT>" + this . classname ) ; return false ; } } if ( ( this . usedfield == null ) && ( this . fieldname != null ) ) { try { this . usedfield = this . usedclass . getField ( this . fieldname ) ; } catch ( SecurityException e ) { logger . warning ( "<STR_LIT>" + this . fieldname ) ; return false ; } catch ( NoSuchFieldException e ) { logger . warning ( "<STR_LIT>" + this . fieldname ) ; return false ; } } if ( ( this . usedmethod == null ) && ( this . methodname != null ) ) { logger . warning ( "<STR_LIT>" ) ; return false ; } if ( this . usedfield != null ) { if ( "<STR_LIT:boolean>" . equals ( this . returnvaluetype ) ) { try { boolean returnval = this . usedfield . getBoolean ( null ) ; boolean expectedreturnval = Boolean . valueOf ( this . returnvalue ) ; return returnval == expectedreturnval ; } catch ( IllegalArgumentException e ) { logger . log ( Level . WARNING , this . fieldname + "<STR_LIT::U+0020>" + e . getMessage ( ) , e ) ; } catch ( IllegalAccessException e ) { logger . log ( Level . WARNING , this . fieldname + "<STR_LIT::U+0020>" + e . getMessage ( ) , e ) ; } } else { logger . warning ( "<STR_LIT>" ) ; return false ; } } return false ; } } @ Override public void readFromXML ( IXMLElement xmlcondition ) throws Exception { if ( xmlcondition . getChildrenCount ( ) != <NUM_LIT:2> ) { throw new Exception ( "<STR_LIT>" ) ; } IXMLElement javael = xmlcondition . getFirstChildNamed ( "<STR_LIT>" ) ; IXMLElement classel = javael . getFirstChildNamed ( "<STR_LIT:class>" ) ; if ( classel != null ) { this . classname = classel . getContent ( ) ; } else { throw new Exception ( "<STR_LIT>" ) ; } IXMLElement methodel = javael . getFirstChildNamed ( "<STR_LIT>" ) ; if ( methodel != null ) { this . methodname = methodel . getContent ( ) ; } IXMLElement fieldel = javael . getFirstChildNamed ( "<STR_LIT:field>" ) ; if ( fieldel != null ) { this . fieldname = fieldel . getContent ( ) ; } if ( ( this . methodname == null ) && ( this . fieldname == null ) ) { throw new Exception ( "<STR_LIT>" ) ; } IXMLElement returnvalel = xmlcondition . getFirstChildNamed ( "<STR_LIT>" ) ; if ( returnvalel != null ) { this . returnvalue = returnvalel . getContent ( ) ; this . returnvaluetype = returnvalel . getAttribute ( "<STR_LIT:type>" ) ; } else { throw new Exception ( "<STR_LIT>" ) ; } this . complete = true ; } @ Override public void makeXMLData ( IXMLElement conditionRoot ) { XMLElementImpl javael = new XMLElementImpl ( "<STR_LIT>" , conditionRoot ) ; conditionRoot . addChild ( javael ) ; XMLElementImpl classel = new XMLElementImpl ( "<STR_LIT:class>" , javael ) ; classel . setContent ( this . classname ) ; javael . addChild ( classel ) ; if ( this . methodname != null ) { XMLElementImpl methodel = new XMLElementImpl ( "<STR_LIT>" , javael ) ; methodel . setContent ( this . methodname ) ; javael . addChild ( methodel ) ; } if ( this . fieldname != null ) { XMLElementImpl fieldel = new XMLElementImpl ( "<STR_LIT:field>" , javael ) ; fieldel . setContent ( this . fieldname ) ; javael . addChild ( fieldel ) ; } XMLElementImpl returnvalel = new XMLElementImpl ( "<STR_LIT>" , javael ) ; returnvalel . setContent ( this . returnvalue ) ; returnvalel . setAttribute ( "<STR_LIT:type>" , this . returnvaluetype ) ; javael . addChild ( returnvalel ) ; } @ Override public String getDependenciesDetails ( ) { StringBuffer details = new StringBuffer ( ) ; details . append ( this . getId ( ) ) ; details . append ( "<STR_LIT>" ) ; if ( this . fieldname != null ) { details . append ( "<STR_LIT>" ) ; details . append ( this . fieldname ) ; details . append ( "<STR_LIT>" ) ; } else { details . append ( "<STR_LIT>" ) ; details . append ( this . methodname ) ; details . append ( "<STR_LIT>" ) ; } details . append ( "<STR_LIT>" ) ; details . append ( this . classname ) ; details . append ( "<STR_LIT>" ) ; details . append ( this . returnvalue ) ; details . append ( "<STR_LIT>" ) ; return details . toString ( ) ; } } </s>
|
<s> package com . izforge . izpack . core . rules . process ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . rules . Condition ; public class VariableCondition extends Condition { private static final long serialVersionUID = <NUM_LIT> ; protected String variablename ; protected String value ; public VariableCondition ( ) { this ( null , null ) ; } public VariableCondition ( String name , String value ) { this . variablename = name ; this . value = value ; } public String getValue ( ) { return value ; } public void setValue ( String value ) { this . value = value ; } public String getVariablename ( ) { return variablename ; } public void setVariablename ( String variablename ) { this . variablename = variablename ; } @ Override public void readFromXML ( IXMLElement xmlcondition ) throws Exception { try { this . variablename = xmlcondition . getFirstChildNamed ( "<STR_LIT:name>" ) . getContent ( ) ; this . value = xmlcondition . getFirstChildNamed ( "<STR_LIT:value>" ) . getContent ( ) ; } catch ( Exception e ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT:\">" ) ; } } @ Override public boolean isTrue ( ) { InstallData installData = getInstallData ( ) ; if ( installData != null ) { String val = installData . getVariable ( variablename ) ; if ( val == null ) { return false ; } else { Variables variables = installData . getVariables ( ) ; return val . equals ( variables . replace ( value ) ) ; } } else { return false ; } } @ Override public String getDependenciesDetails ( ) { StringBuffer details = new StringBuffer ( ) ; details . append ( this . getId ( ) ) ; details . append ( "<STR_LIT>" ) ; details . append ( this . value ) ; details . append ( "<STR_LIT>" ) ; details . append ( this . variablename ) ; details . append ( "<STR_LIT>" ) ; details . append ( this . getInstallData ( ) . getVariable ( variablename ) ) ; details . append ( "<STR_LIT:)>" ) ; details . append ( "<STR_LIT>" ) ; return details . toString ( ) ; } @ Override public void makeXMLData ( IXMLElement conditionRoot ) { XMLElementImpl nameEl = new XMLElementImpl ( "<STR_LIT:name>" , conditionRoot ) ; nameEl . setContent ( this . variablename ) ; conditionRoot . addChild ( nameEl ) ; XMLElementImpl valueEl = new XMLElementImpl ( "<STR_LIT:value>" , conditionRoot ) ; valueEl . setContent ( this . value ) ; conditionRoot . addChild ( valueEl ) ; } } </s>
|
<s> package com . izforge . izpack . core . rules . process ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . rules . Condition ; import com . izforge . izpack . api . rules . ConditionReference ; import com . izforge . izpack . api . rules . RulesEngine ; public class RefCondition extends ConditionReference { private static final long serialVersionUID = - <NUM_LIT> ; protected transient RulesEngine rules ; Condition referencedcondition ; private String referencedConditionId ; public RefCondition ( RulesEngine rules ) { this . rules = rules ; } public String getReferencedConditionId ( ) { return referencedConditionId ; } @ Override public void readFromXML ( IXMLElement xmlcondition ) throws Exception { this . referencedConditionId = xmlcondition . getAttribute ( "<STR_LIT>" ) ; if ( this . referencedConditionId == null ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT:\">" ) ; } } @ Override public void resolveReference ( ) { Condition condition = null ; if ( referencedConditionId != null ) { condition = rules . getCondition ( referencedConditionId ) ; } if ( condition == null ) { throw new IzPackException ( "<STR_LIT>" + referencedConditionId + "<STR_LIT>" ) ; } setReferencedCondition ( condition ) ; } @ Override public boolean isTrue ( ) { Condition condition = getReferencedCondition ( ) ; if ( condition == null ) { return false ; } return condition . isTrue ( ) ; } @ Override public String getDependenciesDetails ( ) { StringBuffer details = new StringBuffer ( ) ; details . append ( this . getId ( ) ) ; details . append ( "<STR_LIT>" ) ; details . append ( referencedcondition . getDependenciesDetails ( ) ) ; details . append ( "<STR_LIT>" ) ; return details . toString ( ) ; } @ Override public void makeXMLData ( IXMLElement conditionRoot ) { conditionRoot . setAttribute ( "<STR_LIT>" , this . referencedConditionId ) ; } } </s>
|
<s> package com . izforge . izpack . core . rules . process ; import java . util . Comparator ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . rules . CompareCondition ; import com . izforge . izpack . api . rules . ComparisonOperator ; public class CompareVersionsCondition extends CompareCondition { private static final long serialVersionUID = - <NUM_LIT> ; @ Override public boolean isTrue ( ) { boolean result = false ; InstallData installData = getInstallData ( ) ; if ( installData != null && operand1 != null && operand2 != null ) { Variables variables = installData . getVariables ( ) ; String arg1 = variables . replace ( operand1 ) ; String arg2 = variables . replace ( operand2 ) ; if ( operator == null ) { operator = ComparisonOperator . EQUAL ; } int res = new VersionStringComparator ( ) . compare ( arg1 , arg2 ) ; switch ( operator ) { case EQUAL : result = ( res == <NUM_LIT:0> ) ; break ; case NOTEQUAL : result = ( res != <NUM_LIT:0> ) ; break ; case GREATER : result = ( res > <NUM_LIT:0> ) ; break ; case GREATEREQUAL : result = ( res >= <NUM_LIT:0> ) ; break ; case LESS : result = ( res < <NUM_LIT:0> ) ; break ; case LESSEQUAL : result = ( res <= <NUM_LIT:0> ) ; break ; default : break ; } } return result ; } private static class VersionStringComparator implements Comparator < String > { public int compare ( String s1 , String s2 ) { if ( s1 == null && s2 == null ) { return <NUM_LIT:0> ; } else if ( s1 == null ) { return - <NUM_LIT:1> ; } else if ( s2 == null ) { return <NUM_LIT:1> ; } String [ ] arr1 = s1 . split ( "<STR_LIT>" ) , arr2 = s2 . split ( "<STR_LIT>" ) ; int i1 , i2 , i3 ; for ( int ii = <NUM_LIT:0> , max = Math . min ( arr1 . length , arr2 . length ) ; ii <= max ; ii ++ ) { if ( ii == arr1 . length ) { return ii == arr2 . length ? <NUM_LIT:0> : - <NUM_LIT:1> ; } else if ( ii == arr2 . length ) { return <NUM_LIT:1> ; } try { i1 = Integer . parseInt ( arr1 [ ii ] ) ; } catch ( Exception x ) { i1 = Integer . MAX_VALUE ; } try { i2 = Integer . parseInt ( arr2 [ ii ] ) ; } catch ( Exception x ) { i2 = Integer . MAX_VALUE ; } if ( i1 != i2 ) { return i1 - i2 ; } i3 = arr1 [ ii ] . compareTo ( arr2 [ ii ] ) ; if ( i3 != <NUM_LIT:0> ) { return i3 ; } } return <NUM_LIT:0> ; } } } </s>
|
<s> package com . izforge . izpack . core . rules . logic ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . rules . Condition ; import com . izforge . izpack . api . rules . ConditionWithMultipleOperands ; import com . izforge . izpack . api . rules . RulesEngine ; public class OrCondition extends ConditionWithMultipleOperands { private static final long serialVersionUID = <NUM_LIT> ; protected transient RulesEngine rules ; public OrCondition ( RulesEngine rules ) { this . rules = rules ; } @ Override public void readFromXML ( IXMLElement xmlcondition ) throws Exception { if ( xmlcondition . getChildrenCount ( ) <= <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT:\">" ) ; } for ( IXMLElement element : xmlcondition . getChildren ( ) ) { nestedConditions . add ( rules . createCondition ( element ) ) ; } } @ Override public boolean isTrue ( ) { boolean result = false ; for ( Condition condition : nestedConditions ) { result = result || condition . isTrue ( ) ; } return result ; } @ Override public String getDependenciesDetails ( ) { StringBuffer details = new StringBuffer ( ) ; details . append ( this . getId ( ) ) ; details . append ( "<STR_LIT>" ) ; for ( Condition condition : nestedConditions ) { details . append ( condition . getDependenciesDetails ( ) ) ; details . append ( "<STR_LIT>" ) ; } details . append ( "<STR_LIT>" ) ; return details . toString ( ) ; } @ Override public void makeXMLData ( IXMLElement conditionRoot ) { for ( Condition condition : nestedConditions ) { IXMLElement left = rules . createConditionElement ( condition , conditionRoot ) ; condition . makeXMLData ( left ) ; conditionRoot . addChild ( left ) ; } } } </s>
|
<s> package com . izforge . izpack . core . rules . logic ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . rules . Condition ; import com . izforge . izpack . api . rules . ConditionWithMultipleOperands ; import com . izforge . izpack . api . rules . RulesEngine ; public class AndCondition extends ConditionWithMultipleOperands { private static final long serialVersionUID = - <NUM_LIT> ; protected transient RulesEngine rules ; public AndCondition ( RulesEngine rules ) { this . rules = rules ; } @ Override public void readFromXML ( IXMLElement xmlcondition ) throws Exception { if ( xmlcondition . getChildrenCount ( ) <= <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT:\">" ) ; } for ( IXMLElement element : xmlcondition . getChildren ( ) ) { nestedConditions . add ( rules . createCondition ( element ) ) ; } } @ Override public boolean isTrue ( ) { boolean result = true ; for ( Condition condition : nestedConditions ) { result = result && condition . isTrue ( ) ; } return result ; } @ Override public String getDependenciesDetails ( ) { StringBuffer details = new StringBuffer ( ) ; details . append ( this . getId ( ) ) ; details . append ( "<STR_LIT>" ) ; for ( Condition condition : nestedConditions ) { details . append ( condition . getDependenciesDetails ( ) ) ; details . append ( "<STR_LIT>" ) ; } details . append ( "<STR_LIT>" ) ; return details . toString ( ) ; } @ Override public void makeXMLData ( IXMLElement conditionRoot ) { for ( Condition condition : nestedConditions ) { IXMLElement left = rules . createConditionElement ( condition , conditionRoot ) ; condition . makeXMLData ( left ) ; conditionRoot . addChild ( left ) ; } } } </s>
|
<s> package com . izforge . izpack . core . rules . logic ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . rules . Condition ; import com . izforge . izpack . api . rules . RulesEngine ; public class XorCondition extends OrCondition { private static final long serialVersionUID = <NUM_LIT> ; public XorCondition ( RulesEngine rules ) { super ( rules ) ; } @ Override public void readFromXML ( IXMLElement xmlcondition ) throws Exception { if ( xmlcondition . getChildrenCount ( ) > <NUM_LIT:2> ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT:\">" ) ; } super . readFromXML ( xmlcondition ) ; } @ Override public boolean isTrue ( ) { boolean result = false ; boolean marked = false ; for ( Condition condition : nestedConditions ) { boolean currentResult = condition . isTrue ( ) ; if ( ! marked ) { result = currentResult ; marked = true ; } else { result ^= currentResult ; } } return result ; } @ Override public String getDependenciesDetails ( ) { StringBuffer details = new StringBuffer ( ) ; details . append ( this . getId ( ) ) ; details . append ( "<STR_LIT>" ) ; for ( Condition condition : nestedConditions ) { details . append ( condition . getDependenciesDetails ( ) ) ; details . append ( "<STR_LIT>" ) ; } details . append ( "<STR_LIT>" ) ; return details . toString ( ) ; } } </s>
|
<s> package com . izforge . izpack . core . rules . logic ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . rules . Condition ; import com . izforge . izpack . api . rules . ConditionReference ; import com . izforge . izpack . api . rules . RulesEngine ; public class NotCondition extends ConditionReference { private static final long serialVersionUID = <NUM_LIT> ; protected transient RulesEngine rules ; private IXMLElement referencedConditionXMLElement ; public NotCondition ( RulesEngine rules ) { this . rules = rules ; } public IXMLElement getReferencedConditionXMLElement ( ) { return referencedConditionXMLElement ; } @ Override public void readFromXML ( IXMLElement xmlcondition ) throws Exception { if ( xmlcondition . getChildrenCount ( ) <= <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT:\">" ) ; } else if ( xmlcondition . getChildrenCount ( ) != <NUM_LIT:1> ) { throw new Exception ( "<STR_LIT>" + getId ( ) + "<STR_LIT>" ) ; } this . referencedConditionXMLElement = xmlcondition . getChildAtIndex ( <NUM_LIT:0> ) ; } @ Override public void resolveReference ( ) { String refid = referencedConditionXMLElement . getAttribute ( "<STR_LIT>" ) ; Condition condition ; if ( refid != null ) { condition = rules . getCondition ( refid ) ; } else { condition = rules . createCondition ( referencedConditionXMLElement ) ; } if ( condition == null ) { throw new IzPackException ( "<STR_LIT>" + refid + "<STR_LIT>" ) ; } setReferencedCondition ( condition ) ; } @ Override public boolean isTrue ( ) { Condition condition = getReferencedCondition ( ) ; return condition != null && ! condition . isTrue ( ) ; } @ Override public String getDependenciesDetails ( ) { StringBuilder details = new StringBuilder ( ) ; details . append ( this . getId ( ) ) ; details . append ( "<STR_LIT>" ) ; details . append ( getReferencedCondition ( ) . getDependenciesDetails ( ) ) ; details . append ( "<STR_LIT>" ) ; return details . toString ( ) ; } @ Override public void makeXMLData ( IXMLElement conditionRoot ) { IXMLElement conditionElement = rules . createConditionElement ( getReferencedCondition ( ) , conditionRoot ) ; getReferencedCondition ( ) . makeXMLData ( conditionElement ) ; conditionRoot . addChild ( conditionElement ) ; } public static Condition createFromCondition ( Condition referencedCondition , RulesEngine rules ) { NotCondition notCondition = null ; if ( referencedCondition != null ) { notCondition = new NotCondition ( rules ) ; notCondition . setReferencedCondition ( referencedCondition ) ; notCondition . setInstallData ( referencedCondition . getInstallData ( ) ) ; } return notCondition ; } } </s>
|
<s> package com . izforge . izpack . core . os ; import com . izforge . izpack . util . TargetFactory ; import java . util . logging . Level ; import java . util . logging . Logger ; public class RegistryDefaultHandler { private RegistryHandler registryHandler = null ; private TargetFactory factory ; private boolean initialized = false ; private static final Logger log = Logger . getLogger ( RegistryDefaultHandler . class . getName ( ) ) ; public RegistryDefaultHandler ( TargetFactory factory ) { this . factory = factory ; } public synchronized RegistryHandler getInstance ( ) { if ( ! initialized ) { try { registryHandler = factory . makeObject ( RegistryHandler . class ) ; } catch ( Throwable exception ) { log . log ( Level . WARNING , "<STR_LIT>" + exception . getMessage ( ) , exception ) ; } initialized = true ; } return ( registryHandler ) ; } } </s>
|
<s> package com . izforge . izpack . core . os ; import com . coi . tools . os . win . MSWinConstants ; import com . coi . tools . os . win . RegDataContainer ; import com . izforge . izpack . api . exception . NativeLibException ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; public class RegistryHandler implements MSWinConstants { public static final String UNINSTALL_ROOT = "<STR_LIT>" ; public static final Map < String , Integer > ROOT_KEY_MAP = new HashMap < String , Integer > ( ) ; protected String uninstallName = null ; static { ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_CLASSES_ROOT ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_CLASSES_ROOT ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_CURRENT_USER ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_CURRENT_USER ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_LOCAL_MACHINE ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_LOCAL_MACHINE ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_USERS ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_USERS ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_PERFORMANCE_DATA ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_PERFORMANCE_DATA ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_CURRENT_CONFIG ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_CURRENT_CONFIG ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_DYN_DATA ) ; ROOT_KEY_MAP . put ( "<STR_LIT>" , HKEY_DYN_DATA ) ; } public RegistryHandler ( ) { } public void setValue ( String key , String value , String contents ) throws NativeLibException { } public void setValue ( String key , String value , String [ ] contents ) throws NativeLibException { } public void setValue ( String key , String value , byte [ ] contents ) throws NativeLibException { } public void setValue ( String key , String value , long contents ) throws NativeLibException { } public RegDataContainer getValue ( String key , String value , RegDataContainer defaultVal ) throws NativeLibException { return ( null ) ; } public boolean keyExist ( String key ) throws NativeLibException { return ( false ) ; } public boolean valueExist ( String key , String value ) throws NativeLibException { return ( false ) ; } public String [ ] getSubkeys ( String key ) throws NativeLibException { return ( null ) ; } public String [ ] getValueNames ( String key ) throws NativeLibException { return ( null ) ; } public RegDataContainer getValue ( String key , String value ) throws NativeLibException { return ( null ) ; } public void createKey ( String key ) throws NativeLibException { } public void deleteKey ( String key ) throws NativeLibException { } public void deleteKeyIfEmpty ( String key ) throws NativeLibException { } public void deleteValue ( String key , String value ) throws NativeLibException { } public void setRoot ( int i ) throws NativeLibException { } public int getRoot ( ) throws NativeLibException { return ( <NUM_LIT:0> ) ; } public void setLogPrevSetValueFlag ( boolean flagVal ) throws NativeLibException { } public boolean getLogPrevSetValueFlag ( ) throws NativeLibException { return ( true ) ; } public void activateLogging ( ) throws NativeLibException { } public void suspendLogging ( ) throws NativeLibException { } public void resetLogging ( ) throws NativeLibException { } public List < Object > getLoggingInfo ( ) throws NativeLibException { return ( null ) ; } public void setLoggingInfo ( List info ) throws NativeLibException { } public void addLoggingInfo ( List info ) throws NativeLibException { } public void rewind ( ) throws NativeLibException { } public String getUninstallName ( ) { return uninstallName ; } public void setUninstallName ( String name ) { uninstallName = name ; } } </s>
|
<s> package com . izforge . izpack . core . os ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . InstallData ; @ Deprecated public class OSClassHelper { private static final Logger logger = Logger . getLogger ( OSClassHelper . class . getName ( ) ) ; protected InstallData installdata ; protected Class workerClass = null ; protected Object worker = null ; public OSClassHelper ( ) { super ( ) ; } public OSClassHelper ( String className ) { super ( ) ; try { workerClass = Class . forName ( className ) ; worker = workerClass . newInstance ( ) ; } catch ( InstantiationException e ) { logger . log ( Level . WARNING , "<STR_LIT>" , e ) ; } catch ( IllegalAccessException e ) { logger . log ( Level . WARNING , "<STR_LIT>" , e ) ; } catch ( ClassNotFoundException e ) { logger . log ( Level . WARNING , "<STR_LIT>" , e ) ; } catch ( Exception e ) { logger . warning ( "<STR_LIT>" + className + "<STR_LIT>" + e . getMessage ( ) + "<STR_LIT:)>" ) ; return ; } logger . fine ( "<STR_LIT>" + className + "<STR_LIT>" + good ( ) ) ; } public boolean good ( ) { return ( worker != null ) ; } public boolean verify ( InstallData idata ) throws Exception { installdata = idata ; return ( false ) ; } } </s>
|
<s> package com . izforge . izpack . core . substitutor ; import com . izforge . izpack . api . data . Value ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . substitutor . SubstitutionType ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . util . IoHelper ; import java . io . * ; import java . util . HashMap ; import java . util . Map ; import java . util . logging . Level ; import java . util . logging . Logger ; public abstract class VariableSubstitutorBase implements VariableSubstitutor { private static final Logger LOGGER = Logger . getLogger ( VariableSubstitutorBase . class . getName ( ) ) ; protected boolean bracesRequired = false ; protected final static int TYPE_PLAIN = <NUM_LIT:0> ; protected final static int TYPE_JAVA_PROPERTIES = <NUM_LIT:1> ; protected final static int TYPE_XML = <NUM_LIT:2> ; protected final static int TYPE_SHELL = <NUM_LIT:3> ; protected final static int TYPE_AT = <NUM_LIT:4> ; protected final static int TYPE_JAVA = <NUM_LIT:5> ; protected final static int TYPE_ANT = <NUM_LIT:6> ; public final static String PLAIN = "<STR_LIT>" ; protected final static Map < String , Integer > typeNameToConstantMap ; static { typeNameToConstantMap = new HashMap < String , Integer > ( ) ; typeNameToConstantMap . put ( "<STR_LIT>" , TYPE_PLAIN ) ; typeNameToConstantMap . put ( "<STR_LIT>" , TYPE_JAVA_PROPERTIES ) ; typeNameToConstantMap . put ( "<STR_LIT>" , TYPE_JAVA ) ; typeNameToConstantMap . put ( "<STR_LIT>" , TYPE_XML ) ; typeNameToConstantMap . put ( "<STR_LIT>" , TYPE_SHELL ) ; typeNameToConstantMap . put ( "<STR_LIT>" , TYPE_AT ) ; typeNameToConstantMap . put ( "<STR_LIT>" , TYPE_ANT ) ; } public abstract Value getValue ( String name ) ; public boolean isBracesRequired ( ) { return bracesRequired ; } public void setBracesRequired ( boolean braces ) { bracesRequired = braces ; } public String substitute ( String str ) { return substitute ( str , SubstitutionType . TYPE_PLAIN ) ; } public String substitute ( String str , SubstitutionType type ) { if ( str == null ) { return null ; } StringReader reader = new StringReader ( str ) ; StringWriter writer = new StringWriter ( ) ; try { substitute ( reader , writer , type ) ; } catch ( Exception e ) { LOGGER . log ( Level . SEVERE , "<STR_LIT>" , e ) ; throw new IzPackException ( e ) ; } return writer . getBuffer ( ) . toString ( ) ; } public int substitute ( InputStream in , OutputStream out , SubstitutionType type , String encoding ) throws Exception { if ( encoding == null ) { if ( type == null ) { type = SubstitutionType . getDefault ( ) ; } switch ( type ) { case TYPE_JAVA_PROPERTIES : encoding = "<STR_LIT>" ; break ; case TYPE_XML : encoding = "<STR_LIT:UTF-8>" ; break ; } } InputStreamReader reader = ( encoding != null ? new InputStreamReader ( in , encoding ) : new InputStreamReader ( in ) ) ; OutputStreamWriter writer = ( encoding != null ? new OutputStreamWriter ( out , encoding ) : new OutputStreamWriter ( out ) ) ; int subs = substitute ( reader , writer , type ) ; writer . flush ( ) ; return subs ; } public String substitute ( InputStream in , SubstitutionType type ) throws Exception { String encoding = PLAIN ; { if ( type == null ) { type = SubstitutionType . getDefault ( ) ; } switch ( type ) { case TYPE_JAVA_PROPERTIES : encoding = "<STR_LIT>" ; break ; case TYPE_XML : encoding = "<STR_LIT:UTF-8>" ; break ; } } InputStreamReader reader = ( ( encoding != null ) ? new InputStreamReader ( in , encoding ) : new InputStreamReader ( in ) ) ; StringWriter writer = new StringWriter ( ) ; substitute ( reader , writer , type ) ; writer . flush ( ) ; return writer . getBuffer ( ) . toString ( ) ; } public int substitute ( Reader reader , Writer writer , SubstitutionType type ) throws Exception { if ( type == null ) { type = SubstitutionType . getDefault ( ) ; } char variable_start = '<CHAR_LIT>' ; char variable_end = '<STR_LIT>' ; switch ( type ) { case TYPE_SHELL : variable_start = '<CHAR_LIT>' ; break ; case TYPE_AT : variable_start = '<CHAR_LIT>' ; break ; case TYPE_ANT : variable_start = '<CHAR_LIT>' ; variable_end = '<CHAR_LIT>' ; break ; default : break ; } int subs = <NUM_LIT:0> ; int c = reader . read ( ) ; while ( true ) { while ( c != - <NUM_LIT:1> && c != variable_start ) { writer . write ( c ) ; c = reader . read ( ) ; } if ( c == - <NUM_LIT:1> ) { return subs ; } boolean braces = false ; c = reader . read ( ) ; if ( c == '<CHAR_LIT>' ) { braces = true ; c = reader . read ( ) ; } else if ( bracesRequired ) { writer . write ( variable_start ) ; continue ; } else if ( c == - <NUM_LIT:1> ) { writer . write ( variable_start ) ; return subs ; } StringBuffer nameBuffer = new StringBuffer ( ) ; while ( c != - <NUM_LIT:1> && ( braces && c != '<CHAR_LIT:}>' ) || ( c >= '<CHAR_LIT:a>' && c <= '<CHAR_LIT>' ) || ( c >= '<CHAR_LIT:A>' && c <= '<CHAR_LIT:Z>' ) || ( braces && ( ( c == '<CHAR_LIT:[>' ) || ( c == '<CHAR_LIT:]>' ) ) ) || ( ( ( c >= '<CHAR_LIT:0>' && c <= '<CHAR_LIT:9>' ) || c == '<CHAR_LIT:_>' || c == '<CHAR_LIT:.>' || c == '<CHAR_LIT:->' ) && nameBuffer . length ( ) > <NUM_LIT:0> ) ) { nameBuffer . append ( ( char ) c ) ; c = reader . read ( ) ; } String name = nameBuffer . toString ( ) ; String varvalue = null ; if ( ( ( ! braces || c == '<CHAR_LIT:}>' ) && ( ! braces || variable_end == '<STR_LIT>' || variable_end == c ) ) && name . length ( ) > <NUM_LIT:0> ) { if ( braces && name . startsWith ( "<STR_LIT>" ) && ( name . lastIndexOf ( '<CHAR_LIT:]>' ) == name . length ( ) - <NUM_LIT:1> ) ) { varvalue = IoHelper . getenv ( name . substring ( <NUM_LIT:4> , name . length ( ) - <NUM_LIT:1> ) ) ; if ( varvalue == null ) { varvalue = "<STR_LIT>" ; } } else { Value val = getValue ( name ) ; if ( val != null ) { varvalue = val . resolve ( ) ; } } subs ++ ; } if ( varvalue != null ) { writer . write ( escapeSpecialChars ( varvalue , type ) ) ; if ( braces || variable_end != '<STR_LIT>' ) { c = reader . read ( ) ; } } else { writer . write ( variable_start ) ; if ( braces ) { writer . write ( '<CHAR_LIT>' ) ; } writer . write ( name ) ; } } } protected int getTypeConstant ( String type ) { if ( type == null ) { return TYPE_PLAIN ; } Integer integer = typeNameToConstantMap . get ( type ) ; if ( integer == null ) { throw new IllegalArgumentException ( "<STR_LIT>" + type ) ; } else { return integer ; } } protected String escapeSpecialChars ( String str , SubstitutionType type ) { StringBuffer buffer ; int len ; int i ; if ( type == null ) { type = SubstitutionType . getDefault ( ) ; } switch ( type ) { case TYPE_PLAIN : case TYPE_AT : case TYPE_ANT : return str ; case TYPE_SHELL : return str . replace ( "<STR_LIT:r>" , "<STR_LIT>" ) ; case TYPE_JAVA_PROPERTIES : case TYPE_JAVA : buffer = new StringBuffer ( str ) ; len = str . length ( ) ; boolean leading = true ; for ( i = <NUM_LIT:0> ; i < len ; i ++ ) { char c = buffer . charAt ( i ) ; if ( type . equals ( SubstitutionType . TYPE_JAVA_PROPERTIES ) ) { if ( c == '<STR_LIT:\t>' || c == '<STR_LIT:\n>' || c == '<STR_LIT>' ) { char tag ; if ( c == '<STR_LIT:\t>' ) { tag = '<CHAR_LIT>' ; } else if ( c == '<STR_LIT:\n>' ) { tag = '<CHAR_LIT>' ; } else { tag = '<CHAR_LIT>' ; } buffer . replace ( i , i + <NUM_LIT:1> , "<STR_LIT:\\>" + tag ) ; len ++ ; i ++ ; } else if ( c == '<CHAR_LIT:U+0020>' ) { if ( leading ) { buffer . insert ( i , '<STR_LIT:\\>' ) ; len ++ ; i ++ ; } } else if ( c == '<STR_LIT:\\>' || c == '<CHAR_LIT:">' || c == '<STR_LIT>' ) { leading = false ; buffer . insert ( i , '<STR_LIT:\\>' ) ; len ++ ; i ++ ; } else { leading = false ; } } else { if ( c == '<STR_LIT:\\>' ) { buffer . replace ( i , i + <NUM_LIT:1> , "<STR_LIT>" ) ; len ++ ; i ++ ; } } } return buffer . toString ( ) ; case TYPE_XML : buffer = new StringBuffer ( str ) ; len = str . length ( ) ; for ( i = <NUM_LIT:0> ; i < len ; i ++ ) { String r = null ; char c = buffer . charAt ( i ) ; switch ( c ) { case '<CHAR_LIT>' : r = "<STR_LIT>" ; break ; case '<CHAR_LIT:>>' : r = "<STR_LIT>" ; break ; case '<CHAR_LIT>' : r = "<STR_LIT>" ; break ; case '<STR_LIT>' : r = "<STR_LIT>" ; break ; case '<CHAR_LIT:">' : r = "<STR_LIT>" ; break ; } if ( r != null ) { buffer . replace ( i , i + <NUM_LIT:1> , r ) ; len = buffer . length ( ) ; i += r . length ( ) - <NUM_LIT:1> ; } } return buffer . toString ( ) ; default : throw new Error ( "<STR_LIT>" + type ) ; } } } </s>
|
<s> package com . izforge . izpack . core . substitutor ; import java . io . Serializable ; import java . util . Properties ; import com . izforge . izpack . api . data . Value ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . core . variable . PlainValue ; public class VariableSubstitutorImpl extends VariableSubstitutorBase implements Serializable { private static final long serialVersionUID = <NUM_LIT> ; protected transient Properties variables ; public VariableSubstitutorImpl ( Variables variables ) { this ( variables . getProperties ( ) ) ; } public VariableSubstitutorImpl ( Properties properties ) { this . variables = properties ; } @ Override public Value getValue ( String name ) { return new PlainValue ( variables . getProperty ( name ) ) ; } } </s>
|
<s> package com . izforge . izpack . core . variable ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import java . io . FileInputStream ; import java . io . Serializable ; public class PlainConfigFileValue extends ConfigFileValue implements Serializable { private static final long serialVersionUID = <NUM_LIT> ; public String location ; public PlainConfigFileValue ( String location , int type , String section , String key ) { super ( type , section , key ) ; this . location = location ; } public String getLocation ( ) { return location ; } public void setLocation ( String location ) { this . location = location ; } @ Override public void validate ( ) throws Exception { super . validate ( ) ; if ( this . location == null || this . location . length ( ) <= <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" ) ; } } @ Override public String resolve ( ) throws Exception { return resolve ( new FileInputStream ( location ) ) ; } @ Override public String resolve ( VariableSubstitutor ... substitutors ) throws Exception { String _location_ = location ; for ( VariableSubstitutor substitutor : substitutors ) { _location_ = substitutor . substitute ( _location_ ) ; } return resolve ( new FileInputStream ( _location_ ) , substitutors ) ; } } </s>
|
<s> package com . izforge . izpack . core . variable ; import java . io . InputStream ; import java . util . zip . ZipEntry ; import java . util . zip . ZipException ; import java . util . zip . ZipFile ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; public class ZipEntryConfigFileValue extends ConfigFileValue { private String filename ; private String entryname ; public ZipEntryConfigFileValue ( String filename , String entryname , int type , String section , String key ) { super ( type , section , key ) ; this . filename = filename ; this . entryname = entryname ; } public String getFilename ( ) { return filename ; } public void setFilename ( String filename ) { this . filename = filename ; } public String getEntryname ( ) { return entryname ; } public void setEntryname ( String entryname ) { this . entryname = entryname ; } @ Override public void validate ( ) throws Exception { super . validate ( ) ; if ( this . filename == null || this . filename . length ( ) <= <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" ) ; } if ( this . entryname == null || this . entryname . length ( ) <= <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" ) ; } } @ Override public String resolve ( ) throws Exception { return super . resolve ( getZipEntryInputStream ( getFilename ( ) , getEntryname ( ) ) ) ; } @ Override public String resolve ( VariableSubstitutor ... substitutors ) throws Exception { String _filename_ = this . filename , _entryname_ = this . entryname ; for ( VariableSubstitutor substitutor : substitutors ) { _filename_ = substitutor . substitute ( _filename_ ) ; } for ( VariableSubstitutor substitutor : substitutors ) { _entryname_ = substitutor . substitute ( _entryname_ ) ; } return super . resolve ( getZipEntryInputStream ( _filename_ , _entryname_ ) , substitutors ) ; } private InputStream getZipEntryInputStream ( String filename , String entryname ) throws Exception { ZipFile zipfile ; try { zipfile = new ZipFile ( filename ) ; ZipEntry entry = zipfile . getEntry ( entryname ) ; if ( entry == null ) { throw new Exception ( "<STR_LIT>" + entryname + "<STR_LIT>" + zipfile . getName ( ) ) ; } return zipfile . getInputStream ( entry ) ; } catch ( ZipException ze ) { throw new Exception ( "<STR_LIT>" + filename , ze ) ; } } } </s>
|
<s> package com . izforge . izpack . core . variable . filters ; import com . izforge . izpack . api . data . ValueFilter ; import com . izforge . izpack . api . regex . RegularExpressionProcessor ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . regex . RegularExpressionProcessorImpl ; public class RegularExpressionFilter implements ValueFilter { private static final long serialVersionUID = - <NUM_LIT> ; public String regexp ; public String select , replace ; public String defaultValue ; public Boolean casesensitive ; public Boolean global ; public RegularExpressionFilter ( String regexp , String select , String replace , String defaultValue , Boolean casesensitive , Boolean global ) { this . regexp = regexp ; this . select = select ; this . replace = replace ; this . defaultValue = defaultValue ; this . casesensitive = casesensitive ; this . global = global ; } public RegularExpressionFilter ( String regexp , String select , String defaultValue , Boolean casesensitive ) { this ( regexp , select , null , defaultValue , casesensitive , null ) ; } public RegularExpressionFilter ( String regexp , String replace , String defaultValue , Boolean casesensitive , Boolean global ) { this ( regexp , null , replace , defaultValue , casesensitive , global ) ; } @ Override public void validate ( ) throws Exception { if ( this . regexp == null || this . regexp . length ( ) <= <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" ) ; } if ( this . select == null && this . replace == null ) { throw new Exception ( "<STR_LIT>" ) ; } if ( this . select != null && this . replace != null ) { throw new Exception ( "<STR_LIT>" ) ; } } public String getRegexp ( ) { return regexp ; } public void setRegexp ( String regexp ) { this . regexp = regexp ; } public String getSelect ( ) { return select ; } public void setSelect ( String select ) { this . select = select ; } public String getReplace ( ) { return replace ; } public void setReplace ( String replace ) { this . replace = replace ; } public String getDefaultValue ( ) { return defaultValue ; } public void setDefaultValue ( String defaultValue ) { this . defaultValue = defaultValue ; } public Boolean getCasesensitive ( ) { return casesensitive ; } public void setCasesensitive ( Boolean casesensitive ) { this . casesensitive = casesensitive ; } public Boolean getGlobal ( ) { return global ; } public void setGlobal ( Boolean global ) { this . global = global ; } @ Override public String filter ( String value , VariableSubstitutor ... substitutors ) throws Exception { String _replace = replace , _select = select , _regexp = regexp , _defaultValue = defaultValue ; for ( VariableSubstitutor substitutor : substitutors ) { if ( _replace != null ) { _replace = substitutor . substitute ( _replace ) ; } if ( _select != null ) { _select = substitutor . substitute ( _select ) ; } if ( _regexp != null ) { _regexp = substitutor . substitute ( _regexp ) ; } if ( _defaultValue != null ) { _defaultValue = substitutor . substitute ( _defaultValue ) ; } } RegularExpressionProcessor processor = new RegularExpressionProcessorImpl ( ) ; processor . setInput ( value ) ; processor . setRegexp ( _regexp ) ; processor . setCaseSensitive ( casesensitive ) ; if ( _select != null ) { processor . setSelect ( _select ) ; } else if ( _replace != null ) { processor . setReplace ( _replace ) ; processor . setGlobal ( global ) ; } processor . setDefaultValue ( _defaultValue ) ; return processor . execute ( ) ; } } </s>
|
<s> package com . izforge . izpack . core . variable . filters ; import org . apache . commons . io . FilenameUtils ; import com . izforge . izpack . api . data . ValueFilter ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; public class LocationFilter implements ValueFilter { private static final long serialVersionUID = <NUM_LIT> ; public String baseDir ; public LocationFilter ( String baseDir ) { this . baseDir = baseDir ; } public String getBaseDir ( ) { return this . baseDir ; } public void setBaseDir ( String baseDir ) { this . baseDir = baseDir ; } @ Override public void validate ( ) throws Exception { } @ Override public String filter ( String value , VariableSubstitutor ... substitutors ) throws Exception { String _baseDir_ = baseDir ; for ( VariableSubstitutor substitutor : substitutors ) { _baseDir_ = substitutor . substitute ( _baseDir_ ) ; } return FilenameUtils . concat ( _baseDir_ , value ) ; } } </s>
|
<s> package com . izforge . izpack . core . variable ; import java . io . InputStream ; import java . util . jar . JarEntry ; import java . util . jar . JarFile ; import java . util . zip . ZipException ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; public class JarEntryConfigValue extends ZipEntryConfigFileValue { public JarEntryConfigValue ( String filename , String entryname , int type , String section , String key ) { super ( filename , entryname , type , section , key ) ; } @ Override public String resolve ( ) throws Exception { return super . resolve ( getJarEntryInputStream ( getFilename ( ) , getEntryname ( ) ) ) ; } @ Override public String resolve ( VariableSubstitutor ... substitutors ) throws Exception { String _filename_ = getFilename ( ) , _entryname_ = getEntryname ( ) ; for ( VariableSubstitutor substitutor : substitutors ) { _filename_ = substitutor . substitute ( _filename_ ) ; } for ( VariableSubstitutor substitutor : substitutors ) { _entryname_ = substitutor . substitute ( _entryname_ ) ; } return super . resolve ( getJarEntryInputStream ( _filename_ , _entryname_ ) , substitutors ) ; } private InputStream getJarEntryInputStream ( String filename , String entryname ) throws Exception { JarFile jarfile ; try { jarfile = new JarFile ( filename ) ; JarEntry entry = jarfile . getJarEntry ( entryname ) ; if ( entry == null ) { throw new Exception ( "<STR_LIT>" + entryname + "<STR_LIT>" + jarfile . getName ( ) ) ; } return jarfile . getInputStream ( entry ) ; } catch ( ZipException ze ) { throw new Exception ( "<STR_LIT>" + filename , ze ) ; } } } </s>
|
<s> package com . izforge . izpack . core . variable ; import java . io . IOException ; import java . io . InputStream ; import java . io . Serializable ; import javax . xml . parsers . DocumentBuilder ; import javax . xml . parsers . DocumentBuilderFactory ; import javax . xml . parsers . ParserConfigurationException ; import javax . xml . xpath . XPath ; import javax . xml . xpath . XPathConstants ; import javax . xml . xpath . XPathExpression ; import javax . xml . xpath . XPathExpressionException ; import javax . xml . xpath . XPathFactory ; import org . w3c . dom . Document ; import org . w3c . dom . NodeList ; import org . xml . sax . SAXException ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . util . config . base . Ini ; import com . izforge . izpack . util . config . base . Options ; public abstract class ConfigFileValue extends ValueImpl implements Serializable { private static final long serialVersionUID = <NUM_LIT> ; public final static int CONFIGFILE_TYPE_OPTIONS = <NUM_LIT:0> ; public final static int CONFIGFILE_TYPE_INI = <NUM_LIT:1> ; public final static int CONFIGFILE_TYPE_XML = <NUM_LIT:2> ; public int type = CONFIGFILE_TYPE_OPTIONS ; public String section ; public String key ; public ConfigFileValue ( int type , String section , String key ) { super ( ) ; this . type = type ; this . section = section ; this . key = key ; } public int getType ( ) { return type ; } public void setType ( int type ) { this . type = type ; } public String getSection ( ) { return section ; } public void setSection ( String section ) { this . section = section ; } public String getKey ( ) { return key ; } public void setKey ( String key ) { this . key = key ; } @ Override public void validate ( ) throws Exception { if ( this . type == CONFIGFILE_TYPE_INI && ( this . section == null || this . section . length ( ) <= <NUM_LIT:0> ) ) { throw new Exception ( "<STR_LIT>" ) ; } if ( this . type != CONFIGFILE_TYPE_INI && this . section != null ) { throw new Exception ( "<STR_LIT>" ) ; } } protected String resolve ( InputStream in ) throws Exception { switch ( type ) { case CONFIGFILE_TYPE_OPTIONS : Options opts ; opts = new Options ( in ) ; return opts . get ( key ) ; case CONFIGFILE_TYPE_INI : Ini ini ; ini = new Ini ( in ) ; return ini . get ( section , key ) ; case CONFIGFILE_TYPE_XML : return parseXPath ( in , key , System . getProperty ( "<STR_LIT>" ) ) ; default : throw new Exception ( "<STR_LIT>" + type ) ; } } protected String resolve ( InputStream in , VariableSubstitutor ... substitutors ) throws Exception { String _key_ = key ; for ( VariableSubstitutor substitutor : substitutors ) { _key_ = substitutor . substitute ( _key_ ) ; } switch ( type ) { case CONFIGFILE_TYPE_OPTIONS : Options opts ; opts = new Options ( in ) ; return opts . get ( _key_ ) ; case CONFIGFILE_TYPE_INI : Ini ini ; String _section_ = section ; for ( VariableSubstitutor substitutor : substitutors ) { _key_ = substitutor . substitute ( _key_ ) ; } ini = new Ini ( in ) ; return ini . get ( _section_ , _key_ ) ; case CONFIGFILE_TYPE_XML : return parseXPath ( in , _key_ , System . getProperty ( "<STR_LIT>" ) ) ; default : throw new Exception ( "<STR_LIT>" + type + "<STR_LIT:'>" ) ; } } private static String parseXPath ( InputStream in , String expression , String separator ) throws ParserConfigurationException , SAXException , IOException , XPathExpressionException { DocumentBuilderFactory domFactory = DocumentBuilderFactory . newInstance ( ) ; domFactory . setNamespaceAware ( true ) ; DocumentBuilder builder ; builder = domFactory . newDocumentBuilder ( ) ; Document doc = builder . parse ( in ) ; XPath xpath = XPathFactory . newInstance ( ) . newXPath ( ) ; XPathExpression expr = xpath . compile ( expression ) ; Object result = expr . evaluate ( doc , XPathConstants . NODESET ) ; NodeList nodes = ( NodeList ) result ; StringBuffer sb = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < nodes . getLength ( ) ; i ++ ) { String value = nodes . item ( i ) . getNodeValue ( ) ; if ( value != null ) { if ( sb . length ( ) > <NUM_LIT:0> ) { sb . append ( separator ) ; } sb . append ( value ) ; } } return sb . toString ( ) ; } } </s>
|
<s> package com . izforge . izpack . core . variable ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . util . IoHelper ; import java . io . Serializable ; public class EnvironmentValue extends ValueImpl implements Serializable { private static final long serialVersionUID = - <NUM_LIT> ; public String variable ; public EnvironmentValue ( String variable ) { super ( ) ; this . variable = variable ; } public String getVariable ( ) { return this . variable ; } public void setVariable ( String variable ) { this . variable = variable ; } @ Override public void validate ( ) throws Exception { if ( this . variable == null || this . variable . length ( ) <= <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" ) ; } } @ Override public String resolve ( ) { return IoHelper . getenv ( variable ) ; } @ Override public String resolve ( VariableSubstitutor ... substitutors ) throws Exception { String _variable_ = variable ; for ( VariableSubstitutor substitutor : substitutors ) { _variable_ = substitutor . substitute ( _variable_ ) ; } return IoHelper . getenv ( _variable_ ) ; } } </s>
|
<s> package com . izforge . izpack . core . variable ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Value ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; public abstract class ValueImpl implements Value { private InstallData installData ; @ Override public abstract void validate ( ) throws Exception ; @ Override public abstract String resolve ( ) throws Exception ; @ Override public abstract String resolve ( VariableSubstitutor ... substitutors ) throws Exception ; @ Override public InstallData getInstallData ( ) { return installData ; } @ Override public void setInstallData ( InstallData installData ) { this . installData = installData ; } } </s>
|
<s> package com . izforge . izpack . core . variable ; import java . io . Serializable ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; import com . izforge . izpack . util . FileExecutor ; import com . izforge . izpack . util . OsVersion ; public class ExecValue extends ValueImpl implements Serializable { private static final long serialVersionUID = - <NUM_LIT> ; private String cmd [ ] ; private String dir ; private boolean useStdErr = true ; public ExecValue ( String [ ] command , String dir , boolean isShellCommand , boolean useStdErr ) { super ( ) ; if ( isShellCommand ) { if ( OsVersion . IS_WINDOWS ) { this . cmd = new String [ command . length + <NUM_LIT:2> ] ; this . cmd [ <NUM_LIT:0> ] = "<STR_LIT>" ; this . cmd [ <NUM_LIT:1> ] = "<STR_LIT>" ; for ( int i = <NUM_LIT:2> ; i < this . cmd . length ; i ++ ) { this . cmd [ i ] = command [ i - <NUM_LIT:2> ] ; } } else if ( OsVersion . IS_UNIX ) { this . cmd = new String [ command . length + <NUM_LIT:1> ] ; this . cmd [ <NUM_LIT:0> ] = "<STR_LIT>" ; for ( int i = <NUM_LIT:1> ; i < this . cmd . length ; i ++ ) { this . cmd [ i ] = command [ i - <NUM_LIT:1> ] ; } } else { this . cmd = command ; } } else { this . cmd = command ; } this . dir = dir ; this . useStdErr = useStdErr ; } public String [ ] getCmd ( ) { return cmd ; } public void setCmd ( String [ ] cmd ) { this . cmd = cmd ; } @ Override public void validate ( ) throws Exception { if ( this . cmd == null || this . cmd . length <= <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } @ Override public String resolve ( ) { VariableSubstitutor substitutor = new VariableSubstitutorImpl ( getInstallData ( ) . getVariables ( ) ) ; return resolve ( substitutor ) ; } @ Override public String resolve ( VariableSubstitutor ... substitutors ) { String _dir_ = null , _cmd_ [ ] = new String [ cmd . length ] ; for ( VariableSubstitutor substitutor : substitutors ) { _dir_ = substitutor . substitute ( dir , null ) ; } for ( int i = <NUM_LIT:0> ; i < cmd . length ; i ++ ) { String _cmdarg_ = cmd [ i ] ; for ( VariableSubstitutor substitutor : substitutors ) { _cmdarg_ = substitutor . substitute ( _cmdarg_ , null ) ; } _cmd_ [ i ] = _cmdarg_ ; } String [ ] execOut = new String [ <NUM_LIT:2> ] ; int ret = new FileExecutor ( ) . executeCommand ( _cmd_ , execOut , _dir_ ) ; if ( ret == <NUM_LIT:0> ) { if ( useStdErr ) { return execOut [ <NUM_LIT:1> ] ; } else { return execOut [ <NUM_LIT:0> ] ; } } return null ; } } </s>
|
<s> package com . izforge . izpack . core . variable ; import java . io . Serializable ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . util . OsVersion ; import com . izforge . izpack . util . config . base . Reg ; public class RegistryValue extends ValueImpl implements Serializable { private static final long serialVersionUID = <NUM_LIT> ; public String root ; public String key ; public String value ; public RegistryValue ( String root , String key , String value ) { super ( ) ; this . root = root ; this . key = key ; this . value = value ; } public String getRoot ( ) { return root ; } public void setRoot ( String root ) { this . root = root ; } public String getKey ( ) { return key ; } public void setKey ( String key ) { this . key = key ; } public String getValue ( ) { return this . value ; } public void setValue ( String value ) { this . value = value ; } @ Override public void validate ( ) throws Exception { if ( ( this . root == null && this . key == null ) || ( ( this . root != null && this . root . length ( ) <= <NUM_LIT:0> ) && ( this . key != null && this . key . length ( ) <= <NUM_LIT:0> ) ) ) { throw new Exception ( "<STR_LIT>" ) ; } } @ Override public String resolve ( ) throws Exception { if ( ! OsVersion . IS_WINDOWS ) { throw new Exception ( "<STR_LIT>" ) ; } Reg reg = null ; Reg . Key regkey = null ; if ( root != null ) { reg = new Reg ( root ) ; } if ( key != null ) { if ( reg == null ) { reg = new Reg ( ) ; } regkey = reg . get ( key ) ; } if ( regkey != null ) { return regkey . get ( value ) ; } return null ; } @ Override public String resolve ( VariableSubstitutor ... substitutors ) throws Exception { if ( ! OsVersion . IS_WINDOWS ) { throw new Exception ( "<STR_LIT>" ) ; } Reg reg = null ; Reg . Key regkey = null ; if ( root != null ) { String _root_ = root ; for ( VariableSubstitutor substitutor : substitutors ) { _root_ = substitutor . substitute ( _root_ ) ; } reg = new Reg ( _root_ ) ; } if ( key != null ) { if ( reg == null ) { reg = new Reg ( ) ; } String _key_ = key ; for ( VariableSubstitutor substitutor : substitutors ) { _key_ = substitutor . substitute ( _key_ ) ; } regkey = reg . get ( _key_ ) ; } if ( regkey != null ) { String _value_ = value ; for ( VariableSubstitutor substitutor : substitutors ) { _value_ = substitutor . substitute ( _value_ ) ; } return regkey . get ( _value_ ) ; } return null ; } } </s>
|
<s> package com . izforge . izpack . core . variable ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import java . io . Serializable ; public class PlainValue extends ValueImpl implements Serializable { private static final long serialVersionUID = - <NUM_LIT> ; public String value ; public PlainValue ( String value ) { super ( ) ; this . value = value ; } public String getValue ( ) { return this . value ; } public void setValue ( String value ) { this . value = value ; } @ Override public void validate ( ) throws Exception { if ( this . value == null || this . value . length ( ) <= <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" ) ; } } @ Override public String resolve ( ) { return value ; } @ Override public String resolve ( VariableSubstitutor ... substitutors ) throws Exception { String _value_ = value ; for ( VariableSubstitutor substitutor : substitutors ) { _value_ = substitutor . substitute ( _value_ ) ; } return _value_ ; } } </s>
|
<s> package com . izforge . izpack . core . resource ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . ObjectInputStream ; import java . net . URL ; import java . util . Arrays ; import javax . swing . ImageIcon ; import com . izforge . izpack . api . exception . ResourceException ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . util . file . FileUtils ; public abstract class AbstractResources implements Resources { private final ClassLoader loader ; public AbstractResources ( ) { this ( AbstractResources . class . getClassLoader ( ) ) ; } public AbstractResources ( ClassLoader loader ) { this . loader = loader ; } @ Override public InputStream getInputStream ( String name ) { name = resolveName ( name ) ; InputStream result = loader . getResourceAsStream ( name ) ; if ( result == null ) { throw new ResourceNotFoundException ( "<STR_LIT>" + name ) ; } return result ; } @ Override public URL getURL ( String name ) { URL result = getResource ( name ) ; if ( result == null ) { throw new ResourceNotFoundException ( "<STR_LIT>" + name ) ; } return result ; } @ Override public String getString ( String name ) { try { return readString ( name , "<STR_LIT:UTF-8>" ) ; } catch ( IOException exception ) { throw new ResourceException ( "<STR_LIT>" + name , exception ) ; } } @ Override public String getString ( String name , String defaultValue ) { return getString ( name , "<STR_LIT:UTF-8>" , defaultValue ) ; } @ Override public String getString ( String name , String encoding , String defaultValue ) { String result ; try { result = readString ( name , encoding ) ; } catch ( Exception exception ) { result = defaultValue ; } return result ; } @ Override public Object getObject ( String name ) { Object result ; InputStream in = getInputStream ( name ) ; ObjectInputStream objectIn = null ; try { objectIn = new ObjectInputStream ( in ) ; result = objectIn . readObject ( ) ; } catch ( Exception exception ) { throw new ResourceException ( "<STR_LIT>" + name , exception ) ; } finally { FileUtils . close ( objectIn ) ; FileUtils . close ( in ) ; } return result ; } @ Override public ImageIcon getImageIcon ( String name , String ... alternatives ) { URL result = getResource ( name ) ; if ( result == null ) { for ( String fallback : alternatives ) { result = getResource ( fallback ) ; if ( result != null ) { break ; } } } if ( result == null ) { StringBuilder message = new StringBuilder ( "<STR_LIT>" ) ; message . append ( name ) ; if ( alternatives . length != <NUM_LIT:0> ) { message . append ( "<STR_LIT>" ) ; message . append ( Arrays . toString ( alternatives ) ) ; } throw new ResourceNotFoundException ( message . toString ( ) ) ; } return new ImageIcon ( result ) ; } protected URL getResource ( String name ) { name = resolveName ( name ) ; return loader . getResource ( name ) ; } protected String resolveName ( String name ) { if ( name . charAt ( <NUM_LIT:0> ) == '<CHAR_LIT:/>' ) { name = name . substring ( <NUM_LIT:1> ) ; } return name ; } protected ClassLoader getLoader ( ) { return loader ; } protected String readString ( String name , String encoding ) throws IOException { String result ; InputStream in = getInputStream ( name ) ; InputStreamReader reader = null ; try { reader = ( encoding != null ) ? new InputStreamReader ( in , encoding ) : new InputStreamReader ( in ) ; result = FileUtils . readFully ( reader ) ; } finally { FileUtils . close ( reader ) ; FileUtils . close ( in ) ; } return result ; } } </s>
|
<s> package com . izforge . izpack . core . resource ; import java . io . InputStream ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . List ; import java . util . Locale ; import java . util . Map ; import java . util . MissingResourceException ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . LocaleDatabase ; import com . izforge . izpack . api . exception . ResourceException ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . resource . Locales ; import com . izforge . izpack . api . resource . Messages ; import com . izforge . izpack . api . resource . Resources ; public class DefaultLocales implements Locales { private final Resources resources ; private Locale locale ; private List < Locale > locales = new ArrayList < Locale > ( ) ; private static final Logger logger = Logger . getLogger ( DefaultLocales . class . getName ( ) ) ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public DefaultLocales ( Resources resources ) { this . resources = resources ; List < String > codes = getSupportedLocales ( ) ; if ( ! codes . isEmpty ( ) ) { Locale defaultLocale = Locale . getDefault ( ) ; Map < String , Locale > iso3 = getLocalesByISO3 ( defaultLocale ) ; for ( String code : codes ) { Locale locale = iso3 . get ( code ) ; if ( locale == null ) { logger . warning ( "<STR_LIT>" + code ) ; } else { locales . add ( locale ) ; } } if ( ! locales . isEmpty ( ) ) { if ( locales . contains ( defaultLocale ) ) { locale = defaultLocale ; } else { locale = locales . get ( <NUM_LIT:0> ) ; } } } } public Locale getLocale ( ) { return locale ; } public void setLocale ( Locale locale ) { this . locale = locale ; } @ Override public Locale getLocale ( String code ) { int length = code . length ( ) ; for ( Locale locale : locales ) { if ( length == <NUM_LIT:3> ) { if ( code . equalsIgnoreCase ( locale . getISO3Language ( ) ) ) { return locale ; } } else { if ( code . equalsIgnoreCase ( locale . getLanguage ( ) ) ) { return locale ; } } } return null ; } @ Override public List < Locale > getLocales ( ) { return locales ; } @ Override public Messages getMessages ( ) { if ( locale == null ) { throw new ResourceException ( "<STR_LIT>" ) ; } InputStream in = resources . getInputStream ( "<STR_LIT>" + locale . getISO3Language ( ) + "<STR_LIT>" ) ; return new LocaleDatabase ( in , this ) ; } @ Override public Messages getMessages ( String name ) { InputStream in = resources . getInputStream ( name ) ; return new LocaleDatabase ( in , this ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public List < String > getSupportedLocales ( ) { List < String > locales = null ; try { locales = ( List < String > ) resources . getObject ( "<STR_LIT>" ) ; } catch ( ResourceNotFoundException ignore ) { } return ( locales != null ) ? locales : Collections . < String > emptyList ( ) ; } private Map < String , Locale > getLocalesByISO3 ( Locale defaultLocale ) { String defaultCode = getISO3Language ( defaultLocale ) ; Map < String , Locale > iso3 = new HashMap < String , Locale > ( ) ; if ( defaultCode != null ) { iso3 . put ( defaultCode , defaultLocale ) ; } for ( Locale locale : Locale . getAvailableLocales ( ) ) { String code = getISO3Language ( locale ) ; if ( ! code . equals ( defaultCode ) ) { Locale existing = iso3 . get ( code ) ; if ( existing == null || locale . getCountry ( ) . isEmpty ( ) ) { iso3 . put ( code , locale ) ; } } } return iso3 ; } private String getISO3Language ( Locale locale ) { String result ; try { result = locale . getISO3Language ( ) ; } catch ( MissingResourceException ignore ) { result = null ; } return result ; } } </s>
|
<s> package com . izforge . izpack . core . resource ; public class DefaultResources extends AbstractResources { public DefaultResources ( ) { } } </s>
|
<s> package com . izforge . izpack . core . resource ; import java . io . IOException ; import java . io . InputStream ; import java . net . URL ; import java . util . List ; import java . util . Locale ; import javax . swing . ImageIcon ; import com . izforge . izpack . api . exception . ResourceException ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . resource . Locales ; public class ResourceManager extends AbstractResources { private Locales locales ; public final String resourceBasePathDefaultConstant = "<STR_LIT>" ; private String resourceBasePath = "<STR_LIT>" ; public ResourceManager ( ) { this ( ClassLoader . getSystemClassLoader ( ) ) ; } public ResourceManager ( ClassLoader loader ) { super ( loader ) ; } public void setLocales ( Locales locales ) { this . locales = locales ; } @ Deprecated public void setDefaultOrResourceBasePath ( String aDefaultBasePath ) { if ( null != aDefaultBasePath ) { this . setResourceBasePath ( aDefaultBasePath ) ; } else { this . setResourceBasePath ( resourceBasePathDefaultConstant ) ; } } @ Deprecated public boolean isResourceExist ( String resource ) { return this . getLanguageResourceString ( resource ) != null ; } public InputStream getInputStream ( String resource ) { resource = getLanguageResourceString ( resource ) ; return super . getInputStream ( resource ) ; } @ Override public URL getURL ( String name ) { return getResource ( getLanguageResourceString ( name ) ) ; } @ Deprecated public InputStream getInputStream ( String resource , InputStream defaultValue ) { String resourcepath = this . getLanguageResourceString ( resource ) ; if ( resourcepath == null ) { return defaultValue ; } return getInputStream ( resourcepath ) ; } @ Deprecated public URL getLocalizedURL ( String resource ) { return getResource ( getLanguageResourceString ( resource ) ) ; } @ Deprecated public String getTextResource ( String resource , String encoding ) throws IOException { return readString ( resource , encoding ) ; } @ Deprecated public String getTextResource ( String resource ) throws IOException { return this . getTextResource ( resource , null ) ; } @ Deprecated public ImageIcon getImageIconResource ( String resource , String ... fallback ) { return getImageIcon ( resource , fallback ) ; } @ Deprecated public void setLocale ( String locale ) { locales . setLocale ( locales . getLocale ( locale ) ) ; } public String getLocale ( ) { if ( locales != null ) { Locale locale = locales . getLocale ( ) ; return ( locale != null ) ? locale . getISO3Language ( ) : null ; } return null ; } public String getResourceBasePath ( ) { return resourceBasePath ; } public void setResourceBasePath ( String resourceBasePath ) { this . resourceBasePath = resourceBasePath ; } @ Deprecated public InputStream getLangPack ( String localeISO3 ) { return getInputStream ( "<STR_LIT>" + localeISO3 + "<STR_LIT>" ) ; } @ Deprecated public InputStream getLangPack ( ) { return this . getLangPack ( locales . getLocale ( ) . getISO3Language ( ) ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) @ Deprecated public List < String > getAvailableLangPacks ( ) { return ( List < String > ) getObject ( "<STR_LIT>" ) ; } @ Override protected String resolveName ( String name ) { name = ( name . charAt ( <NUM_LIT:0> ) == '<CHAR_LIT:/>' ) ? name : getResourceBasePath ( ) + name ; return super . resolveName ( name ) ; } private String getLanguageResourceString ( String resource ) { String code = getLocale ( ) ; String resourcePath = ( code != null ) ? resource + "<STR_LIT:_>" + code : null ; if ( resourcePath != null && getResource ( resourcePath ) != null ) { return resourcePath ; } else if ( getResource ( resource ) != null ) { return resource ; } if ( resourcePath != null ) { throw new ResourceNotFoundException ( "<STR_LIT>" + resource + "<STR_LIT>" + resourcePath + "<STR_LIT:'>" ) ; } throw new ResourceNotFoundException ( "<STR_LIT>" + resource + "<STR_LIT:'>" ) ; } } </s>
|
<s> package com . izforge . izpack . core . factory ; import com . izforge . izpack . api . container . Container ; import com . izforge . izpack . api . factory . ObjectFactory ; public class DefaultObjectFactory implements ObjectFactory { private final Container container ; public DefaultObjectFactory ( Container container ) { this . container = container ; } @ Override public < T > T create ( Class < T > type , Object ... parameters ) { T result ; Container child = container . createChildContainer ( ) ; try { child . addComponent ( type ) ; for ( Object parameter : parameters ) { child . addComponent ( parameter , parameter ) ; } result = child . getComponent ( type ) ; } finally { container . removeChildContainer ( child ) ; child . dispose ( ) ; } return result ; } @ Override public < T > T create ( String className , Class < T > superType , Object ... parameters ) { Class < ? extends T > type = container . getClass ( className , superType ) ; return create ( type , parameters ) ; } } </s>
|
<s> package com . izforge . izpack . compiler . compressor ; import java . io . IOException ; import org . apache . commons . compress . compressors . CompressorException ; import org . apache . tools . zip . ZipEntry ; import org . junit . Test ; import com . izforge . izpack . compiler . container . provider . JarOutputStreamProvider ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . stream . JarOutputStream ; public class CompressorTest { @ Test public void testBzip2Compression ( ) throws IOException , CompressorException { CompilerData data = new CompilerData ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , false ) ; data . setComprFormat ( "<STR_LIT>" ) ; data . setComprLevel ( <NUM_LIT:5> ) ; JarOutputStreamProvider jarOutputStreamProvider = new JarOutputStreamProvider ( ) ; JarOutputStream jarOutputStream = jarOutputStreamProvider . provide ( data ) ; ZipEntry zipEntry = new ZipEntry ( "<STR_LIT:test>" ) ; zipEntry . setMethod ( java . util . zip . ZipEntry . STORED ) ; zipEntry . setComment ( "<STR_LIT>" ) ; jarOutputStream . putNextEntry ( zipEntry ) ; } } </s>
|
<s> package com . izforge . izpack . compiler . cli ; import static org . hamcrest . MatcherAssert . assertThat ; import org . hamcrest . core . Is ; import org . junit . Before ; import org . junit . Test ; import com . izforge . izpack . compiler . data . CompilerData ; public class CliAnalyzerTest { private CliAnalyzer analyzer ; @ Before public void initAnalyzer ( ) { analyzer = new CliAnalyzer ( ) ; } @ Test ( expected = RuntimeException . class ) public void voidArgumentShouldThrowRuntimeException ( ) throws Exception { analyzer . parseArgs ( new String [ ] { } ) ; } @ Test public void fileNameShouldBeParsed ( ) throws Exception { CompilerData data = analyzer . parseArgs ( new String [ ] { "<STR_LIT>" } ) ; assertThat ( data . getInstallFile ( ) , Is . is ( "<STR_LIT>" ) ) ; } @ Test public void homeDirShouldBeParsed ( ) throws Exception { CompilerData data = analyzer . parseArgs ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ) ; assertThat ( data . getInstallFile ( ) , Is . is ( "<STR_LIT>" ) ) ; assertThat ( CompilerData . IZPACK_HOME , Is . is ( "<STR_LIT>" ) ) ; } @ Test public void baseDirShouldBeParsed ( ) throws Exception { CompilerData data = analyzer . parseArgs ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ) ; assertThat ( data . getInstallFile ( ) , Is . is ( "<STR_LIT>" ) ) ; assertThat ( data . getBasedir ( ) , Is . is ( "<STR_LIT>" ) ) ; } @ Test public void multipleOptionShouldBeParsed ( ) throws Exception { CompilerData data = analyzer . parseArgs ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ; assertThat ( data . getInstallFile ( ) , Is . is ( "<STR_LIT>" ) ) ; assertThat ( data . getBasedir ( ) , Is . is ( "<STR_LIT>" ) ) ; assertThat ( data . getKind ( ) , Is . is ( "<STR_LIT>" ) ) ; assertThat ( data . getOutput ( ) , Is . is ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . compiler . container ; import java . io . File ; import java . io . IOException ; 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 TestCompilerContainer extends CompilerContainer { public static final String APPNAME = "<STR_LIT>" ; private Class < ? > testClass ; private FrameworkMethod testMethod ; public TestCompilerContainer ( Class < ? > testClass , FrameworkMethod testMethod ) { super ( null ) ; this . testClass = testClass ; this . testMethod = testMethod ; initialise ( ) ; } 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 ) ; try { deleteLock ( ) ; } catch ( IOException exception ) { throw new ContainerException ( exception ) ; } InstallFile installFile = testMethod . getAnnotation ( InstallFile . class ) ; if ( installFile == null ) { installFile = testClass . getAnnotation ( InstallFile . class ) ; } String installFileName = installFile . value ( ) ; File installerFile = FileUtil . convertUrlToFile ( getClass ( ) . getClassLoader ( ) . getResource ( installFileName ) ) ; File baseDir = installerFile . getParentFile ( ) ; File out = new File ( baseDir , "<STR_LIT>" + Math . random ( ) + "<STR_LIT>" ) ; out . deleteOnExit ( ) ; CompilerData data = new CompilerData ( installerFile . getAbsolutePath ( ) , baseDir . getAbsolutePath ( ) , out . getAbsolutePath ( ) , false ) ; addComponent ( CompilerData . class , data ) ; addComponent ( File . class , out ) ; container . addConfig ( "<STR_LIT>" , installerFile . getAbsolutePath ( ) ) ; container . addAdapter ( new JarFileProvider ( ) ) ; } private void deleteLock ( ) throws IOException { 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 java . util . Properties ; import org . picocontainer . PicoException ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . compiler . util . CompilerClassLoader ; import com . izforge . izpack . compiler . merge . CompilerPathResolver ; import com . izforge . izpack . compiler . util . DefaultClassNameMapper ; import com . izforge . izpack . core . container . AbstractContainer ; import com . izforge . izpack . merge . resolve . MergeableResolver ; public class TestResolveContainer extends AbstractContainer { public TestResolveContainer ( ) { initialise ( ) ; } @ Override protected void fillContainer ( ) { addComponent ( Properties . class ) ; addComponent ( CompilerPathResolver . class ) ; addComponent ( CompilerClassLoader . class ) ; addComponent ( DefaultClassNameMapper . class ) ; addComponent ( MergeableResolver . class ) ; Properties properties = getComponent ( Properties . class ) ; properties . put ( "<STR_LIT>" , "<STR_LIT>" ) ; } } </s>
|
<s> package com . izforge . izpack . compiler ; import static org . hamcrest . MatcherAssert . assertThat ; import java . io . File ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . jar . JarFile ; import org . apache . maven . shared . jar . JarAnalyzer ; import org . apache . maven . shared . jar . classes . JarClasses ; import org . apache . maven . shared . jar . classes . JarClassesAnalysis ; import org . junit . Assert ; import org . junit . Ignore ; import org . junit . Test ; import org . junit . runner . RunWith ; import com . izforge . izpack . compiler . container . TestCompilerContainer ; import com . izforge . izpack . compiler . merge . CompilerPathResolver ; import com . izforge . izpack . core . container . AbstractContainer ; import com . izforge . izpack . matcher . MergeMatcher ; import com . izforge . izpack . matcher . ZipMatcher ; import com . izforge . izpack . merge . MergeManagerImpl ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . InstallFile ; import com . izforge . izpack . test . junit . PicoRunner ; @ RunWith ( PicoRunner . class ) @ Container ( TestCompilerContainer . class ) @ InstallFile ( "<STR_LIT>" ) public class CompilerConfigTest { private JarFile jar ; private CompilerConfig compilerConfig ; private CompilerPathResolver pathResolver ; private MergeManagerImpl mergeManager ; private AbstractContainer testContainer ; public CompilerConfigTest ( TestCompilerContainer container , CompilerConfig compilerConfig , CompilerPathResolver pathResolver , MergeManagerImpl mergeManager ) { this . testContainer = container ; this . compilerConfig = compilerConfig ; this . pathResolver = pathResolver ; this . mergeManager = mergeManager ; } @ Test public void installerShouldContainInstallerClassResourcesAndImages ( ) throws Exception { compilerConfig . executeCompiler ( ) ; jar = testContainer . getComponent ( JarFile . class ) ; assertThat ( jar , ZipMatcher . isZipContainingFiles ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void mergeManagerShouldGetTheMergeableFromPanel ( ) throws Exception { mergeManager . addResourceToMerge ( pathResolver . getPanelMerge ( "<STR_LIT>" ) ) ; mergeManager . addResourceToMerge ( pathResolver . getPanelMerge ( "<STR_LIT>" ) ) ; assertThat ( mergeManager , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test @ Ignore public void testImportAreResolved ( ) throws Exception { JarAnalyzer jarAnalyzer = new JarAnalyzer ( new File ( jar . getName ( ) ) ) ; JarClassesAnalysis jarClassAnalyzer = new JarClassesAnalysis ( ) ; JarClasses jarClasses = jarClassAnalyzer . analyze ( jarAnalyzer ) ; List < String > imports = jarClasses . getImports ( ) ; List < String > listFromZip = ZipMatcher . getFileNameListFromZip ( jar ) ; ArrayList < String > result = new ArrayList < String > ( ) ; List < String > ignorePackage = Arrays . asList ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:text/html>" , "<STR_LIT>" , "<STR_LIT>" ) ; for ( String anImport : imports ) { if ( anImport . matches ( "<STR_LIT>" ) ) { String currentClass = anImport . replaceAll ( "<STR_LIT:\\.>" , "<STR_LIT:/>" ) + "<STR_LIT:.class>" ; if ( ignorePackage . contains ( currentClass ) ) { continue ; } if ( ! listFromZip . contains ( currentClass ) ) { result . add ( currentClass ) ; } } if ( ! result . isEmpty ( ) ) { StringBuilder stringBuilder = new StringBuilder ( ) ; for ( String s : result ) { stringBuilder . append ( s ) . append ( '<STR_LIT:\n>' ) ; } Assert . fail ( "<STR_LIT>" + stringBuilder ) ; } } } } </s>
|
<s> package com . izforge . izpack . compiler . util ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertNull ; import org . junit . Test ; import com . izforge . izpack . event . AntActionInstallerListener ; import com . izforge . izpack . event . AntActionUninstallerListener ; import com . izforge . izpack . event . BSFInstallerListener ; import com . izforge . izpack . event . BSFUninstallerListener ; import com . izforge . izpack . event . ConfigurationInstallerListener ; import com . izforge . izpack . event . ProgressBarInstallerListener ; import com . izforge . izpack . event . RegistryInstallerListener ; import com . izforge . izpack . event . RegistryUninstallerListener ; import com . izforge . izpack . event . SummaryLoggerInstallerListener ; import com . izforge . izpack . installer . web . DownloadPanel ; import com . izforge . izpack . panels . checkedhello . CheckedHelloPanel ; import com . izforge . izpack . panels . compile . CompilePanel ; import com . izforge . izpack . panels . datacheck . DataCheckPanel ; import com . izforge . izpack . panels . defaulttarget . DefaultTargetPanel ; import com . izforge . izpack . panels . extendedinstall . ExtendedInstallPanel ; import com . izforge . izpack . panels . finish . FinishPanel ; import com . izforge . izpack . panels . hello . HelloPanel ; import com . izforge . izpack . panels . htmlhello . HTMLHelloPanel ; import com . izforge . izpack . panels . htmlinfo . HTMLInfoPanel ; import com . izforge . izpack . panels . htmllicence . HTMLLicencePanel ; import com . izforge . izpack . panels . imgpacks . ImgPacksPanel ; import com . izforge . izpack . panels . info . InfoPanel ; import com . izforge . izpack . panels . install . InstallPanel ; import com . izforge . izpack . panels . installationgroup . InstallationGroupPanel ; import com . izforge . izpack . panels . installationtype . InstallationTypePanel ; import com . izforge . izpack . panels . jdkpath . JDKPathPanel ; import com . izforge . izpack . panels . licence . LicencePanel ; import com . izforge . izpack . panels . packs . PacksPanel ; import com . izforge . izpack . panels . process . ProcessPanel ; import com . izforge . izpack . panels . selectprinter . SelectPrinterPanel ; import com . izforge . izpack . panels . shortcut . ShortcutPanel ; import com . izforge . izpack . panels . simplefinish . SimpleFinishPanel ; import com . izforge . izpack . panels . sudo . SudoPanel ; import com . izforge . izpack . panels . summary . SummaryPanel ; import com . izforge . izpack . panels . target . TargetPanel ; import com . izforge . izpack . panels . treepacks . TreePacksPanel ; import com . izforge . izpack . panels . userinput . UserInputPanel ; import com . izforge . izpack . panels . userinput . validator . HostAddressValidator ; import com . izforge . izpack . panels . userinput . validator . IsPortValidator ; import com . izforge . izpack . panels . userinput . validator . NotEmptyValidator ; import com . izforge . izpack . panels . userinput . validator . PasswordEncryptionValidator ; import com . izforge . izpack . panels . userinput . validator . PasswordEqualityValidator ; import com . izforge . izpack . panels . userinput . validator . PortValidator ; import com . izforge . izpack . panels . userinput . validator . RegularExpressionValidator ; import com . izforge . izpack . panels . userpath . UserPathPanel ; import com . izforge . izpack . panels . xinfo . XInfoPanel ; public class DefaultClassNameMapperTest { private ClassNameMapper mapper ; public DefaultClassNameMapperTest ( ) { mapper = new DefaultClassNameMapper ( ) ; } @ Test public void testInstallerListeners ( ) { assertEquals ( AntActionInstallerListener . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( BSFInstallerListener . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( ConfigurationInstallerListener . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( ProgressBarInstallerListener . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( RegistryInstallerListener . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( SummaryLoggerInstallerListener . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; } @ Test public void testUninstallerListeners ( ) { assertEquals ( AntActionUninstallerListener . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( BSFUninstallerListener . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( RegistryUninstallerListener . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; } @ Test public void testValidators ( ) { assertEquals ( HostAddressValidator . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( IsPortValidator . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( NotEmptyValidator . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( PasswordEncryptionValidator . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( PasswordEqualityValidator . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( PortValidator . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( RegularExpressionValidator . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; } @ Test public void testIzPanels ( ) { assertEquals ( CheckedHelloPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( CompilePanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( DataCheckPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( DefaultTargetPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( DownloadPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( ExtendedInstallPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( FinishPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( HTMLHelloPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( HTMLInfoPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( HTMLLicencePanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( HelloPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( ImgPacksPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( InfoPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( InstallationGroupPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( InstallationTypePanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( InstallPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( JDKPathPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( LicencePanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( PacksPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( ProcessPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( SelectPrinterPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( ShortcutPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( SimpleFinishPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( SudoPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( SummaryPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( TargetPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( TreePacksPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( UserInputPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( UserPathPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; assertEquals ( XInfoPanel . class . getName ( ) , mapper . map ( "<STR_LIT>" ) ) ; } @ Test public void testNoMapping ( ) { assertNull ( mapper . map ( "<STR_LIT>" ) ) ; assertNull ( mapper . map ( HelloPanel . class . getName ( ) ) ) ; } } </s>
|
<s> package com . izforge . izpack . compiler . packager . impl ; import java . util . Properties ; import org . mockito . Mockito ; import com . izforge . izpack . api . data . Info ; import com . izforge . izpack . compiler . compressor . PackCompressor ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . listener . PackagerListener ; import com . izforge . izpack . compiler . merge . CompilerPathResolver ; import com . izforge . izpack . compiler . stream . JarOutputStream ; import com . izforge . izpack . merge . MergeManager ; import com . izforge . izpack . merge . resolve . MergeableResolver ; public class MultiVolumePackagerTest extends AbstractPackagerTest { @ Override protected PackagerBase createPackager ( JarOutputStream jar , MergeManager mergeManager ) { Properties properties = new Properties ( ) ; PackagerListener listener = null ; PackCompressor compressor = Mockito . mock ( PackCompressor . class ) ; CompilerPathResolver pathResolver = Mockito . mock ( CompilerPathResolver . class ) ; MergeableResolver resolver = Mockito . mock ( MergeableResolver . class ) ; CompilerData data = new CompilerData ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , true ) ; MultiVolumePackager packager = new MultiVolumePackager ( properties , listener , jar , mergeManager , pathResolver , resolver , compressor , data ) ; packager . setInfo ( new Info ( ) ) ; return packager ; } } </s>
|
<s> package com . izforge . izpack . compiler . packager . impl ; import java . util . Properties ; import org . mockito . Mockito ; import com . izforge . izpack . api . data . Info ; import com . izforge . izpack . compiler . compressor . PackCompressor ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . listener . PackagerListener ; import com . izforge . izpack . compiler . merge . CompilerPathResolver ; import com . izforge . izpack . compiler . stream . JarOutputStream ; import com . izforge . izpack . merge . MergeManager ; import com . izforge . izpack . merge . resolve . MergeableResolver ; public class PackagerTest extends AbstractPackagerTest { @ Override protected PackagerBase createPackager ( JarOutputStream jar , MergeManager mergeManager ) { Properties properties = new Properties ( ) ; PackagerListener listener = null ; PackCompressor compressor = Mockito . mock ( PackCompressor . class ) ; CompilerPathResolver pathResolver = Mockito . mock ( CompilerPathResolver . class ) ; MergeableResolver resolver = Mockito . mock ( MergeableResolver . class ) ; CompilerData data = new CompilerData ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , true ) ; Packager packager = new Packager ( properties , listener , jar , compressor , jar , mergeManager , pathResolver , resolver , data ) ; packager . setInfo ( new Info ( ) ) ; return packager ; } } </s>
|
<s> package com . izforge . izpack . compiler . packager . impl ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertTrue ; import static org . junit . Assert . fail ; import static org . mockito . Matchers . anyString ; import static org . mockito . Matchers . eq ; import static org . mockito . Mockito . mock ; import static org . mockito . Mockito . times ; import static org . mockito . Mockito . verify ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . ObjectInputStream ; import java . io . PrintStream ; import java . util . jar . JarEntry ; import java . util . jar . JarInputStream ; import org . junit . Before ; import org . junit . Test ; import org . mockito . Mockito ; import com . izforge . izpack . api . data . Blockable ; import com . izforge . izpack . api . data . GUIPrefs ; import com . izforge . izpack . api . data . OverrideType ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . compiler . stream . JarOutputStream ; import com . izforge . izpack . data . PackInfo ; import com . izforge . izpack . merge . MergeManager ; public abstract class AbstractPackagerTest { private MergeManager mergeManager ; @ Before public void setUp ( ) { mergeManager = mock ( MergeManager . class ) ; } @ Test public void noSplash ( ) throws IOException { PackagerBase packager = createPackager ( Mockito . mock ( JarOutputStream . class ) , mergeManager ) ; packager . setSplashScreenImage ( null ) ; packager . writeManifest ( ) ; verify ( mergeManager ) . addResourceToMerge ( anyString ( ) , eq ( "<STR_LIT>" ) ) ; } @ Test public void guiPrefsWithSplash ( ) throws IOException { final File splashImage = new File ( "<STR_LIT>" ) ; PackagerBase packager = createPackager ( Mockito . mock ( JarOutputStream . class ) , mergeManager ) ; packager . setGUIPrefs ( new GUIPrefs ( ) ) ; packager . setSplashScreenImage ( splashImage ) ; packager . writeManifest ( ) ; verify ( mergeManager , times ( <NUM_LIT:1> ) ) . addResourceToMerge ( anyString ( ) , eq ( "<STR_LIT>" ) ) ; verify ( mergeManager , times ( <NUM_LIT:1> ) ) . addResourceToMerge ( anyString ( ) , eq ( "<STR_LIT>" ) ) ; } @ Test public void noGuiPrefs ( ) throws IOException { PackagerBase packager = createPackager ( Mockito . mock ( JarOutputStream . class ) , mergeManager ) ; packager . writeManifest ( ) ; verify ( mergeManager ) . addResourceToMerge ( anyString ( ) , anyString ( ) ) ; } @ Test public void testSize ( ) throws Exception { File file = createTextFile ( "<STR_LIT>" ) ; long size = <NUM_LIT> ; long fileSize = file . length ( ) ; checkSize ( fileSize , fileSize , <NUM_LIT:0> , file ) ; checkSize ( size , <NUM_LIT:0> , size ) ; checkSize ( size , fileSize , size , file ) ; long tooSmall = fileSize - <NUM_LIT:1> ; checkSize ( fileSize , fileSize , tooSmall , file ) ; assertTrue ( file . delete ( ) ) ; } protected abstract PackagerBase createPackager ( JarOutputStream jar , MergeManager mergeManager ) ; private void checkSize ( long expectedSize , long expectedFileSize , long size , File ... files ) throws Exception { File jar = File . createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) ; JarOutputStream output = new JarOutputStream ( new FileOutputStream ( jar ) ) ; output . setPreventClose ( true ) ; PackagerBase packager = createPackager ( output , mergeManager ) ; PackInfo packInfo = new PackInfo ( "<STR_LIT>" , "<STR_LIT>" , null , true , false , null , true , size ) ; long fileSize = <NUM_LIT:0> ; for ( File file : files ) { packInfo . addFile ( file . getParentFile ( ) , file , "<STR_LIT>" + file . getName ( ) , null , OverrideType . OVERRIDE_TRUE , null , Blockable . BLOCKABLE_NONE , null , null ) ; fileSize += file . length ( ) ; } packager . addPack ( packInfo ) ; packager . createInstaller ( ) ; InputStream jarEntry = getJarEntry ( "<STR_LIT>" , jar ) ; ObjectInputStream packStream = new ObjectInputStream ( jarEntry ) ; int packs = packStream . readInt ( ) ; assertEquals ( <NUM_LIT:1> , packs ) ; Pack pack = ( Pack ) packStream . readObject ( ) ; assertEquals ( expectedSize , pack . getSize ( ) ) ; assertEquals ( expectedFileSize , fileSize ) ; jarEntry . close ( ) ; packStream . close ( ) ; assertTrue ( jar . delete ( ) ) ; } private InputStream getJarEntry ( String name , File jar ) throws IOException { JarInputStream input = new JarInputStream ( new FileInputStream ( jar ) ) ; JarEntry entry ; while ( ( entry = input . getNextJarEntry ( ) ) != null ) { if ( entry . getName ( ) . equals ( name ) ) { return input ; } } fail ( "<STR_LIT>" + name ) ; return null ; } private File createTextFile ( String text ) throws IOException { File file = File . createTempFile ( "<STR_LIT:data>" , "<STR_LIT>" ) ; PrintStream printStream = new PrintStream ( file ) ; printStream . print ( text ) ; printStream . close ( ) ; return file ; } } </s>
|
<s> package com . izforge . izpack . compiler ; import static org . hamcrest . MatcherAssert . assertThat ; import java . io . InputStream ; import java . util . List ; import java . util . jar . JarFile ; import java . util . zip . ZipEntry ; import java . util . zip . ZipFile ; import org . apache . commons . io . IOUtils ; import org . hamcrest . collection . IsCollectionContaining ; import org . hamcrest . core . IsNot ; import org . junit . Test ; import org . junit . runner . RunWith ; import com . izforge . izpack . compiler . container . TestCompilerContainer ; import com . izforge . izpack . core . container . AbstractContainer ; 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 ; @ RunWith ( PicoRunner . class ) @ Container ( TestCompilerContainer . class ) public class CompilerConfigSamplesTest { private JarFile jar ; private CompilerConfig compilerConfig ; private AbstractContainer testContainer ; public CompilerConfigSamplesTest ( TestCompilerContainer container , CompilerConfig compilerConfig ) { this . testContainer = container ; this . compilerConfig = compilerConfig ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void installerShouldContainInstallerClassResourcesAndImages ( ) throws Exception { compilerConfig . executeCompiler ( ) ; jar = testContainer . getComponent ( JarFile . class ) ; assertThat ( ( ZipFile ) jar , ZipMatcher . isZipContainingFiles ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void installerShouldMergeProcessPanelCorrectly ( ) throws Exception { compilerConfig . executeCompiler ( ) ; jar = testContainer . getComponent ( JarFile . class ) ; assertThat ( ( ZipFile ) jar , ZipMatcher . isZipMatching ( IsNot . not ( IsCollectionContaining . hasItems ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ) ) ; } @ Test @ InstallFile ( "<STR_LIT>" ) public void installerShouldConfigureSplashScreenCorrectly ( ) throws Exception { compilerConfig . executeCompiler ( ) ; jar = testContainer . getComponent ( JarFile . class ) ; assertThat ( ( ZipFile ) jar , ZipMatcher . isZipMatching ( IsCollectionContaining . hasItems ( "<STR_LIT>" ) ) ) ; ZipEntry entry = jar . getEntry ( "<STR_LIT>" ) ; InputStream content = jar . getInputStream ( entry ) ; try { List < String > list = IOUtils . readLines ( content ) ; assertThat ( list , IsCollectionContaining . hasItem ( "<STR_LIT>" ) ) ; } finally { content . close ( ) ; } } } </s>
|
<s> package com . izforge . izpack . compiler . helper ; import static org . hamcrest . MatcherAssert . assertThat ; import static org . hamcrest . core . Is . is ; import org . junit . Test ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . exception . CompilerException ; public class XmlCompilerHelperTest { private XmlCompilerHelper helper = new XmlCompilerHelper ( new AssertionHelper ( "<STR_LIT>" ) ) ; @ Test public void testRequireURLContent ( ) throws CompilerException { IXMLElement webDir = new XMLElementImpl ( "<STR_LIT>" ) ; webDir . setContent ( "<STR_LIT>" ) ; assertThat ( helper . requireURLContent ( webDir ) . toString ( ) , is ( "<STR_LIT>" ) ) ; webDir . setContent ( "<STR_LIT>" ) ; assertThat ( helper . requireURLContent ( webDir ) . toString ( ) , is ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . compiler . helper ; import static org . hamcrest . MatcherAssert . assertThat ; import static org . hamcrest . core . Is . is ; import org . junit . Test ; public class CompilerHelperTest { private CompilerHelper helper = new CompilerHelper ( ) ; @ Test public void testResolveJarPath ( ) throws Exception { assertThat ( helper . resolveCustomActionsJarPath ( "<STR_LIT>" ) , is ( "<STR_LIT>" ) ) ; } @ Test public void testConvertCamelToHyphen ( ) throws Exception { assertThat ( helper . convertNameToDashSeparated ( "<STR_LIT>" ) . toString ( ) , is ( "<STR_LIT>" ) ) ; assertThat ( helper . convertNameToDashSeparated ( "<STR_LIT>" ) . toString ( ) , is ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . compiler . bootstrap ; import static org . hamcrest . MatcherAssert . assertThat ; import java . util . Properties ; import org . hamcrest . core . IsNull ; import org . junit . Test ; import org . junit . runner . RunWith ; import com . izforge . izpack . compiler . Compiler ; import com . izforge . izpack . compiler . CompilerConfig ; import com . izforge . izpack . compiler . container . CompilerContainer ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . stream . JarOutputStream ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . junit . PicoRunner ; @ RunWith ( PicoRunner . class ) @ Container ( CompilerContainer . class ) public class CompilerLauncherTest { private CompilerContainer compilerContainer ; public CompilerLauncherTest ( CompilerContainer compilerContainer ) { this . compilerContainer = compilerContainer ; } @ Test public void testPropertiesBinding ( ) throws Exception { Properties properties = compilerContainer . getComponent ( Properties . class ) ; assertThat ( properties , IsNull . notNullValue ( ) ) ; } @ Test public void testJarOutputStream ( ) throws Exception { compilerContainer . addComponent ( CompilerData . class , new CompilerData ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , false ) ) ; JarOutputStream jarOutputStream = compilerContainer . getComponent ( JarOutputStream . class ) ; assertThat ( jarOutputStream , IsNull . notNullValue ( ) ) ; } @ Test public void testCompilerBinding ( ) throws Exception { compilerContainer . processCompileDataFromArgs ( new String [ ] { "<STR_LIT>" } ) ; Compiler compiler = compilerContainer . getComponent ( Compiler . class ) ; assertThat ( compiler , IsNull . notNullValue ( ) ) ; } @ Test public void testCompilerDataBinding ( ) { compilerContainer . addComponent ( CompilerData . class , new CompilerData ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , false ) ) ; CompilerData data = compilerContainer . getComponent ( CompilerData . class ) ; assertThat ( data , IsNull . notNullValue ( ) ) ; } @ Test public void testCompilerConfigBinding ( ) throws Exception { compilerContainer . processCompileDataFromArgs ( new String [ ] { "<STR_LIT>" } ) ; CompilerData data = compilerContainer . getComponent ( CompilerData . class ) ; assertThat ( data , IsNull . notNullValue ( ) ) ; CompilerConfig compiler = compilerContainer . getComponent ( CompilerConfig . class ) ; assertThat ( compiler , IsNull . notNullValue ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . compiler ; import java . util . ArrayList ; import java . util . List ; import java . util . Map ; import java . util . Properties ; import org . junit . Before ; import org . junit . Test ; import org . mockito . Mockito ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLParser ; import com . izforge . izpack . api . data . DynamicVariable ; import com . izforge . izpack . api . data . Value ; import com . izforge . izpack . api . exception . CompilerException ; import com . izforge . izpack . api . factory . ObjectFactory ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . data . PropertyManager ; import com . izforge . izpack . compiler . helper . AssertionHelper ; import com . izforge . izpack . compiler . helper . XmlCompilerHelper ; import com . izforge . izpack . compiler . util . CompilerClassLoader ; import com . izforge . izpack . compiler . merge . CompilerPathResolver ; import com . izforge . izpack . compiler . packager . IPackager ; import com . izforge . izpack . compiler . resource . ResourceFinder ; import com . izforge . izpack . compiler . util . DefaultClassNameMapper ; import com . izforge . izpack . core . data . DynamicVariableImpl ; import com . izforge . izpack . core . variable . PlainValue ; import com . izforge . izpack . merge . MergeManager ; import com . izforge . izpack . util . PlatformModelMatcher ; import com . izforge . izpack . util . Platforms ; public class CompilerConfigMockedTest { private Map < String , List < DynamicVariable > > mapStringListDyn ; private XMLParser xmlParser = new XMLParser ( ) ; private CompilerConfig compilerConfig ; private IPackager packager ; @ Before public void setUp ( ) { mapStringListDyn = Mockito . mock ( Map . class ) ; packager = Mockito . mock ( IPackager . class ) ; compilerConfig = new TestCompilerConfig ( packager ) ; } @ Test public void testAddTwoVariables ( ) throws Exception { Mockito . when ( mapStringListDyn . containsKey ( "<STR_LIT>" ) ) . thenReturn ( false ) ; Mockito . when ( packager . getDynamicVariables ( ) ) . thenReturn ( mapStringListDyn ) ; Properties variable = new Properties ( ) ; Mockito . when ( packager . getVariables ( ) ) . thenReturn ( variable ) ; IXMLElement element = xmlParser . parse ( "<STR_LIT>" ) ; compilerConfig . addDynamicVariables ( element ) ; element = xmlParser . parse ( "<STR_LIT>" ) ; compilerConfig . addVariables ( element ) ; verifyCallToMap ( mapStringListDyn , "<STR_LIT>" , new PlainValue ( "<STR_LIT>" ) ) ; } @ Test public void testAddDynamicVariable ( ) throws CompilerException { Mockito . when ( mapStringListDyn . containsKey ( "<STR_LIT>" ) ) . thenReturn ( false ) ; Mockito . when ( packager . getDynamicVariables ( ) ) . thenReturn ( mapStringListDyn ) ; IXMLElement element = xmlParser . parse ( "<STR_LIT>" ) ; compilerConfig . addDynamicVariables ( element ) ; verifyCallToMap ( mapStringListDyn , "<STR_LIT>" , new PlainValue ( "<STR_LIT>" ) ) ; } private void verifyCallToMap ( Map < String , List < DynamicVariable > > mapStringListDyn , String name , Value value ) { DynamicVariable dynamicVariable = new DynamicVariableImpl ( ) ; dynamicVariable . setName ( name ) ; dynamicVariable . setValue ( value ) ; ArrayList < DynamicVariable > list = new ArrayList < DynamicVariable > ( ) ; list . add ( dynamicVariable ) ; Mockito . verify ( mapStringListDyn ) . put ( name , list ) ; } @ Test public void compilerShouldAddVariable ( ) throws Exception { IXMLElement xmlData = xmlParser . parse ( "<STR_LIT>" ) ; Properties variable = Mockito . mock ( Properties . class ) ; Mockito . when ( packager . getVariables ( ) ) . thenReturn ( variable ) ; compilerConfig . addVariables ( xmlData ) ; Mockito . verify ( variable ) . setProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; } @ Test public void shouldAddDynamicVariable ( ) throws Exception { IXMLElement xmlData = xmlParser . parse ( "<STR_LIT>" ) ; Map variable = Mockito . mock ( Map . class ) ; Mockito . when ( variable . containsKey ( "<STR_LIT>" ) ) . thenReturn ( false ) ; Mockito . when ( packager . getDynamicVariables ( ) ) . thenReturn ( variable ) ; compilerConfig . addDynamicVariables ( xmlData ) ; new ArrayList ( ) ; DynamicVariable dynamicVariable = new DynamicVariableImpl ( ) ; dynamicVariable . setName ( "<STR_LIT>" ) ; dynamicVariable . setValue ( new PlainValue ( "<STR_LIT>" ) ) ; ArrayList < DynamicVariable > list = new ArrayList < DynamicVariable > ( ) ; list . add ( dynamicVariable ) ; Mockito . verify ( variable ) . put ( "<STR_LIT>" , list ) ; } private class TestCompilerConfig extends CompilerConfig { public TestCompilerConfig ( IPackager packager ) { super ( Mockito . mock ( CompilerData . class ) , Mockito . mock ( VariableSubstitutor . class ) , Mockito . mock ( Compiler . class ) , new XmlCompilerHelper ( Mockito . mock ( AssertionHelper . class ) ) , Mockito . mock ( PropertyManager . class ) , Mockito . mock ( MergeManager . class ) , Mockito . mock ( AssertionHelper . class ) , Mockito . mock ( RulesEngine . class ) , Mockito . mock ( CompilerPathResolver . class ) , Mockito . mock ( ResourceFinder . class ) , Mockito . mock ( ObjectFactory . class ) , new PlatformModelMatcher ( new Platforms ( ) , Platforms . WINDOWS ) , new CompilerClassLoader ( new DefaultClassNameMapper ( ) ) ) ; setPackager ( packager ) ; } } } </s>
|
<s> package com . izforge . izpack . compiler . merge . resolve ; import static org . hamcrest . MatcherAssert . assertThat ; import org . hamcrest . core . IsNot ; import org . junit . Test ; import org . junit . runner . RunWith ; import com . izforge . izpack . compiler . container . TestResolveContainer ; import com . izforge . izpack . compiler . merge . CompilerPathResolver ; import com . izforge . izpack . compiler . merge . PanelMerge ; import com . izforge . izpack . matcher . MergeMatcher ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . junit . PicoRunner ; @ RunWith ( PicoRunner . class ) @ Container ( TestResolveContainer . class ) public class PathResolverRealPanelTest { private CompilerPathResolver pathResolver ; public PathResolverRealPanelTest ( CompilerPathResolver pathResolver ) { this . pathResolver = pathResolver ; } @ Test public void testAddProcessPanel ( ) throws Exception { PanelMerge panelMerge = pathResolver . getPanelMerge ( "<STR_LIT>" ) ; assertThat ( panelMerge , IsNot . not ( MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ) ; assertThat ( panelMerge , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . compiler . merge . resolve ; import static org . hamcrest . MatcherAssert . assertThat ; import java . io . File ; import java . util . zip . ZipFile ; import org . hamcrest . core . Is ; import org . junit . Test ; import org . junit . runner . RunWith ; import com . izforge . izpack . api . merge . Mergeable ; import com . izforge . izpack . compiler . container . TestResolveContainer ; import com . izforge . izpack . compiler . merge . CompilerPathResolver ; import com . izforge . izpack . compiler . merge . PanelMerge ; import com . izforge . izpack . matcher . DuplicateMatcher ; import com . izforge . izpack . matcher . MergeMatcher ; import com . izforge . izpack . matcher . ZipMatcher ; import com . izforge . izpack . panels . hello . HelloPanel ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . MergeUtils ; import com . izforge . izpack . test . junit . PicoRunner ; @ RunWith ( PicoRunner . class ) @ Container ( TestResolveContainer . class ) public class PanelMergeTest { private PanelMerge panelMerge ; private CompilerPathResolver pathResolver ; public PanelMergeTest ( CompilerPathResolver pathResolver ) { this . pathResolver = pathResolver ; } @ Test public void testResolvePanelNameFromFile ( ) throws Exception { panelMerge = pathResolver . getPanelMerge ( "<STR_LIT>" ) ; assertThat ( panelMerge , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } @ Test public void testResolvePanelWithCompleteNameFromFile ( ) throws Exception { panelMerge = pathResolver . getPanelMerge ( "<STR_LIT>" ) ; assertThat ( panelMerge , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } @ Test public void testResolvePanelWithDependencies ( ) throws Exception { panelMerge = pathResolver . getPanelMerge ( "<STR_LIT>" ) ; assertThat ( panelMerge , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void testGetClassNameFromPanelMergeWithFullClassGiven ( ) throws Exception { panelMerge = pathResolver . getPanelMerge ( "<STR_LIT>" ) ; assertThat ( panelMerge . getPanelClass ( ) . getName ( ) , Is . is ( "<STR_LIT>" ) ) ; } @ Test public void testGetClassNameFromPanelMergeWithOnlyPanelName ( ) throws Exception { panelMerge = pathResolver . getPanelMerge ( "<STR_LIT>" ) ; assertThat ( panelMerge . getPanelClass ( ) . getName ( ) , Is . is ( HelloPanel . class . getName ( ) ) ) ; } @ Test public void testMergeDuplicatePanel ( ) throws Exception { Mergeable mergeable = pathResolver . getPanelMerge ( "<STR_LIT>" ) ; File tempFile = MergeUtils . doDoubleMerge ( mergeable ) ; ZipFile tempZipFile = new ZipFile ( tempFile ) ; assertThat ( tempZipFile , ZipMatcher . isZipMatching ( DuplicateMatcher . isEntryUnique ( "<STR_LIT>" ) ) ) ; } @ Test public void testMergePanelWithDependenciesInAnotherPackage ( ) { PanelMerge merge1 = pathResolver . getPanelMerge ( "<STR_LIT>" ) ; assertThat ( merge1 , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" , "<STR_LIT>" ) ) ; PanelMerge merge2 = pathResolver . getPanelMerge ( "<STR_LIT>" ) ; assertThat ( merge2 , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . panels . depend ; public class DependedClass { } </s>
|
<s> package com . izforge . izpack . panels . hello ; import com . izforge . izpack . api . data . Panel ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . gui . InstallerFrame ; import com . izforge . izpack . installer . gui . IzPanel ; public class HelloPanelTestClass extends IzPanel { public HelloPanelTestClass ( Panel panel , InstallerFrame parent , GUIInstallData installData , Resources resources ) { super ( panel , parent , installData , resources ) ; } } </s>
|
<s> package com . izforge . izpack . panels . hello ; import com . izforge . izpack . api . data . Panel ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . gui . InstallerFrame ; import com . izforge . izpack . installer . gui . IzPanel ; public class HelloPanelTestWithDependenciesClass extends IzPanel { public HelloPanelTestWithDependenciesClass ( Panel panel , InstallerFrame parent , GUIInstallData installData , Resources resources ) { super ( panel , parent , installData , resources ) ; } } </s>
|
<s> package com . izforge . izpack . compiler ; import java . io . BufferedInputStream ; import java . io . BufferedOutputStream ; import java . io . ByteArrayInputStream ; import java . io . ByteArrayOutputStream ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . OutputStreamWriter ; import java . net . URL ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Enumeration ; import java . util . HashMap ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . Properties ; import java . util . Set ; import java . util . StringTokenizer ; import java . util . TreeMap ; import java . util . Vector ; import java . util . logging . Level ; import java . util . logging . Logger ; import java . util . zip . ZipEntry ; import java . util . zip . ZipFile ; import java . util . zip . ZipInputStream ; import org . apache . commons . lang . StringUtils ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . IXMLParser ; import com . izforge . izpack . api . adaptator . IXMLWriter ; import com . izforge . izpack . api . adaptator . impl . XMLParser ; import com . izforge . izpack . api . adaptator . impl . XMLWriter ; import com . izforge . izpack . api . data . Blockable ; import com . izforge . izpack . api . data . DynamicInstallerRequirementValidator ; import com . izforge . izpack . api . data . DynamicVariable ; import com . izforge . izpack . api . data . GUIPrefs ; import com . izforge . izpack . api . data . Info ; import com . izforge . izpack . api . data . Info . TempDir ; import com . izforge . izpack . api . data . InstallerRequirement ; import com . izforge . izpack . api . data . LookAndFeels ; import com . izforge . izpack . api . data . OverrideType ; import com . izforge . izpack . api . data . Panel ; import com . izforge . izpack . api . data . PanelActionConfiguration ; import com . izforge . izpack . api . data . binding . Help ; import com . izforge . izpack . api . data . binding . OsModel ; import com . izforge . izpack . api . data . binding . Stage ; import com . izforge . izpack . api . exception . CompilerException ; import com . izforge . izpack . api . factory . ObjectFactory ; import com . izforge . izpack . api . installer . DataValidator ; import com . izforge . izpack . api . installer . DataValidator . Status ; import com . izforge . izpack . api . merge . Mergeable ; import com . izforge . izpack . api . rules . Condition ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . api . substitutor . SubstitutionType ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . data . PropertyManager ; import com . izforge . izpack . compiler . helper . AssertionHelper ; import com . izforge . izpack . compiler . helper . TargetFileSet ; import com . izforge . izpack . compiler . helper . XmlCompilerHelper ; import com . izforge . izpack . compiler . listener . CompilerListener ; import com . izforge . izpack . compiler . merge . CompilerPathResolver ; import com . izforge . izpack . compiler . packager . IPackager ; import com . izforge . izpack . compiler . resource . ResourceFinder ; import com . izforge . izpack . compiler . util . CompilerClassLoader ; import com . izforge . izpack . core . data . DynamicInstallerRequirementValidatorImpl ; import com . izforge . izpack . core . data . DynamicVariableImpl ; import com . izforge . izpack . core . variable . ConfigFileValue ; import com . izforge . izpack . core . variable . EnvironmentValue ; import com . izforge . izpack . core . variable . ExecValue ; import com . izforge . izpack . core . variable . JarEntryConfigValue ; import com . izforge . izpack . core . variable . PlainConfigFileValue ; import com . izforge . izpack . core . variable . PlainValue ; import com . izforge . izpack . core . variable . RegistryValue ; import com . izforge . izpack . core . variable . ZipEntryConfigFileValue ; import com . izforge . izpack . core . variable . filters . LocationFilter ; import com . izforge . izpack . core . variable . filters . RegularExpressionFilter ; import com . izforge . izpack . data . CustomData ; import com . izforge . izpack . data . ExecutableFile ; import com . izforge . izpack . data . PackInfo ; import com . izforge . izpack . data . PanelAction ; import com . izforge . izpack . data . ParsableFile ; import com . izforge . izpack . data . UpdateCheck ; import com . izforge . izpack . installer . gui . IzPanel ; import com . izforge . izpack . installer . unpacker . IUnpacker ; import com . izforge . izpack . merge . MergeManager ; import com . izforge . izpack . panels . extendedinstall . ExtendedInstallPanel ; import com . izforge . izpack . panels . install . InstallPanel ; import com . izforge . izpack . panels . treepacks . PackValidator ; import com . izforge . izpack . util . FileUtil ; import com . izforge . izpack . util . IoHelper ; import com . izforge . izpack . util . OsConstraintHelper ; import com . izforge . izpack . util . PlatformModelMatcher ; import com . izforge . izpack . util . file . DirectoryScanner ; import com . izforge . izpack . util . file . FileUtils ; public class CompilerConfig extends Thread { private static final Logger logger = Logger . getLogger ( CompilerConfig . class . getName ( ) ) ; private static final boolean YES = Boolean . TRUE ; private static final Boolean NO = Boolean . FALSE ; private Compiler compiler ; private CompilerData compilerData ; private List < CompilerListener > compilerListeners = new ArrayList < CompilerListener > ( ) ; private Map < String , List < URL > > packsLangUrlMap = new HashMap < String , List < URL > > ( ) ; private String unpackerClassname = "<STR_LIT>" ; private String packagerClassname = "<STR_LIT>" ; private CompilerPathResolver pathResolver ; private VariableSubstitutor variableSubstitutor ; private XmlCompilerHelper xmlCompilerHelper ; private PropertyManager propertyManager ; private IPackager packager ; private ResourceFinder resourceFinder ; private MergeManager mergeManager ; private AssertionHelper assertionHelper ; private RulesEngine rules ; private final ObjectFactory factory ; private final PlatformModelMatcher constraints ; private final CompilerClassLoader classLoader ; private static final String TEMP_DIR_ELEMENT_NAME = "<STR_LIT>" ; private static final String TEMP_DIR_PREFIX_ATTRIBUTE = "<STR_LIT>" ; private static final String DEFAULT_TEMP_DIR_PREFIX = "<STR_LIT>" ; private static final String TEMP_DIR_SUFFIX_ATTRIBUTE = "<STR_LIT>" ; private static final String DEFAULT_TEMP_DIR_SUFFIX = "<STR_LIT>" ; private static final String TEMP_DIR_VARIABLE_NAME_ATTRIBUTE = "<STR_LIT>" ; private static final String TEMP_DIR_DEFAULT_PROPERTY_NAME = "<STR_LIT>" ; private final static String HELP_TAG = "<STR_LIT>" ; private static final String ISO3_ATTRIBUTE = "<STR_LIT>" ; private final static String SRC_ATTRIBUTE = "<STR_LIT:src>" ; public CompilerConfig ( CompilerData compilerData , VariableSubstitutor variableSubstitutor , Compiler compiler , XmlCompilerHelper xmlCompilerHelper , PropertyManager propertyManager , MergeManager mergeManager , AssertionHelper assertionHelper , RulesEngine rules , CompilerPathResolver pathResolver , ResourceFinder resourceFinder , ObjectFactory factory , PlatformModelMatcher constraints , CompilerClassLoader classLoader ) { this . assertionHelper = assertionHelper ; this . rules = rules ; this . compilerData = compilerData ; this . variableSubstitutor = variableSubstitutor ; this . compiler = compiler ; this . xmlCompilerHelper = xmlCompilerHelper ; this . propertyManager = propertyManager ; this . mergeManager = mergeManager ; this . pathResolver = pathResolver ; this . resourceFinder = resourceFinder ; this . factory = factory ; this . constraints = constraints ; this . classLoader = classLoader ; } @ Override public void run ( ) { try { executeCompiler ( ) ; } catch ( CompilerException ce ) { logger . severe ( ce . getMessage ( ) ) ; } catch ( Exception e ) { logger . log ( Level . SEVERE , e . getMessage ( ) , e ) ; } } public void executeCompiler ( ) throws Exception { File base = new File ( compilerData . getBasedir ( ) ) . getAbsoluteFile ( ) ; if ( ! base . canRead ( ) || ! base . isDirectory ( ) ) { throw new CompilerException ( "<STR_LIT>" + base ) ; } propertyManager . setProperty ( "<STR_LIT>" , base . toString ( ) ) ; IXMLElement data = resourceFinder . getXMLTree ( ) ; addCompilerListeners ( data ) ; loadPackagingInformation ( data ) ; substituteProperties ( data ) ; addVariables ( data ) ; addDynamicVariables ( data ) ; addDynamicInstallerRequirement ( data ) ; addConditions ( data ) ; addInfo ( data ) ; addGUIPrefs ( data ) ; addLangpacks ( data ) ; addResources ( data ) ; addNativeLibraries ( data ) ; addJars ( data ) ; addPanelJars ( data ) ; addListenerJars ( data ) ; addPanels ( data ) ; addListeners ( data ) ; addPacks ( data ) ; addInstallerRequirement ( data ) ; mergePacksLangFiles ( ) ; compiler . createInstaller ( ) ; } protected void setPackager ( IPackager packager ) { this . packager = packager ; } private void addInstallerRequirement ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement root = data . getFirstChildNamed ( "<STR_LIT>" ) ; List < InstallerRequirement > installerrequirements = new ArrayList < InstallerRequirement > ( ) ; if ( root != null ) { List < IXMLElement > installerrequirementsels = root . getChildrenNamed ( "<STR_LIT>" ) ; for ( IXMLElement installerrequirement : installerrequirementsels ) { InstallerRequirement basicInstallerCondition = new InstallerRequirement ( ) ; String condition = installerrequirement . getAttribute ( "<STR_LIT>" ) ; basicInstallerCondition . setCondition ( condition ) ; String message = installerrequirement . getAttribute ( "<STR_LIT:message>" ) ; basicInstallerCondition . setMessage ( message ) ; installerrequirements . add ( basicInstallerCondition ) ; } } packager . addInstallerRequirements ( installerrequirements ) ; notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } private void loadPackagingInformation ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement root = data . getFirstChildNamed ( "<STR_LIT>" ) ; IXMLElement packagerElement = null ; if ( root != null ) { packagerElement = root . getFirstChildNamed ( "<STR_LIT>" ) ; if ( packagerElement != null ) { Class < IPackager > packagerClass = classLoader . loadClass ( xmlCompilerHelper . requireAttribute ( packagerElement , "<STR_LIT:class>" ) , IPackager . class ) ; packagerClassname = packagerClass . getName ( ) ; } IXMLElement unpacker = root . getFirstChildNamed ( "<STR_LIT>" ) ; if ( unpacker != null ) { Class < IUnpacker > unpackerClass = classLoader . loadClass ( xmlCompilerHelper . requireAttribute ( unpacker , "<STR_LIT:class>" ) , IUnpacker . class ) ; unpackerClassname = unpackerClass . getName ( ) ; } } packager = factory . create ( packagerClassname , IPackager . class ) ; if ( packagerElement != null ) { IXMLElement options = packagerElement . getFirstChildNamed ( "<STR_LIT>" ) ; if ( options != null ) { packager . addConfigurationInformation ( options ) ; } } compiler . setPackager ( packager ) ; propertyManager . addProperty ( "<STR_LIT>" , unpackerClassname ) ; notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } public boolean wasSuccessful ( ) { return compiler . wasSuccessful ( ) ; } protected void addGUIPrefs ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement guiPrefsElement = data . getFirstChildNamed ( "<STR_LIT>" ) ; GUIPrefs prefs = new GUIPrefs ( ) ; if ( guiPrefsElement != null ) { prefs . resizable = xmlCompilerHelper . requireYesNoAttribute ( guiPrefsElement , "<STR_LIT>" ) ; prefs . width = xmlCompilerHelper . requireIntAttribute ( guiPrefsElement , "<STR_LIT>" ) ; prefs . height = xmlCompilerHelper . requireIntAttribute ( guiPrefsElement , "<STR_LIT>" ) ; for ( IXMLElement lafNode : guiPrefsElement . getChildrenNamed ( "<STR_LIT>" ) ) { String lafName = xmlCompilerHelper . requireAttribute ( lafNode , "<STR_LIT:name>" ) ; xmlCompilerHelper . requireChildNamed ( lafNode , "<STR_LIT>" ) ; for ( IXMLElement osNode : lafNode . getChildrenNamed ( "<STR_LIT>" ) ) { String osName = xmlCompilerHelper . requireAttribute ( osNode , "<STR_LIT>" ) ; prefs . lookAndFeelMapping . put ( osName , lafName ) ; } Map < String , String > params = new TreeMap < String , String > ( ) ; for ( IXMLElement parameterNode : lafNode . getChildrenNamed ( "<STR_LIT>" ) ) { String name = xmlCompilerHelper . requireAttribute ( parameterNode , "<STR_LIT:name>" ) ; String value = xmlCompilerHelper . requireAttribute ( parameterNode , "<STR_LIT:value>" ) ; params . put ( name , value ) ; } prefs . lookAndFeelParams . put ( lafName , params ) ; } for ( IXMLElement ixmlElement : guiPrefsElement . getChildrenNamed ( "<STR_LIT>" ) ) { String key = xmlCompilerHelper . requireAttribute ( ixmlElement , "<STR_LIT:key>" ) ; String value = xmlCompilerHelper . requireAttribute ( ixmlElement , "<STR_LIT:value>" ) ; prefs . modifier . put ( key , value ) ; } for ( String s : prefs . lookAndFeelMapping . keySet ( ) ) { String lafName = prefs . lookAndFeelMapping . get ( s ) ; LookAndFeels feels = LookAndFeels . lookup ( lafName ) ; List < Mergeable > mergeableList = Collections . emptyList ( ) ; switch ( feels ) { case KUNSTSTOFF : mergeableList = pathResolver . getMergeableFromPackageName ( "<STR_LIT>" ) ; break ; case LIQUID : mergeableList = pathResolver . getMergeableFromPackageName ( "<STR_LIT>" ) ; break ; case LOOKS : mergeableList = pathResolver . getMergeableFromPackageName ( "<STR_LIT>" ) ; break ; case SUBSTANCE : mergeableList = pathResolver . getMergeableJarFromPackageName ( "<STR_LIT>" ) ; mergeableList . addAll ( pathResolver . getMergeableFromPackageName ( "<STR_LIT>" ) ) ; break ; case NIMBUS : break ; default : assertionHelper . parseError ( guiPrefsElement , "<STR_LIT>" + lafName ) ; } for ( Mergeable mergeable : mergeableList ) { mergeManager . addResourceToMerge ( mergeable ) ; } } IXMLElement splashNode = guiPrefsElement . getFirstChildNamed ( "<STR_LIT>" ) ; if ( splashNode != null ) { File file = org . apache . commons . io . FileUtils . toFile ( resourceFinder . findProjectResource ( splashNode . getContent ( ) , "<STR_LIT>" , splashNode ) ) ; packager . setSplashScreenImage ( file ) ; } } packager . setGUIPrefs ( prefs ) ; notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } protected void addJars ( IXMLElement data ) throws IOException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; for ( IXMLElement ixmlElement : data . getChildrenNamed ( "<STR_LIT>" ) ) { String src = xmlCompilerHelper . requireAttribute ( ixmlElement , "<STR_LIT:src>" ) ; String stage = ixmlElement . getAttribute ( "<STR_LIT>" ) ; URL url = resourceFinder . findProjectResource ( src , "<STR_LIT>" , ixmlElement ) ; boolean uninstaller = "<STR_LIT>" . equalsIgnoreCase ( stage ) || "<STR_LIT>" . equalsIgnoreCase ( stage ) ; compiler . addJar ( url , uninstaller ) ; } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } protected void addPanelJars ( IXMLElement data ) throws IOException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement panels = xmlCompilerHelper . requireChildNamed ( data , "<STR_LIT>" ) ; for ( IXMLElement panel : panels . getChildrenNamed ( "<STR_LIT>" ) ) { URL url = getPanelJarURL ( panel ) ; if ( url != null ) { compiler . addJar ( url , false ) ; } } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } private URL getPanelJarURL ( IXMLElement panel ) throws CompilerException { return getResourceURL ( panel , "<STR_LIT>" , "<STR_LIT>" ) ; } private URL getListenerJarURL ( IXMLElement listener ) throws CompilerException { return getResourceURL ( listener , "<STR_LIT>" , "<STR_LIT>" ) ; } private URL getResourceURL ( IXMLElement element , String attribute , String description ) throws CompilerException { String value = element . getAttribute ( attribute ) ; if ( ! StringUtils . isEmpty ( value ) ) { return resourceFinder . findIzPackResource ( value , description , element , false ) ; } return null ; } protected void addListenerJars ( IXMLElement data ) throws IOException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement listeners = data . getFirstChildNamed ( "<STR_LIT>" ) ; if ( listeners != null ) { for ( IXMLElement listener : listeners . getChildrenNamed ( "<STR_LIT>" ) ) { Stage stage = Stage . valueOf ( xmlCompilerHelper . requireAttribute ( listener , "<STR_LIT>" ) ) ; if ( Stage . isInInstaller ( stage ) ) { URL url = getListenerJarURL ( listener ) ; if ( url != null ) { compiler . addJar ( url , stage == Stage . uninstall ) ; } } } } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } protected void addNativeLibraries ( IXMLElement data ) throws Exception { boolean needAddOns = false ; notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement nativesElement = data . getFirstChildNamed ( "<STR_LIT>" ) ; if ( nativesElement == null ) { return ; } for ( IXMLElement ixmlElement : nativesElement . getChildrenNamed ( "<STR_LIT>" ) ) { String type = xmlCompilerHelper . requireAttribute ( ixmlElement , "<STR_LIT:type>" ) ; String name = xmlCompilerHelper . requireAttribute ( ixmlElement , "<STR_LIT:name>" ) ; String path = ixmlElement . getAttribute ( "<STR_LIT:src>" ) ; if ( path == null ) { path = "<STR_LIT>" + type + "<STR_LIT:/>" + name ; } String destination = "<STR_LIT>" + name ; mergeManager . addResourceToMerge ( path , destination ) ; String stage = ixmlElement . getAttribute ( "<STR_LIT>" ) ; List < OsModel > constraints = OsConstraintHelper . getOsList ( ixmlElement ) ; if ( "<STR_LIT>" . equalsIgnoreCase ( stage ) || "<STR_LIT>" . equalsIgnoreCase ( stage ) ) { List < String > contents = new ArrayList < String > ( ) ; contents . add ( destination ) ; CustomData customData = new CustomData ( null , contents , constraints , CustomData . UNINSTALLER_LIB ) ; packager . addNativeUninstallerLibrary ( customData ) ; needAddOns = true ; } } if ( needAddOns ) { IXMLElement root = xmlCompilerHelper . requireChildNamed ( data , "<STR_LIT>" ) ; IXMLElement uninstallInfo = root . getFirstChildNamed ( "<STR_LIT>" ) ; if ( xmlCompilerHelper . validateYesNoAttribute ( uninstallInfo , "<STR_LIT>" , YES ) ) { } } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } protected void addPacks ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; addPacksSingle ( data ) ; compiler . checkDependencies ( ) ; compiler . checkExcludes ( ) ; notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } private void addPacksSingle ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement root = xmlCompilerHelper . requireChildNamed ( data , "<STR_LIT>" ) ; List < IXMLElement > packElements = root . getChildrenNamed ( "<STR_LIT>" ) ; List < IXMLElement > refPackElements = root . getChildrenNamed ( "<STR_LIT>" ) ; List < IXMLElement > refPackSets = root . getChildrenNamed ( "<STR_LIT>" ) ; if ( packElements . isEmpty ( ) && refPackElements . isEmpty ( ) && refPackSets . isEmpty ( ) ) { assertionHelper . parseError ( root , "<STR_LIT>" ) ; } File baseDir = new File ( compilerData . getBasedir ( ) ) ; for ( IXMLElement packElement : packElements ) { String name = xmlCompilerHelper . requireAttribute ( packElement , "<STR_LIT:name>" ) ; String id = packElement . getAttribute ( "<STR_LIT:id>" ) ; String packImgId = packElement . getAttribute ( "<STR_LIT>" ) ; boolean loose = Boolean . parseBoolean ( packElement . getAttribute ( "<STR_LIT>" , "<STR_LIT:false>" ) ) ; String description = xmlCompilerHelper . requireChildNamed ( packElement , "<STR_LIT:description>" ) . getContent ( ) ; boolean required = xmlCompilerHelper . requireYesNoAttribute ( packElement , "<STR_LIT>" ) ; String group = packElement . getAttribute ( "<STR_LIT>" ) ; String installGroups = packElement . getAttribute ( "<STR_LIT>" ) ; String excludeGroup = packElement . getAttribute ( "<STR_LIT>" ) ; boolean uninstall = "<STR_LIT:yes>" . equalsIgnoreCase ( packElement . getAttribute ( "<STR_LIT>" , "<STR_LIT:yes>" ) ) ; long size = xmlCompilerHelper . getLong ( packElement , "<STR_LIT:size>" , <NUM_LIT:0> ) ; String parent = packElement . getAttribute ( "<STR_LIT>" ) ; boolean hidden = Boolean . parseBoolean ( packElement . getAttribute ( "<STR_LIT>" , "<STR_LIT:false>" ) ) ; String conditionid = packElement . getAttribute ( "<STR_LIT>" ) ; if ( required && excludeGroup != null ) { assertionHelper . parseError ( packElement , "<STR_LIT>" , new Exception ( "<STR_LIT>" ) ) ; } PackInfo pack = new PackInfo ( name , id , description , required , loose , excludeGroup , uninstall , size ) ; pack . setOsConstraints ( OsConstraintHelper . getOsList ( packElement ) ) ; pack . setParent ( parent ) ; pack . setCondition ( conditionid ) ; pack . setHidden ( hidden ) ; if ( excludeGroup == null ) { pack . setPreselected ( xmlCompilerHelper . validateYesNoAttribute ( packElement , "<STR_LIT>" , YES ) ) ; } else { pack . setPreselected ( xmlCompilerHelper . validateYesNoAttribute ( packElement , "<STR_LIT>" , NO ) ) ; } if ( group != null ) { pack . setGroup ( group ) ; } if ( installGroups != null ) { StringTokenizer st = new StringTokenizer ( installGroups , "<STR_LIT:U+002C>" ) ; while ( st . hasMoreTokens ( ) ) { String igroup = st . nextToken ( ) ; pack . addInstallGroup ( igroup ) ; } } if ( packImgId != null ) { pack . setPackImgId ( packImgId ) ; } List < IXMLElement > parsableChildren = packElement . getChildrenNamed ( "<STR_LIT>" ) ; processParsableChildren ( pack , parsableChildren ) ; List < IXMLElement > executableChildren = packElement . getChildrenNamed ( "<STR_LIT>" ) ; processExecutableChildren ( pack , executableChildren ) ; processFileChildren ( baseDir , packElement , pack ) ; processSingleFileChildren ( baseDir , packElement , pack ) ; processFileSetChildren ( baseDir , packElement , pack ) ; processUpdateCheckChildren ( packElement , pack ) ; for ( IXMLElement dependsNode : packElement . getChildrenNamed ( "<STR_LIT>" ) ) { String depName = xmlCompilerHelper . requireAttribute ( dependsNode , "<STR_LIT>" ) ; pack . addDependency ( depName ) ; } for ( IXMLElement validator : packElement . getChildrenNamed ( "<STR_LIT>" ) ) { Class < PackValidator > type = classLoader . loadClass ( xmlCompilerHelper . requireContent ( validator ) , PackValidator . class ) ; pack . addValidator ( type . getName ( ) ) ; } packager . addPack ( pack ) ; } for ( IXMLElement refPackElement : refPackElements ) { String refFileName = xmlCompilerHelper . requireAttribute ( refPackElement , "<STR_LIT:file>" ) ; String selfcontained = refPackElement . getAttribute ( "<STR_LIT>" ) ; boolean isselfcontained = Boolean . valueOf ( selfcontained ) ; IXMLElement refXMLData = this . readRefPackData ( refFileName , isselfcontained ) ; logger . info ( "<STR_LIT>" + refFileName ) ; addPacksSingle ( refXMLData ) ; } for ( IXMLElement refPackSet : refPackSets ) { String dir_attr = xmlCompilerHelper . requireAttribute ( refPackSet , "<STR_LIT>" ) ; File dir = new File ( dir_attr ) ; if ( ! dir . isAbsolute ( ) ) { dir = new File ( compilerData . getBasedir ( ) , dir_attr ) ; } if ( ! dir . isDirectory ( ) ) { assertionHelper . parseError ( refPackSet , "<STR_LIT>" + dir_attr ) ; } String includeString = xmlCompilerHelper . requireAttribute ( refPackSet , "<STR_LIT>" ) ; String [ ] includes = includeString . split ( "<STR_LIT:U+002CU+0020>" ) ; DirectoryScanner ds = new DirectoryScanner ( ) ; ds . setIncludes ( includes ) ; ds . setBasedir ( dir ) ; ds . setCaseSensitive ( true ) ; String [ ] files ; try { ds . scan ( ) ; files = ds . getIncludedFiles ( ) ; for ( String file : files ) { String refFileName = new File ( dir , file ) . toString ( ) ; IXMLElement refXMLData = this . readRefPackData ( refFileName , false ) ; addPacksSingle ( refXMLData ) ; } } catch ( Exception e ) { throw new CompilerException ( e . getMessage ( ) ) ; } } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } private void processUpdateCheckChildren ( IXMLElement packElement , PackInfo pack ) throws CompilerException { for ( IXMLElement updateNode : packElement . getChildrenNamed ( "<STR_LIT>" ) ) { String casesensitive = updateNode . getAttribute ( "<STR_LIT>" ) ; ArrayList < String > includesList = new ArrayList < String > ( ) ; ArrayList < String > excludesList = new ArrayList < String > ( ) ; for ( IXMLElement ixmlElement1 : updateNode . getChildrenNamed ( "<STR_LIT>" ) ) { includesList . add ( xmlCompilerHelper . requireAttribute ( ixmlElement1 , "<STR_LIT:name>" ) ) ; } for ( IXMLElement ixmlElement : updateNode . getChildrenNamed ( "<STR_LIT>" ) ) { excludesList . add ( xmlCompilerHelper . requireAttribute ( ixmlElement , "<STR_LIT:name>" ) ) ; } pack . addUpdateCheck ( new UpdateCheck ( includesList , excludesList , casesensitive ) ) ; } } private void processFileSetChildren ( File baseDir , IXMLElement packElement , PackInfo pack ) throws CompilerException { for ( TargetFileSet fs : readFileSets ( packElement ) ) { try { String [ ] [ ] includedFilesAndDirs = new String [ ] [ ] { fs . getDirectoryScanner ( ) . getIncludedDirectories ( ) , fs . getDirectoryScanner ( ) . getIncludedFiles ( ) } ; for ( String [ ] filesOrDirs : includedFilesAndDirs ) { if ( filesOrDirs != null ) { for ( String filePath : filesOrDirs ) { if ( ! filePath . isEmpty ( ) ) { File file = new File ( fs . getDir ( ) , filePath ) ; String target = new File ( fs . getTargetDir ( ) , filePath ) . getPath ( ) ; logger . info ( "<STR_LIT>" + file + "<STR_LIT>" + target ) ; pack . addFile ( baseDir , file , target , fs . getOsList ( ) , fs . getOverride ( ) , fs . getOverrideRenameTo ( ) , fs . getBlockable ( ) , fs . getAdditionals ( ) , fs . getCondition ( ) ) ; } } } } } catch ( Exception e ) { assertionHelper . parseError ( packElement , e . getMessage ( ) , e ) ; } } } private void processSingleFileChildren ( File baseDir , IXMLElement packElement , PackInfo pack ) throws CompilerException { for ( IXMLElement singleFileNode : packElement . getChildrenNamed ( "<STR_LIT>" ) ) { String src = xmlCompilerHelper . requireAttribute ( singleFileNode , "<STR_LIT:src>" ) ; String target = xmlCompilerHelper . requireAttribute ( singleFileNode , "<STR_LIT:target>" ) ; List < OsModel > osList = OsConstraintHelper . getOsList ( singleFileNode ) ; OverrideType override = getOverrideValue ( singleFileNode ) ; String overrideRenameTo = getOverrideRenameToValue ( singleFileNode ) ; Blockable blockable = getBlockableValue ( singleFileNode , osList ) ; Map additionals = getAdditionals ( singleFileNode ) ; String condition = singleFileNode . getAttribute ( "<STR_LIT>" ) ; File file = new File ( src ) ; if ( ! file . isAbsolute ( ) ) { file = new File ( compilerData . getBasedir ( ) , src ) ; } if ( ! file . exists ( ) ) { try { file = new File ( variableSubstitutor . substitute ( file . getAbsolutePath ( ) ) ) ; } catch ( Exception e ) { assertionHelper . parseWarn ( singleFileNode , e . getMessage ( ) ) ; } } try { logger . info ( "<STR_LIT>" + file + "<STR_LIT>" + target ) ; pack . addFile ( baseDir , file , target , osList , override , overrideRenameTo , blockable , additionals , condition ) ; } catch ( IOException x ) { assertionHelper . parseError ( singleFileNode , x . getMessage ( ) , x ) ; } } } private void processFileChildren ( File baseDir , IXMLElement packElement , PackInfo pack ) throws CompilerException { for ( IXMLElement fileNode : packElement . getChildrenNamed ( "<STR_LIT:file>" ) ) { String src = xmlCompilerHelper . requireAttribute ( fileNode , "<STR_LIT:src>" ) ; boolean unpack = Boolean . parseBoolean ( fileNode . getAttribute ( "<STR_LIT>" ) ) ; TargetFileSet fs = new TargetFileSet ( ) ; try { File relsrcfile = new File ( src ) ; File abssrcfile = FileUtil . getAbsoluteFile ( src , compilerData . getBasedir ( ) ) ; if ( ! abssrcfile . exists ( ) ) { throw new FileNotFoundException ( "<STR_LIT>" + relsrcfile + "<STR_LIT>" ) ; } if ( relsrcfile . isDirectory ( ) ) { fs . setDir ( abssrcfile . getParentFile ( ) ) ; fs . createInclude ( ) . setName ( relsrcfile . getName ( ) + "<STR_LIT>" ) ; } else { fs . setFile ( abssrcfile ) ; } fs . setTargetDir ( xmlCompilerHelper . requireAttribute ( fileNode , "<STR_LIT>" ) ) ; List < OsModel > osList = OsConstraintHelper . getOsList ( fileNode ) ; fs . setOsList ( osList ) ; fs . setOverride ( getOverrideValue ( fileNode ) ) ; fs . setOverrideRenameTo ( getOverrideRenameToValue ( fileNode ) ) ; fs . setBlockable ( getBlockableValue ( fileNode , osList ) ) ; fs . setAdditionals ( getAdditionals ( fileNode ) ) ; fs . setCondition ( fileNode . getAttribute ( "<STR_LIT>" ) ) ; String boolval = fileNode . getAttribute ( "<STR_LIT>" ) ; if ( boolval != null ) { fs . setCaseSensitive ( Boolean . parseBoolean ( boolval ) ) ; } boolval = fileNode . getAttribute ( "<STR_LIT>" ) ; if ( boolval != null ) { fs . setDefaultexcludes ( Boolean . parseBoolean ( boolval ) ) ; } boolval = fileNode . getAttribute ( "<STR_LIT>" ) ; if ( boolval != null ) { fs . setFollowSymlinks ( Boolean . parseBoolean ( boolval ) ) ; } LinkedList < String > srcfiles = new LinkedList < String > ( ) ; Collections . addAll ( srcfiles , fs . getDirectoryScanner ( ) . getIncludedDirectories ( ) ) ; Collections . addAll ( srcfiles , fs . getDirectoryScanner ( ) . getIncludedFiles ( ) ) ; for ( String filePath : srcfiles ) { if ( ! filePath . isEmpty ( ) ) { abssrcfile = new File ( fs . getDir ( ) , filePath ) ; if ( unpack ) { logger . info ( "<STR_LIT>" + abssrcfile ) ; addArchiveContent ( baseDir , abssrcfile , fs . getTargetDir ( ) , fs . getOsList ( ) , fs . getOverride ( ) , fs . getOverrideRenameTo ( ) , fs . getBlockable ( ) , pack , fs . getAdditionals ( ) , fs . getCondition ( ) ) ; } else { String target = fs . getTargetDir ( ) + "<STR_LIT:/>" + filePath ; logger . info ( "<STR_LIT>" + abssrcfile + "<STR_LIT>" + target ) ; pack . addFile ( baseDir , abssrcfile , target , fs . getOsList ( ) , fs . getOverride ( ) , fs . getOverrideRenameTo ( ) , fs . getBlockable ( ) , fs . getAdditionals ( ) , fs . getCondition ( ) ) ; } } } } catch ( Exception e ) { throw new CompilerException ( e . getMessage ( ) , e ) ; } } } private void processExecutableChildren ( PackInfo pack , List < IXMLElement > childrenNamed ) throws CompilerException { for ( IXMLElement executableNode : childrenNamed ) { ExecutableFile executable = new ExecutableFile ( ) ; String val ; String condition = executableNode . getAttribute ( "<STR_LIT>" ) ; executable . setCondition ( condition ) ; executable . path = xmlCompilerHelper . requireAttribute ( executableNode , "<STR_LIT>" ) ; val = executableNode . getAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( "<STR_LIT>" . equalsIgnoreCase ( val ) ) { executable . executionStage = ExecutableFile . POSTINSTALL ; } else if ( "<STR_LIT>" . equalsIgnoreCase ( val ) ) { executable . executionStage = ExecutableFile . UNINSTALL ; } val = executableNode . getAttribute ( "<STR_LIT:type>" , "<STR_LIT>" ) ; if ( "<STR_LIT>" . equalsIgnoreCase ( val ) ) { executable . type = ExecutableFile . JAR ; executable . mainClass = executableNode . getAttribute ( "<STR_LIT:class>" ) ; } val = executableNode . getAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( "<STR_LIT>" . equalsIgnoreCase ( val ) ) { executable . onFailure = ExecutableFile . ABORT ; } else if ( "<STR_LIT>" . equalsIgnoreCase ( val ) ) { executable . onFailure = ExecutableFile . WARN ; } else if ( "<STR_LIT>" . equalsIgnoreCase ( val ) ) { executable . onFailure = ExecutableFile . IGNORE ; } val = executableNode . getAttribute ( "<STR_LIT>" ) ; executable . keepFile = Boolean . parseBoolean ( val ) ; IXMLElement args = executableNode . getFirstChildNamed ( "<STR_LIT>" ) ; if ( null != args ) { for ( IXMLElement ixmlElement : args . getChildrenNamed ( "<STR_LIT>" ) ) { executable . argList . add ( xmlCompilerHelper . requireAttribute ( ixmlElement , "<STR_LIT:value>" ) ) ; } } executable . osList = OsConstraintHelper . getOsList ( executableNode ) ; pack . addExecutable ( executable ) ; } } private void processParsableChildren ( PackInfo pack , List < IXMLElement > parsableChildren ) throws CompilerException { for ( IXMLElement parsableNode : parsableChildren ) { String target = parsableNode . getAttribute ( "<STR_LIT>" ) ; SubstitutionType type = SubstitutionType . lookup ( parsableNode . getAttribute ( "<STR_LIT:type>" , "<STR_LIT>" ) ) ; String encoding = parsableNode . getAttribute ( "<STR_LIT>" , null ) ; List < OsModel > osList = OsConstraintHelper . getOsList ( parsableNode ) ; String condition = parsableNode . getAttribute ( "<STR_LIT>" ) ; if ( target != null ) { ParsableFile parsable = new ParsableFile ( target , type , encoding , osList ) ; parsable . setCondition ( condition ) ; pack . addParsable ( parsable ) ; } for ( IXMLElement fileSetElement : parsableNode . getChildrenNamed ( "<STR_LIT>" ) ) { String targetdir = xmlCompilerHelper . requireAttribute ( fileSetElement , "<STR_LIT>" ) ; String dir_attr = xmlCompilerHelper . requireAttribute ( fileSetElement , "<STR_LIT>" ) ; File dir = new File ( dir_attr ) ; if ( ! dir . isAbsolute ( ) ) { dir = new File ( compilerData . getBasedir ( ) , dir_attr ) ; } if ( ! dir . isDirectory ( ) ) { assertionHelper . parseError ( fileSetElement , "<STR_LIT>" + dir_attr ) ; } String [ ] includedFiles = getFilesetIncludedFiles ( fileSetElement ) ; if ( includedFiles != null ) { for ( String filePath : includedFiles ) { File file = new File ( dir , filePath ) ; if ( file . exists ( ) && file . isFile ( ) ) { String targetFile = new File ( targetdir , filePath ) . getPath ( ) . replace ( File . separatorChar , '<CHAR_LIT:/>' ) ; ParsableFile parsable = new ParsableFile ( targetFile , type , encoding , osList ) ; parsable . setCondition ( condition ) ; pack . addParsable ( parsable ) ; } } } } } } private String [ ] getFilesetIncludedFiles ( IXMLElement fileSetElement ) throws CompilerException { List < String > includedFiles = new ArrayList < String > ( ) ; String dir_attr = xmlCompilerHelper . requireAttribute ( fileSetElement , "<STR_LIT>" ) ; File dir = new File ( dir_attr ) ; if ( ! dir . isAbsolute ( ) ) { dir = new File ( compilerData . getBasedir ( ) , dir_attr ) ; } if ( ! dir . isDirectory ( ) ) { assertionHelper . parseError ( fileSetElement , "<STR_LIT>" + dir_attr ) ; } boolean casesensitive = xmlCompilerHelper . validateYesNoAttribute ( fileSetElement , "<STR_LIT>" , YES ) ; boolean defexcludes = xmlCompilerHelper . validateYesNoAttribute ( fileSetElement , "<STR_LIT>" , YES ) ; List < IXMLElement > xcludesList ; String [ ] includes = null ; xcludesList = fileSetElement . getChildrenNamed ( "<STR_LIT>" ) ; if ( ! xcludesList . isEmpty ( ) ) { includes = new String [ xcludesList . size ( ) ] ; for ( int j = <NUM_LIT:0> ; j < xcludesList . size ( ) ; j ++ ) { IXMLElement xclude = xcludesList . get ( j ) ; includes [ j ] = xmlCompilerHelper . requireAttribute ( xclude , "<STR_LIT:name>" ) ; } } String [ ] excludes = null ; xcludesList = fileSetElement . getChildrenNamed ( "<STR_LIT>" ) ; if ( ! xcludesList . isEmpty ( ) ) { excludes = new String [ xcludesList . size ( ) ] ; for ( int j = <NUM_LIT:0> ; j < xcludesList . size ( ) ; j ++ ) { IXMLElement xclude = xcludesList . get ( j ) ; excludes [ j ] = xmlCompilerHelper . requireAttribute ( xclude , "<STR_LIT:name>" ) ; } } String [ ] toDo = new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ; String [ ] [ ] containers = new String [ ] [ ] { includes , excludes } ; for ( int j = <NUM_LIT:0> ; j < toDo . length ; ++ j ) { String inex = fileSetElement . getAttribute ( toDo [ j ] ) ; if ( inex != null && inex . length ( ) > <NUM_LIT:0> ) { StringTokenizer tokenizer = new StringTokenizer ( inex , "<STR_LIT:U+002CU+0020>" , false ) ; int newSize = tokenizer . countTokens ( ) ; String [ ] nCont = null ; if ( containers [ j ] != null && containers [ j ] . length > <NUM_LIT:0> ) { newSize += containers [ j ] . length ; nCont = new String [ newSize ] ; System . arraycopy ( containers [ j ] , <NUM_LIT:0> , nCont , <NUM_LIT:0> , containers [ j ] . length ) ; } if ( nCont == null ) { nCont = new String [ newSize ] ; } for ( int k = <NUM_LIT:0> ; k < newSize ; ++ k ) { nCont [ k ] = tokenizer . nextToken ( ) ; } containers [ j ] = nCont ; } } includes = containers [ <NUM_LIT:0> ] ; excludes = containers [ <NUM_LIT:1> ] ; DirectoryScanner directoryScanner = new DirectoryScanner ( ) ; directoryScanner . setIncludes ( includes ) ; directoryScanner . setExcludes ( excludes ) ; if ( defexcludes ) { directoryScanner . addDefaultExcludes ( ) ; } directoryScanner . setBasedir ( dir ) ; directoryScanner . setCaseSensitive ( casesensitive ) ; try { directoryScanner . scan ( ) ; String [ ] files = directoryScanner . getIncludedFiles ( ) ; String [ ] dirs = directoryScanner . getIncludedDirectories ( ) ; Collections . addAll ( includedFiles , files ) ; Collections . addAll ( includedFiles , dirs ) ; } catch ( Exception e ) { throw new CompilerException ( e . getMessage ( ) ) ; } return includedFiles . toArray ( new String [ includedFiles . size ( ) ] ) ; } private IXMLElement readRefPackData ( String refFileName , boolean isselfcontained ) throws CompilerException { File refXMLFile = new File ( refFileName ) ; if ( ! refXMLFile . isAbsolute ( ) ) { refXMLFile = new File ( compilerData . getBasedir ( ) , refFileName ) ; } if ( ! refXMLFile . canRead ( ) ) { throw new CompilerException ( "<STR_LIT>" + refXMLFile ) ; } InputStream specin ; if ( isselfcontained ) { if ( ! refXMLFile . getAbsolutePath ( ) . endsWith ( "<STR_LIT>" ) ) { throw new CompilerException ( "<STR_LIT>" + refXMLFile + "<STR_LIT>" ) ; } ZipFile zip ; try { zip = new ZipFile ( refXMLFile , ZipFile . OPEN_READ ) ; ZipEntry specentry = zip . getEntry ( "<STR_LIT>" ) ; specin = zip . getInputStream ( specentry ) ; } catch ( IOException e ) { throw new CompilerException ( "<STR_LIT>" + refXMLFile ) ; } } else { try { specin = new FileInputStream ( refXMLFile . getAbsolutePath ( ) ) ; } catch ( FileNotFoundException e ) { throw new CompilerException ( "<STR_LIT>" ) ; } } IXMLParser refXMLParser = new XMLParser ( ) ; IXMLElement refXMLData = refXMLParser . parse ( specin , refXMLFile . getAbsolutePath ( ) ) ; if ( ! "<STR_LIT>" . equalsIgnoreCase ( refXMLData . getName ( ) ) ) { assertionHelper . parseError ( refXMLData , "<STR_LIT>" ) ; } if ( ! CompilerData . VERSION . equalsIgnoreCase ( xmlCompilerHelper . requireAttribute ( refXMLData , "<STR_LIT:version>" ) ) ) { assertionHelper . parseError ( refXMLData , "<STR_LIT>" ) ; } substituteProperties ( refXMLData ) ; addResources ( refXMLData ) ; try { specin . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return refXMLData ; } protected void addArchiveContent ( File baseDir , File archive , String targetdir , List < OsModel > osList , OverrideType override , String overrideRenameTo , Blockable blockable , PackInfo pack , Map additionals , String condition ) throws IOException { FileInputStream fin = new FileInputStream ( archive ) ; ZipInputStream zin = new ZipInputStream ( fin ) ; List < String > allDirList = new ArrayList < String > ( ) ; while ( true ) { ZipEntry zentry = zin . getNextEntry ( ) ; if ( zentry == null ) { break ; } if ( zentry . isDirectory ( ) ) { String dName = zentry . getName ( ) . substring ( <NUM_LIT:0> , zentry . getName ( ) . length ( ) - <NUM_LIT:1> ) ; allDirList . add ( dName ) ; continue ; } try { File temp = FileUtils . createTempFile ( "<STR_LIT>" , null ) ; temp . deleteOnExit ( ) ; FileOutputStream out = new FileOutputStream ( temp ) ; IoHelper . copyStream ( zin , out ) ; out . close ( ) ; String target = targetdir + "<STR_LIT:/>" + zentry . getName ( ) ; logger . info ( "<STR_LIT>" + zentry . getName ( ) + "<STR_LIT>" + target ) ; pack . addFile ( baseDir , temp , target , osList , override , overrideRenameTo , blockable , additionals , condition ) ; } catch ( IOException e ) { throw new IOException ( "<STR_LIT>" + zentry . getName ( ) + "<STR_LIT>" + archive + "<STR_LIT:U+0020(>" + e . getMessage ( ) + "<STR_LIT:)>" ) ; } } for ( String dirName : allDirList ) { File tmp = new File ( dirName ) ; if ( ! tmp . mkdirs ( ) ) { throw new CompilerException ( "<STR_LIT>" + tmp ) ; } tmp . deleteOnExit ( ) ; String target = targetdir + "<STR_LIT:/>" + dirName ; logger . info ( "<STR_LIT>" + tmp + "<STR_LIT>" + target ) ; pack . addFile ( baseDir , tmp , target , osList , override , overrideRenameTo , blockable , additionals , condition ) ; } fin . close ( ) ; } protected void addPanels ( IXMLElement data ) throws IOException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement root = xmlCompilerHelper . requireChildNamed ( data , "<STR_LIT>" ) ; List < IXMLElement > panels = root . getChildrenNamed ( "<STR_LIT>" ) ; if ( panels . isEmpty ( ) ) { assertionHelper . parseError ( root , "<STR_LIT>" ) ; } int panelCounter = <NUM_LIT:0> ; for ( IXMLElement panelElement : panels ) { panelCounter ++ ; Panel panel = new Panel ( ) ; panel . setOsConstraints ( OsConstraintHelper . getOsList ( panelElement ) ) ; String className = xmlCompilerHelper . requireAttribute ( panelElement , "<STR_LIT>" ) ; String id = panelElement . getAttribute ( "<STR_LIT:id>" ) ; panel . setPanelId ( id ) ; String condition = panelElement . getAttribute ( "<STR_LIT>" ) ; panel . setCondition ( condition ) ; Class type = classLoader . loadClass ( className , IzPanel . class ) ; if ( type . equals ( ExtendedInstallPanel . class ) ) { logger . warning ( ExtendedInstallPanel . class . getSimpleName ( ) + "<STR_LIT>" + InstallPanel . class . getSimpleName ( ) + "<STR_LIT>" ) ; } panel . setClassName ( type . getName ( ) ) ; IXMLElement configurationElement = panelElement . getFirstChildNamed ( "<STR_LIT>" ) ; if ( configurationElement != null ) { logger . fine ( "<STR_LIT>" + panel . getPanelId ( ) ) ; List < IXMLElement > params = configurationElement . getChildrenNamed ( "<STR_LIT>" ) ; for ( IXMLElement param : params ) { String name = xmlCompilerHelper . requireAttribute ( param , "<STR_LIT:name>" ) ; String value = xmlCompilerHelper . requireAttribute ( param , "<STR_LIT:value>" ) ; logger . fine ( "<STR_LIT>" + name + "<STR_LIT>" + value ) ; panel . addConfiguration ( name , value ) ; } } IXMLElement validatorElement = panelElement . getFirstChildNamed ( DataValidator . DATA_VALIDATOR_TAG ) ; if ( validatorElement != null ) { String validator = validatorElement . getAttribute ( DataValidator . DATA_VALIDATOR_CLASSNAME_TAG ) ; if ( ! "<STR_LIT>" . equals ( validator ) ) { Class < DataValidator > validatorType = classLoader . loadClass ( validator , DataValidator . class ) ; panel . setValidator ( validatorType . getName ( ) ) ; } } List < IXMLElement > helpSpecs = panelElement . getChildrenNamed ( HELP_TAG ) ; if ( helpSpecs != null ) { List < Help > helps = new ArrayList < Help > ( ) ; for ( IXMLElement help : helpSpecs ) { String iso3 = help . getAttribute ( ISO3_ATTRIBUTE ) ; String resourceId ; if ( id == null ) { resourceId = className + "<STR_LIT:_>" + panelCounter + "<STR_LIT>" + iso3 ; } else { resourceId = id + "<STR_LIT:_>" + panelCounter + "<STR_LIT>" + iso3 ; } helps . add ( new Help ( iso3 , resourceId ) ) ; URL originalUrl = resourceFinder . findProjectResource ( help . getAttribute ( SRC_ATTRIBUTE ) , "<STR_LIT>" , help ) ; packager . addResource ( resourceId , originalUrl ) ; } panel . setHelps ( helps ) ; } addPanelActions ( panelElement , panel ) ; packager . addPanel ( panel ) ; } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } protected void addResources ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement root = data . getFirstChildNamed ( "<STR_LIT>" ) ; if ( root == null ) { return ; } for ( IXMLElement resNode : root . getChildrenNamed ( "<STR_LIT>" ) ) { String id = xmlCompilerHelper . requireAttribute ( resNode , "<STR_LIT:id>" ) ; String src = xmlCompilerHelper . requireAttribute ( resNode , "<STR_LIT:src>" ) ; boolean substitute = xmlCompilerHelper . validateYesNoAttribute ( resNode , "<STR_LIT>" , NO ) ; boolean parsexml = xmlCompilerHelper . validateYesNoAttribute ( resNode , "<STR_LIT>" , NO ) ; String encoding = resNode . getAttribute ( "<STR_LIT>" ) ; if ( encoding == null ) { encoding = "<STR_LIT>" ; } URL originalUrl = resourceFinder . findProjectResource ( src , "<STR_LIT>" , resNode ) ; URL url = originalUrl ; InputStream is = null ; OutputStream os = null ; try { if ( parsexml || ( ! "<STR_LIT>" . equals ( encoding ) ) || ( substitute && ! packager . getVariables ( ) . isEmpty ( ) ) ) { File parsedFile = FileUtils . createTempFile ( "<STR_LIT>" , null ) ; parsedFile . deleteOnExit ( ) ; FileOutputStream outFile = new FileOutputStream ( parsedFile ) ; os = new BufferedOutputStream ( outFile ) ; url = parsedFile . toURI ( ) . toURL ( ) ; } if ( ! "<STR_LIT>" . equals ( encoding ) ) { File recodedFile = FileUtils . createTempFile ( "<STR_LIT>" , null ) ; recodedFile . deleteOnExit ( ) ; InputStreamReader reader = new InputStreamReader ( originalUrl . openStream ( ) , encoding ) ; OutputStreamWriter writer = new OutputStreamWriter ( new FileOutputStream ( recodedFile ) , "<STR_LIT:UTF-8>" ) ; char [ ] buffer = new char [ <NUM_LIT> ] ; int read ; while ( ( read = reader . read ( buffer ) ) != - <NUM_LIT:1> ) { writer . write ( buffer , <NUM_LIT:0> , read ) ; } reader . close ( ) ; writer . close ( ) ; if ( parsexml ) { originalUrl = recodedFile . toURI ( ) . toURL ( ) ; } else { url = recodedFile . toURI ( ) . toURL ( ) ; } } if ( parsexml ) { IXMLParser parser = new XMLParser ( ) ; IXMLElement xml = parser . parse ( originalUrl ) ; IXMLWriter writer = new XMLWriter ( ) ; if ( substitute && ! packager . getVariables ( ) . isEmpty ( ) ) { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; writer . setOutput ( baos ) ; is = new ByteArrayInputStream ( baos . toByteArray ( ) ) ; } else { writer . setOutput ( os ) ; } writer . write ( xml ) ; } if ( substitute ) { if ( packager . getVariables ( ) . isEmpty ( ) ) { url = originalUrl ; assertionHelper . parseWarn ( resNode , "<STR_LIT>" + url . getPath ( ) + "<STR_LIT>" ) ; } else { SubstitutionType type = SubstitutionType . lookup ( resNode . getAttribute ( "<STR_LIT:type>" ) ) ; if ( null == is ) { is = new BufferedInputStream ( originalUrl . openStream ( ) ) ; } variableSubstitutor . substitute ( is , os , type , "<STR_LIT:UTF-8>" ) ; } } } catch ( Exception e ) { assertionHelper . parseError ( resNode , e . getMessage ( ) , e ) ; } finally { if ( null != os ) { try { os . close ( ) ; } catch ( IOException e ) { } } if ( null != is ) { try { is . close ( ) ; } catch ( IOException e ) { } } } packager . addResource ( id , url ) ; if ( id . startsWith ( "<STR_LIT>" ) ) { List < URL > packsLangURLs ; if ( packsLangUrlMap . containsKey ( id ) ) { packsLangURLs = packsLangUrlMap . get ( id ) ; } else { packsLangURLs = new ArrayList < URL > ( ) ; packsLangUrlMap . put ( id , packsLangURLs ) ; } packsLangURLs . add ( url ) ; } } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } protected void addLangpacks ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement root = xmlCompilerHelper . requireChildNamed ( data , "<STR_LIT>" ) ; List < IXMLElement > locals = root . getChildrenNamed ( "<STR_LIT>" ) ; if ( locals . isEmpty ( ) ) { assertionHelper . parseError ( root , "<STR_LIT>" ) ; } for ( IXMLElement localNode : locals ) { String iso3 = xmlCompilerHelper . requireAttribute ( localNode , "<STR_LIT>" ) ; String path ; path = "<STR_LIT>" + iso3 + "<STR_LIT>" ; URL iso3xmlURL = resourceFinder . findIzPackResource ( path , "<STR_LIT>" , localNode ) ; path = "<STR_LIT>" + iso3 + "<STR_LIT>" ; URL iso3FlagURL = resourceFinder . findIzPackResource ( path , "<STR_LIT>" , localNode ) ; packager . addLangPack ( iso3 , iso3xmlURL , iso3FlagURL ) ; } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } protected void addInfo ( IXMLElement data ) throws Exception { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement root = xmlCompilerHelper . requireChildNamed ( data , "<STR_LIT>" ) ; Info info = compilerData . getExternalInfo ( ) ; info . setAppName ( xmlCompilerHelper . requireContent ( xmlCompilerHelper . requireChildNamed ( root , "<STR_LIT>" ) ) ) ; info . setAppVersion ( xmlCompilerHelper . requireContent ( xmlCompilerHelper . requireChildNamed ( root , "<STR_LIT>" ) ) ) ; IXMLElement subpath = root . getFirstChildNamed ( "<STR_LIT>" ) ; if ( subpath != null ) { info . setInstallationSubPath ( xmlCompilerHelper . requireContent ( subpath ) ) ; } final IXMLElement URLElem = root . getFirstChildNamed ( "<STR_LIT:url>" ) ; if ( URLElem != null ) { URL appURL = xmlCompilerHelper . requireURLContent ( URLElem ) ; info . setAppURL ( appURL . toString ( ) ) ; } IXMLElement authors = root . getFirstChildNamed ( "<STR_LIT>" ) ; if ( authors != null ) { for ( IXMLElement authorNode : authors . getChildrenNamed ( "<STR_LIT>" ) ) { String name = xmlCompilerHelper . requireAttribute ( authorNode , "<STR_LIT:name>" ) ; String email = xmlCompilerHelper . requireAttribute ( authorNode , "<STR_LIT:email>" ) ; info . addAuthor ( new Info . Author ( name , email ) ) ; } } IXMLElement javaVersion = root . getFirstChildNamed ( "<STR_LIT>" ) ; if ( javaVersion != null ) { info . setJavaVersion ( xmlCompilerHelper . requireContent ( javaVersion ) ) ; } IXMLElement jdkRequired = root . getFirstChildNamed ( "<STR_LIT>" ) ; if ( jdkRequired != null ) { info . setJdkRequired ( "<STR_LIT:yes>" . equals ( jdkRequired . getContent ( ) ) ) ; } IXMLElement webDirURL = root . getFirstChildNamed ( "<STR_LIT>" ) ; if ( webDirURL != null ) { info . setWebDirURL ( xmlCompilerHelper . requireURLContent ( webDirURL ) . toString ( ) ) ; } String kind = compilerData . getKind ( ) ; if ( kind != null ) { if ( kind . equalsIgnoreCase ( CompilerData . WEB ) && webDirURL == null ) { assertionHelper . parseError ( root , "<STR_LIT>" ) ; } else if ( kind . equalsIgnoreCase ( CompilerData . STANDARD ) && webDirURL != null ) { info . setWebDirURL ( null ) ; } } IXMLElement pack200 = root . getFirstChildNamed ( "<STR_LIT>" ) ; info . setPack200Compression ( pack200 != null ) ; IXMLElement privileged = root . getFirstChildNamed ( "<STR_LIT>" ) ; info . setRequirePrivilegedExecution ( privileged != null ) ; if ( privileged != null && privileged . hasAttribute ( "<STR_LIT>" ) ) { info . setPrivilegedExecutionConditionID ( privileged . getAttribute ( "<STR_LIT>" ) ) ; } IXMLElement reboot = root . getFirstChildNamed ( "<STR_LIT>" ) ; if ( reboot != null ) { String content = reboot . getContent ( ) ; if ( "<STR_LIT>" . equalsIgnoreCase ( content ) ) { info . setRebootAction ( Info . REBOOT_ACTION_IGNORE ) ; } else if ( "<STR_LIT>" . equalsIgnoreCase ( content ) ) { info . setRebootAction ( Info . REBOOT_ACTION_NOTICE ) ; } else if ( "<STR_LIT>" . equalsIgnoreCase ( content ) ) { info . setRebootAction ( Info . REBOOT_ACTION_ASK ) ; } else if ( "<STR_LIT>" . equalsIgnoreCase ( content ) ) { info . setRebootAction ( Info . REBOOT_ACTION_ALWAYS ) ; } else { throw new CompilerException ( "<STR_LIT>" + content + "<STR_LIT>" ) ; } if ( reboot . hasAttribute ( "<STR_LIT>" ) ) { info . setRebootActionConditionID ( reboot . getAttribute ( "<STR_LIT>" ) ) ; } } IXMLElement uninstallInfo = root . getFirstChildNamed ( "<STR_LIT>" ) ; if ( xmlCompilerHelper . validateYesNoAttribute ( uninstallInfo , "<STR_LIT>" , YES ) ) { logger . info ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; if ( privileged != null ) { info . setRequirePrivilegedExecutionUninstaller ( xmlCompilerHelper . validateYesNoAttribute ( privileged , "<STR_LIT>" , YES ) ) ; } if ( uninstallInfo != null ) { String uninstallerName = uninstallInfo . getAttribute ( "<STR_LIT:name>" ) ; if ( uninstallerName != null && uninstallerName . length ( ) > "<STR_LIT>" . length ( ) ) { info . setUninstallerName ( uninstallerName ) ; } String uninstallerPath = uninstallInfo . getAttribute ( "<STR_LIT:path>" ) ; if ( uninstallerPath != null ) { info . setUninstallerPath ( uninstallerPath ) ; } if ( uninstallInfo . hasAttribute ( "<STR_LIT>" ) ) { String uninstallerCondition = uninstallInfo . getAttribute ( "<STR_LIT>" ) ; info . setUninstallerCondition ( uninstallerCondition ) ; } } } else { logger . info ( "<STR_LIT>" ) ; info . setUninstallerPath ( null ) ; } IXMLElement slfPath = root . getFirstChildNamed ( "<STR_LIT>" ) ; if ( slfPath != null ) { info . setSummaryLogFilePath ( xmlCompilerHelper . requireContent ( slfPath ) ) ; } IXMLElement writeInstallInfo = root . getFirstChildNamed ( "<STR_LIT>" ) ; if ( writeInstallInfo != null ) { String writeInstallInfoString = xmlCompilerHelper . requireContent ( writeInstallInfo ) ; info . setWriteInstallationInformation ( validateYesNo ( writeInstallInfoString ) ) ; } String unpackerclass = propertyManager . getProperty ( "<STR_LIT>" ) ; info . setUnpackerClassName ( unpackerclass ) ; List < IXMLElement > tempdirs = root . getChildrenNamed ( TEMP_DIR_ELEMENT_NAME ) ; if ( null != tempdirs && tempdirs . size ( ) > <NUM_LIT:0> ) { Set < String > tempDirAttributeNames = new HashSet < String > ( ) ; for ( IXMLElement tempdir : tempdirs ) { final String prefix ; if ( tempdir . hasAttribute ( TEMP_DIR_PREFIX_ATTRIBUTE ) ) { prefix = tempdir . getAttribute ( "<STR_LIT>" ) ; } else { prefix = DEFAULT_TEMP_DIR_PREFIX ; } final String suffix ; if ( tempdir . hasAttribute ( TEMP_DIR_SUFFIX_ATTRIBUTE ) ) { suffix = tempdir . getAttribute ( TEMP_DIR_SUFFIX_ATTRIBUTE ) ; } else { suffix = DEFAULT_TEMP_DIR_SUFFIX ; } final String variableName ; if ( tempdir . hasAttribute ( TEMP_DIR_VARIABLE_NAME_ATTRIBUTE ) ) { variableName = tempdir . getAttribute ( TEMP_DIR_VARIABLE_NAME_ATTRIBUTE ) ; } else { if ( tempDirAttributeNames . contains ( TEMP_DIR_DEFAULT_PROPERTY_NAME ) ) { throw new CompilerException ( "<STR_LIT>" + TEMP_DIR_VARIABLE_NAME_ATTRIBUTE + "<STR_LIT>" + tempdir . getLineNr ( ) + "<STR_LIT>" ) ; } variableName = TEMP_DIR_DEFAULT_PROPERTY_NAME ; } if ( tempDirAttributeNames . contains ( variableName ) ) { throw new CompilerException ( "<STR_LIT>" + variableName + "<STR_LIT>" + tempdir . getLineNr ( ) + "<STR_LIT>" ) ; } tempDirAttributeNames . add ( variableName ) ; info . addTempDir ( new TempDir ( variableName , prefix , suffix ) ) ; } } packager . setInfo ( info ) ; notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } protected void addVariables ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement root = data . getFirstChildNamed ( "<STR_LIT>" ) ; if ( root == null ) { return ; } Properties variables = packager . getVariables ( ) ; for ( IXMLElement variableNode : root . getChildrenNamed ( "<STR_LIT>" ) ) { String name = xmlCompilerHelper . requireAttribute ( variableNode , "<STR_LIT:name>" ) ; String value = xmlCompilerHelper . requireAttribute ( variableNode , "<STR_LIT:value>" ) ; if ( variables . contains ( name ) ) { assertionHelper . parseWarn ( variableNode , "<STR_LIT>" + name + "<STR_LIT>" ) ; } variables . setProperty ( name , value ) ; } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } private int getConfigFileType ( String varname , String type ) throws CompilerException { int filetype = ConfigFileValue . CONFIGFILE_TYPE_OPTIONS ; if ( type != null ) { if ( type . equalsIgnoreCase ( "<STR_LIT>" ) ) { filetype = ConfigFileValue . CONFIGFILE_TYPE_OPTIONS ; } else if ( type . equalsIgnoreCase ( "<STR_LIT>" ) ) { filetype = ConfigFileValue . CONFIGFILE_TYPE_XML ; } else if ( type . equalsIgnoreCase ( "<STR_LIT>" ) ) { filetype = ConfigFileValue . CONFIGFILE_TYPE_INI ; } else { assertionHelper . parseError ( "<STR_LIT>" + varname + "<STR_LIT>" + type ) ; } } return filetype ; } protected void addDynamicVariables ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement root = data . getFirstChildNamed ( "<STR_LIT>" ) ; if ( root == null ) { return ; } Map < String , List < DynamicVariable > > dynamicvariables = packager . getDynamicVariables ( ) ; for ( IXMLElement var : root . getChildrenNamed ( "<STR_LIT>" ) ) { String name = xmlCompilerHelper . requireAttribute ( var , "<STR_LIT:name>" ) ; DynamicVariable dynamicVariable = new DynamicVariableImpl ( ) ; dynamicVariable . setName ( name ) ; String value = var . getAttribute ( "<STR_LIT:value>" ) ; if ( value != null ) { dynamicVariable . setValue ( new PlainValue ( value ) ) ; } else { IXMLElement valueElement = var . getFirstChildNamed ( "<STR_LIT:value>" ) ; if ( valueElement != null ) { value = valueElement . getContent ( ) ; if ( value == null ) { assertionHelper . parseError ( "<STR_LIT>" + name ) ; } dynamicVariable . setValue ( new PlainValue ( value ) ) ; } } value = var . getAttribute ( "<STR_LIT>" ) ; if ( value != null ) { if ( dynamicVariable . getValue ( ) == null ) { dynamicVariable . setValue ( new EnvironmentValue ( value ) ) ; } else { assertionHelper . parseError ( "<STR_LIT>" + name ) ; } } value = var . getAttribute ( "<STR_LIT>" ) ; if ( value != null ) { String regroot = var . getAttribute ( "<STR_LIT>" ) ; String regvalue = var . getAttribute ( "<STR_LIT>" ) ; if ( dynamicVariable . getValue ( ) == null ) { dynamicVariable . setValue ( new RegistryValue ( regroot , value , regvalue ) ) ; } else { assertionHelper . parseError ( "<STR_LIT>" + name ) ; } } value = var . getAttribute ( "<STR_LIT:file>" ) ; if ( value != null ) { String stype = var . getAttribute ( "<STR_LIT:type>" ) ; String filesection = var . getAttribute ( "<STR_LIT>" ) ; String filekey = xmlCompilerHelper . requireAttribute ( var , "<STR_LIT:key>" ) ; if ( dynamicVariable . getValue ( ) == null ) { dynamicVariable . setValue ( new PlainConfigFileValue ( value , getConfigFileType ( name , stype ) , filesection , filekey ) ) ; } else { assertionHelper . parseError ( "<STR_LIT>" + name ) ; } } value = var . getAttribute ( "<STR_LIT>" ) ; if ( value != null ) { String entryname = xmlCompilerHelper . requireAttribute ( var , "<STR_LIT>" ) ; String stype = var . getAttribute ( "<STR_LIT:type>" ) ; String filesection = var . getAttribute ( "<STR_LIT>" ) ; String filekey = xmlCompilerHelper . requireAttribute ( var , "<STR_LIT:key>" ) ; if ( dynamicVariable . getValue ( ) == null ) { dynamicVariable . setValue ( new ZipEntryConfigFileValue ( value , entryname , getConfigFileType ( name , stype ) , filesection , filekey ) ) ; } else { assertionHelper . parseError ( "<STR_LIT>" + name ) ; } } value = var . getAttribute ( "<STR_LIT>" ) ; if ( value != null ) { String entryname = xmlCompilerHelper . requireAttribute ( var , "<STR_LIT>" ) ; String stype = var . getAttribute ( "<STR_LIT:type>" ) ; String filesection = var . getAttribute ( "<STR_LIT>" ) ; String filekey = xmlCompilerHelper . requireAttribute ( var , "<STR_LIT:key>" ) ; if ( dynamicVariable . getValue ( ) == null ) { dynamicVariable . setValue ( new JarEntryConfigValue ( value , entryname , getConfigFileType ( name , stype ) , filesection , filekey ) ) ; } else { assertionHelper . parseError ( "<STR_LIT>" + name ) ; } } value = var . getAttribute ( "<STR_LIT>" ) ; if ( value != null ) { if ( dynamicVariable . getValue ( ) == null ) { String dir = var . getAttribute ( "<STR_LIT>" ) ; String exectype = var . getAttribute ( "<STR_LIT:type>" ) ; String boolval = var . getAttribute ( "<STR_LIT>" ) ; boolean stderr = true ; if ( boolval != null ) { stderr = Boolean . parseBoolean ( boolval ) ; } if ( value . length ( ) <= <NUM_LIT:0> ) { assertionHelper . parseError ( "<STR_LIT>" + name ) ; } Vector < String > cmd = new Vector < String > ( ) ; cmd . add ( value ) ; List < IXMLElement > args = var . getChildrenNamed ( "<STR_LIT>" ) ; if ( args != null ) { for ( IXMLElement arg : args ) { String content = arg . getContent ( ) ; if ( content != null ) { cmd . add ( content ) ; } } } String [ ] cmdarr = new String [ cmd . size ( ) ] ; if ( exectype . equalsIgnoreCase ( "<STR_LIT>" ) || exectype == null ) { dynamicVariable . setValue ( new ExecValue ( cmd . toArray ( cmdarr ) , dir , false , stderr ) ) ; } else if ( exectype . equalsIgnoreCase ( "<STR_LIT>" ) ) { dynamicVariable . setValue ( new ExecValue ( cmd . toArray ( cmdarr ) , dir , true , stderr ) ) ; } else { assertionHelper . parseError ( "<STR_LIT>" + exectype + "<STR_LIT>" + name ) ; } } else { assertionHelper . parseError ( "<STR_LIT>" + name ) ; } } if ( dynamicVariable . getValue ( ) == null ) { assertionHelper . parseError ( "<STR_LIT>" + name ) ; } value = var . getAttribute ( "<STR_LIT>" ) ; if ( value != null ) { dynamicVariable . setCheckonce ( Boolean . valueOf ( value ) ) ; } value = var . getAttribute ( "<STR_LIT>" ) ; if ( value != null ) { dynamicVariable . setIgnoreFailure ( Boolean . valueOf ( value ) ) ; } IXMLElement filters = var . getFirstChildNamed ( "<STR_LIT>" ) ; if ( filters != null ) { List < IXMLElement > filterList = filters . getChildren ( ) ; for ( IXMLElement filterElement : filterList ) { if ( filterElement . getName ( ) . equals ( "<STR_LIT>" ) ) { String expression = filterElement . getAttribute ( "<STR_LIT>" ) ; String selectexpr = filterElement . getAttribute ( "<STR_LIT>" ) ; String replaceexpr = filterElement . getAttribute ( "<STR_LIT>" ) ; String defaultvalue = filterElement . getAttribute ( "<STR_LIT>" ) ; String scasesensitive = filterElement . getAttribute ( "<STR_LIT>" ) ; String sglobal = filterElement . getAttribute ( "<STR_LIT>" ) ; dynamicVariable . addFilter ( new RegularExpressionFilter ( expression , selectexpr , replaceexpr , defaultvalue , Boolean . valueOf ( scasesensitive != null ? scasesensitive : "<STR_LIT:true>" ) , Boolean . valueOf ( sglobal != null ? sglobal : "<STR_LIT:false>" ) ) ) ; } else if ( filterElement . getName ( ) . equals ( "<STR_LIT>" ) ) { String basedir = filterElement . getAttribute ( "<STR_LIT>" ) ; dynamicVariable . addFilter ( new LocationFilter ( basedir ) ) ; } } } try { dynamicVariable . validate ( ) ; } catch ( Exception e ) { assertionHelper . parseError ( "<STR_LIT>" + name + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } List < DynamicVariable > dynamicValues = new ArrayList < DynamicVariable > ( ) ; if ( dynamicvariables . containsKey ( name ) ) { dynamicValues = dynamicvariables . get ( name ) ; } else { dynamicvariables . put ( name , dynamicValues ) ; } String conditionid = var . getAttribute ( "<STR_LIT>" ) ; dynamicVariable . setConditionid ( conditionid ) ; if ( dynamicValues . remove ( dynamicVariable ) ) { assertionHelper . parseWarn ( var , "<STR_LIT>" + name + "<STR_LIT>" ) ; } dynamicValues . add ( dynamicVariable ) ; } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } protected void addDynamicInstallerRequirement ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement root = data . getFirstChildNamed ( "<STR_LIT>" ) ; List < DynamicInstallerRequirementValidator > dynamicReq = packager . getDynamicInstallerRequirements ( ) ; if ( root != null ) { List < IXMLElement > installerRequirementList = root . getChildrenNamed ( "<STR_LIT>" ) ; for ( IXMLElement installerrequirement : installerRequirementList ) { Status severity = Status . valueOf ( xmlCompilerHelper . requireAttribute ( installerrequirement , "<STR_LIT>" ) ) ; if ( severity == null || severity == Status . OK ) { assertionHelper . parseError ( installerrequirement , "<STR_LIT>" ) ; } dynamicReq . add ( new DynamicInstallerRequirementValidatorImpl ( xmlCompilerHelper . requireAttribute ( installerrequirement , "<STR_LIT>" ) , severity , xmlCompilerHelper . requireAttribute ( installerrequirement , "<STR_LIT>" ) ) ) ; } } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } protected void addConditions ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement root = data . getFirstChildNamed ( "<STR_LIT>" ) ; Map < String , Condition > conditions = packager . getRules ( ) ; if ( root != null ) { for ( IXMLElement conditionNode : root . getChildrenNamed ( "<STR_LIT>" ) ) { try { Condition condition = rules . createCondition ( conditionNode ) ; if ( condition != null ) { String conditionid = condition . getId ( ) ; if ( conditions . put ( conditionid , condition ) != null ) { assertionHelper . parseWarn ( conditionNode , "<STR_LIT>" + conditionid + "<STR_LIT>" ) ; } } else { assertionHelper . parseError ( conditionNode , "<STR_LIT>" ) ; } } catch ( Exception e ) { throw new CompilerException ( "<STR_LIT>" + conditionNode . getLineNr ( ) + "<STR_LIT::U+0020>" + e . getMessage ( ) , e ) ; } } try { rules . resolveConditions ( ) ; } catch ( Exception e ) { throw new CompilerException ( "<STR_LIT>" + e . getMessage ( ) , e ) ; } } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } protected void substituteProperties ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement root = data . getFirstChildNamed ( "<STR_LIT>" ) ; if ( root != null ) { for ( IXMLElement propertyNode : root . getChildrenNamed ( "<STR_LIT>" ) ) { propertyManager . execute ( propertyNode ) ; } } if ( root != null ) { data . removeChild ( root ) ; } substituteAllProperties ( data ) ; if ( root != null ) { data . addChild ( root ) ; } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } protected void substituteAllProperties ( IXMLElement element ) throws CompilerException { Enumeration attributes = element . enumerateAttributeNames ( ) ; while ( attributes . hasMoreElements ( ) ) { String name = ( String ) attributes . nextElement ( ) ; try { String value = variableSubstitutor . substitute ( element . getAttribute ( name ) , SubstitutionType . TYPE_AT ) ; element . setAttribute ( name , value ) ; } catch ( Exception e ) { assertionHelper . parseWarn ( element , "<STR_LIT>" + name + "<STR_LIT>" + e . getMessage ( ) + "<STR_LIT:)>" ) ; } } String content = element . getContent ( ) ; if ( content != null ) { try { element . setContent ( variableSubstitutor . substitute ( content , SubstitutionType . TYPE_AT ) ) ; } catch ( Exception e ) { assertionHelper . parseWarn ( element , "<STR_LIT>" + e . getMessage ( ) + "<STR_LIT:)>" ) ; } } for ( int i = <NUM_LIT:0> ; i < element . getChildren ( ) . size ( ) ; i ++ ) { IXMLElement child = element . getChildren ( ) . get ( i ) ; substituteAllProperties ( child ) ; } } protected OverrideType getOverrideValue ( IXMLElement fileElement ) throws CompilerException { String override_val = fileElement . getAttribute ( "<STR_LIT>" ) ; if ( override_val == null ) { return OverrideType . OVERRIDE_UPDATE ; } OverrideType override = OverrideType . getOverrideTypeFromAttribute ( override_val ) ; if ( override == null ) { assertionHelper . parseError ( fileElement , "<STR_LIT>" ) ; } return override ; } protected String getOverrideRenameToValue ( IXMLElement f ) throws CompilerException { String override_val = f . getAttribute ( "<STR_LIT>" ) ; String overrideRenameTo = f . getAttribute ( "<STR_LIT>" ) ; if ( overrideRenameTo != null && override_val == null ) { assertionHelper . parseError ( f , "<STR_LIT>" ) ; } return overrideRenameTo ; } protected Blockable getBlockableValue ( IXMLElement blockableElement , List < OsModel > osList ) throws CompilerException { String blockable_val = blockableElement . getAttribute ( "<STR_LIT>" ) ; if ( blockable_val == null ) { return Blockable . BLOCKABLE_NONE ; } Blockable blockable = Blockable . getBlockableFromAttribute ( blockable_val ) ; if ( blockable == null ) { assertionHelper . parseError ( blockableElement , "<STR_LIT>" ) ; } if ( blockable != Blockable . BLOCKABLE_NONE ) { boolean found = false ; for ( OsModel anOsList : osList ) { if ( "<STR_LIT>" . equals ( anOsList . getFamily ( ) ) ) { found = true ; } } if ( ! found ) { assertionHelper . parseWarn ( blockableElement , "<STR_LIT>" ) ; } } return blockable ; } protected boolean validateYesNo ( String value ) { boolean result ; if ( "<STR_LIT:yes>" . equalsIgnoreCase ( value ) ) { result = true ; } else if ( "<STR_LIT>" . equalsIgnoreCase ( value ) ) { result = false ; } else { result = Boolean . valueOf ( value ) ; } return result ; } private void addListeners ( IXMLElement data ) throws CompilerException { notifyCompilerListener ( "<STR_LIT>" , CompilerListener . BEGIN , data ) ; IXMLElement listeners = data . getFirstChildNamed ( "<STR_LIT>" ) ; if ( listeners != null ) { for ( IXMLElement listener : listeners . getChildrenNamed ( "<STR_LIT>" ) ) { String className = xmlCompilerHelper . requireAttribute ( listener , "<STR_LIT>" ) ; Stage stage = Stage . valueOf ( xmlCompilerHelper . requireAttribute ( listener , "<STR_LIT>" ) ) ; if ( Stage . isInInstaller ( stage ) ) { List < OsModel > constraints = OsConstraintHelper . getOsList ( listener ) ; compiler . addListener ( className , stage , constraints ) ; } } } notifyCompilerListener ( "<STR_LIT>" , CompilerListener . END , data ) ; } private void addCompilerListeners ( IXMLElement data ) throws CompilerException { IXMLElement listeners = data . getFirstChildNamed ( "<STR_LIT>" ) ; if ( listeners != null ) { for ( IXMLElement listener : listeners . getChildrenNamed ( "<STR_LIT>" ) ) { String className = xmlCompilerHelper . requireAttribute ( listener , "<STR_LIT>" ) ; Stage stage = Stage . valueOf ( xmlCompilerHelper . requireAttribute ( listener , "<STR_LIT>" ) ) ; if ( Stage . compiler . equals ( stage ) ) { List < OsModel > osConstraints = OsConstraintHelper . getOsList ( listener ) ; boolean matchesCurrentSystem = false ; if ( osConstraints . isEmpty ( ) ) { matchesCurrentSystem = true ; } else { if ( constraints . matchesCurrentPlatform ( osConstraints ) ) { matchesCurrentSystem = true ; } } if ( matchesCurrentSystem ) { Class < CompilerListener > clazz = classLoader . loadClass ( className , CompilerListener . class ) ; CompilerListener l = factory . create ( clazz , CompilerListener . class ) ; compilerListeners . add ( l ) ; } } } } } private void notifyCompilerListener ( String callerName , int state , IXMLElement data ) { for ( CompilerListener compilerListener : compilerListeners ) { compilerListener . notify ( callerName , state , data , packager ) ; } } private Map getAdditionals ( IXMLElement fileElement ) throws CompilerException { Map retval = null ; try { for ( CompilerListener compilerListener : compilerListeners ) { retval = compilerListener . reviseAdditionalDataMap ( retval , fileElement ) ; } } catch ( CompilerException ce ) { assertionHelper . parseError ( fileElement , ce . getMessage ( ) ) ; } return ( retval ) ; } private void mergePacksLangFiles ( ) throws CompilerException { if ( packsLangUrlMap . size ( ) <= <NUM_LIT:0> ) { return ; } OutputStream os = null ; try { IXMLParser parser = new XMLParser ( ) ; for ( String id : packsLangUrlMap . keySet ( ) ) { URL mergedPackLangFileURL ; List < URL > packsLangURLs = packsLangUrlMap . get ( id ) ; if ( packsLangURLs . size ( ) == <NUM_LIT:0> ) { continue ; } if ( packsLangURLs . size ( ) == <NUM_LIT:1> ) { mergedPackLangFileURL = packsLangURLs . get ( <NUM_LIT:0> ) ; } else { IXMLElement mergedPacksLang = null ; for ( URL packslangURL : packsLangURLs ) { IXMLElement xml = parser . parse ( packslangURL ) ; if ( mergedPacksLang == null ) { mergedPacksLang = xml ; } else { List < IXMLElement > langStrings = xml . getChildrenNamed ( "<STR_LIT>" ) ; for ( IXMLElement langString : langStrings ) { mergedPacksLang . addChild ( langString ) ; } } } File mergedPackLangFile = FileUtils . createTempFile ( "<STR_LIT>" , null ) ; mergedPackLangFile . deleteOnExit ( ) ; FileOutputStream outFile = new FileOutputStream ( mergedPackLangFile ) ; os = new BufferedOutputStream ( outFile ) ; IXMLWriter xmlWriter = new XMLWriter ( os ) ; xmlWriter . write ( mergedPacksLang ) ; os . close ( ) ; os = null ; mergedPackLangFileURL = mergedPackLangFile . toURI ( ) . toURL ( ) ; } packager . addResource ( id , mergedPackLangFileURL ) ; } } catch ( Exception e ) { throw new CompilerException ( "<STR_LIT>" + e . getMessage ( ) , e ) ; } finally { if ( null != os ) { try { os . close ( ) ; } catch ( IOException e ) { } } } } private void addPanelActions ( IXMLElement xmlPanel , Panel panel ) throws CompilerException { IXMLElement xmlActions = xmlPanel . getFirstChildNamed ( PanelAction . PANEL_ACTIONS_TAG ) ; if ( xmlActions != null ) { List < IXMLElement > actionList = xmlActions . getChildrenNamed ( PanelAction . PANEL_ACTION_TAG ) ; if ( actionList != null ) { for ( IXMLElement action : actionList ) { String stage = xmlCompilerHelper . requireAttribute ( action , PanelAction . PANEL_ACTION_STAGE_TAG ) ; String actionName = xmlCompilerHelper . requireAttribute ( action , PanelAction . PANEL_ACTION_CLASSNAME_TAG ) ; Class actionType = classLoader . loadClass ( actionName , PanelAction . class ) ; List < IXMLElement > params = action . getChildrenNamed ( "<STR_LIT>" ) ; PanelActionConfiguration config = new PanelActionConfiguration ( actionType . getName ( ) ) ; for ( IXMLElement param : params ) { String name = xmlCompilerHelper . requireAttribute ( param , "<STR_LIT:name>" ) ; String value = xmlCompilerHelper . requireAttribute ( param , "<STR_LIT:value>" ) ; logger . fine ( "<STR_LIT>" + name + "<STR_LIT>" + value + "<STR_LIT>" + actionName ) ; config . addProperty ( name , value ) ; } try { PanelAction . ActionStage actionStage = PanelAction . ActionStage . valueOf ( stage ) ; switch ( actionStage ) { case preconstruct : panel . addPreConstructionAction ( config ) ; break ; case preactivate : panel . addPreActivationAction ( config ) ; break ; case prevalidate : panel . addPreValidationAction ( config ) ; break ; case postvalidate : panel . addPostValidationAction ( config ) ; break ; } } catch ( IllegalArgumentException e ) { assertionHelper . parseError ( action , "<STR_LIT>" + stage + "<STR_LIT>" + PanelAction . PANEL_ACTION_STAGE_TAG ) ; } } } else { assertionHelper . parseError ( xmlActions , "<STR_LIT:<>" + PanelAction . PANEL_ACTIONS_TAG + "<STR_LIT>" + PanelAction . PANEL_ACTION_TAG + "<STR_LIT:>>" ) ; } } } private List < TargetFileSet > readFileSets ( IXMLElement parent ) throws CompilerException { List < TargetFileSet > fslist = new ArrayList < TargetFileSet > ( ) ; for ( IXMLElement fileSetNode : parent . getChildrenNamed ( "<STR_LIT>" ) ) { try { fslist . add ( readFileSet ( fileSetNode ) ) ; } catch ( Exception e ) { throw new CompilerException ( e . getMessage ( ) ) ; } } return fslist ; } private TargetFileSet readFileSet ( IXMLElement fileSetNode ) throws CompilerException { TargetFileSet fs = new TargetFileSet ( ) ; fs . setTargetDir ( xmlCompilerHelper . requireAttribute ( fileSetNode , "<STR_LIT>" ) ) ; List < OsModel > osList = OsConstraintHelper . getOsList ( fileSetNode ) ; fs . setOsList ( osList ) ; fs . setOverride ( getOverrideValue ( fileSetNode ) ) ; fs . setOverrideRenameTo ( getOverrideRenameToValue ( fileSetNode ) ) ; fs . setBlockable ( getBlockableValue ( fileSetNode , osList ) ) ; fs . setAdditionals ( getAdditionals ( fileSetNode ) ) ; fs . setCondition ( fileSetNode . getAttribute ( "<STR_LIT>" ) ) ; String dir_attr = xmlCompilerHelper . requireAttribute ( fileSetNode , "<STR_LIT>" ) ; try { if ( dir_attr != null ) { fs . setDir ( FileUtil . getAbsoluteFile ( dir_attr , compilerData . getBasedir ( ) ) ) ; } dir_attr = fileSetNode . getAttribute ( "<STR_LIT:file>" ) ; if ( dir_attr != null ) { fs . setFile ( FileUtil . getAbsoluteFile ( dir_attr , compilerData . getBasedir ( ) ) ) ; } else { if ( fs . getDir ( ) == null ) { throw new CompilerException ( "<STR_LIT>" ) ; } } } catch ( Exception e ) { throw new CompilerException ( e . getMessage ( ) ) ; } String attr = fileSetNode . getAttribute ( "<STR_LIT>" ) ; if ( attr != null ) { fs . setIncludes ( attr ) ; } attr = fileSetNode . getAttribute ( "<STR_LIT>" ) ; if ( attr != null ) { fs . setExcludes ( attr ) ; } String boolval = fileSetNode . getAttribute ( "<STR_LIT>" ) ; if ( boolval != null ) { fs . setCaseSensitive ( Boolean . parseBoolean ( boolval ) ) ; } boolval = fileSetNode . getAttribute ( "<STR_LIT>" ) ; if ( boolval != null ) { fs . setDefaultexcludes ( Boolean . parseBoolean ( boolval ) ) ; } boolval = fileSetNode . getAttribute ( "<STR_LIT>" ) ; if ( boolval != null ) { fs . setFollowSymlinks ( Boolean . parseBoolean ( boolval ) ) ; } readAndAddIncludes ( fileSetNode , fs ) ; readAndAddExcludes ( fileSetNode , fs ) ; return fs ; } private void readAndAddIncludes ( IXMLElement parent , TargetFileSet fileset ) throws CompilerException { for ( IXMLElement f : parent . getChildrenNamed ( "<STR_LIT>" ) ) { fileset . createInclude ( ) . setName ( variableSubstitutor . substitute ( xmlCompilerHelper . requireAttribute ( f , "<STR_LIT:name>" ) ) ) ; } } private void readAndAddExcludes ( IXMLElement parent , TargetFileSet fileset ) throws CompilerException { for ( IXMLElement f : parent . getChildrenNamed ( "<STR_LIT>" ) ) { fileset . createExclude ( ) . setName ( variableSubstitutor . substitute ( xmlCompilerHelper . requireAttribute ( f , "<STR_LIT:name>" ) ) ) ; } } } </s>
|
<s> package com . izforge . izpack . compiler . container . provider ; import org . apache . commons . cli . ParseException ; import org . picocontainer . injectors . Provider ; import com . izforge . izpack . compiler . cli . CliAnalyzer ; import com . izforge . izpack . compiler . container . CompilerContainer ; import com . izforge . izpack . compiler . data . CompilerData ; public class CompilerDataProvider implements Provider { private String [ ] args ; public CompilerDataProvider ( String [ ] args ) { this . args = args ; } public CompilerData provide ( CliAnalyzer cliAnalyzer , CompilerContainer compilerContainer ) throws ParseException { CompilerData compilerData = cliAnalyzer . printAndParseArgs ( args ) ; compilerContainer . addConfig ( "<STR_LIT>" , compilerData . getInstallFile ( ) ) ; return compilerData ; } } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.