text
stringlengths 30
1.67M
|
|---|
<s> package com . izforge . izpack . util . xmlmerge ; public class ParseException extends AbstractXmlMergeException { public ParseException ( String message ) { super ( message ) ; } public ParseException ( String message , Throwable cause ) { super ( message , cause ) ; } public ParseException ( Throwable cause ) { super ( cause ) ; } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge ; import org . jdom . Element ; public interface Action extends Operation { void perform ( Element originalElement , Element patchElement , Element outputParentElement ) throws AbstractXmlMergeException ; } </s>
|
<s> package com . izforge . izpack . util . xmlmerge ; import org . jdom . Element ; public interface Mapper extends Operation { public Element map ( Element patchElement ) ; } </s>
|
<s> package com . izforge . izpack . util . xmlmerge ; public interface MergeAction extends Action { public void setMapperFactory ( OperationFactory factory ) ; public void setMatcherFactory ( OperationFactory factory ) ; public void setActionFactory ( OperationFactory factory ) ; } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . factory ; import org . jdom . Element ; import org . jdom . Namespace ; import com . izforge . izpack . util . xmlmerge . AbstractXmlMergeException ; import com . izforge . izpack . util . xmlmerge . Operation ; import com . izforge . izpack . util . xmlmerge . OperationFactory ; public class AttributeOperationFactory implements OperationFactory { private Operation m_defaultOperation ; private Namespace m_namespace ; private String m_keyword ; private OperationResolver m_resolver ; public AttributeOperationFactory ( Operation defaultOperation , OperationResolver resolver , String keyword , String namespace ) { this . m_defaultOperation = defaultOperation ; this . m_keyword = keyword ; this . m_resolver = resolver ; this . m_namespace = Namespace . getNamespace ( namespace ) ; } @ Override public Operation getOperation ( Element originalElement , Element modifiedElement ) throws AbstractXmlMergeException { if ( modifiedElement == null ) { return m_defaultOperation ; } String operationString = modifiedElement . getAttributeValue ( m_keyword , m_namespace ) ; if ( operationString != null ) { return m_resolver . resolve ( operationString ) ; } else { return m_defaultOperation ; } } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . factory ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . AbstractXmlMergeException ; import com . izforge . izpack . util . xmlmerge . Operation ; import com . izforge . izpack . util . xmlmerge . OperationFactory ; public class DiffOperationFactory implements OperationFactory { OperationFactory m_onlyInOriginalOperationFactory ; OperationFactory m_onlyInPatchOperationFactory ; OperationFactory m_inBothOperationFactory ; public void setInBothOperationFactory ( OperationFactory inBothOperationFactory ) { this . m_inBothOperationFactory = inBothOperationFactory ; } public void setOnlyInOriginalOperationFactory ( OperationFactory onlyInOriginalOperationFactory ) { this . m_onlyInOriginalOperationFactory = onlyInOriginalOperationFactory ; } public void setOnlyInPatchOperationFactory ( OperationFactory onlyInPatchOperationFactory ) { this . m_onlyInPatchOperationFactory = onlyInPatchOperationFactory ; } @ Override public Operation getOperation ( Element originalElement , Element patchElement ) throws AbstractXmlMergeException { if ( originalElement != null && patchElement == null ) { return m_onlyInOriginalOperationFactory . getOperation ( originalElement , null ) ; } if ( originalElement == null && patchElement != null ) { return m_onlyInPatchOperationFactory . getOperation ( null , patchElement ) ; } if ( originalElement != null && patchElement != null ) { return m_inBothOperationFactory . getOperation ( originalElement , patchElement ) ; } throw new IllegalArgumentException ( ) ; } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . factory ; import java . lang . reflect . Field ; import com . izforge . izpack . util . xmlmerge . ConfigurationException ; import com . izforge . izpack . util . xmlmerge . Operation ; public class OperationResolver { Class m_constantClass ; public OperationResolver ( Class class1 ) { m_constantClass = class1 ; } public Operation resolve ( String aliasOrClassName ) throws ConfigurationException { Field field = null ; try { field = m_constantClass . getField ( aliasOrClassName . toUpperCase ( ) ) ; } catch ( NoSuchFieldException e ) { try { return ( Operation ) Class . forName ( aliasOrClassName ) . newInstance ( ) ; } catch ( InstantiationException e1 ) { throw new ConfigurationException ( "<STR_LIT>" + aliasOrClassName ) ; } catch ( IllegalAccessException e1 ) { throw new ConfigurationException ( "<STR_LIT>" + aliasOrClassName ) ; } catch ( ClassNotFoundException e1 ) { throw new ConfigurationException ( "<STR_LIT>" + aliasOrClassName ) ; } catch ( ClassCastException e1 ) { throw new ConfigurationException ( "<STR_LIT>" + aliasOrClassName ) ; } } try { return ( Operation ) field . get ( null ) ; } catch ( IllegalAccessException e ) { throw new ConfigurationException ( e ) ; } } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . factory ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . Operation ; import com . izforge . izpack . util . xmlmerge . OperationFactory ; public class StaticOperationFactory implements OperationFactory { Operation m_operation ; public StaticOperationFactory ( Operation operation ) { this . m_operation = operation ; } @ Override public Operation getOperation ( Element originalElement , Element modifiedElement ) { return m_operation ; } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . factory ; import java . util . HashMap ; import java . util . Map ; import org . jaxen . JaxenException ; import org . jaxen . jdom . JDOMXPath ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . AbstractXmlMergeException ; import com . izforge . izpack . util . xmlmerge . MatchException ; import com . izforge . izpack . util . xmlmerge . Operation ; import com . izforge . izpack . util . xmlmerge . OperationFactory ; public class XPathOperationFactory implements OperationFactory { Map < String , Operation > m_map = new HashMap < String , Operation > ( ) ; Operation m_defaultOperation ; public void setOperationMap ( Map < String , Operation > map ) { this . m_map = map ; } public void setDefaultOperation ( Operation operation ) { this . m_defaultOperation = operation ; } @ Override public Operation getOperation ( Element originalElement , Element patchElement ) throws AbstractXmlMergeException { for ( String xPath : m_map . keySet ( ) ) { if ( matches ( originalElement , xPath ) || matches ( patchElement , xPath ) ) { return m_map . get ( xPath ) ; } } return m_defaultOperation ; } private boolean matches ( Element element , String xPathString ) throws AbstractXmlMergeException { if ( element == null ) { return false ; } try { JDOMXPath xPath = new JDOMXPath ( xPathString ) ; boolean result = xPath . selectNodes ( element . getParent ( ) ) . contains ( element ) ; return result ; } catch ( JaxenException e ) { throw new MatchException ( element , e ) ; } } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge ; import java . io . File ; import java . io . InputStream ; import org . w3c . dom . Document ; public interface XmlMerge { public InputStream merge ( InputStream [ ] sources ) throws AbstractXmlMergeException ; public void merge ( File [ ] sources , File target ) throws AbstractXmlMergeException ; public Document merge ( Document [ ] sources ) throws AbstractXmlMergeException ; public String merge ( String [ ] sources ) throws AbstractXmlMergeException ; public void setRootMergeAction ( MergeAction rootMergeAction ) ; public void setRootMapper ( Mapper rootMapper ) ; } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . mapper ; import java . util . Iterator ; import java . util . List ; import org . jdom . Attribute ; import org . jdom . Element ; import org . jdom . Namespace ; import com . izforge . izpack . util . xmlmerge . Mapper ; public class NamespaceFilterMapper implements Mapper { Namespace m_namespace ; public NamespaceFilterMapper ( String filteredNamespace ) { this . m_namespace = Namespace . getNamespace ( filteredNamespace ) ; } @ Override public Element map ( Element patchElement ) { if ( patchElement == null ) { return null ; } if ( patchElement . getNamespace ( ) . equals ( m_namespace ) ) { return null ; } else { return filterAttributes ( patchElement ) ; } } private Element filterAttributes ( Element element ) { Element result = ( Element ) element . clone ( ) ; List < Attribute > attributes = result . getAttributes ( ) ; Iterator < Attribute > it = attributes . iterator ( ) ; while ( it . hasNext ( ) ) { Attribute attr = it . next ( ) ; if ( attr . getNamespace ( ) . equals ( m_namespace ) ) { it . remove ( ) ; } } return result ; } public void setFilteredNamespace ( Namespace namespace ) { this . m_namespace = namespace ; } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . mapper ; public class StandardMappers { public static final IdentityMapper IDENTITY = new IdentityMapper ( ) ; } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . mapper ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . Mapper ; public class IdentityMapper implements Mapper { @ Override public Element map ( Element patchElement ) { if ( patchElement == null ) { return null ; } return ( Element ) patchElement . clone ( ) ; } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . matcher ; public class NameAttributeMatcher extends AbstractAttributeMatcher { @ Override protected final String getAttributeName ( ) { return "<STR_LIT:name>" ; } @ Override protected boolean ignoreCaseElementName ( ) { return true ; } @ Override protected boolean ignoreCaseAttributeName ( ) { return true ; } @ Override protected boolean ignoreCaseAttributeValue ( ) { return true ; } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . matcher ; public class StandardMatchers { public static final TagMatcher TAG = new TagMatcher ( ) ; public static final AttributeMatcher ATTRIBUTE = new AttributeMatcher ( ) ; public static final IdAttributeMatcher ID_ATTRIBUTE = new IdAttributeMatcher ( ) ; public static final NameAttributeMatcher NAME_ATTRIBUTE = new NameAttributeMatcher ( ) ; public static final SkipMatcher SKIP = new SkipMatcher ( ) ; } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . matcher ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . Matcher ; public abstract class AbstractTagMatcher implements Matcher { protected abstract boolean ignoreCaseElementName ( ) ; @ Override public boolean matches ( Element originalElement , Element patchElement ) { return equalsString ( originalElement . getQualifiedName ( ) , patchElement . getQualifiedName ( ) , ignoreCaseElementName ( ) ) ; } protected static boolean equalsString ( String s1 , String s2 , boolean ignoreCase ) { if ( ignoreCase ) { return s1 . equalsIgnoreCase ( s2 ) ; } else { return s1 . equals ( s2 ) ; } } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . matcher ; public class AttributeMatcher extends AbstractAttributeMatcher { @ Override protected boolean ignoreCaseAttributeName ( ) { return true ; } @ Override protected boolean ignoreCaseAttributeValue ( ) { return true ; } @ Override protected String getAttributeName ( ) { return null ; } @ Override protected boolean ignoreCaseElementName ( ) { return true ; } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . matcher ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . Matcher ; public class SkipMatcher implements Matcher { @ Override public boolean matches ( Element originalElement , Element patchElement ) { return false ; } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . matcher ; public class IdAttributeMatcher extends AbstractAttributeMatcher { @ Override protected final String getAttributeName ( ) { return "<STR_LIT:id>" ; } @ Override protected boolean ignoreCaseElementName ( ) { return true ; } @ Override protected boolean ignoreCaseAttributeName ( ) { return true ; } @ Override protected boolean ignoreCaseAttributeValue ( ) { return true ; } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . matcher ; public class TagMatcher extends AbstractTagMatcher { @ Override protected boolean ignoreCaseElementName ( ) { return true ; } } </s>
|
<s> package com . izforge . izpack . util . xmlmerge . matcher ; import java . util . List ; import org . jdom . Attribute ; import org . jdom . Element ; public abstract class AbstractAttributeMatcher extends AbstractTagMatcher { protected abstract boolean ignoreCaseAttributeName ( ) ; protected abstract boolean ignoreCaseAttributeValue ( ) ; protected abstract String getAttributeName ( ) ; @ Override public boolean matches ( Element originalElement , Element patchElement ) { if ( super . matches ( originalElement , patchElement ) ) { List < Attribute > origAttList = originalElement . getAttributes ( ) ; List < Attribute > patchAttList = patchElement . getAttributes ( ) ; if ( origAttList . size ( ) == <NUM_LIT:0> && patchAttList . size ( ) == <NUM_LIT:0> ) { return true ; } if ( origAttList . size ( ) != patchAttList . size ( ) ) { return false ; } for ( Attribute origAttribute : origAttList ) { if ( getAttributeName ( ) == null || ( getAttributeName ( ) != null && equalsString ( origAttribute . getQualifiedName ( ) , getAttributeName ( ) , ignoreCaseAttributeName ( ) ) ) ) { for ( Attribute patchAttribute : patchAttList ) { if ( ignoreCaseAttributeName ( ) ) { if ( origAttribute . getQualifiedName ( ) . equalsIgnoreCase ( patchAttribute . getQualifiedName ( ) ) ) { return equalsString ( origAttribute . getValue ( ) , patchAttribute . getValue ( ) , ignoreCaseAttributeValue ( ) ) ; } } else { if ( origAttribute . getQualifiedName ( ) . equals ( patchAttribute . getQualifiedName ( ) ) ) { return equalsString ( origAttribute . getValue ( ) , patchAttribute . getValue ( ) , ignoreCaseAttributeValue ( ) ) ; } } } } } } return false ; } } </s>
|
<s> package com . izforge . izpack . util ; import java . lang . management . ManagementFactory ; import java . lang . management . RuntimeMXBean ; import java . util . ArrayList ; import java . util . List ; class JVMHelper { public List < String > getJVMArguments ( ) { List < String > result = new ArrayList < String > ( ) ; List < String > inputArguments = getInputArguments ( ) ; inputArguments = join ( inputArguments ) ; for ( String arg : inputArguments ) { if ( ! arg . startsWith ( "<STR_LIT>" ) && ! arg . equals ( "<STR_LIT>" ) && ! arg . startsWith ( "<STR_LIT>" ) && ! arg . startsWith ( "<STR_LIT>" ) && ! arg . startsWith ( "<STR_LIT>" ) && ! arg . startsWith ( "<STR_LIT>" ) ) { result . add ( arg ) ; } } return result ; } protected List < String > getInputArguments ( ) { RuntimeMXBean bean = ManagementFactory . getRuntimeMXBean ( ) ; return bean . getInputArguments ( ) ; } protected List < String > join ( List < String > arguments ) { List < String > result = new ArrayList < String > ( ) ; for ( int i = <NUM_LIT:0> ; i < arguments . size ( ) ; ) { String arg = arguments . get ( i ) ; ++ i ; while ( i < arguments . size ( ) && ! arguments . get ( i ) . startsWith ( "<STR_LIT:->" ) ) { arg = arg + "<STR_LIT:U+0020>" + arguments . get ( i ) ; ++ i ; } result . add ( arg ) ; } return result ; } } </s>
|
<s> package com . izforge . izpack . util ; import java . io . PrintWriter ; import java . io . StringWriter ; import java . text . MessageFormat ; import java . util . Date ; import java . util . logging . Formatter ; import java . util . logging . LogRecord ; public class LogFormatter extends Formatter { Date date = new Date ( ) ; private final static String format = "<STR_LIT>" ; private final String lineSeparator = System . getProperty ( "<STR_LIT>" ) ; private MessageFormat formatter ; private Object args [ ] = new Object [ <NUM_LIT:1> ] ; public synchronized String format ( LogRecord record ) { StringBuffer sb = new StringBuffer ( ) ; date . setTime ( record . getMillis ( ) ) ; args [ <NUM_LIT:0> ] = date ; StringBuffer text = new StringBuffer ( ) ; if ( formatter == null ) { formatter = new MessageFormat ( format ) ; } formatter . format ( args , text , null ) ; sb . append ( text ) ; sb . append ( "<STR_LIT:U+0020>" ) ; if ( Debug . isDEBUG ( ) ) { if ( record . getSourceClassName ( ) != null ) { sb . append ( record . getSourceClassName ( ) ) ; } else { sb . append ( record . getLoggerName ( ) ) ; } if ( record . getSourceMethodName ( ) != null ) { sb . append ( "<STR_LIT:U+0020>" ) ; sb . append ( record . getSourceMethodName ( ) ) ; } sb . append ( lineSeparator ) ; } String message = formatMessage ( record ) ; sb . append ( record . getLevel ( ) . getLocalizedName ( ) ) ; sb . append ( "<STR_LIT::U+0020>" ) ; sb . append ( message ) ; if ( Debug . isSTACKTRACE ( ) && ( record . getThrown ( ) != null ) ) { sb . append ( lineSeparator ) ; try { StringWriter sw = new StringWriter ( ) ; PrintWriter pw = new PrintWriter ( sw ) ; record . getThrown ( ) . printStackTrace ( pw ) ; pw . close ( ) ; sb . append ( sw . toString ( ) ) ; } catch ( Exception ex ) { } } sb . append ( lineSeparator ) ; return sb . toString ( ) ; } } </s>
|
<s> package com . izforge . izpack . util ; import com . izforge . izpack . api . event . ProgressListener ; @ Deprecated public interface ExtendedUIProgressHandler extends ProgressListener { static final int BEFORE = <NUM_LIT:0> ; static final int AFTER = <NUM_LIT:1> ; } </s>
|
<s> package com . izforge . izpack . util . unix ; import com . izforge . izpack . util . FileExecutor ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileWriter ; import java . io . IOException ; import java . util . Date ; public class ShellScript { private final static String Author = "<STR_LIT>" ; private final static String Generator = "<STR_LIT>" + ShellScript . class . getName ( ) ; private final static String SCM_ID = "<STR_LIT>" ; private final static String Revision = "<STR_LIT>" ; private final static String CommentPre = "<STR_LIT>" ; private final static String H = CommentPre ; private final static String lf = "<STR_LIT:n>" ; private final static String lh = lf + H ; private final static String explanation = lh + "<STR_LIT>" + lh + "<STR_LIT>" + lh + "<STR_LIT>" + lf ; private static String currentDateMsg = "<STR_LIT>" + new Date ( ) . toString ( ) ; private final static String header = lf + explanation + lf + H + Generator + lf + H + SCM_ID + lf + H + Author + lf + H + Revision + lf + H + currentDateMsg + lf + lf ; private StringBuffer content = new StringBuffer ( ) ; private String itsLocation ; private String itsShell ; public final static String SH = "<STR_LIT>" ; public final static String BOURNE_SHELL = SH ; public final static String BASH = "<STR_LIT>" ; public final static String BOURNE_AGAIN_SHELL = BASH ; public ShellScript ( String aShell ) { if ( null != aShell ) { setShell ( aShell ) ; content . append ( "<STR_LIT>" ) . append ( getShell ( ) ) ; content . append ( header ) ; } } public ShellScript ( ) { this ( SH ) ; } public void setShell ( String aShell ) { itsShell = aShell ; } public String getShell ( ) { return itsShell ; } public void append ( Object anObject ) { content . append ( anObject ) ; } public void append ( char aChar ) { content . append ( aChar ) ; } public void append ( String [ ] anArray ) { for ( int i = <NUM_LIT:0> ; i < anArray . length ; i ++ ) { String string = anArray [ i ] ; append ( string ) ; if ( anArray . length > i ) { append ( '<CHAR_LIT:U+0020>' ) ; } } } public void appendln ( String [ ] anArray ) { for ( int i = <NUM_LIT:0> ; i < anArray . length ; i ++ ) { String string = anArray [ i ] ; append ( string ) ; if ( anArray . length > i ) { append ( '<CHAR_LIT:U+0020>' ) ; } } appendln ( ) ; } public void appendln ( Object anObject ) { append ( anObject ) ; append ( lf ) ; } public void appendln ( char aChar ) { append ( aChar ) ; append ( lf ) ; } public void appendln ( ) { append ( lf ) ; } public StringBuffer getContent ( ) { return content ; } public String getContentAsString ( ) { return content . toString ( ) ; } public String toString ( ) { StringBuffer result = new StringBuffer ( ) ; result . append ( getClass ( ) . getName ( ) ) ; result . append ( '<STR_LIT:\n>' ) ; result . append ( itsLocation ) ; result . append ( '<STR_LIT:\n>' ) ; result . append ( content ) ; return result . toString ( ) ; } public void write ( String aDestination ) { itsLocation = aDestination ; try { BufferedWriter writer = new BufferedWriter ( new FileWriter ( aDestination ) ) ; writer . write ( content . toString ( ) ) ; writer . write ( lh + aDestination + lf ) ; writer . flush ( ) ; writer . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } public String exec ( String itsParams ) { FileExecutor . getExecOutput ( new String [ ] { UnixHelper . getCustomCommand ( "<STR_LIT>" ) , "<STR_LIT>" , itsLocation } ) ; if ( itsParams != null ) { return FileExecutor . getExecOutput ( new String [ ] { itsLocation , itsParams } ) ; } else { return FileExecutor . getExecOutput ( new String [ ] { itsLocation } ) ; } } public String exec ( ) { return exec ( null ) ; } public static String execute ( String aShell , StringBuffer lines , String aLocation , String itsParams ) { ShellScript script = new ShellScript ( ( aShell == null ) ? "<STR_LIT>" : aShell ) ; script . append ( lines ) ; script . write ( aLocation ) ; return ( itsParams == null ) ? script . exec ( ) : script . exec ( itsParams ) ; } public static String execute ( StringBuffer lines , String aLocation ) { return ShellScript . execute ( null , lines , aLocation , null ) ; } public static String execAndDelete ( String aShell , StringBuffer lines , String aLocation , String itsParams ) { String result = execute ( aShell , lines , aLocation , itsParams ) ; File location = new File ( aLocation ) ; try { location . delete ( ) ; } catch ( Exception e ) { location . deleteOnExit ( ) ; } return result ; } public static String execAndDelete ( StringBuffer lines , String aLocation ) { return execAndDelete ( null , lines , aLocation , null ) ; } public static void main ( String [ ] args ) { } public void delete ( ) { if ( itsLocation != null ) { File location = new File ( itsLocation ) ; try { location . delete ( ) ; } catch ( Exception e ) { location . deleteOnExit ( ) ; } } } } </s>
|
<s> package com . izforge . izpack . util . unix ; import com . izforge . izpack . util . FileExecutor ; import java . io . File ; import java . io . IOException ; import java . util . StringTokenizer ; public class UnixUser { private String itsName ; private String itsPasswdDigest ; private String itsId ; private String itsGid ; private String itsDescription ; private String itsHome ; private String itsShell ; private static String XDGDesktopFolderNameScriptFilename ; private static File XDGDesktopFolderNameScript ; public String getName ( ) { return itsName ; } public String getPasswdDigest ( ) { return itsPasswdDigest ; } public String getId ( ) { return itsId ; } public String getGid ( ) { return itsGid ; } public String getDescription ( ) { return itsDescription ; } public String getHome ( ) { return itsHome . trim ( ) ; } public String getShell ( ) { return itsShell ; } public UnixUser fromEtcPasswdLine ( String anEtcPasswdLine ) { if ( anEtcPasswdLine == null ) { return null ; } StringTokenizer usersToken = new StringTokenizer ( anEtcPasswdLine , "<STR_LIT::>" ) ; UnixUser user = new UnixUser ( ) ; if ( usersToken . hasMoreTokens ( ) ) { user . itsName = usersToken . nextToken ( ) ; } if ( usersToken . hasMoreTokens ( ) ) { user . itsPasswdDigest = usersToken . nextToken ( ) ; } if ( usersToken . hasMoreTokens ( ) ) { user . itsId = usersToken . nextToken ( ) ; } if ( usersToken . hasMoreTokens ( ) ) { user . itsGid = usersToken . nextToken ( ) ; } if ( usersToken . hasMoreTokens ( ) ) { user . itsDescription = usersToken . nextToken ( ) ; } if ( usersToken . hasMoreTokens ( ) ) { user . itsHome = usersToken . nextToken ( ) ; } if ( usersToken . hasMoreTokens ( ) ) { user . itsShell = usersToken . nextToken ( ) ; } return user ; } public String getCreatedXDGDesktopFolderNameScriptFilename ( ) { ShellScript sh = new ShellScript ( ) ; sh . appendln ( "<STR_LIT>" + getHome ( ) + File . separator + "<STR_LIT>" + File . separator + "<STR_LIT>" ) ; sh . appendln ( ) ; sh . appendln ( "<STR_LIT>" ) ; String pseudoUnique = this . getClass ( ) . getName ( ) + Long . toString ( System . currentTimeMillis ( ) ) ; String scriptFilename = null ; try { scriptFilename = File . createTempFile ( pseudoUnique , "<STR_LIT>" ) . toString ( ) ; } catch ( IOException e ) { scriptFilename = System . getProperty ( "<STR_LIT>" , "<STR_LIT>" ) + "<STR_LIT:/>" + pseudoUnique + "<STR_LIT>" ; e . printStackTrace ( ) ; } sh . write ( scriptFilename ) ; return scriptFilename ; } public String getXdgDesktopfolder ( ) { File configFile = new File ( getHome ( ) + File . separator + "<STR_LIT>" + File . separator + "<STR_LIT>" ) ; if ( configFile . exists ( ) ) { if ( XDGDesktopFolderNameScript == null ) { XDGDesktopFolderNameScriptFilename = getCreatedXDGDesktopFolderNameScriptFilename ( ) ; } FileExecutor . getExecOutput ( new String [ ] { UnixHelper . getCustomCommand ( "<STR_LIT>" ) , "<STR_LIT>" , XDGDesktopFolderNameScriptFilename } , true ) ; String xdgDesktopfolder = FileExecutor . getExecOutput ( new String [ ] { XDGDesktopFolderNameScriptFilename } , true ) . trim ( ) ; new File ( XDGDesktopFolderNameScriptFilename ) . delete ( ) ; return xdgDesktopfolder ; } else { return getHome ( ) + File . separator + "<STR_LIT>" ; } } public String toString ( ) { StringBuffer result = new StringBuffer ( ) ; result . append ( "<STR_LIT>" ) ; result . append ( itsName ) ; result . append ( "<STR_LIT>" ) ; result . append ( itsPasswdDigest ) ; result . append ( "<STR_LIT>" ) ; result . append ( itsId ) ; result . append ( "<STR_LIT>" ) ; result . append ( itsGid ) ; result . append ( "<STR_LIT>" ) ; result . append ( itsDescription ) ; result . append ( "<STR_LIT>" ) ; result . append ( itsHome ) ; result . append ( "<STR_LIT>" ) ; result . append ( itsShell ) ; return result . toString ( ) ; } public static void main ( String [ ] args ) { System . out . println ( new UnixUser ( ) . fromEtcPasswdLine ( "<STR_LIT>" ) ) ; System . out . println ( new UnixUser ( ) . fromEtcPasswdLine ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . util . unix ; import com . izforge . izpack . util . FileExecutor ; import java . io . * ; import java . util . ArrayList ; public class UnixHelper { public static String whichCommand = FileExecutor . getExecOutput ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } , false ) . trim ( ) ; public final static String VERSION = "<STR_LIT>" ; public static ArrayList < String > getEtcPasswdArray ( ) { ArrayList < String > result = new ArrayList < String > ( ) ; String line = "<STR_LIT>" ; BufferedReader reader = null ; try { reader = new BufferedReader ( new FileReader ( UnixConstants . etcPasswd ) ) ; while ( ( line = reader . readLine ( ) ) != null ) { result . add ( line ) ; } } catch ( Exception e ) { } finally { try { if ( reader != null ) { reader . close ( ) ; } } catch ( Exception ignore ) { } } return result ; } public static ArrayList < String > getYpPasswdArray ( ) { ArrayList < String > result = new ArrayList < String > ( ) ; String line = "<STR_LIT>" ; BufferedReader reader = null ; String ypcommand = getYpCatCommand ( ) ; if ( ypcommand != null && ypcommand . length ( ) > <NUM_LIT:0> ) { try { reader = new BufferedReader ( new StringReader ( FileExecutor . getExecOutput ( new String [ ] { ypcommand , "<STR_LIT>" } ) ) ) ; while ( ( line = reader . readLine ( ) ) != null ) { result . add ( line ) ; } } catch ( Exception e ) { } finally { try { if ( reader != null ) { reader . close ( ) ; } } catch ( Exception exception ) { } } } return result ; } public static boolean kdeIsInstalled ( ) { FileExecutor fileExecutor = new FileExecutor ( ) ; String [ ] execOut = new String [ <NUM_LIT:2> ] ; int execResult = fileExecutor . executeCommand ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } , execOut ) ; return execResult == <NUM_LIT:0> ; } public static String getWhichCommand ( ) { return whichCommand ; } public static String getCpCommand ( ) { return FileExecutor . getExecOutput ( new String [ ] { getWhichCommand ( ) , "<STR_LIT>" } ) . trim ( ) ; } public static String getSuCommand ( ) { return FileExecutor . getExecOutput ( new String [ ] { getWhichCommand ( ) , "<STR_LIT>" } ) . trim ( ) ; } public static String getRmCommand ( ) { return FileExecutor . getExecOutput ( new String [ ] { whichCommand , "<STR_LIT>" } ) . trim ( ) ; } public static String getYpCatCommand ( ) { return FileExecutor . getExecOutput ( new String [ ] { whichCommand , "<STR_LIT>" } ) . trim ( ) ; } public static String getCustomCommand ( String aCommand ) { return FileExecutor . getExecOutput ( new String [ ] { whichCommand , aCommand } ) . trim ( ) ; } public static void main ( String [ ] args ) { System . out . println ( "<STR_LIT>" + UnixHelper . class . getName ( ) + VERSION ) ; System . out . println ( "<STR_LIT>" + getWhichCommand ( ) + "<STR_LIT:'>" ) ; System . out . println ( "<STR_LIT>" + getSuCommand ( ) ) ; System . out . println ( "<STR_LIT>" + getRmCommand ( ) ) ; System . out . println ( "<STR_LIT>" + getCpCommand ( ) ) ; System . out . println ( "<STR_LIT>" + getYpCatCommand ( ) ) ; System . out . println ( "<STR_LIT>" + getCustomCommand ( "<STR_LIT>" ) ) ; File tempFile = null ; try { tempFile = File . createTempFile ( UnixHelper . class . getName ( ) , Long . toString ( System . currentTimeMillis ( ) ) + "<STR_LIT>" ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } System . out . println ( "<STR_LIT>" + tempFile . toString ( ) ) ; System . out . println ( "<STR_LIT>" + tempFile . getName ( ) ) ; String username = System . getProperty ( "<STR_LIT>" ) ; if ( "<STR_LIT:root>" . equals ( username ) ) { try { BufferedWriter writer = new BufferedWriter ( new FileWriter ( tempFile ) ) ; writer . write ( "<STR_LIT>" ) ; writer . flush ( ) ; writer . close ( ) ; if ( tempFile . exists ( ) ) { System . out . println ( "<STR_LIT>" + tempFile + "<STR_LIT>" ) ; } else { System . out . println ( "<STR_LIT>" + tempFile + "<STR_LIT>" ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } String destfilename = "<STR_LIT>" + File . separator + "<STR_LIT>" + File . separator + tempFile . getName ( ) ; System . out . println ( "<STR_LIT>" + tempFile . toString ( ) + "<STR_LIT:U+0020toU+0020>" + destfilename ) ; ShellScript script = new ShellScript ( "<STR_LIT>" ) ; script . append ( getSuCommand ( ) + "<STR_LIT:U+0020>" + "<STR_LIT>" + "<STR_LIT:U+0020>" + "<STR_LIT>" + "<STR_LIT:U+0020>" + "<STR_LIT:\">" + getCpCommand ( ) + "<STR_LIT:U+0020>" + tempFile . toString ( ) + "<STR_LIT:U+0020>" + destfilename + "<STR_LIT:\">" ) ; String shLocation = "<STR_LIT>" ; try { shLocation = File . createTempFile ( UnixHelper . class . getName ( ) , Long . toString ( System . currentTimeMillis ( ) ) + "<STR_LIT>" ) . toString ( ) ; } catch ( Exception x ) { x . printStackTrace ( ) ; } script . write ( shLocation ) ; script . exec ( ) ; } else { System . out . println ( "<STR_LIT>" + username + "<STR_LIT>" ) ; } } } </s>
|
<s> package com . izforge . izpack . util . unix ; public class UnixConstants { public static String etcPasswd = "<STR_LIT>" ; public UnixConstants ( ) { } public static void main ( String [ ] args ) { } } </s>
|
<s> package com . izforge . izpack . util . unix ; import com . izforge . izpack . util . StringTool ; import java . io . File ; import java . util . ArrayList ; public class UnixUsers extends ArrayList < UnixUser > { private static final long serialVersionUID = - <NUM_LIT> ; public UnixUsers ( ) { fromUsersArrayList ( getEtcPasswdUsersAsArrayList ( ) ) ; fromUsersArrayList ( getYpPasswdUsersAsArrayList ( ) ) ; } public ArrayList < UnixUser > getUsersWithValidShells ( ) { ArrayList < UnixUser > result = new ArrayList < UnixUser > ( ) ; for ( int idx = <NUM_LIT:0> ; idx < size ( ) ; idx ++ ) { UnixUser user = get ( idx ) ; if ( ( user . getShell ( ) != null ) && user . getShell ( ) . trim ( ) . endsWith ( "<STR_LIT>" ) ) { result . add ( user ) ; } } return result ; } public ArrayList < UnixUser > getUsersWithValidShellsAndExistingHomes ( ) { ArrayList < UnixUser > result = new ArrayList < UnixUser > ( ) ; ArrayList < UnixUser > usersWithValidShells = getUsersWithValidShells ( ) ; for ( UnixUser user : usersWithValidShells ) { if ( ( user . getHome ( ) != null ) && new File ( user . getHome ( ) . trim ( ) ) . exists ( ) ) { result . add ( user ) ; } } return result ; } public ArrayList < UnixUser > _getUsersWithValidShellsExistingHomesAndDesktops ( ) { ArrayList < UnixUser > result = new ArrayList < UnixUser > ( ) ; ArrayList < UnixUser > usersWithValidShellsAndExistingHomes = getUsersWithValidShellsAndExistingHomes ( ) ; for ( UnixUser user : usersWithValidShellsAndExistingHomes ) { if ( ( user . getHome ( ) != null ) && new File ( user . getXdgDesktopfolder ( ) ) . exists ( ) ) { result . add ( user ) ; } } return result ; } public ArrayList < String > getValidUsersDesktopFolders ( ) { ArrayList < String > result = new ArrayList < String > ( ) ; ArrayList < UnixUser > validUserDesktops = getUsersWithValidShellsExistingHomesAndDesktops ( ) ; for ( UnixUser user : validUserDesktops ) { if ( user . getHome ( ) != null ) { File DesktopFolder = new File ( user . getXdgDesktopfolder ( ) ) ; if ( DesktopFolder . exists ( ) && DesktopFolder . isDirectory ( ) ) { result . add ( DesktopFolder . toString ( ) ) ; } } } return result ; } public static ArrayList < UnixUser > getUsersWithValidShellsExistingHomesAndDesktops ( ) { UnixUsers users = new UnixUsers ( ) ; return users . _getUsersWithValidShellsExistingHomesAndDesktops ( ) ; } private void fromUsersArrayList ( ArrayList < String > anUsersArrayList ) { for ( String anAnUsersArrayList : anUsersArrayList ) { add ( new UnixUser ( ) . fromEtcPasswdLine ( anAnUsersArrayList ) ) ; } } public static ArrayList < String > getEtcPasswdUsersAsArrayList ( ) { ArrayList < String > result = new ArrayList < String > ( ) ; ArrayList < String > etcPasswdArray = UnixHelper . getEtcPasswdArray ( ) ; for ( String line : etcPasswdArray ) { result . add ( line ) ; } return result ; } public static ArrayList < String > getYpPasswdUsersAsArrayList ( ) { return UnixHelper . getYpPasswdArray ( ) ; } public static String getUsersColonString ( ) { ArrayList < String > usersArrayList = getEtcPasswdUsersAsArrayList ( ) ; String retValue = "<STR_LIT>" ; for ( String userline : usersArrayList ) { retValue += ( userline . substring ( <NUM_LIT:0> , userline . indexOf ( "<STR_LIT::>" ) ) + "<STR_LIT::>" ) ; } if ( retValue . endsWith ( "<STR_LIT::>" ) ) { retValue = retValue . substring ( <NUM_LIT:0> , retValue . length ( ) - <NUM_LIT:1> ) ; } return retValue ; } public static void main ( String [ ] args ) { System . out . println ( "<STR_LIT>" ) ; UnixUsers users = new UnixUsers ( ) ; for ( Object user : users ) { System . out . println ( ( ( UnixUser ) user ) . getName ( ) ) ; } System . out . println ( StringTool . listToString ( getUsersWithValidShellsExistingHomesAndDesktops ( ) ) ) ; } } </s>
|
<s> package com . izforge . izpack . util ; import java . io . * ; public class MonitorInputStream implements Runnable { private BufferedReader reader ; private BufferedWriter writer ; private boolean shouldStop = false ; public MonitorInputStream ( Reader in , Writer out ) { this . reader = new BufferedReader ( in ) ; this . writer = new BufferedWriter ( out ) ; } public void doStop ( ) { this . shouldStop = true ; } public void run ( ) { try { String line ; while ( ( line = this . reader . readLine ( ) ) != null ) { this . writer . write ( line ) ; this . writer . newLine ( ) ; this . writer . flush ( ) ; if ( this . shouldStop ) { return ; } } } catch ( IOException ioe ) { ioe . printStackTrace ( System . out ) ; } } } </s>
|
<s> package com . izforge . izpack . util ; import java . io . * ; import java . text . SimpleDateFormat ; import java . util . * ; public class LibraryRemover { private static final String [ ] SANDBOX_CONTENT = { "<STR_LIT>" } ; private static final String BASE_KEY = "<STR_LIT>" ; private static final String PHASE_KEY = "<STR_LIT>" ; private static final String JAVA_HOME = System . getProperty ( "<STR_LIT>" ) ; private static final String PREFIX = "<STR_LIT>" ; private int phase = <NUM_LIT:0> ; private File logFile = null ; private File sandbox = null ; private File specFile = null ; private SimpleDateFormat isoPoint = new SimpleDateFormat ( "<STR_LIT>" ) ; private Date date = new Date ( ) ; private LibraryRemover ( int phase ) throws IOException { this . phase = phase ; if ( phase == <NUM_LIT:1> ) { initJavaExec ( ) ; } else { logFile = new File ( System . getProperty ( BASE_KEY ) + "<STR_LIT>" ) ; specFile = new File ( System . getProperty ( BASE_KEY ) + "<STR_LIT>" ) ; sandbox = new File ( System . getProperty ( BASE_KEY ) + "<STR_LIT>" ) ; } } public static void invoke ( List < String > temporaryFileNames ) throws IOException { LibraryRemover self = new LibraryRemover ( <NUM_LIT:1> ) ; self . invoke1 ( temporaryFileNames ) ; } private void initJavaExec ( ) throws IOException { try { Process process = Runtime . getRuntime ( ) . exec ( javaCommand ( ) ) ; new StreamProxy ( process . getErrorStream ( ) , "<STR_LIT>" ) . start ( ) ; new StreamProxy ( process . getInputStream ( ) , "<STR_LIT>" ) . start ( ) ; process . getOutputStream ( ) . close ( ) ; process . waitFor ( ) ; } catch ( InterruptedException ie ) { throw new IOException ( "<STR_LIT>" ) ; } } private void invoke1 ( List < String > temporaryFileNames ) throws IOException { while ( true ) { logFile = File . createTempFile ( PREFIX , "<STR_LIT>" ) ; String canonicalPath = logFile . getCanonicalPath ( ) ; specFile = new File ( canonicalPath . substring ( <NUM_LIT:0> , canonicalPath . length ( ) - <NUM_LIT:4> ) + "<STR_LIT>" ) ; sandbox = new File ( canonicalPath . substring ( <NUM_LIT:0> , canonicalPath . length ( ) - <NUM_LIT:4> ) + "<STR_LIT>" ) ; if ( ! sandbox . exists ( ) ) { break ; } logFile . delete ( ) ; } if ( ! sandbox . mkdir ( ) ) { throw new RuntimeException ( "<STR_LIT>" + sandbox ) ; } sandbox = sandbox . getCanonicalFile ( ) ; logFile = logFile . getCanonicalFile ( ) ; OutputStream out = null ; InputStream in = null ; byte [ ] buf = new byte [ <NUM_LIT> ] ; int extracted = <NUM_LIT:0> ; for ( String aSANDBOX_CONTENT : SANDBOX_CONTENT ) { in = getClass ( ) . getResourceAsStream ( "<STR_LIT:/>" + aSANDBOX_CONTENT ) ; File outFile = new File ( sandbox , aSANDBOX_CONTENT ) ; File parent = outFile . getParentFile ( ) ; if ( parent != null && ! parent . exists ( ) ) { parent . mkdirs ( ) ; } out = new BufferedOutputStream ( new FileOutputStream ( outFile ) ) ; int n ; while ( ( n = in . read ( buf , <NUM_LIT:0> , buf . length ) ) > <NUM_LIT:0> ) { out . write ( buf , <NUM_LIT:0> , n ) ; } out . close ( ) ; extracted ++ ; } out = new BufferedOutputStream ( new FileOutputStream ( specFile ) ) ; BufferedWriter specWriter = new BufferedWriter ( new OutputStreamWriter ( out ) ) ; Iterator < String > iter = temporaryFileNames . iterator ( ) ; while ( iter . hasNext ( ) ) { specWriter . write ( iter . next ( ) ) ; if ( iter . hasNext ( ) ) { specWriter . newLine ( ) ; } } specWriter . flush ( ) ; out . close ( ) ; spawn ( <NUM_LIT:2> ) ; log ( "<STR_LIT>" ) ; } private ArrayList < File > getFilesList ( ) throws Exception { TreeSet < File > files = new TreeSet < File > ( Collections . reverseOrder ( ) ) ; InputStream in = new FileInputStream ( specFile ) ; InputStreamReader inReader = new InputStreamReader ( in ) ; BufferedReader reader = new BufferedReader ( inReader ) ; String read = reader . readLine ( ) ; while ( read != null ) { files . add ( new File ( read ) ) ; read = reader . readLine ( ) ; } in . close ( ) ; return new ArrayList < File > ( files ) ; } private void invoke2 ( ) { try { try { Thread . sleep ( <NUM_LIT:1000> ) ; } catch ( Exception x ) { } ArrayList < File > files = getFilesList ( ) ; log ( "<STR_LIT>" ) ; for ( File file : files ) { file . delete ( ) ; if ( file . exists ( ) ) { log ( "<STR_LIT>" + file . getCanonicalPath ( ) + "<STR_LIT>" ) ; } else { log ( "<STR_LIT:U+0020U+0020U+0020U+0020>" + file . getCanonicalPath ( ) ) ; } } log ( "<STR_LIT>" ) ; deleteTree ( sandbox ) ; specFile . delete ( ) ; } catch ( Exception e ) { log ( e ) ; } } private Process spawn ( int nextPhase ) throws IOException { String base = logFile . getAbsolutePath ( ) ; base = base . substring ( <NUM_LIT:0> , base . length ( ) - <NUM_LIT:4> ) ; String [ ] javaCmd = new String [ ] { javaCommand ( ) , "<STR_LIT>" , sandbox . getAbsolutePath ( ) , "<STR_LIT>" + BASE_KEY + "<STR_LIT:=>" + base , "<STR_LIT>" + PHASE_KEY + "<STR_LIT:=>" + nextPhase , getClass ( ) . getName ( ) } ; StringBuffer sb = new StringBuffer ( "<STR_LIT>" ) ; sb . append ( nextPhase ) . append ( "<STR_LIT::U+0020>" ) ; for ( String aJavaCmd : javaCmd ) { sb . append ( "<STR_LIT>" ) . append ( aJavaCmd ) ; } log ( sb . toString ( ) ) ; return Runtime . getRuntime ( ) . exec ( javaCmd , null , null ) ; } public static boolean deleteTree ( File file ) { if ( file . isDirectory ( ) ) { File [ ] files = file . listFiles ( ) ; for ( File file1 : files ) { deleteTree ( file1 ) ; } } return file . delete ( ) ; } private static String addExtension ( String command ) { return command + ( OsVersion . IS_WINDOWS || OsVersion . IS_OS2 ? "<STR_LIT>" : "<STR_LIT>" ) ; } private static String javaCommand ( ) { String executable = addExtension ( "<STR_LIT>" ) ; String dir = new File ( JAVA_HOME + "<STR_LIT>" ) . getAbsolutePath ( ) ; File jExecutable = new File ( dir , executable ) ; if ( ! jExecutable . exists ( ) ) { return executable ; } return jExecutable . getAbsolutePath ( ) ; } public static void main ( String [ ] args ) { try { LibraryRemover librianRemover = new LibraryRemover ( <NUM_LIT:2> ) ; librianRemover . invoke2 ( ) ; } catch ( IOException ioe ) { System . err . println ( "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" ) ; ioe . printStackTrace ( ) ; } } PrintStream log = null ; private PrintStream checkLog ( ) { try { if ( log == null ) { log = new PrintStream ( new FileOutputStream ( logFile . toString ( ) , true ) ) ; } } catch ( IOException x ) { System . err . println ( "<STR_LIT>" + phase + "<STR_LIT>" + x . getMessage ( ) ) ; x . printStackTrace ( ) ; } date . setTime ( System . currentTimeMillis ( ) ) ; return log ; } private void log ( Throwable t ) { if ( checkLog ( ) != null ) { log . println ( isoPoint . format ( date ) + "<STR_LIT>" + phase + "<STR_LIT::U+0020>" + t . getMessage ( ) ) ; t . printStackTrace ( log ) ; } } private void log ( String msg ) { if ( checkLog ( ) != null ) { log . println ( isoPoint . format ( date ) + "<STR_LIT>" + phase + "<STR_LIT::U+0020>" + msg ) ; } } public static class StreamProxy extends Thread { InputStream in ; String name ; OutputStream out ; public StreamProxy ( InputStream in , String name ) { this ( in , name , null ) ; } public StreamProxy ( InputStream in , String name , OutputStream out ) { this . in = in ; this . name = name ; this . out = out ; } public void run ( ) { try { PrintWriter printWriter = null ; if ( out != null ) { printWriter = new PrintWriter ( out ) ; } BufferedReader br = new BufferedReader ( new InputStreamReader ( in ) ) ; String line ; while ( ( line = br . readLine ( ) ) != null ) { if ( printWriter != null ) { printWriter . println ( line ) ; } } if ( printWriter != null ) { printWriter . flush ( ) ; } } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } } } } </s>
|
<s> package com . izforge . izpack . util ; public interface CleanupClient { public void cleanUp ( ) ; } </s>
|
<s> package com . izforge . izpack . util ; import java . io . IOException ; import java . io . InputStream ; import java . net . URL ; import java . util . Enumeration ; import java . util . HashMap ; import java . util . Map ; import java . util . Properties ; import java . util . Set ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . factory . ObjectFactory ; public class DefaultTargetPlatformFactory implements TargetPlatformFactory { private final ObjectFactory factory ; private final Platforms platforms ; private final Platform platform ; private Map < String , Implementations > implementations = new HashMap < String , Implementations > ( ) ; private static final Logger logger = Logger . getLogger ( DefaultTargetPlatformFactory . class . getName ( ) ) ; private static final String RESOURCE_PATH = "<STR_LIT>" ; public DefaultTargetPlatformFactory ( ObjectFactory factory , Platform platform , Platforms platforms ) { this . factory = factory ; this . platform = platform ; this . platforms = platforms ; try { Enumeration < URL > urls = getClass ( ) . getClassLoader ( ) . getResources ( RESOURCE_PATH ) ; while ( urls . hasMoreElements ( ) ) { URL url = urls . nextElement ( ) ; try { add ( url ) ; } catch ( IOException exception ) { logger . log ( Level . WARNING , exception . getMessage ( ) , exception ) ; } } } catch ( IOException exception ) { logger . log ( Level . WARNING , exception . getMessage ( ) , exception ) ; } } @ Override public < T > T create ( Class < T > clazz ) throws Exception { return create ( clazz , platform ) ; } @ Override @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public < T > T create ( Class < T > type , Platform platform ) throws Exception { Class < T > impl = getImplementation ( type , platform ) ; return factory . create ( impl ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) protected < T > Class < T > getImplementation ( Class < T > type , Platform platform ) throws ClassNotFoundException { Implementations impls = getImplementations ( type ) ; if ( impls == null ) { throw new IllegalArgumentException ( "<STR_LIT>" + type . getName ( ) ) ; } Platform match = null ; Platform fallback = null ; for ( Platform p : impls . getPlatforms ( ) ) { if ( p . equals ( platform ) ) { match = p ; break ; } else if ( platform . isA ( p ) ) { if ( fallback == null || moreSpecific ( platform , fallback , p ) ) { fallback = p ; } } } if ( match == null ) { if ( fallback != null ) { match = fallback ; } } String implName = ( match != null ) ? impls . getImplementation ( match ) : impls . getDefault ( ) ; if ( implName == null ) { throw new IllegalStateException ( "<STR_LIT>" + type . getName ( ) + "<STR_LIT>" + platform ) ; } Class impl = Class . forName ( implName ) ; if ( ! type . isAssignableFrom ( impl ) ) { throw new IllegalStateException ( impl . getName ( ) + "<STR_LIT>" + type . getName ( ) ) ; } return ( Class < T > ) impl ; } protected void add ( Properties properties , URL url ) { Parser parser = createParser ( platforms , url ) ; parser . parse ( properties , implementations ) ; } protected Parser createParser ( Platforms platforms , URL url ) { return new Parser ( platforms , url ) ; } protected Implementations getImplementations ( Class clazz ) { return implementations . get ( clazz . getName ( ) ) ; } private void add ( URL url ) throws IOException { Properties properties = new Properties ( ) ; InputStream stream = url . openStream ( ) ; try { properties . load ( stream ) ; } finally { stream . close ( ) ; } add ( properties , url ) ; } private boolean moreSpecific ( Platform requested , Platform fallback , Platform platform ) { boolean result = platform . isA ( fallback ) ; if ( ! result ) { if ( requested . getVersion ( ) != null && requested . getVersion ( ) . equals ( platform . getVersion ( ) ) && fallback . getVersion ( ) == null ) { result = true ; } } return result ; } protected static class Parser { private final Platforms platforms ; private final URL url ; public Parser ( Platforms platforms , URL url ) { this . platforms = platforms ; this . url = url ; } public void parse ( Properties properties , Map < String , Implementations > implementations ) { for ( String key : properties . stringPropertyNames ( ) ) { String [ ] interfacePlatform = key . split ( "<STR_LIT:U+002C>" ) ; if ( interfacePlatform . length >= <NUM_LIT:1> && interfacePlatform . length <= <NUM_LIT:3> ) { String iface = trimToNull ( interfacePlatform [ <NUM_LIT:0> ] ) ; String name = ( interfacePlatform . length >= <NUM_LIT:2> ) ? trimToNull ( interfacePlatform [ <NUM_LIT:1> ] ) : null ; String arch = ( interfacePlatform . length == <NUM_LIT:3> ) ? trimToNull ( interfacePlatform [ <NUM_LIT:2> ] ) : null ; String impl = trimToNull ( properties . getProperty ( key ) ) ; if ( iface == null ) { warning ( "<STR_LIT>" + key + "<STR_LIT>" + url ) ; } else if ( impl == null ) { warning ( "<STR_LIT>" + key + "<STR_LIT>" + url ) ; } else { Implementations impls = implementations . get ( iface ) ; if ( impls == null ) { impls = new Implementations ( ) ; implementations . put ( iface , impls ) ; } if ( name == null ) { if ( impls . getDefault ( ) == null ) { impls . setDefault ( impl ) ; } else { warning ( "<STR_LIT>" + impl + "<STR_LIT>" + url ) ; } } else { Platform platform = platforms . getPlatform ( name , arch ) ; if ( platform . getName ( ) == Platform . Name . UNKNOWN ) { warning ( "<STR_LIT>" + platform + "<STR_LIT>" + key + "<STR_LIT>" + url ) ; } else if ( impls . getImplementation ( platform ) == null ) { impls . addImplementation ( platform , impl ) ; } else { warning ( "<STR_LIT>" + impl + "<STR_LIT>" + platform + "<STR_LIT>" + url ) ; } } } } else { warning ( "<STR_LIT>" + key + "<STR_LIT>" + interfacePlatform . length + "<STR_LIT>" + url ) ; } } } protected void warning ( String message ) { logger . warning ( message ) ; } private String trimToNull ( String str ) { if ( str != null ) { str = str . trim ( ) ; } return ( str == null || str . length ( ) == <NUM_LIT:0> ) ? null : str ; } } protected static class Implementations { private String defaultImplementation ; private Map < Platform , String > implementations = new HashMap < Platform , String > ( ) ; public void setDefault ( String defaultImplementation ) { this . defaultImplementation = defaultImplementation ; } public String getDefault ( ) { return defaultImplementation ; } public Set < Platform > getPlatforms ( ) { return implementations . keySet ( ) ; } public String getImplementation ( Platform platform ) { return implementations . get ( platform ) ; } public void addImplementation ( Platform platform , String implementation ) { implementations . put ( platform , implementation ) ; } } } </s>
|
<s> package com . izforge . izpack . util ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . logging . Level ; import java . util . logging . Logger ; public class Console { private static final Logger logger = Logger . getLogger ( Console . class . getName ( ) ) ; private final BufferedReader in ; private final PrintWriter out ; public Console ( ) { this ( System . in , System . out ) ; } public Console ( InputStream in , OutputStream out ) { this . in = new BufferedReader ( new InputStreamReader ( in ) ) ; this . out = new PrintWriter ( out , true ) ; } public String readLine ( ) throws IOException { return in . readLine ( ) ; } public void print ( String message ) { out . print ( message ) ; out . flush ( ) ; } public void println ( ) { out . println ( ) ; } public void println ( String message ) { out . println ( message ) ; } public int prompt ( String prompt , int min , int max , int eof ) { int result = <NUM_LIT:0> ; try { do { println ( prompt ) ; String value = readLine ( ) ; if ( value != null ) { try { result = Integer . valueOf ( value ) ; } catch ( NumberFormatException ignore ) { } } else { result = eof ; break ; } } while ( result < min || result > max ) ; } catch ( IOException e ) { logger . log ( Level . WARNING , e . getMessage ( ) , e ) ; result = eof ; } return result ; } public String prompt ( String prompt , String eof ) { String result ; try { print ( prompt ) ; result = readLine ( ) ; if ( result == null ) { result = eof ; } } catch ( IOException e ) { result = eof ; logger . log ( Level . WARNING , e . getMessage ( ) , e ) ; } return result ; } public String prompt ( String prompt , String [ ] values , String eof ) { while ( true ) { String input = prompt ( prompt , eof ) ; if ( input == null || input . equals ( eof ) ) { return input ; } else { for ( String value : values ) { if ( value . equalsIgnoreCase ( input ) ) { return value ; } } } } } } </s>
|
<s> package com . izforge . izpack . util . helper ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . InputStream ; import java . util . ArrayList ; import java . util . List ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . IXMLParser ; import com . izforge . izpack . api . adaptator . impl . XMLParser ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; public class SpecHelper { public static final String YES = "<STR_LIT:yes>" ; public static final String NO = "<STR_LIT>" ; private String specFilename ; private IXMLElement spec ; private boolean _haveSpec ; private final Resources resources ; private static final String PACK_KEY = "<STR_LIT>" ; private static final String PACK_NAME = "<STR_LIT:name>" ; public SpecHelper ( Resources resources ) { super ( ) ; this . resources = resources ; } public void readSpec ( String specFileName ) throws Exception { readSpec ( specFileName , null ) ; } public void readSpec ( String specFileName , VariableSubstitutor substitutor ) throws Exception { InputStream input = null ; try { input = getResource ( specFileName ) ; } catch ( Exception exception ) { _haveSpec = false ; return ; } if ( input == null ) { _haveSpec = false ; return ; } readSpec ( input , substitutor ) ; input . close ( ) ; this . specFilename = specFileName ; } public void readSpec ( InputStream input ) throws Exception { readSpec ( input , null ) ; } public void readSpec ( InputStream input , VariableSubstitutor substitutor ) throws Exception { if ( substitutor != null ) { input = substituteVariables ( input , substitutor ) ; } IXMLParser parser = new XMLParser ( ) ; spec = parser . parse ( input ) ; _haveSpec = true ; } public InputStream getResource ( String res ) { try { return resources . getInputStream ( res ) ; } catch ( ResourceNotFoundException exception ) { return null ; } } public IXMLElement getPackForName ( String packDestName ) { List < IXMLElement > packs = getSpec ( ) . getChildrenNamed ( PACK_KEY ) ; if ( packs == null ) { return ( null ) ; } for ( IXMLElement pack : packs ) { String packName = pack . getAttribute ( PACK_NAME ) ; if ( packName . equals ( packDestName ) ) { return ( pack ) ; } } return ( null ) ; } public void parseError ( IXMLElement parent , String message ) throws InstallerException { throw new InstallerException ( specFilename + "<STR_LIT::>" + parent . getLineNr ( ) + "<STR_LIT::U+0020>" + message ) ; } public boolean haveSpec ( ) { return _haveSpec ; } public IXMLElement getSpec ( ) { return spec ; } public void setSpec ( IXMLElement element ) { spec = element ; } public List < IXMLElement > getAllSubChildren ( IXMLElement root , String [ ] childdef ) { return ( getSubChildren ( root , childdef , <NUM_LIT:0> ) ) ; } private List < IXMLElement > getSubChildren ( IXMLElement root , String [ ] childdef , int depth ) { List < IXMLElement > retval = null ; List < IXMLElement > retval2 = null ; List < IXMLElement > children = root != null ? root . getChildrenNamed ( childdef [ depth ] ) : null ; if ( children == null ) { return ( null ) ; } if ( depth < childdef . length - <NUM_LIT:1> ) { for ( IXMLElement child : children ) { retval2 = getSubChildren ( child , childdef , depth + <NUM_LIT:1> ) ; if ( retval2 != null ) { if ( retval == null ) { retval = new ArrayList < IXMLElement > ( ) ; } retval . addAll ( retval2 ) ; } } } else { return ( children ) ; } return ( retval ) ; } public InputStream substituteVariables ( InputStream input , VariableSubstitutor substitutor ) throws Exception { File tempFile = File . createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) ; FileOutputStream fos = null ; tempFile . deleteOnExit ( ) ; try { fos = new FileOutputStream ( tempFile ) ; substitutor . substitute ( input , fos , null , "<STR_LIT:UTF-8>" ) ; } finally { if ( fos != null ) { fos . close ( ) ; } } return new FileInputStream ( tempFile ) ; } public boolean isAttributeYes ( IXMLElement element , String attribute , boolean defaultValue ) { String value = element . getAttribute ( attribute , ( defaultValue ? YES : NO ) ) ; if ( value . equalsIgnoreCase ( YES ) ) { return true ; } if ( value . equalsIgnoreCase ( NO ) ) { return false ; } return defaultValue ; } public String getRequiredAttribute ( IXMLElement element , String attrName ) throws InstallerException { String attr = element . getAttribute ( attrName ) ; if ( attr == null ) { parseError ( element , "<STR_LIT:<>" + element . getName ( ) + "<STR_LIT>" + attrName + "<STR_LIT>" ) ; } return ( attr ) ; } } </s>
|
<s> package com . izforge . izpack . util ; public interface TargetPlatformFactory { < T > T create ( Class < T > clazz ) throws Exception ; < T > T create ( Class < T > clazz , Platform platform ) throws Exception ; } </s>
|
<s> package com . izforge . izpack . matcher ; import java . io . IOException ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; import org . hamcrest . Description ; import org . hamcrest . Factory ; import org . hamcrest . Matcher ; import org . hamcrest . TypeSafeMatcher ; import org . hamcrest . collection . IsCollectionContaining ; import org . hamcrest . core . Is ; import com . izforge . izpack . api . merge . Mergeable ; import com . izforge . izpack . mock . MockOutputStream ; public class MergeMatcher extends TypeSafeMatcher < Mergeable > { private static final Logger logger = Logger . getLogger ( MergeMatcher . class . getName ( ) ) ; private Matcher < Iterable < String > > listMatcher ; MergeMatcher ( Matcher < Iterable < String > > matcher ) { this . listMatcher = matcher ; } @ Override public boolean matchesSafely ( Mergeable mergeable ) { try { MockOutputStream outputStream = new MockOutputStream ( ) ; mergeable . merge ( outputStream ) ; List < String > entryName = outputStream . getListEntryName ( ) ; boolean match = listMatcher . matches ( entryName ) ; if ( logger . isLoggable ( Level . FINE ) && ! match ) { logger . fine ( "<STR_LIT>" ) ; logger . fine ( "<STR_LIT>" + mergeable + "<STR_LIT>" ) ; for ( String entry : entryName ) { logger . fine ( "<STR_LIT:t>" + entry ) ; } logger . fine ( "<STR_LIT>" + match + "<STR_LIT:n>" ) ; logger . fine ( "<STR_LIT>" ) ; } return match ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } @ Override public void describeTo ( Description description ) { description . appendText ( "<STR_LIT>" ) . appendValue ( listMatcher ) ; } @ Factory public static Matcher < Mergeable > isMergeableContainingFile ( String fileName ) { return new MergeMatcher ( IsCollectionContaining . hasItem ( Is . is ( fileName ) ) ) ; } @ Factory public static Matcher < Mergeable > isMergeableMatching ( Matcher < Iterable < String > > matcher ) { return new MergeMatcher ( matcher ) ; } @ Factory public static Matcher < Mergeable > isMergeableContainingFiles ( String ... files ) { return new MergeMatcher ( IsCollectionContaining . hasItems ( files ) ) ; } } </s>
|
<s> package com . izforge . izpack . matcher ; import org . hamcrest . Description ; import org . hamcrest . Matcher ; import org . hamcrest . MatcherAssert ; import org . hamcrest . TypeSafeMatcher ; import java . io . IOException ; import java . io . ObjectInputStream ; import java . util . Enumeration ; import java . util . zip . ZipEntry ; import java . util . zip . ZipFile ; public class ObjectInputMatcher extends TypeSafeMatcher < ZipFile > { private Matcher < Object > listMatcher ; private String resourceId ; ObjectInputMatcher ( String resourceId , Matcher < Object > listMatcher ) { this . listMatcher = listMatcher ; this . resourceId = resourceId ; } @ Override public boolean matchesSafely ( ZipFile file ) { try { Object object = getObjectFromZip ( file , resourceId ) ; MatcherAssert . assertThat ( object , listMatcher ) ; return true ; } catch ( Exception e ) { throw new AssertionError ( e ) ; } } public static Object getObjectFromZip ( ZipFile file , String resourceId ) throws IOException , ClassNotFoundException { Object result = null ; Enumeration < ? extends ZipEntry > zipEntries = file . entries ( ) ; while ( zipEntries . hasMoreElements ( ) ) { ZipEntry zipEntry = zipEntries . nextElement ( ) ; if ( zipEntry . getName ( ) . equals ( resourceId ) ) { ObjectInputStream inputStream = new ObjectInputStream ( file . getInputStream ( zipEntry ) ) ; result = inputStream . readObject ( ) ; } } return result ; } public void describeTo ( Description description ) { description . appendText ( "<STR_LIT>" ) . appendValue ( listMatcher ) ; } public static ObjectInputMatcher isInputMatching ( String resourceId , Matcher < Object > objectMatcher ) { return new ObjectInputMatcher ( resourceId , objectMatcher ) ; } } </s>
|
<s> package com . izforge . izpack . matcher ; import org . hamcrest . Description ; import org . hamcrest . Matcher ; import org . hamcrest . TypeSafeMatcher ; import org . hamcrest . core . Is ; public class DuplicateMatcher extends TypeSafeMatcher < Iterable < String > > { public Matcher < String > itemMatcher ; public DuplicateMatcher ( Matcher < String > itemMatcher ) { this . itemMatcher = itemMatcher ; } @ Override public boolean matchesSafely ( Iterable < String > strings ) { boolean alreadyFound = false ; for ( String string : strings ) { if ( itemMatcher . matches ( string ) ) { if ( alreadyFound ) { return false ; } alreadyFound = true ; } } return alreadyFound ; } public void describeTo ( Description description ) { description . appendText ( "<STR_LIT>" ) . appendValue ( itemMatcher ) ; } public static DuplicateMatcher isEntryUnique ( String entry ) { return new DuplicateMatcher ( Is . is ( entry ) ) ; } } </s>
|
<s> package com . izforge . izpack . matcher ; import java . io . IOException ; import java . util . ArrayList ; import java . util . Enumeration ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; import java . util . zip . ZipEntry ; import java . util . zip . ZipFile ; import org . hamcrest . Description ; import org . hamcrest . Factory ; import org . hamcrest . Matcher ; import org . hamcrest . TypeSafeMatcher ; import org . hamcrest . collection . IsCollectionContaining ; import org . hamcrest . core . Is ; public class ZipMatcher extends TypeSafeMatcher < ZipFile > { private static final Logger logger = Logger . getLogger ( ZipMatcher . class . getName ( ) ) ; private Matcher < Iterable < String > > listMatcher ; ZipMatcher ( Matcher < Iterable < String > > matcher ) { this . listMatcher = matcher ; } @ Override public boolean matchesSafely ( ZipFile file ) { try { List < String > fileList = getFileNameListFromZip ( file ) ; boolean match = listMatcher . matches ( fileList ) ; if ( logger . isLoggable ( Level . FINE ) && ! match ) { logger . fine ( "<STR_LIT>" ) ; logger . fine ( "<STR_LIT>" + file . getName ( ) + "<STR_LIT>" ) ; for ( String f : fileList ) { logger . fine ( "<STR_LIT:t>" + f ) ; } logger . fine ( "<STR_LIT>" + match + "<STR_LIT:n>" ) ; logger . fine ( "<STR_LIT>" ) ; } return match ; } catch ( IOException e ) { throw new AssertionError ( e ) ; } } public static List < String > getFileNameListFromZip ( ZipFile file ) throws IOException { List < String > entryList = new ArrayList < String > ( ) ; Enumeration < ? extends ZipEntry > zipEntries = file . entries ( ) ; while ( zipEntries . hasMoreElements ( ) ) { ZipEntry zipEntry = zipEntries . nextElement ( ) ; entryList . add ( zipEntry . getName ( ) ) ; } return entryList ; } @ Override public void describeTo ( Description description ) { description . appendText ( "<STR_LIT>" ) . appendValue ( listMatcher ) ; } @ Factory public static Matcher < ZipFile > isZipContainingFile ( String fileName ) { return new ZipMatcher ( IsCollectionContaining . hasItem ( Is . is ( fileName ) ) ) ; } @ Factory public static Matcher < ZipFile > isZipContainingFiles ( String ... fileNames ) { return new ZipMatcher ( IsCollectionContaining . hasItems ( fileNames ) ) ; } @ Factory public static Matcher < ZipFile > isZipMatching ( Matcher < Iterable < String > > matcher ) { return new ZipMatcher ( matcher ) ; } } </s>
|
<s> package com . izforge . izpack . mock ; import org . apache . tools . zip . ZipEntry ; import org . apache . tools . zip . ZipOutputStream ; import java . io . File ; import java . io . IOException ; import java . util . ArrayList ; import java . util . List ; public class MockOutputStream extends ZipOutputStream { private List < String > listEntryName = new ArrayList < String > ( ) ; public List < String > getListEntryName ( ) { return listEntryName ; } @ Override public void putNextEntry ( ZipEntry ze ) throws IOException { listEntryName . add ( ze . getName ( ) ) ; } public MockOutputStream ( ) throws IOException { super ( File . createTempFile ( "<STR_LIT:test>" , "<STR_LIT:test>" ) ) ; } @ Override public void write ( int b ) throws IOException { } @ Override public void write ( byte [ ] b ) throws IOException { } @ Override public void write ( byte [ ] b , int offset , int length ) throws IOException { } } </s>
|
<s> package com . izforge . izpack . test ; import java . lang . annotation . * ; @ Retention ( RetentionPolicy . RUNTIME ) @ Target ( { ElementType . TYPE } ) @ Inherited public @ interface BaseDir { public abstract String value ( ) ; } </s>
|
<s> package com . izforge . izpack . test . provider ; import java . io . File ; import java . io . IOException ; import java . util . jar . JarFile ; import org . picocontainer . ComponentAdapter ; import org . picocontainer . injectors . ProviderAdapter ; public class JarFileProvider extends ProviderAdapter { public JarFile provide ( File file ) throws IOException { return new JarFile ( file , true ) ; } @ Override public boolean isLazy ( ComponentAdapter < ? > adapter ) { return true ; } } </s>
|
<s> package com . izforge . izpack . test ; import com . izforge . izpack . api . merge . Mergeable ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . util . zip . ZipOutputStream ; public class MergeUtils { public static File doDoubleMerge ( Mergeable mergeable ) throws IOException { File tempFile = File . createTempFile ( "<STR_LIT:test>" , "<STR_LIT>" ) ; ZipOutputStream outputStream = new ZipOutputStream ( new FileOutputStream ( tempFile ) ) ; mergeable . merge ( outputStream ) ; mergeable . merge ( outputStream ) ; outputStream . close ( ) ; return tempFile ; } public static File doMerge ( Mergeable mergeable ) throws IOException { File tempFile = File . createTempFile ( "<STR_LIT:test>" , "<STR_LIT>" ) ; ZipOutputStream outputStream = new ZipOutputStream ( new FileOutputStream ( tempFile ) ) ; mergeable . merge ( outputStream ) ; outputStream . close ( ) ; return tempFile ; } } </s>
|
<s> package com . izforge . izpack . test . util ; import com . izforge . izpack . util . Housekeeper ; public class TestHousekeeper extends Housekeeper { private boolean shutdown = false ; private int exitCode ; private boolean reboot ; public void waitShutdown ( long timeout ) { synchronized ( this ) { if ( ! shutdown ) { try { wait ( timeout ) ; } catch ( InterruptedException ignore ) { } } } } public boolean hasShutdown ( ) { return shutdown ; } public int getExitCode ( ) { return exitCode ; } public boolean getReboot ( ) { return reboot ; } @ Override protected void terminate ( int exitCode , boolean reboot ) { this . exitCode = exitCode ; this . reboot = reboot ; synchronized ( this ) { shutdown = true ; notifyAll ( ) ; } } } </s>
|
<s> package com . izforge . izpack . test . util ; import sun . misc . URLClassPath ; import java . io . File ; import java . lang . reflect . Field ; import java . lang . reflect . Method ; import java . net . URL ; import java . net . URLClassLoader ; import java . util . ArrayList ; public class ClassUtils { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public static void unloadLastJar ( ) { try { URLClassLoader systemClassLoader = ( URLClassLoader ) ClassLoader . getSystemClassLoader ( ) ; Field ucpField = URLClassLoader . class . getDeclaredField ( "<STR_LIT>" ) ; ucpField . setAccessible ( true ) ; URLClassPath ucp = ( URLClassPath ) ucpField . get ( systemClassLoader ) ; Field pathField = URLClassPath . class . getDeclaredField ( "<STR_LIT:path>" ) ; pathField . setAccessible ( true ) ; ArrayList < URL > path = ( ArrayList < URL > ) pathField . get ( ucp ) ; path . remove ( path . size ( ) - <NUM_LIT:1> ) ; Field loaderField = URLClassPath . class . getDeclaredField ( "<STR_LIT>" ) ; loaderField . setAccessible ( true ) ; ArrayList loaders = ( ArrayList ) loaderField . get ( ucp ) ; loaders . remove ( loaders . size ( ) - <NUM_LIT:1> ) ; } catch ( Exception e ) { throw new IllegalStateException ( e ) ; } } public static void loadJarInSystemClassLoader ( File out ) { try { URLClassLoader systemClassLoader = ( URLClassLoader ) ClassLoader . getSystemClassLoader ( ) ; Method declaredMethod = URLClassLoader . class . getDeclaredMethod ( "<STR_LIT>" , new Class [ ] { URL . class } ) ; declaredMethod . setAccessible ( true ) ; declaredMethod . invoke ( systemClassLoader , out . toURI ( ) . toURL ( ) ) ; } catch ( Exception e ) { throw new IllegalStateException ( e ) ; } } } </s>
|
<s> package com . izforge . izpack . test . util ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import static org . junit . Assert . fail ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . util . Random ; import org . apache . commons . io . FileUtils ; public class TestHelper { public static File createFile ( File dir , String name , int size ) throws IOException { return createFile ( new File ( dir , name ) , size ) ; } public static File createFile ( File file , int size ) throws IOException { byte [ ] data = new byte [ size ] ; Random random = new Random ( ) ; random . nextBytes ( data ) ; FileOutputStream stream = new FileOutputStream ( file ) ; stream . write ( data ) ; return file ; } public static void assertFileEquals ( File expected , File actualDir , String actualName ) { assertFileEquals ( expected , new File ( actualDir , actualName ) ) ; } public static void assertFileExists ( File dir , String name ) { assertFileExists ( new File ( dir , name ) ) ; } public static void assertFileExists ( File file ) { assertTrue ( file . exists ( ) ) ; } public static void assertFileNotExists ( File dir , String name ) { assertFalse ( new File ( dir , name ) . exists ( ) ) ; } public static void assertFileNotExists ( File file ) { assertFalse ( file . exists ( ) ) ; } public static void assertFileEquals ( File expected , File actual ) { assertTrue ( actual . exists ( ) ) ; assertFalse ( actual . getAbsolutePath ( ) . equals ( expected . getAbsolutePath ( ) ) ) ; assertEquals ( expected . length ( ) , actual . length ( ) ) ; try { assertEquals ( FileUtils . checksumCRC32 ( expected ) , FileUtils . checksumCRC32 ( actual ) ) ; } catch ( IOException exception ) { fail ( exception . getMessage ( ) ) ; } } } </s>
|
<s> package com . izforge . izpack . test . util ; import java . net . URL ; import com . izforge . izpack . util . Housekeeper ; import com . izforge . izpack . util . Librarian ; import com . izforge . izpack . util . TargetFactory ; public class TestLibrarian extends Librarian { public TestLibrarian ( TargetFactory factory , Housekeeper housekeeper ) { super ( factory , housekeeper ) ; } @ Override protected URL getResourcePath ( String name ) { if ( name . startsWith ( "<STR_LIT>" ) ) { String resource = "<STR_LIT>" + name + "<STR_LIT>" ; return getClass ( ) . getResource ( resource ) ; } return super . getResourcePath ( name ) ; } } </s>
|
<s> package com . izforge . izpack . test . util ; import java . io . IOException ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import com . izforge . izpack . util . Console ; public class TestConsole extends Console { private List < List < String > > scripts = new ArrayList < List < String > > ( ) ; private List < String > output = new ArrayList < String > ( ) ; private int scriptIndex = <NUM_LIT:0> ; List < String > currentScript = null ; private int index = <NUM_LIT:0> ; private int reads = <NUM_LIT:0> ; public TestConsole ( ) { } public void addScript ( String name , String ... script ) { List < String > list = new ArrayList < String > ( ) ; list . add ( name ) ; list . addAll ( Arrays . asList ( script ) ) ; scripts . add ( list ) ; } public String getScriptName ( ) { return currentScript != null ? currentScript . get ( <NUM_LIT:0> ) : null ; } public boolean scriptCompleted ( ) { return scriptIndex == scripts . size ( ) && ( scripts . isEmpty ( ) || index == scripts . get ( scriptIndex - <NUM_LIT:1> ) . size ( ) ) ; } @ Override public String readLine ( ) throws IOException { ++ reads ; String result = null ; advanceScript ( ) ; while ( currentScript != null ) { if ( index == <NUM_LIT:0> ) { ++ index ; } if ( index < currentScript . size ( ) ) { result = currentScript . get ( index ++ ) ; break ; } else { advanceScript ( ) ; } } if ( result != null ) { if ( result . endsWith ( "<STR_LIT>" ) ) { result = result . substring ( <NUM_LIT:0> , result . length ( ) - <NUM_LIT:2> ) ; } else if ( result . endsWith ( "<STR_LIT:r>" ) || result . endsWith ( "<STR_LIT:n>" ) ) { result = result . substring ( <NUM_LIT:0> , result . length ( ) - <NUM_LIT:1> ) ; } println ( result ) ; } return result ; } public int getReads ( ) { return reads ; } @ Override public void print ( String message ) { super . print ( message ) ; output . add ( message ) ; } @ Override public void println ( String message ) { super . println ( message ) ; output . add ( message ) ; } public List < String > getOutput ( ) { return output ; } private void advanceScript ( ) { if ( currentScript == null || index == currentScript . size ( ) ) { if ( scriptIndex < scripts . size ( ) ) { currentScript = scripts . get ( scriptIndex ++ ) ; System . out . println ( "<STR_LIT>" + getScriptName ( ) ) ; index = <NUM_LIT:0> ; } else { currentScript = null ; } } } } </s>
|
<s> package com . izforge . izpack . test . junit ; import org . junit . runner . notification . RunNotifier ; import org . junit . runners . BlockJUnit4ClassRunner ; import org . junit . runners . model . FrameworkMethod ; import org . junit . runners . model . InitializationError ; import com . izforge . izpack . test . RunOn ; import com . izforge . izpack . util . Platform ; import com . izforge . izpack . util . Platforms ; public class PlatformRunner extends BlockJUnit4ClassRunner { public PlatformRunner ( Class < ? > klass ) throws InitializationError { super ( klass ) ; } @ Override protected void runChild ( FrameworkMethod method , RunNotifier notifier ) { RunOn runOn = method . getAnnotation ( RunOn . class ) ; if ( runOn == null ) { runOn = method . getMethod ( ) . getDeclaringClass ( ) . getAnnotation ( RunOn . class ) ; } boolean ignore = false ; if ( runOn != null ) { Platform platform = new Platforms ( ) . getCurrentPlatform ( ) ; boolean found = false ; for ( Platform . Name name : runOn . value ( ) ) { if ( platform . isA ( name ) ) { found = true ; break ; } } ignore = ! found ; } if ( ! ignore ) { super . runChild ( method , notifier ) ; } else { notifier . fireTestIgnored ( describeChild ( method ) ) ; } } } </s>
|
<s> package com . izforge . izpack . test . junit ; import java . lang . annotation . Annotation ; import java . lang . reflect . Constructor ; import java . lang . reflect . Field ; import java . lang . reflect . InvocationTargetException ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; import javax . swing . SwingUtilities ; import org . junit . Rule ; import org . junit . rules . TestRule ; import org . junit . runner . Description ; import org . junit . runners . model . FrameworkMethod ; import org . junit . runners . model . InitializationError ; import org . junit . runners . model . Statement ; import com . izforge . izpack . api . container . Container ; import com . izforge . izpack . api . exception . IzPackException ; public class PicoRunner extends PlatformRunner { private Class < ? > klass ; private FrameworkMethod method ; private Object currentTestInstance ; private Class < ? extends Container > containerClass ; private Container containerInstance ; private static final Logger logger = Logger . getLogger ( PicoRunner . class . getName ( ) ) ; public PicoRunner ( Class < ? > klass ) throws InitializationError { super ( klass ) ; this . klass = klass ; } @ Override protected void validateConstructor ( List < Throwable > errors ) { } @ Override protected Statement methodBlock ( FrameworkMethod method ) { this . method = method ; Statement statement = super . methodBlock ( method ) ; try { for ( Field field : containerClass . getFields ( ) ) { Annotation annotation = field . getAnnotation ( Rule . class ) ; if ( annotation != null ) { TestRule rule = ( TestRule ) field . get ( containerInstance ) ; Description description = Description . createTestDescription ( method . getMethod ( ) . getDeclaringClass ( ) , method . getName ( ) ) ; statement = rule . apply ( statement , description ) ; } } } catch ( IllegalAccessException e ) { throw new IzPackException ( e ) ; } return statement ; } @ Override protected Object createTest ( ) throws Exception { containerClass = getTestClass ( ) . getJavaClass ( ) . getAnnotation ( com . izforge . izpack . test . Container . class ) . value ( ) ; logger . info ( "<STR_LIT>" + getTestClass ( ) . getName ( ) ) ; SwingUtilities . invokeAndWait ( new Runnable ( ) { public void run ( ) { try { containerInstance = createContainer ( containerClass ) ; containerInstance . addComponent ( klass ) ; currentTestInstance = containerInstance . getComponent ( klass ) ; } catch ( Exception e ) { logger . log ( Level . SEVERE , e . getMessage ( ) , e ) ; throw new IzPackException ( e ) ; } } } ) ; return currentTestInstance ; } private Container createContainer ( Class < ? extends Container > containerClass ) throws InvocationTargetException , IllegalAccessException , InstantiationException , NoSuchMethodException { Constructor < ? extends Container > constructor ; Container result ; try { constructor = containerClass . getConstructor ( klass . getClass ( ) , method . getClass ( ) ) ; result = constructor . newInstance ( klass , method ) ; } catch ( NoSuchMethodException exception ) { try { constructor = containerClass . getConstructor ( klass . getClass ( ) ) ; result = constructor . newInstance ( klass ) ; } catch ( NoSuchMethodException nested ) { constructor = containerClass . getConstructor ( ) ; result = constructor . newInstance ( ) ; } } return result ; } } </s>
|
<s> package com . izforge . izpack . test . junit ; import org . junit . rules . TestRule ; import org . junit . runner . Description ; import org . junit . runners . model . Statement ; import com . izforge . izpack . test . util . ClassUtils ; public class UnloadJarRule implements TestRule { @ Override public Statement apply ( Statement base , Description description ) { return statement ( base ) ; } private Statement statement ( final Statement base ) { return new Statement ( ) { @ Override public void evaluate ( ) throws Throwable { try { base . evaluate ( ) ; } finally { ClassUtils . unloadLastJar ( ) ; } } } ; } } </s>
|
<s> package com . izforge . izpack . test ; import java . lang . annotation . * ; @ Retention ( RetentionPolicy . RUNTIME ) @ Target ( { ElementType . METHOD , ElementType . TYPE } ) @ Inherited public @ interface InstallFile { public abstract String value ( ) ; } </s>
|
<s> package com . izforge . izpack . test ; import java . lang . annotation . ElementType ; import java . lang . annotation . Inherited ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import com . izforge . izpack . util . Platform ; @ Retention ( RetentionPolicy . RUNTIME ) @ Target ( { ElementType . METHOD , ElementType . TYPE } ) @ Inherited public @ interface RunOn { Platform . Name [ ] value ( ) ; } </s>
|
<s> package com . izforge . izpack . test ; import java . lang . annotation . ElementType ; import java . lang . annotation . Inherited ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; @ Retention ( RetentionPolicy . RUNTIME ) @ Target ( { ElementType . TYPE } ) @ Inherited public @ interface Container { public abstract Class < ? extends com . izforge . izpack . api . container . Container > value ( ) ; } </s>
|
<s> package com . izforge . izpack . util ; import static com . izforge . izpack . util . Platform . Arch ; import static com . izforge . izpack . util . Platform . Name ; import java . io . File ; import java . io . IOException ; import java . util . logging . Level ; import java . util . logging . Logger ; public final class OsVersion implements OsVersionConstants , StringConstants { private static final Logger LOGGER = Logger . getLogger ( OsVersion . class . getName ( ) ) ; public static final String OS_NAME = System . getProperty ( OSNAME ) ; public static final String OS_ARCH = System . getProperty ( OSARCH ) ; public static final String OS_VERSION = System . getProperty ( OSVERSION ) ; public static final Platform PLATFORM = new Platforms ( ) . getCurrentPlatform ( OS_NAME , OS_ARCH , OS_VERSION ) ; public static final boolean IS_X86 = PLATFORM . isA ( Arch . X86 ) ; public static final boolean IS_X64 = PLATFORM . isA ( Arch . X64 ) ; public static final boolean IS_PPC = PLATFORM . isA ( Arch . PPC ) ; public static final boolean IS_SPARC = PLATFORM . isA ( Arch . SPARC ) ; public static final boolean IS_FREEBSD = PLATFORM . isA ( Name . FREEBSD ) ; public static final boolean IS_LINUX = PLATFORM . isA ( Name . LINUX ) ; public static final boolean IS_HPUX = PLATFORM . isA ( Name . HP_UX ) ; public static final boolean IS_AIX = PLATFORM . isA ( Name . AIX ) ; public static final boolean IS_SUNOS = PLATFORM . isA ( Name . SUNOS ) ; public static final boolean IS_SUNOS_X86 = PLATFORM . isA ( Platforms . SUNOS_X86 ) ; public static final boolean IS_SUNOS_SPARC = PLATFORM . isA ( Platforms . SUNOS_SPARC ) ; public static final boolean IS_OS2 = PLATFORM . isA ( Name . OS_2 ) ; public static final boolean IS_MAC = PLATFORM . isA ( Name . MAC ) ; public static final boolean IS_OSX = PLATFORM . isA ( Name . MAC_OSX ) ; public static final boolean IS_WINDOWS = PLATFORM . isA ( Platforms . WINDOWS ) ; public static final boolean IS_WINDOWS_XP = PLATFORM . isA ( Platforms . WINDOWS_XP ) ; public static final boolean IS_WINDOWS_2003 = PLATFORM . isA ( Platforms . WINDOWS_2003 ) ; public static final boolean IS_WINDOWS_VISTA = PLATFORM . isA ( Platforms . WINDOWS_VISTA ) ; public static final boolean IS_WINDOWS_7 = PLATFORM . isA ( Platforms . WINDOWS_7 ) ; public static final boolean IS_UNIX = PLATFORM . isA ( Name . UNIX ) ; public static final boolean IS_REDHAT_LINUX = PLATFORM . isA ( Name . RED_HAT_LINUX ) ; public static final boolean IS_FEDORA_LINUX = PLATFORM . isA ( Name . FEDORA_LINUX ) ; public static final boolean IS_MANDRAKE_LINUX = PLATFORM . isA ( Name . MANDRAKE_LINUX ) ; public static final boolean IS_MANDRIVA_LINUX = PLATFORM . isA ( Name . MANDRIVA_LINUX ) || IS_MANDRAKE_LINUX ; public static final boolean IS_SUSE_LINUX = PLATFORM . isA ( Name . SUSE_LINUX ) ; public static final boolean IS_DEBIAN_LINUX = PLATFORM . isA ( Name . DEBIAN_LINUX ) ; public static final boolean IS_UBUNTU_LINUX = PLATFORM . isA ( Name . UBUNTU_LINUX ) ; private static String getReleaseFileName ( ) { String result = "<STR_LIT>" ; File [ ] etcList = new File ( "<STR_LIT>" ) . listFiles ( ) ; if ( etcList != null ) { for ( File etcEntry : etcList ) { if ( etcEntry . isFile ( ) ) { if ( etcEntry . getName ( ) . endsWith ( "<STR_LIT>" ) ) { return etcEntry . toString ( ) ; } } } } return result ; } private static String getLinuxDistribution ( ) { String result = null ; if ( IS_SUSE_LINUX ) { try { result = SUSE + SP + LINUX + NL + StringTool . listToString ( FileUtil . getFileContent ( getReleaseFileName ( ) ) ) ; } catch ( IOException e ) { } } else if ( IS_REDHAT_LINUX ) { try { result = REDHAT + SP + LINUX + NL + StringTool . listToString ( FileUtil . getFileContent ( getReleaseFileName ( ) ) ) ; } catch ( IOException e ) { } } else if ( IS_FEDORA_LINUX ) { try { result = FEDORA + SP + LINUX + NL + StringTool . listToString ( FileUtil . getFileContent ( getReleaseFileName ( ) ) ) ; } catch ( IOException e ) { } } else if ( IS_MANDRAKE_LINUX ) { try { result = MANDRAKE + SP + LINUX + NL + StringTool . listToString ( FileUtil . getFileContent ( getReleaseFileName ( ) ) ) ; } catch ( IOException e ) { } } else if ( IS_MANDRIVA_LINUX ) { try { result = MANDRIVA + SP + LINUX + NL + StringTool . listToString ( FileUtil . getFileContent ( getReleaseFileName ( ) ) ) ; } catch ( IOException e ) { } } else if ( IS_DEBIAN_LINUX ) { try { result = DEBIAN + SP + LINUX + NL + StringTool . listToString ( FileUtil . getFileContent ( "<STR_LIT>" ) ) ; } catch ( IOException e ) { } } else { try { result = "<STR_LIT>" + StringTool . listToString ( FileUtil . getFileContent ( getReleaseFileName ( ) ) ) ; } catch ( IOException e ) { } } return result ; } public static String getOsDetails ( ) { StringBuffer result = new StringBuffer ( ) ; result . append ( "<STR_LIT>" ) . append ( OS_NAME ) . append ( NL ) ; if ( IS_UNIX ) { if ( IS_LINUX ) { result . append ( getLinuxDistribution ( ) ) . append ( NL ) ; } else { try { result . append ( FileUtil . getFileContent ( getReleaseFileName ( ) ) ) . append ( NL ) ; } catch ( IOException e ) { LOGGER . log ( Level . INFO , "<STR_LIT>" ) ; } } } if ( IS_WINDOWS ) { result . append ( System . getProperty ( OSNAME ) ) . append ( SP ) . append ( System . getProperty ( "<STR_LIT>" , "<STR_LIT>" ) ) . append ( NL ) ; } return result . toString ( ) ; } public static void main ( String [ ] args ) { System . out . println ( getOsDetails ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . util ; public interface OsVersionConstants { public final static String OSNAME = "<STR_LIT>" ; public final static String OSARCH = "<STR_LIT>" ; public final static String OSVERSION = "<STR_LIT>" ; public static final String X86 = "<STR_LIT>" ; public static final String X64 = "<STR_LIT>" ; public static final String I386 = "<STR_LIT>" ; public static final String AMD64 = "<STR_LIT>" ; public static final String PPC = "<STR_LIT>" ; public static final String SPARC = "<STR_LIT>" ; public final static String FREEBSD = "<STR_LIT>" ; public final static String LINUX = "<STR_LIT>" ; public final static String HP_UX = "<STR_LIT>" ; public final static String AIX = "<STR_LIT>" ; public final static String SUNOS = "<STR_LIT>" ; public static final String SOLARIS = "<STR_LIT>" ; public final static String OS_2 = "<STR_LIT>" ; public final static String MAC = "<STR_LIT>" ; public final static String MACOSX = "<STR_LIT>" ; public final static String WINDOWS = "<STR_LIT>" ; public final static String WINDOWS_XP_VERSION = "<STR_LIT>" ; public final static String WINDOWS_2003_VERSION = "<STR_LIT>" ; public final static String WINDOWS_VISTA_VERSION = "<STR_LIT>" ; public final static String WINDOWS_7_VERSION = "<STR_LIT>" ; public final static String REDHAT = "<STR_LIT>" ; public final static String RED_HAT = "<STR_LIT>" ; public final static String FEDORA = "<STR_LIT>" ; public final static String MANDRAKE = "<STR_LIT>" ; public final static String MANDRIVA = "<STR_LIT>" ; public final static String SUSE = "<STR_LIT>" ; public final static String DEBIAN = "<STR_LIT>" ; public final static String UBUNTU = "<STR_LIT>" ; public final static String PROC_VERSION = "<STR_LIT>" ; } </s>
|
<s> package com . izforge . izpack . util ; public interface StringConstants { public final static String NL = "<STR_LIT:n>" ; public final static String SP = "<STR_LIT:U+0020>" ; } </s>
|
<s> package com . izforge . izpack . util ; import static com . izforge . izpack . util . Platform . Arch ; import static com . izforge . izpack . util . Platform . Name ; import java . io . File ; import java . io . IOException ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; public class Platforms { public static Platform AIX = new Platform ( Name . AIX ) ; public static Platform DEBIAN_LINUX = new Platform ( Name . DEBIAN_LINUX ) ; public static Platform FEDORA_LINUX = new Platform ( Name . FEDORA_LINUX ) ; public static Platform FREEBSD = new Platform ( Name . FREEBSD ) ; public static Platform HP_UX = new Platform ( Name . HP_UX ) ; public static Platform LINUX = new Platform ( Name . LINUX ) ; public static Platform MAC = new Platform ( Name . MAC ) ; public static Platform MAC_OSX = new Platform ( Name . MAC_OSX ) ; public static Platform MANDRAKE_LINUX = new Platform ( Name . MANDRAKE_LINUX ) ; public static Platform MANDRIVA_LINUX = new Platform ( Name . MANDRIVA_LINUX ) ; public static Platform OS_2 = new Platform ( Name . OS_2 ) ; public static Platform RED_HAT_LINUX = new Platform ( Name . RED_HAT_LINUX ) ; public static Platform SUNOS = new Platform ( Name . SUNOS ) ; public static Platform SUNOS_X86 = new Platform ( Name . SUNOS , "<STR_LIT>" , Arch . X86 ) ; public static Platform SUNOS_SPARC = new Platform ( Name . SUNOS , "<STR_LIT>" , Arch . SPARC ) ; public static Platform SUSE_LINUX = new Platform ( Name . SUSE_LINUX ) ; public static Platform UNIX = new Platform ( Name . UNIX ) ; public static Platform UBUNTU_LINUX = new Platform ( Name . UBUNTU_LINUX ) ; public static Platform WINDOWS = new Platform ( Name . WINDOWS ) ; public static Platform WINDOWS_XP = new Platform ( Name . WINDOWS , "<STR_LIT>" , OsVersionConstants . WINDOWS_XP_VERSION ) ; public static Platform WINDOWS_2003 = new Platform ( Name . WINDOWS , "<STR_LIT>" , OsVersionConstants . WINDOWS_2003_VERSION ) ; public static Platform WINDOWS_VISTA = new Platform ( Name . WINDOWS , "<STR_LIT>" , OsVersionConstants . WINDOWS_VISTA_VERSION ) ; public static Platform WINDOWS_7 = new Platform ( Name . WINDOWS , "<STR_LIT>" , OsVersionConstants . WINDOWS_7_VERSION ) ; public static Platform [ ] PLATFORMS = { AIX , DEBIAN_LINUX , FEDORA_LINUX , FREEBSD , HP_UX , LINUX , MAC , MAC_OSX , MANDRAKE_LINUX , MANDRIVA_LINUX , OS_2 , RED_HAT_LINUX , SUNOS , SUNOS_X86 , SUNOS_SPARC , SUSE_LINUX , UBUNTU_LINUX , UNIX , WINDOWS , WINDOWS_XP , WINDOWS_2003 , WINDOWS_VISTA , WINDOWS_7 } ; private Name linuxName ; private static final Logger log = Logger . getLogger ( Platforms . class . getName ( ) ) ; public Platform getCurrentPlatform ( ) { return getCurrentPlatform ( System . getProperty ( OsVersionConstants . OSNAME ) , System . getProperty ( OsVersionConstants . OSARCH ) , System . getProperty ( OsVersionConstants . OSVERSION ) , System . getProperty ( "<STR_LIT>" ) ) ; } public Platform getCurrentPlatform ( String name , String arch ) { return getCurrentPlatform ( name , arch , null ) ; } public Platform getCurrentPlatform ( String name , String arch , String version ) { return getCurrentPlatform ( name , arch , version , null ) ; } public Platform getCurrentPlatform ( String name , String arch , String version , String javaVersion ) { Platform result ; Name pname = getCurrentOSName ( name ) ; Arch parch = getArch ( arch ) ; Platform match = findMatch ( name , pname , parch , version ) ; result = getPlatform ( match , parch , version , javaVersion ) ; return result ; } public Platform getPlatform ( String name , String arch ) { return getPlatform ( name , arch , null ) ; } public Platform getPlatform ( String name , String arch , String version ) { return getPlatform ( name , arch , version , null ) ; } public Platform getPlatform ( String name , String arch , String version , String javaVersion ) { Platform result ; Name pname = getName ( name ) ; Arch parch = getArch ( arch ) ; Platform match = findMatch ( name , pname , parch , version ) ; result = getPlatform ( match , parch , version , javaVersion ) ; return result ; } public Arch getArch ( String arch ) { Arch result = null ; if ( arch != null ) { try { result = Arch . valueOf ( arch . toUpperCase ( ) ) ; } catch ( IllegalArgumentException ignore ) { } } if ( result == null ) { if ( StringTool . startsWithIgnoreCase ( arch , OsVersionConstants . X86 ) || StringTool . startsWithIgnoreCase ( arch , OsVersionConstants . I386 ) ) { result = Arch . X86 ; } else if ( StringTool . startsWithIgnoreCase ( arch , OsVersionConstants . X64 ) || StringTool . startsWithIgnoreCase ( arch , OsVersionConstants . AMD64 ) ) { result = Arch . X64 ; } else if ( StringTool . startsWithIgnoreCase ( arch , OsVersionConstants . PPC ) ) { result = Arch . PPC ; } else if ( StringTool . startsWithIgnoreCase ( arch , OsVersionConstants . SPARC ) ) { result = Arch . SPARC ; } else { result = Arch . UNKNOWN ; } } return result ; } public Name getCurrentOSName ( ) { return getCurrentOSName ( System . getProperty ( OsVersionConstants . OSNAME ) ) ; } public Name getName ( String name ) { Name result ; if ( StringTool . startsWithIgnoreCase ( name , OsVersionConstants . FREEBSD ) ) { result = Name . FREEBSD ; } else if ( StringTool . startsWithIgnoreCase ( name , OsVersionConstants . LINUX ) ) { result = Name . LINUX ; } else if ( StringTool . startsWithIgnoreCase ( name , OsVersionConstants . HP_UX ) ) { result = Name . HP_UX ; } else if ( StringTool . startsWithIgnoreCase ( name , OsVersionConstants . AIX ) ) { result = Name . AIX ; } else if ( StringTool . startsWithIgnoreCase ( name , OsVersionConstants . SUNOS ) || StringTool . startsWithIgnoreCase ( name , OsVersionConstants . SOLARIS ) ) { result = Name . SUNOS ; } else if ( StringTool . startsWith ( name , OsVersionConstants . OS_2 ) ) { result = Name . OS_2 ; } else if ( StringTool . startsWithIgnoreCase ( name , OsVersionConstants . MACOSX ) ) { result = Name . MAC_OSX ; } else if ( StringTool . startsWith ( name , OsVersionConstants . MAC ) ) { result = Name . MAC ; } else if ( StringTool . startsWith ( name , OsVersionConstants . WINDOWS ) ) { result = Name . WINDOWS ; } else { try { result = Name . valueOf ( name . toUpperCase ( ) ) ; } catch ( IllegalArgumentException exception ) { result = Name . UNKNOWN ; } } return result ; } protected Name getCurrentOSName ( String name ) { Name result = getName ( name ) ; if ( result == Name . LINUX ) { result = getLinuxName ( ) ; } return result ; } protected Platform getPlatform ( Platform match , Arch arch , String version , String javaVersion ) { Platform result ; if ( match != null ) { if ( arch == Arch . UNKNOWN ) { arch = match . getArch ( ) ; } if ( version == null ) { version = match . getVersion ( ) ; } if ( javaVersion == null ) { javaVersion = match . getJavaVersion ( ) ; } result = new Platform ( match . getName ( ) , match . getSymbolicName ( ) , version , arch , javaVersion ) ; } else { result = new Platform ( Name . UNKNOWN , null , version , arch , javaVersion ) ; } return result ; } protected Platform findMatch ( String name , Name pname , Arch arch , String version ) { Platform best = null ; int bestMatches = <NUM_LIT:0> ; for ( Platform platform : PLATFORMS ) { if ( ( pname == Name . UNKNOWN && equals ( name , platform . getSymbolicName ( ) , true ) ) || ( pname != Name . UNKNOWN && pname == platform . getName ( ) ) ) { int currentMatches = <NUM_LIT:0> ; boolean archMatch = arch == platform . getArch ( ) ; boolean optArchMatch = platform . getArch ( ) == Arch . UNKNOWN ; boolean versionMatch = version != null && equals ( version , platform . getVersion ( ) ) ; boolean optVersionMatch = platform . getVersion ( ) == null ; boolean symbolicMatch = equals ( name , platform . getSymbolicName ( ) , true ) ; if ( archMatch ) { currentMatches += <NUM_LIT:2> ; } else if ( optArchMatch ) { currentMatches ++ ; } if ( symbolicMatch ) { currentMatches += <NUM_LIT:2> ; } if ( versionMatch ) { currentMatches += <NUM_LIT:2> ; } else if ( optVersionMatch ) { currentMatches ++ ; } if ( currentMatches > bestMatches ) { best = platform ; if ( currentMatches == <NUM_LIT:6> ) { break ; } else { bestMatches = currentMatches ; } } } } return best ; } protected synchronized Name getLinuxName ( ) { Name result = linuxName ; if ( result == null ) { result = Name . LINUX ; String path = getReleasePath ( ) ; if ( path != null ) { List < String > text = getText ( path ) ; if ( text != null ) { if ( search ( text , OsVersionConstants . REDHAT ) || search ( text , OsVersionConstants . RED_HAT ) ) { result = Name . RED_HAT_LINUX ; } else if ( search ( text , OsVersionConstants . FEDORA ) ) { result = Name . FEDORA_LINUX ; } else if ( search ( text , OsVersionConstants . MANDRAKE ) ) { result = Name . MANDRAKE_LINUX ; } else if ( search ( text , OsVersionConstants . MANDRIVA ) ) { result = Name . MANDRIVA_LINUX ; } else if ( search ( text , OsVersionConstants . SUSE , true ) ) { result = Name . SUSE_LINUX ; } } } if ( result == Name . LINUX ) { List < String > text = getText ( OsVersionConstants . PROC_VERSION ) ; if ( text != null ) { if ( search ( text , OsVersionConstants . DEBIAN ) ) { result = Name . DEBIAN_LINUX ; } else if ( search ( text , OsVersionConstants . UBUNTU ) ) { result = Name . UBUNTU_LINUX ; } } if ( result == Name . LINUX && exists ( "<STR_LIT>" ) ) { result = Name . DEBIAN_LINUX ; } } linuxName = result ; } return result ; } protected List < String > getText ( String path ) { List < String > text = null ; try { text = FileUtil . getFileContent ( path ) ; } catch ( IOException ignore ) { if ( log . isLoggable ( Level . FINE ) ) { log . log ( Level . FINE , "<STR_LIT>" + path , ignore ) ; } } return text ; } protected String getReleasePath ( ) { String result = null ; File [ ] etcList = new File ( "<STR_LIT>" ) . listFiles ( ) ; if ( etcList != null ) { for ( File etcEntry : etcList ) { if ( etcEntry . isFile ( ) ) { if ( etcEntry . getName ( ) . endsWith ( "<STR_LIT>" ) ) { result = etcEntry . toString ( ) ; break ; } } } } return result ; } protected boolean exists ( String path ) { return new File ( path ) . exists ( ) ; } private boolean search ( List < String > text , String str ) { return search ( text , str , false ) ; } private boolean search ( List < String > text , String str , boolean caseInsensitive ) { boolean result = false ; if ( caseInsensitive ) { str = str . toLowerCase ( ) ; } for ( String line : text ) { if ( caseInsensitive ) { line = line . toLowerCase ( ) ; } if ( line . contains ( str ) ) { result = true ; break ; } } return result ; } private boolean equals ( String a , String b ) { return equals ( a , b , false ) ; } private boolean equals ( String a , String b , boolean ignoreCase ) { boolean result = false ; if ( a == null && b == null ) { result = true ; } else if ( a != null ) { if ( ignoreCase ) { result = a . equalsIgnoreCase ( b ) ; } else { result = a . equals ( b ) ; } } return result ; } } </s>
|
<s> package com . izforge . izpack . util ; import java . io . * ; import java . net . URL ; import java . net . URLDecoder ; import java . util . ArrayList ; import java . util . List ; public class FileUtil { public static File convertUrlToFile ( URL url ) { return new File ( convertUrlToFilePath ( url ) ) ; } public static String convertUrlToFilePath ( URL url ) { try { return URLDecoder . decode ( url . getFile ( ) , "<STR_LIT:UTF-8>" ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( e ) ; } } public static File getLockFile ( String applicationName ) { String tempDir = System . getProperty ( "<STR_LIT>" ) ; String fileName = "<STR_LIT>" + applicationName + "<STR_LIT>" ; return new File ( tempDir , fileName ) ; } public static List < String > getFileContent ( String fileName ) throws IOException { List < String > result = new ArrayList < String > ( ) ; File aFile = new File ( fileName ) ; if ( ! aFile . isFile ( ) ) { return result ; } BufferedReader reader = null ; try { reader = new BufferedReader ( new FileReader ( aFile ) ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; return result ; } String aLine = null ; while ( ( aLine = reader . readLine ( ) ) != null ) { result . add ( aLine + "<STR_LIT:n>" ) ; } reader . close ( ) ; return result ; } public static boolean fileContains ( String aFileName , String aSearchString ) { return ( fileContains ( aFileName , aSearchString , false ) ) ; } public static boolean fileContains ( String aFileName , String aSearchString , boolean caseInSensitiveSearch ) { boolean result = false ; String searchString = caseInSensitiveSearch ? aSearchString . toLowerCase ( ) : aSearchString ; List < String > fileContent = new ArrayList < String > ( ) ; try { fileContent = getFileContent ( aFileName ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } for ( String currentline : fileContent ) { if ( caseInSensitiveSearch ) { currentline = currentline . toLowerCase ( ) ; } if ( currentline . contains ( searchString ) ) { result = true ; break ; } } return result ; } public static long getFileDateTime ( URL url ) { if ( url == null ) { return - <NUM_LIT:1> ; } String fileName = url . getFile ( ) ; if ( fileName . charAt ( <NUM_LIT:0> ) == '<CHAR_LIT:/>' || fileName . charAt ( <NUM_LIT:0> ) == '<STR_LIT:\\>' ) { fileName = fileName . substring ( <NUM_LIT:1> , fileName . length ( ) ) ; } try { File file = new File ( fileName ) ; if ( ! file . isDirectory ( ) && ! file . isFile ( ) ) { return - <NUM_LIT:1> ; } return file . lastModified ( ) ; } catch ( java . lang . Exception e ) { return - <NUM_LIT:1> ; } } public static String [ ] getFileNames ( String dirPath ) throws Exception { return getFileNames ( dirPath , null ) ; } public static String [ ] getFileNames ( String dirPath , FilenameFilter fileNameFilter ) throws Exception { String fileNames [ ] = null ; File dir = new File ( dirPath ) ; if ( dir . isDirectory ( ) ) { if ( fileNameFilter != null ) { fileNames = dir . list ( fileNameFilter ) ; } else { fileNames = dir . list ( ) ; } } return fileNames ; } public static File getAbsoluteFile ( String filename , String basedir ) { if ( filename == null ) { return null ; } File file = new File ( filename ) ; if ( file . isAbsolute ( ) ) { return file ; } else { return new File ( basedir , file . getPath ( ) ) ; } } public static String getRelativeFileName ( File file , File basedir ) throws IOException { String canonicalFilePath = file . getCanonicalPath ( ) ; String canonicalBaseDirPath = basedir . getCanonicalPath ( ) ; if ( canonicalFilePath . startsWith ( canonicalBaseDirPath ) ) { int length = canonicalBaseDirPath . length ( ) ; if ( length < canonicalFilePath . length ( ) ) { return canonicalFilePath . substring ( length + <NUM_LIT:1> ) ; } } return null ; } } </s>
|
<s> package com . izforge . izpack . util ; public class Platform { public enum Name { UNIX , LINUX ( Name . UNIX ) , AIX ( Name . UNIX ) , DEBIAN_LINUX ( Name . LINUX ) , FEDORA_LINUX ( Name . LINUX ) , FREEBSD ( Name . UNIX ) , HP_UX ( Name . UNIX ) , MAC , MAC_OSX ( Name . MAC , Name . UNIX ) , MANDRAKE_LINUX ( Name . LINUX ) , MANDRIVA_LINUX ( Name . LINUX ) , OS_2 , RED_HAT_LINUX ( Name . LINUX ) , SUNOS ( Name . UNIX ) , SUSE_LINUX ( Name . LINUX ) , UBUNTU_LINUX ( Name . LINUX ) , WINDOWS , UNKNOWN ; private final Name [ ] parents ; Name ( ) { parents = new Name [ <NUM_LIT:0> ] ; } Name ( Name ... parents ) { this . parents = parents ; } public Name [ ] getParents ( ) { return parents ; } public boolean isA ( Name name ) { return isA ( this , name ) ; } private boolean isA ( Name current , Name name ) { if ( name == current ) { return true ; } else { for ( Name parent : current . getParents ( ) ) { if ( isA ( parent , name ) ) { return true ; } } } return false ; } } public enum Arch { X86 , X64 , PPC , SPARC , UNKNOWN } private final Name name ; private final String symbolicName ; private final Arch arch ; private final String version ; private final String javaVersion ; public Platform ( Name name ) { this ( name , ( String ) null ) ; } public Platform ( Name name , String version ) { this ( name , null , version ) ; } public Platform ( Name name , String symbolicName , String version ) { this ( name , symbolicName , version , null ) ; } public Platform ( Name name , Arch arch ) { this ( name , null , arch ) ; } public Platform ( Name name , String symbolicName , Arch arch ) { this ( name , symbolicName , null , arch ) ; } public Platform ( Name name , String symbolicName , String version , Arch arch ) { this ( name , symbolicName , version , arch , null ) ; } public Platform ( Name name , String symbolicName , String version , Arch arch , String javaVersion ) { if ( symbolicName != null && ( symbolicName . indexOf ( '<CHAR_LIT:U+0020>' ) > <NUM_LIT:0> || symbolicName . indexOf ( '<CHAR_LIT:U+002C>' ) > <NUM_LIT:0> ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } this . name = name ; this . symbolicName = symbolicName ; this . version = version ; this . arch = ( arch != null ) ? arch : Arch . UNKNOWN ; this . javaVersion = javaVersion ; } public Platform ( Platform platform , Arch arch ) { this ( platform . name , platform . symbolicName , platform . version , arch ) ; } public Name getName ( ) { return name ; } public String getSymbolicName ( ) { return symbolicName ; } public String getVersion ( ) { return version ; } public String getJavaVersion ( ) { return javaVersion ; } public Arch getArch ( ) { return arch ; } public boolean isA ( Platform platform ) { boolean result = false ; if ( isA ( platform . name ) && hasSymbolicName ( platform . symbolicName ) && hasArch ( platform . arch ) && hasVersion ( platform . version ) && hasJavaVersion ( platform . javaVersion ) ) { result = true ; } return result ; } public boolean isA ( Name name ) { return isA ( this . name , name ) ; } public boolean isA ( Arch arch ) { return this . arch == arch ; } public boolean equals ( Object other ) { if ( this == other ) { return true ; } if ( other instanceof Platform ) { Platform p = ( Platform ) other ; if ( name == p . name && arch == p . arch && ( ( version == null && p . version == null ) || ( version != null && version . equals ( p . version ) ) ) && ( ( javaVersion == null && p . javaVersion == null ) || ( javaVersion != null && javaVersion . equals ( p . javaVersion ) ) ) ) { return true ; } } return false ; } public int hashCode ( ) { int hash = name . hashCode ( ) ^ arch . hashCode ( ) ; if ( version != null ) { hash ^= version . hashCode ( ) ; } if ( javaVersion != null ) { hash ^= javaVersion . hashCode ( ) ; } return hash ; } public String toString ( ) { return name . toString ( ) . toLowerCase ( ) + "<STR_LIT>" + version + "<STR_LIT>" + arch . toString ( ) . toLowerCase ( ) + "<STR_LIT>" + symbolicName + "<STR_LIT>" + javaVersion ; } private boolean isA ( Name current , Name name ) { if ( name == current ) { return true ; } else { for ( Name parent : current . getParents ( ) ) { if ( isA ( parent , name ) ) { return true ; } } } return false ; } private boolean hasSymbolicName ( String other ) { return other == null || ( symbolicName != null && symbolicName . equals ( other ) ) ; } private boolean hasArch ( Arch other ) { return arch == other || other == Arch . UNKNOWN ; } private boolean hasVersion ( String other ) { return ( other == null ) || ( version != null && version . equals ( other ) ) ; } private boolean hasJavaVersion ( String other ) { return ( other == null ) || ( javaVersion != null && javaVersion . equals ( other ) ) ; } } </s>
|
<s> package com . izforge . izpack . util ; import java . io . File ; import java . util . List ; public class StringTool { public StringTool ( ) { super ( ) ; } public static String replace ( String value , String from , String to ) { return replace ( value , from , to , true ) ; } public static String replace ( String value , String from , String to , boolean aCaseSensitiveFlag ) { if ( ( value == null ) || ( value . length ( ) == <NUM_LIT:0> ) || ( from == null ) || ( from . length ( ) == <NUM_LIT:0> ) ) { return value ; } if ( to == null ) { to = "<STR_LIT>" ; } if ( ! aCaseSensitiveFlag ) { from = from . toLowerCase ( ) ; } String result = value ; int lastIndex = <NUM_LIT:0> ; int index = value . indexOf ( from ) ; if ( index != - <NUM_LIT:1> ) { StringBuffer buffer = new StringBuffer ( ) ; while ( index != - <NUM_LIT:1> ) { buffer . append ( value . substring ( lastIndex , index ) ) . append ( to ) ; lastIndex = index + from . length ( ) ; index = value . indexOf ( from , lastIndex ) ; } buffer . append ( value . substring ( lastIndex ) ) ; result = buffer . toString ( ) ; } return result ; } public static String escapeSpaces ( String aPathString ) { return replaceOrEscapeAll ( aPathString , null , null , true ) ; } public static String replaceSpacesWithMinus ( String aPathString ) { return replaceSpaces ( aPathString , "<STR_LIT:->" ) ; } public static String replaceSpaces ( String aPathString , String replaceWith ) { return replaceOrEscapeAll ( aPathString , replaceWith , null , false ) ; } public static String replaceOrEscapeAll ( String aPathString , String replaceOrEscapeWith , String [ ] replaceWhat , boolean escape ) { if ( replaceWhat == null ) { replaceWhat = new String [ ] { "<STR_LIT:U+0020>" , "<STR_LIT:t>" , "<STR_LIT:n>" } ; } if ( replaceOrEscapeWith == null ) { replaceOrEscapeWith = "<STR_LIT:\\>" ; } for ( String aReplaceWhat : replaceWhat ) { aPathString = replace ( aPathString , aReplaceWhat , escape == true ? replaceOrEscapeWith + aReplaceWhat : replaceOrEscapeWith ) ; } return aPathString ; } public static String normalizePath ( String destination , String fileSeparator ) { String FILESEP = ( fileSeparator == null ) ? File . separator : fileSeparator ; destination = StringTool . replace ( destination , "<STR_LIT:\\>" , "<STR_LIT:/>" ) ; destination = StringTool . replace ( destination , "<STR_LIT>" , "<STR_LIT:/>" ) ; destination = StringTool . replace ( destination , "<STR_LIT::>" , "<STR_LIT:;>" ) ; destination = StringTool . replace ( destination , "<STR_LIT:;>" , "<STR_LIT::>" ) ; destination = StringTool . replace ( destination , "<STR_LIT:/>" , FILESEP ) ; if ( "<STR_LIT:\\>" . equals ( FILESEP ) ) { destination = StringTool . replace ( destination , "<STR_LIT::>" , "<STR_LIT:;>" ) ; destination = StringTool . replace ( destination , "<STR_LIT>" , "<STR_LIT>" ) ; } return ( destination ) ; } public static String normalizePath ( String destination ) { return ( normalizePath ( destination , null ) ) ; } public static String stringArrayToSpaceSeparatedString ( String [ ] args ) { String result = "<STR_LIT>" ; for ( String arg : args ) { result += arg + "<STR_LIT:U+0020>" ; } return result ; } public static String getPlatformEncoding ( ) { return System . getProperty ( "<STR_LIT>" ) ; } public static String UTF16 ( ) { return "<STR_LIT>" ; } public static String listToString ( List < ? > aStringList ) { return listToString ( aStringList , null ) ; } public static String listToString ( List < ? > aStringList , String aLineSeparator ) { String LineSeparator = aLineSeparator ; if ( LineSeparator == null ) { LineSeparator = System . getProperty ( "<STR_LIT>" , "<STR_LIT:n>" ) ; } StringBuffer temp = new StringBuffer ( ) ; for ( Object anAStringList : aStringList ) { temp . append ( anAStringList ) . append ( LineSeparator ) ; } return temp . toString ( ) ; } public static boolean startsWith ( String str , String prefix ) { return ( str != null ) && str . startsWith ( prefix ) ; } public static boolean startsWithIgnoreCase ( String str , String prefix ) { return ( str != null ) && ( prefix != null ) && str . toUpperCase ( ) . startsWith ( prefix . toUpperCase ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . util ; import static com . izforge . izpack . util . Platform . Arch ; import static com . izforge . izpack . util . Platform . Name ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import static org . junit . Assert . fail ; import org . junit . Test ; public class PlatformTest extends AbstractPlatformTest { @ Test public void testConstructors ( ) { checkPlatform ( new Platform ( Name . UNIX ) , Name . UNIX , null , null , Arch . UNKNOWN ) ; checkPlatform ( new Platform ( Name . WINDOWS , OsVersionConstants . WINDOWS_7_VERSION ) , Name . WINDOWS , null , OsVersionConstants . WINDOWS_7_VERSION , Arch . UNKNOWN ) ; checkPlatform ( new Platform ( Name . WINDOWS , "<STR_LIT>" , OsVersionConstants . WINDOWS_VISTA_VERSION ) , Name . WINDOWS , "<STR_LIT>" , OsVersionConstants . WINDOWS_VISTA_VERSION , Arch . UNKNOWN ) ; checkPlatform ( new Platform ( Name . WINDOWS , Arch . X86 ) , Name . WINDOWS , null , null , Arch . X86 ) ; checkPlatform ( new Platform ( Name . SUNOS , "<STR_LIT>" , Arch . SPARC ) , Name . SUNOS , "<STR_LIT>" , null , Arch . SPARC ) ; checkPlatform ( new Platform ( Name . MAC_OSX , "<STR_LIT>" , OsVersionConstants . MACOSX , Arch . X64 ) , Name . MAC_OSX , "<STR_LIT>" , OsVersionConstants . MACOSX , Arch . X64 ) ; Platform win7 = new Platform ( Name . WINDOWS , "<STR_LIT>" , OsVersionConstants . WINDOWS_7_VERSION ) ; checkPlatform ( new Platform ( win7 , Arch . X64 ) , Name . WINDOWS , "<STR_LIT>" , OsVersionConstants . WINDOWS_7_VERSION , Arch . X64 ) ; } @ Test public void testIsAName ( ) { Platform p1 = new Platform ( Name . UNIX ) ; assertTrue ( p1 . isA ( Name . UNIX ) ) ; assertFalse ( p1 . isA ( Name . LINUX ) ) ; Platform p2 = new Platform ( Name . LINUX ) ; assertTrue ( p2 . isA ( Name . LINUX ) ) ; assertTrue ( p2 . isA ( Name . UNIX ) ) ; assertFalse ( p2 . isA ( Name . DEBIAN_LINUX ) ) ; Name [ ] linuxes = { Name . DEBIAN_LINUX , Name . FEDORA_LINUX , Name . MANDRAKE_LINUX , Name . MANDRIVA_LINUX , Name . RED_HAT_LINUX , Name . SUSE_LINUX , Name . UBUNTU_LINUX } ; for ( Name name : linuxes ) { Platform linux = new Platform ( name ) ; assertTrue ( linux . isA ( name ) ) ; assertTrue ( linux . isA ( Name . LINUX ) ) ; assertTrue ( linux . isA ( Name . UNIX ) ) ; assertFalse ( linux . isA ( Name . WINDOWS ) ) ; } Name [ ] unixes = { Name . AIX , Name . LINUX , Name . FREEBSD , Name . HP_UX , Name . MAC_OSX , Name . SUNOS } ; for ( Name name : unixes ) { Platform unix = new Platform ( name ) ; assertTrue ( unix . isA ( name ) ) ; assertTrue ( unix . isA ( Name . UNIX ) ) ; } Platform p3 = new Platform ( Name . MAC_OSX ) ; assertTrue ( p3 . isA ( Name . MAC_OSX ) ) ; assertTrue ( p3 . isA ( Name . UNIX ) ) ; assertFalse ( p3 . isA ( Name . LINUX ) ) ; assertTrue ( p3 . isA ( Name . MAC ) ) ; Platform p4 = new Platform ( Name . MAC ) ; assertTrue ( p4 . isA ( Name . MAC ) ) ; assertFalse ( p4 . isA ( Name . MAC_OSX ) ) ; } @ Test public void testIsAPlatform ( ) { Platform debian = new Platform ( Name . DEBIAN_LINUX ) ; Platform linux = new Platform ( Name . LINUX ) ; Platform unix = new Platform ( Name . UNIX ) ; Platform windows = new Platform ( Name . WINDOWS ) ; Platform windows7 = new Platform ( Name . WINDOWS , OsVersionConstants . WINDOWS_7_VERSION ) ; Platform windows64 = new Platform ( Name . WINDOWS , Arch . X64 ) ; Platform vista32 = new Platform ( Name . WINDOWS , OsVersionConstants . WINDOWS_VISTA_VERSION , Arch . X86 ) ; Platform vista64 = new Platform ( Name . WINDOWS , OsVersionConstants . WINDOWS_VISTA_VERSION , Arch . X64 ) ; assertTrue ( debian . isA ( debian ) ) ; assertTrue ( debian . isA ( linux ) ) ; assertTrue ( debian . isA ( unix ) ) ; assertFalse ( debian . isA ( windows ) ) ; assertFalse ( linux . isA ( debian ) ) ; assertFalse ( unix . isA ( debian ) ) ; assertTrue ( windows7 . isA ( windows7 ) ) ; assertTrue ( windows7 . isA ( windows ) ) ; assertFalse ( windows . isA ( windows7 ) ) ; assertTrue ( windows64 . isA ( windows64 ) ) ; assertTrue ( windows64 . isA ( windows ) ) ; assertFalse ( windows . isA ( windows64 ) ) ; assertTrue ( vista32 . isA ( vista32 ) ) ; assertTrue ( vista32 . isA ( windows ) ) ; assertFalse ( vista64 . isA ( vista32 ) ) ; assertTrue ( vista64 . isA ( vista64 ) ) ; assertTrue ( vista64 . isA ( windows ) ) ; assertFalse ( vista32 . isA ( vista64 ) ) ; } @ Test public void testIsArch ( ) { Platform platform = new Platform ( Name . WINDOWS , Arch . X64 ) ; assertTrue ( platform . isA ( Arch . X64 ) ) ; assertFalse ( platform . isA ( Arch . X86 ) ) ; } @ Test public void testEquals ( ) { Platform platform1 = new Platform ( Name . WINDOWS ) ; Platform platform2 = new Platform ( Name . WINDOWS ) ; Platform platform3 = new Platform ( Name . WINDOWS , OsVersionConstants . WINDOWS_7_VERSION ) ; Platform platform4 = new Platform ( Name . WINDOWS , Arch . X86 ) ; Platform platform5 = new Platform ( Name . WINDOWS , null , OsVersionConstants . WINDOWS_2003_VERSION , Arch . X86 ) ; Platform platform6 = new Platform ( Name . WINDOWS , "<STR_LIT>" , OsVersionConstants . WINDOWS_2003_VERSION , Arch . X86 ) ; assertTrue ( platform1 . equals ( platform1 ) ) ; assertTrue ( platform1 . equals ( platform2 ) ) ; assertFalse ( platform1 . equals ( platform3 ) ) ; assertFalse ( platform1 . equals ( platform4 ) ) ; assertFalse ( platform1 . equals ( platform5 ) ) ; assertFalse ( platform4 . equals ( platform5 ) ) ; assertTrue ( platform5 . equals ( platform6 ) ) ; } @ Test public void testSymbolicName ( ) { String validName = "<STR_LIT>" ; Platform platform1 = new Platform ( Name . WINDOWS , validName , OsVersionConstants . WINDOWS_7_VERSION ) ; assertEquals ( validName , platform1 . getSymbolicName ( ) ) ; String invalidSpaces = "<STR_LIT>" ; try { new Platform ( Name . WINDOWS , invalidSpaces , OsVersionConstants . WINDOWS_7_VERSION ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException expected ) { } String invalidCommas = "<STR_LIT>" ; try { new Platform ( Name . WINDOWS , invalidCommas , OsVersionConstants . WINDOWS_7_VERSION ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException expected ) { } } @ Test public void testToString ( ) { Platform platform1 = new Platform ( Name . WINDOWS , "<STR_LIT>" , OsVersionConstants . WINDOWS_7_VERSION , Arch . X64 , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , platform1 . toString ( ) ) ; Platform platform2 = new Platform ( Name . SUNOS ) ; assertEquals ( "<STR_LIT>" , platform2 . toString ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . util ; import static com . izforge . izpack . util . Platform . Arch ; import static com . izforge . izpack . util . Platform . Name ; import static org . junit . Assert . assertEquals ; public abstract class AbstractPlatformTest { protected void checkPlatform ( Platform expected , Platform platform ) { checkPlatform ( platform , expected . getName ( ) , expected . getSymbolicName ( ) , expected . getVersion ( ) , expected . getArch ( ) ) ; } protected void checkPlatform ( Platform platform , Name name , String symbolicName , String version , Arch arch ) { assertEquals ( name , platform . getName ( ) ) ; assertEquals ( symbolicName , platform . getSymbolicName ( ) ) ; assertEquals ( version , platform . getVersion ( ) ) ; assertEquals ( arch , platform . getArch ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . util ; import static com . izforge . izpack . util . Platform . Arch ; import static com . izforge . izpack . util . Platform . Name ; import static org . junit . Assert . assertEquals ; import java . lang . reflect . Field ; import java . lang . reflect . Modifier ; import java . util . Arrays ; import java . util . List ; import org . junit . Test ; public class PlatformsTest extends AbstractPlatformTest { @ Test public void testGetCurrentPlatform ( ) { Platforms platforms = new Platforms ( ) ; Platform platform = platforms . getCurrentPlatform ( ) ; String osName = System . getProperty ( OsVersionConstants . OSNAME ) ; Name name = platforms . getCurrentOSName ( ) ; Arch arch = platforms . getArch ( System . getProperty ( OsVersionConstants . OSARCH ) ) ; String version = System . getProperty ( OsVersionConstants . OSVERSION ) ; String javaVersion = System . getProperty ( "<STR_LIT>" ) ; Platform match = platforms . findMatch ( osName , name , arch , version ) ; Platform expected = platforms . getPlatform ( match , arch , version , javaVersion ) ; checkPlatform ( expected , platform ) ; } @ Test public void testGetCurrentPlatformByNameArch ( ) { Platforms platforms = new Platforms ( ) ; Platform platform1 = platforms . getCurrentPlatform ( "<STR_LIT>" , OsVersionConstants . AMD64 ) ; checkPlatform ( platform1 , Name . WINDOWS , null , null , Arch . X64 ) ; Platform platform2 = platforms . getCurrentPlatform ( "<STR_LIT>" , OsVersionConstants . X86 ) ; checkPlatform ( platform2 , Name . MAC_OSX , null , null , Arch . X86 ) ; } @ Test public void testGetCurrentPlatformForLinux ( ) { checkLinuxPlatform ( Name . DEBIAN_LINUX , null , null , true ) ; checkLinuxPlatform ( Name . FEDORA_LINUX , OsVersionConstants . FEDORA , null , false ) ; checkLinuxPlatform ( Name . MANDRAKE_LINUX , OsVersionConstants . MANDRAKE , null , false ) ; checkLinuxPlatform ( Name . MANDRIVA_LINUX , OsVersionConstants . MANDRIVA , null , false ) ; checkLinuxPlatform ( Name . RED_HAT_LINUX , OsVersionConstants . REDHAT , null , false ) ; checkLinuxPlatform ( Name . SUSE_LINUX , OsVersionConstants . SUSE , null , false ) ; checkLinuxPlatform ( Name . UBUNTU_LINUX , null , OsVersionConstants . UBUNTU , false ) ; } @ Test public void testGetCurrentPlatformByNameArchVersion ( ) { Platforms platforms = new Platforms ( ) ; Platform windows7x64 = platforms . getCurrentPlatform ( "<STR_LIT>" , OsVersionConstants . AMD64 , OsVersionConstants . WINDOWS_7_VERSION ) ; assertEquals ( Name . WINDOWS , windows7x64 . getName ( ) ) ; assertEquals ( "<STR_LIT>" , windows7x64 . getSymbolicName ( ) ) ; assertEquals ( Arch . X64 , windows7x64 . getArch ( ) ) ; assertEquals ( "<STR_LIT>" , windows7x64 . getVersion ( ) ) ; } @ Test public void testGetPlatformByNameArch ( ) { Platforms platforms = new Platforms ( ) ; checkPlatform ( Platforms . WINDOWS , platforms . getPlatform ( "<STR_LIT>" , null ) ) ; checkPlatform ( new Platform ( Platforms . WINDOWS , Arch . X86 ) , platforms . getPlatform ( "<STR_LIT>" , "<STR_LIT>" ) ) ; checkPlatform ( Platforms . WINDOWS_7 , platforms . getPlatform ( "<STR_LIT>" , null ) ) ; checkPlatform ( new Platform ( Platforms . WINDOWS_7 , Arch . X64 ) , platforms . getPlatform ( "<STR_LIT>" , "<STR_LIT>" ) ) ; checkPlatform ( Platforms . LINUX , platforms . getPlatform ( "<STR_LIT>" , null ) ) ; } @ Test public void testGetPlatformByNameArchVersion ( ) { Platforms platforms = new Platforms ( ) ; checkPlatform ( Platforms . WINDOWS , platforms . getPlatform ( "<STR_LIT>" , null , null ) ) ; checkPlatform ( new Platform ( Platforms . WINDOWS_7 , Arch . X86 ) , platforms . getPlatform ( "<STR_LIT>" , "<STR_LIT>" , OsVersionConstants . WINDOWS_7_VERSION ) ) ; checkPlatform ( new Platform ( Platforms . DEBIAN_LINUX , Arch . X64 ) , platforms . getPlatform ( "<STR_LIT>" , "<STR_LIT>" , null ) ) ; } @ Test public void testPlatforms ( ) { int expected = <NUM_LIT:0> ; for ( Field field : Platforms . class . getFields ( ) ) { int mod = field . getModifiers ( ) ; if ( Modifier . isStatic ( mod ) && Modifier . isPublic ( mod ) && field . getType ( ) . equals ( Platform . class ) ) { ++ expected ; } } assertEquals ( expected , Platforms . PLATFORMS . length ) ; } private void checkLinuxPlatform ( Name expectedName , final String fromRelease , final String fromProcVersion , final boolean debianExists ) { Platforms platforms = new Platforms ( ) { @ Override protected String getReleasePath ( ) { return "<STR_LIT>" ; } @ Override protected List < String > getText ( String path ) { if ( OsVersionConstants . PROC_VERSION . equals ( path ) ) { if ( fromProcVersion != null ) { return Arrays . asList ( fromProcVersion ) ; } } else if ( fromRelease != null ) { return Arrays . asList ( fromRelease ) ; } return null ; } @ Override protected boolean exists ( String path ) { return debianExists ; } } ; String version = "<STR_LIT>" ; Platform platform = platforms . getCurrentPlatform ( OsVersionConstants . LINUX , OsVersionConstants . X86 , version ) ; checkPlatform ( platform , expectedName , null , version , Arch . X86 ) ; } } </s>
|
<s> package com . izforge . izpack . gui ; import javax . swing . * ; import java . awt . * ; public class MultiLineLabel extends JComponent { private static final long serialVersionUID = <NUM_LIT> ; public static final int LEFT = <NUM_LIT:0> ; public static final int CENTER = <NUM_LIT:1> ; public static final int RIGHT = <NUM_LIT:2> ; public static final int DEFAULT_MARGIN = <NUM_LIT:10> ; public static final int DEFAULT_ALIGN = LEFT ; public static final int LEAST_ALLOWED = <NUM_LIT> ; private static final int FOUND = <NUM_LIT:0> ; private static final int NOT_FOUND = <NUM_LIT:1> ; private static final int NOT_DONE = <NUM_LIT:0> ; private static final int DONE = <NUM_LIT:1> ; private static final char [ ] WHITE_SPACE = { '<CHAR_LIT:U+0020>' , '<STR_LIT:\n>' , '<STR_LIT:\t>' } ; private static final char [ ] SPACES = { '<CHAR_LIT:U+0020>' , '<STR_LIT:\t>' } ; private static final char NEW_LINE = '<STR_LIT:\n>' ; protected java . util . List < String > line = new java . util . ArrayList < String > ( ) ; protected String labelText ; protected int numLines ; protected int marginHeight ; protected int marginWidth ; protected int lineHeight ; protected int lineAscent ; protected int lineDescent ; protected int [ ] lineWidth ; protected int maxWidth ; private int maxAllowed = LEAST_ALLOWED ; private boolean maxAllowedSet = false ; protected int alignment = LEFT ; public MultiLineLabel ( String text , int horMargin , int vertMargin , int maxWidth , int justify ) { this . labelText = text ; this . marginWidth = horMargin ; this . marginHeight = vertMargin ; this . maxAllowed = maxWidth ; this . maxAllowedSet = true ; this . alignment = justify ; } public MultiLineLabel ( String label , int marginWidth , int marginHeight ) { this . labelText = label ; this . marginWidth = marginWidth ; this . marginHeight = marginHeight ; } public MultiLineLabel ( String label , int alignment ) { this . labelText = label ; this . alignment = alignment ; } public MultiLineLabel ( String label ) { this . labelText = label ; } int getPosition ( String target , int start , char [ ] source , int mode ) { int status ; int position ; int scan ; int targetEnd ; int sourceLength ; char temp ; targetEnd = ( target . length ( ) - <NUM_LIT:1> ) ; sourceLength = source . length ; position = start ; if ( mode == FOUND ) { status = NOT_DONE ; while ( status != DONE ) { position ++ ; if ( ! ( position < targetEnd ) ) { return ( targetEnd ) ; } temp = target . charAt ( position ) ; for ( scan = <NUM_LIT:0> ; scan < sourceLength ; scan ++ ) { if ( source [ scan ] == temp ) { status = DONE ; } } } return ( position ) ; } else if ( mode == NOT_FOUND ) { status = NOT_DONE ; while ( status != DONE ) { position ++ ; if ( ! ( position < targetEnd ) ) { return ( targetEnd ) ; } temp = target . charAt ( position ) ; status = DONE ; for ( scan = <NUM_LIT:0> ; scan < sourceLength ; scan ++ ) { if ( source [ scan ] == temp ) { status = NOT_DONE ; } } } return ( position ) ; } return ( <NUM_LIT:0> ) ; } int breakWord ( String word , FontMetrics fm ) { int width ; int currentPos ; int endPos ; width = <NUM_LIT:0> ; currentPos = <NUM_LIT:0> ; endPos = word . length ( ) - <NUM_LIT:1> ; if ( endPos <= <NUM_LIT:0> ) { return ( currentPos ) ; } while ( ( width < maxAllowed ) && ( currentPos < endPos ) ) { currentPos ++ ; width = fm . stringWidth ( labelText . substring ( <NUM_LIT:0> , currentPos ) ) ; } if ( currentPos != endPos ) { currentPos -- ; } return ( currentPos ) ; } private void divideLabel ( ) { int width ; int startPos ; int currentPos ; int lastPos ; int endPos ; line . clear ( ) ; FontMetrics fontMetrics = this . getFontMetrics ( this . getFont ( ) ) ; startPos = <NUM_LIT:0> ; currentPos = startPos ; lastPos = currentPos ; endPos = ( labelText . length ( ) - <NUM_LIT:1> ) ; while ( currentPos < endPos ) { width = <NUM_LIT:0> ; while ( ( width < maxAllowed ) && ( currentPos < endPos ) && ( labelText . charAt ( currentPos ) != NEW_LINE ) ) { lastPos = currentPos ; currentPos = getPosition ( labelText , currentPos , WHITE_SPACE , FOUND ) ; width = fontMetrics . stringWidth ( labelText . substring ( startPos , currentPos ) ) ; } if ( labelText . charAt ( currentPos ) == NEW_LINE ) { lastPos = currentPos ; } if ( currentPos == endPos && width <= maxAllowed ) { lastPos = currentPos ; String s = labelText . substring ( startPos ) ; line . add ( s ) ; } else { if ( lastPos == startPos ) { lastPos = startPos + breakWord ( labelText . substring ( startPos , currentPos ) , fontMetrics ) ; } String s = labelText . substring ( startPos , lastPos ) ; line . add ( s ) ; } startPos = getPosition ( labelText , lastPos , SPACES , NOT_FOUND ) ; currentPos = startPos ; } numLines = line . size ( ) ; lineWidth = new int [ numLines ] ; } protected void measure ( ) { if ( ! maxAllowedSet ) { maxAllowed = getParent ( ) . getSize ( ) . width ; } if ( maxAllowed < ( <NUM_LIT:20> ) ) { return ; } FontMetrics fontMetrics = this . getFontMetrics ( this . getFont ( ) ) ; if ( fontMetrics == null ) { return ; } divideLabel ( ) ; this . lineHeight = fontMetrics . getHeight ( ) ; this . lineDescent = fontMetrics . getDescent ( ) ; this . maxWidth = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < numLines ; i ++ ) { this . lineWidth [ i ] = fontMetrics . stringWidth ( this . line . get ( i ) ) ; if ( this . lineWidth [ i ] > this . maxWidth ) { this . maxWidth = this . lineWidth [ i ] ; } } } public void paint ( Graphics graphics ) { int x ; int y ; measure ( ) ; Dimension size = this . getSize ( ) ; y = lineAscent + ( size . height - ( numLines * lineHeight ) ) / <NUM_LIT:2> ; for ( int i = <NUM_LIT:0> ; i < numLines ; i ++ ) { y += lineHeight ; switch ( alignment ) { case LEFT : x = marginWidth ; break ; case CENTER : x = ( size . width - lineWidth [ i ] ) / <NUM_LIT:2> ; break ; case RIGHT : x = size . width - marginWidth - lineWidth [ i ] ; break ; default : x = ( size . width - lineWidth [ i ] ) / <NUM_LIT:2> ; } graphics . drawString ( line . get ( i ) , x , y ) ; } } public void setText ( String labelText ) { this . labelText = labelText ; repaint ( ) ; } public void setFont ( Font font ) { super . setFont ( font ) ; repaint ( ) ; } public void setColor ( Color color ) { super . setForeground ( color ) ; repaint ( ) ; } public void setJustify ( int alignment ) { this . alignment = alignment ; repaint ( ) ; } public void setMaxWidth ( int width ) { this . maxAllowed = width ; this . maxAllowedSet = true ; repaint ( ) ; } public void setMarginWidth ( int margin ) { this . marginWidth = margin ; repaint ( ) ; } public void setMarginHeight ( int margin ) { this . marginHeight = margin ; repaint ( ) ; } public void setBounds ( int x , int y , int width , int height ) { super . setBounds ( x , y , width , height ) ; this . maxAllowed = width ; this . maxAllowedSet = true ; } public int getAlignment ( ) { return ( this . alignment ) ; } public int getMarginWidth ( ) { return ( this . marginWidth ) ; } public int getMarginHeight ( ) { return ( this . marginHeight ) ; } public Dimension getPreferredSize ( ) { measure ( ) ; return ( new Dimension ( maxAllowed , ( numLines * ( lineHeight + lineAscent + lineDescent ) ) + ( <NUM_LIT:2> * marginHeight ) ) ) ; } public Dimension getMinimumSize ( ) { measure ( ) ; return ( new Dimension ( maxAllowed , ( numLines * ( lineHeight + lineAscent + lineDescent ) ) + ( <NUM_LIT:2> * marginHeight ) ) ) ; } public void addNotify ( ) { super . addNotify ( ) ; } } </s>
|
<s> package com . izforge . izpack . gui ; import javax . swing . * ; import java . awt . * ; public class LabelFactory implements SwingConstants { private static boolean useLabelIcons = true ; private static float labelFontSizeVal = <NUM_LIT:1.0f> ; private static Font customLabelFontObj = null ; public static boolean isUseLabelIcons ( ) { return useLabelIcons ; } public static void setUseLabelIcons ( boolean useLabelIcons ) { LabelFactory . useLabelIcons = useLabelIcons ; } public static float getLabelFontSize ( ) { return labelFontSizeVal ; } public static void setLabelFontSize ( float val ) { if ( val > <NUM_LIT:0.0f> && val <= <NUM_LIT> && val != labelFontSizeVal ) { labelFontSizeVal = val ; final Font fontObj = ( new JLabel ( ) ) . getFont ( ) ; customLabelFontObj = fontObj . deriveFont ( fontObj . getSize2D ( ) * val ) ; } } public static JLabel create ( Icon image ) { return ( create ( image , CENTER ) ) ; } public static JLabel create ( Icon image , int horizontalAlignment ) { return ( create ( null , image , horizontalAlignment ) ) ; } public static JLabel create ( String text ) { return ( create ( text , CENTER ) ) ; } public static JLabel create ( String text , boolean isFullLine ) { return ( create ( text , CENTER , isFullLine ) ) ; } public static JLabel create ( String text , int horizontalAlignment ) { return ( create ( text , null , horizontalAlignment ) ) ; } public static JLabel create ( String text , int horizontalAlignment , boolean isFullLine ) { return ( create ( text , null , horizontalAlignment , isFullLine ) ) ; } public static JLabel create ( String text , Icon image , int horizontalAlignment ) { return ( create ( text , image , horizontalAlignment , false ) ) ; } public static JLabel create ( String text , Icon image , int horizontalAlignment , boolean isFullLine ) { JLabel retval = null ; if ( image != null && isUseLabelIcons ( ) ) { if ( isFullLine ) { retval = new FullLineLabel ( image ) ; } else { retval = new JLabel ( image ) ; } } else { if ( isFullLine ) { retval = new FullLineLabel ( ) ; } else { retval = new JLabel ( ) ; } } if ( text != null ) { retval . setText ( text ) ; } if ( customLabelFontObj != null ) { retval . setFont ( customLabelFontObj ) ; } retval . setHorizontalAlignment ( horizontalAlignment ) ; return ( retval ) ; } public static class FullLineLabel extends JLabel { private static final long serialVersionUID = <NUM_LIT> ; public FullLineLabel ( Icon image ) { super ( image ) ; } public FullLineLabel ( ) { super ( ) ; } } } </s>
|
<s> package com . izforge . izpack . gui ; import java . awt . * ; public class FlowLayout implements LayoutManager { public static final int LEFT = <NUM_LIT:0> ; public static final int CENTER = <NUM_LIT:1> ; public static final int RIGHT = <NUM_LIT:2> ; public static final int LEADING = <NUM_LIT:3> ; public static final int TRAILING = <NUM_LIT:4> ; int align ; int newAlign ; int hgap ; int vgap ; public FlowLayout ( ) { this ( CENTER , <NUM_LIT:5> , <NUM_LIT:5> ) ; } public FlowLayout ( int align ) { this ( align , <NUM_LIT:5> , <NUM_LIT:5> ) ; } public FlowLayout ( int align , int hgap , int vgap ) { this . hgap = hgap ; this . vgap = vgap ; setAlignment ( align ) ; } public int getAlignment ( ) { return ( newAlign ) ; } public void setAlignment ( int align ) { this . newAlign = align ; switch ( align ) { case LEADING : this . align = LEFT ; break ; case TRAILING : this . align = RIGHT ; break ; default : this . align = align ; break ; } } public int getHgap ( ) { return ( hgap ) ; } public void setHgap ( int hgap ) { this . hgap = hgap ; } public int getVgap ( ) { return ( vgap ) ; } public void setVgap ( int vgap ) { this . vgap = vgap ; } public void addLayoutComponent ( String name , Component comp ) { } public void removeLayoutComponent ( Component comp ) { } public Dimension preferredLayoutSize ( Container target ) { synchronized ( target . getTreeLock ( ) ) { Dimension dimension = new Dimension ( <NUM_LIT:0> , <NUM_LIT:0> ) ; int nmembers = target . getComponentCount ( ) ; boolean firstVisibleComponent = true ; for ( int i = <NUM_LIT:0> ; i < nmembers ; i ++ ) { Component component = target . getComponent ( i ) ; if ( component . isVisible ( ) ) { Dimension preferredSize = component . getPreferredSize ( ) ; dimension . height = Math . max ( dimension . height , preferredSize . height ) ; if ( firstVisibleComponent ) { firstVisibleComponent = false ; } else { dimension . width += hgap ; } dimension . width += preferredSize . width ; } } Insets insets = target . getInsets ( ) ; dimension . width += insets . left + insets . right + hgap * <NUM_LIT:2> ; dimension . height += insets . top + insets . bottom + vgap * <NUM_LIT:2> ; return ( dimension ) ; } } public Dimension minimumLayoutSize ( Container target ) { synchronized ( target . getTreeLock ( ) ) { Dimension dimension = new Dimension ( <NUM_LIT:0> , <NUM_LIT:0> ) ; int nmembers = target . getComponentCount ( ) ; for ( int i = <NUM_LIT:0> ; i < nmembers ; i ++ ) { Component component = target . getComponent ( i ) ; if ( component . isVisible ( ) ) { Dimension minimumSize = component . getMinimumSize ( ) ; dimension . height = Math . max ( dimension . height , minimumSize . height ) ; if ( i > <NUM_LIT:0> ) { dimension . width += hgap ; } dimension . width += minimumSize . width ; } } Insets insets = target . getInsets ( ) ; dimension . width += insets . left + insets . right + hgap * <NUM_LIT:2> ; dimension . height += insets . top + insets . bottom + vgap * <NUM_LIT:2> ; return ( dimension ) ; } } private void moveComponents ( Container target , int x , int y , int width , int height , int rowStart , int rowEnd , boolean ltr ) { synchronized ( target . getTreeLock ( ) ) { switch ( newAlign ) { case LEFT : x += ltr ? <NUM_LIT:0> : width ; break ; case CENTER : x += width / <NUM_LIT:2> ; break ; case RIGHT : x += ltr ? width : <NUM_LIT:0> ; break ; case LEADING : break ; case TRAILING : x += width ; break ; } for ( int i = rowStart ; i < rowEnd ; i ++ ) { Component component = target . getComponent ( i ) ; if ( component . isVisible ( ) ) { if ( ltr ) { component . setLocation ( x , y + ( height - component . getSize ( ) . height ) / <NUM_LIT:2> ) ; } else { component . setLocation ( target . getSize ( ) . width - x - component . getSize ( ) . width , y + ( height - component . getSize ( ) . height ) / <NUM_LIT:2> ) ; } x += component . getSize ( ) . width + hgap ; } } } } public void layoutContainer ( Container target ) { synchronized ( target . getTreeLock ( ) ) { Insets insets = target . getInsets ( ) ; int maxWidth = target . getSize ( ) . width - ( insets . left + insets . right + hgap * <NUM_LIT:2> ) ; int nMembers = target . getComponentCount ( ) ; int x = <NUM_LIT:0> ; int y = insets . top + vgap ; int rowh = <NUM_LIT:0> ; int start = <NUM_LIT:0> ; boolean ltr = target . getComponentOrientation ( ) . isLeftToRight ( ) ; for ( int i = <NUM_LIT:0> ; i < nMembers ; i ++ ) { Component component = target . getComponent ( i ) ; if ( component . isVisible ( ) ) { Dimension preferredSize = component . getPreferredSize ( ) ; component . setSize ( preferredSize . width , preferredSize . height ) ; if ( ( x == <NUM_LIT:0> ) || ( ( x + preferredSize . width ) <= maxWidth ) ) { if ( x > <NUM_LIT:0> ) { x += hgap ; } x += preferredSize . width ; rowh = Math . max ( rowh , preferredSize . height ) ; } else { moveComponents ( target , insets . left , y , maxWidth - x , rowh , start , i , ltr ) ; x = preferredSize . width ; y += vgap + rowh ; rowh = preferredSize . height ; start = i ; } } } moveComponents ( target , insets . left , y , maxWidth - x , rowh , start , nMembers , ltr ) ; } } public String toString ( ) { String str = "<STR_LIT>" ; switch ( align ) { case LEFT : str = "<STR_LIT>" ; break ; case CENTER : str = "<STR_LIT>" ; break ; case RIGHT : str = "<STR_LIT>" ; break ; case LEADING : str = "<STR_LIT>" ; break ; case TRAILING : str = "<STR_LIT>" ; break ; } return ( getClass ( ) . getName ( ) + "<STR_LIT>" + hgap + "<STR_LIT>" + vgap + str + "<STR_LIT:]>" ) ; } } </s>
|
<s> package com . izforge . izpack . gui ; import java . awt . Color ; import java . awt . event . ActionListener ; import java . awt . event . KeyEvent ; import javax . swing . Action ; import javax . swing . Icon ; import javax . swing . JButton ; import javax . swing . JComponent ; import javax . swing . KeyStroke ; public class ButtonFactory { private static boolean useHighlightButtons = false ; private static boolean useButtonIcons = false ; public static void useButtonIcons ( ) { useButtonIcons ( true ) ; } public static void useButtonIcons ( boolean useit ) { if ( System . getProperty ( "<STR_LIT>" ) == null ) { useButtonIcons = useit ; } } public static void useHighlightButtons ( ) { useHighlightButtons ( true ) ; } public static void useHighlightButtons ( boolean useit ) { if ( System . getProperty ( "<STR_LIT>" ) == null ) { useHighlightButtons = useit ; } useButtonIcons ( useit ) ; } public static JButton createButton ( Icon icon , Color color ) { JButton result ; if ( useHighlightButtons ) { if ( useButtonIcons ) { result = new HighlightJButton ( icon , color ) ; } else { result = new HighlightJButton ( "<STR_LIT>" , color ) ; } } else { if ( useButtonIcons ) { result = new JButton ( icon ) ; } else { result = new JButton ( ) ; } } return addEnterKeyAction ( result ) ; } public static JButton createButton ( String text , Color color ) { JButton result ; if ( useHighlightButtons ) { result = new HighlightJButton ( text , color ) ; } else { result = new JButton ( text ) ; } return result ; } public static JButton createButton ( String text , Icon icon , Color color ) { JButton result ; if ( useHighlightButtons ) { if ( useButtonIcons ) { result = new HighlightJButton ( text , icon , color ) ; } else { result = new HighlightJButton ( text , color ) ; } } else { if ( useButtonIcons ) { result = new JButton ( text , icon ) ; } else { result = new JButton ( text ) ; } } return addEnterKeyAction ( result ) ; } public static JButton createButton ( Action a , Color color ) { JButton result ; if ( useHighlightButtons ) { result = new HighlightJButton ( a , color ) ; } else { result = new JButton ( a ) ; } return addEnterKeyAction ( result ) ; } private static JButton addEnterKeyAction ( JButton button ) { ActionListener spacePress = button . getActionForKeyStroke ( KeyStroke . getKeyStroke ( KeyEvent . VK_SPACE , <NUM_LIT:0> , false ) ) ; ActionListener spaceRelease = button . getActionForKeyStroke ( KeyStroke . getKeyStroke ( KeyEvent . VK_SPACE , <NUM_LIT:0> , true ) ) ; ActionListener enterPress = button . getActionForKeyStroke ( KeyStroke . getKeyStroke ( KeyEvent . VK_ENTER , <NUM_LIT:0> , false ) ) ; ActionListener enterRelease = button . getActionForKeyStroke ( KeyStroke . getKeyStroke ( KeyEvent . VK_ENTER , <NUM_LIT:0> , true ) ) ; if ( spacePress != null && spaceRelease != null && enterPress == null && enterRelease == null ) { button . registerKeyboardAction ( spacePress , null , KeyStroke . getKeyStroke ( KeyEvent . VK_ENTER , <NUM_LIT:0> , false ) , JComponent . WHEN_FOCUSED ) ; button . registerKeyboardAction ( spaceRelease , null , KeyStroke . getKeyStroke ( KeyEvent . VK_ENTER , <NUM_LIT:0> , true ) , JComponent . WHEN_FOCUSED ) ; } return button ; } } </s>
|
<s> package com . izforge . izpack . gui ; import javax . swing . SwingConstants ; public interface LayoutConstants extends SwingConstants { final static int LABEL_GAP = - <NUM_LIT:1> ; final static int TEXT_GAP = - <NUM_LIT:2> ; final static int CONTROL_GAP = - <NUM_LIT:3> ; final static int PARAGRAPH_GAP = - <NUM_LIT:4> ; final static int LABEL_TO_TEXT_GAP = - <NUM_LIT:5> ; final static int LABEL_TO_CONTROL_GAP = - <NUM_LIT:6> ; final static int TEXT_TO_LABEL_GAP = - <NUM_LIT:7> ; final static int CONTROL_TO_LABEL_GAP = - <NUM_LIT:8> ; final static int CONTROL_TO_TEXT_GAP = - <NUM_LIT:9> ; final static int TEXT_TO_CONTROL_GAP = - <NUM_LIT:10> ; final static int TOP_GAP = - <NUM_LIT:11> ; final static int ALL_GAP = - <NUM_LIT:12> ; final static int NO_GAP = - <NUM_LIT> ; final static int FILLER1_GAP = - <NUM_LIT> ; final static int FILLER2_GAP = - <NUM_LIT:15> ; final static int FILLER13_GAP = - <NUM_LIT:16> ; final static int FILLER4_GAP = - <NUM_LIT> ; final static int FILLER5_GAP = - <NUM_LIT> ; final static int AUTOMATIC_GAP = - <NUM_LIT> ; final static int GAP_LOAD_MARKER = <NUM_LIT:0> ; public static final int NEXT_ROW = - <NUM_LIT:1> ; public static final int CURRENT_ROW = - <NUM_LIT:2> ; public static final int NEXT_COLUMN = - <NUM_LIT:1> ; public static final int CURRENT_COLUMN = - <NUM_LIT:2> ; public static final int DEFAULT_LABEL_ALIGNMENT = - <NUM_LIT:1> ; public static final int DEFAULT_TEXT_ALIGNMENT = - <NUM_LIT:2> ; public static final int DEFAULT_CONTROL_ALIGNMENT = - <NUM_LIT:3> ; public static final int LABEL_CONSTRAINT = <NUM_LIT:0> ; public static final int TEXT_CONSTRAINT = <NUM_LIT:1> ; public static final int CONTROL_CONSTRAINT = <NUM_LIT:2> ; public static final int FULL_LINE_COMPONENT_CONSTRAINT = <NUM_LIT:3> ; public static final int XY_VARIABLE_CONSTRAINT = <NUM_LIT:4> ; public static final int XDUMMY_CONSTRAINT = <NUM_LIT:5> ; public static final int YDUMMY_CONSTRAINT = <NUM_LIT:6> ; public static final int FULL_LINE_CONTROL_CONSTRAINT = <NUM_LIT:7> ; public static final int NO_STRETCH = <NUM_LIT:0> ; public static final int RELATIVE_STRETCH = <NUM_LIT:1> ; public static final int ABSOLUTE_STRETCH = <NUM_LIT:2> ; public static final double FULL_LINE_STRETCH = - <NUM_LIT:1.0> ; public static final double FULL_COLUMN_STRETCH = - <NUM_LIT> ; public static final String NEXT_LINE = "<STR_LIT>" ; public static final int NO_FILL_OUT_COLUMN = <NUM_LIT:0> ; public static final int FILL_OUT_COLUMN_WIDTH = <NUM_LIT:1> ; public static final int FILL_OUT_COLUMN_HEIGHT = <NUM_LIT:2> ; public static final int FILL_OUT_COLUMN_SIZE = <NUM_LIT:3> ; } </s>
|
<s> package com . izforge . izpack . gui ; import com . izforge . izpack . api . adaptator . IXMLElement ; public class TwoColumnConstraintsFactory { private static final String ALIGNMENT = "<STR_LIT>" ; private static final String LABEL_ALIGNMENT = "<STR_LIT>" ; private static final String CONTROL_ALIGNMENT = "<STR_LIT>" ; private static final String LABEL_POSITION = "<STR_LIT>" ; private static final String CONTROL_POSITION = "<STR_LIT>" ; private static final String LABEL_INDENT = "<STR_LIT>" ; private static final String CONTROL_INDENT = "<STR_LIT>" ; private static final String LEFT = "<STR_LIT>" ; private static final String CENTER = "<STR_LIT>" ; private static final String RIGHT = "<STR_LIT>" ; private static final String WEST = "<STR_LIT>" ; private static final String WESTONLY = "<STR_LIT>" ; private static final String EAST = "<STR_LIT>" ; private static final String EASTONLY = "<STR_LIT>" ; private static final String BOTH = "<STR_LIT>" ; private static final String TRUE = "<STR_LIT:true>" ; private static final String FALSE = "<STR_LIT:false>" ; public static TwoColumnConstraints createTextConstraint ( IXMLElement field ) { return createTextConstraint ( field , TwoColumnConstraints . BOTH , false , false ) ; } public static TwoColumnConstraints createLabelConstraint ( IXMLElement field ) { return createLabelConstraint ( field , TwoColumnConstraints . WEST , false , false ) ; } public static TwoColumnConstraints createControlConstraint ( IXMLElement field ) { return createControlConstraint ( field , TwoColumnConstraints . EAST , false , false ) ; } public static TwoColumnConstraints createTextConstraint ( IXMLElement field , int position , boolean indent , boolean stretch ) { TwoColumnConstraints constraint = new TwoColumnConstraints ( ) ; constraint . position = position ; constraint . indent = indent ; constraint . stretch = stretch ; constraint . align = TwoColumnConstraints . LEFT ; overrideTextDefaults ( constraint , field ) ; return constraint ; } public static TwoColumnConstraints createControlConstraint ( IXMLElement field , int position , boolean indent , boolean stretch ) { TwoColumnConstraints constraint = new TwoColumnConstraints ( ) ; constraint . position = position ; constraint . indent = indent ; constraint . stretch = stretch ; constraint . align = TwoColumnConstraints . LEFT ; overrideControlDefaults ( constraint , field ) ; return constraint ; } public static TwoColumnConstraints createLabelConstraint ( IXMLElement field , int position , boolean indent , boolean stretch ) { TwoColumnConstraints constraint = new TwoColumnConstraints ( ) ; constraint . position = position ; constraint . indent = indent ; constraint . stretch = stretch ; constraint . align = TwoColumnConstraints . LEFT ; overrideLabelDefaults ( constraint , field ) ; return constraint ; } private static void overrideTextDefaults ( TwoColumnConstraints constraint , IXMLElement field ) { if ( field != null ) { overrideAlignment ( constraint , field . getAttribute ( ALIGNMENT ) ) ; overrideAlignment ( constraint , field . getAttribute ( LABEL_ALIGNMENT ) ) ; } } private static void overrideLabelDefaults ( TwoColumnConstraints constraint , IXMLElement field ) { if ( field != null ) { overrideAlignment ( constraint , field . getAttribute ( LABEL_ALIGNMENT ) ) ; overridePosition ( constraint , field . getAttribute ( LABEL_POSITION ) ) ; overrideIndent ( constraint , field . getAttribute ( LABEL_INDENT ) ) ; } } private static void overrideControlDefaults ( TwoColumnConstraints constraint , IXMLElement field ) { if ( field != null ) { overrideAlignment ( constraint , field . getAttribute ( CONTROL_ALIGNMENT ) ) ; overridePosition ( constraint , field . getAttribute ( CONTROL_POSITION ) ) ; overrideIndent ( constraint , field . getAttribute ( CONTROL_INDENT ) ) ; } } private static void overrideAlignment ( TwoColumnConstraints constraint , String value ) { if ( value != null ) { if ( value . equalsIgnoreCase ( LEFT ) ) { constraint . align = TwoColumnConstraints . LEFT ; } else if ( value . equalsIgnoreCase ( CENTER ) ) { constraint . align = TwoColumnConstraints . CENTER ; } else if ( value . equalsIgnoreCase ( RIGHT ) ) { constraint . align = TwoColumnConstraints . RIGHT ; } } } private static void overridePosition ( TwoColumnConstraints constraint , String value ) { if ( value != null ) { if ( value . equalsIgnoreCase ( WEST ) ) { constraint . position = TwoColumnConstraints . WEST ; } else if ( value . equalsIgnoreCase ( EAST ) ) { constraint . position = TwoColumnConstraints . EAST ; } else if ( value . equalsIgnoreCase ( BOTH ) ) { constraint . position = TwoColumnConstraints . BOTH ; } else if ( value . equalsIgnoreCase ( WESTONLY ) ) { constraint . position = TwoColumnConstraints . WESTONLY ; } else if ( value . equalsIgnoreCase ( EASTONLY ) ) { constraint . position = TwoColumnConstraints . EASTONLY ; } } } private static void overrideIndent ( TwoColumnConstraints constraint , String value ) { if ( value != null ) { if ( value . equalsIgnoreCase ( TRUE ) ) { constraint . indent = true ; } else if ( value . equalsIgnoreCase ( FALSE ) ) { constraint . indent = false ; } } } } </s>
|
<s> package com . izforge . izpack . gui ; import java . io . File ; import javax . swing . filechooser . FileFilter ; import com . izforge . izpack . api . resource . Messages ; public class AutomatedInstallScriptFilter extends FileFilter { public static final String DEFAULT_DESCRIPTION = "<STR_LIT>" ; public static final String DESCRIPTION_LOCALE_DATABASE_KEY = "<STR_LIT>" ; private final Messages messages ; public AutomatedInstallScriptFilter ( Messages messages ) { this . messages = messages ; } @ Override public boolean accept ( File pathname ) { return pathname != null && ( pathname . isDirectory ( ) || pathname . getName ( ) . endsWith ( "<STR_LIT>" ) ) ; } @ Override public String getDescription ( ) { String result = messages . get ( DESCRIPTION_LOCALE_DATABASE_KEY ) ; return ( DESCRIPTION_LOCALE_DATABASE_KEY . equals ( result ) ) ? DEFAULT_DESCRIPTION : result ; } } </s>
|
<s> package com . izforge . izpack . gui ; import javax . swing . Action ; import javax . swing . Icon ; import javax . swing . JButton ; import java . awt . Color ; import java . awt . event . MouseAdapter ; import java . awt . event . MouseEvent ; public class HighlightJButton extends JButton { private static final long serialVersionUID = <NUM_LIT> ; HighlightJButton ( Icon icon , Color color ) { super ( icon ) ; initButton ( color ) ; } HighlightJButton ( String text , Color color ) { super ( text ) ; initButton ( color ) ; } HighlightJButton ( String text , Icon icon , Color color ) { super ( text , icon ) ; initButton ( color ) ; } HighlightJButton ( Action a , Color color ) { super ( a ) ; initButton ( color ) ; } protected void initButton ( Color highlightColor ) { this . highlightColor = highlightColor ; defaultColor = getBackground ( ) ; addMouseListener ( new MouseHandler ( ) ) ; } public void setEnabled ( boolean b ) { reset ( ) ; super . setEnabled ( b ) ; } protected void reset ( ) { setBackground ( defaultColor ) ; } protected Color highlightColor ; protected Color defaultColor ; private class MouseHandler extends MouseAdapter { public void mouseEntered ( MouseEvent e ) { if ( isEnabled ( ) ) { setBackground ( highlightColor ) ; } } public void mouseExited ( MouseEvent e ) { if ( isEnabled ( ) ) { setBackground ( defaultColor ) ; } } } } </s>
|
<s> package com . izforge . izpack . gui ; import javax . swing . plaf . ColorUIResource ; @ Deprecated public class IzPackKMetalTheme extends IzPackMetalTheme { private final ColorUIResource primary1 = new ColorUIResource ( <NUM_LIT:32> , <NUM_LIT:32> , <NUM_LIT> ) ; private final ColorUIResource primary2 = new ColorUIResource ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; private final ColorUIResource primary3 = new ColorUIResource ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; private final ColorUIResource secondary1 = new ColorUIResource ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; private final ColorUIResource secondary2 = new ColorUIResource ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; private final ColorUIResource secondary3 = new ColorUIResource ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; public IzPackKMetalTheme ( ) { super ( ) ; } public ColorUIResource getPrimary1 ( ) { return primary1 ; } public ColorUIResource getPrimary2 ( ) { return primary2 ; } public ColorUIResource getPrimary3 ( ) { return primary3 ; } public ColorUIResource getSecondary1 ( ) { return secondary1 ; } public ColorUIResource getSecondary2 ( ) { return secondary2 ; } public ColorUIResource getSecondary3 ( ) { return secondary3 ; } } </s>
|
<s> package com . izforge . izpack . gui ; 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 java . util . ArrayList ; import java . util . List ; import javax . swing . JComponent ; import javax . swing . JOptionPane ; import javax . swing . SwingUtilities ; import javax . swing . UIManager ; import com . izforge . izpack . api . handler . Prompt ; public class GUIPrompt implements Prompt { private final JComponent parent ; private static final String OK_BUTTON = "<STR_LIT>" ; private static final String CANCEL_BUTTON = "<STR_LIT>" ; private static final String YES_BUTTON = "<STR_LIT>" ; private static final String NO_BUTTON = "<STR_LIT>" ; public GUIPrompt ( ) { this ( null ) ; } public GUIPrompt ( JComponent parent ) { this . parent = parent ; } @ Override public void message ( Type type , String message ) { message ( type , null , message ) ; } @ Override public void message ( Type type , String title , String message ) { if ( title == null ) { title = getTitle ( type ) ; } showMessageDialog ( getMessageType ( type ) , title , message ) ; } @ Override public Option confirm ( Type type , String message , Options options ) { return confirm ( type , message , options , null ) ; } @ Override public Option confirm ( Type type , String message , Options options , Option defaultOption ) { return confirm ( type , getTitle ( type ) , message , options , defaultOption ) ; } @ Override public Option confirm ( Type type , String title , String message , Options options ) { return confirm ( type , title , message , options , null ) ; } @ Override @ SuppressWarnings ( "<STR_LIT>" ) public Option confirm ( Type type , String title , final String message , Options options , Option defaultOption ) { final int messageType = getMessageType ( type ) ; final int optionType ; switch ( options ) { case OK_CANCEL : optionType = JOptionPane . OK_CANCEL_OPTION ; break ; case YES_NO_CANCEL : optionType = JOptionPane . YES_NO_CANCEL_OPTION ; break ; default : optionType = JOptionPane . YES_NO_OPTION ; break ; } if ( title == null ) { title = getTitle ( type ) ; } int selected ; if ( defaultOption == null ) { selected = showConfirmDialog ( messageType , title , message , optionType ) ; } else { List < Object > opts = new ArrayList < Object > ( ) ; Object initialValue ; switch ( optionType ) { case JOptionPane . OK_CANCEL_OPTION : { String ok = UIManager . getString ( OK_BUTTON ) ; String cancel = UIManager . getString ( CANCEL_BUTTON ) ; opts . add ( ok ) ; opts . add ( cancel ) ; initialValue = ( defaultOption == OK ) ? ok : ( defaultOption == CANCEL ) ? cancel : null ; break ; } case JOptionPane . YES_NO_OPTION : { String yes = UIManager . getString ( YES_BUTTON ) ; String no = UIManager . getString ( NO_BUTTON ) ; opts . add ( yes ) ; opts . add ( no ) ; initialValue = ( defaultOption == YES ) ? yes : ( defaultOption == NO ) ? no : null ; break ; } case JOptionPane . YES_NO_CANCEL_OPTION : { String yes = UIManager . getString ( YES_BUTTON ) ; String no = UIManager . getString ( NO_BUTTON ) ; opts . add ( yes ) ; opts . add ( no ) ; String cancel = UIManager . getString ( CANCEL_BUTTON ) ; initialValue = ( defaultOption == YES ) ? yes : ( defaultOption == NO ) ? no : ( defaultOption == CANCEL ) ? cancel : null ; break ; } default : initialValue = null ; break ; } selected = showOptionDialog ( messageType , title , message , optionType , opts , initialValue ) ; } return getSelected ( options , selected ) ; } @ SuppressWarnings ( "<STR_LIT>" ) private void showMessageDialog ( final int type , final String title , final String message ) { if ( SwingUtilities . isEventDispatchThread ( ) ) { JOptionPane . showMessageDialog ( parent , message , title , type ) ; } else { try { SwingUtilities . invokeAndWait ( new Runnable ( ) { @ Override public void run ( ) { JOptionPane . showMessageDialog ( parent , message , title , type ) ; } } ) ; } catch ( Throwable exception ) { throw new IllegalStateException ( exception ) ; } } } @ SuppressWarnings ( "<STR_LIT>" ) private int showOptionDialog ( final int type , final String title , final String message , final int optionType , final List < Object > opts , final Object initialValue ) { int selected ; if ( SwingUtilities . isEventDispatchThread ( ) ) { selected = JOptionPane . showOptionDialog ( parent , message , title , optionType , type , null , opts . toArray ( ) , initialValue ) ; } else { final int [ ] handle = new int [ <NUM_LIT:1> ] ; try { SwingUtilities . invokeAndWait ( new Runnable ( ) { @ Override public void run ( ) { handle [ <NUM_LIT:0> ] = JOptionPane . showOptionDialog ( parent , message , title , optionType , type , null , opts . toArray ( ) , initialValue ) ; } } ) ; } catch ( Throwable exception ) { throw new IllegalStateException ( exception ) ; } selected = handle [ <NUM_LIT:0> ] ; } return selected ; } @ SuppressWarnings ( "<STR_LIT>" ) private int showConfirmDialog ( final int type , final String title , final String message , final int optionType ) { int selected ; if ( SwingUtilities . isEventDispatchThread ( ) ) { selected = JOptionPane . showConfirmDialog ( parent , message , title , optionType , type ) ; } else { final int [ ] handle = new int [ <NUM_LIT:1> ] ; try { SwingUtilities . invokeAndWait ( new Runnable ( ) { @ Override public void run ( ) { handle [ <NUM_LIT:0> ] = JOptionPane . showConfirmDialog ( parent , message , title , optionType , type ) ; } } ) ; } catch ( Throwable exception ) { throw new IllegalStateException ( exception ) ; } selected = handle [ <NUM_LIT:0> ] ; } return selected ; } private Option getSelected ( Options options , int selected ) { Option result ; switch ( selected ) { case JOptionPane . YES_OPTION : result = ( options == Options . OK_CANCEL ) ? OK : YES ; break ; case JOptionPane . NO_OPTION : result = NO ; break ; case JOptionPane . CANCEL_OPTION : result = CANCEL ; break ; default : result = ( options == Options . YES_NO_CANCEL ) ? CANCEL : NO ; } return result ; } private String getTitle ( Type type ) { String result ; switch ( type ) { case INFORMATION : result = "<STR_LIT>" ; break ; case QUESTION : result = "<STR_LIT>" ; break ; case WARNING : result = "<STR_LIT>" ; break ; default : result = "<STR_LIT>" ; } return result ; } private int getMessageType ( Type type ) { int result ; switch ( type ) { case INFORMATION : result = JOptionPane . INFORMATION_MESSAGE ; break ; case WARNING : result = JOptionPane . WARNING_MESSAGE ; break ; default : result = JOptionPane . ERROR_MESSAGE ; break ; } return result ; } } </s>
|
<s> package com . izforge . izpack . gui ; import javax . swing . plaf . ColorUIResource ; import javax . swing . plaf . FontUIResource ; import javax . swing . plaf . metal . DefaultMetalTheme ; import java . awt . * ; @ Deprecated public class IzPackMetalTheme extends DefaultMetalTheme { private ColorUIResource color ; private FontUIResource controlFont ; private FontUIResource menuFont ; private FontUIResource windowTitleFont ; public IzPackMetalTheme ( ) { color = new ColorUIResource ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; Font font1 = createFont ( "<STR_LIT>" , Font . PLAIN , <NUM_LIT:11> ) ; Font font2 = createFont ( "<STR_LIT>" , Font . BOLD , <NUM_LIT:11> ) ; menuFont = new FontUIResource ( font1 ) ; controlFont = new FontUIResource ( font1 ) ; windowTitleFont = new FontUIResource ( font2 ) ; } private Font createFont ( String name , int style , int size ) { Font font = new Font ( name , style , size ) ; return font ; } public ColorUIResource getControlTextColor ( ) { return color ; } public ColorUIResource getMenuTextColor ( ) { return color ; } public ColorUIResource getSystemTextColor ( ) { return color ; } public ColorUIResource getUserTextColor ( ) { return color ; } public FontUIResource getControlTextFont ( ) { return controlFont ; } public FontUIResource getMenuTextFont ( ) { return menuFont ; } public FontUIResource getSystemTextFont ( ) { return controlFont ; } public FontUIResource getUserTextFont ( ) { return controlFont ; } public FontUIResource getWindowTitleFont ( ) { return windowTitleFont ; } } </s>
|
<s> package com . izforge . izpack . gui . log ; public interface LogWarning { static final int WARNING_BASE = <NUM_LIT:1000> ; static final int MAX_WARNING = WARNING_BASE ; } </s>
|
<s> package com . izforge . izpack . gui . log ; import java . io . File ; import java . io . FileWriter ; import java . text . DateFormatSymbols ; import java . text . MessageFormat ; import java . text . SimpleDateFormat ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Date ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import javax . swing . JFileChooser ; import javax . swing . JOptionPane ; import com . izforge . izpack . api . data . AutomatedInstallData ; import com . izforge . izpack . api . data . InstallData ; public class Log implements LogError , LogWarning , LogMessage { private static final String RESOURCE_PREFIX = "<STR_LIT>" ; private static final String DATE_FORMAT = RESOURCE_PREFIX + "<STR_LIT>" ; private static final String MESSAGE_PREFIX = RESOURCE_PREFIX + "<STR_LIT>" ; private static final String WARNING_PREFIX = RESOURCE_PREFIX + "<STR_LIT>" ; private static final String ERROR_PREFIX = RESOURCE_PREFIX + "<STR_LIT>" ; private static final String DEBUG_SWITCH = "<STR_LIT>" ; private static final String CHANNEL_SPEC = "<STR_LIT>" ; private static final String CHANNEL_LIST = "<STR_LIT>" ; private String newline = System . getProperty ( "<STR_LIT>" ) ; private InstallData installData = null ; private ArrayList < Record > messages = new ArrayList < Record > ( ) ; private ArrayList < Record > warnings = new ArrayList < Record > ( ) ; private ArrayList < Record > errors = new ArrayList < Record > ( ) ; private ArrayList < Record > debug = new ArrayList < Record > ( ) ; private List < String > channels = null ; private Map < String , String > recordedChannels = null ; private boolean debugActive = false ; private boolean dumpChannels = false ; public final static String PANEL_TRACE = "<STR_LIT>" ; public Log ( AutomatedInstallData installData ) { this . installData = installData ; String temp = System . getProperty ( DEBUG_SWITCH ) ; if ( ( temp != null ) && ( temp . toUpperCase ( ) . equals ( "<STR_LIT>" ) ) ) { debugActive = true ; } if ( debugActive ) { recordedChannels = new HashMap < String , String > ( ) ; channels = new ArrayList < String > ( ) ; temp = System . getProperty ( CHANNEL_LIST ) ; if ( ( temp != null ) && ( temp . toUpperCase ( ) . equals ( "<STR_LIT>" ) ) ) { dumpChannels = true ; } temp = System . getProperty ( CHANNEL_SPEC ) ; if ( temp != null ) { String [ ] channelList = temp . split ( "<STR_LIT:U+002C>" ) ; channels . addAll ( Arrays . asList ( channelList ) ) ; } } } public void addMessage ( int message , String [ ] detail ) { if ( ( message >= LogMessage . MESSAGE_BASE ) && ( message < LogMessage . MAX_MESSAGE ) ) { messages . add ( new Record ( message , detail ) ) ; } } public void addCustomMessage ( String template , String [ ] detail ) { messages . add ( new Record ( template , detail ) ) ; } public void addWarning ( int message , String [ ] detail , Throwable exception ) { if ( ( message >= LogWarning . WARNING_BASE ) && ( message < LogWarning . MAX_WARNING ) ) { warnings . add ( new Record ( message , detail , exception ) ) ; } } public void addCustomWarning ( String template , String [ ] detail , Throwable exception ) { warnings . add ( new Record ( template , detail , exception ) ) ; } public void addError ( int message , String [ ] detail , Throwable exception ) { if ( ( message >= LogError . ERROR_BASE ) && ( message < LogError . MAX_ERROR ) ) { errors . add ( new Record ( message , detail , exception ) ) ; installData . setInstallSuccess ( false ) ; } } public void addCustomError ( String template , String [ ] detail , Throwable exception ) { errors . add ( new Record ( template , detail , exception ) ) ; } public void addDebugMessage ( String template , String [ ] detail , String channel , Throwable exception ) { if ( debugActive ) { recordedChannels . put ( channel , channel ) ; if ( ( channel == null ) || ( channel . length ( ) == <NUM_LIT:0> ) || channels . contains ( channel ) ) { Record record = new Record ( template , detail , exception , channel ) ; debug . add ( record ) ; System . out . println ( buildDebug ( record ) ) ; } } } public boolean messagesRecorded ( ) { return ( ! messages . isEmpty ( ) ) ; } public boolean warningsRecorded ( ) { return ( ! warnings . isEmpty ( ) ) ; } public boolean errorsRecorded ( ) { return ( ! errors . isEmpty ( ) ) ; } public void informUser ( ) { String message ; int messageType ; if ( errorsRecorded ( ) ) { messageType = JOptionPane . ERROR_MESSAGE ; message = format ( RESOURCE_PREFIX + "<STR_LIT>" ) ; } else if ( warningsRecorded ( ) ) { messageType = JOptionPane . WARNING_MESSAGE ; message = format ( RESOURCE_PREFIX + "<STR_LIT>" ) ; } else { return ; } int userChoice = JOptionPane . showConfirmDialog ( null , message , format ( RESOURCE_PREFIX + "<STR_LIT>" ) , JOptionPane . YES_NO_OPTION , messageType ) ; if ( userChoice == JOptionPane . OK_OPTION ) { writeReport ( ) ; } } public void writeReport ( ) { JFileChooser fileChooser = new JFileChooser ( ) ; fileChooser . setDialogTitle ( format ( RESOURCE_PREFIX + "<STR_LIT>" ) ) ; fileChooser . setSelectedFile ( new File ( format ( RESOURCE_PREFIX + "<STR_LIT>" ) ) ) ; int choice = fileChooser . showSaveDialog ( null ) ; if ( choice == JFileChooser . APPROVE_OPTION ) { writeReport ( fileChooser . getSelectedFile ( ) . getAbsolutePath ( ) ) ; } } public void writeReport ( String file ) { try { FileWriter writer = new FileWriter ( file ) ; String text = compileReport ( ) ; writer . write ( text , <NUM_LIT:0> , text . length ( ) ) ; writer . flush ( ) ; writer . close ( ) ; } catch ( Throwable exception ) { try { JOptionPane . showMessageDialog ( null , format ( ( RESOURCE_PREFIX + "<STR_LIT>" ) , file ) , format ( RESOURCE_PREFIX + "<STR_LIT>" ) , JOptionPane . ERROR_MESSAGE ) ; } catch ( Throwable exception2 ) { exception2 . printStackTrace ( ) ; } } } private String compileReport ( ) { StringBuilder report = new StringBuilder ( ) ; String dateFormat = format ( DATE_FORMAT ) ; int count ; report . append ( "<STR_LIT>" ) ; report . append ( newline ) ; report . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" ) ) ; report . append ( newline ) ; report . append ( "<STR_LIT>" ) ; report . append ( newline ) ; if ( errorsRecorded ( ) ) { report . append ( newline ) ; report . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" ) ) ; report . append ( newline ) ; } else if ( warningsRecorded ( ) ) { report . append ( newline ) ; report . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" ) ) ; report . append ( newline ) ; } report . append ( newline ) ; report . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" , messages . size ( ) , warnings . size ( ) , errors . size ( ) ) ) ; report . append ( newline ) ; report . append ( newline ) ; report . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" , installData . getInfo ( ) . getAppName ( ) , installData . getInfo ( ) . getAppVersion ( ) ) ) ; report . append ( newline ) ; report . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" , new SimpleDateFormat ( dateFormat , new DateFormatSymbols ( ) ) . format ( new Date ( ) ) ) ) ; report . append ( newline ) ; report . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" , installData . getInstallPath ( ) ) ) ; report . append ( newline ) ; if ( messagesRecorded ( ) ) { report . append ( newline ) ; report . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" ) ) ; report . append ( newline ) ; report . append ( newline ) ; count = messages . size ( ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { report . append ( buildMessage ( i ) ) ; } } if ( warningsRecorded ( ) ) { report . append ( newline ) ; report . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" ) ) ; report . append ( newline ) ; report . append ( newline ) ; count = warnings . size ( ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { report . append ( buildWarning ( i ) ) ; } } if ( errorsRecorded ( ) ) { report . append ( newline ) ; report . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" ) ) ; report . append ( newline ) ; report . append ( newline ) ; count = errors . size ( ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { report . append ( buildError ( i ) ) ; } } if ( debugActive ) { report . append ( newline ) ; report . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" ) ) ; report . append ( newline ) ; report . append ( newline ) ; count = errors . size ( ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { report . append ( buildDebug ( i ) ) ; } } report . append ( "<STR_LIT>" ) ; report . append ( newline ) ; return ( report . toString ( ) ) ; } private String buildMessage ( int index ) { Record record = messages . get ( index ) ; StringBuilder message = new StringBuilder ( ) ; message . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" , index ) ) ; if ( record . message >= <NUM_LIT:0> ) { message . append ( format ( MESSAGE_PREFIX + record . message , ( Object [ ] ) record . variables ) ) ; } else { message . append ( MessageFormat . format ( record . template , ( Object [ ] ) record . variables ) ) ; } message . append ( newline ) ; return ( message . toString ( ) ) ; } private String buildWarning ( int index ) { Record record = warnings . get ( index ) ; StringBuilder message = new StringBuilder ( ) ; message . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" , index ) ) ; if ( record . message >= <NUM_LIT:0> ) { message . append ( format ( WARNING_PREFIX + Integer . toString ( record . message - LogWarning . WARNING_BASE ) , ( Object [ ] ) record . variables ) ) ; } else { message . append ( MessageFormat . format ( record . template , ( Object [ ] ) record . variables ) ) ; } if ( record . exception != null ) { message . append ( newline ) ; message . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" , record . exception ) ) ; } message . append ( newline ) ; return ( message . toString ( ) ) ; } private String buildError ( int index ) { Record record = errors . get ( index ) ; StringBuilder message = new StringBuilder ( ) ; message . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" , Integer . toString ( index ) ) ) ; if ( record . message >= <NUM_LIT:0> ) { message . append ( format ( ERROR_PREFIX + Integer . toString ( record . message - LogError . ERROR_BASE ) , ( Object [ ] ) record . variables ) ) ; } else { message . append ( MessageFormat . format ( record . template , ( Object [ ] ) record . variables ) ) ; } if ( record . exception != null ) { message . append ( newline ) ; message . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" , record . exception ) ) ; } message . append ( newline ) ; return ( message . toString ( ) ) ; } private String buildDebug ( int index ) { Record record = debug . get ( index ) ; return ( buildDebug ( record ) ) ; } private String buildDebug ( Record record ) { StringBuilder message = new StringBuilder ( ) ; if ( ( record . channel == null ) || ( record . channel . length ( ) == <NUM_LIT:0> ) ) { message . append ( "<STR_LIT>" ) ; } else { message . append ( "<STR_LIT>" ) . append ( record . channel ) . append ( "<STR_LIT::U+0020>" ) ; } message . append ( MessageFormat . format ( record . template , ( Object [ ] ) record . variables ) ) ; if ( record . exception != null ) { message . append ( newline ) ; message . append ( format ( RESOURCE_PREFIX + "<STR_LIT>" , record . exception ) ) ; } message . append ( newline ) ; return ( message . toString ( ) ) ; } public void dumpRecordedChannels ( ) { if ( debugActive && dumpChannels ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( ) ; for ( String channel : recordedChannels . keySet ( ) ) { System . out . println ( "<STR_LIT:U+0020-U+0020>" + channel ) ; } System . out . println ( ) ; } } private String format ( String id , Object ... args ) { return installData . getMessages ( ) . get ( id , args ) ; } private class Record { String channel ; String template ; int message ; String [ ] variables ; Throwable exception ; Record ( int message , String [ ] variables ) { this . message = message ; this . variables = variables ; } Record ( String template , String [ ] variables ) { this . message = - <NUM_LIT:1> ; this . template = template ; this . variables = variables ; } Record ( int message , String [ ] variables , Throwable exception ) { this . message = message ; this . variables = variables ; this . exception = exception ; } Record ( String template , String [ ] variables , Throwable exception ) { this . message = - <NUM_LIT:1> ; this . template = template ; this . variables = variables ; this . exception = exception ; } Record ( String template , String [ ] variables , Throwable exception , String channel ) { this . message = - <NUM_LIT:1> ; this . template = template ; this . variables = variables ; this . exception = exception ; this . channel = channel ; } } } </s>
|
<s> package com . izforge . izpack . gui . log ; public interface LogMessage { static final int MESSAGE_BASE = <NUM_LIT:0> ; static final int MAX_MESSAGE = <NUM_LIT:0> ; } </s>
|
<s> package com . izforge . izpack . gui . log ; public interface LogError { static final int ERROR_BASE = <NUM_LIT> ; public static final int COULD_NOT_WRITE_FILE = ERROR_BASE ; static final int MAX_ERROR = ERROR_BASE + <NUM_LIT:1> ; } </s>
|
<s> package com . izforge . izpack . gui ; import java . awt . Component ; public class TwoColumnConstraints implements Cloneable { public static final int NORTH = <NUM_LIT:9> ; public static final int WEST = <NUM_LIT:15> ; public static final int WESTONLY = <NUM_LIT:16> ; public static final int EAST = <NUM_LIT> ; public static final int EASTONLY = <NUM_LIT> ; public static final int BOTH = <NUM_LIT> ; public static final int LEFT = <NUM_LIT:31> ; public static final int CENTER = <NUM_LIT> ; public static final int RIGHT = <NUM_LIT> ; public int position = WEST ; public int align = LEFT ; public boolean indent = false ; public boolean stretch = false ; Component component = null ; @ Override public Object clone ( ) { TwoColumnConstraints newObject = new TwoColumnConstraints ( ) ; newObject . position = position ; newObject . align = align ; newObject . indent = indent ; newObject . stretch = stretch ; newObject . component = component ; return ( newObject ) ; } } </s>
|
<s> package com . izforge . izpack . gui ; import javax . swing . border . EtchedBorder ; import java . awt . * ; public class EtchedLineBorder extends EtchedBorder { private static final long serialVersionUID = <NUM_LIT> ; public void paintBorder ( Component component , Graphics graphics , int x , int y , int width , int height ) { graphics . translate ( x , y ) ; graphics . setColor ( etchType == LOWERED ? getShadowColor ( component ) : getHighlightColor ( component ) ) ; graphics . drawLine ( <NUM_LIT:10> , <NUM_LIT:0> , width - <NUM_LIT:2> , <NUM_LIT:0> ) ; graphics . setColor ( etchType == LOWERED ? getHighlightColor ( component ) : getShadowColor ( component ) ) ; graphics . drawLine ( <NUM_LIT:10> , <NUM_LIT:1> , width - <NUM_LIT:2> , <NUM_LIT:1> ) ; graphics . translate ( <NUM_LIT:0> - x , <NUM_LIT:0> - y ) ; } } </s>
|
<s> package com . izforge . izpack . gui ; import com . izforge . izpack . gui . log . Log ; import javax . swing . JCheckBox ; import javax . swing . JLabel ; import javax . swing . JRadioButton ; import javax . swing . JScrollPane ; import javax . swing . JTextArea ; import javax . swing . text . JTextComponent ; import java . awt . Component ; import java . awt . Container ; import java . awt . Dimension ; import java . awt . Insets ; import java . awt . LayoutManager ; import java . awt . LayoutManager2 ; import java . awt . Rectangle ; import java . util . ArrayList ; public class IzPanelLayout implements LayoutManager , LayoutManager2 , LayoutConstants { private static Class pathSelectionPanel ; private ArrayList < ArrayList < IzPanelConstraints > > components = new ArrayList < ArrayList < IzPanelConstraints > > ( ) ; private int currentYPos = <NUM_LIT:0> ; private int currentXPos = - <NUM_LIT:1> ; private Dimension prefLayoutDim ; private Dimension oldParentSize ; private Insets oldParentInsets ; private int columnFillOutRule ; private double [ ] overallYStretch = { - <NUM_LIT:1.0> , <NUM_LIT:0.0> } ; private final Log log ; protected static int [ ] DEFAULT_Y_GAPS = { - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:9> , <NUM_LIT:6> , <NUM_LIT:3> , <NUM_LIT:0> } ; protected static int [ ] DEFAULT_X_GAPS = { - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:9> , <NUM_LIT:6> , <NUM_LIT:3> , <NUM_LIT:0> } ; protected static int [ ] DEFAULT_X_ALIGNMENT = { LEFT , LEFT , LEFT , LEFT } ; protected static int [ ] DEFAULT_Y_ALIGNMENT = { CENTER , CENTER , CENTER , CENTER } ; private static final String USER_PATH_SELECTION_PANEL_CLASS = "<STR_LIT>" ; private static final String PATH_SELECTION_PANEL_CLASS = "<STR_LIT>" ; static { try { pathSelectionPanel = Class . forName ( PATH_SELECTION_PANEL_CLASS ) ; } catch ( ClassNotFoundException e ) { pathSelectionPanel = null ; e . printStackTrace ( ) ; } } private static IzPanelConstraints DEFAULT_CONSTRAINTS [ ] = { new IzPanelConstraints ( DEFAULT_LABEL_ALIGNMENT , DEFAULT_LABEL_ALIGNMENT , NEXT_COLUMN , CURRENT_ROW , <NUM_LIT:1> , <NUM_LIT:1> , AUTOMATIC_GAP , AUTOMATIC_GAP , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , new IzPanelConstraints ( DEFAULT_TEXT_ALIGNMENT , DEFAULT_TEXT_ALIGNMENT , NEXT_COLUMN , CURRENT_ROW , <NUM_LIT:1> , <NUM_LIT:1> , AUTOMATIC_GAP , AUTOMATIC_GAP , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , new IzPanelConstraints ( DEFAULT_CONTROL_ALIGNMENT , DEFAULT_CONTROL_ALIGNMENT , NEXT_COLUMN , CURRENT_ROW , <NUM_LIT:1> , <NUM_LIT:1> , AUTOMATIC_GAP , AUTOMATIC_GAP , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , new IzPanelConstraints ( DEFAULT_LABEL_ALIGNMENT , DEFAULT_LABEL_ALIGNMENT , <NUM_LIT:0> , NEXT_ROW , Byte . MAX_VALUE , Byte . MAX_VALUE , AUTOMATIC_GAP , AUTOMATIC_GAP , FULL_LINE_STRETCH , <NUM_LIT:0.0> ) , new IzPanelConstraints ( DEFAULT_LABEL_ALIGNMENT , DEFAULT_LABEL_ALIGNMENT , <NUM_LIT:0> , NEXT_ROW , Byte . MAX_VALUE , Byte . MAX_VALUE , AUTOMATIC_GAP , AUTOMATIC_GAP , FULL_LINE_STRETCH , FULL_COLUMN_STRETCH ) , new IzPanelConstraints ( DEFAULT_LABEL_ALIGNMENT , DEFAULT_LABEL_ALIGNMENT , NEXT_COLUMN , CURRENT_ROW , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , new IzPanelConstraints ( DEFAULT_LABEL_ALIGNMENT , DEFAULT_LABEL_ALIGNMENT , <NUM_LIT:0> , NEXT_ROW , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , new IzPanelConstraints ( DEFAULT_CONTROL_ALIGNMENT , DEFAULT_CONTROL_ALIGNMENT , <NUM_LIT:0> , NEXT_ROW , Byte . MAX_VALUE , Byte . MAX_VALUE , AUTOMATIC_GAP , AUTOMATIC_GAP , FULL_LINE_STRETCH , <NUM_LIT:0.0> ) , } ; private static int ANCHOR = CENTER ; private static int X_STRETCH_TYPE = RELATIVE_STRETCH ; private static int Y_STRETCH_TYPE = RELATIVE_STRETCH ; private static double FULL_LINE_STRETCH_DEFAULT = <NUM_LIT:1.0> ; private static double FULL_COLUMN_STRETCH_DEFAULT = <NUM_LIT:1.0> ; private static int DEFAULT_TEXTFIELD_LENGTH = <NUM_LIT:12> ; private static final int [ ] [ ] GAP_INTERMEDIAER_LOOKUP = { { LABEL_GAP , LABEL_TO_TEXT_GAP , LABEL_TO_CONTROL_GAP , LABEL_GAP , LABEL_TO_CONTROL_GAP , LABEL_GAP , LABEL_GAP } , { TEXT_TO_LABEL_GAP , TEXT_GAP , TEXT_TO_CONTROL_GAP , TEXT_TO_LABEL_GAP , TEXT_TO_CONTROL_GAP , TEXT_GAP , TEXT_GAP } , { CONTROL_TO_LABEL_GAP , CONTROL_TO_TEXT_GAP , CONTROL_GAP , CONTROL_TO_LABEL_GAP , CONTROL_GAP , CONTROL_GAP , CONTROL_GAP } , { LABEL_GAP , LABEL_TO_TEXT_GAP , LABEL_TO_CONTROL_GAP , LABEL_GAP , LABEL_TO_CONTROL_GAP , LABEL_GAP , LABEL_GAP } , { CONTROL_TO_LABEL_GAP , CONTROL_TO_TEXT_GAP , CONTROL_GAP , CONTROL_TO_LABEL_GAP , CONTROL_GAP , CONTROL_GAP , CONTROL_GAP } , { NO_GAP , NO_GAP , NO_GAP , NO_GAP , NO_GAP , NO_GAP , NO_GAP , NO_GAP } , { NO_GAP , NO_GAP , NO_GAP , NO_GAP , NO_GAP , NO_GAP , NO_GAP , NO_GAP } , { NO_GAP , NO_GAP , NO_GAP , NO_GAP , NO_GAP , NO_GAP , NO_GAP , NO_GAP } } ; public IzPanelLayout ( Log log ) { this ( NO_FILL_OUT_COLUMN , log ) ; } public IzPanelLayout ( int colFillOutRule , Log log ) { super ( ) ; columnFillOutRule = colFillOutRule ; this . log = log ; } private static int getYGap ( IzPanelConstraints curConst , IzPanelConstraints nextYConst ) { Class nextClass = ( nextYConst != null ) ? nextYConst . component . getClass ( ) : FillerComponent . class ; int interId = GAP_INTERMEDIAER_LOOKUP [ getIntermediarId ( curConst . component . getClass ( ) , null ) ] [ getIntermediarId ( nextClass , null ) ] ; if ( interId < <NUM_LIT:0> ) { interId = - interId ; } return ( DEFAULT_Y_GAPS [ interId ] ) ; } private static int getXGap ( IzPanelConstraints curConst , IzPanelConstraints nextXConst ) { Class nextClass = ( nextXConst != null ) ? nextXConst . component . getClass ( ) : FillerComponent . class ; int interId = GAP_INTERMEDIAER_LOOKUP [ getIntermediarId ( curConst . component . getClass ( ) , null ) ] [ getIntermediarId ( nextClass , null ) ] ; if ( interId < <NUM_LIT:0> ) { interId = - interId ; } return ( DEFAULT_X_GAPS [ interId ] ) ; } private static int getIntermediarId ( Class clazz , Component comp ) { if ( comp != null ) { if ( MultiLineLabel . class . isAssignableFrom ( clazz ) || LabelFactory . FullLineLabel . class . isAssignableFrom ( clazz ) ) { return ( FULL_LINE_COMPONENT_CONSTRAINT ) ; } if ( pathSelectionPanel . isAssignableFrom ( clazz ) || JCheckBox . class . isAssignableFrom ( clazz ) || JRadioButton . class . isAssignableFrom ( clazz ) || USER_PATH_SELECTION_PANEL_CLASS . equals ( clazz . getName ( ) ) ) { return ( FULL_LINE_CONTROL_CONSTRAINT ) ; } if ( FillerComponent . class . isAssignableFrom ( clazz ) || javax . swing . Box . Filler . class . isAssignableFrom ( clazz ) ) { Dimension size = comp . getPreferredSize ( ) ; if ( size . height >= Short . MAX_VALUE || size . height <= <NUM_LIT:0> ) { size . height = <NUM_LIT:0> ; comp . setSize ( size ) ; return ( XDUMMY_CONSTRAINT ) ; } else if ( size . width >= Short . MAX_VALUE || size . width <= <NUM_LIT:0> ) { size . width = <NUM_LIT:0> ; comp . setSize ( size ) ; return ( YDUMMY_CONSTRAINT ) ; } } } if ( JScrollPane . class . isAssignableFrom ( clazz ) ) { return ( XY_VARIABLE_CONSTRAINT ) ; } if ( JLabel . class . isAssignableFrom ( clazz ) ) { return ( LABEL_CONSTRAINT ) ; } if ( JTextComponent . class . isAssignableFrom ( clazz ) ) { return ( TEXT_CONSTRAINT ) ; } if ( FillerComponent . class . isAssignableFrom ( clazz ) ) { return ( XDUMMY_CONSTRAINT ) ; } if ( javax . swing . Box . Filler . class . isAssignableFrom ( clazz ) ) { return ( XDUMMY_CONSTRAINT ) ; } return ( CONTROL_CONSTRAINT ) ; } public void addLayoutComponent ( String name , Component comp ) { } public void removeLayoutComponent ( Component comp ) { } public Dimension minimumLayoutSize ( Container parent ) { return preferredLayoutSize ( parent ) ; } public Dimension preferredLayoutSize ( Container parent ) { return ( determineSize ( ) ) ; } private Dimension determineSize ( ) { if ( prefLayoutDim == null ) { int width = minimumAllColumnsWidth ( ) ; int height = minimumOverallHeight ( ) ; prefLayoutDim = new Dimension ( width , height ) ; } return ( Dimension ) ( prefLayoutDim . clone ( ) ) ; } private int rows ( ) { int maxRows = <NUM_LIT:0> ; for ( ArrayList < IzPanelConstraints > component : components ) { int curRows = component . size ( ) ; if ( curRows > maxRows ) { maxRows = curRows ; } } return ( maxRows ) ; } private int columns ( ) { return ( components . size ( ) ) ; } private int minimumOverallHeight ( ) { int height = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < rows ( ) ; i ++ ) { height += rowHeight ( i ) ; } return ( height ) ; } private int rowHeight ( int row ) { int height = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < components . size ( ) ; ++ i ) { int curHeight = getCellSize ( i , row , null ) . height ; if ( curHeight > height ) { height = curHeight ; } } return ( height ) ; } private int rowHeight ( int row , int minOverallHeight , int maxOverallHeight ) { int height = <NUM_LIT:0> ; double [ ] yStretch = getOverallYStretch ( ) ; if ( yStretch [ <NUM_LIT:0> ] <= <NUM_LIT:0.0> ) { return ( rowHeight ( row ) ) ; } double maxStretch = <NUM_LIT:0.0> ; double [ ] stretchParts = new double [ components . size ( ) ] ; for ( int i = <NUM_LIT:0> ; i < components . size ( ) ; ++ i ) { IzPanelConstraints constraints = getConstraints ( i , row ) ; double stretch = constraints . getYStretch ( ) ; stretchParts [ i ] = stretch ; if ( stretch > maxStretch ) { maxStretch = stretch ; } int curHeight = getCellSize ( i , row , constraints ) . height ; if ( curHeight > height ) { height = curHeight ; } } if ( maxOverallHeight <= minOverallHeight ) { return ( height ) ; } int pixels = ( int ) ( maxOverallHeight - yStretch [ <NUM_LIT:1> ] - minOverallHeight ) ; int stretchPart = ( int ) ( pixels * maxStretch ) ; if ( stretchPart > <NUM_LIT:0> ) { for ( int i = <NUM_LIT:0> ; i < components . size ( ) ; ++ i ) { if ( stretchParts [ i ] < <NUM_LIT> ) { continue ; } IzPanelConstraints constraints = getConstraints ( i , row ) ; Dimension size = constraints . component . getPreferredSize ( ) ; if ( size . height + stretchPart * stretchParts [ i ] < height ) { size . height = ( int ) ( height + stretchPart * stretchParts [ i ] ) ; } else { size . height = height + stretchPart ; } if ( constraints . component instanceof JScrollPane ) { if ( ( ( JScrollPane ) constraints . component ) . getViewport ( ) . getView ( ) instanceof JTextArea ) { if ( ( ( JTextArea ) ( ( JScrollPane ) constraints . component ) . getViewport ( ) . getView ( ) ) . getLineWrap ( ) ) { size . width = <NUM_LIT:1000> ; } } } constraints . component . setPreferredSize ( size ) ; } height += stretchPart ; } return ( height ) ; } private double [ ] getOverallYStretch ( ) { if ( overallYStretch [ <NUM_LIT:0> ] >= <NUM_LIT:0.0> ) { return ( overallYStretch ) ; } overallYStretch [ <NUM_LIT:0> ] = <NUM_LIT:0.0> ; for ( int row = <NUM_LIT:0> ; row < rows ( ) ; ++ row ) { double maxStretch = <NUM_LIT:0.0> ; double maxGap = <NUM_LIT:0.0> ; for ( int i = <NUM_LIT:0> ; i < components . size ( ) ; ++ i ) { IzPanelConstraints constraints = getConstraints ( i , row ) ; resolveDefaultSettings ( i , row ) ; if ( constraints . getYStretch ( ) == FULL_COLUMN_STRETCH ) { constraints . setYStretch ( IzPanelLayout . getFullColumnStretch ( ) ) ; } double curStretch = constraints . getYStretch ( ) ; if ( curStretch > maxStretch ) { maxStretch = curStretch ; } double curYGap = constraints . getYGap ( ) ; if ( curYGap > maxGap ) { maxGap = curYGap ; } } overallYStretch [ <NUM_LIT:0> ] += maxStretch ; overallYStretch [ <NUM_LIT:1> ] += maxGap ; } if ( overallYStretch [ <NUM_LIT:0> ] > <NUM_LIT:0.0> ) { switch ( IzPanelLayout . getYStretchType ( ) ) { case RELATIVE_STRETCH : break ; case ABSOLUTE_STRETCH : overallYStretch [ <NUM_LIT:0> ] = <NUM_LIT:1.0> ; break ; case NO_STRETCH : default : overallYStretch [ <NUM_LIT:0> ] = <NUM_LIT:0.0> ; break ; } } return ( overallYStretch ) ; } private Dimension getCellSize ( int column , int row , IzPanelConstraints constraints ) { Dimension retval = new Dimension ( ) ; Component component ; try { if ( constraints == null ) { constraints = getConstraints ( column , row ) ; } if ( constraints != null ) { component = constraints . component ; Dimension dim = component . getPreferredSize ( ) ; Dimension dim2 = component . getMinimumSize ( ) ; retval . height = ( dim . height > dim2 . height ) ? dim . height : dim2 . height ; retval . width = ( dim . width > dim2 . width ) ? dim . width : dim2 . width ; if ( component instanceof JScrollPane ) { retval . height = dim2 . height ; retval . width = dim2 . width ; } if ( needsReEvaluation ( component ) ) { retval . width = <NUM_LIT:0> ; } } } catch ( Throwable exception ) { } return ( retval ) ; } private int minimumColumnWidth ( int column ) { int maxWidth = <NUM_LIT:0> ; Dimension [ ] cs = new Dimension [ rows ( ) ] ; for ( int i = <NUM_LIT:0> ; i < rows ( ) ; ++ i ) { IzPanelConstraints constraints = getConstraints ( column , i ) ; cs [ i ] = getCellSize ( column , i , constraints ) ; if ( constraints . getXWeight ( ) <= <NUM_LIT:1> ) { if ( maxWidth < cs [ i ] . width ) { maxWidth = cs [ i ] . width ; } } } if ( maxWidth == <NUM_LIT:0> ) { for ( int i = <NUM_LIT:0> ; i < rows ( ) ; ++ i ) { if ( maxWidth < cs [ i ] . width ) { maxWidth = cs [ i ] . width ; } } } return ( maxWidth ) ; } private int minimumAllColumnsWidth ( ) { int width = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < this . components . size ( ) ; ++ i ) { width += minimumColumnWidth ( i ) ; } return ( width ) ; } private IzPanelConstraints getConstraints ( int col , int row ) { if ( col >= columns ( ) || row >= rows ( ) ) { return ( null ) ; } ArrayList < IzPanelConstraints > constraints = components . get ( col ) ; if ( constraints != null ) { try { return constraints . get ( row ) ; } catch ( Throwable t ) { } for ( int curRow = constraints . size ( ) ; row >= curRow ; ++ curRow ) { IzPanelConstraints currentConst = IzPanelLayout . getDefaultConstraint ( XDUMMY_CONSTRAINT ) ; currentConst . setXPos ( col ) ; currentConst . setYPos ( curRow ) ; currentConst . component = new FillerComponent ( ) ; try { constraints . add ( row , currentConst ) ; } catch ( Throwable t ) { return ( null ) ; } } return ( getConstraints ( col , row ) ) ; } return ( null ) ; } private int getAdaptedXPos ( int xpos , int curWidth , Dimension curDim , IzPanelConstraints currentConst ) { int adaptedXPos = xpos ; if ( ( columnFillOutRule & FILL_OUT_COLUMN_WIDTH ) > <NUM_LIT:0> ) { return ( adaptedXPos ) ; } switch ( currentConst . getXCellAlignment ( ) ) { case LEFT : break ; case RIGHT : adaptedXPos += curWidth - curDim . width ; break ; case CENTER : default : adaptedXPos += ( curWidth - curDim . width ) / <NUM_LIT:2> ; break ; } return ( adaptedXPos ) ; } private int getAdaptedYPos ( int ypos , int curHeight , Dimension curDim , IzPanelConstraints currentConst ) { int adaptedYPos = ypos ; if ( ( columnFillOutRule & FILL_OUT_COLUMN_HEIGHT ) > <NUM_LIT:0> ) { return ( adaptedYPos ) ; } int height = curDim . height ; switch ( currentConst . getYCellAlignment ( ) ) { case TOP : break ; case BOTTOM : adaptedYPos += curHeight - height ; break ; case CENTER : default : adaptedYPos += ( curHeight - height ) / <NUM_LIT:2> ; break ; } if ( adaptedYPos < ypos ) { return ( ypos ) ; } return ( adaptedYPos ) ; } private void resolveDefaultSettings ( int col , int row ) { IzPanelConstraints currentConst = getConstraints ( col , row ) ; IzPanelConstraints nextYConst = getConstraints ( col , row + <NUM_LIT:1> ) ; IzPanelConstraints nextXConst = getConstraints ( col + <NUM_LIT:1> , row ) ; if ( currentConst == null ) { return ; } int gap = currentConst . getYGap ( ) ; if ( gap == AUTOMATIC_GAP ) { currentConst . setYGap ( getYGap ( currentConst , nextYConst ) ) ; } else if ( gap < <NUM_LIT:0> ) { currentConst . setYGap ( DEFAULT_Y_GAPS [ - gap ] ) ; } gap = currentConst . getXGap ( ) ; if ( gap == AUTOMATIC_GAP ) { currentConst . setXGap ( getXGap ( currentConst , nextXConst ) ) ; } else if ( gap < <NUM_LIT:0> ) { currentConst . setXGap ( DEFAULT_X_GAPS [ - gap ] ) ; } if ( currentConst . getXCellAlignment ( ) < <NUM_LIT:0> ) { currentConst . setXCellAlignment ( DEFAULT_X_ALIGNMENT [ - currentConst . getXCellAlignment ( ) ] ) ; } if ( currentConst . getYCellAlignment ( ) < <NUM_LIT:0> ) { currentConst . setYCellAlignment ( DEFAULT_Y_ALIGNMENT [ - currentConst . getYCellAlignment ( ) ] ) ; } } public void layoutContainer ( Container parent ) { if ( ! needNewLayout ( parent ) ) { fastLayoutContainer ( parent ) ; return ; } prefLayoutDim = null ; preferredLayoutSize ( parent ) ; Dimension realSizeDim = parent . getSize ( ) ; log . addDebugMessage ( "<STR_LIT>" , new String [ ] { parent . getSize ( ) . toString ( ) } , "<STR_LIT>" , null ) ; Insets insets = parent . getInsets ( ) ; int rowHeight = <NUM_LIT:0> ; int onceAgain = <NUM_LIT:0> ; int [ ] generellOffset = new int [ ] { <NUM_LIT:0> , <NUM_LIT:0> } ; int maxWidth = <NUM_LIT:0> ; int overallHeight = <NUM_LIT:0> ; int anchorNeedsReEval = <NUM_LIT:0> ; Rectangle curRect = new Rectangle ( ) ; int minOverallHeight = minimumOverallHeight ( ) ; int maxOverallHeight = realSizeDim . height - insets . top - insets . bottom ; while ( anchorNeedsReEval < <NUM_LIT:2> ) { int ypos = insets . top ; int row = <NUM_LIT:0> ; int minWidth = <NUM_LIT> ; int minHeight = <NUM_LIT> ; maxWidth = <NUM_LIT:0> ; overallHeight = <NUM_LIT:0> ; while ( row < rows ( ) ) { int outerRowHeight = <NUM_LIT:0> ; int xpos = insets . left ; int col = <NUM_LIT:0> ; IzPanelConstraints [ ] colConstraints = new IzPanelConstraints [ columns ( ) ] ; int usedWidth = <NUM_LIT:0> ; Dimension curDim ; while ( col < columns ( ) ) { if ( col == <NUM_LIT:0> ) { rowHeight = rowHeight ( row , minOverallHeight , maxOverallHeight ) ; } IzPanelConstraints currentConst = getConstraints ( col , row ) ; colConstraints [ col ] = currentConst ; Component currentComp = currentConst . component ; curDim = currentComp . getPreferredSize ( ) ; int curWidth = minimumColumnWidth ( col ) ; col ++ ; if ( currentConst . getXWeight ( ) > <NUM_LIT:1> ) { int weight = currentConst . getXWeight ( ) ; while ( weight > <NUM_LIT:1> && col < columns ( ) ) { colConstraints [ col ] = getConstraints ( col , row ) ; if ( ! ( colConstraints [ col ] . component instanceof FillerComponent ) ) { break ; } curWidth += minimumColumnWidth ( col ) ; col ++ ; weight -- ; } } int adaptedXPos = getAdaptedXPos ( xpos , curWidth , curDim , currentConst ) ; int adaptedYPos = getAdaptedYPos ( ypos , rowHeight , curDim , currentConst ) ; int useWidth = curDim . width ; int useHeight = curDim . height ; if ( ( columnFillOutRule & FILL_OUT_COLUMN_WIDTH ) > <NUM_LIT:0> ) { useWidth = curWidth ; } if ( ( columnFillOutRule & FILL_OUT_COLUMN_HEIGHT ) > <NUM_LIT:0> ) { useHeight = rowHeight ; } if ( curWidth < useWidth ) { useWidth = curWidth ; } currentComp . setBounds ( adaptedXPos + generellOffset [ <NUM_LIT:0> ] , adaptedYPos + generellOffset [ <NUM_LIT:1> ] , useWidth , useHeight ) ; currentComp . getBounds ( curRect ) ; if ( curRect . height > <NUM_LIT:100> ) { curRect . height = useHeight ; } if ( ! ( currentComp instanceof FillerComponent ) ) { if ( curRect . x < minWidth ) { minWidth = curRect . x ; } if ( curRect . y < minHeight ) { minHeight = curRect . y ; } } int curMax = ( int ) curRect . getMaxX ( ) ; if ( curMax - minWidth > maxWidth ) { maxWidth = curMax - minWidth ; } curMax = ( int ) curRect . getMaxY ( ) ; currentConst . setBounds ( curRect ) ; if ( curMax - minHeight > overallHeight ) { overallHeight = curMax - minHeight ; } xpos += curWidth + currentConst . getXGap ( ) ; usedWidth += curWidth ; if ( outerRowHeight < rowHeight + currentConst . getYGap ( ) ) { outerRowHeight = rowHeight + currentConst . getYGap ( ) ; } } double rowStretch = <NUM_LIT:0.0> ; int i ; for ( i = <NUM_LIT:0> ; i < colConstraints . length ; ++ i ) { if ( colConstraints [ i ] . getXStretch ( ) == FULL_LINE_STRETCH ) { colConstraints [ i ] . setXStretch ( IzPanelLayout . getFullLineStretch ( ) ) ; } rowStretch += colConstraints [ i ] . getXStretch ( ) ; } if ( rowStretch > <NUM_LIT:0.0> ) { switch ( IzPanelLayout . getXStretchType ( ) ) { case RELATIVE_STRETCH : break ; case ABSOLUTE_STRETCH : rowStretch = <NUM_LIT:1.0> ; break ; case NO_STRETCH : default : rowStretch = <NUM_LIT:0.0> ; break ; } } if ( realSizeDim . width - insets . right != xpos && rowStretch > <NUM_LIT:0.0> ) { int pixel = realSizeDim . width - insets . right - xpos ; int offset = <NUM_LIT:0> ; int oldOnceAgain = onceAgain ; for ( i = <NUM_LIT:0> ; i < colConstraints . length ; ++ i ) { int curPixel = ( int ) ( ( colConstraints [ i ] . getXStretch ( ) / rowStretch ) * pixel ) ; Rectangle curBounds = colConstraints [ i ] . component . getBounds ( ) ; int curWidth = this . minimumColumnWidth ( i ) ; if ( curBounds . width < curWidth ) { curBounds . width = curWidth ; } int newWidth = curPixel + curBounds . width ; log . addDebugMessage ( "<STR_LIT>" , new String [ ] { Integer . toString ( curBounds . width ) , Integer . toString ( newWidth ) , Integer . toString ( row ) , Integer . toString ( i ) } , "<STR_LIT>" , null ) ; colConstraints [ i ] . component . setBounds ( curBounds . x + offset , curBounds . y , newWidth , curBounds . height ) ; colConstraints [ i ] . component . getBounds ( curRect ) ; if ( curRect . x > <NUM_LIT:0> && curRect . x < minWidth ) { minWidth = curRect . x ; } if ( curRect . y > <NUM_LIT:0> && curRect . y < minHeight ) { minHeight = curRect . y ; } int curMax = ( int ) curRect . getMaxX ( ) ; if ( curMax - minWidth > maxWidth ) { maxWidth = curMax - minWidth ; } curMax = ( int ) curRect . getMaxY ( ) ; colConstraints [ i ] . setBounds ( curRect ) ; if ( curMax - minHeight > overallHeight ) { overallHeight = curMax - minHeight ; } log . addDebugMessage ( "<STR_LIT>" , new String [ ] { colConstraints [ i ] . component . getClass ( ) . getName ( ) , curRect . toString ( ) , Integer . toString ( row ) , Integer . toString ( i ) } , "<STR_LIT>" , null ) ; log . addDebugMessage ( "<STR_LIT>" , new String [ ] { Integer . toString ( maxWidth ) , Integer . toString ( overallHeight ) , Integer . toString ( row ) , Integer . toString ( i ) } , "<STR_LIT>" , null ) ; offset += curPixel ; if ( needsReEvaluation ( colConstraints [ i ] . component ) ) { if ( oldOnceAgain == onceAgain ) { onceAgain ++ ; } } } } if ( onceAgain == <NUM_LIT:1> ) { continue ; } onceAgain = <NUM_LIT:0> ; ypos += outerRowHeight ; row ++ ; } anchorNeedsReEval += resolveGenerellOffsets ( generellOffset , realSizeDim , insets , maxWidth , overallHeight ) ; } } private void fastLayoutContainer ( Container parent ) { for ( int row = <NUM_LIT:0> ; row < rows ( ) ; ++ row ) { for ( int col = <NUM_LIT:0> ; col < columns ( ) ; ++ col ) { IzPanelConstraints currentConst = getConstraints ( col , row ) ; if ( currentConst != null ) { log . addDebugMessage ( "<STR_LIT>" , new String [ ] { currentConst . getBounds ( ) . toString ( ) } , "<STR_LIT>" , null ) ; currentConst . component . setBounds ( currentConst . getBounds ( ) ) ; } } } } private boolean needNewLayout ( Container parent ) { Dimension ops = oldParentSize ; Insets opi = oldParentInsets ; oldParentSize = parent . getSize ( ) ; oldParentInsets = parent . getInsets ( ) ; if ( opi == null ) { return ( true ) ; } if ( ops . equals ( parent . getSize ( ) ) && opi . equals ( parent . getInsets ( ) ) ) { return ( false ) ; } return ( true ) ; } private int resolveGenerellOffsets ( int [ ] generellOffset , Dimension realSizeDim , Insets insets , int maxWidth , int overallHeight ) { int retval = <NUM_LIT:1> ; switch ( getAnchor ( ) ) { case CENTER : generellOffset [ <NUM_LIT:0> ] = ( realSizeDim . width - insets . left - insets . right - maxWidth ) / <NUM_LIT:2> ; generellOffset [ <NUM_LIT:1> ] = ( realSizeDim . height - insets . top - insets . bottom - overallHeight ) / <NUM_LIT:2> ; break ; case WEST : generellOffset [ <NUM_LIT:0> ] = <NUM_LIT:0> ; generellOffset [ <NUM_LIT:1> ] = ( realSizeDim . height - insets . top - insets . bottom - overallHeight ) / <NUM_LIT:2> ; break ; case EAST : generellOffset [ <NUM_LIT:0> ] = realSizeDim . width - insets . left - insets . right - maxWidth ; generellOffset [ <NUM_LIT:1> ] = ( realSizeDim . height - insets . top - insets . bottom - overallHeight ) / <NUM_LIT:2> ; break ; case NORTH : generellOffset [ <NUM_LIT:0> ] = ( realSizeDim . width - insets . left - insets . right - maxWidth ) / <NUM_LIT:2> ; generellOffset [ <NUM_LIT:1> ] = <NUM_LIT:0> ; break ; case SOUTH : generellOffset [ <NUM_LIT:0> ] = ( realSizeDim . width - insets . left - insets . right - maxWidth ) / <NUM_LIT:2> ; generellOffset [ <NUM_LIT:1> ] = realSizeDim . height - insets . top - insets . bottom - overallHeight ; break ; case NORTH_WEST : generellOffset [ <NUM_LIT:0> ] = <NUM_LIT:0> ; generellOffset [ <NUM_LIT:1> ] = <NUM_LIT:0> ; retval = <NUM_LIT:2> ; break ; case NORTH_EAST : generellOffset [ <NUM_LIT:0> ] = realSizeDim . width - insets . left - insets . right - maxWidth ; generellOffset [ <NUM_LIT:1> ] = <NUM_LIT:0> ; break ; case SOUTH_WEST : generellOffset [ <NUM_LIT:0> ] = <NUM_LIT:0> ; generellOffset [ <NUM_LIT:1> ] = realSizeDim . height - insets . top - insets . bottom - overallHeight ; break ; case SOUTH_EAST : generellOffset [ <NUM_LIT:0> ] = realSizeDim . width - insets . left - insets . right - maxWidth ; generellOffset [ <NUM_LIT:1> ] = realSizeDim . height - insets . top - insets . bottom - overallHeight ; break ; } if ( generellOffset [ <NUM_LIT:0> ] < <NUM_LIT:0> ) { generellOffset [ <NUM_LIT:0> ] = <NUM_LIT:0> ; } if ( generellOffset [ <NUM_LIT:1> ] < <NUM_LIT:0> ) { generellOffset [ <NUM_LIT:1> ] = <NUM_LIT:0> ; } return ( retval ) ; } private boolean needsReEvaluation ( Component comp ) { if ( ( comp instanceof MultiLineLabel ) || pathSelectionPanel . isInstance ( comp ) || USER_PATH_SELECTION_PANEL_CLASS . equals ( comp . getClass ( ) . getName ( ) ) ) { return ( true ) ; } return ( false ) ; } public float getLayoutAlignmentX ( Container target ) { return <NUM_LIT:0> ; } public float getLayoutAlignmentY ( Container target ) { return <NUM_LIT:0> ; } public void invalidateLayout ( Container target ) { } public Dimension maximumLayoutSize ( Container target ) { return ( minimumLayoutSize ( target ) ) ; } public void addLayoutComponent ( Component comp , Object constraints ) { if ( comp == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } IzPanelConstraints cc ; if ( ! ( constraints instanceof IzPanelConstraints ) ) { if ( ( comp instanceof FillerComponent ) && ( ( FillerComponent ) comp ) . getConstraints ( ) != null ) { cc = ( IzPanelConstraints ) ( ( FillerComponent ) comp ) . getConstraints ( ) . clone ( ) ; } else { cc = ( IzPanelConstraints ) IzPanelLayout . DEFAULT_CONSTRAINTS [ getIntermediarId ( comp . getClass ( ) , comp ) ] . clone ( ) ; } if ( NEXT_LINE . equals ( constraints ) ) { cc . setXPos ( <NUM_LIT:0> ) ; cc . setYPos ( NEXT_ROW ) ; } } else { cc = ( IzPanelConstraints ) ( ( IzPanelConstraints ) constraints ) . clone ( ) ; } cc . component = comp ; int yPos = cc . getYPos ( ) ; if ( yPos == LayoutConstants . NEXT_ROW ) { yPos = currentYPos + <NUM_LIT:1> ; } if ( yPos == LayoutConstants . CURRENT_ROW ) { yPos = currentYPos ; } cc . setYPos ( yPos ) ; int xPos = cc . getXPos ( ) ; if ( xPos == LayoutConstants . NEXT_COLUMN ) { xPos = currentXPos + <NUM_LIT:1> ; } if ( xPos == LayoutConstants . CURRENT_COLUMN ) { xPos = currentXPos ; } cc . setXPos ( xPos ) ; int perfCol = cc . getXWeight ( ) < Byte . MAX_VALUE ? cc . getXWeight ( ) : <NUM_LIT:1> ; if ( components . size ( ) < cc . getXPos ( ) + perfCol ) { for ( int i = components . size ( ) - <NUM_LIT:1> ; i < cc . getXPos ( ) + perfCol - <NUM_LIT:1> ; ++ i ) { components . add ( new ArrayList < IzPanelConstraints > ( ) ) ; } } IzPanelConstraints curConst = cc ; for ( int j = <NUM_LIT:0> ; j < perfCol ; ++ j ) { ArrayList < IzPanelConstraints > xComp = components . get ( xPos ) ; if ( xComp . size ( ) < yPos ) { for ( int i = xComp . size ( ) - <NUM_LIT:1> ; i < yPos - <NUM_LIT:1> ; ++ i ) { IzPanelConstraints dc = getDefaultConstraint ( XDUMMY_CONSTRAINT ) ; dc . component = new FillerComponent ( ) ; xComp . add ( dc ) ; } } xComp . add ( yPos , curConst ) ; if ( j < perfCol - <NUM_LIT:1> ) { curConst = getDefaultConstraint ( XDUMMY_CONSTRAINT ) ; curConst . component = new FillerComponent ( ) ; xPos ++ ; } } int xcsize = ( components . get ( xPos ) ) . size ( ) - <NUM_LIT:1> ; if ( currentYPos < xcsize ) { currentYPos = xcsize ; } currentXPos = xPos ; } public static Component createHorizontalStrut ( int width ) { return ( new FillerComponent ( new Dimension ( width , <NUM_LIT:0> ) ) ) ; } public static Component createVerticalStrut ( int height ) { return ( new FillerComponent ( new Dimension ( <NUM_LIT:0> , height ) ) ) ; } public static Component createParagraphGap ( ) { return ( createGap ( PARAGRAPH_GAP , VERTICAL ) ) ; } public static Component createVerticalFiller ( int fillerNumber ) { return ( createGap ( FILLER1_GAP + <NUM_LIT:1> - fillerNumber , VERTICAL ) ) ; } public static Component createHorizontalFiller ( int fillerNumber ) { return ( createGap ( FILLER1_GAP + <NUM_LIT:1> - fillerNumber , HORIZONTAL ) ) ; } public static Component createGap ( int gapType , int direction ) { if ( direction == HORIZONTAL ) { return ( new FillerComponent ( new Dimension ( <NUM_LIT:0> , <NUM_LIT:0> ) , new IzPanelConstraints ( DEFAULT_CONTROL_ALIGNMENT , DEFAULT_CONTROL_ALIGNMENT , NEXT_COLUMN , CURRENT_ROW , <NUM_LIT:1> , <NUM_LIT:1> , gapType , <NUM_LIT:0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ) ) ; } return ( new FillerComponent ( new Dimension ( <NUM_LIT:0> , <NUM_LIT:0> ) , new IzPanelConstraints ( DEFAULT_CONTROL_ALIGNMENT , DEFAULT_CONTROL_ALIGNMENT , <NUM_LIT:0> , NEXT_ROW , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:0> , gapType , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ) ) ; } public static IzPanelConstraints getDefaultConstraint ( int type ) { return ( ( IzPanelConstraints ) DEFAULT_CONSTRAINTS [ type ] . clone ( ) ) ; } public static class FillerComponent extends Component { private static final long serialVersionUID = <NUM_LIT> ; private Dimension size ; private IzPanelConstraints constraints ; public FillerComponent ( ) { this ( new Dimension ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ; } public FillerComponent ( Dimension size ) { this ( size , null ) ; } public FillerComponent ( Dimension size , IzPanelConstraints constraints ) { super ( ) ; this . size = size ; this . constraints = constraints ; } public Dimension getMinimumSize ( ) { return ( Dimension ) ( size . clone ( ) ) ; } public Dimension getPreferredSize ( ) { return getMinimumSize ( ) ; } public Dimension getMaximumSize ( ) { return getMinimumSize ( ) ; } public Rectangle getBounds ( ) { return ( getBounds ( new Rectangle ( ) ) ) ; } public Rectangle getBounds ( Rectangle rect ) { Rectangle rectangle = ( rect != null ) ? rect : new Rectangle ( ) ; rectangle . setBounds ( <NUM_LIT:0> , <NUM_LIT:0> , size . width , size . height ) ; return ( rectangle ) ; } public IzPanelConstraints getConstraints ( ) { return constraints ; } public void setConstraints ( IzPanelConstraints constraints ) { this . constraints = constraints ; } } public static int getAnchor ( ) { return ANCHOR ; } public static void setAnchor ( int anchor ) { ANCHOR = anchor ; } public static int getXStretchType ( ) { return X_STRETCH_TYPE ; } public static void setXStretchType ( int x_stretch ) { X_STRETCH_TYPE = x_stretch ; } public static int getYStretchType ( ) { return Y_STRETCH_TYPE ; } public static void setYStretchType ( int y_stretch ) { Y_STRETCH_TYPE = y_stretch ; } public static double getFullLineStretch ( ) { return FULL_LINE_STRETCH_DEFAULT ; } public static void setFullLineStretch ( double fullLineStretch ) { FULL_LINE_STRETCH_DEFAULT = fullLineStretch ; } public static double getFullColumnStretch ( ) { return FULL_COLUMN_STRETCH_DEFAULT ; } public static void setFullColumnStretch ( double fullStretch ) { FULL_COLUMN_STRETCH_DEFAULT = fullStretch ; } public static int verifyGapId ( int gapId ) { if ( gapId < <NUM_LIT:0> ) { gapId = - gapId ; } if ( gapId >= DEFAULT_X_GAPS . length ) { throw new IndexOutOfBoundsException ( "<STR_LIT>" ) ; } return ( gapId ) ; } public static int getDefaultXGap ( int gapId ) { gapId = verifyGapId ( gapId ) ; return DEFAULT_X_GAPS [ gapId ] ; } public static void setDefaultXGap ( int gap , int gapId ) { gapId = verifyGapId ( gapId ) ; DEFAULT_X_GAPS [ gapId ] = gap ; } public static int getDefaultYGap ( int gapId ) { gapId = verifyGapId ( gapId ) ; return DEFAULT_Y_GAPS [ gapId ] ; } public static void setDefaultYGap ( int gap , int gapId ) { gapId = verifyGapId ( gapId ) ; DEFAULT_Y_GAPS [ gapId ] = gap ; } public static int getDefaultTextfieldLength ( ) { return DEFAULT_TEXTFIELD_LENGTH ; } public static void setDefaultTextfieldLength ( int val ) { DEFAULT_TEXTFIELD_LENGTH = val ; } } </s>
|
<s> package com . izforge . izpack . gui ; import java . awt . * ; import java . util . ArrayList ; public class TwoColumnLayout implements LayoutManager2 { public static final int LEFT = <NUM_LIT:0> ; public static final int RIGHT = <NUM_LIT:1> ; public static final int CENTER = <NUM_LIT:2> ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private java . util . List < TwoColumnConstraints > [ ] components = new ArrayList [ ] { new ArrayList < TwoColumnConstraints > ( ) , new ArrayList < TwoColumnConstraints > ( ) } ; private TwoColumnConstraints title = null ; private int margin = <NUM_LIT:0> ; private int topBuffer = <NUM_LIT:0> ; private int indent = <NUM_LIT:0> ; private int gap = <NUM_LIT:5> ; private int colWidth ; private int alignment = LEFT ; private int leftRule ; private int rightRule ; private int centerRule ; private int titleHeight ; public TwoColumnLayout ( int margin , int gap , int indent , int topBuffer , int colWidth , int alignment ) { this . indent = indent ; this . gap = gap ; this . colWidth = colWidth ; if ( ( margin >= <NUM_LIT:0> ) && ( margin <= <NUM_LIT> ) ) { this . margin = margin ; } if ( ( topBuffer >= <NUM_LIT:0> ) && ( topBuffer <= <NUM_LIT:100> ) ) { this . topBuffer = topBuffer ; } if ( ( alignment == LEFT ) || ( alignment == CENTER ) || ( alignment == RIGHT ) ) { this . alignment = alignment ; } } public TwoColumnLayout ( int margin , int gap , int indent , int topBuffer , int alignment ) { this ( margin , gap , indent , topBuffer , <NUM_LIT:0> , alignment ) ; } public void addLayoutComponent ( Component comp , Object constraints ) { if ( constraints == null ) { return ; } TwoColumnConstraints component = null ; try { component = ( TwoColumnConstraints ) constraints ; component = ( TwoColumnConstraints ) component . clone ( ) ; } catch ( Throwable exception ) { return ; } component . component = comp ; if ( component . position == TwoColumnConstraints . NORTH ) { title = component ; if ( title . stretch ) { title . align = LEFT ; } } else if ( component . position == TwoColumnConstraints . BOTH ) { while ( components [ RIGHT ] . size ( ) > components [ LEFT ] . size ( ) ) { components [ LEFT ] . add ( null ) ; } while ( components [ LEFT ] . size ( ) > components [ RIGHT ] . size ( ) ) { components [ RIGHT ] . add ( null ) ; } components [ LEFT ] . add ( component ) ; components [ RIGHT ] . add ( null ) ; } else if ( component . position == TwoColumnConstraints . WEST ) { components [ LEFT ] . add ( component ) ; } else if ( component . position == TwoColumnConstraints . WESTONLY ) { components [ LEFT ] . add ( component ) ; while ( components [ RIGHT ] . size ( ) < components [ LEFT ] . size ( ) ) { components [ RIGHT ] . add ( null ) ; } } else if ( component . position == TwoColumnConstraints . EAST ) { components [ RIGHT ] . add ( component ) ; } else if ( component . position == TwoColumnConstraints . EASTONLY ) { components [ RIGHT ] . add ( component ) ; while ( components [ LEFT ] . size ( ) < components [ RIGHT ] . size ( ) ) { components [ LEFT ] . add ( null ) ; } } } public void layoutContainer ( Container parent ) { positionRules ( parent ) ; positionTitle ( parent ) ; positionComponents ( parent ) ; } private void positionRules ( Container parent ) { int margin = margin ( parent ) ; if ( alignment == LEFT ) { leftRule = margin ; rightRule = parent . getWidth ( ) - margin ; if ( colWidth > <NUM_LIT:0> ) { centerRule = leftRule + ( rightRule - leftRule ) / <NUM_LIT:100> * colWidth + gap ; } else { centerRule = leftRule + minimumColumnWidth ( LEFT , parent ) + gap ; } } else if ( alignment == CENTER ) { centerRule = ( int ) ( parent . getMinimumSize ( ) . getWidth ( ) / <NUM_LIT:2> ) ; leftRule = centerRule - minimumColumnWidth ( LEFT , parent ) - gap ; rightRule = parent . getWidth ( ) - margin ; } else if ( alignment == RIGHT ) { rightRule = parent . getWidth ( ) - margin ; leftRule = centerRule - minimumColumnWidth ( LEFT , parent ) - gap ; if ( colWidth > <NUM_LIT:0> ) { centerRule = rightRule - ( rightRule - leftRule ) / <NUM_LIT:100> * colWidth ; } else { centerRule = rightRule - minimumColumnWidth ( RIGHT , parent ) ; } } } private void positionTitle ( Container parent ) { if ( title != null ) { Component component = title . component ; int width = ( int ) component . getMinimumSize ( ) . getWidth ( ) ; titleHeight = ( int ) component . getMinimumSize ( ) . getHeight ( ) ; if ( component != null ) { if ( title . stretch ) { width = rightRule - leftRule ; component . setBounds ( leftRule , <NUM_LIT:0> , width , titleHeight ) ; } else if ( title . align == TwoColumnConstraints . LEFT ) { component . setBounds ( leftRule , <NUM_LIT:0> , width , titleHeight ) ; } else if ( title . align == TwoColumnConstraints . CENTER ) { int left = centerRule - ( width / <NUM_LIT:2> ) ; component . setBounds ( left , <NUM_LIT:0> , width , titleHeight ) ; } else if ( title . align == TwoColumnConstraints . RIGHT ) { int left = rightRule - width ; component . setBounds ( left , <NUM_LIT:0> , width , titleHeight ) ; } } } } private void positionComponents ( Container parent ) { int usedHeight = titleHeight + minimumClusterHeight ( ) ; int topBuffer = topBuffer ( usedHeight , parent ) ; int leftHeight = <NUM_LIT:0> ; int rightHeight = <NUM_LIT:0> ; if ( topBuffer < <NUM_LIT:0> ) { topBuffer = <NUM_LIT:0> ; } int y = titleHeight + topBuffer ; for ( int i = <NUM_LIT:0> ; i < rows ( ) ; i ++ ) { leftHeight = height ( i , LEFT ) ; rightHeight = height ( i , RIGHT ) ; if ( leftHeight > rightHeight ) { int offset = ( leftHeight - rightHeight ) / <NUM_LIT:2> ; positionComponent ( y , i , LEFT , parent ) ; positionComponent ( ( y + offset ) , i , RIGHT , parent ) ; y += leftHeight ; } else if ( leftHeight < rightHeight ) { int offset = ( rightHeight - leftHeight ) / <NUM_LIT:2> ; positionComponent ( ( y + offset ) , i , LEFT , parent ) ; positionComponent ( y , i , RIGHT , parent ) ; y += rightHeight ; } else { positionComponent ( y , i , LEFT , parent ) ; positionComponent ( y , i , RIGHT , parent ) ; y += leftHeight ; } } } private void positionComponent ( int y , int row , int column , Container parent ) { TwoColumnConstraints constraints = null ; try { constraints = components [ column ] . get ( row ) ; } catch ( Throwable exception ) { return ; } int x = <NUM_LIT:0> ; if ( constraints != null ) { Component component = constraints . component ; int width = ( int ) component . getPreferredSize ( ) . getWidth ( ) ; int height = ( int ) component . getPreferredSize ( ) . getHeight ( ) ; boolean stretchBool = constraints . stretch ; boolean indentBool = constraints . indent ; int align = constraints . align ; if ( constraints . position == TwoColumnConstraints . BOTH ) { width = getWidth ( leftRule , rightRule , stretchBool , indentBool , width ) ; if ( width > ( rightRule - leftRule ) ) { stretchBool = true ; } x = getPosition ( leftRule , rightRule , stretchBool , indentBool , width , align ) ; } else if ( column == LEFT ) { width = getWidth ( leftRule , centerRule , stretchBool , indentBool , width ) ; x = getPosition ( leftRule , centerRule , stretchBool , indentBool , width , align ) ; } else { width = getWidth ( centerRule , rightRule , stretchBool , indentBool , width ) ; x = getPosition ( centerRule , rightRule , stretchBool , indentBool , width , align ) ; } if ( component != null ) { component . setBounds ( x , y , width , height ) ; } } } private int getWidth ( int left , int right , boolean stretch , boolean indent , int componentWidth ) { int width = componentWidth ; if ( stretch ) { width = right - left ; } if ( indent ) { width -= this . indent ; } return width ; } private int getPosition ( int left , int right , boolean stretch , boolean indent , int componentWidth , int align ) { int position = left ; if ( align == TwoColumnConstraints . LEFT ) { position = left ; } else if ( align == TwoColumnConstraints . CENTER ) { position += ( right - left ) / <NUM_LIT:2> - componentWidth / <NUM_LIT:2> - this . gap / <NUM_LIT:2> ; } else if ( align == TwoColumnConstraints . RIGHT ) { position = right - componentWidth - this . gap ; } if ( indent ) { position += this . indent ; } return position ; } private int minimumColumnWidth ( int column , Container parent ) { Component component = null ; int width = <NUM_LIT:0> ; int temp = <NUM_LIT:0> ; for ( TwoColumnConstraints constraints : components [ column ] ) { if ( ( constraints != null ) && ( constraints . position != TwoColumnConstraints . BOTH ) ) { component = constraints . component ; temp = ( int ) component . getMinimumSize ( ) . getWidth ( ) ; if ( constraints . indent ) { temp += indent ; } if ( temp > width ) { width = temp ; } } } return ( width ) ; } private int minimumBothColumnsWidth ( Container parent ) { Component component = null ; int width = <NUM_LIT:0> ; int temp = <NUM_LIT:0> ; if ( title != null ) { component = title . component ; width = ( int ) component . getMinimumSize ( ) . getWidth ( ) ; } for ( TwoColumnConstraints constraints : components [ LEFT ] ) { if ( ( constraints != null ) && ( constraints . position == TwoColumnConstraints . BOTH ) ) { component = constraints . component ; temp = ( int ) component . getMinimumSize ( ) . getWidth ( ) ; if ( constraints . indent ) { temp += indent ; } if ( temp > width ) { width = temp ; } } } return ( width ) ; } private int minimumClusterHeight ( ) { int height = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < rows ( ) ; i ++ ) { height += rowHeight ( i ) ; } return ( height ) ; } private int rows ( ) { int rows = <NUM_LIT:0> ; int leftRows = components [ LEFT ] . size ( ) ; int rightRows = components [ RIGHT ] . size ( ) ; if ( leftRows > rightRows ) { rows = leftRows ; } else { rows = rightRows ; } return ( rows ) ; } private int rowHeight ( int row ) { int height = <NUM_LIT:0> ; int height1 = height ( row , LEFT ) ; int height2 = height ( row , RIGHT ) ; if ( height1 > height2 ) { height = height1 ; } else { height = height2 ; } return ( height ) ; } private int height ( int row , int column ) { int height = <NUM_LIT:0> ; int width = <NUM_LIT:0> ; Component component ; TwoColumnConstraints constraints ; try { constraints = components [ column ] . get ( row ) ; if ( constraints != null ) { component = constraints . component ; width = ( int ) component . getMinimumSize ( ) . getWidth ( ) ; height = ( int ) component . getMinimumSize ( ) . getHeight ( ) ; if ( constraints . position == TwoColumnConstraints . WEST ) { if ( width > ( centerRule - leftRule ) ) { component . setBounds ( <NUM_LIT:0> , <NUM_LIT:0> , ( centerRule - leftRule ) , height ) ; } } else if ( constraints . position == TwoColumnConstraints . EAST ) { if ( width > ( rightRule - centerRule ) ) { component . setBounds ( <NUM_LIT:0> , <NUM_LIT:0> , ( rightRule - centerRule ) , height ) ; } } else if ( constraints . position == TwoColumnConstraints . BOTH ) { if ( width > ( rightRule - leftRule ) ) { component . setBounds ( <NUM_LIT:0> , <NUM_LIT:0> , ( rightRule - leftRule ) , height ) ; } } height = ( int ) component . getMinimumSize ( ) . getHeight ( ) ; } } catch ( Throwable exception ) { } return ( height ) ; } private int margin ( Container parent ) { int amount = ( int ) ( ( ( parent . getSize ( ) . getWidth ( ) ) * margin ) / <NUM_LIT:100> ) ; return ( amount ) ; } private int topBuffer ( int usedHeight , Container parent ) { int amount = ( ( int ) parent . getSize ( ) . getHeight ( ) ) - usedHeight ; amount = amount * topBuffer / <NUM_LIT:100> ; return ( amount ) ; } public Dimension preferredLayoutSize ( Container parent ) { return ( minimumLayoutSize ( parent ) ) ; } public Dimension minimumLayoutSize ( Container parent ) { positionTitle ( parent ) ; int width = minimumBothColumnsWidth ( parent ) ; int height = minimumClusterHeight ( ) + titleHeight ; return ( new Dimension ( width , height ) ) ; } public Dimension maximumLayoutSize ( Container parent ) { return ( minimumLayoutSize ( parent ) ) ; } public float getLayoutAlignmentX ( Container parent ) { return ( <NUM_LIT:0> ) ; } public float getLayoutAlignmentY ( Container parent ) { return ( <NUM_LIT:0> ) ; } public void invalidateLayout ( Container parent ) { leftRule = <NUM_LIT:0> ; rightRule = <NUM_LIT:0> ; centerRule = <NUM_LIT:0> ; titleHeight = <NUM_LIT:0> ; } public void addLayoutComponent ( String name , Component comp ) { } public void removeLayoutComponent ( Component comp ) { java . util . List < TwoColumnConstraints > left = components [ LEFT ] ; java . util . List < TwoColumnConstraints > right = components [ RIGHT ] ; for ( int i = <NUM_LIT:0> ; i < left . size ( ) ; i ++ ) { TwoColumnConstraints constraints = left . get ( i ) ; if ( constraints == null ) { continue ; } Component ctemp = constraints . component ; if ( ctemp != null && ctemp . equals ( comp ) ) { if ( constraints . position == TwoColumnConstraints . BOTH || constraints . position == TwoColumnConstraints . WESTONLY ) { right . remove ( i ) ; } break ; } } for ( int j = <NUM_LIT:0> ; j < right . size ( ) ; j ++ ) { TwoColumnConstraints constraints = right . get ( j ) ; if ( constraints == null ) { continue ; } Component ctemp = constraints . component ; if ( ctemp != null && ctemp . equals ( comp ) ) { if ( constraints . position == TwoColumnConstraints . BOTH || constraints . position == TwoColumnConstraints . EASTONLY ) { left . remove ( j ) ; } break ; } } } public void showRules ( Graphics2D graphics , Color color ) { int height = graphics . getClipBounds ( ) . height ; Stroke currentStroke = graphics . getStroke ( ) ; Color currentColor = graphics . getColor ( ) ; Stroke stroke = new BasicStroke ( <NUM_LIT:1> , BasicStroke . CAP_BUTT , BasicStroke . JOIN_BEVEL , <NUM_LIT> , new float [ ] { <NUM_LIT:10> , <NUM_LIT:5> } , <NUM_LIT:5> ) ; graphics . setColor ( color ) ; graphics . drawLine ( leftRule , <NUM_LIT:0> , leftRule , height ) ; graphics . drawLine ( centerRule , titleHeight , centerRule , height ) ; graphics . drawLine ( rightRule , <NUM_LIT:0> , rightRule , height ) ; graphics . drawLine ( leftRule , titleHeight , rightRule , titleHeight ) ; graphics . setStroke ( stroke ) ; graphics . drawLine ( ( leftRule + indent ) , titleHeight , ( leftRule + indent ) , height ) ; graphics . drawLine ( ( centerRule + indent ) , titleHeight , ( centerRule + indent ) , height ) ; graphics . setStroke ( currentStroke ) ; graphics . setColor ( currentColor ) ; } } </s>
|
<s> package com . izforge . izpack . gui ; import java . awt . Dimension ; import java . awt . Font ; import java . awt . Toolkit ; import java . awt . event . KeyEvent ; import java . awt . event . KeyListener ; import java . awt . event . WindowEvent ; import java . awt . event . WindowListener ; import java . io . BufferedOutputStream ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . io . PipedInputStream ; import java . io . PipedOutputStream ; import java . io . PrintStream ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . List ; import javax . swing . JFrame ; import javax . swing . JScrollPane ; import javax . swing . JTextArea ; import javax . swing . SwingUtilities ; import javax . swing . event . DocumentEvent ; import javax . swing . event . DocumentListener ; import javax . swing . text . Document ; import javax . swing . text . Segment ; public final class Console { public static final int INITIAL_WIDTH = <NUM_LIT> ; public static final int INITIAL_HEIGHT = <NUM_LIT> ; public static void main ( String [ ] args ) { Runtime runtime = Runtime . getRuntime ( ) ; Process process = null ; try { process = runtime . exec ( args ) ; new Console ( process ) ; System . exit ( process . exitValue ( ) ) ; } catch ( IOException e ) { System . out . println ( "<STR_LIT>" + args [ <NUM_LIT:0> ] ) ; System . out . println ( e ) ; } } private StdOut so ; private StdOut se ; public String getOutputData ( ) { if ( so != null ) { return so . getData ( ) ; } else { return "<STR_LIT>" ; } } public String getErrorData ( ) { if ( se != null ) { return se . getData ( ) ; } else { return "<STR_LIT>" ; } } public Console ( final Process p ) { JFrame frame = new JFrame ( ) ; frame . setTitle ( "<STR_LIT>" ) ; Dimension screenSize = Toolkit . getDefaultToolkit ( ) . getScreenSize ( ) ; frame . setLocation ( screenSize . width / <NUM_LIT:2> - INITIAL_WIDTH / <NUM_LIT:2> , screenSize . height / <NUM_LIT:2> - INITIAL_HEIGHT / <NUM_LIT:2> ) ; ConsoleTextArea cta = new ConsoleTextArea ( ) ; JScrollPane scroll = new JScrollPane ( cta ) ; scroll . setPreferredSize ( new Dimension ( INITIAL_WIDTH , INITIAL_HEIGHT ) ) ; frame . getContentPane ( ) . add ( scroll ) ; frame . pack ( ) ; frame . addWindowListener ( new WindowListener ( ) { public void windowActivated ( WindowEvent e ) { } public void windowClosed ( WindowEvent e ) { } public void windowClosing ( WindowEvent e ) { p . destroy ( ) ; } public void windowDeactivated ( WindowEvent e ) { } public void windowDeiconified ( WindowEvent e ) { } public void windowIconified ( WindowEvent e ) { } public void windowOpened ( WindowEvent e ) { } } ) ; so = new StdOut ( p , cta ) ; se = new StdOut ( p , cta ) ; StdIn si = new StdIn ( p , cta ) ; so . start ( ) ; se . start ( ) ; si . start ( ) ; try { frame . setVisible ( true ) ; p . waitFor ( ) ; } catch ( InterruptedException e ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( e ) ; } try { so . done ( ) ; se . done ( ) ; si . done ( ) ; so . join ( ) ; se . join ( ) ; si . join ( ) ; } catch ( InterruptedException e ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( e ) ; } frame . setVisible ( false ) ; } } class ConsoleTextArea extends JTextArea implements KeyListener , DocumentListener { private static final long serialVersionUID = <NUM_LIT> ; private ConsoleWriter console1 ; private PrintStream out ; private PrintStream err ; private PrintWriter inPipe ; private PipedInputStream in ; private List < String > history ; private int historyIndex = - <NUM_LIT:1> ; private int outputMark = <NUM_LIT:0> ; public void select ( int start , int end ) { requestFocus ( ) ; super . select ( start , end ) ; } public ConsoleTextArea ( ) { super ( ) ; history = new ArrayList < String > ( ) ; console1 = new ConsoleWriter ( this ) ; ConsoleWriter console2 = new ConsoleWriter ( this ) ; out = new PrintStream ( console1 ) ; err = new PrintStream ( console2 ) ; PipedOutputStream outPipe = new PipedOutputStream ( ) ; inPipe = new PrintWriter ( outPipe ) ; in = new PipedInputStream ( ) ; try { outPipe . connect ( in ) ; } catch ( IOException exc ) { exc . printStackTrace ( ) ; } getDocument ( ) . addDocumentListener ( this ) ; addKeyListener ( this ) ; setLineWrap ( true ) ; setFont ( new Font ( "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT:12> ) ) ; } void returnPressed ( ) { Document doc = getDocument ( ) ; int len = doc . getLength ( ) ; Segment segment = new Segment ( ) ; try { synchronized ( doc ) { doc . getText ( outputMark , len - outputMark , segment ) ; } } catch ( javax . swing . text . BadLocationException ignored ) { ignored . printStackTrace ( ) ; } if ( segment . count > <NUM_LIT:0> ) { history . add ( segment . toString ( ) ) ; } historyIndex = history . size ( ) ; inPipe . write ( segment . array , segment . offset , segment . count ) ; append ( "<STR_LIT:n>" ) ; synchronized ( doc ) { outputMark = doc . getLength ( ) ; } inPipe . write ( "<STR_LIT:n>" ) ; inPipe . flush ( ) ; console1 . flush ( ) ; } public void eval ( String str ) { inPipe . write ( str ) ; inPipe . write ( "<STR_LIT:n>" ) ; inPipe . flush ( ) ; console1 . flush ( ) ; } public void keyPressed ( KeyEvent e ) { int code = e . getKeyCode ( ) ; if ( code == KeyEvent . VK_BACK_SPACE || code == KeyEvent . VK_LEFT ) { if ( outputMark == getCaretPosition ( ) ) { e . consume ( ) ; } } else if ( code == KeyEvent . VK_HOME ) { int caretPos = getCaretPosition ( ) ; if ( caretPos == outputMark ) { e . consume ( ) ; } else if ( caretPos > outputMark ) { if ( ! e . isControlDown ( ) ) { if ( e . isShiftDown ( ) ) { moveCaretPosition ( outputMark ) ; } else { setCaretPosition ( outputMark ) ; } e . consume ( ) ; } } } else if ( code == KeyEvent . VK_ENTER ) { returnPressed ( ) ; e . consume ( ) ; } else if ( code == KeyEvent . VK_UP ) { historyIndex -- ; if ( historyIndex >= <NUM_LIT:0> ) { if ( historyIndex >= history . size ( ) ) { historyIndex = history . size ( ) - <NUM_LIT:1> ; } if ( historyIndex >= <NUM_LIT:0> ) { String str = history . get ( historyIndex ) ; int len = getDocument ( ) . getLength ( ) ; replaceRange ( str , outputMark , len ) ; int caretPos = outputMark + str . length ( ) ; select ( caretPos , caretPos ) ; } else { historyIndex ++ ; } } else { historyIndex ++ ; } e . consume ( ) ; } else if ( code == KeyEvent . VK_DOWN ) { int caretPos = outputMark ; if ( history . size ( ) > <NUM_LIT:0> ) { historyIndex ++ ; if ( historyIndex < <NUM_LIT:0> ) { historyIndex = <NUM_LIT:0> ; } int len = getDocument ( ) . getLength ( ) ; if ( historyIndex < history . size ( ) ) { String str = history . get ( historyIndex ) ; replaceRange ( str , outputMark , len ) ; caretPos = outputMark + str . length ( ) ; } else { historyIndex = history . size ( ) ; replaceRange ( "<STR_LIT>" , outputMark , len ) ; } } select ( caretPos , caretPos ) ; e . consume ( ) ; } } public void keyTyped ( KeyEvent e ) { int keyChar = e . getKeyChar ( ) ; if ( keyChar == <NUM_LIT> ) { if ( outputMark == getCaretPosition ( ) ) { e . consume ( ) ; } } else if ( getCaretPosition ( ) < outputMark ) { setCaretPosition ( outputMark ) ; } } public void keyReleased ( KeyEvent e ) { } public synchronized void write ( String str ) { insert ( str , outputMark ) ; int len = str . length ( ) ; outputMark += len ; select ( outputMark , outputMark ) ; } public synchronized void insertUpdate ( DocumentEvent e ) { int len = e . getLength ( ) ; int off = e . getOffset ( ) ; if ( outputMark > off ) { outputMark += len ; } } public synchronized void removeUpdate ( DocumentEvent e ) { int len = e . getLength ( ) ; int off = e . getOffset ( ) ; if ( outputMark > off ) { if ( outputMark >= off + len ) { outputMark -= len ; } else { outputMark = off ; } } } public void postUpdateUI ( ) { requestFocus ( ) ; setCaret ( getCaret ( ) ) ; synchronized ( this ) { select ( outputMark , outputMark ) ; } } public void changedUpdate ( DocumentEvent e ) { } public InputStream getIn ( ) { return in ; } public PrintStream getOut ( ) { return out ; } public PrintStream getErr ( ) { return err ; } } class ConsoleWriter extends java . io . OutputStream { private ConsoleTextArea textArea ; private StringBuffer buffer ; public ConsoleWriter ( ConsoleTextArea textArea ) { this . textArea = textArea ; buffer = new StringBuffer ( ) ; } public synchronized void write ( int ch ) { buffer . append ( ( char ) ch ) ; if ( ch == '<STR_LIT:\n>' ) { flushBuffer ( ) ; } } public synchronized void write ( char [ ] data , int off , int len ) { for ( int i = off ; i < len ; i ++ ) { buffer . append ( data [ i ] ) ; if ( data [ i ] == '<STR_LIT:\n>' ) { flushBuffer ( ) ; } } } public synchronized void flush ( ) { if ( buffer . length ( ) > <NUM_LIT:0> ) { flushBuffer ( ) ; } } public void close ( ) { flush ( ) ; } private void flushBuffer ( ) { String str = buffer . toString ( ) ; buffer . setLength ( <NUM_LIT:0> ) ; SwingUtilities . invokeLater ( new ConsoleWrite ( textArea , str ) ) ; } } class ConsoleWrite implements Runnable { private ConsoleTextArea textArea ; private String str ; public ConsoleWrite ( ConsoleTextArea textArea , String str ) { this . textArea = textArea ; this . str = str ; } public void run ( ) { textArea . write ( str ) ; } } class StdOut extends Thread { private InputStreamReader output ; private boolean processRunning ; private ConsoleTextArea cta ; private StringBuffer data ; public StdOut ( Process p , ConsoleTextArea cta ) { setDaemon ( true ) ; output = new InputStreamReader ( p . getInputStream ( ) ) ; this . cta = cta ; processRunning = true ; data = new StringBuffer ( ) ; } public void run ( ) { try { while ( output . ready ( ) || processRunning ) { if ( output . ready ( ) ) { char [ ] array = new char [ <NUM_LIT:255> ] ; int num = output . read ( array ) ; if ( num != - <NUM_LIT:1> ) { String s = new String ( array , <NUM_LIT:0> , num ) ; data . append ( s ) ; SwingUtilities . invokeAndWait ( new ConsoleWrite ( cta , s ) ) ; } } } } catch ( Exception e ) { System . err . println ( "<STR_LIT>" ) ; System . err . println ( e ) ; } } public void done ( ) { processRunning = false ; } public String getData ( ) { return data . toString ( ) ; } } class StdIn extends Thread { private BufferedReader kb ; private boolean processRunning ; private PrintWriter op ; public StdIn ( Process p , ConsoleTextArea cta ) { setDaemon ( true ) ; InputStreamReader ir = new InputStreamReader ( cta . getIn ( ) ) ; kb = new BufferedReader ( ir ) ; BufferedOutputStream os = new BufferedOutputStream ( p . getOutputStream ( ) ) ; op = new PrintWriter ( ( new OutputStreamWriter ( os ) ) , true ) ; processRunning = true ; } public void run ( ) { try { while ( kb . ready ( ) || processRunning ) { if ( kb . ready ( ) ) { op . println ( kb . readLine ( ) ) ; } } } catch ( IOException e ) { System . err . println ( "<STR_LIT>" ) ; System . err . println ( e ) ; } } public void done ( ) { processRunning = false ; } } </s>
|
<s> package com . izforge . izpack . gui ; import java . awt . * ; public class IzPanelConstraints implements Cloneable , LayoutConstants { private int xCellAlignment = IzPanelLayout . DEFAULT_X_ALIGNMENT [ <NUM_LIT:0> ] ; private int yCellAlignment = IzPanelLayout . DEFAULT_Y_ALIGNMENT [ <NUM_LIT:0> ] ; private int xPos = <NUM_LIT:0> ; private int yPos = NEXT_ROW ; private int xWeight = <NUM_LIT:1> ; private int yWeight = <NUM_LIT:1> ; private int xGap = IzPanelLayout . DEFAULT_X_GAPS [ - LABEL_GAP ] ; private int yGap = IzPanelLayout . DEFAULT_Y_GAPS [ - LABEL_GAP ] ; private double xStretch = <NUM_LIT:0.0> ; private double yStretch = <NUM_LIT:0.0> ; private Rectangle bounds ; Component component = null ; int preferredHeight = <NUM_LIT:0> ; public double getXStretch ( ) { return xStretch ; } public void setXStretch ( double stretch ) { this . xStretch = stretch ; } public double getYStretch ( ) { return yStretch ; } public void setYStretch ( double stretch ) { this . yStretch = stretch ; } public int getXGap ( ) { return xGap ; } public void setXGap ( int gap ) { xGap = gap ; } public int getYGap ( ) { return yGap ; } public void setYGap ( int gap ) { yGap = gap ; } public IzPanelConstraints ( int xCellAlignment , int yCellAlignment , int xPos , int yPos , int xWeight , int yWeight , int xGap , int yGap , double xStretch , double yStretch ) { this . xCellAlignment = xCellAlignment ; this . yCellAlignment = yCellAlignment ; this . xPos = xPos ; this . yPos = yPos ; this . xWeight = xWeight ; this . yWeight = yWeight ; setXGap ( xGap ) ; setYGap ( yGap ) ; setXStretch ( xStretch ) ; setYStretch ( yStretch ) ; } public IzPanelConstraints ( ) { super ( ) ; } public Object clone ( ) { try { IzPanelConstraints constraints = ( IzPanelConstraints ) super . clone ( ) ; return constraints ; } catch ( CloneNotSupportedException e ) { throw new InternalError ( ) ; } } public int getXCellAlignment ( ) { return xCellAlignment ; } public void setXCellAlignment ( int cellAlignment ) { xCellAlignment = cellAlignment ; } public int getXPos ( ) { return xPos ; } public void setXPos ( int pos ) { xPos = pos ; } public int getXWeight ( ) { return xWeight ; } public void setXWeight ( int weight ) { xWeight = weight ; } public int getYCellAlignment ( ) { return yCellAlignment ; } public void setYCellAlignment ( int cellAlignment ) { yCellAlignment = cellAlignment ; } public int getYPos ( ) { return yPos ; } public void setYPos ( int pos ) { yPos = pos ; } public int getYWeight ( ) { return yWeight ; } public void setYWeight ( int weight ) { yWeight = weight ; } public Rectangle getBounds ( ) { if ( bounds != null ) { return ( Rectangle ) ( bounds . clone ( ) ) ; } return ( new Rectangle ( ) ) ; } public void setBounds ( Rectangle bounds ) { this . bounds = ( Rectangle ) bounds . clone ( ) ; } } </s>
|
<s> package com . izforge . izpack . gui ; import javax . swing . * ; import java . util . TreeMap ; public class IconsDatabase extends TreeMap < String , ImageIcon > { private static final long serialVersionUID = <NUM_LIT> ; } </s>
|
<s> package com . izforge . izpack . merge ; import static org . hamcrest . MatcherAssert . assertThat ; import java . io . File ; import java . net . URL ; import java . util . zip . ZipFile ; import org . junit . Test ; import org . junit . runner . RunWith ; import com . izforge . izpack . api . merge . Mergeable ; import com . izforge . izpack . core . container . TestMergeContainer ; import com . izforge . izpack . matcher . DuplicateMatcher ; import com . izforge . izpack . matcher . ZipMatcher ; import com . izforge . izpack . merge . resolve . MergeableResolver ; import com . izforge . izpack . merge . resolve . PathResolver ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . MergeUtils ; import com . izforge . izpack . test . junit . PicoRunner ; @ RunWith ( PicoRunner . class ) @ Container ( TestMergeContainer . class ) public class MergeDuplicationTest { private PathResolver pathResolver ; private MergeableResolver mergeableResolver ; public MergeDuplicationTest ( PathResolver pathResolver , MergeableResolver mergeableResolver ) { this . pathResolver = pathResolver ; this . mergeableResolver = mergeableResolver ; } @ Test public void testAddJarDuplicated ( ) throws Exception { URL resource = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; Mergeable jarMerge = mergeableResolver . getMergeableFromURL ( resource ) ; File tempFile = MergeUtils . doDoubleMerge ( jarMerge ) ; ZipFile tempZipFile = new ZipFile ( tempFile ) ; assertThat ( tempZipFile , ZipMatcher . isZipMatching ( DuplicateMatcher . isEntryUnique ( "<STR_LIT>" ) ) ) ; } @ Test public void testMergeDuplicateFile ( ) throws Exception { Mergeable mergeable = mergeableResolver . getMergeableFromURL ( getClass ( ) . getResource ( "<STR_LIT>" ) , "<STR_LIT>" ) ; File tempFile = MergeUtils . doDoubleMerge ( mergeable ) ; ZipFile tempZipFile = new ZipFile ( tempFile ) ; assertThat ( tempZipFile , ZipMatcher . isZipMatching ( DuplicateMatcher . isEntryUnique ( "<STR_LIT>" ) ) ) ; } } </s>
|
<s> package com . izforge . izpack . merge ; import static org . hamcrest . MatcherAssert . assertThat ; import java . net . URL ; import org . hamcrest . core . Is ; import org . junit . Test ; import org . junit . runner . RunWith ; import com . izforge . izpack . core . container . TestMergeContainer ; import com . izforge . izpack . matcher . MergeMatcher ; import com . izforge . izpack . merge . resolve . ResolveUtils ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . junit . PicoRunner ; @ RunWith ( PicoRunner . class ) @ Container ( TestMergeContainer . class ) public class MergeManagerTest { private MergeManagerImpl mergeManager ; public MergeManagerTest ( MergeManagerImpl mergeManager ) { this . mergeManager = mergeManager ; } @ Test public void testProcessJarPath ( ) throws Exception { URL resource = new URL ( "<STR_LIT>" ) ; String jarPath = ResolveUtils . processUrlToJarPath ( resource ) ; System . out . println ( jarPath ) ; assertThat ( jarPath , Is . is ( "<STR_LIT>" ) ) ; } @ Test public void testAddDirectoryWithFile ( ) throws Exception { mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; assertThat ( mergeManager , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void testAddResourceToMerge ( ) throws Exception { mergeManager . addResourceToMerge ( "<STR_LIT>" ) ; assertThat ( mergeManager , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } @ Test public void testAddResourceToMergeWithDestination ( ) throws Exception { mergeManager . addResourceToMerge ( "<STR_LIT>" , "<STR_LIT>" ) ; assertThat ( mergeManager , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } @ Test public void testAddSingleClassToMergeWithDestinationFromAJar ( ) throws Exception { mergeManager . addResourceToMerge ( "<STR_LIT>" , "<STR_LIT>" ) ; assertThat ( mergeManager , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } @ Test public void testAddPackageToMergeWithDestinationFromAJar ( ) throws Exception { mergeManager . addResourceToMerge ( "<STR_LIT>" , "<STR_LIT>" ) ; assertThat ( mergeManager , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . merge . jar ; import static org . hamcrest . MatcherAssert . assertThat ; import static org . junit . Assert . assertEquals ; import java . io . File ; import java . io . FileFilter ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . OutputStream ; import java . net . URL ; import java . net . URLClassLoader ; import java . util . HashMap ; import java . util . List ; import java . util . jar . JarOutputStream ; import java . util . zip . ZipEntry ; import org . hamcrest . core . Is ; import org . hamcrest . text . StringContains ; import org . junit . Test ; import org . junit . runner . RunWith ; import org . mockito . ArgumentCaptor ; import org . mockito . Mockito ; import com . izforge . izpack . api . merge . Mergeable ; import com . izforge . izpack . core . container . TestMergeContainer ; import com . izforge . izpack . matcher . MergeMatcher ; import com . izforge . izpack . merge . resolve . MergeableResolver ; import com . izforge . izpack . merge . resolve . PathResolver ; import com . izforge . izpack . merge . resolve . ResolveUtils ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . junit . PicoRunner ; @ RunWith ( PicoRunner . class ) @ Container ( TestMergeContainer . class ) public class JarMergeTest { private PathResolver pathResolver ; private MergeableResolver mergeableResolver ; public JarMergeTest ( PathResolver pathResolver , MergeableResolver mergeableResolver ) { this . pathResolver = pathResolver ; this . mergeableResolver = mergeableResolver ; } @ Test public void testAddJarContent ( ) throws Exception { URL resource = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; Mergeable jarMerge = mergeableResolver . getMergeableFromURL ( resource ) ; assertThat ( jarMerge , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } @ Test public void testMergeClassFromJarFile ( ) throws Exception { List < Mergeable > jarMergeList = pathResolver . getMergeableFromPath ( "<STR_LIT>" ) ; assertThat ( jarMergeList . size ( ) , Is . is ( <NUM_LIT:1> ) ) ; Mergeable jarMerge = jarMergeList . get ( <NUM_LIT:0> ) ; assertThat ( jarMerge , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } @ Test public void testMergeClassFromJarFileWithDestination ( ) throws Exception { List < Mergeable > jarMergeList = pathResolver . getMergeableFromPath ( "<STR_LIT>" , "<STR_LIT>" ) ; assertThat ( jarMergeList . size ( ) , Is . is ( <NUM_LIT:1> ) ) ; Mergeable jarMerge = jarMergeList . get ( <NUM_LIT:0> ) ; assertThat ( jarMerge , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } @ Test public void testMergeJarFoundDynamicallyLoaded ( ) throws Exception { URL urlJar = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; URLClassLoader loader = URLClassLoader . newInstance ( new URL [ ] { urlJar } , ClassLoader . getSystemClassLoader ( ) ) ; Mergeable jarMerge = mergeableResolver . getMergeableFromURLWithDestination ( loader . getResource ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertThat ( jarMerge , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } @ Test public void testFindPanelInJar ( ) throws Exception { URL resource = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; Mergeable jarMerge = mergeableResolver . getMergeableFromURL ( resource ) ; File file = jarMerge . find ( new FileFilter ( ) { public boolean accept ( File pathname ) { return pathname . isDirectory ( ) || pathname . getName ( ) . replaceAll ( "<STR_LIT:.class>" , "<STR_LIT>" ) . equalsIgnoreCase ( "<STR_LIT>" ) ; } } ) ; assertThat ( ResolveUtils . convertPathToPosixPath ( file . getAbsolutePath ( ) ) , StringContains . containsString ( "<STR_LIT>" ) ) ; } @ Test public void testFindFileInJarFoundWithURL ( ) throws Exception { URL urlJar = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; URLClassLoader loader = URLClassLoader . newInstance ( new URL [ ] { urlJar } , ClassLoader . getSystemClassLoader ( ) ) ; Mergeable jarMerge = mergeableResolver . getMergeableFromURL ( loader . getResource ( "<STR_LIT>" ) ) ; File file = jarMerge . find ( new FileFilter ( ) { public boolean accept ( File pathname ) { return pathname . getName ( ) . matches ( "<STR_LIT>" ) || pathname . isDirectory ( ) ; } } ) ; assertThat ( file . getName ( ) , Is . is ( "<STR_LIT>" ) ) ; } @ Test public void testRegexpMatch ( ) throws Exception { String toCheckKo = "<STR_LIT>" ; String toCheckOk = "<STR_LIT>" ; String regexp = "<STR_LIT>" ; assertThat ( toCheckKo . matches ( regexp ) , Is . is ( false ) ) ; assertThat ( toCheckOk . matches ( regexp ) , Is . is ( true ) ) ; assertThat ( "<STR_LIT>" . replaceAll ( "<STR_LIT>" , "<STR_LIT:/>" ) , Is . is ( "<STR_LIT>" ) ) ; } @ Test public void testExcludeSignatures ( ) throws IOException { File jar = File . createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) ; FileOutputStream file = new FileOutputStream ( jar ) ; JarOutputStream stream = new JarOutputStream ( file ) ; stream . putNextEntry ( new ZipEntry ( "<STR_LIT>" ) ) ; stream . closeEntry ( ) ; stream . putNextEntry ( new ZipEntry ( "<STR_LIT>" ) ) ; stream . closeEntry ( ) ; stream . putNextEntry ( new ZipEntry ( "<STR_LIT>" ) ) ; stream . closeEntry ( ) ; stream . putNextEntry ( new ZipEntry ( "<STR_LIT>" ) ) ; stream . closeEntry ( ) ; stream . putNextEntry ( new ZipEntry ( "<STR_LIT>" ) ) ; stream . closeEntry ( ) ; stream . putNextEntry ( new ZipEntry ( "<STR_LIT>" ) ) ; stream . closeEntry ( ) ; stream . close ( ) ; URL url = jar . toURI ( ) . toURL ( ) ; String jarPath = ResolveUtils . processUrlToJarPath ( url ) ; JarMerge merge = new JarMerge ( url , jarPath , new HashMap < OutputStream , List < String > > ( ) ) ; JarOutputStream output = Mockito . mock ( JarOutputStream . class ) ; merge . merge ( output ) ; ArgumentCaptor < ZipEntry > captor = ArgumentCaptor . forClass ( ZipEntry . class ) ; Mockito . verify ( output , Mockito . times ( <NUM_LIT:2> ) ) . putNextEntry ( captor . capture ( ) ) ; List < ZipEntry > allValues = captor . getAllValues ( ) ; assertEquals ( <NUM_LIT:2> , allValues . size ( ) ) ; assertEquals ( "<STR_LIT>" , allValues . get ( <NUM_LIT:0> ) . getName ( ) ) ; assertEquals ( "<STR_LIT>" , allValues . get ( <NUM_LIT:1> ) . getName ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . merge . resolve ; import static org . hamcrest . MatcherAssert . assertThat ; import static org . hamcrest . core . Is . is ; import java . net . URL ; import org . junit . Test ; public class ResolveUtilsTest { @ Test public void testConvertPathToPosixPath ( ) throws Exception { assertThat ( ResolveUtils . convertPathToPosixPath ( "<STR_LIT>" ) , is ( "<STR_LIT>" ) ) ; } @ Test public void testIsFileInJar ( ) throws Exception { URL container = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; URL resource = new URL ( container . toString ( ) + "<STR_LIT>" ) ; assertThat ( ResolveUtils . isFileInJar ( resource ) , is ( true ) ) ; resource = new URL ( container . toString ( ) + "<STR_LIT>" ) ; assertThat ( ResolveUtils . isFileInJar ( resource ) , is ( false ) ) ; } } </s>
|
<s> package com . izforge . izpack . merge . resolve ; import static org . hamcrest . MatcherAssert . assertThat ; import java . io . File ; import java . net . MalformedURLException ; import java . net . URL ; import org . junit . Before ; import org . junit . Test ; import org . junit . runner . RunWith ; import com . izforge . izpack . api . merge . Mergeable ; import com . izforge . izpack . core . container . TestMergeContainer ; import com . izforge . izpack . matcher . MergeMatcher ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . junit . PicoRunner ; import com . izforge . izpack . util . FileUtil ; @ RunWith ( PicoRunner . class ) @ Container ( TestMergeContainer . class ) public class MergeableResolverTest { private MergeableResolver mergeableResolver ; private URL resource ; public MergeableResolverTest ( MergeableResolver mergeableResolver ) { this . mergeableResolver = mergeableResolver ; } @ Before public void before ( ) throws MalformedURLException { resource = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; resource = new File ( FileUtil . convertUrlToFilePath ( resource ) + "<STR_LIT>" ) . toURI ( ) . toURL ( ) ; } @ Test public void testGetMergeableFromURL ( ) throws Exception { Mergeable mergeable = mergeableResolver . getMergeableFromURL ( resource ) ; assertThat ( mergeable , MergeMatcher . isMergeableContainingFile ( "<STR_LIT>" ) ) ; } @ Test public void testGetMergeableWithSpaces ( ) throws Exception { resource = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; resource = new File ( FileUtil . convertUrlToFilePath ( resource ) + "<STR_LIT>" ) . toURI ( ) . toURL ( ) ; Mergeable mergeable = mergeableResolver . getMergeableFromURL ( resource ) ; assertThat ( mergeable , MergeMatcher . isMergeableContainingFile ( "<STR_LIT>" ) ) ; } @ Test public void testGetMergeableFromURLWithDestination ( ) throws Exception { Mergeable jarMerge = mergeableResolver . getMergeableFromURLWithDestination ( resource , "<STR_LIT>" ) ; assertThat ( jarMerge , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . merge . resolve ; import static org . hamcrest . MatcherAssert . assertThat ; import java . io . File ; import java . net . URL ; import java . util . ArrayList ; import java . util . Collection ; import java . util . List ; import java . util . Set ; import org . hamcrest . collection . IsCollectionContaining ; import org . hamcrest . core . Is ; import org . hamcrest . core . IsNot ; import org . hamcrest . number . IsGreaterThan ; import org . hamcrest . text . StringContains ; import org . junit . Test ; import org . junit . runner . RunWith ; import com . izforge . izpack . api . merge . Mergeable ; import com . izforge . izpack . core . container . TestMergeContainer ; import com . izforge . izpack . matcher . MergeMatcher ; import com . izforge . izpack . merge . jar . JarMerge ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . junit . PicoRunner ; import com . izforge . izpack . util . FileUtil ; @ RunWith ( PicoRunner . class ) @ Container ( TestMergeContainer . class ) public class PathResolverTest { private PathResolver pathResolver ; public PathResolverTest ( PathResolver pathResolver ) { this . pathResolver = pathResolver ; } @ Test public void testGetMergeableFromJar ( ) throws Exception { List < Mergeable > jarMergeList = pathResolver . getMergeableFromPath ( "<STR_LIT>" ) ; assertThat ( jarMergeList . size ( ) , Is . is ( <NUM_LIT:1> ) ) ; Mergeable jarMerge = jarMergeList . get ( <NUM_LIT:0> ) ; assertThat ( jarMerge , Is . is ( JarMerge . class ) ) ; assertThat ( jarMerge , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void testResolvePathOfJar ( ) { Set < URL > urlList = pathResolver . resolvePath ( "<STR_LIT>" ) ; assertThat ( urlList . size ( ) , new IsGreaterThan < Integer > ( <NUM_LIT:1> ) ) ; } @ Test public void testResolvePathOfFileAndJar ( ) throws Exception { Set < URL > urlList = pathResolver . resolvePath ( "<STR_LIT>" ) ; assertThat ( getListPathFromListURL ( urlList ) , IsCollectionContaining . hasItems ( StringContains . containsString ( "<STR_LIT>" ) , IsNot . not ( StringContains . containsString ( "<STR_LIT>" ) ) ) ) ; } @ Test public void testResolvePathOfDirectory ( ) throws Exception { Collection < URL > urlList = pathResolver . resolvePath ( "<STR_LIT>" ) ; assertThat ( getListPathFromListURL ( urlList ) , IsCollectionContaining . hasItems ( IsNot . not ( StringContains . containsString ( "<STR_LIT>" ) ) ) ) ; } @ Test public void ftestGetMergeableFromFile ( ) throws Exception { List < Mergeable > mergeables = pathResolver . getMergeableFromPath ( "<STR_LIT>" ) ; Mergeable mergeable = mergeables . get ( <NUM_LIT:0> ) ; assertThat ( mergeable , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } @ Test public void testGetMergeableFromFileWithDestination ( ) throws Exception { List < Mergeable > mergeables = pathResolver . getMergeableFromPath ( "<STR_LIT>" , "<STR_LIT>" ) ; Mergeable mergeable = mergeables . get ( <NUM_LIT:0> ) ; assertThat ( mergeable , MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ; } @ Test public void testGetMergeableFromDirectory ( ) throws Exception { List < Mergeable > mergeables = pathResolver . getMergeableFromPath ( "<STR_LIT>" ) ; assertThat ( mergeables , IsCollectionContaining . hasItem ( MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ) ; } @ Test public void testGetMergeableFromDirectoryWithDestination ( ) throws Exception { List < Mergeable > mergeables = pathResolver . getMergeableFromPath ( "<STR_LIT>" , "<STR_LIT>" ) ; assertThat ( mergeables , IsCollectionContaining . hasItem ( MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ) ; } @ Test public void testGetMergeableFromPackage ( ) throws Exception { List < Mergeable > mergeables = pathResolver . getMergeableFromPackageName ( "<STR_LIT>" ) ; assertThat ( mergeables , IsCollectionContaining . hasItem ( MergeMatcher . isMergeableContainingFiles ( "<STR_LIT>" ) ) ) ; } private Collection < String > getListPathFromListURL ( Collection < URL > urlList ) { ArrayList < String > arrayList = new ArrayList < String > ( ) ; for ( URL url : urlList ) { arrayList . add ( url . getPath ( ) ) ; } return arrayList ; } @ Test public void testIsJarWithURL ( ) throws Exception { URL fileResource = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; URL jarResource = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; assertThat ( ResolveUtils . isJar ( fileResource ) , Is . is ( false ) ) ; assertThat ( ResolveUtils . isJar ( jarResource ) , Is . is ( true ) ) ; } @ Test public void testIsJarWithFile ( ) throws Exception { File fileResource = FileUtil . convertUrlToFile ( ClassLoader . getSystemResource ( "<STR_LIT>" ) ) ; File jarResource = FileUtil . convertUrlToFile ( ClassLoader . getSystemResource ( "<STR_LIT>" ) ) ; assertThat ( ResolveUtils . isJar ( fileResource ) , Is . is ( false ) ) ; assertThat ( ResolveUtils . isJar ( jarResource ) , Is . is ( true ) ) ; } @ Test public void pathResolverShouldTransformClassNameToPackagePath ( ) throws Exception { String pathFromClassName = ResolveUtils . getPanelsPackagePathFromClassName ( "<STR_LIT>" ) ; assertThat ( pathFromClassName , Is . is ( "<STR_LIT>" ) ) ; } @ Test public void pathResolverShouldReturnDefaultPackagePath ( ) throws Exception { String pathFromClassName = ResolveUtils . getPanelsPackagePathFromClassName ( "<STR_LIT>" ) ; assertThat ( pathFromClassName , Is . is ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . merge . file ; import static org . hamcrest . MatcherAssert . assertThat ; import java . io . File ; import java . io . FileFilter ; import java . io . OutputStream ; import java . net . URL ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . hamcrest . core . Is ; import org . junit . Test ; import com . izforge . izpack . matcher . MergeMatcher ; public class FileMergeTest { private Map < OutputStream , List < String > > mergeContent = new HashMap < OutputStream , List < String > > ( ) ; @ Test public void testMergeSingleFile ( ) throws Exception { FileMerge fileMerge = new FileMerge ( getClass ( ) . getResource ( "<STR_LIT>" ) , mergeContent ) ; assertThat ( fileMerge , MergeMatcher . isMergeableContainingFile ( "<STR_LIT>" ) ) ; } @ Test public void testMergeDirectory ( ) throws Exception { URL url = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; FileMerge fileMerge = new FileMerge ( url , mergeContent ) ; assertThat ( fileMerge , MergeMatcher . isMergeableContainingFile ( "<STR_LIT>" ) ) ; } @ Test public void testMergeDirectoryWithDestination ( ) throws Exception { URL url = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; FileMerge fileMerge = new FileMerge ( url , "<STR_LIT>" , mergeContent ) ; assertThat ( fileMerge , MergeMatcher . isMergeableContainingFile ( "<STR_LIT>" ) ) ; assertThat ( fileMerge , MergeMatcher . isMergeableContainingFile ( "<STR_LIT>" ) ) ; } @ Test public void testMergeFileWithDestination ( ) throws Exception { URL url = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; FileMerge fileMerge = new FileMerge ( url , "<STR_LIT>" , mergeContent ) ; assertThat ( fileMerge , MergeMatcher . isMergeableContainingFile ( "<STR_LIT>" ) ) ; } @ Test public void testMergeFileWithRootDestination ( ) throws Exception { URL url = ClassLoader . getSystemResource ( "<STR_LIT>" ) ; FileMerge fileMerge = new FileMerge ( url , "<STR_LIT>" , mergeContent ) ; assertThat ( fileMerge , MergeMatcher . isMergeableContainingFile ( "<STR_LIT>" ) ) ; } @ Test public void findFileInDirectory ( ) throws Exception { FileMerge fileMerge = new FileMerge ( ClassLoader . getSystemResource ( "<STR_LIT>" ) , mergeContent ) ; File file = fileMerge . find ( new FileFilter ( ) { public boolean accept ( File pathname ) { return pathname . getName ( ) . equals ( "<STR_LIT>" ) || pathname . isDirectory ( ) ; } } ) ; assertThat ( file . getName ( ) , Is . is ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package com . izforge . izpack . core . io ; import static org . junit . Assert . assertEquals ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import org . junit . Test ; public class ByteCountingOutputStreamTest { @ Test public void testWriting ( ) throws IOException { File temp = File . createTempFile ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) ; FileOutputStream fout = new FileOutputStream ( temp ) ; ByteCountingOutputStream out = new ByteCountingOutputStream ( fout ) ; byte [ ] data = { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> } ; out . write ( data ) ; out . write ( data , <NUM_LIT:3> , <NUM_LIT:2> ) ; out . write ( <NUM_LIT> ) ; out . close ( ) ; assertEquals ( temp . length ( ) , out . getByteCount ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . core . io ; import static org . junit . Assert . assertArrayEquals ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertTrue ; import java . io . File ; import java . io . IOException ; import java . util . Random ; import org . junit . Ignore ; import org . junit . Rule ; import org . junit . Test ; import org . junit . rules . TemporaryFolder ; public class FileSpanningStreamTest { @ Rule public TemporaryFolder temporaryFolder = new TemporaryFolder ( ) ; @ Test public void testReadWrite ( ) throws IOException { File volume = new File ( temporaryFolder . getRoot ( ) , "<STR_LIT>" ) ; String basePath = volume . getPath ( ) ; int maxSize = <NUM_LIT:32> ; FileSpanningOutputStream spanningOutputStream = new FileSpanningOutputStream ( volume , maxSize ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:1000> ; ++ i ) { assertEquals ( i , spanningOutputStream . getFilePointer ( ) ) ; spanningOutputStream . write ( i & <NUM_LIT> ) ; } spanningOutputStream . close ( ) ; int volumes = spanningOutputStream . getVolumes ( ) ; assertTrue ( volumes > <NUM_LIT:2> ) ; checkVolumes ( basePath , maxSize , volumes ) ; FileSpanningInputStream spanningInputStream = new FileSpanningInputStream ( volume , volumes ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:1000> ; ++ i ) { assertEquals ( i , spanningInputStream . getFilePointer ( ) ) ; assertEquals ( i & <NUM_LIT> , spanningInputStream . read ( ) ) ; } assertEquals ( - <NUM_LIT:1> , spanningInputStream . read ( ) ) ; spanningInputStream . close ( ) ; } @ Test public void testByteArrayReadWrite ( ) throws IOException { File volume = new File ( temporaryFolder . getRoot ( ) , "<STR_LIT>" ) ; String basePath = volume . getPath ( ) ; int maxSize = <NUM_LIT:32> ; FileSpanningOutputStream spanningOutputStream = new FileSpanningOutputStream ( volume , maxSize ) ; byte [ ] written = new byte [ <NUM_LIT> ] ; for ( int i = <NUM_LIT:0> ; i < written . length ; ++ i ) { written [ i ] = ( byte ) i ; } spanningOutputStream . write ( written ) ; assertEquals ( written . length , spanningOutputStream . getFilePointer ( ) ) ; spanningOutputStream . close ( ) ; int volumes = spanningOutputStream . getVolumes ( ) ; assertTrue ( volumes > <NUM_LIT:2> ) ; checkVolumes ( basePath , maxSize , volumes ) ; FileSpanningInputStream spanningInputStream = new FileSpanningInputStream ( volume , volumes ) ; byte [ ] read = new byte [ written . length ] ; assertEquals ( written . length , spanningInputStream . read ( read ) ) ; assertArrayEquals ( written , read ) ; assertEquals ( read . length , spanningInputStream . getFilePointer ( ) ) ; assertEquals ( - <NUM_LIT:1> , spanningInputStream . read ( read ) ) ; spanningInputStream . close ( ) ; } @ Test public void testSkip ( ) throws IOException { File volume = new File ( temporaryFolder . getRoot ( ) , "<STR_LIT>" ) ; FileSpanningOutputStream spanningOutputStream = new FileSpanningOutputStream ( volume , <NUM_LIT> ) ; byte [ ] written = new byte [ <NUM_LIT> ] ; new Random ( ) . nextBytes ( written ) ; spanningOutputStream . write ( written ) ; spanningOutputStream . close ( ) ; int volumes = spanningOutputStream . getVolumes ( ) ; FileSpanningInputStream spanningInputStream = new FileSpanningInputStream ( volume , volumes ) ; assertEquals ( <NUM_LIT:0> , spanningInputStream . getFilePointer ( ) ) ; int skip = written . length / <NUM_LIT:2> ; assertEquals ( skip , spanningInputStream . skip ( skip ) ) ; assertEquals ( skip , spanningInputStream . getFilePointer ( ) ) ; byte [ ] read = new byte [ written . length - skip ] ; assertEquals ( read . length , spanningInputStream . read ( read ) ) ; assertEquals ( written . length , spanningInputStream . getFilePointer ( ) ) ; for ( int i = <NUM_LIT:0> ; i < read . length ; ++ i ) { assertEquals ( written [ i + skip ] , read [ i ] ) ; } assertEquals ( - <NUM_LIT:1> , spanningInputStream . read ( read ) ) ; spanningInputStream . close ( ) ; } @ Ignore ( "<STR_LIT>" + "<STR_LIT>" ) @ Test public void testLargeFiles ( ) throws IOException { File volume = new File ( temporaryFolder . getRoot ( ) , "<STR_LIT>" ) ; long maxSize = FileSpanningOutputStream . DEFAULT_VOLUME_SIZE ; FileSpanningOutputStream spanningOutputStream = new FileSpanningOutputStream ( volume , maxSize ) ; byte [ ] written = new byte [ ( int ) FileSpanningOutputStream . MB ] ; int count = <NUM_LIT> ; for ( int i = <NUM_LIT:0> ; i < count ; ++ i ) { new Random ( ) . nextBytes ( written ) ; byte id = ( byte ) ( i & <NUM_LIT> ) ; written [ <NUM_LIT:0> ] = id ; written [ written . length - <NUM_LIT:1> ] = id ; System . out . println ( "<STR_LIT>" + i ) ; spanningOutputStream . write ( written ) ; } spanningOutputStream . close ( ) ; System . out . println ( "<STR_LIT>" + volume . getPath ( ) + "<STR_LIT>" + volume . length ( ) ) ; int volumes = spanningOutputStream . getVolumes ( ) ; FileSpanningInputStream spanningInputStream = new FileSpanningInputStream ( volume , volumes ) ; byte [ ] read = new byte [ written . length ] ; for ( int i = <NUM_LIT:0> ; i < count ; ++ i ) { System . out . println ( "<STR_LIT>" + i ) ; assertEquals ( written . length , spanningInputStream . read ( read ) ) ; byte id = ( byte ) ( i & <NUM_LIT> ) ; assertEquals ( id , read [ <NUM_LIT:0> ] ) ; assertEquals ( id , read [ read . length - <NUM_LIT:1> ] ) ; } assertEquals ( - <NUM_LIT:1> , spanningInputStream . read ( read ) ) ; spanningInputStream . close ( ) ; } private void checkVolumes ( String basePath , int maxSize , int volumes ) { assertTrue ( volumes > <NUM_LIT:1> ) ; for ( int i = <NUM_LIT:0> ; i < volumes ; ++ i ) { File volume = ( i == <NUM_LIT:0> ) ? new File ( basePath ) : new File ( basePath + "<STR_LIT:.>" + i ) ; assertTrue ( volume . exists ( ) ) ; if ( i != volumes - <NUM_LIT:1> ) { assertEquals ( maxSize , volume . length ( ) ) ; } } } } </s>
|
<s> package com . izforge . izpack . core . regex ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertNull ; import org . junit . Test ; import com . izforge . izpack . api . regex . RegularExpressionProcessor ; public class RegularExpressionProcessorImplTest { @ Test public void testRegexReplaceNotMatching ( ) { RegularExpressionProcessor processor = new RegularExpressionProcessorImpl ( ) ; processor . setInput ( "<STR_LIT>" ) ; processor . setRegexp ( "<STR_LIT>" ) ; processor . setReplace ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , processor . execute ( ) ) ; } @ Test public void testRegexReplaceMatching ( ) { RegularExpressionProcessor processor = new RegularExpressionProcessorImpl ( ) ; processor . setInput ( "<STR_LIT>" ) ; processor . setRegexp ( "<STR_LIT>" ) ; processor . setReplace ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , processor . execute ( ) ) ; } @ Test public void testRegexReplaceWithDefault ( ) { RegularExpressionProcessor processor = new RegularExpressionProcessorImpl ( ) ; processor . setInput ( "<STR_LIT>" ) ; processor . setRegexp ( "<STR_LIT>" ) ; processor . setReplace ( "<STR_LIT>" ) ; processor . setDefaultValue ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , processor . execute ( ) ) ; } @ Test public void testRegexSelectNotMatching ( ) { RegularExpressionProcessor processor = new RegularExpressionProcessorImpl ( ) ; processor . setInput ( "<STR_LIT>" ) ; processor . setRegexp ( "<STR_LIT>" ) ; processor . setSelect ( "<STR_LIT>" ) ; assertNull ( processor . execute ( ) ) ; } @ Test public void testRegexSelectMatching ( ) { RegularExpressionProcessor processor = new RegularExpressionProcessorImpl ( ) ; processor . setInput ( "<STR_LIT>" ) ; processor . setRegexp ( "<STR_LIT>" ) ; processor . setSelect ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , processor . execute ( ) ) ; } } </s>
|
<s> package com . izforge . izpack . core ; import java . io . File ; import java . io . FileInputStream ; import org . junit . Ignore ; import org . junit . Rule ; import org . junit . experimental . theories . DataPoints ; import org . junit . experimental . theories . Theories ; import org . junit . experimental . theories . Theory ; import org . junit . rules . ErrorCollector ; import org . junit . runner . RunWith ; import org . mockito . Mockito ; import com . izforge . izpack . api . data . LocaleDatabase ; import com . izforge . izpack . api . resource . Locales ; @ Ignore @ RunWith ( Theories . class ) public class Bin_Langpacks_InstallerTest { private final static String referencePack = "<STR_LIT>" ; private final static String basePath = "<STR_LIT:.>" + File . separator + "<STR_LIT>" + File . separator + "<STR_LIT>" + File . separator + "<STR_LIT>" + File . separator ; private static LocaleDatabase reference ; private LocaleDatabase check ; @ Rule public ErrorCollector collector = new ErrorCollector ( ) ; @ DataPoints public static String [ ] langs = { "<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>" } ; @ Theory public void testLangs ( String lang ) throws Exception { Bin_Langpacks_InstallerTest . reference = new LocaleDatabase ( new FileInputStream ( basePath + referencePack ) , Mockito . mock ( Locales . class ) ) ; this . checkLangpack ( lang ) ; } private void checkLangpack ( String langpack ) throws Exception { this . check = new LocaleDatabase ( new FileInputStream ( basePath + langpack ) , Mockito . mock ( Locales . class ) ) ; for ( String id : reference . keySet ( ) ) { if ( this . check . containsKey ( id ) ) { collector . addError ( new Throwable ( "<STR_LIT>" + id ) ) ; } } for ( String id : this . check . keySet ( ) ) { if ( reference . containsKey ( id ) ) { collector . addError ( new Throwable ( "<STR_LIT>" + id ) ) ; } } } } </s>
|
<s> package com . izforge . izpack . core . container ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . merge . MergeManager ; import com . izforge . izpack . merge . MergeManagerImpl ; import com . izforge . izpack . merge . resolve . MergeableResolver ; import com . izforge . izpack . merge . resolve . PathResolver ; public class TestMergeContainer extends AbstractContainer { public TestMergeContainer ( ) { initialise ( ) ; } @ Override protected void fillContainer ( ) { addComponent ( MergeManager . class , MergeManagerImpl . class ) ; addComponent ( PathResolver . class ) ; addComponent ( MergeableResolver . class ) ; } } </s>
|
<s> package com . izforge . izpack . core . rules ; import static junit . framework . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import java . io . ByteArrayInputStream ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; import java . io . ObjectInputStream ; import java . io . ObjectOutputStream ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . junit . Before ; import org . junit . Test ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . IXMLParser ; import com . izforge . izpack . api . adaptator . impl . XMLParser ; import com . izforge . izpack . api . data . AutomatedInstallData ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . rules . Condition ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . core . container . DefaultContainer ; import com . izforge . izpack . core . data . DefaultVariables ; 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 RulesEngineImplTest { private RulesEngine engine = null ; private static final String AIX_INSTALL = "<STR_LIT>" ; private static final String WINDOWS_INSTALL = "<STR_LIT>" ; private static final String WINDOWS_XP_INSTALL = "<STR_LIT>" ; private static final String WINDOWS_2003_INSTALL = "<STR_LIT>" ; private static final String WINDOWS_VISTA_INSTALL = "<STR_LIT>" ; private static final String WINDOWS_7_INSTALL = "<STR_LIT>" ; private static final String LINUX_INSTALL = "<STR_LIT>" ; private static final String SOLARIS_INSTALL = "<STR_LIT>" ; private static final String SOLARIS_X86_INSTALL = "<STR_LIT>" ; private static final String SOLARIS_SPARC_INSTALL = "<STR_LIT>" ; private static final String MAC_INSTALL = "<STR_LIT>" ; private static final String MAC_OSX_INSTALL = "<STR_LIT>" ; private static final String INSTALL_CONDITIONS [ ] = { AIX_INSTALL , WINDOWS_INSTALL , WINDOWS_XP_INSTALL , WINDOWS_2003_INSTALL , WINDOWS_VISTA_INSTALL , WINDOWS_7_INSTALL , LINUX_INSTALL , SOLARIS_INSTALL , SOLARIS_X86_INSTALL , SOLARIS_SPARC_INSTALL , MAC_INSTALL , MAC_OSX_INSTALL } ; @ Before public void setUp ( ) throws Exception { DefaultVariables variables = new DefaultVariables ( ) ; Platform linux = Platforms . LINUX ; engine = new RulesEngineImpl ( new AutomatedInstallData ( variables , linux ) , null , linux ) ; variables . setRules ( engine ) ; Map < String , Condition > conditions = new HashMap < String , Condition > ( ) ; Condition alwaysFalse = new JavaCondition ( ) ; conditions . put ( "<STR_LIT:false>" , alwaysFalse ) ; Condition alwaysTrue = NotCondition . createFromCondition ( alwaysFalse , engine ) ; conditions . put ( "<STR_LIT:true>" , alwaysTrue ) ; engine . readConditionMap ( conditions ) ; } @ Test @ SuppressWarnings ( "<STR_LIT>" ) public void testSimpleNot ( ) throws Exception { Condition condition ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( ! false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( ! true , condition . isTrue ( ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT>" ) public void testSimpleAnd ( ) throws Exception { Condition condition ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && true , condition . isTrue ( ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT>" ) public void testSimpleOr ( ) throws Exception { Condition condition ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false || true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true || true , condition . isTrue ( ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT>" ) public void testSimpleXor ( ) throws Exception { Condition condition ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false ^ false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false ^ true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true ^ false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true ^ true , condition . isTrue ( ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT>" ) public void testComplexNot ( ) throws Exception { Condition condition ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( ! false || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( ! true || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false || ! false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true || ! false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( ! false && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && ! false , condition . isTrue ( ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT>" ) public void testComplexAnd ( ) throws Exception { Condition condition ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false || false && false || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false || false && false || true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false || false && true || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false || false && true || true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false || true && false || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false || true && false || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false || true && false || true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false || true && true || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false || true && true || true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true || false && false || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true || false && false || true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true || false && true || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true || false && true || true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true || true && false || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true || true && false || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true || true && false || true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true || true && true || false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true || true && true || true , condition . isTrue ( ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT>" ) public void testComplexOr ( ) throws Exception { Condition condition ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && false || false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && false || false && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && false || true && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && false || true && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && true || false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && true || false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && true || false && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && true || true && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && true || true && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && false || false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && false || false && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && false || true && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && false || true && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && true || false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && true || false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && true || false && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && true || true && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && true || true && true , condition . isTrue ( ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT>" ) public void testComplexXor ( ) throws Exception { Condition condition ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && false ^ false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && false ^ false && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && false ^ true && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && false ^ true && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && true ^ false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && true ^ false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && true ^ false && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && true ^ true && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false && true ^ true && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && false ^ false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && false ^ false && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && false ^ true && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && false ^ true && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && true ^ false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && true ^ false && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && true ^ false && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && true ^ true && false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true && true ^ true && true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false ^ false && false ^ false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false ^ false && false ^ true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false ^ false && true ^ false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false ^ false && true ^ true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false ^ true && false ^ false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false ^ true && false ^ false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false ^ true && false ^ true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false ^ true && true ^ false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( false ^ true && true ^ true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true ^ false && false ^ false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true ^ false && false ^ true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true ^ false && true ^ false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true ^ false && true ^ true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true ^ true && false ^ false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true ^ true && false ^ false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true ^ true && false ^ true , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true ^ true && true ^ false , condition . isTrue ( ) ) ; condition = engine . getCondition ( "<STR_LIT>" ) ; assertEquals ( true ^ true && true ^ true , condition . isTrue ( ) ) ; } @ Test public void testReadConditionTypes ( ) { RulesEngine rules = createRulesEngine ( new AutomatedInstallData ( new DefaultVariables ( ) , Platforms . UNIX ) ) ; IXMLParser parser = new XMLParser ( ) ; IXMLElement conditions = parser . parse ( getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ) ; rules . analyzeXml ( conditions ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof AndCondition ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof NotCondition ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof OrCondition ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof XorCondition ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof VariableCondition ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof CompareNumericsCondition ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof CompareVersionsCondition ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof EmptyCondition ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof ExistsCondition ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof JavaCondition ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof PackSelectionCondition ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof RefCondition ) ; assertTrue ( rules . getCondition ( "<STR_LIT>" ) instanceof UserCondition ) ; } @ Test public void testPlatformConditions ( ) { checkPlatformCondition ( Platforms . AIX , AIX_INSTALL ) ; checkPlatformCondition ( Platforms . WINDOWS , WINDOWS_INSTALL ) ; checkPlatformCondition ( Platforms . WINDOWS_XP , WINDOWS_XP_INSTALL , WINDOWS_INSTALL ) ; checkPlatformCondition ( Platforms . WINDOWS_2003 , WINDOWS_2003_INSTALL , WINDOWS_INSTALL ) ; checkPlatformCondition ( Platforms . WINDOWS_VISTA , WINDOWS_VISTA_INSTALL , WINDOWS_INSTALL ) ; checkPlatformCondition ( Platforms . WINDOWS_7 , WINDOWS_7_INSTALL , WINDOWS_INSTALL ) ; checkPlatformCondition ( Platforms . LINUX , LINUX_INSTALL ) ; checkPlatformCondition ( Platforms . SUNOS , SOLARIS_INSTALL ) ; checkPlatformCondition ( Platforms . SUNOS_X86 , SOLARIS_X86_INSTALL , SOLARIS_INSTALL ) ; checkPlatformCondition ( Platforms . SUNOS_SPARC , SOLARIS_SPARC_INSTALL , SOLARIS_INSTALL ) ; checkPlatformCondition ( Platforms . MAC , MAC_INSTALL ) ; checkPlatformCondition ( Platforms . MAC_OSX , MAC_OSX_INSTALL , MAC_INSTALL ) ; } @ Test public void testSerialization ( ) throws Exception { InstallData installData1 = new AutomatedInstallData ( new DefaultVariables ( ) , Platforms . WINDOWS ) ; RulesEngine rules1 = createRulesEngine ( installData1 ) ; IXMLParser parser = new XMLParser ( ) ; IXMLElement conditions = parser . parse ( getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ) ; rules1 . analyzeXml ( conditions ) ; rules1 . resolveConditions ( ) ; checkConditions ( rules1 , installData1 ) ; assertTrue ( rules1 . isConditionTrue ( "<STR_LIT>" ) ) ; assertFalse ( rules1 . isConditionTrue ( "<STR_LIT>" ) ) ; Map < String , Condition > read = serializeConditions ( rules1 ) ; InstallData installData2 = new AutomatedInstallData ( new DefaultVariables ( ) , Platforms . MAC_OSX ) ; RulesEngine rules2 = createRulesEngine ( installData2 ) ; rules2 . readConditionMap ( read ) ; checkConditions ( rules2 , installData2 ) ; assertFalse ( rules2 . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules2 . isConditionTrue ( "<STR_LIT>" ) ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void testSerializeBuiltinConditions ( ) throws Exception { InstallData installData1 = new AutomatedInstallData ( new DefaultVariables ( ) , Platforms . WINDOWS_XP ) ; RulesEngine rules1 = createRulesEngine ( installData1 ) ; IXMLParser parser = new XMLParser ( ) ; IXMLElement conditions = parser . parse ( getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ) ; rules1 . analyzeXml ( conditions ) ; rules1 . resolveConditions ( ) ; assertTrue ( rules1 . isConditionTrue ( "<STR_LIT>" ) ) ; assertFalse ( rules1 . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules1 . isConditionTrue ( "<STR_LIT>" ) ) ; Map < String , Condition > read = serializeConditions ( rules1 ) ; InstallData installData2 = new AutomatedInstallData ( new DefaultVariables ( ) , Platforms . WINDOWS_7 ) ; RulesEngine rules2 = createRulesEngine ( installData2 ) ; rules2 . readConditionMap ( read ) ; assertFalse ( rules2 . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules2 . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules2 . isConditionTrue ( "<STR_LIT>" ) ) ; } private void checkConditions ( RulesEngine rules , InstallData installData ) { installData . setVariable ( "<STR_LIT>" , "<STR_LIT>" ) ; assertTrue ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertFalse ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertFalse ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertFalse ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; installData . setVariable ( "<STR_LIT>" , "<STR_LIT>" ) ; assertFalse ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertFalse ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertFalse ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; assertTrue ( rules . isConditionTrue ( "<STR_LIT>" ) ) ; } private void checkPlatformCondition ( Platform platform , String ... conditions ) { DefaultContainer parent = new DefaultContainer ( ) ; RulesEngine rules = new RulesEngineImpl ( new AutomatedInstallData ( new DefaultVariables ( ) , platform ) , new ConditionContainer ( parent ) , platform ) ; for ( String condition : conditions ) { assertTrue ( "<STR_LIT>" + condition + "<STR_LIT>" , rules . isConditionTrue ( condition ) ) ; } List < String > falseConditions = new ArrayList < String > ( Arrays . asList ( INSTALL_CONDITIONS ) ) ; falseConditions . removeAll ( Arrays . asList ( conditions ) ) ; for ( String falseCondition : falseConditions ) { assertFalse ( "<STR_LIT>" + falseCondition + "<STR_LIT>" , rules . isConditionTrue ( falseCondition ) ) ; } } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private Map < String , Condition > serializeConditions ( RulesEngine rules ) throws IOException , ClassNotFoundException { Map < String , Condition > map = new HashMap < String , Condition > ( ) ; for ( String id : rules . getKnownConditionIds ( ) ) { map . put ( id , rules . getCondition ( id ) ) ; } ByteArrayOutputStream byteOut = new ByteArrayOutputStream ( ) ; ObjectOutputStream objectOut = new ObjectOutputStream ( byteOut ) ; objectOut . writeObject ( map ) ; objectOut . close ( ) ; ByteArrayInputStream byteIn = new ByteArrayInputStream ( byteOut . toByteArray ( ) ) ; ObjectInputStream objectIn = new ObjectInputStream ( byteIn ) ; return ( Map < String , Condition > ) objectIn . readObject ( ) ; } private RulesEngine createRulesEngine ( InstallData installData ) { DefaultContainer parent = new DefaultContainer ( ) ; RulesEngine rules = new RulesEngineImpl ( installData , new ConditionContainer ( parent ) , installData . getPlatform ( ) ) ; parent . addComponent ( RulesEngine . class , rules ) ; return rules ; } } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.