diff options
Diffstat (limited to 'org.eclipse.m2e.editor.xml')
28 files changed, 2151 insertions, 1845 deletions
diff --git a/org.eclipse.m2e.editor.xml/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.editor.xml/.settings/org.eclipse.jdt.core.prefs index 3bbcdfcf..80d9c54b 100644 --- a/org.eclipse.m2e.editor.xml/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.m2e.editor.xml/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,22 @@ -#Sat Jul 30 19:02:00 MSD 2011 eclipse.preferences.version=1 +org.eclipse.jdt.core.builder.cleanOutputFolder=clean +org.eclipse.jdt.core.builder.duplicateResourceTask=warning +org.eclipse.jdt.core.builder.invalidClasspath=abort +org.eclipse.jdt.core.builder.recreateModifiedClassFileInOutputFolder=ignore +org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch +org.eclipse.jdt.core.circularClasspath=error +org.eclipse.jdt.core.classpath.exclusionPatterns=enabled +org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled +org.eclipse.jdt.core.codeComplete.argumentPrefixes= +org.eclipse.jdt.core.codeComplete.argumentSuffixes= +org.eclipse.jdt.core.codeComplete.fieldPrefixes= +org.eclipse.jdt.core.codeComplete.fieldSuffixes= +org.eclipse.jdt.core.codeComplete.localPrefixes= +org.eclipse.jdt.core.codeComplete.localSuffixes= +org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= +org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve @@ -7,11 +24,94 @@ org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.doc.comment.support=enabled +org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=enabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning +org.eclipse.jdt.core.compiler.problem.invalidJavadoc=ignore +org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public +org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning +org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled +org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,HIGH +org.eclipse.jdt.core.compiler.taskTags=TODO,FIXME,XXX org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 @@ -22,15 +122,18 @@ org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 org.eclipse.jdt.core.formatter.blank_lines_after_imports=2 org.eclipse.jdt.core.formatter.blank_lines_after_package=1 org.eclipse.jdt.core.formatter.blank_lines_before_field=1 @@ -66,10 +169,16 @@ org.eclipse.jdt.core.formatter.comment.indent_root_tags=true org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert org.eclipse.jdt.core.formatter.comment.line_length=120 +org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true +org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true +org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false org.eclipse.jdt.core.formatter.compact_else_if=true org.eclipse.jdt.core.formatter.continuation_indentation=2 org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off +org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true @@ -87,6 +196,7 @@ org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert @@ -153,12 +263,14 @@ org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invoca org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert @@ -182,6 +294,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invoc org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert @@ -237,6 +350,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invoc org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=do not insert org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert @@ -246,6 +360,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=inser org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert @@ -255,6 +370,8 @@ org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_ org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.join_lines_in_comments=true +org.eclipse.jdt.core.formatter.join_wrapped_lines=true org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false @@ -267,5 +384,10 @@ org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.tabulation.char=space org.eclipse.jdt.core.formatter.tabulation.size=2 +org.eclipse.jdt.core.formatter.use_on_off_tags=false org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true +org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true +org.eclipse.jdt.core.incompatibleJDKLevel=ignore +org.eclipse.jdt.core.incompleteClasspath=error diff --git a/org.eclipse.m2e.editor.xml/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.m2e.editor.xml/.settings/org.eclipse.jdt.ui.prefs index 83d1ff6e..595d9975 100644 --- a/org.eclipse.m2e.editor.xml/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.m2e.editor.xml/.settings/org.eclipse.jdt.ui.prefs @@ -1,9 +1,66 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_m2 plugin -formatter_settings_version=11 +formatter_settings_version=12 +org.eclipse.jdt.ui.exception.name=ex +org.eclipse.jdt.ui.gettersetter.use.is=true org.eclipse.jdt.ui.ignorelowercasenames=true -org.eclipse.jdt.ui.importorder=java;javax;org;com;org.osgi;org.eclipse;org.eclipse.m2e; -org.eclipse.jdt.ui.javadoc=false +org.eclipse.jdt.ui.importorder=java;javax;org;org.w3c;org.xml;org.apache;com;junit;org.eclipse;org.codehaus;org.apache.lucene;org.apache.maven;org.sonatype;org.eclipse.m2e; +org.eclipse.jdt.ui.javadoc=true +org.eclipse.jdt.ui.keywordthis=true org.eclipse.jdt.ui.ondemandthreshold=99 +org.eclipse.jdt.ui.overrideannotation=false org.eclipse.jdt.ui.staticondemandthreshold=99 -org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*******************************************************************************\n * Copyright (c) 2010 Sonatype, Inc.\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http\://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors\:\n * Sonatype, Inc. - initial API and implementation\n *******************************************************************************/</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates> +org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return Returns the ${bare_field_name}.\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} The ${bare_field_name} to set.\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*******************************************************************************&\#13;\n * Copyright (c) 2010 Sonatype, Inc.&\#13;\n * All rights reserved. This program and the accompanying materials&\#13;\n * are made available under the terms of the Eclipse Public License v1.0&\#13;\n * which accompanies this distribution, and is available at&\#13;\n * http\://www.eclipse.org/legal/epl-v10.html&\#13;\n *&\#13;\n * Contributors\:&\#13;\n * Sonatype, Inc. - initial API and implementation&\#13;\n *******************************************************************************/</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * ${type_name}\n *\n * @author ${user}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\nlog.error(${exception_var}.getMessage(), ${exception_var});</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method ${enclosing_method}\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter function" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter function" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="filecomment_context" deleted\="false" description\="Comment for created JavaScript files" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\n * \n */</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for vars" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding function" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding functions" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Jsdoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate functions" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\nlog.error(${exception_var}.getMessage(), ${exception_var});</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created function stubs" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated function stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates> +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=true +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=true +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=false +sp_cleanup.organize_imports=true +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_trailing_whitespaces=false +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertArtifactProposal.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertArtifactProposal.java index 3587ff0d..2f96292e 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertArtifactProposal.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertArtifactProposal.java @@ -11,13 +11,36 @@ package org.eclipse.m2e.editor.xml; -import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.*; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.BUILD; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.CLASSIFIER; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCIES; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY_MANAGEMENT; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.GROUP_ID; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.PARENT; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.PLUGIN; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.PLUGINS; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.PLUGIN_MANAGEMENT; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.PROFILE; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.RELATIVE_PATH; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.SCOPE; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.TYPE; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.VERSION; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.createElement; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.elementAtOffset; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChild; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.format; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.getChild; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.insertAt; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument; +import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.setText; import java.io.IOException; -import org.apache.maven.project.MavenProject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -37,6 +60,8 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; +import org.apache.maven.project.MavenProject; + import org.eclipse.m2e.core.internal.index.IIndex; import org.eclipse.m2e.core.internal.index.IndexedArtifactFile; import org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog; @@ -45,13 +70,19 @@ import org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple; import org.eclipse.m2e.editor.xml.internal.Messages; import org.eclipse.m2e.editor.xml.internal.XmlUtils; -public class InsertArtifactProposal implements ICompletionProposal, ICompletionProposalExtension4, ICompletionProposalExtension5 { + +public class InsertArtifactProposal implements ICompletionProposal, ICompletionProposalExtension4, + ICompletionProposalExtension5 { private static final Logger log = LoggerFactory.getLogger(InsertArtifactProposal.class); private ISourceViewer sourceViewer; + private Region region; + private int generatedLength = 0; + private int generatedOffset; + private Configuration config; public InsertArtifactProposal(ISourceViewer sourceViewer, Region region, Configuration config) { @@ -66,28 +97,28 @@ public class InsertArtifactProposal implements ICompletionProposal, ICompletionP MavenProject prj = XmlUtils.extractMavenProject(sourceViewer); IProject eclPrj = XmlUtils.extractProject(sourceViewer); MavenRepositorySearchDialog dialog = null; - if (config.getType() == SearchType.PLUGIN) { + if(config.getType() == SearchType.PLUGIN) { String path = XmlUtils.pathUp(config.getCurrentNode(), 2); - boolean inPM = path.contains("pluginManagement"); //$NON-NLS-1$ - dialog = MavenRepositorySearchDialog.createSearchPluginDialog(sourceViewer.getTextWidget().getShell(), - config.getType().getWindowTitle(), prj, eclPrj, inPM); + boolean inPM = path.contains("pluginManagement"); //$NON-NLS-1$ + dialog = MavenRepositorySearchDialog.createSearchPluginDialog(sourceViewer.getTextWidget().getShell(), config + .getType().getWindowTitle(), prj, eclPrj, inPM); } - if (config.getType() == SearchType.PARENT) { - dialog = MavenRepositorySearchDialog.createSearchParentDialog(sourceViewer.getTextWidget().getShell(), - config.getType().getWindowTitle(), prj, eclPrj); + if(config.getType() == SearchType.PARENT) { + dialog = MavenRepositorySearchDialog.createSearchParentDialog(sourceViewer.getTextWidget().getShell(), config + .getType().getWindowTitle(), prj, eclPrj); } - if (config.getType() == SearchType.DEPENDENCY) { + if(config.getType() == SearchType.DEPENDENCY) { //only populate the lists when in dependency search.. // and when in dependency management or plugin section use the different set than elsewhere to get different visual effect. String path = XmlUtils.pathUp(config.getCurrentNode(), 2); boolean inDM = path.contains(DEPENDENCY_MANAGEMENT); - dialog = MavenRepositorySearchDialog.createSearchDependencyDialog(sourceViewer.getTextWidget().getShell(), - config.getType().getWindowTitle(), prj, eclPrj, inDM); + dialog = MavenRepositorySearchDialog.createSearchDependencyDialog(sourceViewer.getTextWidget().getShell(), config + .getType().getWindowTitle(), prj, eclPrj, inDM); } - if (dialog == null) { + if(dialog == null) { throw new IllegalStateException("Wrong search type: " + config.getType()); } - if (config.getInitiaSearchString() != null) { + if(config.getInitiaSearchString() != null) { dialog.setQuery(config.getInitiaSearchString()); } final MavenRepositorySearchDialog fDialog = dialog; @@ -95,24 +126,25 @@ public class InsertArtifactProposal implements ICompletionProposal, ICompletionP final IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); int offset = region.getOffset(); if(af != null) { - if (config.getType() == SearchType.PARENT) { + if(config.getType() == SearchType.PARENT) { try { - final int fOffset = offset; - performOnDOMDocument(new OperationTuple(document, new Operation() { - public void process(Document doc) { - Element parent = insertAt(doc.createElement(PARENT), fOffset); - setText(getChild(parent, GROUP_ID), af.group); - setText(getChild(parent, ARTIFACT_ID), af.artifact); - setText(getChild(parent, VERSION), af.version); - String relativePath = PomContentAssistProcessor.findRelativePath(sourceViewer, af.group, af.artifact, af.version); - if (relativePath != null) { - setText(getChild(parent, RELATIVE_PATH), relativePath); - } - format(parent); - generatedOffset = ((IndexedRegion)parent).getStartOffset(); - generatedLength = ((IndexedRegion)parent).getEndOffset() - generatedOffset; + final int fOffset = offset; + performOnDOMDocument(new OperationTuple(document, new Operation() { + public void process(Document doc) { + Element parent = insertAt(doc.createElement(PARENT), fOffset); + setText(getChild(parent, GROUP_ID), af.group); + setText(getChild(parent, ARTIFACT_ID), af.artifact); + setText(getChild(parent, VERSION), af.version); + String relativePath = PomContentAssistProcessor.findRelativePath(sourceViewer, af.group, af.artifact, + af.version); + if(relativePath != null) { + setText(getChild(parent, RELATIVE_PATH), relativePath); } - })); + format(parent); + generatedOffset = ((IndexedRegion) parent).getStartOffset(); + generatedLength = ((IndexedRegion) parent).getEndOffset() - generatedOffset; + } + })); } catch(IOException e) { log.error("Failed inserting parent element", e); //$NON-NLS-1$ } catch(CoreException e) { @@ -121,14 +153,14 @@ public class InsertArtifactProposal implements ICompletionProposal, ICompletionP } // plugin type - + if(config.getType() == SearchType.PLUGIN) { try { final int fOffset = offset; performOnDOMDocument(new OperationTuple(document, new Operation() { public void process(Document doc) { Element currentNode = elementAtOffset(doc, fOffset); - if (currentNode == null) { + if(currentNode == null) { return; } String currentName = currentNode.getNodeName(); @@ -153,17 +185,17 @@ public class InsertArtifactProposal implements ICompletionProposal, ICompletionP if(PLUGINS.equals(currentName)) { plugin = insertAt(doc.createElement(PLUGIN), fOffset); } - if (toFormat == null) { + if(toFormat == null) { toFormat = plugin; } setText(getChild(plugin, GROUP_ID), af.group); setText(getChild(plugin, ARTIFACT_ID), af.artifact); - if (af.version != null) { + if(af.version != null) { setText(getChild(plugin, VERSION), af.version); } format(toFormat); - generatedOffset = ((IndexedRegion)toFormat).getStartOffset(); - generatedLength = ((IndexedRegion)toFormat).getEndOffset() - generatedOffset; + generatedOffset = ((IndexedRegion) toFormat).getStartOffset(); + generatedLength = ((IndexedRegion) toFormat).getEndOffset() - generatedOffset; } })); } catch(IOException e) { @@ -172,65 +204,64 @@ public class InsertArtifactProposal implements ICompletionProposal, ICompletionP log.error("Failed inserting plugin element", e); //$NON-NLS-1$ } } - // dependency type - - if (config.getType() == SearchType.DEPENDENCY) { - try { - final int fOffset = offset; - performOnDOMDocument(new OperationTuple(document, new Operation() { - public void process(Document doc) { - Element currentNode = elementAtOffset(doc, fOffset); - if (currentNode == null) { - return; - } - String currentName = currentNode.getNodeName(); - Element dependency = null; - Element toFormat = null; - if("project".equals(currentName) || DEPENDENCY_MANAGEMENT.equals(currentName) || PROFILE.equals(currentName)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - Element deps = findChild(currentNode, DEPENDENCIES); - if(deps == null) { - deps = insertAt(doc.createElement(DEPENDENCIES), fOffset); - toFormat = deps; - } - dependency = doc.createElement(DEPENDENCY); - deps.appendChild(dependency); - } - if(DEPENDENCIES.equals(currentName)) { - dependency = insertAt(doc.createElement(DEPENDENCY), fOffset); - } - if (toFormat == null) { - toFormat = dependency; - } - setText(getChild(dependency, GROUP_ID), af.group); - setText(getChild(dependency, ARTIFACT_ID), af.artifact); - if (af.version != null) { - setText(getChild(dependency, VERSION), af.version); - } - if (fDialog.getSelectedScope() != null && !"compile".equals(fDialog.getSelectedScope())) { - setText(getChild(dependency, SCOPE), fDialog.getSelectedScope()); - } - if (af.type != null && !"jar".equals(af.type) - && !"null".equals(af.type)) { // guard against MNGECLIPSE-622 //$NON-NLS-1$) - setText(getChild(dependency, TYPE), af.type); - } - if (af.classifier != null) { - setText(getChild(dependency, CLASSIFIER), af.classifier); + // dependency type + + if(config.getType() == SearchType.DEPENDENCY) { + try { + final int fOffset = offset; + performOnDOMDocument(new OperationTuple(document, new Operation() { + public void process(Document doc) { + Element currentNode = elementAtOffset(doc, fOffset); + if(currentNode == null) { + return; + } + String currentName = currentNode.getNodeName(); + Element dependency = null; + Element toFormat = null; + if("project".equals(currentName) || DEPENDENCY_MANAGEMENT.equals(currentName) || PROFILE.equals(currentName)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Element deps = findChild(currentNode, DEPENDENCIES); + if(deps == null) { + deps = insertAt(doc.createElement(DEPENDENCIES), fOffset); + toFormat = deps; } - format(toFormat); - generatedOffset = ((IndexedRegion)toFormat).getStartOffset(); - generatedLength = ((IndexedRegion)toFormat).getEndOffset() - generatedOffset; + dependency = doc.createElement(DEPENDENCY); + deps.appendChild(dependency); + } + if(DEPENDENCIES.equals(currentName)) { + dependency = insertAt(doc.createElement(DEPENDENCY), fOffset); + } + if(toFormat == null) { + toFormat = dependency; + } + setText(getChild(dependency, GROUP_ID), af.group); + setText(getChild(dependency, ARTIFACT_ID), af.artifact); + if(af.version != null) { + setText(getChild(dependency, VERSION), af.version); } - })); - } catch(IOException e) { - log.error("Failed inserting dependency element", e); //$NON-NLS-1$ - } catch(CoreException e) { - log.error("Failed inserting dependency element", e); //$NON-NLS-1$ - } + if(fDialog.getSelectedScope() != null && !"compile".equals(fDialog.getSelectedScope())) { + setText(getChild(dependency, SCOPE), fDialog.getSelectedScope()); + } + if(af.type != null && !"jar".equals(af.type) && !"null".equals(af.type)) { // guard against MNGECLIPSE-622 //$NON-NLS-1$) + setText(getChild(dependency, TYPE), af.type); + } + if(af.classifier != null) { + setText(getChild(dependency, CLASSIFIER), af.classifier); + } + format(toFormat); + generatedOffset = ((IndexedRegion) toFormat).getStartOffset(); + generatedLength = ((IndexedRegion) toFormat).getEndOffset() - generatedOffset; + } + })); + } catch(IOException e) { + log.error("Failed inserting dependency element", e); //$NON-NLS-1$ + } catch(CoreException e) { + log.error("Failed inserting dependency element", e); //$NON-NLS-1$ + } } } } } - + public Point getSelection(IDocument document) { return new Point(generatedOffset, generatedLength); } @@ -240,7 +271,7 @@ public class InsertArtifactProposal implements ICompletionProposal, ICompletionP } public String getDisplayString() { - return config.getType().getDisplayName(); + return config.getType().getDisplayName(); } public Image getImage() { @@ -259,23 +290,33 @@ public class InsertArtifactProposal implements ICompletionProposal, ICompletionP public Object getAdditionalProposalInfo(IProgressMonitor monitor) { return config.getType().getAdditionalInfo(); } - + /** * supported search types + * * @author mkleint - * */ public static enum SearchType { - - PARENT(IIndex.SEARCH_PARENTS, Messages.InsertArtifactProposal_searchDialog_title, Messages.InsertArtifactProposal_display_name, MvnImages.IMG_OPEN_POM, Messages.InsertArtifactProposal_additionals), - PLUGIN(IIndex.SEARCH_PLUGIN, Messages.InsertArtifactProposal_insert_plugin_title, Messages.InsertArtifactProposal_insert_plugin_display_name, MvnImages.IMG_OPEN_POM, Messages.InsertArtifactProposal_insert_plugin_description), - DEPENDENCY(IIndex.SEARCH_ARTIFACT, Messages.InsertArtifactProposal_insert_dep_title, Messages.InsertArtifactProposal_insert_dep_display_name, MvnImages.IMG_OPEN_POM, Messages.InsertArtifactProposal_insert_dep_desc); - + + PARENT(IIndex.SEARCH_PARENTS, Messages.InsertArtifactProposal_searchDialog_title, + Messages.InsertArtifactProposal_display_name, MvnImages.IMG_OPEN_POM, + Messages.InsertArtifactProposal_additionals), PLUGIN(IIndex.SEARCH_PLUGIN, + Messages.InsertArtifactProposal_insert_plugin_title, + Messages.InsertArtifactProposal_insert_plugin_display_name, MvnImages.IMG_OPEN_POM, + Messages.InsertArtifactProposal_insert_plugin_description), DEPENDENCY(IIndex.SEARCH_ARTIFACT, + Messages.InsertArtifactProposal_insert_dep_title, Messages.InsertArtifactProposal_insert_dep_display_name, + MvnImages.IMG_OPEN_POM, Messages.InsertArtifactProposal_insert_dep_desc); + private final String type; + private final String windowTitle; + private final String displayName; + private final Image image; + private final String additionalInfo; + private SearchType(String type, String windowTitle, String dn, Image img, String addInfo) { this.type = type; this.windowTitle = windowTitle; @@ -283,7 +324,7 @@ public class InsertArtifactProposal implements ICompletionProposal, ICompletionP this.image = img; this.additionalInfo = addInfo; } - + String getIIndexType() { return type; } @@ -303,24 +344,28 @@ public class InsertArtifactProposal implements ICompletionProposal, ICompletionP public String getAdditionalInfo() { return additionalInfo; } - + } - + public static class Configuration { private final SearchType type; + private String initiaSearchString; + private Node node; - + public Configuration(SearchType type) { this.type = type; } - + public void setInitiaSearchString(String initiaSearchString) { this.initiaSearchString = initiaSearchString; } + public String getInitiaSearchString() { return initiaSearchString; } + public SearchType getType() { return type; } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertExpressionProposal.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertExpressionProposal.java index 276548e3..973c6837 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertExpressionProposal.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertExpressionProposal.java @@ -11,10 +11,6 @@ package org.eclipse.m2e.editor.xml; -import org.apache.maven.model.InputLocation; -import org.apache.maven.model.InputSource; -import org.apache.maven.model.Model; -import org.apache.maven.project.MavenProject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,18 +25,28 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; +import org.apache.maven.model.InputLocation; +import org.apache.maven.model.InputSource; +import org.apache.maven.model.Model; +import org.apache.maven.project.MavenProject; + import org.eclipse.m2e.editor.xml.internal.Messages; + + /** * insertion proposal for ${ expressions + * * @author mkleint - * */ public class InsertExpressionProposal implements ICompletionProposal, ICompletionProposalExtension5 { private static final Logger log = LoggerFactory.getLogger(InsertExpressionProposal.class); private MavenProject project; + private String key; + private Region region; + private int len = 0; public InsertExpressionProposal(Region region, String key, MavenProject mvnproject) { @@ -51,22 +57,22 @@ public class InsertExpressionProposal implements ICompletionProposal, ICompletio } public Object getAdditionalProposalInfo(IProgressMonitor monitor) { - if (project == null) { + if(project == null) { return null; } String value = PomTemplateContext.simpleInterpolate(project, "${" + key + "}"); //$NON-NLS-1$ //$NON-NLS-2$ MavenProject mavprj = project; String loc = null; - if (mavprj != null) { + if(mavprj != null) { Model mdl = mavprj.getModel(); - if (mdl.getProperties() != null && mdl.getProperties().containsKey(key)) { - if (mdl.getLocation("properties") != null) { + if(mdl.getProperties() != null && mdl.getProperties().containsKey(key)) { + if(mdl.getLocation("properties") != null) { InputLocation location = mdl.getLocation("properties").getLocation(key); //$NON-NLS-1$ - if (location != null) { + if(location != null) { //MNGECLIPSE-2539 apparently you can have an InputLocation with null input source. // check! InputSource source = location.getSource(); - if (source != null) { + if(source != null) { loc = source.getModelId(); } } @@ -75,10 +81,10 @@ public class InsertExpressionProposal implements ICompletionProposal, ICompletio } StringBuffer buff = new StringBuffer(); buff.append("<html>"); //$NON-NLS-1$ - if (value != null) { + if(value != null) { buff.append(NLS.bind(Messages.InsertExpressionProposal_hint1, value)); } - if (loc != null) { + if(loc != null) { buff.append(NLS.bind(Messages.InsertExpressionProposal_hint2, loc)); } buff.append("</html>"); //$NON-NLS-1$ @@ -92,7 +98,7 @@ public class InsertExpressionProposal implements ICompletionProposal, ICompletio document.replace(offset, region.getLength(), replace); len = replace.length(); } catch(BadLocationException e) { - log.error("Cannot apply proposal", e); + log.error("Cannot apply proposal", e); } } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MvnImages.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MvnImages.java index f8f495f6..48913fbb 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MvnImages.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MvnImages.java @@ -19,6 +19,7 @@ import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; + /** * @author Eugene Kuleshov */ @@ -26,35 +27,35 @@ public class MvnImages { private static final Logger log = LoggerFactory.getLogger(MvnImages.class); // object images - - public static final Image IMG_JAR = createImage("jar_obj.gif"); //$NON-NLS-1$ - public static final Image IMG_JARS = createImage("jars_obj.gif"); //$NON-NLS-1$ + public static final Image IMG_JAR = createImage("jar_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_JARS = createImage("jars_obj.gif"); //$NON-NLS-1$ - public static final Image IMG_REPOSITORY = createImage("repository_obj.gif"); //$NON-NLS-1$ - - public static final Image IMG_PLUGIN = createImage("plugin_obj.gif"); //$NON-NLS-1$ + public static final Image IMG_REPOSITORY = createImage("repository_obj.gif"); //$NON-NLS-1$ - public static final Image IMG_PLUGINS = createImage("plugins_obj.gif"); //$NON-NLS-1$ + public static final Image IMG_PLUGIN = createImage("plugin_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_PLUGINS = createImage("plugins_obj.gif"); //$NON-NLS-1$ public static final Image IMG_EXECUTION = createImage("execution_obj.gif"); //$NON-NLS-1$ - - public static final Image IMG_GOAL = createImage("goal_obj.gif"); //$NON-NLS-1$ - public static final Image IMG_FILTER = createImage("filter_obj.gif"); //$NON-NLS-1$ + public static final Image IMG_GOAL = createImage("goal_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_FILTER = createImage("filter_obj.gif"); //$NON-NLS-1$ public static final Image IMG_RESOURCE = createImage("resource_obj.gif"); //$NON-NLS-1$ - - public static final Image IMG_RESOURCES = createImage("resources_obj.gif"); //$NON-NLS-1$ - public static final Image IMG_INCLUDE = createImage("include_obj.gif"); //$NON-NLS-1$ - - public static final Image IMG_EXCLUDE = createImage("exclude_obj.gif"); //$NON-NLS-1$ - + public static final Image IMG_RESOURCES = createImage("resources_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_INCLUDE = createImage("include_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_EXCLUDE = createImage("exclude_obj.gif"); //$NON-NLS-1$ + public static final Image IMG_PERSON = createImage("person_obj.gif"); //$NON-NLS-1$ - + public static final Image IMG_ROLE = createImage("role_obj.gif"); //$NON-NLS-1$ - + public static final Image IMG_PROPERTY = createImage("property_obj.gif"); //$NON-NLS-1$ public static final Image IMG_PROPERTIES = createImage("properties_obj.gif"); //$NON-NLS-1$ @@ -70,24 +71,24 @@ public class MvnImages { public static final Image IMG_LICENSE = createImage("license.png"); //$NON-NLS-1$ public static final Image IMG_BUILD = createImage("build_obj.gif"); //$NON-NLS-1$ - + public static final Image IMG_ELEMENT = createImage("element_obj.gif"); //$NON-NLS-1$ - + public static final Image IMG_USER_TEMPLATE = createImage("template_obj.gif"); //$NON-NLS-1$ public static final Image IMG_OPEN_POM = createImage("open_pom.gif"); //$NON-NLS-1$ - + public static final Image IMG_CLOSE = createImage("close.gif"); //$NON-NLS-1$ - + private static ImageDescriptor create(String key) { try { ImageDescriptor imageDescriptor = createDescriptor(key); ImageRegistry imageRegistry = getImageRegistry(); - if(imageRegistry!=null) { + if(imageRegistry != null) { imageRegistry.put(key, imageDescriptor); } return imageDescriptor; - } catch (Exception ex) { + } catch(Exception ex) { log.error(key, ex); return null; } @@ -96,16 +97,16 @@ public class MvnImages { private static Image createImage(String key) { create(key); ImageRegistry imageRegistry = getImageRegistry(); - return imageRegistry==null ? null : imageRegistry.get(key); + return imageRegistry == null ? null : imageRegistry.get(key); } private static ImageRegistry getImageRegistry() { MvnIndexPlugin plugin = MvnIndexPlugin.getDefault(); - return plugin==null ? null : plugin.getImageRegistry(); + return plugin == null ? null : plugin.getImageRegistry(); } private static ImageDescriptor createDescriptor(String image) { return AbstractUIPlugin.imageDescriptorFromPlugin(MvnIndexPlugin.PLUGIN_ID, "icons/" + image); //$NON-NLS-1$ } - + } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MvnIndexPlugin.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MvnIndexPlugin.java index eb66cbfe..707f188b 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MvnIndexPlugin.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MvnIndexPlugin.java @@ -13,11 +13,10 @@ package org.eclipse.m2e.editor.xml; import java.io.IOException; +import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.osgi.framework.BundleContext; - import org.eclipse.jface.text.templates.ContextTypeRegistry; import org.eclipse.jface.text.templates.persistence.TemplateStore; import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry; diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomContentAssistProcessor.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomContentAssistProcessor.java index b6dd1d53..dc97394c 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomContentAssistProcessor.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomContentAssistProcessor.java @@ -20,7 +20,6 @@ import java.util.Properties; import java.util.Set; import java.util.TreeSet; -import org.apache.maven.project.MavenProject; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.Text; @@ -54,11 +53,14 @@ import org.eclipse.wst.sse.core.utils.StringUtils; import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest; import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistProcessor; +import org.apache.maven.project.MavenProject; + import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.project.IMavenProjectFacade; import org.eclipse.m2e.editor.xml.internal.Messages; import org.eclipse.m2e.editor.xml.internal.XmlUtils; + /** * @author Lukas Krecan * @author Eugene Kuleshov @@ -67,44 +69,42 @@ import org.eclipse.m2e.editor.xml.internal.XmlUtils; public class PomContentAssistProcessor extends XMLContentAssistProcessor { private static final ProposalComparator PROPOSAL_COMPARATOR = new ProposalComparator(); - + private ISourceViewer sourceViewer; public PomContentAssistProcessor(ISourceViewer sourceViewer) { this.sourceViewer = sourceViewer; } - //broken - + //broken + protected void addTagNameProposals(ContentAssistRequest contentAssistRequest, int childPosition) { String currentNodeName = getCurrentNode(contentAssistRequest).getNodeName(); PomTemplateContext context = PomTemplateContext.fromNodeName(currentNodeName); - if(PomTemplateContext.CONFIGURATION == context) - { + if(PomTemplateContext.CONFIGURATION == context) { //this is sort of hack that makes sure the config proposals appear even // when you type <prefix // the downside is that additional typing hides the proposals popup // there has to be a better way though. the xml element completions seems to be coping with it fine.. contentAssistRequest.setReplacementBeginPosition(contentAssistRequest.getReplacementBeginPosition() - 1); contentAssistRequest.setReplacementLength(contentAssistRequest.getReplacementLength() + 1); - addProposals(contentAssistRequest, context, getCurrentNode(contentAssistRequest), contentAssistRequest.getMatchString()); + addProposals(contentAssistRequest, context, getCurrentNode(contentAssistRequest), + contentAssistRequest.getMatchString()); } - if(PomTemplateContext.UNKNOWN == context) - { + if(PomTemplateContext.UNKNOWN == context) { context = PomTemplateContext.fromNodeName(getCurrentNode(contentAssistRequest).getParentNode().getNodeName()); - if(PomTemplateContext.CONFIGURATION == context) - { - addProposals(contentAssistRequest, context, getCurrentNode(contentAssistRequest).getParentNode(), contentAssistRequest.getMatchString()); + if(PomTemplateContext.CONFIGURATION == context) { + addProposals(contentAssistRequest, context, getCurrentNode(contentAssistRequest).getParentNode(), + contentAssistRequest.getMatchString()); } } super.addTagNameProposals(contentAssistRequest, childPosition); } - - + @Override protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition) { String currentNodeName = getCurrentNode(contentAssistRequest).getNodeName(); - + addProposals(contentAssistRequest, PomTemplateContext.fromNodeName(currentNodeName)); super.addTagInsertionProposals(contentAssistRequest, childPosition); } @@ -126,15 +126,17 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { } String prefix = extractPrefix(sourceViewer, offset); - + addExpressionProposal(request, context, getCurrentNode(request), prefix); - + addGenerateProposals(request, context, getCurrentNode(request), prefix); - + addProposals(request, context, getCurrentNode(request), prefix); } + /** - * this is a proposal method for adding expressions when ${ is typed.. + * this is a proposal method for adding expressions when ${ is typed.. + * * @param request * @param context * @param currentNode @@ -143,93 +145,87 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { private void addExpressionProposal(ContentAssistRequest request, PomTemplateContext context, Node currentNode, String prefix) { int exprStart = prefix.lastIndexOf("${"); //$NON-NLS-1$ - if (exprStart != -1) { + if(exprStart != -1) { //the regular prefix is separated by whitespace and <> brackets only, we need to cut the last portion String realExpressionPrefix = prefix.substring(exprStart); - if (realExpressionPrefix.contains("}")) { //$NON-NLS-1$ + if(realExpressionPrefix.contains("}")) { //$NON-NLS-1$ //the expression is not opened.. return; } - if (expressionproposalContexts.contains(context)) { + if(expressionproposalContexts.contains(context)) { //add all effective pom expressions MavenProject prj = XmlUtils.extractMavenProject(sourceViewer); - Region region = new Region(request.getReplacementBeginPosition() - realExpressionPrefix.length(), realExpressionPrefix.length()); + Region region = new Region(request.getReplacementBeginPosition() - realExpressionPrefix.length(), + realExpressionPrefix.length()); Set<String> collect = new TreeSet<String>(); - if (prj != null) { - Properties props = prj.getProperties(); - if (props != null) { - for (Object key : props.keySet()) { - String keyString = key.toString(); - if (("${" + keyString).startsWith(realExpressionPrefix)) { //$NON-NLS-1$ - collect.add(keyString); - } - } - } - } - - //add a few hardwired values as well - if ("${basedir}".startsWith(realExpressionPrefix)) { //$NON-NLS-1$ - collect.add("basedir"); //$NON-NLS-1$ - } - if ("${project.version}".startsWith(realExpressionPrefix)) { //$NON-NLS-1$ - collect.add("project.version"); //$NON-NLS-1$ - } - if ("${project.groupId}".startsWith(realExpressionPrefix)) { //$NON-NLS-1$ - collect.add("project.groupId"); //$NON-NLS-1$ - } - if ("${project.artifactId}".startsWith(realExpressionPrefix)) { //$NON-NLS-1$ - collect.add("project.artifactId"); //$NON-NLS-1$ - } - if ("${project.build.directory}".startsWith(realExpressionPrefix)) { //$NON-NLS-1$ - collect.add("project.build.directory"); //$NON-NLS-1$ - } - for (String key : collect) { - ICompletionProposal proposal = new InsertExpressionProposal(region, key, prj); - if(request.shouldSeparate()) { - request.addMacro(proposal); - } else { - request.addProposal(proposal); + if(prj != null) { + Properties props = prj.getProperties(); + if(props != null) { + for(Object key : props.keySet()) { + String keyString = key.toString(); + if(("${" + keyString).startsWith(realExpressionPrefix)) { //$NON-NLS-1$ + collect.add(keyString); } } } } + + //add a few hardwired values as well + if("${basedir}".startsWith(realExpressionPrefix)) { //$NON-NLS-1$ + collect.add("basedir"); //$NON-NLS-1$ + } + if("${project.version}".startsWith(realExpressionPrefix)) { //$NON-NLS-1$ + collect.add("project.version"); //$NON-NLS-1$ + } + if("${project.groupId}".startsWith(realExpressionPrefix)) { //$NON-NLS-1$ + collect.add("project.groupId"); //$NON-NLS-1$ + } + if("${project.artifactId}".startsWith(realExpressionPrefix)) { //$NON-NLS-1$ + collect.add("project.artifactId"); //$NON-NLS-1$ + } + if("${project.build.directory}".startsWith(realExpressionPrefix)) { //$NON-NLS-1$ + collect.add("project.build.directory"); //$NON-NLS-1$ + } + for(String key : collect) { + ICompletionProposal proposal = new InsertExpressionProposal(region, key, prj); + if(request.shouldSeparate()) { + request.addMacro(proposal); + } else { + request.addProposal(proposal); + } + } + } + } } - + private static List<PomTemplateContext> expressionproposalContexts = Arrays.asList(new PomTemplateContext[] { - PomTemplateContext.ARTIFACT_ID, - PomTemplateContext.CLASSIFIER, + PomTemplateContext.ARTIFACT_ID, PomTemplateContext.CLASSIFIER, // PomTemplateContext.CONFIGURATION, - PomTemplateContext.GOAL, - PomTemplateContext.GROUP_ID, - PomTemplateContext.MODULE, - PomTemplateContext.PACKAGING, - PomTemplateContext.PHASE, - PomTemplateContext.PROPERTIES, //?? - PomTemplateContext.SCOPE, - PomTemplateContext.SYSTEM_PATH, - PomTemplateContext.TYPE, + PomTemplateContext.GOAL, PomTemplateContext.GROUP_ID, PomTemplateContext.MODULE, PomTemplateContext.PACKAGING, + PomTemplateContext.PHASE, PomTemplateContext.PROPERTIES, //?? + PomTemplateContext.SCOPE, PomTemplateContext.SYSTEM_PATH, PomTemplateContext.TYPE, // PomTemplateContext.VERSION, version is intentionally not included as we have specialized handling there.. - PomTemplateContext.UNKNOWN //this one is both important and troubling.. but having a context for everything is weird. - }); + PomTemplateContext.UNKNOWN //this one is both important and troubling.. but having a context for everything is weird. + }); private void addGenerateProposals(ContentAssistRequest request, PomTemplateContext context, Node node, String prefix) { - if (prefix.trim().length() != 0) { + if(prefix.trim().length() != 0) { //only provide these generate proposals when there is no prefix. return; } - if (context == PomTemplateContext.PARENT && node.getNodeName().equals("parent")) { //$NON-NLS-1$ - Element parent = (Element)node; + if(context == PomTemplateContext.PARENT && node.getNodeName().equals("parent")) { //$NON-NLS-1$ + Element parent = (Element) node; Element relPath = XmlUtils.findChild(parent, "relativePath"); //$NON-NLS-1$ - if (relPath == null) { + if(relPath == null) { //only show when no relpath already defined.. String relative = findRelativePath(sourceViewer, parent); - if (relative != null) { + if(relative != null) { Region region = new Region(request.getReplacementBeginPosition(), 0); - ICompletionProposal proposal = new CompletionProposal("<relativePath>" + relative + "</relativePath>", //$NON-NLS-1$ //$NON-NLS-2$ + ICompletionProposal proposal = new CompletionProposal("<relativePath>" + relative + "</relativePath>", //$NON-NLS-1$ //$NON-NLS-2$ region.getOffset(), region.getLength(), 0, // PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD), // NLS.bind(Messages.PomContentAssistProcessor_insert_relPath_title, relative), null, null); - if (request.shouldSeparate()) { + if(request.shouldSeparate()) { request.addMacro(proposal); } else { request.addProposal(proposal); @@ -237,25 +233,24 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { } } } - if (context == PomTemplateContext.RELATIVE_PATH) { + if(context == PomTemplateContext.RELATIVE_PATH) { //completion in the text portion of relative path Element parent = (Element) node.getParentNode(); - if (parent != null && "parent".equals(parent.getNodeName())) { //$NON-NLS-1$ + if(parent != null && "parent".equals(parent.getNodeName())) { //$NON-NLS-1$ String relative = findRelativePath(sourceViewer, parent); - String textContent = XmlUtils.getTextValue(node); - if (relative != null && !relative.equals(textContent)) { + String textContent = XmlUtils.getTextValue(node); + if(relative != null && !relative.equals(textContent)) { Region region = new Region(request.getReplacementBeginPosition() - prefix.length(), prefix.length()); - if (request.getNode() instanceof IndexedRegion && request.getNode() instanceof Text) { + if(request.getNode() instanceof IndexedRegion && request.getNode() instanceof Text) { //for <relativePath>|</relativePath> the current node is the element node and not the text node //only replace the text node content.. - IndexedRegion index = (IndexedRegion)request.getNode(); + IndexedRegion index = (IndexedRegion) request.getNode(); region = new Region(index.getStartOffset(), index.getEndOffset() - index.getStartOffset()); } - ICompletionProposal proposal = new CompletionProposal(relative, - region.getOffset(), region.getLength(), 0, - PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD), - NLS.bind(Messages.PomContentAssistProcessor_set_relPath_title, relative), null, null); - if (request.shouldSeparate()) { + ICompletionProposal proposal = new CompletionProposal(relative, region.getOffset(), region.getLength(), 0, + PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD), NLS.bind( + Messages.PomContentAssistProcessor_set_relPath_title, relative), null, null); + if(request.shouldSeparate()) { request.addMacro(proposal); } else { request.addProposal(proposal); @@ -263,29 +258,31 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { } } } - if (context == PomTemplateContext.DEPENDENCIES || context == PomTemplateContext.PROFILE + if(context == PomTemplateContext.DEPENDENCIES || context == PomTemplateContext.PROFILE || context == PomTemplateContext.DEPENDENCY_MANAGEMENT || context == PomTemplateContext.PROJECT) { //now add the proposal for dependency inclusion Region region = new Region(request.getReplacementBeginPosition(), 0); - InsertArtifactProposal.Configuration config = new InsertArtifactProposal.Configuration(InsertArtifactProposal.SearchType.DEPENDENCY); + InsertArtifactProposal.Configuration config = new InsertArtifactProposal.Configuration( + InsertArtifactProposal.SearchType.DEPENDENCY); config.setCurrentNode(node); - - ICompletionProposal proposal = new InsertArtifactProposal(sourceViewer, region, config); + + ICompletionProposal proposal = new InsertArtifactProposal(sourceViewer, region, config); if(request.shouldSeparate()) { request.addMacro(proposal); } else { request.addProposal(proposal); } } - - if (context == PomTemplateContext.PLUGINS || context == PomTemplateContext.BUILD + + if(context == PomTemplateContext.PLUGINS || context == PomTemplateContext.BUILD || context == PomTemplateContext.PLUGIN_MANAGEMENT || context == PomTemplateContext.PROJECT) { //now add the proposal for plugin inclusion Region region = new Region(request.getReplacementBeginPosition(), 0); - InsertArtifactProposal.Configuration config = new InsertArtifactProposal.Configuration(InsertArtifactProposal.SearchType.PLUGIN); + InsertArtifactProposal.Configuration config = new InsertArtifactProposal.Configuration( + InsertArtifactProposal.SearchType.PLUGIN); config.setCurrentNode(node); - - ICompletionProposal proposal = new InsertArtifactProposal(sourceViewer, region, config); + + ICompletionProposal proposal = new InsertArtifactProposal(sourceViewer, region, config); if(request.shouldSeparate()) { request.addMacro(proposal); } else { @@ -294,28 +291,29 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { } //comes after dependency and plugin.. the dep and plugin ones are guessed to be more likely hits.. - if (context == PomTemplateContext.PROJECT) { + if(context == PomTemplateContext.PROJECT) { //check if we have a parent defined.. Node project = node; - if (project != null && project instanceof Element) { - Element parent = XmlUtils.findChild((Element)project, "parent"); //$NON-NLS-1$ - if (parent == null) { + if(project != null && project instanceof Element) { + Element parent = XmlUtils.findChild((Element) project, "parent"); //$NON-NLS-1$ + if(parent == null) { //now add the proposal for parent inclusion Region region = new Region(request.getReplacementBeginPosition(), 0); - Element groupId = XmlUtils.findChild((Element)project, "groupId"); //$NON-NLS-1$ + Element groupId = XmlUtils.findChild((Element) project, "groupId"); //$NON-NLS-1$ String groupString = null; - if (groupId != null) { + if(groupId != null) { groupString = XmlUtils.getTextValue(groupId); } - InsertArtifactProposal.Configuration config = new InsertArtifactProposal.Configuration(InsertArtifactProposal.SearchType.PARENT); + InsertArtifactProposal.Configuration config = new InsertArtifactProposal.Configuration( + InsertArtifactProposal.SearchType.PARENT); config.setInitiaSearchString(groupString); - ICompletionProposal proposal = new InsertArtifactProposal(sourceViewer, region, config); + ICompletionProposal proposal = new InsertArtifactProposal(sourceViewer, region, config); if(request.shouldSeparate()) { request.addMacro(proposal); } else { request.addProposal(proposal); } - } + } } } if((context == PomTemplateContext.PROJECT && XmlUtils.findChild((Element) node, "licenses") == null) @@ -332,21 +330,21 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { String version = XmlUtils.getTextValue(XmlUtils.findChild(parent, "version")); //$NON-NLS-1$ return findRelativePath(viewer, groupId, artifactId, version); } - + public static String findRelativePath(ISourceViewer viewer, String groupId, String artifactId, String version) { - if (groupId != null && artifactId != null && version != null) { + if(groupId != null && artifactId != null && version != null) { IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getMavenProject(groupId, artifactId, version); - if (facade != null) { + if(facade != null) { //now add the proposal for relativePath IFile parentPomFile = facade.getPom(); IPath path = parentPomFile.getLocation(); //TODO we might not need the IPRoject instance at all.. IProject prj = XmlUtils.extractProject(viewer); - if (prj != null && path != null) { + if(prj != null && path != null) { IPath path2 = prj.getLocation(); IPath relative = path.makeRelativeTo(path2); - if (relative != path) { - return relative.toString(); + if(relative != path) { + return relative.toString(); } } } @@ -354,8 +352,6 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { return null; } - - private void addProposals(ContentAssistRequest request, PomTemplateContext context, Node currentNode, String prefix) { if(request != null) { MavenProject prj = XmlUtils.extractMavenProject(sourceViewer); @@ -373,7 +369,8 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { } } - private ICompletionProposal[] getTemplateProposals(MavenProject project, IProject eclipseprj, ITextViewer viewer, int offset, String contextTypeId, Node currentNode, String prefix) { + private ICompletionProposal[] getTemplateProposals(MavenProject project, IProject eclipseprj, ITextViewer viewer, + int offset, String contextTypeId, Node currentNode, String prefix) { ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection(); // adjust offset to end of normalized selection @@ -382,7 +379,7 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { } // String prefix = extractPrefix(viewer, offset); - Region region = new Region(offset - prefix.length(), prefix.length()); + Region region = new Region(offset - prefix.length(), prefix.length()); TemplateContext context = createContext(viewer, region, contextTypeId); if(context == null) { return new ICompletionProposal[0]; @@ -392,7 +389,7 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { context.setVariable("selection", selection.getText()); //$NON-NLS-1$ PomTemplateContext templateContext = PomTemplateContext.fromId(contextTypeId); - + // add the user defined templates - separate them from the rest of the templates // so that we know what they are and can assign proper icon to them. Image image = MvnImages.IMG_USER_TEMPLATE; @@ -402,29 +399,28 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { Template[] templates = store.getTemplates(contextTypeId); for(Template template : templates) { TemplateProposal proposal = createProposalForTemplate(prefix, region, context, image, template, true); - if (proposal != null) { + if(proposal != null) { matches.add(proposal); } } - } - if (templateContext == PomTemplateContext.CONFIGURATION) { + } + if(templateContext == PomTemplateContext.CONFIGURATION) { image = MvnImages.IMG_PARAMETER; } else { //other suggestions from the templatecontext are to be text inside the element, not actual //elements.. image = null; } - + Template[] templates = templateContext.getTemplates(project, eclipseprj, currentNode, prefix); for(Template template : templates) { TemplateProposal proposal = createProposalForTemplate(prefix, region, context, image, template, false); - if (proposal != null) { + if(proposal != null) { matches.add(proposal); } } - - - if (templateContext!=PomTemplateContext.VERSION) { + + if(templateContext != PomTemplateContext.VERSION) { // versions are already sorted with o.a.m.artifact.versioning.ComparableVersion Collections.sort(matches, PROPOSAL_COMPARATOR); } @@ -433,12 +429,12 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { } - private TemplateProposal createProposalForTemplate(String prefix, Region region, TemplateContext context, Image image, - final Template template, boolean isUserTemplate) { + private TemplateProposal createProposalForTemplate(String prefix, Region region, TemplateContext context, + Image image, final Template template, boolean isUserTemplate) { try { context.getContextType().validate(template.getPattern()); if(template.matches(prefix, context.getContextType().getId())) { - if (isUserTemplate) { + if(isUserTemplate) { //for templates defined by users, preserve the default behaviour.. return new TemplateProposal(template, context, region, image, getRelevance(template, prefix)) { public String getAdditionalProposalInfo() { @@ -450,7 +446,7 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { public String getAdditionalProposalInfo() { return getTemplate().getDescription(); } - + public String getDisplayString() { return template.getName(); } @@ -460,14 +456,14 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { } catch(TemplateException e) { // ignore } - + return null; } protected TemplateContext createContext(ITextViewer viewer, IRegion region, String contextTypeId) { - TemplateContextType contextType= getContextType(viewer, region, contextTypeId); - if (contextType != null) { - IDocument document= viewer.getDocument(); + TemplateContextType contextType = getContextType(viewer, region, contextTypeId); + if(contextType != null) { + IDocument document = viewer.getDocument(); return new DocumentTemplateContext(contextType, document, region.getOffset(), region.getLength()); } return null; @@ -475,11 +471,11 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { //TODO we should have different relevance for user defined templates and generated proposals.. protected int getRelevance(Template template, String prefix) { - if (template.getName().startsWith(prefix)) + if(template.getName().startsWith(prefix)) return 90; return 0; } - + protected TemplateContextType getContextType(ITextViewer viewer, IRegion region, String contextTypeId) { ContextTypeRegistry registry = MvnIndexPlugin.getDefault().getTemplateContextRegistry(); if(registry != null) { @@ -487,7 +483,7 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { } return null; } - + public static final String extractPrefix(ITextViewer viewer, int offset) { int i = offset; IDocument document = viewer.getDocument(); @@ -509,7 +505,6 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { } } - static final class ProposalComparator implements Comparator<TemplateProposal> { public int compare(TemplateProposal o1, TemplateProposal o2) { int res = o2.getRelevance() - o1.getRelevance(); @@ -519,5 +514,5 @@ public class PomContentAssistProcessor extends XMLContentAssistProcessor { return res; } } - + } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomContentOutlineConfiguration.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomContentOutlineConfiguration.java index 9f5c270c..0f71dd72 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomContentOutlineConfiguration.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomContentOutlineConfiguration.java @@ -39,7 +39,7 @@ public class PomContentOutlineConfiguration extends XMLContentOutlineConfigurati * POM label provider */ private final class PomLabelProvider implements ILabelProvider { - + private static final String TARGET_PATH = "targetPath"; //$NON-NLS-1$ private static final String DIRECTORY = "directory"; //$NON-NLS-1$ @@ -129,222 +129,222 @@ public class PomContentOutlineConfiguration extends XMLContentOutlineConfigurati private static final String NAMESPACE_POM = "http://maven.apache.org/POM/4.0.0"; //$NON-NLS-1$ private static final int MAX_LABEL_LENGTH = 120; - + private final ILabelProvider labelProvider; - + private PomLabelProvider(ILabelProvider labelProvider) { this.labelProvider = labelProvider; } - + public Image getImage(Object element) { Node node = (Node) element; String namespace = node.getNamespaceURI(); String nodeName = node.getNodeName(); - - if(node.getNodeType()==Node.COMMENT_NODE) { + + if(node.getNodeType() == Node.COMMENT_NODE) { return labelProvider.getImage(element); } - + if(NAMESPACE_POM.equals(namespace)) { if(PARENT.equals(nodeName)) { return MvnImages.IMG_JAR; - + } else if(DEPENDENCIES.equals(nodeName) // || EXCLUSIONS.equals(nodeName) // || EXTENSIONS.equals(nodeName) // || MODULES.equals(nodeName)) { return MvnImages.IMG_JARS; - + } else if(DEPENDENCY.equals(nodeName) // || EXCLUSION.equals(nodeName) // || EXTENSION.equals(nodeName) // || MODULE.equals(nodeName)) { // TODO show folder if module is in the workspace return MvnImages.IMG_JAR; - + } else if(REPOSITORY.equals(nodeName) || PLUGIN_REPOSITORY.equals(nodeName) || SNAPSHOT_REPOSITORY.equals(nodeName) || SITE.equals(nodeName)) { return MvnImages.IMG_REPOSITORY; - + } else if(PROFILES.equals(nodeName)) { return MvnImages.IMG_PROFILES; - + } else if(PROFILE.equals(nodeName)) { return MvnImages.IMG_PROFILE; - + } else if(DEVELOPER.equals(nodeName) || CONTRIBUTOR.equals(nodeName)) { return MvnImages.IMG_PERSON; - + } else if(PLUGINS.equals(nodeName)) { return MvnImages.IMG_PLUGINS; - + } else if(PLUGIN.equals(nodeName)) { return MvnImages.IMG_PLUGIN; - + } else if(EXECUTION.equals(nodeName)) { return MvnImages.IMG_EXECUTION; - + } else if(GOAL.equals(nodeName)) { return MvnImages.IMG_GOAL; - + } else if(RESOURCES.equals(nodeName) // || TEST_RESOURCES.equals(nodeName)) { return MvnImages.IMG_RESOURCES; - + } else if(RESOURCE.equals(nodeName) // || TEST_RESOURCE.equals(nodeName)) { return MvnImages.IMG_RESOURCE; - + } else if(FILTER.equals(nodeName)) { return MvnImages.IMG_FILTER; - + } else if(INCLUDE.equals(nodeName)) { return MvnImages.IMG_INCLUDE; - + } else if(EXCLUDE.equals(nodeName)) { return MvnImages.IMG_EXCLUDE; - + } else if(BUILD.equals(nodeName)) { return MvnImages.IMG_BUILD; - + } else if(REPORTING.equals(nodeName)) { return MvnImages.IMG_REPORT; - + } else if(PROPERTIES.equals(nodeName)) { return MvnImages.IMG_PROPERTIES; - + } else if(PROPERTIES.equals(node.getParentNode().getNodeName())) { return MvnImages.IMG_PROPERTY; - // } else if("mailingList".equals(nodeName)) { - // return MvnImages.IMG_MAIL; - + // } else if("mailingList".equals(nodeName)) { + // return MvnImages.IMG_MAIL; + } - + return MvnImages.IMG_ELEMENT; } - + return labelProvider.getImage(element); } - + public String getText(Object element) { String text = labelProvider.getText(element); - + Node node = (Node) element; String namespace = node.getNamespaceURI(); String nodeName = node.getNodeName(); - - if(node.getNodeType()==Node.COMMENT_NODE) { + + if(node.getNodeType() == Node.COMMENT_NODE) { return cleanText(node); } - + if(NAMESPACE_POM.equals(namespace)) { if(PARENT.equals(nodeName)) { return getLabel(text, node, GROUP_ID, ARTIFACT_ID, VERSION); - + } else if(DEPENDENCY.equals(nodeName)) { return getLabel(text, node, GROUP_ID, ARTIFACT_ID, VERSION, CLASSIFIER, TYPE, SCOPE); - + } else if(EXCLUSION.equals(nodeName)) { return getLabel(text, node, GROUP_ID, ARTIFACT_ID); - + } else if(EXTENSION.equals(nodeName)) { return getLabel(text, node, GROUP_ID, ARTIFACT_ID, VERSION); - + } else if(REPOSITORY.equals(nodeName) || PLUGIN_REPOSITORY.equals(nodeName) || SNAPSHOT_REPOSITORY.equals(nodeName) || SITE.equals(nodeName) || PROFILE.equals(nodeName) || EXECUTION.equals(nodeName)) { return getLabel(text, node, ID); - + } else if("mailingList".equals(nodeName)) { //$NON-NLS-1$ return getLabel(text, node, NAME); - + } else if(DEVELOPER.equals(nodeName)) { return getLabel(text, node, ID, NAME, EMAIL); - + } else if(CONTRIBUTOR.equals(nodeName)) { return getLabel(text, node, NAME, EMAIL); - + } else if(PLUGIN.equals(nodeName)) { return getLabel(text, node, GROUP_ID, ARTIFACT_ID, VERSION); - + } else if(RESOURCE.equals(nodeName) || TEST_RESOURCE.equals(nodeName)) { return getLabel(text, node, DIRECTORY, TARGET_PATH); - + } else if(REPORT_SET.equals(nodeName)) { return getLabel(text, node, ID); - + } else if(EXECUTION.equals(nodeName)) { return getLabel(text, node, ID); - + } - + NodeList childNodes = node.getChildNodes(); - if(childNodes.getLength()==1) { + if(childNodes.getLength() == 1) { Node item = childNodes.item(0); short nodeType = item.getNodeType(); - if(nodeType==Node.TEXT_NODE || nodeType==Node.COMMENT_NODE) { + if(nodeType == Node.TEXT_NODE || nodeType == Node.COMMENT_NODE) { String nodeText = item.getNodeValue(); - if(nodeText.length()>0) { + if(nodeText.length() > 0) { return text + " " + cleanText(item); //$NON-NLS-1$ } } } } - + return text; } - + public boolean isLabelProperty(Object element, String name) { return labelProvider.isLabelProperty(element, name); } - + public void addListener(ILabelProviderListener listener) { labelProvider.addListener(listener); } - + public void removeListener(ILabelProviderListener listener) { labelProvider.removeListener(listener); } - + public void dispose() { labelProvider.dispose(); } - + private String getLabel(String text, Node node, String... names) { StringBuilder sb = new StringBuilder(text).append(" "); //$NON-NLS-1$ String sep = ""; //$NON-NLS-1$ for(String name : names) { String value = getValue(node, name); - if(value!=null) { + if(value != null) { sb.append(sep).append(value); sep = " : "; //$NON-NLS-1$ } } - + return sb.toString(); } - + private String getValue(Node node, String name) { - String val = XmlUtils.getTextValue(XmlUtils.findChild((Element)node, name)); - if (val != null && val.trim().length() == 0) { + String val = XmlUtils.getTextValue(XmlUtils.findChild((Element) node, name)); + if(val != null && val.trim().length() == 0) { //keep the previous contract of the getValue method. val = null; } return val; } - + private String cleanText(Node node) { String value = node.getNodeValue(); - if (value==null) { + if(value == null) { return ""; //$NON-NLS-1$ } - + value = value.replaceAll("\\s", " ").replaceAll("(\\s){2,}", " ").trim(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - if (value.length() > MAX_LABEL_LENGTH) { + if(value.length() > MAX_LABEL_LENGTH) { value = value.substring(0, 120) + Dialog.ELLIPSIS; } - + return value; } } @@ -357,4 +357,3 @@ public class PomContentOutlineConfiguration extends XMLContentOutlineConfigurati return super.createMenuContributions(viewer); } } - diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java index 81231f73..94d1acc2 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java @@ -30,16 +30,9 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; -import org.apache.maven.model.Build; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.DependencyManagement; -import org.apache.maven.model.InputLocation; -import org.apache.maven.model.Model; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginManagement; -import org.apache.maven.project.MavenProject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -83,6 +76,15 @@ import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; import org.eclipse.wst.sse.ui.StructuredTextEditor; +import org.apache.maven.model.Build; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.InputLocation; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; +import org.apache.maven.project.MavenProject; + import org.eclipse.m2e.core.internal.IMavenConstants; import org.eclipse.m2e.core.ui.internal.actions.OpenPomAction; import org.eclipse.m2e.core.ui.internal.actions.OpenPomAction.MavenPathStorageEditorInput; @@ -98,11 +100,12 @@ import org.eclipse.m2e.editor.xml.internal.XmlUtils; public class PomHyperlinkDetector implements IHyperlinkDetector { private static final Logger log = LoggerFactory.getLogger(PomHyperlinkDetector.class); - public IHyperlink[] detectHyperlinks(final ITextViewer textViewer, final IRegion region, boolean canShowMultipleHyperlinks) { + public IHyperlink[] detectHyperlinks(final ITextViewer textViewer, final IRegion region, + boolean canShowMultipleHyperlinks) { if(region == null || textViewer == null) { return null; } - + IDocument document = textViewer.getDocument(); if(document == null) { return null; @@ -122,107 +125,107 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } final List<IHyperlink> hyperlinks = new ArrayList<IHyperlink>(); final int offset = region.getOffset(); - + XmlUtils.performOnCurrentElement(document, offset, new NodeOperation<Node>() { public void process(Node node, IStructuredDocument structured) { - if (textViewer instanceof ISourceViewer) { - IHyperlink[] links = openExternalMarkerDefinition((ISourceViewer)textViewer, offset); - if (links.length > 0) { + if(textViewer instanceof ISourceViewer) { + IHyperlink[] links = openExternalMarkerDefinition((ISourceViewer) textViewer, offset); + if(links.length > 0) { hyperlinks.addAll(Arrays.asList(links)); } } //check if we have a property expression at cursor IHyperlink link = openPropertyDefinition(node, textViewer, offset); - if (link != null) { + if(link != null) { hyperlinks.add(link); } //now check if the dependency/plugin has a version element or not, if not, try searching for it in DM/PM of effective pom link = openDPManagement(node, textViewer, offset); - if (link != null) { + if(link != null) { hyperlinks.add(link); } //check if <module> text is selected. link = openModule(node, textViewer, offset); - if (link != null) { + if(link != null) { hyperlinks.add(link); } link = openPOMbyID(node, textViewer, offset); - if (link != null) { + if(link != null) { hyperlinks.add(link); } } }); - - if (hyperlinks.size() > 0) { + + if(hyperlinks.size() > 0) { return hyperlinks.toArray(new IHyperlink[0]); } return null; } static ManagedArtifactRegion findManagedArtifactRegion(Node current, ITextViewer textViewer, int offset) { - while (current != null && !( current instanceof Element)) { - current = current.getParentNode(); + while(current != null && !(current instanceof Element)) { + current = current.getParentNode(); } - if (current != null) { + if(current != null) { Node artNode = null; Node groupNode = null; - if (ARTIFACT_ID.equals(current.getNodeName())) { //$NON-NLS-1$ + if(ARTIFACT_ID.equals(current.getNodeName())) { //$NON-NLS-1$ artNode = current; } - if (GROUP_ID.equals(current.getNodeName())) { //$NON-NLS-1$ + if(GROUP_ID.equals(current.getNodeName())) { //$NON-NLS-1$ groupNode = current; } //only on artifactid and groupid elements.. - if (artNode == null && groupNode == null) { + if(artNode == null && groupNode == null) { return null; } Node root = current.getParentNode(); boolean isDependency = false; boolean isPlugin = false; - if (root != null) { + if(root != null) { String name = root.getNodeName(); - if (DEPENDENCY.equals(name)) { //$NON-NLS-1$ + if(DEPENDENCY.equals(name)) { //$NON-NLS-1$ isDependency = true; } - if (PLUGIN.equals(name)) { //$NON-NLS-1$ + if(PLUGIN.equals(name)) { //$NON-NLS-1$ isPlugin = true; } } else { return null; } - if (!isDependency && !isPlugin) { + if(!isDependency && !isPlugin) { //some kind of other identifier return null; } //now see if version is missing NodeList childs = root.getChildNodes(); - for (int i = 0; i < childs.getLength(); i++) { + for(int i = 0; i < childs.getLength(); i++ ) { Node child = childs.item(i); - if (child instanceof Element) { + if(child instanceof Element) { Element el = (Element) child; - if (VERSION.equals(el.getNodeName())) { //$NON-NLS-1$ + if(VERSION.equals(el.getNodeName())) { //$NON-NLS-1$ return null; } - if (artNode == null && ARTIFACT_ID.equals(el.getNodeName())) { //$NON-NLS-1$ + if(artNode == null && ARTIFACT_ID.equals(el.getNodeName())) { //$NON-NLS-1$ artNode = el; } - if (groupNode == null && GROUP_ID.equals(el.getNodeName())) { //$NON-NLS-1$ + if(groupNode == null && GROUP_ID.equals(el.getNodeName())) { //$NON-NLS-1$ groupNode = el; } } } - if (groupNode != null && artNode != null) { + if(groupNode != null && artNode != null) { assert groupNode instanceof IndexedRegion; assert artNode instanceof IndexedRegion; - - IndexedRegion groupReg = (IndexedRegion)groupNode; - IndexedRegion artReg = (IndexedRegion)artNode; + + IndexedRegion groupReg = (IndexedRegion) groupNode; + IndexedRegion artReg = (IndexedRegion) artNode; int startOffset = Math.min(groupReg.getStartOffset(), artReg.getStartOffset()); int length = Math.max(groupReg.getEndOffset(), artReg.getEndOffset()) - startOffset; String groupId = XmlUtils.getTextValue(groupNode); String artifactId = XmlUtils.getTextValue(artNode); final MavenProject prj = XmlUtils.extractMavenProject(textViewer); - if (prj != null) { + if(prj != null) { //now we can create the region I guess, return new ManagedArtifactRegion(startOffset, length, groupId, artifactId, isDependency, isPlugin, prj); } @@ -230,7 +233,7 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } return null; } - + public static IHyperlink createHyperlink(final ManagedArtifactRegion region) { return new IHyperlink() { public IRegion getHyperlinkRegion() { @@ -246,101 +249,100 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } public void open() { - //see if we can find the plugin in plugin management of resolved project. + //see if we can find the plugin in plugin management of resolved project. MavenProject mavprj = region.project; - if (mavprj != null) { + if(mavprj != null) { InputLocation openLocation = findLocationForManagedArtifact(region, mavprj); - if (openLocation != null) { + if(openLocation != null) { File file = XmlUtils.fileForInputLocation(openLocation, mavprj); - if (file != null) { + if(file != null) { IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.toURI()); - openXmlEditor(fileStore, openLocation.getLineNumber(), openLocation.getColumnNumber(), openLocation.getSource().getModelId()); + openXmlEditor(fileStore, openLocation.getLineNumber(), openLocation.getColumnNumber(), openLocation + .getSource().getModelId()); } } } } }; - + } - - private IHyperlink openDPManagement(Node current, ITextViewer textViewer, int offset) { - final ManagedArtifactRegion region = findManagedArtifactRegion(current, textViewer, offset); - if (region != null) { - return createHyperlink(region); - } + + private IHyperlink openDPManagement(Node current, ITextViewer textViewer, int offset) { + final ManagedArtifactRegion region = findManagedArtifactRegion(current, textViewer, offset); + if(region != null) { + return createHyperlink(region); + } return null; } - - - + static InputLocation findLocationForManagedArtifact(final ManagedArtifactRegion region, MavenProject mavprj) { - Model mdl = mavprj.getModel(); - InputLocation openLocation = null; - if (region.isDependency) { - DependencyManagement dm = mdl.getDependencyManagement(); - if (dm != null) { - List<Dependency> list = dm.getDependencies(); - String id = region.groupId + ":" + region.artifactId + ":"; //$NON-NLS-1$ //$NON-NLS-2$ - if (list != null) { - for (Dependency dep : list) { - if (dep.getManagementKey().startsWith(id)) { - InputLocation location = dep.getLocation(ARTIFACT_ID); //$NON-NLS-1$ - //when would this be null? - if (location != null) { - openLocation = location; - break; - } - } - } - } - } - } - if (region.isPlugin) { - Build build = mdl.getBuild(); - if (build != null) { - PluginManagement pm = build.getPluginManagement(); - if (pm != null) { - List<Plugin> list = pm.getPlugins(); - String id = Plugin.constructKey(region.groupId, region.artifactId); - if (list != null) { - for (Plugin plg : list) { - if (id.equals(plg.getKey())) { - InputLocation location = plg.getLocation(ARTIFACT_ID); //$NON-NLS-1$ - //when would this be null? - if (location != null) { - openLocation = location; - break; - } - } - } - } - } - } - } - return openLocation; - } + Model mdl = mavprj.getModel(); + InputLocation openLocation = null; + if(region.isDependency) { + DependencyManagement dm = mdl.getDependencyManagement(); + if(dm != null) { + List<Dependency> list = dm.getDependencies(); + String id = region.groupId + ":" + region.artifactId + ":"; //$NON-NLS-1$ //$NON-NLS-2$ + if(list != null) { + for(Dependency dep : list) { + if(dep.getManagementKey().startsWith(id)) { + InputLocation location = dep.getLocation(ARTIFACT_ID); //$NON-NLS-1$ + //when would this be null? + if(location != null) { + openLocation = location; + break; + } + } + } + } + } + } + if(region.isPlugin) { + Build build = mdl.getBuild(); + if(build != null) { + PluginManagement pm = build.getPluginManagement(); + if(pm != null) { + List<Plugin> list = pm.getPlugins(); + String id = Plugin.constructKey(region.groupId, region.artifactId); + if(list != null) { + for(Plugin plg : list) { + if(id.equals(plg.getKey())) { + InputLocation location = plg.getLocation(ARTIFACT_ID); //$NON-NLS-1$ + //when would this be null? + if(location != null) { + openLocation = location; + break; + } + } + } + } + } + } + } + return openLocation; + } static ExpressionRegion findExpressionRegion(Node current, ITextViewer viewer, int offset) { - if (current != null && current instanceof Text) { - Text node = (Text)current; + if(current != null && current instanceof Text) { + Text node = (Text) current; String value = node.getNodeValue(); - if (value != null) { + if(value != null) { assert node instanceof IndexedRegion; - IndexedRegion reg = (IndexedRegion)node; + IndexedRegion reg = (IndexedRegion) node; int index = offset - reg.getStartOffset(); - String before = value.substring(0, Math.min (index + 1, value.length())); - String after = value.substring(Math.min (index + 1, value.length())); + String before = value.substring(0, Math.min(index + 1, value.length())); + String after = value.substring(Math.min(index + 1, value.length())); int start = before.lastIndexOf("${"); //$NON-NLS-1$ - if (before.lastIndexOf("}") > start) {//$NON-NLS-1$ + if(before.lastIndexOf("}") > start) {//$NON-NLS-1$ //we might be in between two expressions.. start = -1; } int end = after.indexOf("}"); //$NON-NLS-1$ - if (after.indexOf("${") != -1 && after.indexOf("${") < end) {//$NON-NLS-1$ + if(after.indexOf("${") != -1 && after.indexOf("${") < end) {//$NON-NLS-1$ //we might be in between two expressions.. end = -1; } - if (start > -1 && end > -1) { + if(start > -1 && end > -1) { final int startOffset = reg.getStartOffset() + start; final String expr = before.substring(start) + after.substring(0, end + 1); final int length = expr.length(); @@ -350,7 +352,7 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { // return null; //ignore these, not in properties section. // } MavenProject prj = XmlUtils.extractMavenProject(viewer); - if (prj != null) { + if(prj != null) { return new ExpressionRegion(startOffset, length, prop, prj); } } @@ -358,7 +360,7 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } return null; } - + public static IHyperlink createHyperlink(final ExpressionRegion region) { return new IHyperlink() { public IRegion getHyperlinkRegion() { @@ -380,7 +382,7 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { //TODO get rid of InputLocation here and use the dom tree to find the property Model mdl = mavprj.getModel(); InputLocation location = null; - if (mdl.getProperties().containsKey(region.property)) { + if(mdl.getProperties().containsKey(region.property)) { location = mdl.getLocation(PROPERTIES).getLocation(region.property); } else if(region.property != null && region.property.startsWith("project.")) {//$NON-NLS-1$ if("project.version".equals(region.property)) { @@ -408,36 +410,36 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } return region.project != null && region.project.getModel().getProperties().containsKey(region.property); } - + //only create the hyperlink when the origin location for jumping is present. //in some cases (managed version comes from imported dependencies) we don't have the location and have nowhere to jump) public static boolean canCreateHyperLink(final ManagedArtifactRegion region) { - return region.project != null && PomHyperlinkDetector.findLocationForManagedArtifact(region, region.project) != null; - } - - + return region.project != null + && PomHyperlinkDetector.findLocationForManagedArtifact(region, region.project) != null; + } + static IHyperlink[] openExternalMarkerDefinition(ISourceViewer sourceViewer, int offset) { List<IHyperlink> toRet = new ArrayList<IHyperlink>(); MarkerRegion[] regions = findMarkerRegions(sourceViewer, offset); - for (MarkerRegion reg : regions) { - if (reg.isDefinedInParent()) { + for(MarkerRegion reg : regions) { + if(reg.isDefinedInParent()) { toRet.add(createHyperlink(reg)); } } return toRet.toArray(new IHyperlink[0]); } - + static MarkerRegion[] findMarkerRegions(ISourceViewer sourceViewer, int offset) { List<MarkerRegion> toRet = new ArrayList<MarkerRegion>(); IAnnotationModel model = sourceViewer.getAnnotationModel(); - if (model != null) { //eg. in tests + if(model != null) { //eg. in tests @SuppressWarnings("unchecked") Iterator<Annotation> it = model.getAnnotationIterator(); - while (it.hasNext()) { + while(it.hasNext()) { Annotation ann = it.next(); - if (ann instanceof MarkerAnnotation) { + if(ann instanceof MarkerAnnotation) { Position pos = sourceViewer.getAnnotationModel().getPosition(ann); - if (pos.includes(offset)) { + if(pos.includes(offset)) { toRet.add(new MarkerRegion(pos.getOffset(), pos.getLength(), (MarkerAnnotation) ann)); } } @@ -445,7 +447,7 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } return toRet.toArray(new MarkerRegion[0]); } - + public static IHyperlink createHyperlink(final MarkerRegion mark) { return new IHyperlink() { @@ -462,9 +464,9 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } public void open() { - IMarker marker = mark.getAnnotation().getMarker(); + IMarker marker = mark.getAnnotation().getMarker(); String loc = marker.getAttribute(IMavenConstants.MARKER_CAUSE_RESOURCE_PATH, null); - if (loc != null) { + if(loc != null) { IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(loc)); int row = marker.getAttribute(IMavenConstants.MARKER_CAUSE_LINE_NUMBER, 0); int column = marker.getAttribute(IMavenConstants.MARKER_CAUSE_COLUMN_START, 0); @@ -476,8 +478,8 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } } }; - } - + } + private IHyperlink openPropertyDefinition(Node current, ITextViewer viewer, int offset) { final ExpressionRegion region = findExpressionRegion(current, viewer, offset); if(region != null && canCreateHyperLink(region)) { @@ -487,20 +489,20 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } private IHyperlink openModule(Node current, ITextViewer textViewer, int offset) { - while (current != null && !( current instanceof Element)) { - current = current.getParentNode(); + while(current != null && !(current instanceof Element)) { + current = current.getParentNode(); } - if (current == null) { + if(current == null) { return null; } String pathUp = XmlUtils.pathUp(current, 2); - if (! "modules/module".equals(pathUp)) { //$NON-NLS-1$ + if(!"modules/module".equals(pathUp)) { //$NON-NLS-1$ //just in case we are in some random plugin configuration snippet.. return null; } - + ITextFileBuffer buf = FileBuffers.getTextFileBufferManager().getTextFileBuffer(textViewer.getDocument()); - if (buf == null) { + if(buf == null) { //for repository based poms.. return null; } @@ -521,7 +523,7 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { modulePom = modulePom.getChild("pom.xml");//$NON-NLS-1$ } final IFileStore fileStore = modulePom; - if (!fileStore.fetchInfo().exists()) { + if(!fileStore.fetchInfo().exists()) { return null; } assert current instanceof IndexedRegion; @@ -545,98 +547,94 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } }; } - - private IHyperlink openPOMbyID(Node current, final ITextViewer viewer, int offset) { - while (current != null && !( current instanceof Element)) { - current = current.getParentNode(); + while(current != null && !(current instanceof Element)) { + current = current.getParentNode(); } - if (current == null) { + if(current == null) { return null; } current = current.getParentNode(); - if (current == null || !(current instanceof Element)) { + if(current == null || !(current instanceof Element)) { return null; } Element parent = (Element) current; String parentName = parent.getNodeName(); - if (DEPENDENCY.equals(parentName) || PARENT.equals(parentName) - || PLUGIN.equals(parentName) || "reportPlugin".equals(parentName) - || EXTENSION.equals(parentName)) { - final Node groupId = XmlUtils.findChild(parent, GROUP_ID); - final Node artifactId = XmlUtils.findChild(parent, ARTIFACT_ID); - final Node version = XmlUtils.findChild(parent, VERSION); + if(DEPENDENCY.equals(parentName) || PARENT.equals(parentName) || PLUGIN.equals(parentName) + || "reportPlugin".equals(parentName) || EXTENSION.equals(parentName)) { + final Node groupId = XmlUtils.findChild(parent, GROUP_ID); + final Node artifactId = XmlUtils.findChild(parent, ARTIFACT_ID); + final Node version = XmlUtils.findChild(parent, VERSION); final MavenProject prj = XmlUtils.extractMavenProject(viewer); - - - IHyperlink pomHyperlink = new IHyperlink() { - public IRegion getHyperlinkRegion() { - //the goal here is to have the groupid/artifactid/version combo underscored by the link. - //that will prevent underscoring big portions (like plugin config) underscored and - // will also handle cases like dependencies within plugins. - int max = groupId != null ? ((IndexedRegion)groupId).getEndOffset() : Integer.MIN_VALUE; - int min = groupId != null ? ((IndexedRegion)groupId).getStartOffset() : Integer.MAX_VALUE; - max = Math.max(max, artifactId != null ? ((IndexedRegion)artifactId).getEndOffset() : Integer.MIN_VALUE); - min = Math.min(min, artifactId != null ? ((IndexedRegion)artifactId).getStartOffset() : Integer.MAX_VALUE); - max = Math.max(max, version != null ? ((IndexedRegion)version).getEndOffset() : Integer.MIN_VALUE); - min = Math.min(min, version != null ? ((IndexedRegion)version).getStartOffset() : Integer.MAX_VALUE); - return new Region(min, max - min); - } - public String getHyperlinkText() { - return NLS.bind(Messages.PomHyperlinkDetector_hyperlink_pattern, XmlUtils.getTextValue(groupId), XmlUtils.getTextValue(artifactId)); - } + IHyperlink pomHyperlink = new IHyperlink() { + public IRegion getHyperlinkRegion() { + //the goal here is to have the groupid/artifactid/version combo underscored by the link. + //that will prevent underscoring big portions (like plugin config) underscored and + // will also handle cases like dependencies within plugins. + int max = groupId != null ? ((IndexedRegion) groupId).getEndOffset() : Integer.MIN_VALUE; + int min = groupId != null ? ((IndexedRegion) groupId).getStartOffset() : Integer.MAX_VALUE; + max = Math.max(max, artifactId != null ? ((IndexedRegion) artifactId).getEndOffset() : Integer.MIN_VALUE); + min = Math.min(min, artifactId != null ? ((IndexedRegion) artifactId).getStartOffset() : Integer.MAX_VALUE); + max = Math.max(max, version != null ? ((IndexedRegion) version).getEndOffset() : Integer.MIN_VALUE); + min = Math.min(min, version != null ? ((IndexedRegion) version).getStartOffset() : Integer.MAX_VALUE); + return new Region(min, max - min); + } - public String getTypeLabel() { - return "pom"; //$NON-NLS-1$ - } + public String getHyperlinkText() { + return NLS.bind(Messages.PomHyperlinkDetector_hyperlink_pattern, XmlUtils.getTextValue(groupId), + XmlUtils.getTextValue(artifactId)); + } - public void open() { - new Job(Messages.PomHyperlinkDetector_job_name) { - protected IStatus run(IProgressMonitor monitor) { - // TODO resolve groupId if groupId==null - String gridString = groupId == null ? "org.apache.maven.plugins" : XmlUtils.getTextValue(groupId); //$NON-NLS-1$ - String artidString = artifactId == null ? null : XmlUtils.getTextValue(artifactId); - String versionString = version == null ? null : XmlUtils.getTextValue(version); - if (prj != null && gridString != null && artidString != null && (versionString == null || versionString.contains("${"))) { //$NON-NLS-1$ - try { - //TODO how do we decide here if the hyperlink is a dependency or a plugin - // hyperlink?? - versionString = PomTemplateContext.extractVersion(prj, null, versionString, gridString, artidString, PomTemplateContext.EXTRACT_STRATEGY_DEPENDENCY); - - } catch(CoreException e) { - versionString = null; + public String getTypeLabel() { + return "pom"; //$NON-NLS-1$ + } + + public void open() { + new Job(Messages.PomHyperlinkDetector_job_name) { + protected IStatus run(IProgressMonitor monitor) { + // TODO resolve groupId if groupId==null + String gridString = groupId == null ? "org.apache.maven.plugins" : XmlUtils.getTextValue(groupId); //$NON-NLS-1$ + String artidString = artifactId == null ? null : XmlUtils.getTextValue(artifactId); + String versionString = version == null ? null : XmlUtils.getTextValue(version); + if(prj != null && gridString != null && artidString != null + && (versionString == null || versionString.contains("${"))) { //$NON-NLS-1$ + try { + //TODO how do we decide here if the hyperlink is a dependency or a plugin + // hyperlink?? + versionString = PomTemplateContext.extractVersion(prj, null, versionString, gridString, artidString, + PomTemplateContext.EXTRACT_STRATEGY_DEPENDENCY); + + } catch(CoreException e) { + versionString = null; + } } - } - if (versionString == null) { - return Status.OK_STATUS; - } - OpenPomAction.openEditor(gridString, - artidString, - versionString, monitor); + if(versionString == null) { + return Status.OK_STATUS; + } + OpenPomAction.openEditor(gridString, artidString, versionString, monitor); // TODO: it's preferable to open the xml page, but this code will blink and open overview first and later switch. looks bad // Display.getDefault().syncExec(new Runnable() { // public void run() { // selectEditorPage(page); // } // }); - return Status.OK_STATUS; - } - }.schedule(); - } + return Status.OK_STATUS; + } + }.schedule(); + } - }; - return pomHyperlink; + }; + return pomHyperlink; } return null; } - private void openXmlEditor(final IFileStore fileStore) { openXmlEditor(fileStore, -1, -1, fileStore.getName()); } - + private static void openXmlEditor(final IFileStore fileStore, int line, int column, String name) { assert fileStore != null; IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); @@ -649,7 +647,7 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { reveal(selectEditorPage(part), line, column); } else { //we need special EditorInput for stuff from repository - name = name + ".pom"; //$NON-NLS-1$ + name = name + ".pom"; //$NON-NLS-1$ File file = new File(fileStore.toURI()); try { IEditorInput input = new MavenPathStorageEditorInput(name, name, file.getAbsolutePath(), @@ -658,7 +656,7 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { reveal(selectEditorPage(part), line, column); } catch(IOException e) { log.error("failed opening editor", e); - } + } } } catch(PartInitException e) { MessageDialog.openInformation( @@ -670,27 +668,27 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } } } - + private static StructuredTextEditor selectEditorPage(IEditorPart part) { - if (part == null) { + if(part == null) { return null; } - if (part instanceof FormEditor) { + if(part instanceof FormEditor) { FormEditor ed = (FormEditor) part; ed.setActivePage(null); //null means source, always or just in the case of MavenPomEditor? - if (ed.getActiveEditor() instanceof StructuredTextEditor) { + if(ed.getActiveEditor() instanceof StructuredTextEditor) { return (StructuredTextEditor) ed.getActiveEditor(); - } + } } return null; } - + private static void reveal(StructuredTextEditor structured, int line, int column) { - if (structured == null || line < 0 || column < 0) { + if(structured == null || line < 0 || column < 0) { return; } IDocument doc = structured.getTextViewer().getDocument(); - if (doc instanceof IStructuredDocument) { + if(doc instanceof IStructuredDocument) { IStructuredDocument document = (IStructuredDocument) doc; try { int offset = document.getLineOffset(line - 1); @@ -700,9 +698,10 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } } } - + /** * duplicate of OpenPomAction method + * * @param is * @return * @throws IOException @@ -728,14 +727,15 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { } } } - - public static class ExpressionRegion implements IRegion { final String property; + private int length; + private int offset; + final MavenProject project; public ExpressionRegion(int startOffset, int length, String prop, MavenProject project) { @@ -754,18 +754,25 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { return offset; } } - + public static class ManagedArtifactRegion implements IRegion { private int length; + private int offset; + final MavenProject project; + final String groupId; + final String artifactId; + final boolean isPlugin; + final boolean isDependency; - public ManagedArtifactRegion(int startOffset, int length, String groupId, String artifactId, boolean isDependency, boolean isPlugin, MavenProject project) { + public ManagedArtifactRegion(int startOffset, int length, String groupId, String artifactId, boolean isDependency, + boolean isPlugin, MavenProject project) { this.offset = startOffset; this.length = length; this.project = project; @@ -783,44 +790,43 @@ public class PomHyperlinkDetector implements IHyperlinkDetector { public int getOffset() { return offset; } - } + } public static class MarkerRegion implements IRegion { - + private final MarkerAnnotation ann; + final int offset; + final int length; - + public MarkerRegion(int offset, int length, MarkerAnnotation applicable) { this.offset = offset; this.length = length; this.ann = applicable; } - + public int getLength() { return length; } - + public int getOffset() { return offset; } - + public MarkerAnnotation getAnnotation() { return ann; } - + public boolean isDefinedInParent() { IMarker mark = ann.getMarker(); String isElsewhere = mark.getAttribute(IMavenConstants.MARKER_CAUSE_RESOURCE_PATH, null); - if (isElsewhere != null) { + if(isElsewhere != null) { return true; } return false; } - - } + } - - } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomModelHandler.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomModelHandler.java index cd68f514..bdcea27b 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomModelHandler.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomModelHandler.java @@ -35,7 +35,6 @@ import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter; import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapterImpl; - @SuppressWarnings("restriction") public class PomModelHandler extends ModelHandlerForXML { @@ -76,8 +75,8 @@ public class PomModelHandler extends ModelHandlerForXML { protected INodeAdapter createAdapter(INodeNotifier target) { if(modelQueryAdapterImpl == null) { ModelQueryAdapter mqa = (ModelQueryAdapter) super.createAdapter(target); - modelQueryAdapterImpl = new ModelQueryAdapterImpl(mqa.getCMDocumentCache(), new PomModelQueryImpl(mqa - .getCMDocumentCache(), mqa.getIdResolver()), mqa.getIdResolver()); + modelQueryAdapterImpl = new ModelQueryAdapterImpl(mqa.getCMDocumentCache(), new PomModelQueryImpl( + mqa.getCMDocumentCache(), mqa.getIdResolver()), mqa.getIdResolver()); } return modelQueryAdapterImpl; } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java index 495edcba..09a5e021 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java @@ -18,6 +18,7 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.Text; @@ -64,17 +65,21 @@ import org.eclipse.m2e.editor.xml.internal.XmlUtils; import org.eclipse.m2e.editor.xml.internal.lifecycle.LifecycleMappingProposal; import org.eclipse.m2e.editor.xml.internal.lifecycle.WorkspaceLifecycleMappingProposal; + public class PomQuickAssistProcessor implements IQuickAssistProcessor { private static final Logger log = LoggerFactory.getLogger(PomQuickAssistProcessor.class); private static final String GROUP_ID_NODE = "groupId"; //$NON-NLS-1$ + private static final String ARTIFACT_ID_NODE = "artifactId"; //$NON-NLS-1$ + private static final String VERSION_NODE = "version"; //$NON-NLS-1$ public static final String PROJECT_NODE = "project"; //$NON-NLS-1$ - public static final String XSI_VALUE = " xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"+ //$NON-NLS-1$ - "xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\""; //$NON-NLS-1$ - + + public static final String XSI_VALUE = " xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + //$NON-NLS-1$ + "xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\""; //$NON-NLS-1$ + public boolean canAssist(IQuickAssistInvocationContext arg0) { return true; } @@ -89,7 +94,7 @@ public class PomQuickAssistProcessor implements IQuickAssistProcessor { } return false; } - + public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) { List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); Iterator<Annotation> annotationIterator = context.getSourceViewer().getAnnotationModel().getAnnotationIterator(); @@ -118,7 +123,7 @@ public class PomQuickAssistProcessor implements IQuickAssistProcessor { proposals.add(new IgnoreWarningProposal(context, mark, IMavenConstants.MARKER_IGNORE_MANAGED)); } else if(hint.equals(IMavenConstants.EDITOR_HINT_MISSING_SCHEMA)) { proposals.add(new SchemaCompletionProposal(context, mark)); - } else if (hint.equals(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION)) { + } else if(hint.equals(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION)) { extractedFromMarkers(proposals, mark); //having this first sort of helps for 335490 proposals.add(new LifecycleMappingProposal(context, mark, PluginExecutionAction.ignore)); proposals.add(new WorkspaceLifecycleMappingProposal(mark.getMarker(), PluginExecutionAction.ignore)); @@ -131,7 +136,8 @@ public class PomQuickAssistProcessor implements IQuickAssistProcessor { } } } catch(Exception e) { - MvnIndexPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MvnIndexPlugin.PLUGIN_ID, "Exception in pom quick assist.", e)); + MvnIndexPlugin.getDefault().getLog() + .log(new Status(IStatus.ERROR, MvnIndexPlugin.PLUGIN_ID, "Exception in pom quick assist.", e)); } } } @@ -148,20 +154,20 @@ public class PomQuickAssistProcessor implements IQuickAssistProcessor { //TODO we might consider moving all proposals to this scheme eventually.. need // to remember not wrapping instances of ICompletionProposal and correctly set the context (but how do you set context // to something not created by you?? possible memory leak. - if (IDE.getMarkerHelpRegistry().hasResolutions(mark.getMarker())) { + if(IDE.getMarkerHelpRegistry().hasResolutions(mark.getMarker())) { IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry().getResolutions(mark.getMarker()); - for (IMarkerResolution res : resolutions) { + for(IMarkerResolution res : resolutions) { //sort of weak condition, but can't think of anything else that would filter our explicitly declared ones.. - if (!res.getClass().getName().contains("org.eclipse.m2e.editor.xml")) { - MarkerResolutionProposal prop = new MarkerResolutionProposal(res, mark.getMarker()); - //335299 for discoveryWizardProposal have only one item returned per invokation. - if (res.getClass().getName().contains("DiscoveryWizardProposal")) { - if (!proposals.contains(prop)) { - proposals.add(prop); - } - } else { + if(!res.getClass().getName().contains("org.eclipse.m2e.editor.xml")) { + MarkerResolutionProposal prop = new MarkerResolutionProposal(res, mark.getMarker()); + //335299 for discoveryWizardProposal have only one item returned per invokation. + if(res.getClass().getName().contains("DiscoveryWizardProposal")) { + if(!proposals.contains(prop)) { proposals.add(prop); } + } else { + proposals.add(prop); + } } } } @@ -170,10 +176,10 @@ public class PomQuickAssistProcessor implements IQuickAssistProcessor { public String getErrorMessage() { return null; } - + static String previewForRemovedElement(IDocument doc, Element removed) { - if (removed != null && removed instanceof IndexedRegion) { - IndexedRegion reg = (IndexedRegion)removed; + if(removed != null && removed instanceof IndexedRegion) { + IndexedRegion reg = (IndexedRegion) removed; try { int line = doc.getLineOfOffset(reg.getStartOffset()); int startLine = doc.getLineOffset(line); @@ -182,9 +188,9 @@ public class PomQuickAssistProcessor implements IQuickAssistProcessor { // String currentLine = doc.get(startLine, doc.getLineLength(line)); int nextLine = Math.min(line + 2, doc.getNumberOfLines() - 1); int next2End = doc.getLineOffset(nextLine) + doc.getLineLength(nextLine); - int next2Start = startLine + doc.getLineLength( line ) + 1; + int next2Start = startLine + doc.getLineLength(line) + 1; String nextString = StringUtils.convertToHTMLContent(doc.get(next2Start, next2End - next2Start)); - return "<html>...<br>" + prevString + /**"<del>" + currentLine + "</del>" +*/ nextString + "...<html>"; //$NON-NLS-1$ //$NON-NLS-2$ + return "<html>...<br>" + prevString + /** "<del>" + currentLine + "</del>" + */nextString + "...<html>"; //$NON-NLS-1$ //$NON-NLS-2$ } catch(BadLocationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -193,183 +199,190 @@ public class PomQuickAssistProcessor implements IQuickAssistProcessor { return null; } -class SchemaCompletionProposal implements ICompletionProposal, ICompletionProposalExtension5 { + class SchemaCompletionProposal implements ICompletionProposal, ICompletionProposalExtension5 { - IQuickAssistInvocationContext context; - private MarkerAnnotation annotation; - public SchemaCompletionProposal(IQuickAssistInvocationContext context, MarkerAnnotation mark){ - this.context = context; - annotation = mark; - } - - public void apply(IDocument doc) { - IDOMModel domModel = null; - try { - domModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(doc); - Element root = domModel.getDocument().getDocumentElement(); - - //now check parent version and groupid against the current project's ones.. - if (root.getNodeName().equals(PomQuickAssistProcessor.PROJECT_NODE)) { //$NON-NLS-1$ - if (root instanceof IndexedRegion) { - IndexedRegion off = (IndexedRegion) root; - - int offset = off.getStartOffset() + PomQuickAssistProcessor.PROJECT_NODE.length() + 1; - if (offset <= 0) { - return; - } - InsertEdit edit = new InsertEdit(offset, PomQuickAssistProcessor.XSI_VALUE); - try { - edit.apply(doc); - annotation.getMarker().delete(); - Display.getDefault().asyncExec(new Runnable() { - public void run() { - IEditorPart activeEditor = MvnIndexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow() - .getActivePage().getActiveEditor(); - MvnIndexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage() - .saveEditor(activeEditor, false); - } - }); - } catch(Exception e) { - log.error("Unable to insert schema info", e); //$NON-NLS-1$ + IQuickAssistInvocationContext context; + + private MarkerAnnotation annotation; + + public SchemaCompletionProposal(IQuickAssistInvocationContext context, MarkerAnnotation mark) { + this.context = context; + annotation = mark; + } + + public void apply(IDocument doc) { + IDOMModel domModel = null; + try { + domModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(doc); + Element root = domModel.getDocument().getDocumentElement(); + + //now check parent version and groupid against the current project's ones.. + if(root.getNodeName().equals(PomQuickAssistProcessor.PROJECT_NODE)) { //$NON-NLS-1$ + if(root instanceof IndexedRegion) { + IndexedRegion off = (IndexedRegion) root; + + int offset = off.getStartOffset() + PomQuickAssistProcessor.PROJECT_NODE.length() + 1; + if(offset <= 0) { + return; + } + InsertEdit edit = new InsertEdit(offset, PomQuickAssistProcessor.XSI_VALUE); + try { + edit.apply(doc); + annotation.getMarker().delete(); + Display.getDefault().asyncExec(new Runnable() { + public void run() { + IEditorPart activeEditor = MvnIndexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow() + .getActivePage().getActiveEditor(); + MvnIndexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage() + .saveEditor(activeEditor, false); + } + }); + } catch(Exception e) { + log.error("Unable to insert schema info", e); //$NON-NLS-1$ + } } } - } - } finally { - if (domModel != null) { - domModel.releaseFromRead(); + } finally { + if(domModel != null) { + domModel.releaseFromRead(); + } } } - } - public String getAdditionalProposalInfo() { - //NOT TO BE REALLY IMPLEMENTED, we have the other method - return null; - } + public String getAdditionalProposalInfo() { + //NOT TO BE REALLY IMPLEMENTED, we have the other method + return null; + } - public IContextInformation getContextInformation() { - return null; - } + public IContextInformation getContextInformation() { + return null; + } - public String getDisplayString() { - return Messages.PomQuickAssistProcessor_name; - } + public String getDisplayString() { + return Messages.PomQuickAssistProcessor_name; + } - public Image getImage() { + public Image getImage() { return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD); - } + } - public Point getSelection(IDocument arg0) { - return null; - } + public Point getSelection(IDocument arg0) { + return null; + } + + public Object getAdditionalProposalInfo(IProgressMonitor monitor) { + return "<html>...<br><project <b>" + PomQuickAssistProcessor.XSI_VALUE + "</b>><br>...</html>"; //$NON-NLS-1$ //$NON-NLS-2$ + } - public Object getAdditionalProposalInfo(IProgressMonitor monitor) { - return "<html>...<br><project <b>" + PomQuickAssistProcessor.XSI_VALUE + "</b>><br>...</html>"; //$NON-NLS-1$ //$NON-NLS-2$ } - -} + static class IdPartRemovalProposal implements ICompletionProposal, ICompletionProposalExtension5, IMarkerResolution, + IMarkerResolution2 { -static class IdPartRemovalProposal implements ICompletionProposal, ICompletionProposalExtension5, IMarkerResolution, IMarkerResolution2 { + private IQuickAssistInvocationContext context; - private IQuickAssistInvocationContext context; - private final boolean isVersion; - private final IMarker marker; - public IdPartRemovalProposal(IQuickAssistInvocationContext context, boolean version, MarkerAnnotation mark) { - this.context = context; - isVersion = version; - marker = mark.getMarker(); - } - - public IdPartRemovalProposal(IMarker marker, boolean version) { - this.marker = marker; - isVersion = version; - } - - public void apply(final IDocument doc) { - XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() { - public void process(Element node, IStructuredDocument structured) { - processFix(doc, node, isVersion, marker); - } - }); - } + private final boolean isVersion; - private void processFix(IDocument doc, Element root, boolean isversion, IMarker marker) { - //now check parent version and groupid against the current project's ones.. - if (root.getNodeName().equals(PomQuickAssistProcessor.PROJECT_NODE)) { //$NON-NLS-1$ - Element value = XmlUtils.findChild(root, isversion ? VERSION_NODE : GROUP_ID_NODE); //$NON-NLS-1$ //$NON-NLS-2$ - if (value != null && value instanceof IndexedRegion) { - IndexedRegion off = (IndexedRegion) value; + private final IMarker marker; - int offset = off.getStartOffset(); - if (offset <= 0) { - return; - } - Node prev = value.getNextSibling(); - if (prev instanceof Text) { - //check the content as well?? - off = ((IndexedRegion) prev); + public IdPartRemovalProposal(IQuickAssistInvocationContext context, boolean version, MarkerAnnotation mark) { + this.context = context; + isVersion = version; + marker = mark.getMarker(); + } + + public IdPartRemovalProposal(IMarker marker, boolean version) { + this.marker = marker; + isVersion = version; + } + + public void apply(final IDocument doc) { + XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() { + public void process(Element node, IStructuredDocument structured) { + processFix(doc, node, isVersion, marker); } - DeleteEdit edit = new DeleteEdit(offset, off.getEndOffset() - offset); - try { - edit.apply(doc); - marker.delete(); - } catch(Exception e) { - log.error("Unable to remove the element", e); //$NON-NLS-1$ + }); + } + + private void processFix(IDocument doc, Element root, boolean isversion, IMarker marker) { + //now check parent version and groupid against the current project's ones.. + if(root.getNodeName().equals(PomQuickAssistProcessor.PROJECT_NODE)) { //$NON-NLS-1$ + Element value = XmlUtils.findChild(root, isversion ? VERSION_NODE : GROUP_ID_NODE); //$NON-NLS-1$ //$NON-NLS-2$ + if(value != null && value instanceof IndexedRegion) { + IndexedRegion off = (IndexedRegion) value; + + int offset = off.getStartOffset(); + if(offset <= 0) { + return; + } + Node prev = value.getNextSibling(); + if(prev instanceof Text) { + //check the content as well?? + off = ((IndexedRegion) prev); + } + DeleteEdit edit = new DeleteEdit(offset, off.getEndOffset() - offset); + try { + edit.apply(doc); + marker.delete(); + } catch(Exception e) { + log.error("Unable to remove the element", e); //$NON-NLS-1$ + } } } } - } - public String getAdditionalProposalInfo() { - return null; - } + public String getAdditionalProposalInfo() { + return null; + } - public IContextInformation getContextInformation() { - return null; - } + public IContextInformation getContextInformation() { + return null; + } - public String getDisplayString() { - return isVersion ? Messages.PomQuickAssistProcessor_title_version : Messages.PomQuickAssistProcessor_title_groupId; - } + public String getDisplayString() { + return isVersion ? Messages.PomQuickAssistProcessor_title_version + : Messages.PomQuickAssistProcessor_title_groupId; + } - public Image getImage() { + public Image getImage() { return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE); - } - - public Point getSelection(IDocument arg0) { - return null; - } + } - public Object getAdditionalProposalInfo(IProgressMonitor monitor) { - if (context == null) { - //no context in markerresolution, just to be sure.. - return Messages.PomQuickAssistProcessor_remove_hint; + public Point getSelection(IDocument arg0) { + return null; } - final IDocument doc = context.getSourceViewer().getDocument(); - //oh, how do I miss scala here.. - final String[] toRet = new String[1]; - XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() { - public void process(Element root, IStructuredDocument structured) { - //now check parent version and groupid against the current project's ones.. - if (root.getNodeName().equals(PomQuickAssistProcessor.PROJECT_NODE)) { //$NON-NLS-1$ - Element value = XmlUtils.findChild(root, isVersion ? VERSION_NODE : GROUP_ID_NODE); //$NON-NLS-1$ //$NON-NLS-2$ - toRet[0] = previewForRemovedElement(doc, value); + + public Object getAdditionalProposalInfo(IProgressMonitor monitor) { + if(context == null) { + //no context in markerresolution, just to be sure.. + return Messages.PomQuickAssistProcessor_remove_hint; + } + final IDocument doc = context.getSourceViewer().getDocument(); + //oh, how do I miss scala here.. + final String[] toRet = new String[1]; + XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() { + public void process(Element root, IStructuredDocument structured) { + //now check parent version and groupid against the current project's ones.. + if(root.getNodeName().equals(PomQuickAssistProcessor.PROJECT_NODE)) { //$NON-NLS-1$ + Element value = XmlUtils.findChild(root, isVersion ? VERSION_NODE : GROUP_ID_NODE); //$NON-NLS-1$ //$NON-NLS-2$ + toRet[0] = previewForRemovedElement(doc, value); + } + } + }); + if(toRet[0] != null) { + return toRet[0]; } - }}); - if (toRet[0] != null) { - return toRet[0]; + + return Messages.PomQuickAssistProcessor_remove_hint; } - - return Messages.PomQuickAssistProcessor_remove_hint; - } - public String getLabel() { - return getDisplayString(); - } + public String getLabel() { + return getDisplayString(); + } - public void run(final IMarker marker) { + public void run(final IMarker marker) { try { - XmlUtils.performOnRootElement((IFile)marker.getResource(), new NodeOperation<Element>() { + XmlUtils.performOnRootElement((IFile) marker.getResource(), new NodeOperation<Element>() { public void process(Element node, IStructuredDocument structured) { processFix(structured, node, isVersion, marker); } @@ -381,164 +394,167 @@ static class IdPartRemovalProposal implements ICompletionProposal, ICompletionPr } } - public String getDescription() { - // TODO Auto-generated method stub - return (String) getAdditionalProposalInfo(new NullProgressMonitor()); + public String getDescription() { + // TODO Auto-generated method stub + return (String) getAdditionalProposalInfo(new NullProgressMonitor()); + } } -} -static class ManagedVersionRemovalProposal implements ICompletionProposal, ICompletionProposalExtension5, IMarkerResolution, IMarkerResolution2 { + static class ManagedVersionRemovalProposal implements ICompletionProposal, ICompletionProposalExtension5, + IMarkerResolution, IMarkerResolution2 { - private IQuickAssistInvocationContext context; - private final boolean isDependency; - private final IMarker marker; - public ManagedVersionRemovalProposal(IQuickAssistInvocationContext context, boolean dependency, MarkerAnnotation mark) { - this.context = context; - isDependency = dependency; - marker = mark.getMarker(); - } - - public ManagedVersionRemovalProposal(IMarker marker, boolean dependency) { - this.marker = marker; - isDependency = dependency; - } - + private IQuickAssistInvocationContext context; - - public void apply(final IDocument doc) { - XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() { - public void process(Element node, IStructuredDocument structured) { - processFix(doc, node, isDependency, marker); - } - }); - } + private final boolean isDependency; - private void processFix(IDocument doc, Element root, boolean isdep, IMarker marker) { - if (root.getNodeName().equals(PomQuickAssistProcessor.PROJECT_NODE)) { - Element artifact = findArtifactElement(root, isdep, marker); - if (artifact == null) { - //TODO report somehow? - log.error("Unable to find the marked element"); //$NON-NLS-1$ - return; - } - Element value = XmlUtils.findChild(artifact, VERSION_NODE); //$NON-NLS-1$ //$NON-NLS-2$ - if (value != null && value instanceof IndexedRegion) { - IndexedRegion off = (IndexedRegion) value; + private final IMarker marker; - int offset = off.getStartOffset(); - if (offset <= 0) { - return; + public ManagedVersionRemovalProposal(IQuickAssistInvocationContext context, boolean dependency, + MarkerAnnotation mark) { + this.context = context; + isDependency = dependency; + marker = mark.getMarker(); + } + + public ManagedVersionRemovalProposal(IMarker marker, boolean dependency) { + this.marker = marker; + isDependency = dependency; + } + + public void apply(final IDocument doc) { + XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() { + public void process(Element node, IStructuredDocument structured) { + processFix(doc, node, isDependency, marker); } - Node prev = value.getNextSibling(); - if (prev instanceof Text) { - //check the content as well?? - off = ((IndexedRegion) prev); + }); + } + + private void processFix(IDocument doc, Element root, boolean isdep, IMarker marker) { + if(root.getNodeName().equals(PomQuickAssistProcessor.PROJECT_NODE)) { + Element artifact = findArtifactElement(root, isdep, marker); + if(artifact == null) { + //TODO report somehow? + log.error("Unable to find the marked element"); //$NON-NLS-1$ + return; } - DeleteEdit edit = new DeleteEdit(offset, off.getEndOffset() - offset); - try { - edit.apply(doc); - marker.delete(); - } catch(Exception e) { - log.error("Unable to remove the element", e); //$NON-NLS-1$ + Element value = XmlUtils.findChild(artifact, VERSION_NODE); //$NON-NLS-1$ //$NON-NLS-2$ + if(value != null && value instanceof IndexedRegion) { + IndexedRegion off = (IndexedRegion) value; + + int offset = off.getStartOffset(); + if(offset <= 0) { + return; + } + Node prev = value.getNextSibling(); + if(prev instanceof Text) { + //check the content as well?? + off = ((IndexedRegion) prev); + } + DeleteEdit edit = new DeleteEdit(offset, off.getEndOffset() - offset); + try { + edit.apply(doc); + marker.delete(); + } catch(Exception e) { + log.error("Unable to remove the element", e); //$NON-NLS-1$ + } } } } - } - private Element findArtifactElement(Element root, boolean isdep, IMarker marker) { - if (root == null) { - return null; - } - String groupId = marker.getAttribute("groupId", null); - String artifactId = marker.getAttribute("artifactId", null); - assert groupId != null; - assert artifactId != null; - - String profile = marker.getAttribute("profile", null); - Element artifactParent = root; - if (profile != null) { - Element profileRoot = XmlUtils.findChild(root, "profiles"); - if (profileRoot != null) { - for (Element prf : XmlUtils.findChilds(profileRoot, "profile")) { - if (profile.equals(XmlUtils.getTextValue(XmlUtils.findChild(prf, "id")))) { - artifactParent = prf; - break; + private Element findArtifactElement(Element root, boolean isdep, IMarker marker) { + if(root == null) { + return null; + } + String groupId = marker.getAttribute("groupId", null); + String artifactId = marker.getAttribute("artifactId", null); + assert groupId != null; + assert artifactId != null; + + String profile = marker.getAttribute("profile", null); + Element artifactParent = root; + if(profile != null) { + Element profileRoot = XmlUtils.findChild(root, "profiles"); + if(profileRoot != null) { + for(Element prf : XmlUtils.findChilds(profileRoot, "profile")) { + if(profile.equals(XmlUtils.getTextValue(XmlUtils.findChild(prf, "id")))) { + artifactParent = prf; + break; + } } } } + if(!isdep) { + //we have plugins now, need to go one level down to build + artifactParent = XmlUtils.findChild(artifactParent, "build"); + } + if(artifactParent == null) { + return null; + } + Element list = XmlUtils.findChild(artifactParent, isdep ? "dependencies" : "plugins"); + if(list == null) { + return null; + } + Element artifact = null; + for(Element art : XmlUtils.findChilds(list, isdep ? "dependency" : "plugin")) { + String grpString = XmlUtils.getTextValue(XmlUtils.findChild(art, GROUP_ID_NODE)); + String artString = XmlUtils.getTextValue(XmlUtils.findChild(art, ARTIFACT_ID_NODE)); + if(groupId.equals(grpString) && artifactId.equals(artString)) { + artifact = art; + break; + } + } + return artifact; } - if (!isdep) { - //we have plugins now, need to go one level down to build - artifactParent = XmlUtils.findChild(artifactParent, "build"); - } - if (artifactParent == null) { + + public String getAdditionalProposalInfo() { return null; } - Element list = XmlUtils.findChild(artifactParent, isdep ? "dependencies" : "plugins"); - if (list == null) { + + public IContextInformation getContextInformation() { return null; } - Element artifact = null; - for (Element art : XmlUtils.findChilds(list, isdep ? "dependency" : "plugin")) { - String grpString = XmlUtils.getTextValue(XmlUtils.findChild(art, GROUP_ID_NODE)); - String artString = XmlUtils.getTextValue(XmlUtils.findChild(art, ARTIFACT_ID_NODE)); - if (groupId.equals(grpString) && artifactId.equals(artString)) { - artifact = art; - break; - } - } - return artifact; - } - - public String getAdditionalProposalInfo() { - return null; - } - public IContextInformation getContextInformation() { - return null; - } - - public String getDisplayString() { - return Messages.PomQuickAssistProcessor_title_version; - } + public String getDisplayString() { + return Messages.PomQuickAssistProcessor_title_version; + } - public Image getImage() { + public Image getImage() { return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE); - } - - public Point getSelection(IDocument arg0) { - return null; - } + } - public Object getAdditionalProposalInfo(IProgressMonitor monitor) { - if (context == null) { - //no context in markerresolution, just to be sure.. - return Messages.PomQuickAssistProcessor_remove_hint; + public Point getSelection(IDocument arg0) { + return null; } - final IDocument doc = context.getSourceViewer().getDocument(); - final String[] toRet = new String[1]; - XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() { - public void process(Element node, IStructuredDocument structured) { - Element artifact = findArtifactElement(node, isDependency, marker); - if (artifact != null) { - Element value = XmlUtils.findChild(artifact, VERSION_NODE); - toRet[0] = previewForRemovedElement(doc, value); + + public Object getAdditionalProposalInfo(IProgressMonitor monitor) { + if(context == null) { + //no context in markerresolution, just to be sure.. + return Messages.PomQuickAssistProcessor_remove_hint; + } + final IDocument doc = context.getSourceViewer().getDocument(); + final String[] toRet = new String[1]; + XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() { + public void process(Element node, IStructuredDocument structured) { + Element artifact = findArtifactElement(node, isDependency, marker); + if(artifact != null) { + Element value = XmlUtils.findChild(artifact, VERSION_NODE); + toRet[0] = previewForRemovedElement(doc, value); + } } + }); + if(toRet[0] != null) { + return toRet[0]; } - }); - if (toRet[0] != null) { - return toRet[0]; + return Messages.PomQuickAssistProcessor_remove_hint; } - return Messages.PomQuickAssistProcessor_remove_hint; - } - public String getLabel() { - return getDisplayString(); - } + public String getLabel() { + return getDisplayString(); + } - public void run(final IMarker marker) { + public void run(final IMarker marker) { try { - XmlUtils.performOnRootElement((IFile)marker.getResource(), new NodeOperation<Element>() { + XmlUtils.performOnRootElement((IFile) marker.getResource(), new NodeOperation<Element>() { public void process(Element node, IStructuredDocument structured) { processFix(structured, node, isDependency, marker); } @@ -548,43 +564,47 @@ static class ManagedVersionRemovalProposal implements ICompletionProposal, IComp } catch(CoreException e) { log.error("Error processing marker", e); } - } + } - public String getDescription() { - return (String) getAdditionalProposalInfo(new NullProgressMonitor()); + public String getDescription() { + return (String) getAdditionalProposalInfo(new NullProgressMonitor()); + } } -} -static class IgnoreWarningProposal implements ICompletionProposal, ICompletionProposalExtension5, IMarkerResolution, IMarkerResolution2 { + static class IgnoreWarningProposal implements ICompletionProposal, ICompletionProposalExtension5, IMarkerResolution, + IMarkerResolution2 { - private IQuickAssistInvocationContext context; - private final IMarker marker; - private final String markupText; - public IgnoreWarningProposal(IQuickAssistInvocationContext context, MarkerAnnotation mark, String markupText) { - this.context = context; - marker = mark.getMarker(); - this.markupText = markupText; - } - - public IgnoreWarningProposal(IMarker marker, String markupText) { - this.marker = marker; - this.markupText = markupText; - } - - public void apply(IDocument doc) { - XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() { - public void process(Element node, IStructuredDocument structured) { - processFix(structured, marker); - } - }); - } + private IQuickAssistInvocationContext context; - private void processFix(IStructuredDocument doc, IMarker marker) { + private final IMarker marker; + + private final String markupText; + + public IgnoreWarningProposal(IQuickAssistInvocationContext context, MarkerAnnotation mark, String markupText) { + this.context = context; + marker = mark.getMarker(); + this.markupText = markupText; + } + + public IgnoreWarningProposal(IMarker marker, String markupText) { + this.marker = marker; + this.markupText = markupText; + } + + public void apply(IDocument doc) { + XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() { + public void process(Element node, IStructuredDocument structured) { + processFix(structured, marker); + } + }); + } + + private void processFix(IStructuredDocument doc, IMarker marker) { IDOMModel domModel = null; try { domModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(doc); int line; - if (context != null) { + if(context != null) { line = doc.getLineOfOffset(context.getOffset()); } else { line = marker.getAttribute(IMarker.LINE_NUMBER, -1); @@ -596,13 +616,13 @@ static class IgnoreWarningProposal implements ICompletionProposal, ICompletionPr int lineend = linestart + doc.getLineLength(line); int start = linestart; IndexedRegion reg = domModel.getIndexedRegion(start); - while (reg != null && !(reg instanceof Element) && start < lineend) { + while(reg != null && !(reg instanceof Element) && start < lineend) { reg = domModel.getIndexedRegion(reg.getEndOffset() + 1); - if (reg != null) { + if(reg != null) { start = reg.getStartOffset(); } } - if (reg != null && reg instanceof Element) { + if(reg != null && reg instanceof Element) { InsertEdit edit = new InsertEdit(reg.getEndOffset(), "<!--" + markupText + "-->"); try { edit.apply(doc); @@ -616,109 +636,110 @@ static class IgnoreWarningProposal implements ICompletionProposal, ICompletionPr e1.printStackTrace(); } } finally { - if (domModel != null) { + if(domModel != null) { domModel.releaseFromRead(); } - } - } - - public String getAdditionalProposalInfo() { - return null; - } + } + } - public IContextInformation getContextInformation() { - return null; - } + public String getAdditionalProposalInfo() { + return null; + } - public String getDisplayString() { - return "Ignore this warning"; - } + public IContextInformation getContextInformation() { + return null; + } - public Image getImage() { - return MvnImages.IMG_CLOSE; - } + public String getDisplayString() { + return "Ignore this warning"; + } - public Point getSelection(IDocument arg0) { - return null; - } + public Image getImage() { + return MvnImages.IMG_CLOSE; + } - public Object getAdditionalProposalInfo(IProgressMonitor monitor) { - if (context == null) { - //no context in markerresolution, just to be sure.. - return "Adds comment markup next to the affected element. No longer shows the warning afterwards"; + public Point getSelection(IDocument arg0) { + return null; } - IDOMModel domModel = null; - try { - IDocument doc = context.getSourceViewer().getDocument(); - domModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(doc); + + public Object getAdditionalProposalInfo(IProgressMonitor monitor) { + if(context == null) { + //no context in markerresolution, just to be sure.. + return "Adds comment markup next to the affected element. No longer shows the warning afterwards"; + } + IDOMModel domModel = null; try { - //the offset of context is important here, not the offset of the marker!!! - //line/offset of marker only gets updated hen file gets saved. - //we need the proper handling also for unsaved documents.. - int line = doc.getLineOfOffset(context.getOffset()); - int linestart = doc.getLineOffset(line); - int lineend = linestart + doc.getLineLength(line); - int start = linestart; - IndexedRegion reg = domModel.getIndexedRegion(start); - while (reg != null && !(reg instanceof Element) && start < lineend) { - reg = domModel.getIndexedRegion(reg.getEndOffset() + 1); - if (reg != null) { - start = reg.getStartOffset(); + IDocument doc = context.getSourceViewer().getDocument(); + domModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(doc); + try { + //the offset of context is important here, not the offset of the marker!!! + //line/offset of marker only gets updated hen file gets saved. + //we need the proper handling also for unsaved documents.. + int line = doc.getLineOfOffset(context.getOffset()); + int linestart = doc.getLineOffset(line); + int lineend = linestart + doc.getLineLength(line); + int start = linestart; + IndexedRegion reg = domModel.getIndexedRegion(start); + while(reg != null && !(reg instanceof Element) && start < lineend) { + reg = domModel.getIndexedRegion(reg.getEndOffset() + 1); + if(reg != null) { + start = reg.getStartOffset(); + } } - } - if (reg != null && reg instanceof Element) { //just a simple guard against moved marker - try { - String currentLine = StringUtils.convertToHTMLContent(doc.get(reg.getStartOffset(), reg.getEndOffset() - reg.getStartOffset())); - String insert = StringUtils.convertToHTMLContent("<!--" + markupText + "-->"); - return "<html>...<br>" + currentLine + "<b>" + insert + "</b><br>...<html>"; //$NON-NLS-1$ //$NON-NLS-2$ - } catch(BadLocationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if(reg != null && reg instanceof Element) { //just a simple guard against moved marker + try { + String currentLine = StringUtils.convertToHTMLContent(doc.get(reg.getStartOffset(), reg.getEndOffset() + - reg.getStartOffset())); + String insert = StringUtils.convertToHTMLContent("<!--" + markupText + "-->"); + return "<html>...<br>" + currentLine + "<b>" + insert + "</b><br>...<html>"; //$NON-NLS-1$ //$NON-NLS-2$ + } catch(BadLocationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } + } catch(BadLocationException e1) { + log.error("Error while computing completion proposal", e1); + } + } finally { + if(domModel != null) { + domModel.releaseFromRead(); } - } catch(BadLocationException e1) { - log.error("Error while computing completion proposal", e1); - } - } finally { - if (domModel != null) { - domModel.releaseFromRead(); } - } - return "Adds comment markup next to the affected element. No longer shows the warning afterwards"; - } + return "Adds comment markup next to the affected element. No longer shows the warning afterwards"; + } - public String getLabel() { - return getDisplayString(); - } + public String getLabel() { + return getDisplayString(); + } - public void run(final IMarker marker) { - try { - XmlUtils.performOnRootElement((IFile)marker.getResource(), new NodeOperation<Element>() { - public void process(Element node, IStructuredDocument structured) { - processFix(structured, marker); - } - }); - } catch(IOException e) { - log.error("Error processing marker", e); - } catch(CoreException e) { - log.error("Error processing marker", e); - } - } + public void run(final IMarker marker) { + try { + XmlUtils.performOnRootElement((IFile) marker.getResource(), new NodeOperation<Element>() { + public void process(Element node, IStructuredDocument structured) { + processFix(structured, marker); + } + }); + } catch(IOException e) { + log.error("Error processing marker", e); + } catch(CoreException e) { + log.error("Error processing marker", e); + } + } - public String getDescription() { - return (String) getAdditionalProposalInfo(new NullProgressMonitor()); - } -} + public String getDescription() { + return (String) getAdditionalProposalInfo(new NullProgressMonitor()); + } + } /** - * a wrapper around IMarkerResolution that acts as ICompletionProposal - * for 335299 introduced equals() and hashcode() methods that are based on the MarkerResolution passed in. + * a wrapper around IMarkerResolution that acts as ICompletionProposal for 335299 introduced equals() and hashcode() + * methods that are based on the MarkerResolution passed in. + * * @author mkleint */ public class MarkerResolutionProposal implements ICompletionProposal { - /** - * + /** * for 335299 introduced equals() and hashcode() methods that are based on the MarkerResolution passed in. */ @Override diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomStructuredTextViewConfiguration.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomStructuredTextViewConfiguration.java index 3b3ae8cc..fea585ae 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomStructuredTextViewConfiguration.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomStructuredTextViewConfiguration.java @@ -20,6 +20,7 @@ import org.eclipse.wst.sse.core.text.IStructuredPartitions; import org.eclipse.wst.xml.core.text.IXMLPartitions; import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML; + /** * @author Lukas Krecan */ @@ -32,7 +33,7 @@ public class PomStructuredTextViewConfiguration extends StructuredTextViewerConf } return super.getContentAssistProcessors(sourceViewer, partitionType); } - + @Override public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) { // return super.getTextHover(sourceViewer, contentType, stateMask); @@ -42,14 +43,14 @@ public class PomStructuredTextViewConfiguration extends StructuredTextViewerConf @Override public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) { IHyperlinkDetector[] detectors = super.getHyperlinkDetectors(sourceViewer); - if(detectors==null) { + if(detectors == null) { detectors = new IHyperlinkDetector[0]; } IHyperlinkDetector[] pomDetectors = new IHyperlinkDetector[detectors.length + 1]; pomDetectors[0] = new PomHyperlinkDetector(); System.arraycopy(detectors, 0, pomDetectors, 1, detectors.length); - + return pomDetectors; } @@ -63,4 +64,3 @@ public class PomStructuredTextViewConfiguration extends StructuredTextViewerConf } } - diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTemplateContext.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTemplateContext.java index cdc07b62..060ad8a6 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTemplateContext.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTemplateContext.java @@ -21,21 +21,9 @@ import java.util.HashSet; import java.util.List; import java.util.Properties; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.DependencyManagement; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginManagement; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.interpolation.InterpolationException; -import org.codehaus.plexus.interpolation.PrefixedObjectValueSource; -import org.codehaus.plexus.interpolation.PropertiesBasedValueSource; -import org.codehaus.plexus.interpolation.RegexBasedInterpolator; -import org.codehaus.plexus.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -45,6 +33,21 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.templates.Template; import org.eclipse.osgi.util.NLS; +import org.codehaus.plexus.interpolation.InterpolationException; +import org.codehaus.plexus.interpolation.PrefixedObjectValueSource; +import org.codehaus.plexus.interpolation.PropertiesBasedValueSource; +import org.codehaus.plexus.interpolation.RegexBasedInterpolator; +import org.codehaus.plexus.util.StringUtils; + +import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.plugin.descriptor.Parameter; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.project.MavenProject; + import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator; import org.eclipse.m2e.core.ui.internal.search.util.ArtifactInfo; import org.eclipse.m2e.core.ui.internal.search.util.Packaging; @@ -60,62 +63,64 @@ import org.eclipse.m2e.editor.xml.internal.XmlUtils; * @author Eugene Kuleshov */ public enum PomTemplateContext { - + UNKNOWN("unknown"), // //$NON-NLS-1$ - + DOCUMENT("#document"), // //$NON-NLS-1$ - + PROJECT("project"), // //$NON-NLS-1$ - + BUILD("build"), // //$NON-NLS-1$ - + PARENT("parent"), // //$NON-NLS-1$ - + RELATIVE_PATH("relativePath"), // //$NON-NLS-1$ - + MODULES("modules"), // //$NON-NLS-1$ PROPERTIES("properties"), // //$NON-NLS-1$ - + DEPENDENCIES("dependencies"), // //$NON-NLS-1$ DEPENDENCY_MANAGEMENT("dependencyManagement"), // //$NON-NLS-1$ - + EXCLUSIONS("exclusions"), // //$NON-NLS-1$ - + PLUGINS("plugins"), // //$NON-NLS-1$ PLUGIN("plugin"), // //$NON-NLS-1$ - + PLUGIN_MANAGEMENT("pluginManagement"), // //$NON-NLS-1$ - + EXECUTIONS("executions"), // //$NON-NLS-1$ - + PROFILES("profiles"), // //$NON-NLS-1$ - + PROFILE("profile"), // //$NON-NLS-1$ - + REPOSITORIES("repositories"), // //$NON-NLS-1$ CONFIGURATION("configuration") { //$NON-NLS-1$ @Override - protected void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, String prefix) throws CoreException { + protected void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, + String prefix) throws CoreException { if("execution".equals(node.getParentNode().getNodeName()) //$NON-NLS-1$ || "reportSet".equals(node.getParentNode().getNodeName())) { //$NON-NLS-1$ node = node.getParentNode().getParentNode(); } String groupId = getGroupId(node); - if(groupId==null) { - groupId = "org.apache.maven.plugins"; // TODO support other default groups //$NON-NLS-1$ + if(groupId == null) { + groupId = "org.apache.maven.plugins"; // TODO support other default groups //$NON-NLS-1$ } String artifactId = getArtifactId(node); - String version = extractVersion(project, eclipseprj, getVersion(node), groupId, artifactId, EXTRACT_STRATEGY_PLUGIN | EXTRACT_STRATEGY_SEARCH); - if (version == null) { + String version = extractVersion(project, eclipseprj, getVersion(node), groupId, artifactId, + EXTRACT_STRATEGY_PLUGIN | EXTRACT_STRATEGY_SEARCH); + if(version == null) { return; } PluginDescriptor descriptor = PomTemplateContextUtil.INSTANCE.getPluginDescriptor(groupId, artifactId, version); - if(descriptor!=null) { + if(descriptor != null) { List<MojoDescriptor> mojos = descriptor.getMojos(); HashSet<String> params = new HashSet<String>(); for(MojoDescriptor mojo : mojos) { @@ -126,22 +131,22 @@ public enum PomTemplateContext { String name = parameter.getName(); if(!params.contains(name) && name.startsWith(prefix)) { params.add(name); - + String text = NLS.bind(Messages.PomTemplateContext_param, parameter.isRequired(), parameter.getType()); - + String expression = parameter.getExpression(); - if(expression!=null) { + if(expression != null) { text += NLS.bind(Messages.PomTemplateContext_param_expr, expression); } - + String defaultValue = parameter.getDefaultValue(); - if(defaultValue!=null) { + if(defaultValue != null) { text += NLS.bind(Messages.PomTemplateContext_param_def, defaultValue); } - + String desc = parameter.getDescription().trim(); text += desc.startsWith("<p>") ? desc : "<br>" + desc; //$NON-NLS-1$ //$NON-NLS-2$ - + proposals.add(new Template(name, text, getContextTypeId(), // "<" + name + ">${cursor}</" + name + ">", false)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } @@ -151,12 +156,14 @@ public enum PomTemplateContext { } } }, - + GROUP_ID("groupId") { //$NON-NLS-1$ @Override - public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, String prefix) throws CoreException { + public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, + String prefix) throws CoreException { String contextTypeId = getContextTypeId(); - for(String groupId : getSearchEngine(eclipseprj).findGroupIds(prefix, getPackaging(node), getContainingArtifact(node))) { + for(String groupId : getSearchEngine(eclipseprj).findGroupIds(prefix, getPackaging(node), + getContainingArtifact(node))) { add(proposals, contextTypeId, groupId); } } @@ -164,7 +171,8 @@ public enum PomTemplateContext { ARTIFACT_ID("artifactId") { //$NON-NLS-1$ @Override - public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, String prefix) throws CoreException { + public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, + String prefix) throws CoreException { String groupId = getGroupId(node); //#MNGECLIPSE-1832 if((groupId == null || groupId.trim().length() == 0) && "plugin".equals(node.getParentNode().getNodeName())) { @@ -182,7 +190,8 @@ public enum PomTemplateContext { VERSION("version") { //$NON-NLS-1$ @Override - public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, String prefix) throws CoreException { + public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, + String prefix) throws CoreException { String groupId = getGroupId(node); //#MNGECLIPSE-1832 if((groupId == null || groupId.trim().length() == 0) && "plugin".equals(node.getParentNode().getNodeName())) { @@ -196,49 +205,54 @@ public enum PomTemplateContext { } } //mkleint: this concept that all versions out there are equal is questionable.. - if ("dependency".equals(node.getParentNode().getNodeName())) { //$NON-NLS-1$ + if("dependency".equals(node.getParentNode().getNodeName())) { //$NON-NLS-1$ //see if we can complete the properties ending with .version - + List<String> keys = new ArrayList<String>(); String contextTypeId = getContextTypeId(); - MavenProject mvn = project; - if (mvn != null) { - //if groupid is the same, suggest ${project.version} - if (groupId.equals(mvn.getGroupId())) { - proposals.add(new Template("${project.version}", Messages.PomTemplateContext_project_version_hint, contextTypeId, "$${project.version}", false)); //$NON-NLS-1$ //$NON-NLS-3$ - } - Properties props = mvn.getProperties(); - if (props != null) { - for (Object key : props.keySet()) { - //only add the properties following the .version convention - if (key.toString().endsWith(".version") || key.toString().endsWith("Version")) { //$NON-NLS-1$ //$NON-NLS-2$ - keys.add(key.toString()); - } + MavenProject mvn = project; + if(mvn != null) { + //if groupid is the same, suggest ${project.version} + if(groupId.equals(mvn.getGroupId())) { + proposals + .add(new Template( + "${project.version}", Messages.PomTemplateContext_project_version_hint, contextTypeId, "$${project.version}", false)); //$NON-NLS-1$ //$NON-NLS-3$ + } + Properties props = mvn.getProperties(); + if(props != null) { + for(Object key : props.keySet()) { + //only add the properties following the .version convention + if(key.toString().endsWith(".version") || key.toString().endsWith("Version")) { //$NON-NLS-1$ //$NON-NLS-2$ + keys.add(key.toString()); } - //sort just properties - Collections.sort(keys); - if (keys.size() > 0) { - for (String key : keys) { - String expr = "${" + key + "}"; //$NON-NLS-1$ //$NON-NLS-2$ - proposals.add(new Template(expr, Messages.PomTemplateContext_expression_description, contextTypeId, "$" + expr, false)); //$NON-NLS-2$ //$NON-NLS-1$ - } + } + //sort just properties + Collections.sort(keys); + if(keys.size() > 0) { + for(String key : keys) { + String expr = "${" + key + "}"; //$NON-NLS-1$ //$NON-NLS-2$ + proposals.add(new Template(expr, Messages.PomTemplateContext_expression_description, contextTypeId, + "$" + expr, false)); //$NON-NLS-2$ //$NON-NLS-1$ } } - + } + } else { //if we don't have the maven facade, it means the pom is probably broken. //all we can do is to try guess the groupid and come up with the project.version proposal eventually Element root = node.getOwnerDocument().getDocumentElement(); - if (root != null && "project".equals(root.getNodeName())) {//$NON-NLS-1$ + if(root != null && "project".equals(root.getNodeName())) {//$NON-NLS-1$ String currentgroupid = XmlUtils.getTextValue(XmlUtils.findChild(root, "groupId"));//$NON-NLS-1$ - if (currentgroupid == null) { + if(currentgroupid == null) { Element parEl = XmlUtils.findChild(root, "parent");//$NON-NLS-1$ - if (parEl != null) { + if(parEl != null) { currentgroupid = XmlUtils.getTextValue(XmlUtils.findChild(parEl, "groupId"));//$NON-NLS-1$ } } - if (groupId.equals(currentgroupid)) { - proposals.add(new Template("${project.version}", Messages.PomTemplateContext_project_version_hint, contextTypeId, "$${project.version}", false)); //$NON-NLS-1$ //$NON-NLS-3$ + if(groupId.equals(currentgroupid)) { + proposals + .add(new Template( + "${project.version}", Messages.PomTemplateContext_project_version_hint, contextTypeId, "$${project.version}", false)); //$NON-NLS-1$ //$NON-NLS-3$ } } } @@ -248,7 +262,8 @@ public enum PomTemplateContext { CLASSIFIER("classifier") { //$NON-NLS-1$ @Override - public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, String prefix) throws CoreException { + public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, + String prefix) throws CoreException { String groupId = getGroupId(node); String artifactId = getArtifactId(node); String version = getVersion(node); @@ -264,22 +279,25 @@ public enum PomTemplateContext { TYPE("type") { //$NON-NLS-1$ @Override - public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, String prefix) throws CoreException { + public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, + String prefix) throws CoreException { String groupId = getGroupId(node); String artifactId = getArtifactId(node); String version = getVersion(node); String contextTypeId = getContextTypeId(); if(groupId != null && artifactId != null && version != null) { - for(String type : getSearchEngine(eclipseprj).findTypes(groupId, artifactId, version, prefix, getPackaging(node))) { + for(String type : getSearchEngine(eclipseprj).findTypes(groupId, artifactId, version, prefix, + getPackaging(node))) { add(proposals, contextTypeId, type, groupId + ":" + artifactId + ":" + version + ":" + type); } } } }, - + PACKAGING("packaging") { //$NON-NLS-1$ @Override - public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, String prefix) { + public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, + String prefix) { String contextTypeId = getContextTypeId(); // TODO only show "pom" packaging in root section add(proposals, contextTypeId, "pom"); //$NON-NLS-1$ @@ -294,10 +312,11 @@ public enum PomTemplateContext { add(proposals, contextTypeId, "maven-archetype"); //$NON-NLS-1$ } }, - + SCOPE("scope") { //$NON-NLS-1$ @Override - public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, String prefix) { + public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, + String prefix) { String contextTypeId = getContextTypeId(); add(proposals, contextTypeId, "compile"); //$NON-NLS-1$ add(proposals, contextTypeId, "test"); //$NON-NLS-1$ @@ -306,22 +325,23 @@ public enum PomTemplateContext { add(proposals, contextTypeId, "system"); //$NON-NLS-1$ // TODO only show "import" scope in <dependencyManagement> add(proposals, contextTypeId, "import"); //$NON-NLS-1$ - } + } }, - + SYSTEM_PATH("systemPath"), //$NON-NLS-1$ - + PHASE("phase") { //$NON-NLS-1$ @Override - public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, String prefix) { + public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, + String prefix) { String contextTypeId = getContextTypeId(); // TODO the following list should be derived from the packaging handler (the actual lifecycle) - + // Clean Lifecycle add(proposals, contextTypeId, "pre-clean", Messages.PomTemplateContext_preclean); //$NON-NLS-1$ add(proposals, contextTypeId, "clean", Messages.PomTemplateContext_clean); //$NON-NLS-1$ add(proposals, contextTypeId, "post-clean", Messages.PomTemplateContext_postclean); //$NON-NLS-1$ - + // Default Lifecycle add(proposals, contextTypeId, "validate", Messages.PomTemplateContext_validate); //$NON-NLS-1$ add(proposals, contextTypeId, "generate-sources", Messages.PomTemplateContext_generatesources); //$NON-NLS-1$ @@ -345,7 +365,7 @@ public enum PomTemplateContext { add(proposals, contextTypeId, "verify", Messages.PomTemplateContext_verify); //$NON-NLS-1$ add(proposals, contextTypeId, "install", Messages.PomTemplateContext_install); //$NON-NLS-1$ add(proposals, contextTypeId, "deploy", Messages.PomTemplateContext_deploy); //$NON-NLS-1$ - + // Site Lifecycle add(proposals, contextTypeId, "pre-site", Messages.PomTemplateContext_presite); //$NON-NLS-1$ add(proposals, contextTypeId, "site", Messages.PomTemplateContext_site); //$NON-NLS-1$ @@ -356,7 +376,8 @@ public enum PomTemplateContext { GOAL("goal") { //$NON-NLS-1$ @Override - public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, String prefix) throws CoreException { + public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, + String prefix) throws CoreException { if(!"goals".equals(node.getParentNode().getNodeName())) { //$NON-NLS-1$ return; } @@ -371,22 +392,23 @@ public enum PomTemplateContext { node = node.getParentNode(); String groupId = getGroupId(node); - if(groupId==null) { + if(groupId == null) { groupId = "org.apache.maven.plugins"; //$NON-NLS-1$ } String artifactId = getArtifactId(node); - - String version = extractVersion(project, eclipseprj, getVersion(node), groupId, artifactId, EXTRACT_STRATEGY_PLUGIN | EXTRACT_STRATEGY_SEARCH); - if(version==null) { + + String version = extractVersion(project, eclipseprj, getVersion(node), groupId, artifactId, + EXTRACT_STRATEGY_PLUGIN | EXTRACT_STRATEGY_SEARCH); + if(version == null) { return; } - + PluginDescriptor descriptor = PomTemplateContextUtil.INSTANCE.getPluginDescriptor(groupId, artifactId, version); - if (descriptor != null) { + if(descriptor != null) { List<MojoDescriptor> mojos = descriptor.getMojos(); - if (mojos != null) { + if(mojos != null) { String contextTypeId = getContextTypeId(); - for (MojoDescriptor mojo : mojos) { + for(MojoDescriptor mojo : mojos) { add(proposals, contextTypeId, mojo.getGoal(), mojo.getDescription()); } } @@ -396,8 +418,8 @@ public enum PomTemplateContext { MODULE("module") { //$NON-NLS-1$ @Override - public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, String prefix) - throws CoreException { + public void addTemplates(MavenProject project, IProject eclipseprj, Collection<Template> proposals, Node node, + String prefix) throws CoreException { if(project == null) { //shall not happen just double check. return; @@ -405,20 +427,20 @@ public enum PomTemplateContext { //MNGECLIPSE-2204 collect the existing values from the surrounding xml content only.. List<String> existings = new ArrayList<String>(); Node moduleNode = node; - if (moduleNode != null) { + if(moduleNode != null) { Node modulesNode = moduleNode.getParentNode(); - if (modulesNode != null) { - for (Element el : XmlUtils.findChilds((Element)modulesNode, "module")) { - if (el != moduleNode) { + if(modulesNode != null) { + for(Element el : XmlUtils.findChilds((Element) modulesNode, "module")) { + if(el != moduleNode) { String val = XmlUtils.getTextValue(el); - if (val != null) { + if(val != null) { existings.add(val); } } } } } - + File directory = new File(eclipseprj.getLocationURI()); final File currentPom = new File(directory, "pom.xml"); String path = prefix; @@ -437,7 +459,7 @@ public enum PomTemplateContext { path = lastElement != null ? path.substring(0, path.length() - lastElement.length()) : path; FileFilter filter = new FileFilter() { public boolean accept(File pathname) { - if (pathname.isDirectory()) { + if(pathname.isDirectory()) { File pom = new File(pathname, "pom.xml"); //$NON-NLS-1$ //TODO shall also handle polyglot maven :) return pom.exists() && pom.isFile() && !pom.equals(currentPom); @@ -445,24 +467,24 @@ public enum PomTemplateContext { return false; } }; - if (directory != null && directory.exists() && directory.isDirectory()) { + if(directory != null && directory.exists() && directory.isDirectory()) { File[] offerings = directory.listFiles(filter); - for (File candidate : offerings) { - if(lastElement == null || candidate.getName().startsWith(lastElement) ) { + for(File candidate : offerings) { + if(lastElement == null || candidate.getName().startsWith(lastElement)) { String val = path + candidate.getName(); - if (!existings.contains(val)) { //only those not already being added in the surrounding area + if(!existings.contains(val)) { //only those not already being added in the surrounding area add(proposals, getContextTypeId(), val, NLS.bind(Messages.PomTemplateContext_candidate, candidate)); } } } - if (path.length() == 0 && directory.equals(currentPom.getParentFile())) { + if(path.length() == 0 && directory.equals(currentPom.getParentFile())) { //for the empty value, when searching in current directory, propose also stuff one level up. File currentParent = directory.getParentFile(); - if (currentParent != null && currentParent.exists()) { + if(currentParent != null && currentParent.exists()) { offerings = currentParent.listFiles(filter); - for (File candidate : offerings) { + for(File candidate : offerings) { String val = "../" + candidate.getName(); - if (!existings.contains(val)) { //only those not already being added in the surrounding area + if(!existings.contains(val)) { //only those not already being added in the surrounding area add(proposals, getContextTypeId(), val, NLS.bind(Messages.PomTemplateContext_candidate, candidate)); } } @@ -491,14 +513,13 @@ public enum PomTemplateContext { Collection<Template> templates = new ArrayList<Template>(); try { addTemplates(project, eclipsePrj, templates, node, prefix); - } catch (CoreException e) { + } catch(CoreException e) { log.error(e.getMessage(), e); } return templates.toArray(new Template[templates.size()]); } - + /** - * * @param project * @param eclipsePrj only here because getSearchEngine() requires it as parameter. * @param templates @@ -506,13 +527,14 @@ public enum PomTemplateContext { * @param prefix * @throws CoreException */ - protected void addTemplates(MavenProject project, IProject eclipsePrj, Collection<Template> templates, Node currentNode, String prefix) throws CoreException { + protected void addTemplates(MavenProject project, IProject eclipsePrj, Collection<Template> templates, + Node currentNode, String prefix) throws CoreException { } protected String getNodeName() { return nodeName; } - + public String getContextTypeId() { return PREFIX + nodeName; } @@ -541,7 +563,6 @@ public enum PomTemplateContext { } return M2EUIPluginActivator.getDefault().getSearchEngine(project); } - private static SearchEngine searchEngineForTests; @@ -586,27 +607,26 @@ public enum PomTemplateContext { private boolean isPlugin(Node currentNode) { return "plugin".equals(currentNode.getParentNode().getNodeName()); //$NON-NLS-1$ } - + /** * Returns true if user is editing plugin dependency exclusion. */ private boolean isExclusion(Node currentNode) { return "exclusion".equals(currentNode.getParentNode().getNodeName()); //$NON-NLS-1$ } - + /** * Returns true if user is editing parent dependency. */ private boolean isParent(Node currentNode) { return "parent".equals(currentNode.getParentNode().getNodeName()); //$NON-NLS-1$ } - + protected String getGroupId(Node currentNode) { return getSiblingTextValue(currentNode, "groupId"); //$NON-NLS-1$ } /** - * * @param project * @param version * @param groupId @@ -614,27 +634,29 @@ public enum PomTemplateContext { * @return * @throws CoreException */ - + static int EXTRACT_STRATEGY_PLUGIN = 1; + static int EXTRACT_STRATEGY_DEPENDENCY = 2; + static int EXTRACT_STRATEGY_SEARCH = 4; - - static String extractVersion(MavenProject mp, IProject project, String version, String groupId, String artifactId, int strategy) - throws CoreException { - + + static String extractVersion(MavenProject mp, IProject project, String version, String groupId, String artifactId, + int strategy) throws CoreException { + assert mp != null; version = simpleInterpolate(mp, version); - - if (version==null) { - Packaging pack = Packaging.ALL; - if ( (strategy & EXTRACT_STRATEGY_PLUGIN) != 0) { + + if(version == null) { + Packaging pack = Packaging.ALL; + if((strategy & EXTRACT_STRATEGY_PLUGIN) != 0) { version = searchPM(mp, groupId, artifactId); pack = Packaging.PLUGIN; } - if ( (strategy & EXTRACT_STRATEGY_DEPENDENCY) != 0) { + if((strategy & EXTRACT_STRATEGY_DEPENDENCY) != 0) { version = searchDM(mp, groupId, artifactId); } - if (version == null && (strategy & EXTRACT_STRATEGY_SEARCH) != 0) { + if(version == null && (strategy & EXTRACT_STRATEGY_SEARCH) != 0) { Collection<String> versions = getSearchEngine(project).findVersions(groupId, artifactId, "", pack); //$NON-NLS-1$ if(versions.isEmpty()) { return null; @@ -647,7 +669,7 @@ public enum PomTemplateContext { // TODO copy of this resides in FormUtils static String simpleInterpolate(MavenProject project, String text) { - if (text != null && text.contains("${")) { //$NON-NLS-1$ + if(text != null && text.contains("${")) { //$NON-NLS-1$ //when expression is in the version but no project instance around // just give up. if(project == null) { @@ -655,21 +677,22 @@ public enum PomTemplateContext { } Properties props = project.getProperties(); RegexBasedInterpolator inter = new RegexBasedInterpolator(); - if (props != null) { + if(props != null) { inter.addValueSource(new PropertiesBasedValueSource(props)); } - inter.addValueSource(new PrefixedObjectValueSource(Arrays.asList( new String[]{ "pom.", "project." } ), project.getModel(), false)); //$NON-NLS-1$ //$NON-NLS-2$ + inter.addValueSource(new PrefixedObjectValueSource( + Arrays.asList(new String[] {"pom.", "project."}), project.getModel(), false)); //$NON-NLS-1$ //$NON-NLS-2$ try { text = inter.interpolate(text); } catch(InterpolationException e) { text = null; } - } + } return text; } - + static String searchPM(MavenProject project, String groupId, String artifactId) { - if (project == null) { + if(project == null) { return null; } String version = null; @@ -685,9 +708,9 @@ public enum PomTemplateContext { } return version; } - + static String searchDM(MavenProject project, String groupId, String artifactId) { - if (project == null) { + if(project == null) { return null; } String version = null; @@ -733,8 +756,8 @@ public enum PomTemplateContext { private static void add(Collection<Template> proposals, String contextTypeId, String name) { add(proposals, contextTypeId, name, name); - } - + } + private static void add(Collection<Template> proposals, String contextTypeId, String name, String description) { proposals.add(new Template(name, description, contextTypeId, name, false)); } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTemplateContextUtil.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTemplateContextUtil.java index ffd75d31..ec784f87 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTemplateContextUtil.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTemplateContextUtil.java @@ -21,20 +21,23 @@ import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; -import org.codehaus.plexus.util.IOUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; +import org.codehaus.plexus.util.IOUtil; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; + import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.embedder.IMaven; + class PomTemplateContextUtil { private static final Logger log = LoggerFactory.getLogger(PomTemplateContextUtil.class); @@ -45,16 +48,16 @@ class PomTemplateContextUtil { public PluginDescriptor getPluginDescriptor(String groupId, String artifactId, String version) { String name = groupId + ":" + artifactId + ":" + version; PluginDescriptor descriptor = descriptors.get(name); - if(descriptor!=null) { + if(descriptor != null) { return descriptor; } - + try { IMaven embedder = MavenPlugin.getMaven(); List<ArtifactRepository> repositories = embedder.getArtifactRepositories(); - Artifact artifact = embedder.resolve(groupId, artifactId, version, "maven-plugin", null, repositories, null); //$NON-NLS-1$ + Artifact artifact = embedder.resolve(groupId, artifactId, version, "maven-plugin", null, repositories, null); //$NON-NLS-1$ File file = artifact.getFile(); if(file == null) { diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java index 65cecdf5..9e7967ab 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java @@ -15,10 +15,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.apache.maven.model.InputLocation; -import org.apache.maven.model.InputSource; -import org.apache.maven.model.Model; -import org.apache.maven.project.MavenProject; import org.w3c.dom.Node; import org.eclipse.jface.text.IDocument; @@ -39,6 +35,11 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.texteditor.MarkerAnnotation; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; +import org.apache.maven.model.InputLocation; +import org.apache.maven.model.InputSource; +import org.apache.maven.model.Model; +import org.apache.maven.project.MavenProject; + import org.eclipse.m2e.core.ui.internal.editing.PomEdits; import org.eclipse.m2e.editor.xml.PomHyperlinkDetector.ExpressionRegion; import org.eclipse.m2e.editor.xml.PomHyperlinkDetector.ManagedArtifactRegion; @@ -47,20 +48,21 @@ import org.eclipse.m2e.editor.xml.internal.Messages; import org.eclipse.m2e.editor.xml.internal.NodeOperation; import org.eclipse.m2e.editor.xml.internal.XmlUtils; + public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHoverExtension2 { public PomTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) { } - + public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { - - if (hoverRegion instanceof ExpressionRegion) { - return getLabelForRegion((ExpressionRegion)hoverRegion).toString(); - } else if (hoverRegion instanceof ManagedArtifactRegion) { + + if(hoverRegion instanceof ExpressionRegion) { + return getLabelForRegion((ExpressionRegion) hoverRegion).toString(); + } else if(hoverRegion instanceof ManagedArtifactRegion) { ManagedArtifactRegion region = (ManagedArtifactRegion) hoverRegion; return getLabelForRegion(region).toString(); } - + return null; } @@ -69,27 +71,27 @@ public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHover */ public static StyledString getLabelForRegion(ManagedArtifactRegion region) { MavenProject mavprj = region.project; - if (mavprj != null) { + if(mavprj != null) { String version = null; - if (region.isDependency) { + if(region.isDependency) { version = PomTemplateContext.searchDM(mavprj, region.groupId, region.artifactId); } - if (region.isPlugin) { + if(region.isPlugin) { version = PomTemplateContext.searchPM(mavprj, region.groupId, region.artifactId); } StyledString ret = new StyledString(); - if (version != null) { + if(version != null) { ret.append(Messages.PomTextHover_managed_version); ret.append(version, StyledString.DECORATIONS_STYLER);//not happy with decorations but how to just do bold text } else { ret.append(Messages.PomTextHover_managed_version_missing); } InputLocation openLocation = PomHyperlinkDetector.findLocationForManagedArtifact(region, mavprj); - if (openLocation != null) { + if(openLocation != null) { //MNGECLIPSE-2539 apparently you can have an InputLocation with null input source. // check! InputSource source = openLocation.getSource(); - if (source != null) { + if(source != null) { ret.append(" "); // a space after the version value ret.append(NLS.bind(Messages.PomTextHover_managed_location, source.getModelId())); } @@ -107,18 +109,18 @@ public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHover */ public static StyledString getLabelForRegion(ExpressionRegion region) { MavenProject mavprj = region.project; - if (mavprj != null) { + if(mavprj != null) { String value = PomTemplateContext.simpleInterpolate(region.project, "${" + region.property + "}"); //$NON-NLS-1$ //$NON-NLS-2$ String loc = null; Model mdl = mavprj.getModel(); - if (mdl.getProperties() != null && mdl.getProperties().containsKey(region.property)) { - if (mdl.getLocation(PomEdits.PROPERTIES) != null) { //$NON-NLS-1$ + if(mdl.getProperties() != null && mdl.getProperties().containsKey(region.property)) { + if(mdl.getLocation(PomEdits.PROPERTIES) != null) { //$NON-NLS-1$ InputLocation location = mdl.getLocation(PomEdits.PROPERTIES).getLocation(region.property); //$NON-NLS-1$ - if (location != null) { + if(location != null) { //MNGECLIPSE-2539 apparently you can have an InputLocation with null input source. // check! InputSource source = location.getSource(); - if (source != null) { + if(source != null) { loc = source.getModelId(); } } @@ -127,7 +129,7 @@ public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHover StyledString ret = new StyledString(); ret.append(Messages.PomTextHover_eval1); ret.append(value, StyledString.DECORATIONS_STYLER); //not happy with decorations but how to just do bold text - if (loc != null) { + if(loc != null) { ret.append(" "); //$NON-NLS-1$ ret.append(NLS.bind(Messages.PomTextHover_eval2, loc)); } @@ -145,45 +147,46 @@ public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHover XmlUtils.performOnCurrentElement(document, offset, new NodeOperation<Node>() { public void process(Node node, IStructuredDocument structured) { ExpressionRegion region = PomHyperlinkDetector.findExpressionRegion(node, textViewer, offset); - if (region != null) { + if(region != null) { regs[0] = region; return; } ManagedArtifactRegion manReg = PomHyperlinkDetector.findManagedArtifactRegion(node, textViewer, offset); - if (manReg != null) { + if(manReg != null) { regs[1] = manReg; return; } } }); CompoundRegion toRet = new CompoundRegion(textViewer, offset); - if (regs[0] != null) { + if(regs[0] != null) { toRet.addRegion(regs[0]); } - if (regs[1] != null) { + if(regs[1] != null) { toRet.addRegion(regs[1]); } - if (textViewer instanceof ISourceViewer) { + if(textViewer instanceof ISourceViewer) { ISourceViewer sourceViewer = (ISourceViewer) textViewer; IAnnotationModel model = sourceViewer.getAnnotationModel(); - if (model != null) { //eg. in tests + if(model != null) { //eg. in tests @SuppressWarnings("unchecked") Iterator<Annotation> it = model.getAnnotationIterator(); - while (it.hasNext()) { + while(it.hasNext()) { Annotation ann = it.next(); - if (ann instanceof MarkerAnnotation) { + if(ann instanceof MarkerAnnotation) { Position pos = sourceViewer.getAnnotationModel().getPosition(ann); - if (pos.includes(offset)) { - toRet.addRegion( new PomHyperlinkDetector.MarkerRegion(pos.getOffset(), pos.getLength(), (MarkerAnnotation)ann)); + if(pos.includes(offset)) { + toRet.addRegion(new PomHyperlinkDetector.MarkerRegion(pos.getOffset(), pos.getLength(), + (MarkerAnnotation) ann)); } } } } } - + return toRet.getRegions().size() > 0 ? toRet : null; } - + public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { return hoverRegion; } @@ -195,20 +198,24 @@ public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHover } }; } - + public static class CompoundRegion implements IRegion { private int length = Integer.MIN_VALUE; + private int offset = Integer.MAX_VALUE; + private List<IRegion> regions = new ArrayList<IRegion>(); + public final ITextViewer textViewer; + public final int textOffset; - + public CompoundRegion(ITextViewer textViewer, int textOffset) { this.textViewer = textViewer; this.textOffset = textOffset; } - + public int getLength() { return length; } @@ -216,19 +223,19 @@ public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHover public int getOffset() { return offset; } - + public void addRegion(IRegion region) { regions.add(region); int start = Math.min(region.getOffset(), offset); int end = Math.max(region.getOffset() + region.getLength(), offset + length); offset = start; - length = end - start; + length = end - start; } - + public List<IRegion> getRegions() { return regions; } - + } } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/XMLSchemaMarkerResolution.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/XMLSchemaMarkerResolution.java index c24d7610..7360b84b 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/XMLSchemaMarkerResolution.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/XMLSchemaMarkerResolution.java @@ -28,9 +28,11 @@ import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; import org.eclipse.m2e.editor.xml.internal.Messages; + /** - * MavenMarkerResolution - * TODO mkleint: this class shall be eventually merged with the class doing the same in POMQuickAssistProcessor + * MavenMarkerResolution TODO mkleint: this class shall be eventually merged with the class doing the same in + * POMQuickAssistProcessor + * * @author dyocum */ public class XMLSchemaMarkerResolution implements IMarkerResolution { @@ -47,27 +49,33 @@ public class XMLSchemaMarkerResolution implements IMarkerResolution { * @see org.eclipse.ui.IMarkerResolution#run(org.eclipse.core.resources.IMarker) */ public void run(final IMarker marker) { - if(marker.getResource().getType() == IResource.FILE){ + if(marker.getResource().getType() == IResource.FILE) { try { - IDOMModel domModel = (IDOMModel)StructuredModelManager.getModelManager().getModelForEdit((IFile)marker.getResource()); - int offset = ((Integer)marker.getAttribute("offset")); //$NON-NLS-1$ - IStructuredDocumentRegion regionAtCharacterOffset = domModel.getStructuredDocument().getRegionAtCharacterOffset(offset); - if(regionAtCharacterOffset != null && regionAtCharacterOffset.getText() != null && - regionAtCharacterOffset.getText().lastIndexOf("<project") >=0){ //$NON-NLS-1$ + IDOMModel domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit( + (IFile) marker.getResource()); + int offset = ((Integer) marker.getAttribute("offset")); //$NON-NLS-1$ + IStructuredDocumentRegion regionAtCharacterOffset = domModel.getStructuredDocument() + .getRegionAtCharacterOffset(offset); + if(regionAtCharacterOffset != null && regionAtCharacterOffset.getText() != null + && regionAtCharacterOffset.getText().lastIndexOf("<project") >= 0) { //$NON-NLS-1$ //in case there are unsaved changes, find the current offset of the <project> node before inserting offset = regionAtCharacterOffset.getStartOffset(); - IDE.openEditor(MvnIndexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(), (IFile)marker.getResource()); - InsertEdit edit = new InsertEdit(offset+8, PomQuickAssistProcessor.XSI_VALUE); + IDE.openEditor(MvnIndexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(), + (IFile) marker.getResource()); + InsertEdit edit = new InsertEdit(offset + 8, PomQuickAssistProcessor.XSI_VALUE); try { edit.apply(domModel.getStructuredDocument()); - IEditorPart activeEditor = MvnIndexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); - MvnIndexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().saveEditor(activeEditor, false); - } catch(Exception e){ + IEditorPart activeEditor = MvnIndexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow() + .getActivePage().getActiveEditor(); + MvnIndexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage() + .saveEditor(activeEditor, false); + } catch(Exception e) { log.error("Unable to insert schema info", e); //$NON-NLS-1$ } } else { String msg = Messages.MavenMarkerResolution_error; - MessageDialog.openError(MvnIndexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.MavenMarkerResolution_error_title, msg); + MessageDialog.openError(MvnIndexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), + Messages.MavenMarkerResolution_error_title, msg); } } catch(Exception e) { log.error("Unable to run quick fix for maven marker", e); //$NON-NLS-1$ diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java index c746cc4a..7db77494 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java @@ -36,44 +36,48 @@ import org.eclipse.ui.texteditor.MarkerAnnotation; import org.eclipse.m2e.editor.xml.PomHyperlinkDetector; import org.eclipse.m2e.editor.xml.PomTextHover; + public final class FormHoverProvider { - public static Execute createHoverRunnable(final Shell parentShell, final IMarker[] markers, final ISourceViewer sourceViewer) { - if (markers.length > 0) { - return new Execute() { - public void run(Point position) { - List<IMarker> markersSet = Arrays.asList(markers); - PomTextHover.CompoundRegion compound = new PomTextHover.CompoundRegion(sourceViewer, 0); - Iterator<Annotation> it = sourceViewer.getAnnotationModel().getAnnotationIterator(); - while (it.hasNext()) { - Annotation ann = it.next(); - if (ann instanceof MarkerAnnotation) { - MarkerAnnotation mann = (MarkerAnnotation) ann; - if (markersSet.contains(mann.getMarker())); + public static Execute createHoverRunnable(final Shell parentShell, final IMarker[] markers, + final ISourceViewer sourceViewer) { + if(markers.length > 0) { + return new Execute() { + public void run(Point position) { + List<IMarker> markersSet = Arrays.asList(markers); + PomTextHover.CompoundRegion compound = new PomTextHover.CompoundRegion(sourceViewer, 0); + Iterator<Annotation> it = sourceViewer.getAnnotationModel().getAnnotationIterator(); + while(it.hasNext()) { + Annotation ann = it.next(); + if(ann instanceof MarkerAnnotation) { + MarkerAnnotation mann = (MarkerAnnotation) ann; + if(markersSet.contains(mann.getMarker())) + ; compound.addRegion(new PomHyperlinkDetector.MarkerRegion(0, 0, mann)); + } } - } - final MarkerHoverControl mhc = new MarkerHoverControl(parentShell); - final Display fDisplay= mhc.getMyShell().getDisplay(); - - final Listener displayListener = new Listener() { - public void handleEvent(Event event) { - if (event.type == SWT.MouseMove) { - if (!(event.widget instanceof Control) || event.widget.isDisposed()) - return; + final MarkerHoverControl mhc = new MarkerHoverControl(parentShell); + final Display fDisplay = mhc.getMyShell().getDisplay(); + + final Listener displayListener = new Listener() { + public void handleEvent(Event event) { + if(event.type == SWT.MouseMove) { + if(!(event.widget instanceof Control) || event.widget.isDisposed()) + return; - IInformationControl infoControl= mhc; - if (infoControl != null && !infoControl.isFocusControl() && infoControl instanceof IInformationControlExtension3) { - IInformationControlExtension3 iControl3= (IInformationControlExtension3) infoControl; - Rectangle controlBounds= iControl3.getBounds(); - if (controlBounds != null) { - Point mouseLoc= event.display.map((Control) event.widget, null, event.x, event.y); - int margin= 20; - Geometry.expand(controlBounds, margin, margin, margin, margin); - if (!controlBounds.contains(mouseLoc)) { - mhc.setVisible(false); + IInformationControl infoControl = mhc; + if(infoControl != null && !infoControl.isFocusControl() + && infoControl instanceof IInformationControlExtension3) { + IInformationControlExtension3 iControl3 = (IInformationControlExtension3) infoControl; + Rectangle controlBounds = iControl3.getBounds(); + if(controlBounds != null) { + Point mouseLoc = event.display.map((Control) event.widget, null, event.x, event.y); + int margin = 20; + Geometry.expand(controlBounds, margin, margin, margin, margin); + if(!controlBounds.contains(mouseLoc)) { + mhc.setVisible(false); + } } - } // } else { // System.out.println("removing mouse move.."); @@ -83,42 +87,42 @@ public final class FormHoverProvider { // */ // if (fDisplay != null && !fDisplay.isDisposed()) // fDisplay.removeFilter(SWT.MouseMove, this); - } + } - } else if (event.type == SWT.FocusOut) { - IInformationControl iControl= mhc; - if (iControl != null && ! iControl.isFocusControl()) - mhc.setVisible(false); + } else if(event.type == SWT.FocusOut) { + IInformationControl iControl = mhc; + if(iControl != null && !iControl.isFocusControl()) + mhc.setVisible(false); + } } + }; + + mhc.setLocation(new Point(position.x, position.y)); + mhc.setSizeConstraints(400, 400); + mhc.setInput(compound); + Point hint = mhc.computeSizeHint(); + mhc.setSize(hint.x, Math.min(hint.y, 400)); + if(!fDisplay.getBounds().contains(position.x + hint.x, position.y)) { + mhc.setLocation(new Point(position.x - (position.x + hint.x - fDisplay.getBounds().width), position.y)); } - }; - - mhc.setLocation(new Point(position.x, position.y)); - mhc.setSizeConstraints(400, 400); - mhc.setInput(compound); - Point hint = mhc.computeSizeHint(); - mhc.setSize(hint.x, Math.min(hint.y, 400)); - if (!fDisplay.getBounds().contains(position.x + hint.x, position.y)) { - mhc.setLocation(new Point(position.x - (position.x + hint.x - fDisplay.getBounds().width), position.y)); - } // mhc.getMyShell().addShellListener(new ShellAdapter() { // public void shellActivated(ShellEvent e) { // mhc.setFocus(); // } // }); - if (!fDisplay.isDisposed()) { - fDisplay.addFilter(SWT.MouseMove, displayListener); - fDisplay.addFilter(SWT.FocusOut, displayListener); - } - mhc.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - fDisplay.removeFilter(SWT.MouseMove, displayListener); - fDisplay.removeFilter(SWT.FocusOut, displayListener); + if(!fDisplay.isDisposed()) { + fDisplay.addFilter(SWT.MouseMove, displayListener); + fDisplay.addFilter(SWT.FocusOut, displayListener); } - }); - mhc.setVisible(true); - } - }; + mhc.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + fDisplay.removeFilter(SWT.MouseMove, displayListener); + fDisplay.removeFilter(SWT.FocusOut, displayListener); + } + }); + mhc.setVisible(true); + } + }; } else { return null; } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerHoverControl.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerHoverControl.java index 5b77dcf1..82257d4c 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerHoverControl.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerHoverControl.java @@ -70,143 +70,145 @@ import org.eclipse.m2e.editor.xml.PomHyperlinkDetector.MarkerRegion; import org.eclipse.m2e.editor.xml.PomTextHover; import org.eclipse.m2e.editor.xml.PomTextHover.CompoundRegion; -public class MarkerHoverControl extends AbstractInformationControl implements IInformationControlExtension2, IInformationControlExtension3, IInformationControlExtension5 { - - private CompoundRegion region; - private Control focusControl; - private Composite parent; - private final DefaultMarkerAnnotationAccess markerAccess; - - - public MarkerHoverControl(Shell shell) { - super(shell, EditorsUI.getTooltipAffordanceString()); - markerAccess = new DefaultMarkerAnnotationAccess(); - create(); - } - /* - * @see org.eclipse.jface.text.IInformationControlExtension2#setInput(java.lang.Object) - */ - public void setInput(Object input) { - assert input instanceof CompoundRegion; - if (input instanceof CompoundRegion) { - region = (CompoundRegion) input; - } else { - throw new IllegalStateException("Not CompoundRegion"); //$NON-NLS-1$ - } - disposeDeferredCreatedContent(); - deferredCreateContent(); - } - - Shell getMyShell() { - return super.getShell(); - } - - Control getRoot() { - return parent; - } - - /* - * @see org.eclipse.jface.text.IInformationControlExtension#hasContents() - */ - public boolean hasContents() { - return region != null; - } +public class MarkerHoverControl extends AbstractInformationControl implements IInformationControlExtension2, + IInformationControlExtension3, IInformationControlExtension5 { - /* - * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractAnnotationHover.AbstractInformationControl#setFocus() - */ - public void setFocus() { - super.setFocus(); - if (focusControl != null) { - focusControl.setFocus(); - } - } + private CompoundRegion region; + + private Control focusControl; + + private Composite parent; - /* - * @see org.eclipse.jface.text.AbstractInformationControl#setVisible(boolean) - */ - public final void setVisible(boolean visible) { - if (!visible) - disposeDeferredCreatedContent(); - super.setVisible(visible); + private final DefaultMarkerAnnotationAccess markerAccess; + + public MarkerHoverControl(Shell shell) { + super(shell, EditorsUI.getTooltipAffordanceString()); + markerAccess = new DefaultMarkerAnnotationAccess(); + create(); + } + + /* + * @see org.eclipse.jface.text.IInformationControlExtension2#setInput(java.lang.Object) + */ + public void setInput(Object input) { + assert input instanceof CompoundRegion; + if(input instanceof CompoundRegion) { + region = (CompoundRegion) input; + } else { + throw new IllegalStateException("Not CompoundRegion"); //$NON-NLS-1$ } + disposeDeferredCreatedContent(); + deferredCreateContent(); + } - protected void disposeDeferredCreatedContent() { - Control[] children= parent.getChildren(); - for (int i= 0; i < children.length; i++) { - children[i].dispose(); - } - ToolBarManager toolBarManager= getToolBarManager(); - if (toolBarManager != null) - toolBarManager.removeAll(); + Shell getMyShell() { + return super.getShell(); + } + + Control getRoot() { + return parent; + } + + /* + * @see org.eclipse.jface.text.IInformationControlExtension#hasContents() + */ + public boolean hasContents() { + return region != null; + } + + /* + * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractAnnotationHover.AbstractInformationControl#setFocus() + */ + public void setFocus() { + super.setFocus(); + if(focusControl != null) { + focusControl.setFocus(); } + } - /* - * @see org.eclipse.jface.text.AbstractInformationControl#createContent(org.eclipse.swt.widgets.Composite) - */ - protected void createContent(Composite parent) { - this.parent= parent; - GridLayout layout= new GridLayout(1, false); - layout.verticalSpacing= 0; - layout.marginWidth= 0; - layout.marginHeight= 0; - parent.setLayout(layout); + /* + * @see org.eclipse.jface.text.AbstractInformationControl#setVisible(boolean) + */ + public final void setVisible(boolean visible) { + if(!visible) + disposeDeferredCreatedContent(); + super.setVisible(visible); + } + + protected void disposeDeferredCreatedContent() { + Control[] children = parent.getChildren(); + for(int i = 0; i < children.length; i++ ) { + children[i].dispose(); } + ToolBarManager toolBarManager = getToolBarManager(); + if(toolBarManager != null) + toolBarManager.removeAll(); + } - /* - * @see org.eclipse.jface.text.AbstractInformationControl#computeSizeHint() - */ - public Point computeSizeHint() { - Point preferedSize= getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT, true); + /* + * @see org.eclipse.jface.text.AbstractInformationControl#createContent(org.eclipse.swt.widgets.Composite) + */ + protected void createContent(Composite parent) { + this.parent = parent; + GridLayout layout = new GridLayout(1, false); + layout.verticalSpacing = 0; + layout.marginWidth = 0; + layout.marginHeight = 0; + parent.setLayout(layout); + } - Point constrains= getSizeConstraints(); - if (constrains == null) - return preferedSize; + /* + * @see org.eclipse.jface.text.AbstractInformationControl#computeSizeHint() + */ + public Point computeSizeHint() { + Point preferedSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT, true); - Point constrainedSize= getShell().computeSize(constrains.x, SWT.DEFAULT, true); + Point constrains = getSizeConstraints(); + if(constrains == null) + return preferedSize; - int width= Math.min(preferedSize.x, constrainedSize.x); - int height= Math.max(preferedSize.y, constrainedSize.y); + Point constrainedSize = getShell().computeSize(constrains.x, SWT.DEFAULT, true); - return new Point(width, height); - } + int width = Math.min(preferedSize.x, constrainedSize.x); + int height = Math.max(preferedSize.y, constrainedSize.y); - /** - * Create content of the hover. This is called after - * the input has been set. - */ - protected void deferredCreateContent() { + return new Point(width, height); + } + + /** + * Create content of the hover. This is called after the input has been set. + */ + protected void deferredCreateContent() { // fillToolbar(); - if (region != null) { - final ScrolledComposite scrolledComposite= new ScrolledComposite(parent, SWT.V_SCROLL); - GridData gridData= new GridData(SWT.FILL, SWT.FILL, true, true); - scrolledComposite.setLayoutData(gridData); - scrolledComposite.setExpandVertical(false); - scrolledComposite.setExpandHorizontal(false); - Composite composite = new Composite(scrolledComposite, SWT.NONE); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - GridLayout layout = new GridLayout(1, false); - composite.setLayout(layout); - scrolledComposite.setContent(composite); - - - for (IRegion reg : region.getRegions()) { - if (reg instanceof PomHyperlinkDetector.MarkerRegion) { - final PomHyperlinkDetector.MarkerRegion markerReg = (PomHyperlinkDetector.MarkerRegion) reg; - createAnnotationInformation(composite, markerReg); - final IMarker mark = markerReg.getAnnotation().getMarker(); - IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry().getResolutions(mark); - if (resolutions.length > 0) { - createResolutionsControl(composite, mark, resolutions); - } + if(region != null) { + final ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + scrolledComposite.setLayoutData(gridData); + scrolledComposite.setExpandVertical(false); + scrolledComposite.setExpandHorizontal(false); + Composite composite = new Composite(scrolledComposite, SWT.NONE); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + GridLayout layout = new GridLayout(1, false); + composite.setLayout(layout); + scrolledComposite.setContent(composite); + + for(IRegion reg : region.getRegions()) { + if(reg instanceof PomHyperlinkDetector.MarkerRegion) { + final PomHyperlinkDetector.MarkerRegion markerReg = (PomHyperlinkDetector.MarkerRegion) reg; + createAnnotationInformation(composite, markerReg); + final IMarker mark = markerReg.getAnnotation().getMarker(); + IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry().getResolutions(mark); + if(resolutions.length > 0) { + createResolutionsControl(composite, mark, resolutions); } + } if(reg instanceof ManagedArtifactRegion) { final ManagedArtifactRegion man = (ManagedArtifactRegion) reg; Composite comp = createTooltipComposite(composite, PomTextHover.getLabelForRegion(man)); //only create the hyperlink when the origin location for jumping is present. //in some cases (managed version comes from imported dependencies) we don't have the location and have nowhere to jump) - if (PomHyperlinkDetector.canCreateHyperLink(man)) { + if(PomHyperlinkDetector.canCreateHyperLink(man)) { Link link = createHyperlink(comp); link.addSelectionListener(new SelectionAdapter() { @Override @@ -218,38 +220,37 @@ public class MarkerHoverControl extends AbstractInformationControl implements II } } - if (reg instanceof ExpressionRegion) { - final ExpressionRegion expr = (ExpressionRegion)reg; - Composite tooltipComposite = createTooltipComposite(composite, PomTextHover.getLabelForRegion(expr)); - if(PomHyperlinkDetector.canCreateHyperLink(expr)) { - Link link = createHyperlink(tooltipComposite); - link.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - dispose(); - PomHyperlinkDetector.createHyperlink(expr).open(); - } - }); - } - } - if (region.getRegions().indexOf(reg) < region.getRegions().size() - 1) { - createSeparator(composite); + if(reg instanceof ExpressionRegion) { + final ExpressionRegion expr = (ExpressionRegion) reg; + Composite tooltipComposite = createTooltipComposite(composite, PomTextHover.getLabelForRegion(expr)); + if(PomHyperlinkDetector.canCreateHyperLink(expr)) { + Link link = createHyperlink(tooltipComposite); + link.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + dispose(); + PomHyperlinkDetector.createHyperlink(expr).open(); + } + }); } } - - - Point constraints = getSizeConstraints(); - Point contentSize = composite.computeSize(constraints != null ? constraints.x : SWT.DEFAULT, SWT.DEFAULT); - - composite.setSize(new Point(contentSize.x, contentSize.y)); //12 is the magic number for height of status line - + if(region.getRegions().indexOf(reg) < region.getRegions().size() - 1) { + createSeparator(composite); + } } - - setColorAndFont(parent, parent.getForeground(), parent.getBackground(), JFaceResources.getDialogFont()); - parent.layout(true); + Point constraints = getSizeConstraints(); + Point contentSize = composite.computeSize(constraints != null ? constraints.x : SWT.DEFAULT, SWT.DEFAULT); + + composite.setSize(new Point(contentSize.x, contentSize.y)); //12 is the magic number for height of status line + } + setColorAndFont(parent, parent.getForeground(), parent.getBackground(), JFaceResources.getDialogFont()); + + parent.layout(true); + } + private Link createHyperlink(Composite parent) { Link link = new Link(parent, SWT.NONE); GridData data2 = new GridData(SWT.FILL, SWT.FILL, true, true); @@ -287,258 +288,256 @@ public class MarkerHoverControl extends AbstractInformationControl implements II return composite; } - - private void setColorAndFont(Control control, Color foreground, Color background, Font font) { - control.setForeground(foreground); - control.setBackground(background); - control.setFont(font); - - if (control instanceof Composite) { - Control[] children= ((Composite) control).getChildren(); - for (int i= 0; i < children.length; i++) { - setColorAndFont(children[i], foreground, background, font); - } + + private void setColorAndFont(Control control, Color foreground, Color background, Font font) { + control.setForeground(foreground); + control.setBackground(background); + control.setFont(font); + + if(control instanceof Composite) { + Control[] children = ((Composite) control).getChildren(); + for(int i = 0; i < children.length; i++ ) { + setColorAndFont(children[i], foreground, background, font); } } + } - private void createAnnotationInformation(Composite parent, final MarkerRegion annotation) { - Composite composite= new Composite(parent, SWT.NONE); - composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); - GridLayout layout= new GridLayout(2, false); - layout.marginHeight= 2; - layout.marginWidth= 2; - layout.horizontalSpacing= 0; - composite.setLayout(layout); + private void createAnnotationInformation(Composite parent, final MarkerRegion annotation) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 2; + layout.marginWidth = 2; + layout.horizontalSpacing = 0; + composite.setLayout(layout); - //this paints the icon.. - final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS); - GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); - gridData.widthHint= 17; - gridData.heightHint= 16; - canvas.setLayoutData(gridData); - canvas.addPaintListener(new PaintListener() { - public void paintControl(PaintEvent e) { - e.gc.setFont(null); - markerAccess.paint(annotation.getAnnotation(), e.gc, canvas, new Rectangle(0, 0, 16, 16)); + //this paints the icon.. + final Canvas canvas = new Canvas(composite, SWT.NO_FOCUS); + GridData gridData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); + gridData.widthHint = 17; + gridData.heightHint = 16; + canvas.setLayoutData(gridData); + canvas.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent e) { + e.gc.setFont(null); + markerAccess.paint(annotation.getAnnotation(), e.gc, canvas, new Rectangle(0, 0, 16, 16)); + } + }); + + //and now comes the text + StyledText text = new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + text.setLayoutData(data); + String annotationText = annotation.getAnnotation().getText(); + if(annotationText != null) { + text.setText(annotationText); + } + if(annotation.isDefinedInParent()) { + new Label(composite, SWT.NONE); + + Link link = new Link(composite, SWT.NONE); + GridData data2 = new GridData(SWT.FILL, SWT.FILL, true, true); + data2.horizontalIndent = 18; + link.setLayoutData(data2); + link.setText("<a>Jump to definition in parent POM</a>"); + link.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + PomHyperlinkDetector.createHyperlink(annotation).open(); + dispose(); } }); - - //and now comes the text - StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY); - GridData data= new GridData(SWT.FILL, SWT.FILL, true, true); - text.setLayoutData(data); - String annotationText = annotation.getAnnotation().getText(); - if (annotationText != null) { - text.setText(annotationText); - } - if (annotation.isDefinedInParent()) { - new Label(composite, SWT.NONE); - - Link link = new Link(composite, SWT.NONE); - GridData data2 = new GridData(SWT.FILL, SWT.FILL, true, true); - data2.horizontalIndent = 18; - link.setLayoutData(data2); - link.setText("<a>Jump to definition in parent POM</a>"); - link.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - PomHyperlinkDetector.createHyperlink(annotation).open(); - dispose(); - } - }); - } - } - - private void createSeparator(Composite parent) { - Label separator= new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); - GridData gridData= new GridData(SWT.FILL, SWT.TOP, true, false); - gridData.verticalIndent = 2; - separator.setLayoutData(gridData); + + } + + private void createSeparator(Composite parent) { + Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); + GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); + gridData.verticalIndent = 2; + separator.setLayoutData(gridData); + } + + private void createResolutionsControl(Composite parent, IMarker mark, IMarkerResolution[] resolutions) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + GridLayout layout = new GridLayout(1, false); + layout.marginWidth = 0; + layout.verticalSpacing = 2; + layout.marginHeight = 0; + composite.setLayout(layout); + + Label quickFixLabel = new Label(composite, SWT.NONE); + GridData layoutData = new GridData(SWT.BEGINNING, SWT.TOP, false, false); + layoutData.horizontalIndent = 4; + quickFixLabel.setLayoutData(layoutData); + String text; + + if(resolutions.length == 1) { + text = Messages.PomTextHover_one_quickfix; + } else { + text = NLS.bind(Messages.PomTextHover_more_quickfixes, String.valueOf(resolutions.length)); } + quickFixLabel.setText(text); - private void createResolutionsControl(Composite parent, IMarker mark, IMarkerResolution[] resolutions) { - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - GridLayout layout= new GridLayout(1, false); - layout.marginWidth = 0; - layout.verticalSpacing = 2; - layout.marginHeight = 0; - composite.setLayout(layout); + Composite composite2 = new Composite(parent, SWT.NONE); + composite2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + GridLayout layout2 = new GridLayout(2, false); + layout2.marginLeft = 5; + layout2.verticalSpacing = 2; + composite2.setLayout(layout2); - Label quickFixLabel= new Label(composite, SWT.NONE); - GridData layoutData= new GridData(SWT.BEGINNING, SWT.TOP, false, false); - layoutData.horizontalIndent= 4; - quickFixLabel.setLayoutData(layoutData); - String text; - - if (resolutions.length == 1) { - text= Messages.PomTextHover_one_quickfix; - } else { - text= NLS.bind(Messages.PomTextHover_more_quickfixes, String.valueOf(resolutions.length)); - } - quickFixLabel.setText(text); - - - Composite composite2= new Composite(parent, SWT.NONE); - composite2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - GridLayout layout2= new GridLayout(2, false); - layout2.marginLeft= 5; - layout2.verticalSpacing= 2; - composite2.setLayout(layout2); - - List<Link> list= new ArrayList<Link>(); - for (int i= 0; i < resolutions.length; i++) { - list.add(createCompletionProposalLink(composite2, mark, resolutions[i], 1));// Original link for single fix, hence pass 1 for count - - } - final Link[] links = list.toArray(new Link[list.size()]); - - - focusControl= links[0]; - for (int i= 0; i < links.length; i++) { - final int index= i; - final Link link= links[index]; - link.addKeyListener(new KeyListener() { - public void keyPressed(KeyEvent e) { - switch (e.keyCode) { - case SWT.ARROW_DOWN: - if (index + 1 < links.length) { - links[index + 1].setFocus(); - } - break; - case SWT.ARROW_UP: - if (index > 0) { - links[index - 1].setFocus(); - } - break; - default: - break; - } - } + List<Link> list = new ArrayList<Link>(); + for(int i = 0; i < resolutions.length; i++ ) { + list.add(createCompletionProposalLink(composite2, mark, resolutions[i], 1));// Original link for single fix, hence pass 1 for count - public void keyReleased(KeyEvent e) { + } + final Link[] links = list.toArray(new Link[list.size()]); + + focusControl = links[0]; + for(int i = 0; i < links.length; i++ ) { + final int index = i; + final Link link = links[index]; + link.addKeyListener(new KeyListener() { + public void keyPressed(KeyEvent e) { + switch(e.keyCode) { + case SWT.ARROW_DOWN: + if(index + 1 < links.length) { + links[index + 1].setFocus(); + } + break; + case SWT.ARROW_UP: + if(index > 0) { + links[index - 1].setFocus(); + } + break; + default: + break; } - }); + } + + public void keyReleased(KeyEvent e) { + } + }); - } } - - private Link createCompletionProposalLink(Composite parent, final IMarker mark, final IMarkerResolution proposal, int count) { - final boolean isMultiFix= count > 1; - if (isMultiFix) { - new Label(parent, SWT.NONE); // spacer to fill image cell - parent= new Composite(parent, SWT.NONE); // indented composite for multi-fix - GridLayout layout= new GridLayout(2, false); - layout.marginWidth= 0; - layout.marginHeight= 0; - parent.setLayout(layout); - } - - Label proposalImage= new Label(parent, SWT.NONE); - proposalImage.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, false, false)); - Image image= null; - if (proposal instanceof ICompletionProposal) { - image = ((ICompletionProposal)proposal).getImage(); - } else if (proposal instanceof IMarkerResolution2) { - image = ((IMarkerResolution2)proposal).getImage(); - } - if (image != null) { - proposalImage.setImage(image); + } + + private Link createCompletionProposalLink(Composite parent, final IMarker mark, final IMarkerResolution proposal, + int count) { + final boolean isMultiFix = count > 1; + if(isMultiFix) { + new Label(parent, SWT.NONE); // spacer to fill image cell + parent = new Composite(parent, SWT.NONE); // indented composite for multi-fix + GridLayout layout = new GridLayout(2, false); + layout.marginWidth = 0; + layout.marginHeight = 0; + parent.setLayout(layout); + } - proposalImage.addMouseListener(new MouseListener() { + Label proposalImage = new Label(parent, SWT.NONE); + proposalImage.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, false, false)); + Image image = null; + if(proposal instanceof ICompletionProposal) { + image = ((ICompletionProposal) proposal).getImage(); + } else if(proposal instanceof IMarkerResolution2) { + image = ((IMarkerResolution2) proposal).getImage(); + } + if(image != null) { + proposalImage.setImage(image); - public void mouseDoubleClick(MouseEvent e) { - } + proposalImage.addMouseListener(new MouseListener() { - public void mouseDown(MouseEvent e) { - } + public void mouseDoubleClick(MouseEvent e) { + } - public void mouseUp(MouseEvent e) { - if (e.button == 1) { - apply(proposal, mark, region.textViewer, region.textOffset); - } - } - }); - } + public void mouseDown(MouseEvent e) { + } - Link proposalLink = new Link(parent, SWT.WRAP); - GridData layoutData= new GridData(SWT.BEGINNING, SWT.TOP, false, false); - String linkText; - if (isMultiFix) { - linkText = NLS.bind(Messages.PomTextHover_category_fix, new Integer(count)); - } else { - linkText = proposal.getLabel(); - } - proposalLink.setText("<a>" + linkText + "</a>"); //$NON-NLS-1$ //$NON-NLS-2$ - proposalLink.setLayoutData(layoutData); - proposalLink.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - apply(proposal, mark, region.textViewer, region.textOffset); + public void mouseUp(MouseEvent e) { + if(e.button == 1) { + apply(proposal, mark, region.textViewer, region.textOffset); + } } }); - return proposalLink; } - - /** - * {@inheritDoc} - * This default implementation returns <code>null</code>. Subclasses may override. - */ - public IInformationControlCreator getInformationPresenterControlCreator() { - return new IInformationControlCreator() { - /* - * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell) - */ - public IInformationControl createInformationControl(Shell parent) { - return new MarkerHoverControl(parent); - } - }; + + Link proposalLink = new Link(parent, SWT.WRAP); + GridData layoutData = new GridData(SWT.BEGINNING, SWT.TOP, false, false); + String linkText; + if(isMultiFix) { + linkText = NLS.bind(Messages.PomTextHover_category_fix, new Integer(count)); + } else { + linkText = proposal.getLabel(); } - - private void apply(IMarkerResolution res, IMarker mark, ITextViewer viewer, int offset) { - if (res instanceof ICompletionProposal) { - apply((ICompletionProposal)res, viewer, offset, false); - } else { - dispose(); - res.run(mark); + proposalLink.setText("<a>" + linkText + "</a>"); //$NON-NLS-1$ //$NON-NLS-2$ + proposalLink.setLayoutData(layoutData); + proposalLink.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + apply(proposal, mark, region.textViewer, region.textOffset); } - } + }); + return proposalLink; + } + + /** + * {@inheritDoc} This default implementation returns <code>null</code>. Subclasses may override. + */ + public IInformationControlCreator getInformationPresenterControlCreator() { + return new IInformationControlCreator() { + /* + * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell) + */ + public IInformationControl createInformationControl(Shell parent) { + return new MarkerHoverControl(parent); + } + }; + } - private void apply(ICompletionProposal p, ITextViewer viewer, int offset, boolean isMultiFix) { - //Focus needs to be in the text viewer, otherwise linked mode does not work + private void apply(IMarkerResolution res, IMarker mark, ITextViewer viewer, int offset) { + if(res instanceof ICompletionProposal) { + apply((ICompletionProposal) res, viewer, offset, false); + } else { dispose(); + res.run(mark); + } + } - IRewriteTarget target= null; - try { - IDocument document= viewer.getDocument(); + private void apply(ICompletionProposal p, ITextViewer viewer, int offset, boolean isMultiFix) { + //Focus needs to be in the text viewer, otherwise linked mode does not work + dispose(); - if (viewer instanceof ITextViewerExtension) { - ITextViewerExtension extension= (ITextViewerExtension) viewer; - target= extension.getRewriteTarget(); - } + IRewriteTarget target = null; + try { + IDocument document = viewer.getDocument(); - if (target != null) - target.beginCompoundChange(); - - if (p instanceof ICompletionProposalExtension2) { - ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p; - e.apply(viewer, (char) 0, isMultiFix ? SWT.CONTROL : SWT.NONE, offset); - } else if (p instanceof ICompletionProposalExtension) { - ICompletionProposalExtension e= (ICompletionProposalExtension) p; - e.apply(document, (char) 0, offset); - } else { - p.apply(document); - } + if(viewer instanceof ITextViewerExtension) { + ITextViewerExtension extension = (ITextViewerExtension) viewer; + target = extension.getRewriteTarget(); + } - Point selection= p.getSelection(document); - if (selection != null) { - viewer.setSelectedRange(selection.x, selection.y); - viewer.revealRange(selection.x, selection.y); - } - } finally { - if (target != null) - target.endCompoundChange(); + if(target != null) + target.beginCompoundChange(); + + if(p instanceof ICompletionProposalExtension2) { + ICompletionProposalExtension2 e = (ICompletionProposalExtension2) p; + e.apply(viewer, (char) 0, isMultiFix ? SWT.CONTROL : SWT.NONE, offset); + } else if(p instanceof ICompletionProposalExtension) { + ICompletionProposalExtension e = (ICompletionProposalExtension) p; + e.apply(document, (char) 0, offset); + } else { + p.apply(document); } + + Point selection = p.getSelection(document); + if(selection != null) { + viewer.setSelectedRange(selection.x, selection.y); + viewer.revealRange(selection.x, selection.y); + } + } finally { + if(target != null) + target.endCompoundChange(); } - - }
\ No newline at end of file + } + +} diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerLocationService.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerLocationService.java index 75577ee4..f0e40179 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerLocationService.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerLocationService.java @@ -25,14 +25,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.DependencyManagement; -import org.apache.maven.model.InputLocation; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginManagement; -import org.apache.maven.project.MavenProject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.w3c.dom.Comment; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -53,6 +48,13 @@ import org.eclipse.wst.xml.core.internal.parser.regions.TagNameRegion; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.InputLocation; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; +import org.apache.maven.project.MavenProject; + import org.eclipse.m2e.core.internal.IMavenConstants; import org.eclipse.m2e.core.internal.markers.IEditorMarkerService; import org.eclipse.m2e.core.internal.markers.IMarkerLocationService; @@ -62,10 +64,11 @@ import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator; import org.eclipse.m2e.core.ui.internal.editing.PomEdits; import org.eclipse.m2e.core.ui.internal.editing.PomEdits.Matcher; + /** * a service impl used by the core module to improve marker locations and addition of our own markers + * * @author mkleint - * */ @SuppressWarnings("restriction") public class MarkerLocationService implements IMarkerLocationService, IEditorMarkerService { @@ -74,6 +77,7 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar private static final String XSI_SCHEMA_LOCATION = "xsi:schemaLocation"; //$NON-NLS-1$ private static final String PROJECT_NODE = "project"; //$NON-NLS-1$ + private static final String OFFSET = "offset"; //$NON-NLS-1$ public void findLocationForMarker(final IMarker marker) { @@ -118,86 +122,88 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar } public void findLocationForMarker_(final IMarker marker) { - + String hint = marker.getAttribute(IMavenConstants.MARKER_ATTR_EDITOR_HINT, null); - - if (IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION.equals(hint)) { + + if(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION.equals(hint)) { try { final boolean lookInPM = false; final String groupId = marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""); final String artifactId = marker.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""); final String exec = marker.getAttribute(IMavenConstants.MARKER_ATTR_EXECUTION_ID, ""); final String goal = marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, ""); - XmlUtils.performOnRootElement((IFile)marker.getResource(), new NodeOperation<Element>() { + XmlUtils.performOnRootElement((IFile) marker.getResource(), new NodeOperation<Element>() { public void process(Element root, IStructuredDocument structuredDocument) { Element build = findChild(root, PomEdits.BUILD); List<Element> candidates = new ArrayList<Element>(); Element plugin = findPlugin(build, groupId, artifactId); - if (plugin != null) { + if(plugin != null) { candidates.add(plugin); } - if (lookInPM) { + if(lookInPM) { plugin = findPlugin(findChild(build, PomEdits.PLUGIN_MANAGEMENT), groupId, artifactId); - if (plugin != null) { + if(plugin != null) { candidates.add(plugin); } } //look in profiles List<Element> profiles = findChilds(findChild(root, PomEdits.PROFILES), PomEdits.PROFILE); //TODO eventually we should only process the activated profiles.. but need MavenProject for it. - for (Element profile : profiles) { + for(Element profile : profiles) { Element profBuild = findChild(profile, PomEdits.BUILD); plugin = findPlugin(profBuild, groupId, artifactId); - if (plugin != null) { + if(plugin != null) { candidates.add(plugin); } - if (lookInPM) { + if(lookInPM) { plugin = findPlugin(findChild(profBuild, PomEdits.PLUGIN_MANAGEMENT), groupId, artifactId); - if (plugin != null) { + if(plugin != null) { candidates.add(plugin); } } } Element ourMarkerPlacement = null; - for (Element candid : candidates) { - Matcher match = exec.equals("default") ? childMissingOrEqual(PomEdits.ID, "default") : childEquals(PomEdits.ID, exec); + for(Element candid : candidates) { + Matcher match = exec.equals("default") ? childMissingOrEqual(PomEdits.ID, "default") : childEquals( + PomEdits.ID, exec); Element execution = findChild(findChild(candid, PomEdits.EXECUTIONS), PomEdits.EXECUTION, match); - if (execution != null) { + if(execution != null) { Element goalEl = findChild(findChild(execution, PomEdits.GOALS), PomEdits.GOAL, textEquals(goal)); - if (goalEl != null) { + if(goalEl != null) { ourMarkerPlacement = goalEl; break; } else { //only remember the first execution match - if (ourMarkerPlacement == null) { + if(ourMarkerPlacement == null) { ourMarkerPlacement = findChild(execution, PomEdits.ID); - if (ourMarkerPlacement == null) { //just old plain paranoia + if(ourMarkerPlacement == null) { //just old plain paranoia ourMarkerPlacement = execution; } } } } } - if (ourMarkerPlacement == null) { - plugin = candidates.size() > 0 ? candidates.get(0) : null; - //executions not here (eg. in PM or parent PM), just mark the plugin's artifactId - ourMarkerPlacement = findChild(plugin, PomEdits.ARTIFACT_ID); - if (ourMarkerPlacement == null && plugin != null) { //just old plain paranoia - ourMarkerPlacement = plugin; - } else { - //what are the strategies for placement when no plugin is found? - // we could.. search pluginManagement, but it's unlikely to be there.. - ourMarkerPlacement = build != null ? build : root; - } + if(ourMarkerPlacement == null) { + plugin = candidates.size() > 0 ? candidates.get(0) : null; + //executions not here (eg. in PM or parent PM), just mark the plugin's artifactId + ourMarkerPlacement = findChild(plugin, PomEdits.ARTIFACT_ID); + if(ourMarkerPlacement == null && plugin != null) { //just old plain paranoia + ourMarkerPlacement = plugin; + } else { + //what are the strategies for placement when no plugin is found? + // we could.. search pluginManagement, but it's unlikely to be there.. + ourMarkerPlacement = build != null ? build : root; + } } - + annotateMarker(marker, structuredDocument, ourMarkerPlacement); } - private Element findPlugin(Element build, String groupId, String artifactId) { - Matcher grIdmatch = groupId.equals("org.apache.maven.plugins") ? childMissingOrEqual(PomEdits.GROUP_ID, groupId) : childEquals(PomEdits.GROUP_ID, groupId); - return findChild(findChild(build, PomEdits.PLUGINS), PomEdits.PLUGIN, grIdmatch, childEquals(PomEdits.ARTIFACT_ID, artifactId)); + Matcher grIdmatch = groupId.equals("org.apache.maven.plugins") ? childMissingOrEqual(PomEdits.GROUP_ID, + groupId) : childEquals(PomEdits.GROUP_ID, groupId); + return findChild(findChild(build, PomEdits.PLUGINS), PomEdits.PLUGIN, grIdmatch, + childEquals(PomEdits.ARTIFACT_ID, artifactId)); } }); } catch(IOException e) { @@ -209,7 +215,7 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar } private void annotateMarker(final IMarker marker, IStructuredDocument structuredDocument, Element ourMarkerPlacement) { - if (ourMarkerPlacement instanceof IndexedRegion) { + if(ourMarkerPlacement instanceof IndexedRegion) { IndexedRegion region = (IndexedRegion) ourMarkerPlacement; try { marker.setAttribute(IMarker.CHAR_START, region.getStartOffset()); @@ -228,7 +234,6 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar } } } - public void addEditorHintMarkers(IMavenMarkerManager markerManager, IFile pom, MavenProject mavenProject, String type) { checkForSchema(markerManager, pom, type); @@ -236,29 +241,30 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar } /** - * The xsi:schema info is not part of the model, it is stored in the xml only. Need to open the DOM - * and look for the project node to see if it has this schema defined - * @param mavenMarkerManager + * The xsi:schema info is not part of the model, it is stored in the xml only. Need to open the DOM and look for the + * project node to see if it has this schema defined + * + * @param mavenMarkerManager * @param pomFile */ static void checkForSchema(IMavenMarkerManager mavenMarkerManager, IResource pomFile, String type) { IDOMModel domModel = null; - try{ - if(!(pomFile instanceof IFile)){ + try { + if(!(pomFile instanceof IFile)) { return; } - domModel = (IDOMModel)StructuredModelManager.getModelManager().getModelForRead((IFile)pomFile); + domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead((IFile) pomFile); IStructuredDocument document = domModel.getStructuredDocument(); - + // iterate through document regions - documentLoop:for(IStructuredDocumentRegion documentRegion : document.getStructuredDocumentRegions()) { + documentLoop: for(IStructuredDocumentRegion documentRegion : document.getStructuredDocumentRegions()) { // only check tag regions - if (DOMRegionContext.XML_TAG_NAME.equals(documentRegion.getType())){ - for(ITextRegion textRegion: documentRegion.getRegions().toArray()){ + if(DOMRegionContext.XML_TAG_NAME.equals(documentRegion.getType())) { + for(ITextRegion textRegion : documentRegion.getRegions().toArray()) { // find a project tag - if(textRegion instanceof TagNameRegion && PROJECT_NODE.equals(documentRegion.getText(textRegion))){ + if(textRegion instanceof TagNameRegion && PROJECT_NODE.equals(documentRegion.getText(textRegion))) { // check if schema is missing - if (documentRegion.getText().lastIndexOf(XSI_SCHEMA_LOCATION) == -1) { + if(documentRegion.getText().lastIndexOf(XSI_SCHEMA_LOCATION) == -1) { int offset = documentRegion.getStartOffset(); int lineNumber = document.getLineOfOffset(offset) + 1; IMarker marker = mavenMarkerManager.addMarker(pomFile, type, @@ -266,7 +272,7 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar IMarker.SEVERITY_WARNING); //the quick fix in the marker view needs to know the offset, since it doesn't have access to the //editor/source viewer - if(marker != null){ + if(marker != null) { marker.setAttribute(OFFSET, offset); marker.setAttribute(IMavenConstants.MARKER_ATTR_EDITOR_HINT, IMavenConstants.EDITOR_HINT_MISSING_SCHEMA); @@ -283,23 +289,22 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar } } catch(Exception ex) { log.error("Error checking for schema", ex); //$NON-NLS-1$ - } - finally { - if ( domModel != null ) { + } finally { + if(domModel != null) { domModel.releaseFromRead(); } } } - private static void checkManagedDependencies(IMavenMarkerManager mavenMarkerManager, Element root, IResource pomFile, MavenProject mavenproject, String type, IStructuredDocument document) - throws CoreException { + private static void checkManagedDependencies(IMavenMarkerManager mavenMarkerManager, Element root, IResource pomFile, + MavenProject mavenproject, String type, IStructuredDocument document) throws CoreException { List<Element> candidates = new ArrayList<Element>(); - + Element dependencies = findChild(root, PomEdits.DEPENDENCIES); - if (dependencies != null) { - for (Element el : findChilds(dependencies, PomEdits.DEPENDENCY)) { + if(dependencies != null) { + for(Element el : findChilds(dependencies, PomEdits.DEPENDENCY)) { Element version = findChild(el, PomEdits.VERSION); - if (version != null) { + if(version != null) { candidates.add(el); } } @@ -307,20 +312,21 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar //we should also consider <dependencies> section in the profiles, but profile are optional and so is their // dependencyManagement section.. that makes handling our markers more complex. // see MavenProject.getInjectedProfileIds() for a list of currently active profiles in effective pom - String currentProjectKey = mavenproject.getGroupId() + ":" + mavenproject.getArtifactId() + ":" + mavenproject.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$ + String currentProjectKey = mavenproject.getGroupId() + + ":" + mavenproject.getArtifactId() + ":" + mavenproject.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$ List<String> activeprofiles = mavenproject.getInjectedProfileIds().get(currentProjectKey); //remember what profile we found the dependency in. Map<Element, String> candidateProfile = new HashMap<Element, String>(); Element profiles = findChild(root, PomEdits.PROFILES); - if (profiles != null) { - for (Element profile : findChilds(profiles, PomEdits.PROFILE)) { + if(profiles != null) { + for(Element profile : findChilds(profiles, PomEdits.PROFILE)) { String idString = getTextValue(findChild(profile, PomEdits.ID)); - if (idString != null && activeprofiles.contains(idString)) { + if(idString != null && activeprofiles.contains(idString)) { dependencies = findChild(profile, PomEdits.DEPENDENCIES); - if (dependencies != null) { - for (Element el : findChilds(dependencies, PomEdits.DEPENDENCY)) { + if(dependencies != null) { + for(Element el : findChilds(dependencies, PomEdits.DEPENDENCY)) { Element version = findChild(el, PomEdits.VERSION); - if (version != null) { + if(version != null) { candidates.add(el); candidateProfile.put(el, idString); } @@ -332,18 +338,18 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar //collect the managed dep ids Map<String, String> managed = new HashMap<String, String>(); DependencyManagement dm = mavenproject.getDependencyManagement(); - if (dm != null) { + if(dm != null) { List<Dependency> deps = dm.getDependencies(); - if (deps != null) { - for (Dependency dep : deps) { - if (dep.getVersion() != null) { //#335366 + if(deps != null) { + for(Dependency dep : deps) { + if(dep.getVersion() != null) { //#335366 //shall we be using geManagementkey() here? but it contains also the type, not only the gr+art ids.. managed.put(dep.getGroupId() + ":" + dep.getArtifactId(), dep.getVersion()); //$NON-NLS-1$ } } } } - + //now we have all the candidates, match them against the effective managed set for(Element dep : candidates) { Element version = findChild(dep, PomEdits.VERSION); @@ -359,7 +365,7 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar if(lookForIgnoreMarker(document, version, off, IMavenConstants.MARKER_IGNORE_MANAGED)) { continue; } - + IMarker mark = mavenMarkerManager.addMarker(pomFile, type, NLS.bind( org.eclipse.m2e.core.internal.Messages.MavenMarkerManager_managed_title, managedVersion, artString), document.getLineOfOffset(off.getStartOffset()) + 1, IMarker.SEVERITY_WARNING); @@ -381,18 +387,18 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar } } - private static void checkManagedPlugins(IMavenMarkerManager mavenMarkerManager, Element root, IResource pomFile, MavenProject mavenproject, String type, IStructuredDocument document) - throws CoreException { + private static void checkManagedPlugins(IMavenMarkerManager mavenMarkerManager, Element root, IResource pomFile, + MavenProject mavenproject, String type, IStructuredDocument document) throws CoreException { List<Element> candidates = new ArrayList<Element>(); Element build = findChild(root, PomEdits.BUILD); - if (build == null) { + if(build == null) { return; } - Element plugins = findChild(build, PomEdits.PLUGINS); - if (plugins != null) { - for (Element el : findChilds(plugins, PomEdits.PLUGIN)) { + Element plugins = findChild(build, PomEdits.PLUGINS); + if(plugins != null) { + for(Element el : findChilds(plugins, PomEdits.PLUGIN)) { Element version = findChild(el, PomEdits.VERSION); - if (version != null) { + if(version != null) { candidates.add(el); } } @@ -400,24 +406,25 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar //we should also consider <plugins> section in the profiles, but profile are optional and so is their // pluginManagement section.. that makes handling our markers more complex. // see MavenProject.getInjectedProfileIds() for a list of currently active profiles in effective pom - String currentProjectKey = mavenproject.getGroupId() + ":" + mavenproject.getArtifactId() + ":" + mavenproject.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$ + String currentProjectKey = mavenproject.getGroupId() + + ":" + mavenproject.getArtifactId() + ":" + mavenproject.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$ List<String> activeprofiles = mavenproject.getInjectedProfileIds().get(currentProjectKey); //remember what profile we found the dependency in. Map<Element, String> candidateProfile = new HashMap<Element, String>(); Element profiles = findChild(root, PomEdits.PROFILES); - if (profiles != null) { - for (Element profile : findChilds(profiles, PomEdits.PROFILE)) { - String idString = getTextValue(findChild(profile, PomEdits.ID)); - if (idString != null && activeprofiles.contains(idString)) { + if(profiles != null) { + for(Element profile : findChilds(profiles, PomEdits.PROFILE)) { + String idString = getTextValue(findChild(profile, PomEdits.ID)); + if(idString != null && activeprofiles.contains(idString)) { build = findChild(profile, PomEdits.BUILD); - if (build == null) { + if(build == null) { continue; } plugins = findChild(build, PomEdits.PLUGINS); - if (plugins != null) { - for (Element el : findChilds(plugins, PomEdits.PLUGIN)) { + if(plugins != null) { + for(Element el : findChilds(plugins, PomEdits.PLUGIN)) { Element version = findChild(el, PomEdits.VERSION); - if (version != null) { + if(version != null) { candidates.add(el); candidateProfile.put(el, idString); } @@ -429,23 +436,23 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar //collect the managed plugin ids Map<String, String> managed = new HashMap<String, String>(); PluginManagement pm = mavenproject.getPluginManagement(); - if (pm != null) { + if(pm != null) { List<Plugin> plgs = pm.getPlugins(); - if (plgs != null) { - for (Plugin plg : plgs) { + if(plgs != null) { + for(Plugin plg : plgs) { InputLocation loc = plg.getLocation("version"); //#350203 skip plugins defined in the superpom - if (loc != null) { + if(loc != null) { managed.put(plg.getKey(), plg.getVersion()); } } } } - + //now we have all the candidates, match them against the effective managed set for(Element dep : candidates) { String grpString = getTextValue(findChild(dep, PomEdits.GROUP_ID)); //$NON-NLS-1$ - if (grpString == null) { + if(grpString == null) { grpString = "org.apache.maven.plugins"; //$NON-NLS-1$ } String artString = getTextValue(findChild(dep, PomEdits.ARTIFACT_ID)); //$NON-NLS-1$ @@ -460,7 +467,7 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar if(lookForIgnoreMarker(document, version, off, IMavenConstants.MARKER_IGNORE_MANAGED)) { continue; } - + IMarker mark = mavenMarkerManager.addMarker(pomFile, type, NLS.bind( org.eclipse.m2e.core.internal.Messages.MavenMarkerManager_managed_title, managedVersion, artString), document.getLineOfOffset(off.getStartOffset()) + 1, IMarker.SEVERITY_WARNING); @@ -482,12 +489,11 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar } } - private static void checkParentMatchingGroupIdVersion(IMavenMarkerManager mavenMarkerManager, Element root, IResource pomFile, String type, - IStructuredDocument document) throws CoreException { + private static void checkParentMatchingGroupIdVersion(IMavenMarkerManager mavenMarkerManager, Element root, + IResource pomFile, String type, IStructuredDocument document) throws CoreException { Element parent = findChild(root, PomEdits.PARENT); Element groupId = findChild(root, PomEdits.GROUP_ID); - if(parent != null && groupId != null - && !skipParentMatchingGroupIdWarning()) { + if(parent != null && groupId != null && !skipParentMatchingGroupIdWarning()) { //now compare the values of parent and project groupid.. String parentString = getTextValue(findChild(parent, PomEdits.GROUP_ID)); String childString = getTextValue(groupId); @@ -506,8 +512,7 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar } } Element version = findChild(root, PomEdits.VERSION); //$NON-NLS-1$ - if(parent != null && version != null - && !skipParentMatchingVersionWarning()) { + if(parent != null && version != null && !skipParentMatchingVersionWarning()) { //now compare the values of parent and project version.. String parentString = getTextValue(findChild(parent, PomEdits.VERSION)); //$NON-NLS-1$ String childString = getTextValue(version); @@ -528,21 +533,22 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar } private static boolean skipParentMatchingGroupIdWarning() { - return M2EUIPluginActivator.getDefault().getPreferenceStore().getBoolean( - MavenPreferenceConstants.P_DISABLE_GROUPID_DUP_OF_PARENT_WARNING); + return M2EUIPluginActivator.getDefault().getPreferenceStore() + .getBoolean(MavenPreferenceConstants.P_DISABLE_GROUPID_DUP_OF_PARENT_WARNING); } private static boolean skipParentMatchingVersionWarning() { - return M2EUIPluginActivator.getDefault().getPreferenceStore().getBoolean( - MavenPreferenceConstants.P_DISABLE_VERSION_DUP_OF_PARENT_WARNING); + return M2EUIPluginActivator.getDefault().getPreferenceStore() + .getBoolean(MavenPreferenceConstants.P_DISABLE_VERSION_DUP_OF_PARENT_WARNING); } /** - * @param mavenMarkerManager + * @param mavenMarkerManager * @param pomFile * @param mavenProject can be null */ - static void checkVarious(IMavenMarkerManager mavenMarkerManager, IResource pomFile, MavenProject mavenProject, String type) { + static void checkVarious(IMavenMarkerManager mavenMarkerManager, IResource pomFile, MavenProject mavenProject, + String type) { IDOMModel domModel = null; try { if(!(pomFile instanceof IFile)) { @@ -551,11 +557,11 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead((IFile) pomFile); IStructuredDocument document = domModel.getStructuredDocument(); Element root = domModel.getDocument().getDocumentElement(); - + if(root.getNodeName().equals("project")) { //$NON-NLS-1$ //now check parent version and groupid against the current project's ones.. checkParentMatchingGroupIdVersion(mavenMarkerManager, root, pomFile, type, document); - if (mavenProject != null) { + if(mavenProject != null) { checkManagedDependencies(mavenMarkerManager, root, pomFile, mavenProject, type, document); checkManagedPlugins(mavenMarkerManager, root, pomFile, mavenProject, type, document); } @@ -568,24 +574,25 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar } } } - - private static boolean lookForIgnoreMarker(IStructuredDocument document, Element version, IndexedRegion off, String ignoreString) { + + private static boolean lookForIgnoreMarker(IStructuredDocument document, Element version, IndexedRegion off, + String ignoreString) { Node reg = version; int line = document.getLineOfOffset(off.getStartOffset()); try { int lineend = document.getLineOffset(line) + document.getLineLength(line) - 1; int start = off.getStartOffset(); - while (reg != null && start < lineend) { + while(reg != null && start < lineend) { reg = reg.getNextSibling(); - if (reg != null && reg instanceof Comment) { - Comment comm = (Comment)reg; - String data =comm.getData(); - if (data != null && data.contains(ignoreString)) { + if(reg != null && reg instanceof Comment) { + Comment comm = (Comment) reg; + String data = comm.getData(); + if(data != null && data.contains(ignoreString)) { return true; } } - if (reg != null) { - start = ((IndexedRegion)reg).getStartOffset(); + if(reg != null) { + start = ((IndexedRegion) reg).getStartOffset(); } } } catch(BadLocationException ex) { @@ -594,5 +601,4 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar return false; } - } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/NodeOperation.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/NodeOperation.java index 82c6e266..25e0cded 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/NodeOperation.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/NodeOperation.java @@ -15,10 +15,12 @@ import org.w3c.dom.Node; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; + /** - *A non-editing operation on top of the DOM document, to be used with XmlUtils.performOnRootElement and XmlUtils.performOnCurrentElement + * A non-editing operation on top of the DOM document, to be used with XmlUtils.performOnRootElement and + * XmlUtils.performOnCurrentElement + * * @author mkleint - * * @param <T> */ public interface NodeOperation<T extends Node> { diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/POMMarkerAnnotationModel.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/POMMarkerAnnotationModel.java index 72031cdf..d7489606 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/POMMarkerAnnotationModel.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/POMMarkerAnnotationModel.java @@ -18,8 +18,10 @@ import org.eclipse.wst.sse.ui.internal.StructuredResourceMarkerAnnotationModel; import org.eclipse.m2e.core.internal.IMavenConstants; + /** * created this file to get the proper lightbulb icon for the warnings with hint + * * @author mkleint */ public class POMMarkerAnnotationModel extends StructuredResourceMarkerAnnotationModel { diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/POMMarkerAnnotationModelFactory.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/POMMarkerAnnotationModelFactory.java index f324d455..9aaeb1b8 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/POMMarkerAnnotationModelFactory.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/POMMarkerAnnotationModelFactory.java @@ -18,9 +18,10 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModelFactory; + /** - * created this file to get the proper lightbulb icon for the warnings with hint - * is almost exact copy of the wst one.. + * created this file to get the proper lightbulb icon for the warnings with hint is almost exact copy of the wst one.. + * * @author mkleint */ public class POMMarkerAnnotationModelFactory extends ResourceMarkerAnnotationModelFactory { @@ -34,10 +35,9 @@ public class POMMarkerAnnotationModelFactory extends ResourceMarkerAnnotationMod public IAnnotationModel createAnnotationModel(IPath location) { IAnnotationModel model = null; IFile file = FileBuffers.getWorkspaceFileAtLocation(location); - if (file != null) { + if(file != null) { model = new POMMarkerAnnotationModel(file); - } - else { + } else { model = new POMMarkerAnnotationModel(ResourcesPlugin.getWorkspace().getRoot(), location.toString()); } return model; diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java index ba210189..42e4ba9d 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java @@ -16,11 +16,9 @@ import java.io.IOException; import java.util.List; import java.util.Stack; -import org.apache.maven.model.InputLocation; -import org.apache.maven.model.InputSource; -import org.apache.maven.project.MavenProject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -43,12 +41,17 @@ import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; +import org.apache.maven.model.InputLocation; +import org.apache.maven.model.InputSource; +import org.apache.maven.project.MavenProject; + import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.embedder.IMaven; import org.eclipse.m2e.core.project.IMavenProjectFacade; import org.eclipse.m2e.core.ui.internal.editing.PomEdits; + + /** - * * @author mkleint */ public class XmlUtils { @@ -65,9 +68,11 @@ public class XmlUtils { public static String getTextValue(Node element) { return PomEdits.getTextValue(element); } + /** - * finds exactly one (first) occurence of child element with the given name (eg. dependency) - * that fulfills conditions expressed by the Matchers (eg. groupId/artifactId match) + * finds exactly one (first) occurence of child element with the given name (eg. dependency) that fulfills conditions + * expressed by the Matchers (eg. groupId/artifactId match) + * * @param parent * @param name * @param matchers @@ -78,17 +83,18 @@ public class XmlUtils { } /** - * what is this method supposed to do? for the sourceViewer find the associated file on disk and for - * that one find the IProject it belongs to. The required condition for the IProject instance is that - * project relative path of the file shall only be pom.xml (thus no nested, unopened maven pom). - * So that when MavenPlugin.getMavenProjectManager().getProject(prj); is called later on - * the instance, it actually returns the maven model facade for the pom.xml backing the sourceViewer. + * what is this method supposed to do? for the sourceViewer find the associated file on disk and for that one find the + * IProject it belongs to. The required condition for the IProject instance is that project relative path of the file + * shall only be pom.xml (thus no nested, unopened maven pom). So that when + * MavenPlugin.getMavenProjectManager().getProject(prj); is called later on the instance, it actually returns the + * maven model facade for the pom.xml backing the sourceViewer. + * * @param sourceViewer * @return */ public static IProject extractProject(ITextViewer sourceViewer) { ITextFileBuffer buf = FileBuffers.getTextFileBufferManager().getTextFileBuffer(sourceViewer.getDocument()); - if (buf == null) { + if(buf == null) { //eg. for viewers of pom files in local repository return null; } @@ -100,22 +106,22 @@ public class XmlUtils { //we do so by shortening the path and remembering all the resources identified. // at the end we pick the last one from the stack. is there a catch to it? IFile ifile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); - if (ifile != null) { + if(ifile != null) { stack.push(ifile); } while(path.segmentCount() > 1) { IResource ires = ResourcesPlugin.getWorkspace().getRoot().findMember(path); if(ires != null && ires instanceof IFile) { - stack.push((IFile)ires); + stack.push((IFile) ires); } path = path.removeFirstSegments(1); } IFile res = stack.empty() ? null : stack.pop(); - if (res != null) { + if(res != null) { IProject prj = res.getProject(); - //the project returned is in a way unrelated to nested child poms that don't have an opened project, - //in that case we pass along a wrong parent/aggregator - if (res.getProjectRelativePath().segmentCount() != 1) { + //the project returned is in a way unrelated to nested child poms that don't have an opened project, + //in that case we pass along a wrong parent/aggregator + if(res.getProjectRelativePath().segmentCount() != 1) { //if the project were the pom's project, the relative path would be just "pom.xml", if it's not just throw it out of the window.. prj = null; } @@ -123,48 +129,51 @@ public class XmlUtils { } return null; } - + public static MavenProject extractMavenProject(ITextViewer sourceViewer) { //look in the sourceViewer's cache only - if (sourceViewer instanceof IAdaptable) { - return (MavenProject)((IAdaptable)sourceViewer).getAdapter(MavenProject.class); + if(sourceViewer instanceof IAdaptable) { + return (MavenProject) ((IAdaptable) sourceViewer).getAdapter(MavenProject.class); } return null; } /** - * converts an InputLocation to a file path on the local disk, null if not available. - * still the input source's model value can be used further.. + * converts an InputLocation to a file path on the local disk, null if not available. still the input source's model + * value can be used further.. + * * @param location * @return */ - public static File fileForInputLocation(InputLocation location, MavenProject origin) { + public static File fileForInputLocation(InputLocation location, MavenProject origin) { InputSource source = location.getSource(); - if (source != null) { + if(source != null) { //MNGECLIPSE-2539 apparently if maven can't resolve the model from local storage, //the location will be empty. not only applicable to local repo models but //apparently also to models in workspace not reachable by relativePath String loc = source.getLocation(); File file = null; - if (loc != null) { + if(loc != null) { file = new File(loc); } else { //try to find pom by coordinates.. String modelId = source.getModelId(); - if (origin.getModel().getId().equals(modelId) && origin.getFile() != null) { + if(origin.getModel().getId().equals(modelId) && origin.getFile() != null) { return origin.getFile(); } String[] splitStrings = modelId.split(":"); assert splitStrings.length == 3; - IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getMavenProject(splitStrings[0], splitStrings[1], splitStrings[2]); - if (facade != null) { + IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getMavenProject(splitStrings[0], + splitStrings[1], splitStrings[2]); + if(facade != null) { file = facade.getPomFile(); } else { //if not in the workspace, try looking into the local repository. IMaven maven = MavenPlugin.getMaven(); try { - String path = maven.getArtifactPath(maven.getLocalRepository(), splitStrings[0], splitStrings[1], splitStrings[2], "pom", null); - if (path != null) { + String path = maven.getArtifactPath(maven.getLocalRepository(), splitStrings[0], splitStrings[1], + splitStrings[2], "pom", null); + if(path != null) { file = new File(maven.getLocalRepositoryPath(), path); } } catch(CoreException e) { @@ -178,12 +187,9 @@ public class XmlUtils { } /** - * originally copied from org.eclipse.wst.xml.ui.internal.hyperlink.XMLHyperlinkDetector - - * this method grabs the IDOMModel for the IDocument, performs the passed operation on the node at the offset - * and then releases the IDOMModel - * - * operation's Node value is also an instance of IndexedRegion + * originally copied from org.eclipse.wst.xml.ui.internal.hyperlink.XMLHyperlinkDetector this method grabs the + * IDOMModel for the IDocument, performs the passed operation on the node at the offset and then releases the + * IDOMModel operation's Node value is also an instance of IndexedRegion * * @param offset */ @@ -195,28 +201,26 @@ public class XmlUtils { IStructuredModel sModel = null; try { sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (sModel != null) { + if(sModel != null) { IndexedRegion inode = sModel.getIndexedRegion(offset); - if (inode == null) { + if(inode == null) { inode = sModel.getIndexedRegion(offset - 1); } - if (inode instanceof Node) { + if(inode instanceof Node) { operation.process((Node) inode, sModel.getStructuredDocument()); - } + } } - } - finally { - if (sModel != null) { + } finally { + if(sModel != null) { sModel.releaseFromRead(); } } } /** - * this method grabs the IDOMModel for the IDocument, performs the passed operation on the root element of the document - * and then releases the IDOMModel + * this method grabs the IDOMModel for the IDocument, performs the passed operation on the root element of the + * document and then releases the IDOMModel root Element value is also an instance of IndexedRegion * - * root Element value is also an instance of IndexedRegion * @param doc * @param operation */ @@ -226,37 +230,38 @@ public class XmlUtils { IDOMModel domModel = null; try { domModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(doc); - if (domModel == null) { + if(domModel == null) { throw new IllegalArgumentException("Document is not structured: " + doc); } IStructuredDocument document = domModel.getStructuredDocument(); Element root = domModel.getDocument().getDocumentElement(); operation.process(root, document); } finally { - if (domModel != null) { + if(domModel != null) { domModel.releaseFromRead(); } } } - - public static void performOnRootElement(IFile resource, NodeOperation<Element> operation) throws IOException, CoreException { + + public static void performOnRootElement(IFile resource, NodeOperation<Element> operation) throws IOException, + CoreException { assert resource != null; assert operation != null; IDOMModel domModel = null; try { domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(resource); - if (domModel == null) { + if(domModel == null) { throw new IllegalArgumentException("Document is not structured: " + resource); } IStructuredDocument document = domModel.getStructuredDocument(); Element root = domModel.getDocument().getDocumentElement(); operation.process(root, document); } finally { - if (domModel != null) { + if(domModel != null) { domModel.releaseFromRead(); } } - } + } /* * calculates the path of the node up in the hierarchy, example of result is project/build/plugins/plugin @@ -266,19 +271,17 @@ public class XmlUtils { public static String pathUp(Node node, int level) { StringBuffer buf = new StringBuffer(); int current = level; - while (node != null && current > 0) { - if (node instanceof Element) { - if (buf.length() > 0) { + while(node != null && current > 0) { + if(node instanceof Element) { + if(buf.length() > 0) { buf.insert(0, "/"); } buf.insert(0, node.getNodeName()); - current = current -1; + current = current - 1; } node = node.getParentNode(); } return buf.toString(); } - - } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/dialogs/SelectSPDXLicenseDialog.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/dialogs/SelectSPDXLicenseDialog.java index 18bb0862..13e10cc8 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/dialogs/SelectSPDXLicenseDialog.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/dialogs/SelectSPDXLicenseDialog.java @@ -13,8 +13,6 @@ package org.eclipse.m2e.editor.xml.internal.dialogs; import java.util.Collection; -import org.apache.maven.project.MavenProject; - import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.ILabelProvider; @@ -44,6 +42,8 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; +import org.apache.maven.project.MavenProject; + import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.project.IMavenProjectFacade; import org.eclipse.m2e.core.ui.internal.components.PomHierarchyComposite; diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java index 59a55028..af53849b 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java @@ -14,10 +14,6 @@ package org.eclipse.m2e.editor.xml.internal.lifecycle; import java.io.File; import java.lang.reflect.InvocationTargetException; -import org.apache.maven.model.InputLocation; -import org.apache.maven.model.Plugin; -import org.apache.maven.project.MavenProject; - import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.dialogs.Dialog; @@ -37,6 +33,10 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; +import org.apache.maven.model.InputLocation; +import org.apache.maven.model.Plugin; +import org.apache.maven.project.MavenProject; + import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.internal.M2EUtils; import org.eclipse.m2e.core.project.IMavenProjectFacade; diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java index 710f9308..27f589a9 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java @@ -9,7 +9,6 @@ * Sonatype, Inc. - initial API and implementation *******************************************************************************/ - package org.eclipse.m2e.editor.xml.internal.lifecycle; import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument; @@ -51,17 +50,17 @@ public class LifecycleMappingProposal extends AbstractLifecycleMappingProposal i private static final Logger log = LoggerFactory.getLogger(LifecycleMappingProposal.class); private IQuickAssistInvocationContext context; - + public LifecycleMappingProposal(IQuickAssistInvocationContext context, MarkerAnnotation mark, PluginExecutionAction action) { super(mark.getMarker(), action); this.context = context; } - + public LifecycleMappingProposal(IMarker marker, PluginExecutionAction action) { super(marker, action); } - + public void apply(final IDocument doc) { try { if(PluginExecutionAction.ignore.equals(action)) { @@ -93,7 +92,7 @@ public class LifecycleMappingProposal extends AbstractLifecycleMappingProposal i }); if(pomFile[0] != null) { List<LifecycleMappingOperation> lst = new ArrayList<LifecycleMappingOperation>(); - for (IMarker m : marks) { + for(IMarker m : marks) { lst.add(createOperation(m)); } performOnDOMDocument(new OperationTuple(pomFile[0], new CompoundOperation(lst.toArray(new Operation[0])))); @@ -104,11 +103,10 @@ public class LifecycleMappingProposal extends AbstractLifecycleMappingProposal i String pluginGroupId = mark.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""); //$NON-NLS-1$ String pluginArtifactId = mark.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""); //$NON-NLS-1$ String pluginVersion = mark.getAttribute(IMavenConstants.MARKER_ATTR_VERSION, ""); //$NON-NLS-1$ - String[] goals = new String[] { mark.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, "")}; //$NON-NLS-1$ + String[] goals = new String[] {mark.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, "")}; //$NON-NLS-1$ return new LifecycleMappingOperation(pluginGroupId, pluginArtifactId, pluginVersion, action, goals); } - public String getAdditionalProposalInfo() { return null; } @@ -128,7 +126,7 @@ public class LifecycleMappingProposal extends AbstractLifecycleMappingProposal i } public Object getAdditionalProposalInfo(IProgressMonitor monitor) { - if (context == null) { + if(context == null) { //no context in markerresolution, just to be sure.. return null; } @@ -138,12 +136,14 @@ public class LifecycleMappingProposal extends AbstractLifecycleMappingProposal i String goal = marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, ""); //$NON-NLS-1$ String execution = marker.getAttribute(IMavenConstants.MARKER_ATTR_EXECUTION_ID, "-"); //$NON-NLS-1$ String phase = marker.getAttribute(IMavenConstants.MARKER_ATTR_LIFECYCLE_PHASE, "-"); //$NON-NLS-1$ - String info = NLS.bind(Messages.LifecycleMappingProposal_all_desc, - new Object[] {goal, execution, phase, pluginGroupId + ":" + pluginArtifactId + ":" + pluginVersion, //$NON-NLS-1$ //$NON-NLS-2$ - (PluginExecutionAction.ignore.equals(action) - ? Messages.LifecycleMappingProposal_ignore_desc + String info = NLS.bind(Messages.LifecycleMappingProposal_all_desc, new Object[] { + goal, + execution, + phase, + pluginGroupId + ":" + pluginArtifactId + ":" + pluginVersion, //$NON-NLS-1$ //$NON-NLS-2$ + (PluginExecutionAction.ignore.equals(action) ? Messages.LifecycleMappingProposal_ignore_desc : Messages.LifecycleMappingProposal_execute_desc)}); - + return info; } @@ -154,10 +154,11 @@ public class LifecycleMappingProposal extends AbstractLifecycleMappingProposal i performIgnore(markers); } else { List<LifecycleMappingOperation> lst = new ArrayList<LifecycleMappingOperation>(); - for (IMarker m : markers) { + for(IMarker m : markers) { lst.add(createOperation(m)); } - performOnDOMDocument(new OperationTuple((IFile) marker.getResource(), new CompoundOperation(lst.toArray(new Operation[0])))); + performOnDOMDocument(new OperationTuple((IFile) marker.getResource(), new CompoundOperation( + lst.toArray(new Operation[0])))); } } catch(IOException e) { log.error("Error generating code in pom.xml", e); //$NON-NLS-1$ @@ -165,6 +166,5 @@ public class LifecycleMappingProposal extends AbstractLifecycleMappingProposal i log.error(e.getMessage(), e); } } - - -}
\ No newline at end of file + +} diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java index 6b8a1d67..70550bbd 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java @@ -14,8 +14,6 @@ package org.eclipse.m2e.editor.xml.internal.lifecycle; import java.util.HashSet; -import org.codehaus.plexus.util.xml.Xpp3Dom; - import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; @@ -25,6 +23,8 @@ import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Point; +import org.codehaus.plexus.util.xml.Xpp3Dom; + import org.eclipse.m2e.core.internal.IMavenConstants; import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory; import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadataSource; diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/preferences/PomTemplatesPreferencePage.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/preferences/PomTemplatesPreferencePage.java index 67022b62..1edaeb16 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/preferences/PomTemplatesPreferencePage.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/preferences/PomTemplatesPreferencePage.java @@ -16,7 +16,6 @@ import org.eclipse.ui.texteditor.templates.TemplatePreferencePage; import org.eclipse.m2e.editor.xml.MvnIndexPlugin; - /** * @author Eugene Kuleshov */ |