├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs ├── org.eclipse.core.runtime.prefs ├── org.eclipse.jdt.core.prefs ├── org.eclipse.jdt.ui.prefs └── org.eclipse.pde.prefs ├── META-INF └── MANIFEST.MF ├── README.txt ├── build.properties ├── build_js_with_jarjar.xml ├── docs ├── index.html ├── script-dialog.png ├── style.css └── updates │ ├── add-site.png │ ├── features │ └── org.eclipsescript_1.0.12-feature.jar │ ├── generateSite.py │ ├── index.html │ ├── plugins │ └── org.eclipsescript_1.0.12.jar │ └── site.xml ├── icons ├── remove_all_terminated.gif └── run_script.gif ├── js.jar ├── plugin.properties ├── plugin.xml └── src └── org └── eclipsescript ├── core ├── Activator.java ├── Autostart.java ├── OpenScriptDialogHandler.java ├── RunCurrentHandler.java └── RunLastHandler.java ├── javascript ├── CustomContextFactory.java ├── JavaScriptLanguageSupport.java └── JavascriptRuntime.java ├── messages ├── Messages.java └── messages.properties ├── preferences ├── EclipseScriptPreferencePage.java ├── Messages.java ├── PreferenceConstants.java ├── PreferenceInitializer.java └── messages.properties ├── scriptobjects ├── Console.java ├── Eclipse.java ├── Editors.java ├── Resources.java ├── Runtime.java ├── Window.java └── Xml.java ├── scripts ├── IScriptLanguageSupport.java ├── IScriptRuntime.java ├── MarkerManager.java ├── ScriptClassLoader.java ├── ScriptException.java ├── ScriptLanguageHandler.java ├── ScriptMetadata.java └── ScriptStore.java ├── ui ├── CloseConsolePageParticipant.java ├── ErrorDetailsDialog.java ├── ErrorHandlingHandler.java ├── QuickAccessElement.java ├── QuickAccessEntry.java ├── QuickAccessProvider.java ├── QuickScriptDialog.java └── QuickScriptProvider.java └── util ├── EclipseUtils.java └── JavaUtils.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.eclipsescript 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Sun Aug 28 22:15:32 CEST 2011 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | #Sun Aug 28 22:15:32 CEST 2011 2 | eclipse.preferences.version=1 3 | line.separator=\n 4 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore 3 | org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull 4 | org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault 5 | org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable 6 | org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled 7 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 8 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 9 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 10 | org.eclipse.jdt.core.compiler.compliance=1.6 11 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 12 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 13 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 14 | org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning 15 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 16 | org.eclipse.jdt.core.compiler.problem.autoboxing=ignore 17 | org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning 18 | org.eclipse.jdt.core.compiler.problem.deadCode=warning 19 | org.eclipse.jdt.core.compiler.problem.deprecation=warning 20 | org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled 21 | org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled 22 | org.eclipse.jdt.core.compiler.problem.discouragedReference=warning 23 | org.eclipse.jdt.core.compiler.problem.emptyStatement=warning 24 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 25 | org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore 26 | org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning 27 | org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled 28 | org.eclipse.jdt.core.compiler.problem.fieldHiding=warning 29 | org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning 30 | org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning 31 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=error 32 | org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning 33 | org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled 34 | org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning 35 | org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning 36 | org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning 37 | org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning 38 | org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning 39 | org.eclipse.jdt.core.compiler.problem.missingDefaultCase=warning 40 | org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning 41 | org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled 42 | org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning 43 | org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning 44 | org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled 45 | org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning 46 | org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning 47 | org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning 48 | org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning 49 | org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning 50 | org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error 51 | org.eclipse.jdt.core.compiler.problem.nullReference=warning 52 | org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error 53 | org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning 54 | org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning 55 | org.eclipse.jdt.core.compiler.problem.parameterAssignment=warning 56 | org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning 57 | org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning 58 | org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning 59 | org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning 60 | org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning 61 | org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning 62 | org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore 63 | org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning 64 | org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore 65 | org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=warning 66 | org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled 67 | org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning 68 | org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled 69 | org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled 70 | org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning 71 | org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning 72 | org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled 73 | org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning 74 | org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning 75 | org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=warning 76 | org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning 77 | org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore 78 | org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning 79 | org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore 80 | org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning 81 | org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled 82 | org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled 83 | org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled 84 | org.eclipse.jdt.core.compiler.problem.unusedImport=warning 85 | org.eclipse.jdt.core.compiler.problem.unusedLabel=warning 86 | org.eclipse.jdt.core.compiler.problem.unusedLocal=warning 87 | org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore 88 | org.eclipse.jdt.core.compiler.problem.unusedParameter=warning 89 | org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled 90 | org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled 91 | org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled 92 | org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning 93 | org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning 94 | org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning 95 | org.eclipse.jdt.core.compiler.source=1.6 96 | org.eclipse.jdt.core.formatter.align_type_members_on_columns=false 97 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 98 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 99 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 100 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 101 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 102 | org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 103 | org.eclipse.jdt.core.formatter.alignment_for_assignment=0 104 | org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 105 | org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 106 | org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 107 | org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 108 | org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 109 | org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 110 | org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 111 | org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 112 | org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 113 | org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 114 | org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 115 | org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 116 | org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 117 | org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 118 | org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 119 | org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 120 | org.eclipse.jdt.core.formatter.blank_lines_after_package=1 121 | org.eclipse.jdt.core.formatter.blank_lines_before_field=0 122 | org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 123 | org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 124 | org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 125 | org.eclipse.jdt.core.formatter.blank_lines_before_method=1 126 | org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 127 | org.eclipse.jdt.core.formatter.blank_lines_before_package=0 128 | org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 129 | org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 130 | org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line 131 | org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line 132 | org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line 133 | org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line 134 | org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line 135 | org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line 136 | org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line 137 | org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line 138 | org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line 139 | org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line 140 | org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line 141 | org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false 142 | org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false 143 | org.eclipse.jdt.core.formatter.comment.format_block_comments=true 144 | org.eclipse.jdt.core.formatter.comment.format_header=false 145 | org.eclipse.jdt.core.formatter.comment.format_html=true 146 | org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true 147 | org.eclipse.jdt.core.formatter.comment.format_line_comments=true 148 | org.eclipse.jdt.core.formatter.comment.format_source_code=true 149 | org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true 150 | org.eclipse.jdt.core.formatter.comment.indent_root_tags=true 151 | org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert 152 | org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert 153 | org.eclipse.jdt.core.formatter.comment.line_length=120 154 | org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true 155 | org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true 156 | org.eclipse.jdt.core.formatter.compact_else_if=true 157 | org.eclipse.jdt.core.formatter.continuation_indentation=2 158 | org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 159 | org.eclipse.jdt.core.formatter.disabling_tag= 160 | org.eclipse.jdt.core.formatter.enabling_tag= 161 | org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false 162 | org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true 163 | org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true 164 | org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true 165 | org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true 166 | org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true 167 | org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true 168 | org.eclipse.jdt.core.formatter.indent_empty_lines=false 169 | org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true 170 | org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true 171 | org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true 172 | org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false 173 | org.eclipse.jdt.core.formatter.indentation.size=4 174 | org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert 175 | org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert 176 | org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert 177 | org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert 178 | org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert 179 | org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert 180 | org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert 181 | org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert 182 | org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert 183 | org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert 184 | org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert 185 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert 186 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert 187 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert 188 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert 189 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert 190 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert 191 | org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert 192 | org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert 193 | org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert 194 | org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert 195 | org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert 196 | org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert 197 | org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert 198 | org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert 199 | org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert 200 | org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert 201 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert 202 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert 203 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert 204 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert 205 | org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert 206 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert 207 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert 208 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert 209 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert 210 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert 211 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert 212 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert 213 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert 214 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert 215 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert 216 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert 217 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert 218 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert 219 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert 220 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert 221 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert 222 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert 223 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert 224 | org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert 225 | org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert 226 | org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert 227 | org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert 228 | org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert 229 | org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert 230 | org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert 231 | org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert 232 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert 233 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert 234 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert 235 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert 236 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert 237 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert 238 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert 239 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert 240 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert 241 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert 242 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert 243 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert 244 | org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert 245 | org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert 246 | org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert 247 | org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert 248 | org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert 249 | org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert 250 | org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert 251 | org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert 252 | org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert 253 | org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert 254 | org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert 255 | org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert 256 | org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert 257 | org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert 258 | org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert 259 | org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert 260 | org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert 261 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert 262 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert 263 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert 264 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert 265 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert 266 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert 267 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert 268 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert 269 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert 270 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert 271 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert 272 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert 273 | org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert 274 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert 275 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert 276 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert 277 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert 278 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert 279 | org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert 280 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert 281 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert 282 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert 283 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert 284 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert 285 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert 286 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert 287 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert 288 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert 289 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert 290 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert 291 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert 292 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert 293 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert 294 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert 295 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert 296 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert 297 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert 298 | org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert 299 | org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert 300 | org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert 301 | org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert 302 | org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert 303 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert 304 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert 305 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert 306 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert 307 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert 308 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert 309 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert 310 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert 311 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert 312 | org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert 313 | org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert 314 | org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert 315 | org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert 316 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert 317 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert 318 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert 319 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert 320 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert 321 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert 322 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert 323 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert 324 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert 325 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert 326 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert 327 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert 328 | org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert 329 | org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert 330 | org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert 331 | org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert 332 | org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert 333 | org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert 334 | org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert 335 | org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert 336 | org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert 337 | org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert 338 | org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert 339 | org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert 340 | org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert 341 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert 342 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert 343 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert 344 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert 345 | org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert 346 | org.eclipse.jdt.core.formatter.join_lines_in_comments=true 347 | org.eclipse.jdt.core.formatter.join_wrapped_lines=true 348 | org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false 349 | org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false 350 | org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false 351 | org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false 352 | org.eclipse.jdt.core.formatter.lineSplit=120 353 | org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false 354 | org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false 355 | org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 356 | org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 357 | org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true 358 | org.eclipse.jdt.core.formatter.tabulation.char=tab 359 | org.eclipse.jdt.core.formatter.tabulation.size=4 360 | org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false 361 | org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true 362 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | #Mon Mar 22 18:31:04 CET 2010 2 | cleanup.add_default_serial_version_id=true 3 | cleanup.add_generated_serial_version_id=false 4 | cleanup.add_missing_annotations=true 5 | cleanup.add_missing_deprecated_annotations=true 6 | cleanup.add_missing_methods=false 7 | cleanup.add_missing_nls_tags=false 8 | cleanup.add_missing_override_annotations=true 9 | cleanup.add_missing_override_annotations_interface_methods=true 10 | cleanup.add_serial_version_id=false 11 | cleanup.always_use_blocks=true 12 | cleanup.always_use_parentheses_in_expressions=false 13 | cleanup.always_use_this_for_non_static_field_access=false 14 | cleanup.always_use_this_for_non_static_method_access=false 15 | cleanup.convert_to_enhanced_for_loop=false 16 | cleanup.correct_indentation=true 17 | cleanup.format_source_code=true 18 | cleanup.format_source_code_changes_only=false 19 | cleanup.make_local_variable_final=true 20 | cleanup.make_parameters_final=false 21 | cleanup.make_private_fields_final=true 22 | cleanup.make_type_abstract_if_missing_method=false 23 | cleanup.make_variable_declarations_final=false 24 | cleanup.never_use_blocks=false 25 | cleanup.never_use_parentheses_in_expressions=true 26 | cleanup.organize_imports=true 27 | cleanup.qualify_static_field_accesses_with_declaring_class=false 28 | cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 29 | cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 30 | cleanup.qualify_static_member_accesses_with_declaring_class=true 31 | cleanup.qualify_static_method_accesses_with_declaring_class=false 32 | cleanup.remove_private_constructors=true 33 | cleanup.remove_trailing_whitespaces=true 34 | cleanup.remove_trailing_whitespaces_all=true 35 | cleanup.remove_trailing_whitespaces_ignore_empty=false 36 | cleanup.remove_unnecessary_casts=true 37 | cleanup.remove_unnecessary_nls_tags=true 38 | cleanup.remove_unused_imports=true 39 | cleanup.remove_unused_local_variables=false 40 | cleanup.remove_unused_private_fields=true 41 | cleanup.remove_unused_private_members=false 42 | cleanup.remove_unused_private_methods=true 43 | cleanup.remove_unused_private_types=true 44 | cleanup.sort_members=true 45 | cleanup.sort_members_all=true 46 | cleanup.use_blocks=false 47 | cleanup.use_blocks_only_for_return_and_throw=false 48 | cleanup.use_parentheses_in_expressions=false 49 | cleanup.use_this_for_non_static_field_access=false 50 | cleanup.use_this_for_non_static_field_access_only_if_necessary=true 51 | cleanup.use_this_for_non_static_method_access=false 52 | cleanup.use_this_for_non_static_method_access_only_if_necessary=true 53 | cleanup_profile=_Custom 54 | cleanup_settings_version=2 55 | eclipse.preferences.version=1 56 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true 57 | formatter_profile=_Eclipse [long-lines] 58 | formatter_settings_version=11 59 | sp_cleanup.add_default_serial_version_id=true 60 | sp_cleanup.add_generated_serial_version_id=false 61 | sp_cleanup.add_missing_annotations=true 62 | sp_cleanup.add_missing_deprecated_annotations=true 63 | sp_cleanup.add_missing_methods=false 64 | sp_cleanup.add_missing_nls_tags=false 65 | sp_cleanup.add_missing_override_annotations=true 66 | sp_cleanup.add_missing_override_annotations_interface_methods=true 67 | sp_cleanup.add_serial_version_id=false 68 | sp_cleanup.always_use_blocks=true 69 | sp_cleanup.always_use_parentheses_in_expressions=false 70 | sp_cleanup.always_use_this_for_non_static_field_access=false 71 | sp_cleanup.always_use_this_for_non_static_method_access=false 72 | sp_cleanup.convert_to_enhanced_for_loop=false 73 | sp_cleanup.correct_indentation=true 74 | sp_cleanup.format_source_code=true 75 | sp_cleanup.format_source_code_changes_only=false 76 | sp_cleanup.make_local_variable_final=false 77 | sp_cleanup.make_parameters_final=false 78 | sp_cleanup.make_private_fields_final=true 79 | sp_cleanup.make_type_abstract_if_missing_method=false 80 | sp_cleanup.make_variable_declarations_final=true 81 | sp_cleanup.never_use_blocks=false 82 | sp_cleanup.never_use_parentheses_in_expressions=true 83 | sp_cleanup.on_save_use_additional_actions=true 84 | sp_cleanup.organize_imports=true 85 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false 86 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 87 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 88 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false 89 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 90 | sp_cleanup.remove_private_constructors=true 91 | sp_cleanup.remove_trailing_whitespaces=true 92 | sp_cleanup.remove_trailing_whitespaces_all=true 93 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false 94 | sp_cleanup.remove_unnecessary_casts=true 95 | sp_cleanup.remove_unnecessary_nls_tags=false 96 | sp_cleanup.remove_unused_imports=true 97 | sp_cleanup.remove_unused_local_variables=false 98 | sp_cleanup.remove_unused_private_fields=true 99 | sp_cleanup.remove_unused_private_members=false 100 | sp_cleanup.remove_unused_private_methods=true 101 | sp_cleanup.remove_unused_private_types=true 102 | sp_cleanup.sort_members=true 103 | sp_cleanup.sort_members_all=true 104 | sp_cleanup.use_blocks=false 105 | sp_cleanup.use_blocks_only_for_return_and_throw=false 106 | sp_cleanup.use_parentheses_in_expressions=false 107 | sp_cleanup.use_this_for_non_static_field_access=false 108 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true 109 | sp_cleanup.use_this_for_non_static_method_access=false 110 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 111 | -------------------------------------------------------------------------------- /.settings/org.eclipse.pde.prefs: -------------------------------------------------------------------------------- 1 | #Tue Mar 16 10:05:26 CET 2010 2 | compilers.f.unresolved-features=1 3 | compilers.f.unresolved-plugins=1 4 | compilers.incompatible-environment=1 5 | compilers.p.build=1 6 | compilers.p.deprecated=1 7 | compilers.p.discouraged-class=1 8 | compilers.p.internal=1 9 | compilers.p.missing-packages=2 10 | compilers.p.missing-version-export-package=2 11 | compilers.p.missing-version-import-package=2 12 | compilers.p.missing-version-require-bundle=2 13 | compilers.p.no-required-att=0 14 | compilers.p.not-externalized-att=1 15 | compilers.p.unknown-attribute=1 16 | compilers.p.unknown-class=1 17 | compilers.p.unknown-element=1 18 | compilers.p.unknown-identifier=1 19 | compilers.p.unknown-resource=1 20 | compilers.p.unresolved-ex-points=0 21 | compilers.p.unresolved-import=0 22 | compilers.s.create-docs=false 23 | compilers.s.doc-folder=doc 24 | compilers.s.open-tags=1 25 | eclipse.preferences.version=1 26 | -------------------------------------------------------------------------------- /META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: %pluginName 4 | Bundle-SymbolicName: org.eclipsescript; singleton:=true 5 | Bundle-Version: 1.0.12 6 | Bundle-Activator: org.eclipsescript.core.Activator 7 | Bundle-Vendor: %bundleVendor 8 | Require-Bundle: org.eclipse.ui;bundle-version="3.3", 9 | org.eclipse.core.runtime;bundle-version="3.6.0", 10 | org.eclipse.core.resources;bundle-version="3.3", 11 | org.eclipse.ui.editors;bundle-version="3.3", 12 | org.eclipse.jface.text;bundle-version="3.3", 13 | org.eclipse.ui.ide;bundle-version="3.3", 14 | org.eclipse.ui.console;bundle-version="3.2" 15 | Bundle-RequiredExecutionEnvironment: JavaSE-1.6 16 | Bundle-ActivationPolicy: lazy 17 | Bundle-ClassPath: ., 18 | js.jar 19 | Bundle-Localization: plugin 20 | DynamicImport-Package: * 21 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Eclipse plugin for scripting using javascript. 2 | 3 | Read more at fornwall.github.io/eclipsescript/. 4 | 5 | For development, an eclipse project containing some tests are available at: 6 | https://github.com/fornwall/eclipsescript-tests 7 | 8 | This plug-in currently uses a re-packaged version of rhino in js.jar. This was built from rhino master git on 2016-01-12 using: 9 | (1) Get the source (https://developer.mozilla.org/en-US/docs/Rhino/Download_Rhino?redirectlocale=en-US&redirectslug=RhinoDownload): 10 | git clone https://github.com/mozilla/rhino.git 11 | cd rhino 12 | (2) Change string references to class: 13 | perl -p -i -e 's/org\/mozilla\//org\/eclipsescript\/rhino\//g' `find ./ -name *.java` 14 | (3) Build: 15 | ant jar 16 | (4) 17 | cp build/rhino1.7.8-SNAPSHOT/js.jar $ECLIPSESCRIPT/js_orig.jar 18 | cd $ECLIPSESCRIPT 19 | ant -f build_js_with_jarjar.xml 20 | (5) Test the re-packaged rhino from shell with: 21 | java -cp js.jar org.eclipsescript.rhino.javascript.tools.shell.Main 22 | -------------------------------------------------------------------------------- /build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = plugin.xml,\ 4 | META-INF/,\ 5 | .,\ 6 | icons/,\ 7 | plugin.properties,\ 8 | js.jar 9 | -------------------------------------------------------------------------------- /build_js_with_jarjar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | EclipseScript 5 | 6 | 7 | 8 | 9 | 10 |
11 |

EclipseScript

12 | 13 | 24 | 25 | 26 |

About

27 |

EclipseScript is an Eclipse plug-in providing support for scripting the development environment using javascript. It provides a simple API to interact with the editor while also exposing the full Eclipse platform and plug-in system.

28 | 29 |

News

30 |
31 | 32 |
2016-01-12 - Version 1.0.12 released, introducing eclipse.runtime.exec() and eclipse.editors.open()
33 |
The rhino javascript engine has also been updated, which brings in the changes made in rhino 1.7.6 and rhino 1.7.7.
34 |
35 | 36 |

Installing

37 |

Eclipse 3.6 and Java 6 or later is required. Update site URL:

38 | 39 | 40 | 41 |

Writing and running scripts

42 |

EclipseScript scripts are javascript files inside the workspace with the file extension .eclipse.js. As a start, create a new file with the name count-js.eclipse.js and put the following content in it:

43 | 44 | 45 |

To run a script, open the EclipseScript launch dialog by using the shortcut Ctrl+4 (or Cmd+4 on Mac). Start writing the name of the script and execute it by pressing return when the script is selected in the list.

46 | The script dialog 47 | 48 |

Basics of scripting

49 |

Scripting is implemented using version 1.7R4 of the Rhino javascript engine. For more information on using java from Rhino, see the Rhino documentation on the subject.

50 |

Besides this general java <-> javascript bridging, the EclipseScript plug-in injects a global object with the name eclipse exposing a simplified API to interact with the Eclipse development environment. See the below documentation for the eclipse global object.

51 |

Besides using the eclipse global object scripts may access eclipse plug-in classes just as normal java code. Plug-in loading is on demand - when first accessing a class unknown to the runtime, the EclipseScript plug-in will resolve a plug-in providing the class and load it.

52 | 53 |

Example scripts

54 |

Accessing and replacing the currently selected text:

55 | 56 | 57 |

SWT may be used directly:

58 | 59 | 60 |

A plug-in such as JDT is loaded just by using a package from the plug-in:

61 | 62 | 63 |

Debug output to the console:

64 | 65 | 66 |

Operations that may take some time should be run in a background job to avoid blocking the user interface thread:

67 | 68 | 69 |

A script to post the current selection to gisthub:

70 | 71 | 72 |

Example using the java AST and the eclipse markers API:

73 | 74 | 75 |

Finally an example using the java AST to wrap method bodies in timing statements, adding statements to void myMethod() { ... } resulting in void myMethod() { long _startTime = System.currentTimeMillis(); try { ... } finally { long _stopTime = System.currentTimeMillis() - _startTime; System.out.println("Time executing MyClass#myMethod: " + _passedTime) }:

76 | 77 | 78 |

The eclipse global object

79 |

The eclipse object is a global object injected by the EclipseScript plug-in and provides a simplified API to interact with the Eclipse environment compared to accessing the API directly.

80 | 81 |
82 |
eclipse.console.print(String message)
83 |
Function to print a message to the console view.
84 |
eclipse.console.println(String message)
85 |
Function to print a message line to the console view.
86 |
87 | 88 |
89 |
eclipse.editors.clipboard
90 |
String property. The current clipboard text content or null if none - may both be set and read.
91 |
eclipse.editors.document
92 |
Read-only property. The currently selected text document or null if none. An instanceof of IDocument which most notable contains the get() method to get the text of the document and the set(String) method to set the text.
93 |
eclipse.editors.file
94 |
Read-only property. The currently edited file or null if none. An instance of IFile.
95 |
eclipse.editors.insert(String textToInsert)
96 |
Function to insert text at the current cursor position.
97 |
eclipse.editors.open(IFile file)
98 |
Open the specified file in an eclipse editor..
99 |
eclipse.editors.replaceSelection(String newText)
100 |
Function to replace the current selection.
101 |
eclipse.editors.selection
102 |
Read-only property. The current text selection or null if no selection. This object is an instance of ITextSelection and contains the text property for the text, as well as the offset, length, startLine and endLine properties. This property is read-only, use eclipse.editors.replaceSelection(String) to change the content of the current selection. Example: eclipse.window.alert('Selection is ' + eclipse.editors.selection.text + ' and starts at line ' + eclipse.editors.selection.startLine);
103 |
104 | 105 |
106 |
eclipse.resources.currentProject
107 |
Read-only property. The project of the current editor or null if none. An instance of IProject.
108 |
eclipse.resources.read(Object input)
109 |
Function returning a String resulting from reading the input, which may be an URL or an IFile.
110 |
eclipse.resources.filesMatching(String regexp, IResource startingPoint)
111 |
Function returning an array of IFile:s matching the regular expression and which are children of the starting point. Note that both IProject:s are IResource:s, so eclipse.resources.scriptProject and eclipse.resources.currentProject are valid starting points. Use eclipse.resources.workspace.root as starting point to examine the whole workspace.
112 |
eclipse.resources.scriptProject
113 |
Read-only property. The project which the currently executing script is a part of. An instance of IProject.
114 |
eclipse.resources.workspace
115 |
Read-only property. The current eclipse workspace. An instance of IWorkspace.
116 |
117 | 118 |
119 |
eclipse.runtime.include(String ... files)
120 |
Executes one or more script files in the current context. If the path starts with a slash it is workspace-relative, so use eclipse.runtime.include('/' + eclipse.resources.currentProject.name + '/path/to/file') to include project-absolute paths. Otherwise the path is relative to the current script, so use eclipse.runtime.include('file.js') to include a script being side-by-side with the current one.
121 |
eclipse.runtime.die(String message)
122 |
Function to exit the execution of the currently running script while providing a message shown to the user. An example for scripts operating on a selection would be if (eclipse.editor.selection == null) die('Nothing is selected').
123 |
eclipse.runtime.exec(String cmd)
124 |
Execute the specified command in an external process.
125 |
eclipse.runtime.exit()
126 |
Function to exit the execution of the currently running script.
127 |
eclipse.runtime.schedule(IJobRunnable runnable)
128 |
Function to run a task in a background, non-ui thread. See the IJobRunnable class documentation for more info, though the example given previously should cover many use cases.
129 |
eclipse.runtime.putGlobal(String key, Object value), eclipse.runtime.getGlobal(String key)
130 |
Functions to manipulate global state bound to the lifetime of the whole eclipse process (that is, outliving the current script execution).
131 |
132 | 133 |
134 |
eclipse.window.alert(String message)
135 |
The normal javascript alert function as available in browsers.
136 |
eclipse.window.confirm(String question)
137 |
The normal javascript confirm function as available in browsers.
138 |
eclipse.window.open(String url)
139 |
The normal javascript open function to open a browser.
140 |
eclipse.window.prompt(String message, String initialValue = "")
141 |
The normal javascript prompt function as available in browsers.
142 |
143 | 144 |
145 |
eclipse.xml.parse(Object input)
146 |
Parse the input into a org.w3c.dom.Document object.
147 |
148 | 149 |

Source code

150 |

Source code is available at https://github.com/fornwall/eclipsescript/.

151 | 152 | 153 |

Feedback

154 |

Comments, ideas and bug reports can be filed at the issue tracker.

155 | 156 |
157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /docs/script-dialog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fornwall/eclipsescript/0737f118debe507c2b66cc20edda31ce3e8541cf/docs/script-dialog.png -------------------------------------------------------------------------------- /docs/style.css: -------------------------------------------------------------------------------- 1 | h1 { text-align: center; } 2 | h1, h2 { background-color: #E5ECF9; color: black; border-top: 1px solid #6F6F6F; border-bottom: 1px solid #6F6F6F; padding: 0.4em; } 3 | hr { margin-top: 4em; } 4 | dt { background-color: white; color: #65738A; font-weight: bold; } 5 | img { margin: 0.5em; border: none; } 6 | p img, li img { vertical-align: middle; margin: 0; } 7 | -------------------------------------------------------------------------------- /docs/updates/add-site.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fornwall/eclipsescript/0737f118debe507c2b66cc20edda31ce3e8541cf/docs/updates/add-site.png -------------------------------------------------------------------------------- /docs/updates/features/org.eclipsescript_1.0.12-feature.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fornwall/eclipsescript/0737f118debe507c2b66cc20edda31ce3e8541cf/docs/updates/features/org.eclipsescript_1.0.12-feature.jar -------------------------------------------------------------------------------- /docs/updates/generateSite.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Create Eclipse feature jars from plug-in jars in the plugins folder 3 | # See: http://www.eclipse.org/articles/Article-Update/keeping-up-to-date.html 4 | # for more information about features and update sites 5 | 6 | # for ganymede compliance, see 7 | # https://bugs.eclipse.org/bugs/show_bug.cgi?id=236142 8 | # http://wiki.eclipse.org/WTP/What_we_have_learned_(to_love)_about_P2 9 | 10 | import re 11 | from glob import glob 12 | from os import stat, remove 13 | from xml.dom.minidom import parseString 14 | from zipfile import ZipFile 15 | 16 | 17 | descriptions = { 18 | 'org.eclipsescript': 'Plug-in allowing scripting of the Eclipse IDE using javascript.', 19 | 'org.mozilla.javascript': 'Mozilla Rhino 1.7r2.' 20 | } 21 | 22 | 23 | def readProps(lines): 24 | result = {} 25 | for line in lines: 26 | if '=' in line and not line.startswith('#'): 27 | line = line.strip() 28 | i = line.index('=') 29 | result[line[0:i].strip()] = line[i+1:len(line)].strip() 30 | return result 31 | 32 | def unzippedSize(zipFile): 33 | "Return the size of the zipFile it it were to be uncompressed" 34 | return sum([info.file_size for info in zipFile.infolist()]) 35 | 36 | def featureXMLFromPlugin(pluginJarFileName): 37 | "Return a feature.xml for the ZipFile passed" 38 | print 'Parsing ' + pluginJarFileName 39 | result = '' 40 | pluginJar = ZipFile(pluginJarFileName) 41 | manifest = pluginJar.read('META-INF/MANIFEST.MF') 42 | for line in manifest.split("\n"): 43 | if line.find('Bundle-SymbolicName') != -1: 44 | featureID = re.match('Bundle-SymbolicName: ([^;]*)', line).group(1).strip() 45 | print 'FeatureId: ' + featureID 46 | if line.find('Bundle-Version:') != -1: 47 | featureVersion = re.match('Bundle-Version: (.*)', line).group(1).strip() 48 | print 'Version: ' + featureVersion 49 | if line.find('Bundle-Name:') != -1: 50 | featureLabel = re.match('Bundle-Name: (.*)', line).group(1).strip() 51 | if featureLabel.startswith('%'): # localized 52 | featureLabel = readProps(pluginJar.read('plugin.properties').split('\n'))[featureLabel[1:len(featureLabel)]] 53 | print 'Name: ' + featureLabel 54 | print '' 55 | 56 | result += '\n' 57 | result += '\n' % \ 58 | (featureID, featureVersion, featureLabel) 59 | result += ' \n' 60 | 61 | result += ' ' + \ 62 | descriptions[featureID] + \ 63 | '\n' 64 | #result += ' 2010 Fredrik Fornwall. All rights reserved.\n' 65 | result += ' Eclipse Public License 1.0\n' 66 | result += ' \n' 67 | 68 | if 'Require-Bundle' in manifest: 69 | result += ' \n' 70 | # get content between "Require-Bundle:" and next entry: 71 | reg = re.compile('Require-Bundle:(.+?)(^[^ ])', re.DOTALL | re.MULTILINE) 72 | #for package in manifest.split("Require-Bundle:")[1].split("Bundle")[0].split(","): 73 | for package in reg.search(manifest).group(1).split(","): 74 | # handle lines with version: net.fornwall.eclipsecoder;bundle-version="0.2.7", 75 | package = package.strip().replace('\n', '').replace('\r', '').replace(' ', '') 76 | if ';' in package: package = package[0:package.index(';')] 77 | if package[0:1].isdigit(): 78 | # handle commans in "eclipsecoder;bundle-version="x.x,y,y". ugly... 79 | continue 80 | result += ' \n' % package 81 | result += ' \n' 82 | 83 | # Note the the unit is KB. TODO: Update to KB? 84 | jarSize = stat(pluginJarFileName).st_size / 1024 85 | result += ' \n' % \ 86 | (featureID, jarSize, jarSize, featureVersion) 87 | #if 'net.fornwall.eclipsecoder' == featureID: 88 | #result += ' \n' % \ 89 | #(appletID, appletSize, appletSize, appletVersion) 90 | result += '\n' 91 | return (featureID, featureVersion, result) 92 | 93 | #'\n' + \ 94 | siteXML = '\n' + \ 95 | '\n' + \ 96 | ' \n' + \ 97 | ' Update site for EclipseScript\n' + \ 98 | ' \n' 99 | 100 | # Clear old featuers 101 | for f in glob('features/*'): remove(f) 102 | 103 | # Go through all plugin jars and sort them in wanted order 104 | files = glob('plugins/*') 105 | wantedOrder = [ 106 | 'org.eclipsescript', 107 | 'org.mozilla.javascript' 108 | ] 109 | def pluginSort(a, b): 110 | # plugins/..._0.2.0.jar 111 | aName = a[a.index('/')+1:a.index('_')] 112 | bName = b[b.index('/')+1:b.index('_')] 113 | return wantedOrder.index(aName) - wantedOrder.index(bName) 114 | files.sort(pluginSort) 115 | 116 | siteXML += ' \n' 117 | siteXML += ' Plug-in allowing scripting of the Eclipse IDE using javascript.\n' 118 | siteXML += ' \n' 119 | 120 | for f in files: 121 | (featureID, featureVersion, featureXML) = featureXMLFromPlugin(f) 122 | if featureID == None: continue 123 | featureJarFileName = f.replace('plugins/', 'features/').replace('.jar', '-feature.jar') 124 | featureJar = ZipFile(featureJarFileName, 'w') 125 | featureJar.writestr('feature.xml', featureXML) 126 | 127 | # Update site.xml 128 | siteXML += ' \n' % (featureID, featureJarFileName, featureVersion) 129 | 130 | siteXML += '' 131 | 132 | print 'Writing file site.xml:\n', siteXML 133 | open('site.xml', 'w').write(siteXML) 134 | 135 | -------------------------------------------------------------------------------- /docs/updates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | EclipseScript Update Site 6 | 7 | 8 | 9 | 10 |
11 |

EclipseScript Update Site

12 | 13 |

This is an Eclipse update site. To install the plug-in provided here:

14 | 15 |
    16 |
  1. Open the Help menu.
  2. 17 |
  3. Select the Install New Software... menu item. A dialog will open.
  4. 18 |
  5. In the opened dialog, press the Add.. button to add this update site.
  6. 19 |
  7. Enter the following: 20 |
      21 |
    • Name: EclipseScript
    • 22 |
    • Location: https://eclipsescript.org/updates/
    • 23 |
    24 | and press the OK button. 25 |
  8. 26 |
27 |
28 | 29 |
30 | 31 |

To eclipsescript.org.

32 | 33 |
34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /docs/updates/plugins/org.eclipsescript_1.0.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fornwall/eclipsescript/0737f118debe507c2b66cc20edda31ce3e8541cf/docs/updates/plugins/org.eclipsescript_1.0.12.jar -------------------------------------------------------------------------------- /docs/updates/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Update site for EclipseScript 5 | 6 | 7 | Plug-in allowing scripting of the Eclipse IDE using javascript. 8 | 9 | 10 | -------------------------------------------------------------------------------- /icons/remove_all_terminated.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fornwall/eclipsescript/0737f118debe507c2b66cc20edda31ce3e8541cf/icons/remove_all_terminated.gif -------------------------------------------------------------------------------- /icons/run_script.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fornwall/eclipsescript/0737f118debe507c2b66cc20edda31ce3e8541cf/icons/run_script.gif -------------------------------------------------------------------------------- /js.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fornwall/eclipsescript/0737f118debe507c2b66cc20edda31ce3e8541cf/js.jar -------------------------------------------------------------------------------- /plugin.properties: -------------------------------------------------------------------------------- 1 | commandCategoryName = EclipseScript 2 | commandCategoryDescription = Commands for using the EclipseScript plug-in 3 | commandRunLastName = EclipseScript: Run Last 4 | commandRunLastDescription = Run the last EclipseScript that has been executed 5 | commandRunCurrentName = EclipseScript: Run Current 6 | commandRunCurrentDescription = Run the currently edited EclipseScript 7 | commandRunScriptParameterName = Script 8 | commandOpenScriptDialogName = EclipseScript: Open Script Dialog 9 | commandOpenScriptDialogDescription = Search and select available scripts 10 | 11 | markerName=EclipseScript Problem 12 | pluginName=EclipseScript 13 | bundleVendor=eclipsescript.org 14 | commandRunLastSequence = Ctrl+R 15 | commandRunCurrentSequence = Alt+R 16 | commandOpenScriptDialogSequence = M1+4 17 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 15 | 20 | 25 | 26 | 27 | 28 | 31 | 34 | 37 | 38 | 39 | 40 | 44 | 48 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 65 | 67 | 68 | 69 | 71 | 75 | 76 | 77 | 79 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/org/eclipsescript/core/Activator.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.core; 2 | 3 | import java.net.URL; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import org.eclipse.core.runtime.FileLocator; 8 | import org.eclipse.core.runtime.ILog; 9 | import org.eclipse.core.runtime.IPath; 10 | import org.eclipse.core.runtime.IStatus; 11 | import org.eclipse.core.runtime.Path; 12 | import org.eclipse.core.runtime.Platform; 13 | import org.eclipse.core.runtime.Status; 14 | import org.eclipse.jface.resource.ImageDescriptor; 15 | import org.eclipse.jface.resource.ImageRegistry; 16 | import org.eclipse.osgi.service.resolver.BundleDescription; 17 | import org.eclipse.osgi.service.resolver.ExportPackageDescription; 18 | import org.eclipse.osgi.service.resolver.PlatformAdmin; 19 | import org.eclipse.osgi.service.resolver.Resolver; 20 | import org.eclipse.osgi.service.resolver.State; 21 | import org.eclipse.swt.widgets.Display; 22 | import org.eclipse.ui.plugin.AbstractUIPlugin; 23 | import org.eclipsescript.messages.Messages; 24 | import org.eclipsescript.ui.ErrorDetailsDialog; 25 | import org.eclipsescript.util.EclipseUtils; 26 | import org.eclipsescript.util.EclipseUtils.DisplayThreadRunnable; 27 | import org.osgi.framework.Bundle; 28 | import org.osgi.framework.BundleContext; 29 | import org.osgi.framework.FrameworkUtil; 30 | import org.osgi.framework.ServiceReference; 31 | 32 | /** 33 | * The activator class controls the plug-in life cycle 34 | */ 35 | public class Activator extends AbstractUIPlugin { 36 | 37 | public static final String IMG_REMOVE_ALL = "img_remove_all"; //$NON-NLS-1$ 38 | 39 | private static Activator plugin; 40 | 41 | public static Bundle getBundleExportingClass(String className) { 42 | String packageName = getPackageNameFromClassName(className); 43 | if (packageName != null) { 44 | ExportPackageDescription desc = plugin.resolver.resolveDynamicImport(plugin.bundleDescription, packageName); 45 | if (desc != null) { 46 | BundleDescription exporter = desc.getExporter(); 47 | long exporterBundleId = exporter.getBundleId(); 48 | Bundle exportingBundle = plugin.context.getBundle(exporterBundleId); 49 | return exportingBundle; 50 | } 51 | } 52 | return null; 53 | } 54 | 55 | public static Bundle[] getBundlesExportingPackage(String className) { 56 | List bundles = new ArrayList(); 57 | 58 | String packageName = getPackageNameFromClassName(className); 59 | if (packageName != null) { 60 | BundleContext bundleContext = FrameworkUtil.getBundle(Activator.class).getBundleContext(); 61 | ExportPackageDescription[] exportedPackages = plugin.resolver.getState().getExportedPackages(); 62 | for (ExportPackageDescription packageDescription : exportedPackages) { 63 | boolean found = packageName.equals(packageDescription.getName()); 64 | if (found) { 65 | BundleDescription exporter = packageDescription.getExporter(); 66 | long bundleId = exporter.getBundleId(); 67 | Bundle bundle = bundleContext.getBundle(bundleId); 68 | bundles.add(bundle); 69 | } 70 | } 71 | } 72 | 73 | return bundles.toArray(new Bundle[bundles.size()]); 74 | } 75 | 76 | /** 77 | * Returns the shared instance 78 | */ 79 | public static Activator getDefault() { 80 | return plugin; 81 | } 82 | 83 | public static ImageDescriptor getImageDescriptor(String id) { 84 | return getDefault().getImageRegistry().getDescriptor(id); 85 | } 86 | 87 | private static String getPackageNameFromClassName(String className) { 88 | int lastIndexOfDot = className.lastIndexOf('.'); 89 | if (lastIndexOfDot > 0 && lastIndexOfDot < className.length() - 1) { 90 | char firstCharOfClassName = className.charAt(lastIndexOfDot + 1); 91 | if (Character.isLowerCase(firstCharOfClassName)) { 92 | // probably a package requested by rhino "org.eclipse" part of "org.eclipse.ui.xxx" 93 | return null; 94 | } 95 | String packageName = className.substring(0, lastIndexOfDot); 96 | return packageName; 97 | } 98 | 99 | return null; 100 | } 101 | 102 | public static void logError(final Throwable exception) { 103 | ILog log = plugin.getLog(); 104 | log.log(new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), exception.getMessage(), exception)); 105 | 106 | try { 107 | EclipseUtils.runInDisplayThreadAsync(new DisplayThreadRunnable() { 108 | @Override 109 | public void runWithDisplay(Display display) { 110 | ErrorDetailsDialog.openError(EclipseUtils.getWindowShell(), Messages.internalErrorDialogTitle, 111 | Messages.internalErrorDialogText, exception); 112 | } 113 | }); 114 | } catch (Exception e) { 115 | log.log(new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), e.getMessage(), e)); 116 | } 117 | } 118 | 119 | private BundleDescription bundleDescription; 120 | 121 | private BundleContext context; 122 | 123 | private Resolver resolver; 124 | 125 | @Override 126 | protected void initializeImageRegistry(ImageRegistry registry) { 127 | Bundle bundle = Platform.getBundle(getBundle().getSymbolicName()); 128 | IPath path = new Path("icons/remove_all_terminated.gif"); //$NON-NLS-1$ 129 | URL url = FileLocator.find(bundle, path, null); 130 | ImageDescriptor desc = ImageDescriptor.createFromURL(url); 131 | registry.put(IMG_REMOVE_ALL, desc); 132 | } 133 | 134 | @Override 135 | public void start(BundleContext bundleContext) throws Exception { 136 | super.start(bundleContext); 137 | 138 | Activator.plugin = this; 139 | context = bundleContext; 140 | 141 | // Eclipse 3.7+ api: 142 | // ServiceReference platformAdminServiceRef = context.getServiceReference(PlatformAdmin.class); 143 | // PlatformAdmin platformAdminService = context.getService(platformAdminServiceRef); 144 | // Eclipse 3.6 api: 145 | ServiceReference platformAdminServiceRef = context.getServiceReference(PlatformAdmin.class.getName()); 146 | PlatformAdmin platformAdminService = (PlatformAdmin) context.getService(platformAdminServiceRef); 147 | 148 | resolver = platformAdminService.createResolver(); 149 | State state = platformAdminService.getState(false); 150 | context.ungetService(platformAdminServiceRef); 151 | resolver.setState(state); 152 | bundleDescription = state.getBundle(plugin.getBundle().getSymbolicName(), null); 153 | } 154 | 155 | @Override 156 | public void stop(BundleContext bundleContext) throws Exception { 157 | super.stop(bundleContext); 158 | Activator.plugin = null; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/org/eclipsescript/core/Autostart.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.core; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.Comparator; 6 | import java.util.List; 7 | 8 | import org.eclipse.core.resources.IFile; 9 | import org.eclipse.core.resources.IResource; 10 | import org.eclipse.core.resources.IResourceProxy; 11 | import org.eclipse.core.resources.IResourceProxyVisitor; 12 | import org.eclipse.core.resources.IWorkspaceRoot; 13 | import org.eclipse.core.resources.ResourcesPlugin; 14 | import org.eclipse.core.runtime.CoreException; 15 | import org.eclipse.ui.IStartup; 16 | import org.eclipse.ui.IWorkbench; 17 | import org.eclipse.ui.PlatformUI; 18 | import org.eclipsescript.scripts.ScriptMetadata; 19 | import org.eclipsescript.scripts.ScriptStore; 20 | 21 | public class Autostart implements IStartup { 22 | 23 | @Override 24 | public void earlyStartup() { 25 | final IWorkbench workbench = PlatformUI.getWorkbench(); 26 | workbench.getDisplay().asyncExec(new Runnable() { 27 | @Override 28 | public void run() { 29 | executeAutoScripts(); 30 | } 31 | }); 32 | } 33 | 34 | void executeAutoScripts() { 35 | final List autoScripts = new ArrayList(); 36 | 37 | IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); 38 | try { 39 | root.accept(new IResourceProxyVisitor() { 40 | @Override 41 | public boolean visit(IResourceProxy proxy) throws CoreException { 42 | if (proxy.getName().endsWith(".eclipse.auto.js")) { //$NON-NLS-1$ 43 | IResource resource = proxy.requestResource(); 44 | if (resource instanceof IFile && !resource.isDerived()) { 45 | IFile file = (IFile) resource; 46 | autoScripts.add(new ScriptMetadata(file)); 47 | } 48 | } 49 | return true; 50 | } 51 | }, 0); 52 | } catch (CoreException e) { 53 | e.printStackTrace(); 54 | } 55 | 56 | Collections.sort(autoScripts, new Comparator() { 57 | @Override 58 | public int compare(ScriptMetadata o1, ScriptMetadata o2) { 59 | return o1.getLabel().compareTo(o2.getLabel()); 60 | } 61 | }); 62 | for (ScriptMetadata script : autoScripts) { 63 | ScriptStore.executeScript(script); 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/org/eclipsescript/core/OpenScriptDialogHandler.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.core; 2 | 3 | 4 | import org.eclipse.core.commands.ExecutionEvent; 5 | import org.eclipse.core.commands.ExecutionException; 6 | import org.eclipsescript.ui.ErrorHandlingHandler; 7 | import org.eclipsescript.ui.QuickScriptDialog; 8 | import org.eclipsescript.util.EclipseUtils; 9 | 10 | public class OpenScriptDialogHandler extends ErrorHandlingHandler { 11 | 12 | @Override 13 | public void doExecute(ExecutionEvent event) throws ExecutionException { 14 | QuickScriptDialog d = new QuickScriptDialog(EclipseUtils.activeWindow()); 15 | d.open(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/org/eclipsescript/core/RunCurrentHandler.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.core; 2 | 3 | 4 | import org.eclipse.core.commands.ExecutionEvent; 5 | import org.eclipse.core.resources.IFile; 6 | import org.eclipse.jface.dialogs.MessageDialog; 7 | import org.eclipse.ui.IEditorInput; 8 | import org.eclipse.ui.part.FileEditorInput; 9 | import org.eclipsescript.messages.Messages; 10 | import org.eclipsescript.scripts.ScriptLanguageHandler; 11 | import org.eclipsescript.scripts.ScriptMetadata; 12 | import org.eclipsescript.scripts.ScriptStore; 13 | import org.eclipsescript.ui.ErrorHandlingHandler; 14 | import org.eclipsescript.util.EclipseUtils; 15 | 16 | public class RunCurrentHandler extends ErrorHandlingHandler { 17 | 18 | @Override 19 | protected void doExecute(ExecutionEvent event) throws Exception { 20 | IEditorInput editorInput = EclipseUtils.getCurrentEditorInput(); 21 | if (editorInput instanceof FileEditorInput) { 22 | FileEditorInput fileInput = (FileEditorInput) editorInput; 23 | IFile editedFile = fileInput.getFile(); 24 | boolean isScriptFile = ScriptLanguageHandler.isEclipseScriptFile(editedFile); 25 | if (isScriptFile) { 26 | ScriptMetadata m = new ScriptMetadata(fileInput.getFile()); 27 | ScriptStore.executeScript(m); 28 | return; 29 | } 30 | } 31 | MessageDialog.openInformation(EclipseUtils.getWindowShell(), Messages.cannotRunCurrentScriptTitle, 32 | Messages.cannotRunCurrentScriptText); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/org/eclipsescript/core/RunLastHandler.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.core; 2 | 3 | 4 | import org.eclipse.core.commands.ExecutionEvent; 5 | import org.eclipse.core.commands.ExecutionException; 6 | import org.eclipse.jface.dialogs.MessageDialog; 7 | import org.eclipsescript.messages.Messages; 8 | import org.eclipsescript.scripts.ScriptMetadata; 9 | import org.eclipsescript.scripts.ScriptStore; 10 | import org.eclipsescript.ui.ErrorHandlingHandler; 11 | import org.eclipsescript.util.EclipseUtils; 12 | 13 | public class RunLastHandler extends ErrorHandlingHandler { 14 | 15 | public static ScriptMetadata lastRun = null; 16 | 17 | @Override 18 | public void doExecute(ExecutionEvent event) throws ExecutionException { 19 | if (lastRun == null) { 20 | MessageDialog.openWarning(EclipseUtils.activeWindow().getShell(), "No script to run", //$NON-NLS-1$ 21 | Messages.runScriptBeforeRunningLast); 22 | } else { 23 | ScriptStore.executeScript(lastRun); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/org/eclipsescript/javascript/CustomContextFactory.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.javascript; 2 | 3 | import java.security.AccessController; 4 | import java.security.PrivilegedAction; 5 | 6 | import org.eclipse.jface.preference.IPreferenceStore; 7 | import org.eclipse.osgi.util.NLS; 8 | import org.eclipse.ui.PlatformUI; 9 | import org.eclipsescript.core.Activator; 10 | import org.eclipsescript.messages.Messages; 11 | import org.eclipsescript.preferences.PreferenceConstants; 12 | import org.eclipsescript.rhino.javascript.Callable; 13 | import org.eclipsescript.rhino.javascript.Context; 14 | import org.eclipsescript.rhino.javascript.ContextFactory; 15 | import org.eclipsescript.rhino.javascript.Scriptable; 16 | import org.eclipsescript.scripts.ScriptClassLoader; 17 | 18 | class CustomContextFactory extends ContextFactory { 19 | 20 | static class CustomContext extends Context { 21 | public JavascriptRuntime jsRuntime; 22 | 23 | long startTime; 24 | int timeout; 25 | volatile boolean useTimeout = true; 26 | 27 | public CustomContext(ContextFactory factory) { 28 | super(factory); 29 | try { 30 | IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); 31 | timeout = preferenceStore.getInt(PreferenceConstants.P_TIMEOUT); 32 | } catch (Throwable t) { 33 | System.err.println(t.getMessage()); 34 | } 35 | 36 | if (timeout == 0) { 37 | timeout = PreferenceConstants.P_TIMEOUT_DEFAULT; 38 | } 39 | // System.out.println("timeout=" + timeout + " @" + this); 40 | } 41 | } 42 | 43 | @Override 44 | protected Object doTopCall(Callable callable, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { 45 | CustomContext mcx = (CustomContext) cx; 46 | mcx.startTime = System.currentTimeMillis(); 47 | 48 | return super.doTopCall(callable, cx, scope, thisObj, args); 49 | } 50 | 51 | @Override 52 | public boolean hasFeature(Context cx, int featureIndex) { 53 | switch (featureIndex) { 54 | case Context.FEATURE_STRICT_EVAL: 55 | // error on eval(arg) with non-string arg - sensible 56 | return true; 57 | case Context.FEATURE_LOCATION_INFORMATION_IN_ERROR: 58 | return true; 59 | default: 60 | return super.hasFeature(cx, featureIndex); 61 | } 62 | } 63 | 64 | @Override 65 | protected Context makeContext() { 66 | final CustomContext cx = new CustomContext(this); 67 | // prevent generating of java class files loaded into the JVM, use 68 | // interpreted mode 69 | cx.setOptimizationLevel(-1); 70 | 71 | if (Thread.currentThread().equals(PlatformUI.getWorkbench().getDisplay().getThread())) { 72 | // only observe instructions in UI thread to avoid locking UI 73 | cx.setInstructionObserverThreshold(5000); 74 | } 75 | ClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction() { 76 | @Override 77 | public ClassLoader run() { 78 | return new ScriptClassLoader(cx.getApplicationClassLoader()); 79 | } 80 | }); 81 | 82 | cx.setApplicationClassLoader(classLoader); 83 | cx.setLanguageVersion(Context.VERSION_1_8); 84 | cx.getWrapFactory().setJavaPrimitiveWrap(false); 85 | return cx; 86 | } 87 | 88 | @Override 89 | protected void observeInstructionCount(Context cx, int instructionCount) { 90 | CustomContext mcx = (CustomContext) cx; 91 | if (!mcx.useTimeout) 92 | return; 93 | final int MAX_SECONDS = mcx.timeout; 94 | long currentTime = System.currentTimeMillis(); 95 | if (currentTime - mcx.startTime > MAX_SECONDS * 1000) { 96 | mcx.jsRuntime.abortRunningScript(NLS.bind(Messages.scriptTimeout, MAX_SECONDS)); 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/org/eclipsescript/javascript/JavaScriptLanguageSupport.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.javascript; 2 | 3 | import org.eclipsescript.javascript.CustomContextFactory.CustomContext; 4 | import org.eclipsescript.rhino.javascript.Context; 5 | import org.eclipsescript.rhino.javascript.ContextAction; 6 | import org.eclipsescript.rhino.javascript.ImporterTopLevel; 7 | import org.eclipsescript.rhino.javascript.ScriptableObject; 8 | import org.eclipsescript.scriptobjects.Eclipse; 9 | import org.eclipsescript.scripts.IScriptLanguageSupport; 10 | import org.eclipsescript.scripts.ScriptMetadata; 11 | 12 | public class JavaScriptLanguageSupport implements IScriptLanguageSupport { 13 | 14 | private final CustomContextFactory contextFactory = new CustomContextFactory(); 15 | 16 | @Override 17 | public void executeScript(final ScriptMetadata script) { 18 | contextFactory.call(new ContextAction() { 19 | @Override 20 | public Object run(Context _context) { 21 | if (!(_context instanceof CustomContext)) 22 | throw new IllegalArgumentException("Wrong context class: " + _context.getClass()); //$NON-NLS-1$ 23 | CustomContext context = (CustomContext) _context; 24 | ScriptableObject scope = new ImporterTopLevel(context); 25 | JavascriptRuntime jsRuntime = new JavascriptRuntime(context, scope, script); 26 | 27 | Eclipse eclipseJavaObject = new Eclipse(jsRuntime); 28 | Object eclipseJsObject = Context.javaToJS(eclipseJavaObject, scope); 29 | ScriptableObject.putConstProperty(scope, Eclipse.VARIABLE_NAME, eclipseJsObject); 30 | 31 | try { 32 | jsRuntime.evaluate(script.getFile(), false); 33 | } catch (Throwable e) { 34 | jsRuntime.handleExceptionFromScriptRuntime(e); 35 | } 36 | return null; 37 | } 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/org/eclipsescript/javascript/JavascriptRuntime.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.javascript; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.concurrent.Callable; 6 | 7 | import org.eclipse.core.resources.IFile; 8 | import org.eclipse.core.runtime.CoreException; 9 | import org.eclipse.core.runtime.IProgressMonitor; 10 | import org.eclipse.core.runtime.IStatus; 11 | import org.eclipse.core.runtime.Status; 12 | import org.eclipse.ui.progress.IJobRunnable; 13 | import org.eclipsescript.javascript.CustomContextFactory.CustomContext; 14 | import org.eclipsescript.rhino.javascript.BaseFunction; 15 | import org.eclipsescript.rhino.javascript.Context; 16 | import org.eclipsescript.rhino.javascript.ContextAction; 17 | import org.eclipsescript.rhino.javascript.EvaluatorException; 18 | import org.eclipsescript.rhino.javascript.RhinoException; 19 | import org.eclipsescript.rhino.javascript.Scriptable; 20 | import org.eclipsescript.rhino.javascript.WrappedException; 21 | import org.eclipsescript.scripts.IScriptRuntime; 22 | import org.eclipsescript.scripts.MarkerManager; 23 | import org.eclipsescript.scripts.ScriptClassLoader; 24 | import org.eclipsescript.scripts.ScriptException; 25 | import org.eclipsescript.scripts.ScriptMetadata; 26 | import org.eclipsescript.scripts.ScriptStore; 27 | import org.eclipsescript.util.JavaUtils; 28 | 29 | class JavascriptRuntime implements IScriptRuntime { 30 | 31 | /** 32 | * Throw to indicate abnormal exception of script. Needs to extend error to prevent script from being able to catch 33 | * exception. 34 | */ 35 | @SuppressWarnings("serial") 36 | static class DieError extends Error { 37 | public EvaluatorException evalException; 38 | 39 | public DieError(String dieMessage) { 40 | super(dieMessage); 41 | try { 42 | Context.reportError(dieMessage); 43 | } catch (EvaluatorException e) { 44 | evalException = e; 45 | } 46 | } 47 | } 48 | 49 | /** 50 | * Throw to indicate normal exit of script. Needs to extend error to prevent script from being able to catch 51 | * exception. 52 | */ 53 | @SuppressWarnings("serial") 54 | static class ExitError extends Error { 55 | // just a marker class 56 | } 57 | 58 | final CustomContext context; 59 | final InheritableThreadLocal currentFile = new InheritableThreadLocal(); 60 | final ScriptMetadata script; 61 | final Scriptable topLevelScope; 62 | 63 | public JavascriptRuntime(CustomContext context, Scriptable topLevelScope, ScriptMetadata script) { 64 | this.context = context; 65 | this.topLevelScope = topLevelScope; 66 | this.script = script; 67 | setExecutingFile(script.getFile()); 68 | 69 | context.jsRuntime = this; 70 | } 71 | 72 | @Override 73 | public void abortRunningScript(String errorMessage) { 74 | throw new DieError(errorMessage); 75 | } 76 | 77 | @SuppressWarnings("unchecked") 78 | @Override 79 | public T adaptTo(Object object, Class clazz) { 80 | if (object == null) 81 | return null; 82 | if (clazz.isInstance(object)) 83 | return (T) object; 84 | if (clazz == IJobRunnable.class) { 85 | if (!(object instanceof BaseFunction)) 86 | return null; 87 | 88 | final BaseFunction function = (BaseFunction) object; 89 | return (T) new IJobRunnable() { 90 | @Override 91 | public IStatus run(final IProgressMonitor monitor) { 92 | Object functionReturnValue = context.getFactory().call(new ContextAction() { 93 | @Override 94 | public Object run(final Context cx) { 95 | return ScriptStore.executeRunnableWhichMayThrowScriptException(script, 96 | new Callable() { 97 | @Override 98 | public Object call() throws Exception { 99 | final Object[] arguments = new Object[] { monitor }; 100 | try { 101 | return function.call(cx, topLevelScope, topLevelScope, arguments); 102 | } catch (Throwable t) { 103 | handleExceptionFromScriptRuntime(t); 104 | return null; 105 | } 106 | } 107 | }); 108 | } 109 | }); 110 | if (functionReturnValue instanceof IStatus) { 111 | return (IStatus) functionReturnValue; 112 | } else if (functionReturnValue instanceof Boolean) { 113 | return (Boolean.TRUE.equals(functionReturnValue)) ? Status.OK_STATUS : Status.CANCEL_STATUS; 114 | } 115 | return Status.OK_STATUS; 116 | } 117 | }; 118 | } 119 | return null; 120 | } 121 | 122 | @Override 123 | public void disableTimeout() { 124 | context.useTimeout = false; 125 | } 126 | 127 | @Override 128 | public void evaluate(IFile file, boolean nested) throws IOException { 129 | // Cleanup eventual error markers from last run of this file since it may now be fixed - if an error remains it 130 | // will be re-added later when it fails again: 131 | MarkerManager.clearMarkers(file); 132 | 133 | InputStreamReader reader = null; 134 | IFile previousFile = getExecutingFile(); 135 | try { 136 | setExecutingFile(file); 137 | reader = new InputStreamReader(file.getContents(true), file.getCharset()); 138 | String sourceName = file.getFullPath().toPortableString(); 139 | Scriptable fileScope = nested ? topLevelScope : context.newObject(topLevelScope); 140 | context.evaluateReader(fileScope, reader, sourceName, 1, null); 141 | } catch (CoreException e) { 142 | throw new RuntimeException(e); 143 | } finally { 144 | setExecutingFile(previousFile); 145 | if (reader != null) { 146 | reader.close(); 147 | } 148 | } 149 | } 150 | 151 | @Override 152 | public void exitRunningScript() { 153 | throw new ExitError(); 154 | } 155 | 156 | @Override 157 | public IFile getExecutingFile() { 158 | return currentFile.get(); 159 | } 160 | 161 | @Override 162 | public ScriptClassLoader getScriptClassLoader() { 163 | return (ScriptClassLoader) context.getApplicationClassLoader(); 164 | } 165 | 166 | public void handleExceptionFromScriptRuntime(Throwable err) { 167 | if (err instanceof ExitError) { 168 | // do nothing, just exit quietly due to eclipse.runtime.exit() call 169 | } else if (err instanceof DieError) { 170 | DieError e = (DieError) err; 171 | RhinoException re = e.evalException; 172 | throw new ScriptException(e.getMessage(), re, re.sourceName(), re.lineNumber(), re.getScriptStackTrace(), 173 | false); 174 | } else if (err instanceof RhinoException) { 175 | RhinoException re = (RhinoException) err; 176 | boolean showStackTrace = (re instanceof WrappedException); 177 | Throwable cause = showStackTrace ? ((WrappedException) re).getCause() : re; 178 | throw new ScriptException(re.getMessage(), cause, re.sourceName(), re.lineNumber(), 179 | re.getScriptStackTrace(), showStackTrace); 180 | } else { 181 | if (err instanceof Error) { 182 | throw (Error) err; 183 | } 184 | throw JavaUtils.asRuntime(err); 185 | } 186 | } 187 | 188 | @Override 189 | public void setExecutingFile(IFile file) { 190 | currentFile.set(file); 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /src/org/eclipsescript/messages/Messages.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.messages; 2 | 3 | import org.eclipse.osgi.util.NLS; 4 | 5 | /** 6 | * Localization messages using the {@link NLS} system. The static initializer block will initialize the fields of this 7 | * class with values loaded from the messages properties file. 8 | */ 9 | public class Messages extends NLS { 10 | 11 | private static final String BUNDLE_NAME = Messages.class.getPackage().getName() + ".messages"; //$NON-NLS-1$ 12 | 13 | public static String cannotRunCurrentScriptText; 14 | public static String cannotRunCurrentScriptTitle; 15 | public static String clearMarkersJobName; 16 | public static String fileToIncludeDoesNotExist; 17 | public static String fileToReadDoesNotExist; 18 | public static String internalErrorDialogDetails; 19 | public static String internalErrorDialogText; 20 | public static String internalErrorDialogTitle; 21 | public static String noDocumentSelected; 22 | public static String noSelectionSelected; 23 | public static String noTextEditorSelected; 24 | public static String notPossibleToScheduleObject; 25 | public static String removeAllTerminatedConsoles; 26 | public static String Resources_cannotReadFromObject; 27 | public static String runScriptBeforeRunningLast; 28 | public static String scriptAlertDialogTitle; 29 | public static String scriptBackgroundJobName; 30 | public static String scriptConfirmDialogTitle; 31 | public static String scriptConsoleName; 32 | public static String scriptErrorWhenRunningScriptDialogText; 33 | public static String scriptErrorWhenRunningScriptDialogTitle; 34 | public static String scriptErrorWhenRunningScriptJumpToScriptButton; 35 | public static String scriptErrorWhenRunningScriptOkButton; 36 | public static String scriptPromptDialogTitle; 37 | public static String scriptTimeout; 38 | public static String windowOpenArgumentNull; 39 | 40 | static { 41 | NLS.initializeMessages(BUNDLE_NAME, Messages.class); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/org/eclipsescript/messages/messages.properties: -------------------------------------------------------------------------------- 1 | internalErrorDialogTitle=EclipseScript Internal Error 2 | internalErrorDialogText=The error has been logged. See below for details. 3 | internalErrorDialogDetails=Plug-in name: {0}\nPlug-in ID: {1}\nVersion: {2}\n\n{3} 4 | runScriptBeforeRunningLast=No EclipseScript script has been run\! 5 | scriptAlertDialogTitle=EclipseScript Alert 6 | scriptConfirmDialogTitle=EclipseScript Prompt 7 | scriptConsoleName=EclipseScript: {0} 8 | scriptErrorWhenRunningScriptDialogTitle=EclipseScript Error 9 | scriptErrorWhenRunningScriptDialogText=Execution of the script "{0}" failed at line {2} with the following message:\n\n{1} 10 | scriptErrorWhenRunningScriptJumpToScriptButton=&Go to script 11 | scriptErrorWhenRunningScriptOkButton=&Ok 12 | scriptTimeout = Script timeout after {0} seconds.\n\nTry using the eclipse.runtime.schedule(runnable) function for long-running background tasks. 13 | scriptBackgroundJobName=EclipseScript: {0} 14 | scriptPromptDialogTitle=EclipseScript Prompt 15 | cannotRunCurrentScriptText=Cannot run the currently edited script 16 | cannotRunCurrentScriptTitle=Cannot run 17 | clearMarkersJobName=Clear script markers 18 | fileToIncludeDoesNotExist=File does not exist: 19 | fileToReadDoesNotExist=File to read does not exist: 20 | noDocumentSelected=No document selected\! 21 | noSelectionSelected=No selection selected\! 22 | noTextEditorSelected=No text editor selected\! 23 | notPossibleToScheduleObject=Not possible to schedule object: 24 | Resources_cannotReadFromObject=Cannot read from object: 25 | windowOpenArgumentNull=The urlString argument to open(urlString) was null 26 | removeAllTerminatedConsoles=Remove All EclipseScript Consoles -------------------------------------------------------------------------------- /src/org/eclipsescript/preferences/EclipseScriptPreferencePage.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.preferences; 2 | 3 | import org.eclipse.jface.preference.FieldEditorPreferencePage; 4 | import org.eclipse.jface.preference.IntegerFieldEditor; 5 | import org.eclipse.ui.IWorkbench; 6 | import org.eclipse.ui.IWorkbenchPreferencePage; 7 | import org.eclipsescript.core.Activator; 8 | 9 | /** 10 | * This class represents a preference page that is contributed to the Preferences dialog. By subclassing 11 | * FieldEditorPreferencePage, we can use the field support built into JFace that allows us to create a page 12 | * that is small and knows how to save, restore and apply itself. 13 | *

14 | * This page is used to modify preferences only. They are stored in the preference store that belongs to the main 15 | * plug-in class. That way, preferences can be accessed directly via the preference store. 16 | */ 17 | 18 | public class EclipseScriptPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { 19 | 20 | public EclipseScriptPreferencePage() { 21 | super(GRID); 22 | setPreferenceStore(Activator.getDefault().getPreferenceStore()); 23 | setDescription(Messages.EclipseScriptPreferencePage_0); 24 | } 25 | 26 | /** 27 | * Creates the field editors. Field editors are abstractions of the common GUI blocks needed to manipulate various 28 | * types of preferences. Each field editor knows how to save and restore itself. 29 | */ 30 | @Override 31 | public void createFieldEditors() { 32 | addField(new IntegerFieldEditor(PreferenceConstants.P_TIMEOUT, Messages.EclipseScriptPreferencePage_1, 33 | getFieldEditorParent())); 34 | } 35 | 36 | /* 37 | * (non-Javadoc) 38 | * 39 | * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) 40 | */ 41 | @Override 42 | public void init(IWorkbench workbench) { 43 | // nothing to do here 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /src/org/eclipsescript/preferences/Messages.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.preferences; 2 | 3 | import org.eclipse.osgi.util.NLS; 4 | 5 | public class Messages extends NLS { 6 | private static final String BUNDLE_NAME = "org.eclipsescript.preferences.messages"; //$NON-NLS-1$ 7 | public static String EclipseScriptPreferencePage_0; 8 | public static String EclipseScriptPreferencePage_1; 9 | static { 10 | // initialize resource bundle 11 | NLS.initializeMessages(BUNDLE_NAME, Messages.class); 12 | } 13 | 14 | private Messages() { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/org/eclipsescript/preferences/PreferenceConstants.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.preferences; 2 | 3 | /** 4 | * Constant definitions for plug-in preferences 5 | */ 6 | public class PreferenceConstants { 7 | public static final String P_TIMEOUT = "timeout"; //$NON-NLS-1$ 8 | public static final int P_TIMEOUT_DEFAULT = 10; 9 | } 10 | -------------------------------------------------------------------------------- /src/org/eclipsescript/preferences/PreferenceInitializer.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.preferences; 2 | 3 | import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; 4 | import org.eclipse.jface.preference.IPreferenceStore; 5 | import org.eclipsescript.core.Activator; 6 | 7 | /** 8 | * Class used to initialize default preference values. 9 | */ 10 | public class PreferenceInitializer extends AbstractPreferenceInitializer { 11 | 12 | /* 13 | * (non-Javadoc) 14 | * 15 | * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() 16 | */ 17 | @Override 18 | public void initializeDefaultPreferences() { 19 | IPreferenceStore store = Activator.getDefault().getPreferenceStore(); 20 | store.setDefault(PreferenceConstants.P_TIMEOUT, PreferenceConstants.P_TIMEOUT_DEFAULT); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/org/eclipsescript/preferences/messages.properties: -------------------------------------------------------------------------------- 1 | EclipseScriptPreferencePage_0=EclipseScript 2 | EclipseScriptPreferencePage_1=Script &timeout (seconds): 3 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scriptobjects/Console.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scriptobjects; 2 | 3 | import org.eclipse.jface.resource.ImageDescriptor; 4 | import org.eclipse.osgi.util.NLS; 5 | import org.eclipse.swt.widgets.Display; 6 | import org.eclipse.ui.console.ConsolePlugin; 7 | import org.eclipse.ui.console.IConsole; 8 | import org.eclipse.ui.console.IConsoleManager; 9 | import org.eclipse.ui.console.MessageConsole; 10 | import org.eclipse.ui.console.MessageConsoleStream; 11 | import org.eclipsescript.messages.Messages; 12 | import org.eclipsescript.scripts.IScriptRuntime; 13 | import org.eclipsescript.util.EclipseUtils; 14 | import org.eclipsescript.util.EclipseUtils.DisplayThreadRunnable; 15 | 16 | public class Console { 17 | 18 | // just a marker superclass for enablement in console closer, see plugin.xml 19 | public static class ConsoleClass extends MessageConsole { 20 | public boolean isDisposed = false; 21 | 22 | public ConsoleClass(String name, ImageDescriptor imageDescriptor) { 23 | super(name, imageDescriptor); 24 | } 25 | 26 | @Override 27 | protected void dispose() { 28 | isDisposed = true; 29 | super.dispose(); 30 | } 31 | 32 | } 33 | 34 | private ConsoleClass console; 35 | private final String name; 36 | MessageConsoleStream out; 37 | 38 | public Console(IScriptRuntime runtime) { 39 | this.name = NLS.bind(Messages.scriptConsoleName, runtime.getExecutingFile().getName()); 40 | } 41 | 42 | void init() { 43 | // Open a console for the first time or re-open 44 | if (console == null || console.isDisposed) { 45 | console = new ConsoleClass(name, null); 46 | out = console.newMessageStream(); 47 | ConsolePlugin consolePlugin = ConsolePlugin.getDefault(); 48 | IConsoleManager consoleManager = consolePlugin.getConsoleManager(); 49 | consoleManager.addConsoles(new IConsole[] { console }); 50 | consoleManager.showConsoleView(console); 51 | } 52 | } 53 | 54 | public void print(final String msg) throws Exception { 55 | EclipseUtils.runInDisplayThreadAsync(new DisplayThreadRunnable() { 56 | 57 | @Override 58 | public void runWithDisplay(Display display) throws Exception { 59 | init(); 60 | out.print(msg); 61 | } 62 | 63 | }); 64 | } 65 | 66 | public void println(final String msg) throws Exception { 67 | EclipseUtils.runInDisplayThreadAsync(new DisplayThreadRunnable() { 68 | 69 | @Override 70 | public void runWithDisplay(Display display) throws Exception { 71 | init(); 72 | out.println(msg); 73 | } 74 | 75 | }); 76 | } 77 | 78 | public void printStackTrace(final Throwable t) throws Exception { 79 | EclipseUtils.runInDisplayThreadAsync(new DisplayThreadRunnable() { 80 | 81 | @Override 82 | public void runWithDisplay(Display display) throws Exception { 83 | init(); 84 | out.println(t.getClass().getName()); 85 | for (StackTraceElement stack : t.getStackTrace()) { 86 | out.println("\t at " + stack.toString()); //$NON-NLS-1$ 87 | } 88 | } 89 | 90 | }); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scriptobjects/Eclipse.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scriptobjects; 2 | 3 | import org.eclipsescript.scripts.IScriptRuntime; 4 | 5 | public class Eclipse { 6 | 7 | public static final String VARIABLE_NAME = "eclipse"; //$NON-NLS-1$ 8 | 9 | private final Console console; 10 | private final Editors editors; 11 | private final Resources resources; 12 | private final Runtime runtime; 13 | private final Window window; 14 | private final Xml xml; 15 | 16 | public Eclipse(IScriptRuntime scriptRuntime) { 17 | this.console = new Console(scriptRuntime); 18 | this.editors = new Editors(); 19 | this.resources = new Resources(scriptRuntime); 20 | this.runtime = new Runtime(scriptRuntime); 21 | this.window = new Window(); 22 | this.xml = new Xml(resources); 23 | } 24 | 25 | public Console getConsole() { 26 | return console; 27 | } 28 | 29 | public Editors getEditors() { 30 | return editors; 31 | } 32 | 33 | public Resources getResources() { 34 | return resources; 35 | } 36 | 37 | public Runtime getRuntime() { 38 | return runtime; 39 | } 40 | 41 | public Window getWindow() { 42 | return window; 43 | } 44 | 45 | public Xml getXml() { 46 | return xml; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scriptobjects/Editors.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scriptobjects; 2 | 3 | import org.eclipse.core.resources.IFile; 4 | import org.eclipse.jface.text.BadLocationException; 5 | import org.eclipse.jface.text.IDocument; 6 | import org.eclipse.jface.text.ITextSelection; 7 | import org.eclipse.jface.text.TextSelection; 8 | import org.eclipse.jface.viewers.ISelection; 9 | import org.eclipse.jface.viewers.ISelectionProvider; 10 | import org.eclipse.swt.custom.StyledText; 11 | import org.eclipse.swt.dnd.Clipboard; 12 | import org.eclipse.swt.dnd.TextTransfer; 13 | import org.eclipse.swt.dnd.Transfer; 14 | import org.eclipse.swt.widgets.Control; 15 | import org.eclipse.swt.widgets.Display; 16 | import org.eclipse.ui.IEditorDescriptor; 17 | import org.eclipse.ui.IEditorInput; 18 | import org.eclipse.ui.IEditorRegistry; 19 | import org.eclipse.ui.IWorkbench; 20 | import org.eclipse.ui.IWorkbenchPage; 21 | import org.eclipse.ui.PlatformUI; 22 | import org.eclipse.ui.part.FileEditorInput; 23 | import org.eclipse.ui.texteditor.IDocumentProvider; 24 | import org.eclipse.ui.texteditor.ITextEditor; 25 | import org.eclipsescript.messages.Messages; 26 | import org.eclipsescript.util.EclipseUtils; 27 | import org.eclipsescript.util.EclipseUtils.DisplayThreadCallable; 28 | import org.eclipsescript.util.EclipseUtils.DisplayThreadRunnable; 29 | import org.eclipsescript.util.JavaUtils.MutableObject; 30 | 31 | public class Editors { 32 | 33 | public String getClipboard() throws Exception { 34 | final MutableObject result = new MutableObject(); 35 | EclipseUtils.runInDisplayThreadSync(new DisplayThreadRunnable() { 36 | @Override 37 | public void runWithDisplay(Display display) { 38 | Clipboard clipboard = new Clipboard(display); 39 | try { 40 | result.value = (String) clipboard.getContents(TextTransfer.getInstance()); 41 | } finally { 42 | clipboard.dispose(); 43 | } 44 | } 45 | }); 46 | return result.value; 47 | } 48 | 49 | /** Returns the currently edited document or null if none. */ 50 | public IDocument getDocument() throws Exception { 51 | return EclipseUtils.runInDisplayThreadSync(new DisplayThreadCallable() { 52 | @Override 53 | public IDocument callWithDisplay(Display display) throws Exception { 54 | return EclipseUtils.getCurrentDocument(); 55 | } 56 | }); 57 | } 58 | 59 | /** Returns the currently edited file or null if none. */ 60 | public IFile getFile() throws Exception { 61 | return EclipseUtils.runInDisplayThreadSync(new DisplayThreadCallable() { 62 | @Override 63 | public IFile callWithDisplay(Display display) throws Exception { 64 | IEditorInput editorInput = EclipseUtils.getCurrentEditorInput(); 65 | IFile fileEditorInput = null; 66 | if (editorInput != null) { 67 | fileEditorInput = editorInput.getAdapter(IFile.class); 68 | } 69 | return fileEditorInput; 70 | } 71 | }); 72 | } 73 | 74 | /** 75 | * Returns the current text selection or null if none. 76 | */ 77 | public ITextSelection getSelection() throws Exception { 78 | return EclipseUtils.runInDisplayThreadSync(new DisplayThreadCallable() { 79 | @Override 80 | public ITextSelection callWithDisplay(Display display) throws Exception { 81 | ITextEditor editor = EclipseUtils.getCurrentTextEditor(); 82 | if (editor == null) 83 | return null; 84 | ISelectionProvider provider = editor.getSelectionProvider(); 85 | if (provider == null) 86 | return null; 87 | ISelection selection = provider.getSelection(); 88 | if (!(selection instanceof ITextSelection)) 89 | return null; 90 | return (ITextSelection) selection; 91 | } 92 | }); 93 | } 94 | 95 | public void insert(final String textToInsert) throws Exception { 96 | EclipseUtils.runInDisplayThreadSync(new DisplayThreadRunnable() { 97 | @Override 98 | public void runWithDisplay(Display display) throws BadLocationException { 99 | 100 | ITextEditor editor = EclipseUtils.getCurrentTextEditor(); 101 | if (editor == null) 102 | throw new IllegalArgumentException(Messages.noTextEditorSelected); 103 | IDocument document = EclipseUtils.getCurrentDocument(); 104 | if (document == null) 105 | throw new IllegalArgumentException(Messages.noDocumentSelected); 106 | 107 | StyledText styledText = (StyledText) editor.getAdapter(Control.class); 108 | int offset = styledText.getCaretOffset(); 109 | document.replace(offset, 0, textToInsert); 110 | } 111 | }); 112 | } 113 | 114 | public void open(final IFile file) throws Exception { 115 | EclipseUtils.runInDisplayThreadSync(new DisplayThreadRunnable() { 116 | @Override 117 | public void runWithDisplay(Display display) throws Exception { 118 | 119 | IWorkbench workbench = PlatformUI.getWorkbench(); 120 | IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage(); 121 | 122 | IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry(); 123 | IEditorDescriptor editorDescriptor = editorRegistry.getDefaultEditor(file.getName()); 124 | 125 | if (editorDescriptor == null) { 126 | // there is no default editor for the file, use text editor 127 | editorDescriptor = editorRegistry.getDefaultEditor("1.txt"); //$NON-NLS-1$ 128 | } 129 | 130 | activePage.openEditor(new FileEditorInput(file), editorDescriptor.getId()); 131 | 132 | } 133 | }); 134 | } 135 | 136 | public void replaceSelection(final String newText) throws Exception { 137 | EclipseUtils.runInDisplayThreadSync(new DisplayThreadRunnable() { 138 | @Override 139 | public void runWithDisplay(Display display) throws Exception { 140 | TextSelection selection = EclipseUtils.getCurrentEditorSelection(); 141 | if (selection == null) 142 | throw new IllegalArgumentException(Messages.noSelectionSelected); 143 | ITextEditor editor = EclipseUtils.getCurrentTextEditor(); 144 | if (editor == null) 145 | throw new IllegalArgumentException(Messages.noTextEditorSelected); 146 | IDocumentProvider documentProvider = editor.getDocumentProvider(); 147 | IDocument document = documentProvider.getDocument(editor.getEditorInput()); 148 | if (document == null) 149 | throw new IllegalArgumentException(Messages.noDocumentSelected); 150 | document.replace(selection.getOffset(), selection.getLength(), newText); 151 | editor.selectAndReveal(selection.getOffset(), newText.length()); 152 | } 153 | }); 154 | } 155 | 156 | public void setClipboard(final String text) throws Exception { 157 | EclipseUtils.runInDisplayThreadSync(new DisplayThreadRunnable() { 158 | @Override 159 | public void runWithDisplay(Display display) { 160 | Clipboard clipboard = new Clipboard(display); 161 | try { 162 | clipboard.setContents(new Object[] { text }, new Transfer[] { TextTransfer.getInstance() }); 163 | } finally { 164 | clipboard.dispose(); 165 | } 166 | } 167 | }); 168 | } 169 | 170 | } 171 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scriptobjects/Resources.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scriptobjects; 2 | 3 | import static java.util.regex.Pattern.compile; 4 | 5 | import java.io.InputStream; 6 | import java.io.Reader; 7 | import java.net.URL; 8 | import java.net.URLConnection; 9 | import java.util.ArrayList; 10 | import java.util.Collection; 11 | import java.util.List; 12 | import java.util.regex.Matcher; 13 | import java.util.regex.Pattern; 14 | 15 | import org.eclipse.core.resources.IContainer; 16 | import org.eclipse.core.resources.IFile; 17 | import org.eclipse.core.resources.IProject; 18 | import org.eclipse.core.resources.IResource; 19 | import org.eclipse.core.resources.IWorkspace; 20 | import org.eclipse.core.resources.ResourcesPlugin; 21 | import org.eclipse.core.runtime.CoreException; 22 | import org.eclipse.core.runtime.Path; 23 | import org.eclipse.ui.IEditorInput; 24 | import org.eclipse.ui.IEditorPart; 25 | import org.eclipse.ui.IWorkbench; 26 | import org.eclipse.ui.IWorkbenchPage; 27 | import org.eclipse.ui.IWorkbenchWindow; 28 | import org.eclipse.ui.PlatformUI; 29 | import org.eclipsescript.messages.Messages; 30 | import org.eclipsescript.scripts.IScriptRuntime; 31 | import org.eclipsescript.util.JavaUtils; 32 | 33 | public class Resources { 34 | 35 | private final IScriptRuntime scriptRuntime; 36 | 37 | public Resources(IScriptRuntime scriptRuntime) { 38 | this.scriptRuntime = scriptRuntime; 39 | } 40 | 41 | public IFile[] filesMatching(final String patternString, IResource startingPoint) { 42 | final Pattern pattern = compile(patternString); 43 | final List result = new ArrayList(); 44 | try { 45 | walk(startingPoint, pattern, result); 46 | } catch (final CoreException x) { 47 | // ignore Eclipse internal errors 48 | } 49 | return result.toArray(new IFile[result.size()]); 50 | } 51 | 52 | /** Get the currently selected project. */ 53 | public IProject getCurrentProject() { 54 | IWorkbench workbench = PlatformUI.getWorkbench(); 55 | IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); 56 | if (window == null) { 57 | IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); 58 | if (windows != null) { 59 | window = windows[0]; 60 | } 61 | } 62 | if (window == null) 63 | return null; 64 | IWorkbenchPage activePage = window.getActivePage(); 65 | if (activePage == null) 66 | return null; 67 | IEditorPart activeEditor = activePage.getActiveEditor(); 68 | if (activeEditor == null) 69 | return null; 70 | IEditorInput editorInput = activeEditor.getEditorInput(); 71 | if (editorInput == null) 72 | return null; 73 | IResource resource = (IResource) editorInput.getAdapter(IResource.class); 74 | if (resource == null) 75 | return null; 76 | return resource.getProject(); 77 | } 78 | 79 | // note that exists() should be called to determine existence 80 | public IProject getProject(String projectName) { 81 | return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); 82 | } 83 | 84 | /** Get the project of the currently executing script. */ 85 | public IProject getScriptProject() { 86 | if (scriptRuntime == null) 87 | return null; 88 | if (scriptRuntime.getExecutingFile() == null) 89 | return null; 90 | return scriptRuntime.getExecutingFile().getProject(); 91 | } 92 | 93 | public IWorkspace getWorkspace() { 94 | return ResourcesPlugin.getWorkspace(); 95 | } 96 | 97 | public String read(Object objectToRead) throws Exception { 98 | if (objectToRead instanceof IFile) { 99 | IFile file = (IFile) objectToRead; 100 | return JavaUtils.readAllToStringAndClose(file.getContents(true), file.getCharset()); 101 | } else if (objectToRead instanceof URLConnection) { 102 | URLConnection uc = (URLConnection) objectToRead; 103 | return JavaUtils.readURLConnection(uc); 104 | } else if (objectToRead instanceof URL) { 105 | URL url = (URL) objectToRead; 106 | return JavaUtils.readURL(url); 107 | } else if (objectToRead instanceof String) { 108 | String string = (String) objectToRead; 109 | if (string.contains("://")) { //$NON-NLS-1$ 110 | URL url = new URL(string); 111 | return JavaUtils.readURL(url); 112 | } else { 113 | Path includePath = new Path(string); 114 | IContainer parent = string.startsWith("/") ? scriptRuntime.getExecutingFile().getProject() //$NON-NLS-1$ 115 | : scriptRuntime.getExecutingFile().getParent(); 116 | IFile fileToRead = parent.getFile(includePath); 117 | if (!fileToRead.exists()) 118 | scriptRuntime.abortRunningScript(Messages.fileToReadDoesNotExist 119 | + fileToRead.getFullPath().toOSString()); 120 | return JavaUtils.readAllToStringAndClose(fileToRead.getContents(true), fileToRead.getCharset()); 121 | } 122 | } else if (objectToRead instanceof Reader) { 123 | Reader in = (Reader) objectToRead; 124 | return JavaUtils.readAllToStringAndClose(in); 125 | } else if (objectToRead instanceof InputStream) { 126 | InputStream in = (InputStream) objectToRead; 127 | return JavaUtils.readAllToStringAndClose(in); 128 | } 129 | throw new IllegalArgumentException(Messages.Resources_cannotReadFromObject + objectToRead); 130 | } 131 | 132 | private void walk(final IResource resource, final Pattern pattern, final Collection result) 133 | throws CoreException { 134 | if (resource instanceof IProject) { 135 | final IProject project = (IProject) resource; 136 | if (!project.isOpen()) 137 | return; 138 | final IResource[] children = project.members(); 139 | for (final IResource resource2 : children) 140 | walk(resource2, pattern, result); 141 | } else if (resource instanceof IContainer) { 142 | final IResource[] children = ((IContainer) resource).members(); 143 | for (final IResource resource2 : children) { 144 | walk(resource2, pattern, result); 145 | } 146 | } else if (resource instanceof IFile) { 147 | final String path = resource.getFullPath().toString(); 148 | final Matcher match = pattern.matcher(path); 149 | if (match.matches()) 150 | result.add((IFile) resource); 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scriptobjects/Runtime.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scriptobjects; 2 | 3 | import java.io.IOException; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.eclipse.core.resources.IContainer; 8 | import org.eclipse.core.resources.IFile; 9 | import org.eclipse.core.resources.WorkspaceJob; 10 | import org.eclipse.core.runtime.IProgressMonitor; 11 | import org.eclipse.core.runtime.IStatus; 12 | import org.eclipse.core.runtime.Path; 13 | import org.eclipse.core.runtime.jobs.Job; 14 | import org.eclipse.osgi.util.NLS; 15 | import org.eclipse.swt.widgets.Shell; 16 | import org.eclipse.ui.IWorkbench; 17 | import org.eclipse.ui.PlatformUI; 18 | import org.eclipse.ui.progress.IJobRunnable; 19 | import org.eclipsescript.core.Activator; 20 | import org.eclipsescript.messages.Messages; 21 | import org.eclipsescript.scripts.IScriptRuntime; 22 | import org.eclipsescript.util.EclipseUtils; 23 | 24 | /** 25 | * Object which is put under eclipse.runtime in the script scope containing methods for manipulating the 26 | * currently executing scripts runtime. 27 | */ 28 | public class Runtime { 29 | 30 | private static final Map globals = new HashMap(); 31 | private final IScriptRuntime scriptRuntime; 32 | 33 | public Runtime(IScriptRuntime scriptRuntime) { 34 | this.scriptRuntime = scriptRuntime; 35 | } 36 | 37 | public void asyncExec(Runnable runnable) { 38 | IWorkbench workbench = PlatformUI.getWorkbench(); 39 | workbench.getDisplay().asyncExec(runnable); 40 | } 41 | 42 | public void die(String message) { 43 | scriptRuntime.abortRunningScript(message); 44 | } 45 | 46 | public void disableTimeout() { 47 | scriptRuntime.disableTimeout(); 48 | } 49 | 50 | public void exec(String command) { 51 | try { 52 | java.lang.Runtime.getRuntime().exec(command); 53 | } catch (IOException e) { 54 | Activator.logError(e); 55 | } 56 | } 57 | 58 | public void exit() { 59 | scriptRuntime.exitRunningScript(); 60 | } 61 | 62 | public synchronized Object getGlobal(String key) { 63 | return globals.get(key); 64 | } 65 | 66 | public Shell getShell() { 67 | return EclipseUtils.getWindowShell(); 68 | } 69 | 70 | public void include(Object... includes) throws Exception { 71 | for (Object includeObject : includes) { 72 | IFile fileToInclude; 73 | if (includeObject instanceof IFile) { 74 | fileToInclude = (IFile) includeObject; 75 | } else { 76 | String includeStringPath = (String) includeObject; 77 | Path includePath = new Path(includeStringPath); 78 | IFile executingScriptFile = scriptRuntime.getExecutingFile(); 79 | IContainer startingScriptContainer = executingScriptFile.getParent(); 80 | if (includePath.isAbsolute()) { 81 | fileToInclude = startingScriptContainer.getWorkspace().getRoot().getFile(includePath); 82 | } else { 83 | fileToInclude = startingScriptContainer.getFile(includePath); 84 | } 85 | } 86 | if (!fileToInclude.exists()) 87 | scriptRuntime.abortRunningScript( 88 | Messages.fileToIncludeDoesNotExist + fileToInclude.getFullPath().toOSString()); 89 | scriptRuntime.evaluate(fileToInclude, true); 90 | } 91 | } 92 | 93 | public synchronized void putGlobal(String key, Object value) { 94 | globals.put(key, value); 95 | } 96 | 97 | public void schedule(final Object objectToSchedule) { 98 | final IJobRunnable runnable = scriptRuntime.adaptTo(objectToSchedule, IJobRunnable.class); 99 | if (runnable == null) 100 | throw new IllegalArgumentException(Messages.notPossibleToScheduleObject + objectToSchedule); 101 | String jobName = NLS.bind(Messages.scriptBackgroundJobName, scriptRuntime.getExecutingFile().getName()); 102 | final IScriptRuntime runtime = scriptRuntime; 103 | final IFile executingFile = scriptRuntime.getExecutingFile(); 104 | Job job = new WorkspaceJob(jobName) { 105 | @Override 106 | public IStatus runInWorkspace(IProgressMonitor monitor) { 107 | runtime.setExecutingFile(executingFile); 108 | return runnable.run(monitor); 109 | } 110 | }; 111 | job.setSystem(false); 112 | job.setUser(true); 113 | job.schedule(); 114 | } 115 | 116 | public void syncExec(Runnable runnable) { 117 | IWorkbench workbench = PlatformUI.getWorkbench(); 118 | workbench.getDisplay().syncExec(runnable); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scriptobjects/Window.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scriptobjects; 2 | 3 | import java.net.MalformedURLException; 4 | import java.net.URL; 5 | 6 | 7 | import org.eclipse.jface.action.IStatusLineManager; 8 | import org.eclipse.jface.dialogs.Dialog; 9 | import org.eclipse.jface.dialogs.MessageDialog; 10 | import org.eclipse.swt.SWT; 11 | import org.eclipse.swt.layout.GridData; 12 | import org.eclipse.swt.layout.GridLayout; 13 | import org.eclipse.swt.widgets.Composite; 14 | import org.eclipse.swt.widgets.Control; 15 | import org.eclipse.swt.widgets.Display; 16 | import org.eclipse.swt.widgets.Label; 17 | import org.eclipse.swt.widgets.Shell; 18 | import org.eclipse.swt.widgets.Text; 19 | import org.eclipse.ui.IActionBars; 20 | import org.eclipse.ui.IEditorSite; 21 | import org.eclipse.ui.IViewSite; 22 | import org.eclipse.ui.IWorkbench; 23 | import org.eclipse.ui.IWorkbenchPage; 24 | import org.eclipse.ui.IWorkbenchPart; 25 | import org.eclipse.ui.IWorkbenchPartSite; 26 | import org.eclipse.ui.PartInitException; 27 | import org.eclipse.ui.PlatformUI; 28 | import org.eclipse.ui.browser.IWebBrowser; 29 | import org.eclipse.ui.browser.IWorkbenchBrowserSupport; 30 | import org.eclipsescript.messages.Messages; 31 | import org.eclipsescript.util.EclipseUtils; 32 | import org.eclipsescript.util.EclipseUtils.DisplayThreadRunnable; 33 | import org.eclipsescript.util.JavaUtils.MutableObject; 34 | 35 | public class Window { 36 | 37 | private static class PromptDialog extends Dialog { 38 | 39 | private final String promptText; 40 | Text promptField; 41 | String enteredText; 42 | 43 | public PromptDialog(Shell parentShell, String promptText) { 44 | super(parentShell); 45 | this.promptText = promptText; 46 | } 47 | 48 | @Override 49 | public boolean close() { 50 | enteredText = promptField.getText(); 51 | return super.close(); 52 | } 53 | 54 | @Override 55 | protected Control createDialogArea(Composite parent) { 56 | Composite container = (Composite) super.createDialogArea(parent); 57 | final GridLayout gridLayout = new GridLayout(); 58 | gridLayout.numColumns = 1; 59 | container.setLayout(gridLayout); 60 | 61 | final Label nameLabel = new Label(container, SWT.NONE); 62 | nameLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false)); 63 | nameLabel.setText(promptText + ":"); //$NON-NLS-1$ 64 | 65 | promptField = new Text(container, SWT.BORDER); 66 | promptField.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false)); 67 | promptField.setText(""); //$NON-NLS-1$ 68 | 69 | return container; 70 | } 71 | 72 | } 73 | 74 | public static void alert(final String message) throws Exception { 75 | EclipseUtils.runInDisplayThreadSync(new DisplayThreadRunnable() { 76 | @Override 77 | public void runWithDisplay(Display display) { 78 | MessageDialog.openInformation(EclipseUtils.activeWindow().getShell(), Messages.scriptAlertDialogTitle, 79 | message); 80 | } 81 | }); 82 | } 83 | 84 | public static boolean confirm(final String message) throws Exception { 85 | final MutableObject enteredText = new MutableObject(); 86 | EclipseUtils.runInDisplayThreadSync(new DisplayThreadRunnable() { 87 | @Override 88 | public void runWithDisplay(Display display) { 89 | enteredText.value = MessageDialog.openConfirm(EclipseUtils.getWindowShell(), 90 | Messages.scriptConfirmDialogTitle, message); 91 | } 92 | }); 93 | return enteredText.value; 94 | } 95 | 96 | public static IWebBrowser open(String urlString) throws PartInitException, MalformedURLException { 97 | if (urlString == null) 98 | throw new IllegalArgumentException(Messages.windowOpenArgumentNull); 99 | URL url = new URL(urlString); 100 | IWorkbench workbench = PlatformUI.getWorkbench(); 101 | IWorkbenchBrowserSupport browserSupport = workbench.getBrowserSupport(); 102 | IWebBrowser browser = browserSupport.createBrowser(IWorkbenchBrowserSupport.AS_EXTERNAL, null, null, null); 103 | browser.openURL(url); 104 | return browser; 105 | } 106 | 107 | public static String prompt(final String message) throws Exception { 108 | return prompt(message, ""); //$NON-NLS-1$ 109 | } 110 | 111 | public static String prompt(final String message, final String initialValue) throws Exception { 112 | final MutableObject enteredText = new MutableObject(); 113 | EclipseUtils.runInDisplayThreadSync(new DisplayThreadRunnable() { 114 | @Override 115 | public void runWithDisplay(Display display) { 116 | final PromptDialog dialog = new PromptDialog(EclipseUtils.getWindowShell(), message); 117 | 118 | // create the window shell so the title can be set 119 | dialog.create(); 120 | dialog.getShell().setText(Messages.scriptPromptDialogTitle); 121 | if (initialValue != null) { 122 | dialog.promptField.setText(initialValue); 123 | } 124 | // since the Window has the blockOnOpen property set to true, it 125 | // will dipose of the shell upon close 126 | if (dialog.open() == org.eclipse.jface.window.Window.OK) { 127 | enteredText.value = dialog.enteredText; 128 | } 129 | } 130 | }); 131 | return enteredText.value; 132 | } 133 | 134 | public void setStatus(final String status) throws Exception { 135 | EclipseUtils.runInDisplayThreadAsync(new DisplayThreadRunnable() { 136 | @Override 137 | public void runWithDisplay(Display display) { 138 | IWorkbenchPage page = EclipseUtils.activePage(); 139 | IWorkbenchPart part = page.getActivePart(); 140 | IWorkbenchPartSite site = part.getSite(); 141 | IActionBars actionBars = null; 142 | if (site instanceof IEditorSite) { 143 | IEditorSite editorSite = (IEditorSite) site; 144 | actionBars = editorSite.getActionBars(); 145 | } else if (site instanceof IViewSite) { 146 | IViewSite viewSite = (IViewSite) site; 147 | actionBars = viewSite.getActionBars(); 148 | } 149 | if (actionBars == null) 150 | return; 151 | IStatusLineManager statusLineManager = actionBars.getStatusLineManager(); 152 | if (statusLineManager == null) 153 | return; 154 | statusLineManager.setMessage(status); 155 | } 156 | }); 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scriptobjects/Xml.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scriptobjects; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.DocumentBuilder; 8 | import javax.xml.parsers.DocumentBuilderFactory; 9 | import javax.xml.xpath.XPath; 10 | import javax.xml.xpath.XPathConstants; 11 | import javax.xml.xpath.XPathFactory; 12 | 13 | import org.w3c.dom.Document; 14 | import org.w3c.dom.Element; 15 | import org.w3c.dom.NodeList; 16 | 17 | public class Xml { 18 | 19 | private final Resources resources; 20 | 21 | public Xml(Resources resources) { 22 | this.resources = resources; 23 | } 24 | 25 | public Document parse(Object sourceObject) throws Exception { 26 | String source; 27 | if (sourceObject instanceof String) { 28 | source = (String) sourceObject; 29 | } else { 30 | source = resources.read(sourceObject); 31 | } 32 | DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 33 | builderFactory.setValidating(false); 34 | builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); //$NON-NLS-1$ 35 | DocumentBuilder builder = builderFactory.newDocumentBuilder(); 36 | return builder.parse(new ByteArrayInputStream(source.getBytes("utf-8"))); //$NON-NLS-1$ 37 | } 38 | 39 | public List xpath(Document doc, String expression) throws Exception { 40 | XPathFactory factory = XPathFactory.newInstance(); 41 | XPath xpath = factory.newXPath(); 42 | NodeList resultNodeList = (NodeList) xpath.evaluate(expression, doc, XPathConstants.NODESET); 43 | List resultList = new ArrayList(resultNodeList.getLength()); 44 | for (int i = 0; i < resultNodeList.getLength(); i++) { 45 | resultList.add((Element) resultNodeList.item(i)); 46 | } 47 | return resultList; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scripts/IScriptLanguageSupport.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scripts; 2 | 3 | public interface IScriptLanguageSupport { 4 | 5 | /** 6 | * Execute all scripts in the same contexts. 7 | */ 8 | public void executeScript(ScriptMetadata script); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scripts/IScriptRuntime.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scripts; 2 | 3 | import java.io.IOException; 4 | 5 | import org.eclipse.core.resources.IFile; 6 | 7 | public interface IScriptRuntime { 8 | 9 | public void abortRunningScript(String errorMessage); 10 | 11 | public T adaptTo(Object object, Class clazz); 12 | 13 | public void disableTimeout(); 14 | 15 | public void evaluate(IFile file, boolean nested) throws IOException; 16 | 17 | public void exitRunningScript(); 18 | 19 | public IFile getExecutingFile(); 20 | 21 | public ScriptClassLoader getScriptClassLoader(); 22 | 23 | public void setExecutingFile(IFile file); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scripts/MarkerManager.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scripts; 2 | 3 | import org.eclipse.core.resources.IFile; 4 | import org.eclipse.core.resources.IMarker; 5 | import org.eclipse.core.resources.IResource; 6 | import org.eclipse.core.runtime.CoreException; 7 | import org.eclipsescript.core.Activator; 8 | 9 | public class MarkerManager { 10 | 11 | private static final String SCRIPT_PROBLEM_MARKER_TYPE = "org.eclipsescript.scriptproblemmarker"; //$NON-NLS-1$ 12 | 13 | public static void addMarker(IFile file, ScriptException error) { 14 | try { 15 | IMarker m = file.createMarker(SCRIPT_PROBLEM_MARKER_TYPE); 16 | if (error.getLineNumber() > 0) { 17 | m.setAttribute(IMarker.LINE_NUMBER, error.getLineNumber()); 18 | } 19 | m.setAttribute(IMarker.MESSAGE, error.getMessage()); 20 | m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH); 21 | m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); 22 | // TODO: ? "If we indicated additional information in the marker for IMarker.CHAR_START and 23 | // IMarker.CHAR_END, the 24 | // editor will also draw a red squiggly line under the offending problem" 25 | } catch (CoreException e) { 26 | Activator.logError(e); 27 | } 28 | } 29 | 30 | public static void clearMarkers(IFile file) { 31 | try { 32 | file.deleteMarkers(SCRIPT_PROBLEM_MARKER_TYPE, true, IResource.DEPTH_INFINITE); 33 | } catch (CoreException e) { 34 | Activator.logError(e); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scripts/ScriptClassLoader.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scripts; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.CopyOnWriteArrayList; 5 | 6 | import org.eclipsescript.core.Activator; 7 | import org.osgi.framework.Bundle; 8 | 9 | public class ScriptClassLoader extends ClassLoader { 10 | 11 | private final List bundles = new CopyOnWriteArrayList(); 12 | private final ClassLoader loader; 13 | private final List loaders = new CopyOnWriteArrayList(); 14 | 15 | public ScriptClassLoader(ClassLoader loader) { 16 | this.loader = loader; 17 | } 18 | 19 | public void addBundle(Bundle bundle) { 20 | // note that this requires script to load bundles in dependant order... 21 | bundles.add(0, bundle); 22 | } 23 | 24 | public void addLoader(ClassLoader classLoader) { 25 | // note that this requires script to load bundles in dependant order... 26 | loaders.add(0, classLoader); 27 | } 28 | 29 | @Override 30 | public Class loadClass(String name) throws ClassNotFoundException { 31 | try { 32 | return loader.loadClass(name); 33 | } catch (ClassNotFoundException e) { 34 | // ignore 35 | } 36 | 37 | for (Bundle bundle : bundles) { 38 | try { 39 | return bundle.loadClass(name); 40 | } catch (ClassNotFoundException e) { 41 | // ignore 42 | } 43 | } 44 | 45 | for (ClassLoader classLoader : loaders) { 46 | try { 47 | return classLoader.loadClass(name); 48 | } catch (ClassNotFoundException e) { 49 | // ignore 50 | } 51 | } 52 | 53 | Bundle bundleContainingClass = Activator.getBundleExportingClass(name); 54 | if (bundleContainingClass != null) { 55 | try { 56 | Class clazz = bundleContainingClass.loadClass(name); 57 | addBundle(bundleContainingClass); 58 | return clazz; 59 | } catch (ClassNotFoundException e) { 60 | // handle classes in "split-packages" see http://wiki.osgi.org/wiki/Split_Packages 61 | Bundle[] bundlesExportingPackage = Activator.getBundlesExportingPackage(name); 62 | for (Bundle bundle : bundlesExportingPackage) { 63 | try { 64 | Class clazz = bundle.loadClass(name); 65 | addBundle(bundle); 66 | return clazz; 67 | } catch (ClassNotFoundException e1) { 68 | continue; 69 | } 70 | } 71 | } 72 | } 73 | 74 | return null; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scripts/ScriptException.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scripts; 2 | 3 | public class ScriptException extends RuntimeException { 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | private final int lineNumber; 8 | private final String scriptStackTrace; 9 | private final String sourceName; 10 | 11 | /** 12 | * @param scriptStackTrace 13 | * @param showStackTrace 14 | * not used at the moment, it could perhaps always be useful with stack trace? 15 | */ 16 | public ScriptException(String message, Throwable cause, String sourceName, int lineNumber, String scriptStackTrace, 17 | boolean showStackTrace) { 18 | super(message, cause); 19 | this.lineNumber = lineNumber; 20 | this.sourceName = sourceName; 21 | this.scriptStackTrace = scriptStackTrace; 22 | } 23 | 24 | public int getLineNumber() { 25 | return lineNumber; 26 | } 27 | 28 | public String getScriptStackTrace() { 29 | return scriptStackTrace; 30 | } 31 | 32 | public String getSourceName() { 33 | return sourceName; 34 | } 35 | 36 | public boolean isShowStackTrace() { 37 | return true; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scripts/ScriptLanguageHandler.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scripts; 2 | 3 | import java.util.Collections; 4 | import java.util.Map; 5 | 6 | import org.eclipse.core.resources.IFile; 7 | import org.eclipsescript.javascript.JavaScriptLanguageSupport; 8 | 9 | public class ScriptLanguageHandler { 10 | 11 | public static Map getLanguageSupports() { 12 | return Collections.singletonMap("js", new JavaScriptLanguageSupport()); //$NON-NLS-1$ 13 | } 14 | 15 | static IScriptLanguageSupport getScriptSupport(IFile file) { 16 | String fileName = file.getName(); 17 | int index = -1; 18 | int len = 14; 19 | index = fileName.lastIndexOf(".eclipse.auto."); //$NON-NLS-1$ 20 | if (index == -1) { 21 | len = 9; 22 | index = fileName.lastIndexOf(".eclipse."); //$NON-NLS-1$ 23 | } 24 | if (index == -1) 25 | return null; 26 | String fileExtension = fileName.substring(index + len); 27 | return getLanguageSupports().get(fileExtension); 28 | } 29 | 30 | public static boolean isEclipseScriptFile(IFile file) { 31 | return getScriptSupport(file) != null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scripts/ScriptMetadata.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scripts; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.concurrent.atomic.AtomicInteger; 6 | 7 | 8 | import org.eclipse.core.resources.IFile; 9 | import org.eclipsescript.core.Activator; 10 | 11 | public class ScriptMetadata implements Comparable { 12 | 13 | private static final AtomicInteger counter = new AtomicInteger(); 14 | 15 | private final IFile file; 16 | private final int instanceId; 17 | private final String label; 18 | 19 | public ScriptMetadata(IFile file) { 20 | this.instanceId = counter.getAndIncrement(); 21 | this.file = file; 22 | 23 | String fileName = file.getName(); 24 | int index = fileName.lastIndexOf(".eclipse."); //$NON-NLS-1$ 25 | String scriptName = fileName.substring(0, index); 26 | 27 | String firstLine = null; 28 | try { 29 | BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents(true), file.getCharset())); 30 | try { 31 | firstLine = reader.readLine(); 32 | } finally { 33 | reader.close(); 34 | } 35 | } catch (Exception e) { 36 | Activator.logError(e); 37 | } 38 | 39 | if (firstLine == null) { 40 | label = scriptName; 41 | } else { 42 | firstLine = firstLine.trim(); 43 | if (firstLine.startsWith("//") || firstLine.startsWith("/*")) { //$NON-NLS-1$ //$NON-NLS-2$ 44 | this.label = scriptName + " - " + firstLine.substring(2).trim(); //$NON-NLS-1$ 45 | } else { 46 | this.label = scriptName; 47 | } 48 | } 49 | } 50 | 51 | @Override 52 | public int compareTo(ScriptMetadata o) { 53 | return instanceId - o.instanceId; 54 | } 55 | 56 | @Override 57 | public boolean equals(Object other) { 58 | return (other instanceof ScriptMetadata) && ((ScriptMetadata) other).instanceId == instanceId; 59 | } 60 | 61 | public IFile getFile() { 62 | return file; 63 | } 64 | 65 | public String getFullPath() { 66 | return file.getFullPath().toString(); 67 | } 68 | 69 | public String getLabel() { 70 | return label; 71 | } 72 | 73 | @Override 74 | public int hashCode() { 75 | return instanceId; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/org/eclipsescript/scripts/ScriptStore.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.scripts; 2 | 3 | import java.util.concurrent.Callable; 4 | 5 | import org.eclipse.core.resources.IFile; 6 | import org.eclipse.core.runtime.IPath; 7 | import org.eclipse.core.runtime.Path; 8 | import org.eclipse.jface.text.BadLocationException; 9 | import org.eclipse.jface.text.IDocument; 10 | import org.eclipse.osgi.util.NLS; 11 | import org.eclipse.swt.widgets.Display; 12 | import org.eclipse.ui.IEditorPart; 13 | import org.eclipse.ui.IWorkbenchPage; 14 | import org.eclipse.ui.texteditor.IDocumentProvider; 15 | import org.eclipse.ui.texteditor.ITextEditor; 16 | import org.eclipsescript.core.Activator; 17 | import org.eclipsescript.core.RunLastHandler; 18 | import org.eclipsescript.messages.Messages; 19 | import org.eclipsescript.ui.ErrorDetailsDialog; 20 | import org.eclipsescript.util.EclipseUtils; 21 | import org.eclipsescript.util.EclipseUtils.DisplayThreadRunnable; 22 | 23 | public class ScriptStore { 24 | 25 | public static T executeRunnableWhichMayThrowScriptException(final ScriptMetadata script, Callable r) { 26 | try { 27 | try { 28 | return r.call(); 29 | } catch (final ScriptException error) { 30 | IFile file = getFile(script, error); 31 | MarkerManager.addMarker(file, error); 32 | EclipseUtils.runInDisplayThreadSync(new DisplayThreadRunnable() { 33 | @Override 34 | public void runWithDisplay(Display display) throws Exception { 35 | showMessageOfferJumpToScript(script, error); 36 | } 37 | }); 38 | } 39 | } catch (Exception e) { 40 | Activator.logError(e); 41 | } 42 | return null; 43 | } 44 | 45 | public static void executeScript(final ScriptMetadata script) { 46 | // add this even if script execution fails 47 | RunLastHandler.lastRun = script; 48 | final IScriptLanguageSupport languageSupport = ScriptLanguageHandler.getScriptSupport(script.getFile()); 49 | 50 | executeRunnableWhichMayThrowScriptException(script, new Callable() { 51 | @Override 52 | public Void call() throws Exception { 53 | languageSupport.executeScript(script); 54 | return null; 55 | } 56 | }); 57 | } 58 | 59 | static IFile getFile(ScriptMetadata script, ScriptException scriptException) { 60 | IFile file = null; 61 | try { 62 | String sourceName = scriptException.getSourceName(); 63 | int hashIdx = sourceName.indexOf('#'); 64 | if (hashIdx != -1) { 65 | sourceName = sourceName.substring(0, hashIdx); 66 | } 67 | IPath path = new Path(sourceName); 68 | file = script.getFile().getWorkspace().getRoot().getFile(path); 69 | } catch (Throwable t) { 70 | file = script.getFile(); 71 | } 72 | return file; 73 | } 74 | 75 | static void showMessageOfferJumpToScript(ScriptMetadata script, ScriptException e) { 76 | final String[] choices = new String[] { Messages.scriptErrorWhenRunningScriptOkButton, 77 | Messages.scriptErrorWhenRunningScriptJumpToScriptButton }; 78 | 79 | int lineNumber = Math.max(e.getLineNumber(), 1); 80 | IFile file = getFile(script, e); 81 | 82 | String dialogTitle = Messages.scriptErrorWhenRunningScriptDialogTitle; 83 | String dialogText = NLS.bind(Messages.scriptErrorWhenRunningScriptDialogText, new Object[] { 84 | script.getFile().getName(), e.getCause().getMessage(), Integer.toString(lineNumber) }); 85 | 86 | if (e.getScriptStackTrace() != null && !e.getScriptStackTrace().isEmpty()) { 87 | dialogText = dialogText + "\n\n" + e.getScriptStackTrace(); //$NON-NLS-1$ 88 | } 89 | 90 | int result = ErrorDetailsDialog.openError(EclipseUtils.getWindowShell(), dialogTitle, dialogText, e.getCause(), 91 | choices, e.isShowStackTrace()); 92 | if (result == 1) { 93 | IEditorPart editorPart = EclipseUtils.openEditor(file); 94 | if (editorPart instanceof ITextEditor) { 95 | ITextEditor textEditor = (ITextEditor) editorPart; 96 | IDocumentProvider provider = textEditor.getDocumentProvider(); 97 | IDocument document = provider.getDocument(textEditor.getEditorInput()); 98 | try { 99 | int start = document.getLineOffset(lineNumber - 1); 100 | textEditor.selectAndReveal(start, 0); 101 | IWorkbenchPage page = textEditor.getSite().getPage(); 102 | page.activate(textEditor); 103 | } catch (BadLocationException e2) { 104 | throw new RuntimeException(e2); 105 | } 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/org/eclipsescript/ui/CloseConsolePageParticipant.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.ui; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.eclipse.jface.action.Action; 7 | import org.eclipse.jface.action.IToolBarManager; 8 | import org.eclipse.ui.IActionBars; 9 | import org.eclipse.ui.console.ConsolePlugin; 10 | import org.eclipse.ui.console.IConsole; 11 | import org.eclipse.ui.console.IConsoleConstants; 12 | import org.eclipse.ui.console.IConsoleManager; 13 | import org.eclipse.ui.console.IConsolePageParticipant; 14 | import org.eclipse.ui.console.actions.CloseConsoleAction; 15 | import org.eclipse.ui.part.IPageBookViewPage; 16 | import org.eclipse.ui.part.IPageSite; 17 | import org.eclipsescript.core.Activator; 18 | import org.eclipsescript.messages.Messages; 19 | import org.eclipsescript.scriptobjects.Console; 20 | 21 | public class CloseConsolePageParticipant implements IConsolePageParticipant { 22 | 23 | public static class RemoveAllTerminatedAction extends Action { 24 | 25 | public RemoveAllTerminatedAction() { 26 | super(Messages.removeAllTerminatedConsoles, Activator.getImageDescriptor(Activator.IMG_REMOVE_ALL)); 27 | setToolTipText(Messages.removeAllTerminatedConsoles); 28 | } 29 | 30 | @Override 31 | public void run() { 32 | // ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[] { fConsole }); 33 | ConsolePlugin consolePlugin = ConsolePlugin.getDefault(); 34 | IConsoleManager consoleManager = consolePlugin.getConsoleManager(); 35 | List consolesToRemove = new ArrayList(); 36 | for (IConsole console : consoleManager.getConsoles()) { 37 | if (console instanceof Console.ConsoleClass) { 38 | ((Console.ConsoleClass) console).isDisposed = true; 39 | consolesToRemove.add(console); 40 | } 41 | } 42 | consoleManager.removeConsoles(consolesToRemove.toArray(new IConsole[consolesToRemove.size()])); 43 | } 44 | 45 | } 46 | 47 | @Override 48 | public void activated() { 49 | // do nothing 50 | } 51 | 52 | @Override 53 | public void deactivated() { 54 | // do nothing 55 | } 56 | 57 | @Override 58 | public void dispose() { 59 | // do nothing 60 | } 61 | 62 | @Override 63 | public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { 64 | return adapter.isInstance(this) ? this : null; 65 | } 66 | 67 | /** Method overridden to add close console action to the console toolbar. */ 68 | @Override 69 | public void init(IPageBookViewPage page, IConsole console) { 70 | CloseConsoleAction action = new CloseConsoleAction(console); 71 | IPageSite site = page.getSite(); 72 | IActionBars actionBars = site.getActionBars(); 73 | IToolBarManager manager = actionBars.getToolBarManager(); 74 | manager.appendToGroup(IConsoleConstants.LAUNCH_GROUP, action); 75 | manager.appendToGroup(IConsoleConstants.LAUNCH_GROUP, new RemoveAllTerminatedAction()); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/org/eclipsescript/ui/ErrorDetailsDialog.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.ui; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | 6 | 7 | import org.eclipse.jface.dialogs.IDialogConstants; 8 | import org.eclipse.jface.dialogs.IconAndMessageDialog; 9 | import org.eclipse.jface.resource.JFaceResources; 10 | import org.eclipse.osgi.util.NLS; 11 | import org.eclipse.swt.SWT; 12 | import org.eclipse.swt.dnd.Clipboard; 13 | import org.eclipse.swt.dnd.TextTransfer; 14 | import org.eclipse.swt.dnd.Transfer; 15 | import org.eclipse.swt.events.SelectionEvent; 16 | import org.eclipse.swt.events.SelectionListener; 17 | import org.eclipse.swt.graphics.Image; 18 | import org.eclipse.swt.graphics.Point; 19 | import org.eclipse.swt.layout.GridData; 20 | import org.eclipse.swt.layout.GridLayout; 21 | import org.eclipse.swt.widgets.Button; 22 | import org.eclipse.swt.widgets.Composite; 23 | import org.eclipse.swt.widgets.Control; 24 | import org.eclipse.swt.widgets.Label; 25 | import org.eclipse.swt.widgets.Menu; 26 | import org.eclipse.swt.widgets.MenuItem; 27 | import org.eclipse.swt.widgets.Shell; 28 | import org.eclipse.swt.widgets.Text; 29 | import org.eclipsescript.core.Activator; 30 | import org.eclipsescript.messages.Messages; 31 | import org.osgi.framework.Constants; 32 | 33 | /** 34 | * A dialog to display one or more errors to the user, as contained in an IStatus object. If an error 35 | * contains additional detailed information then a Details button is automatically supplied, which shows or hides an 36 | * error details viewer when pressed by the user. 37 | * 38 | *

39 | * This dialog should be considered being a "local" way of error handling. It cannot be changed or replaced by "global" 40 | * error handling facility ( org.eclipse.ui.statushandler.StatusManager). If product defines its own way of 41 | * handling errors, this error dialog may cause UI inconsistency, so until it is absolutely necessary, 42 | * StatusManager should be used. 43 | *

44 | * 45 | * @see org.eclipse.core.runtime.IStatus 46 | */ 47 | public class ErrorDetailsDialog extends IconAndMessageDialog { 48 | 49 | public static int openError(Shell parent, String dialogTitle, String message, Throwable exception) { 50 | return openError(parent, dialogTitle, message, exception, new String[] { IDialogConstants.OK_LABEL }, true); 51 | } 52 | 53 | /** 54 | * Opens an error dialog to display the given error. Use this method if the error object being displayed does not 55 | * contain child items, or if you wish to display all such items without filtering. 56 | * 57 | * @param parent 58 | * the parent shell of the dialog, or null if none 59 | * @param dialogTitle 60 | * the title to use for this dialog, or null to indicate that the default title should be 61 | * used 62 | * @param message 63 | * the message to show in this dialog, or null to indicate that the error's message should 64 | * be shown as the primary message 65 | * @param choices 66 | * @param status 67 | * the error to show to the user 68 | * @return the code of the button that was pressed that resulted in this dialog closing. This will be 69 | * Dialog.OK if the OK button was pressed, or Dialog.CANCEL if this dialog's close 70 | * window decoration or the ESC key was used. 71 | */ 72 | public static int openError(Shell parent, String dialogTitle, String message, Throwable exception2, 73 | String[] choices, boolean showDetails) { 74 | ErrorDetailsDialog dialog = new ErrorDetailsDialog(parent, dialogTitle, message, exception2, choices, 75 | showDetails); 76 | return dialog.open(); 77 | } 78 | 79 | private final String[] choices; 80 | private Button detailsButton; 81 | private final String dialogTitle; 82 | private Text errorDetailsText; 83 | private final Throwable exception; 84 | private final boolean showDetails; 85 | 86 | /** 87 | * Creates an error dialog. Note that the dialog will have no visual representation (no widgets) until it is told to 88 | * open. 89 | *

90 | * Normally one should use openError to create and open one of these. This constructor is useful only 91 | * if the error object being displayed contains child items and you need to specify a mask which will be 92 | * used to filter the displaying of these children. The error dialog will only be displayed if there is at least one 93 | * child status matching the mask. 94 | *

95 | * 96 | * @param parentShell 97 | * the shell under which to create this dialog 98 | * @param dialogTitle 99 | * the title to use for this dialog, or null to indicate that the default title should be 100 | * used 101 | * @param message 102 | * the message to show in this dialog, or null to indicate that the error's message should 103 | * be shown as the primary message 104 | * @param choices2 105 | */ 106 | ErrorDetailsDialog(Shell parentShell, String dialogTitle, String message, Throwable exception, String[] choices, 107 | boolean showDetails) { 108 | super(parentShell); 109 | this.dialogTitle = dialogTitle == null ? JFaceResources.getString("Problem_Occurred") : //$NON-NLS-1$ 110 | dialogTitle; 111 | this.message = message; 112 | this.exception = exception; 113 | this.choices = choices; 114 | this.showDetails = showDetails; 115 | } 116 | 117 | /* 118 | * (non-Javadoc) Method declared on Dialog. Handles the pressing of the Ok or Details button in this dialog. If the 119 | * Ok button was pressed then close this dialog. If the Details button was pressed then toggle the displaying of the 120 | * error details area. Note that the Details button will only be visible if the error being displayed specifies 121 | * child details. 122 | */ 123 | @Override 124 | protected void buttonPressed(int id) { 125 | if (id == IDialogConstants.DETAILS_ID) { 126 | // was the details button pressed? 127 | toggleDetailsArea(); 128 | } else { 129 | setReturnCode(id); 130 | close(); 131 | } 132 | } 133 | 134 | @Override 135 | protected void configureShell(Shell shell) { 136 | super.configureShell(shell); 137 | shell.setText(dialogTitle); 138 | } 139 | 140 | /** Copy the contents of the statuses to the clipboard. */ 141 | void copyToClipboard() { 142 | String textToCopy = errorDetailsText.getText(); 143 | Clipboard clipboard = new Clipboard(errorDetailsText.getDisplay()); 144 | try { 145 | clipboard.setContents(new Object[] { textToCopy }, new Transfer[] { TextTransfer.getInstance() }); 146 | } finally { 147 | clipboard.dispose(); 148 | } 149 | } 150 | 151 | @Override 152 | protected void createButtonsForButtonBar(Composite parent) { 153 | // create OK and Details buttons 154 | boolean defaultButton = true; 155 | int id = 0; 156 | for (String choice : choices) { 157 | createButton(parent, id++, choice, defaultButton); 158 | if (defaultButton) 159 | defaultButton = false; 160 | } 161 | if (showDetails) { 162 | detailsButton = createButton(parent, IDialogConstants.DETAILS_ID, IDialogConstants.SHOW_DETAILS_LABEL, 163 | false); 164 | } 165 | } 166 | 167 | @Override 168 | protected void createDialogAndButtonArea(Composite parent) { 169 | super.createDialogAndButtonArea(parent); 170 | if (this.dialogArea instanceof Composite) { 171 | // Create a label if there are no children to force a smaller layout 172 | Composite dialogComposite = (Composite) dialogArea; 173 | if (dialogComposite.getChildren().length == 0) { 174 | new Label(dialogComposite, SWT.NULL); 175 | } 176 | } 177 | } 178 | 179 | /** 180 | * This implementation of the Dialog framework method creates and lays out a composite. Subclasses that 181 | * require a different dialog area may either override this method, or call the super implementation 182 | * and add controls to the created composite. 183 | * 184 | * Note: Since 3.4, the created composite no longer grabs excess vertical space. See 185 | * https://bugs.eclipse.org/bugs/show_bug.cgi?id=72489. If the old behavior is desired by subclasses, get the 186 | * returned composite's layout data and set grabExcessVerticalSpace to true. 187 | */ 188 | @Override 189 | protected Control createDialogArea(Composite parent) { 190 | // Create a composite with standard margins and spacing 191 | // Add the messageArea to this composite so that as subclasses add widgets to the messageArea 192 | // and dialogArea, the number of children of parent remains fixed and with consistent layout. 193 | // Fixes bug #240135 194 | Composite composite = new Composite(parent, SWT.NONE); 195 | createMessageArea(composite); 196 | GridLayout layout = new GridLayout(); 197 | layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 198 | layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 199 | layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); 200 | layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 201 | layout.numColumns = 2; 202 | composite.setLayout(layout); 203 | GridData childData = new GridData(GridData.FILL_BOTH); 204 | childData.horizontalSpan = 2; 205 | childData.grabExcessVerticalSpace = false; 206 | composite.setLayoutData(childData); 207 | composite.setFont(parent.getFont()); 208 | 209 | return composite; 210 | } 211 | 212 | /** 213 | * Create this dialog's drop-down list component. 214 | * 215 | * @param parent 216 | * the parent composite 217 | * @return the drop-down list component 218 | */ 219 | protected Text createDropDownList(Composite parent) { 220 | // create the list 221 | errorDetailsText = new Text(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY | SWT.WRAP); 222 | 223 | StringWriter writer = new StringWriter(); 224 | exception.printStackTrace(new PrintWriter(writer)); 225 | String stackTraceText = writer.getBuffer().toString(); 226 | 227 | String detailsText = NLS.bind(Messages.internalErrorDialogDetails, new Object[] { 228 | Activator.getDefault().getBundle().getHeaders().get(Constants.BUNDLE_NAME), 229 | Activator.getDefault().getBundle().getSymbolicName(), 230 | Activator.getDefault().getBundle().getHeaders().get(Constants.BUNDLE_VERSION), stackTraceText }); 231 | errorDetailsText.setText(detailsText); 232 | 233 | GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL 234 | | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_VERTICAL); 235 | data.heightHint = 300; 236 | data.horizontalSpan = 2; 237 | errorDetailsText.setLayoutData(data); 238 | errorDetailsText.setFont(parent.getFont()); 239 | Menu copyMenu = new Menu(errorDetailsText); 240 | MenuItem copyItem = new MenuItem(copyMenu, SWT.NONE); 241 | copyItem.addSelectionListener(new SelectionListener() { 242 | /** @see SelectionListener.widgetDefaultSelected(SelectionEvent) */ 243 | @Override 244 | public void widgetDefaultSelected(SelectionEvent e) { 245 | copyToClipboard(); 246 | } 247 | 248 | /** @see SelectionListener.widgetSelected (SelectionEvent) */ 249 | @Override 250 | public void widgetSelected(SelectionEvent e) { 251 | copyToClipboard(); 252 | } 253 | }); 254 | copyItem.setText(JFaceResources.getString("copy")); //$NON-NLS-1$ 255 | errorDetailsText.setMenu(copyMenu); 256 | return errorDetailsText; 257 | } 258 | 259 | @Override 260 | protected Image getImage() { 261 | // If it was not a warning or an error then return the error image 262 | return getErrorImage(); 263 | } 264 | 265 | @Override 266 | protected boolean isResizable() { 267 | return true; 268 | } 269 | 270 | /** 271 | * Toggles the unfolding of the details area. This is triggered by the user pressing the details button. 272 | */ 273 | private void toggleDetailsArea() { 274 | Point windowSize = getShell().getSize(); 275 | Point oldSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); 276 | if (errorDetailsText != null && !errorDetailsText.isDisposed()) { 277 | errorDetailsText.dispose(); 278 | detailsButton.setText(IDialogConstants.SHOW_DETAILS_LABEL); 279 | } else { 280 | errorDetailsText = createDropDownList((Composite) getContents()); 281 | detailsButton.setText(IDialogConstants.HIDE_DETAILS_LABEL); 282 | getContents().getShell().layout(); 283 | } 284 | Point newSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); 285 | getShell().setSize(new Point(windowSize.x, windowSize.y + (newSize.y - oldSize.y))); 286 | } 287 | 288 | } 289 | -------------------------------------------------------------------------------- /src/org/eclipsescript/ui/ErrorHandlingHandler.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.ui; 2 | 3 | 4 | import org.eclipse.core.commands.AbstractHandler; 5 | import org.eclipse.core.commands.ExecutionEvent; 6 | import org.eclipse.core.commands.ExecutionException; 7 | import org.eclipsescript.core.Activator; 8 | 9 | public abstract class ErrorHandlingHandler extends AbstractHandler { 10 | 11 | protected abstract void doExecute(ExecutionEvent event) throws Exception; 12 | 13 | @Override 14 | public final Object execute(ExecutionEvent event) throws ExecutionException { 15 | try { 16 | doExecute(event); 17 | } catch (LinkageError e) { 18 | Activator.logError(e); 19 | } catch (Exception e) { 20 | Activator.logError(e); 21 | } 22 | return null; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/org/eclipsescript/ui/QuickAccessElement.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.ui; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.eclipse.jface.resource.ImageDescriptor; 7 | 8 | public abstract class QuickAccessElement { 9 | 10 | /** Copied from internal class org.eclipse.ui.internal.quickaccess.CamelUtil. */ 11 | private static class CamelUtil { 12 | 13 | /** 14 | * Returns a lowercase string consisting of all initials of the words in the given String. Words are separated 15 | * by whitespace and other special characters, or by uppercase letters in a word like CamelCase. 16 | * 17 | * @param s 18 | * the string 19 | * @return a lowercase string containing the first character of every wordin the given string. 20 | */ 21 | public static String getCamelCase(String s) { 22 | StringBuffer result = new StringBuffer(); 23 | if (s.length() > 0) { 24 | int index = 0; 25 | while (index != -1) { 26 | result.append(s.charAt(index)); 27 | index = getNextCamelIndex(s, index + 1); 28 | } 29 | } 30 | return result.toString().toLowerCase(); 31 | } 32 | 33 | /** 34 | * Return an array with start/end indices for the characters used for camel case matching, ignoring the first 35 | * (start) many camel case characters. For example, getCamelCaseIndices("some CamelCase", 1, 2) will return 36 | * {{5,5},{10,10}}. 37 | * 38 | * @param s 39 | * the source string 40 | * @param start 41 | * how many characters of getCamelCase(s) should be ignored 42 | * @param length 43 | * for how many characters should indices be returned 44 | * @return an array of length start 45 | */ 46 | public static int[][] getCamelCaseIndices(String s, int startParameter, int lengthParameter) { 47 | int start = startParameter; 48 | int length = lengthParameter; 49 | List result = new ArrayList(); 50 | int index = 0; 51 | while (start > 0) { 52 | index = getNextCamelIndex(s, index + 1); 53 | start--; 54 | } 55 | while (length > 0) { 56 | result.add(new int[] { index, index }); 57 | index = getNextCamelIndex(s, index + 1); 58 | length--; 59 | } 60 | return result.toArray(new int[result.size()][]); 61 | } 62 | 63 | /** 64 | * Returns the next index to be used for camel case matching. 65 | * 66 | * @param s 67 | * the string 68 | * @param index 69 | * the index 70 | * @return the next index, or -1 if not found 71 | */ 72 | public static int getNextCamelIndex(String s, int indexParameter) { 73 | int index = indexParameter; 74 | char c; 75 | while (index < s.length() && !(isSeparatorForCamelCase(c = s.charAt(index))) && Character.isLowerCase(c)) { 76 | index++; 77 | } 78 | while (index < s.length() && isSeparatorForCamelCase(c = s.charAt(index))) { 79 | index++; 80 | } 81 | if (index >= s.length()) { 82 | index = -1; 83 | } 84 | return index; 85 | } 86 | 87 | /** 88 | * Returns true if the given character is to be considered a separator for camel case matching purposes. 89 | * 90 | * @param c 91 | * the character 92 | * @return true if the character is a separator 93 | */ 94 | public static boolean isSeparatorForCamelCase(char c) { 95 | return !Character.isLetterOrDigit(c); 96 | } 97 | 98 | } 99 | 100 | /** Executes the associated action for this element. */ 101 | public abstract void execute(); 102 | 103 | /** The image descriptor for this element, or null if no image is available */ 104 | public abstract ImageDescriptor getImageDescriptor(); 105 | 106 | /** The label to be displayed to the user. */ 107 | public abstract String getLabel(); 108 | 109 | /** The label to be used for sorting and matching elements. */ 110 | public String getSortLabel() { 111 | return getLabel(); 112 | } 113 | 114 | public QuickAccessEntry match(String filter) { 115 | String sortLabel = getLabel(); 116 | int index = sortLabel.toLowerCase().indexOf(filter); 117 | if (index != -1) { 118 | return new QuickAccessEntry(this, new int[][] { { index, index + filter.length() - 1 } }); 119 | } 120 | String camelCase = CamelUtil.getCamelCase(sortLabel); 121 | index = camelCase.indexOf(filter); 122 | if (index != -1) { 123 | int[][] indices = CamelUtil.getCamelCaseIndices(sortLabel, index, filter.length()); 124 | return new QuickAccessEntry(this, indices); 125 | } 126 | return null; 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /src/org/eclipsescript/ui/QuickAccessEntry.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.ui; 2 | 3 | import org.eclipse.jface.resource.DeviceResourceException; 4 | import org.eclipse.jface.resource.ImageDescriptor; 5 | import org.eclipse.jface.resource.ResourceManager; 6 | import org.eclipse.swt.SWT; 7 | import org.eclipse.swt.graphics.Image; 8 | import org.eclipse.swt.graphics.Rectangle; 9 | import org.eclipse.swt.graphics.TextLayout; 10 | import org.eclipse.swt.graphics.TextStyle; 11 | import org.eclipse.swt.widgets.Event; 12 | import org.eclipse.swt.widgets.Table; 13 | import org.eclipse.swt.widgets.TableItem; 14 | import org.eclipsescript.core.Activator; 15 | 16 | final class QuickAccessEntry { 17 | public static void erase(Event event) { 18 | // We are only custom drawing the foreground. 19 | event.detail &= ~SWT.FOREGROUND; 20 | } 21 | 22 | private static Image findOrCreateImage(ImageDescriptor imageDescriptor, ResourceManager resourceManager) { 23 | if (imageDescriptor == null) { 24 | return null; 25 | } 26 | Image image = (Image) resourceManager.find(imageDescriptor); 27 | if (image == null) { 28 | try { 29 | image = resourceManager.createImage(imageDescriptor); 30 | } catch (DeviceResourceException e) { 31 | Activator.logError(e); 32 | } 33 | } 34 | return image; 35 | } 36 | 37 | QuickAccessElement element; 38 | 39 | private final int[][] elementMatchRegions; 40 | 41 | QuickAccessEntry(QuickAccessElement element, int[][] elementMatchRegions) { 42 | this.element = element; 43 | this.elementMatchRegions = elementMatchRegions; 44 | } 45 | 46 | Image getImage(ResourceManager resourceManager) { 47 | Image image = findOrCreateImage(element.getImageDescriptor(), resourceManager); 48 | if (image == null) { 49 | throw new IllegalArgumentException("Null image for element: " + element); //$NON-NLS-1$ 50 | } 51 | return image; 52 | } 53 | 54 | public void measure(Event event, TextLayout textLayout, ResourceManager resourceManager, TextStyle boldStyle) { 55 | Table table = ((TableItem) event.item).getParent(); 56 | textLayout.setFont(table.getFont()); 57 | event.width = 0; 58 | switch (event.index) { 59 | case 0: 60 | Image image = getImage(resourceManager); 61 | Rectangle imageRect = image.getBounds(); 62 | event.width += imageRect.width + 4; 63 | event.height = Math.max(event.height, imageRect.height + 2); 64 | textLayout.setText(element.getLabel()); 65 | for (int i = 0; i < elementMatchRegions.length; i++) { 66 | int[] matchRegion = elementMatchRegions[i]; 67 | textLayout.setStyle(boldStyle, matchRegion[0], matchRegion[1]); 68 | } 69 | break; 70 | default: 71 | throw new IllegalArgumentException("Invalid event.index: " + event.index); //$NON-NLS-1$ 72 | } 73 | Rectangle rect = textLayout.getBounds(); 74 | event.width += rect.width + 4; 75 | event.height = Math.max(event.height, rect.height + 2); 76 | } 77 | 78 | public void paint(Event event, TextLayout textLayout, ResourceManager resourceManager, TextStyle boldStyle) { 79 | final Table table = ((TableItem) event.item).getParent(); 80 | textLayout.setFont(table.getFont()); 81 | switch (event.index) { 82 | case 0: 83 | Image image = getImage(resourceManager); 84 | event.gc.drawImage(image, event.x + 1, event.y + 1); 85 | textLayout.setText(element.getLabel()); 86 | for (int i = 0; i < elementMatchRegions.length; i++) { 87 | int[] matchRegion = elementMatchRegions[i]; 88 | textLayout.setStyle(boldStyle, matchRegion[0], matchRegion[1]); 89 | } 90 | Rectangle availableBounds = ((TableItem) event.item).getTextBounds(event.index); 91 | Rectangle requiredBounds = textLayout.getBounds(); 92 | textLayout.draw(event.gc, availableBounds.x + 1 + image.getBounds().width, availableBounds.y 93 | + (availableBounds.height - requiredBounds.height) / 2); 94 | break; 95 | default: 96 | throw new IllegalArgumentException("Invalid event.index: " + event.index); //$NON-NLS-1$ 97 | } 98 | } 99 | } -------------------------------------------------------------------------------- /src/org/eclipsescript/ui/QuickAccessProvider.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.ui; 2 | 3 | import java.util.Arrays; 4 | import java.util.Comparator; 5 | 6 | public abstract class QuickAccessProvider { 7 | 8 | private QuickAccessElement[] sortedElements; 9 | 10 | /** 11 | * Returns the elements provided by this provider. 12 | * 13 | * @return this provider's elements 14 | */ 15 | public abstract QuickAccessElement[] getElements(); 16 | 17 | public QuickAccessElement[] getElementsSorted() { 18 | if (sortedElements == null) { 19 | sortedElements = getElements(); 20 | Arrays.sort(sortedElements, new Comparator() { 21 | @Override 22 | public int compare(QuickAccessElement e1, QuickAccessElement e2) { 23 | return e1.getLabel().compareToIgnoreCase(e2.getLabel()); 24 | } 25 | }); 26 | } 27 | return sortedElements; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /src/org/eclipsescript/ui/QuickScriptDialog.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.ui; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.Iterator; 6 | import java.util.List; 7 | 8 | import org.eclipse.jface.dialogs.IDialogSettings; 9 | import org.eclipse.jface.dialogs.PopupDialog; 10 | import org.eclipse.jface.layout.GridDataFactory; 11 | import org.eclipse.jface.layout.GridLayoutFactory; 12 | import org.eclipse.jface.layout.TableColumnLayout; 13 | import org.eclipse.jface.resource.FontDescriptor; 14 | import org.eclipse.jface.resource.JFaceResources; 15 | import org.eclipse.jface.resource.LocalResourceManager; 16 | import org.eclipse.jface.viewers.ColumnWeightData; 17 | import org.eclipse.swt.SWT; 18 | import org.eclipse.swt.events.KeyAdapter; 19 | import org.eclipse.swt.events.KeyEvent; 20 | import org.eclipse.swt.events.ModifyEvent; 21 | import org.eclipse.swt.events.ModifyListener; 22 | import org.eclipse.swt.events.MouseAdapter; 23 | import org.eclipse.swt.events.MouseEvent; 24 | import org.eclipse.swt.events.SelectionAdapter; 25 | import org.eclipse.swt.events.SelectionEvent; 26 | import org.eclipse.swt.graphics.Font; 27 | import org.eclipse.swt.graphics.Point; 28 | import org.eclipse.swt.graphics.TextLayout; 29 | import org.eclipse.swt.graphics.TextStyle; 30 | import org.eclipse.swt.widgets.Composite; 31 | import org.eclipse.swt.widgets.Control; 32 | import org.eclipse.swt.widgets.Event; 33 | import org.eclipse.swt.widgets.Listener; 34 | import org.eclipse.swt.widgets.Table; 35 | import org.eclipse.swt.widgets.TableColumn; 36 | import org.eclipse.swt.widgets.TableItem; 37 | import org.eclipse.swt.widgets.Text; 38 | import org.eclipse.ui.IWorkbenchWindow; 39 | import org.eclipsescript.core.Activator; 40 | 41 | /** 42 | * Derived from org.eclipse.ui.internal.QuickAccessDialog. 43 | */ 44 | public final class QuickScriptDialog extends PopupDialog { 45 | 46 | Text filterText; 47 | final QuickAccessProvider provider = new QuickScriptProvider(); 48 | LocalResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources()); 49 | Table table; 50 | TextLayout textLayout; 51 | 52 | public QuickScriptDialog(IWorkbenchWindow window) { 53 | super(/* parent: */window.getShell(), /* shellStyle: */SWT.RESIZE, /* takeFocusOnOpen: */true, /* persistSize: */ 54 | true, /* persistLocation: */false, 55 | /* showDialogMenu: */false, /* showPersistActions: */false, /* titleText: */"", //$NON-NLS-1$ 56 | /* infoText: */null); 57 | } 58 | 59 | @Override 60 | public boolean close() { 61 | if (textLayout != null && !textLayout.isDisposed()) { 62 | textLayout.dispose(); 63 | } 64 | if (resourceManager != null) { 65 | resourceManager.dispose(); 66 | resourceManager = null; 67 | } 68 | return super.close(); 69 | } 70 | 71 | /** 72 | * @see org.eclipse.jface.dialogs.PopupDialog#createDialogArea(org.eclipse.swt.widgets.Composite) 73 | */ 74 | @Override 75 | protected Control createDialogArea(Composite parent) { 76 | Composite composite = (Composite) super.createDialogArea(parent); 77 | boolean isWin32 = "win32".equals(SWT.getPlatform()); //$NON-NLS-1$ 78 | GridLayoutFactory.fillDefaults().extendedMargins(isWin32 ? 0 : 3, 3, 2, 2).applyTo(composite); 79 | Composite tableComposite = new Composite(composite, SWT.NONE); 80 | GridDataFactory.fillDefaults().grab(true, true).applyTo(tableComposite); 81 | TableColumnLayout tableColumnLayout = new TableColumnLayout(); 82 | tableComposite.setLayout(tableColumnLayout); 83 | table = new Table(tableComposite, SWT.SINGLE | SWT.FULL_SELECTION); 84 | textLayout = new TextLayout(table.getDisplay()); 85 | textLayout.setOrientation(getDefaultOrientation()); 86 | Font boldFont = resourceManager.createFont(FontDescriptor.createFrom(JFaceResources.getDialogFont()).setStyle( 87 | SWT.BOLD)); 88 | textLayout.setFont(table.getFont()); 89 | 90 | // tableColumnLayout.setColumnData(new TableColumn(table, SWT.NONE), new ColumnWeightData(0, maxProviderWidth)); 91 | tableColumnLayout.setColumnData(new TableColumn(table, SWT.NONE), new ColumnWeightData(100, 100)); 92 | 93 | table.addKeyListener(new KeyAdapter() { 94 | @Override 95 | public void keyPressed(KeyEvent e) { 96 | if (e.keyCode == SWT.ARROW_UP && table.getSelectionIndex() == 0) { 97 | filterText.setFocus(); 98 | } else if (e.character == SWT.ESC) { 99 | close(); 100 | } 101 | } 102 | }); 103 | 104 | table.addMouseListener(new MouseAdapter() { 105 | @Override 106 | public void mouseUp(MouseEvent e) { 107 | if (table.getSelectionCount() < 1) 108 | return; 109 | if (e.button != 1) 110 | return; 111 | if (table.equals(e.getSource())) { 112 | Object o = table.getItem(new Point(e.x, e.y)); 113 | TableItem selection = table.getSelection()[0]; 114 | if (selection.equals(o)) 115 | handleSelection(); 116 | } 117 | } 118 | }); 119 | 120 | table.addSelectionListener(new SelectionAdapter() { 121 | @Override 122 | public void widgetDefaultSelected(SelectionEvent e) { 123 | handleSelection(); 124 | } 125 | }); 126 | 127 | // italicsFont = resourceManager.createFont(FontDescriptor.createFrom( 128 | // table.getFont()).setStyle(SWT.ITALIC)); 129 | final TextStyle boldStyle = new TextStyle(boldFont, null, null); 130 | Listener listener = new Listener() { 131 | @Override 132 | public void handleEvent(Event event) { 133 | QuickAccessEntry entry = (QuickAccessEntry) event.item.getData(); 134 | if (entry != null) { 135 | switch (event.type) { 136 | case SWT.MeasureItem: 137 | entry.measure(event, textLayout, resourceManager, boldStyle); 138 | break; 139 | case SWT.PaintItem: 140 | entry.paint(event, textLayout, resourceManager, boldStyle); 141 | break; 142 | case SWT.EraseItem: 143 | QuickAccessEntry.erase(event); 144 | break; 145 | default: 146 | break; 147 | } 148 | } 149 | } 150 | }; 151 | table.addListener(SWT.MeasureItem, listener); 152 | table.addListener(SWT.EraseItem, listener); 153 | table.addListener(SWT.PaintItem, listener); 154 | 155 | return composite; 156 | } 157 | 158 | @Override 159 | protected Control createTitleControl(Composite parent) { 160 | filterText = new Text(parent, SWT.NONE); 161 | 162 | GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(filterText); 163 | 164 | filterText.addKeyListener(new KeyAdapter() { 165 | @Override 166 | public void keyPressed(KeyEvent e) { 167 | if (e.keyCode == 0x0D) { 168 | handleSelection(); 169 | return; 170 | } else if (e.keyCode == SWT.ARROW_DOWN) { 171 | int index = table.getSelectionIndex(); 172 | if (index != -1 && table.getItemCount() > index + 1) { 173 | table.setSelection(index + 1); 174 | } 175 | table.setFocus(); 176 | } else if (e.keyCode == SWT.ARROW_UP) { 177 | int index = table.getSelectionIndex(); 178 | if (index != -1 && index >= 1) { 179 | table.setSelection(index - 1); 180 | table.setFocus(); 181 | } 182 | } else if (e.character == 0x1B) // ESC 183 | close(); 184 | } 185 | }); 186 | filterText.addModifyListener(new ModifyListener() { 187 | @Override 188 | public void modifyText(ModifyEvent e) { 189 | String text = ((Text) e.widget).getText().toLowerCase(); 190 | refresh(text); 191 | } 192 | }); 193 | 194 | return filterText; 195 | } 196 | 197 | // eclipse 3.4: 198 | // @Override 199 | // protected Point getDefaultLocation(Point initialSize) { 200 | // Point size = new Point(400, 400); 201 | // Rectangle parentBounds = getParentShell().getBounds(); 202 | // int x = parentBounds.x + parentBounds.width / 2 - size.x / 2; 203 | // int y = parentBounds.y + parentBounds.height / 2 - size.y / 2; 204 | // return new Point(x, y); 205 | // } 206 | 207 | @Override 208 | protected Point getDefaultSize() { 209 | return new Point(600, 600); 210 | } 211 | 212 | @Override 213 | protected IDialogSettings getDialogSettings() { 214 | return Activator.getDefault().getDialogSettings(); 215 | } 216 | 217 | @Override 218 | protected Control getFocusControl() { 219 | return filterText; 220 | } 221 | 222 | void handleSelection() { 223 | QuickAccessElement selectedElement = null; 224 | if (table.getSelectionCount() == 1) { 225 | QuickAccessEntry entry = (QuickAccessEntry) table.getSelection()[0].getData(); 226 | selectedElement = entry == null ? null : entry.element; 227 | } 228 | close(); 229 | if (selectedElement != null) { 230 | selectedElement.execute(); 231 | } 232 | } 233 | 234 | void refresh(String filter) { 235 | List entries; 236 | if (filter.isEmpty()) { 237 | entries = Collections.emptyList(); 238 | } else { 239 | entries = new ArrayList(); 240 | QuickAccessElement[] elements = provider.getElementsSorted(); 241 | for (QuickAccessElement element : elements) { 242 | QuickAccessEntry entry = element.match(filter); 243 | if (entry != null) 244 | entries.add(entry); 245 | } 246 | } 247 | 248 | TableItem[] items = table.getItems(); 249 | int index = 0; 250 | for (Iterator it = entries.iterator(); it.hasNext();) { 251 | QuickAccessEntry entry = it.next(); 252 | TableItem item; 253 | if (index < items.length) { 254 | item = items[index]; 255 | table.clear(index); 256 | } else { 257 | item = new TableItem(table, SWT.NONE); 258 | } 259 | item.setData(entry); 260 | item.setText(0, entry.element.getLabel()); 261 | if (SWT.getPlatform().equals("wpf")) { //$NON-NLS-1$ 262 | item.setImage(0, entry.getImage(resourceManager)); 263 | } 264 | index++; 265 | } 266 | if (index < items.length) { 267 | table.remove(index, items.length - 1); 268 | } 269 | if (table.getItems().length > 0) 270 | table.setSelection(0); 271 | } 272 | 273 | } -------------------------------------------------------------------------------- /src/org/eclipsescript/ui/QuickScriptProvider.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.ui; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | 7 | import org.eclipse.core.resources.IFile; 8 | import org.eclipse.core.resources.IResource; 9 | import org.eclipse.core.resources.IResourceProxy; 10 | import org.eclipse.core.resources.IResourceProxyVisitor; 11 | import org.eclipse.core.resources.IWorkspaceRoot; 12 | import org.eclipse.core.resources.ResourcesPlugin; 13 | import org.eclipse.core.runtime.CoreException; 14 | import org.eclipse.jface.resource.ImageDescriptor; 15 | import org.eclipsescript.core.Activator; 16 | import org.eclipsescript.scripts.ScriptMetadata; 17 | import org.eclipsescript.scripts.ScriptStore; 18 | 19 | public class QuickScriptProvider extends QuickAccessProvider { 20 | 21 | static final ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle() 22 | .getEntry("icons/run_script.gif")); //$NON-NLS-1$ 23 | 24 | @Override 25 | public QuickAccessElement[] getElements() { 26 | final List allScripts = new ArrayList(); 27 | IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); 28 | try { 29 | root.accept(new IResourceProxyVisitor() { 30 | @Override 31 | public boolean visit(IResourceProxy proxy) throws CoreException { 32 | if (proxy.getName().endsWith(".eclipse.js")) { //$NON-NLS-1$ 33 | IResource resource = proxy.requestResource(); 34 | if (resource instanceof IFile && !resource.isDerived()) { 35 | IFile file = (IFile) resource; 36 | allScripts.add(new ScriptMetadata(file)); 37 | } 38 | } 39 | return true; 40 | } 41 | }, 0); 42 | } catch (CoreException e) { 43 | e.printStackTrace(); 44 | } 45 | 46 | QuickAccessElement[] elements = new QuickAccessElement[allScripts.size()]; 47 | for (int i = 0; i < elements.length; i++) { 48 | final ScriptMetadata script = allScripts.get(i); 49 | elements[i] = new QuickAccessElement() { 50 | 51 | @Override 52 | public void execute() { 53 | ScriptStore.executeScript(script); 54 | } 55 | 56 | @Override 57 | public ImageDescriptor getImageDescriptor() { 58 | return imageDescriptor; 59 | } 60 | 61 | @Override 62 | public String getLabel() { 63 | return script.getLabel(); 64 | } 65 | }; 66 | } 67 | return elements; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/org/eclipsescript/util/EclipseUtils.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.util; 2 | 3 | import org.eclipse.core.resources.IFile; 4 | import org.eclipse.jface.text.IDocument; 5 | import org.eclipse.jface.text.TextSelection; 6 | import org.eclipse.jface.viewers.ISelection; 7 | import org.eclipse.jface.viewers.ISelectionProvider; 8 | import org.eclipse.swt.widgets.Display; 9 | import org.eclipse.swt.widgets.Shell; 10 | import org.eclipse.ui.IEditorDescriptor; 11 | import org.eclipse.ui.IEditorInput; 12 | import org.eclipse.ui.IEditorPart; 13 | import org.eclipse.ui.IEditorRegistry; 14 | import org.eclipse.ui.IWorkbench; 15 | import org.eclipse.ui.IWorkbenchPage; 16 | import org.eclipse.ui.IWorkbenchWindow; 17 | import org.eclipse.ui.PartInitException; 18 | import org.eclipse.ui.PlatformUI; 19 | import org.eclipse.ui.part.FileEditorInput; 20 | import org.eclipse.ui.texteditor.IDocumentProvider; 21 | import org.eclipse.ui.texteditor.ITextEditor; 22 | import org.eclipsescript.core.Activator; 23 | import org.eclipsescript.util.JavaUtils.MutableObject; 24 | 25 | public class EclipseUtils { 26 | 27 | public static interface DisplayThreadCallable { 28 | public T callWithDisplay(Display display) throws Exception; 29 | } 30 | 31 | /** A runnable to run in the display thread. */ 32 | public static interface DisplayThreadRunnable { 33 | public void runWithDisplay(Display display) throws Exception; 34 | } 35 | 36 | public static IWorkbenchPage activePage() { 37 | return activeWindow().getActivePage(); 38 | } 39 | 40 | public static IWorkbenchWindow activeWindow() { 41 | return PlatformUI.getWorkbench().getActiveWorkbenchWindow(); 42 | } 43 | 44 | public static IDocument getCurrentDocument() { 45 | ITextEditor editor = getCurrentTextEditor(); 46 | if (editor == null) 47 | return null; 48 | IDocumentProvider documentProvider = editor.getDocumentProvider(); 49 | IDocument document = documentProvider.getDocument(editor.getEditorInput()); 50 | return document; 51 | } 52 | 53 | public static IEditorInput getCurrentEditorInput() { 54 | ITextEditor editor = getCurrentTextEditor(); 55 | if (editor == null) 56 | return null; 57 | return editor.getEditorInput(); 58 | } 59 | 60 | public static TextSelection getCurrentEditorSelection() { 61 | ITextEditor editor = getCurrentTextEditor(); 62 | if (editor == null) 63 | return null; 64 | ISelectionProvider selectionProvider = editor.getSelectionProvider(); 65 | ISelection selection = selectionProvider.getSelection(); 66 | if (selection instanceof TextSelection) { 67 | TextSelection textSelection = (TextSelection) selection; 68 | return textSelection; 69 | } 70 | return null; 71 | } 72 | 73 | public static ITextEditor getCurrentTextEditor() { 74 | IWorkbench workbench = PlatformUI.getWorkbench(); 75 | IWorkbenchWindow activeWindow = workbench.getActiveWorkbenchWindow(); 76 | IWorkbenchPage activePage = activeWindow.getActivePage(); 77 | if (activePage == null) 78 | return null; 79 | IEditorPart activeEditor = activePage.getActiveEditor(); 80 | if (activeEditor == null) 81 | return null; 82 | ITextEditor textEditor = (ITextEditor) activeEditor.getAdapter(ITextEditor.class); 83 | return textEditor; 84 | } 85 | 86 | public static IEditorDescriptor getDefaultEditor(final IFile file) { 87 | if (file == null) 88 | return null; 89 | IWorkbench workbench = PlatformUI.getWorkbench(); 90 | IEditorDescriptor descriptor = workbench.getEditorRegistry().getDefaultEditor(file.getName()); 91 | if (descriptor != null) 92 | return descriptor; 93 | descriptor = workbench.getEditorRegistry().getDefaultEditor("simple_text_file.txt"); //$NON-NLS-1$ 94 | if (descriptor != null) 95 | return descriptor; 96 | descriptor = workbench.getEditorRegistry().findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID); 97 | if (descriptor != null) 98 | return descriptor; 99 | return workbench.getEditorRegistry().findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); 100 | } 101 | 102 | public static Shell getWindowShell() { 103 | return activeWindow().getShell(); 104 | } 105 | 106 | public static IEditorPart openEditor(final IFile file) { 107 | final IEditorDescriptor descriptor = getDefaultEditor(file); 108 | try { 109 | return activePage().openEditor(new FileEditorInput(file), descriptor.getId()); 110 | } catch (PartInitException e) { 111 | Activator.logError(e); 112 | return null; 113 | } 114 | } 115 | 116 | private static T runInDisplayThread(final DisplayThreadCallable runnable, final boolean sync) 117 | throws Exception { 118 | final Display display = PlatformUI.getWorkbench().getDisplay(); 119 | 120 | if (Thread.currentThread().equals(display.getThread())) { 121 | return runnable.callWithDisplay(display); 122 | } else { 123 | final MutableObject exceptionThrownInUIThread = new MutableObject(); 124 | final MutableObject result = new MutableObject(); 125 | 126 | Runnable showExceptionWrapper = new Runnable() { 127 | @Override 128 | public void run() { 129 | try { 130 | result.value = runnable.callWithDisplay(display); 131 | } catch (Exception e) { 132 | if (sync) { 133 | exceptionThrownInUIThread.value = e; 134 | } else { 135 | Activator.logError(e); 136 | } 137 | } 138 | } 139 | }; 140 | 141 | if (sync) { 142 | display.syncExec(showExceptionWrapper); 143 | } else { 144 | display.asyncExec(showExceptionWrapper); 145 | } 146 | if (exceptionThrownInUIThread.value != null) { 147 | throw exceptionThrownInUIThread.value; 148 | } 149 | 150 | return result.value; 151 | } 152 | } 153 | 154 | public static void runInDisplayThreadAsync(final DisplayThreadRunnable runnable) throws Exception { 155 | runInDisplayThread(new DisplayThreadCallable() { 156 | 157 | @Override 158 | public Void callWithDisplay(Display display) throws Exception { 159 | runnable.runWithDisplay(display); 160 | return null; 161 | } 162 | }, false); 163 | } 164 | 165 | public static T runInDisplayThreadSync(final DisplayThreadCallable runnable) throws Exception { 166 | return runInDisplayThread(runnable, true); 167 | } 168 | 169 | public static void runInDisplayThreadSync(final DisplayThreadRunnable runnable) throws Exception { 170 | runInDisplayThread(new DisplayThreadCallable() { 171 | 172 | @Override 173 | public Void callWithDisplay(Display display) throws Exception { 174 | runnable.runWithDisplay(display); 175 | return null; 176 | } 177 | }, false); 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/org/eclipsescript/util/JavaUtils.java: -------------------------------------------------------------------------------- 1 | package org.eclipsescript.util; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.Closeable; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.Reader; 8 | import java.net.URL; 9 | import java.net.URLConnection; 10 | 11 | public class JavaUtils { 12 | 13 | public static abstract class BaseRunnable implements Runnable { 14 | public abstract void doRun() throws Exception; 15 | 16 | @Override 17 | public final void run() { 18 | try { 19 | doRun(); 20 | } catch (Exception e) { 21 | throw asRuntime(e); 22 | } 23 | } 24 | } 25 | 26 | public static class MutableObject { 27 | public T value; 28 | } 29 | 30 | private static final String UTF8_CHARSET_NAME = "utf-8"; //$NON-NLS-1$ 31 | 32 | public static RuntimeException asRuntime(Throwable e) { 33 | return (e instanceof RuntimeException) ? ((RuntimeException) e) : new RuntimeException(e); 34 | } 35 | 36 | public static void close(Closeable c) { 37 | if (c == null) 38 | return; 39 | try { 40 | c.close(); 41 | } catch (IOException e) { 42 | throw new RuntimeException(e); 43 | } 44 | } 45 | 46 | public static boolean isNotBlank(String s) { 47 | return s != null && s.length() != 0; 48 | } 49 | 50 | public static byte[] readAll(InputStream in) throws IOException { 51 | try { 52 | byte[] buffer = new byte[512]; 53 | int n; 54 | ByteArrayOutputStream baous = new ByteArrayOutputStream(); 55 | while ((n = in.read(buffer)) != -1) { 56 | baous.write(buffer, 0, n); 57 | } 58 | return baous.toByteArray(); 59 | } finally { 60 | close(in); 61 | } 62 | } 63 | 64 | public static String readAllToStringAndClose(InputStream in) { 65 | return readAllToStringAndClose(in, UTF8_CHARSET_NAME); 66 | } 67 | 68 | public static String readAllToStringAndClose(InputStream in, String charSetName) { 69 | try { 70 | String charSetNameToUse = charSetName; 71 | if (charSetName == null || charSetName.isEmpty()) 72 | charSetNameToUse = UTF8_CHARSET_NAME; 73 | return new String(readAll(in), charSetNameToUse); 74 | } catch (IOException e) { 75 | throw new RuntimeException(e); 76 | } finally { 77 | close(in); 78 | } 79 | } 80 | 81 | public static String readAllToStringAndClose(Reader in) { 82 | StringBuilder result = new StringBuilder(); 83 | try { 84 | char[] buffer = new char[4096]; 85 | int n; 86 | while ((n = in.read(buffer)) != -1) { 87 | result.append(buffer, 0, n); 88 | } 89 | return result.toString(); 90 | } catch (IOException e) { 91 | throw new RuntimeException(e); 92 | } finally { 93 | close(in); 94 | } 95 | } 96 | 97 | public static String readURL(URL url) throws Exception { 98 | URLConnection uc = url.openConnection(); 99 | return readURLConnection(uc); 100 | } 101 | 102 | public static String readURLConnection(URLConnection uc) throws Exception { 103 | String contentType = uc.getContentType(); 104 | int charSetNameIndex = contentType.indexOf("charset="); //$NON-NLS-1$ 105 | String charSet; 106 | if (charSetNameIndex == -1) { 107 | charSet = UTF8_CHARSET_NAME; 108 | } else { 109 | charSet = contentType.substring(charSetNameIndex + 8); 110 | } 111 | InputStream in = uc.getInputStream(); 112 | try { 113 | return readAllToStringAndClose(in, charSet); 114 | } finally { 115 | in.close(); 116 | } 117 | } 118 | 119 | } 120 | --------------------------------------------------------------------------------