text
stringlengths
30
1.67M
<s> package org . eclim . plugin . core . preference ; import java . util . Map ; import org . eclipse . core . resources . IProject ; public interface OptionHandler { public String getNature ( ) ; public Map < String , String > getValues ( ) throws Exception ; public Map < String , String > getValues ( IProject project ) throws Exception ; public void setOption ( String name , String value ) throws Exception ; public void setOption ( IProject project , String name , String value ) throws Exception ; } </s>
<s> package org . eclim . plugin . core . preference ; import org . eclim . Services ; public class RegexValidator implements Validator { private String regex ; public RegexValidator ( String regex ) { this . regex = regex ; } public boolean isValid ( Object value ) { return value != null && ( ( String ) value ) . matches ( regex ) ; } public String getMessage ( String name , Object value ) { return Services . getMessage ( "<STR_LIT>" , value , regex ) ; } } </s>
<s> package org . eclim . plugin . core . preference ; import com . google . gson . Gson ; import com . google . gson . JsonParseException ; public class JsonValidator implements Validator { private static final Gson GSON = new Gson ( ) ; private Class < ? > type ; private Validator itemValidator ; public JsonValidator ( Class < ? > type , Validator itemValidator ) { this . type = type ; this . itemValidator = itemValidator ; } @ Override public boolean isValid ( Object value ) { if ( value != null ) { try { Object result = GSON . fromJson ( ( String ) value , type ) ; if ( result != null && type . isArray ( ) && itemValidator != null ) { Object [ ] results = ( Object [ ] ) result ; for ( Object v : results ) { if ( ! itemValidator . isValid ( v ) ) { return false ; } } } } catch ( JsonParseException jpe ) { return false ; } } return true ; } @ Override public String getMessage ( String name , Object value ) { if ( value != null ) { try { Object result = GSON . fromJson ( ( String ) value , type ) ; if ( type . isArray ( ) && itemValidator != null ) { Object [ ] results = ( Object [ ] ) result ; for ( Object v : results ) { if ( ! itemValidator . isValid ( v ) ) { return itemValidator . getMessage ( name , v ) ; } } } } catch ( JsonParseException jpe ) { Throwable cause = jpe . getCause ( ) ; if ( cause != null && cause . getMessage ( ) != null ) { return cause . getMessage ( ) ; } return jpe . getMessage ( ) ; } } return null ; } } </s>
<s> package org . eclim . plugin . core . preference ; import org . eclim . Services ; public class Option implements Comparable < Option > { private static final String GENERAL = "<STR_LIT>" ; private String nature ; private String path ; private String name ; private String description ; private Validator validator ; public String getNature ( ) { return this . nature ; } public void setNature ( String nature ) { this . nature = nature ; } public String getPath ( ) { return this . path ; } public void setPath ( String path ) { this . path = path ; } public String getName ( ) { return this . name ; } public void setName ( String name ) { this . name = name ; } public String getDescription ( ) { return this . description ; } public void setDescription ( String description ) { this . description = Services . getMessage ( description ) ; } public Validator getValidator ( ) { return this . validator ; } public void setValidator ( Validator validator ) { this . validator = validator ; } public int compareTo ( Option obj ) { if ( obj == this ) { return <NUM_LIT:0> ; } int compare = <NUM_LIT:0> ; if ( this . getPath ( ) . equals ( obj . getPath ( ) ) ) { compare = <NUM_LIT:0> ; } if ( this . getPath ( ) . startsWith ( GENERAL ) && ! obj . getPath ( ) . startsWith ( GENERAL ) ) { return - <NUM_LIT:1> ; } if ( obj . getPath ( ) . startsWith ( GENERAL ) && ! this . getPath ( ) . startsWith ( GENERAL ) ) { return <NUM_LIT:1> ; } compare = this . getPath ( ) . compareTo ( obj . getPath ( ) ) ; if ( compare == <NUM_LIT:0> ) { compare = this . getName ( ) . compareTo ( obj . getName ( ) ) ; } return compare ; } } </s>
<s> package org . eclim . plugin . core . preference ; public interface Validator { public boolean isValid ( Object value ) ; public String getMessage ( String name , Object value ) ; } </s>
<s> package org . eclim . plugin . core . preference ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . apache . commons . lang . StringUtils ; public class PreferenceFactory { private static final Pattern JSON_ARRAY = Pattern . compile ( "<STR_LIT>" ) ; public static Preferences addOptions ( String nature , String optionsString ) { Preferences preferences = Preferences . getInstance ( ) ; String [ ] strings = StringUtils . split ( optionsString , '<STR_LIT:\n>' ) ; for ( int ii = <NUM_LIT:0> ; ii < strings . length ; ii ++ ) { if ( strings [ ii ] . trim ( ) . length ( ) > <NUM_LIT:0> ) { String [ ] attrs = parseOptionAttributes ( strings [ ii ] ) ; Option option = new Option ( ) ; option . setNature ( nature ) ; option . setPath ( attrs [ <NUM_LIT:0> ] ) ; option . setName ( attrs [ <NUM_LIT:1> ] ) ; if ( attrs [ <NUM_LIT:2> ] != null && ! attrs [ <NUM_LIT:2> ] . trim ( ) . equals ( StringUtils . EMPTY ) ) { option . setValidator ( new RegexValidator ( attrs [ <NUM_LIT:2> ] ) ) ; } preferences . addOption ( option ) ; } } return preferences ; } public static Preferences addPreferences ( String nature , String preferencesString ) { Preferences preferences = Preferences . getInstance ( ) ; String [ ] strings = StringUtils . split ( preferencesString , '<STR_LIT:\n>' ) ; for ( int ii = <NUM_LIT:0> ; ii < strings . length ; ii ++ ) { if ( strings [ ii ] . trim ( ) . length ( ) > <NUM_LIT:0> ) { String [ ] attrs = parsePreferenceAttributes ( strings [ ii ] ) ; Preference preference = new Preference ( ) ; preference . setNature ( nature ) ; preference . setPath ( attrs [ <NUM_LIT:0> ] ) ; preference . setName ( attrs [ <NUM_LIT:1> ] ) ; preference . setDefaultValue ( attrs [ <NUM_LIT:2> ] ) ; if ( attrs [ <NUM_LIT:3> ] != null && ! attrs [ <NUM_LIT:3> ] . trim ( ) . equals ( StringUtils . EMPTY ) ) { Matcher jsonArrayMatcher = JSON_ARRAY . matcher ( attrs [ <NUM_LIT:3> ] ) ; if ( jsonArrayMatcher . matches ( ) ) { String pattern = jsonArrayMatcher . group ( <NUM_LIT:1> ) ; preference . setValidator ( new JsonValidator ( String [ ] . class , pattern . length ( ) != <NUM_LIT:0> ? new RegexValidator ( pattern ) : null ) ) ; } else { preference . setValidator ( new RegexValidator ( attrs [ <NUM_LIT:3> ] ) ) ; } } preferences . addPreference ( preference ) ; } } return preferences ; } private static String [ ] parsePreferenceAttributes ( String attrString ) { attrString = attrString . trim ( ) ; String [ ] attrs = new String [ <NUM_LIT:4> ] ; int index = attrString . indexOf ( '<CHAR_LIT:U+0020>' ) ; attrs [ <NUM_LIT:0> ] = attrString . substring ( <NUM_LIT:0> , index ) ; attrString = attrString . substring ( index + <NUM_LIT:1> ) ; index = attrString . indexOf ( '<CHAR_LIT:U+0020>' ) ; if ( index == - <NUM_LIT:1> ) { attrs [ <NUM_LIT:1> ] = attrString ; } else { attrs [ <NUM_LIT:1> ] = attrString . substring ( <NUM_LIT:0> , index ) ; attrString = attrString . substring ( index + <NUM_LIT:1> ) ; index = attrString . indexOf ( '<CHAR_LIT:U+0020>' ) ; if ( index != - <NUM_LIT:1> ) { attrs [ <NUM_LIT:2> ] = attrString . substring ( <NUM_LIT:0> , index ) ; attrs [ <NUM_LIT:3> ] = attrString . substring ( index + <NUM_LIT:1> ) ; } else { attrs [ <NUM_LIT:2> ] = attrString ; } } return attrs ; } private static String [ ] parseOptionAttributes ( String attrString ) { attrString = attrString . trim ( ) ; String [ ] attrs = new String [ <NUM_LIT:3> ] ; int index = attrString . indexOf ( '<CHAR_LIT:U+0020>' ) ; attrs [ <NUM_LIT:0> ] = attrString . substring ( <NUM_LIT:0> , index ) ; attrString = attrString . substring ( index + <NUM_LIT:1> ) ; index = attrString . indexOf ( '<CHAR_LIT:U+0020>' ) ; if ( index != - <NUM_LIT:1> ) { attrs [ <NUM_LIT:1> ] = attrString . substring ( <NUM_LIT:0> , index ) ; attrs [ <NUM_LIT:2> ] = attrString . substring ( index + <NUM_LIT:1> ) ; } else { attrs [ <NUM_LIT:1> ] = attrString ; } return attrs ; } } </s>
<s> package org . eclim . plugin . core . preference ; public class OptionInstance extends Option { private String value ; public OptionInstance ( Option option , String value ) { this . value = value ; setPath ( option . getPath ( ) ) ; setName ( option . getName ( ) ) ; } public void setName ( String name ) { super . setName ( name ) ; super . setDescription ( name ) ; } public String getValue ( ) { return this . value ; } public void setValue ( String value ) { this . value = value ; } } </s>
<s> package org . eclim . plugin . core . preference ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Map ; import org . apache . commons . lang . ArrayUtils ; import org . eclim . Services ; import org . eclim . logging . Logger ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . ProjectScope ; import org . eclipse . core . runtime . preferences . IEclipsePreferences ; import org . eclipse . core . runtime . preferences . IScopeContext ; import org . eclipse . core . runtime . preferences . InstanceScope ; import com . google . gson . Gson ; public class Preferences { private static final Logger logger = Logger . getLogger ( Preferences . class ) ; public static final String USERNAME_PREFERENCE = "<STR_LIT>" ; public static final String USEREMAIL_PREFERENCE = "<STR_LIT>" ; public static final String PROJECT_COPYRIGHT_PREFERENCE = "<STR_LIT>" ; private static final String NODE_NAME = "<STR_LIT>" ; private static final String CORE = "<STR_LIT>" ; private static final String GLOBAL = "<STR_LIT>" ; private static Preferences instance = new Preferences ( ) ; private static Map < String , OptionHandler > optionHandlers = new HashMap < String , OptionHandler > ( ) ; private Map < String , Preference > preferences = new HashMap < String , Preference > ( ) ; private Map < String , Option > options = new HashMap < String , Option > ( ) ; private Map < String , Map < String , String > > preferenceValues = new HashMap < String , Map < String , String > > ( ) ; private Map < String , Map < String , String > > optionValues = new HashMap < String , Map < String , String > > ( ) ; private Preferences ( ) { } public static Preferences getInstance ( ) { return instance ; } public static OptionHandler addOptionHandler ( String prefix , OptionHandler handler ) { optionHandlers . put ( prefix , handler ) ; return handler ; } public void addPreference ( Preference preference ) { preferences . put ( preference . getName ( ) , preference ) ; preferenceValues . clear ( ) ; } public String [ ] getPreferenceNames ( ) { return preferences . keySet ( ) . toArray ( new String [ <NUM_LIT:0> ] ) ; } public void addOption ( Option option ) { options . put ( option . getName ( ) , option ) ; optionValues . clear ( ) ; } public String [ ] getOptionNames ( ) { return options . keySet ( ) . toArray ( new String [ <NUM_LIT:0> ] ) ; } public void clearProjectValueCache ( IProject project ) { preferenceValues . remove ( project . getName ( ) ) ; optionValues . remove ( project . getName ( ) ) ; } public Map < String , String > getValues ( ) throws Exception { return getValues ( null ) ; } public Map < String , String > getValues ( IProject project ) throws Exception { String cacheKey = project != null ? project . getName ( ) : GLOBAL ; Map < String , String > prefVals = preferenceValues . get ( cacheKey ) ; if ( prefVals == null ) { prefVals = new HashMap < String , String > ( ) ; preferenceValues . put ( cacheKey , prefVals ) ; IScopeContext context = InstanceScope . INSTANCE ; IEclipsePreferences globalPrefs = context . getNode ( NODE_NAME ) ; initializeDefaultPreferences ( globalPrefs ) ; for ( String key : globalPrefs . keys ( ) ) { prefVals . put ( key , globalPrefs . get ( key , null ) ) ; } if ( project != null ) { context = new ProjectScope ( project ) ; IEclipsePreferences projectPrefs = context . getNode ( NODE_NAME ) ; for ( String key : projectPrefs . keys ( ) ) { prefVals . put ( key , projectPrefs . get ( key , null ) ) ; } } } Map < String , String > optVals = optionValues . get ( cacheKey ) ; if ( optVals == null ) { optVals = new HashMap < String , String > ( ) ; optionValues . put ( cacheKey , optVals ) ; for ( OptionHandler handler : optionHandlers . values ( ) ) { String nature = handler . getNature ( ) ; if ( CORE . equals ( nature ) || project == null || project . getNature ( nature ) != null ) { Map < String , String > ops = project == null ? handler . getValues ( ) : handler . getValues ( project ) ; if ( ops != null ) { optVals . putAll ( ops ) ; } } } } Map < String , String > all = new HashMap < String , String > ( preferenceValues . size ( ) + optionValues . size ( ) ) ; all . putAll ( optVals ) ; all . putAll ( prefVals ) ; return all ; } public String getValue ( String name ) throws Exception { return getValues ( null ) . get ( name ) ; } public String getValue ( IProject project , String name ) throws Exception { return getValues ( project ) . get ( name ) ; } public int getIntValue ( String name ) throws Exception { return getIntValue ( null , name ) ; } public int getIntValue ( IProject project , String name ) throws Exception { String value = getValues ( project ) . get ( name ) ; return value != null ? Integer . parseInt ( value ) : - <NUM_LIT:1> ; } public String [ ] getArrayValue ( String name ) throws Exception { return getArrayValue ( null , name ) ; } public String [ ] getArrayValue ( IProject project , String name ) throws Exception { String value = getValues ( project ) . get ( name ) ; if ( value != null && value . trim ( ) . length ( ) != <NUM_LIT:0> ) { return new Gson ( ) . fromJson ( value , String [ ] . class ) ; } return ArrayUtils . EMPTY_STRING_ARRAY ; } public Option [ ] getOptions ( ) throws Exception { return getOptions ( null ) ; } public Option [ ] getOptions ( IProject project ) throws Exception { ArrayList < OptionInstance > results = new ArrayList < OptionInstance > ( ) ; Map < String , String > options = new HashMap < String , String > ( ) ; IScopeContext context = InstanceScope . INSTANCE ; IEclipsePreferences globalPrefs = context . getNode ( NODE_NAME ) ; initializeDefaultPreferences ( globalPrefs ) ; for ( String key : globalPrefs . keys ( ) ) { options . put ( key , globalPrefs . get ( key , null ) ) ; } if ( project != null ) { context = new ProjectScope ( project ) ; IEclipsePreferences projectPrefs = context . getNode ( NODE_NAME ) ; for ( String key : projectPrefs . keys ( ) ) { options . put ( key , projectPrefs . get ( key , null ) ) ; } } for ( OptionHandler handler : optionHandlers . values ( ) ) { String nature = handler . getNature ( ) ; if ( CORE . equals ( nature ) || project == null || project . getNature ( nature ) != null ) { Map < String , String > ops = project == null ? handler . getValues ( ) : handler . getValues ( project ) ; if ( ops != null ) { options . putAll ( ops ) ; } } } for ( String key : options . keySet ( ) ) { String value = options . get ( key ) ; Option option = this . options . get ( key ) ; if ( option == null ) { option = this . preferences . get ( key ) ; } if ( option != null && value != null ) { String nature = option . getNature ( ) ; if ( CORE . equals ( nature ) || project == null || project . getNature ( nature ) != null ) { OptionInstance instance = new OptionInstance ( option , value ) ; results . add ( instance ) ; } } } return results . toArray ( new Option [ results . size ( ) ] ) ; } public void setValue ( String name , String value ) throws Exception { setValue ( null , name , value ) ; } public void setValue ( IProject project , String name , String value ) throws IllegalArgumentException , Exception { if ( name . startsWith ( NODE_NAME ) ) { setPreference ( NODE_NAME , project , name , value ) ; } else { validateValue ( options . get ( name ) , name , value ) ; OptionHandler handler = null ; for ( Object k : optionHandlers . keySet ( ) ) { String key = ( String ) k ; if ( name . startsWith ( key ) ) { handler = ( OptionHandler ) optionHandlers . get ( key ) ; break ; } } if ( handler != null ) { if ( project == null ) { handler . setOption ( name , value ) ; } else { handler . setOption ( project , name , value ) ; } optionValues . clear ( ) ; } else { logger . warn ( "<STR_LIT>" , name ) ; } } } public void setPreference ( String nodeName , IProject project , String name , String value ) throws IllegalArgumentException , Exception { IScopeContext context = InstanceScope . INSTANCE ; IEclipsePreferences globalPrefs = context . getNode ( nodeName ) ; initializeDefaultPreferences ( globalPrefs ) ; Option pref = preferences . get ( name ) ; if ( pref == null ) { pref = options . get ( name ) ; } if ( project == null ) { validateValue ( pref , name , value ) ; globalPrefs . put ( name , value ) ; globalPrefs . flush ( ) ; } else { context = new ProjectScope ( project ) ; IEclipsePreferences projectPrefs = context . getNode ( nodeName ) ; if ( value . equals ( globalPrefs . get ( name , null ) ) ) { projectPrefs . remove ( name ) ; projectPrefs . flush ( ) ; } else { validateValue ( pref , name , value ) ; projectPrefs . put ( name , value ) ; projectPrefs . flush ( ) ; } } preferenceValues . clear ( ) ; } private void initializeDefaultPreferences ( IEclipsePreferences preferences ) throws Exception { String node = preferences . name ( ) ; for ( Preference preference : this . preferences . values ( ) ) { String name = preference . getName ( ) ; if ( name . startsWith ( node ) && preferences . get ( name , null ) == null ) { preferences . put ( preference . getName ( ) , preference . getDefaultValue ( ) ) ; } } preferences . flush ( ) ; } private void validateValue ( Option option , String name , String value ) throws IllegalArgumentException { if ( option != null ) { Validator validator = option . getValidator ( ) ; if ( validator == null || validator . isValid ( value ) ) { return ; } throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , name , validator . getMessage ( name , value ) ) ) ; } throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , name ) ) ; } } </s>
<s> package org . eclim . plugin . core . project ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; import org . apache . commons . lang . ArrayUtils ; import org . eclim . logging . Logger ; import org . eclipse . core . resources . IProject ; public class ProjectNatureFactory { private static final Logger logger = Logger . getLogger ( ProjectNatureFactory . class ) ; public static String NONE = "<STR_LIT:none>" ; private static Map < String , String [ ] > natureAliases = new HashMap < String , String [ ] > ( ) ; public static void addNature ( String alias , String nature ) { logger . debug ( "<STR_LIT>" , alias , nature ) ; natureAliases . put ( alias , new String [ ] { nature } ) ; } public static void addNature ( String alias , String [ ] natures ) { logger . debug ( "<STR_LIT>" , alias , Arrays . toString ( natures ) ) ; natureAliases . put ( alias , natures ) ; } public static String [ ] getNatureAliases ( ) { return natureAliases . keySet ( ) . toArray ( ArrayUtils . EMPTY_STRING_ARRAY ) ; } public static Map < String , String [ ] > getNatureAliasesMap ( ) { return Collections . unmodifiableMap ( natureAliases ) ; } public static String getNatureForAlias ( String alias ) { String [ ] natures = natureAliases . get ( alias ) ; return natures != null ? natures [ natures . length - <NUM_LIT:1> ] : null ; } public static String [ ] getNaturesForAlias ( String alias ) { return natureAliases . get ( alias ) ; } public static String getAliasForNature ( String natureId ) { for ( String key : natureAliases . keySet ( ) ) { if ( natureId . equals ( getNatureForAlias ( key ) ) ) { return key ; } } return null ; } public static String [ ] getProjectNatureAliases ( IProject project ) throws Exception { ArrayList < String > aliases = new ArrayList < String > ( ) ; for ( String key : natureAliases . keySet ( ) ) { if ( project . hasNature ( getNatureForAlias ( key ) ) ) { aliases . add ( key ) ; } } return aliases . toArray ( new String [ aliases . size ( ) ] ) ; } public static String [ ] getProjectNatures ( IProject project ) throws Exception { ArrayList < String > natures = new ArrayList < String > ( ) ; for ( String key : natureAliases . keySet ( ) ) { String [ ] ids = natureAliases . get ( key ) ; for ( String id : ids ) { if ( project . hasNature ( id ) ) { natures . add ( id ) ; } } } return natures . toArray ( new String [ natures . size ( ) ] ) ; } } </s>
<s> package org . eclim . plugin . core . project ; import java . util . List ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; public interface ProjectManager { public void create ( IProject project , CommandLine commandLine ) throws Exception ; public List < Error > update ( IProject project , CommandLine commandLine ) throws Exception ; public void delete ( IProject project , CommandLine commandLine ) throws Exception ; public void refresh ( IProject project , CommandLine commandLine ) throws Exception ; public void refresh ( IProject project , IFile file ) throws Exception ; } </s>
<s> package org . eclim . plugin . core . project ; import java . io . File ; import java . util . ArrayList ; import java . util . Collection ; import java . util . HashMap ; import java . util . List ; import java . util . Set ; import javax . xml . parsers . DocumentBuilderFactory ; import javax . xml . xpath . XPathExpression ; import org . apache . commons . lang . StringUtils ; import org . eclim . Services ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . logging . Logger ; import org . eclim . plugin . core . preference . Preferences ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . core . util . XmlUtils ; import org . eclim . util . CollectionUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IProjectDescription ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . Path ; import org . w3c . dom . Document ; public class ProjectManagement { private static final Logger logger = Logger . getLogger ( ProjectManagement . class ) ; private static HashMap < String , ProjectManager > managers = new HashMap < String , ProjectManager > ( ) ; private static XPathExpression xpath ; private static DocumentBuilderFactory factory ; public static ProjectManager addProjectManager ( String nature , ProjectManager manager ) { logger . debug ( "<STR_LIT>" , nature , manager ) ; managers . put ( nature , manager ) ; return manager ; } public static ProjectManager getProjectManager ( String nature ) { return managers . get ( nature ) ; } public static String [ ] getProjectManagerNatures ( ) { Set < String > registered = managers . keySet ( ) ; return registered . toArray ( new String [ registered . size ( ) ] ) ; } public static ProjectManager [ ] getProjectManagers ( ) { Collection < ProjectManager > registered = managers . values ( ) ; return registered . toArray ( new ProjectManager [ registered . size ( ) ] ) ; } public static void create ( String name , String folder , CommandLine commandLine ) throws Exception { String [ ] aliases = StringUtils . split ( commandLine . getValue ( Options . NATURE_OPTION ) , '<CHAR_LIT:U+002C>' ) ; ArrayList < String > natures = new ArrayList < String > ( ) ; for ( int ii = <NUM_LIT:0> ; ii < aliases . length ; ii ++ ) { if ( ! ProjectNatureFactory . NONE . equals ( aliases [ ii ] ) ) { String [ ] ids = ProjectNatureFactory . getNaturesForAlias ( aliases [ ii ] ) ; if ( ids != null ) { for ( String id : ids ) { natures . add ( id ) ; } } else { String [ ] registered = ProjectNatureFactory . getNatureAliases ( ) ; StringBuffer supported = new StringBuffer ( ) ; for ( String key : registered ) { if ( supported . length ( ) > <NUM_LIT:0> ) { supported . append ( "<STR_LIT:U+002CU+0020>" ) ; } supported . append ( key ) . append ( '<CHAR_LIT:=>' ) . append ( ProjectNatureFactory . getNatureForAlias ( key ) ) ; } throw new IllegalArgumentException ( "<STR_LIT>" + aliases [ ii ] + "<STR_LIT>" + "<STR_LIT>" + supported ) ; } } } deleteStaleProject ( name , folder ) ; IProject project = createProject ( name , folder , ( String [ ] ) natures . toArray ( new String [ natures . size ( ) ] ) ) ; project . open ( null ) ; refresh ( project , commandLine ) ; for ( int ii = <NUM_LIT:0> ; ii < natures . size ( ) ; ii ++ ) { ProjectManager manager = getProjectManager ( ( String ) natures . get ( ii ) ) ; if ( manager != null ) { manager . create ( project , commandLine ) ; } } Preferences . getInstance ( ) . clearProjectValueCache ( project ) ; } protected static IProject createProject ( String name , String folder , String [ ] natures ) throws Exception { IProject project = ProjectUtils . getProject ( name , true ) ; if ( ! project . exists ( ) ) { IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; IPath location = new Path ( folder ) ; IPath workspaceLocation = workspace . getRoot ( ) . getRawLocation ( ) ; if ( location . toOSString ( ) . toLowerCase ( ) . startsWith ( workspaceLocation . toOSString ( ) . toLowerCase ( ) ) ) { IPath tmpLocation = location . removeFirstSegments ( location . matchingFirstSegments ( workspaceLocation ) ) ; if ( tmpLocation . segmentCount ( ) > <NUM_LIT:1> ) { throw new RuntimeException ( Services . getMessage ( "<STR_LIT>" ) ) ; } String tmpName = tmpLocation . toString ( ) ; tmpName = tmpName . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; project = ProjectUtils . getProject ( tmpName , true ) ; if ( ! project . exists ( ) ) { IProjectDescription description = workspace . newProjectDescription ( tmpName ) ; description . setNatureIds ( natures ) ; project . create ( description , null ) ; } } else { IProjectDescription description = workspace . newProjectDescription ( name ) ; description . setLocation ( location ) ; description . setNatureIds ( natures ) ; project . create ( description , null ) ; } } else { IProjectDescription desc = project . getDescription ( ) ; String [ ] natureIds = desc . getNatureIds ( ) ; ArrayList < String > modified = new ArrayList < String > ( ) ; ArrayList < String > newNatures = new ArrayList < String > ( ) ; CollectionUtils . addAll ( modified , natureIds ) ; for ( String natureId : natures ) { if ( ! modified . contains ( natureId ) ) { modified . add ( natureId ) ; newNatures . add ( natureId ) ; } } desc . setNatureIds ( ( String [ ] ) modified . toArray ( new String [ modified . size ( ) ] ) ) ; project . setDescription ( desc , new NullProgressMonitor ( ) ) ; } return project ; } protected static void deleteStaleProject ( String name , String folder ) throws Exception { File projectFile = new File ( folder + File . separator + "<STR_LIT>" ) ; if ( projectFile . exists ( ) ) { if ( xpath == null ) { xpath = XmlUtils . createXPathExpression ( "<STR_LIT>" ) ; factory = DocumentBuilderFactory . newInstance ( ) ; } Document document = factory . newDocumentBuilder ( ) . parse ( projectFile ) ; String projectName = ( String ) xpath . evaluate ( document ) ; if ( ! projectName . equals ( name ) ) { IProject project = ProjectUtils . getProject ( projectName ) ; if ( project . exists ( ) ) { project . delete ( false , true , null ) ; } else { projectFile . delete ( ) ; } } } } public static List < Error > update ( IProject project , CommandLine commandLine ) throws Exception { ProjectUtils . assertExists ( project ) ; ArrayList < Error > errors = new ArrayList < Error > ( ) ; for ( String nature : managers . keySet ( ) ) { if ( project . hasNature ( nature ) ) { ProjectManager manager = ProjectManagement . getProjectManager ( nature ) ; List < Error > errs = manager . update ( project , commandLine ) ; if ( errs != null ) { errors . addAll ( errs ) ; } } } return errors ; } public static void delete ( IProject project , CommandLine commandLine ) throws Exception { ProjectUtils . assertExists ( project ) ; try { if ( ! project . isOpen ( ) ) { project . open ( null ) ; } Preferences . getInstance ( ) . clearProjectValueCache ( project ) ; for ( String nature : managers . keySet ( ) ) { if ( project . hasNature ( nature ) ) { ProjectManager manager = ProjectManagement . getProjectManager ( nature ) ; manager . delete ( project , commandLine ) ; } } } catch ( Exception e ) { logger . debug ( "<STR_LIT>" , e ) ; } finally { project . delete ( false , true , null ) ; } } public static void refresh ( IProject project , CommandLine commandLine ) throws Exception { ProjectUtils . assertExists ( project ) ; project . refreshLocal ( IResource . DEPTH_INFINITE , null ) ; for ( String nature : managers . keySet ( ) ) { if ( project . hasNature ( nature ) ) { ProjectManager manager = ProjectManagement . getProjectManager ( nature ) ; manager . refresh ( project , commandLine ) ; } } Preferences . getInstance ( ) . clearProjectValueCache ( project ) ; } } </s>
<s> package org . eclim . plugin . core . command . complete ; import java . util . ArrayList ; import org . apache . commons . lang . StringUtils ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . eclipse . jface . text . DummyTextViewer ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . command . complete . CodeCompleteResult ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . jface . text . ITextViewer ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . eclipse . jface . text . contentassist . IContentAssistProcessor ; public abstract class AbstractCodeCompleteCommand extends AbstractCommand { private static String COMPACT = "<STR_LIT>" ; @ Override public Object execute ( final CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; int offset = getOffset ( commandLine ) ; ICompletionProposal [ ] proposals = getCompletionProposals ( commandLine , project , file , offset ) ; ArrayList < CodeCompleteResult > results = new ArrayList < CodeCompleteResult > ( ) ; if ( proposals != null ) { for ( ICompletionProposal proposal : proposals ) { if ( acceptProposal ( proposal ) ) { CodeCompleteResult ccresult = createCodeCompletionResult ( proposal ) ; if ( ! results . contains ( ccresult ) ) { results . add ( ccresult ) ; } } } } String layout = commandLine . getValue ( Options . LAYOUT_OPTION ) ; if ( COMPACT . equals ( layout ) && results . size ( ) > <NUM_LIT:0> ) { results = compact ( results ) ; } return results ; } protected CodeCompleteResult createCodeCompletionResult ( ICompletionProposal proposal ) { return new CodeCompleteResult ( getCompletion ( proposal ) , getMenu ( proposal ) , getInfo ( proposal ) ) ; } protected ICompletionProposal [ ] getCompletionProposals ( CommandLine commandLine , String project , String file , int offset ) throws Exception { IContentAssistProcessor processor = getContentAssistProcessor ( commandLine , project , file ) ; ITextViewer viewer = getTextViewer ( commandLine , project , file ) ; if ( processor != null && viewer != null ) { return processor . computeCompletionProposals ( viewer , offset ) ; } return new ICompletionProposal [ <NUM_LIT:0> ] ; } protected IContentAssistProcessor getContentAssistProcessor ( CommandLine commandLine , String project , String file ) throws Exception { throw new UnsupportedOperationException ( ) ; } protected ITextViewer getTextViewer ( CommandLine commandLine , String project , String file ) throws Exception { int offset = getOffset ( commandLine ) ; return new DummyTextViewer ( ProjectUtils . getDocument ( project , file ) , offset , <NUM_LIT:1> ) ; } protected boolean acceptProposal ( ICompletionProposal proposal ) { return true ; } protected String getCompletion ( ICompletionProposal proposal ) { return proposal . getDisplayString ( ) ; } protected String getMenu ( ICompletionProposal proposal ) { return StringUtils . EMPTY ; } protected String getInfo ( ICompletionProposal proposal ) { String info = proposal . getAdditionalProposalInfo ( ) ; if ( info != null ) { info = info . trim ( ) ; } else { info = StringUtils . EMPTY ; } return info ; } protected ArrayList < CodeCompleteResult > compact ( ArrayList < CodeCompleteResult > results ) { ArrayList < CodeCompleteResult > compactResults = new ArrayList < CodeCompleteResult > ( ) ; CodeCompleteResult first = results . get ( <NUM_LIT:0> ) ; String lastWord = first . getCompletion ( ) ; String lastType = first . getType ( ) ; ArrayList < CodeCompleteResult > overloaded = new ArrayList < CodeCompleteResult > ( ) ; for ( CodeCompleteResult result : results ) { if ( ! result . getCompletion ( ) . equals ( lastWord ) || ! result . getType ( ) . equals ( lastType ) ) { compactResults . add ( compactOverloaded ( overloaded ) ) ; overloaded . clear ( ) ; } overloaded . add ( result ) ; lastWord = result . getCompletion ( ) ; lastType = result . getType ( ) ; } if ( overloaded . size ( ) > <NUM_LIT:0> ) { compactResults . add ( compactOverloaded ( overloaded ) ) ; } return compactResults ; } private CodeCompleteResult compactOverloaded ( ArrayList < CodeCompleteResult > overloaded ) { CodeCompleteResult r = overloaded . get ( <NUM_LIT:0> ) ; if ( overloaded . size ( ) == <NUM_LIT:1> ) { return r ; } StringBuffer info = new StringBuffer ( ) ; for ( CodeCompleteResult o : overloaded ) { if ( info . length ( ) > <NUM_LIT:0> ) { info . append ( "<STR_LIT>" ) ; } info . append ( o . getMenu ( ) ) ; } return new CodeCompleteResult ( r . getCompletion ( ) , "<STR_LIT>" , info . toString ( ) , r . getType ( ) ) ; } } </s>
<s> package org . eclim . plugin . core . command . complete ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . apache . commons . lang . StringUtils ; import org . apache . commons . lang . builder . EqualsBuilder ; import org . apache . commons . lang . builder . HashCodeBuilder ; public class CodeCompleteResult { private static final Pattern FIRST_LINE = Pattern . compile ( "<STR_LIT>" ) ; private static final int MAX_SHORT_DESCRIPTION_LENGTH = <NUM_LIT> ; public static final String VARIABLE = "<STR_LIT>" ; public static final String FUNCTION = "<STR_LIT:f>" ; public static final String TYPE = "<STR_LIT:t>" ; public static final String KEYWORD = "<STR_LIT>" ; private String completion ; private String menu ; private String info ; private String type ; public CodeCompleteResult ( String completion , String menu , String info ) { this ( completion , menu , info , StringUtils . EMPTY ) ; } public CodeCompleteResult ( String completion , String menu , String info , String type ) { this . completion = completion ; this . menu = menu ; this . info = info ; this . type = type != null ? type : StringUtils . EMPTY ; if ( this . info != null ) { this . info = StringUtils . replace ( this . info , "<STR_LIT:n>" , "<STR_LIT>" ) ; } if ( this . menu != null ) { this . menu = StringUtils . replace ( this . menu , "<STR_LIT:n>" , "<STR_LIT>" ) ; } if ( this . info != null && this . menu == null ) { this . menu = menuFromInfo ( this . info ) ; } } public String getCompletion ( ) { return completion ; } public String getInfo ( ) { return info ; } public String getMenu ( ) { return menu ; } public String getType ( ) { return this . type ; } public static String menuFromInfo ( String info ) { if ( info == null ) { return null ; } String menu = info ; Matcher matcher = FIRST_LINE . matcher ( menu ) ; if ( menu . length ( ) > <NUM_LIT:1> && matcher . find ( <NUM_LIT:1> ) ) { menu = menu . substring ( <NUM_LIT:0> , matcher . start ( ) + <NUM_LIT:1> ) ; if ( menu . endsWith ( "<STR_LIT:<>" ) ) { menu = menu . substring ( <NUM_LIT:0> , menu . length ( ) - <NUM_LIT:1> ) ; } } menu = menu . replaceAll ( "<STR_LIT:n>" , StringUtils . EMPTY ) ; menu = menu . replaceAll ( "<STR_LIT>" , StringUtils . EMPTY ) ; return StringUtils . abbreviate ( menu , MAX_SHORT_DESCRIPTION_LENGTH ) ; } public boolean equals ( Object other ) { if ( ! ( other instanceof CodeCompleteResult ) ) { return false ; } if ( this == other ) { return true ; } CodeCompleteResult result = ( CodeCompleteResult ) other ; boolean equal = new EqualsBuilder ( ) . append ( getCompletion ( ) , result . getCompletion ( ) ) . append ( getMenu ( ) , result . getMenu ( ) ) . append ( getType ( ) , result . getType ( ) ) . isEquals ( ) ; return equal ; } public int hashCode ( ) { return new HashCodeBuilder ( <NUM_LIT> , <NUM_LIT> ) . append ( completion ) . append ( menu ) . toHashCode ( ) ; } } </s>
<s> package org . eclim . plugin . core . command ; import java . util . Arrays ; import org . eclim . command . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . logging . Logger ; import org . eclim . plugin . core . preference . Preferences ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . file . FileUtils ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IProject ; import com . martiansoftware . nailgun . NGContext ; public abstract class AbstractCommand implements Command { private static final Logger logger = Logger . getLogger ( AbstractCommand . class ) ; private NGContext context ; public Preferences getPreferences ( ) { return Preferences . getInstance ( ) ; } public int getOffset ( CommandLine commandLine ) throws Exception { return getOffset ( commandLine , Options . OFFSET_OPTION ) ; } public int getOffset ( CommandLine commandLine , String option ) throws Exception { int offset = commandLine . getIntValue ( option ) ; if ( offset == - <NUM_LIT:1> ) { return offset ; } String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; if ( project == null ) { project = commandLine . getValue ( Options . NAME_OPTION ) ; } String file = commandLine . getValue ( Options . FILE_OPTION ) ; String encoding = commandLine . getValue ( Options . ENCODING_OPTION ) ; file = ProjectUtils . getFilePath ( project , file ) ; return FileUtils . byteOffsetToCharOffset ( file , offset , encoding ) ; } public NGContext getContext ( ) { return context ; } public void setContext ( NGContext context ) { this . context = context ; } public void cleanup ( CommandLine commandLine ) { try { if ( commandLine . hasOption ( Options . FILE_OPTION ) && ( commandLine . hasOption ( Options . PROJECT_OPTION ) || commandLine . hasOption ( Options . NAME_OPTION ) ) ) { IProject project = null ; String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; if ( projectName == null ) { projectName = commandLine . getValue ( Options . NAME_OPTION ) ; project = ProjectUtils . getProject ( projectName ) ; } else { try { project = ProjectUtils . getProject ( projectName ) ; if ( ! project . exists ( ) ) { project = null ; } } catch ( IllegalArgumentException iae ) { } if ( project == null ) { projectName = commandLine . getValue ( Options . NAME_OPTION ) ; project = ProjectUtils . getProject ( projectName ) ; } } String file = commandLine . getValue ( Options . FILE_OPTION ) ; if ( project != null && project . exists ( ) && file != null ) { IFile temp = ProjectUtils . getFile ( project , file ) ; if ( temp . exists ( ) && temp . getName ( ) . startsWith ( "<STR_LIT>" ) ) { temp . delete ( true , false , null ) ; } } } } catch ( Exception e ) { logger . error ( "<STR_LIT>" + Arrays . toString ( context . getArgs ( ) ) , e ) ; } } public void println ( ) { context . out . println ( ) ; } public void println ( boolean x ) { context . out . println ( x ) ; } public void println ( char x ) { context . out . println ( x ) ; } public void println ( char [ ] x ) { context . out . println ( x ) ; } public void println ( double x ) { context . out . println ( x ) ; } public void println ( float x ) { context . out . println ( x ) ; } public void println ( int x ) { context . out . println ( x ) ; } public void println ( long x ) { context . out . println ( x ) ; } public void println ( Object x ) { context . out . println ( x ) ; } public void println ( String x ) { context . out . println ( x ) ; } } </s>
<s> package org . eclim . plugin . core . command . admin ; import java . util . HashMap ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . plugin . PluginResources ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclipse . core . runtime . Platform ; import org . osgi . framework . Bundle ; @ Command ( name = "<STR_LIT>" ) public class PingCommand extends AbstractCommand { private HashMap < String , String > versions ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { if ( versions == null ) { PluginResources resources = Services . getPluginResources ( "<STR_LIT>" ) ; versions = new HashMap < String , String > ( ) ; versions . put ( "<STR_LIT>" , resources . getProperty ( "<STR_LIT>" ) ) ; versions . put ( "<STR_LIT>" , getVersion ( ) ) ; } return versions ; } private String getVersion ( ) { Bundle bundle = Platform . getBundle ( "<STR_LIT>" ) ; if ( bundle != null ) { String eclipse_version = ( String ) bundle . getHeaders ( ) . get ( "<STR_LIT>" ) ; if ( eclipse_version != null ) { eclipse_version = eclipse_version . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; return eclipse_version . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; } } return null ; } } </s>
<s> package org . eclim . plugin . core . command . admin ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class SettingCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String setting = commandLine . getValue ( Options . SETTING_OPTION ) ; return getPreferences ( ) . getValue ( setting ) ; } } </s>
<s> package org . eclim . plugin . core . command . admin ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . eclipse . EclimApplication ; import org . eclim . eclipse . EclimDaemon ; import org . eclim . logging . Logger ; import org . eclim . plugin . core . command . AbstractCommand ; @ Command ( name = "<STR_LIT>" ) public class ShutdownCommand extends AbstractCommand { private static final Logger logger = Logger . getLogger ( ShutdownCommand . class ) ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { try { EclimDaemon . getInstance ( ) . stop ( ) ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } if ( EclimApplication . isEnabled ( ) ) { EclimApplication . shutdown ( ) ; } return null ; } } </s>
<s> package org . eclim . plugin . core . command . admin ; import java . util . Arrays ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . preference . Option ; @ Command ( name = "<STR_LIT>" ) public class SettingsCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { Option [ ] options = getPreferences ( ) . getOptions ( ) ; Arrays . sort ( options ) ; return options ; } } </s>
<s> package org . eclim . plugin . core . command . admin ; import java . io . File ; import java . io . FileReader ; import java . util . ArrayList ; import java . util . Map ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . logging . Logger ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . preference . Preferences ; import org . eclim . util . IOUtils ; import com . google . gson . JsonElement ; import com . google . gson . JsonObject ; import com . google . gson . JsonStreamParser ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class SettingsUpdateCommand extends AbstractCommand { private static final Logger logger = Logger . getLogger ( SettingsUpdateCommand . class ) ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { String settings = commandLine . getValue ( Options . SETTINGS_OPTION ) ; FileReader in = null ; File file = new File ( settings ) ; ArrayList < String > errors = new ArrayList < String > ( ) ; try { in = new FileReader ( file ) ; JsonStreamParser parser = new JsonStreamParser ( in ) ; JsonObject obj = ( JsonObject ) parser . next ( ) ; Preferences preferences = getPreferences ( ) ; for ( Map . Entry < String , JsonElement > entry : obj . entrySet ( ) ) { String name = entry . getKey ( ) ; String value = entry . getValue ( ) . getAsString ( ) ; try { preferences . setValue ( name , value ) ; } catch ( IllegalArgumentException iae ) { errors . add ( iae . getMessage ( ) ) ; } } } finally { IOUtils . closeQuietly ( in ) ; try { file . delete ( ) ; } catch ( Exception e ) { logger . warn ( "<STR_LIT>" + file , e ) ; } } if ( errors . size ( ) > <NUM_LIT:0> ) { return errors ; } return Services . getMessage ( "<STR_LIT>" ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . io . File ; import java . io . FileReader ; import java . util . ArrayList ; import java . util . List ; import java . util . Map ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . logging . Logger ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . preference . Preferences ; import org . eclim . plugin . core . project . ProjectManagement ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . IOUtils ; import org . eclipse . core . resources . IProject ; import com . google . gson . JsonElement ; import com . google . gson . JsonObject ; import com . google . gson . JsonStreamParser ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class ProjectUpdateCommand extends AbstractCommand { private static final Logger logger = Logger . getLogger ( ProjectUpdateCommand . class ) ; public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; String settings = commandLine . getValue ( Options . SETTINGS_OPTION ) ; IProject project = ProjectUtils . getProject ( name ) ; if ( settings != null ) { List < String > errors = updateSettings ( project , settings ) ; if ( errors . size ( ) > <NUM_LIT:0> ) { return errors ; } } else { List < Error > errors = ProjectManagement . update ( project , commandLine ) ; if ( errors . size ( ) > <NUM_LIT:0> ) { return errors ; } } return Services . getMessage ( "<STR_LIT>" , name ) ; } private List < String > updateSettings ( IProject project , String settings ) throws Exception { FileReader in = null ; File file = new File ( settings ) ; ArrayList < String > errors = new ArrayList < String > ( ) ; try { in = new FileReader ( file ) ; JsonStreamParser parser = new JsonStreamParser ( in ) ; JsonObject obj = ( JsonObject ) parser . next ( ) ; Preferences preferences = getPreferences ( ) ; for ( Map . Entry < String , JsonElement > entry : obj . entrySet ( ) ) { String name = entry . getKey ( ) ; String value = entry . getValue ( ) . getAsString ( ) ; try { preferences . setValue ( project , name , value ) ; } catch ( IllegalArgumentException iae ) { errors . add ( iae . getMessage ( ) ) ; } } } finally { IOUtils . closeQuietly ( in ) ; try { file . delete ( ) ; } catch ( Exception e ) { logger . warn ( "<STR_LIT>" + file , e ) ; } } return errors ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . util . ArrayList ; import org . apache . commons . lang . StringUtils ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . project . ProjectManagement ; import org . eclim . plugin . core . project . ProjectManager ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . CollectionUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IProjectDescription ; import org . eclipse . core . runtime . NullProgressMonitor ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class ProjectNatureRemoveCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( name ) ; String [ ] aliases = StringUtils . split ( commandLine . getValue ( Options . NATURE_OPTION ) , '<CHAR_LIT:U+002C>' ) ; IProjectDescription desc = project . getDescription ( ) ; String [ ] natureIds = desc . getNatureIds ( ) ; ArrayList < String > modified = new ArrayList < String > ( ) ; ArrayList < String > removed = new ArrayList < String > ( ) ; CollectionUtils . addAll ( modified , natureIds ) ; for ( String alias : aliases ) { String natureId = ProjectNatureFactory . getNatureForAlias ( alias ) ; if ( natureId != null && modified . contains ( natureId ) ) { modified . remove ( natureId ) ; removed . add ( natureId ) ; } } desc . setNatureIds ( ( String [ ] ) modified . toArray ( new String [ modified . size ( ) ] ) ) ; project . setDescription ( desc , new NullProgressMonitor ( ) ) ; for ( String nature : removed ) { ProjectManager manager = ProjectManagement . getProjectManager ( nature ) ; if ( manager != null ) { manager . delete ( project , commandLine ) ; } } return Services . getMessage ( "<STR_LIT>" ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . util . HashMap ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . ResourcesPlugin ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectInfoCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( name ) ; if ( project . exists ( ) ) { String workspace = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getRawLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; HashMap < String , Object > info = new HashMap < String , Object > ( ) ; info . put ( "<STR_LIT:name>" , name ) ; info . put ( "<STR_LIT:path>" , ProjectUtils . getPath ( project ) ) ; info . put ( "<STR_LIT>" , workspace ) ; info . put ( "<STR_LIT>" , project . isOpen ( ) ) ; if ( project . isOpen ( ) ) { String [ ] aliases = ProjectNatureFactory . getProjectNatureAliases ( project ) ; if ( aliases . length == <NUM_LIT:0> ) { aliases = new String [ ] { "<STR_LIT:none>" } ; } info . put ( "<STR_LIT>" , aliases ) ; IProject [ ] depends = project . getReferencedProjects ( ) ; if ( depends . length > <NUM_LIT:0> ) { String [ ] names = new String [ depends . length ] ; for ( int ii = <NUM_LIT:0> ; ii < depends . length ; ii ++ ) { names [ ii ] = depends [ ii ] . getName ( ) ; } info . put ( "<STR_LIT>" , names ) ; } IProject [ ] references = project . getReferencingProjects ( ) ; if ( references . length > <NUM_LIT:0> ) { String [ ] names = new String [ references . length ] ; for ( int ii = <NUM_LIT:0> ; ii < references . length ; ii ++ ) { names [ ii ] = references [ ii ] . getName ( ) ; } info . put ( "<STR_LIT>" , names ) ; } } return info ; } return Services . getMessage ( "<STR_LIT>" , name ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . project . ProjectNatureFactory ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectNatureAliasesCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { if ( commandLine . hasOption ( "<STR_LIT:m>" ) ) { return ProjectNatureFactory . getNatureAliasesMap ( ) ; } return ProjectNatureFactory . getNatureAliases ( ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectCloseCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( name ) ; if ( project . exists ( ) ) { project . close ( null ) ; return Services . getMessage ( "<STR_LIT>" , name ) ; } return Services . getMessage ( "<STR_LIT>" , name ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . util . ArrayList ; import java . util . HashMap ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . ResourcesPlugin ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectListCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { IProject [ ] projects = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProjects ( ) ; String natureId = null ; if ( commandLine . hasOption ( Options . NATURE_OPTION ) ) { String alias = commandLine . getValue ( Options . NATURE_OPTION ) ; natureId = ProjectNatureFactory . getNatureForAlias ( alias ) ; ArrayList < IProject > filtered = new ArrayList < IProject > ( ) ; for ( IProject project : projects ) { if ( project . isOpen ( ) && project . hasNature ( natureId ) ) { filtered . add ( project ) ; } } projects = ( IProject [ ] ) filtered . toArray ( new IProject [ filtered . size ( ) ] ) ; } ArrayList < HashMap < String , Object > > results = new ArrayList < HashMap < String , Object > > ( ) ; for ( IProject project : projects ) { if ( project . exists ( ) ) { HashMap < String , Object > result = new HashMap < String , Object > ( ) ; result . put ( "<STR_LIT:name>" , project . getName ( ) ) ; result . put ( "<STR_LIT:path>" , ProjectUtils . getPath ( project ) ) ; result . put ( "<STR_LIT>" , project . isOpen ( ) ) ; results . add ( result ) ; } } return results ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . io . File ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IProjectDescription ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . IPath ; import org . eclipse . core . runtime . Path ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class ProjectMoveCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String newDir = commandLine . getValue ( Options . DIR_OPTION ) ; if ( new File ( newDir ) . exists ( ) ) { newDir = newDir + '<CHAR_LIT:/>' + projectName ; } IProject project = ProjectUtils . getProject ( projectName ) ; if ( project . exists ( ) ) { IProjectDescription desc = project . getDescription ( ) ; IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; IPath workspaceLocation = workspace . getRoot ( ) . getRawLocation ( ) ; IPath location = new Path ( newDir ) ; if ( location . toOSString ( ) . toLowerCase ( ) . startsWith ( workspaceLocation . toOSString ( ) . toLowerCase ( ) ) ) { String name = location . removeFirstSegments ( location . matchingFirstSegments ( workspaceLocation ) ) . toString ( ) ; name = name . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; name = name . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; location = null ; desc . setName ( name ) ; } desc . setLocation ( location ) ; project . move ( desc , true , null ) ; project = ProjectUtils . getProject ( desc . getName ( ) ) ; return Services . getMessage ( "<STR_LIT>" , projectName , ProjectUtils . getPath ( project ) ) ; } return Services . getMessage ( "<STR_LIT>" , projectName ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . util . ArrayList ; import org . apache . commons . lang . StringUtils ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . project . ProjectManagement ; import org . eclim . plugin . core . project . ProjectManager ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . CollectionUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IProjectDescription ; import org . eclipse . core . runtime . NullProgressMonitor ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class ProjectNatureAddCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( name ) ; String [ ] aliases = StringUtils . split ( commandLine . getValue ( Options . NATURE_OPTION ) , '<CHAR_LIT:U+002C>' ) ; IProjectDescription desc = project . getDescription ( ) ; String [ ] natureIds = desc . getNatureIds ( ) ; ArrayList < String > modified = new ArrayList < String > ( ) ; ArrayList < String > newNatures = new ArrayList < String > ( ) ; CollectionUtils . addAll ( modified , natureIds ) ; for ( String alias : aliases ) { String natureId = ProjectNatureFactory . getNatureForAlias ( alias ) ; if ( natureId != null && ! modified . contains ( natureId ) ) { modified . add ( natureId ) ; newNatures . add ( natureId ) ; } } desc . setNatureIds ( ( String [ ] ) modified . toArray ( new String [ modified . size ( ) ] ) ) ; project . setDescription ( desc , new NullProgressMonitor ( ) ) ; for ( String nature : newNatures ) { ProjectManager manager = ProjectManagement . getProjectManager ( nature ) ; if ( manager != null ) { manager . create ( project , commandLine ) ; } } return Services . getMessage ( "<STR_LIT>" ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class ProjectRefreshFileCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; String filename = commandLine . getValue ( Options . FILE_OPTION ) ; ProjectUtils . getFile ( name , filename ) ; return null ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . net . URI ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . ResourcesPlugin ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectLinkResource extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String file = commandLine . getValue ( Options . FILE_OPTION ) ; URI uri = new URI ( "<STR_LIT>" + file . replaceAll ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) ) ; IFile [ ] files = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . findFilesForLocationURI ( uri ) ; if ( files . length > <NUM_LIT:0> ) { return files [ <NUM_LIT:0> ] . getProjectRelativePath ( ) . toString ( ) ; } return null ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . io . File ; import java . lang . reflect . Constructor ; import java . lang . reflect . Field ; import java . lang . reflect . Method ; import java . util . ArrayList ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . ui . internal . wizards . datatransfer . WizardProjectsImportPage ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectImportCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String folder = commandLine . getValue ( Options . FOLDER_OPTION ) ; if ( folder . endsWith ( "<STR_LIT:/>" ) || folder . endsWith ( "<STR_LIT:\\>" ) ) { folder = folder . substring ( <NUM_LIT:0> , folder . length ( ) - <NUM_LIT:1> ) ; } if ( ! new File ( folder ) . exists ( ) ) { return Services . getMessage ( "<STR_LIT>" , folder ) ; } File dotproject = new File ( folder + "<STR_LIT>" ) ; if ( ! dotproject . exists ( ) ) { return Services . getMessage ( "<STR_LIT>" , folder ) ; } WizardProjectsImportPage page = new WizardProjectsImportPage ( ) ; Constructor < WizardProjectsImportPage . ProjectRecord > construct = WizardProjectsImportPage . ProjectRecord . class . getDeclaredConstructor ( WizardProjectsImportPage . class , File . class ) ; construct . setAccessible ( true ) ; WizardProjectsImportPage . ProjectRecord record = construct . newInstance ( page , dotproject ) ; String projectName = record . getProjectName ( ) ; IProject project = ProjectUtils . getProject ( projectName ) ; if ( project . exists ( ) ) { return Services . getMessage ( "<STR_LIT>" , projectName , folder ) ; } Field field = page . getClass ( ) . getDeclaredField ( "<STR_LIT>" ) ; field . setAccessible ( true ) ; field . set ( page , new ArrayList < IProject > ( ) ) ; Method method = page . getClass ( ) . getDeclaredMethod ( "<STR_LIT>" , WizardProjectsImportPage . ProjectRecord . class , IProgressMonitor . class ) ; method . setAccessible ( true ) ; Boolean result = ( Boolean ) method . invoke ( page , record , new NullProgressMonitor ( ) ) ; if ( ! result . booleanValue ( ) ) { return Services . getMessage ( "<STR_LIT>" , projectName ) ; } return Services . getMessage ( "<STR_LIT>" , projectName ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectOpenCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( name ) ; if ( project . exists ( ) ) { project . open ( null ) ; return Services . getMessage ( "<STR_LIT>" , name ) ; } return Services . getMessage ( "<STR_LIT>" , name ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . project . ProjectManagement ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectDeleteCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( name ) ; if ( ! project . exists ( ) ) { return Services . getMessage ( "<STR_LIT>" , name ) ; } ProjectManagement . delete ( project , commandLine ) ; return Services . getMessage ( "<STR_LIT>" , name ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . util . Arrays ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . preference . Option ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectSettingsCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( name , true ) ; Option [ ] options = getPreferences ( ) . getOptions ( project ) ; Arrays . sort ( options ) ; return options ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . net . URI ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . ResourcesPlugin ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectByResource extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String file = commandLine . getValue ( Options . FILE_OPTION ) ; URI uri = new URI ( "<STR_LIT>" + file . replaceAll ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) ) ; IFile [ ] files = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . findFilesForLocationURI ( uri ) ; if ( files . length > <NUM_LIT:0> ) { return files [ <NUM_LIT:0> ] . getProject ( ) . getName ( ) ; } return null ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IProjectDescription ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class ProjectRenameCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; String newName = commandLine . getValue ( Options . NAME_OPTION ) ; newName = newName . replace ( '<CHAR_LIT:U+0020>' , '<CHAR_LIT:_>' ) ; IProject project = ProjectUtils . getProject ( projectName ) ; if ( project . exists ( ) ) { IProjectDescription desc = project . getDescription ( ) ; desc . setName ( newName ) ; project . move ( desc , true , null ) ; return Services . getMessage ( "<STR_LIT>" , projectName , newName ) ; } return Services . getMessage ( "<STR_LIT>" , projectName ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . util . ArrayList ; import java . util . HashMap ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . ResourcesPlugin ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectNaturesCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; ArrayList < HashMap < String , Object > > results = new ArrayList < HashMap < String , Object > > ( ) ; if ( name == null ) { IProject [ ] projects = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProjects ( ) ; for ( IProject project : projects ) { if ( project . isOpen ( ) ) { String [ ] aliases = ProjectNatureFactory . getProjectNatureAliases ( project ) ; if ( aliases . length == <NUM_LIT:0> ) { aliases = new String [ ] { "<STR_LIT:none>" } ; } HashMap < String , Object > result = new HashMap < String , Object > ( ) ; result . put ( "<STR_LIT:name>" , project . getName ( ) ) ; result . put ( "<STR_LIT>" , aliases ) ; results . add ( result ) ; } } } else { String [ ] aliases = ProjectNatureFactory . getProjectNatureAliases ( ProjectUtils . getProject ( name ) ) ; if ( aliases . length == <NUM_LIT:0> ) { aliases = new String [ ] { "<STR_LIT:none>" } ; } HashMap < String , Object > result = new HashMap < String , Object > ( ) ; result . put ( "<STR_LIT:name>" , name ) ; result . put ( "<STR_LIT>" , aliases ) ; results . add ( result ) ; } return results ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IncrementalProjectBuilder ; import org . eclipse . core . runtime . NullProgressMonitor ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectBuildCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( name , true ) ; project . build ( IncrementalProjectBuilder . FULL_BUILD , new NullProgressMonitor ( ) ) ; return Services . getMessage ( "<STR_LIT>" , name ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . logging . Logger ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . project . ProjectManagement ; import org . eclim . util . file . FileUtils ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class ProjectCreateCommand extends AbstractCommand { private static final Logger logger = Logger . getLogger ( ProjectCreateCommand . class ) ; public Object execute ( CommandLine commandLine ) throws Exception { String folder = commandLine . getValue ( Options . FOLDER_OPTION ) ; if ( folder . endsWith ( "<STR_LIT:/>" ) || folder . endsWith ( "<STR_LIT:\\>" ) ) { folder = folder . substring ( <NUM_LIT:0> , folder . length ( ) - <NUM_LIT:1> ) ; } String name = commandLine . hasOption ( Options . PROJECT_OPTION ) ? commandLine . getValue ( Options . PROJECT_OPTION ) : FileUtils . getBaseName ( folder ) . replace ( '<CHAR_LIT:U+0020>' , '<CHAR_LIT:_>' ) ; logger . debug ( "<STR_LIT>" , name , folder ) ; ProjectManagement . create ( name , folder , commandLine ) ; return Services . getMessage ( "<STR_LIT>" , name ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . preference . Preferences ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class ProjectSettingCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( name , true ) ; String setting = commandLine . getValue ( Options . SETTING_OPTION ) ; Preferences preferences = getPreferences ( ) ; if ( commandLine . hasOption ( Options . VALUE_OPTION ) ) { String value = commandLine . getValue ( Options . VALUE_OPTION ) ; preferences . setValue ( project , setting , value ) ; return null ; } return preferences . getValue ( project , setting ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . project . ProjectManagement ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ProjectRefreshCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( name , true ) ; ProjectManagement . refresh ( project , commandLine ) ; return Services . getMessage ( "<STR_LIT>" , name ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . io . File ; import java . util . ArrayList ; import java . util . HashMap ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . filesystem . EFS ; import org . eclipse . core . filesystem . IFileStore ; import org . eclipse . core . internal . resources . LinkDescription ; import org . eclipse . core . internal . resources . Project ; import org . eclipse . core . internal . resources . ProjectDescription ; import org . eclipse . core . internal . resources . ProjectInfo ; import org . eclipse . core . internal . resources . ResourceInfo ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . IPath ; @ Command ( name = "<STR_LIT>" ) public class ProjectsCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { ArrayList < HashMap < String , Object > > results = new ArrayList < HashMap < String , Object > > ( ) ; IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; IProject [ ] projects = workspace . getRoot ( ) . getProjects ( ) ; for ( IProject project : projects ) { HashMap < String , Object > info = new HashMap < String , Object > ( ) ; info . put ( "<STR_LIT:name>" , project . getName ( ) ) ; if ( project . isOpen ( ) ) { String [ ] aliases = ProjectNatureFactory . getProjectNatureAliases ( project ) ; if ( aliases . length == <NUM_LIT:0> ) { aliases = new String [ ] { "<STR_LIT:none>" } ; } info . put ( "<STR_LIT>" , aliases ) ; } else { info . put ( "<STR_LIT>" , new String [ <NUM_LIT:0> ] ) ; } String projectPath = ProjectUtils . getPath ( project ) ; info . put ( "<STR_LIT:path>" , projectPath ) ; if ( project . isOpen ( ) ) { HashMap < String , String > links = new HashMap < String , String > ( ) ; if ( new File ( projectPath ) . exists ( ) ) { ResourceInfo pinfo = ( ( Project ) project ) . getResourceInfo ( false , false ) ; ProjectDescription desc = ( ( ProjectInfo ) pinfo ) . getDescription ( ) ; if ( desc != null ) { HashMap < IPath , LinkDescription > linfo = ( HashMap < IPath , LinkDescription > ) desc . getLinks ( ) ; if ( linfo != null ) { for ( IPath path : linfo . keySet ( ) ) { LinkDescription link = linfo . get ( path ) ; IResource member = project . findMember ( link . getProjectRelativePath ( ) ) ; IFileStore store = EFS . getStore ( member . getLocationURI ( ) ) ; String resolvedPath = store != null ? store . toString ( ) : link . getLocationURI ( ) . getPath ( ) ; links . put ( path . toString ( ) , resolvedPath ) ; } } } } info . put ( "<STR_LIT>" , links ) ; } results . add ( info ) ; } return results ; } } </s>
<s> package org . eclim . plugin . core . command . search ; import java . io . BufferedReader ; import java . io . FileReader ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . IOUtils ; import org . eclim . util . file . FileUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IResourceProxy ; import org . eclipse . core . resources . IResourceProxyVisitor ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . IPath ; import com . wcohen . ss . Levenstein ; import com . wcohen . ss . api . StringDistance ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class LocateFileCommand extends AbstractCommand { public static final String SCOPE_PROJECT = "<STR_LIT>" ; public static final String SCOPE_WORKSPACE = "<STR_LIT>" ; public static final String SCOPE_LIST = "<STR_LIT:list>" ; public Object execute ( CommandLine commandLine ) throws Exception { String pattern = commandLine . getValue ( Options . PATTERN_OPTION ) ; String scope = commandLine . getValue ( Options . SCOPE_OPTION ) ; String projectName = commandLine . getValue ( Options . NAME_OPTION ) ; List < Result > results = null ; if ( SCOPE_LIST . equals ( scope ) ) { results = executeLocateFromFileList ( commandLine , pattern , scope ) ; } else { results = executeLocateFromEclipse ( commandLine , pattern , scope ) ; } FilePathComparator comparator = new FilePathComparator ( pattern , projectName ) ; Collections . sort ( results , comparator ) ; return results ; } private List < Result > executeLocateFromFileList ( CommandLine commandLine , String pattern , String scope ) throws Exception { ArrayList < Result > results = new ArrayList < Result > ( ) ; String fileName = commandLine . getValue ( Options . FILE_OPTION ) ; BufferedReader reader = null ; try { reader = new BufferedReader ( new FileReader ( fileName ) ) ; int flags = <NUM_LIT:0> ; if ( commandLine . hasOption ( Options . CASE_INSENSITIVE_OPTION ) ) { flags = Pattern . CASE_INSENSITIVE ; } Matcher matcher = Pattern . compile ( pattern , flags ) . matcher ( "<STR_LIT>" ) ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) { if ( matcher . reset ( line ) . find ( ) ) { results . add ( new Result ( FileUtils . getBaseName ( line ) , line , null , null ) ) ; } } } finally { IOUtils . closeQuietly ( reader ) ; } return results ; } private List < Result > executeLocateFromEclipse ( CommandLine commandLine , String pattern , String scope ) throws Exception { ArrayList < IProject > projects = new ArrayList < IProject > ( ) ; String projectName = commandLine . getValue ( Options . NAME_OPTION ) ; if ( projectName != null ) { IProject project = ProjectUtils . getProject ( projectName , true ) ; projects . add ( project ) ; IProject [ ] depends = project . getReferencedProjects ( ) ; for ( IProject p : depends ) { if ( ! p . isOpen ( ) ) { p . open ( null ) ; } projects . add ( p ) ; } } if ( SCOPE_WORKSPACE . equals ( scope ) ) { IProject [ ] all = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getProjects ( ) ; for ( IProject p : all ) { if ( p . isOpen ( ) && ! projects . contains ( p ) ) { projects . add ( p ) ; } } } FileMatcher matcher = new FileMatcher ( pattern , commandLine . hasOption ( Options . CASE_INSENSITIVE_OPTION ) ) ; for ( IProject resource : projects ) { resource . accept ( matcher , <NUM_LIT:0> ) ; } return matcher . getResults ( ) ; } public static class Result { public String name ; public String path ; public String project ; public String projectPath ; public Result ( String name , String path , String project , String projectPath ) { this . name = name ; this . path = path ; this . project = project ; this . projectPath = projectPath ; } } private static class FileMatcher implements IResourceProxyVisitor { private static final Pattern FIND_BASE = Pattern . compile ( "<STR_LIT>" ) ; private static final ArrayList < String > IGNORE_DIRS = new ArrayList < String > ( ) ; static { IGNORE_DIRS . add ( "<STR_LIT>" ) ; IGNORE_DIRS . add ( "<STR_LIT>" ) ; IGNORE_DIRS . add ( "<STR_LIT>" ) ; IGNORE_DIRS . add ( "<STR_LIT>" ) ; IGNORE_DIRS . add ( "<STR_LIT>" ) ; } private static final ArrayList < String > IGNORE_EXTS = new ArrayList < String > ( ) ; static { IGNORE_EXTS . add ( "<STR_LIT:class>" ) ; IGNORE_EXTS . add ( "<STR_LIT>" ) ; IGNORE_EXTS . add ( "<STR_LIT>" ) ; IGNORE_EXTS . add ( "<STR_LIT>" ) ; IGNORE_EXTS . add ( "<STR_LIT>" ) ; IGNORE_EXTS . add ( "<STR_LIT>" ) ; IGNORE_EXTS . add ( "<STR_LIT>" ) ; } private Matcher matcher ; private boolean includesPath ; private Matcher baseMatcher ; private ArrayList < Result > results = new ArrayList < Result > ( ) ; private ArrayList < String > seen = new ArrayList < String > ( ) ; public FileMatcher ( String pattern , boolean ignoreCase ) { int flags = <NUM_LIT:0> ; if ( ignoreCase ) { flags = Pattern . CASE_INSENSITIVE ; } this . matcher = Pattern . compile ( pattern , flags ) . matcher ( "<STR_LIT>" ) ; Matcher baseMatcher = FIND_BASE . matcher ( pattern ) ; if ( baseMatcher . find ( ) ) { String base = baseMatcher . group ( <NUM_LIT:1> ) ; this . baseMatcher = Pattern . compile ( base ) . matcher ( "<STR_LIT>" ) ; this . includesPath = true ; } } public boolean visit ( IResourceProxy proxy ) throws CoreException { if ( results . size ( ) >= <NUM_LIT:100> ) { return false ; } int type = proxy . getType ( ) ; String name = proxy . getName ( ) ; if ( type == IResource . PROJECT ) { return true ; } else if ( type == IResource . FOLDER && IGNORE_DIRS . contains ( name ) ) { return false ; } else if ( type == IResource . FOLDER ) { return true ; } else if ( type == IResource . FILE ) { String ext = FileUtils . getExtension ( name ) . toLowerCase ( ) ; if ( IGNORE_EXTS . contains ( ext ) ) { return false ; } } IResource resource = null ; if ( includesPath ) { if ( ! baseMatcher . reset ( name ) . matches ( ) ) { return true ; } resource = proxy . requestResource ( ) ; name = resource . getFullPath ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; } if ( matcher . reset ( name ) . matches ( ) ) { if ( resource == null ) { resource = proxy . requestResource ( ) ; } IPath raw = resource . getLocation ( ) ; if ( raw != null ) { String rel = resource . getFullPath ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; String path = raw . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; Result entry = new Result ( FileUtils . getBaseName ( rel ) , path , resource . getProject ( ) . getName ( ) , rel ) ; if ( ! seen . contains ( path ) ) { results . add ( entry ) ; seen . add ( path ) ; } } } return true ; } public List < Result > getResults ( ) { return results ; } } private static class FilePathComparator implements Comparator < Result > { private StringDistance distance ; private String pattern ; private String projectName ; private Map < String , Double > scores = new HashMap < String , Double > ( ) ; public FilePathComparator ( String pattern , String projectName ) { this . distance = new Levenstein ( ) ; this . pattern = pattern ; this . pattern = this . pattern . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; this . projectName = projectName ; } public int compare ( Result o1 , Result o2 ) { double score1 = score ( o1 ) ; double score2 = score ( o2 ) ; return ( int ) Math . round ( score1 - score2 ) ; } public double score ( Result result ) { String path = result . projectPath != null ? result . projectPath : result . path ; if ( this . scores . containsKey ( path ) ) { return this . scores . get ( path ) ; } double score = <NUM_LIT:0> - this . distance . score ( this . pattern , path ) ; if ( projectName != null && result . project != null ) { if ( result . project . equals ( projectName ) ) { score -= score * <NUM_LIT> ; } } this . scores . put ( path , score ) ; return score ; } public boolean equals ( Object obj ) { return super . equals ( obj ) ; } } } </s>
<s> package org . eclim . plugin . core . command . history ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . internal . resources . File ; import org . eclipse . core . runtime . NullProgressMonitor ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class HistoryClearCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String filename = commandLine . getValue ( Options . FILE_OPTION ) ; File file = ( File ) ProjectUtils . getFile ( project , filename ) ; file . getLocalManager ( ) . getHistoryStore ( ) . remove ( file . getFullPath ( ) , new NullProgressMonitor ( ) ) ; return Services . getMessage ( "<STR_LIT>" ) ; } } </s>
<s> package org . eclim . plugin . core . command . history ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . filesystem . IFileInfo ; import org . eclipse . core . filesystem . IFileStore ; import org . eclipse . core . internal . localstore . FileSystemResourceManager ; import org . eclipse . core . internal . resources . File ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class HistoryAddCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; String filename = commandLine . getValue ( Options . FILE_OPTION ) ; File file = ( File ) ProjectUtils . getFile ( name , filename ) ; if ( file . exists ( ) ) { FileSystemResourceManager localManager = file . getLocalManager ( ) ; IFileStore store = localManager . getStore ( file ) ; IFileInfo fileInfo = store . fetchInfo ( ) ; localManager . getHistoryStore ( ) . addState ( file . getFullPath ( ) , store , fileInfo , false ) ; } return null ; } } </s>
<s> package org . eclim . plugin . core . command . history ; import java . text . SimpleDateFormat ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Comparator ; import java . util . Date ; import java . util . HashMap ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . StringUtils ; import org . eclipse . core . internal . resources . File ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . team . core . history . IFileRevision ; import org . eclipse . team . internal . core . history . LocalFileHistory ; import org . joda . time . Period ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class HistoryListCommand extends AbstractCommand { private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat ( "<STR_LIT>" ) ; public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String filename = commandLine . getValue ( Options . FILE_OPTION ) ; File file = ( File ) ProjectUtils . getFile ( project , filename ) ; LocalFileHistory history = new LocalFileHistory ( file , false ) ; history . refresh ( new NullProgressMonitor ( ) ) ; IFileRevision [ ] revisions = history . getFileRevisions ( ) ; Arrays . sort ( revisions , new Comparator < IFileRevision > ( ) { public int compare ( IFileRevision r1 , IFileRevision r2 ) { return ( int ) ( r2 . getTimestamp ( ) - r1 . getTimestamp ( ) ) ; } } ) ; ArrayList < HashMap < String , Object > > results = new ArrayList < HashMap < String , Object > > ( ) ; for ( IFileRevision revision : revisions ) { HashMap < String , Object > result = new HashMap < String , Object > ( ) ; result . put ( "<STR_LIT>" , String . valueOf ( revision . getTimestamp ( ) ) ) ; result . put ( "<STR_LIT>" , DATE_FORMATTER . format ( new Date ( revision . getTimestamp ( ) ) ) ) ; result . put ( "<STR_LIT>" , delta ( revision . getTimestamp ( ) ) ) ; results . add ( result ) ; } return results ; } private String delta ( long time ) { Period period = new Period ( time , System . currentTimeMillis ( ) ) ; ArrayList < String > parts = new ArrayList < String > ( ) ; int years = period . getYears ( ) ; if ( years > <NUM_LIT:0> ) { parts . add ( years + "<STR_LIT>" + ( years == <NUM_LIT:1> ? "<STR_LIT>" : "<STR_LIT:s>" ) ) ; } int months = period . getMonths ( ) ; if ( months > <NUM_LIT:0> ) { parts . add ( months + "<STR_LIT>" + ( months == <NUM_LIT:1> ? "<STR_LIT>" : "<STR_LIT:s>" ) ) ; } int weeks = period . getWeeks ( ) ; if ( weeks > <NUM_LIT:0> ) { parts . add ( weeks + "<STR_LIT>" + ( weeks == <NUM_LIT:1> ? "<STR_LIT>" : "<STR_LIT:s>" ) ) ; } int days = period . getDays ( ) ; if ( days > <NUM_LIT:0> ) { parts . add ( days + "<STR_LIT>" + ( days == <NUM_LIT:1> ? "<STR_LIT>" : "<STR_LIT:s>" ) ) ; } int hours = period . getHours ( ) ; if ( hours > <NUM_LIT:0> ) { parts . add ( hours + "<STR_LIT>" + ( hours == <NUM_LIT:1> ? "<STR_LIT>" : "<STR_LIT:s>" ) ) ; } int minutes = period . getMinutes ( ) ; if ( minutes > <NUM_LIT:0> ) { parts . add ( minutes + "<STR_LIT>" + ( minutes == <NUM_LIT:1> ? "<STR_LIT>" : "<STR_LIT:s>" ) ) ; } int seconds = period . getSeconds ( ) ; if ( seconds > <NUM_LIT:0> ) { parts . add ( seconds + "<STR_LIT>" + ( seconds == <NUM_LIT:1> ? "<STR_LIT>" : "<STR_LIT:s>" ) ) ; } if ( parts . size ( ) == <NUM_LIT:0> ) { int millis = period . getMillis ( ) ; if ( millis > <NUM_LIT:0> ) { parts . add ( millis + "<STR_LIT>" ) ; } } return StringUtils . join ( parts . toArray ( ) , '<CHAR_LIT:U+0020>' ) + "<STR_LIT>" ; } } </s>
<s> package org . eclim . plugin . core . command . history ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . IOUtils ; import org . eclipse . core . internal . resources . File ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . team . core . history . IFileRevision ; import org . eclipse . team . internal . core . history . LocalFileHistory ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class HistoryRevisionCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String filename = commandLine . getValue ( Options . FILE_OPTION ) ; long revision = commandLine . getLongValue ( Options . REVISION_OPTION ) ; File file = ( File ) ProjectUtils . getFile ( project , filename ) ; LocalFileHistory history = new LocalFileHistory ( file , false ) ; history . refresh ( new NullProgressMonitor ( ) ) ; IFileRevision [ ] revisions = history . getFileRevisions ( ) ; for ( IFileRevision rev : revisions ) { if ( rev . getTimestamp ( ) == revision ) { return IOUtils . toString ( rev . getStorage ( new NullProgressMonitor ( ) ) . getContents ( ) ) ; } } return null ; } } </s>
<s> package org . eclim . plugin . core . command . eclipse ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclipse . core . resources . ResourcesPlugin ; @ Command ( name = "<STR_LIT>" ) public class WorkspaceCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { return ResourcesPlugin . getWorkspace ( ) . getRoot ( ) . getRawLocation ( ) . toOSString ( ) ; } } </s>
<s> package org . eclim . plugin . core . command . eclipse ; import java . util . ArrayList ; import java . util . HashMap ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . util . StringUtils ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . jobs . IJobManager ; import org . eclipse . core . runtime . jobs . Job ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class JobsCommand extends AbstractCommand { public static final String AUTO_BUILD = "<STR_LIT>" ; public static final String AUTO_REFRESH = "<STR_LIT>" ; public static final String MANUAL_BUILD = "<STR_LIT>" ; public static final String MANUAL_REFRESH = "<STR_LIT>" ; public Object execute ( CommandLine commandLine ) throws Exception { Object family = getFamily ( commandLine . getValue ( Options . FAMILY_OPTION ) ) ; IJobManager manager = Job . getJobManager ( ) ; Job [ ] jobs = manager . find ( family ) ; ArrayList < HashMap < String , String > > results = new ArrayList < HashMap < String , String > > ( ) ; for ( Job job : jobs ) { HashMap < String , String > result = new HashMap < String , String > ( ) ; result . put ( "<STR_LIT>" , job . toString ( ) ) ; result . put ( "<STR_LIT:status>" , getStatus ( job ) ) ; results . add ( result ) ; } return results ; } private Object getFamily ( String name ) { if ( name != null ) { if ( AUTO_BUILD . equals ( name ) ) { return ResourcesPlugin . FAMILY_AUTO_BUILD ; } else if ( AUTO_REFRESH . equals ( name ) ) { return ResourcesPlugin . FAMILY_AUTO_REFRESH ; } else if ( MANUAL_BUILD . equals ( name ) ) { return ResourcesPlugin . FAMILY_MANUAL_BUILD ; } else if ( MANUAL_REFRESH . equals ( name ) ) { return ResourcesPlugin . FAMILY_MANUAL_REFRESH ; } } return null ; } private String getStatus ( Job job ) { int status = job . getState ( ) ; switch ( status ) { case Job . RUNNING : return "<STR_LIT>" ; case Job . SLEEPING : return "<STR_LIT>" ; case Job . WAITING : return "<STR_LIT>" ; case Job . NONE : return "<STR_LIT:none>" ; } return StringUtils . EMPTY ; } } </s>
<s> package org . eclim . plugin . core . command . xml ; import java . io . FileInputStream ; import java . io . StringWriter ; import javax . xml . transform . OutputKeys ; import javax . xml . transform . Transformer ; import javax . xml . transform . TransformerFactory ; import javax . xml . transform . sax . SAXSource ; import javax . xml . transform . stream . StreamResult ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . util . IOUtils ; import org . xml . sax . InputSource ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class FormatCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String restoreNewline = null ; FileInputStream in = null ; try { String file = commandLine . getValue ( Options . FILE_OPTION ) ; int indent = commandLine . getIntValue ( Options . INDENT_OPTION ) ; String format = commandLine . getValue ( "<STR_LIT:m>" ) ; String newline = System . getProperty ( "<STR_LIT>" ) ; if ( newline . equals ( "<STR_LIT>" ) && format . equals ( "<STR_LIT>" ) ) { restoreNewline = newline ; System . setProperty ( "<STR_LIT>" , "<STR_LIT:n>" ) ; } else if ( newline . equals ( "<STR_LIT:n>" ) && format . equals ( "<STR_LIT>" ) ) { restoreNewline = newline ; System . setProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; } TransformerFactory factory = TransformerFactory . newInstance ( ) ; factory . setAttribute ( "<STR_LIT>" , Integer . valueOf ( indent ) ) ; Transformer serializer = factory . newTransformer ( ) ; serializer . setOutputProperty ( OutputKeys . INDENT , "<STR_LIT:yes>" ) ; StringWriter out = new StringWriter ( ) ; in = new FileInputStream ( file ) ; serializer . transform ( new SAXSource ( new InputSource ( in ) ) , new StreamResult ( out ) ) ; return out . toString ( ) ; } finally { IOUtils . closeQuietly ( in ) ; if ( restoreNewline != null ) { System . setProperty ( "<STR_LIT>" , restoreNewline ) ; } } } } </s>
<s> package org . eclim . plugin . core . command . xml ; import java . util . Iterator ; import java . util . List ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . XmlUtils ; import org . xml . sax . helpers . DefaultHandler ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class ValidateCommand extends AbstractCommand { private static final String NO_GRAMMER = "<STR_LIT>" ; private static final String DOCTYPE_ROOT_NULL = "<STR_LIT>" ; public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; boolean schema = commandLine . hasOption ( Options . SCHEMA_OPTION ) ; List < Error > errors = validate ( project , file , schema , null ) ; return errors ; } protected List < Error > validate ( String project , String file , boolean schema , DefaultHandler handler ) throws Exception { List < Error > errors = XmlUtils . validateXml ( project , file , schema , handler ) ; for ( Iterator < Error > ii = errors . iterator ( ) ; ii . hasNext ( ) ; ) { Error error = ii . next ( ) ; if ( error . getMessage ( ) . indexOf ( NO_GRAMMER ) != - <NUM_LIT:1> || error . getMessage ( ) . indexOf ( DOCTYPE_ROOT_NULL ) != - <NUM_LIT:1> ) { ii . remove ( ) ; } } return errors ; } } </s>
<s> package org . eclim . plugin . core . command . refactoring ; import org . eclipse . ltk . core . refactoring . Refactoring ; public class Refactor { public String name ; public Refactoring refactoring ; public Refactor ( String name , Refactoring refactoring ) { this . name = name ; this . refactoring = refactoring ; } public Refactor ( Refactoring refactoring ) { this . name = refactoring . getName ( ) ; this . refactoring = refactoring ; } } </s>
<s> package org . eclim . plugin . core . command . refactoring ; import java . lang . reflect . Field ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . project . ProjectManagement ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . SubProgressMonitor ; import org . eclipse . ltk . core . refactoring . Change ; import org . eclipse . ltk . core . refactoring . CompositeChange ; import org . eclipse . ltk . core . refactoring . PerformChangeOperation ; import org . eclipse . ltk . core . refactoring . Refactoring ; import org . eclipse . ltk . core . refactoring . RefactoringCore ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; import org . eclipse . ltk . core . refactoring . RefactoringStatusEntry ; import org . eclipse . ltk . core . refactoring . TextFileChange ; public abstract class AbstractRefactorCommand extends AbstractCommand { private static final String PREVIEW_OPTION = "<STR_LIT>" ; private static final String DIFF_OPTION = "<STR_LIT:d>" ; @ Override public Object execute ( CommandLine commandLine ) throws Exception { if ( ! commandLine . hasOption ( PREVIEW_OPTION ) ) { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( projectName , true ) ; ProjectManagement . refresh ( project , commandLine ) ; IProject [ ] references = project . getReferencingProjects ( ) ; for ( IProject p : references ) { ProjectManagement . refresh ( p , commandLine ) ; } } try { NullProgressMonitor monitor = new NullProgressMonitor ( ) ; Refactor refactor = createRefactoring ( commandLine ) ; Refactoring refactoring = refactor . refactoring ; RefactoringStatus status = refactoring . checkAllConditions ( new SubProgressMonitor ( monitor , <NUM_LIT:4> ) ) ; int stopSeverity = RefactoringCore . getConditionCheckingFailedSeverity ( ) ; if ( status . getSeverity ( ) >= stopSeverity ) { throw new RefactorException ( status ) ; } Change change = refactoring . createChange ( new SubProgressMonitor ( monitor , <NUM_LIT:2> ) ) ; change . initializeValidationData ( new SubProgressMonitor ( monitor , <NUM_LIT:1> ) ) ; if ( commandLine . hasOption ( PREVIEW_OPTION ) ) { if ( commandLine . hasOption ( DIFF_OPTION ) ) { return previewChange ( change , commandLine . getValue ( "<STR_LIT:d>" ) ) ; } HashMap < String , Object > preview = new HashMap < String , Object > ( ) ; String previewOpt = "<STR_LIT:->" + PREVIEW_OPTION ; String [ ] args = commandLine . getArgs ( ) ; StringBuffer apply = new StringBuffer ( ) ; for ( String arg : args ) { if ( arg . equals ( previewOpt ) ) { continue ; } if ( apply . length ( ) > <NUM_LIT:0> ) { apply . append ( '<CHAR_LIT:U+0020>' ) ; } if ( arg . startsWith ( "<STR_LIT:->" ) ) { apply . append ( arg ) ; } else { apply . append ( '<CHAR_LIT:">' ) . append ( arg ) . append ( '<CHAR_LIT:">' ) ; } } preview . put ( "<STR_LIT>" , apply . toString ( ) . replaceFirst ( "<STR_LIT:->" + Options . EDITOR_OPTION + "<STR_LIT>" , "<STR_LIT>" ) . replaceFirst ( "<STR_LIT:->" + Options . PRETTY_OPTION + '<CHAR_LIT:U+0020>' , "<STR_LIT>" ) ) ; preview . put ( "<STR_LIT>" , previewChanges ( change ) ) ; return preview ; } IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; ResourceChangeListener rcl = new ResourceChangeListener ( ) ; workspace . addResourceChangeListener ( rcl ) ; try { PerformChangeOperation changeOperation = new PerformChangeOperation ( change ) ; if ( change instanceof CompositeChange ) { try { Field fName = CompositeChange . class . getDeclaredField ( "<STR_LIT>" ) ; fName . setAccessible ( true ) ; fName . set ( change , refactor . name ) ; } catch ( NoSuchFieldException nsfe ) { } } changeOperation . setUndoManager ( RefactoringCore . getUndoManager ( ) , change . getName ( ) ) ; changeOperation . run ( new SubProgressMonitor ( monitor , <NUM_LIT:4> ) ) ; return rcl . getChangedFiles ( ) ; } finally { workspace . removeResourceChangeListener ( rcl ) ; } } catch ( RefactorException re ) { HashMap < String , List < String > > result = new HashMap < String , List < String > > ( ) ; List < String > errors = new ArrayList < String > ( ) ; if ( re . getMessage ( ) != null ) { errors . add ( re . getMessage ( ) ) ; } RefactoringStatus status = re . getStatus ( ) ; if ( status != null ) { for ( RefactoringStatusEntry entry : status . getEntries ( ) ) { String message = entry . getMessage ( ) ; if ( ! errors . contains ( message ) && ! message . startsWith ( "<STR_LIT>" ) ) { errors . add ( message ) ; } } } result . put ( "<STR_LIT>" , errors ) ; return result ; } } public abstract Refactor createRefactoring ( CommandLine commandLine ) throws Exception ; private ArrayList < HashMap < String , String > > previewChanges ( Change change ) throws Exception { ArrayList < HashMap < String , String > > results = new ArrayList < HashMap < String , String > > ( ) ; if ( change instanceof CompositeChange ) { for ( Change c : ( ( CompositeChange ) change ) . getChildren ( ) ) { results . addAll ( previewChanges ( c ) ) ; } } else { HashMap < String , String > result = new HashMap < String , String > ( ) ; if ( change instanceof TextFileChange ) { TextFileChange text = ( TextFileChange ) change ; result . put ( "<STR_LIT:type>" , "<STR_LIT>" ) ; result . put ( "<STR_LIT:file>" , text . getFile ( ) . getLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ) ; } else { result . put ( "<STR_LIT:type>" , "<STR_LIT>" ) ; result . put ( "<STR_LIT:message>" , change . toString ( ) ) ; } results . add ( result ) ; } return results ; } private String previewChange ( Change change , String file ) throws Exception { if ( change instanceof CompositeChange ) { for ( Change c : ( ( CompositeChange ) change ) . getChildren ( ) ) { String preview = previewChange ( c , file ) ; if ( preview != null ) { return preview ; } } } else { if ( change instanceof TextFileChange ) { TextFileChange text = ( TextFileChange ) change ; String path = text . getFile ( ) . getLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; if ( path . equals ( file ) ) { return text . getPreviewContent ( new NullProgressMonitor ( ) ) ; } } } return null ; } } </s>
<s> package org . eclim . plugin . core . command . refactoring ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . ltk . core . refactoring . IUndoManager ; import org . eclipse . ltk . core . refactoring . RefactoringCore ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class RedoCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; ResourceChangeListener rcl = new ResourceChangeListener ( ) ; workspace . addResourceChangeListener ( rcl ) ; try { IUndoManager manager = RefactoringCore . getUndoManager ( ) ; if ( commandLine . hasOption ( Options . PEEK_OPTION ) ) { return manager . peekUndoName ( ) ; } manager . performRedo ( null , null ) ; return rcl . getChangedFiles ( ) ; } finally { workspace . removeResourceChangeListener ( rcl ) ; } } } </s>
<s> package org . eclim . plugin . core . command . refactoring ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclipse . core . resources . IWorkspace ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . ltk . core . refactoring . IUndoManager ; import org . eclipse . ltk . core . refactoring . RefactoringCore ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class UndoCommand extends AbstractCommand { @ Override public Object execute ( CommandLine commandLine ) throws Exception { IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; ResourceChangeListener rcl = new ResourceChangeListener ( ) ; workspace . addResourceChangeListener ( rcl ) ; try { IUndoManager manager = RefactoringCore . getUndoManager ( ) ; if ( commandLine . hasOption ( Options . PEEK_OPTION ) ) { return manager . peekUndoName ( ) ; } manager . performUndo ( null , null ) ; return rcl . getChangedFiles ( ) ; } finally { workspace . removeResourceChangeListener ( rcl ) ; } } } </s>
<s> package org . eclim . plugin . core . command . refactoring ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IResourceChangeEvent ; import org . eclipse . core . resources . IResourceChangeListener ; import org . eclipse . core . resources . IResourceDelta ; import org . eclipse . core . resources . IResourceDeltaVisitor ; import org . eclipse . core . runtime . CoreException ; public class ResourceChangeListener implements IResourceChangeListener , IResourceDeltaVisitor { private List < IResourceDelta > deltas = new ArrayList < IResourceDelta > ( ) ; @ Override public void resourceChanged ( IResourceChangeEvent event ) { try { event . getDelta ( ) . accept ( this ) ; } catch ( CoreException ce ) { throw new RuntimeException ( ce ) ; } } @ Override public boolean visit ( IResourceDelta delta ) throws CoreException { IResource resource = delta . getResource ( ) ; if ( delta . getKind ( ) != IResourceDelta . NO_CHANGE && ( resource . getType ( ) == IResource . FILE || resource . getType ( ) == IResource . FOLDER ) ) { deltas . add ( delta ) ; } return true ; } public List < IResourceDelta > getResourceDeltas ( ) { return deltas ; } public List < Map < String , String > > getChangedFiles ( ) throws Exception { List < Map < String , String > > results = new ArrayList < Map < String , String > > ( ) ; HashSet < String > seen = new HashSet < String > ( ) ; for ( IResourceDelta delta : getResourceDeltas ( ) ) { int flags = delta . getFlags ( ) ; if ( ( flags & IResourceDelta . MOVED_TO ) != <NUM_LIT:0> ) { continue ; } HashMap < String , String > result = new HashMap < String , String > ( ) ; IResource resource = delta . getResource ( ) ; String file = resource . getLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; if ( ( flags & IResourceDelta . MOVED_FROM ) != <NUM_LIT:0> ) { String path = ProjectUtils . getFilePath ( resource . getProject ( ) , delta . getMovedFromPath ( ) . toOSString ( ) ) ; result . put ( "<STR_LIT>" , path ) ; result . put ( "<STR_LIT>" , file ) ; } else if ( resource . getLocation ( ) . getFileExtension ( ) != null ) { if ( ! seen . contains ( file ) ) { result . put ( "<STR_LIT:file>" , file ) ; seen . add ( file ) ; } } if ( result . size ( ) > <NUM_LIT:0> ) { results . add ( result ) ; } } return results ; } } </s>
<s> package org . eclim . plugin . core . command . refactoring ; import org . eclipse . ltk . core . refactoring . RefactoringStatus ; public class RefactorException extends RuntimeException { private static final long serialVersionUID = <NUM_LIT:1L> ; private RefactoringStatus status ; public RefactorException ( ) { super ( ) ; } public RefactorException ( String message ) { super ( message ) ; } public RefactorException ( RefactoringStatus status ) { super ( ) ; this . status = status ; } public RefactoringStatus getStatus ( ) { return status ; } } </s>
<s> package org . eclim . plugin . core . command . archive ; import java . io . File ; import java . io . InputStream ; import java . io . OutputStream ; import java . util . regex . Pattern ; import org . apache . commons . lang . SystemUtils ; import org . apache . commons . vfs . FileObject ; import org . apache . commons . vfs . FileSystemManager ; import org . apache . commons . vfs . VFS ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . util . IOUtils ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" ) public class ArchiveReadCommand extends AbstractCommand { private static final String URI_PREFIX = "<STR_LIT>" ; private static final Pattern WIN_PATH = Pattern . compile ( "<STR_LIT>" ) ; public String execute ( CommandLine commandLine ) throws Exception { InputStream in = null ; OutputStream out = null ; FileSystemManager fsManager = null ; try { String file = commandLine . getValue ( Options . FILE_OPTION ) ; fsManager = VFS . getManager ( ) ; FileObject fileObject = fsManager . resolveFile ( file ) ; FileObject tempFile = fsManager . resolveFile ( SystemUtils . JAVA_IO_TMPDIR + "<STR_LIT>" + fileObject . getName ( ) . getPath ( ) ) ; fsManager . getFilesCache ( ) . clear ( fileObject . getFileSystem ( ) ) ; fsManager . getFilesCache ( ) . clear ( tempFile . getFileSystem ( ) ) ; String path = tempFile . getName ( ) . getURI ( ) . substring ( URI_PREFIX . length ( ) ) ; if ( WIN_PATH . matcher ( path ) . matches ( ) ) { path = path . substring ( <NUM_LIT:1> ) ; } tempFile . createFile ( ) ; in = fileObject . getContent ( ) . getInputStream ( ) ; out = tempFile . getContent ( ) . getOutputStream ( ) ; IOUtils . copy ( in , out ) ; new File ( path ) . deleteOnExit ( ) ; return path ; } finally { IOUtils . closeQuietly ( in ) ; IOUtils . closeQuietly ( out ) ; } } } </s>
<s> package org . eclim . plugin . core . command . problems ; import java . io . File ; import java . lang . reflect . Field ; import java . lang . reflect . Method ; import java . text . Collator ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . Comparator ; import java . util . HashSet ; import java . util . Map ; import java . util . regex . Pattern ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . plugin . core . CorePlugin ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . CollectionUtils ; import org . eclim . util . file . FileUtils ; import org . eclipse . core . internal . resources . ResourceException ; import org . eclipse . core . resources . IMarker ; import org . eclipse . core . resources . IProject ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . ui . IPageLayout ; import org . eclipse . ui . internal . views . markers . CachedMarkerBuilder ; import org . eclipse . ui . internal . views . markers . ExtendedMarkersView ; import org . eclipse . ui . internal . views . markers . MarkerContentGenerator ; import org . eclipse . ui . views . markers . internal . ContentGeneratorDescriptor ; import org . eclipse . ui . views . markers . internal . MarkerSupportRegistry ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class ProblemsCommand extends AbstractCommand { @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) public Object execute ( CommandLine commandLine ) throws Exception { waitOnBuild ( ) ; String name = commandLine . getValue ( Options . PROJECT_OPTION ) ; boolean errorsOnly = commandLine . hasOption ( Options . ERRORS_OPTION ) ; IProject project = ProjectUtils . getProject ( name ) ; ContentGeneratorDescriptor descriptor = MarkerSupportRegistry . getInstance ( ) . getDefaultContentGenDescriptor ( ) ; ExtendedMarkersView view = new ExtendedMarkersView ( descriptor . getId ( ) ) ; String viewId = IPageLayout . ID_PROBLEM_VIEW ; MarkerContentGenerator generator = new MarkerContentGenerator ( descriptor , new CachedMarkerBuilder ( view ) , viewId ) ; Field enabledFilters = MarkerContentGenerator . class . getDeclaredField ( "<STR_LIT>" ) ; enabledFilters . setAccessible ( true ) ; enabledFilters . set ( generator , new HashSet ( ) ) ; Method gatherMarkers = MarkerContentGenerator . class . getDeclaredMethod ( "<STR_LIT>" , String [ ] . class , Boolean . TYPE , Collection . class , IProgressMonitor . class ) ; gatherMarkers . setAccessible ( true ) ; ArrayList markers = new ArrayList ( ) ; gatherMarkers . invoke ( generator , generator . getTypes ( ) , true , markers , new NullProgressMonitor ( ) ) ; ArrayList < Error > problems = new ArrayList < Error > ( ) ; if ( markers . size ( ) == <NUM_LIT:0> ) { return problems ; } ArrayList < IProject > projects = new ArrayList < IProject > ( ) ; projects . add ( project ) ; CollectionUtils . addAll ( projects , project . getReferencedProjects ( ) ) ; CollectionUtils . addAll ( projects , project . getReferencingProjects ( ) ) ; Method getMarker = null ; for ( Object markerEntry : markers ) { if ( getMarker == null ) { getMarker = markerEntry . getClass ( ) . getDeclaredMethod ( "<STR_LIT>" ) ; getMarker . setAccessible ( true ) ; } try { IMarker marker = ( IMarker ) getMarker . invoke ( markerEntry ) ; Map < String , Object > attributes = marker . getAttributes ( ) ; int severity = attributes . containsKey ( "<STR_LIT>" ) ? ( ( Integer ) attributes . get ( "<STR_LIT>" ) ) . intValue ( ) : IMarker . SEVERITY_WARNING ; if ( errorsOnly && severity != IMarker . SEVERITY_ERROR ) { continue ; } IResource resource = marker . getResource ( ) ; if ( resource == null || resource . getRawLocation ( ) == null ) { continue ; } if ( ! projects . contains ( resource . getProject ( ) ) ) { continue ; } int offset = attributes . containsKey ( "<STR_LIT>" ) ? ( ( Integer ) attributes . get ( "<STR_LIT>" ) ) . intValue ( ) : <NUM_LIT:1> ; int line = attributes . containsKey ( "<STR_LIT>" ) ? ( ( Integer ) attributes . get ( "<STR_LIT>" ) ) . intValue ( ) : <NUM_LIT:1> ; int [ ] pos = { <NUM_LIT:1> , <NUM_LIT:1> } ; String message = ( String ) attributes . get ( "<STR_LIT:message>" ) ; String path = resource . getLocation ( ) . toOSString ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; File file = new File ( path ) ; if ( file . isFile ( ) && file . exists ( ) && offset > <NUM_LIT:0> ) { pos = FileUtils . offsetToLineColumn ( path , offset ) ; } problems . add ( new Error ( message , path , Math . max ( pos [ <NUM_LIT:0> ] , line ) , pos [ <NUM_LIT:1> ] , severity != IMarker . SEVERITY_ERROR ) ) ; } catch ( ResourceException ignore ) { } } Collections . sort ( problems , new ProblemComparator ( project ) ) ; return problems ; } private void waitOnBuild ( ) { CorePlugin plugin = CorePlugin . getDefault ( ) ; int tries = <NUM_LIT:0> ; while ( tries < <NUM_LIT:30> && plugin . isBuildRunning ( ) ) { try { Thread . sleep ( <NUM_LIT:100> ) ; } catch ( Exception ignore ) { } tries ++ ; } } private static class ProblemComparator implements Comparator < Error > { private Pattern projectPattern ; private Collator collator = Collator . getInstance ( ) ; public ProblemComparator ( IProject project ) throws Exception { this . projectPattern = Pattern . compile ( "<STR_LIT>" + ProjectUtils . getPath ( project ) + "<STR_LIT>" ) ; } public int compare ( Error e1 , Error e2 ) { String ef1 = e1 . getFilename ( ) ; boolean e1InProject = projectPattern . matcher ( ef1 ) . matches ( ) ; String ef2 = e2 . getFilename ( ) ; boolean e2InProject = projectPattern . matcher ( ef2 ) . matches ( ) ; if ( e1InProject && ! e2InProject ) { return - <NUM_LIT:1> ; } if ( e2InProject && ! e1InProject ) { return <NUM_LIT:1> ; } int result = collator . compare ( ef1 , ef2 ) ; if ( result == <NUM_LIT:0> ) { result = e1 . getLine ( ) - e2 . getLine ( ) ; } if ( result == <NUM_LIT:0> ) { result = e1 . getColumn ( ) - e2 . getColumn ( ) ; } return result ; } public boolean equals ( Object obj ) { return super . equals ( obj ) ; } } } </s>
<s> package org . eclim ; import java . io . File ; import java . io . FileInputStream ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Map ; import org . apache . commons . lang . StringUtils ; import org . apache . tools . ant . taskdefs . condition . Os ; import org . eclim . util . CommandExecutor ; import org . eclim . util . IOUtils ; import static org . junit . Assert . assertNotNull ; import com . google . gson . JsonElement ; import com . google . gson . JsonParser ; import com . google . gson . JsonPrimitive ; import com . google . gson . JsonSyntaxException ; public class Eclim { public static final String TEST_PROJECT = "<STR_LIT>" ; private static final String ECLIM = System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ; private static final String PORT = System . getProperty ( "<STR_LIT>" ) ; private static final String PRETTY = "<STR_LIT>" ; private static final String COMMAND = "<STR_LIT>" ; private static final JsonParser JSON_PARSER = new JsonParser ( ) ; private static String workspace ; public static Object execute ( String [ ] args ) { return execute ( args , - <NUM_LIT:1> , true ) ; } public static Object execute ( String [ ] args , boolean failOnError ) { return execute ( args , - <NUM_LIT:1> , failOnError ) ; } public static Object execute ( String [ ] args , long timeout ) { return execute ( args , timeout , true ) ; } public static Object execute ( String [ ] args , long timeout , boolean failOnError ) { assertNotNull ( "<STR_LIT>" , PORT ) ; assertNotNull ( "<STR_LIT>" , ECLIM ) ; String [ ] arguments = null ; if ( Os . isFamily ( Os . FAMILY_WINDOWS ) ) { String eclimCmd = ECLIM + "<STR_LIT>" ; String drive = eclimCmd . substring ( <NUM_LIT:0> , <NUM_LIT:2> ) ; arguments = new String [ <NUM_LIT:3> ] ; arguments [ <NUM_LIT:0> ] = "<STR_LIT>" ; arguments [ <NUM_LIT:1> ] = "<STR_LIT>" ; arguments [ <NUM_LIT:2> ] = drive + "<STR_LIT>" + eclimCmd + "<STR_LIT>" + PORT + "<STR_LIT:U+0020>" + PRETTY + "<STR_LIT:U+0020>" + COMMAND + "<STR_LIT>" + StringUtils . join ( args , "<STR_LIT>" ) + "<STR_LIT:\">" ; } else { arguments = new String [ args . length + <NUM_LIT:5> ] ; System . arraycopy ( args , <NUM_LIT:0> , arguments , <NUM_LIT:5> , args . length ) ; arguments [ <NUM_LIT:0> ] = ECLIM ; arguments [ <NUM_LIT:1> ] = "<STR_LIT>" ; arguments [ <NUM_LIT:2> ] = PORT ; arguments [ <NUM_LIT:3> ] = PRETTY ; arguments [ <NUM_LIT:4> ] = COMMAND ; } System . out . println ( "<STR_LIT>" + StringUtils . join ( arguments , '<CHAR_LIT:U+0020>' ) ) ; CommandExecutor process = null ; try { process = CommandExecutor . execute ( arguments , timeout ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } if ( process . getReturnCode ( ) == - <NUM_LIT:1> ) { process . destroy ( ) ; throw new RuntimeException ( "<STR_LIT>" ) ; } String result = process . getResult ( ) . trim ( ) ; String error = process . getErrorMessage ( ) ; if ( process . getReturnCode ( ) != <NUM_LIT:0> ) { if ( ! failOnError ) { System . out . println ( "<STR_LIT>" + result ) ; if ( ! StringUtils . EMPTY . equals ( error ) ) { System . out . println ( "<STR_LIT>" + error ) ; } return result ; } System . out . println ( "<STR_LIT>" + result ) ; System . out . println ( "<STR_LIT>" + error ) ; throw new RuntimeException ( "<STR_LIT>" + process . getReturnCode ( ) ) ; } System . out . println ( "<STR_LIT>" + result ) ; if ( ! StringUtils . EMPTY . equals ( error ) ) { System . out . println ( "<STR_LIT>" + error ) ; } if ( result . equals ( StringUtils . EMPTY ) ) { result = "<STR_LIT>" ; } try { return toType ( JSON_PARSER . parse ( result ) ) ; } catch ( JsonSyntaxException jse ) { if ( ! failOnError ) { return result ; } throw jse ; } } public static Object toType ( JsonElement json ) { if ( json . isJsonNull ( ) ) { return null ; } else if ( json . isJsonPrimitive ( ) ) { JsonPrimitive prim = json . getAsJsonPrimitive ( ) ; if ( prim . isBoolean ( ) ) { return prim . getAsBoolean ( ) ; } else if ( prim . isString ( ) ) { return prim . getAsString ( ) ; } else if ( prim . isNumber ( ) ) { if ( prim . getAsString ( ) . indexOf ( '<CHAR_LIT:.>' ) != - <NUM_LIT:1> ) { return prim . getAsDouble ( ) ; } return prim . getAsInt ( ) ; } } else if ( json . isJsonArray ( ) ) { ArrayList < Object > type = new ArrayList < Object > ( ) ; for ( JsonElement element : json . getAsJsonArray ( ) ) { type . add ( toType ( element ) ) ; } return type ; } else if ( json . isJsonObject ( ) ) { HashMap < String , Object > type = new HashMap < String , Object > ( ) ; for ( Map . Entry < String , JsonElement > entry : json . getAsJsonObject ( ) . entrySet ( ) ) { type . put ( entry . getKey ( ) , toType ( entry . getValue ( ) ) ) ; } return type ; } return null ; } public static String getWorkspace ( ) { if ( workspace == null ) { workspace = ( ( String ) execute ( new String [ ] { "<STR_LIT>" } ) ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; } return workspace ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public static String getProjectPath ( String name ) { Object result = execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , name } ) ; if ( result instanceof Map ) { Map < String , String > info = ( Map < String , String > ) result ; if ( info . containsKey ( "<STR_LIT:path>" ) ) { return info . get ( "<STR_LIT:path>" ) ; } } return null ; } public static boolean projectExists ( String name ) { return getProjectPath ( name ) != null ; } public static String getProjectSetting ( String project , String name ) { return ( String ) execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , project , "<STR_LIT>" , name , } ) ; } public static void setProjectSetting ( String project , String name , String value ) { execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , project , "<STR_LIT>" , name , "<STR_LIT>" , value , } ) ; } public static String resolveFile ( String file ) { return resolveFile ( TEST_PROJECT , file ) ; } public static String resolveFile ( String project , String file ) { return new StringBuffer ( ) . append ( getProjectPath ( project ) ) . append ( '<CHAR_LIT:/>' ) . append ( file ) . toString ( ) ; } public static String fileToString ( String project , String file ) { String path = resolveFile ( project , file ) ; FileInputStream fin = null ; try { fin = new FileInputStream ( path ) ; return IOUtils . toString ( fin ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } finally { IOUtils . closeQuietly ( fin ) ; } } public static void deleteDirectory ( File dir ) { if ( ! dir . exists ( ) ) { return ; } for ( File f : dir . listFiles ( ) ) { if ( f . isDirectory ( ) ) { deleteDirectory ( f ) ; } else { f . delete ( ) ; } } dir . delete ( ) ; } } </s>
<s> package org . eclim . plugin . core . command . xml . validate ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . junit . Test ; import static org . junit . Assert . * ; public class ValidateCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) { List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , results . size ( ) ) ; String file = Eclim . resolveFile ( Eclim . TEST_PROJECT , TEST_FILE ) ; Map < String , Object > error = results . get ( <NUM_LIT:0> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertTrue ( ( ( String ) error . get ( "<STR_LIT:message>" ) ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:12> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:11> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; error = results . get ( <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertTrue ( ( ( String ) error . get ( "<STR_LIT:message>" ) ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:9> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; } } </s>
<s> package org . eclim . plugin . core . command . xml . format ; import org . apache . commons . lang . StringUtils ; import org . eclim . Eclim ; import org . junit . Test ; import static org . junit . Assert . * ; public class FormatCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test public void execute ( ) { String result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . resolveFile ( TEST_FILE ) , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:2>" , "<STR_LIT>" , "<STR_LIT>" } ) ; String [ ] lines = StringUtils . split ( result , '<STR_LIT:\n>' ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:5> , lines . length ) ; assertEquals ( "<STR_LIT>" , lines [ <NUM_LIT:1> ] ) ; assertEquals ( "<STR_LIT>" , lines [ <NUM_LIT:2> ] ) ; assertEquals ( "<STR_LIT>" , lines [ <NUM_LIT:3> ] ) ; assertEquals ( "<STR_LIT>" , lines [ <NUM_LIT:4> ] ) ; } } </s>
<s> package org . eclim . plugin . core . command . admin ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . junit . Test ; import static org . junit . Assert . * ; public class SettingsCommandTest { @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) throws Exception { List < Map < String , String > > results = ( List < Map < String , String > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" } ) ; HashMap < String , String > properties = new HashMap < String , String > ( ) ; for ( Map < String , String > result : results ) { properties . put ( result . get ( "<STR_LIT:name>" ) , result . get ( "<STR_LIT:value>" ) ) ; } assertTrue ( "<STR_LIT>" , properties . containsKey ( "<STR_LIT>" ) ) ; assertTrue ( "<STR_LIT>" , properties . containsKey ( "<STR_LIT>" ) ) ; assertTrue ( "<STR_LIT>" , properties . containsKey ( "<STR_LIT>" ) ) ; assertTrue ( "<STR_LIT>" , properties . containsKey ( "<STR_LIT>" ) ) ; assertTrue ( "<STR_LIT>" , properties . containsKey ( "<STR_LIT>" ) ) ; assertTrue ( "<STR_LIT>" , properties . containsKey ( "<STR_LIT>" ) ) ; assertTrue ( "<STR_LIT>" , properties . containsKey ( "<STR_LIT>" ) ) ; } } </s>
<s> package org . eclim . plugin . core . command . admin ; import java . util . Map ; import org . eclim . Eclim ; import org . junit . Test ; import static org . junit . Assert . * ; public class PingCommandTest { @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) { Map < String , String > result = ( Map < String , String > ) Eclim . execute ( new String [ ] { "<STR_LIT>" } ) ; assertEquals ( "<STR_LIT>" , System . getProperty ( "<STR_LIT>" ) , result . get ( "<STR_LIT>" ) ) ; assertTrue ( "<STR_LIT>" , result . get ( "<STR_LIT>" ) . startsWith ( "<STR_LIT>" ) ) ; } } </s>
<s> package org . eclim . plugin . core . command . project ; import java . io . File ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . junit . Test ; import static org . junit . Assert . * ; public class ProjectCommandsTest { private static final String TEST_PROJECT = "<STR_LIT>" ; private static final String TEST_PROJECT_IMPORT = "<STR_LIT>" ; @ Test public void createProject ( ) { if ( Eclim . projectExists ( TEST_PROJECT ) ) { Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_PROJECT } ) ; } assertFalse ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . getWorkspace ( ) + "<STR_LIT:/>" + TEST_PROJECT , "<STR_LIT>" , "<STR_LIT>" } ) ; assertTrue ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT ) ) ; } @ Test public void closeProject ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_PROJECT } ) ; assertFalse ( "<STR_LIT>" , projectOpen ( ) ) ; } @ Test public void openProject ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_PROJECT } ) ; assertTrue ( "<STR_LIT>" , projectOpen ( ) ) ; } @ Test public void renameProject ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT ) ) ; String renamed = TEST_PROJECT + "<STR_LIT>" ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_PROJECT , "<STR_LIT>" , renamed } ) ; assertFalse ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT ) ) ; assertTrue ( "<STR_LIT>" , Eclim . projectExists ( renamed ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , renamed , "<STR_LIT>" , TEST_PROJECT } ) ; assertFalse ( "<STR_LIT>" , Eclim . projectExists ( renamed ) ) ; assertTrue ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT ) ) ; } @ Test public void moveProject ( ) throws Exception { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT ) ) ; String path = new File ( Eclim . getWorkspace ( ) + "<STR_LIT>" ) . getCanonicalPath ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_PROJECT , "<STR_LIT>" , path } ) ; assertTrue ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT ) ) ; assertEquals ( "<STR_LIT>" , path + '<CHAR_LIT:/>' + TEST_PROJECT , Eclim . getProjectPath ( TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_PROJECT , "<STR_LIT>" , Eclim . getWorkspace ( ) } ) ; assertTrue ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT ) ) ; path = new File ( Eclim . getWorkspace ( ) + '<CHAR_LIT:/>' + TEST_PROJECT ) . getCanonicalPath ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; assertEquals ( "<STR_LIT>" , path , Eclim . getProjectPath ( TEST_PROJECT ) ) ; } @ Test public void deleteProject ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_PROJECT } ) ; assertFalse ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT ) ) ; File dir = new File ( Eclim . getWorkspace ( ) + "<STR_LIT:/>" + TEST_PROJECT ) ; for ( File f : dir . listFiles ( ) ) { f . delete ( ) ; } dir . delete ( ) ; } @ Test @ SuppressWarnings ( { "<STR_LIT:rawtypes>" , "<STR_LIT:unchecked>" } ) public void importProject ( ) { if ( Eclim . projectExists ( TEST_PROJECT_IMPORT ) ) { Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_PROJECT_IMPORT } ) ; } assertFalse ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT_IMPORT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . getWorkspace ( ) + "<STR_LIT:/>" + TEST_PROJECT_IMPORT , "<STR_LIT>" , "<STR_LIT>" } ) ; assertTrue ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT_IMPORT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_PROJECT_IMPORT } ) ; assertFalse ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT_IMPORT ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . getWorkspace ( ) + "<STR_LIT:/>" + TEST_PROJECT_IMPORT , } ) ; assertTrue ( "<STR_LIT>" , Eclim . projectExists ( TEST_PROJECT_IMPORT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_PROJECT_IMPORT , } ) ; assertEquals ( <NUM_LIT:1> , results . size ( ) ) ; assertEquals ( <NUM_LIT:1> , ( ( List ) results . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , ( ( List ) results . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) ) . get ( <NUM_LIT:0> ) ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_PROJECT_IMPORT } ) ; File dir = new File ( Eclim . getWorkspace ( ) + "<STR_LIT:/>" + TEST_PROJECT_IMPORT ) ; for ( File f : dir . listFiles ( ) ) { f . delete ( ) ; } dir . delete ( ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private boolean projectOpen ( ) { List < Map < String , Object > > projects = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" } ) ; for ( Map < String , Object > project : projects ) { if ( project . get ( "<STR_LIT:name>" ) . equals ( TEST_PROJECT ) && project . get ( "<STR_LIT>" ) . equals ( Boolean . TRUE ) ) { return true ; } } return false ; } } </s>
<s> package org . eclim . plugin . core . command . history ; import java . io . BufferedWriter ; import java . io . FileOutputStream ; import java . io . OutputStreamWriter ; import java . util . List ; import java . util . Map ; import java . util . regex . Pattern ; import org . eclim . Eclim ; import org . junit . Test ; import static org . junit . Assert . * ; public class HistoryCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; private static final Pattern ENTRY_TIMESTAMP = Pattern . compile ( "<STR_LIT>" ) ; private static final Pattern ENTRY_DATETIME = Pattern . compile ( "<STR_LIT>" ) ; private static final Pattern ENTRY_DELTA = Pattern . compile ( "<STR_LIT>" ) ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) throws Exception { String result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; assertEquals ( result , "<STR_LIT>" ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; assertEquals ( <NUM_LIT:0> , results . size ( ) ) ; assertEquals ( "<STR_LIT>" , Eclim . fileToString ( Eclim . TEST_PROJECT , TEST_FILE ) , "<STR_LIT>" ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; BufferedWriter out = null ; try { out = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( Eclim . resolveFile ( TEST_FILE ) , true ) ) ) ; out . write ( "<STR_LIT>" ) ; } finally { try { out . close ( ) ; } catch ( Exception ignore ) { } } Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; assertEquals ( <NUM_LIT:2> , results . size ( ) ) ; for ( Map < String , Object > entry : results ) { assertTrue ( ENTRY_TIMESTAMP . matcher ( entry . get ( "<STR_LIT>" ) . toString ( ) ) . matches ( ) ) ; assertTrue ( ENTRY_DATETIME . matcher ( entry . get ( "<STR_LIT>" ) . toString ( ) ) . matches ( ) ) ; assertTrue ( ENTRY_DELTA . matcher ( entry . get ( "<STR_LIT>" ) . toString ( ) ) . matches ( ) ) ; } result = ( String ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Eclim . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , results . get ( <NUM_LIT:1> ) . get ( "<STR_LIT>" ) . toString ( ) } ) ; assertEquals ( "<STR_LIT>" , result , "<STR_LIT>" ) ; } } </s>
<s> package org . eclim . plugin . core . command . problems ; import java . util . HashMap ; import java . util . List ; import org . eclim . Eclim ; import org . junit . Test ; import static org . junit . Assert . * ; public class ProblemsCommandTest { private static final String TEST_PROJECT = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) { List < Object > results = ( List < Object > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , TEST_PROJECT } ) ; HashMap < String , Object > error = new HashMap < String , Object > ( ) ; error . put ( "<STR_LIT:message>" , "<STR_LIT>" ) ; error . put ( "<STR_LIT>" , Eclim . getWorkspace ( ) + "<STR_LIT:/>" + TEST_PROJECT + "<STR_LIT>" ) ; error . put ( "<STR_LIT>" , <NUM_LIT:5> ) ; error . put ( "<STR_LIT>" , <NUM_LIT:11> ) ; error . put ( "<STR_LIT>" , - <NUM_LIT:1> ) ; error . put ( "<STR_LIT>" , - <NUM_LIT:1> ) ; error . put ( "<STR_LIT>" , false ) ; assertTrue ( results . contains ( error ) ) ; } } </s>
<s> package org . eclim . test ; public class Test { private ArrayList list = new ArrayList ( ) ; } </s>
<s> package org . eclim . plugin . wst . command . complete ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . wst . Wst ; import org . junit . Test ; import static org . junit . Assert . * ; public class CssCodeCompleteCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void complete ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Wst . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Wst . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:8> , results . size ( ) ) ; assertEquals ( results . get ( <NUM_LIT:0> ) . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( results . get ( <NUM_LIT:1> ) . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( results . get ( <NUM_LIT:2> ) . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( results . get ( <NUM_LIT:3> ) . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( results . get ( <NUM_LIT:4> ) . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( results . get ( <NUM_LIT:5> ) . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( results . get ( <NUM_LIT:6> ) . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( results . get ( <NUM_LIT:7> ) . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; } } </s>
<s> package org . eclim . plugin . wst . command . complete ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . wst . Wst ; import org . junit . Test ; import static org . junit . Assert . * ; public class XmlCodeCompleteCommandTest { private static final String TEST_FILE_XSD = "<STR_LIT>" ; private static final String TEST_FILE_WSDL = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completeXsd ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Wst . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Wst . TEST_PROJECT , "<STR_LIT>" , TEST_FILE_XSD , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , results . size ( ) ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" + "<STR_LIT>" ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completeWsdl ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Wst . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Wst . TEST_PROJECT , "<STR_LIT>" , TEST_FILE_WSDL , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , results . size ( ) ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" + "<STR_LIT>" ) ; } } </s>
<s> package org . eclim . plugin . wst . command . complete ; import java . util . List ; import java . util . Map ; import org . apache . tools . ant . taskdefs . condition . Os ; import org . eclim . Eclim ; import org . eclim . plugin . wst . Wst ; import org . junit . Test ; import static org . junit . Assert . * ; public class HtmlCodeCompleteCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completeAttribute ( ) { if ( Os . isFamily ( Os . FAMILY_WINDOWS ) ) { return ; } assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Wst . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Wst . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , results . size ( ) ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completeElement ( ) { if ( Os . isFamily ( Os . FAMILY_WINDOWS ) ) { return ; } assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Wst . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Wst . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:7> , results . size ( ) ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; result = results . get ( <NUM_LIT:1> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; } @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void completeCss ( ) { if ( Os . isFamily ( Os . FAMILY_WINDOWS ) ) { return ; } assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Wst . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Wst . TEST_PROJECT , "<STR_LIT>" , TEST_FILE , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:utf-8>" } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:8> , results . size ( ) ) ; Map < String , Object > result = results . get ( <NUM_LIT:0> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; result = results . get ( <NUM_LIT:1> ) ; assertEquals ( result . get ( "<STR_LIT>" ) , "<STR_LIT>" ) ; } } </s>
<s> package org . eclim . plugin . wst . command . validate ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . wst . Wst ; import org . junit . Test ; import static org . junit . Assert . * ; public class HtmlValidateCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void validate ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Wst . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Wst . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , results . size ( ) ) ; String file = Eclim . resolveFile ( Wst . TEST_PROJECT , TEST_FILE ) ; Map < String , Object > error = results . get ( <NUM_LIT:0> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertTrue ( ( ( String ) error . get ( "<STR_LIT:message>" ) ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:5> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:5> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; error = results . get ( <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertTrue ( ( ( String ) error . get ( "<STR_LIT:message>" ) ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:5> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:5> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , true ) ; error = results . get ( <NUM_LIT:2> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertTrue ( ( ( String ) error . get ( "<STR_LIT:message>" ) ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:8> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:5> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , true ) ; } } </s>
<s> package org . eclim . plugin . wst . command . validate ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . wst . Wst ; import org . junit . Test ; import static org . junit . Assert . * ; public class CssValidateCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void validate ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Wst . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Wst . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , results . size ( ) ) ; String file = Eclim . resolveFile ( Wst . TEST_PROJECT , TEST_FILE ) ; Map < String , Object > error = results . get ( <NUM_LIT:0> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertTrue ( ( ( String ) error . get ( "<STR_LIT:message>" ) ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:2> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; error = results . get ( <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertTrue ( ( ( String ) error . get ( "<STR_LIT:message>" ) ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:6> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; } } </s>
<s> package org . eclim . plugin . wst . command . validate ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . wst . Wst ; import org . junit . Test ; import static org . junit . Assert . * ; public class XsdValidateCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void validate ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Wst . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Wst . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , results . size ( ) ) ; String file = Eclim . resolveFile ( Wst . TEST_PROJECT , TEST_FILE ) ; Map < String , Object > error = results . get ( <NUM_LIT:0> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertTrue ( ( ( String ) error . get ( "<STR_LIT:message>" ) ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:3> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; error = results . get ( <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertTrue ( ( ( String ) error . get ( "<STR_LIT:message>" ) ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:11> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:12> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; } } </s>
<s> package org . eclim . plugin . wst . command . validate ; import java . util . List ; import java . util . Map ; import org . eclim . Eclim ; import org . eclim . plugin . wst . Wst ; import org . junit . Test ; import static org . junit . Assert . * ; public class DtdValidateCommandTest { private static final String TEST_FILE = "<STR_LIT>" ; @ Test @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void validate ( ) { assertTrue ( "<STR_LIT>" , Eclim . projectExists ( Wst . TEST_PROJECT ) ) ; List < Map < String , Object > > results = ( List < Map < String , Object > > ) Eclim . execute ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , Wst . TEST_PROJECT , "<STR_LIT>" , TEST_FILE } ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , results . size ( ) ) ; String file = Eclim . resolveFile ( Wst . TEST_PROJECT , TEST_FILE ) ; Map < String , Object > error = results . get ( <NUM_LIT:0> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , file ) ; assertEquals ( error . get ( "<STR_LIT:message>" ) , "<STR_LIT>" ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT:3> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( error . get ( "<STR_LIT>" ) , false ) ; } } </s>
<s> package org . eclim . plugin . wst ; public class Wst { public static final String TEST_PROJECT = "<STR_LIT>" ; } </s>
<s> package org . eclim . plugin . wst ; import org . eclim . Services ; import org . eclim . plugin . AbstractPluginResources ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclipse . wst . jsdt . core . JavaScriptCore ; public class PluginResources extends AbstractPluginResources { public static final String NAME = "<STR_LIT>" ; public static final String JAVASCRIPT_NATURE = JavaScriptCore . NATURE_ID ; public void initialize ( String name ) { super . initialize ( name ) ; ProjectNatureFactory . addNature ( "<STR_LIT>" , JAVASCRIPT_NATURE ) ; } protected String getBundleBaseName ( ) { return "<STR_LIT>" ; } } </s>
<s> package org . eclim . plugin . wst . util ; import org . eclim . Services ; import org . eclim . plugin . core . project . ProjectNatureFactory ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . wst . PluginResources ; import org . eclipse . core . resources . IProject ; import org . eclipse . wst . jsdt . core . IJavaScriptProject ; import org . eclipse . wst . jsdt . core . IJavaScriptUnit ; import org . eclipse . wst . jsdt . core . JavaScriptCore ; public class JavaScriptUtils { public static IJavaScriptProject getJavaScriptProject ( String project ) throws Exception { return getJavaScriptProject ( ProjectUtils . getProject ( project , true ) ) ; } public static IJavaScriptProject getJavaScriptProject ( IProject project ) throws Exception { if ( ProjectUtils . getPath ( project ) == null ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , project . getName ( ) ) ) ; } if ( ! project . hasNature ( PluginResources . JAVASCRIPT_NATURE ) ) { String alias = ProjectNatureFactory . getAliasForNature ( PluginResources . JAVASCRIPT_NATURE ) ; throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , project . getName ( ) , alias ) ) ; } IJavaScriptProject javascriptProject = JavaScriptCore . create ( project ) ; if ( javascriptProject == null || ! javascriptProject . exists ( ) ) { throw new IllegalArgumentException ( Services . getMessage ( "<STR_LIT>" , project ) ) ; } return javascriptProject ; } public static IJavaScriptUnit getJavaScriptUnit ( String project , String file ) throws Exception { IJavaScriptProject javascriptProject = getJavaScriptProject ( project ) ; return getJavaScriptUnit ( javascriptProject , file ) ; } public static IJavaScriptUnit getJavaScriptUnit ( IJavaScriptProject project , String file ) throws Exception { if ( ! project . isOpen ( ) ) { project . open ( null ) ; } return JavaScriptCore . createCompilationUnitFrom ( ProjectUtils . getFile ( project . getProject ( ) , file ) ) ; } } </s>
<s> package org . eclim . plugin . wst . command . complete ; import java . util . ArrayList ; import java . util . List ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . command . complete . CodeCompleteResult ; import org . eclim . plugin . wst . util . JavaScriptUtils ; import org . eclipse . wst . jsdt . core . CompletionProposal ; import org . eclipse . wst . jsdt . core . IJavaScriptUnit ; import org . eclipse . wst . jsdt . core . Signature ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class JavaScriptCodeCompleteCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; int offset = getOffset ( commandLine ) ; IJavaScriptUnit src = JavaScriptUtils . getJavaScriptUnit ( project , file ) ; CompletionRequestor collector = new CompletionRequestor ( ) ; src . codeComplete ( offset , collector ) ; return collector . getResults ( ) ; } public static class CompletionRequestor extends org . eclipse . wst . jsdt . core . CompletionRequestor { private ArrayList < CodeCompleteResult > results = new ArrayList < CodeCompleteResult > ( ) ; @ Override public void accept ( CompletionProposal proposal ) { String completion = String . valueOf ( proposal . getCompletion ( ) ) ; String type = String . valueOf ( proposal . getDeclarationTypeName ( ) ) ; StringBuffer desc = new StringBuffer ( ) ; desc . append ( type ) . append ( '<CHAR_LIT:.>' ) ; if ( proposal . getKind ( ) == CompletionProposal . METHOD_REF ) { String sig = String . valueOf ( Signature . getSignatureSimpleName ( proposal . getSignature ( ) ) ) ; String name = completion . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ; int index = sig . indexOf ( "<STR_LIT:U+0020(>" ) ; String ret = sig . substring ( <NUM_LIT:0> , index ) ; String params = sig . substring ( index ) . trim ( ) ; desc . append ( name ) . append ( params ) . append ( "<STR_LIT:U+0020:U+0020>" ) . append ( ret ) ; if ( params . lastIndexOf ( '<CHAR_LIT:)>' ) > params . lastIndexOf ( '<CHAR_LIT:(>' ) + <NUM_LIT:1> && ( completion . length ( ) > <NUM_LIT:0> && completion . charAt ( completion . length ( ) - <NUM_LIT:1> ) == '<CHAR_LIT:)>' ) ) { completion = completion . substring ( <NUM_LIT:0> , completion . length ( ) - <NUM_LIT:1> ) ; } } else { desc . append ( completion ) ; } String info = desc . toString ( ) ; results . add ( new CodeCompleteResult ( completion , null , info ) ) ; } public List < CodeCompleteResult > getResults ( ) { return results ; } } } </s>
<s> package org . eclim . plugin . wst . command . complete ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . eclipse . EclimPlugin ; import org . eclim . plugin . core . command . complete . AbstractCodeCompleteCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IResource ; import org . eclipse . jface . text . ITextViewer ; import org . eclipse . jface . text . contentassist . IContentAssistProcessor ; import org . eclipse . swt . widgets . Composite ; import org . eclipse . wst . css . ui . internal . contentassist . CSSContentAssistProcessor ; import org . eclipse . wst . sse . core . StructuredModelManager ; import org . eclipse . wst . sse . core . internal . provisional . IStructuredModel ; import org . eclipse . wst . sse . ui . internal . StructuredTextViewer ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class CssCodeCompleteCommand extends WstCodeCompleteCommand { private static StructuredTextViewer viewer ; @ Override protected IContentAssistProcessor getContentAssistProcessor ( CommandLine commandLine , String project , String file ) throws Exception { return new CSSContentAssistProcessor ( ) ; } @ Override protected ITextViewer getTextViewer ( CommandLine commandLine , String project , String file ) throws Exception { IFile ifile = ProjectUtils . getFile ( ProjectUtils . getProject ( project , true ) , file ) ; ifile . refreshLocal ( IResource . DEPTH_INFINITE , null ) ; IStructuredModel model = StructuredModelManager . getModelManager ( ) . getModelForRead ( ifile ) ; if ( viewer == null ) { viewer = new StructuredTextViewer ( EclimPlugin . getShell ( ) , null , null , false , <NUM_LIT:0> ) { protected void createControl ( Composite parent , int styles ) { } } ; } viewer . setDocument ( model . getStructuredDocument ( ) ) ; return viewer ; } } </s>
<s> package org . eclim . plugin . wst . command . complete ; import org . eclim . command . CommandLine ; import org . eclim . eclipse . EclimPlugin ; import org . eclim . plugin . core . command . complete . AbstractCodeCompleteCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IFile ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . eclipse . jface . text . contentassist . IContentAssistProcessor ; import org . eclipse . swt . graphics . Point ; import org . eclipse . wst . sse . core . StructuredModelManager ; import org . eclipse . wst . sse . core . internal . provisional . IStructuredModel ; import org . eclipse . wst . sse . ui . internal . StructuredTextViewer ; public abstract class WstCodeCompleteCommand extends AbstractCodeCompleteCommand { @ Override protected ICompletionProposal [ ] getCompletionProposals ( CommandLine commandLine , String project , String file , int offset ) throws Exception { IContentAssistProcessor processor = getContentAssistProcessor ( commandLine , project , file ) ; IFile ifile = ProjectUtils . getFile ( ProjectUtils . getProject ( project , true ) , file ) ; IStructuredModel model = StructuredModelManager . getModelManager ( ) . getModelForRead ( ifile ) ; if ( model != null ) { StructuredTextViewer viewer = new StructuredTextViewer ( EclimPlugin . getShell ( ) , null , null , false , <NUM_LIT:0> ) { private Point point ; public Point getSelectedRange ( ) { return point ; } public void setSelectedRange ( int x , int y ) { point = new Point ( x , y ) ; } } ; viewer . setDocument ( model . getStructuredDocument ( ) ) ; viewer . setSelectedRange ( offset , <NUM_LIT:0> ) ; ICompletionProposal [ ] proposals = processor . computeCompletionProposals ( viewer , offset ) ; model . releaseFromRead ( ) ; return proposals ; } return new ICompletionProposal [ <NUM_LIT:0> ] ; } } </s>
<s> package org . eclim . plugin . wst . command . complete ; import java . util . ArrayList ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . plugin . core . command . complete . CodeCompleteResult ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . eclipse . jface . text . contentassist . IContentAssistProcessor ; import org . eclipse . wst . xml . ui . internal . contentassist . XMLContentAssistProcessor ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class XmlCodeCompleteCommand extends WstCodeCompleteCommand { private static final ArrayList < String > IGNORE = new ArrayList < String > ( ) ; static { IGNORE . add ( "<STR_LIT>" ) ; IGNORE . add ( "<STR_LIT>" ) ; } @ Override protected IContentAssistProcessor getContentAssistProcessor ( CommandLine commandLine , String project , String file ) throws Exception { return new XMLContentAssistProcessor ( ) ; } @ Override protected boolean acceptProposal ( ICompletionProposal proposal ) { String display = proposal . getDisplayString ( ) ; return ! display . toLowerCase ( ) . startsWith ( "<STR_LIT>" ) && ! display . toLowerCase ( ) . startsWith ( "<STR_LIT>" ) && ! IGNORE . contains ( display ) ; } @ Override protected String getMenu ( ICompletionProposal proposal ) { String menu = proposal . getAdditionalProposalInfo ( ) ; if ( menu != null ) { int index = menu . indexOf ( "<STR_LIT>" ) ; if ( index != - <NUM_LIT:1> ) { menu = menu . substring ( index + <NUM_LIT:4> ) ; menu = CodeCompleteResult . menuFromInfo ( menu ) ; } } return menu ; } } </s>
<s> package org . eclim . plugin . wst . command . complete ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclipse . jface . text . contentassist . ICompletionProposal ; import org . eclipse . jface . text . contentassist . IContentAssistProcessor ; import org . eclipse . wst . html . ui . internal . contentassist . HTMLContentAssistProcessor ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class HtmlCodeCompleteCommand extends WstCodeCompleteCommand { @ Override protected IContentAssistProcessor getContentAssistProcessor ( CommandLine commandLine , String project , String file ) throws Exception { return new HTMLContentAssistProcessor ( ) ; } @ Override protected boolean acceptProposal ( ICompletionProposal proposal ) { String display = proposal . getDisplayString ( ) ; return ! display . toLowerCase ( ) . startsWith ( "<STR_LIT>" ) ; } } </s>
<s> package org . eclim . plugin . wst . command . src ; import java . util . ArrayList ; import java . util . List ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . plugin . wst . util . JavaScriptUtils ; import org . eclim . util . file . FileOffsets ; import org . eclipse . wst . jsdt . core . IJavaScriptUnit ; import org . eclipse . wst . jsdt . core . compiler . IProblem ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) public class JavaScriptSrcUpdateCommand extends AbstractCommand { public Object execute ( CommandLine commandLine ) throws Exception { String file = commandLine . getValue ( Options . FILE_OPTION ) ; String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; if ( ! commandLine . hasOption ( Options . VALIDATE_OPTION ) ) { ProjectUtils . getFile ( projectName , file ) ; } else { IJavaScriptUnit src = JavaScriptUtils . getJavaScriptUnit ( projectName , file ) ; IJavaScriptUnit workingCopy = src . getWorkingCopy ( null ) ; ProblemRequestor requestor = new ProblemRequestor ( ) ; try { workingCopy . discardWorkingCopy ( ) ; workingCopy . becomeWorkingCopy ( requestor , null ) ; } finally { workingCopy . discardWorkingCopy ( ) ; } List < IProblem > problems = requestor . getProblems ( ) ; ArrayList < Error > errors = new ArrayList < Error > ( ) ; String filename = src . getResource ( ) . getLocation ( ) . toOSString ( ) ; FileOffsets offsets = FileOffsets . compile ( filename ) ; for ( IProblem problem : problems ) { int [ ] lineColumn = offsets . offsetToLineColumn ( problem . getSourceStart ( ) ) ; errors . add ( new Error ( problem . getMessage ( ) , filename , lineColumn [ <NUM_LIT:0> ] , lineColumn [ <NUM_LIT:1> ] , problem . isWarning ( ) ) ) ; } return errors ; } return null ; } public static class ProblemRequestor implements org . eclipse . wst . jsdt . core . IProblemRequestor { private ArrayList < IProblem > problems = new ArrayList < IProblem > ( ) ; public List < IProblem > getProblems ( ) { return problems ; } public void acceptProblem ( IProblem problem ) { problems . add ( problem ) ; } public void beginReporting ( ) { } public void endReporting ( ) { } public boolean isActive ( ) { return true ; } } } </s>
<s> package org . eclim . plugin . wst . command . validate ; import java . util . ArrayList ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclipse . wst . dtd . core . internal . validation . eclipse . DTDValidator ; import org . eclipse . wst . xml . core . internal . validation . core . ValidationMessage ; import org . eclipse . wst . xml . core . internal . validation . core . ValidationReport ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class DtdValidateCommand extends WstValidateCommand { public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; ArrayList < Error > results = new ArrayList < Error > ( ) ; DTDValidator validator = DTDValidator . getInstance ( ) ; ValidationReport result = validator . validate ( toUri ( project , file ) ) ; ValidationMessage [ ] messages = result . getValidationMessages ( ) ; for ( int ii = <NUM_LIT:0> ; ii < messages . length ; ii ++ ) { StringBuffer message = new StringBuffer ( messages [ ii ] . getMessage ( ) ) ; for ( Object o : messages [ ii ] . getNestedMessages ( ) ) { ValidationMessage nested = ( ValidationMessage ) o ; message . append ( '<CHAR_LIT:U+0020>' ) . append ( nested . getMessage ( ) ) ; } results . add ( new Error ( message . toString ( ) , toFile ( messages [ ii ] . getUri ( ) ) , messages [ ii ] . getLineNumber ( ) , messages [ ii ] . getColumnNumber ( ) , false ) ) ; } return results ; } } </s>
<s> package org . eclim . plugin . wst . command . validate ; import java . util . ArrayList ; import java . util . List ; import org . eclipse . wst . validation . internal . provisional . core . IMessage ; import org . eclipse . wst . validation . internal . provisional . core . IReporter ; import org . eclipse . wst . validation . internal . provisional . core . IValidator ; public class Reporter implements IReporter { private ArrayList < IMessage > messages = new ArrayList < IMessage > ( ) ; public List < IMessage > getMessages ( ) { return messages ; } public void addMessage ( IValidator origin , IMessage message ) { messages . add ( message ) ; } public void displaySubtask ( IValidator validator , IMessage message ) { } public boolean isCancelled ( ) { return false ; } public void removeAllMessages ( IValidator origin ) { } public void removeAllMessages ( IValidator origin , Object object ) { } public void removeMessageSubset ( IValidator validator , Object obj , String groupName ) { } } </s>
<s> package org . eclim . plugin . wst . command . validate ; import java . io . ByteArrayOutputStream ; import java . io . FileInputStream ; import java . io . PrintWriter ; import java . util . ArrayList ; import org . apache . commons . lang . StringUtils ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclim . util . IOUtils ; import org . w3c . tidy . Tidy ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class HtmlValidateCommand extends WstValidateCommand { public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; final String file = ProjectUtils . getFilePath ( project , commandLine . getValue ( Options . FILE_OPTION ) ) ; Tidy tidy = new Tidy ( ) ; tidy . setEmacs ( true ) ; tidy . setOnlyErrors ( true ) ; tidy . setQuiet ( true ) ; FileInputStream in = new FileInputStream ( file ) ; ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; PrintWriter writer = new PrintWriter ( out , true ) ; try { tidy . setErrout ( writer ) ; tidy . parse ( in , out ) ; } finally { IOUtils . closeQuietly ( in ) ; IOUtils . closeQuietly ( out ) ; } ArrayList < Error > results = new ArrayList < Error > ( ) ; String [ ] lines = StringUtils . split ( out . toString ( ) , '<STR_LIT:\n>' ) ; for ( int ii = <NUM_LIT:0> ; ii < lines . length ; ii ++ ) { if ( accept ( lines [ ii ] ) ) { Error error = parseError ( file , lines [ ii ] ) ; if ( error != null ) { results . add ( error ) ; } } } return results ; } private boolean accept ( String line ) { return line . indexOf ( "<STR_LIT>" ) == - <NUM_LIT:1> && line . indexOf ( "<STR_LIT>" ) == - <NUM_LIT:1> ; } private Error parseError ( String file , String line ) throws Exception { String [ ] parts = StringUtils . split ( line , '<CHAR_LIT::>' ) ; if ( parts . length == <NUM_LIT:5> ) { int lnum = Integer . parseInt ( parts [ <NUM_LIT:1> ] . replaceAll ( "<STR_LIT:U+002C>" , "<STR_LIT>" ) ) ; int cnum = Integer . parseInt ( parts [ <NUM_LIT:2> ] . replaceAll ( "<STR_LIT:U+002C>" , "<STR_LIT>" ) ) ; return new Error ( parts [ <NUM_LIT:4> ] . trim ( ) , file , lnum , cnum , parts [ <NUM_LIT:3> ] . trim ( ) . equals ( "<STR_LIT>" ) ) ; } return null ; } } </s>
<s> package org . eclim . plugin . wst . command . validate ; import java . util . ArrayList ; import org . apache . commons . lang . StringUtils ; import org . eclim . Services ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclim . plugin . core . util . ProjectUtils ; import org . eclipse . core . resources . IProject ; import org . w3c . css . css . DocumentParser ; import org . w3c . css . css . StyleSheet ; import org . w3c . css . parser . CssError ; import org . w3c . css . parser . analyzer . TokenMgrError ; import org . w3c . css . util . ApplContext ; import org . w3c . css . util . Warning ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class CssValidateCommand extends WstValidateCommand { private static final String URI_PREFIX = "<STR_LIT>" ; public Object execute ( CommandLine commandLine ) throws Exception { String projectName = commandLine . getValue ( Options . PROJECT_OPTION ) ; IProject project = ProjectUtils . getProject ( projectName ) ; if ( ! project . exists ( ) ) { throw new RuntimeException ( Services . getMessage ( "<STR_LIT>" , projectName ) ) ; } String uri = toUri ( projectName , commandLine . getValue ( Options . FILE_OPTION ) ) ; ApplContext context = new ApplContext ( "<STR_LIT:en>" ) ; context . setCssVersion ( "<STR_LIT>" ) ; context . setMedium ( "<STR_LIT:all>" ) ; ArrayList < Error > errors = new ArrayList < Error > ( ) ; try { DocumentParser parser = new DocumentParser ( context , uri ) ; StyleSheet css = parser . getStyleSheet ( ) ; css . findConflicts ( context ) ; for ( CssError error : css . getErrors ( ) . getErrors ( ) ) { if ( ! StringUtils . EMPTY . equals ( error . getException ( ) . getMessage ( ) ) ) { errors . add ( new Error ( error . getException ( ) . getMessage ( ) , toFile ( error . getSourceFile ( ) ) , error . getLine ( ) , <NUM_LIT:1> , false ) ) ; } } for ( Warning warning : css . getWarnings ( ) . getWarnings ( ) ) { if ( ! StringUtils . EMPTY . equals ( warning . getWarningMessage ( ) ) ) { errors . add ( new Error ( warning . getWarningMessage ( ) , toFile ( warning . getSourceFile ( ) ) , warning . getLine ( ) , <NUM_LIT:1> , true ) ) ; } } } catch ( TokenMgrError tme ) { errors . add ( new Error ( tme . getMessage ( ) , super . toFile ( uri ) , <NUM_LIT:1> , <NUM_LIT:1> , false ) ) ; } return errors ; } @ Override protected String toFile ( String uri ) { uri = uri . startsWith ( URI_PREFIX ) ? uri . substring ( URI_PREFIX . length ( ) ) : uri ; uri = uri . replaceFirst ( "<STR_LIT>" , "<STR_LIT:/>" ) ; return uri ; } } </s>
<s> package org . eclim . plugin . wst . command . validate ; import org . eclipse . wst . validation . internal . provisional . core . IValidationContext ; public class ValidationContext implements IValidationContext { private String [ ] uris ; public ValidationContext ( String uri ) { this . uris = new String [ ] { uri } ; } public String [ ] getURIs ( ) { return uris ; } public Object loadModel ( String name ) { return null ; } public Object loadModel ( String name , Object [ ] params ) { return null ; } } </s>
<s> package org . eclim . plugin . wst . command . validate ; import java . util . ArrayList ; import org . eclim . annotation . Command ; import org . eclim . command . CommandLine ; import org . eclim . command . Error ; import org . eclim . command . Options ; import org . eclipse . wst . xml . core . internal . validation . core . ValidationMessage ; import org . eclipse . wst . xml . core . internal . validation . core . ValidationReport ; import org . eclipse . wst . xsd . core . internal . validation . eclipse . XSDValidator ; @ Command ( name = "<STR_LIT>" , options = "<STR_LIT>" + "<STR_LIT>" ) public class XsdValidateCommand extends WstValidateCommand { public Object execute ( CommandLine commandLine ) throws Exception { String project = commandLine . getValue ( Options . PROJECT_OPTION ) ; String file = commandLine . getValue ( Options . FILE_OPTION ) ; ArrayList < Error > results = new ArrayList < Error > ( ) ; XSDValidator validator = XSDValidator . getInstance ( ) ; ValidationReport result = validator . validate ( toUri ( project , file ) ) ; ValidationMessage [ ] messages = result . getValidationMessages ( ) ; for ( int ii = <NUM_LIT:0> ; ii < messages . length ; ii ++ ) { StringBuffer message = new StringBuffer ( messages [ ii ] . getMessage ( ) ) ; for ( Object o : messages [ ii ] . getNestedMessages ( ) ) { ValidationMessage nested = ( ValidationMessage ) o ; message . append ( '<CHAR_LIT:U+0020>' ) . append ( nested . getMessage ( ) ) ; } results . add ( new Error ( message . toString ( ) , toFile ( messages [ ii ] . getUri ( ) ) , messages [ ii ] . getLineNumber ( ) , messages [ ii ] . getColumnNumber ( ) , false ) ) ; } return results ; } } </s>
<s> package org . eclim . plugin . wst . command . validate ; import java . net . URLDecoder ; import org . eclim . plugin . core . command . AbstractCommand ; import org . eclim . plugin . core . util . ProjectUtils ; public abstract class WstValidateCommand extends AbstractCommand { private static final String URI_PREFIX = "<STR_LIT>" ; protected String toUri ( String project , String filename ) throws Exception { if ( filename . indexOf ( "<STR_LIT>" ) == - <NUM_LIT:1> ) { filename = URI_PREFIX + ProjectUtils . getFilePath ( project , filename ) ; } return filename . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; } protected String toFile ( String uri ) { String file = uri . startsWith ( URI_PREFIX ) ? uri . substring ( URI_PREFIX . length ( ) ) : uri ; try { return URLDecoder . decode ( file , "<STR_LIT:utf-8>" ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } } </s>
<s> package org . eclim . installer . ant ; import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import org . apache . commons . io . IOUtils ; import org . apache . commons . lang . StringUtils ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . Task ; import org . apache . tools . ant . taskdefs . Move ; import org . eclim . installer . step . EclipseInfo ; import org . eclim . installer . step . command . Command ; import org . eclim . installer . step . command . OutputHandler ; import org . eclim . installer . step . command . UninstallCommand ; import org . formic . Installer ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class UninstallIUTask extends Task implements OutputHandler { private static final Logger logger = LoggerFactory . getLogger ( UninstallIUTask . class ) ; private String repository ; private String iu ; private boolean failonerror = true ; public void execute ( ) throws BuildException { if ( iu == null ) { throw new BuildException ( "<STR_LIT>" ) ; } EclipseInfo info = ( EclipseInfo ) Installer . getContext ( ) . getValue ( "<STR_LIT>" ) ; runCommand ( new UninstallCommand ( this , repository , iu , "<STR_LIT>" ) , "<STR_LIT>" + iu ) ; runCommand ( new Command ( this , new String [ ] { "<STR_LIT>" , info . getProfileName ( ) } , "<STR_LIT>" ) , "<STR_LIT>" ) ; if ( iu . equals ( "<STR_LIT>" ) ) { String prefs = info . getLocalPath ( ) + "<STR_LIT>" + info . getProfileName ( ) + "<STR_LIT>" ; logger . info ( "<STR_LIT>" + prefs ) ; File prefFile = new File ( prefs ) ; File prefFileNew = new File ( prefs + "<STR_LIT>" ) ; if ( ! prefFile . exists ( ) ) { logger . warn ( "<STR_LIT>" ) ; } else { BufferedReader in = null ; BufferedWriter out = null ; try { in = new BufferedReader ( new FileReader ( prefFile ) ) ; out = new BufferedWriter ( new FileWriter ( prefFileNew ) ) ; String line = null ; while ( ( line = in . readLine ( ) ) != null ) { if ( line . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ) { continue ; } out . write ( line ) ; out . newLine ( ) ; } IOUtils . closeQuietly ( in ) ; IOUtils . closeQuietly ( out ) ; Move move = new Move ( ) ; move . setTaskName ( "<STR_LIT>" ) ; move . setProject ( getProject ( ) ) ; move . setFile ( prefFileNew ) ; move . setTofile ( prefFile ) ; move . setFailOnError ( false ) ; move . setForce ( true ) ; move . setOverwrite ( true ) ; move . execute ( ) ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } finally { IOUtils . closeQuietly ( in ) ; IOUtils . closeQuietly ( out ) ; } } } } private void runCommand ( Command command , String message ) { log ( StringUtils . capitalize ( message ) + "<STR_LIT:...>" ) ; try { command . start ( ) ; command . join ( ) ; if ( command . getReturnCode ( ) != <NUM_LIT:0> ) { logger . warn ( "<STR_LIT>" + command . getErrorMessage ( ) + "<STR_LIT>" + command . getResult ( ) ) ; if ( failonerror ) { throw new BuildException ( "<STR_LIT>" + command . getErrorMessage ( ) + "<STR_LIT>" + command . getResult ( ) ) ; } } } catch ( Exception e ) { if ( failonerror ) { throw new BuildException ( e ) ; } else { logger . error ( "<STR_LIT>" + message , e ) ; return ; } } finally { if ( command != null ) { command . destroy ( ) ; } } } public void process ( String line ) { logger . info ( line ) ; } public void setRepository ( String repository ) { this . repository = repository ; } public void setIU ( String iu ) { this . iu = iu ; } public void setFailonerror ( boolean failonerror ) { this . failonerror = failonerror ; } } </s>
<s> package org . eclim . installer . ant ; public class UnzipTask extends org . formic . ant . UnzipTask { public void addFeatureset ( FeatureSet set ) { addPatternset ( set ) ; } } </s>
<s> package org . eclim . installer . ant ; import org . apache . tools . ant . types . PatternSet ; import org . formic . InstallContext ; import org . formic . Installer ; public class FeatureSet extends PatternSet { public FeatureSet ( ) { super ( ) ; createInclude ( ) . setName ( "<STR_LIT>" ) ; createInclude ( ) . setName ( "<STR_LIT>" ) ; createInclude ( ) . setName ( "<STR_LIT>" ) ; createInclude ( ) . setName ( "<STR_LIT>" ) ; createInclude ( ) . setName ( "<STR_LIT>" ) ; createInclude ( ) . setName ( "<STR_LIT>" ) ; InstallContext context = Installer . getContext ( ) ; String [ ] keys = context . getKeysByPrefix ( "<STR_LIT>" ) ; for ( int ii = <NUM_LIT:0> ; ii < keys . length ; ii ++ ) { String key = keys [ ii ] ; Boolean value = Boolean . valueOf ( context . getValue ( key ) . toString ( ) ) ; if ( value . booleanValue ( ) ) { String name = "<STR_LIT>" + key . substring ( key . indexOf ( '<CHAR_LIT:.>' ) + <NUM_LIT:1> ) ; createInclude ( ) . setName ( name + "<STR_LIT>" ) ; createInclude ( ) . setName ( name + "<STR_LIT>" ) ; } } } } </s>
<s> package org . eclim . installer . ant ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . IOException ; import java . io . OutputStream ; import java . net . Socket ; import java . util . Iterator ; import org . apache . commons . io . IOUtils ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . Task ; public class ShutdownTask extends Task { private static final long WAIT_TIME = <NUM_LIT> ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void execute ( ) throws BuildException { FileReader reader = null ; try { File instances = new File ( System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ) ; int count = <NUM_LIT:0> ; if ( instances . exists ( ) ) { reader = new FileReader ( instances ) ; for ( Iterator < String > ii = IOUtils . lineIterator ( reader ) ; ii . hasNext ( ) ; ) { count ++ ; String instance = ii . next ( ) ; try { log ( "<STR_LIT>" + instance ) ; int port = Integer . parseInt ( instance . replaceFirst ( "<STR_LIT>" , "<STR_LIT>" ) ) ; shutdown ( port ) ; } catch ( Exception e ) { log ( "<STR_LIT>" + instance + "<STR_LIT>" + e . getClass ( ) . getName ( ) + "<STR_LIT:U+0020-U+0020>" + e . getMessage ( ) ) ; } } } if ( count == <NUM_LIT:0> ) { try { shutdown ( <NUM_LIT> ) ; } catch ( Exception e ) { log ( "<STR_LIT>" + e . getClass ( ) . getName ( ) + "<STR_LIT:U+0020-U+0020>" + e . getMessage ( ) ) ; } } } catch ( FileNotFoundException fnfe ) { log ( "<STR_LIT>" ) ; } finally { IOUtils . closeQuietly ( reader ) ; } } private void shutdown ( int port ) throws Exception { Socket socket = null ; try { socket = new Socket ( "<STR_LIT:localhost>" , port ) ; OutputStream out = socket . getOutputStream ( ) ; out . write ( nailgunPacket ( '<CHAR_LIT:A>' , "<STR_LIT>" ) ) ; out . write ( nailgunPacket ( '<CHAR_LIT:A>' , "<STR_LIT>" ) ) ; out . write ( nailgunPacket ( '<CHAR_LIT>' , "<STR_LIT>" ) ) ; out . flush ( ) ; Thread . sleep ( WAIT_TIME ) ; } finally { try { socket . close ( ) ; } catch ( IOException ioe ) { } } } private byte [ ] nailgunPacket ( char type , String value ) { int length = value . length ( ) ; byte [ ] packet = new byte [ <NUM_LIT:5> + length ] ; packet [ <NUM_LIT:0> ] = ( byte ) ( ( length > > <NUM_LIT:24> ) & <NUM_LIT> ) ; packet [ <NUM_LIT:1> ] = ( byte ) ( ( length > > <NUM_LIT:16> ) & <NUM_LIT> ) ; packet [ <NUM_LIT:2> ] = ( byte ) ( ( length > > <NUM_LIT:8> ) & <NUM_LIT> ) ; packet [ <NUM_LIT:3> ] = ( byte ) ( length & <NUM_LIT> ) ; packet [ <NUM_LIT:4> ] = ( byte ) type ; System . arraycopy ( value . getBytes ( ) , <NUM_LIT:0> , packet , <NUM_LIT:5> , length ) ; return packet ; } } </s>
<s> package org . eclim . installer . ant ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . Task ; import org . eclim . installer . step . command . Command ; import org . eclim . installer . step . command . InstallCommand ; public class InstallIUTask extends Task { private String repository ; private String iu ; public void execute ( ) throws BuildException { if ( iu == null || repository == null ) { throw new BuildException ( "<STR_LIT>" ) ; } Command command = null ; try { log ( "<STR_LIT>" + iu + "<STR_LIT:...>" ) ; command = new InstallCommand ( null , repository , iu , "<STR_LIT>" ) ; command . start ( ) ; command . join ( ) ; if ( command . getReturnCode ( ) != <NUM_LIT:0> ) { throw new BuildException ( "<STR_LIT>" + command . getErrorMessage ( ) + "<STR_LIT>" + command . getResult ( ) ) ; } } catch ( BuildException e ) { throw e ; } catch ( Exception e ) { throw new BuildException ( e ) ; } finally { if ( command != null ) { command . destroy ( ) ; } } } public void setRepository ( String repository ) { this . repository = repository ; } public void setIU ( String iu ) { this . iu = iu ; } } </s>
<s> package org . eclim . installer . ant ; import java . io . File ; import java . io . FilenameFilter ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . Project ; import org . apache . tools . ant . ProjectComponent ; import org . apache . tools . ant . taskdefs . condition . Condition ; import org . eclim . installer . step . EclipseInfo ; import org . formic . Installer ; public class IsInstalled extends ProjectComponent implements Condition { private String feature ; public boolean eval ( ) throws BuildException { if ( feature == null ) { throw new BuildException ( "<STR_LIT>" ) ; } EclipseInfo info = ( EclipseInfo ) Installer . getContext ( ) . getValue ( "<STR_LIT>" ) ; if ( info != null && info . hasFeature ( feature ) ) { return true ; } Project project = Installer . getProject ( ) ; String [ ] names = new File ( project . replaceProperties ( "<STR_LIT>" ) ) . list ( new FilenameFilter ( ) { public boolean accept ( File dir , String name ) { return name . startsWith ( feature + "<STR_LIT:_>" ) ; } } ) ; return names != null && names . length > <NUM_LIT:0> ; } public void setFeature ( String feature ) { this . feature = feature ; } } </s>
<s> package org . eclim . installer . ant ; import java . util . HashMap ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . MagicNames ; import org . apache . tools . ant . Task ; import org . eclim . installer . step . EclipseInfo ; import org . eclim . installer . step . FeatureProvider ; import org . formic . Installer ; import org . formic . wizard . step . shared . Feature ; public class UnattendedInstallTask extends Task { public void execute ( ) throws BuildException { boolean uninstall = false ; if ( Installer . getProject ( ) == null ) { Installer . setProject ( getProject ( ) ) ; String targets = getProject ( ) . getProperty ( MagicNames . PROJECT_INVOKED_TARGETS ) ; uninstall = "<STR_LIT>" . equals ( targets ) ; } else { uninstall = Installer . isUninstall ( ) ; } EclipseInfo info = ( EclipseInfo ) Installer . getContext ( ) . getValue ( "<STR_LIT>" ) ; if ( info == null ) { try { log ( "<STR_LIT>" ) ; if ( EclipseInfo . installInstallerPlugin ( ) ) { log ( "<STR_LIT>" ) ; info = EclipseInfo . gatherEclipseInfo ( ) ; log ( "<STR_LIT>" ) ; Installer . getContext ( ) . setValue ( "<STR_LIT>" , info ) ; } } catch ( Exception e ) { throw new BuildException ( e ) ; } if ( ! uninstall ) { FeatureProvider provider = new FeatureProvider ( ) ; Feature [ ] features = provider . getFeatures ( ) ; HashMap < String , Feature > featureMap = new HashMap < String , Feature > ( ) ; for ( Feature feature : features ) { featureMap . put ( feature . getKey ( ) , feature ) ; } log ( "<STR_LIT>" ) ; for ( Feature feature : features ) { boolean enabled = feature . isEnabled ( ) ; if ( "<STR_LIT>" . equals ( feature . getKey ( ) ) ) { enabled = "<STR_LIT:true>" . equals ( Installer . getContext ( ) . getValue ( "<STR_LIT>" ) ) ; } if ( enabled ) { enabled = dependenciesEnabled ( feature , featureMap ) ; } Installer . getContext ( ) . setValue ( "<STR_LIT>" + feature . getKey ( ) , enabled ) ; if ( enabled ) { log ( "<STR_LIT:U+0020U+0020>" + feature . getKey ( ) ) ; } } } } } private boolean dependenciesEnabled ( Feature feature , HashMap < String , Feature > featureMap ) { boolean enabled = true ; String [ ] dependencies = feature . getDependencies ( ) ; if ( dependencies != null ) { for ( String dep : dependencies ) { Feature dependency = featureMap . get ( dep ) ; if ( ! dependency . isEnabled ( ) || ! dependenciesEnabled ( dependency , featureMap ) ) { enabled = false ; break ; } } } return enabled ; } } </s>
<s> package org . eclim . installer . step ; import java . awt . Component ; import java . io . File ; import java . util . Properties ; import javax . swing . JFileChooser ; import javax . swing . JLabel ; import javax . swing . JPanel ; import org . apache . commons . io . FilenameUtils ; import org . apache . commons . lang . SystemUtils ; import org . apache . tools . ant . taskdefs . condition . Os ; import org . formic . Installer ; import org . formic . wizard . form . GuiForm ; import org . formic . wizard . form . Validator ; import org . formic . wizard . form . gui . component . FileChooser ; import org . formic . wizard . form . validator . ValidatorBuilder ; import org . formic . wizard . step . AbstractGuiStep ; import net . miginfocom . swing . MigLayout ; public class EclipseStep extends AbstractGuiStep { private static final String [ ] WINDOWS_ECLIPSES = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , } ; private static final String [ ] UNIX_ECLIPSES = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , SystemUtils . USER_HOME + "<STR_LIT>" , "<STR_LIT>" , } ; private FileChooser eclipseHomeChooser ; public EclipseStep ( String name , Properties properties ) { super ( name , properties ) ; } public Component init ( ) { final JPanel panel = new JPanel ( new MigLayout ( "<STR_LIT>" , "<STR_LIT>" ) ) ; GuiForm form = createForm ( ) ; String home = fieldName ( "<STR_LIT>" ) ; eclipseHomeChooser = new FileChooser ( JFileChooser . DIRECTORIES_ONLY ) ; panel . add ( form . createMessagePanel ( ) , "<STR_LIT>" ) ; panel . add ( new JLabel ( Installer . getString ( home ) ) ) ; panel . add ( eclipseHomeChooser ) ; form . bind ( home , eclipseHomeChooser . getTextField ( ) , new ValidatorBuilder ( ) . required ( ) . isDirectory ( ) . validator ( new EclipseHomeValidator ( ) ) . validator ( ) ) ; String eclipseHomeDefault = getDefaultEclipseHome ( ) ; eclipseHomeChooser . getTextField ( ) . setText ( eclipseHomeDefault ) ; return panel ; } public void displayed ( ) { eclipseHomeChooser . getTextField ( ) . requestFocus ( ) ; } public boolean proceed ( ) { boolean proceed = super . proceed ( ) ; String home = ( String ) Installer . getContext ( ) . getValue ( "<STR_LIT>" ) ; home = FilenameUtils . normalizeNoEndSeparator ( home ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; Installer . getContext ( ) . setValue ( "<STR_LIT>" , home ) ; return proceed ; } private String getDefaultEclipseHome ( ) { String home = Installer . getEnvironmentVariable ( "<STR_LIT>" ) ; if ( home == null || home . trim ( ) . length ( ) == <NUM_LIT:0> ) { if ( Os . isFamily ( Os . FAMILY_WINDOWS ) ) { for ( int ii = <NUM_LIT:0> ; ii < WINDOWS_ECLIPSES . length ; ii ++ ) { if ( new File ( WINDOWS_ECLIPSES [ ii ] ) . exists ( ) ) { home = WINDOWS_ECLIPSES [ ii ] ; break ; } } } else { for ( int ii = <NUM_LIT:0> ; ii < UNIX_ECLIPSES . length ; ii ++ ) { if ( new File ( UNIX_ECLIPSES [ ii ] ) . exists ( ) ) { home = UNIX_ECLIPSES [ ii ] ; break ; } } } } return home ; } private class EclipseHomeValidator implements Validator { public boolean isValid ( Object value ) { String folder = ( String ) value ; if ( folder != null && folder . trim ( ) . length ( ) > <NUM_LIT:0> ) { File plugins = new File ( FilenameUtils . concat ( folder , "<STR_LIT>" ) ) ; if ( plugins . exists ( ) && plugins . isDirectory ( ) ) { return EclipseUtils . findEclipseLauncherJar ( folder ) != null ; } } return false ; } public String getErrorMessage ( ) { return getName ( ) + "<STR_LIT>" ; } } } </s>
<s> package org . eclim . installer . step ; import java . util . Properties ; import org . formic . Installer ; import org . formic . wizard . step . gui . InstallStep ; import foxtrot . Worker ; public class EclipseInfoStep extends InstallStep { public EclipseInfoStep ( String name , Properties properties ) { super ( name , properties ) ; } public void displayed ( ) { setBusy ( true ) ; setPreviousEnabled ( false ) ; EclipseInfo info = null ; try { overallLabel . setText ( "<STR_LIT>" ) ; overallProgress . setValue ( <NUM_LIT:0> ) ; taskLabel . setText ( "<STR_LIT>" ) ; taskProgress . setValue ( <NUM_LIT:0> ) ; taskProgress . setIndeterminate ( true ) ; info = ( EclipseInfo ) Worker . post ( new foxtrot . Task ( ) { public Object run ( ) throws Exception { overallLabel . setText ( "<STR_LIT>" ) ; if ( EclipseInfo . installInstallerPlugin ( ) ) { overallProgress . setMaximum ( <NUM_LIT:2> ) ; overallProgress . setValue ( <NUM_LIT:1> ) ; overallLabel . setText ( "<STR_LIT>" ) ; EclipseInfo info = EclipseInfo . gatherEclipseInfo ( ) ; overallLabel . setText ( "<STR_LIT>" ) ; overallProgress . setValue ( <NUM_LIT:2> ) ; taskProgress . setIndeterminate ( false ) ; taskProgress . setMaximum ( <NUM_LIT:1> ) ; taskProgress . setValue ( <NUM_LIT:1> ) ; return info ; } return null ; } } ) ; Installer . getContext ( ) . setValue ( "<STR_LIT>" , info ) ; } catch ( Exception e ) { setError ( e ) ; } finally { setValid ( info != null ) ; setBusy ( false ) ; taskProgress . setIndeterminate ( false ) ; } } } </s>
<s> package org . eclim . installer . step ; import java . util . Properties ; public class FeatureListStep extends org . formic . wizard . step . gui . FeatureListStep { public FeatureListStep ( String name , Properties properties ) { super ( name , properties ) ; setPreviousEnabled ( false ) ; } } </s>